def go(self): self.data_reader.open('r') pi = self.progress.indicator pi.operation = 'Initializing' with pi: self.output_file = h5py.File(self.output_filename, 'w') h5io.stamp_creator_data(self.output_file) self.iter_start = self.iter_range.iter_start self.iter_stop = self.iter_range.iter_stop # Construct bin boundaries self.construct_bins(self.parse_binspec(self.binspec)) for idim, (binbounds, midpoints) in enumerate(izip(self.binbounds, self.midpoints)): self.output_file['binbounds_{}'.format(idim)] = binbounds self.output_file['midpoints_{}'.format(idim)] = midpoints # construct histogram self.construct_histogram() # Record iteration range iter_range = self.iter_range.iter_range() self.output_file['n_iter'] = iter_range self.iter_range.record_data_iter_range(self.output_file['histograms']) self.output_file.close()
def go(self): self.data_reader.open('r') pi = self.progress.indicator pi.operation = 'Initializing' with pi: self.output_file = h5py.File(self.output_filename, 'w') h5io.stamp_creator_data(self.output_file) self.iter_start = self.iter_range.iter_start self.iter_stop = self.iter_range.iter_stop # Construct bin boundaries self.construct_bins(self.parse_binspec(self.binspec)) for idim, (binbounds, midpoints) in enumerate( zip(self.binbounds, self.midpoints)): self.output_file['binbounds_{}'.format(idim)] = binbounds self.output_file['midpoints_{}'.format(idim)] = midpoints # construct histogram self.construct_histogram() # Record iteration range iter_range = self.iter_range.iter_range() self.output_file['n_iter'] = iter_range self.iter_range.record_data_iter_range( self.output_file['histograms']) self.output_file.close()
def go(self): pi = self.progress.indicator pi.operation = 'Initializing' with pi: self.duration = self.kinetics_file['durations'][self.iter_start-1:self.iter_stop-1] ##Only select transition events from specified istate to fstate mask = (self.duration['istate'] == self.istate) & (self.duration['fstate'] == self.fstate) self.duration_dsspec = DurationDataset(self.kinetics_file['durations']['duration'], mask, self.iter_start) self.wt_dsspec = DurationDataset(self.kinetics_file['durations']['weight'], mask, self.iter_start) self.output_file = h5py.File(self.output_filename, 'w') h5io.stamp_creator_data(self.output_file) # Construct bin boundaries self.construct_bins(self.parse_binspec(self.binspec)) for idim, (binbounds, midpoints) in enumerate(izip(self.binbounds, self.midpoints)): self.output_file['binbounds_{}'.format(idim)] = binbounds self.output_file['midpoints_{}'.format(idim)] = midpoints # construct histogram self.construct_histogram() # Record iteration range iter_range = numpy.arange(self.iter_start, self.iter_stop, 1, dtype=(numpy.min_scalar_type(self.iter_stop))) self.output_file['n_iter'] = iter_range self.output_file['histograms'].attrs['iter_start'] = self.iter_start self.output_file['histograms'].attrs['iter_stop'] = self.iter_stop self.output_file.close()
def open_files(self): self.output_file = h5io.WESTPAH5File(self.output_filename, 'a', creating_program=True) h5io.stamp_creator_data(self.output_file) self.assignments_file = h5io.WESTPAH5File(self.assignments_filename, 'r')#, driver='core', backing_store=False) self.kinetics_file = h5io.WESTPAH5File(self.kinetics_filename, 'r')#, driver='core', backing_store=False) if not self.iter_range.check_data_iter_range_least(self.assignments_file): raise ValueError('assignments data do not span the requested iterations')
def go(self): pi = self.progress.indicator pi.operation = 'Initializing' with pi: self.duration = self.kinetics_file['durations'][self.iter_start-1:self.iter_stop-1] ##Only select transition events from specified istate to fstate mask = (self.duration['istate'] == self.istate) & (self.duration['fstate'] == self.fstate) self.duration_dsspec = DurationDataset(self.kinetics_file['durations']['duration'], mask, self.iter_start) self.wt_dsspec = DurationDataset(self.kinetics_file['durations']['weight'], mask, self.iter_start) self.output_file = h5py.File(self.output_filename, 'w') h5io.stamp_creator_data(self.output_file) # Construct bin boundaries self.construct_bins(self.parse_binspec(self.binspec)) for idim, (binbounds, midpoints) in enumerate(izip(self.binbounds, self.midpoints)): self.output_file['binbounds_{}'.format(idim)] = binbounds self.output_file['midpoints_{}'.format(idim)] = midpoints # construct histogram self.construct_histogram() # Record iteration range iter_range = numpy.arange(self.iter_start, self.iter_stop, 1, dtype=(numpy.min_scalar_type(self.iter_stop))) self.output_file['n_iter'] = iter_range self.output_file['histograms'].attrs['iter_start'] = self.iter_start self.output_file['histograms'].attrs['iter_stop'] = self.iter_stop self.output_file.close()
def open_files(self): self.output_file = h5io.WESTPAH5File(self.output_filename, 'a', creating_program=True) h5io.stamp_creator_data(self.output_file) self.assignments_file = h5io.WESTPAH5File(self.assignments_filename, 'r')#, driver='core', backing_store=False) self.kinetics_file = h5io.WESTPAH5File(self.kinetics_filename, 'r')#, driver='core', backing_store=False) if not self.iter_range.check_data_iter_range_least(self.assignments_file): raise ValueError('assignments data do not span the requested iterations')
def open_files(self): self.output_file = h5io.WESTPAH5File(self.output_file, 'w', creating_program=True) h5io.stamp_creator_data(self.output_file) opened_files = self.generate_file_list([self.west]) self.westH5 = opened_files[self.west]
def process_args(self, args): self.progress.process_args(args) self.assignments_file = h5io.WESTPAH5File(args.assignments, 'r') self.data_reader.process_args(args) with self.data_reader: self.iter_range.process_args(args) self.output_file = h5io.WESTPAH5File(args.output, 'w', creating_program=True) h5io.stamp_creator_data(self.output_file) if not self.iter_range.check_data_iter_range_least(self.assignments_file): raise ValueError('assignments do not span the requested iterations') self.do_compression = args.compression
def _do_1d_output(self, hist, idim, midpoints): enehist = self._ener_zero(hist) log10hist = numpy.log10(hist) if self.hdf5_output_filename: with h5py.File(self.hdf5_output_filename, 'w') as output_h5: h5io.stamp_creator_data(output_h5) output_h5.attrs['source_data'] = os.path.abspath( self.input_h5.filename) output_h5.attrs['source_dimension'] = idim output_h5['midpoints'] = midpoints output_h5['histogram'] = hist if self.text_output_filename: with textio.NumericTextOutputFormatter( self.text_output_filename) as output_file: output_file.write_header('source data: {} dimension {}'.format( os.path.abspath(self.input_h5.filename), idim)) output_file.write_header('column 0: midpoint of bin') output_file.write_header('column 1: probability in bin') output_file.write_header('column 2: -ln P') output_file.write_header('column 3: log10 P') numpy.savetxt( output_file, numpy.column_stack([midpoints, hist, enehist, log10hist])) if self.plot_output_filename: if self.plotscale == 'energy': plothist = enehist label = r'$\Delta F(x)\,/\,kT$' + '\n' + r'$\left[-\ln\,P(x)\right]$' elif self.plotscale == 'log10': plothist = log10hist label = r'$\log_{10}\ P(x)$' else: plothist = hist label = r'$P(x)$' pyplot.figure() pyplot.plot(midpoints, plothist) pyplot.xlim(self.dimensions[0].get('lb'), self.dimensions[0].get('ub')) if self.plotrange: pyplot.ylim(*self.plotrange) pyplot.xlabel(self.dimensions[0]['label']) pyplot.ylabel(label) if self.plottitle: pyplot.title(self.plottitle) if self.postprocess_function: self.postprocess_function(plothist, midpoints, None) pyplot.savefig(self.plot_output_filename)
def process_args(self, args): self.progress.process_args(args) self.assignments_file = h5io.WESTPAH5File(args.assignments, 'r') self.data_reader.process_args(args) with self.data_reader: self.iter_range.process_args(args) self.output_file = h5io.WESTPAH5File(args.output, 'w', creating_program=True) h5io.stamp_creator_data(self.output_file) if not self.iter_range.check_data_iter_range_least( self.assignments_file): raise ValueError( 'assignments do not span the requested iterations') self.do_compression = args.compression
def _do_1d_output(self, hist, idim, midpoints): enehist = self._ener_zero(hist) log10hist = numpy.log10(hist) if self.hdf5_output_filename: with h5py.File(self.hdf5_output_filename, 'w') as output_h5: h5io.stamp_creator_data(output_h5) output_h5.attrs['source_data'] = os.path.abspath(self.input_h5.filename) output_h5.attrs['source_dimension'] = idim output_h5['midpoints'] = midpoints output_h5['histogram'] = hist if self.text_output_filename: with textio.NumericTextOutputFormatter(self.text_output_filename) as output_file: output_file.write_header('source data: {} dimension {}'.format(os.path.abspath(self.input_h5.filename),idim)) output_file.write_header('column 0: midpoint of bin') output_file.write_header('column 1: probability in bin') output_file.write_header('column 2: -ln P') output_file.write_header('column 3: log10 P') numpy.savetxt(output_file, numpy.column_stack([midpoints,hist, enehist, log10hist])) if self.plot_output_filename: if self.plotscale == 'energy': plothist = enehist label = r'$\Delta F(x)\,/\,kT$' +'\n' + r'$\left[-\ln\,P(x)\right]$' elif self.plotscale == 'log10': plothist = log10hist label = r'$\log_{10}\ P(x)$' else: plothist = hist label = r'$P(x)$' pyplot.figure() pyplot.plot(midpoints, plothist) pyplot.xlim(self.dimensions[0].get('lb'), self.dimensions[0].get('ub')) if self.plotrange: pyplot.ylim(*self.plotrange) pyplot.xlabel(self.dimensions[0]['label']) pyplot.ylabel(label) if self.plottitle: pyplot.title(self.plottitle) if self.postprocess_function: self.postprocess_function(plothist, midpoints, None) pyplot.savefig(self.plot_output_filename)
def go(self): '''Plot the evolution of the histogram for iterations self.iter_start to self.iter_stop''' idim = self.dimensions[0]['idim'] n_iters = self.input_h5['n_iter'][...] iiter_start = numpy.searchsorted(n_iters, self.iter_start) iiter_stop = numpy.searchsorted(n_iters, self.iter_stop) binbounds = self.input_h5['binbounds_{}'.format(idim)][...] midpoints = self.input_h5['midpoints_{}'.format(idim)][...] hists_ds = self.input_h5['histograms'] itercount = self.iter_stop - self.iter_start # We always round down, so that we don't have a dangling partial block at the end nblocks = itercount // self.iter_step block_iters = numpy.empty((nblocks, 2), dtype=n_iters.dtype) blocked_hists = numpy.zeros((nblocks, hists_ds.shape[1 + idim]), dtype=hists_ds.dtype) for iblock, istart in enumerate( xrange(iiter_start, iiter_start + nblocks * self.iter_step, self.iter_step)): istop = min(istart + self.iter_step, iiter_stop) histslice = hists_ds[istart:istop] # Sum over time histslice = numpy.add.reduce(histslice, axis=0) # Sum over other dimensions blocked_hists[iblock] = sum_except_along(histslice, idim) # Normalize normhistnd(blocked_hists[iblock], [binbounds]) block_iters[iblock, 0] = n_iters[istart] block_iters[iblock, 1] = n_iters[istop - 1] + 1 #enehists = -numpy.log(blocked_hists) enehists = self._ener_zero(blocked_hists) log10hists = numpy.log10(blocked_hists) if self.hdf5_output_filename: with h5py.File(self.hdf5_output_filename, 'w') as output_h5: h5io.stamp_creator_data(output_h5) output_h5.attrs['source_data'] = os.path.abspath( self.input_h5.filename) output_h5.attrs['source_dimension'] = idim output_h5['midpoints'] = midpoints output_h5['histograms'] = blocked_hists output_h5['n_iter'] = block_iters if self.plot_output_filename: if self.plotscale == 'energy': plothist = enehists label = r'$\Delta F(x)\,/\,kT$' + '\n' + r'$\left[-\ln\,P(x)\right]$' elif self.plotscale == 'log10': plothist = log10hists label = r'$\log_{10}\ P(x)$' else: plothist = blocked_hists label = r'$P(x)$' try: vmin, vmax = self.plotrange except TypeError: vmin, vmax = None, None pyplot.figure() norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax) ax = pyplot.gca() nui = NonUniformImage(ax, extent=(midpoints[0], midpoints[-1], block_iters[0, -1], block_iters[-1, -1]), origin='lower', norm=norm) # not sure why plothist works but plothist.T doesn't, and the opposite is true # for _do_2d_output nui.set_data(midpoints, block_iters[:, -1], plothist) ax.images.append(nui) ax.set_xlim(midpoints[0], midpoints[-1]) ax.set_ylim(block_iters[0, -1], block_iters[-1, -1]) cb = pyplot.colorbar(nui) cb.set_label(label) pyplot.xlabel(self.dimensions[0]['label']) pyplot.xlim(self.dimensions[0].get('lb'), self.dimensions[0].get('ub')) pyplot.ylabel('WE Iteration') if self.plottitle: pyplot.title(self.plottitle) if self.postprocess_function: self.postprocess_function(plothist, midpoints, binbounds) pyplot.savefig(self.plot_output_filename)
def _do_2d_output(self, hist, idims, midpoints, binbounds): enehist = self._ener_zero(hist) log10hist = numpy.log10(hist) if self.hdf5_output_filename: with h5py.File(self.hdf5_output_filename, 'w') as output_h5: h5io.stamp_creator_data(output_h5) output_h5.attrs['source_data'] = os.path.abspath( self.input_h5.filename) output_h5.attrs['source_dimensions'] = numpy.array( idims, numpy.min_scalar_type(max(idims))) output_h5.attrs['source_dimension_labels'] = numpy.array( [dim['label'] for dim in self.dimensions]) for idim in idims: output_h5['midpoints_{}'.format(idim)] = midpoints output_h5['histogram'] = hist if self.plot_output_filename: if self.plotscale == 'energy': plothist = enehist label = r'$\Delta F(\vec{x})\,/\,kT$' + '\n' + r'$\left[-\ln\,P(x)\right]$' elif self.plotscale == 'log10': plothist = log10hist label = r'$\log_{10}\ P(\vec{x})$' else: plothist = hist plothist[~numpy.isfinite(plothist)] = numpy.nan label = r'$P(\vec{x})$' try: vmin, vmax = self.plotrange except TypeError: vmin, vmax = None, None pyplot.figure() # Transpose input so that axis 0 is displayed as x and axis 1 is displayed as y # pyplot.imshow(plothist.T, interpolation='nearest', aspect='auto', # extent=(midpoints[0][0], midpoints[0][-1], midpoints[1][0], midpoints[1][-1]), # origin='lower', vmin=vmin, vmax=vmax) # The following reproduces the former calls to imshow and colorbar norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax) ax = pyplot.gca() nui = NonUniformImage(ax, extent=(midpoints[0][0], midpoints[0][-1], midpoints[1][0], midpoints[1][-1]), origin='lower', norm=norm) nui.set_data(midpoints[0], midpoints[1], plothist.T) ax.images.append(nui) ax.set_xlim(midpoints[0][0], midpoints[0][-1]) ax.set_ylim(midpoints[1][0], midpoints[1][-1]) cb = pyplot.colorbar(nui) cb.set_label(label) pyplot.xlabel(self.dimensions[0]['label']) pyplot.xlim(self.dimensions[0].get('lb'), self.dimensions[0].get('ub')) pyplot.ylabel(self.dimensions[1]['label']) pyplot.ylim(self.dimensions[1].get('lb'), self.dimensions[1].get('ub')) if self.plottitle: pyplot.title(self.plottitle) if self.postprocess_function: self.postprocess_function(plothist, midpoints, binbounds) if self.plot_contour: pyplot.contour(midpoints[0], midpoints[1], plothist.T) pyplot.savefig(self.plot_output_filename)
def go(self): '''Plot the evolution of the histogram for iterations self.iter_start to self.iter_stop''' idim = self.dimensions[0]['idim'] n_iters = self.input_h5['n_iter'][...] iiter_start = numpy.searchsorted(n_iters, self.iter_start) iiter_stop = numpy.searchsorted(n_iters, self.iter_stop) binbounds = self.input_h5['binbounds_{}'.format(idim)][...] midpoints = self.input_h5['midpoints_{}'.format(idim)][...] hists_ds = self.input_h5['histograms'] itercount = self.iter_stop - self.iter_start # We always round down, so that we don't have a dangling partial block at the end nblocks = itercount // self.iter_step block_iters = numpy.empty((nblocks,2), dtype=n_iters.dtype) blocked_hists = numpy.zeros((nblocks,hists_ds.shape[1+idim]), dtype=hists_ds.dtype) for iblock, istart in enumerate(xrange(iiter_start, iiter_start+nblocks*self.iter_step, self.iter_step)): istop = min(istart+self.iter_step, iiter_stop) histslice = hists_ds[istart:istop] # Sum over time histslice = numpy.add.reduce(histslice, axis=0) # Sum over other dimensions blocked_hists[iblock] = sum_except_along(histslice, idim) # Normalize normhistnd(blocked_hists[iblock], [binbounds]) block_iters[iblock,0] = n_iters[istart] block_iters[iblock,1] = n_iters[istop-1]+1 #enehists = -numpy.log(blocked_hists) enehists = self._ener_zero(blocked_hists) log10hists = numpy.log10(blocked_hists) if self.hdf5_output_filename: with h5py.File(self.hdf5_output_filename, 'w') as output_h5: h5io.stamp_creator_data(output_h5) output_h5.attrs['source_data'] = os.path.abspath(self.input_h5.filename) output_h5.attrs['source_dimension'] = idim output_h5['midpoints'] = midpoints output_h5['histograms'] = blocked_hists output_h5['n_iter'] = block_iters if self.plot_output_filename: if self.plotscale == 'energy': plothist = enehists label = r'$\Delta F(x)\,/\,kT$' +'\n' + r'$\left[-\ln\,P(x)\right]$' elif self.plotscale == 'log10': plothist = log10hists label = r'$\log_{10}\ P(x)$' else: plothist = blocked_hists label = r'$P(x)$' try: vmin, vmax = self.plotrange except TypeError: vmin, vmax = None, None pyplot.figure() norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax) ax = pyplot.gca() nui = NonUniformImage(ax, extent=(midpoints[0], midpoints[-1], block_iters[0,-1], block_iters[-1,-1]), origin='lower', norm=norm) # not sure why plothist works but plothist.T doesn't, and the opposite is true # for _do_2d_output nui.set_data(midpoints, block_iters[:,-1], plothist) ax.images.append(nui) ax.set_xlim(midpoints[0], midpoints[-1]) ax.set_ylim(block_iters[0,-1], block_iters[-1,-1]) cb = pyplot.colorbar(nui) cb.set_label(label) pyplot.xlabel(self.dimensions[0]['label']) pyplot.xlim(self.dimensions[0].get('lb'), self.dimensions[0].get('ub')) pyplot.ylabel('WE Iteration') if self.plottitle: pyplot.title(self.plottitle) if self.postprocess_function: self.postprocess_function(plothist, midpoints, binbounds) pyplot.savefig(self.plot_output_filename)
def _do_2d_output(self, hist, idims, midpoints, binbounds): enehist = self._ener_zero(hist) log10hist = numpy.log10(hist) if self.hdf5_output_filename: with h5py.File(self.hdf5_output_filename, 'w') as output_h5: h5io.stamp_creator_data(output_h5) output_h5.attrs['source_data'] = os.path.abspath(self.input_h5.filename) output_h5.attrs['source_dimensions'] = numpy.array(idims, numpy.min_scalar_type(max(idims))) output_h5.attrs['source_dimension_labels'] = numpy.array([dim['label'] for dim in self.dimensions]) for idim in idims: output_h5['midpoints_{}'.format(idim)] = midpoints output_h5['histogram'] = hist if self.plot_output_filename: if self.plotscale == 'energy': plothist = enehist label = r'$\Delta F(\vec{x})\,/\,kT$' +'\n' + r'$\left[-\ln\,P(x)\right]$' elif self.plotscale == 'log10': plothist = log10hist label = r'$\log_{10}\ P(\vec{x})$' else: plothist = hist plothist[~numpy.isfinite(plothist)] = numpy.nan label = r'$P(\vec{x})$' try: vmin, vmax = self.plotrange except TypeError: vmin, vmax = None, None pyplot.figure() # Transpose input so that axis 0 is displayed as x and axis 1 is displayed as y # pyplot.imshow(plothist.T, interpolation='nearest', aspect='auto', # extent=(midpoints[0][0], midpoints[0][-1], midpoints[1][0], midpoints[1][-1]), # origin='lower', vmin=vmin, vmax=vmax) # The following reproduces the former calls to imshow and colorbar norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax) ax = pyplot.gca() nui = NonUniformImage(ax, extent=(midpoints[0][0], midpoints[0][-1], midpoints[1][0], midpoints[1][-1]), origin='lower', norm=norm) nui.set_data(midpoints[0], midpoints[1], plothist.T) ax.images.append(nui) ax.set_xlim(midpoints[0][0], midpoints[0][-1]) ax.set_ylim(midpoints[1][0], midpoints[1][-1]) cb = pyplot.colorbar(nui) cb.set_label(label) pyplot.xlabel(self.dimensions[0]['label']) pyplot.xlim(self.dimensions[0].get('lb'), self.dimensions[0].get('ub')) pyplot.ylabel(self.dimensions[1]['label']) pyplot.ylim(self.dimensions[1].get('lb'), self.dimensions[1].get('ub')) if self.plottitle: pyplot.title(self.plottitle) if self.postprocess_function: self.postprocess_function(plothist, midpoints, binbounds) if self.plot_contour: pyplot.contour(midpoints[0], midpoints[1],plothist.T) pyplot.savefig(self.plot_output_filename)