htmd.projections.metric module#

class htmd.projections.metric.Metric(simulations, skip=1, metricdata=None)#

Bases: object

Class for calculating projections of a simlist.

Parameters:
  • simulations (list | ndarray | Molecule) – A list of simulations produced by simlist, or a single Molecule.

  • skip (int) – Frame skipping. Setting to 3 will keep only every third frame of each simulation.

  • metricdata (MetricData | None) – If a MetricData object is passed in the constructor, Metric will try to update it by only adding simulations which do not exist in it yet.

Examples

>>> metr = Metric(sims)
>>> metr.set(MetricSelfDistance('protein and name CA', metric='contacts'))
>>> data = metr.project()
>>>
>>> # Or define your own function which accepts as first argument a Molecule object. Further arguments are passed as
>>> # function/argument tuples
>>> def foo(mol, ref):
>>>     from moleculekit.util import molRMSD
>>>     mol.wrap('protein')
>>>     mol.align('protein and name CA', refmol=ref)
>>>     return molRMSD(mol, ref, mol.atomselect('protein and name CA'), ref.atomselect('protein and name CA'))
>>>
>>> metr = Metric(sims)
>>> metr.set( (foo, (ref,)) )
>>> data2 = metr.project()

Methods

Attributes

getMapping(mol)#

Return the description of each projected dimension.

Parameters:

mol (Molecule | None) – A Molecule object used to calculate the descriptions of the projected dimensions. If None, returns None.

Returns:

map – A DataFrame containing the descriptions of each dimension.

Return type:

DataFrame | None

project(njobs=None)#

Apply all projections stored in Metric on all simulations.

Parameters:

njobs (int | None) – Number of parallel jobs to spawn for projection of trajectories. Take care that this can use large amounts of memory as multiple trajectories are loaded at once. If None it will use the default from htmd.config.

Returns:

data – A MetricData object containing the projected data.

Return type:

MetricData

set(projection)#

Set the projection to be applied to the simulations.

Parameters:

projection (Projection object or list) – A function, a Projection object, or a list of projections/functions to apply to the simulations. Can also be a (function, args) tuple.