pyemma.coordinates.data.CustomFeature

class pyemma.coordinates.data.CustomFeature(*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 \(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: (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__(fun, dim, description=None, fun_args=(), fun_kwargs=None)

Initialize self. See help(type(self)) for accurate signature.

Methods

_SerializableMixIn__interpolate(state, klass)

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(other)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getstate__()

__gt__(value, /)

Return self>value.

__init__(fun, dim[, description, fun_args, …])

Initialize self.

__init_subclass__(*args, **kwargs)

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__ne__(value, /)

Return self!=value.

__new__(cls, *args, **kwargs)

Create and return a new object.

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__setattr__(name, value, /)

Implement setattr(self, name, value).

__setstate__(state)

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

_get_classes_to_inspect()

gets classes self derives from which 1.

_get_interpolation_map(cls)

_get_private_field(cls, name[, default])

_get_serialize_fields(cls)

_get_state_of_serializeable_fields(klass, state)

:return a dictionary {k:v} for k in self.serialize_fields and v=getattr(self, k)

_get_version(cls[, require])

_get_version_for_class_from_state(state, klass)

retrieves the version of the current klass from the state mapping from old locations to new ones.

_set_state_from_serializeable_fields_and_state(…)

set only fields from state, which are present in klass.__serialize_fields

describe()

load(file_name[, model_name])

Loads a previously saved PyEMMA object from disk.

save(file_name[, model_name, overwrite, …])

saves the current state of this object to given file and name.

transform(traj)

Attributes

_CustomFeature__serialize_fields

_CustomFeature__serialize_version

_Feature__serialize_fields

_Feature__serialize_version

_SerializableMixIn__serialize_fields

_SerializableMixIn__serialize_modifications_map

_SerializableMixIn__serialize_version

__dict__

__doc__

__hash__

__module__

__weakref__

list of weak references to the object (if defined)

_id

_save_data_producer

dimension

top