@@ -102,6 +102,41 @@ def parmed2trappe(val):
102102def 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
106141class 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