entities.molecule.CalculationManager

entities.molecule.CalculationManager(entity)

Calculations that write attributes from the universe.

Works like a dictionary of functions by attribute name, so mol.calculations["name"] = func adds an updating calculation and del mol.calculations["name"] removes it.

Parameters

Name Type Description Default
entity Molecule The molecule the calculations write attributes on. required

Attributes

Name Description
ui_items The saved calculation items on the object, obj.mn.calculations.

Methods

Name Description
add Add a calculation, replacing any with the same name.
dssp Secondary structure from DSSP, as the sec_struct calculation.
from_text Add the BaseCalculation subclasses defined in a text block.
hbonds Hydrogen bonds from MDAnalysis, as the hbonds calculation.
refresh Run a calculation now and store its values, whether or not it updates.
set_updating Set whether a calculation recalculates on every frame change.
updating Whether a calculation recalculates on every frame change.

add

entities.molecule.CalculationManager.add(
    name,
    func,
    *,
    updating=True,
    refresh=True,
    data_object=None,
)

Add a calculation, replacing any with the same name.

A calculation that isn’t updating is run once now, an updating one on the next frame change.

Parameters

Name Type Description Default
name str Name of the attribute the calculation writes. required
func Callable[[Universe], np.ndarray | None] Function returning one value per atom, or writing data_object and returning None. required
updating bool Whether to recalculate on every frame change. True
refresh bool Whether to run a calculation that isn’t updating now. Without this the attribute keeps its current values until the next refresh. True
data_object bpy.types.Object Object the calculation writes rather than an attribute, recorded with its settings on the object. None

dssp

entities.molecule.CalculationManager.dssp(selection=None, *, updating=None)

Secondary structure from DSSP, as the sec_struct calculation.

Sets DSSP up if it isn’t already, and changes only the settings given. A trajectory whose files have no secondary structure has it set up on load, not updating, so it has run on the first frame.

Parameters

Name Type Description Default
selection str MDAnalysis selection string limiting the atoms DSSP is run on, "protein" when setting up. Use this to exclude termini or non-standard residues that lack the required (N, CA, C, O) atoms. Protein residues outside it are drawn as loops. None
updating bool Whether to recalculate on every frame change, True when setting up. Otherwise the values are kept from when it last ran. None

Returns

Name Type Description
DSSPCalculation The DSSP calculation, whose methods choose what is shown, such as show_sliding_window_average()

Examples

dssp = mol.calculations.dssp(updating=True)
dssp.show_trajectory_average(threshold=0.5)

from_text

entities.molecule.CalculationManager.from_text(text, *, updating=None)

Add the BaseCalculation subclasses defined in a text block.

The text is run as Python, with BaseCalculation and np already available, and each subclass it defines is added as a calculation named after the subclass, replacing any with the same name.

Parameters

Name Type Description Default
text bpy.types.Text or str The text block, or its name in bpy.data.texts. required
updating bool Whether the calculations recalculate on every frame change. Left out, a calculation that was already added keeps its setting, and a new one updates. None

Returns

Name Type Description
list[str] The names of the calculations that were added.

Raises

Name Type Description
ValueError When the text defines no BaseCalculation subclasses, or one of them returns a number of values other than the number of atoms.

hbonds

entities.molecule.CalculationManager.hbonds(
    selection=None,
    *,
    updating=None,
    **kwargs,
)

Hydrogen bonds from MDAnalysis, as the hbonds calculation.

Sets hydrogen bonds up if they aren’t already, and changes only the settings given. The calculation writes the bonds as edges on a data object, HBondCalculation.object, for the Style HBonds node to draw.

Parameters

Name Type Description Default
selection str MDAnalysis selection string limiting the atoms considered as hydrogens, donors and acceptors, "all" when setting up. None
updating bool Whether to recalculate on every frame change, True when setting up. Otherwise the bonds are kept from when it last ran. None
**kwargs Passed to MDAnalysis.analysis.hydrogenbonds.HydrogenBondAnalysis, overriding the defaults and any given before. The cutoffs d_a_cutoff (3.0 Å), d_h_a_angle_cutoff (150 degrees) and d_h_cutoff (1.2 Å) are stored as properties, adjustable in the Attributes panel, and see HBondCalculation.cutoffs. By default hydrogens (H or D), donors and acceptors (N or O) are selected by element, donors are paired with hydrogens by distance, and selections are not updated per frame. {}

Returns

Name Type Description
HBondCalculation The hydrogen bond calculation, whose object is the Data Object for a Style HBonds node

Raises

Name Type Description
ValueError When there are no hydrogens, which the analysis requires

Examples

hbonds = mol.calculations.hbonds(d_a_cutoff=3.5)
with mol.tree.reset() as (atoms, join):
    atoms >> StyleHBonds(data_object=hbonds.object) >> join

refresh

entities.molecule.CalculationManager.refresh(name)

Run a calculation now and store its values, whether or not it updates.

set_updating

entities.molecule.CalculationManager.set_updating(name, updating)

Set whether a calculation recalculates on every frame change.

updating

entities.molecule.CalculationManager.updating(name)

Whether a calculation recalculates on every frame change.