@@ -29,39 +29,40 @@ Let us add the following method called *monte_carlo_exchange* to the *MonteCarlo
29
29
.. code-block :: python
30
30
31
31
def monte_carlo_exchange (self ):
32
- # The first step is to make a copy of the previous state
33
- # Since atoms numbers are evolving, its also important to store the
34
- # neighbor, sigma, and epsilon lists
35
- self .Epot = self .compute_potential() # TOFIX: not necessary every time
36
- initial_positions = copy.deepcopy(self .atoms_positions)
37
- initial_number_atoms = copy.deepcopy(self .number_atoms)
38
- initial_neighbor_lists = copy.deepcopy(self .neighbor_lists)
39
- initial_sigma_lists = copy.deepcopy(self .sigma_ij_list)
40
- initial_epsilon_lists = copy.deepcopy(self .epsilon_ij_list)
41
- # Apply a 50-50 probability to insert or delete
42
- insert_or_delete = np.random.random()
43
- if np.random.random() < insert_or_delete:
44
- self .monte_carlo_insert()
45
- else :
46
- self .monte_carlo_delete()
47
- if np.random.random() < self .acceptation_probability: # accepted move
48
- # Update the success counters
32
+ if self .desired_mu is not None :
33
+ # The first step is to make a copy of the previous state
34
+ # Since atoms numbers are evolving, its also important to store the
35
+ # neighbor, sigma, and epsilon lists
36
+ self .Epot = self .compute_potential() # TOFIX: not necessary every time
37
+ initial_positions = copy.deepcopy(self .atoms_positions)
38
+ initial_number_atoms = copy.deepcopy(self .number_atoms)
39
+ initial_neighbor_lists = copy.deepcopy(self .neighbor_lists)
40
+ initial_sigma_lists = copy.deepcopy(self .sigma_ij_list)
41
+ initial_epsilon_lists = copy.deepcopy(self .epsilon_ij_list)
42
+ # Apply a 50-50 probability to insert or delete
43
+ insert_or_delete = np.random.random()
49
44
if np.random.random() < insert_or_delete:
50
- self .successful_insert += 1
45
+ self .monte_carlo_insert()
51
46
else :
52
- self .successful_delete += 1
53
- else :
54
- # Reject the new position, revert to inital position
55
- self .neighbor_lists = initial_neighbor_lists
56
- self .sigma_ij_list = initial_sigma_lists
57
- self .epsilon_ij_list = initial_epsilon_lists
58
- self .atoms_positions = initial_positions
59
- self .number_atoms = initial_number_atoms
60
- # Update the failed counters
61
- if np.random.random() < insert_or_delete:
62
- self .failed_insert += 1
47
+ self .monte_carlo_delete()
48
+ if np.random.random() < self .acceptation_probability: # accepted move
49
+ # Update the success counters
50
+ if np.random.random() < insert_or_delete:
51
+ self .successful_insert += 1
52
+ else :
53
+ self .successful_delete += 1
63
54
else :
64
- self .failed_delete += 1
55
+ # Reject the new position, revert to inital position
56
+ self .neighbor_lists = initial_neighbor_lists
57
+ self .sigma_ij_list = initial_sigma_lists
58
+ self .epsilon_ij_list = initial_epsilon_lists
59
+ self .atoms_positions = initial_positions
60
+ self .number_atoms = initial_number_atoms
61
+ # Update the failed counters
62
+ if np.random.random() < insert_or_delete:
63
+ self .failed_insert += 1
64
+ else :
65
+ self .failed_delete += 1
65
66
66
67
.. label :: end_MonteCarlo_class
67
68
0 commit comments