Validatorο
Exceptions & Enumsο
- class sloth.mmcif.validator.ValidationError[source]ο
Bases:
ExceptionException raised for validation errors.
- __init__(message, path='', severity=ValidationSeverity.ERROR)[source]ο
Initialize validation error.
- Parameters:
message (
str) β Error messagepath (
str) β Path where the error occurred (e.g., JSON path, category name)severity (
ValidationSeverity) β Validation error severity
Validation Reportο
- class sloth.mmcif.validator.ValidationReport[source]ο
Bases:
objectCollects validation errors from a recursive validation pass.
Returned by
DataBlockValidator.execute(),ContainerValidator.execute(), andValidatorPlugin.validate().- add(error)[source]ο
Append a single
ValidationError.- Return type:
- Parameters:
error (ValidationError)
- extend(other)[source]ο
Merge all issues from other into this report.
- Return type:
- Parameters:
other (ValidationReport)
- property all_issues: List[ValidationError]ο
Every collected issue regardless of severity.
- property errors: List[ValidationError]ο
Only
ValidationSeverity.ERRORissues.
- property warnings: List[ValidationError]ο
Only
ValidationSeverity.WARNINGissues.
- raise_on_error()[source]ο
Raise
ValidationErrorif any errors are present.- Return type:
Validator Pluginο
- class sloth.mmcif.validator.ValidatorPlugin[source]ο
Bases:
PluginPlugin for per-category validation with cross-checker support.
Multiple validators can be registered for the same category β they will all run in registration order.
Use
validate()for a standalone convenience entry-point that accepts any level of the data hierarchy and returns aValidationReport.- register_validator(category_name, validator_function)[source]ο
Register a validator callable for a category name.
Multiple validators for the same category are allowed.
- register_cross_checker(category_pair, cross_checker_function)[source]ο
Register a cross-checker callable for a pair of category names.
- merge(other)[source]ο
Return a new ValidatorPlugin whose rules are self + other.
Rules from other run after rules from self for each category / cross-checker pair. Neither the receiver nor the argument is mutated.
- Return type:
- Parameters:
other (ValidatorPlugin)
- create_wrapper(target)[source]ο
Return a
PluginWrapper(or subclass) bound to target.- Return type:
- execute(target, *args, **kwargs)[source]ο
Run the plugin logic on target. Called by
PluginWrapper.__call__().- Return type:
- validate(data)[source]ο
Validate data and return a
ValidationReport.Accepts any level of the hierarchy:
Categoryβ runs per-category validators only.DataBlockβ runs per-category validators and cross-checkers for all categories in the block.MMCIFDataContainerβ validates each block in turn.
- Parameters:
data (
Union[Category,DataBlock,MMCIFDataContainer]) β The data object to validate.- Return type:
- Returns:
A
ValidationReportwith all collected issues.
Multi-Level Validatorsο
- class sloth.mmcif.validator.DataBlockValidator[source]ο
Bases:
PluginValidates every category in a
DataBlock.Runs all per-category validators and cross-checkers registered on the wrapped
ValidatorPlugin, collecting errors into aValidationReportrather than raising on the first failure.- __init__(category_validator)[source]ο
- Parameters:
category_validator (ValidatorPlugin)
- create_wrapper(target)[source]ο
Return a
PluginWrapper(or subclass) bound to target.- Return type:
- Parameters:
target (DataBlock)
- class sloth.mmcif.validator.BlockValidationWrapper[source]ο
Bases:
PluginWrapperChainable wrapper for block-level validation.
- property report: ValidationReport | Noneο
Shortcut for
resultβ theValidationReport.
- class sloth.mmcif.validator.ContainerValidator[source]ο
Bases:
PluginValidates every block in an
MMCIFDataContainer.Delegates to a
DataBlockValidatorfor each block and merges all results into a singleValidationReport.- __init__(block_validator)[source]ο
- Parameters:
block_validator (DataBlockValidator)
- create_wrapper(target)[source]ο
Return a
PluginWrapper(or subclass) bound to target.- Return type:
- Parameters:
target (MMCIFDataContainer)
- execute(target, *args, **kwargs)[source]ο
Run the plugin logic on target. Called by
PluginWrapper.__call__().- Return type:
- Parameters:
target (MMCIFDataContainer)
- class sloth.mmcif.validator.ContainerValidationWrapper[source]ο
Bases:
PluginWrapperChainable wrapper for container-level validation.
- property report: ValidationReport | Noneο
Shortcut for
resultβ theValidationReport.
Validator Classesο
- class sloth.mmcif.validator.SchemaValidator[source]ο
Bases:
ValidatorPluginValidator auto-generated from an mmCIF dictionary.
Parses a
.dicfile via SLOTHβsDictionaryParser, retains the schema metadata, and registers validators from it:mandatory items β from
_item.mandatory_codeenumeration β from
_item_enumeration.valuetype regex β from
_item_type_list.constructforeign-key integrity β single-key relationships
composite-key integrity β multi-key relationships
parent/child category presence β parent must exist when child does
- Parameters:
dict_path (str, optional) β Path to an mmCIF dictionary. Defaults to the bundled
mmcif_pdbx_v50.dic.quiet (bool) β Suppress progress messages from the dictionary parser (default True).
Usage:: β
from sloth.mmcif.validator import SchemaValidator
v = SchemaValidator() # schema-only rules report = v.validate(block) # validate a DataBlock
- class sloth.mmcif.validator.MMCIFValidator[source]ο
Bases:
SchemaValidatorFull wwPDB validator = dictionary schema + deposition business rules.
Inherits all schema-level checks from
SchemaValidator, then registers wwPDB-specific rules from the declarative tables below.- Parameters:
dict_path (str, optional) β Path to an mmCIF dictionary. Defaults to the bundled
mmcif_pdbx_v50.dic.quiet (bool) β Suppress dictionary parser progress messages (default True).
Usage:: β
from sloth.mmcif.validator import MMCIFValidator
v = MMCIFValidator() # full wwPDB + dictionary rules report = v.validate(container) # validate an entire container
Single-Category Rule Factoriesο
- sloth.mmcif.validator.mandatory_items(items, exclude=(), severity=ValidationSeverity.ERROR)[source]ο
Items that must be non-null when the category is present.
- sloth.mmcif.validator.one_of_following(items, severity=ValidationSeverity.ERROR)[source]ο
At least one of items must be non-null.
- sloth.mmcif.validator.value_length(item, min_len=None, max_len=None, severity=ValidationSeverity.WARNING)[source]ο
String length bounds for an item.
- sloth.mmcif.validator.value_range(item, min_val=None, max_val=None, severity=ValidationSeverity.WARNING)[source]ο
Numeric bounds for an item.
- sloth.mmcif.validator.conditional_mandatory(required_items, when_item, when_values, severity=ValidationSeverity.ERROR)[source]ο
Items that must be non-null when when_item has one of when_values.
- sloth.mmcif.validator.regex_check(item, pattern, error_text='', severity=ValidationSeverity.ERROR)[source]ο
Values of item must match pattern.
- sloth.mmcif.validator.ordering_check(item_a, item_b, op='<', severity=ValidationSeverity.WARNING)[source]ο
Numeric ordering: item_a
opitem_b (per row).
- sloth.mmcif.validator.allowed_pairs(item_a, item_b, valid_mapping, severity=ValidationSeverity.ERROR)[source]ο
Restrict allowed (item_a, item_b) value combinations per row.
valid_mapping maps each value of item_a to the sequence of allowed values in item_b.
- sloth.mmcif.validator.min_rows(n, severity=ValidationSeverity.ERROR)[source]ο
Category must contain at least n rows.
- Return type:
- Parameters:
n (int)
severity (ValidationSeverity)
- sloth.mmcif.validator.enumeration_check(item, allowed_values, severity=ValidationSeverity.ERROR)[source]ο
Values of item must be in allowed_values.
Mirrors the dictionary
_item_enumerationvalidation from the PDBeurope/mmcif-validator.
Cross-Category Rule Factoriesο
- sloth.mmcif.validator.foreign_key(child_item, parent_item, severity=ValidationSeverity.ERROR)[source]ο
Cross-checker: every non-null value of child_item in cat_a must exist in parent_item of cat_b.
Mirrors the FK integrity check from the PDBeurope/mmcif-validator.
- sloth.mmcif.validator.parent_child(severity=ValidationSeverity.ERROR)[source]ο
Cross-checker: if child category (cat_a) is present, parent category (cat_b) must also be present and non-empty.
Mirrors the parent/child category validation from the PDBeurope/mmcif-validator.
- Return type:
- Parameters:
severity (ValidationSeverity)
- sloth.mmcif.validator.composite_key(child_items, parent_items, severity=ValidationSeverity.ERROR)[source]ο
Cross-checker: each combination of child_items in cat_a must exist as a matching combination of parent_items in cat_b.
Mirrors the composite key validation from the PDBeurope/mmcif-validator.
- sloth.mmcif.validator.oper_expression(expression_item='oper_expression', oper_list_item='id', severity=ValidationSeverity.ERROR)[source]ο
Cross-checker: validate that operation expression references in cat_a all resolve to valid IDs in cat_b (
_pdbx_struct_oper_list).Parses expressions like
(1-60),(1,2,5),(X0)(1-5,11-15).Mirrors the oper_expression validation from the PDBeurope/mmcif-validator.
- sloth.mmcif.validator.cross_mandatory(required_items, severity=ValidationSeverity.ERROR)[source]ο
Cross-checker: required_items must exist in the second category.