Example #1
0
 def test_no_cluster(self):
     reader_xtc = api.source(self.traj_files, top=self.pdb_file)
     # only reader
     api.pipeline(reader_xtc)
     reader_xtc.get_output()
     # reader + pca / tica
     tica = api.tica()
     pca = api.pca()
     api.pipeline([reader_xtc, tica])._chain[-1].get_output()
     api.pipeline([reader_xtc, pca])._chain[-1].get_output()
Example #2
0
 def test_discretizer(self):
     reader_gen = DataInMemory(data=self.generated_data)
     # check if exception safe
     api.discretizer(reader_gen)._chain[-1].get_output()
     api.discretizer(reader_gen,
                     transform=api.tica())._chain[-1].get_output()
     api.discretizer(
         reader_gen,
         cluster=api.cluster_uniform_time())._chain[-1].get_output()
     api.discretizer(
         reader_gen,
         transform=api.pca(),
         cluster=api.cluster_regspace(dmin=10))._chain[-1].get_output()
Example #3
0
    def test(self):
        reader = source(self.trajfiles, top=self.topfile)
        pcat = pca(dim=2)

        n_clusters = 2
        clustering = UniformTimeClustering(n_clusters=n_clusters)

        D = Discretizer(reader, transform=pcat, cluster=clustering)
        D.parametrize()

        self.assertEqual(len(D.dtrajs), len(self.trajfiles))

        for dtraj in clustering.dtrajs:
            unique = np.unique(dtraj)
            self.assertEqual(unique.shape[0], n_clusters)
Example #4
0
 def test_is_parametrized(self):
     # construct pipeline with all possible transformers
     p = api.pipeline([
         api.source(self.traj_files, top=self.pdb_file),
         api.tica(),
         api.pca(),
         api.cluster_kmeans(k=50),
         api.cluster_regspace(dmin=50),
         api.cluster_uniform_time(k=20)
     ],
                      run=False)
     self.assertFalse(
         p._is_estimated(),
         "If run=false, the pipeline should not be parametrized.")
     p.parametrize()
     self.assertTrue(
         p._is_estimated(),
         "If parametrized was called, the pipeline should be parametrized.")
Example #5
0
 def test_set_element(self):
     reader = api.source(self.traj_files, top=self.pdb_file)
     pca = api.pca()
     p = api.pipeline([reader, pca])
     self.assertTrue(p._is_estimated())
     pca_out = pca.get_output()
     tica = api.tica(lag=self.generated_lag)
     # replace pca with tica
     p.set_element(1, tica)
     self.assertFalse(
         p._is_estimated(),
         "After replacing an element, the pipeline should not be parametrized."
     )
     p.parametrize()
     tica_out = tica.get_output()
     # check if replacement actually happened
     self.assertFalse(
         np.array_equal(pca_out[0], tica_out[0]),
         "The output should not be the same when the method got replaced.")