def __init__(self, config, plot_config): # self.logger = get_logger('plotnm.log', 'plotnm', []) # #Get Surface Point Provider config_spp = self._get_spp_config(config['spp']) natoms, self.nstates, properties = self._get_db_info( config_spp['use_db']['database']) atomids = [1 for _ in range(natoms)] self.spp = SurfacePointProvider(None, properties, self.nstates, natoms, atomids, logger=self.logger, config=config_spp) # self.interpolator = self.spp.interpolator self.savefile = config['savefile'] self.interpolator.train(self.savefile) # qs, crds = self.generate_crds(config['moldenfile'], mode=config['mode'], start=config['start'], end=config['end'], npoints=config['npoints']) energy = self._compute(crds) data = [] conv = energy_converter.get_converter('au', config['energy_units']) for q, en in zip(qs, energy): en = conv(en) - conv(config['reference_energy']) data += [[q, *en]] data = np.array(data) if config['save_data'] == 'yes': np.savetxt(config['save_data']['data_file'], data) if config['plot_pes'] == 'yes': nstates = data.shape[1] - 1 myplt = Plot(plot_config) myax = myplt.line_plot(data[:, [0, 1]], x_units_in=('length', 'au'), y_units_in=('energy', config['energy_units']), ax=None, show_plot=False, save_plot=False) for state in range(1, nstates): save = False plot = False if state == nstates - 1: save = True plot = True myax = myplt.line_plot(data[:, [0, state + 1]], x_units_in=('length', 'au'), y_units_in=('energy', config['energy_units']), ax=myax, show_plot=plot, save_plot=save)
def from_inputfile(cls, inputfile): if not (exists_and_isfile(inputfile)): config = cls.generate_input(inputfile, config=None) else: config = cls.generate_input(inputfile, config=inputfile) quests = cls.generate_questions(config=inputfile) config = quests.check_only(inputfile) plot_config = {} if config['plot_pes'].value == 'yes': plot_config = {} plot_config['x_label'] = 'mode' plot_config['x_label_unit'] = False plot_config['y_label_unit'] = True plot_config['y_label'] = 'energy' plot_config = {'': plot_config} presets = '' presets += f"y_label = energy\n" presets += f"x_label_unit = True\n" presets += f"[save_plot(yes)]\nplot_file = plot_fit_pes_nm.png\n" presets += "legend = {}\n" plot_input = config['plot_pes']['plot_inputfile'] if exists_and_isfile(plot_input): plot_config = Plot.generate_input(plot_input, config=plot_input, presets=presets) else: plot_config = Plot.generate_input(plot_input, config=plot_config, presets=presets) return cls(config, plot_config)
def from_inputfile(cls, inputfile): if not(exists_and_isfile(inputfile)): config = cls.generate_input(inputfile, config=None) else: config = cls.generate_input(inputfile, config=inputfile) quests = cls.generate_questions(config=inputfile) config = quests.check_only(inputfile) if config['plot_spectrum'].value == 'yes': plot_config = {} if config['broadening'].value == 'yes': plot_config['x_start'] = config['broadening']['energy_start'] plot_config['x_end'] = config['broadening']['energy_end'] plot_config['x_label'] = 'energy' plot_config['y_label_unit'] = True plot_config['y_label'] = 'intensity' plot_config['x_units'] = config['energy_units'] plot_config['x_label_unit'] = True plot_config = {'': plot_config} presets = '' if config['broadening'].value == 'yes': presets += f"x_start = {config['broadening']['energy_start']}\n" presets += f"x_end = {config['broadening']['energy_end']}\n" presets += f"x_label = energy\n" presets += f"y_label_unit = True\n" presets += f"y_label = intensity\n" presets += f"y_units = a.u.\n" presets += f"x_units = {config['energy_units']}\n" presets += f"x_label_unit = True\n" presets += f"[save_plot(yes)]\nplot_file = spectrum/spectrum.png\n" plot_input = config['plot_spectrum']['plot_inputfile'] if exists_and_isfile(plot_input): plot_config = Plot.generate_input(plot_input, config=plot_input, presets=presets) else: plot_config = Plot.generate_input(plot_input, config=plot_config, presets=presets) return cls(config, plot_config)
def from_inputfile(cls, inputfile): if not (exists_and_isfile(inputfile)): config = cls.generate_input(inputfile, config=None) else: config = cls.generate_input(inputfile, config=inputfile) quests = cls.generate_questions(config=inputfile) config = quests.check_only(inputfile) plot_config = {} if config['plot_population'].value == 'yes': plot_config = {} # plot_config['x_label'] = 'time' plot_config['x_units'] = config['time_units'] plot_config['x_label_unit'] = True plot_config['y_label_unit'] = False plot_config['y_label'] = 'population' plot_config = {'': plot_config} presets = '' presets += f"y_start = 0.0\n" presets += f"y_end = 1.0\n" presets += f"x_label = time\n" presets += f"y_label_unit = False\n" presets += f"y_label = population\n" presets += f"x_units = {config['time_units']}\n" presets += f"x_label_unit = True\n" presets += f"[save_plot(yes)]\nplot_file = population.png\n" presets += "legend = {}\n" plot_input = config['plot_population']['plot_inputfile'] if exists_and_isfile(plot_input): plot_config = Plot.generate_input(plot_input, config=plot_input, presets=presets) else: plot_config = Plot.generate_input(plot_input, config=plot_config, presets=presets) return cls(config, plot_config)
def __init__(self, config): db = DynDB.load_database(config['prop_db'], read_only=True) nstates = db.nstates npoints = len(db) data = np.empty((npoints, nstates+1), dtype=float) data[:, 0] = np.array(db['time'])[:, 0] data[:, 1:] = np.array(db['energy'])-config['reference_energy'] currstate = np.array(db['currstate'])[:, 0] plot_config = {} plot_config['x_label'] = 'time' plot_config['y_label'] = 'energy' plot_config['y_units'] = 'eV' plot_config['x_units'] = 'fs' plot_config['y_label_unit'] = True plot_config['x_label_unit'] = True plot_config = {'': plot_config} # plot_config['save_plot'] = {'plot_file': 'pes_traj.png'} presets = """ x_label = time y_label = energy y_units = eV x_units = fs y_label_unit = True x_label_unit = True """ if exists_and_isfile(self._plot_input): plot_config = Plot.generate_input(self._plot_input, config=self._plot_input, presets=presets) else: plot_config = Plot.generate_input(self._plot_input, config=plot_config, presets=presets) myplot = Plot(plot_config) if nstates == 1: save_plot = True show_plot = True else: save_plot = False show_plot = False myax = myplot.line_plot(data[:,[0,1]], x_units_in=['time', 'au'], y_units_in=['energy', 'au'], ax=None, save_plot=save_plot, show_plot=show_plot) for state in range(1, nstates): myax = myplot.line_plot(data[:,[0, state+1]], x_units_in=['time', 'au'], y_units_in=['energy', 'au'], ax=myax, show_plot=False, save_plot=False) curr_plot = np.empty((npoints, 2), dtype=float) curr_plot[:, 0] = data[:, 0] for idx, state in enumerate(currstate): curr_plot[idx, 1] = data[idx, int(state + 1)] myax = myplot.line_plot(curr_plot, x_units_in=['time', 'au'], y_units_in=['energy', 'au'], ax=myax, save_plot=True, show_plot=True, line_props={'marker': 'o', 'color': 'red'})
def __init__(self, config, plot_config=None): self.config = config sampling = Sampling.from_db(self.specfile) nstates = sampling.info['dimensions']['nstates'] npoints = sampling.nconditions data = [] for energy, fosc in zip(np.copy(sampling._db['energy']), np.copy(sampling._db['fosc'])): for idx, en in enumerate(energy[1:]): data += [[en - energy[0], fosc[idx+1]]] data = np.array(data) converter = energy_converter.get_converter('au', self.config['energy_units']) data[:, 0] = converter(data[:, 0]) if config['broadening'].value == 'yes': cont_data = Broadening(config['broadening']).broadening(data) else: cont_data = np.sort(data) Plot(plot_config).line_plot(cont_data, ('energy', self.config['energy_units']), y_units_in=None, ax=None, line_props={'linestyle':'solid'})
def __init__(self, config, plot_config=None): self.config = config self.folder = os.path.abspath(config['folder']) self.subfolder = config['subfolder'] subfolderhandle = SubfolderHandle(self.folder, self.subfolder) propfiles = subfolderhandle.fileiter('prop.db') first = True for idx, propfile in enumerate(propfiles): db = DynDB.load_database(propfile, read_only=True) print(propfile) dbtime = np.array(db['time']).flatten() if len(dbtime) == 0: continue if first is True: first = False if config['nsteps'] is not None: nsteps = config['nsteps'] else: nsteps = len(db) nstates = db.info['dimensions']['nstates'] data = np.zeros(shape=(nsteps, nstates + 1), dtype=float) data[:min(len(db), nsteps), 0] = dbtime counter = np.zeros(nsteps, dtype=int) if nsteps > len(db): times_missing = True time_steps = len(db) else: times_missing = False time_steps = len(db) if np.max( np.abs(data[:min(time_steps, len(dbtime)), 0] - dbtime[:min(time_steps, len(dbtime))])) < 0.1: if len(dbtime) > time_steps and times_missing is True: data[time_steps:len(dbtime), 0] = dbtime[time_steps:min(nsteps, len(dbtime))] time_steps = len(dbtime) currstate = np.array(db['currstate']).flatten() for idx in range(min(len(dbtime), nsteps)): data[idx, int(currstate[idx] + 1)] += 1 counter[idx] += 1 else: print('times do not fit') data[:, 1:] = data[:, 1:] / np.repeat(counter, nstates).reshape( nsteps, nstates) converter = time_converter.get_converter('au', self.config['time_units']) data[:, 0] = converter(data[:, 0]) if config['save_data'].value == 'yes': np.savetxt(config['save_data']['data_file'], data) if config['plot_population'].value == 'yes': myplt = Plot(plot_config) myax = myplt.line_plot(data[:, [0, 1]], ('time', self.config['time_units']), y_units_in=None, ax=None, show_plot=False, save_plot=False, line_props={'label': 'state 0'}) for state in range(1, nstates): save = False plot = False if state == nstates - 1: save = True plot = True myax = myplt.line_plot(data[:, [0, state + 1]], ('time', self.config['time_units']), y_units_in=None, ax=myax, show_plot=plot, save_plot=save, line_props={'label': f"state {state}"})
def __init__(self, config): model = ModelBase._models[config['model'].value].from_config( config['model']) nstates = model.nstates crd_equi = model.crd npoints = 100 data = np.empty((npoints, nstates + 1), dtype=float) data[:, 0] = np.linspace(config['start_plot'], config['end_plot'], npoints) for idx, point in enumerate(data[:, 0]): crd = np.zeros(model.crd.size) crd[config['mode']] = point data[idx, 1:] = model.get( Request(crd, properties=['energy'], states=[i for i in range(nstates)]))['energy'] print(data) plot_config = {} plot_config['x_label'] = f"mode config['mode']" plot_config['x_start'] = config['start_plot'] plot_config['x_end'] = config['end_plot'] plot_config['y_label'] = 'energy' plot_config['y_units'] = 'eV' plot_config['x_units'] = 'au' plot_config['y_label_unit'] = True plot_config['x_label_unit'] = True plot_config = {'': plot_config} presets = """ x_label = mode y_label = energy y_units = eV x_units = au y_label_unit = True x_label_unit = True """ if exists_and_isfile(self._plot_input): plot_config = Plot.generate_input(self._plot_input, config=self._plot_input, presets=presets) else: plot_config = Plot.generate_input(self._plot_input, config=None, presets=None) myplot = Plot(plot_config) if nstates == 1: save_plot = True show_plot = True else: save_plot = False show_plot = False myax = myplot.line_plot(data[:, [0, 1]], x_units_in=['energy', 'a.u.'], y_units_in=['energy', 'au'], ax=None, save_plot=save_plot, show_plot=show_plot) for state in range(1, nstates - 1): myax = myplot.line_plot(data[:, [0, state + 1]], x_units_in=['energy', 'a.u.'], y_units_in=['energy', 'au'], ax=myax, show_plot=False, save_plot=False) myax = myplot.line_plot(data[:, [0, nstates]], x_units_in=['energy', 'a.u.'], y_units_in=['energy', 'au'], ax=myax, show_plot=True, save_plot=True)