@@ -117,13 +117,17 @@ def _select_atoms(q):
117117 assert np .allclose (moi , np .array ([3.0 , 2.0 , 1.0 ]))
118118
119119
120- def test_get_residue_axes_with_bonds_uses_vanilla_axes (monkeypatch ):
120+ def test_get_residue_axes_uses_vanilla_axes (monkeypatch ):
121121 ax = AxesCalculator ()
122122
123123 residue = MagicMock ()
124124 residue .__len__ .return_value = 1
125125 residue .atoms .center_of_mass .return_value = np .array ([1.0 , 2.0 , 3.0 ])
126126 residue .center_of_mass .return_value = np .array ([1.0 , 2.0 , 3.0 ])
127+ residue .select_atoms .return_value = MagicMock (
128+ positions = [[1.0 , 2.0 , 3.0 ], [3.0 , 2.0 , 1.0 ]]
129+ )
130+ uas = MagicMock (positions = np .zeros ((2 , 3 )))
127131
128132 u = MagicMock ()
129133 u .dimensions = np .array ([10.0 , 10.0 , 10.0 , 90 , 90 , 90 ])
@@ -135,20 +139,25 @@ def _select_atoms(q):
135139 return [1 ] # non-empty
136140 if q .startswith ("resindex " ):
137141 return residue
142+ if q == "mass 2 to 999" :
143+ return uas
138144 return []
139145
146+ monkeypatch .setattr (ax , "get_UA_masses" , lambda mol : [10.0 , 12.0 ])
140147 u .select_atoms .side_effect = _select_atoms
148+ residue = u .select_atoms ("resindex 10" )
141149
142150 monkeypatch .setattr ("CodeEntropy.levels.axes.make_whole" , lambda _ag : None )
143- monkeypatch .setattr (
144- ax , "get_vanilla_axes" , lambda mol : (np .eye (3 ) * 2 , np .array ([9.0 , 8.0 , 7.0 ]))
145- )
151+ eigenvalues , eigenvectors = np .linalg .eig ([[48 , 0 , 48 ], [0 , 96 , 0 ], [48 , 0 , 48 ]])
152+ transposed = np .transpose (eigenvectors )
153+ axes = transposed [[2 , 0 , 1 ]]
154+ axes [2 ] = - axes [2 ]
146155
147- trans , rot , center , moi = ax .get_residue_axes (u , index = 10 )
156+ trans , rot , center , moi = ax .get_residue_axes (u , index = 10 , residue = residue )
148157
149- assert np .allclose (trans , np . eye ( 3 ) )
150- assert np .allclose (rot , np . eye ( 3 ) * 2 )
151- assert np .allclose (moi , np .array ([9 .0 , 8 .0 , 7 .0 ]))
158+ assert np .allclose (trans , axes )
159+ assert np .allclose (rot , axes )
160+ assert np .allclose (moi , np .array ([96 .0 , 96 .0 , 0 .0 ]))
152161
153162
154163def test_get_UA_axes_uses_principal_axes_when_single_heavy (monkeypatch ):
@@ -638,6 +647,13 @@ def center_of_mass(self, *args, **kwargs):
638647 def __getitem__ (self , idx ):
639648 return system_atom
640649
650+ def _select_atoms (q ):
651+ if q == "prop mass > 1.1" :
652+ return heavy_atoms
653+ if q .startswith ("index " ):
654+ return heavy_atom_selection
655+ return _FakeAtomGroup ([])
656+
641657 data_container = MagicMock ()
642658 data_container .atoms = _Atoms ()
643659 data_container .dimensions = np .array ([10.0 , 10.0 , 10.0 , 90 , 90 , 90 ], dtype = float )
0 commit comments