forked from stfc/aiida-mlip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_geomopt.py
138 lines (120 loc) · 3.47 KB
/
submit_geomopt.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Example code for submitting geometry optimisation calculation"""
import click
from aiida.common import NotExistent
from aiida.engine import run_get_node
from aiida.orm import Bool, Float, Int, Str, load_code
from aiida.plugins import CalculationFactory
from aiida_mlip.helpers.help_load import load_model, load_structure
def geomopt(params: dict) -> None:
"""
Prepare inputs and run a geometry optimisation calculation.
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
geomoptCalculation = CalculationFactory("mlip.opt")
# 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"]),
"fmax": Float(params["fmax"]),
"vectors_only": Bool(params["vectors_only"]),
"fully_opt": Bool(params["fully_opt"]),
# "opt_kwargs": Dict({"restart": "rest.pkl"}),
"steps": Int(params["steps"]),
}
# Run calculation
result, node = run_get_node(geomoptCalculation, **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("--fmax", default=0.1, type=float, help="Maximum force for convergence.")
@click.option(
"--vectors_only",
default=False,
type=bool,
help="Optimise cell vectors, as well as atomic positions.",
)
@click.option(
"--fully_opt",
default=False,
type=bool,
help="Fully optimise the cell vectors, angles, and atomic positions.",
)
@click.option(
"--steps", default=1000, type=int, help="Maximum number of optimisation steps."
)
def cli(
codelabel,
struct,
model,
arch,
device,
precision,
fmax,
vectors_only,
fully_opt,
steps,
) -> None:
# pylint: disable=too-many-arguments
"""Click interface."""
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,
"fmax": fmax,
"vectors_only": vectors_only,
"fully_opt": fully_opt,
"steps": steps,
}
# Submit single point
geomopt(params)
if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter