-
Notifications
You must be signed in to change notification settings - Fork 41
/
ts.py
307 lines (273 loc) · 9.74 KB
/
ts.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
"""Transition state recipes for Q-Chem."""
from __future__ import annotations
from importlib.util import find_spec
from typing import TYPE_CHECKING
from monty.dev import requires
from quacc import change_settings, job, strip_decorator
from quacc.atoms.core import perturb
from quacc.recipes.qchem._base import run_and_summarize_opt
from quacc.recipes.qchem.core import _BASE_SET, relax_job
from quacc.utils.dicts import recursive_dict_merge
has_sella = bool(find_spec("sella"))
if has_sella:
from sella import IRC, Sella
if TYPE_CHECKING:
from typing import Any, Literal
from ase.atoms import Atoms
from numpy.typing import NDArray
from quacc.runners.ase import OptParams
from quacc.schemas._aliases.ase import OptSchema
from quacc.utils.files import Filenames, SourceDirectory
@job
@requires(has_sella, "Sella must be installed. Refer to the quacc documentation.")
def ts_job(
atoms: Atoms,
charge: int = 0,
spin_multiplicity: int = 1,
method: str = "wb97mv",
basis: str = "def2-svpd",
opt_params: OptParams | None = None,
copy_files: SourceDirectory | dict[SourceDirectory, Filenames] | None = None,
**calc_kwargs,
) -> OptSchema:
"""
TS optimize a molecular structure.
Parameters
----------
atoms
Atoms object
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
method
DFT exchange-correlation functional or other electronic structure
method.
basis
Basis set.
opt_params
Dictionary of custom kwargs for the optimization process. For a list
of available keys, refer to [quacc.runners.ase.run_opt][].
copy_files
Files to copy (and decompress) from source to the runtime directory.
**calc_kwargs
Custom kwargs for the calculator. Set a value to `quacc.Remove` to remove
a pre-existing key entirely. See [quacc.calculators.qchem.qchem.QChem][] for more
details.
Returns
-------
OptSchema
Dictionary of results from [quacc.schemas.ase.summarize_opt_run][].
See the type-hint for the data structure.
"""
calc_defaults = recursive_dict_merge(
_BASE_SET, {"rem": {"job_type": "force", "method": method, "basis": basis}}
)
opt_defaults = {"optimizer": Sella, "optimizer_kwargs": {"order": 1}}
if opt_params and opt_params.get("optimizer", Sella) is not Sella:
raise ValueError("Only Sella should be used for TS optimization.")
return run_and_summarize_opt(
atoms,
charge,
spin_multiplicity,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
opt_defaults=opt_defaults,
opt_params=opt_params,
additional_fields={"name": "Q-Chem TS"},
copy_files=copy_files,
)
@job
@requires(has_sella, "Sella must be installed. Refer to the quacc documentation.")
def irc_job(
atoms: Atoms,
charge: int = 0,
spin_multiplicity: int = 1,
direction: Literal["forward", "reverse"] = "forward",
method: str = "wb97mv",
basis: str = "def2-svpd",
opt_params: OptParams | None = None,
copy_files: SourceDirectory | dict[SourceDirectory, Filenames] | None = None,
**calc_kwargs,
) -> OptSchema:
"""
IRC optimize a molecular structure.
Parameters
----------
atoms
Atoms object
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
direction
Direction of the IRC. Should be "forward" or "reverse".
method
DFT exchange-correlation functional or other electronic structure
method.
basis
Basis set.
opt_params
Dictionary of custom kwargs for the optimization process. For a list
of available keys, refer to [quacc.runners.ase.run_opt][].
copy_files
Files to copy (and decompress) from source to the runtime directory.
**calc_kwargs
Custom kwargs for the calculator. Set a value to `quacc.Remove` to remove
a pre-existing key entirely. See [quacc.calculators.qchem.qchem.QChem][] for more
details.
Returns
-------
OptSchema
Dictionary of results from [quacc.schemas.ase.summarize_opt_run][]
"""
calc_defaults = recursive_dict_merge(
_BASE_SET, {"rem": {"job_type": "force", "method": method, "basis": basis}}
)
opt_defaults = {
"optimizer": IRC,
"optimizer_kwargs": {"keep_going": True},
"run_kwargs": {"direction": direction},
}
if opt_params and opt_params.get("optimizer", IRC) is not IRC:
raise ValueError("Only Sella's IRC should be used for IRC optimization.")
return run_and_summarize_opt(
atoms,
charge,
spin_multiplicity,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
opt_defaults=opt_defaults,
opt_params=opt_params,
additional_fields={"name": "Q-Chem IRC"},
copy_files=copy_files,
)
@job
@requires(has_sella, "Sella must be installed. Refer to the quacc documentation.")
def quasi_irc_job(
atoms: Atoms,
charge: int = 0,
spin_multiplicity: int = 1,
direction: Literal["forward", "reverse"] = "forward",
method: str = "wb97mv",
basis: str = "def2-svpd",
irc_job_kwargs: dict[str, Any] | None = None,
relax_job_kwargs: dict[str, Any] | None = None,
copy_files: SourceDirectory | dict[SourceDirectory, Filenames] | None = None,
) -> OptSchema:
"""
Quasi-IRC optimize a molecular structure. Runs `irc_job` for 10 steps (default)
followed by `relax_job`.
Parameters
----------
atoms
Atoms object.
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
direction
Direction of the IRC. Should be "forward" or "reverse".
irc_job_kwargs
Dictionary of kwargs for the `irc_job`.
relax_job_kwargs
Dictionary of kwargs for the `relax_job`.
copy_files
Files to copy (and decompress) from source to the runtime directory.
Returns
-------
OptSchema
Dictionary of results from [quacc.schemas.ase.summarize_opt_run][]
"""
irc_job_defaults = {
"charge": charge,
"spin_multiplicity": spin_multiplicity,
"direction": direction,
"method": method,
"basis": basis,
"opt_params": {"max_steps": 10},
"copy_files": copy_files,
}
relax_job_defaults = {
"charge": charge,
"spin_multiplicity": spin_multiplicity,
"method": method,
"basis": basis,
}
irc_job_kwargs = recursive_dict_merge(irc_job_defaults, irc_job_kwargs)
relax_job_kwargs = recursive_dict_merge(relax_job_defaults, relax_job_kwargs)
with change_settings({"CHECK_CONVERGENCE": False}):
irc_summary = strip_decorator(irc_job)(atoms, **irc_job_kwargs)
relax_summary = strip_decorator(relax_job)(irc_summary["atoms"], **relax_job_kwargs)
relax_summary["initial_irc"] = irc_summary
return relax_summary
@job
@requires(has_sella, "Sella must be installed. Refer to the quacc documentation.")
def quasi_irc_perturb_job(
atoms: Atoms,
mode: list[list[float]] | NDArray,
perturb_magnitude: float = 0.6,
direction: Literal["forward", "reverse"] = "forward",
charge: int = 0,
spin_multiplicity: int = 1,
method: str = "wb97mv",
basis: str = "def2-svpd",
opt_params: OptParams | None = None,
copy_files: SourceDirectory | dict[SourceDirectory, Filenames] | None = None,
**calc_kwargs,
) -> OptSchema:
"""
Quasi-IRC to optimize a reaction endpoint from a transition-state with known vibrational frequency modes.
Perturbs the structure of `atoms` by a finite amount (0.6 * the normalized mode magnitude) along the specified
vibrational frequency mode (assumed to be the transition mode), and then performs a `relax_job` on the perturbed
structure.
Parameters
----------
atoms
Atoms object.
mode
Transition mode. This should be an Nx3 matrix, where N is the number of atoms in `atoms`.
perturb_magnitude
Factor to multiply the transition mode. Default is 0.6. In some cases, it may be advisable to increase this
factor, perhaps to 1.0 or 1.1. Lowering it is not generally found to be helpful.
direction
Direction of the (Quasi)IRC. Should be "forward" or "reverse".
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
method
DFT exchange-correlation functional or other electronic structure
method.
basis
Basis set.
opt_params
Dictionary of custom kwargs for the optimization process. For a list
of available keys, refer to [quacc.runners.ase.run_opt][].
copy_files
Files to copy (and decompress) from source to the runtime directory.
**calc_kwargs
Custom kwargs for the calculator. Set a value to `quacc.Remove` to remove
a pre-existing key entirely. See [quacc.calculators.qchem.qchem.QChem][] for more
details.
Returns
-------
OptSchema
Dictionary of results from [quacc.schemas.ase.summarize_opt_run][]
"""
calc_defaults = recursive_dict_merge(
_BASE_SET, {"rem": {"job_type": "force", "method": method, "basis": basis}}
)
opt_defaults = {"optimizer": Sella} if has_sella else {}
scale = perturb_magnitude if direction == "forward" else perturb_magnitude * -1
return run_and_summarize_opt(
perturb(atoms, mode, scale),
charge=charge,
spin_multiplicity=spin_multiplicity,
calc_defaults=calc_defaults,
calc_swaps=calc_kwargs,
opt_defaults=opt_defaults,
opt_params=opt_params,
additional_fields={"name": "Q-Chem Quasi-IRC perturbed optimization"},
copy_files=copy_files,
)