def ComputeDihedralsFromTrajectory(Trajectory): """ Compute dihedrals directly from trajectory files. """ traj = {} traj['XYZList'] = Trajectory['XYZList']/1.0 #convert XYZList to float type indices = dihedral.get_indices(Trajectory,'phi/psi') dihedrals = dihedral.compute_dihedrals(traj,indices,'phi/psi') return dihedrals
def extract_dihedral(project, close, stride, types=None, indices=None, far=None): if indices is None: indices = dihedralcalc.get_indices(project.empty_traj(), types) # get trajectories for A, B, C A,B,C = triplets(project, close, stride, far) metric = metrics.Dihedral(indices=indices) A = metric.prepare_trajectory(A) B = metric.prepare_trajectory(B) C = metric.prepare_trajectory(C) return A-B, A-C
def prepare_trajectory(self, trajectory): """Prepare the dihedral angle representation of a trajectory, suitable for distance calculations. Parameters ---------- trajectory : msmbuilder.Trajectory An MSMBuilder trajectory to prepare Returns ------- projected_angles : ndarray A 2D array of dimension len(trajectory) x (2*number of dihedral angles per frame), such that in each row, the first half of the entries contain the cosine of the dihedral angles and the later dihedral angles contain the sine of the dihedral angles. This transform is necessary so that distance calculations preserve the periodic symmetry. """ traj_length = len(trajectory['XYZList']) if self.angles=='user': indices = self.read_dihedral_indices(self.userfilename) else: if self.indices is None: indices = _dihedralcalc.get_indices(trajectory, self.angles) else: indices = self.indices dihedrals = _dihedralcalc.compute_dihedrals(trajectory, indices, degrees=False) # these dihedrals go between -pi and pi but obviously because of the # periodicity, when we take distances we want the distance between -179 # and +179 to be very close, so we need to do a little transform num_dihedrals = dihedrals.shape[1] transformed = np.empty((traj_length, 2 * num_dihedrals)) transformed[:, 0:num_dihedrals] = np.cos(dihedrals) transformed[:, num_dihedrals:2*num_dihedrals] = np.sin(dihedrals) return np.double(transformed)
def prepare_trajectory(self, trajectory): """Prepare the dihedral angle representation of a trajectory, suitable for distance calculations. Parameters ---------- trajectory : msmbuilder.Trajectory An MSMBuilder trajectory to prepare Returns ------- projected_angles : ndarray A 2D array of dimension len(trajectory) x (2*number of dihedral angles per frame), such that in each row, the first half of the entries contain the cosine of the dihedral angles and the later dihedral angles contain the sine of the dihedral angles. This transform is necessary so that distance calculations preserve the periodic symmetry. """ traj_length = len(trajectory['XYZList']) if self.indices is None: indices = _dihedralcalc.get_indices(trajectory, self.angles) else: indices = self.indices dihedrals = _dihedralcalc.compute_dihedrals(trajectory, indices, degrees=False) # these dihedrals go between -pi and pi but obviously because of the # periodicity, when we take distances we want the distance between -179 # and +179 to be very close, so we need to do a little transform num_dihedrals = dihedrals.shape[1] transformed = np.empty((traj_length, 2 * num_dihedrals)) transformed[:, 0:num_dihedrals] = np.cos(dihedrals) transformed[:, num_dihedrals:2 * num_dihedrals] = np.sin(dihedrals) return np.double(transformed)
import numpy as np from msmbuilder import Trajectory from msmbuilder.geometry import dihedral ff_list = ["amber96","amber99","amber99sbnmr-ildn","oplsaa","charmm27"] for ff in ff_list: print(ff) directory = "/home/kyleb/dat/lvbp/%s/" % ff R = Trajectory.load_from_xtc([directory + "/production/trajout.xtc"],directory + "/final.pdb") ind = dihedral.get_indices(R) di = dihedral.compute_dihedrals(R,ind).T phi = di[0] psi = di[3] data = np.array([phi,psi]) np.savez_compressed(directory + "/rama.npz", data) """ ff = "amber99" R = Trajectory.load_from_xtc(["/home/kyleb/dat/lvbp/GA-%s/md/trajout.xtc"%ff],"/home/kyleb/dat/lvbp/GA-%s/equil/native.pdb"%ff) ind = dihedral.get_indices(R) di = dihedral.compute_dihedrals(R,ind) io.saveh("/home/kyleb/dat/lvbp/GA-%s/rama.h5"%ff,di) """