rdkit.Chem.rdmolfiles module

Module containing RDKit functionality for working with molecular file formats.

exception rdkit.Chem.rdmolfiles.BadFileException

Bases: OSError

class rdkit.Chem.rdmolfiles.CDXMLFormat(*values)

Bases: Enum

Auto = 2
CDX = 1
CDXML = 0
class rdkit.Chem.rdmolfiles.CDXMLParserParams(self)
class rdkit.Chem.rdmolfiles.CDXMLParserParams(self, sanitize: bool, removeHs: bool, format: rdkit.Chem.rdmolfiles.CDXMLFormat)

Bases: object

Parameters controlling conversion of a CDXML document to molecules

Overloaded function.

  1. __init__(self) -> None

Construct a default CDXMLFormat

  1. __init__(self, sanitize: bool, removeHs: bool, format: rdkit.Chem.rdmolfiles.CDXMLFormat) -> None

property format

ChemDraw format One of Auto, CDXML, CDX. For data streams, Auto defaults to CDXML

property removeHs

controls whether or not Hs are removed before the molecule is returned

property sanitize

controls whether or not the molecule is sanitized before being returned

class rdkit.Chem.rdmolfiles.CXSmilesFields(*values)

Bases: IntEnum

CX_ALL = 2147483647
CX_ALL_BUT_COORDS = 2147483643
CX_ATOM_LABELS = 1
CX_ATOM_PROPS = 16
CX_BOND_ATROPISOMER = 1024
CX_BOND_CFG = 512
CX_COORDINATE_BONDS = 2048
CX_COORDS = 4
CX_ENHANCEDSTEREO = 64
CX_LINKNODES = 32
CX_MOLFILE_VALUES = 2
CX_NONE = 0
CX_POLYMER = 256
CX_RADICALS = 8
CX_SGROUPS = 128
CX_ZERO_BONDS = 8192
exception rdkit.Chem.rdmolfiles.FileParseException

Bases: RuntimeError

class rdkit.Chem.rdmolfiles.ForwardSDMolSupplier(self, filename: str, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True)
class rdkit.Chem.rdmolfiles.ForwardSDMolSupplier(self, fileobj: object, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True)

Bases: object

A class which supplies molecules from a file-like object containing SD data.

Usage examples:

  1. Lazy evaluation: the molecules are not constructed until we ask for them:

    >>> suppl = ForwardSDMolSupplier(file('in.sdf'))
    >>> for mol in suppl:
    ...    if mol is not None: mol.GetNumAtoms()
    
  2. we can also read from compressed files:

    >>> import gzip
    >>> suppl = ForwardSDMolSupplier(gzip.open('in.sdf.gz'))
    >>> for mol in suppl:
    ...   if mol is not None: print mol.GetNumAtoms()
    

Properties in the SD file are used to set properties on each molecule. The properties are accessible using the mol.GetProp(propName) method.

GetEOFHitOnRead(self) bool

Returns whether EOF was hit while parsing the previous entry.

GetProcessPropertyLists(self) bool

Returns whether or not any property lists that are present will be processed when reading molecules.

SetProcessPropertyLists(self, val: bool) None

Sets whether or not any property lists that are present will be processed when reading molecules.

atEnd(self) bool

Returns whether or not we have hit EOF.

class rdkit.Chem.rdmolfiles.MaeMolSupplier(self)
class rdkit.Chem.rdmolfiles.MaeMolSupplier(self, filename: str, sanitize: bool = True, removeHs: bool = True)
class rdkit.Chem.rdmolfiles.MaeMolSupplier(self, fileobj: object, sanitize: bool = True, removeHs: bool = True)

Bases: object

A class which supplies molecules from a file-like object containing Maestro data.

Usage examples:

  1. Lazy evaluation: the molecules are not constructed until we ask for them:

    >>> suppl = MaeMolSupplier(file('in.mae'))
    >>> for mol in suppl:
    ...    if mol is not None: mol.GetNumAtoms()
    
  2. we can also read from compressed files:

    >>> import gzip
    >>> suppl = MaeMolSupplier(gzip.open('in.maegz'))
    >>> for mol in suppl:
    ...   if mol is not None: print mol.GetNumAtoms()
    

Properties in the Maestro file are used to set properties on each molecule. The properties are accessible using the mol.GetProp(propName) method.

SetData(self, data: str, sanitize: bool = True, removeHs: bool = True) None

Sets the text to be parsed.

atEnd(self) bool

Returns whether or not we have hit EOF.

reset(self) None

Resets our position in the file to the beginning.

class rdkit.Chem.rdmolfiles.MaeWriter(self, filename: str)
class rdkit.Chem.rdmolfiles.MaeWriter(self, fileobj: object)

Bases: object

An experimental class for writing molecules to Maestro files.

Usage examples:

  1. writing to a named file:

    >>> writer = MaeWriter('out.mae')
    >>> for mol in list_of_mols:
    ...    writer.write(mol)
    
  2. writing to a file-like object:

    >>> import gzip
    >>> outf=gzip.open('out.mae.gz','wt+')
    >>> writer = MaeWriter(outf)
    >>> for mol in list_of_mols:
    ...   writer.write(mol)
    >>> writer.close()
    >>> outf.close()
    

By default all non-private molecule, atom and bond properties are written to the Maestro file. This can be changed using the SetProps method:

>>> writer = MaeWriter('out.mae')
>>> writer.SetProps(['prop1','prop2'])

Properties that are specified, but are not present will be ignored.

Kekulization is mandatory, as the Maestro format does not have the concept of an aromatic bond.

As this is an experimental writer, many features are not supported yet, e.g. chirality and bond stereo labels, stereo groups, substance groups, isotopes, or even dummy atoms. Note that these are not supported by MaeMolSupplier either.

GetText = <nanobind.nb_func object>
NumMols(self) int

Returns the number of molecules written so far.

SetProps(self, props_list: collections.abc.Sequence[str]) None

Sets the atom and molecule properties to be written to the output file.

ARGUMENTS:

  • props_list: a list of atom and molecule property names

close(self) None

Flushes the output file and closes it. The writer cannot be used after this.

flush(self) None

Flushes the output file (forces the disk file to be updated).

write(self, mol: rdkit.Chem.rdchem.Mol, confId: int = -1) None

Writes a molecule to the output file.

ARGUMENTS:

  • mol: the molecule to be written

  • confId: (optional) ID of the conformation to write

class rdkit.Chem.rdmolfiles.MolFromSCSRParams(self)

Bases: object

Parameters controlling conversion of an SCSRMol to a Mol

property includeLeavingGroups

include leaving groups atoms if not substited at that position

property scsrBaseHbondOptions

One of Ignore, UseSapAll(default) , UseSapOne, Auto

property scsrTemplateNames

If True, the first template name in the Sgroup is used as the Sgroup label

class rdkit.Chem.rdmolfiles.MolWriterParams

Bases: object

Parameters controlling Mol writing

property forceV3000

force generation a V3000 mol block (happens automatically with more than 999 atoms or bonds)(default=False)

property includeStereo

toggles inclusion of stereochemistry information (default=True)

property kekulize

triggers kekulization of the molecule before it is written (default=True)

property precision

precision of coordinates (only available in V3000)(default=false)

class rdkit.Chem.rdmolfiles.MultithreadedSDMolSupplier(self)
class rdkit.Chem.rdmolfiles.MultithreadedSDMolSupplier(self, fileName: str, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True, numWriterThreads: int = 1, sizeInputQueue: int = 5, sizeOutputQueue: int = 5)

Bases: object

A class which concurrently supplies molecules from an SD file. Please note that this class is still a bit experimental and the API may change in future releases.

Usage examples:

  1. Lazy evaluation: the molecules might not be constructed until we ask for them:

    >>> suppl = MultithreadedSDMolSupplier('in.sdf')
    >>> for mol in suppl:
    ...    if(mol):
    ...      mol.GetNumAtoms()
    
  2. Lazy evaluation 2:

    >>> suppl = MultithreadedSDMolSupplier('in.sdf')
    >>> while (!suppl.atEnd()):
    ...    mol = next(mol)
    ...    if(mol):
    ...      mol.GetNumAtoms()
    

Overloaded function.

  1. __init__(self) -> None

  2. __init__(self, fileName: str, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True, numWriterThreads: int = 1, sizeInputQueue: int = 5, sizeOutputQueue: int = 5) -> None

Constructor

ARGUMENTS:

  • fileName: name of the file to be read

  • sanitize: (optional) toggles sanitization of molecules as they are read. Defaults to true.

  • removeHs: (optional) removes Hs. Defaults to true.

  • strictParsing: (optional) allows strict or lax parsing. Defaults to true.

  • numWriterThreads: (optional) number of writer threads. Defaults to 1.

  • sizeInputQueue: (optional) size of input/reader queue. Defaults to 5.

  • sizeOutputQueue: (optional) size of output/writer queue. Defaults to 5.

GetLastItemText(self) str

Returns the text for the last extracted item.

GetLastRecordId(self) int

Returns the record id for the last extracted item.

GetProcessPropertyLists(self) bool

Returns whether or not any property lists that are present will be processed when reading molecules.

SetProcessPropertyLists(self, val: bool) None

Sets whether or not any property lists that are present will be processed when reading molecules.

atEnd(self) bool

Returns true if we have read all records else false.

class rdkit.Chem.rdmolfiles.MultithreadedSmilesMolSupplier(self)
class rdkit.Chem.rdmolfiles.MultithreadedSmilesMolSupplier(self, fileName: str, delimiter: str = ' \t', smilesColumn: int = 0, nameColumn: int = 1, titleLine: bool = True, sanitize: bool = True, numWriterThreads: int = 1, sizeInputQueue: int = 5, sizeOutputQueue: int = 5)

Bases: object

A class which concurrently supplies molecules from a text file. Please note that this class is still a bit experimental and the API may change in future releases.

Usage examples:

  1. Lazy evaluation: the molecules might not be constructed until we ask for them:

    >>> suppl = MultithreadedSmilesMolSupplier('in.smi')
    >>> for mol in suppl:
    ...    if(mol):
    ...      mol.GetNumAtoms()
    
  2. Lazy evaluation 2:

    >>> suppl = MultithreadedSmilesMolSupplier('in.smi')
    >>> while (!suppl.atEnd()):
    ...    mol = next(mol)
    ...    if(mol):
    ...      mol.GetNumAtoms()
    

Overloaded function.

  1. __init__(self) -> None

  2. __init__(self, fileName: str, delimiter: str = ' \t', smilesColumn: int = 0, nameColumn: int = 1, titleLine: bool = True, sanitize: bool = True, numWriterThreads: int = 1, sizeInputQueue: int = 5, sizeOutputQueue: int = 5) -> None

Constructor

ARGUMENTS:

  • fileName: name of the file to be read

  • delimiter: (optional) text delimiter (a string). Defaults to ‘ t’.

  • smilesColumn: (optional) index of the column containing the SMILES data. Defaults to 0.

  • nameColumn: (optional) index of the column containing molecule names. Defaults to 1.

  • titleLine: (optional) set this toggle if the file contains a title line. Defaults to true.

  • sanitize: (optional) toggles sanitization of molecules as they are read. Defaults to true.

  • numWriterThreads: (optional) number of writer threads. Defaults to 1.

  • sizeInputQueue: (optional) size of input/reader queue. Defaults to 5.

  • sizeOutputQueue: (optional) size of output/writer queue. Defaults to 5.

GetLastItemText(self) str

Returns the text for the last extracted item.

GetLastRecordId(self) int

Returns the record id for the last extracted item.

atEnd(self) bool

Returns true if we have read all records else false.

class rdkit.Chem.rdmolfiles.PDBWriter(self, fileName: str, flavor: int = 0)
class rdkit.Chem.rdmolfiles.PDBWriter(self, fileObj: object, flavor: int = 0)

Bases: object

A class for writing molecules to PDB files.

Overloaded function.

  1. __init__(self, fileName: str, flavor: int = 0) -> None

Constructor.

ARGUMENTS:

  • fileName: name of the output file. (‘-’ to write to stdout)

  • flavor: (optional)

  1. __init__(self, fileObj: object, flavor: int = 0) -> None

NumMols(self) int

Returns the number of molecules written so far.

close(self) None

Flushes the output file and closes it. The Writer cannot be used after this.

flush(self) None

Flushes the output file (forces the disk file to be updated).

write(self, mol: rdkit.Chem.rdchem.Mol, confId: int = -1) None

Writes a molecule to the output file.

ARGUMENTS:

  • mol: the Mol to be written

  • confId: (optional) ignored

class rdkit.Chem.rdmolfiles.PNGMetadataParams(self)

Bases: object

Parameters controlling metadata included in PNG images

property cxSmilesFlags

choose CXSMILES fields to be included in the CXSMILES string (default=rdkit.Chem.rdmolfiles.CXSmilesFields.CX_ALL)

property includeMol

toggles inclusion of molecule molblock (default=False)

property includePkl

toggles inclusion of molecule pickle (default=True)

property includeSmiles

toggles inclusion of molecule CXSMILES (default=True)

property propertyFlags

choose properties to be included in the pickle (default=rdkit.Chem.rdchem.PropertyPickleOptions.NoProps)

property restoreBondDirs

choose what to do with bond dirs in the CXSMILES string (default=rdkit.Chem.rdmolfiles.RestoreBondDirOption.RestoreBondDirOptionClear)

property smilesWriteParams

choose SmilesWriteParams for the CXSMILES string (default=rdkit.Chem.rdmolfiles.SmilesWriteParams())

class rdkit.Chem.rdmolfiles.RestoreBondDirOption(*values)

Bases: Enum

RestoreBondDirOptionClear = 1
RestoreBondDirOptionTrue = 0
class rdkit.Chem.rdmolfiles.SCSRBaseHbondOptions(*values)

Bases: Enum

Auto = 3
Ignore = 0
UseSapAll = 1
UseSapOne = 2
class rdkit.Chem.rdmolfiles.SCSRTemplateNames(*values)

Bases: Enum

AsEntered = 0
UseFirstName = 1
UseSecondName = 2
class rdkit.Chem.rdmolfiles.SDMolSupplier(self)
class rdkit.Chem.rdmolfiles.SDMolSupplier(self, fileName: str, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True)
class rdkit.Chem.rdmolfiles.SDMolSupplier(self, fileName: object, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True)

Bases: object

A class which supplies molecules from an SD file.

Usage examples:

  1. Lazy evaluation: the molecules are not constructed until we ask for them:

    >>> suppl = SDMolSupplier('in.sdf')
    >>> for mol in suppl:
    ...    mol.GetNumAtoms()
    
  2. Lazy evaluation 2:

    >>> suppl = SDMolSupplier('in.sdf')
    >>> mol1 = next(suppl)
    >>> mol2 = next(suppl)
    >>> suppl.reset()
    >>> mol3 = next(suppl)
    # mol3 and mol1 are the same:
    >>> MolToSmiles(mol3)==MolToSmiles(mol1)
    
  3. Random Access:

    >>> suppl = SDMolSupplier('in.sdf')
    >>> mol1 = suppl[0]
    >>> mol2 = suppl[1]
    # NOTE: this will generate an IndexError if the supplier doesn't have that many
    molecules.
    
  4. Random Access 2: looping over all molecules

    >>> suppl = SDMolSupplier('in.sdf')
    >>> nMols = len(suppl)
    >>> for i in range(nMols):
    ...   suppl[i].GetNumAtoms()
    

Properties in the SD file are used to set properties on each molecule. The properties are accessible using the mol.GetProp(propName) method.

GetItemText(self, index: int) str

Returns the text for an item.

GetProcessPropertyLists(self) bool

Returns whether or not any property lists that are present will be processed when reading molecules.

SetData(self, data: str, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True) None
SetData(self, data: bytes, sanitize: bool = True, removeHs: bool = True, strictParsing: bool = True) None

Sets the text to be parsed.

SetProcessPropertyLists(self, val: bool) None

Sets whether or not any property lists that are present will be processed when reading molecules.

atEnd(self) bool

Returns whether or not we have hit EOF.

reset(self) None

Resets our position in the file to the beginning.

class rdkit.Chem.rdmolfiles.SDWriter(self, fileName: str)
class rdkit.Chem.rdmolfiles.SDWriter(self, fileObj: object)

Bases: object

A class for writing molecules to SD files.

Usage examples:

  1. writing to a named file:

    >>> writer = SDWriter('out.sdf')
    >>> for mol in list_of_mols:
    ...    writer.write(mol)
    
  2. writing to a file-like object:

    >>> import gzip
    >>> outf=gzip.open('out.sdf.gz','wt+')
    >>> writer = SDWriter(outf)
    >>> for mol in list_of_mols:
    ...   writer.write(mol)
    >>> writer.close()
    >>> outf.close()
    

By default all non-private molecular properties are written to the SD file. This can be changed using the SetProps method:

>>> writer = SDWriter('out.sdf')
>>> writer.SetProps(['prop1','prop2'])

Overloaded function.

  1. __init__(self, fileName: str) -> None

Constructor.

If a string argument is provided, it will be treated as the name of the output file. If a file-like object is provided, output will be sent there.

  1. __init__(self, fileObj: object) -> None

GetForceV3000(self) bool

Returns whether or not V3000 mol file writing is being forced.

GetKekulize(self) bool

Returns whether or not molecules are kekulized on writing.

GetText = <nanobind.nb_func object>
NumMols(self) int

Returns the number of molecules written so far.

SetForceV3000(self, val: bool) None

Sets whether or not V3000 mol file writing is being forced.

SetKekulize(self, val: bool) None

Sets whether or not molecules are kekulized on writing.

SetProps(self, props: collections.abc.Sequence[str]) None

Sets the properties to be written to the output file

ARGUMENTS:

  • props: a list or tuple of property names

close(self) None

Flushes the output file and closes it. The Writer cannot be used after this.

flush(self) None

Flushes the output file (forces the disk file to be updated).

write(self, mol: rdkit.Chem.rdchem.Mol, confId: int = -1) None

Writes a molecule to the output file.

ARGUMENTS:

  • mol: the Mol to be written

  • confId: (optional) ID of the conformation to write

class rdkit.Chem.rdmolfiles.SmartsParserParams(self)

Bases: object

Parameters controlling SMARTS parsing

property allowCXSMILES

controls whether or not the CXSMILES extensions are parsed

property debugParse

controls the amount of debugging information produced

property mergeHs

toggles merging H atoms in the SMARTS into neighboring atoms

property parseName

controls whether or not the molecule name is also parsed

property strictCXSMILES

controls whether or not problems in CXSMILES parsing causes molecule parsing to fail

class rdkit.Chem.rdmolfiles.SmilesMolSupplier(self, data: str, delimiter: str = ' ', smilesColumn: int = 0, nameColumn: int = 1, titleLine: bool = True, sanitize: bool = True)
class rdkit.Chem.rdmolfiles.SmilesMolSupplier(self)
class rdkit.Chem.rdmolfiles.SmilesMolSupplier(self, fileName: object, delimiter: str = ' ', smilesColumn: int = 0, nameColumn: int = 1, titleLine: bool = True, sanitize: bool = True)

Bases: object

A class which supplies molecules from a text file.

Usage examples:

  1. Lazy evaluation: the molecules are not constructed until we ask for them:

    >>> suppl = SmilesMolSupplier('in.smi')
    >>> for mol in suppl:
    ...    mol.GetNumAtoms()
    
  2. Lazy evaluation 2:

    >>> suppl = SmilesMolSupplier('in.smi')
    >>> mol1 = next(suppl)
    >>> mol2 = next(suppl)
    >>> suppl.reset()
    >>> mol3 = next(suppl)
    # mol3 and mol1 are the same:
    >>> MolToSmiles(mol3)==MolToSmiles(mol1)
    
  3. Random Access: all molecules are constructed as soon as we ask for the length:

    >>> suppl = SmilesMolSupplier('in.smi')
    >>> nMols = len(suppl)
    >>> for i in range(nMols):
    ...   suppl[i].GetNumAtoms()
    

If the input file has a title line and more than two columns (smiles and id), the additional columns will be used to set properties on each molecule. The properties are accessible using the mol.GetProp(propName) method.

Overloaded function.

  1. __init__(self, data: str, delimiter: str = ' ', smilesColumn: int = 0, nameColumn: int = 1, titleLine: bool = True, sanitize: bool = True) -> None

Constructor

ARGUMENTS:

  • fileName: name of the file to be read

  • delimiter: (optional) text delimiter (a string). Defauts to ‘ ‘.

  • smilesColumn: (optional) index of the column containing the SMILES data. Defaults to 0.

  • nameColumn: (optional) index of the column containing molecule names. Defaults to 1.

  • titleLine: (optional) set this toggle if the file contains a title line. Defaults to 1.

  • sanitize: (optional) toggles sanitization of molecules as they are read. Defaults to 1.

  1. __init__(self) -> None

  2. __init__(self, fileName: object, delimiter: str = ' ', smilesColumn: int = 0, nameColumn: int = 1, titleLine: bool = True, sanitize: bool = True) -> None

GetItemText(self, index: int) str

Returns the text for an item.

SetData(self, data: str, delimiter: str = ' ', smilesColumn: int = 0, nameColumn: int = 1, titleLine: bool = True, sanitize: bool = True) None

Sets the text to be parsed.

reset(self) None

Resets our position in the file to the beginning.

class rdkit.Chem.rdmolfiles.SmilesParserParams(self)

Bases: object

Parameters controlling SMILES parsing

property allowCXSMILES

controls whether or not the CXSMILES extensions are parsed

property debugParse

controls the amount of debugging information produced

property parseName

controls whether or not the molecule name is also parsed

property removeHs

controls whether or not Hs are removed before the molecule is returned

property sanitize

controls whether or not the molecule is sanitized before being returned

property strictCXSMILES

controls whether or not problems in CXSMILES parsing causes molecule parsing to fail

class rdkit.Chem.rdmolfiles.SmilesWriteParams(self)

Bases: object

Parameters controlling SMILES writing

property allBondsExplicit

include symbols for all bonds

property allHsExplicit

provide hydrogen counts for every atom

property canonical

generate canonical SMILES

property cleanStereo

chiral centers are removed if they have duplicate sidechains

property doIsomericSmiles

include stereochemistry and isotope information

property doKekule

kekulize the molecule before generating the SMILES and output single/double bonds. NOTE that the output is not canonical and that this will thrown an exception if the molecule cannot be kekulized

property doRandom

randomize the output order. The resulting SMILES is not canonical

property ignoreAtomMapNumbers

ignore atom map numbers when canonicalizing the molecule

property includeDativeBonds

include the RDKit extension for dative bonds. Otherwise dative bonds will be written as single bonds

property rootedAtAtom

make sure the SMILES starts at the specified atom. The resulting SMILES is not canonical

class rdkit.Chem.rdmolfiles.SmilesWriter(self, fileName: str, delimiter: str = ' ', nameHeader: str = 'Name', includeHeader: bool = True, isomericSmiles: bool = True, kekuleSmiles: bool = False)
class rdkit.Chem.rdmolfiles.SmilesWriter(self, fileObj: object, delimiter: str = ' ', nameHeader: str = 'Name', includeHeader: bool = True, isomericSmiles: bool = True, kekuleSmiles: bool = False)

Bases: object

A class for writing molecules to text files.

Overloaded function.

  1. __init__(self, fileName: str, delimiter: str = ' ', nameHeader: str = 'Name', includeHeader: bool = True, isomericSmiles: bool = True, kekuleSmiles: bool = False) -> None

Constructor.

ARGUMENTS:

  • fileName: name of the output file. (‘-’ to write to stdout)

  • delimiter: (optional) delimiter to be used to separate entries on each line.

  • nameHeader: (optional) text to use for the name column in the header line.

    If this is blank, names will not be included in the output.

  • includeHeader: (optional) toggles inclusion of a header line in the output file.

  • isomericSmiles: (optional) toggles output of isomeric smiles (includes stereochem information).

  • kekuleSmiles: (optional) toggles output of kekule smiles (no aromatic bonds for molecules that have been kekulized).

  1. __init__(self, fileObj: object, delimiter: str = ' ', nameHeader: str = 'Name', includeHeader: bool = True, isomericSmiles: bool = True, kekuleSmiles: bool = False) -> None

NumMols(self) int

Returns the number of molecules written so far.

SetProps(self, props: collections.abc.Sequence[str]) None

Sets the properties to be written to the output file

ARGUMENTS:

  • props: a list or tuple of property names

close(self) None

Flushes the output file and closes it. The Writer cannot be used after this.

flush(self) None

Flushes the output file (forces the disk file to be updated).

write(self, mol: rdkit.Chem.rdchem.Mol, confId: int = -1) None

Writes a molecule to the output file.

ARGUMENTS:

  • mol: the Mol to be written

  • confId: (optional) ignored

class rdkit.Chem.rdmolfiles.TDTMolSupplier(self)
class rdkit.Chem.rdmolfiles.TDTMolSupplier(self, fileName: str, nameRecord: str = '', confId2D: int = -1, confId3D: int = -1, sanitize: bool = True)

Bases: object

A class which supplies molecules from a TDT file.

Usage examples:

  1. Lazy evaluation: the molecules are not constructed until we ask for them:

    >>> suppl = TDTMolSupplier('in.smi')
    >>> for mol in suppl:
    ...    mol.GetNumAtoms()
    
  2. Lazy evaluation 2:

    >>> suppl = TDTMolSupplier('in.smi')
    >>> mol1 = next(suppl)
    >>> mol2 = next(suppl)
    >>> suppl.reset()
    >>> mol3 = next(suppl)
    # mol3 and mol1 are the same:
    >>> MolToSmiles(mol3)==MolToSmiles(mol1)
    
  3. Random Access: all molecules are constructed as soon as we ask for the length:

    >>> suppl = TDTMolSupplier('in.smi')
    >>> nMols = len(suppl)
    >>> for i in range(nMols):
    ...   suppl[i].GetNumAtoms()
    

Properties in the file are used to set properties on each molecule. The properties are accessible using the mol.GetProp(propName) method.

GetItemText(self, index: int) str

Returns the text for an item.

SetData(self, data: str, nameRecord: str = '', confId2D: int = -1, confId3D: int = -1, sanitize: bool = True) None

Sets the text to be parsed.

reset(self) None

Resets our position in the file to the beginning.

class rdkit.Chem.rdmolfiles.TDTWriter(self, fileName: str)
class rdkit.Chem.rdmolfiles.TDTWriter(self, fileObj: object)

Bases: object

A class for writing molecules to TDT files.

Overloaded function.

  1. __init__(self, fileName: str) -> None

Constructor.

If a string argument is provided, it will be treated as the name of the output file. If a file-like object is provided, output will be sent there.

  1. __init__(self, fileObj: object) -> None

GetNumDigits(self) int
GetWrite2D(self) bool
GetWriteNames(self) bool
NumMols(self) int

Returns the number of molecules written so far.

SetNumDigits(self, numDigits: int) None

Sets the number of digits to be written for coordinates.

SetProps(self, props: collections.abc.Sequence[str]) None

Sets the properties to be written to the output file

ARGUMENTS:

  • props: a list or tuple of property names

SetWrite2D(self, state: bool = True) None

Causes 2D conformations to be written (default is 3D conformations).

SetWriteNames(self, state: bool = True) None

Causes names to be written to the output file as NAME records.

close(self) None

Flushes the output file and closes it. The Writer cannot be used after this.

flush(self) None

Flushes the output file (forces the disk file to be updated).

write(self, mol: rdkit.Chem.rdchem.Mol, confId: int = -1) None

Writes a molecule to the output file.

ARGUMENTS:

  • mol: the Mol to be written

  • confId: (optional) ID of the conformation to write