def generate_configuration(self, lmp_, radius_, lower_bound_=float('-inf'), upper_bound_=float('inf'), moves_=1000): """ Generate an initial configuration that lies within an energy range. """ # Function shortcuts for speed. move = self.move_atom pick_atom = self.get_random_atom # Initialise lammps for initial input. lmp_.command("run 0 post no") lmp_.command("variable e equal pe") # Extract the atomic coordinates. # This is an array of pointers. # Note: Changing these values will alter the values in lammps. self.positions = lmp_.extract_atom("x", 3) # Calculate and store the total energy of the initial configuration. lmp_.command("variable elast equal $e") elast = lmp_.extract_variable("elast", None, 0) # Store previous positions. self.positions_store = pos_to_array(lmp_) for i in xrange(1, moves_): # Move all atoms # Gibbs sampler (all atoms are moved) for j in xrange(self.num_atoms): # Move selected atom to generate a new configuration. move(j, radius_) # Run lammps for the new configuration. lmp_.command("run 0 post no") # Refresh positions from lammps. # Required due to book-keeping (neighbour lists etc). self.positions = lmp_.extract_atom("x", 3) # Extract the total energy of the new configuration. lmp_.command("variable enew equal v_e") enew = lmp_.extract_variable("enew", None, 0) # Apply WL criterion to see if the move is accepted. if enew < upper_bound_ and enew > lower_bound_: # print "Found initial configuration." # print "Energy of initial configuration = " + str(enew) return 1. / float(i) else: # If the move is rejected revert to original position of atom. array_to_pos(lmp_, self.positions_store) array_to_pos(lmp_, self.positions_store) lmp_.command("run 0 post no")
def generate_configuration(self, lmp_, radius_,lower_bound_=float('-inf'), upper_bound_=float('inf'), moves_ = 1000): """ Generate an initial configuration that lies within an energy range. """ # Function shortcuts for speed. move = self.move_atom pick_atom = self.get_random_atom # Initialise lammps for initial input. lmp_.command("run 0 post no") lmp_.command("variable e equal pe") # Extract the atomic coordinates. # This is an array of pointers. # Note: Changing these values will alter the values in lammps. self.positions = lmp_.extract_atom("x", 3) # Calculate and store the total energy of the initial configuration. lmp_.command("variable elast equal $e") elast = lmp_.extract_variable("elast", None, 0) # Store previous positions. self.positions_store = pos_to_array(lmp_) for i in xrange(1, moves_): # Move all atoms # Gibbs sampler (all atoms are moved) for j in xrange(self.num_atoms): # Move selected atom to generate a new configuration. move(j, radius_) # Run lammps for the new configuration. lmp_.command("run 0 post no") # Refresh positions from lammps. # Required due to book-keeping (neighbour lists etc). self.positions = lmp_.extract_atom("x", 3) # Extract the total energy of the new configuration. lmp_.command("variable enew equal v_e") enew = lmp_.extract_variable("enew", None, 0) # Apply WL criterion to see if the move is accepted. if enew < upper_bound_ and enew > lower_bound_: # print "Found initial configuration." # print "Energy of initial configuration = " + str(enew) return 1./float(i) else: # If the move is rejected revert to original position of atom. array_to_pos(lmp_,self.positions_store) array_to_pos(lmp_,self.positions_store) lmp_.command("run 0 post no")
def copy_config(self, config): array_to_pos(self.lmp, config)