def test(self):
        # extract xtcs to a temp dir
        xtc_fn = get('XTC.tgz', just_filename=True)
        fh = tarfile.open(xtc_fn, mode='r:gz')
        fh.extractall(self.td)
        fh.close()

        outfn = pjoin(self.td, 'ProjectInfo.yaml')
        # move to that directory
        os.chdir(self.td)

        atom_indices = np.arange(4)

        ConvertDataToHDF.run(projectfn=outfn,
                             conf_filename=get('native.pdb', just_filename=True),
                             input_dir=pjoin(self.td, 'XTC'),
                             source='file',
                             min_length=0,
                             stride=1,
                             rmsd_cutoff=np.inf,
                             atom_indices=atom_indices, iext=".xtc")

        project = load(outfn)
        traj = project.load_conf()
        eq(traj.n_atoms, 4)
    def test(self):

        num_macro = 5

        TC = get("PCCA_ref/tProb.mtx")
        A = get("PCCA_ref/Assignments.Fixed.h5")['arr_0']

        macro_map, macro_assign = PCCA.run_pcca(num_macro, A, TC)
        r_macro_map = get("PCCA_ref/MacroMapping.dat")

        macro_map = macro_map.astype(np.int)
        r_macro_map = r_macro_map.astype(np.int)

        # The order of macrostates might be different between the reference and
        # new lumping. We therefore find a permutation to match them.
        permutation_mapping = np.zeros(macro_assign.max() + 1, 'int')
        for i in range(num_macro):
            j = np.where(macro_map == i)[0][0]
            permutation_mapping[i] = r_macro_map[j]

        macro_map_permuted = permutation_mapping[macro_map]
        MSMLib.apply_mapping_to_assignments(macro_assign, permutation_mapping)

        r_macro_assign = get("PCCA_ref/MacroAssignments.h5")['arr_0']

        eq(macro_map_permuted, r_macro_map)
        eq(macro_assign, r_macro_assign)
 def test(self):
     args, metric = Cluster.parser.parse_args([
         '-p', get('points_on_cube/ProjectInfo.yaml', just_filename=True),
         '-o', self.td,
         'rmsd', '-a', get('points_on_cube/AtomIndices.dat', just_filename=True),
         'hybrid', '-k', '4'], print_banner=False)
     Cluster.main(args, metric)
Esempio n. 4
0
    def test(self):

        num_macro = 5

        TC = get("PCCA_ref/tProb.mtx")
        A = get("PCCA_ref/Assignments.Fixed.h5")['arr_0']
        print A

        macro_map, macro_assign = PCCA.run_pcca(num_macro, A, TC)
        r_macro_map = get("PCCA_ref/MacroMapping.dat")

        macro_map = macro_map.astype(np.int)
        r_macro_map = r_macro_map.astype(np.int)

        # The order of macrostates might be different between the reference and
        # new lumping. We therefore find a permutation to match them.
        permutation_mapping = np.zeros(macro_assign.max() + 1, 'int')
        for i in range(num_macro):
            j = np.where(macro_map == i)[0][0]
            permutation_mapping[i] = r_macro_map[j]

        macro_map_permuted = permutation_mapping[macro_map]
        MSMLib.apply_mapping_to_assignments(macro_assign, permutation_mapping)

        r_macro_assign = get("PCCA_ref/MacroAssignments.h5")['arr_0']

        eq(macro_map_permuted, r_macro_map)
        eq(macro_assign, r_macro_assign)
    def test(self):

        prep_metric = metrics.Dihedral(angles='phi/psi')
        project = get('ProjectInfo.yaml')

        os.chdir(self.td)
        tICA_train.run(prep_metric, project, delta_time=10, atom_indices=None,
                       output='tICAtest.h5', min_length=0, stride=1)

        ref_tICA = get('tICA_ref_mle.h5')

        ref_vals = ref_tICA['vals']
        ref_vecs = ref_tICA['vecs']
        ref_inds = np.argsort(ref_vals)
        ref_vals = ref_vals[ref_inds]
        ref_vecs = ref_vecs[:, ref_inds]

        test_tICA = load('tICAtest.h5')

        test_vals = test_tICA['vals']
        test_vecs = test_tICA['vecs']
        test_inds = np.argsort(test_vals)
        test_vals = test_vals[test_inds]
        test_vecs = test_vecs[:, test_inds]

        eq(test_vals, ref_vals)
        eq(test_vecs, test_vecs)
Esempio n. 6
0
    def test(self):
        from msmbuilder.scripts.SaveStructures import save

        project = get('ProjectInfo.yaml')
        assignments = get('Assignments.h5')['arr_0']
        which_states = [0, 1, 2]
        list_of_trajs = project.get_random_confs_from_states(assignments, 
            which_states, num_confs=2, replacement=True,
            random=np.random.RandomState(42))

        assert isinstance(list_of_trajs, list)
        assert isinstance(list_of_trajs[0], Trajectory)
        eq(len(list_of_trajs), len(which_states))
        for t in list_of_trajs:
            eq(len(t), 2)

        print list_of_trajs[0].keys()
        # sep, tps, one
        save(list_of_trajs, which_states, style='sep', format='lh5', outdir=self.td)
        save(list_of_trajs, which_states, style='tps', format='lh5', outdir=self.td)
        save(list_of_trajs, which_states, style='one', format='lh5', outdir=self.td)

        names = ['State0-0.lh5', 'State0-1.lh5', 'State0.lh5', 'State1-0.lh5',
                'State1-1.lh5', 'State1.lh5', 'State2-0.lh5', 'State2-1.lh5',
                'State2.lh5']

        for name in names:
            t = Trajectory.load_trajectory_file(pjoin(self.td, name))
            eq(t, get('save_structures/' + name))
    def test(self):
        from msmbuilder.scripts.SaveStructures import save

        os.chdir(self.td)

        project = get('ProjectInfo.yaml')
        assignments = get('Assignments.h5')['arr_0']
        which_states = [0, 1, 2]
        list_of_trajs = project.get_random_confs_from_states(assignments,
            which_states, num_confs=2, replacement=True,
            random=np.random.RandomState(42))

        assert isinstance(list_of_trajs, list)
        assert isinstance(list_of_trajs[0], md.Trajectory)
        eq(len(list_of_trajs), len(which_states))
        for t in list_of_trajs:
            eq(len(t), 2)

        # sep, tps, one
        save(list_of_trajs, which_states, style='sep', format='lh5', outdir=self.td)
        save(list_of_trajs, which_states, style='tps', format='lh5', outdir=self.td)
        save(list_of_trajs, which_states, style='one', format='lh5', outdir=self.td)

        names = ['State0-0.lh5', 'State0-1.lh5', 'State0.lh5', 'State1-0.lh5',
                'State1-1.lh5', 'State1.lh5', 'State2-0.lh5', 'State2-1.lh5',
                'State2.lh5']

        for name in names:
            t = md.load(pjoin(self.td, name))
            eq(t.xyz, get('save_structures/' + name).xyz)  # Just checking coordinates because atom names / bonds in reference data are incompatible with MDTraj.
Esempio n. 8
0
    def test(self):
        args, metric = Cluster.parser.parse_args([
            '-p', get('ProjectInfo.yaml', just_filename=True),
            '-s', '10',
            '-o', self.td,
            'rmsd', '-a', get('AtomIndices.dat', just_filename=True),
            'hierarchical'],
            print_banner=False)
        Cluster.main(args, metric)

        eq(load(pjoin(self.td, 'ZMatrix.h5')), get('ZMatrix.h5'))
Esempio n. 9
0
def test_CalculateTPT():
    T = get("transition_path_theory_reference/tProb.mtx")
    sources = [0]  # chosen arb. for ref. by TJL
    sinks = [70]  # chosen arb. for ref. by TJL
    script_out = CalculateTPT.run(T, sources, sinks)
    committors_ref = get(pjoin("transition_path_theory_reference",
                          "committors.h5"))['Data']
    net_flux_ref = get(pjoin("transition_path_theory_reference",
                        "net_flux.h5"))['Data']
    eq(script_out[0], committors_ref)
    eq(script_out[1].toarray(), net_flux_ref)
def test_CalculateTPT():
    T = get("transition_path_theory_reference/tProb.mtx")
    sources = [0]  # chosen arb. for ref. by TJL
    sinks = [70]  # chosen arb. for ref. by TJL
    script_out = CalculateTPT.run(T, sources, sinks)
    committors_ref = get(pjoin("transition_path_theory_reference",
                          "committors.h5"))['Data']
    net_flux_ref = get(pjoin("transition_path_theory_reference",
                        "net_flux.h5"))['Data']
    eq(script_out[0], committors_ref)
    eq(script_out[1].toarray(), net_flux_ref)
def test_FindPaths():
    tprob = get("transition_path_theory_reference/tProb.mtx")
    sources = [0]
    sinks = [70]
    paths, bottlenecks, fluxes = FindPaths.run(tprob, sources, sinks, 10)
    # paths are hard to test due to type issues, adding later --TJL
    bottlenecks_ref = get(pjoin("transition_path_theory_reference",
                           "dijkstra_bottlenecks.h5"))['Data']
    fluxes_ref = get(pjoin("transition_path_theory_reference",
                      "dijkstra_fluxes.h5"))['Data']
    eq(bottlenecks, bottlenecks_ref)
    eq(fluxes, fluxes_ref)
Esempio n. 12
0
 def setUp(self):
     
     self.generators = get('cfep_reference/Gens.lh5')
     N = len(self.generators)
     
     self.counts = get('cfep_reference/tCounts.mtx')
     self.lag_time = 1.0
     self.pfolds = np.random.rand(N)
     self.rescale = False
     
     self.reactant = 0
     self.product  = N
Esempio n. 13
0
def test_FindPaths():
    tprob = get("transition_path_theory_reference/tProb.mtx")
    sources = [0]
    sinks = [70]
    paths, bottlenecks, fluxes = FindPaths.run(tprob, sources, sinks, 10)
    # paths are hard to test due to type issues, adding later --TJL
    bottlenecks_ref = get(pjoin("transition_path_theory_reference",
                           "dijkstra_bottlenecks.h5"))['Data']
    fluxes_ref = get(pjoin("transition_path_theory_reference",
                      "dijkstra_fluxes.h5"))['Data']
    eq(bottlenecks, bottlenecks_ref)
    eq(fluxes, fluxes_ref)
Esempio n. 14
0
    def test(self):
        args, metric = Assign.parser.parse_args([
            '-p', get('ProjectInfo.yaml', just_filename=True),
            '-g', get('Gens.lh5', just_filename=True),
            '-o', self.td,
            'rmsd', '-a', get('AtomIndices.dat', just_filename=True)],
            print_banner=False)
        Assign.main(args, metric)

        eq(load(pjoin(self.td, 'Assignments.h5')),
           get('assign/Assignments.h5'))
        eq(load(pjoin(self.td, 'Assignments.h5.distances')),
           get('assign/Assignments.h5.distances'))
    def test(self):
        args, metric = Cluster.parser.parse_args([
            '-p', get('points_on_cube/ProjectInfo.yaml', just_filename=True),
            '-o', self.td,
            'rmsd', '-a', get('points_on_cube/AtomIndices.dat', just_filename=True),
            'kcenters', '-k', '4'], print_banner=False)
        Cluster.main(args, metric)

        assignments = load(pjoin(self.td, 'Assignments.h5'))["arr_0"]
        assignment_counts = np.bincount(assignments.flatten())
        eq(assignment_counts, np.array([2, 2, 2, 2]))

        distances = load(pjoin(self.td, 'Assignments.h5.distances'))["arr_0"]
        eq(distances, np.zeros((1,8)))
Esempio n. 16
0
    def setUp(self):
        if PY3:
            raise nose.SkipTest("TestCfep requires scipy.weave which doesnt exist on python3")

        self.generators = get("cfep_reference/Gens.lh5")
        N = len(self.generators)

        self.counts = get("cfep_reference/tCounts.mtx")
        self.lag_time = 1.0
        self.pfolds = np.random.rand(N)
        self.rescale = False

        self.reactant = 0
        self.product = N
Esempio n. 17
0
    def setUp(self):
        if PY3:
            raise nose.SkipTest(
                'TestCfep requires scipy.weave which doesnt exist on python3')

        self.generators = get('cfep_reference/Gens.lh5')
        N = len(self.generators)

        self.counts = get('cfep_reference/tCounts.mtx')
        self.lag_time = 1.0
        self.pfolds = np.random.rand(N)
        self.rescale = False

        self.reactant = 0
        self.product = N
Esempio n. 18
0
    def test(self):
        args, metric = Cluster.parser.parse_args([
            '-p', get('ProjectInfo.yaml', just_filename=True),
            '-a', pjoin(self.td, 'Assignments.h5'),
            '-d', pjoin(self.td, 'Assignments.h5.distances'),
            '-g', pjoin(self.td, 'Gens.lh5'),
            'rmsd', '-a', get('AtomIndices.dat', just_filename=True),
            'kcenters', '-k', '100'], print_banner=False)
        Cluster.main(args, metric)

        eq(load(pjoin(self.td, 'Assignments.h5')),
           get('Assignments.h5'))
        eq(load(pjoin(self.td, 'Assignments.h5.distances')),
           get('Assignments.h5.distances'))
        eq(load(pjoin(self.td, 'Gens.lh5')),
           get('Gens.lh5'))
    def test(self):
        args, metric = Assign.parser.parse_args([
            '-p', get('ProjectInfo.yaml', just_filename=True),
            '-g', get('Gens.lh5', just_filename=True),
            '-o', self.td,
            'rmsd', '-a', get('OldAtomIndices.dat', just_filename=True)],
            print_banner=False)
        if os.getenv('TRAVIS', None) == 'true':
            raise nose.SkipTest('Skipping test_Assign on TRAVIS')

        Assign.main(args, metric)

        eq(load(pjoin(self.td, 'Assignments.h5')),
           get('assign/Assignments.h5'))
        eq(load(pjoin(self.td, 'Assignments.h5.distances')),
           get('assign/Assignments.h5.distances'), decimal=5)
Esempio n. 20
0
    def test(self):
        try:
            import fastcluster
        except ImportError:
            raise nose.SkipTest("Cannot find fastcluster, so skipping hierarchical clustering test.")

        args, metric = Cluster.parser.parse_args([
            '-p', get('ProjectInfo.yaml', just_filename=True),
            '-s', '10',
            '-o', self.td,
            'rmsd', '-a', get('AtomIndices.dat', just_filename=True),
            'hierarchical'],
            print_banner=False)
        Cluster.main(args, metric)

        eq(load(pjoin(self.td, 'ZMatrix.h5')), get('ZMatrix.h5'))
    def test(self):
        if os.getenv('TRAVIS', None) == 'true':
            raise nose.SkipTest('Skipping test_Assign on TRAVIS')

        try:
            import fastcluster
        except ImportError:
            raise nose.SkipTest("Cannot find fastcluster, so skipping hierarchical clustering test.")

        args, metric = Cluster.parser.parse_args([
            '-p', get('ProjectInfo.yaml', just_filename=True),
            '-s', '10',
            '-o', self.td,
            'rmsd', '-a', get('AtomIndices.dat', just_filename=True),
            'hierarchical'],
            print_banner=False)
        Cluster.main(args, metric)

        eq(load(pjoin(self.td, 'ZMatrix.h5')), get('ZMatrix.h5'))
Esempio n. 22
0
    def test(self):
        # extract xtcs to a temp dir
        xtc_fn = get('XTC.tgz', just_filename=True)
        fh = tarfile.open(xtc_fn, mode='r:gz')
        fh.extractall(self.td)
        fh.close()

        outfn = pjoin(self.td, 'ProjectInfo.yaml')
        # mode to that directory
        os.chdir(self.td)
        ConvertDataToHDF.run(projectfn=outfn,
                             PDBfn=get('native.pdb', just_filename=True),
                             InputDir=pjoin(self.td, 'XTC'),
                             source='file',
                             min_length=0,
                             stride=1,
                             rmsd_cutoff=np.inf)

        eq(load(outfn), get('ProjectInfo.yaml'))
Esempio n. 23
0
    def test(self):
        BuildMSM.run(LagTime=1, assignments=get('Assignments.h5')['arr_0'], Symmetrize='MLE',
            OutDir=self.td)

        eq(load(pjoin(self.td, 'tProb.mtx')), get('tProb.mtx'))
        eq(load(pjoin(self.td, 'tCounts.mtx')), get('tCounts.mtx'))
        eq(load(pjoin(self.td, 'Mapping.dat')), get('Mapping.dat'))
        eq(load(pjoin(self.td, 'Assignments.Fixed.h5')), get('Assignments.Fixed.h5'))
        eq(load(pjoin(self.td, 'Populations.dat')), get('Populations.dat'))
Esempio n. 24
0
    def test(self):
        BuildMSM.run(lagtime=1, assignments=get('Assignments.h5')['arr_0'], symmetrize='MLE',
            out_dir=self.td)

        eq(load(pjoin(self.td, 'tProb.mtx')), get('tProb.mtx'), decimal=5)
        eq(load(pjoin(self.td, 'tCounts.mtx')), get('tCounts.mtx'), decimal=3)
        eq(load(pjoin(self.td, 'Mapping.dat')), get('Mapping.dat'))
        eq(load(pjoin(self.td, 'Assignments.Fixed.h5')), get('Assignments.Fixed.h5'))
        eq(load(pjoin(self.td, 'Populations.dat')), get('Populations.dat'))
    def test(self):
        BuildMSM.run(lagtime=1, assignments=get('Assignments.h5')['arr_0'], symmetrize='MLE',
            out_dir=self.td)

        eq(load(pjoin(self.td, 'tProb.mtx')), get('tProb.mtx'), decimal=5)
        eq(load(pjoin(self.td, 'tCounts.mtx')), get('tCounts.mtx'), decimal=3)
        eq(load(pjoin(self.td, 'Mapping.dat')), get('Mapping.dat'))
        eq(load(pjoin(self.td, 'Assignments.Fixed.h5')), get('Assignments.Fixed.h5'))
        eq(load(pjoin(self.td, 'Populations.dat')), get('Populations.dat'))
Esempio n. 26
0
    def setUp(self):
        
        # load in the reference data
        self.tprob = get("transition_path_theory_reference/tProb.mtx")
        self.sources   = [0]   # chosen arbitarily by TJL
        self.sinks     = [70]  # chosen arbitarily by TJL
        self.waypoints = [60]  # chosen arbitarily by TJL
        self.lag_time  = 1.0   # chosen arbitarily by TJL

        self.multi_sources = get("transition_path_theory_reference/many_state/sources.dat").astype(int)
        self.multi_sinks = get("transition_path_theory_reference/many_state/sinks.dat").astype(int)

        self.num_paths = 10

        # set up the reference data for hub scores
        K = np.loadtxt( hub_get('ratemat_1.dat') )
        #self.hub_T = scipy.linalg.expm( K ) # delta-t should not affect hub scores
        self.hub_T = np.transpose( np.genfromtxt( hub_get('mat_1.dat') )[:,:-3] )
        
        for i in range(self.hub_T.shape[0]):
            self.hub_T[i,:] /= np.sum(self.hub_T[i,:])
        
        self.hc = np.loadtxt( hub_get('fraction_visited.dat') )
        self.Hc = np.loadtxt( hub_get('hub_scores.dat') )[:,2]
Esempio n. 27
0
    def setUp(self):
        
        # load in the reference data
        self.tprob = get("transition_path_theory_reference/tProb.mtx")
        self.sources   = [0]   # chosen arbitarily by TJL
        self.sinks     = [70]  # chosen arbitarily by TJL
        self.waypoints = [60]  # chosen arbitarily by TJL
        self.lag_time  = 1.0   # chosen arbitarily by TJL

        self.multi_sources = get("transition_path_theory_reference/many_state/sources.dat").astype(int)
        self.multi_sinks = get("transition_path_theory_reference/many_state/sinks.dat").astype(int)

        self.num_paths = 10

        # set up the reference data for hub scores
        K = np.loadtxt( hub_get('ratemat_1.dat') )
        #self.hub_T = scipy.linalg.expm( K ) # delta-t should not affect hub scores
        self.hub_T = np.transpose( np.genfromtxt( hub_get('mat_1.dat') )[:,:-3] )
        
        for i in range(self.hub_T.shape[0]):
            self.hub_T[i,:] /= np.sum(self.hub_T[i,:])
        
        self.hc = np.loadtxt( hub_get('fraction_visited.dat') )
        self.Hc = np.loadtxt( hub_get('hub_scores.dat') )[:,2]
def test_CalculateImpliedTimescales():
    impTimes = CalculateImpliedTimescales.run(MinLagtime=3, MaxLagtime=5,
        Interval=1, NumEigen=10, AssignmentsFn=get('Assignments.h5', just_filename=True),
        trimming=True, symmetrize='Transpose', nProc=1)

    eq(impTimes, get('ImpliedTimescales.dat'))
Esempio n. 29
0
def hub_get(filename):
    """ a little hack to save headache -- returns the path to a file in 
        the hub_ref subdir inside reference/ """
    return get( os.path.join('transition_path_theory_reference', 'hub_ref', filename), just_filename=True )
Esempio n. 30
0
def test_CalculateClusterRadii():
    cr = CalculateClusterRadii.main(get("Assignments.h5")['arr_0'],
                                    get("Assignments.h5.distances")['arr_0'])
    cr_r = get("ClusterRadii.dat")
    eq(cr, cr_r)
def test_CreateAtomIndices():
    indices = CreateAtomIndices.run(get('native.pdb', just_filename=True),
                                   'minimal')
    eq(indices, get('AtomIndices.dat'))
Esempio n. 32
0
def test_CalculateMFPTs(mfpt_state=70):
    mfpt = CalculateMFPTs.run(get('transition_path_theory_reference/tProb.mtx'), mfpt_state)
    mfpt0 = get(pjoin("transition_path_theory_reference", "mfpt.h5"))['Data']
    eq(mfpt, mfpt0)
Esempio n. 33
0
def test_CalculateImpliedTimescales():
    impTimes = CalculateImpliedTimescales.run(MinLagtime=3, MaxLagtime=5,
        Interval=1, NumEigen=10, AssignmentsFn=get('Assignments.h5', just_filename=True),
        trimming=True, symmetrize='Transpose', nProc=1)

    eq(impTimes, get('ImpliedTimescales.dat'))
def test_CalculateMFPTs(mfpt_state=70):
    mfpt = CalculateMFPTs.run(get('transition_path_theory_reference/tProb.mtx'), mfpt_state)
    mfpt0 = get(pjoin("transition_path_theory_reference", "mfpt.h5"))['Data']
    eq(mfpt, mfpt0)
Esempio n. 35
0
def test_CreateAtomIndices():
    indices = CreateAtomIndices.run(get('native.pdb', just_filename=True),
                                   'minimal')
    eq(indices, get('AtomIndices.dat'))
Esempio n. 36
0
def hub_get(filename):
    """ a little hack to save headache -- returns the path to a file in 
        the hub_ref subdir inside reference/ """
    return get( os.path.join('hub_ref', filename), just_filename=True )
Esempio n. 37
0
def tpt_get(filename):
    """ a little hack to save headache -- returns the path to a file in 
        the hub_ref subdir inside reference/ """
    return get( os.path.join('transition_path_theory_reference', filename), just_filename=True )
    def test(self):
        project = get('ProjectInfo.yaml')
        asgn = AssignHierarchical.main(k=100, d=None,
            zmatrix_fn=get('ZMatrix.h5', just_filename=True), stride=10, project=project)

        eq(asgn, get('WardAssignments.h5')['arr_0'])
Esempio n. 39
0
def test_AssignHierarchical():
    asgn = AssignHierarchical.main(k=100, d=None,
        zmatrix_fn=get('ZMatrix.h5', just_filename=True))

    eq(asgn, get('WardAssignments.h5')['Data'])
def test_CalculateClusterRadii():
    cr = CalculateClusterRadii.main(get("Assignments.h5")['arr_0'],
                                    get("Assignments.h5.distances")['arr_0'])
    cr_r = get("ClusterRadii.dat")
    eq(cr, cr_r)