forked from lilyminium/valence-fitting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-forcefield.py
37 lines (28 loc) · 930 Bytes
/
generate-forcefield.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
from collections import defaultdict
from copy import deepcopy
from openff.toolkit import ForceField
base = ForceField("openff-2.2.0-rc1.offxml")
with open("to_add.dat") as inp:
to_add = [
line.strip()
for line in inp
if not line.startswith("#") and len(line) > 1
]
new_params = defaultdict(list)
for line in to_add:
[pid, smirks] = line.split()
new_params[pid].append(smirks)
to_remove = ["t123"]
torsions = base.get_parameter_handler("ProperTorsions")
old = deepcopy(torsions.parameters)
torsions.parameters.clear()
for t in old:
if t.id in new_params:
for i, p in enumerate(new_params[t.id]):
tmp = deepcopy(t)
tmp.id = t.id + "ghijkl"[i]
tmp.smirks = p
torsions.parameters.append(tmp)
elif t.id not in to_remove:
torsions.parameters.append(t)
base.to_file("output/initial-force-field-openff-2.1.0.offxml")