コード例 #1
0
def get_rmsds(traj_fn, native_fn='native.pdb', aindices_fn="project/AtomIndices.dat"):

    aindices = np.loadtxt(aindices_fn, dtype='int')
    native = mdtraj.load(native_fn, atom_indices=aindices)
    traj = mdtraj.load(traj_fn, atom_indices=aindices)

    native = mdtraj.rmsd_cache(native)
    traj = mdtraj.rmsd_cache(traj)

    rmsds = traj.rmsds_to(native, 0)
    return rmsds
コード例 #2
0
    def __init__(
        self, wildtype_counts, wildtype_states_fn, wildtype_topology_fn, mutant_topology_fn, lag_time, simulation
    ):
        """Create an OpenMM sampler

        Parameters
        ----------
        wildtype_counts : np.ndarray, shape=(n_states, n_states)
            The number of observed transition counts in the base
            protein
        wildtype_states_fn : string
            Path to a trajectory file giving the states at the
            centers of each state, for the wildtype topology.
            The states must be defined by RMSD.
        wildtype_topology_fn : string
            Path to a file giving the topology of the wildtype.
            Should be a pdb.
        mutant_topology_fn : string
            Path to a file giving the topology of the mutant.
            Should be a pdb.
        lag_time : simtk.unit.Quantity
            The msm lag time, in real time units.
        simulation : simtk.openmm.app.Simulation
            A simulation object, set up for the mutant.
        """
        self._wt_states = md.load(wildtype_states_fn)
        wt_backbone_inds = [a.index for a in self._wt_states.topology.atoms if a.name in ["C", "CA", "CB", "N", "O"]]
        assert len(wt_backbone_inds) > 0
        wt_backbone = md.load(wildtype_states_fn, atom_indices=wt_backbone_inds)
        self._wt_rmsd_cache = md.rmsd_cache(wt_backbone)

        self._wt_topology = app.PDBFile(wildtype_topology_fn).topology
        self._lag_time = lag_time
        self._mutant_topology = app.PDBFile(mutant_topology_fn).topology

        self._mutant_backbone_inds = [
            a.index for a in self._mutant_topology.atoms() if a.name in ["C", "CA", "CB", "N", "O"]
        ]

        if not len(list(self._wt_topology.atoms())) == self._wt_states.n_atoms:
            raise ValueError("wt topology fn must have same # of states as wt state file")

        self._simulation = simulation
        super(OpenMMMutantSampler, self).__init__(wildtype_counts, verbose=True)
コード例 #3
0
ファイル: example_rmsd.py プロジェクト: raviramanathan/mdtraj
crystal = md.load(crystal_fn)
trajectory = md.load(trajectory_fn, top=crystal)  # load the xtc. the crystal structure defines the topology
print trajectory

# Let's also try loading only the heavy atoms from disk, because calculating
# RMSD with exchangeable hydrogen atoms is generally not a good idea

heavy_atoms = [atom.index for atom in crystal.topology.atoms if atom.element.symbol != 'H']
heavy_crystal = md.load(crystal_fn, atom_indices=heavy_atoms)
heavy_trajectory = md.load(trajectory_fn, top=crystal, atom_indices=heavy_atoms)
print heavy_trajectory

# Format the data for the RMSD calculation by building an RMSDCache.

crystal_cache = md.rmsd_cache(crystal)
trajectory_cache = md.rmsd_cache(trajectory)
crystal_heavy_cache = md.rmsd_cache(heavy_crystal)
trajectory_heavy_cache = md.rmsd_cache(heavy_trajectory)
rmsds_to_crystal = trajectory_cache.rmsds_to(crystal_cache, 0)
heavy_rmds_to_crystal = trajectory_heavy_cache.rmsds_to(crystal_heavy_cache, 0)

# Plot the results

import matplotlib.pyplot as pp
pp.figure();
pp.plot(trajectory.time, rmsds_to_crystal, 'r', label='all atom');
pp.plot(heavy_trajectory.time, heavy_rmds_to_crystal, 'b', label='heavy atom');
pp.legend();
pp.title('RMSDs to crystal');
pp.xlabel('simulation time (ps)');
コード例 #4
0
ファイル: test.py プロジェクト: mpharrigan/tungsten
import mdtraj as md
import numpy as np

atom_indices = np.loadtxt('data/AtomIndices.dat', int)
t1 = md.load('data/trj-00000.nc', top='data/input.pdb', atom_indices=atom_indices)
t2 = md.load('data/trj-00001.nc', top='data/input.pdb', atom_indices=atom_indices)
t = t1 + t2

r = md.rmsd_cache(t, 'axis')

print "Coords"
print r.cords[0]
print 'RMSDs\n', r.rmsds_to(r, 0)
print 'G\n', r._g[:len(t1)]
print r._g[len(t1):]

コード例 #5
0
# In this example, we cluster our alanine dipeptide trajectory using
# the RMSD distance and Ward's algorithm.

import mdtraj as md
import numpy as np
import scipy.cluster.hierarchy


# Lets load up our trajectory. This is the trajectory that we generated in
# the "Running a simulation in OpenMM and analyzing the results with mdtraj"
# example. The first step is to build the rmsd cache, which precalculates
# some values for the rmsd computation.

traj = md.load('ala2.h5')
print traj
engine = md.rmsd_cache(traj)

# Lets compute all pairwise rmsds between conformations.

distances = np.empty((traj.n_frames, traj.n_frames))
for i in range(traj.n_frames):
    distances[i] = engine.rmsds_to(engine, i)
print 'Max pairwise rmsd: %f nm' % np.max(distances)

# scipy.cluster implements the ward linkage
# algorithm (among others)

linkage = scipy.cluster.hierarchy.ward(distances)

# Lets plot the resulting dendrogram.
コード例 #6
0
"""
Little script to find all-atom generators from the dimensionality reduced
generators.
"""
import mdtraj as md
import numpy as np
import mdtraj.compatibility

trjs = md.load('Trajectories/trj0.lh5')
trjs.restrict_atoms(np.loadtxt('AtomIndices.dat', int))

rc = md.rmsd_cache(trjs)
gens = md.rmsd_cache(md.load('Data_RMSD2_5A/Gens.lh5'))

ks = []
for i in range(len(gens)):
    k = np.argmin(rc.rmsds_to(gens, i))
    ks.append(k)

t = md.load('Trajectories/trj0.lh5')
print 'Done'
md.Trajectory(xyz=t.xyz[ks], topology=t.topology).save('Data_RMSD2_5A/Gens.h5')