openforcefield.utils.toolkits.RDKitToolkitWrapper

class openforcefield.utils.toolkits.RDKitToolkitWrapper[source]

RDKit toolkit wrapper

Warning

This API is experimental and subject to change.

Attributes
toolkit_file_read_formats

List of file formats that this toolkit can read.

toolkit_file_write_formats

List of file formats that this toolkit can write.

toolkit_installation_instructions

classmethod(function) -> method

toolkit_name

The name of the toolkit wrapped by this class.

Methods

find_smarts_matches(self, molecule, smarts)

Find all SMARTS matches for the specified molecule, using the specified aromaticity model.

from_file(self, file_path, file_format[, …])

Create an openforcefield.topology.Molecule from a file using this toolkit.

from_file_obj(self, file_obj, file_format[, …])

Return an openforcefield.topology.Molecule from a file-like object (an object with a “.read()” method using this toolkit.

from_object(self, object[, …])

If given an rdchem.Mol (or rdchem.Mol-derived object), this function will load it into an openforcefield.topology.molecule.

from_rdkit(self, rdmol[, allow_undefined_stereo])

Create a Molecule from an RDKit molecule.

from_smiles(self, smiles[, …])

Create a Molecule from a SMILES string using the RDKit toolkit.

generate_conformers(self, molecule[, …])

Generate molecule conformers using RDKit.

is_available()

Check whether the RDKit toolkit can be imported

requires_toolkit()

to_file(self, molecule, file_path, file_format)

Writes an OpenFF Molecule to a file-like object

to_file_obj(self, molecule, file_obj, …)

Writes an OpenFF Molecule to a file-like object

to_rdkit(molecule[, aromaticity_model])

Create an RDKit molecule

to_smiles(molecule)

Uses the RDKit toolkit to convert a Molecule into a SMILES string.

__init__(self, /, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, /, \*args, \*\*kwargs)

Initialize self.

find_smarts_matches(self, molecule, smarts)

Find all SMARTS matches for the specified molecule, using the specified aromaticity model.

from_file(self, file_path, file_format[, …])

Create an openforcefield.topology.Molecule from a file using this toolkit.

from_file_obj(self, file_obj, file_format[, …])

Return an openforcefield.topology.Molecule from a file-like object (an object with a “.read()” method using this toolkit.

from_object(self, object[, …])

If given an rdchem.Mol (or rdchem.Mol-derived object), this function will load it into an openforcefield.topology.molecule.

from_rdkit(self, rdmol[, allow_undefined_stereo])

Create a Molecule from an RDKit molecule.

from_smiles(self, smiles[, …])

Create a Molecule from a SMILES string using the RDKit toolkit.

generate_conformers(self, molecule[, …])

Generate molecule conformers using RDKit.

is_available()

Check whether the RDKit toolkit can be imported

requires_toolkit()

to_file(self, molecule, file_path, file_format)

Writes an OpenFF Molecule to a file-like object

to_file_obj(self, molecule, file_obj, …)

Writes an OpenFF Molecule to a file-like object

to_rdkit(molecule[, aromaticity_model])

Create an RDKit molecule

to_smiles(molecule)

Uses the RDKit toolkit to convert a Molecule into a SMILES string.

Attributes

toolkit_file_read_formats

List of file formats that this toolkit can read.

toolkit_file_write_formats

List of file formats that this toolkit can write.

toolkit_installation_instructions

classmethod(function) -> method

toolkit_name

The name of the toolkit wrapped by this class.

static is_available()[source]

Check whether the RDKit toolkit can be imported

Returns
is_installedbool

True if RDKit is installed, False otherwise.

from_object(self, object, allow_undefined_stereo=False)[source]

If given an rdchem.Mol (or rdchem.Mol-derived object), this function will load it into an openforcefield.topology.molecule. Otherwise, it will return False.

Parameters
objectA rdchem.Mol-derived object

An object to be type-checked and converted into a Molecule, if possible.

allow_undefined_stereobool, default=False

Whether to accept molecules with undefined stereocenters. If False, an exception will be raised if a molecule with undefined stereochemistry is passed into this function.

Returns
Molecule or False

An openforcefield.topology.molecule Molecule.

Raises
NotImplementedError

If the object could not be converted into a Molecule.

from_file(self, file_path, file_format, allow_undefined_stereo=False)[source]

Create an openforcefield.topology.Molecule from a file using this toolkit.

Parameters
file_pathstr

The file to read the molecule from

file_formatstr

Format specifier, usually file suffix (eg. ‘MOL2’, ‘SMI’) Note that not all toolkits support all formats. Check ToolkitWrapper.toolkit_file_read_formats for details.

allow_undefined_stereobool, default=False

If false, raises an exception if oemol contains undefined stereochemistry.

Returns
moleculesiterable of Molecules

a list of Molecule objects is returned.

from_file_obj(self, file_obj, file_format, allow_undefined_stereo=False)[source]

Return an openforcefield.topology.Molecule from a file-like object (an object with a “.read()” method using this toolkit.

Warning

This API is experimental and subject to change.

Parameters
file_objfile-like object

The file-like object to read the molecule from

file_formatstr

Format specifier, usually file suffix (eg. ‘MOL2’, ‘SMI’) Note that not all toolkits support all formats. Check ToolkitWrapper.toolkit_file_read_formats for details.

allow_undefined_stereobool, default=False

If false, raises an exception if oemol contains undefined stereochemistry.

Returns
moleculesMolecule or list of Molecules

a list of Molecule objects is returned.

to_file_obj(self, molecule, file_obj, file_format)[source]

Writes an OpenFF Molecule to a file-like object

Parameters
moleculean OpenFF Molecule

The molecule to write

file_obj

The file-like object to write to

file_format

The format for writing the molecule data

to_file(self, molecule, file_path, file_format)[source]

Writes an OpenFF Molecule to a file-like object

Parameters
moleculean OpenFF Molecule

The molecule to write

file_path

The file path to write to

file_format

The format for writing the molecule data

Returns
——
classmethod to_smiles(molecule)[source]

Uses the RDKit toolkit to convert a Molecule into a SMILES string.

Parameters
moleculeAn openforcefield.topology.Molecule

The molecule to convert into a SMILES.

Returns
smilesstr

The SMILES of the input molecule.

from_smiles(self, smiles, hydrogens_are_explicit=False, allow_undefined_stereo=False)[source]

Create a Molecule from a SMILES string using the RDKit toolkit.

Warning

This API is experimental and subject to change.

Parameters
smilesstr

The SMILES string to turn into a molecule

hydrogens_are_explicitbool, default=False

If False, RDKit will perform hydrogen addition using Chem.AddHs

allow_undefined_stereobool, default=False

Whether to accept SMILES with undefined stereochemistry. If False, an exception will be raised if a SMILES with undefined stereochemistry is passed into this function.

Returns
moleculeopenforcefield.topology.Molecule

An openforcefield-style molecule.

generate_conformers(self, molecule, n_conformers=1, clear_existing=True)[source]

Generate molecule conformers using RDKit.

Warning

This API is experimental and subject to change.

moleculea Molecule

The molecule to generate conformers for.

n_conformersint, default=1

Maximum number of conformers to generate.

clear_existingbool, default=True

Whether to overwrite existing conformers for the molecule.

from_rdkit(self, rdmol, allow_undefined_stereo=False)[source]

Create a Molecule from an RDKit molecule.

Requires the RDKit to be installed.

Warning

This API is experimental and subject to change.

Parameters
rdmolrkit.RDMol

An RDKit molecule

allow_undefined_stereobool, default=False

If false, raises an exception if rdmol contains undefined stereochemistry.

Returns
moleculeopenforcefield.Molecule

An openforcefield molecule

Examples

Create a molecule from an RDKit molecule

>>> from rdkit import Chem
>>> from openforcefield.tests.utils import get_data_file_path
>>> rdmol = Chem.MolFromMolFile(get_data_file_path('systems/monomers/ethanol.sdf'))
>>> toolkit_wrapper = RDKitToolkitWrapper()
>>> molecule = toolkit_wrapper.from_rdkit(rdmol)
classmethod to_rdkit(molecule, aromaticity_model='OEAroModel_MDL')[source]

Create an RDKit molecule

Requires the RDKit to be installed.

Warning

This API is experimental and subject to change.

Parameters
aromaticity_modelstr, optional, default=DEFAULT_AROMATICITY_MODEL

The aromaticity model to use

Returns
rdmolrkit.RDMol

An RDKit molecule

Examples

Convert a molecule to RDKit

>>> from openforcefield.topology import Molecule
>>> ethanol = Molecule.from_smiles('CCO')
>>> rdmol = ethanol.to_rdkit()
find_smarts_matches(self, molecule, smarts, aromaticity_model='OEAroModel_MDL')[source]

Find all SMARTS matches for the specified molecule, using the specified aromaticity model.

Warning

This API is experimental and subject to change.

Parameters
moleculeopenforcefield.topology.Molecule

The molecule for which all specified SMARTS matches are to be located

smartsstr

SMARTS string with optional SMIRKS-style atom tagging

aromaticity_modelstr, optional, default=’OEAroModel_MDL’

Aromaticity model to use during matching

.. note :: Currently, the only supported ``aromaticity_model`` is ``OEAroModel_MDL``
property toolkit_file_read_formats

List of file formats that this toolkit can read.

property toolkit_file_write_formats

List of file formats that this toolkit can write.

property toolkit_installation_instructions

classmethod(function) -> method

Convert a function to be a class method.

A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:

class C:

@classmethod def f(cls, arg1, arg2, …):

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.

Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.

property toolkit_name

The name of the toolkit wrapped by this class.