torchref.restraints.library module

Monomer Library Manager for TorchRef.

Manages access to the CCP4 Monomer Library restraint dictionaries with a priority-based resolution strategy. Standard amino acids and nucleotides are bundled as package data; non-standard residues are downloaded on demand from the MonomerLibrary GitHub repository and cached locally.

The monomer library provides ideal geometry parameters (bond lengths, angles, torsions, planes, chirals) derived from the Cambridge Structural Database.

References

Long, F., et al. (2017). AceDRG: a stereochemical description generator

for ligands. Acta Cryst. D73, 112-122.

class torchref.restraints.library.MonomerLibraryManager(verbose=1)[source]

Bases: object

Manages access to the CCP4 Monomer Library with priority-based resolution.

Resolution priority for individual CIF files: 1. TORCHREF_MONOMER_LIB environment variable (local library install) 2. Bundled package data (standard amino acids, nucleotides) 3. User cache (~/.cache/torchref/monomer_library/) 4. Legacy external_monomer_library/ directory 5. On-demand download from GitHub (cached for future use)

Parameters:

verbose (int, optional) – Verbosity level. 0 = silent, 1 = warnings, 2 = info. Default 1.

__init__(verbose=1)[source]
get_cif_file(resname)[source]

Resolve the CIF file path for a given residue name.

Parameters:

resname (str) – Residue name (e.g., ‘ALA’, ‘GLY’, ‘ATP’).

Returns:

Path to the CIF file, or None if not found anywhere.

Return type:

Path or None

Resolve the path to mon_lib_list.cif (inter-residue link definitions).

Returns:

Path to mon_lib_list.cif.

Return type:

Path

Raises:

FileNotFoundError – If the file cannot be found or downloaded.

property monomer_dir

Return a directory path suitable for monomer library access.

Prefers environment variable, then bundled data, then legacy path. This is provided for backward compatibility with code that expects a directory path rather than individual file resolution.

Returns:

Path to the monomer library root directory.

Return type:

Path

torchref.restraints.library.get_library_manager(verbose=1)[source]

Get the global MonomerLibraryManager singleton.

Parameters:

verbose (int, optional) – Verbosity level (only used on first call).

Return type:

MonomerLibraryManager