CCD Utilities#

atomworks.io.utils.ccd.aa_chem_comps() frozenset[str][source]#

Set of amino acid chemical components.

Returns:

Set of amino acid chemical components (e.g., {‘ALA’, ‘ARG’, …}).

atomworks.io.utils.ccd.add_annotations_from_ccd(atom_array: AtomArray, annotations: list[str] | None = None, overwrite: dict[str, bool] | bool = False, ccd_mirror_path: PathLike = None, hydrogen_policy: Literal['keep', 'remove'] = 'keep', on_mismatch: Literal['ignore', 'error_heavy', 'error'] = 'ignore', match_alt_atom_ids: bool = False) AtomArray[source]#

Add CCD structural annotations to atoms in an existing AtomArray.

Matches atoms to CCD templates by residue and copies specified annotations.

Parameters:
  • atom_array – Structure to annotate.

  • annotations – List of annotation names to add. If None, adds all core structural annotations: ["charge", "stereo", "is_aromatic", "is_leaving_atom", "is_backbone_atom", "is_n_terminal_atom", "is_c_terminal_atom", "nhyd"].

  • overwrite – Control overwriting of existing annotations. If bool, applies to all. If dict, maps annotation name to overwrite policy. Example: {"charge": False, "stereo": True} keeps existing charges but overwrites stereochemistry. Defaults to False.

  • ccd_mirror_path – Path to local CCD mirror.

  • hydrogen_policy – Whether to use the "keep" or "remove" CCD template. When "remove", the template has nhyd set on heavy atoms so that implicit H counts are copied to atom_array before bond inference.

  • on_mismatch

    How to handle residue atoms whose names are not in the CCD template. One of:

    • "ignore" (default): silently skip unmatched atoms (debug log only).

    • "error_heavy": raise ValueError if any unmatched atom is a heavy atom

    • "error": raise ValueError on any unmatched atom.

  • match_alt_atom_ids – If True, residue atoms whose names don’t match the template’s atom_name column are also matched against the template’s alt_atom_id column. Defaults to False.

Returns:

AtomArray with CCD annotations added (modified in-place).

Raises:

ValueError – If on_mismatch is "error" or "error_heavy" and unmatched atoms are found.

atomworks.io.utils.ccd.atom_array_from_ccd_code(ccd_code: str, ccd_mirror_path: PathLike = None, **parse_ccd_cif_kwargs) AtomArray[source]#

Retrieves a component from the Chemical Component Dictionary.

Checks custom registry first (overriding standard CCD), then uses the local mirror if configured (never falling back to biotite), or biotite if no mirror and allowed.

Parameters:
  • ccd_code – The chemical component code

  • ccd_mirror_path – Path to local CCD mirror

  • **parse_ccd_cif_kwargs – Additional args passed to parse_ccd_cif()

Returns:

AtomArray of the requested component

Note

Registry entries override standard CCD definitions. Use register_custom_ccd_entry() to provide custom templates that will be used instead of standard CCD data.

atomworks.io.utils.ccd.build_ccd_entries_from_cif_block(cif_block: CIFBlock, on_mismatch: Literal['ignore', 'error_heavy', 'error'] = 'error_heavy') dict[str, AtomArray][source]#

Build per-residue CCD-style AtomArray templates from a CIF’s chem_comp* categories.

One entry per comp_id in chem_comp_atom (authored rows override the bundled CCD); missing annotation columns are supplemented from the bundled CCD.

Parameters:

on_mismatch – How authored atoms absent from the bundled template are handled. "error_heavy" (default) raises — a mismatch in curated inputs signals a bad block; "ignore" keeps them, for custom ligands that reuse a real CCD code.

Raises:

ValueError – If chem_comp_atom is present without chem_comp.

atomworks.io.utils.ccd.check_ccd_codes_are_available(ccd_codes: Iterable[str], ccd_mirror_path: PathLike = None, mode: Literal['warn', 'raise'] = 'warn') bool[source]#

Checks if the provided CCD codes are available in the current environment

atomworks.io.utils.ccd.chem_comp_to_one_letter() dict[str, str][source]#

Dictionary mapping the chemical components to their 1-letter code.

Note

Chemical components historically used to be 3-letter codes, but nowadays longer codes exist.

Returns:

Dictionary mapping chemical component names to their 1-letter codes.

References

RCSB Chemical Component Dictionary Biotite CCD Module

atomworks.io.utils.ccd.clear_custom_ccd_registry() int[source]#

Clear all custom CCD entries. Returns number of entries cleared.

atomworks.io.utils.ccd.custom_ccd_residues(entries: dict[str, AtomArray]) Generator[None, None, None][source]#

Temporarily register custom CCD entries. Restores registry state on exit.

Parameters:

entries – Dict mapping CCD codes to AtomArrays.

Example

>>> with custom_ccd_residues({"ALA": custom_ala, "GLY": custom_gly}):
...     ala = atom_array_from_ccd_code("ALA")
atomworks.io.utils.ccd.dna_chem_comps() frozenset[str][source]#

Set of DNA chemical components.

Returns:

Set of DNA chemical components (e.g., {‘DA’, ‘DC’, …}).

atomworks.io.utils.ccd.get_atom_names_for_residue(res_name: str, ccd_mirror_path: str) tuple[frozenset[str], frozenset[str], dict[str, str]][source]#

Get atom name sets and alt→standard mapping from a CCD template.

Parameters:
  • res_name – Residue name (3-letter code).

  • ccd_mirror_path – Path to CCD mirror (as string), or empty string to use Biotite’s built-in CCD.

Returns:

Tuple of (std_names_set, alt_names_set, alt_to_std_mapping). Returns (frozenset(), frozenset(), {}) if template unavailable.

atomworks.io.utils.ccd.get_available_ccd_codes(ccd_mirror_path: PathLike | None = None) frozenset[str][source]#

Returns all available CCD codes including registry entries.

atomworks.io.utils.ccd.get_available_ccd_codes_in_biotite() frozenset[str][source]#

Set of all CCD codes available in Biotite’s built-in Chemical Component Dictionary.

atomworks.io.utils.ccd.get_available_ccd_codes_in_mirror(ccd_mirror_path: PathLike = None) frozenset[str][source]#

Set of all CCD codes available in the local mirror.

Only counts codes when they adhere to the CCD mirror layout (e.g. …/H/HEM/HEM.cif)

Parameters:

ccd_mirror_path – Path to the CCD mirror directory.

Returns:

Set of all available CCD codes in the mirror.

References

RCSB Chemical Component Dictionary CCD Mirror Layout

atomworks.io.utils.ccd.get_ccd_component_from_biotite(ccd_code: str, **parse_ccd_cif_kwargs) AtomArray[source]#

Retrieves a component from the Chemical Component Dictionary using Biotite’s built-in CCD.

Parameters:

ccd_code (-) – The three-letter code of the chemical component to retrieve.

Returns:

The atomic structure of the requested component.

Return type:

  • AtomArray

atomworks.io.utils.ccd.get_ccd_component_from_mirror(ccd_code: str, ccd_mirror_path: PathLike = None, **parse_ccd_cif_kwargs) AtomArray[source]#

Retrieves and parses a component from a local mirror of the Chemical Component Dictionary.

Parameters:
  • ccd_code – The three-letter code of the chemical component.

  • ccd_mirror_path – Path to the root of the CCD mirror directory.

  • **parse_ccd_cif_kwargs

    Additional keyword arguments passed to parse_ccd_cif(): coords: Type of coordinates to use (“model”, “ideal_pdbx”, “ideal_rdkit”, or None).

    Defaults to “ideal_pdbx”.

    add_properties: Whether to include RDKit-computed properties. Defaults to True. add_mapping: Whether to include external resource mappings, such as e.g. the ChEMBL ID.

    Defaults to False.

Returns:

The parsed atomic structure of the requested component.

Return type:

AtomArray

Example

>>> atom_array = get_ccd_component_from_mirror("ALA", coords="ideal_pdbx")
atomworks.io.utils.ccd.get_ccd_descriptors(ccd_code: str, ccd_mirror_path: PathLike = None) dict[str, str][source]#

Extract SMILES and InChI descriptors from a CCD entry.

Parses the _pdbx_chem_comp_descriptor category to retrieve molecular descriptors. Available descriptor types depend on the CCD entry.

Parameters:
  • ccd_code – The CCD code for the component.

  • ccd_mirror_path – Path to the local CCD mirror.

Returns:

Dictionary with descriptor types as keys and descriptor values as values. Common keys include: “SMILES”, “SMILES_CANONICAL”, “InChI”, “InChIKey”. Returns empty dict if the CCD code is not found or has no descriptors.

Example

>>> get_ccd_descriptors("ATP")
{'SMILES_CANONICAL': 'Nc1ncnc2c1ncn2...', 'InChI': 'InChI=1S/...', ...}
atomworks.io.utils.ccd.get_chain_type_from_ccd_code(ccd_code: str, ccd_mirror_path: PathLike = None) ChainType[source]#

Get the ChainType enum corresponding to a CCD code.

atomworks.io.utils.ccd.get_chain_type_from_chem_comp_type(chem_comp_type: str) ChainType[source]#

Get the ChainType enum corresponding to a chemical component type.

atomworks.io.utils.ccd.get_chem_comp_type(ccd_code: str, atom_names: set[str] | None = None, mode: Literal['warn', 'raise'] = 'warn', ccd_mirror_path: PathLike = None) str[source]#

Get the chemical component type for a CCD code.

Routes through atom_array_from_ccd_code() so the custom CCD registry is the single interception point. Falls back to inference from atom_names when the code is unknown.

Parameters:
  • ccd_code – The CCD code for the component. E.g. "ALA" for alanine.

  • atom_names – Atom names used to infer the type when the code is not in the CCD.

  • mode – How to handle unknown chemical component types.

  • ccd_mirror_path – Path to the local CCD mirror directory.

Example

>>> get_chem_comp_type("ALA")
'L-PEPTIDE LINKING'
atomworks.io.utils.ccd.get_custom_ccd_entries() frozenset[str][source]#

Get set of currently registered custom CCD codes.

atomworks.io.utils.ccd.get_parent_comp_id(ccd_code: str, ccd_mirror_path: PathLike = None) str | None[source]#

Return the canonical parent residue for a modified CCD code, or None.

Uses the local CCD mirror when configured, falling back to biotite’s built-in CCD.

atomworks.io.utils.ccd.get_parent_template_atom_names(parent_code: str, ccd_mirror_path: str = '', hydrogen_policy: Literal['keep', 'remove'] = 'remove') set[str][source]#

Return the set of atom names from a parent CCD template.

atomworks.io.utils.ccd.get_polymerization_atoms(res_name: str) tuple[str, str] | None[source]#

Return the (leaving_atom, entering_atom) pair for a polymer bond, or None.

Looks up the chemical component type via :pyfunc:`get_chem_comp_type` and checks CHEM_TYPE_POLYMERIZATION_ATOMS, falling back to ChainTypeInfo.ATOMS_AT_POLYMER_BOND.

atomworks.io.utils.ccd.get_standard_ccd_codes(ccd_mirror_path: PathLike | None = None) frozenset[str][source]#

Returns standard CCD codes (from mirror + Biotite). Cached.

atomworks.io.utils.ccd.get_std_to_alt_atom_name_map(ccd_code: str, ccd_mirror_path: PathLike = None) dict[str, str][source]#

Get a map from standard atom names to alternative atom names.

atomworks.io.utils.ccd.get_unknown_ccd_code_for_chem_comp_type(chem_comp_type: str) str[source]#

Get the CCD code for an unknown chemical component type.

atomworks.io.utils.ccd.is_parent_strict_atom_subset(child_code: str, parent_code: str, ccd_mirror_path: str = '', hydrogen_policy: Literal['keep', 'remove'] = 'remove') bool[source]#

Check if the parent template’s heavy-atom names are a strict subset of the child’s.

Parameters:
  • child_code – Modified residue CCD code (e.g. "ASB").

  • parent_code – Parent residue CCD code (e.g. "ASP").

  • ccd_mirror_path – Path to CCD mirror, or empty string for Biotite’s built-in.

  • hydrogen_policy – Hydrogen handling for templates.

atomworks.io.utils.ccd.na_chem_comps() frozenset[str][source]#

Set of nucleic acid chemical components.

Returns:

Set of nucleic acid chemical components (e.g., {‘DA’, ‘DC’, …}).

atomworks.io.utils.ccd.parse_ccd_cif(cif: CIFFile, coords: Literal['model', 'ideal_pdbx', 'ideal_rdkit'] | None | tuple[str, ...] = ('ideal_pdbx', 'model', 'ideal_rdkit'), add_properties: bool = False, add_mapping: bool = False) AtomArray[source]#

Parses a Chemical Component Dictionary CIF file into a Biotite AtomArray structure.

Parameters:
  • cif – The CIF file containing the component data.

  • coords – Type of coordinates to use. Defaults to (“ideal_pdbx”, “model”, “ideal_rdkit”). Can be a single coordinate type or a tuple of fallback preferences (e.g., (“ideal_pdbx”, “model”, “ideal_rdkit”)). - “model”: Use the coordinates that are found in a random (but fixed) pdb file. - “ideal_pdbx”: Use the idealized coordinates computed by the RCSB PDB (sometimes not available). - “ideal_rdkit”: Use the idealized coordinates computed by RDKit (sometimes unrealistic).

  • add_properties – Whether to include RDKit-computed properties. Defaults to False. Properties are available under the properties attribute of the returned AtomArray.

  • add_mapping – Whether to include external resource mappings, such as e.g. the ChEMBL ID. Defaults to False. Mappings are available under the mapping attribute of the returned AtomArray.

Returns:

The parsed atomic structure with requested annotations and properties.

Return type:

AtomArray

Example

>>> cif = pdbx.CIFFile.read("path/to/ALA.cif")
>>> atom_array = parse_ccd_cif(cif, coords="ideal_pdbx")
>>> # With fallback preferences:
>>> atom_array = parse_ccd_cif(cif, coords=["ideal_pdbx", "model", "ideal_rdkit"])
atomworks.io.utils.ccd.register_custom_ccd_entries(entries: dict[str, AtomArray]) None[source]#

Register multiple custom CCD entries at once.

atomworks.io.utils.ccd.register_custom_ccd_entry(code: str, atom_array: AtomArray) None[source]#

Register a custom CCD entry to override/supplement standard CCD lookups.

atomworks.io.utils.ccd.register_custom_residues_from_atom_array(atom_array: AtomArray, ccd_mirror_path: PathLike = None) list[str][source]#

Extract and register non-standard residues from AtomArray.

Compares residue names against standard CCD codes only (not registry). This allows re-registration/overwriting of custom residues.

Parameters:
  • atom_array – Structure containing residues to extract.

  • ccd_mirror_path – Path to CCD mirror for standard codes check.

Returns:

List of CCD codes that were successfully registered.

atomworks.io.utils.ccd.rna_chem_comps() frozenset[str][source]#

Set of RNA chemical components.

Returns:

Set of RNA chemical components (e.g., {‘A’, ‘C’, …}).

atomworks.io.utils.ccd.snapshot_custom_ccd_registry() dict[str, AtomArray][source]#

Return a deep copy of the current custom CCD registry.

atomworks.io.utils.ccd.unregister_custom_ccd_entry(code: str) bool[source]#

Unregister a custom CCD entry. Returns True if entry existed.