Beispiel #1
0
    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 __init__(self, config):
        """ Class to create initial conditions due to user input. Initial conditions are saved 
            in a file for further usage.
        """
        logger = get_logger('setup_propagation.log', 'setup_propagation')
        SetupBase.__init__(self, logger)


        # Open DB of initial conditions once, so that it is available
        sampling = Sampling.from_db(config['sampling_db'])

        #Make sure that inputfile for the SPP exists and is complete
        
        if exists_and_isfile(config['spp']): lconfig = config['spp']
        else: lconfig = None
        SurfacePointProvider.generate_input(config['spp'], config=lconfig)

        #Make sure that inputfile for RunTrajectory exists and is complete
        if exists_and_isfile(config['prop']): lconfig = config['prop']
        else: lconfig = None
        RunTrajectory.generate_input(config['prop'], config=lconfig)

        #
        if config['n_traj'] == -1:
            ntraj = len(sampling._db)
        else:
            ntraj = config['n_traj']
        if sampling.nconditions < ntraj:
            logger.error(f"Too few initial conditions in {config['sampling_db']}")

        self.setup_folders(range(ntraj), config, sampling)
Beispiel #3
0
    def __init__(self, config):
        """ Class to create initial conditions due to user input. Initial conditions are saved 
            in a file for further usage.
        """
        logger = get_logger('setup_spectrum.log', 'setup_spectrum')
        logger.header('SETUP SPECTRUM', config)
        SetupBase.__init__(self, logger)
        #
        logger.info(f"Opening sampling database {config['sampling_db']}")
        sampling = Sampling.from_db(config['sampling_db'], logger=logger)

        if not exists_and_isfile(config['spp']):
            presets="""
                use_db = no
                """
            logger.info(f"Setting up SPP inputfile: {config['spp']}")
            SurfacePointProvider.generate_input(config['spp'], config=None, presets=presets)
        else:
            logger.info(f"Using SPP inputfile as it is")
            
        if not exists_and_isfile(config['sp_calc']):
            presets=f"""
                properties = {config['properties']}
                nstates = {config['nstates']}
                init_db = init.db
                """
            logger.info(f"Setting up inputfile for the single point calculations")
            SinglePointCalculation.generate_input(config['sp_calc'], config=None, presets=presets)
        else:
            logger.info(f"Using inputfile for the single point calculations as it is")

        logger.info("Starting to prepare the folders...")
        self.setup_folders(range(config['n_cond']), config, sampling)
Beispiel #4
0
 def _check_res_db(self, config, sampling):
     if exists_and_isfile(config['init_db']):
         info = sampling.info
         check1 = all(item in info['variables']
                      for item in config['properties'])
         if 'nstates' in info['dimensions']:
             if (info['dimensions']['nstates'] >= config['nstates']):
                 if 'natoms' in info['dimensions']:
                     if (info['dimensions']['natoms'] ==
                             sampling._db.info['dimensions']['natoms']):
                         check2 = True
                     else:
                         check2 = False
                 if 'nmodes' in info['dimensions']:
                     if (info['dimensions']['nmodes'] ==
                             sampling._db.info['dimensions']['nmodes']):
                         check2 = True
                     else:
                         check2 = False
             else:
                 check2 = False
         else:
             check2 = False
         if check1 and check2:
             return
         else:
             self.logger.error(
                 f"Given database is not appropriate for the results: {config['init_db']}"
             )
Beispiel #5
0
def fill_db(filename, npoints):
    if exists_and_isfile(filename) is True:
        os.remove(filename)

    ho = HarmonicOscillator()
    model = PyrazineSala({'n_states': 3})
    nmodes = len(model.crd)
    nstates = 3
    db = PySurfDB.generate_database(filename,
                                    data=['crd', 'energy'],
                                    dimensions={
                                        'nmodes': nmodes,
                                        'nstates': nstates
                                    },
                                    model=True)
    x = (np.random.random((npoints, nmodes)) - 0.5) * 20
    y = []
    for r in x:
        db.append('crd', r)
        y += [
            model.get(Request(r, ['energy'],
                              [i for i in range(nstates)]))['energy']
        ]
        db.append(
            'energy',
            model.get(Request(r, ['energy'],
                              [i for i in range(nstates)]))['energy'])
        db.increase
    return db
Beispiel #6
0
    def __init__(self, config):
        setup = SubfolderHandle(config['folder'], config['subfolder'])

        counter = 0
        for file in setup.fileiter(config['dbfiles']):
            if counter == 0:
                copied = False
                if not exists_and_isfile(config['mother_db']):
                    copy(file, config['mother_db'])
                    copied = True
                info = PySurfDB.info_database(config['mother_db'])
                if 'natoms' not in info['dimensions']:
                    model = True
                else:
                    model = False
                mother_db = PySurfDB.load_database(
                    config['mother_db'],
                    data=info['variables'],
                    dimensions=info['dimensions'],
                    model=model,
                    sp=False)
                counter += 1
                if copied is True:
                    continue

            CombineDBs(mother_db, file, start=config['start_value'])
            print(f"Added file {file} to DB")
Beispiel #7
0
    def __init__(self, config, logger=None):
        """ 
            Args:
                config, ColtObj:
                    The config contains the information from the colt 
                    questions of the class
                logger, Logger:
                    Logger for the class. If not provided a new logger is created.
        """

        if logger is None:
            self.logger = get_logger('sp_calc.log', 'sp_calc')
            self.logger.header('Single Point Calculation', config)
        else:
            self.logger = logger
        #
        self.logger.info(f"Taking information from {config['init_db']}")
        sampling = Sampling.from_db(config['init_db'], logger=self.logger)

        if not (exists_and_isfile(config['spp'])):
            spp_config = SurfacePointProvider.generate_input(config['spp'])
        else:
            spp_config = SurfacePointProvider.generate_input(
                config['spp'], config=config['spp'])

        self.logger.debug(f"Setting up SPP with {config['spp']}")
        if sampling.molecule is not None:
            spp = SurfacePointProvider.from_config(
                spp_config,
                config['properties'],
                config['nstates'],
                sampling.natoms,
                nghost_states=config['nghost_states'],
                atomids=sampling.atomids)
        else:  #model calculation
            spp = SurfacePointProvider, from_config(spp_config,
                                                    config['properties'],
                                                    config['nstates'],
                                                    sampling.nmodes)

        crd = sampling.get_condition(0).crd

        #check that DB can take the results
        self.logger.debug(
            f"Checking whether {config['init_db']} can take the results")
        self._check_res_db(config, sampling)

        with self.logger.info_block("SPP calculation"):
            res = spp.request(crd,
                              config['properties'],
                              states=[st for st in range(config['nstates'])])

        self.logger.info(f"Writing results to: {config['init_db']}")
        for prop, value in res.iter_data():
            sampling.set(prop, value)
Beispiel #8
0
    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)
Beispiel #10
0
    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'})
Beispiel #11
0
    def __init__(self, config):
        self.logger = get_logger('collect_spectrum.log',
                                 'collect_spectrum.log')
        subfolderhandle = SubfolderHandle(self.folder, self.subfolder)
        specfile = os.path.join(self.folder, 'spectrum.db')

        if exists_and_isfile(specfile):
            self.sampling = Sampling.from_db(specfile, logger=self.logger)
            self.dimensions = self.sampling.info['dimensions']
            self.variables = self.sampling.info['variables']
            if not self._check_sampling(self.sampling):
                logger.error(f"Existing spectrum db is corrupted")
            for counter in range(self.sampling.nconditions,
                                 len(subfolderhandle)):
                snew = Sampling.from_db(subfolderhandle.get_file(
                    self.file, counter),
                                        logger=self.logger)
                if self._check_sampling(snew):
                    self.add_condition(snew)

        else:
            counter = 0
            for file in subfolderhandle.fileiter('init.db'):
                snew = Sampling.from_db(file, logger=self.logger)
                if counter == 0:
                    self.sampling = Sampling.create_db(specfile,
                                                       snew.info['variables'],
                                                       snew.info['dimensions'],
                                                       snew.molecule,
                                                       snew.modes,
                                                       snew.model,
                                                       sp=False,
                                                       logger=self.logger)
                    self.dimensions = self.sampling.info['dimensions']
                    self.variables = self.sampling.info['variables']
                self.add_condition(snew)
                counter += 1
Beispiel #12
0
    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)