forked from dkoes/rdkit-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uffminimize.py
executable file
·43 lines (34 loc) · 1.19 KB
/
uffminimize.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
43
#!/usr/bin/python
import sys,string
from rdkit.Chem import AllChem as Chem
from optparse import OptionParser
#minimize sdf structures with the UFF forcefiled and rdkit
parser = OptionParser(usage="Usage: %prog [options] <input>.sdf <output>.sdf")
parser.add_option("-v","--verbose", dest="verbose",action="store_true",default=False,
help="verbose output")
(options, args) = parser.parse_args()
input = args[0]
output = args[1]
inmols = Chem.SDMolSupplier(input)
if inmols is None:
print "Could not open ".input
sys.exit(-1)
sdwriter = Chem.SDWriter(output)
if sdwriter is None:
print "Could not open ".output
sys.exit(-1)
for mol in inmols:
if mol is not None:
try:
orig = Chem.UFFGetMoleculeForceField(mol).CalcEnergy()
Chem.UFFOptimizeMolecule(mol)
if options.verbose:
e = Chem.UFFGetMoleculeForceField(mol).CalcEnergy()
print mol.GetProp('_Name'),orig,"->",e
sdwriter.write(mol)
except (KeyboardInterrupt, SystemExit):
raise
except:
print "Exception occurred",mol.GetProp('_Name')
else:
print "ERROR"