forked from stfc/aiida-mlip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_md.py
117 lines (100 loc) · 2.9 KB
/
submit_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""Example code for submitting a molecular dynamics simulation."""
import ast
from aiida.common import NotExistent
from aiida.engine import run_get_node
from aiida.orm import Dict, Str, load_code
from aiida.plugins import CalculationFactory
import click
from aiida_mlip.helpers.help_load import load_model, load_structure
def md(params: dict) -> None:
"""
Prepare inputs and run a molecular dynamics simulation.
Parameters
----------
params : dict
A dictionary containing the input parameters for the calculations
Returns
-------
None
"""
structure = load_structure(params["struct"])
# Select model to use
model = load_model(params["model"], params["arch"])
# Select calculation to use
MDCalc = CalculationFactory("mlip.md")
# Define inputs
inputs = {
"metadata": {"options": {"resources": {"num_machines": 1}}},
"code": params["code"],
"arch": Str(params["arch"]),
"struct": structure,
"model": model,
"precision": Str(params["precision"]),
"device": Str(params["device"]),
"ensemble": Str(params["ensemble"]),
"md_kwargs": Dict(params["md_dict"]),
}
# Run calculation
result, node = run_get_node(MDCalc, **inputs)
print(f"Printing results from calculation: {result}")
print(f"Printing node of calculation: {node}")
# Arguments and options to give to the cli when running the script
@click.command("cli")
@click.argument("codelabel", type=str)
@click.option(
"--struct",
default=None,
type=str,
help="Specify the structure (aiida node or path to a structure file)",
)
@click.option(
"--model",
default=None,
type=str,
help="Specify path or URI of the model to use",
)
@click.option(
"--arch",
default="mace_mp",
type=str,
help="MLIP architecture to use for calculations.",
)
@click.option(
"--device", default="cpu", type=str, help="Device to run calculations on."
)
@click.option(
"--precision", default="float64", type=str, help="Chosen level of precision."
)
@click.option(
"--ensemble", default="nve", type=str, help="Name of thermodynamic ensemble."
)
@click.option(
"--md_dict_str",
default="{}",
type=str,
help="String containing a dictionary with other md parameters",
)
def cli(
codelabel, struct, model, arch, device, precision, ensemble, md_dict_str
) -> None:
"""Click interface."""
md_dict = ast.literal_eval(md_dict_str)
try:
code = load_code(codelabel)
except NotExistent as exc:
print(f"The code '{codelabel}' does not exist.")
raise SystemExit from exc
params = {
"code": code,
"struct": struct,
"model": model,
"arch": arch,
"device": device,
"precision": precision,
"ensemble": ensemble,
"md_dict": md_dict,
}
# Submit MD
md(params)
if __name__ == "__main__":
cli()