Example #1
0
 def __init__(self, lmp_, input_file_=None):
     self.num_atoms = lmp_.extract_global("natoms", 0)
     self.num_atom_types = []
     self.atom_types = []
     self.initial_positions = pos_to_array(lmp_)
     self.positions_store = pos_to_array(lmp_)
     self.positions = pos_to_array(lmp_)
     if input_file_ == None:
         print "No input file defined in atoms system"
         exit()
     else:
         """
         Assign atom types.
         """
         data_file = get_data_file(input_file_)
         print "Obtaining atom types from " + data_file
         with open(data_file) as f:
             content = f.readlines()
         types_array = get_atom_types(input_file_)
         self.num_atom_types = int(str.split(content[3])[0])
         print str(self.num_atom_types) + " found of type:"
         print types_array
         for i in range(self.num_atoms):
             atom_type = int(
                 str.split(content[14 + (self.num_atom_types) + i])[1])
             self.atom_types.append(types_array[atom_type - 1])
         print "Atom types are as follows:"
         print self.atom_types
         print "\n"
Example #2
0
 def __init__(self, lmp_, input_file_ = None):
     self.num_atoms = lmp_.extract_global("natoms", 0)
     self.num_atom_types = []
     self.atom_types = []
     self.initial_positions = pos_to_array(lmp_)
     self.positions_store = pos_to_array(lmp_)
     self.positions = pos_to_array(lmp_)
     if input_file_ == None:
         print "No input file defined in atoms system"
         exit()
     else:    
         """
         Assign atom types.
         """
         data_file = get_data_file(input_file_)
         print "Obtaining atom types from " + data_file
         with open(data_file) as f:
             content = f.readlines()
         types_array=get_atom_types(input_file_)
         self.num_atom_types = int(str.split(content[3])[0])
         print str(self.num_atom_types) + " found of type:"
         print types_array
         for i in range(self.num_atoms):
             atom_type = int(str.split(content[14+(self.num_atom_types)+i])[1])
             self.atom_types.append(types_array[atom_type-1])
         print "Atom types are as follows:"
         print self.atom_types
         print "\n"
Example #3
0
    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")
Example #4
0
 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")
Example #5
0
 def get_config(self):
     return pos_to_array(self.lmp)