HierarchyScheme
- class openff.toolkit.topology.HierarchyScheme(parent: Molecule | FrozenMolecule | _SimpleMolecule, uniqueness_criteria: Iterable[str], iterator_name: str)[source]
Perceives hierarchy elements from the metadata of atoms in a
Molecule
.The Open Force Field Toolkit has no native understanding of hierarchical atom organisation schemes common to other biomolecular software, such as “residues” or “chains” (see Hierarchy data (chains and residues)). To facilitate iterating over groups of atoms, a
HierarchyScheme
can be used to collect atoms intoHierarchyElements
, groups of atoms that share the same values for certain metadata elements. Metadata elements are stored in theAtom.properties
attribute.Hierarchy schemes are not updated dynamically; if a
Molecule
with hierarchy schemes changes,Molecule.update_hierarchy_schemes()
must be called before the scheme is iterated over again or else the grouping may be incorrect.A
HierarchyScheme
contains the information needed to perceiveHierarchyElement
objects from aMolecule
containing atoms with metadata.See also
Molecule.add_default_hierarchy_schemes
,Molecule.add_hierarchy_scheme
,Molecule.hierarchy_schemes
,Molecule.delete_hierarchy_scheme
,Molecule.update_hierarchy_schemes
,Molecule.perceive_residues
,Topology.hierarchy_iterator
,HierarchyElement
- __init__(parent: Molecule | FrozenMolecule | _SimpleMolecule, uniqueness_criteria: Iterable[str], iterator_name: str)[source]
Create a new hierarchy scheme for iterating over groups of atoms.
- Parameters:
parent – The
Molecule
to which this scheme belongs.uniqueness_criteria – The names of
Atom
metadata entries that define this scheme. An atom belongs to aHierarchyElement
only if its metadata has the same values for these criteria as the other atoms in theHierarchyElement
.iterator_name – The name of the iterator that will be exposed to access the hierarchy elements generated by this scheme
Methods
__init__
(parent, uniqueness_criteria, ...)Create a new hierarchy scheme for iterating over groups of atoms.
add_hierarchy_element
(identifier, atom_indices)Instantiate a new HierarchyElement belonging to this HierarchyScheme.
Prepare the parent
Molecule
for iteration according to this scheme.Semantically sort the HierarchyElements belonging to this object, according to their identifiers.
to_dict
()Serialize this object to a basic dict of strings, ints, and floats
- perceive_hierarchy()[source]
Prepare the parent
Molecule
for iteration according to this scheme.Groups the atoms of the parent of this
HierarchyScheme
according to their metadata, and createsHierarchyElement
objects suitable for iteration over the parent. Atoms missing the metadata fields in this object’suniqueness_criteria
tuple will have those spots populated with the string'None'
.This method overwrites the scheme’s
hierarchy_elements
attribute in place. EachHierarchyElement
in the scheme’s hierarchy_elements attribute is static — that is, it is updated only when perceive_hierarchy() is called, and not on-the-fly when atom metadata is modified.
- add_hierarchy_element(identifier: tuple[Union[str, int]], atom_indices: Sequence[int]) HierarchyElement [source]
Instantiate a new HierarchyElement belonging to this HierarchyScheme.
This is the main way to instantiate new HierarchyElements.
- Parameters:
identifier – tuple of metadata values (not keys) that define the uniqueness criteria for this element
atom_indices – The indices of atoms in
scheme.parent
that are in this element
- sort_hierarchy_elements()[source]
Semantically sort the HierarchyElements belonging to this object, according to their identifiers.