forked from PythonFZ/ase_md_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
76 lines (65 loc) · 1.86 KB
/
main.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
from zntrack import Node, zn
import ase
import ase_md.simulator as asemd
import typing
import matplotlib.pyplot as plt
import pandas as pd
class GetAtoms(Node):
"""Generate Atoms for Simulation"""
# Inputs:
size: int = zn.params()
# Outputs:
atoms: ase.Atoms = zn.outs()
# Function:
def run(self):
self.atoms = asemd.generate_atoms(self.size)
class RunMD(Node):
"""runs MD (time expensive)"""
# Inputs:
atoms: GetAtoms = zn.deps()
temperature = zn.params()
timestep = zn.params()
steps = zn.params()
dump_interval = zn.params()
# Outputs:
atoms_list = zn.outs()
# Function
def run(self):
self.atoms_list = asemd.run_simulation(
atoms=self.atoms.atoms,
temperature=self.temperature,
timestep=self.timestep,
steps=self.steps,
dump_interval=self.dump_interval,
)
class ComputeRDF(Node):
"""Calculate RDF whatever that means..."""
# Inputs:
atoms_list: RunMD = zn.deps()
rmax: float = zn.params()
nbins: int = zn.params()
# Outputs:
rdf: dict = zn.outs()
nice_plot = zn.plots(x_label="r", y_label="amp")
# Function:
def run(self):
self.rdf = asemd.compute_rdf(
atoms_list=self.atoms_list.atoms_list,
rmax=self.rmax,
nbins=self.nbins,
elements="Cu",
)
x_data = self.rdf["x"]
y_data = self.rdf["y"]
df = pd.DataFrame({"y": y_data, "x": x_data})
self.nice_plot = df
self.nice_plot.index.name=("x")
if __name__ == "__main__":
atoms = GetAtoms(size=3)
atoms.write_graph()
atoms_list = RunMD(
atoms=atoms, temperature=300, timestep=1.0, steps=20, dump_interval=5
)
atoms_list.write_graph()
rdf = ComputeRDF(atoms_list=atoms_list, rmax=3.6, nbins=50)
rdf.write_graph()