def calculate_energy(x0, trainer): OH_bond_length = x0[0] bond_angle = x0[1] calculator = AMPtorch(trainer) image = molecule('H2O') image.set_distance(0, 2, OH_bond_length, fix=0) image.set_angle(1, 0, 2, bond_angle) image.set_cell([10, 10, 10]) image.center() image.set_calculator(calculator) return image.get_potential_energy() # def optimize_energy(x0): # OH_bond_length = x0[0] # bond_angle = x0[1] # trainer = AtomsTrainer() # # loading the pretrained model # trainer.load_pretrained("../checkpoints/2021-03-22-14-02-20-test") # calculator = AMPtorch(trainer) # image = molecule('H2O') # image.set_distance(0, 2, OH_bond_length, fix=0) # image.set_angle(1, 0, 2, bond_angle) # image.set_cell([10, 10, 10]) # # fix the OH. # fix_OH = FixAtoms([0, 1]) # image.set_constraint(fix_OH) # image.center() # image.set_calculator(calculator) # print("Before minimizing forces: ") # print(image.get_distance(0, 2)) # print(image.get_angle(1, 0, 2)) # print(image.get_potential_energy()) # dyn = BFGS(image) # dyn.run(fmax=1e-3) # print("Before minimizing forces: ") # print(image.get_distance(0, 2)) # print(image.get_angle(1, 0, 2)) # return dyn # optimize_energy([1.2, 120])
"scaling": { "type": "normalize", "range": (0, 1) }, }, "cmd": { "debug": False, "run_dir": "./", "seed": 1, "identifier": "test", "verbose": True, # Weights and Biases used for logging - an account(free) is required "logger": False, }, } torch.set_num_threads(1) trainer = AtomsTrainer(config) trainer.train() predictions = trainer.predict(images) true_energies = np.array([image.get_potential_energy() for image in images]) pred_energies = np.array(predictions["energy"]) print("Energy MSE:", np.mean((true_energies - pred_energies)**2)) print("Energy MAE:", np.mean(np.abs(true_energies - pred_energies))) image.set_calculator(AMPtorch(trainer)) image.get_potential_energy()
def calculate_energy(x0): OH_bond_length = x0[0] bond_angle = x0[1] images = read("../data/water.traj", index=":") images = [images[0]] sigmas = np.logspace(np.log10(0.02), np.log10(1.0), num=5) MCSHs = { "MCSHs": { "0": {"groups": [1], "sigmas": sigmas}, "1": {"groups": [1], "sigmas": sigmas}, "2": {"groups": [1, 2], "sigmas": sigmas}, "3": {"groups": [1, 2, 3], "sigmas": sigmas}, "4": {"groups": [1, 2, 3, 4], "sigmas": sigmas}, "5": {"groups": [1, 2, 3, 4, 5], "sigmas": sigmas}, # "6": {"groups": [1, 2, 3, 4, 5, 6, 7], "sigmas": sigmas}, }, "atom_gaussians": { "H": "../MCSH_potentials/H_pseudodensity_2.g", "O": "../MCSH_potentials/O_pseudodensity_4.g", }, "cutoff": 8, } elements = ["H", "O"] config = { "model": {"get_forces": True, "num_layers": 3, "num_nodes": 20}, "optim": { "device": "cpu", "force_coefficient": 0.2, "lr": 1e-3, "batch_size": 8, "epochs": 500, }, "dataset": { "raw_data": images, # "val_split": 0.1, "elements": elements, "fp_scheme": "mcsh", "fp_params": MCSHs, "save_fps": True, }, "cmd": { "debug": False, "run_dir": "./", "seed": 1, "identifier": "test", "verbose": True, "logger": False, }, } trainer = AtomsTrainer(config) # loading the pretrained model trainer.load_pretrained("../checkpoints/2021-03-22-14-02-20-test") calculator = AMPtorch(trainer) image = molecule('H2O') image.set_distance(0, 2, OH_bond_length, fix=0) image.set_angle(1, 0, 2, bond_angle) image.set_cell([10, 10, 10]) image.center() image.set_calculator(calculator) return image.get_potential_energy()
def get_calc(self): return AMPtorch(self)
"verbose": True, "logger": False, }, } config["dataset"]["cutoff_params"] = cosine_cutoff_params torch.set_num_threads(1) cosine_trainer = AtomsTrainer(config) cosine_trainer.train() predictions = cosine_trainer.predict(images) true_energies = np.array([image.get_potential_energy() for image in images]) cosine_pred_energies = np.array(predictions["energy"]) image.set_calculator(AMPtorch(cosine_trainer)) image.get_potential_energy() config["dataset"]["cutoff_params"] = polynomial_cutoff_params torch.set_num_threads(1) polynomial_trainer = AtomsTrainer(config) polynomial_trainer.train() predictions = polynomial_trainer.predict(images) polynomial_pred_energies = np.array(predictions["energy"]) print("Energy MSE (Cosine):", np.mean( (true_energies - cosine_pred_energies)**2)) print("Energy MAE (Cosine):", np.mean(np.abs(true_energies - cosine_pred_energies)))