MMCIFHandler β Main Entry Pointο
The MMCIFHandler is the primary interface for reading, writing,
exporting, and importing mmCIF data.
from sloth import MMCIFHandler
handler = MMCIFHandler()
mmcif = handler.read("1abc.cif")
- class sloth.mmcif.handler.MMCIFHandler[source]ο
Bases:
objectA class to handle reading and writing mmCIF files with high-performance gemmi backend.
- __init__(strict=False)[source]ο
Initialize the handler with gemmi backend for optimal performance.
- Parameters:
strict (
bool) β IfTrue, prevent silent auto-creation of categories and data blocks on attribute access (setsauto_create=False) and register the default wwPDB validation rules viaMmcifValidator.
- property plugin_factory: PluginFactoryο
The underlying plugin factory (read-only, for advanced use).
- register(name, plugin, *, scope='category')[source]ο
Register a plugin for dot-notation access.
- Parameters:
- Return type:
Example:
from sloth.mmcif.validator import ValidatorPlugin handler.register("validate", ValidatorPlugin()) # Or a simple function plugin handler.register("stats", lambda cat: cat.row_count)
- read(filename, categories=None)[source]ο
Parse an mmCIF file and returns a data container using gemmiβs high-performance backend.
- Parameters:
- Returns:
The data container with lazy-loaded items.
- Return type:
- write(mmcif, filename=None)[source]ο
Writes a data container to a file using gemmiβs high-performance backend.
- Parameters:
mmcif (MMCIFDataContainer) β The data container to write.
filename (Optional[str]) β Optional filename to write to. If not provided, uses pre-set file object.
- Return type:
- Returns:
None
- export(mmcif, file_path=None, **kwargs)[source]ο
Export mmCIF data to JSON format.
- Parameters:
mmcif (MMCIFDataContainer) β The data container to export
file_path (Optional[str]) β Path to save the file (optional)
kwargs β Additional options (e.g., indent, quiet)
- Returns:
String representation if no file_path provided, otherwise None
- Return type:
Optional[str]