예제 #1
0
 def test_atomic_structure_repr_full(self):
     structure = AtomStructure(*self.atoms, name="N", id="T")
     AtomStructure.__name__ = "OBJ"
     try:
         self.assertEqual(repr(structure), "<OBJ N (T, 3 atoms)>")
     finally:
         AtomStructure.__name__ = "AtomStructure"
예제 #2
0
 def test_can_get_atoms_in_sphere(self):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     atoms = structure.atoms_in_sphere(1, 2, 3, 10)
     self.assertEqual(atoms, {self.atom1, self.atom2})
     self.atom1.distance_to.assert_called_with((1, 2, 3))
     self.atom2.distance_to.assert_called_with((1, 2, 3))
     self.atom3.distance_to.assert_called_with((1, 2, 3))
예제 #3
0
 def test_structure_is_container_of_other_structures(self):
     structure = AtomStructure(self.atom1, self.atom2)
     other = Mock()
     other._atoms = {self.atom2}
     self.assertIn(other, structure)
     other._atoms.add(self.atom3)
     self.assertNotIn(other, structure)
예제 #4
0
 def test_can_remove_structure(self):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     other = Mock(AtomStructure)
     other._atoms = {self.atom3}
     structure.remove(other)
     self.assertEqual(structure._id_atoms, {500: {self.atom1, self.atom2}})
     self.assertEqual(structure._atoms, {self.atom1, self.atom2})
예제 #5
0
 def test_can_update_structure_name(self):
     structure = AtomStructure(self.atom1,
                               self.atom2,
                               self.atom3,
                               name="VAL")
     structure.name = "HIS"
     self.assertEqual(structure._name, "HIS")
예제 #6
0
 def test_can_create_atom_structure_with_atoms(self):
     structure = AtomStructure(*self.atoms)
     self.assertEqual(structure._atoms, set(self.atoms))
     self.assertEqual(structure._id_atoms, {
         500: {self.atom1, self.atom2},
         700: {self.atom3}
     })
예제 #7
0
 def test_atomic_structure_repr(self):
     structure = AtomStructure(self.atoms[0])
     AtomStructure.__name__ = "OBJ"
     try:
         self.assertEqual(repr(structure), "<OBJ (1 atom)>")
     finally:
         AtomStructure.__name__ = "AtomStructure"
예제 #8
0
 def test_can_get_objects_by_name(self):
     objects = [Mock(_name="AAA"), Mock(_name="BBB"), Mock(_name="CCC")]
     self.atom1._aaa, self.atom2._aaa, self.atom3._aaa = objects
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     self.assertEqual(structure._get("aaa"), set(objects))
     self.assertEqual(structure._get("aaa", name="AAA"), {objects[0]})
     self.assertEqual(structure._get("aaa", name_regex="(AAA)|(BBB)"),
                      set(objects[:2]))
예제 #9
0
 def test_can_get_center_of_mass_when_unequal_mass(self, mock_mass):
     mock_mass.return_value = 40
     self.atom1.x, self.atom1.y, self.atom1.z = 0, 0, 0
     self.atom2.x, self.atom2.y, self.atom2.z = 1, 1, 1
     self.atom1.mass = 10
     self.atom2.mass = 30
     structure = AtomStructure(self.atom1, self.atom2)
     self.assertEqual(structure.center_of_mass, (0.75, 0.75, 0.75))
예제 #10
0
 def test_can_get_objects_by_water_status(self):
     objects = [Mock(_name="HOH"), Mock(_name="BBB"), Mock(_name="WAT")]
     self.atom1._ligand, self.atom2._ligand, self.atom3._ligand = objects
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     self.assertEqual(structure._get("ligand"), set(objects))
     self.assertEqual(structure._get("ligand", water=False), {objects[1]})
     self.atom1._aaa, self.atom2._aaa, self.atom3._aaa = objects
     self.assertEqual(structure._get("aaa", water=False), set(objects))
예제 #11
0
 def test_can_vary_grid_size(self):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     grid = list(structure.grid(size=0.5))
     self.assertEqual(grid, [
         (x, y, z) for x in [-1, -0.5, 0, 0.5, 1, 1.5]
         for y in [-2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5]
         for z in [-3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3]
     ])
예제 #12
0
 def test_can_get_objects(self):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     self.atom1._aaa = 10
     self.atom2._aaa = 11
     self.atom3._aaa = None
     self.assertEqual(structure._get("aaa"), {10, 11})
     self.atom3._aaa = 10
     self.assertEqual(structure._get("aaa"), {10, 11})
예제 #13
0
 def test_can_get_pairwise_atoms(self, mock_atoms):
     mock_atoms.return_value = set(self.atoms)
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     collected_atoms = []
     for pair in structure.pairwise_atoms(a=1, b=2):
         collected_atoms += list(pair)
     for atom in self.atoms:
         self.assertEqual(collected_atoms.count(atom), 2)
     mock_atoms.assert_called_with(a=1, b=2)
예제 #14
0
 def test_atom_structure_will_accept_atom_structures(self):
     structure = Mock(AtomStructure)
     structure._atoms = set(self.atoms[1:])
     structure2 = AtomStructure(self.atom1, structure)
     self.assertEqual(structure2._id_atoms, {
         500: {self.atom1, self.atom2},
         700: {self.atom3}
     })
     self.assertEqual(structure2._atoms, set(self.atoms))
예제 #15
0
 def setUp(self):
     AtomStructureTest.setUp(self)
     self.atoms = [Mock(Atom) for _ in range(10)]
     self.other_atoms = [Mock(Atom) for _ in range(10)]
     self.structure1 = AtomStructure(*self.atoms)
     self.structure2 = Mock(AtomStructure)
     self.structure2._atoms = set(self.other_atoms)
     for i, atom1, atom2 in zip(range(10), self.atoms, self.other_atoms):
         atom1.element = atom2.element = chr(i + 65)
         atom1.bonded_atoms = atom2.bonded_atoms = []
예제 #16
0
 def test_can_get_radius_of_gyration(self, mock_center):
     mock_center.return_value = (5, 0, 0)
     self.atom1.distance_to.return_value = 5
     self.atom2.distance_to.return_value = 5
     self.atom1.x, self.atom1.y, self.atom1.z = 0, 0, 0
     self.atom2.x, self.atom2.y, self.atom2.z = 10, 0, 0
     structure = AtomStructure(self.atom1, self.atom2)
     self.assertEqual(structure.radius_of_gyration, 5)
     self.atom1.distance_to.assert_called_with((5, 0, 0))
     self.atom2.distance_to.assert_called_with((5, 0, 0))
예제 #17
0
 def test_can_update_atom_awareness(self):
     self.atom1._model, self.atom2._model, self.atom3._model = 5, 5, 5
     try:
         structure = AtomStructure(self.atom1, self.atom2, self.atom3)
         structure.remove(self.atom2)
         AtomStructure.__name__ = "Model"
         structure.remove(self.atom1)
         self.assertIs(self.atom1._model, None)
     finally:
         AtomStructure.__name__ = "AtomStructure"
예제 #18
0
 def test_can_add_structure(self):
     structure = AtomStructure(self.atom1, self.atom2)
     other = Mock(AtomStructure)
     other._atoms = {self.atom3}
     structure.add(other)
     self.assertEqual(structure._id_atoms, {
         500: {self.atom1, self.atom2},
         700: {self.atom3}
     })
     self.assertEqual(structure._atoms, set(self.atoms))
예제 #19
0
 def test_atoms_are_updated(self):
     try:
         AtomStructure.__name__ = "AtomStructure"
         structure = AtomStructure(self.atom1)
         self.assertFalse(hasattr(self.atom1, "_atomstructure"))
         AtomStructure.__name__ = "Model"
         structure = AtomStructure(self.atom1)
         self.assertIs(self.atom1._model, structure)
         AtomStructure.__name__ = "Ligand"
         structure = AtomStructure(self.atom1)
         self.assertIs(self.atom1._ligand, structure)
         AtomStructure.__name__ = "Residue"
         structure = AtomStructure(self.atom1)
         self.assertIs(self.atom1._residue, structure)
         AtomStructure.__name__ = "Chain"
         structure = AtomStructure(self.atom1)
         self.assertIs(self.atom1._chain, structure)
     finally:
         AtomStructure.__name__ = "AtomStructure"
예제 #20
0
 def test_atom_can_get_atom_by_id(self, mock_atoms):
     mock_atoms.return_value = {self.atoms[1]}
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     atom = structure.atom(id=700)
     self.assertFalse(mock_atoms.called)
     self.assertIs(atom, self.atom3)
     atom = structure.atom(500)
     self.assertFalse(mock_atoms.called)
     self.assertIn(atom, (self.atom1, self.atom2))
     self.assertIsNone(structure.atom(id=100))
예제 #21
0
 def test_can_get_nearby_atoms(self):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     self.atom1.nearby_atoms.return_value = {1, 2, 3, self.atom2}
     self.atom2.nearby_atoms.return_value = {
         1, 3, 7, self.atom1, self.atom3
     }
     self.atom3.nearby_atoms.return_value = {1, 3, 7, 9, self.atom2}
     self.assertEqual(structure.nearby_atoms(2, a=4), {1, 2, 3, 7, 9})
     self.atom1.nearby_atoms.assert_called_with(2, a=4)
     self.atom2.nearby_atoms.assert_called_with(2, a=4)
     self.atom3.nearby_atoms.assert_called_with(2, a=4)
예제 #22
0
 def test_can_create_copy_of_atomic_structure(self):
     new_atoms = [Mock(Atom), Mock(Atom)]
     self.atom1.copy.return_value, self.atom2.copy.return_value = new_atoms
     new_atoms[0].id = 0
     new_atoms[1].id = 0
     structure = AtomStructure(self.atom1, self.atom2)
     structure._id, structure._name = 10, 20
     copy = structure.copy()
     self.assertEqual(copy._id_atoms, {0: set(new_atoms)})
     self.assertEqual(copy._atoms, set(new_atoms))
     self.assertEqual(copy._id, 10)
     self.assertEqual(copy._name, 20)
예제 #23
0
 def test_can_get_nearby_residues(self, mock_get):
     mock_get.side_effect = [{1, 2}, {3}]
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     self.atom1.nearby_residues.return_value = {1, 2, 3, 6}
     self.atom2.nearby_residues.return_value = {1, 3, 7}
     self.atom3.nearby_residues.return_value = {1, 3, 7, 9}
     self.assertEqual(structure.nearby_residues(2, a=4), {6, 7, 9})
     self.atom1.nearby_residues.assert_called_with(2, a=4)
     self.atom2.nearby_residues.assert_called_with(2, a=4)
     self.atom3.nearby_residues.assert_called_with(2, a=4)
     mock_get.assert_any_call("ligand")
     mock_get.assert_any_call("residue")
예제 #24
0
 def test_can_add_atom_to_structure(self):
     structure = AtomStructure(self.atom1)
     self.assertEqual(structure._id_atoms, {500: {self.atom1}})
     self.assertEqual(structure._atoms, {self.atom1})
     structure.add(self.atom2)
     self.assertEqual(structure._id_atoms, {500: {self.atom1, self.atom2}})
     self.assertEqual(structure._atoms, {self.atom1, self.atom2})
     structure.add(self.atom3)
     self.assertEqual(structure._id_atoms, {
         500: {self.atom1, self.atom2},
         700: {self.atom3}
     })
     self.assertEqual(structure._atoms, set(self.atoms))
예제 #25
0
 def test_can_superimpose(self, mock_tran, mock_cntr, mock_pair):
     m1, m2, m3 = Mock(), Mock(), Mock()
     mock_pair.return_value = {
         self.atom1: m1,
         self.atom2: m2,
         self.atom3: m3
     }
     other = Mock()
     other.center_of_mass = (10, 20, 30)
     mock_cntr.return_value = (1, 2, 3)
     self.atom1.location, m1.x, m1.y, m1.z = (0.1, 0.2, 0.3), 0.6, 0.7, 0.8
     self.atom2.location, m2.x, m2.y, m2.z = (0.2, 0.3, 0.4), 0.7, 0.8, 0.9
     self.atom3.location, m3.x, m3.y, m3.z = (0.3, 0.4, 0.5), 0.8, 0.9, 1
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     structure.superimpose_onto(other)
     mock_tran.assert_any_call(-1, -2, -3)
     mock_pair.assert_called_with(other)
     self.assertAlmostEqual(self.atom1.move_to.call_args_list[0][0][0],
                            -0.135,
                            delta=0.005)
     self.assertAlmostEqual(self.atom1.move_to.call_args_list[0][0][1],
                            -0.208,
                            delta=0.005)
     self.assertAlmostEqual(self.atom1.move_to.call_args_list[0][0][2],
                            -0.280,
                            delta=0.005)
     self.assertAlmostEqual(self.atom2.move_to.call_args_list[0][0][0],
                            -0.138,
                            delta=0.005)
     self.assertAlmostEqual(self.atom2.move_to.call_args_list[0][0][1],
                            -0.286,
                            delta=0.005)
     self.assertAlmostEqual(self.atom2.move_to.call_args_list[0][0][2],
                            -0.434,
                            delta=0.005)
     self.assertAlmostEqual(self.atom3.move_to.call_args_list[0][0][0],
                            -0.142,
                            delta=0.005)
     self.assertAlmostEqual(self.atom3.move_to.call_args_list[0][0][1],
                            -0.365,
                            delta=0.005)
     self.assertAlmostEqual(self.atom3.move_to.call_args_list[0][0][2],
                            -0.589,
                            delta=0.005)
     mock_tran.assert_any_call(10, 20, 30)
예제 #26
0
 def test_can_get_rmsd(self, mock_pair):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     other = Mock(AtomStructure)
     other_atoms = [Mock(), Mock(), Mock()]
     self.atom1.distance_to.return_value = 5
     self.atom2.distance_to.return_value = 1
     self.atom3.distance_to.return_value = -1
     mock_pair.return_value = {
         self.atom1: other_atoms[0],
         self.atom2: other_atoms[1],
         self.atom3: other_atoms[2]
     }
     rmsd = structure.rmsd_with(other)
     mock_pair.assert_called_with(other)
     self.atom1.distance_to.assert_called_with(other_atoms[0])
     self.atom2.distance_to.assert_called_with(other_atoms[1])
     self.atom3.distance_to.assert_called_with(other_atoms[2])
     self.assertEqual(rmsd, 3)
예제 #27
0
 def test_can_get_rmsd_after_superposition(self, mock_onto, mock_pair):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     other = Mock(AtomStructure)
     other_atoms = [Mock(), Mock(), Mock()]
     self.atom1.distance_to.return_value = 5
     self.atom2.distance_to.return_value = 1
     self.atom3.distance_to.return_value = -1
     self.atom1.location = (1, 2, 3)
     self.atom2.location = (4, 5, 6)
     self.atom3.location = (7, 8, 9)
     mock_pair.return_value = {
         self.atom1: other_atoms[0],
         self.atom2: other_atoms[1],
         self.atom3: other_atoms[2]
     }
     rmsd = structure.rmsd_with(other, superimpose=True)
     mock_onto.assert_called_with(other)
     self.atom1.move_to.assert_called_with(1, 2, 3)
     self.atom2.move_to.assert_called_with(4, 5, 6)
     self.atom3.move_to.assert_called_with(7, 8, 9)
예제 #28
0
 def test_can_remove_atom_from_structure(self):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     self.assertEqual(structure._id_atoms, {
         500: {self.atom1, self.atom2},
         700: {self.atom3}
     })
     self.assertEqual(structure._atoms, set(self.atoms))
     structure.remove(self.atom1)
     self.assertEqual(structure._id_atoms, {
         500: {self.atom2},
         700: {self.atom3}
     })
     self.assertEqual(structure._atoms, set(self.atoms[1:]))
     mock_atom = Mock(Atom)
     mock_atom.id = 300
     structure.remove(mock_atom)
     structure.remove(self.atom2)
     self.assertEqual(structure._id_atoms, {700: {self.atom3}})
     self.assertEqual(structure._atoms, {self.atom3})
     structure.remove(self.atom3)
     self.assertEqual(structure._id_atoms, {})
     self.assertEqual(structure._atoms, set())
예제 #29
0
 def test_atom_structure_is_container_of_its_atoms(self):
     structure = AtomStructure(self.atom1, self.atom2)
     self.assertIn(self.atom1, structure)
     self.assertIn(self.atom2, structure)
     self.assertNotIn(self.atom3, structure)
예제 #30
0
 def test_can_get_grid_with_margin(self):
     structure = AtomStructure(self.atom1, self.atom2, self.atom3)
     grid = list(structure.grid(margin=5))
     self.assertEqual(grid, [(x, y, z) for x in range(-6, 8)
                             for y in range(-8, 8) for z in range(-8, 9)])