Python rdkit.Chem.AllChem.MMFFGetMoleculeProperties() Examples

The following are 4 code examples of rdkit.Chem.AllChem.MMFFGetMoleculeProperties(). 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: conformers.py    From deepchem with MIT License 5 votes vote down vote up
def get_molecule_force_field(self, mol, conf_id=None, **kwargs):
    """
    Get a force field for a molecule.

    Parameters
    ----------
    mol : RDKit Mol
        Molecule.
    conf_id : int, optional
        ID of the conformer to associate with the force field.
    kwargs : dict, optional
        Keyword arguments for force field constructor.
    """
    from rdkit.Chem import AllChem
    if self.force_field == 'uff':
      ff = AllChem.UFFGetMoleculeForceField(mol, confId=conf_id, **kwargs)
    elif self.force_field.startswith('mmff'):
      AllChem.MMFFSanitizeMolecule(mol)
      mmff_props = AllChem.MMFFGetMoleculeProperties(
          mol, mmffVariant=self.force_field)
      ff = AllChem.MMFFGetMoleculeForceField(
          mol, mmff_props, confId=conf_id, **kwargs)
    else:
      raise ValueError("Invalid force_field " +
                       "'{}'.".format(self.force_field))
    return ff 
Example #2
Source File: rdk.py    From oddt with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def calccharges(self, model='gasteiger'):
        """Calculate partial charges for a molecule. By default the Gasteiger
        charge model is used.

        Parameters
        ----------
        model : str (default="gasteiger")
            Method for generating partial charges. Supported models:
            * gasteiger
            * mmff94
        """
        self._clear_cache()
        if model.lower() == 'gasteiger':
            ComputeGasteigerCharges(self.Mol, nIter=50)
        elif model.lower() == 'mmff94':
            fps = AllChem.MMFFGetMoleculeProperties(self.Mol)
            if fps is None:
                raise Exception('Could not charge molecule "%s"' % self.title)
            for i, atom in enumerate(self.Mol.GetAtoms()):
                atom.SetDoubleProp('_MMFF94Charge', fps.GetMMFFPartialCharge(i))
        else:
            raise ValueError('The "%s" is not supported in RDKit backend' %
                             model)
        if np.isnan(self.charges).any() or np.isinf(self.charges).any():
            warnings.warn('Some partial charges for molecule "%s" are not '
                          'finite (NaN, +/-Inf).' % self.title, UserWarning) 
Example #3
Source File: generator.py    From e3fp with GNU Lesser General Public License v3.0 5 votes vote down vote up
def get_molecule_force_field(self, mol, conf_id=None, **kwargs):
        """Get a force field for a molecule.

        Parameters
        ----------
        mol : RDKit Mol
            Molecule.
        conf_id : int, optional
            ID of the conformer to associate with the force field.
        **kwargs : dict, optional
            Keyword arguments for force field constructor.
        """
        if self.forcefield == "uff":
            ff = AllChem.UFFGetMoleculeForceField(
                mol, confId=conf_id, **kwargs
            )
        elif self.forcefield.startswith("mmff"):
            AllChem.MMFFSanitizeMolecule(mol)
            mmff_props = AllChem.MMFFGetMoleculeProperties(
                mol, mmffVariant=self.forcefield
            )
            ff = AllChem.MMFFGetMoleculeForceField(
                mol, mmff_props, confId=conf_id, **kwargs
            )
        else:
            raise ValueError(
                "Invalid forcefield " + "'{}'.".format(self.forcefield)
            )
        return ff 
Example #4
Source File: rdkit.py    From QCEngine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def compute(self, input_data: "AtomicInput", config: "TaskConfig") -> "AtomicResult":
        """
        Runs RDKit in FF typing
        """

        self.found(raise_error=True)
        import rdkit
        from rdkit.Chem import AllChem

        # Failure flag
        ret_data = {"success": False}

        # Build the Molecule
        jmol = input_data.molecule
        mol = self._process_molecule_rdkit(jmol)

        if input_data.model.method.lower() == "uff":
            ff = AllChem.UFFGetMoleculeForceField(mol)
            all_params = AllChem.UFFHasAllMoleculeParams(mol)
        elif input_data.model.method.lower() in ["mmff94", "mmff94s"]:
            props = AllChem.MMFFGetMoleculeProperties(mol, mmffVariant=input_data.model.method)
            ff = AllChem.MMFFGetMoleculeForceField(mol, props)
            all_params = AllChem.MMFFHasAllMoleculeParams(mol)
        else:
            raise InputError("RDKit only supports the UFF, MMFF94, and MMFF94s methods currently.")

        if all_params is False:
            raise InputError("RDKit parameters not found for all atom types in molecule.")

        ff.Initialize()

        ret_data["properties"] = {"return_energy": ff.CalcEnergy() * ureg.conversion_factor("kJ / mol", "hartree")}

        if input_data.driver == "energy":
            ret_data["return_result"] = ret_data["properties"]["return_energy"]
        elif input_data.driver == "gradient":
            coef = ureg.conversion_factor("kJ / mol", "hartree") * ureg.conversion_factor("angstrom", "bohr")
            ret_data["return_result"] = [x * coef for x in ff.CalcGrad()]
        else:
            raise InputError(f"RDKit can only compute energy and gradient driver methods. Found {input_data.driver}.")

        ret_data["provenance"] = Provenance(
            creator="rdkit", version=rdkit.__version__, routine="rdkit.Chem.AllChem.UFFGetMoleculeForceField"
        )

        ret_data["schema_name"] = "qcschema_output"
        ret_data["success"] = True

        # Form up a dict first, then sent to BaseModel to avoid repeat kwargs which don't override each other
        return AtomicResult(**{**input_data.dict(), **ret_data})