def get_angle_trajectory(self, atomSelectionArray, _stop =-1): '''This function returns the alangle between three specified atoms over the whole trajectory\n The preferred input is in dcd format. Otherwise the first trajectory frame is missing\n ToDo: fix issues with xtc input trajectory that angles for all frames are computed. Args: atomSelectionArray(numpy array): list of 3 atom indices as in the structure file _stop (int): Default =-1 (i.e. all frames) Returns: anglesTraj trajectory containing angles between the three atoms specified in the atomSelectionArray Useage: >>> dihedralTraj = get_dihedral_trajectory(_trajectoryFile='test.xtc/dcd', _topologyFile='test.gro',atoms) ''' #if filename is a dcd file use fast method if self.extension_DcD(self._trajectoryFile): collection.clear() selectionString =self.generate_selection_string(atomSelectionArray, "bynum ") selection = self._u.selectAtoms(selectionString) collection.addTimeseries(Timeseries.Angle(selection)) if _stop == -1: _stop = self._u.trajectory.numframes-1 collection.compute(self._u.trajectory, stop=_stop) return collection[0][0] #else else: print "Using frame iteration and not collections module" frames = self._u.trajectory.numframes-1 angles = [] selectionString =self.generate_selection_string(atomSelectionArray, "bynum ") selection = self._u.selectAtoms(selectionString) count =0 for ts in self._u.trajectory: if count == _stop: break angle = selection.angle() angles.append(angle) count = count+1 angles = np.array(angles) angles = np.radians(angles) return angles
def run_dcd_timeseries(self, start, stop, skip=1): collection.clear() for path, analysis in self._dcd_timeseries.items(): print " Adding timeseries: %s" % path collection.addTimeseries(analysis.func) print " Computing..." collection.compute(self._u, start=start, stop=stop, skip=skip) print " Done computing." print "Loading data..." for i, path in enumerate(self._dcd_timeseries.keys()): print " loading table %s with %d values..." % (path, len(collection[i][0])) self.sim.data[path] = collection[i][0] self.sim.data[path+"/analysis_stats"] = np.array([start, stop, skip, -1, -1])
def get_custom_distances_trajectory(self, _atomsArray,_stop=-1): if self.extension_DcD(self._trajectoryFile): collection.clear() selections = [] for l in range(len(_atomsArray)): selectionString =self.generate_selection_string(_atomsArray[l], "bynum ") s = self._u.selectAtoms(selectionString) selections.append(s) for s in selections: collection.addTimeseries(Timeseries.Distance('r',s)) if _stop == -1: _stop = self._u.trajectory.numframes-1 collection.compute(self._u.trajectory, stop=_stop) distances = np.array(collection) distances = distances[:,0,:].transpose() return distances else: selectionsList = [] for atoms in _atomsArray: selection=[] selection.append(self._u.selectAtoms("bynum "+str(atoms[0]))) selection.append(self._u.selectAtoms("bynum "+str(atoms[1]))) selectionsList.append(selection) count = 0 allDist = [] for ts in self._u.trajectory: distArray = [] for s in selectionsList: var = dist(s[0], s[1]) distArray.append(var[2]) allDist.append(distArray) if count == _stop: break count = count+1 allDist = np.array(allDist) allDist = allDist[:,:,0] return allDist
def run(self, trj, ref): self._trj = trj self._ref = ref if len(self._timeseries) > 0: print "Starting timeseries analysis..." collection.clear() for path, tpl in self._timeseries.items(): print " Adding timeseries: %s" % path collection.addTimeseries(tpl[0]) print " Computing..." collection.compute(self._trj.trajectory) print " Done computing." print "Loading data..." for i, path in enumerate(self._timeseries.keys()): print " loading table %s with %d values..." % (path, len(collection[i][0])) self._timeseries[path][1].load(list(collection[i][0])) print "Done timeseries analysis." if len(self._sequential) > 0: print "Running sequential analyses..." for path, tpl in self._sequential.items(): print " Preparing %s" % path tpl[0].prepare(ref=self._ref, trj=self._trj) frames = self._trj.trajectory print " Processing %d frames..." % frames.numframes for i, f in enumerate(frames): if i % len(frames) / 10 == 0: print ".", for path, tpl in self._sequential.items(): tpl[0].process(f) print " done." print " Loading result data..." for path, tpl in self._sequential.items(): tpl[1].load(tpl[0].results()) print "Done sequential analysis."
collection.clear() for res in range(2, numresidues-1): print "Processing residue %d" % res # selection of the atoms involved for the phi for resid '%d' %res ## selectAtoms("atom 4AKE %d C"%(res-1), "atom 4AKE %d N"%res, "atom %d 4AKE CA"%res, "atom 4AKE %d C" % res) phi_sel = universe.residues[res].phi_selection() print phi_sel; # selection of the atoms involved for the psi for resid '%d' %res psi_sel = universe.residues[res].psi_selection() print psi_sel; # collect the timeseries of a dihedral collection.addTimeseries(Timeseries.Dihedral(phi_sel)) collection.addTimeseries(Timeseries.Dihedral(psi_sel)) # iterate through trajectory and compute (see docs for start/stop/skip options) collection.compute(universe.trajectory) # finding the avg and stdev for each residue phi = [] psi = [] for data_phi in collection[0::2]: dih = numpy.rad2deg(data_phi[0]) phi.append([dih.mean(), dih.std()]) for data_psi in collection[1::2]: dih = numpy.rad2deg(data_psi[0]) psi.append([dih.mean(), dih.std()]) # making an array for phi and psi data res = numpy.arange(2, numresidues-1) phi = numpy.array(phi) psi = numpy.array(psi)
collection.clear() for res in range(2, numresidues - 1): print "Processing residue {0:d}".format(res) # selection of the atoms involved for the phi for resid '%d' %res ## select_atoms("atom 4AKE %d C"%(res-1), "atom 4AKE %d N"%res, "atom %d 4AKE CA"%res, "atom 4AKE %d C" % res) phi_sel = universe.residues[res].phi_selection() # selection of the atoms involved for the psi for resid '%d' %res psi_sel = universe.residues[res].psi_selection() # collect the timeseries of a dihedral collection.addTimeseries(Timeseries.Dihedral(phi_sel)) collection.addTimeseries(Timeseries.Dihedral(psi_sel)) # iterate through trajectory and compute (see docs for start/stop/skip options) collection.compute(universe.trajectory) # finding the avg and stdev for each residue phi = [] psi = [] for data_phi in collection[0::2]: dih = np.rad2deg(data_phi[0]) phi.append([dih.mean(), dih.std()]) for data_psi in collection[1::2]: dih = np.rad2deg(data_psi[0]) psi.append([dih.mean(), dih.std()]) # making an array for phi and psi data res = np.arange(2, numresidues - 1) phi = np.array(phi) psi = np.array(psi)