The ihm.dumper Python module

Utility classes to dump out information in mmCIF or BinaryCIF format

class ihm.dumper.Dumper[source]

Base class for helpers to dump output to mmCIF or BinaryCIF. See write().

dump(system, writer)[source]

Use writer to write information about system to mmCIF or BinaryCIF.


Called for all dumpers prior to dump(). This can be used to assign numeric IDs to objects, check for sanity, etc.

class ihm.dumper.Variant[source]

Utility class to select the type of file to output by write().


Get the Dumper objects to use to write output.


a list of Dumper objects.

get_system_writer(system, writer_class, writer)[source]

Get a writer tailored to the given system. By default, this just returns the writer unchanged.

class ihm.dumper.IHMVariant[source]

Used to select typical PDBx/IHM file output. See write().

class ihm.dumper.IgnoreVariant(ignores)[source]

Exclude selected CIF categories from output.

This generates the same PDBx/IHM output as IHMVariant, but explicitly listed CIF categories are discarded, for example:

ihm.dumper.write(fh, systems,

This is intended for advanced users that have a working knowledge of the PDBx and IHM CIF dictionaries.


ignores (sequence) – A list or tuple of CIF categories to exclude.


Set whether output lines are wrapped at 80 characters. By default the mmCIF writer tries to avoid writing lines longer than 80 characters, for compatibility with traditional PDB. When disabled, each row in a “loop” construct will be written on a single line.

This setting has no effect on binary formats (BinaryCIF).


line_wrap (bool) – whether to wrap lines at 80 characters.

ihm.dumper.write(fh, systems, format='mmCIF', dumpers=[], variant=<class 'ihm.dumper.IHMVariant'>)[source]

Write out all systems to the file handle fh. Files can be written in either the text-based mmCIF format or the BinaryCIF format. The BinaryCIF writer needs the msgpack Python module to function.

The file handle should be opened in binary mode for BinaryCIF files. For mmCIF, text mode should be used, usually with UTF-8 encoding, e.g.:

with open('output.cif', 'w', encoding='utf-8') as fh:
    ihm.dumper.write(fh, systems)
with open('output.bcif', 'wb') as fh:
    ihm.dumper.write(fh, systems, format='BCIF')

If generating files for a tool that is sensitive to non-ASCII data, a more restrictive encoding such as ASCII or ISO-8859-1 could also be used (although note that this may lose some information such as accented characters):

with open('output.cif', 'w', encoding='ascii',
          errors='replace') as fh:
    ihm.dumper.write(fh, systems)
  • fh (file) – The file handle to write to.

  • systems (list) – The list of ihm.System objects to write.

  • format (str) – The format of the file. This can be ‘mmCIF’ (the default) for the (text-based) mmCIF format or ‘BCIF’ for BinaryCIF.

  • dumpers (list) – A list of Dumper classes (not objects). These can be used to add extra categories to the file.

  • variant (Variant) – A class or object that selects the type of file to output. This primarily controls the set of tables that are written to the file. In most cases the default IHMVariant should be used.