def run(self): output.write_header(self.gp.cutoffs, self.gp.kernel_name, self.gp.hyps, self.gp.algo, self.dt, self.number_of_steps, self.structure, self.output_name, 1.) self.write_mgp_header() counter = 0 self.start_time = time.time() while self.curr_step < self.number_of_steps: self.pred_func() self.dft_step = False new_pos = md.update_positions(self.dt, self.noa, self.structure) if self.curr_step in self.dft_steps: # record GP forces self.update_temperature(new_pos) self.record_state() # run DFT and record forces self.dft_step = True self.run_dft() new_pos = md.update_positions(self.dt, self.noa, self.structure) self.update_temperature(new_pos) self.record_state() # write gp forces if counter >= self.skip and not self.dft_step: self.update_temperature(new_pos) self.record_state() counter = 0 counter += 1 self.update_positions(new_pos) self.curr_step += 1 output.conclude_run(self.output_name)
def run(self): self.output.write_header(self.gp.cutoffs, self.gp.kernel_name, self.gp.hyps, self.gp.algo, self.dt, self.Nsteps, self.structure) self.start_time = time.time() while self.curr_step < self.Nsteps: # verlet algorithm follows Frenkel p. 70 self.pred_func() new_pos = md.update_positions(self.dt, self.noa, self.structure) self.update_temperature(new_pos) self.record_state() self.update_positions(new_pos) self.curr_step += 1 self.output.conclude_run()
def run(self): self.output.write_header(self.gp.cutoffs, self.gp.kernel_name, self.gp.hyps, self.gp.algo, self.dt, self.number_of_steps, self.structure, self.std_tolerance) counter = 0 self.start_time = time.time() while self.curr_step < self.number_of_steps: print('curr_step:', self.curr_step) # run DFT and train initial model if first step and DFT is on if self.curr_step == 0 and self.std_tolerance != 0: # call dft and update positions self.run_dft() dft_frcs = copy.deepcopy(self.structure.forces) new_pos = md.update_positions(self.dt, self.noa, self.structure) self.update_temperature(new_pos) self.record_state() # make initial gp model and predict forces self.update_gp(self.init_atoms, dft_frcs) if (self.dft_count - 1) < self.freeze_hyps: self.train_gp() # after step 1, try predicting with GP model else: self.gp.check_L_alpha() self.pred_func(self.structure, self.gp, self.no_cpus) self.dft_step = False new_pos = md.update_positions(self.dt, self.noa, self.structure) # get max uncertainty atoms std_in_bound, target_atoms = is_std_in_bound( self.std_tolerance, self.gp.hyps[-1], self.structure, self.max_atoms_added) if not std_in_bound: # record GP forces self.update_temperature(new_pos) self.record_state() gp_frcs = copy.deepcopy(self.structure.forces) # run DFT and record forces self.dft_step = True self.run_dft() dft_frcs = copy.deepcopy(self.structure.forces) new_pos = md.update_positions(self.dt, self.noa, self.structure) self.update_temperature(new_pos) self.record_state() # compute mae and write to output mae = np.mean(np.abs(gp_frcs - dft_frcs)) mac = np.mean(np.abs(dft_frcs)) self.output.write_to_log('\nmean absolute error:' ' %.4f eV/A \n' % mae) self.output.write_to_log('mean absolute dft component:' ' %.4f eV/A \n' % mac) # add max uncertainty atoms to training set self.update_gp(target_atoms, dft_frcs) if (self.dft_count - 1) < self.freeze_hyps: self.train_gp() # write gp forces if counter >= self.skip and not self.dft_step: self.update_temperature(new_pos) self.record_state() counter = 0 counter += 1 self.update_positions(new_pos) self.curr_step += 1 self.output.conclude_run()
def md_step(self): """ Take an MD step. This updates the positions of the structure. """ md.update_positions(self.dt, self.noa, self.structure)
def run(self): """ Performs an on-the-fly training run. If OTF has store_dft_output set, then the specified DFT files will be copied with the current date and time prepended in the format 'Year.Month.Day:Hour:Minute:Second:'. """ self.output.write_header(self.gp.cutoffs, self.gp.kernel_name, self.gp.hyps, self.gp.opt_algorithm, self.dt, self.number_of_steps, self.structure, self.std_tolerance) counter = 0 self.start_time = time.time() while self.curr_step < self.number_of_steps: # run DFT and train initial model if first step and DFT is on if self.curr_step == 0 and self.std_tolerance != 0 and len( self.gp.training_data) == 0: # call dft and update positions self.run_dft() dft_frcs = copy.deepcopy(self.structure.forces) new_pos = md.update_positions(self.dt, self.noa, self.structure) self.update_temperature(new_pos) self.record_state() # make initial gp model and predict forces self.update_gp(self.init_atoms, dft_frcs) if (self.dft_count - 1) < self.freeze_hyps: self.train_gp() if self.write_model >= 2: self.gp.write_model(self.output_name + "_model") # after step 1, try predicting with GP model else: self.gp.check_L_alpha() self.pred_func(self.structure, self.gp, self.n_cpus) self.dft_step = False new_pos = md.update_positions(self.dt, self.noa, self.structure) # get max uncertainty atoms std_in_bound, target_atoms = \ is_std_in_bound(self.std_tolerance, self.gp.hyps[-1], self.structure, self.max_atoms_added) if not std_in_bound: # record GP forces self.update_temperature(new_pos) self.record_state() gp_frcs = copy.deepcopy(self.structure.forces) # run DFT and record forces self.dft_step = True self.run_dft() dft_frcs = copy.deepcopy(self.structure.forces) new_pos = md.update_positions(self.dt, self.noa, self.structure) self.update_temperature(new_pos) self.record_state() # compute mae and write to output mae = np.mean(np.abs(gp_frcs - dft_frcs)) mac = np.mean(np.abs(dft_frcs)) self.output.write_to_log('\nmean absolute error:' ' %.4f eV/A \n' % mae) self.output.write_to_log('mean absolute dft component:' ' %.4f eV/A \n' % mac) # add max uncertainty atoms to training set self.update_gp(target_atoms, dft_frcs) if (self.dft_count - 1) < self.freeze_hyps: self.train_gp() if self.write_model == 2: self.gp.write_model(self.output_name + "_model") if self.write_model == 3: self.gp.write_model(self.output_name + '_model') # write gp forces if counter >= self.skip and not self.dft_step: self.update_temperature(new_pos) self.record_state() counter = 0 counter += 1 self.update_positions(new_pos) self.curr_step += 1 self.output.conclude_run() if self.write_model >= 1: self.gp.write_model(self.output_name + "_model")