-
Notifications
You must be signed in to change notification settings - Fork 41
/
_base.py
125 lines (108 loc) · 3.93 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
"""Base jobs for Q-Chem."""
from __future__ import annotations
from typing import TYPE_CHECKING
from quacc.calculators.qchem import QChem
from quacc.runners.ase import Runner
from quacc.schemas.ase import summarize_opt_run, summarize_run
from quacc.utils.dicts import recursive_dict_merge
if TYPE_CHECKING:
from typing import Any
from ase.atoms import Atoms
from quacc.runners.ase import OptParams
from quacc.schemas._aliases.ase import OptSchema, RunSchema
from quacc.utils.files import Filenames, SourceDirectory
def run_and_summarize(
atoms: Atoms,
charge: int = 0,
spin_multiplicity: int = 1,
calc_defaults: dict[str, Any] | None = None,
calc_swaps: dict[str, Any] | None = None,
additional_fields: dict[str, Any] | None = None,
copy_files: SourceDirectory | dict[SourceDirectory, Filenames] | None = None,
) -> RunSchema:
"""
Base job function used for Q-Chem recipes that don't rely on ASE optimizers or other
ASE dynamics classes.
Parameters
----------
atoms
Atoms object
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
calc_defaults
The default parameters for the recipe.
calc_swaps
Dictionary of custom kwargs for the Q-Chem calculator. Set a value to `quacc.Remove` to
remove a pre-existing key entirely. For a list of available keys, refer to the
`quacc.calculators.qchem.qchem.QChem` calculator.
additional_fields
Any additional fields to set in the summary.
copy_files
Files to copy (and decompress) from source to the runtime directory.
Returns
-------
RunSchema
Dictionary of results from [quacc.schemas.ase.summarize_run][]
"""
calc_flags = recursive_dict_merge(calc_defaults, calc_swaps)
calc = QChem(
atoms, charge=charge, spin_multiplicity=spin_multiplicity, **calc_flags
)
final_atoms = Runner(atoms, calc, copy_files=copy_files).run_calc()
return summarize_run(
final_atoms,
atoms,
charge_and_multiplicity=(charge, spin_multiplicity),
additional_fields=additional_fields,
)
def run_and_summarize_opt(
atoms: Atoms,
charge: int = 0,
spin_multiplicity: int = 1,
calc_defaults: dict[str, Any] | None = None,
calc_swaps: dict[str, Any] | 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,
) -> OptSchema:
"""
Base function for Q-Chem recipes that involve ASE optimizers.
Parameters
----------
atoms
Atoms object
charge
Charge of the system.
spin_multiplicity
Multiplicity of the system.
calc_defaults
Default arguments for the Q-Chem calculator.
calc_swaps
Dictionary of custom kwargs for the Q-Chem calculator. Set a value to `quacc.Remove` to
remove a pre-existing key entirely. For a list of available keys, refer to the
`quacc.calculators.qchem.qchem.QChem` calculator.
opt_defaults
Default arguments for the ASE optimizer.
opt_params
Dictionary of custom kwargs for [quacc.runners.ase.Runner.run_opt][]
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][]
"""
calc_flags = recursive_dict_merge(calc_defaults, calc_swaps)
opt_flags = recursive_dict_merge(opt_defaults, opt_params)
calc = QChem(
atoms, charge=charge, spin_multiplicity=spin_multiplicity, **calc_flags
)
dyn = Runner(atoms, calc, copy_files=copy_files).run_opt(**opt_flags)
return summarize_opt_run(
dyn,
charge_and_multiplicity=(charge, spin_multiplicity),
additional_fields=additional_fields,
)