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:
system (
ihm.System
) – Theihm.System
object containing all information about the system.writer (
ihm.format.CifWriter
orihm.format_bcif.BinaryCifWriter
.) – Utility class to write data to the output file.
- class ihm.dumper.Variant[source]¶
Utility class to select the type of file to output by
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'>, check=True)[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 defaultIHMVariant
should be used.check (bool) – If True (the default), check the output objects for self-consistency. If this is set to False, disabling some of these checks, the output files may not correctly validate against the mmCIF dictionaries. (Note that some checks are always performed, as the library cannot function correctly without these.)