示例#1
0
    def setUpClass(cls):
        # load observations
        import pyemma.datasets
        data = pyemma.datasets.load_2well_discrete()
        obs_micro = data.dtraj_T100K_dt10

        # stationary distribution
        pi_micro = data.msm.stationary_distribution
        pi_macro = np.zeros(2)
        pi_macro[0] = pi_micro[0:50].sum()
        pi_macro[1] = pi_micro[50:].sum()

        # coarse-grain microstates to two metastable states
        cg = np.zeros(100, dtype=int)
        cg[50:] = 1
        obs_macro = cg[obs_micro]

        # hidden states
        cls.nstates = 2
        # samples
        cls.nsamples = 100

        cls.lag = 100
        cls.bmsm_rev = bayesian_markov_model(obs_macro,
                                             cls.lag,
                                             dt_traj='4 fs',
                                             reversible=True,
                                             nsamples=cls.nsamples)
        cls.bmsm_revpi = bayesian_markov_model(obs_macro,
                                               cls.lag,
                                               dt_traj='4 fs',
                                               reversible=True,
                                               statdist=pi_macro,
                                               nsamples=cls.nsamples)
示例#2
0
文件: test_msm.py 项目: mejk/PyEMMA
 def test_bmsm(self):
     from pyemma.msm import bayesian_markov_model
     msm = bayesian_markov_model(self.dtraj,
                                 lag=1,
                                 mincount_connectivity='1/n')
     msm_restricted = bayesian_markov_model(
         self.dtraj,
         lag=1,
         mincount_connectivity=self.mincount_connectivity)
     self._test_connectivity(msm, msm_restricted)
示例#3
0
 def test_its_bmsm(self):
     BMSM = msm.bayesian_markov_model(
         [self.double_well_data.dtraj_T100K_dt10_n6good], 40)
     ck = BMSM.cktest(2, mlags=[0, 1, 10])
     estref = np.array([[[1., 0.], [0., 1.]],
                        [[0.89722931, 0.10277069], [0.10070029,
                                                    0.89929971]],
                        [[0.64668027, 0.35331973], [0.34369109,
                                                    0.65630891]]])
     predref = np.array([[[1., 0.], [0., 1.]],
                         [[0.89722931, 0.10277069],
                          [0.10070029, 0.89929971]],
                         [[0.62568693, 0.37431307],
                          [0.36677222, 0.63322778]]])
     predLref = np.array([[[1., 0.], [0., 1.]],
                          [[0.89398296, 0.09942586],
                           [0.09746008, 0.89588256]],
                          [[0.6074675, 0.35695492],
                           [0.34831224, 0.61440531]]])
     predRref = np.array([[[1., 0.], [0., 1.]],
                          [[0.90070139, 0.10630301],
                           [0.10456111, 0.90255169]],
                          [[0.64392557, 0.39258944],
                           [0.38762444, 0.65176265]]])
     # rough agreement
     assert np.allclose(ck.estimates, estref, rtol=0.1, atol=10.0)
     assert ck.estimates_conf[0] is None
     assert ck.estimates_conf[1] is None
     assert np.allclose(ck.predictions, predref, rtol=0.1, atol=10.0)
     assert np.allclose(ck.predictions[0], predLref, rtol=0.1, atol=10.0)
     assert np.allclose(ck.predictions[1], predRref, rtol=0.1, atol=10.0)
示例#4
0
    def buildMSM(self):
        """ Estimate a MSM from the trajectories using a provided lagtime that
        should be big enough so that the relevant processes have converged.

        self.error: whether to estimate errors or not
        """
        if self.error:
            self.MSM_object = msm.bayesian_markov_model(self.dtrajs, self.lagtime)
        else:
            self.MSM_object = msm.estimate_markov_model(self.dtrajs, self.lagtime)
示例#5
0
def estimateMSM(trajectories, lagtime, error_est=False):
    """ Estimate a MSM from the trajectories using a provided lagtime that
    should be big enough so that the relevant processes have converged.
    Return a MaximumLikelihoodMSM object"""
    if error_est:
        print "Computing msm with bayes error calc"
        MSM_object = MSM.bayesian_markov_model(trajectories, lagtime)
    else:
        print "Computing msm with no error calc"
        MSM_object = MSM.estimate_markov_model(trajectories,
                                               lagtime,
                                               count_mode='sliding')
    return MSM_object
示例#6
0
    def setUpClass(cls):
        # load observations
        import pyemma.datasets
        obs_micro = pyemma.datasets.load_2well_discrete().dtraj_T100K_dt10
        # coarse-grain microstates to two metastable states
        cg = np.zeros(100, dtype=int)
        cg[50:] = 1
        obs_macro = cg[obs_micro]

        # hidden states
        cls.nstates = 2
        # samples
        cls.nsamples = 100

        cls.lag = 100
        cls.sampled_msm_lag100 = bayesian_markov_model(obs_macro,
                                                       cls.lag,
                                                       reversible=True,
                                                       nsamples=cls.nsamples)
示例#7
0
    def setUpClass(cls):
        data = datasets.load_2well_discrete()
        cls.obs_micro = data.dtraj_T100K_dt10

        # coarse-grain microstates to two metastable states
        cg = np.zeros(100, dtype=int)
        cg[50:] = 1
        cls.obs_macro = cg[cls.obs_micro]
        # hidden states
        cls.nstates = 2
        # samples
        cls.nsamples = 10

        cls.lag = 100

        cls.msm = datasets.load_2well_discrete().msm
        cls.bmsm_rev = bayesian_markov_model(cls.obs_macro,
                                             cls.lag,
                                             reversible=True,
                                             nsamples=cls.nsamples)
import matplotlib
matplotlib.use('Agg')
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('ticks')
colors = sns.color_palette()
import pickle
start_time = time.time()
## Load
meta, ktrajs = load_trajs('../../ktrajs_cen_30_100_5')

dtrajs = list(ktrajs.values())
type(dtrajs[0])
## Fit
msm = bayesian_markov_model(dtrajs, lag=16, nsamples=100000)

print('done with bmm')

## Load
kmeans = load_generic('../../kcenters_30_100_5.pickl')
msm2 = load_generic('../msm_kcen_30_100_5_16.pickl')
meta, ttrajs = load_trajs('../../../ttrajs_a0_30')
txx = np.concatenate(list(ttrajs.values()))
a1 = ttrajs[14]

print('done with load')

print('active_count_fraction is ', msm.active_count_fraction)
print('active_state_fraction is ', msm.active_state_fraction)
print('shape of transition matrix is ', msm.P.shape)
示例#9
0
delG_nstates_prob = {}
delG_interval = {}

for system in systems:
    print('calculating free energy landscape for %s' % system)

    delG_nstates_prob[system] = []

    Y = np.load('%s/tica_projection.npy' % file_paths[system])
    Y1 = [y[:, 0] for y in Y]
    Y2 = [y[:, 1] for y in Y]

    clkmeans_dtrajs = np.load('%s/clkmeans_dtrajs.npy' % file_paths[system])
    clkmeans_dtrajs = clkmeans_dtrajs.tolist()

    MSM = msm.bayesian_markov_model(clkmeans_dtrajs, lag=200, nsamples=1000)

    #Calculate delG
    Y1_hstack = np.hstack(Y1)
    Y2_hstack = np.hstack(Y2)
    MSM_weights_hstack = np.hstack(MSM.trajectory_weights())

    Y1_DFG_in = []
    Y2_DFG_in = []
    Y1_DFG_out = []
    Y2_DFG_out = []
    weights_DFG_in = []
    weights_DFG_out = []

    for i, y1 in enumerate(Y1_hstack):
        this_y1 = y1