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.
- property plugin_factory: PluginFactoryο
The underlying plugin factory (read-only, for advanced use).
- register(name, plugin, *, scope)[source]ο
Register a plugin for dot-notation access.
- Parameters:
name (
str) β The attribute name (e.g."validate","statistics").plugin β A
Plugininstance or a plain callable.scope (
PluginScope) β APluginScopemember.
- Return type:
Example:
from sloth.mmcif import PluginScope from sloth.mmcif.validator import ValidatorPlugin handler.register("validate", ValidatorPlugin(), scope=PluginScope.CATEGORY) # Or a simple function plugin handler.register("stats", lambda cat: cat.row_count, scope=PluginScope.CATEGORY)
- 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]
- load(file_path, **kwargs)[source]ο
Import mmCIF data from JSON format.
- Parameters:
file_path (str) β Path to the JSON file to import
kwargs β Additional options
- Returns:
An MMCIFDataContainer instance
- Return type:
- validate(data, *, relaxed=False)[source]ο
Validate mmCIF data recursively and return a
ValidationReport.Works on any level of the hierarchy β a single
Category, aDataBlock, or an entireMMCIFDataContainer.The rules that run depend on the relaxed flag:
default (
relaxed=False): the fullMmcifValidatordictionary + wwPDB suite runs first, followed by any user-registered custom validators.relaxed (
relaxed=True): only user-registered validators run. If none have been registered the report will be empty.
- Parameters:
data (
Union[MMCIFDataContainer,DataBlock,Category]) β The data object to validate.relaxed (
bool) β WhenTrue, skip the official MmcifValidator and only run user-registered rules.
- Return type:
- Returns:
A
ValidationReportwith all collected issues.
Example:
handler = MMCIFHandler() report = handler.validate(container) # full suite report = handler.validate(container, relaxed=True) # user rules only