コード例 #1
0
    def predict(self, confs, return_std=False, ncores=1):
        """ Predict the forces acting on the central atoms of confs using the
        2- and 3-body GPs. The total force is the sum of the two predictions.

        Args:
            confs (list): List of M x 5 arrays containing coordinates and
                atomic numbers of atoms within a cutoff from the central one
            return_std (bool): if True, returns the standard deviation 
                associated to predictions according to the GP framework

        Returns:
            forces (array): array of force vectors predicted by the GPs
            forces_errors (array): errors associated to the force predictions,
                returned only if return_std is True
        """

        if return_std:
            if self.rep_sig:
                rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
                force_2b, std_2b = self.gp_2b.predict(confs, return_std)
                force_2b += rep_forces
            else:
                force_2b, std_2b = self.gp_2b.predict(
                    confs, return_std, ncores=ncores)
            force_3b, std_3b = self.gp_2b.predict(
                confs, return_std, ncores=ncores)
            return force_2b + force_3b, std_2b + std_3b
        else:
            if self.rep_sig:
                rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
                return self.gp_2b.predict(confs, return_std, ncores=ncores) + rep_forces + \
                    self.gp_3b.predict(confs, return_std, ncores=ncores)
            else:
                return self.gp_2b.predict(confs, return_std, ncores=ncores) + \
                    self.gp_3b.predict(confs, return_std, ncores=ncores)
コード例 #2
0
    def fit_force_and_energy(self, confs, forces, glob_confs, energies, ncores=1):
        """ Fit the GP to a set of training energies using a 2- and
        3-body single species force-force, energy-energy, and energy-forces kernel 
        functions. The 2-body Gaussian process is first fitted, then the 3-body GP 
        is fitted to the difference between the training energies (and forces) and 
        the 2-body predictions of energies (and forces) on the training configurations.

        Args:
            confs (list): List of M x 5 arrays containing coordinates and
                atomic numbers of atoms within a cutoff from the central one
            forces (array) : Array containing the vector forces on 
                the central atoms of the training configurations
            glob_confs (list of lists): List of configurations arranged so that
                grouped configurations belong to the same snapshot
            energies (array) : Array containing the total energy of each snapshot
            ncores (int): number of CPUs to use for the gram matrix evaluation
        """

        hypotetical_model_name = "models/MODEL_ker_TwoBodySingleSpecies_ntr_%i.json" %(len(energies)+len(forces))
        try:
            model_2b = models.TwoBodySingleSpeciesModel.from_json(hypotetical_model_name)
            self.rep_sig = model_2b.rep_sig
            self.gp_2b = model_2b.gp
            if self.rep_sig:
                self.rep_energies = utility.get_repulsive_energies(
                    glob_confs, self.rep_sig)
                energies -= self.rep_energies
                self.rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
                forces -= self.rep_forces

            print("Loaded 2-body model to bootstart training")

        except:
            if self.rep_sig:
                self.rep_sig = utility.find_repulstion_sigma(confs)
                self.rep_energies = utility.get_repulsive_energies(
                    glob_confs, self.rep_sig)
                energies -= self.rep_energies
                self.rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
                forces -= self.rep_forces

            self.gp_2b.fit_force_and_energy(
                confs, forces, glob_confs, energies, ncores=ncores)

        two_body_forces = self.gp_2b.predict(confs, ncores=ncores)
        two_body_energies = self.gp_2b.predict_energy(
            glob_confs, ncores=ncores)
        self.gp_3b.fit_force_and_energy(
            confs, forces - two_body_forces, glob_confs, energies - two_body_energies, ncores=ncores)
コード例 #3
0
    def fit_force_and_energy(self,
                             confs,
                             forces,
                             glob_confs,
                             energies,
                             ncores=1):
        """ Fit the GP to a set of training forces and energies using 
        2-body single species force-force, energy-force and energy-energy kernels

        Args:
            confs (list): List of M x 5 arrays containing coordinates and
                atomic numbers of atoms within a cutoff from the central one
            forces (array) : Array containing the vector forces on 
                the central atoms of the training configurations
            glob_confs (list of lists): List of configurations arranged so that
                grouped configurations belong to the same snapshot
            energies (array) : Array containing the total energy of each snapshot
            ncores (int): number of CPUs to use for the gram matrix evaluation

        """
        if self.rep_sig:
            self.rep_sig = utility.find_repulstion_sigma(confs)
            self.rep_energies = utility.get_repulsive_energies(
                glob_confs, self.rep_sig)
            energies -= self.rep_energies
            self.rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
            forces -= self.rep_forces

        self.gp.fit_force_and_energy(confs,
                                     forces,
                                     glob_confs,
                                     energies,
                                     ncores=ncores)
コード例 #4
0
    def fit(self, confs, forces, ncores=1):
        """ Fit the GP to a set of training forces using a 2- and
        3-body single species force-force kernel functions. The 2-body Gaussian
        process is first fitted, then the 3-body GP is fitted to the difference
        between the training forces and the 2-body predictions of force on the 
        training configurations

        Args:
            confs (list): List of M x 5 arrays containing coordinates and
                atomic numbers of atoms within a cutoff from the central one
            forces (array) : Array containing the vector forces on 
                the central atoms of the training configurations
            ncores (int): number of CPUs to use for the gram matrix evaluation
        """
        hypotetical_model_name = "models/MODEL_ker_TwoBodyManySpecies_ntr_%i.json" %(len(forces))
        try:
            model_2b = models.TwoBodyManySpeciesModel.from_json(hypotetical_model_name)
            self.rep_sig = model_2b.rep_sig
            self.gp_2b = model_2b.gp
            if self.rep_sig:
                self.rep_sig = utility.find_repulstion_sigma(confs)
                self.rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
                forces -= self.rep_forces
            print("Loaded 2-body model to bootstart training")

        except:
            if self.rep_sig:
                self.rep_sig = utility.find_repulstion_sigma(confs)
                self.rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
                forces -= self.rep_forces

            self.gp_2b.fit(confs, forces, ncores=ncores)

        ntr = len(confs)
        two_body_forces = self.gp_2b.predict(confs, ncores=ncores)

        self.gp_3b.fit(confs, forces - two_body_forces, ncores=ncores)
コード例 #5
0
    def fit(self, confs, forces, ncores=1):
        """ Fit the GP to a set of training forces using a 
        2-body single species force-force kernel

        Args:
            confs (list): List of M x 5 arrays containing coordinates and
                atomic numbers of atoms within a cutoff from the central one
            forces (array) : Array containing the vector forces on 
                the central atoms of the training configurations
            ncores (int): number of CPUs to use for the gram matrix evaluation
        """

        if self.rep_sig:
            self.rep_sig = utility.find_repulstion_sigma(confs)
            self.rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
            forces -= self.rep_forces

        self.gp.fit(confs, forces, ncores=ncores)
コード例 #6
0
    def predict(self, confs, return_std=False, ncores=1):
        """ Predict the forces acting on the central atoms of confs using a GP

        Args:
            confs (list): List of M x 5 arrays containing coordinates and
                atomic numbers of atoms within a cutoff from the central one
            return_std (bool): if True, returns the standard deviation 
                associated to predictions according to the GP framework

        Returns:
            forces (array): array of force vectors predicted by the GP
            forces_errors (array): errors associated to the force predictions,
                returned only if return_std is True

        """

        if self.rep_sig:
            rep_forces = utility.get_repulsive_forces(confs, self.rep_sig)
            return self.gp.predict(confs, return_std,
                                   ncores=ncores) + rep_forces

        else:
            return self.gp.predict(confs, return_std, ncores=ncores)