Base Classes

These abstract base classes define the common interfaces that all SLOTH implementations must follow.

class sloth.mmcif.common.BaseParser[source]

Bases: ABC

Abstract base class for mmCIF parsers.

All parser implementations (MMCIFParser, GemmiParser, etc.) must inherit from this class and implement the required abstract methods.

__init__(categories=None)[source]

Initialize the parser.

Parameters:

categories (Optional[list]) – Optional list of categories to parse (for performance)

abstract parse(file_path)[source]

Parse mmCIF file and return a data container.

Parameters:

file_path (Union[str, Path]) – Path to the mmCIF file to parse

Returns:

The data container with parsed mmCIF data

Return type:

MMCIFDataContainer

class sloth.mmcif.common.BaseWriter[source]

Bases: ABC

Abstract base class for mmCIF writers.

All writer implementations (MMCIFWriter, GemmiWriter, etc.) must inherit from this class and implement the required abstract methods.

abstract write(file_obj, mmcif)[source]

Write mmCIF data container to a file object.

Parameters:
  • file_obj (IO) – The file object to write to

  • mmcif (MMCIFDataContainer) – The data container to write

Return type:

None

Returns:

None

class sloth.mmcif.common.BaseImporter[source]

Bases: ABC

Abstract base class for all SLOTH importers.

__init__(dict_path=None, cache_dir=None, quiet=False)[source]

Initialize the importer.

Parameters:
  • dict_path (Union[str, Path, None]) – Path to mmCIF dictionary file

  • cache_dir (Optional[str]) – Directory for caching

  • quiet (bool) – Suppress output messages

abstract import_data(data)[source]

Import data back to mmCIF format.

Parameters:

data (Union[str, Dict[str, Any], Path]) – Data to import (string, dict, or file path)

Return type:

MMCIFDataContainer

Returns:

MMCIFDataContainer with imported data

class sloth.mmcif.common.BaseExporter[source]

Bases: ABC

Abstract base class for all SLOTH exporters.

__init__(dict_path=None, cache_dir=None, quiet=False)[source]

Initialize the exporter.

Parameters:
  • dict_path (Union[str, Path, None]) – Path to mmCIF dictionary file

  • cache_dir (Optional[str]) – Directory for caching

  • quiet (bool) – Suppress output messages

abstract export_data(mmcif_data, file_path=None, nested=True, **kwargs)[source]

Export mmCIF data to target format.

Parameters:
  • mmcif_data (MMCIFDataContainer) – The mmCIF data container to export

  • file_path (Union[str, Path, None]) – Path to save the file (optional)

  • nested (bool) – Whether to use nested structure

  • **kwargs – Additional format-specific options

Return type:

Optional[str]

Returns:

String representation if no file_path provided, otherwise None