def optimize(self, n_steps): # set up initial system current_system = System(self.system.particles, self.parameters) # pass particle positions and neighbourlist to the energy calculator class self.energy_calculator.set_system( current_system.neighbourlist.particle_positions, current_system.neighbourlist.cell_list, current_system.neighbourlist.particle_neighbour_list) # calculate energy of initial system current_system.energy = self._calculate_overall_energy() # append to optimize trajectory self.opt_systems.append(current_system) # crude optimization for i in range(n_steps): # generate trial system trial_system = MetropolisMonteCarlo.generate_trial_configuration( self.opt_systems[-1], self.parameters) # update particle positions and neighbourlist self.energy_calculator.set_system( trial_system.neighbourlist.particle_positions, trial_system.neighbourlist.cell_list, trial_system.neighbourlist.particle_neighbour_list) # calculate energy of trial system trial_system.energy = self._calculate_overall_energy() # evaluate system and trial system and append the accepted system to the trajectory self.opt_systems.append( MetropolisMonteCarlo.evaluate_trial_configuration_greedy( self.opt_systems[-1], trial_system)) # interim update_radius update_radius = self.parameters.update_radius self.parameters.update_radius = update_radius / 10 # fine optimization for i in range(100): # generate trial system trial_system = MetropolisMonteCarlo.generate_trial_configuration( self.opt_systems[-1], self.parameters) # update particle positions and neighbourlist self.energy_calculator.set_system( trial_system.neighbourlist.particle_positions, trial_system.neighbourlist.cell_list, trial_system.neighbourlist.particle_neighbour_list) # calculate energy of trial system trial_system.energy = self._calculate_overall_energy() # evaluate system and trial system and append the accepted system to the trajectory self.opt_systems.append( MetropolisMonteCarlo.evaluate_trial_configuration_greedy( self.opt_systems[-1], trial_system)) # resetting update_radius to desired value self.parameters.update_radius = update_radius
def test_evaluate_trial_configuration_greedy_3(self): # set test parameters charges = np.ones(10).astype(np.float32) lj_sigmas = np.ones(10).astype(np.float32) lj_epsilons = np.ones(10).astype(np.float32) para = Parameters(temperature=1, box=np.array([1, 1, 1]), es_sigma=1, update_radius=1, charges=charges, lj_sigmas=lj_sigmas, lj_epsilons=lj_epsilons, update_probability=0.5, accuracy=1) particle1 = Particle(np.array([0.5, 0.5, 0.5])) particle2 = Particle(np.array([0.5, 0.5, 0.1])) particles = [particle1, particle2] system = System(particles=particles, parameters=para) system.energy.overall_energy = 1.1 trial_system = System(particles=particles, parameters=para) trial_system.energy.overall_energy = 1 actual = MetropolisMonteCarlo.evaluate_trial_configuration_greedy( system, trial_system) npt.assert_equal(actual, trial_system)
def optimize(self, n_steps): raise NotImplementedError() current_system = System(self.system.particles, self.parameters) current_system.energy = calculate_energy() # not implemented yet for i in range(n_steps): trial_system = MetropolisMonteCarlo.generate_trial_configuration( current_system, self.parameters) trial_system.energy = calculate_energy() # not implemented yet current_system = MetropolisMonteCarlo.evaluate_trial_configuration_greedy( current_system, trial_system) self.opt_system = current_system