-
Notifications
You must be signed in to change notification settings - Fork 41
/
_base.py
205 lines (181 loc) · 6.14 KB
/
_base.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"""Base jobs for ORCA."""
from __future__ import annotations
from typing import TYPE_CHECKING
from ase.calculators.orca import ORCA, OrcaProfile, OrcaTemplate
from quacc import SETTINGS
from quacc.runners.ase import run_calc, run_opt
from quacc.schemas.cclib import cclib_summarize_run, summarize_cclib_opt_run
from quacc.utils.dicts import recursive_dict_merge
from quacc.utils.lists import merge_list_params
if TYPE_CHECKING:
from typing import Any
from ase.atoms import Atoms
from quacc.runners.ase import OptParams
from quacc.schemas._aliases.cclib import cclibASEOptSchema, cclibSchema
from quacc.utils.files import Filenames, SourceDirectory
_LABEL = OrcaTemplate()._label # skipcq: PYL-W0212
LOG_FILE = f"{_LABEL}.out"
GEOM_FILE = f"{_LABEL}.xyz"
def run_and_summarize(
atoms: Atoms,
charge: int = 0,
spin_multiplicity: int = 1,
default_inputs: list[str] | None = None,
default_blocks: list[str] | None = None,
input_swaps: list[str] | None = None,
block_swaps: list[str] | None = None,
additional_fields: dict[str, Any] | None = None,
copy_files: SourceDirectory | dict[SourceDirectory, Filenames] | None = None,
**calc_kwargs,
) -> cclibSchema:
"""
Base job function for ORCA recipes.
Parameters
----------
atoms
Atoms object
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
default_inputs
Default input parameters.
default_blocks
Default block input parameters.
input_swaps
List of orcasimpleinput swaps for the calculator. To remove entries
from the defaults, put a `#` in front of the name.
block_swaps
List of orcablock swaps for the calculator. To remove entries
from the defaults, put a `#` in front of the name.
additional_fields
Any additional fields to supply to the summarizer.
copy_files
Files to copy (and decompress) from source to the runtime directory.
**calc_kwargs
Any other keyword arguments to pass to the `ORCA` calculator.
Returns
-------
cclibSchema
Dictionary of results
"""
atoms.calc = prep_calculator(
charge=charge,
spin_multiplicity=spin_multiplicity,
default_inputs=default_inputs,
default_blocks=default_blocks,
input_swaps=input_swaps,
block_swaps=block_swaps,
**calc_kwargs,
)
atoms = run_calc(atoms, geom_file=GEOM_FILE, copy_files=copy_files)
return cclib_summarize_run(atoms, LOG_FILE, additional_fields=additional_fields)
def run_and_summarize_opt(
atoms: Atoms,
charge: int = 0,
spin_multiplicity: int = 1,
default_inputs: list[str] | None = None,
default_blocks: list[str] | None = None,
input_swaps: list[str] | None = None,
block_swaps: list[str] | None = None,
opt_defaults: dict[str, Any] | None = None,
opt_params: OptParams | None = None,
additional_fields: dict[str, Any] | None = None,
copy_files: SourceDirectory | dict[SourceDirectory, Filenames] | None = None,
**calc_kwargs,
) -> cclibASEOptSchema:
"""
Base job function for ORCA recipes with ASE optimizer.
Parameters
----------
atoms
Atoms object
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
default_inputs
Default input parameters.
default_blocks
Default block input parameters.
input_swaps
List of orcasimpleinput swaps for the calculator. To remove entries
from the defaults, put a `#` in front of the name.
block_swaps
List of orcablock swaps for the calculator. To remove entries
from the defaults, put a `#` in front of the name.
opt_defaults
Default arguments for the ASE optimizer.
opt_params
Dictionary of custom kwargs for [quacc.runners.ase.run_opt][]
additional_fields
Any additional fields to supply to the summarizer.
copy_files
Files to copy (and decompress) from source to the runtime directory.
**calc_kwargs
Any other keyword arguments to pass to the `ORCA` calculator.
Returns
-------
cclibASEOptSchema
Dictionary of results
"""
atoms.calc = prep_calculator(
charge=charge,
spin_multiplicity=spin_multiplicity,
default_inputs=default_inputs,
default_blocks=default_blocks,
input_swaps=input_swaps,
block_swaps=block_swaps,
**calc_kwargs,
)
opt_flags = recursive_dict_merge(opt_defaults, opt_params)
dyn = run_opt(atoms, copy_files=copy_files, **opt_flags)
return summarize_cclib_opt_run(dyn, LOG_FILE, additional_fields=additional_fields)
def prep_calculator(
charge: int = 0,
spin_multiplicity: int = 1,
default_inputs: list[str] | None = None,
default_blocks: list[str] | None = None,
input_swaps: list[str] | None = None,
block_swaps: list[str] | None = None,
**calc_kwargs,
) -> ORCA:
"""
Prepare the ORCA calculator.
Parameters
----------
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
default_inputs
Default input parameters.
default_blocks
Default block input parameters.
input_swaps
List of orcasimpleinput swaps for the calculator. To remove entries
from the defaults, put a `#` in front of the name.
block_swaps
List of orcablock swaps for the calculator. To remove entries
from the defaults, put a `#` in front of the name.
**calc_kwargs
Any other keyword arguments to pass to the `ORCA` calculator.
Returns
-------
ORCA
The ORCA calculator
"""
inputs = merge_list_params(default_inputs, input_swaps)
blocks = merge_list_params(default_blocks, block_swaps)
if "xyzfile" not in inputs:
inputs.append("xyzfile")
orcasimpleinput = " ".join(inputs)
orcablocks = "\n".join(blocks)
return ORCA(
profile=OrcaProfile(command=SETTINGS.ORCA_CMD),
charge=charge,
mult=spin_multiplicity,
orcasimpleinput=orcasimpleinput,
orcablocks=orcablocks,
**calc_kwargs,
)