pyemma.coordinates.data.CustomFeature¶
-
class
pyemma.coordinates.data.
CustomFeature
(func=None, *args, **kwargs)¶ A CustomFeature is the base class for user-defined features. If you want to implement a new fancy feature, derive from this class, calculate the quantity of interest in the map method and return it as an ndarray.
If you have defined a map function that should be classed, you don’t need to derive a class, but you can simply pass a function to the constructor of this class
Parameters: - func (function) – will be invoked with given args and kwargs on mapping traj
- args (list of positional args (optional) passed to func) –
- kwargs (named arguments (optional) passed to func) –
Notes
Your passed in function will get a mdtraj.Trajectory object as first argument.
Examples
We define a feature that transforms all coordinates by \(1 / x^2\):
>>> from pyemma.coordinates import source >>> from pyemma.datasets import get_bpti_test_data >>> inp = get_bpti_test_data()
Define a function which transforms the coordinates of the trajectory object. Note that you need to define the output dimension, which we pass directly in the feature construction. The trajectory contains 58 atoms, so the output dimension will be 3 * 58 = 174:
>>> my_feature = CustomFeature(lambda x: (1.0 / x.xyz**2).reshape(-1, 174), dim=174) >>> reader = source(inp['trajs'][0], top=inp['top'])
pass the feature to the featurizer and transform the data
>>> reader.featurizer.add_custom_feature(my_feature) >>> data = reader.get_output()
-
__init__
(func=None, *args, **kwargs)¶
Methods
__init__
([func])describe
()map
(traj)transform
(traj)Attributes
dimension