@@ -123,6 +123,7 @@ def get_residue_axes(self, data_container, index: int, residue=None):
123123 # No UAS are bonded to other residues
124124 # Use a custom principal axes, from a MOI tensor that uses positions of
125125 # heavy atoms only, but including masses of heavy atom + bonded H.
126+
126127 moi_tensor = self .get_moment_of_inertia_tensor (
127128 center_of_mass = np .array (residue .center_of_mass ()),
128129 positions = uas .positions ,
@@ -225,7 +226,6 @@ def get_UA_axes(self, data_container, index: int, res_position):
225226 """
226227 index = int (index ) # bead index
227228 heavy_atoms = data_container .atoms .select_atoms ("mass 2 to 999" )
228-
229229 # use the same customPI trans axes as the residue level
230230 if len (heavy_atoms ) > 1 :
231231 if len (data_container .residues ) == 1 :
@@ -289,15 +289,6 @@ def get_UA_axes(self, data_container, index: int, res_position):
289289 trans_center = np .array (backbone .center_of_mass ())
290290 trans_axes = self .get_residue_custom_axes (edges , trans_center )
291291
292- else :
293- # only one heavy atom or hydrogen molecule
294- make_whole (data_container .atoms )
295- residue = data_container
296- # trans_center is center of mass
297- trans_center = np .array (data_container .center_of_mass ())
298- trans_axes = data_container .atoms .principal_axes ()
299-
300- if len (heavy_atoms ) > 1 :
301292 residue_heavy_atoms = residue .atoms .select_atoms ("mass 2 to 999" )
302293 # look for heavy atoms in residue of interest
303294 heavy_atom_indices = []
@@ -307,19 +298,30 @@ def get_UA_axes(self, data_container, index: int, res_position):
307298 # where n is the bead index
308299 heavy_atom_index = heavy_atom_indices [index ]
309300 heavy_atom = residue .atoms .select_atoms (f"index { heavy_atom_index } " )
301+ rot_center = heavy_atom .positions [0 ]
302+ rot_axes , moment_of_inertia = self .get_bonded_axes (
303+ system = data_container ,
304+ atom = heavy_atom [0 ],
305+ dimensions = data_container .dimensions [:3 ],
306+ )
307+
310308 else :
311- # only the one heavy atom
309+ # 1 heavy atom in the data_container
312310 heavy_atom = heavy_atoms [0 ]
311+ # trans and rot centres are centre of mass
312+ rot_center = data_container .center_of_mass ()
313+ rot_axes , moment_of_inertia = self .get_bonded_axes (
314+ system = data_container ,
315+ atom = heavy_atom [0 ],
316+ dimensions = data_container .dimensions [:3 ],
317+ )
318+ trans_center = rot_center
319+ # principal axes
320+ trans_axes = rot_axes
321+
313322 if trans_axes is None :
314323 raise ValueError ("Unable to compute translation axes for UA bead." )
315324
316- rot_center = heavy_atom .positions [0 ]
317- rot_axes , moment_of_inertia = self .get_bonded_axes (
318- system = data_container ,
319- atom = heavy_atom [0 ],
320- dimensions = data_container .dimensions [:3 ],
321- )
322-
323325 if rot_axes is None or moment_of_inertia is None :
324326 raise ValueError ("Unable to compute bonded axes for UA bead." )
325327
@@ -765,7 +767,6 @@ def get_moment_of_inertia_tensor(
765767 """
766768 r = self .get_vector (center_of_mass , positions , dimensions )
767769 r2 = np .sum (r ** 2 , axis = 1 )
768-
769770 masses_arr = np .asarray (list (masses ), dtype = float )
770771 moment_of_inertia_tensor = np .eye (3 ) * np .sum (masses_arr * r2 )
771772 moment_of_inertia_tensor -= np .einsum ("i,ij,ik->jk" , masses_arr , r , r )
@@ -797,6 +798,7 @@ def get_custom_principal_axes(
797798 - principal_axes: (3, 3) principal axes (rows).
798799 - moment_of_inertia: (3,) principal moments.
799800 """
801+
800802 eigenvalues , eigenvectors = np .linalg .eig (moment_of_inertia_tensor )
801803 order = np .abs (eigenvalues ).argsort ()[::- 1 ] # descending order
802804 transposed = np .transpose (eigenvectors ) # columns -> rows
0 commit comments