示例#1
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)
示例#2
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)
示例#3
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)