The ihm.dictionary Python module

Classes to read in and represent an mmCIF extension dictionary

class ihm.dictionary.Dictionary[source]

Representation of an mmCIF dictionary. See read() to create a Dictionary from a file.

Multiple Dictionaries can be added together to yield a Dictionary that includes all the data in the original Dictionaries.

See the validator example for an example of using this class.

categories

Mapping from name to Category objects

linked_items

Links between items; keys are children, values are parents e.g. linked_items['_ihm_starting_model_details.asym_id'] = '_struct_asym.id'

validate(fh, format='mmCIF', warn_missing_category=None, warn_missing_keyword=None)[source]

Validate the given file against this dictionary.

Optionally, a ValidatorWarning can also be emitted for optional (non-mandatory) categories or keywords that are missing from the file. This can be useful to determine whether a file contains all of the data defined in the dictionary; it is primarily used by python-ihm developers to test the library itself, using the script util/check-supported-items.py.

Parameters:
  • fh (file) – The file handle to read from.

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

  • warn_missing_category – If given, a Python callable which is called with the name of each optional category (without the leading underscore) that is not present in the file. If it returns True, a warning is emitted for that category.

  • warn_missing_keyword – If given, a Python callable which is called with the names of the category and keyword for each optional keyword that is not present in the file, but whose category is present. If it returns True, a warning is emitted for that keyword.

Raises:

ValidatorError if the file fails to validate.

class ihm.dictionary.Category[source]

Representation of a single category in a Dictionary.

description

Human-readable text

keywords

Mapping from name to Keyword objects

mandatory

True iff this category is required in a compliant mmCIF file

name

Category name

class ihm.dictionary.ItemType(name, primitive_code, construct)[source]

Represent the type of a data item. This keeps the set of valid strings for values of a given Keyword. For example, integer values can only contain the digits 0-9 with an optional +/- prefix.

property case_sensitive

True iff this type is case sensitive

class ihm.dictionary.Keyword[source]

Representation of a single keyword in a Category.

enumeration

Set of acceptable values, or None

item_type

ItemType for this keyword, or None

mandatory

True iff this keyword is required in a compliant mmCIF file

name

Keyword name

ihm.dictionary.read(fh)[source]

Read dictionary data from the mmCIF file handle fh.

Returns:

The dictionary data.

Return type:

Dictionary

exception ihm.dictionary.ValidatorError[source]

Exception raised if a file fails to validate. See Dictionary.validate().

exception ihm.dictionary.ValidatorWarning[source]

Warning emitted for an optional category or keyword that is missing from a file. See Dictionary.validate().