Ejemplo n.º 1
0
    def all_to_all(self, prepared_traj1, prepared_traj2):
        """Get a matrix of distances from all frames in one traj to all frames in
        another


        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory

        Returns
        -------
        distances : ndarray
            A 2D array of shape len(preprared_traj1) * len(preprared_traj2)"""

        if prepared_traj1 is prepared_traj2:
            warnings.warn('runtime', re.sub("\s+", " ", """it's not recommended to
            use this method to calculate the full pairwise distance matrix for
            one trajectory to itself (as you're doing). Use all_pairwise, which
            will be more efficient if you reall need the results as a 2D matrix
            (why?) then you can always use scipy.spatial.distance.squareform()
            on the output of all_pairwise()""".replace('\n', ' ')))

        out = cdist(prepared_traj1, prepared_traj2, metric=self.metric, p=self.p,
                    V=self.V, VI=self.VI)
        return out                                        
Ejemplo n.º 2
0
    def one_to_all(self, prepared_traj1, prepared_traj2, index1):
        """Measure the distance from one frame to every frame in a trajectory

        The distances calculated are from the `index1`th frame of `prepared_traj1`
        to all the frames in `prepared_traj2` with indices `indices2`. Although
        this is similar to one_to_many, it can often be computed faster

        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory
        index1 : int
            index in `prepared_trajectory`


        Returns
        -------
        distances : ndarray
            A vector of distances of length len(prepared_traj2)"""

        if not isinstance(index1, int):
            raise TypeError('index1 must be of type int.')
        out2 = cdist(prepared_traj2, prepared_traj1[[index1]], metric=self.metric,
                     p=self.p, V=self.V, VI=self.VI)
        return out2[:, 0]
Ejemplo n.º 3
0
    def many_to_many(self, prepared_traj1, prepared_traj2, indices1, indices2):
        """Get a matrix of distances from each frame in a set to each other frame
        in a second set.

        Calculate a MATRIX of distances from the frames in prepared_traj1 with
        indices `indices1` to the frames in prepared_traj2 with indices `indices2`,
        using supplied metric.

        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory
        indices1 : array_like
            list of indices in `prepared_traj1` to calculate the distances from
        indices2 : array_like
            list of indices in `prepared_traj2` to calculate the distances to

        Returns
        -------
        distances : ndarray
            A 2D array of shape len(indices1) * len(indices2)"""


        out = cdist(prepared_traj1[indices1], prepared_traj2[indices2], metric=self.metric,
                    p=self.p, V=self.V, VI=self.VI)
        return out
Ejemplo n.º 4
0
    def one_to_many(self, prepared_traj1, prepared_traj2, index1, indices2):
        """Calculate a vector of distances from one frame of the first trajectory
        to many frames of the second trajectory

        The distances calculated are from the `index1`th frame of `prepared_traj1`
        to the frames in `prepared_traj2` with indices `indices2`

        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory
        index1 : int
            index in `prepared_trajectory`
        indices2 : ndarray
            list of indices in `prepared_traj2` to calculate the distances to

        Returns
        -------
        distances : ndarray
            Vector of distances of length len(indices2)
        """

        if not isinstance(index1, int):
            raise TypeError('index1 must be of type int.')
        out = cdist(prepared_traj2[indices2], prepared_traj1[[index1]],
                    metric=self.metric, p=self.p, V=self.V, VI=self.VI)

        return out[:, 0]
Ejemplo n.º 5
0
    def all_to_all(self, prepared_traj1, prepared_traj2):
        """Get a matrix of distances from all frames in one traj to all frames in
        another


        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory

        Returns
        -------
        distances : ndarray
            A 2D array of shape len(preprared_traj1) * len(preprared_traj2)"""

        if prepared_traj1 is prepared_traj2:
            warnings.warn(
                'runtime',
                re.sub(
                    "\s+", " ", """it's not recommended to
            use this method to calculate the full pairwise distance matrix for
            one trajectory to itself (as you're doing). Use all_pairwise, which
            will be more efficient if you reall need the results as a 2D matrix
            (why?) then you can always use scipy.spatial.distance.squareform()
            on the output of all_pairwise()""".replace('\n', ' ')))

        out = cdist(prepared_traj1,
                    prepared_traj2,
                    metric=self.metric,
                    p=self.p,
                    V=self.V,
                    VI=self.VI)
        return out
Ejemplo n.º 6
0
    def many_to_many(self, prepared_traj1, prepared_traj2, indices1, indices2):
        """Get a matrix of distances from each frame in a set to each other frame
        in a second set.

        Calculate a MATRIX of distances from the frames in prepared_traj1 with
        indices `indices1` to the frames in prepared_traj2 with indices `indices2`,
        using supplied metric.

        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory
        indices1 : array_like
            list of indices in `prepared_traj1` to calculate the distances from
        indices2 : array_like
            list of indices in `prepared_traj2` to calculate the distances to

        Returns
        -------
        distances : ndarray
            A 2D array of shape len(indices1) * len(indices2)"""

        out = cdist(prepared_traj1[indices1],
                    prepared_traj2[indices2],
                    metric=self.metric,
                    p=self.p,
                    V=self.V,
                    VI=self.VI)
        return out
Ejemplo n.º 7
0
    def one_to_all(self, prepared_traj1, prepared_traj2, index1):
        """Measure the distance from one frame to every frame in a trajectory

        The distances calculated are from the `index1`th frame of `prepared_traj1`
        to all the frames in `prepared_traj2` with indices `indices2`. Although
        this is similar to one_to_many, it can often be computed faster

        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory
        index1 : int
            index in `prepared_trajectory`


        Returns
        -------
        distances : ndarray
            A vector of distances of length len(prepared_traj2)"""

        if not isinstance(index1, int):
            raise TypeError('index1 must be of type int.')
        out2 = cdist(prepared_traj2,
                     prepared_traj1[[index1]],
                     metric=self.metric,
                     p=self.p,
                     V=self.V,
                     VI=self.VI)
        return out2[:, 0]
Ejemplo n.º 8
0
    def one_to_many(self, prepared_traj1, prepared_traj2, index1, indices2):
        """Calculate a vector of distances from one frame of the first trajectory
        to many frames of the second trajectory

        The distances calculated are from the `index1`th frame of `prepared_traj1`
        to the frames in `prepared_traj2` with indices `indices2`

        Parameters
        ----------
        prepared_traj1 : ndarray
            First prepared trajectory
        prepared_traj2 : ndarray
            Second prepared trajectory
        index1 : int
            index in `prepared_trajectory`
        indices2 : ndarray
            list of indices in `prepared_traj2` to calculate the distances to

        Returns
        -------
        distances : ndarray
            Vector of distances of length len(indices2)
        """

        if not isinstance(index1, int):
            raise TypeError('index1 must be of type int.')
        out = cdist(prepared_traj2[indices2],
                    prepared_traj1[[index1]],
                    metric=self.metric,
                    p=self.p,
                    V=self.V,
                    VI=self.VI)

        return out[:, 0]