@@ -83,7 +83,6 @@ def test_get_residue_axes_bonded_default_axes_branch(self):
8383 atom_set .__len__ .return_value = 2
8484
8585 residue = MagicMock ()
86-
8786 data_container .select_atoms .side_effect = [atom_set , residue ]
8887
8988 trans_axes_expected = np .eye (3 ) * 2
@@ -96,42 +95,28 @@ def test_get_residue_axes_bonded_default_axes_branch(self):
9695 residue .moment_of_inertia .return_value = moi_tensor
9796
9897 center_expected = np .array ([9.0 , 8.0 , 7.0 ])
98+ residue .atoms .center_of_mass .return_value = center_expected
9999 residue .center_of_mass .return_value = center_expected
100100
101- with patch ("CodeEntropy.axes.np.linalg.eig" ) as eig_mock :
102- eig_mock .return_value = (np .array ([1.0 , 3.0 , 2.0 ]), None )
103-
101+ with (
102+ patch ("CodeEntropy.axes.make_whole" , autospec = True ),
103+ patch .object (
104+ AxesManager ,
105+ "get_vanilla_axes" ,
106+ return_value = (rot_axes_expected , np .array ([3.0 , 2.0 , 1.0 ])),
107+ ),
108+ ):
104109 trans_axes_out , rot_axes_out , center_out , moi_out = (
105110 axes_manager .get_residue_axes (
106111 data_container = data_container ,
107112 index = 5 ,
108113 )
109114 )
110115
111- calls = data_container .select_atoms .call_args_list
112- assert len (calls ) == 2
113- assert calls [0 ].args [0 ] == "(resindex 4 or resindex 6) and bonded resid 5"
114- assert calls [1 ].args [0 ] == "resindex 5"
115-
116- data_container .atoms .principal_axes .assert_called_once ()
117- residue .principal_axes .assert_called_once ()
118- residue .moment_of_inertia .assert_called_once ()
119- residue .center_of_mass .assert_called_once ()
120-
121- eig_mock .assert_called_once ()
122- eig_args , eig_kwargs = eig_mock .call_args
123- np .testing .assert_array_equal (eig_args [0 ], moi_tensor )
124- assert eig_kwargs == {}
125-
126- assert (
127- not hasattr (axes_manager .get_UA_masses , "call_count" )
128- or getattr (axes_manager .get_UA_masses , "call_count" , 0 ) == 0
129- )
130-
131- np .testing .assert_array_equal (trans_axes_out , trans_axes_expected )
132- np .testing .assert_array_equal (rot_axes_out , np .real (rot_axes_expected ))
133- np .testing .assert_array_equal (center_out , center_expected )
134- assert moi_out == [3.0 , 2.0 , 1.0 ]
116+ np .testing .assert_allclose (trans_axes_out , trans_axes_expected )
117+ np .testing .assert_allclose (rot_axes_out , rot_axes_expected )
118+ np .testing .assert_allclose (center_out , center_expected )
119+ np .testing .assert_allclose (moi_out , np .array ([3.0 , 2.0 , 1.0 ]))
135120
136121 def test_get_UA_axes_returns_expected_outputs (self ):
137122 """
@@ -392,9 +377,7 @@ def test_get_custom_axes_uses_bc_vector_when_multiple_heavy_atoms(self):
392377
393378 axes .get_custom_axes (a , b_list , c , dimensions )
394379
395- # get_vector should be called:
396- # - twice for axis1 (a → b0, a → b1)
397- # - once for ac_vector using (c → b_list[0])
380+ # get_vector should be called
398381 calls = axes .get_vector .call_args_list
399382
400383 # Last call must be (c, b_list[0], dimensions)
@@ -415,7 +398,9 @@ def test_get_custom_moment_of_inertia_len2_zeroed(self):
415398 UA .masses = np .array ([12.0 , 1.0 ])
416399 UA .__len__ .return_value = 2
417400
418- moi = axes .get_custom_moment_of_inertia (UA , np .eye (3 ), np .zeros (3 ))
401+ dimensions = np .array ([100.0 , 100.0 , 100.0 ])
402+
403+ moi = axes .get_custom_moment_of_inertia (UA , np .eye (3 ), np .zeros (3 ), dimensions )
419404
420405 assert moi .shape == (3 ,)
421406 assert np .any (np .isclose (moi , 0.0 ))
@@ -449,8 +434,9 @@ def test_get_moment_of_inertia_tensor_simple(self):
449434 center = np .zeros (3 )
450435 pos = np .array ([[1 , 0 , 0 ], [0 , 1 , 0 ]])
451436 masses = np .array ([1.0 , 1.0 ])
437+ dimensions = np .array ([100.0 , 100.0 , 100.0 ])
452438
453- tensor = axes .get_moment_of_inertia_tensor (center , pos , masses )
439+ tensor = axes .get_moment_of_inertia_tensor (center , pos , masses , dimensions )
454440
455441 expected = np .array ([[1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 2 ]])
456442 np .testing .assert_array_equal (tensor , expected )
0 commit comments