pyemma.coordinates.data.FeatureReader¶
-
class
pyemma.coordinates.data.
FeatureReader
(trajectories, topologyfile=None, chunksize=100, featurizer=None)¶ Reads features from MD data.
To select a feature, access the
featurizer
and call a feature selecting method (e.g) distances.Parameters: - trajectories (list of strings) – paths to trajectory files
- topologyfile (string) – path to topology file (e.g. pdb)
Examples
>>> from pyemma.datasets import get_bpti_test_data
Iterator access:
>>> reader = FeatureReader(get_bpti_test_data()['trajs'], get_bpti_test_data()['top'])
Optionally set a chunksize
>>> reader.chunksize = 300
Store chunks by their trajectory index
>>> chunks = {i : [] for i in range(reader.number_of_trajectories())} >>> for itraj, X in reader: ... chunks[itraj].append(X)
Calculate some distances of protein during feature reading:
>>> reader.featurizer.add_distances([[0, 3], [10, 15]]) >>> X = reader.get_output()
-
__init__
(trajectories, topologyfile=None, chunksize=100, featurizer=None)¶
Methods
__init__
(trajectories[, topologyfile, ...])describe
()Returns a description of this transformer dimension
()Returns the number of output dimensions get_output
([dimensions, stride, skip, chunk])iterator
([stride, lag, chunk, ...])n_frames_total
([stride])Returns the total number of frames, over all trajectories number_of_trajectories
()Returns the number of trajectories output_type
()By default transformers return single precision floats. register_progress_callback
(call_back[, stage])Registers the progress reporter. trajectory_length
(itraj[, stride, skip])Returns the length of trajectory trajectory_lengths
([stride, skip])Returns the length of each trajectory write_to_csv
([filename, extension, ...])write all data to csv with numpy.savetxt Attributes
SUPPORTED_RANDOM_ACCESS_FORMATS
chunksize
data_producer
The data producer for this data source object (can be another data source object). default_chunksize
filenames
Property which returns a list of filenames the data is originally from. in_memory
are results stored in memory? is_random_accessible
Check if self._is_random_accessible is set to true and if all the random access strategies are implemented. is_reader
Property telling if this data source is a reader or not. logger
The logger for this class instance name
The name of this instance ndim
ntraj
ra_itraj_cuboid
Implementation of random access with slicing that can be up to 3-dimensional, where the first dimension corresponds to the trajectory index, the second dimension corresponds to the frames and the third dimension corresponds to the dimensions of the frames. ra_itraj_jagged
Behaves like ra_itraj_cuboid just that the trajectories are not truncated and returned as a list. ra_itraj_linear
Implementation of random access that takes arguments as the default random access (i.e., up to three dimensions with trajs, frames and dims, respectively), but which considers the frame indexing to be contiguous. ra_linear
Implementation of random access that takes a (maximal) two-dimensional slice where the first component corresponds to the frames and the second component corresponds to the dimensions. show_progress
trajfiles
-
data_producer
¶ The data producer for this data source object (can be another data source object). :returns: :rtype: This data source’s data producer.
-
describe
()¶ Returns a description of this transformer
Returns:
-
dimension
()¶ Returns the number of output dimensions
Returns:
-
filenames
¶ Property which returns a list of filenames the data is originally from. :returns: list of str :rtype: list of filenames if data is originating from a file based reader
-
in_memory
¶ are results stored in memory?
-
is_random_accessible
¶ Check if self._is_random_accessible is set to true and if all the random access strategies are implemented. :returns: bool :rtype: Returns True if random accessible via strategies and False otherwise.
-
is_reader
¶ Property telling if this data source is a reader or not. :returns: bool :rtype: True if this data source is a reader and False otherwise
-
logger
¶ The logger for this class instance
-
n_frames_total
(stride=1)¶ Returns the total number of frames, over all trajectories
Parameters: stride – return value is the number of frames in trajectories when running through them with a step size of stride Returns: the total number of frames, over all trajectories
-
name
¶ The name of this instance
-
number_of_trajectories
()¶ Returns the number of trajectories
Returns: number of trajectories
-
output_type
()¶ By default transformers return single precision floats.
-
ra_itraj_cuboid
¶ Implementation of random access with slicing that can be up to 3-dimensional, where the first dimension corresponds to the trajectory index, the second dimension corresponds to the frames and the third dimension corresponds to the dimensions of the frames.
The with the frame slice selected frames will be loaded from each in the trajectory-slice selected trajectories and then sliced with the dimension slice. For example: The data consists out of three trajectories with length 10, 20, 10, respectively. The slice data[:, :15, :3] returns a 3D array of shape (3, 10, 3), where the first component corresponds to the three trajectories, the second component corresponds to 10 frames (note that the last 5 frames are being truncated as the other two trajectories only have 10 frames) and the third component corresponds to the selected first three dimensions.
Returns: Returns an object that allows access by slices in the described manner.
-
ra_itraj_jagged
¶ Behaves like ra_itraj_cuboid just that the trajectories are not truncated and returned as a list.
Returns: Returns an object that allows access by slices in the described manner.
-
ra_itraj_linear
¶ Implementation of random access that takes arguments as the default random access (i.e., up to three dimensions with trajs, frames and dims, respectively), but which considers the frame indexing to be contiguous. Therefore, it returns a simple 2D array.
Returns: A 2D array of the sliced data containing [frames, dims].
-
ra_linear
¶ Implementation of random access that takes a (maximal) two-dimensional slice where the first component corresponds to the frames and the second component corresponds to the dimensions. Here it is assumed that the frame indexing is contiguous, i.e., the first frame of the second trajectory has the index of the last frame of the first trajectory plus one.
Returns: Returns an object that allows access by slices in the described manner.
-
register_progress_callback
(call_back, stage=0)¶ Registers the progress reporter.
Parameters: - call_back (function) –
This function will be called with the following arguments:
- stage (int)
- instance of pyemma.utils.progressbar.ProgressBar
- optional *args and named keywords (**kw), for future changes
- stage (int, optional, default=0) – The stage you want the given call back function to be fired.
- call_back (function) –
-
trajectory_length
(itraj, stride=1, skip=None)¶ Returns the length of trajectory
Parameters: - itraj – trajectory index
- stride – return value is the number of frames in trajectory when running through it with a step size of stride
- skip – skip parameter
Returns: length of trajectory
-
trajectory_lengths
(stride=1, skip=0)¶ Returns the length of each trajectory
Parameters: - stride – return value is the number of frames in trajectories when running through them with a step size of stride
- skip – return value is the number of frames in trajectories when skipping the first “skip” frames (plus stride)
Returns: numpy array containing length of each trajectory
-
write_to_csv
(filename=None, extension='.dat', overwrite=False, stride=1, chunksize=100, **kw)¶ write all data to csv with numpy.savetxt
Parameters: - filename (str, optional) –
filename string, which may contain placeholders {itraj} and {stride}:
- itraj will be replaced by trajetory index
- stride is stride argument of this method
If filename is not given, it is being tried to obtain the filenames from the data source of this iterator.
- extension (str, optional, default='.dat') – filename extension of created files
- overwrite (bool, optional, default=False) – shall existing files be overwritten? If a file exists, this method will raise.
- stride (int) – omit every n’th frame
- chunksize (int) – how many frames to process at once
- kw (dict) – named arguments passed into numpy.savetxt (header, seperator etc.)
Example
Assume you want to save features calculated by some FeatureReader to ASCII: >>> import numpy as np, pyemma >>> from pyemma.util.files import TemporaryDirectory >>> import os >>> data = [np.random.random((10,3))] * 3 >>> reader = pyemma.coordinates.source(data) >>> filename = “distances_{itraj}.dat” >>> with TemporaryDirectory() as td: ... os.chdir(td) ... reader.write_to_csv(filename, header=’‘, delim=’;’) ... print(os.listdir(‘.’)) [‘distances_2.dat’, ‘distances_1.dat’, ‘distances_0.dat’]
- filename (str, optional) –