def test_lengths(): num = 3 inptrajs = ['PROJ9761/RUN3/CLONE9/frame{}.xtc'.format(i) for i in range(num)] stride = 8 subprocess.check_call( ['gmx', 'trjcat', '-f'] + inptrajs + ['-o', 'catty.xtc'], stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL) with mdtraj.open("catty.xtc") as xtc: stridelen = len(xtc) // stride remain = len(xtc) % stride assert stridelen == num * PROJ61_LENGTH_PER_GEN, (stridelen, remain) top = mdtraj.load_prmtop("tops-p9712/4bw5.prmtop") traj1 = mdtraj.load("catty.xtc", top=top)[::stride] # blarg! the last frame is duplicatey traj2 = mdtraj.load(inptrajs[0], top=top)[::stride][:-1] traj2 += mdtraj.load(inptrajs[1], top=top)[::stride][:-1] traj2 += mdtraj.load(inptrajs[2], top=top)[::stride] traj3 = mdtraj.load(inptrajs, top=top, discard_overlapping_frames=True)[::stride] np.testing.assert_array_equal(traj1.xyz, traj3.xyz) np.testing.assert_array_equal(traj1.xyz, traj2.xyz)
def generate_traj_from_stateinds(inds, meta, atom_selection='all'): """ Concatenate several frames from different trajectories to create a new one. Parameters ---------- inds: list of tuples, Each element of the list has to be a 2D tuple of ints (traj_index, frame_index) meta: a metadata object atom_selection: str, Which atoms to load Returns ------- traj: mdtraj.Trajectory """ frame_list = [] for traj_i, frame_i in inds: top = mdtraj.load_prmtop(meta.loc[traj_i]['top_fn']) atoms = top.select(atom_selection) frame_list.append( mdtraj.load_frame(meta.loc[traj_i]['traj_fn'], atom_indices=atoms, index=frame_i, top=meta.loc[traj_i]['top_fn']) ) traj = mdtraj.join(frame_list, check_topology=False) traj.center_coordinates() traj.superpose(traj, 0) return traj
def cmap_Cheng(traj_generator, mask1, mask2, pairs, topology): """ Calculate contact maps between mask1 and mask2 as described in [1]. Parameters ---------- traj_generator: generator MD trajectory as obtained through the load_Trajs_generator() function mask1, mask2, pairs: Two masks and the corresponding residue-residue list of tuples as obtained from the get_residuepairs() function Returns ------- contact_frequency: np.array of shape (len(mask1), len(mask2)) Contact map between mask1 and mask2. Can be used directly as input by the sns.heatmap() function. References ---------- [1] Cheng, Y. et al., 2014. Biophysical Journal, 107(7), pp.1675–1685. """ print("Starting the cmap_Cheng calculation...") top = md.load_prmtop(topology) frequency = np.zeros(len(pairs)) frame_count = 0 for traj_chunk in traj_generator: frame_count += traj_chunk.n_frames index = 0 # To iterate through the residue-residue pair list for residue_pair in pairs: # Atom selection for each residue in the pair c_atoms_residue1 = top.select("resid %d and (type C)" % residue_pair[0]) c_atoms_residue2 = top.select("resid %d and type C" % residue_pair[1]) not_c_atoms_residue1 = top.select("resid %d and not type C" % residue_pair[0]) not_c_atoms_residue2 = top.select("resid %d and not type C" % residue_pair[1]) # Calculate all the possible distances between the C-C atoms and # the non C-C atoms. Results are stored in two np.arrays of shape: # (traj_chunk.n_frames, c_atoms_residue1*c_atoms_residue2) # (traj_chunk.n_frames, non_c_atoms_residue1*non_c_atoms_residue2) c_atoms_dist = md.compute_distances(traj_chunk, cartesianProduct(c_atoms_residue1, c_atoms_residue2)) not_c_atoms_dist = md.compute_distances(traj_chunk, cartesianProduct(not_c_atoms_residue1, not_c_atoms_residue2)) # Implementation of the contact condition if (((c_atoms_dist <= 5.4).sum(1).any() > 0) and ((not_c_atoms_dist <= 4.6).sum(1).any() > 0)): frequency[index] += 1 index += 1 contact_frequency = ( frequency / frame_count).reshape(len(mask1), len(mask2)) print('Number of analyzed frames: %d\n' % frame_count) print('Aggregate simulation time: %2.f ns\n' % (frame_count * 0.02 * args.stride)) return(contact_frequency)
def get_pca_array(list_chunks, topology): """ Takes a list of mdtraj.Trajectory objects and featurize them to backbone - Alpha Carbons pairwise distances. Perform 2 component Incremental PCA on the featurized trajectory. Parameters ---------- list_chunks: list of mdTraj.Trajectory objects topology: str Name of the Topology file Returns ------- Y: np.array shape(frames, features) """ pca = IncrementalPCA(n_components=2) top = md.load_prmtop(topology) ca_backbone = top.select("name CA") pairs = top.select_pairs(ca_backbone, ca_backbone) pair_distances = [] for chunk in list_chunks: X = md.compute_distances(chunk, pairs) pair_distances.append(X) distance_array = np.concatenate(pair_distances) print("No. of data points: %d" % distance_array.shape[0]) print("No. of features (pairwise distances): %d" % distance_array.shape[1]) Y = pca.fit_transform(distance_array) return Y
def test_0(self): try: import mdtraj as md has_mdtraj = True except ImportError: has_mdtraj = False if has_mdtraj: mtop = md.load_prmtop("./data/Tc5b.top") print mtop pseudotop = Topology() for mdatom in mtop.atoms: atom = Atom(mdatom.name, mdatom.name) mdres = mdatom.residue pseudotop.add_atom(atom=atom, resid=mdres.index, resname=mdres.name) print pseudotop pseudotop.summary() pseudotop.angle_info() print pseudotop("@CA").selected_indices() print pseudotop[4] # try loading traj with pseudotop traj = FrameArray() traj.top = pseudotop.copy() print traj.top
def renumber_mask(mask, top_fn=None): """ Renumbers the mask to match the correct sequence of each subunit. Also takes into account the 0-indexed lists of Python. """ if top_fn is not None: top = md.load_prmtop(top_fn) else: top = None if max(mask) > 160 and max(mask) < 249: # It's in cTnT if top is None: new_mask = [x + 51 for x in mask] else: new_mask = ['{} {}'.format( top.residue(x).name, x + 51) for x in mask] elif max(mask) >= 249: # It's in cTnI if top is None: new_mask = [x - 247 for x in mask] else: new_mask = ['{} {}'.format( top.residue(x).name, x - 247) for x in mask] else: # It's in cTnC if top is None: new_mask = [x + 1 for x in mask] else: new_mask = ['{} {}'.format( top.residue(x).name, x + 1) for x in mask] return(new_mask)
def test_lengths(): num = 3 inptrajs = [ 'PROJ9761/RUN3/CLONE9/frame{}.xtc'.format(i) for i in range(num) ] stride = 8 subprocess.check_call(['gmx', 'trjcat', '-f'] + inptrajs + ['-o', 'catty.xtc'], stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL) with mdtraj.open("catty.xtc") as xtc: stridelen = len(xtc) // stride remain = len(xtc) % stride assert stridelen == num * PROJ61_LENGTH_PER_GEN, (stridelen, remain) top = mdtraj.load_prmtop("tops-p9712/4bw5.prmtop") traj1 = mdtraj.load("catty.xtc", top=top)[::stride] # blarg! the last frame is duplicatey traj2 = mdtraj.load(inptrajs[0], top=top)[::stride][:-1] traj2 += mdtraj.load(inptrajs[1], top=top)[::stride][:-1] traj2 += mdtraj.load(inptrajs[2], top=top)[::stride] traj3 = mdtraj.load(inptrajs, top=top, discard_overlapping_frames=True)[::stride] np.testing.assert_array_equal(traj1.xyz, traj3.xyz) np.testing.assert_array_equal(traj1.xyz, traj2.xyz)
def test_ComparetoMDtraj(self): import mdtraj as md traj = pt.load(filename="./data/Tc5b.x", top="./data/Tc5b.top") m_top = md.load_prmtop("./data/Tc5b.top") m_traj = md.load_mdcrd("./data/Tc5b.x", m_top) m_traj.xyz = m_traj.xyz * 10 # convert `nm` to `Angstrom` unit arr0 = pt.rmsd(traj, ref=0) arr1 = pt.rmsd(traj, ref=0) arr2 = pt.rmsd(traj, ) a_md0 = md.rmsd(m_traj, m_traj, 0) aa_eq(arr0, arr1) aa_eq(arr0, arr2) aa_eq(arr0, a_md0) arr0 = pt.rmsd(traj, ref=-1) arr1 = pt.rmsd(traj, ref=-1) a_md = md.rmsd(m_traj, m_traj, -1) aa_eq(arr0, arr1) aa_eq(arr0, a_md) mask = ":3-18@CA,C" atm = traj.top(mask) arr0 = pt.rmsd(traj, ref=-1, mask=mask) arr1 = pt.rmsd(traj, mask=atm.indices, ref=-1) arr2 = pt.rmsd(traj, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(traj, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) arr0 = pt.rmsd(fa, ref=-1, mask=mask) arr1 = pt.rmsd(fa, mask=atm.indices, ref=-1) arr2 = pt.rmsd(fa, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(fa, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) mask = "!@H=" atm = fa.top(mask) arr0 = pt.rmsd(fa, ref=4, mask=mask) a_md = md.rmsd(m_traj, m_traj, 4, atm.indices) # exclude 0-th frame for ref aa_eq(arr0, a_md)
def test_ComparetoMDtraj(self): import mdtraj as md traj = pt.load(filename=tc5b_trajin, top=tc5b_top) m_top = md.load_prmtop(tc5b_top) m_traj = md.load_mdcrd(tc5b_trajin, m_top) m_traj.xyz = m_traj.xyz * 10 # convert `nm` to `Angstrom` unit arr0 = pt.rmsd(traj, ref=0) arr1 = pt.rmsd(traj, ref=0) arr2 = pt.rmsd(traj, ) a_md0 = md.rmsd(m_traj, m_traj, 0) aa_eq(arr0, arr1) aa_eq(arr0, arr2) aa_eq(arr0, a_md0) arr0 = pt.rmsd(traj, ref=-1) arr1 = pt.rmsd(traj, ref=-1) a_md = md.rmsd(m_traj, m_traj, -1) aa_eq(arr0, arr1) aa_eq(arr0, a_md) mask = ":3-18@CA,C" atm = traj.top(mask) arr0 = pt.rmsd(traj, ref=-1, mask=mask) arr1 = pt.rmsd(traj, mask=atm.indices, ref=-1) arr2 = pt.rmsd(traj, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(traj, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) arr0 = pt.rmsd(fa, ref=-1, mask=mask) arr1 = pt.rmsd(fa, mask=atm.indices, ref=-1) arr2 = pt.rmsd(fa, mask=list(atm.indices), ref=-1) arr3 = pt.rmsd(fa, mask=tuple(atm.indices), ref=-1) a_md = md.rmsd(m_traj, m_traj, -1, atm.indices) aa_eq(arr0, a_md) aa_eq(arr1, a_md) aa_eq(arr2, a_md) aa_eq(arr3, a_md) fa = Trajectory(traj) mask = "!@H=" atm = fa.top(mask) arr0 = pt.rmsd(fa, ref=4, mask=mask) a_md = md.rmsd(m_traj, m_traj, 4, atm.indices) # exclude 0-th frame for ref aa_eq(arr0, a_md)
def to_mdtraj_Topology(item, atom_indices='all', check=True): if check: digest_item(item, 'file:prmtop') atom_indices = digest_atom_indices(atom_indices) try: from mdtraj import load_prmtop except: raise LibreryNotFoundError() tmp_item = load_prmtop(item) return tmp_item
def makeHMM(Trajectories, topology): top = md.load_prmtop(topology) alpha_carbons = [a.index for a in top.atoms if a.name == 'CA'] filenames = sorted(glob(Trajectories)) first_frame = md.load_frame(filenames[0], 0, top=top) f = SuperposeFeaturizer(alpha_carbons, first_frame) dataset = [] for fragment in filenames: for chunk in md.iterload(fragment, chunk=100, top=top): dataset.append(f.partial_transform(chunk)) hmm = GaussianHMM(n_states=8) hmm.fit(dataset) print(hmm.timescales_) return hmm
def _nav_asserts1(I): out = Path("processed.v2") assert out.exists() with (out / "p9704/9/19/info.json").open('r') as file: info = json.load(file) top = mdtraj.load_prmtop(info['stp']['outtop']) for step in ['raw', 'cnv2', 'stp', 'ctr']: assert len(info[step]['gens']) == I, (step, I) for i in range(I): assert Path(info['ctr']['gens'][i]).exists(), i # Load all gens traj = mdtraj.load(info['ctr']['gens'], top=top) assert len(traj) == traj.n_frames assert traj.n_atoms == N_TRIM_ATOMS, traj.n_atoms assert traj.n_frames == PROJ9704_FRAMES_PER_GEN * I, traj.n_frames
def _trek_asserts1(I): out = Path("processed.v2") assert out.exists() with (out / "p9712/5/32/info.json").open('r') as file: info = json.load(file) top = mdtraj.load_prmtop(info['stp']['outtop']) for step in ['raw', 'cnv2', 'stp', 'ctr']: assert len(info[step]['gens']) == I, (step, I) for i in range(I): assert Path(info['ctr']['gens'][i]).exists(), i # Load all gens traj = mdtraj.load(info['ctr']['gens'], top=top) assert len(traj) == traj.n_frames assert traj.n_atoms == 30962, (traj.n_atoms) assert traj.n_frames == 16 * I, traj.n_frames
def _trek_asserts2(I): out = Path("processed.v2") assert out.exists() with (out / "p9761/3/9/info.json").open('r') as file: info = json.load(file) assert info['cnv2']['had_overlapping_frames'] top = mdtraj.load_prmtop(info['stp']['outtop']) for step in ['raw', 'cnv1', 'cnv2', 'stp', 'ctr']: assert len(info[step]['gens']) == I, (step, I) for i in range(I): assert Path(info['ctr']['gens'][i]).exists(), i # Load all gens traj = mdtraj.load(info['ctr']['gens'], top=top) assert len(traj) == traj.n_frames assert traj.n_atoms == 30962, traj.n_atoms assert traj.n_frames == PROJ61_LENGTH_PER_GEN * I, traj.n_frames
ax.set_zlabel("z (nm)") p = ax.scatter(com_matrix[:, 0], com_matrix[:, 1], com_matrix[:, 2], c=time, cmap='viridis') cbar = fig.colorbar(p) cbar.set_label('Time (ns)') return fig, ax if __name__ == '__main__': plt.style.use(['seaborn-talk', 'seaborn-whitegrid']) args = parser.parse_args() print(args) top = mdtraj.load_prmtop(args.prmtop) traj = mdtraj.load([t for t in args.Trajectories], top=args.prmtop, stride=args.stride) print('{} frames have been loaded'.format(traj.n_frames)) # Center all coordinates, makes center of geometry of the system (0, 0, 0) traj.center_coordinates() # Superpose trajectory onto first frame # This is exactly like the 'hold selection steady' command in Chimera traj.superpose(traj, 0) # Create separate trajectory for the ligand ligand_indices = top.select(args.ligand_selection) lig_traj = traj.atom_slice(ligand_indices) center_mass_ligand = mdtraj.compute_center_of_mass(lig_traj) # Plot projections
def SMD(system, prmtop, platform, platformProperties, temperature, positions, velocities, keyInteraction, spring_k, dist_in, dist_fin, SMD_num, save_step, move_force_step): # See page 456 of http://ambermd.org/doc12/Amber17.pdf pullforce = mm.CustomExternalForce('k_sp*0.5*(dx^2+dy^2+dz^2); \ dx=x-(x0+displace_x); \ dy=y-(y0+displace_y); \ dz=z-(z0+displace_z);') pullforce.addPerParticleParameter('k_sp') pullforce.addPerParticleParameter('x0') pullforce.addPerParticleParameter('y0') pullforce.addPerParticleParameter('z0') pullforce.addGlobalParameter("displace_x", 0.0 * u.nanometer) pullforce.addGlobalParameter("displace_y", 0.0 * u.nanometer) pullforce.addGlobalParameter("displace_z", 0.0 * u.nanometer) keyInteraction_pos = [positions[keyInteraction[0]], positions[keyInteraction[1]]] keyInteraction_dist = np.linalg.norm(keyInteraction_pos[0] - keyInteraction_pos[1]) keyInteraction_vect = (keyInteraction_pos[1] - keyInteraction_pos[0]) / keyInteraction_dist keyInteraction_vect = u.Quantity(value=keyInteraction_vect, unit=u.nanometers) pullto = keyInteraction_pos[0] + 0.25 * keyInteraction_vect pullto_old = pullto pullforce.addParticle(keyInteraction[1], [spring_k, pullto[0], pullto[1], pullto[2] ]) system.addForce(pullforce) integrator = mm.LangevinIntegrator(temperature, 4/u.picosecond, 0.002*u.picosecond) simulation = app.Simulation(prmtop.topology, system, integrator, platform, platformProperties) simulation.context.setPositions(positions) simulation.context.setVelocities(velocities) force_val_old = -spring_k*(keyInteraction_dist - dist_in) energy_val_old = u.Quantity(value=0, unit=u.kilocalorie/u.mole) f=open('duck_'+str(temperature).split()[0].replace('.0','K')+'_'+str(SMD_num)+'.dat','w') steps = int((dist_fin.value_in_unit(u.nanometer) / 0.000001 - dist_in.value_in_unit(u.nanometer) / 0.000001)) / move_force_step pull_distance = 0.000001 * move_force_step #write trajectory top = md.load_prmtop('system_solv.prmtop') atom_subset = top.select('not water') simulation.reporters.append(app.StateDataReporter("smd_"+str(temperature).split()[0].replace('.0','K')+"_"+str(SMD_num)+".csv", move_force_step, step=True, time=True, totalEnergy=True, kineticEnergy=True, potentialEnergy=True, temperature=True, density=True, progress=True, totalSteps=move_force_step*steps, speed=True)) simulation.reporters.append(HDF5Reporter("smd_"+str(temperature).split()[0].replace('.0','K')+"_"+str(SMD_num)+".h5", move_force_step*20, atomSubset=atom_subset)) for i in range(steps): state = simulation.context.getState(getPositions=True) pos_keyInt = state.getPositions() keyInteraction_pos = [pos_keyInt[keyInteraction[0]], pos_keyInt[keyInteraction[1]]] keyInteraction_dist = np.linalg.norm(keyInteraction_pos[0]-keyInteraction_pos[1]) keyInteraction_vect = (keyInteraction_pos[1] - keyInteraction_pos[0]) / keyInteraction_dist keyInteraction_vect = u.Quantity(value=keyInteraction_vect, unit=u.nanometers) pullto = keyInteraction_pos[0] + (0.25 + float(i) * pull_distance) * keyInteraction_vect displace = pullto - pullto_old simulation.context.setParameter('displace_x', displace[0]) simulation.context.setParameter('displace_y', displace[1]) simulation.context.setParameter('displace_z', displace[2]) if i == 0: distance = 0.0 else: distance = pull_distance dist_spring = (0.25 + float(i) * pull_distance) * u.nanometer force_val = -spring_k * (keyInteraction_dist - dist_spring) energy_val = energy_val_old + (distance * u.nanometer) * 0.5 * (force_val+force_val_old) force_val_old = force_val energy_val_old = energy_val if (i%int(save_step/move_force_step)) == 0: f.write(str(i)+' '+str(dist_spring)+' '+str(keyInteraction_dist)+' '+str(force_val)+' '+str(energy_val)+'\n') simulation.step(move_force_step) #f.write(str(i)+' '+str(dist_spring)+' '+str(keyInteraction_dist)+' '+str(force_val)+' '+str(energy_val)+'\n') f.close()
import matplotlib.pyplot as plt plt.style.use("ggplot") from msmbuilder.featurizer import SuperposeFeaturizer from msmbuilder.example_datasets import AlanineDipeptide from msmbuilder.hmm import GaussianHMM from msmbuilder.cluster import KCenters from msmbuilder.msm import MarkovStateModel from msmbuilder.dataset import dataset import mdtraj as md from glob import glob filenames = sorted(glob("05_Prod_*.nc")) topology = md.load_prmtop(glob("*nowat.prmtop")[0]) first_frame = md.load_frame(filenames[0], 0, top=topology) indices = [atom.index for atom in topology.atoms if atom.element.symbol in ['C', 'O', 'N']] featurizer = SuperposeFeaturizer(indices, first_frame) sequences = [] for fragment in filenames: for chunk in md.iterload(fragment, chunk = 100, top = topology): sequences.append(featurizer.partial_transform(chunk)) lag_times = [1, 20, 50, 100, 200, 400] hmm_ts0 = {} hmm_ts1 = {} n_states = [n for n in range(2,11,2)]
# coding: utf-8 import scipy as sp from scipy import stats import numpy as np import matplotlib.pyplot as plt import mdtraj as md import sys from sys import argv import math script, parmfile, trajfile = argv top = md.load_prmtop(parmfile) traj = md.load(trajfile, top=top) print(traj) psi_list = md.compute_psi(traj) #phi_list = md.compute_phi(traj) #chi1_list = md.compute_chi1(traj) #chi2_list = md.compute_chi2(traj) for i in xrange(psi_list[1].shape[1]): dihedral_traj = psi_list[1][:, i] dihedral_traj_deg = (dihedral_traj * 180) / math.pi index = np.linspace(1, len(dihedral_traj), len(dihedral_traj)).astype('int') (n, bins, patches) = plt.hist(dihedral_traj_deg, bins=300, range=(-180.00, 180.00), normed=True)
# coding: utf-8 # In[4]: get_ipython().magic(u'pylab inline') import mdtraj as md # In[5]: # Load parameters top = md.load_prmtop("SYSTEM.top") # In[12]: # Select residues of ATP phosphate and Tyr atp_phos = top.select("resSeq 288 and name PG") tyr = top.select("resSeq 53 and name OH") # In[13]: # Check correct atoms selected atom = top.atom(int(atp_phos)) print('''This is the %sth atom, atom type is %s. Part of a %s residue.''' % (atom.index, atom.name, atom.residue.name)) atom = top.atom(int(tyr)) print('''This is the %sth atom, atom type is %s. Part of a %s residue.''' % (atom.index, atom.name, atom.residue.name)) # In[15]: # Make an array containing each atom pair involved in the interaction
import os import matplotlib from matplotlib.pyplot import * import matplotlib.pyplot as plt plt.style.use("ggplot") from msmbuilder.featurizer import SuperposeFeaturizer from msmbuilder.example_datasets import AlanineDipeptide from msmbuilder.hmm import GaussianHMM from msmbuilder.cluster import KCenters from msmbuilder.msm import MarkovStateModel from msmbuilder.dataset import dataset import mdtraj as md from glob import glob filenames = sorted(glob("05_Prod_*.nc")) topology = md.load_prmtop(glob("*nowat.prmtop")[0]) first_frame = md.load_frame(filenames[0], 0, top=topology) indices = [ atom.index for atom in topology.atoms if atom.element.symbol in ['C', 'O', 'N'] ] featurizer = SuperposeFeaturizer(indices, first_frame) sequences = [] for fragment in filenames: for chunk in md.iterload(fragment, chunk=100, top=topology): sequences.append(featurizer.partial_transform(chunk)) lag_times = [1, 20, 50, 100, 200, 400] hmm_ts0 = {}
# Run from a folder with directory structure *current folder*/ATP_OUTPUT/ # coding: utf-8 # get_ipython().magic(u'pylab inline') import scipy as sp from scipy import stats import numpy as np import matplotlib.pyplot as plt import mdtraj as md import sys from sys import argv #use pylab inline with ipython, but switch to import when converting to a script import mdtraj as md # Load parameters top = md.load_prmtop("complex_solv.parm7") # Load trajectory traj = md.load('traj000000002.dcd', top=top) print traj # Select residues of ATP phosphate and Peptide Thr atp_phos = top.select("resSeq 288 and name PG") pep_thr = top.select("resSeq 293 and name OG1") # Check correct atoms selected atom = top.atom(int(atp_phos)) print('''This is the %sth atom, atom type is %s. Part of a %s residue.''' % (atom.index, atom.name, atom.residue.name)) atom = top.atom(int(pep_thr)) print('''This is the %sth atom, atom type is %s.