@@ -1363,6 +1363,7 @@ def _select_atoms(q):
13631363 u .atoms .principal_axes .return_value = np .eye (3 )
13641364 u .atoms .select_atoms .side_effect = _select_atoms
13651365 residue .select_atoms .side_effect = _select_atoms
1366+ residue .atoms .select_atoms .side_effect = _select_atoms
13661367
13671368 monkeypatch .setattr (
13681369 ax ,
@@ -1624,16 +1625,19 @@ def test_get_UA_axes_raises_when_only_rot_axes_fail(monkeypatch):
16241625 u .dimensions = np .array ([10.0 , 10.0 , 10.0 , 90 , 90 , 90 ])
16251626 residue = MagicMock ()
16261627 u .residues = [residue ]
1627- heavy_atoms = [
1628- _atom (index = 0 , mass = 12.0 , pos = (1 , 0 , 0 )),
1629- _atom (index = 1 , mass = 12.0 , pos = (0 , 1 , 0 )),
1630- ]
1628+ heavy_atoms = _FakeAtomGroup (
1629+ [
1630+ _atom (index = 0 , mass = 12.0 , pos = (1 , 0 , 0 )),
1631+ _atom (index = 1 , mass = 12.0 , pos = (0 , 1 , 0 )),
1632+ ],
1633+ )
16311634
16321635 def _sel (q ):
16331636 if q == "mass 2 to 999" :
1634- return heavy_atoms
1637+ return [ heavy_atoms ]
16351638
16361639 u .select_atoms .side_effect = _sel
1640+ residue .atoms .select_atoms .side_effect = _sel
16371641 monkeypatch .setattr ("CodeEntropy.levels.axes.make_whole" , lambda _ag : None )
16381642 monkeypatch .setattr (ax , "get_bonded_axes" , lambda ** kwargs : (None , None ))
16391643
@@ -1779,7 +1783,7 @@ def test_get_residue_axes_terminal_2_atoms(monkeypatch):
17791783 u .dimensions = np .array ([10.0 , 10.0 , 10.0 , 90 , 90 , 90 ])
17801784 monkeypatch .setattr ("CodeEntropy.levels.axes.make_whole" , lambda _ag : None )
17811785 residue = u .select_atoms ("resindex 0" )
1782- residue .__len__ .return_value = 3
1786+ residue .__len__ .return_value = 2
17831787 uas = _FakeAtomGroup (
17841788 [
17851789 _atom (index = 0 , mass = 12.0 , pos = (1 , 0 , 0 )),
@@ -1800,6 +1804,7 @@ def _select_atoms(q):
18001804
18011805 u .atoms .select_atoms .side_effect = _select_atoms
18021806 residue .select_atoms .side_effect = _select_atoms
1807+ residue .atoms .select_atoms .side_effect = _select_atoms
18031808 monkeypatch .setattr (ax , "get_custom_axes" , lambda a , b , c : 2 * np .eye (3 ))
18041809 monkeypatch .setattr (
18051810 ax ,
@@ -1817,3 +1822,221 @@ def _select_atoms(q):
18171822 assert np .allclose (rot_axes , 2 * np .eye (3 ))
18181823 assert np .allclose (rot_center , [0 , 0 , 1 ])
18191824 assert np .allclose (moi , [1 , 1 , 1 ])
1825+
1826+
1827+ def test_get_res_axes_terminal_1_atom (monkeypatch ):
1828+ ax = AxesCalculator ()
1829+ u = MagicMock ()
1830+ u .dimensions = np .array ([10.0 , 10.0 , 10.0 , 90 , 90 , 90 ])
1831+ monkeypatch .setattr ("CodeEntropy.levels.axes.make_whole" , lambda _ag : None )
1832+ residue = u .select_atoms ("resindex 0" )
1833+ residue .__len__ .return_value = 1
1834+ uas = _FakeAtomGroup (
1835+ [
1836+ _atom (index = 0 , mass = 12.0 , pos = (1 , 0 , 0 )),
1837+ ],
1838+ )
1839+ u .atoms .principal_axes .return_value = np .eye (3 )
1840+ residue .atoms .principal_axes .return_value = np .eye (3 )
1841+
1842+ def _select_atoms (q ):
1843+ if q == "mass 2 to 999" :
1844+ return uas
1845+ if q .startswith ("(mass 2 to 999) and bonded index " ):
1846+ return []
1847+ if q .startswith ("resindex " ):
1848+ return [uas [0 ]]
1849+
1850+ u .atoms .select_atoms .side_effect = _select_atoms
1851+ residue .select_atoms .side_effect = _select_atoms
1852+ residue .atoms .select_atoms .side_effect = _select_atoms
1853+
1854+ monkeypatch .setattr (
1855+ ax ,
1856+ "get_custom_residue_moment_of_inertia" ,
1857+ lambda center_of_mass , positions , masses , custom_rot_axes , dimensions : np .array (
1858+ [1 , 1 , 1 ]
1859+ ),
1860+ )
1861+ trans_axes , rot_axes , rot_center , moi = ax .get_residue_axes (
1862+ data_container = u ,
1863+ index = 0 ,
1864+ relative_index = 0 ,
1865+ )
1866+ assert np .allclose (trans_axes , np .eye (3 ))
1867+ assert np .allclose (rot_axes , np .eye (3 ))
1868+ assert np .allclose (rot_center , [1 , 0 , 0 ])
1869+ assert np .allclose (moi , [1 , 1 , 1 ])
1870+
1871+
1872+ def test_get_UA_axes_terminal_1_atom (monkeypatch ):
1873+ ax = AxesCalculator ()
1874+ residue_group = MagicMock ()
1875+ residue_group .__len__ = 2
1876+ residue = residue_group .residues [1 ]
1877+ heavy_atoms = _FakeAtomGroup (
1878+ [
1879+ _atom (index = 0 , mass = 12.0 , pos = (1 , 1 , 1 )),
1880+ _atom (index = 1 , mass = 12.0 , pos = (3 , 3 , 3 )),
1881+ ],
1882+ )
1883+
1884+ def _select_atoms_data_container (q ):
1885+ if q == "mass 2 to 999" :
1886+ # return heavy atoms group
1887+ return heavy_atoms
1888+ if q .startswith ("resindex " ):
1889+ return [heavy_atoms [0 ]]
1890+
1891+ def _select_atoms_residue (q ):
1892+ if q == "mass 2 to 999" :
1893+ # return heavy atoms group
1894+ return [heavy_atoms [0 ]]
1895+ if q .startswith ("index" ):
1896+ return [heavy_atoms [0 ]]
1897+ if q .startswith ("(mass 2 to 999) and bonded " ):
1898+ return []
1899+
1900+ residue_group .select_atoms .side_effect = _select_atoms_data_container
1901+ residue_group .atoms .select_atoms .side_effect = _select_atoms_data_container
1902+ residue .select_atoms .side_effect = _select_atoms_residue
1903+ residue .atoms .select_atoms .side_effect = _select_atoms_residue
1904+ monkeypatch .setattr (
1905+ ax ,
1906+ "get_bonded_axes" ,
1907+ lambda system , atom , dimensions : (np .eye (3 ), 3 * np .eye (3 )),
1908+ )
1909+ residue .atoms .principal_axes .return_value = 2 * np .eye (3 )
1910+
1911+ trans_axes , rot_axes , rot_center , moi = ax .get_UA_axes (
1912+ data_container = residue_group , index = 0 , res_position = - 1
1913+ )
1914+
1915+ assert np .allclose (trans_axes , 2 * np .eye (3 ))
1916+ assert np .allclose (rot_axes , np .eye (3 ))
1917+ assert np .allclose (rot_center , [1 , 1 , 1 ])
1918+ assert np .allclose (moi , 3 * np .eye (3 ))
1919+
1920+
1921+ def test_get_terminal_axes_1point (monkeypatch ):
1922+ ax = AxesCalculator ()
1923+ residue = MagicMock ()
1924+ residue .__len__ = 1
1925+ heavy_atoms = _FakeAtomGroup (
1926+ [
1927+ _atom (index = 0 , mass = 12.0 , pos = (1 , 0 , 0 )),
1928+ ],
1929+ )
1930+
1931+ def _select_atoms (q ):
1932+ if q == "mass 2 to 999" :
1933+ return heavy_atoms
1934+ if q .startswith ("(mass 2 to 999) and bonded" ):
1935+ return []
1936+
1937+ residue .atoms .select_atoms .side_effect = _select_atoms
1938+ residue .atoms .principal_axes .return_value = np .eye (3 )
1939+ centre , axes = ax .get_terminal_axes (residue , heavy_atoms [0 ])
1940+ assert np .allclose (centre , [1 , 0 , 0 ])
1941+ assert np .allclose (axes , np .eye (3 ))
1942+
1943+
1944+ def test_get_terminal_axes_2points (monkeypatch ):
1945+ ax = AxesCalculator ()
1946+ residue = MagicMock ()
1947+ residue .__len__ = 2
1948+ heavy_atoms = _FakeAtomGroup (
1949+ [
1950+ _atom (index = 0 , mass = 12.0 , pos = (1 , 0 , 0 )),
1951+ _atom (index = 1 , mass = 12.0 , pos = (0 , 1 , 0 )),
1952+ ],
1953+ )
1954+
1955+ def _select_atoms (q ):
1956+ if q == "mass 2 to 999" :
1957+ return heavy_atoms
1958+ if q .startswith ("(mass 2 to 999) and bonded" ):
1959+ return [heavy_atoms [1 ]]
1960+
1961+ residue .atoms .select_atoms .side_effect = _select_atoms
1962+ monkeypatch .setattr (ax , "get_custom_axes" , lambda a , b , c : 2 * np .eye (3 ))
1963+ centre , axes = ax .get_terminal_axes (residue , heavy_atoms [0 ])
1964+ assert np .allclose (centre , [1 , 0 , 0 ])
1965+ assert np .allclose (axes , 2 * np .eye (3 ))
1966+
1967+
1968+ def test_get_terminal_axes_3points (monkeypatch ):
1969+ ax = AxesCalculator ()
1970+ residue = MagicMock ()
1971+ residue .__len__ = 4
1972+ heavy_atoms = _FakeAtomGroup (
1973+ [
1974+ _atom (index = 0 , mass = 12.0 , pos = (0 , 0 , 0 )),
1975+ _atom (index = 1 , mass = 12.0 , pos = (1 , 1 , 0 )),
1976+ _atom (index = 2 , mass = 12.0 , pos = (1 , 0 , 0 )),
1977+ _atom (index = 3 , mass = 14.0 , pos = (3 , 0 , 0 )),
1978+ ],
1979+ )
1980+
1981+ def _select_atoms (q ):
1982+ if q == "mass 2 to 999" :
1983+ return heavy_atoms
1984+ if q .startswith ("(mass 2 to 999) and bonded" ):
1985+ return [heavy_atoms [1 ]]
1986+
1987+ residue .atoms .select_atoms .side_effect = _select_atoms
1988+ monkeypatch .setattr (
1989+ ax , "get_residue_custom_axes" , lambda edges , center : ([1 , 0 , 0 ], 3 * np .eye (3 ))
1990+ )
1991+
1992+ centre , axes = ax .get_terminal_axes (residue , heavy_atoms [0 ])
1993+
1994+ assert np .allclose (centre , [1 , 0 , 0 ])
1995+ assert np .allclose (axes , 3 * np .eye (3 ))
1996+
1997+
1998+ def test_get_non_terminal_axes_2points (monkeypatch ):
1999+ ax = AxesCalculator ()
2000+ residue = MagicMock ()
2001+ residue .__len__ = 2
2002+ heavy_atoms = _FakeAtomGroup (
2003+ [
2004+ _atom (index = 0 , mass = 12.0 , pos = (2 , 0 , 0 )),
2005+ _atom (index = 1 , mass = 12.0 , pos = (0 , 2 , 0 )),
2006+ ],
2007+ )
2008+ monkeypatch .setattr (ax , "get_chain" , lambda residue , first , last : [])
2009+ monkeypatch .setattr (ax , "get_custom_axes" , lambda a , b , c : 2 * np .eye (3 ))
2010+ centre , axes = ax .get_non_terminal_axes (residue , heavy_atoms )
2011+ assert np .allclose (centre , [1 , 1 , 0 ])
2012+ assert np .allclose (axes , 2 * np .eye (3 ))
2013+
2014+
2015+ def test_get_non_terminal_axes_3points (monkeypatch ):
2016+ ax = AxesCalculator ()
2017+ residue = MagicMock ()
2018+ residue .__len__ = 4
2019+ heavy_atoms = _FakeAtomGroup (
2020+ [
2021+ _atom (index = 0 , mass = 12.0 , pos = (0 , 0 , 0 )),
2022+ _atom (index = 1 , mass = 12.0 , pos = (1 , 0 , 0 )),
2023+ _atom (index = 2 , mass = 14.0 , pos = (3 , 0 , 0 )),
2024+ _atom (index = 3 , mass = 12.0 , pos = (1 , 1 , 0 )),
2025+ ],
2026+ )
2027+ edges = _FakeAtomGroup (
2028+ [
2029+ _atom (index = 0 , mass = 12.0 , pos = (0 , 0 , 0 )),
2030+ _atom (index = 3 , mass = 12.0 , pos = (1 , 1 , 0 )),
2031+ ],
2032+ )
2033+ monkeypatch .setattr (
2034+ ax , "get_chain" , lambda residue , first , last : [heavy_atoms [1 ], heavy_atoms [2 ]]
2035+ )
2036+ monkeypatch .setattr (
2037+ ax , "get_residue_custom_axes" , lambda edges , center : ([1 , 0 , 0 ], 3 * np .eye (3 ))
2038+ )
2039+ centre , axes = ax .get_non_terminal_axes (residue , edges )
2040+
2041+ assert np .allclose (centre , [1 , 0 , 0 ])
2042+ assert np .allclose (axes , 3 * np .eye (3 ))
0 commit comments