MOL/SDF file reader
Added in version 3.15.0.
For loading molecular structures stored in the MDL Molfile (“.mol”) and Structure-Data File (“.sdf”) formats,
which belong to the family of chemical table file (CTfile) formats
originally developed by MDL Information Systems (now BIOVIA). A Molfile describes a single molecule, whereas an SD file
concatenates several Molfile records, each terminated by a $$$$ line and optionally followed by associated data items.
These formats are widely used in cheminformatics and drug discovery and are written by programs and databases such as
RDKit, Open Babel, ChemDraw, PubChem, and ChEMBL. OVITO can directly load gzipped MOL/SDF files (“.gz” suffix).
Only the V2000 connection table format is supported. Files written in the extended V3000 format are rejected by the file reader.
Imported data
- Header block
The three header lines of each molecule record (molecule name, program/timestamp line, and comment line) are stored as global attributes named
SDF/MDL.Title,SDF/MDL.Program, andSDF/MDL.Comment. The dimensional code (2D/3D) contained in the program line is not interpreted; the atomic coordinates are always imported as three-dimensional positions (with z = 0 for 2D structure drawings).- Atom block
Each line of the atom block is read as one atom. The file reader creates the following per-atom properties:
Position — the Cartesian x, y, z coordinates.
Particle Type — the chemical element symbol. The atomic number of the element is used as numeric type ID, and OVITO assigns the standard CPK color and display radius of the element.
Mass Difference — the isotope field (mass difference relative to the natural abundance mass) of the atom block. If the file contains
M ISOproperty lines, these supersede the atom block values, and the absolute isotope masses specified there are stored in this property instead.Charge — the formal charge of the atom, converted from the charge code of the atom block (1 = +3, 2 = +2, 3 = +1, 5 = -1, 6 = -2, 7 = -3; code 4 denotes a doublet radical and is treated as uncharged). If the file contains
M CHGproperty lines, these supersede the charge codes of the atom block, as prescribed by the format specification.Hydrogen Count +1 — the implicit hydrogen count field (used in query structures).
Valence — the valence field.
The properties Mass Difference, Charge, Hydrogen Count +1, and Valence are only created if at least one atom in the file has a non-zero value in the corresponding field. The remaining fields of the atom block (stereo parity, stereo care box, H0 designator, atom-atom mapping number, inversion/retention flag, exact change flag) are ignored.
- Bond block
Each line of the bond block is read as one bond connecting two atoms. The following per-bond properties are created:
Topology — the indices of the two atoms connected by the bond.
Bond Type — the bond type code, stored as a typed property with named types Single (1), Double (2), Triple (3), Aromatic (4), Single or Double (5), Single or Aromatic (6), Double or Aromatic (7), and Any (8).
Bond Stereo — the bond stereo field (0 = not stereo, 1 = up, 4 = either, 6 = down for single bonds; 0 = use x, y, z coordinates, 3 = cis or trans for double bonds).
Bond Configuration — the bond topology field used in query structures (0 = either, 1 = ring, 2 = chain).
The reacting center status field of the bond block is ignored. Note that the file reader does not derive the
Bond Orderproperty from the bond types, which would be needed by the Bonds visual element to render double, triple, or aromatic bonds as multiple cylinders. Use the Compute property modifier to set bond orders based on theBond Typeproperty if desired.- Properties block
Of the property lines following the bond block, only
M CHG(formal charges) andM ISO(isotope masses) are processed; see the description of the atom block above. All other property lines (M RAD,M STY,M ALS, atom aliasAlines, atom valueVlines, etc.) are skipped.- Data items
In SD files, each molecule record may be followed by a list of associated data items of the form
> <FIELDNAME>(optionally with an external registry number and further information on the header line, e.g.> 25 <FIELDNAME>), each followed by one or more value lines and terminated by a blank line. Every data item is imported as a global attribute namedSDF/MDL.<FIELDNAME>(including the angle brackets), whose value is the text of the value line(s). Numeric values are not converted and remain text strings.- Multiple molecules
An SD file can contain several molecule records, each terminated by a
$$$$line. OVITO loads them as individual animation frames, i.e. the n-th record of the file becomes frame n of the loaded trajectory. The global attributes listed above are set per frame. Single-molecule “.mol” files, which end after theM ENDline without a$$$$terminator, are accepted as well.
Limitations
Only the V2000 connection table format is supported. V3000 files are rejected with an error message.
The fields of the counts line, atom block, and bond block are parsed as whitespace-separated columns. The 3-character fields of the counts line and the bond block may run together without a separating blank, as in strictly fixed-width files of molecules with 100 or more atoms (e.g. the bond line
100101 1 0). Trailing fields of the atom and bond lines may be omitted.Radicals (
M RAD), atom aliases, S-groups, and all other property lines exceptM CHGandM ISOare ignored.Atom symbols that do not denote a chemical element (e.g. the query symbols
A,Q,L,*, or R-group labelsR#) are assigned numeric type ID 0 and displayed with a default color and radius.The file formats do not describe a simulation cell or periodic boundary conditions. OVITO can generate an ad-hoc bounding box cell (see Generate bounding box if needed option below).
Since the bond topology is always stored explicitly in the file, the reader provides no option to generate bonds based on interatomic distances. The Create bonds modifier can be applied after import if needed.
Options
- Generate bounding box if needed
If this option is enabled, OVITO will generate an axis-aligned bounding box enclosing all atoms of the molecule. This bounding box has open boundary conditions and serves as an approximate simulation cell.
Python parameters
The file reader accepts the following optional keyword parameters in a call to the import_file() or load() Python functions.
- import_file(location, bounding_box=False)
- Parameters:
bounding_box (bool) – Generate an ad-hoc simulation cell as a bounding box around the imported atoms.