Пример #1
0
def test_dump():
    # gh-713
    sequence = [0, 0, 0, 1, 1, 1, 0, 0, 2, 2, 0, 1, 1, 1, 2, 2, 2, 2, 2]
    model = PESContinuousTimeMSM(verbose=False)
    model.fit([sequence])

    d = tempfile.mkdtemp()
    try:
        utils.dump(model, '{}/cmodel'.format(d))
        m2 = utils.load('{}/cmodel'.format(d))
        np.testing.assert_array_almost_equal(model.transmat_, m2.transmat_)
    finally:
        shutil.rmtree(d)
Пример #2
0
def test_dump():
    # gh-713
    sequence = [0, 0, 0, 1, 1, 1, 0, 0, 2, 2, 0, 1, 1, 1, 2, 2, 2, 2, 2]
    model = ContinuousTimeMSM(verbose=False)
    model.fit([sequence])

    d = tempfile.mkdtemp()
    try:
        utils.dump(model, '{}/cmodel'.format(d))
        m2 = utils.load('{}/cmodel'.format(d))
        np.testing.assert_array_almost_equal(model.transmat_, m2.transmat_)
    finally:
        shutil.rmtree(d)
Пример #3
0
    def _write_scripts_and_dump(self):
        n_gpus = self.n_tics
        if self.neutral_replica:
            n_gpus += 1
        with open(os.path.join(self.base_dir, "sub.sh"), 'w') as f:
            f.writelines(
                slurm_temp.render(job_name="tica_metad",
                                  base_dir=self.base_dir,
                                  partition="pande,normal,gpu,hns_gpu",
                                  n_tics=n_gpus))

        if self.render_scripts:
            if self.plumed_script is not None:
                #self.plumed_scripts_dict = self.plumed_dict
                self.plumed_scripts_dict = {0: self.plumed_script}
            else:
                self.plumed_scripts_dict = get_plumed_dict(self)
            for i in range(self.n_tics):
                with open("%s/tic_%d/plumed.dat" % (self.base_dir, i),
                          'w') as f:
                    f.writelines(self.plumed_scripts_dict[i])

        dump(self, "%s/metad_sim.pkl" % self.base_dir)
        return
Пример #4
0
            traj.xyz,
            (traj.superpose(reference_frame).xyz.shape[0], num_features))
        for traj in xyz
    ]
    X = np.concatenate(pre_X)
if feature == 'angle':
    _, num_features = diheds[0].shape
    pre_X = [
        np.reshape(traj, (traj.shape[0], num_features)) for traj in diheds
    ]
    X = np.concatenate(pre_X)

# save MSM
import msmbuilder.utils as msmutils
msmutils.dump(
    msm, '/scratch/users/mincheol/' + which_dataset + '/sim_datasets/msm_' +
    which_dataset + '.pkl')

# save assignments
np.savetxt(folder + 'msm_clustering_labels.csv',
           cluster_indices,
           delimiter=',')

# Generate sampled data
# Find frame limit

limit_list = []
state_list = []
for state in msm.mapping_.keys():
    num_frame = np.where(cluster_indices == state)[0].shape[0]
    prob = msm.populations_[msm.mapping_[state]]
Пример #5
0
import os, glob
from msmbuilder.decomposition import tICA
import mdtraj as md
import pandas as pd
from msmbuilder.msm import MarkovStateModel
from msmbuilder.cluster import KMeans

flist = glob.glob("../trajectory.xtc")

top = md.load("../top.pdb")

trj_list = [md.load(i, top=top) for i in flist]
print("Found %d trajs" % len(trj_list))

f = DihedralFeaturizer(sincos=False)
dump(f, "raw_featurizer.pkl")

feat = f.transform(trj_list)

dump(feat, "raw_features.pkl")

f = load("./featurizer.pkl")
dump(f, "featurizer.pkl")
df1 = pd.DataFrame(f.describe_features(trj_list[0]))
dump(df1, "feature_descriptor.pkl")
feat = f.transform(trj_list)

dump(feat, "features.pkl")

t = tICA(lag_time=100, n_components=2, kinetic_mapping=False)
Пример #6
0
from msmbuilder.utils import load, dump
from msmbuilder.featurizer import DihedralFeaturizer
import os, glob
from msmbuilder.decomposition import tICA
import mdtraj as md
import pandas as pd
from msmbuilder.msm import MarkovStateModel
from msmbuilder.cluster import KMeans

trj_list = load("traj_list.pkl")
print("Found %d trajs" % len(trj_list))

f = DihedralFeaturizer(sincos=False)
dump(f, "raw_featurizer.pkl")

feat = f.transform(trj_list)

dump(feat, "raw_features.pkl")

f = DihedralFeaturizer()
dump(f, "featurizer.pkl")
df1 = pd.DataFrame(f.describe_features(trj_list[0]))
dump(df1, "feature_descriptor.pkl")
feat = f.transform(trj_list)

dump(feat, "features.pkl")
#msmbuilder imports
from msmbuilder.dataset import dataset
from msmbuilder.featurizer import ContactFeaturizer
from msmbuilder.featurizer import DihedralFeaturizer
from msmbuilder.decomposition import tICA
from msmbuilder.cluster import MiniBatchKMeans
from msmbuilder.msm import ContinuousTimeMSM
from msmbuilder.utils import verbosedump, verboseload
from msmbuilder.cluster import KCenters
from msmbuilder.utils import load, dump

#other imports
import os, glob, shutil
import numpy as np
import mdtraj as md
import pandas as pd
import pickle
#prettier plots

a = np.arange(1119, 1277)
top = md.load("../prot.pdb", atom_indices=a)

# swap this for whatever you have. The code for now supports contacts, dihedral, and angles.
feat = DihedralFeaturizer(types=['chi1', 'chi2'])

# this basically maps every feature to atom indices.
df1 = pd.DataFrame(feat.describe_features(top))
dump(df1, "feature_descriptor.pkl")
Пример #8
0
T = msm.transmat_
flux = np.linalg.multi_dot([Pi_L,T,Pi_R])

# Concatenate the trajectories in cluster indices
cluster_indices = np.concatenate(clustered_trajs)

# Combine all trajectories into a trajectory "bag"
temp = xyz[0]
_, num_atoms, num_axis = temp.xyz.shape
reference_frame = temp.slice(0, copy=True)
num_features = num_atoms*num_axis;
pre_X = [np.reshape(traj.xyz, (traj.superpose(reference_frame).xyz.shape[0],num_features)) for traj in xyz]
X = np.concatenate(pre_X)

# Save the msm itself
utils.dump(msm, '/scratch/users/mincheol/' + which_dataset + '/msm_out/msm.pkl')

# Save the raw file 
X.savetxt('/scratch/users/mincheol/' + which_dataset + '/datasets/all_frames.csv')

# save MFPT matrix
mfpt_matrix.dump('/scratch/users/mincheol/' + which_dataset + '/msm_out/msm_mfpt_mat.dat')

# save assignments
cluster_indices.dump('/scratch/users/mincheol/' + which_dataset + '/msm_out/msm_clustering_labels.dat')

# save flux matrix
flux.dump('/scratch/users/mincheol/' + which_dataset + '/msm_out/msm_flux_mat.dat')

# save population vector
msm.populations_.dump('/scratch/users/mincheol/' + which_dataset + '/msm_out/msm_pop_vec.dat')
#msmbuilder imports
from msmbuilder.dataset import dataset
from msmbuilder.featurizer import ContactFeaturizer
from msmbuilder.featurizer import DihedralFeaturizer
from msmbuilder.decomposition import tICA
from msmbuilder.cluster import MiniBatchKMeans
from msmbuilder.msm import ContinuousTimeMSM
from msmbuilder.utils import verbosedump, verboseload
from msmbuilder.cluster import KCenters
from msmbuilder.utils import load, dump

#other imports
import os, glob, shutil
import numpy as np
import mdtraj as md
import pandas as pd
import pickle
#prettier plots

a = np.arange(1027, 1357)
top = md.load("../prot.pdb", atom_indices=a)

# swap this for whatever you have. The code for now supports contacts, dihedral, and angles.
feat = DihedralFeaturizer(types=['chi1', 'chi2'])
dump(feat, "featurizer.pkl")

# this basically maps every feature to atom indices.
df1 = pd.DataFrame(feat.describe_features(top))
dump(df1, "feature_descriptor.pkl")
Пример #10
0
def test_dump_load():
    data = dict(name="Fancy_name", arr=np.random.rand(10, 5))
    with tempdir():
        dump(data, 'filename')
        data2 = load('filename')
    eq(data, data2)
Пример #11
0
def test_dump_load():
    data = dict(name="Fancy_name", arr=np.random.rand(10, 5))
    with tempdir():
        dump(data, 'filename')
        data2 = load('filename')
    eq(data, data2)
Пример #12
0
        atom_indices=a),
    md.load_dcd(
        "/home/sbhakat/Aurora/DESRES/Conv_trajectory/DCD_files/Conv-BPTI-all-0001.dcd",
        top="prot_maeconv.pdb",
        atom_indices=a),
    md.load_dcd(
        "/home/sbhakat/Aurora/DESRES/Conv_trajectory/DCD_files/Conv-BPTI-all-4068.dcd",
        top="prot_maeconv.pdb",
        atom_indices=a),
    md.load_dcd(
        "/home/sbhakat/Aurora/DESRES/Conv_trajectory/DCD_files/Conv-BPTI-all-4069.dcd",
        top="prot_maeconv.pdb",
        atom_indices=a)
]

dump(trj_list, "traj_list.pkl")

f = DihedralFeaturizer(types=['phi', 'psi'])
dump(f, "raw_featurizer.pkl")

feat = f.fit_transform(trj_list)
dump(feat, "raw_features.pkl")

f = DihedralFeaturizer(types=['phi', 'psi'])
dump(f, "featurizer.pkl")

df1 = pd.DataFrame(f.describe_features(trj_list[0]))
dump(df1, "feature_descriptor.pkl")

feat = f.fit_transform(trj_list)
dump(feat, "features.pkl")
Пример #13
0
import mdtraj as md
import pandas as pd
import pickle
#prettier plots

#Loading the trajectory
a = np.arange(1118, 1276)
ds = dataset("../trajfit.xtc", topology="../prot.pdb", atom_indices=a)

#Featurization
featurizer = DihedralFeaturizer(types=['chi1', 'chi2'])
#dump(featurizer,"raw_featurizer.pkl")

#from msmbuilder.utils import load,dump
f = DihedralFeaturizer(types=['chi1', 'chi2'], sincos=True)
dump(f, "raw_featurizer.pkl")

#featurizer = DihedralFeaturizer(types=['chi1', 'chi2'], resids= 73,74,75,76,77,78,79,80,81,82,83)
diheds = featurizer.fit_transform(ds)
dump(diheds, "features.pkl")

#print(ds[0].shape)
print(diheds[0].shape)

# this basically maps every feature to atom indices.
#df1 = pd.DataFrame(featurizer.describe_features(ds))
#dump(df1, "feature_descriptor.pkl")

#Robust scaling
from msmbuilder.preprocessing import RobustScaler
scaler = RobustScaler()
Пример #14
0
train_Y=np.concatenate([np.zeros(len(plot_feat[0])),
            np.ones(len(plot_feat[0]))])
if not os.path.isfile("./pasag_model_bpti.pkl"):
    train =True 
else:
    clf = load("./pasag_model_bpti.pkl")
    train =False
if train:
    clf = PassiveAggressiveClassifier(max_iter=1000)
    clf.fit(train_X, train_Y)

#Dumping the Model

if train:
    from msmbuilder.utils import dump
    dump(clf,"./pasag_model_bpti.pkl")

#Checking the clf

clf

#Printing out the Coefficients

coeff = ",".join([str(i) for i in clf.coef_[0]])
coeff

#Normalizing

w_norm = np.linalg.norm(clf.coef_)
func="(x+%s)/%s"%(str(clf.intercept_[0]),str(w_norm))
func