def calculate_gp(self, atoms): # Compute energy, forces, and stresses and their uncertainties if self.par: res = predict_on_structure_efs_par(atoms, self.gp_model, write_to_structure=False) else: res = predict_on_structure_efs(atoms, self.gp_model, write_to_structure=False) # Set the energy, force, and stress attributes of the calculator. res_name = [ "local_energies", "forces", "partial_stresses", "local_energy_stds", "stds", "partial_stress_stds", ] res_dims = [1, 3, 6, 1, 3, 6] for i in range(len(res_name)): if len(res[i].shape) == 2: assert ( res[i].shape[1] == res_dims[i], f"{res_name[i]} shape doesn't match, " f"{res[i].shape[1]} and {res_dims[i]}", ) elif len(res[i].shape) == 1: assert res_dims[i] == 1 self.results[res_name[i]] = res[i]
def test_predict_efs(two_plus_three_gp): test_structure, _ = \ get_random_structure(np.eye(3), [1, 2], 3) ens, forces, stresses, en_stds, force_stds, stress_stds = \ predict_on_structure_efs(test_structure, two_plus_three_gp) forces_2, force_stds_2 = \ predict_on_structure(test_structure, two_plus_three_gp) ens_p, forces_p, stresses_p, en_stds_p, force_stds_p, stress_stds_p = \ predict_on_structure_efs_par(test_structure, two_plus_three_gp) # Check agreement between efs and standard prediction. assert (np.isclose(forces, forces_2).all()) assert (np.isclose(force_stds, force_stds_2).all()) # Check agreement between serial and parallel efs methods. assert (np.isclose(ens, ens_p).all()) assert (np.isclose(forces, forces_p).all()) assert (np.isclose(stresses, stresses_p).all()) assert (np.isclose(en_stds, en_stds_p).all()) assert (np.isclose(force_stds, force_stds_p).all()) assert (np.isclose(stress_stds, stress_stds_p).all()) # Check that the prediction has been recorded within the structure. assert(np.equal(stress_stds, test_structure.partial_stress_stds).all())
def calculate_gp(self, atoms): # Compute energy, forces, and stresses and their uncertainties if self.par: res = predict_on_structure_efs_par(atoms, self.gp_model, write_to_structure=False) else: res = predict_on_structure_efs(atoms, self.gp_model, write_to_structure=False) # Set the energy, force, and stress attributes of the calculator. self.results["local_energies"] = res[0] self.results["forces"] = res[1] self.results["partial_stresses"] = -res[2][:, [0, 3, 5, 4, 2, 1]] self.results["local_energy_stds"] = res[3] self.results["stds"] = res[4] self.results["partial_stress_stds"] = res[5][:, [0, 3, 5, 4, 2, 1]]