@@ -49,22 +49,17 @@ Let us add a method named *monte_carlo_move* to the *MonteCarlo* class:
4949 if self .displace_mc is not None : # only trigger if displace_mc was provided by the user
5050 # If needed, recalculate neighbor/coeff lists
5151 self .update_neighbor_lists()
52- self .identify_atom_properties()
5352 self .update_cross_coefficients()
54- try : # try using the last saved Epot, if it exists
55- initial_Epot = self .Epot
56- except : # If self.Epot does not exists yet, calculate it
57- initial_Epot = self .compute_potential()
53+ if hasattr (self , ' Epot' ) is False : # If self.Epot does not exists yet, calculate it
54+ self .Epot = self .compute_potential()
55+ initial_Epot = self .Epot
5856 # Make a copy of the initial atoms positions
5957 initial_positions = copy.deepcopy(self .atoms_positions)
6058 # Pick an atom id randomly
61- atom_id = np.random.randint(self .total_number_atoms )
59+ atom_id = np.random.randint(np.sum( self .number_atoms) )
6260 # Move the chosen atom in a random direction
6361 # The maximum displacement is set by self.displace_mc
64- if self .dimensions == 3 :
65- move = (np.random.random(3 )- 0.5 )* self .displace_mc
66- elif self .dimensions == 2 : # the third value will be 0
67- move = np.append((np.random.random(2 ) - 0.5 ) * self .displace_mc, 0 )
62+ move = (np.random.random(3 )- 0.5 )* self .displace_mc
6863 self .atoms_positions[atom_id] += move
6964 # Measure the optential energy of the new configuration
7065 trial_Epot = self .compute_potential()
@@ -76,7 +71,6 @@ Let us add a method named *monte_carlo_move* to the *MonteCarlo* class:
7671 if random_number <= acceptation_probability: # Accept new position
7772 self .Epot = trial_Epot
7873 else : # Reject new position
79- self .Epot = initial_Epot
8074 self .atoms_positions = initial_positions # Revert to initial positions
8175
8276 .. label :: end_MonteCarlo_class
@@ -98,13 +92,11 @@ and the desired temperature (:math:`T`). Let us add these parameters to the
9892 maximum_steps ,
9993 desired_temperature ,
10094 displace_mc = None ,
101- thermo_outputs = " press" ,
10295 * args ,
10396 ** kwargs ):
10497 self .maximum_steps = maximum_steps
10598 self .displace_mc = displace_mc
10699 self .desired_temperature = desired_temperature
107- self .thermo_outputs = thermo_outputs
108100 super ().__init__ (* args, ** kwargs)
109101 self .nondimensionalize_units([" desired_temperature" , " displace_mc" ])
110102
@@ -193,6 +185,8 @@ One can use a similar test as previously. Let us use a displace distance of
193185 rc = 2.5 * sig_1
194186 # Pick the desired temperature
195187 T = 300 * ureg.kelvin
188+ # choose the displace_mc
189+ displace_mc = sig_1/ 4
196190
197191 # Initialize the prepare object
198192 mc = MonteCarlo(
@@ -208,6 +202,8 @@ One can use a similar test as previously. Let us use a displace distance of
208202 cut_off = rc,
209203 thermo_outputs = " Epot" ,
210204 desired_temperature = T, # K
205+ neighbor = 20 ,
206+ displace_mc = displace_mc,
211207 )
212208 mc.run()
213209
0 commit comments