Provides a processor that generates positions for nodes based on the weighted average of the positions of the atoms they are constructed from.

class vermouth.processors.average_beads.DoAverageBead(ignore_missing_graphs=False, weight=None)[source]
run_molecule(molecule)[source]
vermouth.processors.average_beads.do_average_bead(molecule, ignore_missing_graphs=False, weight=None)[source]

Set the position of the particles to the mean of the underlying atoms.

This requires the atoms to have a ‘graph’ attributes. By default, a ValueError is raised if any atom in the molecule is missing that ‘graph’ attribute. This behavior can be changed by setting the ‘ignore_missing_graphs’ argument to True, then the average positions are computed, but the atoms without a ‘graph’ attribute are skipped.

The average is weighted using the ‘mapping_weights’ atom attribute. If the ‘mapping_weights’ attribute is set, it has to be a dictionary with the atomname from the underlying graph as keys, and the weights as values. Atoms without a weight set use a default weight of 1.

The average can also be weighted using an arbitrary node attribute by giving the attribute name with the weight keyword argument. This can be used to get the center of mass for instance; assuming the mass of the underlying atoms is stored under the “mass” attribute, setting weight to “mass” will place the bead at the center of mass. By default, weight is set to None and the center of geometry is used.

The atoms in the underlying graph must have a position. If they do not, they are ignored from the average.

Parameters: molecule (vermouth.molecule.Molecule) – The molecule to update. The attribute position of the particles is updated on place. The nodes of the molecule must have an attribute graph that contains the subgraph of the initial molecule. ignore_missing_graphs (bool) – If True, skip the atoms that do not have a graph attribute; else fail if not all the atoms in the molecule have a graph attribute. weight (collections.abc.Hashable) – The name of the attribute used to weight the position of the node. The attribute is read from the underlying atoms.