forked from vtlim/off_psi4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfs2turb.py
More file actions
103 lines (80 loc) · 3.17 KB
/
confs2turb.py
File metadata and controls
103 lines (80 loc) · 3.17 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
## Usage: python confs2turb.py -i /path/and/filename.sdf
## Different from confs2psi.py since method, basisset, calc type, mem
## should be specified in the templateOptions file of Turbomole setup.
import os
import argparse
import openeye.oechem as oechem
import subprocess as sp
### ------------------- Functions -------------------
def GetMolDetails(mol, label):
"""
Parameters
----------
mol: single OEChem conformer with coordinates
label: string - name of the molecule. Can be an empty string.
Returns
-------
optinfo: string - Turbomole input file for autoDefine.py
xinfo: string - XYZ format coordinates to feed into Turbomole's x2t
"""
optinfo = ("$title %s" % label)
optinfo += ("\n$charge %d" % oechem.OENetCharge( mol))
optinfo += ("\n$end")
xinfo = ("%d\n" % mol.NumAtoms())
xyz = oechem.OEFloatArray(3)
# get coordinates of each atom
for atom in mol.GetAtoms():
mol.GetCoords( atom, xyz)
xinfo+=( '\n %s %10.4f %10.4f %10.4f' \
%(oechem.OEGetAtomicSymbol(atom.GetAtomicNum()),
xyz[0], xyz[1], xyz[2]) )
return optinfo, xinfo
### ------------------- Script -------------------
def confs2turb(insdf):
"""
Parameters
----------
insdf: string - PATH+name of SDF file
"""
homedir = os.getcwd()
p = sp.call('module load turbomole/7.1/intel', shell=True)
### Read in .sdf file and distinguish each molecule's conformers
ifs = oechem.oemolistream()
ifs.SetConfTest( oechem.OEAbsoluteConfTest() )
if not ifs.open(insdf):
oechem.OEThrow.Warning("Unable to open %s for reading" % insdf)
return
### For each molecule: for each conf, generate input
for mol in ifs.GetOEMols():
print(mol.GetTitle(), mol.NumConfs())
for i, conf in enumerate( mol.GetConfs()):
# change into subdirectory to use x2t
subdir = os.path.join(homedir,"%s/%s" % (mol.GetTitle(), i+1))
if not os.path.isdir(subdir):
os.makedirs(subdir)
os.chdir(subdir)
# write out relevant files
label = mol.GetTitle()+'_'+str(i+1)
ofile = open('options','w')
xfile = open('input.xyz','w')
optinfo, xinfo = GetMolDetails(conf,label)
ofile.write(optinfo)
xfile.write(xinfo)
ofile.close()
xfile.close()
# run x2t
p=sp.Popen('x2t input.xyz > coord',shell=True)
p.wait()
#os.chdir(wdir) # i don't think i need this?
ifs.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='This script generates, for \
each conformer, a Turbomole-style coord file as well as an options\
file for use with autoDefine.py which automates define process of Turbomole.\
Options file contains title and charge of mol.\
x2t is run for each coord file to generate Turbomole coordinates.')
parser.add_argument('-i','--infile', help='Input file with mols and confs\
for each mol. Include the full path with filename.')
args = parser.parse_args()
confs2turb(args.infile)