22.214.171.124.7. Utility functions for ENCORE
- class MDAnalysis.analysis.encore.utils.ParallelCalculation(n_jobs, function, args=None, kwargs=None)
Generic parallel calculation class. Can use arbitrary functions, arguments to functions and kwargs to functions.
Number of cores to be used for parallel calculation. If -1 use all available cores.
Function to be run in parallel.
Each tuple contains the arguments that will be passed to function(). This means that a call to function() is performed for each tuple. function is called as function(*args, **kwargs). Runs are distributed on the requested numbers of cores.
list of tuples
Each tuple contains the named arguments that will be passed to function, similarly as described for the args attribute.
list of dicts
n_jobs (int) – Number of cores to be used for parallel calculation. If -1 use all available cores.
function (object that supports __call__, as functions) – function to be run in parallel.
args (list of tuples) – Arguments for function; see the ParallelCalculation class description.
kwargs (list of dicts or None) – kwargs for function; see the ParallelCalculation class description.
Run parallel calculation.
results – int is the number of the calculation corresponding to a certain argument in the args list, and object is the result of corresponding calculation. For instance, in (3, output), output is the return of function(*args, **kwargs).
- Return type
- worker(q, results)
Generic worker. Will run function with the prescribed args and kwargs.
q (multiprocessing.Manager.Queue object) – work queue, from which the worker fetches arguments and messages
results (multiprocessing.Manager.Queue object) – results queue, where results are put after each calculation is finished
- class MDAnalysis.analysis.encore.utils.TriangularMatrix(size, metadata=None, loadfile=None)
Triangular matrix class. This class is designed to provide a memory-efficient representation of a triangular matrix that still behaves as a square symmetric one. The class wraps a numpy.array object, in which data are memorized in row-major order. It also has few additional facilities to conveniently load/write a matrix from/to file. It can be accessed using the  and () operators, similarly to a normal numpy array.
size (int / array_like) – Size of the matrix (number of rows or columns). If an array is provided instead, the size of the triangular matrix will be calculated and the array copied as the matrix elements. Otherwise, the matrix is just initialized to zero.
metadata (dict or None) – Metadata dictionary. Used to generate the metadata attribute.
loadfile (str or None) – Load the matrix from this file. All the attributes and data will be determined by the matrix file itself (i.e. metadata will be ignored); size has to be provided though.
Return standard numpy array equivalent
Load matrix from the npz compressed numpy format.
fname (str) – Name of the file to be loaded.
Merge list of universes into one
universes (list of Universe objects) –
- Return type
- MDAnalysis.analysis.encore.utils.trm_indices(a, b)
Generate (i,j) indeces of a triangular matrix, between elements a and b. The matrix size is automatically determined from the number of elements. For instance: trm_indices((0,0),(2,1)) yields (0,0) (1,0) (1,1) (2,0) (2,1).
generate (i,j) indeces of a triangular matrix of n rows (or columns), with diagonal
n (int) – Matrix size
generate (i,j) indeces of a triangular matrix of n rows (or columns), without diagonal (e.g. no elements (0,0),(1,1),…,(n,n))
n (int) – Matrix size