def slice_timeseries(self,grofile,trajfile,**kwargs): """ Get the time series from a trajectory slice. The workspace holds very little data that cannot be parsed from specs files. However timeseries data for newly-created slices or perhaps even original sources can be large and somewhat costly to generate for an entire data set. For that reason we dump these to disk. For now we write the file based on the incoming trajfile name which should refer to new slices in the post directory. In the future we may extend this to sourced trajectories in a "spot". """ timefile = os.path.basename(re.sub('\.(xtc|trr)$','.clock',trajfile)) diskwrite = kwargs.get('diskwrite',self.write_timeseries_to_disk) timefile_exists = os.path.isfile(os.path.join(self.postdir,timefile)) if timefile_exists and not self.autoreload and diskwrite: status('removing clock file because autoreload=False and diskwrite=True',tag='warning') os.remove(timefile) if timefile_exists and self.autoreload: #---load the clockfile instead of parsing the XTC file dat = load(timefile,path=self.postdir) timeseries = dat['timeseries'] else: uni = gmxread(*[os.path.abspath(i) for i in [grofile,trajfile]]) timeseries = [uni.trajectory[fr].time for fr in range(len(uni.trajectory))] if diskwrite: store({'timeseries':timeseries},timefile,self.postdir, attrs=None,print_types=False,verbose=True) return timeseries
def create_group(self,**kwargs): """ Create a group. """ sn = kwargs['sn'] name = kwargs['group'] select = kwargs['select'] cols = 100 if 'cols' not in kwargs else kwargs['cols'] #---naming convention holds that the group names follow the prefix and we suffix with ndx simkey = self.prefixer(sn)+'.'+name fn = '%s.ndx'%simkey #---see if we need to make this group if os.path.isfile(self.postdir+fn) and name in self.groups[sn]: return elif os.path.isfile(self.postdir+fn): if self.confirm_file(self.postdir+fn): self.groups[sn][name] = {'fn':fn,'select':select} return status('creating group %s'%simkey,tag='status') #---read the structure uni = gmxread(self.get_last_start_structure(sn)) sel = mdasel(uni,select) #---write NDX import numpy as np iii = sel.indices+1 rows = [iii[np.arange(cols*i,cols*(i+1) if cols*(i+1)<len(iii) else len(iii))] for i in range(0,len(iii)/cols+1)] with open(self.postdir+fn,'w') as fp: fp.write('[ %s ]\n'%name) for line in rows: fp.write(' '.join(line.astype(str))+'\n') self.groups[sn][name] = {'fn':fn,'select':select}