MOLFile#

class biotite.structure.io.mol.MOLFile[source]#

Bases: TextFile

This class represents a file in MOL format, that is used to store structure information for small molecules. [1]

Since its use is intended for single small molecules, it stores less atom annotation information than the macromolecular structure formats: Only the atom positions, charges, elements and bonds can be read from the file, chain and and residue information is missing.

This class can also be used to parse the first structure from an SDF file, as the SDF format extends the MOL format.

Attributes:
headerHeader

The header of the MOL file.

References

Examples

>>> from os.path import join
>>> mol_file = MOLFile.read(join(path_to_structures, "molecules", "TYR.sdf"))
>>> atom_array = mol_file.get_structure()
>>> print(atom_array)
            0             N         1.320    0.952    1.428
            0             C        -0.018    0.429    1.734
            0             C        -0.103    0.094    3.201
            0             O         0.886   -0.254    3.799
            0             C        -0.274   -0.831    0.907
            0             C        -0.189   -0.496   -0.559
            0             C         1.022   -0.589   -1.219
            0             C        -1.324   -0.102   -1.244
            0             C         1.103   -0.282   -2.563
            0             C        -1.247    0.210   -2.587
            0             C        -0.032    0.118   -3.252
            0             O         0.044    0.420   -4.574
            0             O        -1.279    0.184    3.842
            0             H         1.977    0.225    1.669
            0             H         1.365    1.063    0.426
            0             H        -0.767    1.183    1.489
            0             H         0.473   -1.585    1.152
            0             H        -1.268   -1.219    1.134
            0             H         1.905   -0.902   -0.683
            0             H        -2.269   -0.031   -0.727
            0             H         2.049   -0.354   -3.078
            0             H        -2.132    0.523   -3.121
            0             H        -0.123   -0.399   -5.059
            0             H        -1.333   -0.030    4.784
copy()#

Create a deep copy of this object.

Returns:
copy

A copy of this object.

get_structure()#

Get an AtomArray from the MOL file.

Returns:
arrayAtomArray

This AtomArray contains the optional charge annotation and has an associated BondList. All other annotation categories, except element are empty.

classmethod read(file)#

Parse a file (or file-like object).

Parameters:
filefile-like object or str

The file to be read. Alternatively a file path can be supplied.

Returns:
fileFile

An instance from the respective File subclass representing the parsed file.

static read_iter(file)#

Create an iterator over each line of the given text file.

Parameters:
filefile-like object or str

The file to be read. Alternatively a file path can be supplied.

Yields:
linestr

The current line in the file.

set_structure(atoms, default_bond_type=BondType.ANY, version=None)#

Set the AtomArray for the file.

Parameters:
atomsAtomArray

The array to be saved into this file. Must have an associated BondList.

default_bond_typeBondType, optional

Bond type fallback for the Bond block, if a BondType has no CTAB counterpart. By default, each such bond is treated as BondType.ANY.

version{“V2000”, “V3000”}, optional

The version of the CTAB format. "V2000" uses the Atom and Bond block, while "V3000" uses the Properties block. By default, "V2000" is used, unless the number of atoms or bonds exceeds 999, in which case "V3000" is used.

write(file)#

Write the contents of this object into a file (or file-like object).

Parameters:
filefile-like object or str

The file to be written to. Alternatively a file path can be supplied.

static write_iter(file, lines)#

Iterate over the given lines of text and write each line into the specified file.

In contrast to write(), each line of text is not stored in an intermediate TextFile, but is directly written to the file. Hence, this static method may save a large amount of memory if a large file should be written, especially if the lines are provided as generator.

Parameters:
filefile-like object or str

The file to be written to. Alternatively a file path can be supplied.

linesgenerator or array-like of str

The lines of text to be written. Must not include line break characters.