vermouth.processors.sort_molecule_atoms module

Provides a processor that sorts atoms within molecules.

class vermouth.processors.sort_molecule_atoms.SortMoleculeAtoms(sortby_attrs=('chain', 'resid', 'resname', 'insertion_code', 'atomid'), target_attr=None)[source]

Bases: Processor

Sort the atoms within a molecule by the attributes listed in the sortby_attrs. Optionally, new atom indices are assigned to the node attribute target_attr.

Sorting nodes is useful because a lot of software assumes chains and residues are listed contiguously. In particular this gets important when we add atoms — for instance missing atoms identified by vermouth.processors.repair_graph.RepairGraph).

Nodes in the molecule are reordered according to the node attributes listed in sortby_attrs. The atom keys are left identical, only the order of the nodes is changed. Optionally, the new indices can be assigned to nodes target_attr attribute.


Nodes will be sorted by these node attributes.



If not None, new indices will be assigned to this node attribute, starting with 1. It is a good idea to make sure this attribute is also listed in sortby_attrs so that the sorting is stable.