Exemplo n.º 1
0
 def setUp(self):
     MoleculeTest.setUp(self)
     self.molecule = Molecule(self.atom1, self.atom2, self.atom3)
     other_atoms = [Mock(), Mock(), Mock(), Mock(), Mock(), Mock(), Mock()]
     self.atom1.nearby_atoms.return_value = set(other_atoms[:3] +
                                                self.atoms[1:])
     self.atom2.nearby_atoms.return_value = set(other_atoms[2:5] +
                                                self.atoms[::1])
     self.atom3.nearby_atoms.return_value = set(other_atoms[4:] +
                                                self.atoms[:2])
     self.residues = [
         Mock(), Mock(),
         Mock(), Mock(),
         Mock(), Mock(),
         Mock()
     ]
     self.waters = [Mock(), Mock(), Mock(), Mock()]
     self.waters[0].name = "HOH"
     other_atoms[0].residue = self.residues[0]
     other_atoms[1].residue = self.residues[0]
     other_atoms[2].residue = self.residues[1]
     other_atoms[3].residue = self.residues[1]
     other_atoms[4].residue = self.residues[2]
     other_atoms[5].residue = self.residues[2]
     other_atoms[4].name = "C"
     other_atoms[5].name = "N"
     other_atoms[3].element = "C"
     other_atoms[4].element = "C"
     other_atoms[5].element = "C"
     other_atoms[2].element = "C"
     other_atoms[6].residue = None
     other_atoms[6].molecule = self.waters[0]
Exemplo n.º 2
0
 def test_can_create_molecule(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3)
     self.assertIsInstance(mol, AtomicStructure)
     self.mock_init.assert_called_with(mol, self.atom1, self.atom2,
                                       self.atom3)
     self.assertEqual(mol._id, None)
     self.assertEqual(mol._name, None)
Exemplo n.º 3
0
 def test_can_get_no_model(self, mock_atoms):
     mock_atoms.return_value = set(self.atoms)
     self.atom1.model = None
     self.atom2.model = None
     self.atom3.model = None
     mol = Molecule(self.atom1, self.atom2, self.atom3)
     self.assertIs(mol.model, None)
Exemplo n.º 4
0
 def test_can_get_model(self, mock_atoms):
     mock_atoms.return_value = set(self.atoms)
     model = Mock()
     self.atom1.model = model
     self.atom2.model = model
     self.atom3.model = model
     mol = Molecule(self.atom1, self.atom2, self.atom3)
     self.assertIs(mol.model, model)
Exemplo n.º 5
0
def ligand_contacts_protein(ligand: Molecule, model: Model) -> bool:
    """Determines if molecule is in contact with protein

    Args:
        ligand: The molecule
        model: Model containing protein chains

    Returns:
        True if in contact and false when not in contact
    """
    dist = 999.0
    for latom in ligand.atoms():
        for chain in model.chains():
            for patom in chain.atoms():
                ndist = latom.distance_to(patom)
                if ndist < dist:
                    dist = ndist
    # Added 1 angstrom because ligand is not protonated
    return dist < MAX_CONTACT_DISTANCE + 1
Exemplo n.º 6
0
    def site(self, radius=BINDING_SITE_RADIUS) -> Site:
        """Site of fragment

        If part of residue is inside radius then it is included in site.

        Args:
            radius (float): Radius of ligand within residues are included in site

        Returns:
            atomium.structures.chains.Site: Site
        """
        fragment_positions = self.atom_positions()
        atoms_of_near_residues = set()
        residues = self.parent.model().residues()
        for residue in residues:
            if is_residue_nearby(fragment_positions, residue, radius):
                atoms_of_near_residues.update(residue.atoms())

        name = 'fragment of ' + self.parent.name()
        ligand = Molecule(*self.atoms(), name=name)
        return Site(*atoms_of_near_residues, ligand=ligand)
Exemplo n.º 7
0
 def test_atoms_are_linked_to_molecule(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3)
     self.assertIs(self.atom1._molecule, mol)
     self.assertIs(self.atom2._molecule, mol)
     self.assertIs(self.atom3._molecule, mol)
Exemplo n.º 8
0
 def test_molecule_name_must_be_str(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, name="VAL")
     with self.assertRaises(TypeError):
         mol.name = 10
Exemplo n.º 9
0
 def test_can_update_molecule_name(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, name="VAL")
     mol.name = "HIS"
     self.assertEqual(mol._name, "HIS")
Exemplo n.º 10
0
 def test_molecule_name_property(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, name="VAL")
     self.assertIs(mol._name, mol.name)
Exemplo n.º 11
0
 def test_molecule_id_property(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, id="B10C")
     self.assertIs(mol._id, mol.id)
Exemplo n.º 12
0
 def test_molecule_repr_id_and_name(self):
     mol = Molecule(self.atom1, self.atom2, id="B10B", name="GLY")
     self.assertEqual(str(mol), "<Molecule B10B (GLY, 2 atoms)>")
Exemplo n.º 13
0
 def test_molecule_repr_name_no_id(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, name="GLY")
     self.assertEqual(str(mol), "<Molecule (GLY, 3 atoms)>")
Exemplo n.º 14
0
 def test_molecule_repr_id_no_name(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, id="B10A")
     self.assertEqual(str(mol), "<Molecule B10A (3 atoms)>")
Exemplo n.º 15
0
 def test_molecule_repr_no_id_or_name(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3)
     self.assertEqual(str(mol), "<Molecule (3 atoms)>")
Exemplo n.º 16
0
 def test_molecule_name_must_be_str(self):
     with self.assertRaises(TypeError):
         Molecule(self.atom1, self.atom2, self.atom3, name=1000)
Exemplo n.º 17
0
 def test_can_create_molecule_with_name(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, name="HIS")
     self.assertEqual(mol._name, "HIS")
Exemplo n.º 18
0
 def test_can_create_molecule_with_id(self):
     mol = Molecule(self.atom1, self.atom2, self.atom3, id="A100")
     self.assertEqual(mol._id, "A100")
Exemplo n.º 19
0
class MoleculeSiteTests(MoleculeTest):
    def setUp(self):
        MoleculeTest.setUp(self)
        self.molecule = Molecule(self.atom1, self.atom2, self.atom3)
        other_atoms = [Mock(), Mock(), Mock(), Mock(), Mock(), Mock(), Mock()]
        self.atom1.nearby_atoms.return_value = set(other_atoms[:3] +
                                                   self.atoms[1:])
        self.atom2.nearby_atoms.return_value = set(other_atoms[2:5] +
                                                   self.atoms[::1])
        self.atom3.nearby_atoms.return_value = set(other_atoms[4:] +
                                                   self.atoms[:2])
        self.residues = [
            Mock(), Mock(),
            Mock(), Mock(),
            Mock(), Mock(),
            Mock()
        ]
        self.waters = [Mock(), Mock(), Mock(), Mock()]
        self.waters[0].name = "HOH"
        other_atoms[0].residue = self.residues[0]
        other_atoms[1].residue = self.residues[0]
        other_atoms[2].residue = self.residues[1]
        other_atoms[3].residue = self.residues[1]
        other_atoms[4].residue = self.residues[2]
        other_atoms[5].residue = self.residues[2]
        other_atoms[4].name = "C"
        other_atoms[5].name = "N"
        other_atoms[3].element = "C"
        other_atoms[4].element = "C"
        other_atoms[5].element = "C"
        other_atoms[2].element = "C"
        other_atoms[6].residue = None
        other_atoms[6].molecule = self.waters[0]

    @patch("atomium.structures.Molecule.atoms")
    @patch("atomium.structures.chains.Site")
    def test_can_get_site(self, mock_site, mock_atoms):
        mock_atoms.return_value = set(self.atoms)
        returned_site = self.molecule.site()
        mock_atoms.assert_called_with(hydrogen=False)
        self.atom1.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom2.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom3.nearby_atoms.assert_called_with(4, hydrogen=False)
        residues_passed = mock_site.call_args_list[0][0]
        self.assertEqual(set(residues_passed), set(self.residues[:2]))
        kwargs = mock_site.call_args_list[0][1]
        self.assertEqual(kwargs, {"ligand": self.molecule})

    @patch("atomium.structures.Molecule.atoms")
    @patch("atomium.structures.chains.Site")
    def test_can_get_site_with_water(self, mock_site, mock_atoms):
        mock_atoms.return_value = set(self.atoms)
        returned_site = self.molecule.site(water=True)
        mock_atoms.assert_called_with(hydrogen=False)
        self.atom1.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom2.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom3.nearby_atoms.assert_called_with(4, hydrogen=False)
        residues_passed = mock_site.call_args_list[0][0]
        self.assertEqual(set(residues_passed),
                         set(self.residues[:2] + self.waters[:1]))
        kwargs = mock_site.call_args_list[0][1]
        self.assertEqual(kwargs, {"ligand": self.molecule})

    @patch("atomium.structures.Molecule.atoms")
    @patch("atomium.structures.chains.Site")
    def test_can_get_site_with_main_chain(self, mock_site, mock_atoms):
        mock_atoms.return_value = set(self.atoms)
        returned_site = self.molecule.site(main_chain=True)
        mock_atoms.assert_called_with(hydrogen=False)
        self.atom1.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom2.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom3.nearby_atoms.assert_called_with(4, hydrogen=False)
        residues_passed = mock_site.call_args_list[0][0]
        self.assertEqual(set(residues_passed), set(self.residues[:3]))
        kwargs = mock_site.call_args_list[0][1]
        self.assertEqual(kwargs, {"ligand": self.molecule})

    @patch("atomium.structures.Molecule.atoms")
    @patch("atomium.structures.chains.Site")
    def test_can_get_site_with_cutoff(self, mock_site, mock_atoms):
        mock_atoms.return_value = set(self.atoms)
        returned_site = self.molecule.site(cutoff=1)
        mock_atoms.assert_called_with(hydrogen=False)
        self.atom1.nearby_atoms.assert_called_with(1, hydrogen=False)
        self.atom2.nearby_atoms.assert_called_with(1, hydrogen=False)
        self.atom3.nearby_atoms.assert_called_with(1, hydrogen=False)
        residues_passed = mock_site.call_args_list[0][0]
        self.assertEqual(set(residues_passed), set(self.residues[:2]))
        kwargs = mock_site.call_args_list[0][1]
        self.assertEqual(kwargs, {"ligand": self.molecule})

    @patch("atomium.structures.Molecule.atoms")
    @patch("atomium.structures.chains.Site")
    def test_can_get_site_without_carbon(self, mock_site, mock_atoms):
        mock_atoms.return_value = set(self.atoms)
        returned_site = self.molecule.site(carbon=False)
        mock_atoms.assert_called_with(hydrogen=False)
        self.atom1.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom2.nearby_atoms.assert_called_with(4, hydrogen=False)
        self.atom3.nearby_atoms.assert_called_with(4, hydrogen=False)
        residues_passed = mock_site.call_args_list[0][0]
        self.assertEqual(set(residues_passed), set(self.residues[:1]))
        kwargs = mock_site.call_args_list[0][1]
        self.assertEqual(kwargs, {"ligand": self.molecule})