Esempio n. 1
0
    def _read_in_library(self, path, header, delimiter, quotechar):
        """Fragment library parser

        Args:
            path (str): Path to the fragment library.
            header (bool): Whether or not the library contains a header.
            delimiter (str): Delimiter symbol.
            quotechar (str): Quotechar symbol.
        """
        rdkit.rdBase.DisableLog("rdApp.*")
        rdCoordGen.SetDefaultTemplateFileDir(config.coordgen_templates)
        rdCoordGen.CoordGenParams.coordgenScaling = 33  # to get single bond length 1.5

        with open(path, "r") as csvfile:
            library_reader = csv.reader(
                csvfile, delimiter=delimiter, quotechar=quotechar
            )
            if header:
                next(library_reader)

            for row in library_reader:
                mol = None
                if row[1] == "SMARTS":
                    mol = Chem.MolFromSmarts(row[2])
                else:
                    mol = Chem.MolFromSmiles(row[2])
                    if row[1] == "LIKE":
                        for bond in mol.GetBonds():
                            bond.SetBondType(Chem.rdchem.BondType.UNSPECIFIED)

                Chem.SanitizeMol(mol, catchErrors=True)
                rdCoordGen.AddCoords(mol)

                self.library[row[0]] = FragmentEntry(row[0], row[6], mol)

        rdkit.rdBase.EnableLog("rdApp.*")
Esempio n. 2
0
    # This is an optional component of the build
    from rdkit.Chem.rdMolInterchange import *
except ImportError:
    pass

# Coordgen needs to know where its template file is.
# The default install puts it in RDDataDir
try:
    from rdkit.Chem import rdCoordGen
except ImportError:
    pass
else:
    templDir = RDConfig.RDDataDir
    if templDir[-1] != '/':
        templDir += '/'
    rdCoordGen.SetDefaultTemplateFileDir(templDir)


def QuickSmartsMatch(smi, sma, unique=True, display=False):
    m = MolFromSmiles(smi)
    p = MolFromSmarts(sma)
    res = m.GetSubstructMatches(p, unique)
    if display:
        pass
    return res


def CanonSmiles(smi, useChiral=1):
    m = MolFromSmiles(smi)
    return MolToSmiles(m, useChiral)