-
Notifications
You must be signed in to change notification settings - Fork 0
/
min_sc.py
56 lines (46 loc) · 1.38 KB
/
min_sc.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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# ******************************
# OpenBabel local minimization
# Credit: Kasper Thofte
# ..............................
# ******************************
# Variables:
num_grad_steps = 50
file_name_ini = 'test_ini.pdb'
file_name_opt = 'test_opt.pdb'
# (its not prefectly clear what these identifiers refer to)
movable = [653,661,662,656,663,662,657,665,664,658,660,659]
forceField = 'MMFF94'
informat, outformat = 'pdb', 'pdb'
# ..............................
# ******************************
# Setup
from openbabel import *
conv = OBConversion()
conv.SetInAndOutFormats(informat, outformat)
mol = OBMol()
conv.ReadFile(mol, file_name_ini)
cnstr = OBFFConstraints()
# ..............................
# ******************************
# Define constraints
FF = OBForceField.FindForceField(forceField)
FF.Setup(mol)
for atom in OBMolAtomIter(mol):
Anum = atom.GetIdx()
if Anum not in movable:
cnstr.AddAtomConstraint(Anum)
print Anum
# ..............................
# ******************************
# Optimization
FF.SetConstraints(cnstr)
FF.ConjugateGradients(num_grad_steps)
FF.GetCoordinates(mol)
for atom in OBMolAtomIter(mol):
print atom.GetAtomicNum(), atom.GetX(), atom.GetY(), atom.GetZ()
# ..............................
# ******************************
# Write optimized file
conv.WriteFile(mol, file_name_opt)
# ..............................