biotite.structure.io.mol.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.

References

1

A. Dalby, J. G. Nourse, W. D. Hounshell, A. K. I. Gushurst, D. L. Grier, B. A. Leland, J. Laufer, “Description of several chemical structure file formats used by computer programs developed at Molecular Design Limited,” Journal of Chemical Information and Computer Sciences, vol. 32, pp. 244–255, May 1992. doi: 10.1021/ci00007a012

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_header()

Get the header from the MOL file.

Returns
mol_namestr

The name of the molecule.

initialsstr

The author’s initials.

programstr

The program name.

timedatetime

The time of file creation.

dimensionsstr

Dimensional codes.

scaling_factorsstr

Scaling factors.

energystr

Energy from modeling program.

registry_numberstr

MDL registry number.

commentsstr

Additional comments.

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, *args, **kwargs)

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
file_objectFile

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_header(mol_name, initials='', program='', time=None, dimensions='', scaling_factors='', energy='', registry_number='', comments='')

Set the header for the MOL file.

Parameters
mol_namestr

The name of the molecule.

initialsstr, optional

The author’s initials. Maximum length is 2.

programstr, optional

The program name. Maximum length is 8.

timedatetime or date, optional

The time of file creation.

dimensionsstr, optional

Dimensional codes. Maximum length is 2.

scaling_factorsstr, optional

Scaling factors. Maximum length is 12.

energystr, optional

Energy from modeling program. Maximum length is 12.

registry_numberstr, optional

MDL registry number. Maximum length is 6.

commentsstr, optional

Additional comments.

set_structure(atoms, default_bond_type=BondType.ANY)

Set the AtomArray for the file.

Parameters
arrayAtomArray

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

default_bond_typeBondType

Bond type fallback in the Bond block if a bond has no bond_type defined in atoms array. By default, each bond is treated as BondType.ANY.

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.