-
Notifications
You must be signed in to change notification settings - Fork 0
/
LennardJones.py
executable file
·72 lines (51 loc) · 1.93 KB
/
LennardJones.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
#!/usr/bin/env python
import sys
from fluid import LJContainer
import util
MEASUREMENT_STEPS = 10000
EQUILIBRIATION_STEPS = 2000
class LennardJones:
t = 0.0
def __init__(self, density):
"""Initialize the simulation."""
#Initialize the container
container = LJContainer(density)
#Equilibriate the system
while self.t < EQUILIBRIATION_STEPS:
sys.stdout.write("\rEquilibriating the container: {0:3.1f}%".format(
self.t*100/EQUILIBRIATION_STEPS))
sys.stdout.flush()
#Do one 'tick' consisting of two integrations and a force update
container.tick(rescale=True)
#Increment time
self.t += 1
print("\n")
self.t = 0.0
#Start measuring
while self.t < MEASUREMENT_STEPS:
sys.stdout.write("\rCalculating averages: {0:3.1f}%".format(
self.t*100/MEASUREMENT_STEPS))
sys.stdout.flush()
#Do one 'tick' consisting of two integrations and a force update
container.tick(rescale=True)
#Sample averages
container.sample(self.t)
#Increment time
self.t += 1
#Store sampling data
util.write_data(container.data, density)
#Generate a plot of the measured properties
util.generate_report(density)
#Print out the average value for the pressure
pressure = util.calculate_average(container.data, "P")
#Write calculated pressure to disk
util.store_pressure(pressure, density)
print("\nAverage pressure for density {0}: {1:6.4}".format(
density, pressure))
if __name__ == "__main__":
lj = None
for i in sys.argv:
if i[:2] == "dn":
lj = LennardJones(density=float(i[2:]))
if not lj:
print("Please specify density!")