I have written a python script to do global optimisation on interatomic potential (IP) using Metropolis Monte Carlo.
I have attached the part of the script which is the Metropolis MC part.
I have plotted the plot: IP energy (no Coulomb interaction in the energy) as a function of step number (from the first accepted order to the last).
I expect the plot shows the negative trend data because I expect it converges as the step increases. However, it is not.
Is the plot represent the Markov chain?
# Initialize variables
energy_previous = 0.0
energy_vec = []
while step_cnt < max_steps:
# Calculate energy of proposed configuration
IP_energy = calculate_energy(proposed_configuration)
if step_cnt == 0:
energy_previous = IP_energy
step_cnt = 1
else:
delta = IP_energy - energy_previous
energy_tol = np.random.uniform()
# Accept or reject the new configuration based on the Metropolis-Hastings criterion
if energy_tol < np.exp(-delta):
energy_vec.append(IP_energy) # store the accepted structure energy
energy_previous = IP_energy
# update the proposed configuration for the next iteration
proposed_configuration = update_configuration(proposed_configuration)
step_cnt += 1
Here is the output of
step_no, IP_energy, previous_energy, delta, energy_tol, np.exp(-delta), energy_tol < np.exp(-delta)
1 -0.00179377 -0.00967768 0.00788391 0.08959475 0.99214709 True
2 17.20824264 -0.00179377 17.21003641 0.47674332 0.00000003 False
2 -0.02482590 -0.00179377 -0.02303213 0.94119261 1.02329942 True
3 -0.02276726 -0.02482590 0.00205864 0.46212012 0.99794348 True
4 -0.00245595 -0.02276726 0.02031131 0.03979358 0.97989358 True
5 -0.01868081 -0.00245595 -0.01622486 0.76820130 1.01635720 True
6 -0.00820708 -0.01868081 0.01047373 0.36041987 0.98958093 True
7 -0.01322191 -0.00820708 -0.00501483 0.95599216 1.00502743 True
8 -0.01875933 -0.01322191 -0.00553742 0.35053292 1.00555278 True
9 3.28646223 -0.01875933 3.30522156 0.57247874 0.03669108 False
9 -0.00338494 -0.01875933 0.01537439 0.44678120 0.98474319 True
10 0.00644749 -0.00338494 0.00983243 0.04497439 0.99021575 True
... so on