def create_hcstrings_states(Assignments, outfile='HCstrings_states.txt'): SA = hct.get_StatesAssignments(Assignments) states = SA.keys() HCstrings_states = {} n = 0 for state in states: n += 1 print "Get HC strings for state %d/%d" % (n, len(states)) TrajID = SA[state].keys() numhelix_state = [] HCstrings_states[state] = [] for trajid in TrajID: TrajFile = '/Users/tud51931/projects/MSM/msm/ff03-hybridkcenter/sourcedata/Trajectories/trj%s_hc.lh5' % trajid Traj = Trajectory.LoadFromLHDF(TrajFile) HCstrings_states[state] += [ Traj['HCs'][i] for i in SA[state][trajid] ] fn = outfile if os.path.exists(fn): newfn = fn + '.bck' os.system('mv %s %s' % (fn, newfn)) print "Write HCstings of states into %s" % fn HCfile = open(fn, 'w') pickle.dump(HCstrings_states, HCfile) HCfile.close() print "Done."
def test1(): """ This test shows how to get the number of helix from a trajectory. """ traj = Trajectory.LoadFromLHDF('/Users/tud51931/projects/MSM/msm/ff03-hybridkcenter/sourcedata/Trajectories/trj34.lh5') numhelix = compute_numhelix_trajectory(traj) print len(numhelix)
def LoadTrajectory(trajectory): if isinstance(trajectory, str): try: t = Trajectory.LoadFromLHDF(trajectory) return t except IOError: raise IOError("Can not find %s" % trajectory) elif isinstance(trajectory, Trajectory): return trajectory
def test2(): """ This test shows how to create new trj files with hc strings. """ path ="/Users/tud51931/projects/MSM/msm/ff03-hybridkcenter/sourcedata/Trajectories" for i in range(0,100): Trajfile = "%s/trj%d.lh5"%(path,i) if os.path.exists(Trajfile): T = Trajectory.LoadFromLHDF(Trajfile) CreateTrajFileWithHCstrings(T) print "Done."
def calculatedistance(AtomName1, ResidueID1, AtomName2, ResidueID2, trajfile, LongestTrajLength): """ Calculate the distance between given two atoms in given trajectory""" t = Trajectory.LoadFromLHDF(trajfile) Atom1 = (t['AtomNames'] == AtomName1) * (t['ResidueID'] == ResidueID1) Atom2 = (t['AtomNames'] == AtomName2) * (t['ResidueID'] == ResidueID2) distance = [] for i in range(len(t['XYZList'])): x = (t['XYZList'][i, Atom1, :] - t['XYZList'][i, Atom2, :])[0] x = x.tolist() distance.append(np.dot(x, x)**0.5) distance += [-1] * (LongestTrajLength - len(t['XYZList'])) return distance
def FixGenFile(Mapping, GenFile, Outfile='./Gens.Fixed.lh5'): """ Use Mapping.dat file get a fixed(mapped) generator file. New generator file will be Gens.Fixed.lh5 """ gen = Trajectory.LoadFromLHDF(GenFile) newgen = copy.deepcopy(gen) mapping = loadtxt(Mapping) GeneratorStateID = np.arange(len(gen['XYZList'])) newgen['StateID'] = GeneratorStateID[mapping >= 0] newgen['XYZList'] = gen['XYZList'][mapping >= 0, :, :] print "Save to %s" % Outfile newgen.SaveToLHDF(Outfile)
def Reference_Rg(trajfile): """ Compute the Rg from single trajfile. """ t = Trajectory.LoadFromLHDF(trajfile) Rg = [] for i in range(len(t['XYZList'])): XYZ = t['XYZList'][i, :, :] mu = XYZ.mean(0) mu = mu.tolist() XYZ2 = XYZ - np.tile(mu, (len(XYZ), 1)) Rg.append(((XYZList**2).sum() / n_atoms)**(0.5)) return Rg
import os, sys import numpy as np from msmbuilder import Trajectory sys.path.append('~/scripts/gfzhou/') import HelixCoilTools as hct from scipy import savetxt """ This script is to get the number of helix from trajectories. """ datafile = "./numhelix_alltraj.txt" if os.path.exists(datafile): print "%s already exists!" % datafile print "quit." sys.exit() path = "/Users/tud51931/projects/MSM/msm/ff03-hybridkcenter/sourcedata/Trajectories" numhelix_alltraj = -1 * np.ones((100, 8000), dtype=int) for i in range(100): Trajfile = "%s/trj%d.lh5" % (path, i) if os.path.exists(Trajfile): T = Trajectory.LoadFromLHDF(Trajfile) print "Compute number of helix for %s" % Trajfile numhelix = hct.compute_numhelix_trajectory(T) numhelix_alltraj[i][:len(numhelix)] = numhelix[:] print "Save data to %s" % datafile savetxt(datafile, numhelix_alltraj) print "Done."
def GetHCStringsforTrajectory(trajectory): if isinstance(trajectory, str): gens = Trajectory.LoadFromLHDF(trajectory) dihedrals = hct.ComputeDihedralsFromTrajectory(gens) HCs = hct.ConvertDihedralsToHCStrings(dihedrals) print HCs