Modifier

Module

viennaptm.modification.application.modifier
class Modifier(library: ModificationLibrary = None)

Bases: BaseModel

Applies residue-level chemical modifications to a biomolecular structure.

The Modifier class acts as a high-level interface between a ModificationLibrary and an annotated structure. It locates a specific residue within a structure, removes hydrogen atoms from the target residue, applies the requested modification using a template residue, and records the modification in the structure’s modification log.

Parameters:

library (ModificationLibrary, optional) – Library containing residue modification definitions and template residues. If None, an internal default ModificationLibrary is loaded.

static atoms_to_array(atoms: List[Atom]) ndarray

Convert a list of atoms to a NumPy coordinate array.

Parameters:

atoms (list[Atom]) – Atoms whose coordinates should be extracted.

Returns:

Array of shape (n_atoms, 3) containing atomic coordinates.

Return type:

numpy.ndarray

get_library()

Return the associated modification library.

Returns:

The library used by this Modifier instance.

Return type:

ModificationLibrary

model_config = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

modify(structure: AnnotatedStructure, chain_identifier: str, residue_number: int, target_abbreviation: str, inplace: bool = True) AnnotatedStructure

Apply a residue modification to a structure.

This method locates a residue by chain identifier and residue number, removes all hydrogen atoms, applies a modification defined in the modification library, and optionally returns a modified copy of the structure.

Parameters:
  • structure (AnnotatedStructure) – The structure to be modified.

  • chain_identifier (str) – Chain identifier of the target residue (commonly a single uppercase letter).

  • residue_number (int) – Position of the residue in the polypeptide chain, Residue number as defined in the structure (PDB numbering).

  • target_abbreviation (str) – Three-letter abbreviation of the target (modified) residue.

  • inplace (bool) – If True, the structure is modified in place. If False, a deep copy of the structure is created and modified.

Returns:

The modified structure. This is either the original structure (if inplace=True) or a modified copy.

Return type:

AnnotatedStructure

Raises:
  • ValueError – If no residue matching the given chain identifier and residue number can be found in the structure.

  • KeyError – If atom names required for the modification do not match those in the structure or the template residue.

Note

This method assumes that:

  • Chain identifiers are unique across all models.

  • A template PDB exists for every supported modification.

  • The structure supports modification logging via add_to_modification_log.

static remove_hydrogens(residue: Residue)

Remove all hydrogen atoms from a residue.

Hydrogen atoms are identified by atom names starting with "H". This step avoids inconsistencies in atom naming schemes during modification.

Parameters:

residue (Residue) – Residue from which hydrogen atoms will be removed.

Methods

__init__([library])

Initialize a Modifier instance.

atoms_to_array(atoms)

Convert a list of atoms to a NumPy coordinate array.

construct([_fields_set])

copy(*[, include, exclude, update, deep])

Returns a copy of the model.

dict(*[, include, exclude, by_alias, ...])

from_orm(obj)

get_library()

Return the associated modification library.

json(*[, include, exclude, by_alias, ...])

model_construct([_fields_set])

Creates a new instance of the Model class with validated data.

model_copy(*[, update, deep])

!!! abstract "Usage Documentation"

model_dump(*[, mode, include, exclude, ...])

!!! abstract "Usage Documentation"

model_dump_json(*[, indent, ensure_ascii, ...])

!!! abstract "Usage Documentation"

model_json_schema(by_alias, ref_template, ...)

Generates a JSON schema for a model class.

model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

model_post_init(context, /)

Override this method to perform additional initialization after __init__ and model_construct.

model_rebuild(*[, force, raise_errors, ...])

Try to rebuild the pydantic-core schema for the model.

model_validate(obj, *[, strict, extra, ...])

Validate a pydantic model instance.

model_validate_json(json_data, *[, strict, ...])

!!! abstract "Usage Documentation"

model_validate_strings(obj, *[, strict, ...])

Validate the given object with string data against the Pydantic model.

modify(structure, chain_identifier, ...[, ...])

Apply a residue modification to a structure.

parse_file(path, *[, content_type, ...])

parse_obj(obj)

parse_raw(b, *[, content_type, encoding, ...])

remove_hydrogens(residue)

Remove all hydrogen atoms from a residue.

schema([by_alias, ref_template])

schema_json(*[, by_alias, ref_template])

update_forward_refs(**localns)

validate(value)