예제 #1
0
def sample_tica_dim(dim=0, n_frames=200, meta=None, ttrajs=None):

    ## Load
    if (not meta is None) & (not ttrajs is None):

        ## Sample
        # These are apparently ordered according tica value
        inds = sample_dimension(ttrajs,
                                dimension=dim,
                                n_frames=n_frames,
                                scheme='random')

        save_generic(inds, "tica-dimension-{}-inds.pickl".format(dim + 1))

        ## Get tica components
        tica_values = np.array(
            [ttrajs[traj_i][frame_i][dim] for traj_i, frame_i in inds])
        tica_values = (tica_values - tica_values.min()) / (tica_values.max() -
                                                           tica_values.min())
        tica_values *= 10
        ## Make trajectory
        top = preload_top(meta)

        # Use loc because sample_dimension is nice
        traj = md.join(
            md.load_frame(meta.loc[traj_i]['traj_fn'], index=frame_i, top=top)
            for traj_i, frame_i in inds)

        ## Supperpose

        ## Save
        traj_fn = "tica-dimension-{}.dcd".format(dim + 1)
        backup(traj_fn)
        traj.save(traj_fn)
    else:
        raise ValueError('Specify meta data and trajectory objects')
예제 #2
0
{{header}}

Meta
----
depends:
  - meta.pandas.pickl
  - trajs
  - top.pdb
"""
import mdtraj as md

from msmbuilder.io import load_meta, itertrajs, save_trajs, preload_top

## Load
meta = load_meta()
centroids = md.load("centroids.xtc", top=preload_top(meta))

## Kernel
SIGMA = 0.3  # nm
from msmbuilder.featurizer import RMSDFeaturizer
import numpy as np

featurizer = RMSDFeaturizer(centroids)
lfeats = {}
for i, traj in itertrajs(meta):
    lfeat = featurizer.partial_transform(traj)
    lfeat = np.exp(-lfeat**2 / (2 * (SIGMA**2)))
    lfeats[i] = lfeat
save_trajs(lfeats, 'ftrajs', meta)
예제 #3
0
please cite msmbuilder in any publications


"""

import mdtraj as md
import os

from msmbuilder.io.sampling import sample_states
from msmbuilder.io import load_trajs, save_generic, preload_top, backup, load_generic

## Load
meta, ttrajs = load_trajs('ttrajs')
kmeans = load_generic("kmeans.pickl")

## Sample
inds = sample_states(ttrajs, kmeans.cluster_centers_, k=10)

save_generic(inds, "cluster-sample-inds.pickl")

## Make trajectories
top = preload_top(meta)
out_folder = "cluster_samples"
backup(out_folder)
os.mkdir(out_folder)

for state_i, state_inds in enumerate(inds):
    traj = md.join(
        md.load_frame(meta.loc[traj_i]['traj_fn'], index=frame_i, top=top)
        for traj_i, frame_i in state_inds)
    traj.save("{}/{}.xtc".format(out_folder, state_i))
예제 #4
0
  - trajs
"""

import mdtraj as md

from msmbuilder.io import load_trajs, save_generic, preload_top, backup, load_generic
from msmbuilder.io.sampling import sample_msm

## Load
meta, ttrajs = load_trajs('ttrajs')
msm = load_generic('msm.pickl')
kmeans = load_generic('kmeans.pickl')

## Sample
# Warning: make sure ttrajs and kmeans centers have
# the same number of dimensions
inds = sample_msm(ttrajs, kmeans.cluster_centers_, msm, n_steps=200, stride=1)
save_generic(inds, "msm-traj-inds.pickl")

## Make trajectory
top = preload_top(meta)
traj = md.join(
    md.load_frame(meta.loc[traj_i]['traj_fn'], index=frame_i, top=top)
    for traj_i, frame_i in inds
)

## Save
traj_fn = "msm-traj.xtc"
backup(traj_fn)
traj.save(traj_fn)
예제 #5
0
{{header}}

Meta
----
depends:
  - meta.pandas.pickl
  - trajs
  - top.pdb
"""
import mdtraj as md

from msmbuilder.io import load_meta, itertrajs, save_trajs, preload_top

## Load
meta = load_meta()
centroids = md.load("centroids.xtc", top=preload_top(meta))

## Kernel
SIGMA = 0.3  # nm
from msmbuilder.featurizer import RMSDFeaturizer
import numpy as np

featurizer = RMSDFeaturizer(centroids)
lfeats = {}
for i, traj in itertrajs(meta):
    lfeat = featurizer.partial_transform(traj)
    lfeat = np.exp(-lfeat ** 2 / (2 * (SIGMA ** 2)))
    lfeats[i] = lfeat
save_trajs(lfeats, 'ftrajs', meta)