示例#1
0
 def test_can_get_atoms_in_sphere(self):
     structure = AtomicStructure(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))
示例#2
0
 def test_can_trim_structure(self, mock_atoms):
     mock_atoms.return_value = set(self.atoms)
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     structure.trim(108)
     mock_atoms.assert_called_with()
     self.atom1.trim.assert_called_with(108)
     self.atom2.trim.assert_called_with(108)
     self.atom3.trim.assert_called_with(108)
示例#3
0
 def test_structure_rotation_in_degrees(self, mock_trim, mock_matrix):
     matrix = Mock()
     mock_matrix.return_value = matrix
     matrix.dot.side_effect = ([10, 20, 30], [40, 50, 60], [70, 80, 90])
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     structure._atoms = self.atoms
     structure.rotate(0.1, "z", degrees=True)
     mock_matrix.assert_called_with(None, math.radians(0.1), "z")
示例#4
0
 def test_can_vary_grid_size(self):
     structure = AtomicStructure(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]
     ])
示例#5
0
 def setUp(self):
     AtomicStructureTest.setUp(self)
     self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     self.mol1, self.mol2, self.mol3 = Mock(), Mock(Residue), Mock(Chain)
     self.atom1.molecule, self.atom2.molecule, self.atom3.molecule = (
         self.mol1, self.mol2, self.mol3)
     self.mol1.id, self.mol2.id, self.mol3.id = "A1", "A2", "A3"
     self.mol1.name, self.mol2.name, self.mol3.name = "VAL", "TYR", "TYR"
示例#6
0
 def setUp(self):
     AtomicStructureTest.setUp(self)
     self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     self.res1, self.res2, self.res3 = Mock(), Mock(), Mock()
     self.atom1.residue, self.atom2.residue, self.atom3.residue = (
         self.res1, self.res2, self.res3)
     self.res1.id, self.res2.id, self.res3.id = "A1", "A2", "A3"
     self.res1.name, self.res2.name, self.res3.name = "VAL", "TYR", "TYR"
示例#7
0
 def setUp(self):
     AtomicStructureTest.setUp(self)
     self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     self.complex1, self.complex2, self.complex3 = Mock(), Mock(), Mock()
     self.atom1.complex, self.atom2.complex, self.atom3.complex = (
         self.complex1, self.complex2, self.complex3)
     self.complex1.id, self.complex2.id, self.complex3.id = "1", "2", "3"
     self.complex1.name, self.complex2.name, self.complex3.name = "AA", "CC", "CC"
示例#8
0
 def test_structure_rotation_varied_trim(self, mock_trim, mock_matrix):
     matrix = Mock()
     mock_matrix.return_value = matrix
     matrix.dot.side_effect = ([10, 20, 30], [40, 50, 60], [70, 80, 90])
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     structure._atoms = self.atoms
     structure.rotate(0.1, "z", trim=9)
     mock_trim.assert_called_with(9)
示例#9
0
 def setUp(self):
     AtomicStructureTest.setUp(self)
     self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     self.chain1, self.chain2, self.chain3 = Mock(), Mock(), Mock()
     self.atom1.chain, self.atom2.chain, self.atom3.chain = (self.chain1,
                                                             self.chain2,
                                                             self.chain3)
     self.chain1.id, self.chain2.id, self.chain3.id = "A1", "A2", "A3"
     self.chain1.name, self.chain2.name, self.chain3.name = "VAL", "TYR", "TYR"
示例#10
0
 def test_can_get_pairwise_atoms(self, mock_atoms):
     mock_atoms.return_value = set(self.atoms)
     structure = AtomicStructure(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)
示例#11
0
 def test_can_save_as_xyz_string_with_description(self, mock_string,
                                                  mock_dict):
     structure = AtomicStructure(*self.atoms)
     xyz_dict = {}
     mock_string.return_value = "filecontents"
     mock_dict.return_value = xyz_dict
     s = structure.to_file_string("xyz", description="DDD")
     mock_dict.assert_called_with(structure)
     mock_string.assert_called_with({"title": "DDD"})
     self.assertEqual(s, "filecontents")
示例#12
0
 def test_atom_can_get_atom_by_id(self, mock_atoms):
     mock_atoms.return_value = {self.atoms[1]}
     structure = AtomicStructure(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))
示例#13
0
 def setUp(self):
     AtomicStructureTest.setUp(self)
     self.atoms = [Mock(Atom) for _ in range(10)]
     self.other_atoms = [Mock(Atom) for _ in range(10)]
     self.structure1 = AtomicStructure(*self.atoms)
     self.structure2 = Mock(AtomicStructure)
     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.bonds = atom2.bonds = []
示例#14
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 = AtomicStructure(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)
示例#15
0
 def test_structure_rotation(self, mock_trim, mock_matrix):
     matrix = Mock()
     mock_matrix.return_value = matrix
     matrix.dot.side_effect = ([10, 20, 30], [40, 50, 60], [70, 80, 90])
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     structure._atoms = self.atoms
     structure.rotate(0.1, "z")
     mock_matrix.assert_called_with(None, 0.1, "z")
     for i, atom in enumerate(self.atoms):
         for j, coord in enumerate((atom._x, atom._y, atom._z)):
             self.assertEqual(coord, 10 + (30 * i) + (10 * j))
     mock_trim.assert_called_with(12)
示例#16
0
 def test_coordinates_must_be_numbers(self):
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     with self.assertRaises(TypeError):
         structure.atoms_in_sphere("0", 0, 0, 10)
     with self.assertRaises(TypeError):
         structure.atoms_in_sphere(0, "0", 0, 10)
     with self.assertRaises(TypeError):
         structure.atoms_in_sphere(0, 0, "0", 10)
示例#17
0
 def test_can_create_atomic_structure_with_id_atoms(self):
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     self.assertEqual(structure._atoms, set(self.atoms))
     self.assertEqual(structure._id_atoms, {
         500: {self.atom1, self.atom2},
         700: {self.atom3}
     })
示例#18
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 = AtomicStructure(self.atom1, self.atom2)
     self.assertEqual(structure.center_of_mass, (0.75, 0.75, 0.75))
示例#19
0
def create_site_template(site):
    if not isinstance(site, Site):
        raise TypeError("{} is not a binding site object".format(site))
    atoms = []
    for residue in site.residues():
        atoms.append(residue.atom(name="CA"))
        atoms.append(residue.atom(name="CB"))
    return AtomicStructure(*atoms)
示例#20
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 = AtomicStructure(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)
示例#21
0
class StructureComplexesTests(AtomicStructureTest):
    def setUp(self):
        AtomicStructureTest.setUp(self)
        self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
        self.complex1, self.complex2, self.complex3 = Mock(), Mock(), Mock()
        self.atom1.complex, self.atom2.complex, self.atom3.complex = (
            self.complex1, self.complex2, self.complex3)
        self.complex1.id, self.complex2.id, self.complex3.id = "1", "2", "3"
        self.complex1.name, self.complex2.name, self.complex3.name = "AA", "CC", "CC"

    def test_can_get_complexes(self):
        self.assertEqual(self.structure.complexes(),
                         set([self.complex1, self.complex2, self.complex3]))

    def test_can_filter_none_from_complexes(self):
        self.atom3.complex = None
        self.assertEqual(self.structure.complexes(),
                         {self.complex1, self.complex2})

    def test_can_get_complexes_by_id(self):
        self.assertEqual(self.structure.complexes(id="1"), {self.complex1})
        self.assertEqual(self.structure.complexes(id="2"), {self.complex2})
        self.assertEqual(self.structure.complexes(id="4"), set())

    def test_can_get_complexes_by_name(self):
        self.assertEqual(self.structure.complexes(name="AA"),
                         set([self.complex1]))
        self.assertEqual(self.structure.complexes(name="CC"),
                         set([self.complex2, self.complex3]))
        self.assertEqual(self.structure.complexes(name="DD"), set())
示例#22
0
 def test_atomic_structure_will_accept_atomic_structures(self):
     structure = Mock(AtomicStructure)
     structure._atoms = set(self.atoms[1:])
     structure2 = AtomicStructure(self.atom1, structure)
     self.assertEqual(structure2._id_atoms, {
         500: {self.atom1, self.atom2},
         700: {self.atom3}
     })
     self.assertEqual(structure2._atoms, set(self.atoms))
示例#23
0
 def test_can_get_rmsd(self, mock_pair):
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     other = Mock(AtomicStructure)
     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)
示例#24
0
class StructureComplexTest(AtomicStructureTest):
    def setUp(self):
        AtomicStructureTest.setUp(self)
        self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
        self.complex1, self.complex2, self.complex3 = Mock(), Mock(), Mock()
        self.complex1.id, self.complex2.id, self.complex3.id = "1", "2", "3"
        self.complex1.name, self.complex2.name, self.complex3.name = "AA", "BB", "CC"

    @patch("atomium.structures.molecules.AtomicStructure.complexes")
    def test_complex_calls_complexes(self, mock_complexes):
        mock_complexes.return_value = set([self.complex3])
        complex = self.structure.complex(name="1")
        mock_complexes.assert_called_with(name="1")
        self.assertIs(complex, self.complex3)

    @patch("atomium.structures.molecules.AtomicStructure.complexes")
    def test_complex_can_return_none(self, mock_complexes):
        mock_complexes.return_value = set()
        self.assertIs(self.structure.complex(name="AA"), None)
示例#25
0
class StructureMoleculeTest(AtomicStructureTest):
    def setUp(self):
        AtomicStructureTest.setUp(self)
        self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
        self.res1, self.res2, self.res3 = Mock(), Mock(), Mock()
        self.res1.id, self.res2.id, self.res3.id = "A1", "A2", "A3"
        self.res1.name, self.res2.name, self.res3.name = "VAL", "TYR", "TYR"

    @patch("atomium.structures.molecules.AtomicStructure.molecules")
    def test_molecule_calls_molecules(self, mock_molecules):
        mock_molecules.return_value = set([self.res3])
        molecule = self.structure.molecule(name="A")
        mock_molecules.assert_called_with(name="A")
        self.assertIs(molecule, self.res3)

    @patch("atomium.structures.molecules.AtomicStructure.molecules")
    def test_molecule_can_return_none(self, mock_molecules):
        mock_molecules.return_value = set()
        self.assertIs(self.structure.molecule(name="C"), None)
示例#26
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 = AtomicStructure(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))
示例#27
0
class StructureChainTest(AtomicStructureTest):
    def setUp(self):
        AtomicStructureTest.setUp(self)
        self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
        self.chain1, self.chain2, self.chain3 = Mock(), Mock(), Mock()
        self.chain1.id, self.chain2.id, self.chain3.id = "A1", "A2", "A3"
        self.chain1.name, self.chain2.name, self.chain3.name = "VAL", "TYR", "TYR"

    @patch("atomium.structures.molecules.AtomicStructure.chains")
    def test_chain_calls_chains(self, mock_chains):
        mock_chains.return_value = set([self.chain3])
        chain = self.structure.chain(name="A")
        mock_chains.assert_called_with(name="A")
        self.assertIs(chain, self.chain3)

    @patch("atomium.structures.molecules.AtomicStructure.chains")
    def test_chain_can_return_none(self, mock_chains):
        mock_chains.return_value = set()
        self.assertIs(self.structure.chain(name="C"), None)
示例#28
0
 def test_can_get_rmsd_after_superposition(self, mock_onto, mock_pair):
     structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
     other = Mock(AtomicStructure)
     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)
示例#29
0
class StructureMoleculesTests(AtomicStructureTest):
    def setUp(self):
        AtomicStructureTest.setUp(self)
        self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
        self.mol1, self.mol2, self.mol3 = Mock(), Mock(Residue), Mock(Chain)
        self.atom1.molecule, self.atom2.molecule, self.atom3.molecule = (
            self.mol1, self.mol2, self.mol3)
        self.mol1.id, self.mol2.id, self.mol3.id = "A1", "A2", "A3"
        self.mol1.name, self.mol2.name, self.mol3.name = "VAL", "TYR", "TYR"

    def test_can_get_molecules(self):
        self.assertEqual(self.structure.molecules(),
                         set([self.mol1, self.mol2, self.mol3]))

    def test_can_filter_none_from_molecules(self):
        self.atom3.molecule = None
        self.assertEqual(self.structure.molecules(), {self.mol1, self.mol2})

    def test_can_get_molecules_by_id(self):
        self.assertEqual(self.structure.molecules(id="A1"), {self.mol1})
        self.assertEqual(self.structure.molecules(id="A2"), {self.mol2})
        self.assertEqual(self.structure.molecules(id="A5"), set())

    def test_can_get_molecules_by_name(self):
        self.assertEqual(self.structure.molecules(name="VAL"),
                         set([self.mol1]))
        self.assertEqual(self.structure.molecules(name="TYR"),
                         set([self.mol2, self.mol3]))
        self.assertEqual(self.structure.molecules(name="GLY"), set())

    def test_can_filter_out_specific_molecule_types(self):
        self.assertEqual(self.structure.molecules(generic=True),
                         set([self.mol1]))

    def test_can_filter_out_water(self):
        self.mol2.name = "WAT"
        self.assertEqual(self.structure.molecules(water=False),
                         {self.mol1, self.mol3})
        self.mol2.name = "HOH"
        self.assertEqual(self.structure.molecules(water=False),
                         {self.mol1, self.mol3})
示例#30
0
class StructureChainsTests(AtomicStructureTest):
    def setUp(self):
        AtomicStructureTest.setUp(self)
        self.structure = AtomicStructure(self.atom1, self.atom2, self.atom3)
        self.chain1, self.chain2, self.chain3 = Mock(), Mock(), Mock()
        self.atom1.chain, self.atom2.chain, self.atom3.chain = (self.chain1,
                                                                self.chain2,
                                                                self.chain3)
        self.chain1.id, self.chain2.id, self.chain3.id = "A1", "A2", "A3"
        self.chain1.name, self.chain2.name, self.chain3.name = "VAL", "TYR", "TYR"

    def test_can_get_chains(self):
        self.assertEqual(self.structure.chains(),
                         set([self.chain1, self.chain2, self.chain3]))

    def test_can_filter_none_from_chains(self):
        self.atom3.chain = None
        self.assertEqual(self.structure.chains(), {self.chain1, self.chain2})

    def test_can_get_chains_by_id(self):
        self.assertEqual(self.structure.chains(id="A1"), {self.chain1})
        self.assertEqual(self.structure.chains(id="A2"), {self.chain2})
        self.assertEqual(self.structure.chains(id="A5"), set())

    def test_can_get_chains_by_name(self):
        self.assertEqual(self.structure.chains(name="VAL"), set([self.chain1]))
        self.assertEqual(self.structure.chains(name="TYR"),
                         set([self.chain2, self.chain3]))
        self.assertEqual(self.structure.chains(name="GLY"), set())