/
simulate.py
44 lines (36 loc) · 1.29 KB
/
simulate.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
"""simulate.py: The main driver for the simulation."""
from classes.simulation import Simulation
from classes.analysis import Analysis
from classes.filewriter import fileWriter
import sys
# Number of time steps to run
if len(sys.argv) != 2:
print("Usage: python simulate.py nSteps")
exit(0)
else:
nSteps = int(sys.argv[1])
### INITIALIZATION ###
# Instantiate a new simulation object.
sim = Simulation()
# Instantiate an analysis object to analyze the current simulation.
analysis = Analysis(sim.getAtoms())
# Instatiate an object that writes output to the disk.
fw = fileWriter()
### MAIN LOOP ###
# Run the simulation for n steps
for step in range(0, nSteps):
# Run the simulation for a single step
sim.runSimulation(step, nSteps)
# Add the current state to the analysis object
analysis.updateAtoms(sim.getAtoms())
# Calculate the velocity autocorrelation function for this step.
analysis.velocityAutocorrelation(step)
# Write the positional data to a file
fw.writeXYZ(sim.getAtoms())
### DATA OUTPUT ###
fw.writeData("temp.csv", sim.temperatures)
fw.writeData("rdf.csv", analysis.pairDistributionFunction())
fw.writeData("vac.csv", analysis.getVAC())
analysis.plotRDF()
analysis.plotVAC(nSteps)
analysis.plotEnergy(sim.temperatures, sim.potentials, nSteps)