Example #1
0
 def test_sklearn_affinity_propagation(self, ens1):
     pytest.importorskip('sklearn')
     cc1 = encore.cluster([ens1])
     cc2 = encore.cluster([ens1], method=encore.AffinityPropagation())
     assert len(cc1) == len(cc2), \
                  "Native and sklearn implementations of affinity "\
                           "propagation don't agree: mismatch in number of "\
                           "clusters: {0} {1}".format(len(cc1), len(cc2))
Example #2
0
 def test_sklearn_affinity_propagation(self):
     cc1 = encore.cluster([self.ens1])
     cc2 = encore.cluster([self.ens1], method=encore.AffinityPropagation())
     assert_equal(len(cc1),
                  len(cc2),
                  err_msg="Native and sklearn implementations of affinity "
                  "propagation don't agree: mismatch in number of "
                  "clusters: {0} {1}".format(len(cc1), len(cc2)))
Example #3
0
 def test_sklearn_affinity_propagation(self, ens1):
     pytest.importorskip('sklearn')
     cc1 = encore.cluster([ens1])
     cc2 = encore.cluster([ens1],
                          method=encore.AffinityPropagation())
     assert len(cc1) == len(cc2), \
                  "Native and sklearn implementations of affinity "\
                           "propagation don't agree: mismatch in number of "\
                           "clusters: {0} {1}".format(len(cc1), len(cc2))
Example #4
0
 def test_clustering_three_ensembles_two_identical(self):
     cluster_collection = encore.cluster([self.ens1, self.ens2, self.ens1])
     expected_value = 40
     assert_equal(
         len(cluster_collection),
         expected_value,
         err_msg="Unexpected result: {0}".format(cluster_collection))
Example #5
0
 def test_clustering_two_ensembles(self):
     cluster_collection = encore.cluster([self.ens1, self.ens2])
     expected_value = 14
     assert_equal(
         len(cluster_collection),
         expected_value,
         err_msg="Unexpected results: {0}".format(cluster_collection))
Example #6
0
 def test_clustering_method_w_no_distance_matrix(self, ens1):
     pytest.importorskip('sklearn')
     cluster_collection = encore.cluster(
         [ens1],
         method=encore.KMeans(10))
     assert len(cluster_collection) == 10, \
                  "Unexpected result: {0}".format(cluster_collection)
Example #7
0
 def test_clustering_two_methods(self, ens1):
     cluster_collection = encore.cluster(
         [ens1],
         method=[encore.AffinityPropagationNative(),
                 encore.AffinityPropagationNative()])
     assert len(cluster_collection[0]) == len(cluster_collection[1]), \
                  "Unexpected result: {0}".format(cluster_collection)
Example #8
0
 def test_clustering_one_ensemble(self):
     cluster_collection = encore.cluster(self.ens1)
     expected_value = 7
     assert_equal(
         len(cluster_collection),
         expected_value,
         err_msg="Unexpected results: {0}".format(cluster_collection))
Example #9
0
 def test_clustering_two_methods_one_w_no_distance_matrix(self, ens1):
     pytest.importorskip('sklearn')
     cluster_collection = encore.cluster(
         [ens1],
         method=[encore.KMeans(17),
                 encore.AffinityPropagationNative()])
     assert len(cluster_collection[0]) == len(cluster_collection[0]), \
                  "Unexpected result: {0}".format(cluster_collection)
Example #10
0
 def test_clustering_two_different_methods(self, ens1):
     pytest.importorskip('sklearn')
     cluster_collection = encore.cluster(
         [ens1],
         method=[encore.AffinityPropagation(preference=-7.5),
                 encore.DBSCAN(min_samples=2)])
     assert len(cluster_collection[0]) == len(cluster_collection[1]), \
                  "Unexpected result: {0}".format(cluster_collection)
Example #11
0
 def test_clustering_two_methods_one_w_no_distance_matrix(self, ens1):
     pytest.importorskip('sklearn')
     cluster_collection = encore.cluster(
         [ens1],
         method=[encore.KMeans(17),
                 encore.AffinityPropagationNative()])
     assert len(cluster_collection[0]) == len(cluster_collection[0]), \
                  "Unexpected result: {0}".format(cluster_collection)
Example #12
0
 def test_clustering_method_w_no_distance_matrix(self):
     cluster_collection = encore.cluster([self.ens1],
                                         method=encore.KMeans(10))
     print(cluster_collection)
     assert_equal(
         len(cluster_collection),
         10,
         err_msg="Unexpected result: {0}".format(cluster_collection))
Example #13
0
 def test_clustering_two_methods(self, ens1):
     cluster_collection = encore.cluster(
         [ens1],
         method=[
             encore.AffinityPropagationNative(),
             encore.AffinityPropagationNative()
         ])
     assert len(cluster_collection[0]) == len(cluster_collection[1]), \
                  "Unexpected result: {0}".format(cluster_collection)
Example #14
0
 def test_one(self, distance_matrix):
     preference = -float(np.median(distance_matrix.as_array()) * 10.)
     clustering_method = encore.AffinityPropagationNative(preference=preference)
     ccs = encore.cluster(None,
                          distance_matrix=distance_matrix,
                          method=clustering_method)
     assert self.n_clusters == len(ccs), \
                  "Basic clustering test failed to give the right"\
                 "number of clusters: {0} vs {1}".format(self.n_clusters, len(ccs))
Example #15
0
    def affinity_propagation(self, preference=-6.0):
        '''Performing Affinity Propagation clustering of AMOEBA-run Trp-Cage folding trajectory:-

           Default parameter values from MDAnalysis - damping=0.9, max_iter=500, convergence_iter=50
           Preference reduced to -10 from -1 to reflect local homogenity within the trajectory'''

        print("Performing Affinity Propagation with input preference = %f" %
              preference)
        clust = encore.cluster(self.univ_cut,
                               method=encore.AffinityPropagation(
                                   preference=preference, verbose=True))
        centroids = [cluster.centroid * self.ncut for cluster in clust]
        ids = [cluster.id for cluster in clust]

        print(
            "Clustering complete! - %d clusters formed with average size = %d frames"
            % (len(ids), np.average([cluster.size for cluster in clust])))

        coords_centroids = np.zeros((len(centroids), 304, 3), dtype=np.float64)
        coords_centroids[:, :, :] = [
            self.coords_protein[centroids[i], :, :]
            for i in np.arange(0, len(centroids))
        ]

        protein = self.univ2.select_atoms("protein")

        univ_centroids = mda.Merge(protein)
        univ_centroids.load_new(coords_centroids, format=MemoryReader)

        ref = mda.Universe("folded.pdb")

        nframes = len(univ_centroids.trajectory)

        alignment = align.AlignTraj(univ_centroids,
                                    ref,
                                    select='protein and name CA',
                                    in_memory=True,
                                    verbose=True)
        alignment.run()

        idvscenter = {
            'Cluster ID': [ids[i] for i in range(0, len(ids))],
            'Centroid Time (ps)':
            [centroids[i] * 10 for i in range(0, len(centroids))],
            'Cluster Size': [cluster.size for cluster in clust]
        }

        idtable = pd.DataFrame(data=idvscenter)

        #Visualisation representation set for Trp-Cage - will expand to general proteins later
        view = nglview.show_mdanalysis(univ_centroids)
        view.add_cartoon(selection="protein")
        view.add_licorice('TRP')
        view.add_licorice('PRO')
        view.center(selection='protein', duration=nframes)
        view.player.parameters = dict(frame=True)
        return view, idtable, univ_centroids
Example #16
0
 def test_clustering_two_different_methods(self, ens1):
     pytest.importorskip('sklearn')
     cluster_collection = encore.cluster(
         [ens1],
         method=[
             encore.AffinityPropagation(preference=-7.5),
             encore.DBSCAN(min_samples=2)
         ])
     assert len(cluster_collection[0]) == len(cluster_collection[1]), \
                  "Unexpected result: {0}".format(cluster_collection)
Example #17
0
 def test_one(self, distance_matrix):
     preference = -float(np.median(distance_matrix.as_array()) * 10.)
     clustering_method = encore.AffinityPropagationNative(
         preference=preference)
     ccs = encore.cluster(None,
                          distance_matrix=distance_matrix,
                          method=clustering_method)
     assert self.n_clusters == len(ccs), \
                  "Basic clustering test failed to give the right"\
                 "number of clusters: {0} vs {1}".format(self.n_clusters, len(ccs))
Example #18
0
 def test_clustering_two_methods_one_w_no_distance_matrix(self):
     cluster_collection = encore.cluster(
         [self.ens1],
         method=[encore.KMeans(17),
                 encore.AffinityPropagationNative()])
     print(cluster_collection)
     assert_equal(
         len(cluster_collection[0]),
         len(cluster_collection[0]),
         err_msg="Unexpected result: {0}".format(cluster_collection))
Example #19
0
 def test_clustering_two_methods(self):
     cluster_collection = encore.cluster(
         [self.ens1],
         method=[
             encore.AffinityPropagationNative(),
             encore.AffinityPropagationNative()
         ])
     assert_equal(
         len(cluster_collection[0]),
         len(cluster_collection[1]),
         err_msg="Unexpected result: {0}".format(cluster_collection))
Example #20
0
 def test_clustering_two_different_methods(self):
     cluster_collection = encore.cluster(
         [self.ens1],
         method=[
             encore.AffinityPropagation(preference=-7.5),
             encore.DBSCAN(min_samples=2)
         ])
     print(cluster_collection)
     print(cluster_collection)
     assert_equal(
         len(cluster_collection[0]),
         len(cluster_collection[1]),
         err_msg="Unexpected result: {0}".format(cluster_collection))
Example #21
0
 def test_clustering_three_ensembles_two_identical(self, ens1, ens2):
     cluster_collection = encore.cluster([ens1, ens2, ens1])
     expected_value = 40
     assert len(cluster_collection) == expected_value, "Unexpected result:" \
                                                       " {0}".format(cluster_collection)
Example #22
0
 def test_clustering_one_ensemble(self, ens1):
     cluster_collection = encore.cluster(ens1)
     expected_value = 7
     assert len(cluster_collection) == expected_value, "Unexpected " \
                                                       "results: {0}".format(cluster_collection)
Example #23
0
 def test_clustering_two_ensembles(self, ens1, ens2):
     cluster_collection = encore.cluster([ens1, ens2])
     expected_value = 14
     assert len(cluster_collection) == expected_value, "Unexpected " \
                                                       "results: {0}".format(cluster_collection)
Example #24
0
 def test_clustering_one_ensemble(self, ens1):
     cluster_collection = encore.cluster(ens1)
     expected_value = 7
     assert len(cluster_collection) == expected_value, "Unexpected " \
                                                       "results: {0}".format(cluster_collection)
Example #25
0
 def test_clustering_method_w_no_distance_matrix(self, ens1):
     pytest.importorskip('sklearn')
     cluster_collection = encore.cluster([ens1], method=encore.KMeans(10))
     assert len(cluster_collection) == 10, \
                  "Unexpected result: {0}".format(cluster_collection)
Example #26
0
 def test_clustering_two_ensembles(self, ens1, ens2):
     cluster_collection = encore.cluster([ens1, ens2])
     expected_value = 14
     assert len(cluster_collection) == expected_value, "Unexpected " \
                                                       "results: {0}".format(cluster_collection)
Example #27
0
 def test_clustering_three_ensembles_two_identical(self, ens1, ens2):
     cluster_collection = encore.cluster([ens1, ens2, ens1])
     expected_value = 40
     assert len(cluster_collection) == expected_value, "Unexpected result:" \
                                                       " {0}".format(cluster_collection)