iodata.formats.sdf module

SDF file format.

Usually, the different frames in a trajectory describe different geometries of the same molecule, with atoms in the same order. The load_many and dump_many functions below can also handle an SDF file with different molecules, e.g. a molecular database.

The SDF format is somewhat documented on the following page: http://www.nonlinear.com/progenesis/sdf-studio/v0.9/faq/sdf-file-format-guidance.aspx

This format is one of the chemical table file formats: https://en.wikipedia.org/wiki/Chemical_table_file

dump_many(f, datas)[source]

Dump multiple frames into a SDF file.

Parameters:
  • f (TextIO) – A writeable file object.

  • datas (Iterator[IOData]) – An iterator over IOData instances which must have the following attributes initialized: atcoords, atnums. If the following attributes are present, they are also dumped into the file: title, bonds.

Notes

dump_one(f, data)[source]

Dump a single frame into a SDF file.

Parameters:
  • f (TextIO) – A writeable file object.

  • data (IOData) – An IOData instance which must have the following attributes initialized: atcoords, atnums. If the following attributes are present, they are also dumped into the file: title, bonds.

Notes

load_many(lit)[source]

Load multiple frames from a SDF file.

Parameters:

lit (LineIterator) – The line iterator to read the data from.

Yields:

result (dict) – A dictionary with IOData attributes. The following attribtues are guaranteed to be loaded: atcoords, atnums, bonds, title.

load_one(lit)[source]

Load a single frame from a SDF file.

Parameters:

lit (LineIterator) – The line iterator to read the data from.

Return type:

dict

Returns:

result (dict) – A dictionary with IOData attributes. The following attributes are guaranteed to be loaded: atcoords, atnums, bonds, title.

prepare_dump(data, allow_changes, filename)[source]

Check the compatibility of the IOData object with the SDF format.

Parameters:
  • data (IOData) – The IOData instance to be checked.

  • allow_changes (bool) – Whether conversion of the IOData object to a compatible form is allowed or not.

  • filename (str) – The file to be written to, only used for error messages.

Return type:

IOData

Returns:

data – The given IOData object, or a copy with a title on a single line.

Raises:

PrepareDumpError – If the title has more than one line and allow_changes is False, if the molecule has more atoms or bonds than the three-digit fields of the SDF V2000 format can hold, or if a coordinate does not fit in the fields of ten characters (from -9999.9999 Å to 99999.9999 Å).