@@ -96,7 +96,18 @@ def get_UA_axes(self, data_container, index):
9696
9797 index = int (index )
9898
99- trans_axes = data_container .atoms .principal_axes ()
99+ # trans_axes = data_container.atoms.principal_axes()
100+ # use the same customPI trans axes as the residue level
101+ UAs = data_container .select_atoms ("mass 2 to 999" )
102+ UA_masses = self .get_UA_masses (data_container .atoms )
103+ center = data_container .atoms .center_of_mass ()
104+ moment_of_inertia_tensor = self .get_moment_of_inertia_tensor (
105+ center , UAs .positions , UA_masses
106+ )
107+ trans_axes , _moment_of_inertia = self .get_custom_principal_axes (
108+ moment_of_inertia_tensor
109+ )
110+
100111 # look for heavy atoms in residue of interest
101112 heavy_atoms = data_container .select_atoms ("prop mass > 1.1" )
102113 heavy_atom_indices = []
@@ -174,12 +185,12 @@ def get_bonded_axes(self, system, atom, dimensions):
174185 # find the heavy bonded atoms and light bonded atoms
175186 heavy_bonded , light_bonded = self .find_bonded_atoms (atom .index , system )
176187 UA = atom + light_bonded
177- UA_all = atom + heavy_bonded + light_bonded
188+ # UA_all = atom + heavy_bonded + light_bonded
178189
179190 # now find which atoms to select to find the axes for rotating forces:
180- # case1
181- if len (heavy_bonded ) == 0 :
182- custom_axes , custom_moment_of_inertia = self .get_vanilla_axes (UA_all )
191+ # case1, won't apply to UA level
192+ # if len(heavy_bonded) == 0:
193+ # custom_axes, custom_moment_of_inertia = self.get_vanilla_axes(UA_all)
183194 # case2
184195 if len (heavy_bonded ) == 1 and len (light_bonded ) == 0 :
185196 custom_axes = self .get_custom_axes (
@@ -193,34 +204,35 @@ def get_bonded_axes(self, system, atom, dimensions):
193204 light_bonded [0 ].position ,
194205 dimensions ,
195206 )
196- # case4
197- if len (heavy_bonded ) == 2 :
198- custom_axes = self .get_custom_axes (
199- atom .position ,
200- [heavy_bonded [0 ].position ],
201- heavy_bonded [1 ].position ,
202- dimensions ,
203- )
207+ # case4, not used in Jon's code, use case5 instead
208+ # if len(heavy_bonded) == 2:
209+ # custom_axes = self.get_custom_axes(
210+ # atom.position,
211+ # [heavy_bonded[0].position],
212+ # heavy_bonded[1].position,
213+ # dimensions,
214+ # )
204215 # case5
205- if len (heavy_bonded ) > 2 :
216+ if len (heavy_bonded ) >= 2 :
206217 custom_axes = self .get_custom_axes (
207218 atom .position ,
208219 heavy_bonded .positions ,
209220 heavy_bonded [1 ].position ,
210221 dimensions ,
211222 )
212223
224+ if custom_moment_of_inertia is None :
225+ # find moment of inertia using custom axes and atom position as COM
226+ custom_moment_of_inertia = self .get_custom_moment_of_inertia (
227+ UA , custom_axes , atom .position
228+ )
229+
213230 # get the moment of inertia from the custom axes
214231 if custom_axes is not None :
215232 # flip axes to face correct way wrt COM
216233 custom_axes = self .get_flipped_axes (
217234 UA , custom_axes , atom .position , dimensions
218235 )
219- if custom_moment_of_inertia is None :
220- # find moment of inertia using custom axes and atom position as COM
221- custom_moment_of_inertia = self .get_custom_moment_of_inertia (
222- UA , custom_axes , atom .position
223- )
224236
225237 return custom_axes , custom_moment_of_inertia
226238
@@ -304,31 +316,27 @@ def get_custom_axes(
304316 Returns:
305317 custom_axes: (3,3) array of the axes used to rotate forces
306318 """
307- axis1 = np .zeros (3 )
319+ unscaled_axis1 = np .zeros (3 )
308320 # average of all heavy atom covalent bond vectors for axis1
309321 for b in b_list :
310322 ab_vector = self .get_vector (a , b , dimensions )
311- # scale vector with distance
312- ab_dist = np .sqrt ((ab_vector ** 2 ).sum (axis = - 1 ))
313- scaled_vector = np .divide (ab_vector , ab_dist )
314- axis1 += scaled_vector # ab_vector
315- if len (b_list ) > 2 :
316- # use the first heavy bonded atom and atom c
317- ac_vector = self .get_vector (b_list [0 ], c , dimensions )
323+ unscaled_axis1 += ab_vector
324+ if len (b_list ) >= 2 :
325+ # use the first heavy bonded atom as atom a
326+ ac_vector = self .get_vector (c , b_list [0 ], dimensions )
318327 else :
319- ac_vector = self .get_vector (a , c , dimensions )
320- ac_dist = np .sqrt ((ac_vector ** 2 ).sum (axis = - 1 ))
321- ac_vector_norm = np .divide (ac_vector , ac_dist )
328+ ac_vector = self .get_vector (c , a , dimensions )
322329
323- if len (b_list ) > 2 :
324- axis2 = np .cross (ac_vector_norm , axis1 )
325- else :
326- axis2 = np .cross (axis1 , ac_vector_norm )
327- axis3 = np .cross (axis1 , axis2 )
330+ unscaled_axis2 = np .cross (ac_vector , unscaled_axis1 )
331+ unscaled_axis3 = np .cross (unscaled_axis2 , unscaled_axis1 )
328332
329- custom_axes = np .array ((axis1 , axis2 , axis3 ))
333+ unscaled_custom_axes = np .array (
334+ (unscaled_axis1 , unscaled_axis2 , unscaled_axis3 )
335+ )
336+ mod = np .sqrt (np .sum (unscaled_custom_axes ** 2 , axis = 1 ))
337+ scaled_custom_axes = unscaled_custom_axes / mod [:, np .newaxis ]
330338
331- return custom_axes
339+ return scaled_custom_axes
332340
333341 def get_custom_moment_of_inertia (
334342 self , UA , custom_rotation_axes : np .ndarray , center_of_mass : np .ndarray
@@ -466,8 +474,6 @@ def get_custom_principal_axes(
466474 if dot_z < 0 :
467475 principal_axes [2 ] *= - 1
468476
469- logger .debug (f"principal_axes: { principal_axes } " )
470-
471477 return principal_axes , moment_of_inertia
472478
473479 def get_UA_masses (self , molecule ) -> list [float ]:
0 commit comments