forked from navining/metadynamics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd.py
91 lines (67 loc) · 2.5 KB
/
md.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import matplotlib.pyplot as plt
import random as rd
import initial as init, verlet as verl
from properties import *
from input import *
from metadynamics import *
from processing import *
# Main Loop.
# ------------------------------------------------------------------------
def simulate():
# -----------------------Initialize--------------------------------
## system
N = Ncube ** 3
R = init.InitPositionCubic(Ncube, L)
V = init.InitVelocity(N, T0, M)
E = np.zeros(steps)
## metadynamics
n_gauss = 0
S = [] # position of the center of the Gaussian
print("steps\ttemperature\tpressure\tkinetic\tpotential\tenergy\t")
for t in range(0, steps):
# -----------------------Measuring Physical Properties----------------------------
## calculate kinetic energy contribution
k = my_kinetic_energy(V, M)
## calculate temperature
T = my_temperature(k, N)
## calculate distance table
drij = get_distance_table(N, R, L)
## calculate potential energy contribution
p = my_potential_energy(drij, rc)
## calculate total energy
E[t] = k + p
## calculate forces
F = np.array([my_force_on(i, R, L, rc) for i in range(N)])
A = F / M
## calculate pressure
P = my_pressure(N**3,N,T,R,F)
# -----------------------Anderson Thermostat----------------------
if anderson == True:
sigma = (Ta / M) ** 0.5
mean = 0
for i in V:
if np.random.random() < eta * h:
i[0] = rd.gauss(mean, sigma)
i[1] = rd.gauss(mean, sigma)
i[2] = rd.gauss(mean, sigma)
# -----------------------Propagation----------------------------
## calculate new positions
nR = verl.VerletNextR(R, V, A, h)
nR = my_pos_in_box(nR, L)
## calculate forces with new positions nR
nF = np.array([my_force_on(i, nR, L, rc) for i in range(N)])
## bias forces with metadynamics
metaF = meta(t, n_gauss, S, nF, nR)
## calculate new velocities
nA = nF / M
nV = verl.VerletNextV(V, A, nA, h)
# update positions:
R, V = nR, nV
# ------------------------Output-------------------------------------
print('%d\t%.3f\t%.2e\t%.5f\t%.5f\t%.5f\t' % (t, T, P, k, p, E[t]))
return S
if __name__ == '__main__':
# Run the simulation
S = simulate()
# Post processing
postprocessing(S)