Skip to content

Commit da61d21

Browse files
added round trip tests for dihedrals in trappe
1 parent 0e64d88 commit da61d21

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

foyer/forcefields/trappe-ua.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@
189189
<!-- CHX-CHY-[C]=[O] -->
190190
<Proper class1="CHx" class2="CHx" type3="CH_ald" class4="O_sp2" c0="9.32159" c1="-1.18722" c2="-0.96182" c3="9.7522" c4="0.0" c5="0.0"/>
191191
<Proper class1="CHx" class2="CHx" type3="C_ket" class4="O_sp2" c0="9.32159" c1="-1.18722" c2="-0.96182" c3="9.7522" c4="0.0" c5="0.0"/>
192+
<!-- acrylates -->
193+
<!-- maerzke T4.1 C-O-C=O -->
194+
<Proper class1="CHx" type2="O_acryl_sp3" type3="C_acryl" type4="O_acryl_sp2" c0="-26.55539" c1="2.7175" c2="-22.83383" c3="1.00405" c4="0.0" c5="0.0"/>
195+
<!-- maerzke T4.2 C-O-C(sp2)-C(sp2) -->
196+
<Proper class1="CHx" type2="O_acryl_sp3" type3="C_acryl" class4="CHx_sp2" c0="-26.55539" c1="-2.7175" c2="-22.83383" c3="-1.00405" c4="0.0" c5="0.0"/>
197+
<!-- maerzke T4.3 C(sp2)=C(sp2)-C=O -->
198+
<Proper class1="CHx_sp2" class2="CHx_sp2" type3="C_acryl" type4="O_acryl_sp2" c0="-13.27121" c1="0.34871" c2="-12.85632" c3="0.06618" c4="0.0" c5="0.0"/>
199+
<!-- maerzke T4.4 C(sp2)=C-C-O -->
200+
<Proper class1="CHx_sp2" class2="CHx_sp2" type3="C_acryl" type4="O_acryl_sp3" c0="-13.27121" c1="-0.34871" c2="-12.85632" c3="-0.06618" c4="0.0" c5="0.0"/>
201+
<!-- maerzke T4.5 O=C-C(sp2)-C -->
202+
<Proper type1="O_acryl_sp2" type2="C_acryl" class3="CHx_sp2" class4="CHx" c0="-0.49271" c1="1.84298" c2="0.84109" c3="-0.80218" c4="1.89237" c5="0.0"/>
203+
<!-- maerzke T4.6 O-C-C(sp2)-C -->
204+
<Proper type1="O_acryl_sp3" type2="C_acryl" class3="CHx_sp2" class4="CHx" c0="-0.49271" c1="-1.84298" c2="0.84109" c3="0.80218" c4="1.89237" c5="0.0"/>
205+
<!-- maerzke T4.8 C=C-C=C -->
206+
<Proper type1="CH2_sp2" type2="CH_sp2-Csp2" type3="CH_sp2-Csp2" type4="CH2_sp2" c0="-28.85375" c1="7.05523" c2="-33.6714" c3="-15.29994" c4="13.06235" c5="0.0"/>
192207
<!--
193208
No parameters for CHX-[CH2]-[CH]-OH, CHX-[CH2]-[C]-OH, CHX-[CH]-[CH2]-OH,
194209
CHX-[CH]-[CH]-OH, CHX-[CH]-[C]-OH, CHX-[C]-[CH2]-OH, CHX-[C]-[CH]-OH,
@@ -197,7 +212,7 @@
197212
<!-- alkenes -->
198213
<Proper class1="CHx" type2="CH2_sp3" type3="CH_sp2" class4="CHx_sp2" c0="2.27051" c1="-7.75806" c2="1.82536" c3="9.38669" c4="0.0" c5="0.0"/>
199214
<Proper class1="CHx" type2="CH2_sp3-Cald" type3="CH_sp2" class4="CHx_sp2" c0="2.27051" c1="-7.75806" c2="1.82536" c3="9.38669" c4="0.0" c5="0.0"/>
200-
<Proper type1="CH2_sp2" type2="CH_sp2-Csp2" type3="CH_sp2-Csp2" type4="CH2_sp2" c0="4.55208" c1="7.05523" c2="20.60905" c3="-15.29994" c4="0.0" c5="0.0"/>
215+
201216
<Proper type1="CH2_sp2" type2="CH_sp2-Csp2" type3="C_sp2-Csp2" class4="CHx" c0="-9.69998" c1="-11.57082" c2="17.43875" c3="19.30751" c4="0.0" c5="0.0"/>
202217
</RBTorsionForce>
203218
<NonbondedForce coulomb14scale="0" lj14scale="0">

foyer/tests/test_trappe.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,41 @@ def parmed2trappe(val):
102102
def angle_parmed2trappe(val):
103103
return 2 * parmed2trappe(val)
104104

105+
def assert_dihedrals_match(foyer_d, reference_params):
106+
def conv1(t):
107+
# convert RB to Trappe#1
108+
raise ValueError
109+
R0, R1, R2, R3 = t.c0, t.c1, t.c2, t.c3
110+
c0 = R0 - R1 + R2 - R3
111+
c1 = R1 + 3/4. * R3
112+
c2 = -0.5 * R2
113+
c3 = 1/4. * R3
114+
115+
return c0, c1, c2, c3
116+
117+
def conv2(t):
118+
# convert RB to Trappe#2
119+
R0, R1, R2, R3, R4 = t.c0, t.c1, t.c2, t.c3, t.c4
120+
print(list(map(lambda x: x * calorie, [R0, R1, R2, R3, R4])))
121+
c0 = - R0 + 0.5 * R2 + 3/8. * R4
122+
c1 = - R1 - 3/4. * R3
123+
c2 = 0.5 * R2 + 0.5 * R4
124+
c3 = - 1/4. * R3
125+
c4 = 1/8. * R4
126+
127+
return [parmed2trappe(v) for v in [c0, c1, c2, c3, c4]]
128+
129+
reference_params = list(map(float, reference_params))
130+
# check parameters in *foyer_d* match the raw text from trappe
131+
# trappe's params are in one of two functional forms.....
132+
if len(reference_params) == 5:
133+
# using later form
134+
foyer_params = conv2(foyer_d.type)
135+
else:
136+
# using original dihedral form
137+
foyer_params = conv1(foyer_d.type)
138+
139+
assert_almost_equal(foyer_params, reference_params, decimal=3)
105140

106141
class TestTrappeReferences(object):
107142
@staticmethod
@@ -149,7 +184,7 @@ def check_angles(ref, struc):
149184
angle_dict[i+1, j+1, k+1] = a
150185

151186
for ref_angle in ref_angles:
152-
_, desc, _, angle, k_angle = ref_angle.strip().split(",")
187+
_, desc, _, angle, k_angle = ref_angle.strip().split(',')
153188
i, j, k = map(int, desc.strip("\"\'").split('-'))
154189

155190
foyer_angle = angle_dict[i, j, k]
@@ -165,7 +200,23 @@ def check_angles(ref, struc):
165200
def check_dihedrals(ref, struc):
166201
ref_dihedrals = ref['torsion']
167202

168-
assert len(ref_dihedrals) == len(struc.dihedrals)
203+
assert len(ref_dihedrals) == len(struc.rb_torsions)
204+
205+
dih_dict = {}
206+
for d in struc.rb_torsions:
207+
i, j, k, l = d.atom1.idx, d.atom2.idx, d.atom3.idx, d.atom4.idx
208+
209+
if l < i:
210+
i, j, k, l = l, k, j, i
211+
dih_dict[i+1, j+1, k+1, l+1] = d
212+
213+
for ref_d in ref_dihedrals:
214+
_, desc, _, *params = ref_d.strip().split(',')
215+
i, j, k, l = map(int, desc.strip("\"\'").split('-'))
216+
217+
foyer_d = dih_dict[i, j, k, l]
218+
219+
assert_dihedrals_match(foyer_d, params)
169220

170221
@pytest.mark.parametrize('trappe_ref,mol2file', [
171222
('methyl_acrylate/trappe_parameters_96.csv', 'methyl_acrylate'),

0 commit comments

Comments
 (0)