Example #1
0
 def test_can_translate_atoms_with_iterable(self, mock_trim):
     atom = Atom("C", 20, 30, 50)
     atom.translate((5, -4, 12))
     self.assertEqual(atom._x, 25)
     self.assertEqual(atom._y, 26)
     self.assertEqual(atom._z, 62)
     mock_trim.assert_called_with(12)
Example #2
0
 def test_can_unbond_from_atom(self):
     atom = Atom("C")
     atom2 = Mock(_bonded_atoms={atom})
     atom._bonded_atoms = {atom2}
     atom.unbond_from(atom2)
     self.assertEqual(atom._bonded_atoms, set())
     self.assertEqual(atom2._bonded_atoms, set())
Example #3
0
 def test_can_transform_atoms(self, mock_trim):
     atom = Atom("C", 20, 30, 50)
     atom.transform([[1, 0, 0], [0, 0.7071, -0.7071], [0, 0.7071, 0.7071]],
                    trim=12)
     self.assertEqual(atom._x, 20)
     self.assertAlmostEqual(atom._y, -14.142, delta=3)
     self.assertAlmostEqual(atom._z, 56.569, delta=3)
     mock_trim.assert_called_with(12)
Example #4
0
 def test_atom_mass_case_insensitive(self):
     atom = Atom("he", 2, 3, 5)
     self.assertAlmostEqual(atom.mass, 4, delta=0.1)
     atom = Atom("He", 2, 3, 5)
     self.assertAlmostEqual(atom.mass, 4, delta=0.1)
     atom = Atom("hE", 2, 3, 5)
     self.assertAlmostEqual(atom.mass, 4, delta=0.1)
     atom = Atom("HE", 2, 3, 5)
     self.assertAlmostEqual(atom.mass, 4, delta=0.1)
Example #5
0
 def test_can_get_nearby_atoms(self, mock_loc):
     model = Mock()
     mock_loc.return_value = (1, 2, 3)
     atom = Atom("C", 4, 8, 3)
     atom._model = model
     model.atoms_in_sphere.return_value = [1, 2, atom, 4]
     atoms = atom.nearby_atoms(4, a=1, b=2)
     model.atoms_in_sphere.assert_called_with(1, 2, 3, 4, a=1, b=2)
     self.assertEqual(atoms, [1, 2, 4])
Example #6
0
 def test_can_round_atom_location(self):
     atom = Atom("C", 0.1111, 0.4444, 0.8888)
     atom.trim(3)
     self.assertEqual((atom._x, atom._y, atom._z), (0.111, 0.444, 0.889))
     atom.trim(2)
     self.assertEqual((atom._x, atom._y, atom._z), (0.11, 0.44, 0.89))
     atom.trim(1)
     self.assertEqual((atom._x, atom._y, atom._z), (0.1, 0.4, 0.9))
     atom.trim(0)
     self.assertEqual((atom._x, atom._y, atom._z), (0, 0, 1))
Example #7
0
 def test_can_make_atom_copy(self):
     atom = Atom("he", 2, 3, 5, 10, "H1", 0.5, 0.4, (1, 1, 1, 1, 1, 1))
     patcher = patch("atomium.models.atoms.Atom")
     mock_atom = patcher.start()
     try:
         copy = atom.copy()
         self.assertIs(copy, mock_atom.return_value)
         mock_atom.assert_called_with(element="he",
                                      x=2,
                                      y=3,
                                      z=5,
                                      id=10,
                                      name="H1",
                                      charge=0.5,
                                      bfactor=0.4,
                                      anisotropy=[1, 1, 1, 1, 1, 1])
     finally:
         patcher.stop()
Example #8
0
 def test_can_create_atom(self):
     atom = Atom("C")
     self.assertEqual(atom._element, "C")
     self.assertEqual((atom._x, atom._y, atom._z), (0, 0, 0))
     self.assertEqual(atom._id, 0)
     self.assertEqual(atom._name, None)
     self.assertEqual(atom._charge, 0)
     self.assertEqual(atom._bfactor, 0)
     self.assertEqual(atom._anisotropy, [0, 0, 0, 0, 0, 0])
     self.assertEqual(atom._bonded_atoms, set())
     self.assertEqual(atom._residue, None)
     self.assertEqual(atom._ligand, None)
     self.assertEqual(atom._chain, None)
     self.assertEqual(atom._model, None)
Example #9
0
 def test_can_rotate_atoms(self, mock_transform):
     atom = Atom("C", 20, 30, 50)
     atom.rotate(math.pi / 2, "x", 10, a=20)
     self.assertEqual(mock_transform.call_args_list[0][0][1], 10)
     self.assertEqual(mock_transform.call_args_list[0][1], {"a": 20})
     matrix_used = mock_transform.call_args_list[0][0][0]
     self.assertEqual([[round(val, 12) for val in row]
                       for row in matrix_used],
                      [[1, 0, 0], [0, 0, -1], [0, 1, 0]])
     atom.rotate(math.pi / 18, "y")
     matrix_used = mock_transform.call_args_list[1][0][0]
     self.assertEqual([[round(val, 3) for val in row]
                       for row in matrix_used],
                      [[0.985, 0, 0.174], [0, 1, 0], [-0.174, 0, 0.985]])
     atom.rotate(math.pi / -36, "z")
     matrix_used = mock_transform.call_args_list[2][0][0]
     self.assertEqual([[round(val, 3) for val in row]
                       for row in matrix_used],
                      [[0.996, 0.087, 0], [-0.087, 0.996, 0], [0, 0, 1]])
Example #10
0
 def test_atom_str(self):
     atom = Atom("C", 2, 3, 5, id=15, name="CA")
     self.assertEqual(str(atom), "<Atom 15 (CA)>")
Example #11
0
 def test_basic_atom_repr(self):
     atom = Atom("C")
     self.assertEqual(repr(atom), "<C Atom at (0, 0, 0)>")
Example #12
0
 def test_atom_repr(self):
     atom = Atom("C", 2, 3, 5, id=15, name="CA")
     self.assertEqual(repr(atom), "<C (CA) Atom 15 at (2, 3, 5)>")
Example #13
0
 def test_model_property(self):
     model = Mock()
     atom = Atom("C", 2, 3, 5)
     atom._model = model
     self.assertIs(atom.model, model)
Example #14
0
 def test_x_property(self):
     atom = Atom("C", 2, 3, 5)
     self.assertIs(atom._x, atom.x)
Example #15
0
 def test_y_property(self):
     atom = Atom("C", 2, 3, 5)
     self.assertIs(atom._y, atom.y)
Example #16
0
 def test_atom_with_no_model_has_no_nearby_atoms(self):
     atom = Atom("C", 4, 8, 3)
     self.assertEqual(atom.nearby_atoms(cutoff=1), set())
     self.assertEqual(atom.nearby_atoms(cutoff=100), set())
Example #17
0
 def test_can_handle_unbonding_from_unconnected_atom(self):
     atom = Atom("C")
     atom2 = Mock(_bonded_atoms=set())
     atom.unbond_from(atom2)
     self.assertEqual(atom._bonded_atoms, set())
     self.assertEqual(atom2._bonded_atoms, set())
Example #18
0
 def test_can_create_atom_with_bfactor(self):
     atom = Atom("C", bfactor=1.1)
     self.assertEqual(atom._bfactor, 1.1)
Example #19
0
 def test_can_create_atom_with_charge(self):
     atom = Atom("C", charge=-1)
     self.assertEqual(atom._charge, -1)
Example #20
0
 def test_can_bond_to_atom(self):
     atom = Atom("C")
     atom2 = Mock(_bonded_atoms=set())
     atom.bond_to(atom2)
     self.assertEqual(atom._bonded_atoms, {atom2})
     self.assertEqual(atom2._bonded_atoms, {atom})
Example #21
0
 def test_bonded_atoms_property(self):
     atom = Atom("C", 2, 3, 5)
     atom._bonded_atoms = [1, 2, 3]
     self.assertEqual(atom.bonded_atoms, {1, 2, 3})
Example #22
0
 def test_basic_atom_str(self):
     atom = Atom("C")
     self.assertEqual(str(atom), "<Atom (C)>")
Example #23
0
 def test_element_property(self):
     atom = Atom("C", 2, 3, 5)
     self.assertIs(atom._element, atom.element)
Example #24
0
 def test_can_get_nearby_residues(self, mock_atoms):
     mock_atoms.return_value = self.atoms
     atom = Atom("C", 4, 8, 3)
     self.assertEqual(atom.nearby_residues(3, a=1), set(self.residues))
     mock_atoms.assert_called_with(3, a=1)
Example #25
0
 def test_can_update_element(self):
     atom = Atom("C", 2, 3, 5)
     atom.element = "N"
     self.assertEqual(atom._element, "N")
Example #26
0
 def test_can_get_nearby_residues_and_ligands(self, mock_atoms):
     mock_atoms.return_value = self.atoms
     atom = Atom("C", 4, 8, 3)
     self.assertEqual(atom.nearby_residues(3, ligands=True, a=1),
                      set(self.residues + ["LIG"]))
     mock_atoms.assert_called_with(3, a=1)
Example #27
0
 def test_can_update_x(self):
     atom = Atom("C", 2, 3, 5)
     atom.x = 6
     self.assertEqual(atom._x, 6)
Example #28
0
 def test_chain_property(self):
     chain = Mock()
     atom = Atom("C", 2, 3, 5)
     atom._chain = chain
     self.assertIs(atom.chain, chain)
Example #29
0
 def test_can_update_y(self):
     atom = Atom("C", 2, 3, 5)
     atom.y = 6
     self.assertEqual(atom._y, 6)
Example #30
0
 def test_can_create_atom_with_anisotropy(self):
     atom = Atom("C", anisotropy=[2, 5, 3, 2, 5, 6])
     self.assertEqual(atom._anisotropy, [2, 5, 3, 2, 5, 6])