-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdemo.py
45 lines (34 loc) · 1.02 KB
/
demo.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
import os
import time
import numpy as np
import matplotlib.pyplot as plt
from ionmd import Simulation, Status
sim = Simulation()
params = sim.params
params.filename = "trajectories.bin"
sim.params = params
print(sim.params)
print("Adding ions...")
n_ions = 2
z = np.linspace(-5, 5, n_ions)
for n in range(n_ions):
sim.add_ion(40, 1, [0, 0, z[n]])
print("Running simulation...")
t_start = time.time()
sim.start()
time.sleep(0.2)
while sim.status != Status.FINISHED:
print("Still running... Elapsed time: {:.3f} s".format(time.time() - t_start))
time.sleep(0.5)
print("Done in {:.3f} s".format(time.time() - t_start))
shape = (n_ions*3, params.num_steps)
# shape = (params.num_steps, n_ions*3)
data = np.fromfile(params.filename, dtype=np.double).reshape(shape).T
if n_ions <= 10:
fig, ax = plt.subplots(3, n_ions)
t = np.linspace(0, params.num_steps * params.dt, params.num_steps)
lim = -1
for n in range(n_ions):
for k in range(3):
ax[k, n].plot(t[:lim], data[:lim, k])
plt.show()