Skip to content

Commit 6b81354

Browse files
committed
new unit test
1 parent 12f0612 commit 6b81354

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

‎tests/unit/CodeEntropy/levels/nodes/test_covariance_node.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __init__(self, n_residues=1):
4242
self.atoms = FakeAtomGroup("mol-atoms")
4343
self.residues = [FakeResidue() for _ in range(n_residues)]
4444

45+
@property
46+
def select_atoms(self, query: str):
47+
return self._select_map.get(query, FakeMolecule([]))
48+
4549

4650
class FakeAtoms:
4751
"""Container supporting u.atoms.fragments and u.atoms[index_array]."""
@@ -708,3 +712,60 @@ def test_build_ft_block_rejects_invalid_inputs():
708712

709713
with pytest.raises(ValueError, match="length 3"):
710714
FrameCovarianceNode._build_ft_block([np.ones(2)], [np.ones(3)])
715+
716+
717+
def test_process_united_atom_multiple_residues():
718+
node = FrameCovarianceNode()
719+
mol = FakeMolecule(n_residues=3)
720+
bead_group = FakeAtomGroup("ua", length=3)
721+
universe = FakeUniverse([mol], returned_groups=[bead_group])
722+
mol.residues[0].resindex = 0
723+
mol.residues[1].resindex = 1
724+
mol.residues[2].resindex = 2
725+
726+
def _select_atoms(q):
727+
if q == "resindex 0 or resindex 1":
728+
return mol[0:2]
729+
if q == "resindex 1 or resindex 2":
730+
return mol[1:3]
731+
if q == "resindex 0 or resindex 1 or resindex 2":
732+
return mol
733+
734+
mol.select_atoms.side_effect = _select_atoms
735+
736+
node._build_ua_vectors = MagicMock(
737+
return_value=([np.array([1.0, 0.0, 0.0])], [np.array([0.0, 1.0, 0.0])])
738+
)
739+
node._ft.compute_frame_covariance = MagicMock(
740+
return_value=(np.eye(3), 2.0 * np.eye(3))
741+
)
742+
743+
out_force = {"ua": {}, "res": {}, "poly": {}}
744+
out_torque = {"ua": {}, "res": {}, "poly": {}}
745+
molcount = {}
746+
747+
node._process_united_atom(
748+
u=universe,
749+
mol=mol,
750+
mol_id=0,
751+
group_id=7,
752+
beads={
753+
(0, "united_atom", 0): [np.array([0])],
754+
(0, "united_atom", 1): [np.array([1])],
755+
(0, "united_atom", 2): [np.array([2])],
756+
},
757+
axes_manager="axes",
758+
axes_topology=None,
759+
box=None,
760+
force_partitioning=0.5,
761+
customised_axes=False,
762+
is_highest=True,
763+
out_force=out_force,
764+
out_torque=out_torque,
765+
molcount=molcount,
766+
)
767+
768+
np.testing.assert_allclose(out_force["ua"][(7, 0), (7, 1), (7, 2)], np.eye(3))
769+
np.testing.assert_allclose(
770+
out_torque["ua"][(7, 0), (7, 1), (7, 2)], 2.0 * np.eye(3)
771+
)

0 commit comments

Comments
 (0)