Example #1
0
    def test_get_path_metric_func_bad_key(self):
        '''Test that KeyError is caught by
        get_path_metric_func().'''

        try:
            PSA.get_path_metric_func('123456')
        except KeyError:
            self.fail('KeyError should be caught')
Example #2
0
    def test_get_path_metric_func_bad_key(self):
        '''Test that KeyError is caught by
        get_path_metric_func().'''

        try:
           PSA.get_path_metric_func('123456')
        except KeyError:
            self.fail('KeyError should be caught')
def psa_partial(universesA,
                universesB,
                metric="discrete_frechet",
                selection="name CA"):
    """Calculate path similarity metric between lists of universes.

    Arguments
    ---------
    universesA, universesB : lists
         lists of MDAnalysis.Universe instances
    metric : string, optional
         label of the metric or distance function, can be one of "discrete_frechet",
         "hausdorff", "weighted_average_hausdorff", "average_hausdorff",
         "hausdorff_neighbors". Note that only "discrete_frechet" and "hausdorff"
         are true metrics.
    selection : string, optional
         MDAnalysis selection string that, when applied to *all* universes generates
         the subset of atoms that should be compared.

    Returns
    -------
    numpy.array(len(universesA), len(universesB)) : distance matrix
         The matrix of all the mutual distances D[i, j] with 0 <= i <
         len(A) and 0 <= j < len(B)

    Note
    ----
    Each universe should be transferred to memory
    (`Universe.transfer_to_memory()`) in order to speed up extraction
    of coordinates. However, for very big trajectories, memory
    problems might occur and then this code is not optimal because it does
    not cache extracted coordinates.
    """
    _metric = psa.get_path_metric_func(metric)

    # submatrix of d[i, j] with i from A and j from B
    D = np.zeros((len(universesA), len(universesB)))

    # not optimized: could transpose to keep larger axis outside,
    # cache results (compare u_i and u_j), and generate 0 for u_i == u_j
    for i, u_i in enumerate(universesA):
        g1 = u_i.select_atoms(selection)
        P = u_i.trajectory.timeseries(asel=g1, format="fac")
        for j, u_j in enumerate(universesB):
            g2 = u_j.select_atoms(selection)
            Q = u_j.trajectory.timeseries(asel=g2, format="fac")

            # compute distance between paths
            D[i, j] = _metric(P, Q)

    return D
Example #4
0
 def test_get_path_metric_func_bad_key(self):
     '''Test that KeyError is caught by
     get_path_metric_func().'''
     with pytest.raises(KeyError):
         PSA.get_path_metric_func('123456')
Example #5
0
 def time_get_path_metric_func(self, path_metric):
     """Benchmark for get_path_metric_func in psa
     module
     """
     psa.get_path_metric_func(name=path_metric)