Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
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)
Ejemplo n.º 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_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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
 def __init__(self, sppinp):
     #
     self.logger = get_logger('validate.log', 'validation', [])
     #
     config = self._get_spp_config(sppinp)
     #
     natoms, self.nstates, properties = self._get_db_info(config['use_db']['database'])
     atomids = [1 for _ in range(natoms)]
     self.spp = SurfacePointProvider.from_config(config, properties, self.nstates, natoms, 
                                                 atomids=atomids, logger=self.logger)
     #
     self.interpolator = self.spp.interpolator
     #
     self.weightsfile = self.spp.interpolator.weightsfile
     self.interpolator.train(self.weightsfile)
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 def from_inputfile(cls, inputfile):
     config = cls.generate_input(inputfile, config=inputfile)
     #        config['inputfile'] = inputfile
     logger = get_logger('sp_calc.log', 'sp_calc')
     logger.header('Single Point Calculation', config)
     return cls(config, logger)
Ejemplo n.º 8
0
        db.append(
            'energy',
            model.get(Request(r, ['energy'],
                              [i for i in range(nstates)]))['energy'])
        db.increase
    return db


#db1 = fill_db('db1.dat', 5000)
db1 = PySurfDB.load_database('db.dat', read_only=True)
#db2 = fill_db('db2.dat', 1000)
db2 = PySurfDB.load_database('prop.db', read_only=True)

nstates = 4
nmodes = 9
logger = get_logger('test.log', 'test')
config = {
    'energy_threshold': 0.02,
    'trust_radius_ci': 0.5,
    'trust_radius_general': 1.0,
    'inverse_distance': False
}
rbf = RbfInterpolator(config, db1, ['energy'], nstates, nmodes, logger=logger)

counter = 0
diff_sum = 0
diff = []
for crd, energy in zip(db2['crd'], db2['energy']):
    counter += 1
    res, trust = rbf.get(Request(crd, ['energy'], [0, 1, 2]))
    diff += [res['energy'] - energy]
Ejemplo n.º 9
0
    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.from_config(config_spp,
                                                    properties,
                                                    self.nstates,
                                                    natoms,
                                                    atomids=atomids,
                                                    logger=self.logger)
        #
        self.interpolator = self.spp.interpolator
        self.interpolator.train()
        #
        qx, qy, crds = self.generate_crds(
            config['moldenfile'],
            mode=(config['mode'], config['mode2']),
            start=(config['start'], config['start2']),
            end=(config['end'], config['end2']),
            npoints=(config['npoints'], config['npoints2']))
        energy = self._compute(crds)
        data = []
        conv = energy_converter.get_converter('au', config['energy_units'])
        for qxi, qyi, en in zip(np.ravel(qx), np.ravel(qy), energy):
            en = conv(en) - conv(config['reference_energy'])
            data += [[qxi, qyi, *en]]
        data = np.array(data)
        nstates = data.shape[1] - 2
        energy = data[:, 2:]
        energy = energy.T.reshape((nstates, *qx.shape))

        # Take only states according to user input
        if config['states'] is None:
            statelist = [i for i in range(nstates)]
        else:
            statelist = config['states']

        if config['save_data'] == 'yes':
            np.savetxt(config['save_data']['data_file'], data)

        if config['plot_pes'] == 'yes':
            myplt = Plot3D(plot_config)

            save = False
            plot = False
            for state in statelist:
                if state == nstates - 1:
                    save = True
                    plot = True
                if state == statelist[0]:
                    myax = myplt.surface_plot(
                        (qx, qy, energy[state]),
                        x_units_in=('length', 'au'),
                        y_units_in=('length', 'au'),
                        z_units_in=('energy', config['energy_units']),
                        ax=None,
                        show_plot=plot,
                        save_plot=save)
                else:
                    myax = myplt.surface_plot(
                        (qx, qy, energy[state]),
                        x_units_in=('length', 'au'),
                        y_units_in=('length', 'au'),
                        z_units_in=('energy', config['energy_units']),
                        ax=myax,
                        show_plot=plot,
                        save_plot=save)