Example #1
0
def test_fs_mutinf():

    traj = FsPeptide().get().trajectories[0]

    idx = [at.index for at in traj.topology.atoms
           if at.residue.index in [3, 4, 5, 6, 7, 8]]
    traj = traj.atom_slice(atom_indices=idx)[::100]

    yield _test_mi_alpha, traj
    yield _test_mi_contact, traj
    yield _test_mi_dihedral, traj
Example #2
0
def test_fs_mutinf():

    traj = FsPeptide().get().trajectories[0]

    idx = [
        at.index for at in traj.topology.atoms
        if at.residue.index in [3, 4, 5, 6, 7, 8]
    ]
    traj = traj.atom_slice(atom_indices=idx)[::100]

    yield _test_mi_alpha, traj
    yield _test_mi_contact, traj
    yield _test_mi_dihedral, traj
Example #3
0
def test_fs_tent():

    traj1, traj2 = FsPeptide().get().trajectories[:2]

    idx = [at.index for at in traj1.topology.atoms
           if at.residue.index in [3, 4, 5, 6, 7, 8]]

    traj1 = traj1.atom_slice(atom_indices=idx)[::100]
    traj2 = traj2.atom_slice(atom_indices=idx)[::100]

    traj = (traj1, traj2)

    yield _test_tent_alpha, traj
    yield _test_tent_contact, traj
    yield _test_tent_dihedral, traj
Example #4
0
def test_fs_tent():

    cwd = os.path.abspath(os.curdir)
    dirname = tempfile.mkdtemp()
    FsPeptide(dirname).get()

    try:
        os.chdir(dirname)

        top = md.load(dirname + '/fs_peptide/fs-peptide.pdb')
        idx = [
            at.index for at in top.topology.atoms
            if at.residue.index in [3, 4, 5, 6, 7, 8]
        ]
        traj1 = md.load(dirname + '/fs_peptide/trajectory-1.xtc',
                        stride=100,
                        top=top,
                        atom_indices=idx)
        traj2 = md.load(dirname + '/fs_peptide/trajectory-2.xtc',
                        stride=100,
                        top=top,
                        atom_indices=idx)
        traj = (traj1, traj2)

        yield _test_tent_alpha, traj
        yield _test_tent_contact, traj
        yield _test_tent_dihedral, traj

    finally:
        os.chdir(cwd)
        shutil.rmtree(dirname)
Example #5
0
def test_msmb_feat_select_skeleton():
    try:
        from msmbuilder.example_datasets import FsPeptide
    except ImportError as e:
        raise SkipTest(e)

    assert OSPREY_BIN is not None
    cwd = os.path.abspath(os.curdir)
    dirname = tempfile.mkdtemp()
    FsPeptide(dirname).get()

    try:
        os.chdir(dirname)
        subprocess.check_call([
            OSPREY_BIN, 'skeleton', '-t', 'msmb_feat_select', '-f',
            'config.yaml'
        ])
        subprocess.check_call([OSPREY_BIN, 'worker', 'config.yaml', '-n', '1'])
        assert os.path.exists('osprey-trials.db')

        yield _test_dump_1

        yield _test_plot_1

    finally:
        os.chdir(cwd)
        shutil.rmtree(dirname)
Example #6
0
def test_fs_tent():

    traj1, traj2 = FsPeptide().get().trajectories[:2]

    idx = [
        at.index for at in traj1.topology.atoms
        if at.residue.index in [3, 4, 5, 6, 7, 8]
    ]

    traj1 = traj1.atom_slice(atom_indices=idx)[::100]
    traj2 = traj2.atom_slice(atom_indices=idx)[::100]

    traj = (traj1, traj2)

    yield _test_tent_alpha, traj
    yield _test_tent_contact, traj
    yield _test_tent_dihedral, traj
Example #7
0
def test_MDTrajDatasetLoader_1():
    try:
        from msmbuilder.example_datasets import FsPeptide
    except ImportError as e:
        raise SkipTest(e)

    cwd = os.path.abspath(os.curdir)
    dirname = tempfile.mkdtemp()
    fs_pept = FsPeptide(dirname)
    fs_pept.get()
    try:
        loader = MDTrajDatasetLoader(os.path.join(fs_pept.data_dir, '*.xtc'),
                                     topology=os.path.join(fs_pept.data_dir, 'fs-peptide.pdb'))
        X, y = loader.load()
        assert len(X) == 28
        assert y is None
    finally:
        shutil.rmtree(dirname)
Example #8
0
def test_MDTrajDatasetLoader_1():
    from msmbuilder.example_datasets import FsPeptide
    fs_pept = FsPeptide()

    loader = MDTrajDatasetLoader(os.path.join(fs_pept.data_dir, '*.xtc'),
                                 topology=os.path.join(fs_pept.data_dir,
                                                       'fs-peptide.pdb'))
    X, y = loader.load()
    assert len(X) == 28
    assert y is None
Example #9
0
def test_MDTrajDatasetLoader_1():
    try:
        from msmbuilder.example_datasets import FsPeptide
    except ImportError as e:
        raise SkipTest(e)

    cwd = os.path.abspath(os.curdir)
    dirname = tempfile.mkdtemp()
    fs_pept = FsPeptide(dirname)
    fs_pept.get()
    try:
        loader = MDTrajDatasetLoader(os.path.join(fs_pept.data_dir, '*.xtc'),
                                     topology=os.path.join(
                                         fs_pept.data_dir, 'fs-peptide.pdb'))
        X, y = loader.load()
        assert len(X) == 28
        assert y is None
    finally:
        shutil.rmtree(dirname)
Example #10
0
num_clusters = args.num_clusters
which_dataset = args.which_dataset
feature = args.feature

# Folder to save everything
folder = '/scratch/users/mincheol/' + which_dataset + '/sim_datasets/'

import tempfile
import os
os.chdir(tempfile.mkdtemp())

xyz = []  # placeholder
print(which_dataset)
if which_dataset == 'fspeptide':
    # Get data
    fs_peptide = FsPeptide()
    fs_peptide.cache()
    xyz = dataset(fs_peptide.data_dir + "/*.xtc",
                  topology=fs_peptide.data_dir + '/fs-peptide.pdb',
                  stride=10)
    print("{} trjaectories".format(len(xyz)))
    # msmbuilder does not keep track of units! You must keep track of your
    # data's timestep
    to_ns = 0.5
    print("with length {} ns".format(set(len(x) * to_ns for x in xyz)))

if which_dataset == 'apo_calmodulin':
    print('correct')
    xyz = dataset('/scratch/users/mincheol/apo_trajectories' + '/*.lh5',
                  stride=10)
Example #11
0
=========================
"""
from msmbuilder.example_datasets import FsPeptide
from msmbuilder.featurizer import DihedralFeaturizer
from msmbuilder.decomposition import tICA
from msmbuilder.cluster import MiniBatchKMeans
from msmbuilder.msm import MarkovStateModel

import numpy as np

import msmexplorer as msme

rs = np.random.RandomState(42)

# Load Fs Peptide Data
trajs = FsPeptide().get().trajectories

# Extract Backbone Dihedrals
featurizer = DihedralFeaturizer(types=['chi1'])
diheds = featurizer.fit_transform(trajs)

# Perform Dimensionality Reduction
tica_model = tICA(lag_time=2, n_components=2)
tica_trajs = tica_model.fit_transform(diheds)

# Perform Clustering
clusterer = MiniBatchKMeans(n_clusters=12, random_state=rs)
clustered_trajs = clusterer.fit_transform(tica_trajs)

# Construct MSM
msm = MarkovStateModel(lag_time=2)
Example #12
0
import numpy as np
import mdtraj as md
import pandas as pd
import glob
import os
from scipy.stats import vonmises as vm

from msmbuilder.example_datasets import fetch_fs_peptide, FsPeptide
from msmbuilder.featurizer import DihedralFeaturizer, AlphaAngleFeaturizer,\
    KappaAngleFeaturizer,ContactFeaturizer,VonMisesFeaturizer
"""
Series of tests to make sure all the describe features are putting the right features in the
right place
"""

fs = FsPeptide()
fs.cache()
dirname = fs.data_dir
top = md.load(dirname + "/fs-peptide.pdb")

if np.random.choice([True, False]):
    atom_ind = [
        i.index for i in top.top.atoms if i.residue.is_protein and (
            i.residue.index in range(15) or i.residue.index in range(20, 23))
    ]
else:
    atom_ind = [i.index for i in top.top.atoms]

trajectories = [
    md.load(fn, stride=100, top=top, atom_indices=atom_ind)
    for fn in glob.glob(os.path.join(dirname, "trajectory*.xtc"))
"""Get sample data for testing and experimenting

msmbuilder autogenerated template version 2
created 2017-05-30T15:16:59.061464
please cite msmbuilder in any publications
"""
import os

from msmbuilder.example_datasets import FsPeptide

FsPeptide("./").cache()
if not os.path.exists("trajs"):
    os.symlink("fs_peptide", "trajs")
if not os.path.exists("top.pdb"):
    os.symlink("fs_peptide/fs-peptide.pdb", "top.pdb")
Example #14
0
    def load(self):
        from msmbuilder.example_datasets import FsPeptide

        trajectories = FsPeptide(verbose=False).get().trajectories
        return trajectories, None
Example #15
0
import mdtraj as md
import numpy as np
from mdtraj.testing import eq

from msmbuilder.featurizer import SASAFeaturizer
from msmbuilder.example_datasets import FsPeptide

t = FsPeptide().get().trajectories[0][:10]


def _test_sasa_featurizer(t, value):
    sasa = md.shrake_rupley(t)
    rids = np.array([a.residue.index for a in t.top.atoms])

    for i, rid in enumerate(np.unique(rids)):
        mask = (rids == rid)
        eq(value[:, i], np.sum(sasa[:, mask], axis=1))


def test_sasa_featurizer_1():
    # t = md.load(get_fn('frame0.h5'))

    value = SASAFeaturizer(mode='residue').partial_transform(t)
    assert value.shape == (t.n_frames, t.n_residues)
    _test_sasa_featurizer(t, value)


def test_sasa_featurizer_2():
    # t = md.load(get_fn('frame0.h5'))

    # scramle the order of the atoms, and which residue each is a
Example #16
0
"""
Trace Plot
==========
"""
from msmbuilder.example_datasets import FsPeptide
from msmbuilder.featurizer import RMSDFeaturizer

import msmexplorer as msme

# Load Fs Peptide Data
traj = FsPeptide().get().trajectories[0]

# Calculate RMSD
featurizer = RMSDFeaturizer(reference_traj=traj[0])
rmsd = featurizer.partial_transform(traj).flatten()

# Plot Trace
msme.plot_trace(rmsd, label='traj0', xlabel='Timestep', ylabel='RMSD (nm)')
Example #17
0
         2))  # keeps track of visited frames (frame, # of times visited)
    visited[:, 0] = range(X.shape[0])
    for k in range(0, num_traj):
        if len(choices) == 0:
            idx = np.where(visited[:, 1] == min(visited[:, 1]))[0]
            choices = set(visited[idx, 0])
        start = random.sample(choices, 1)[0]
        choices.remove(start)
        traj = [start]
        visited[start, 1] += 1

        for i in range(0, length - 1):
            neighbor = graph_dict[traj[i]]
            next_frame = random_frame_smart(neighbor, choices)
            traj.append(next_frame)
            visited[next_frame, 1] += 1

        our_traj = np.reshape(X[traj, :], (len(traj), len(X[0]) / 3, 3))
        md_traj = md.Trajectory(
            our_traj,
            md.load(fs_peptide.data_dir + '/fs-peptide.pdb').topology)
        filename = which_dataset + '_sim_' + str(cluster_degree) + '_' + str(
            frame_degree) + '_' + str(k + 1) + '.xtc'
        md_traj.save_xtc(folder_name + filename)


traj_folder = '/scratch/users/mincheol/' + which_dataset + '/trajectories/temp/'
#generate_md_traj_old(edges, X, traj_folder, num_traj, traj_length, random=sample_rand)
fs_peptide = FsPeptide()
generate_md_traj_smart(edges, X, traj_folder, num_traj, traj_length)