Python rdkit.Chem.AllChem.EmbedMultipleConfs() Examples

The following are 7 code examples of rdkit.Chem.AllChem.EmbedMultipleConfs(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rdkit.Chem.AllChem , or try the search function .
Example #1
Source File: flipchiral.py    From rdkit-scripts with MIT License 6 votes vote down vote up
def make_iso_smiles(mol):
    '''enumerate chiral centers and return list of smiles'''
    #for some reason rdkit can't detect chiral centers without a structure
    Chem.EmbedMultipleConfs(mol)
    Chem.rdmolops.AssignAtomChiralTagsFromStructure(mol)
    chirals = [] # chiral atoms
    Chem.rdmolops.AssignStereochemistry(mol) #make sure this is done
    for a in mol.GetAtoms():
        if a.GetChiralTag() == Chem.rdchem.CHI_TETRAHEDRAL_CCW or a.GetChiralTag() == Chem.rdchem.CHI_TETRAHEDRAL_CW:
            chirals.append(a)
    cmask = itertools.product(*[[0,1]]*len(chirals))
    if len(chirals) == 0:
        return [Chem.MolToSmiles(mol)]
    else:
        ret = []
        for m in cmask:
            for i in xrange(len(chirals)):
                if m[i]:
                    chirals[i].SetChiralTag(Chem.rdchem.CHI_TETRAHEDRAL_CCW)
                else:
                    chirals[i].SetChiralTag(Chem.rdchem.CHI_TETRAHEDRAL_CW)
            ret.append(Chem.MolToSmiles(mol,True))
        return ret 
Example #2
Source File: conformers.py    From deepchem with MIT License 5 votes vote down vote up
def embed_molecule(self, mol):
    """
    Generate conformers, possibly with pruning.

    Parameters
    ----------
    mol : RDKit Mol
        Molecule.
    """
    from rdkit import Chem
    from rdkit.Chem import AllChem
    mol = Chem.AddHs(mol)  # add hydrogens
    n_confs = self.max_conformers * self.pool_multiplier
    AllChem.EmbedMultipleConfs(mol, numConfs=n_confs, pruneRmsThresh=-1.)
    return mol 
Example #3
Source File: scoring_functions.py    From GB-GA with MIT License 5 votes vote down vote up
def get_structure(mol,n_confs):
  mol = Chem.AddHs(mol)
  new_mol = Chem.Mol(mol)

  AllChem.EmbedMultipleConfs(mol,numConfs=n_confs,useExpTorsionAnglePrefs=True,useBasicKnowledge=True)
  energies = AllChem.MMFFOptimizeMoleculeConfs(mol,maxIters=2000, nonBondedThresh=100.0)

  energies_list = [e[1] for e in energies]
  min_e_index = energies_list.index(min(energies_list))

  new_mol.AddConformer(mol.GetConformer(min_e_index))

  return new_mol 
Example #4
Source File: chemical.py    From thermo with MIT License 5 votes vote down vote up
def draw_3d(self, width=300, height=500, style='stick', Hs=True): # pragma: no cover
        r'''Interface for drawing an interactive 3D view of the molecule.
        Requires an HTML5 browser, and the libraries RDKit, pymol3D, and
        IPython. An exception is raised if all three of these libraries are
        not installed.

        Parameters
        ----------
        width : int
            Number of pixels wide for the view
        height : int
            Number of pixels tall for the view
        style : str
            One of 'stick', 'line', 'cross', or 'sphere'
        Hs : bool
            Whether or not to show hydrogen

        Examples
        --------
        >>> Chemical('cubane').draw_3d()
        <IPython.core.display.HTML object>
        '''
        try:
            import py3Dmol
            from IPython.display import display
            if Hs:
                mol = self.rdkitmol_Hs
            else:
                mol = self.rdkitmol
            AllChem.EmbedMultipleConfs(mol)
            mb = Chem.MolToMolBlock(mol)
            p = py3Dmol.view(width=width,height=height)
            p.addModel(mb,'sdf')
            p.setStyle({style:{}})
            p.zoomTo()
            display(p.show())
        except:
            return 'py3Dmol, RDKit, and IPython are required for this feature.' 
Example #5
Source File: generator.py    From e3fp with GNU Lesser General Public License v3.0 5 votes vote down vote up
def embed_molecule(self, mol):
        """Generate conformers, possibly with pruning.

        Parameters
        ----------
        mol : RDKit Mol
            Molecule.
        """
        logging.debug("Adding hydrogens for %s" % mol.GetProp("_Name"))
        mol = Chem.AddHs(mol)  # add hydrogens
        logging.debug("Hydrogens added to %s" % mol.GetProp("_Name"))
        logging.debug("Sanitizing mol for %s" % mol.GetProp("_Name"))
        Chem.SanitizeMol(mol)
        logging.debug("Mol sanitized for %s" % mol.GetProp("_Name"))
        if self.max_conformers == -1 or type(self.max_conformers) is not int:
            self.max_conformers = self.get_num_conformers(mol)
        n_confs = self.max_conformers * self.pool_multiplier
        if self.first_conformers == -1:
            self.first_conformers = self.max_conformers
        logging.debug(
            "Embedding %d conformers for %s" % (n_confs, mol.GetProp("_Name"))
        )
        AllChem.EmbedMultipleConfs(
            mol,
            numConfs=n_confs,
            maxAttempts=10 * n_confs,
            pruneRmsThresh=-1.0,
            randomSeed=self.seed,
            ignoreSmoothingFailures=True,
        )
        logging.debug("Conformers embedded for %s" % mol.GetProp("_Name"))
        return mol 
Example #6
Source File: converter.py    From 3DGCN with MIT License 4 votes vote down vote up
def optimize_conformer(idx, m, prop, algo="MMFF"):
    print("Calculating {}: {} ...".format(idx, Chem.MolToSmiles(m)))

    mol = Chem.AddHs(m)

    if algo == "ETKDG":
        # Landrum et al. DOI: 10.1021/acs.jcim.5b00654
        k = AllChem.EmbedMolecule(mol, AllChem.ETKDG())

        if k != 0:
            return None, None

    elif algo == "UFF":
        # Universal Force Field
        AllChem.EmbedMultipleConfs(mol, 50, pruneRmsThresh=0.5)
        try:
            arr = AllChem.UFFOptimizeMoleculeConfs(mol, maxIters=2000)
        except ValueError:
            return None, None

        if not arr:
            return None, None

        else:
            arr = AllChem.UFFOptimizeMoleculeConfs(mol, maxIters=20000)
            idx = np.argmin(arr, axis=0)[1]
            conf = mol.GetConformers()[idx]
            mol.RemoveAllConformers()
            mol.AddConformer(conf)

    elif algo == "MMFF":
        # Merck Molecular Force Field
        AllChem.EmbedMultipleConfs(mol, 50, pruneRmsThresh=0.5)
        try:
            arr = AllChem.MMFFOptimizeMoleculeConfs(mol, maxIters=2000)
        except ValueError:
            return None, None

        if not arr:
            return None, None

        else:
            arr = AllChem.MMFFOptimizeMoleculeConfs(mol, maxIters=20000)
            idx = np.argmin(arr, axis=0)[1]
            conf = mol.GetConformers()[idx]
            mol.RemoveAllConformers()
            mol.AddConformer(conf)

    mol = Chem.RemoveHs(mol)

    return mol, prop 
Example #7
Source File: rdk.py    From oddt with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def diverse_conformers_generator(mol, n_conf=10, method='etkdg', seed=None,
                                 rmsd=0.5):
    """Produce diverse conformers using current conformer as starting point.
    Each conformer is a copy of original molecule object.

    .. versionadded:: 0.6

    Parameters
    ----------
    mol : oddt.toolkit.Molecule object
        Molecule for which generating conformers

    n_conf : int (default=10)
        Targer number of conformers

    method : string (default='etkdg')
        Method for generating conformers. Supported methods: "etkdg", "etdg",
        "kdg", "dg".

    seed : None or int (default=None)
        Random seed

    rmsd : float (default=0.5)
        The minimum RMSD that separates conformers to be ratained (otherwise,
        they will be pruned).

    Returns
    -------
    mols : list of oddt.toolkit.Molecule objects
        Molecules with diverse conformers
    """
    mol_clone = mol.clone
    if method == 'etkdg':
        params = {'useExpTorsionAnglePrefs': True,
                  'useBasicKnowledge': True}
    elif method == 'etdg':
        params = {'useExpTorsionAnglePrefs': True,
                  'useBasicKnowledge': False}
    elif method == 'kdg':
        params = {'useExpTorsionAnglePrefs': False,
                  'useBasicKnowledge': True}
    elif method == 'dg':
        params = {}
    else:
        raise ValueError('Method %s is not implemented' % method)
    params['pruneRmsThresh'] = rmsd
    if seed is None:
        seed = -1
    AllChem.EmbedMultipleConfs(mol_clone.Mol, numConfs=n_conf, randomSeed=seed,
                               **params)
    AllChem.AlignMol(mol_clone.Mol, mol.Mol)
    AllChem.AlignMolConformers(mol_clone.Mol)

    out = []
    mol_clone2 = mol.clone
    mol_clone2.Mol.RemoveAllConformers()
    for conformer in mol_clone.Mol.GetConformers():
        mol_output_clone = mol_clone2.clone
        mol_output_clone.Mol.AddConformer(conformer)
        out.append(mol_output_clone)
    return out