Exemplo n.º 1
0
    def test3Parents(self):
        mol = Chem.MolFromSmiles("[Na]OC(=O)c1ccccc1")
        nmol = rdMolStandardize.FragmentParent(mol)
        self.assertEqual(Chem.MolToSmiles(nmol), "O=C([O-])c1ccccc1")

        mol = Chem.MolFromSmiles("C[NH+](C)(C).[Cl-]")
        nmol = rdMolStandardize.ChargeParent(mol)
        self.assertEqual(Chem.MolToSmiles(nmol), "CN(C)C")

        mol = Chem.MolFromSmiles("[O-]CCCC=CO.[Na+]")
        nmol = rdMolStandardize.TautomerParent(mol)
        self.assertEqual(Chem.MolToSmiles(nmol), "O=CCCCC[O-].[Na+]")
        nmol = rdMolStandardize.TautomerParent(mol, skipStandardize=True)
        # same answer because of the standardization at the end
        self.assertEqual(Chem.MolToSmiles(nmol), "O=CCCCC[O-].[Na+]")

        mol = Chem.MolFromSmiles("C[C@](F)(Cl)C/C=C/[C@H](F)Cl")
        nmol = rdMolStandardize.StereoParent(mol)
        self.assertEqual(Chem.MolToSmiles(nmol), "CC(F)(Cl)CC=CC(F)Cl")

        mol = Chem.MolFromSmiles("[12CH3][13CH3]")
        nmol = rdMolStandardize.IsotopeParent(mol)
        self.assertEqual(Chem.MolToSmiles(nmol), "CC")

        mol = Chem.MolFromSmiles(
            "[Na]Oc1c([12C@H](F)Cl)c(O[2H])c(C(=O)O)cc1CC=CO")
        nmol = rdMolStandardize.SuperParent(mol)
        self.assertEqual(Chem.MolToSmiles(nmol),
                         "O=CCCc1cc(C(=O)O)c(O)c(C(F)Cl)c1O")
        mol = Chem.MolFromSmiles(
            "[Na]Oc1c([12C@H](F)Cl)c(O[2H])c(C(=O)O)cc1CC=CO")
        nmol = rdMolStandardize.SuperParent(mol, skipStandardize=True)
        self.assertEqual(Chem.MolToSmiles(nmol),
                         "O=CCCc1cc(C(=O)[O-])c(O)c(C(F)Cl)c1O.[Na+]")
Exemplo n.º 2
0
 def test20NoneHandling(self):
     with self.assertRaises(ValueError):
         rdMolStandardize.ChargeParent(None)
     with self.assertRaises(ValueError):
         rdMolStandardize.Cleanup(None)
     with self.assertRaises(ValueError):
         rdMolStandardize.FragmentParent(None)
     with self.assertRaises(ValueError):
         rdMolStandardize.Normalize(None)
     with self.assertRaises(ValueError):
         rdMolStandardize.Reionize(None)
Exemplo n.º 3
0
def fix_mol(
    mol: Chem.rdchem.Mol,
    n_iter: int = 1,
    remove_singleton: bool = False,
    largest_only: bool = False,
    inplace: bool = False,
) -> Optional[Chem.rdchem.Mol]:
    """Fix error in molecule using a greedy approach.

    Args:
        mol: input molecule to fix
        n_iter: Number of valence fix iteration to apply
        remove_singleton: Whether `adjust_singleton` should be applied
        largest_only: Whether only the largest fragment should be kept
        inplace: Whether to return a copy of the mol or perform in place operation

    Returns:
        Fixed molecule.
    """

    if not inplace:
        mol = copy.copy(mol)

    m = sanitize_mol(mol) or mol  # fail back to mol when the fixer fail

    if m is not None:
        m = remove_dummies(m)
        for _ in range(n_iter):
            m = fix_valence(m)

        if remove_singleton:
            m = adjust_singleton(m)

        if largest_only:
            # m = max(Chem.rdmolops.GetMolFrags(m, asMols=True, sanitizeFrags=False), key=lambda m: m.GetNumAtoms())
            m = rdMolStandardize.FragmentParent(m, skipStandardize=True)

    return m
    def __init__(self, radius, fpSize, IC50function, molFile):
        self.fpgen = rdFingerprintGenerator.GetMorganGenerator(
            radius=radius, fpSize=fpSize)
        self.getIC50 = IC50function
        self.molFile = molFile

        # Open SMILES file and convert each sequence to rdkit molecule
        with open(self.molFile) as f:
            raw_text = f.read()

        raw_data = raw_text.split("\n")
        mol_list = [Chem.MolFromSmiles(x) for x in raw_data[:1000]]
        self.ms = [rdMolStandardize.FragmentParent(x) for x in mol_list]

        # Get a count of the BRICS bonds within the molecules
        cntr = Counter()
        for m in self.ms:
            bbnds = BRICS.FindBRICSBonds(m)
            for aids, lbls in bbnds:
                cntr[lbls] += 1
        freqs = sorted([(y, x) for x, y in cntr.items()], reverse=True)

        # Keep the top 10 bonds
        self.bondsToKeep = [y for x, y in freqs]
Exemplo n.º 5
0
 def test3FragmentParent(self):
     mol = Chem.MolFromSmiles("[Na]OC(=O)c1ccccc1")
     nmol = rdMolStandardize.FragmentParent(mol)
     self.assertEqual(Chem.MolToSmiles(nmol), "O=C([O-])c1ccccc1")