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.

Parameters:
finalize(system)[source]

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_dumpers()[source]

Get the Dumper objects to use to write output.

Returns:

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,
                 variant=IgnoreVariant(['_audit_conform']))

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

Parameters:

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

ihm.dumper.set_line_wrap(line_wrap)[source]

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).

Parameters:

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)
Parameters:
  • 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.