-
Notifications
You must be signed in to change notification settings - Fork 0
/
TFM_extract_molsbyat.py
42 lines (33 loc) · 1.21 KB
/
TFM_extract_molsbyat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: cp1252 -*-
# ----------------------------------------------------------
# Copyright (C) 2018 PHARAMACELERA S.L.
# All rights reserved.
#
# File: TFM_extract_molsbyat.py
#
# Created on 20/05/2018
# ----------------------------------------------------------
##ELISA G. DE LOPE
##ATOM TYPES - MOPAC PROJECT
#Script to extract the names of the molecules containing a certain atom type.
#USAGE: python extract_molsbyat.py file_with_ats atomtype
import mol2
import sys
def get_data(myfile):
"""Transform each molecule in the file into a molecule object with attributes (check mol2.py file)"""
my_mol=mol2.read_molecule(myfile)
return my_mol
###--------MAIN----------------------------------------------------------
atfile = open(sys.argv[1], 'r')
target_at = sys.argv[2]
target_at = target_at.upper()
myoutput_file = open("mols_"+target_at+".txt", "w")
my_mol_at = get_data(atfile)
while my_mol_at != None:
my_mol_at.lAtomTypes = [element.upper() for element in my_mol_at.lAtomTypes]
if target_at in my_mol_at.lAtomTypes:
print target_at
s = my_mol_at.sName
myoutput_file.write(s)
my_mol_at = get_data(atfile)
myoutput_file.close()