def resample(self,system): """ A resampling that pulls walker cell assignments from an external file and then resamples the whole system under MultiColor. Given that the assignments are left in post-mapping state at the end of the method, it cannot be used multiple times. Parameters: system - a processed aweclasses.System object Returns: A new aweclasses.System instance representing the resampled input system """ cellmap = self.cellmap # Determine the cell that each walker is assigned to so that # cells can be stored in some arbitrary order (?) for w in system.walkers: w.assignment = cellmap[w.assignment] # Perform MultiColor resampling newsystem = MultiColor.resample(self,system) # Save the transition matrix tmat = os.path.join(OUTPUT_DIR, 'transition-matrix.csv') makedirs_parent(tmat) MultiColor.save_transitions(tmat) return newsystem
def __init__(self, targetwalkers): self.targetwalkers = targetwalkers ##### self.histfile = os.path.join(OUTPUT_DIR, 'walker-history.csv') makedirs_parent(self.histfile) with open(self.histfile, 'a') as fd: fd.write('%origID, parentID, currentID \n')
def __init__(self, targetwalkers): self.targetwalkers = targetwalkers ##### self.histfile = os.path.join(OUTPUT_DIR, 'walker-history.csv') makedirs_parent(self.histfile) with open(self.histfile, 'a') as fd: fd.write('%origID, parentID, currentID \n')
def resample(self, system): cellmap = self.cellmap for w in system.walkers: w.assignment = cellmap[w.assignment] newsystem = MultiColor.resample(self, system) tmat = os.path.join(OUTPUT_DIR, 'transition-matrix.csv') makedirs_parent(tmat) MultiColor.save_transitions(tmat) return newsystem
def resample(self,system): cellmap = self.cellmap for w in system.walkers: w.assignment = cellmap[w.assignment] newsystem = MultiColor.resample(self,system) tmat = os.path.join(OUTPUT_DIR, 'transition-matrix.csv') makedirs_parent(tmat) MultiColor.save_transitions(tmat) return newsystem
def __init__(self, targetwalkers): """ Initialize a new instance of OneColor. Parameters: targetwalkers - a list of target weights to converge to (numeric) Returns: None """ self.targetwalkers = targetwalkers ##### self.histfile = os.path.join(OUTPUT_DIR, 'walker-history.csv') makedirs_parent(self.histfile) with open(self.histfile, 'a') as fd: fd.write('%origID, parentID, currentID \n')
def __init__(self, nwalkers, partition): OneColor.__init__(self, nwalkers) self.partition = partition ncolors = partition.ncolors self.transitions = np.zeros((ncolors, ncolors)) self.iteration = 1 self.cellweights_path = os.path.join(OUTPUT_DIR, 'cell-weights.csv') makedirs_parent(self.cellweights_path) of = open(self.cellweights_path, 'a') of.write('%iteration,cellid,color,total_weight \n') of.close() self.tmat_path = os.path.join(OUTPUT_DIR, 'color-transition-matrix.csv') self.tmat_header = textwrap.dedent("""\ # An ((N+1)*2, 2, 2) matrix, where N is the number of iterations # Can be loaded like: # m = np.loadtxt("color-transitions-matrix.csv",delimiter=",") # itrs = m.shape[0] / 2 # T = m.reshape((itrs, 2, 2)) """)
def __init__(self, nwalkers, partition): OneColor.__init__(self, nwalkers) self.partition = partition ncolors = partition.ncolors self.transitions = np.zeros((ncolors, ncolors)) self.iteration = 1 self.cellweights_path = os.path.join(OUTPUT_DIR, 'cell-weights.csv') makedirs_parent(self.cellweights_path) of = open(self.cellweights_path,'a') of.write('%iteration,cellid,color,total_weight \n') of.close() self.tmat_path = os.path.join(OUTPUT_DIR, 'color-transition-matrix.csv') self.tmat_header = textwrap.dedent( """\ # An ((N+1)*2, 2, 2) matrix, where N is the number of iterations # Can be loaded like: # m = np.loadtxt("color-transitions-matrix.csv",delimiter=",") # itrs = m.shape[0] / 2 # T = m.reshape((itrs, 2, 2)) """ )
class MultiColor(OneColor): """ A resampler for handling multiple macro-states (metastable states) by following transitions between states and resampling each individually. Fields: targetwalkers - the number of walkers, creates a target weight histfile - the path to walker-history.csv partition - awe.aweclasses.SinkStates instance transitions - a matrix containing transition rates between macro-states iteration - the current iteration of the cellweights_path - the path to cell-weights.csv tmat_path - the path to color-transition-matrix.csv tmat_header - the header for the color-transition-matrix.csv file Methods: resample - resample across multiple states save_transitions - output the state transition matrix """ def __init__(self, nwalkers, partition): """ Initialize a new instance of MultiColor. Parameters: nwalkers - the target number of walkers partition - an aweclasses.SinkStates instance Returns: None """ # Set up the output filepath and target weights OneColor.__init__(self, nwalkers) # Partitioning of the states (e.g. conformation space cells) self.partition = partition ncolors = partition.ncolors # Matrix to store transitions between states self.transitions = np.zeros((ncolors, ncolors)) self.iteration = 1 # PAths to output files and necessary header information self.cellweights_path = os.path.join(OUTPUT_DIR, 'cell-weights.csv') makedirs_parent(self.cellweights_path) of = open(self.cellweights_path,'a') of.write('%iteration,cellid,color,total_weight \n') of.close() self.tmat_path = os.path.join(OUTPUT_DIR, 'color-transition-matrix.csv') self.tmat_header = textwrap.dedent( """\ # An ((N+1)*2, 2, 2) matrix, where N is the number of iterations # Can be loaded like: # m = np.loadtxt("color-transitions-matrix.csv",delimiter=",") # itrs = m.shape[0] / 2 # T = m.reshape((itrs, 2, 2)) """ )