Ejemplo n.º 1
0
 def setUp(self):
     """
     Set up tests.
     """
     smiles = 'CC(=O)OC1=CC=CC=C1C(=O)O'
     mol = Chem.MolFromSmiles(smiles)
     engine = conformers.ConformerGenerator(max_conformers=1)
     self.mol = engine.generate_conformers(mol)
     assert self.mol.GetNumConformers() > 0
     self.preparator = MolPreparator()
Ejemplo n.º 2
0
 def __init__(self, size=30., resolution=0.5, nb_cutoff=5.,
              ionic_strength=150., ionize=True, pH=7.4, align=False):
     self.size = float(size)
     self.resolution = float(resolution)
     self.nb_cutoff = float(nb_cutoff)
     self.ionic_strength = float(ionic_strength)
     self.preparator = MolPreparator(ionize, pH, align, add_hydrogens=True)
Ejemplo n.º 3
0
 def __init__(self, size=81, resolution=0.5, hydrogens=False, align=False,
              probe_radius=1.4, featurization='occupancy'):
     self.size = size
     self.resolution = resolution
     self.hydrogens = hydrogens
     self.preparator = MolPreparator(align=align, add_hydrogens=hydrogens)
     self.probe_radius = probe_radius
     self.featurization = featurization
Ejemplo n.º 4
0
 def setUp(self):
     """
     Set up tests.
     """
     smiles = 'CC(=O)OC1=CC=CC=C1C(=O)O'
     mol = Chem.MolFromSmiles(smiles)
     engine = conformers.ConformerGenerator(max_conformers=1)
     self.mol = engine.generate_conformers(mol)
     assert self.mol.GetNumConformers() > 0
     self.preparator = MolPreparator()
Ejemplo n.º 5
0
class TestMolPreparator(unittest.TestCase):
    """
    Test MolPreparator.
    """
    def setUp(self):
        """
        Set up tests.
        """
        smiles = 'CC(=O)OC1=CC=CC=C1C(=O)O'
        mol = Chem.MolFromSmiles(smiles)
        engine = conformers.ConformerGenerator(max_conformers=1)
        self.mol = engine.generate_conformers(mol)
        assert self.mol.GetNumConformers() > 0
        self.preparator = MolPreparator()

    def test_identity(self):
        """
        Test MolPreparator does nothing by default.
        """
        mol = self.preparator(self.mol)
        assert mol.GetNumAtoms() == self.mol.GetNumAtoms()
        assert mol.GetNumConformers() == self.mol.GetNumConformers()

    def test_ionize(self):
        """
        Test MolPreparator with ionize=True.
        """
        self.preparator.set_ionize(True)
        mol = self.preparator(self.mol)
        mol_charge = sum([atom.GetFormalCharge() for atom in mol.GetAtoms()])
        ref_charge = sum(
            [atom.GetFormalCharge() for atom in self.mol.GetAtoms()])
        assert mol_charge != ref_charge

    def test_align(self):
        """
        Test MolPreparator with align=True.

        Really just make sure that coordinates are sane, since the alignment
        tends to flatten molecules if there are hydrogens present.
        """
        def _check_flat(this_mol):
            """
            Check whether a molecule is flat.

            Parameters
            ----------
            this_mol : RDKit Mol
                Molecule to check.
            """
            for conf in this_mol.GetConformers():
                coords = []
                for atom in this_mol.GetAtoms():
                    coords.append(list(conf.GetAtomPosition(atom.GetIdx())))
                coords = np.asarray(coords, dtype=float)
                for i in xrange(coords.shape[1]):
                    assert not np.allclose(coords[:, i], 0)

        # test without hydrogens
        self.preparator.set_align(True)
        mol = self.preparator(self.mol)
        _check_flat(mol)

        # test with hydrogens
        self.preparator.set_add_hydrogens(True)
        mol = self.preparator(self.mol)
        _check_flat(mol)

    def test_add_hydrogens(self):
        """
        Test MolPreparator with add_hydrogens=True.
        """
        self.preparator.set_add_hydrogens(True)
        ref_mol = Chem.RemoveHs(self.mol)
        mol = self.preparator(ref_mol)
        assert mol.GetNumAtoms() > ref_mol.GetNumAtoms()
Ejemplo n.º 6
0
class TestMolPreparator(unittest.TestCase):
    """
    Test MolPreparator.
    """
    def setUp(self):
        """
        Set up tests.
        """
        smiles = 'CC(=O)OC1=CC=CC=C1C(=O)O'
        mol = Chem.MolFromSmiles(smiles)
        engine = conformers.ConformerGenerator(max_conformers=1)
        self.mol = engine.generate_conformers(mol)
        assert self.mol.GetNumConformers() > 0
        self.preparator = MolPreparator()

    def test_identity(self):
        """
        Test MolPreparator does nothing by default.
        """
        mol = self.preparator(self.mol)
        assert mol.GetNumAtoms() == self.mol.GetNumAtoms()
        assert mol.GetNumConformers() == self.mol.GetNumConformers()

    def test_ionize(self):
        """
        Test MolPreparator with ionize=True.
        """
        self.preparator.set_ionize(True)
        mol = self.preparator(self.mol)
        mol_charge = sum([atom.GetFormalCharge() for atom in mol.GetAtoms()])
        ref_charge = sum([atom.GetFormalCharge()
                          for atom in self.mol.GetAtoms()])
        assert mol_charge != ref_charge

    def test_align(self):
        """
        Test MolPreparator with align=True.

        Really just make sure that coordinates are sane, since the alignment
        tends to flatten molecules if there are hydrogens present.
        """
        def _check_flat(this_mol):
            """
            Check whether a molecule is flat.

            Parameters
            ----------
            this_mol : RDKit Mol
                Molecule to check.
            """
            for conf in this_mol.GetConformers():
                coords = []
                for atom in this_mol.GetAtoms():
                    coords.append(list(conf.GetAtomPosition(atom.GetIdx())))
                coords = np.asarray(coords, dtype=float)
                for i in xrange(coords.shape[1]):
                    assert not np.allclose(coords[:, i], 0)

        # test without hydrogens
        self.preparator.set_align(True)
        mol = self.preparator(self.mol)
        _check_flat(mol)

        # test with hydrogens
        self.preparator.set_add_hydrogens(True)
        mol = self.preparator(self.mol)
        _check_flat(mol)

    def test_add_hydrogens(self):
        """
        Test MolPreparator with add_hydrogens=True.
        """
        self.preparator.set_add_hydrogens(True)
        ref_mol = Chem.RemoveHs(self.mol)
        mol = self.preparator(ref_mol)
        assert mol.GetNumAtoms() > ref_mol.GetNumAtoms()