Skip to main content

Overview

The mmcif module provides low-level parsing operations and utilities for working with mmCIF (macromolecular Crystallographic Information File) format. It wraps C++ implementations for efficient parsing and provides Python-friendly interfaces.

Core Classes

Mmcif

The Mmcif class (alias for CifDict) represents a parsed mmCIF file as an immutable dictionary-like object. It provides efficient access to mmCIF data categories and items. Dictionary Access:

Parsing Functions

from_string

Parses an mmCIF string into an Mmcif (CifDict) object.
str | bytes
required
The contents of an mmCIF file as a string or bytes
Returns: Mmcif object containing parsed data Example:

parse_multi_data_cif

Parses a CIF string containing multiple data blocks.
str
required
CIF string with multiple data_ records
Returns: Dictionary mapping record names to Mmcif objects Example:

Chain and Entity Functions

get_chain_type_by_entity_id

Returns a mapping from entity ID to its chain type.
Mmcif
required
Parsed mmCIF object
Returns: Dictionary mapping entity IDs to chain types (e.g., ‘polypeptide(L)’, ‘polyribonucleotide’, ‘water’) Example:

get_internal_to_author_chain_id_map

Returns a mapping from internal chain IDs (label_asym_id) to author chain IDs (auth_asym_id).
Mmcif
required
Parsed mmCIF object
Returns: Dictionary mapping internal to author chain IDs Note: This is not a bijection - multiple internal chain IDs can map to the same author chain ID. Example:

Bond Parsing

get_bond_atom_indices

Extracts atom indices that participate in chemical bonds from the _struct_conn table.
Mmcif
required
Parsed mmCIF object
str
default:"'1'"
Model ID to extract bonds for (from _atom_site.pdbx_PDB_model_num)
Returns: Tuple of (from_atoms, to_atoms) where each is a list of 0-based atom indices Raises:
  • BondParsingError: If required tables are missing or bonds reference non-existent atoms
Example:

BondParsingError

Raised when bond information cannot be extracted from an mmCIF file due to missing tables or invalid references.

Atom Data Functions

get_or_infer_type_symbol

Returns element symbols for all atoms in the structure.
Mmcif
required
Parsed mmCIF object
Ccd | None
default:"None"
Chemical Component Dictionary for inferring elements. If None, uses the cached CCD.
Returns: Sequence of element symbols (e.g., [‘C’, ‘N’, ‘O’, ‘S’]) Description: Returns _atom_site.type_symbol if present. If not, infers elements from residue names and atom names using the Chemical Component Dictionary. Example:

Metadata Functions

get_experimental_method

Extracts the experimental method used to determine the structure.
Mmcif
required
Parsed mmCIF object
Returns: Comma-separated string of experimental methods (lowercase) or None if not present Example:

get_resolution

Extracts the resolution of the structure in Angstroms.
Mmcif
required
Parsed mmCIF object
Returns: Resolution in Angstroms or None if not available Description: Checks multiple possible fields in order:
  1. _refine.ls_d_res_high (X-ray refinement)
  2. _em_3d_reconstruction.resolution (EM reconstruction)
  3. _reflns.d_resolution_high (reflection data)
Example:

get_release_date

Returns the oldest revision date from the structure’s release history.
Mmcif
required
Parsed mmCIF object
Returns: ISO-8601 formatted date string (YYYY-MM-DD) or None Example:

Chain ID Conversion Functions

int_id_to_str_id

Converts a positive integer to an mmCIF-style chain ID using reverse spreadsheet naming.
int
required
Positive integer (1-based)
Returns: String chain ID Raises: ValueError if num <= 0 Encoding scheme:
  • 1 → ‘A’
  • 2 → ‘B’
  • 26 → ‘Z’
  • 27 → ‘AA’
  • 28 → ‘BA’
  • 52 → ‘ZZ’
  • 53 → ‘AAA’
Example:

str_id_to_int_id

Converts an mmCIF-style string chain ID to an integer (inverse of int_id_to_str_id).
str
required
String chain ID consisting only of uppercase letters A-Z
Returns: Integer (1-based) Raises: ValueError if str_id contains non-uppercase letters Example:

Bioassembly Functions

parse_oper_expr

Parses bioassembly operation expressions from mmCIF files.
str
required
Operation expression string from _pdbx_struct_assembly_gen.oper_expression
Returns: List of tuples, where each tuple contains transform IDs to apply for generating one copy Expression syntax:
  • 1,2,3 → Apply transforms 1, 2, or 3 separately (3 copies)
  • (1-3) → Same as above using range notation
  • (1-3)(4-6) → Cartesian product: apply all pairs (1,4), (1,5), (1,6), (2,4), (2,5), (2,6), (3,4), (3,5), (3,6) (9 copies)
  • (P) → Apply single transform with ID ‘P’
Raises: ValueError if the expression format is unsupported Example:

Utility Functions

format_float_array

Efficiently converts a 1D float array to formatted strings.
np.ndarray
required
1D NumPy array of values to format (will be cast to float32)
int
required
Number of decimal places to include (with trailing zeros)
Returns: List of formatted strings Raises: ValueError if array is not 1-dimensional Note: This is optimized for performance and faster than Python list comprehensions. Example:

Complete Example

Here’s a comprehensive example showing common mmCIF parsing operations:

See Also