Skip to content

Commit

Permalink
Merge branch 'Quantum-Accelerators:main' into skzcam
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-S-Rosen authored Jul 1, 2024
2 parents bd1395a + 7d4de2b commit 25de1f2
Show file tree
Hide file tree
Showing 71 changed files with 1,059 additions and 1,093 deletions.
2 changes: 1 addition & 1 deletion docs/dev/recipes/jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ The following are typical guidelines for jobs:

A schema is a dictionary containing tabulated input and output properties from a calculation.

All available schemas are stored in `quacc.schemas`, and type-hints associated with the outputs are stored in `quacc.schemas._aliases`.
All available schemas are stored in `quacc.schemas`, and type-hints associated with the outputs are stored in `quacc.types`.

All schemas create quacc-compatible dictionaries from a given calculation and also will automatically store results in the user's database, if one is specified in the global settings.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ skip_gitignore = true

[tool.coverage.run]
source = ["src"]
omit = [
"*/_aliases/*"
]

[tool.coverage.report]
exclude_also = [
Expand Down
6 changes: 6 additions & 0 deletions src/quacc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from pymatgen.io.ase import MSONAtoms

from quacc.settings import QuaccSettings, change_settings
from quacc.types import DefaultSetting
from quacc.utils.dicts import Remove
from quacc.wflow_tools.customizers import redecorate, strip_decorator
from quacc.wflow_tools.decorators import Flow, Job, Subflow, flow, job, subflow

if TYPE_CHECKING:
from typing import Any


__all__ = [
"flow",
"job",
Expand All @@ -30,6 +32,7 @@
"strip_decorator",
"Remove",
"get_settings",
"QuaccDefault",
]


Expand Down Expand Up @@ -85,6 +88,9 @@ def get_settings() -> QuaccSettings:

_settings = get_settings()

# Dummy value for when a default setting will be applied
QuaccDefault = DefaultSetting()

# Set logging info
logging.basicConfig(level=logging.DEBUG if _settings.DEBUG else logging.INFO)

Expand Down
32 changes: 5 additions & 27 deletions src/quacc/atoms/slabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,11 @@
from quacc.atoms.core import copy_atoms

if TYPE_CHECKING:
from typing import Literal, TypedDict
from typing import Literal

from ase.atoms import Atoms
from numpy.typing import ArrayLike

class AdsSiteFinderKwargs(TypedDict, total=False):
"""
Type hint for `ads_site_finder_kwargs` in [quacc.atoms.slabs.make_adsorbate_structures][].
"""

selective_dynamics: bool # default = False
height: float # default = 0.9
mi_vec: ArrayLike | None # default = None

class FindAdsSitesKwargs(TypedDict, total=False):
"""
Type hint for `find_ads_sites_kwargs` in [quacc.atoms.slabs.make_adsorbate_structures][].
"""

distance: float # default = 2.0
put_inside: bool # default = True
symm_reduce: float # default = 1e-2
near_reduce: float # default = 1e-2
positions: list[
Literal["ontop", "bridge", "hollow", "subsurface"]
] # default: ["ontop", "bridge", "hollow"]
no_obtuse_hollow: bool # default = True
from quacc.types import AdsSiteFinderKwargs, FindAdsSitesKwargs


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -201,7 +179,7 @@ def make_slabs_from_bulk(
# Add slab to list
slabs_with_props.append(slab)

final_slabs = []
final_slabs: list[Atoms] = []
if not slabs_with_props:
return final_slabs

Expand All @@ -224,7 +202,7 @@ def make_adsorbate_structures(
atoms: Atoms,
adsorbate: Atoms,
min_distance: float = 2.0,
modes: list[str] | None = None,
modes: list[Literal["ontop", "bridge", "hollow", "subsurface"]] | None = None,
allowed_surface_symbols: list[str] | None = None,
allowed_surface_indices: list[int] | None = None,
ads_site_finder_kwargs: AdsSiteFinderKwargs | None = None,
Expand Down Expand Up @@ -282,7 +260,7 @@ def make_adsorbate_structures(
msg = "Cannot specify both modes and find_ads_sites_kwargs['positions']"
raise ValueError(msg)
find_ads_sites_kwargs["distance"] = min_distance
find_ads_sites_kwargs["positions"] = [mode.lower() for mode in modes]
find_ads_sites_kwargs["positions"] = modes

# Check the provided surface indices are reasonable
atom_indices = [atom.index for atom in atoms]
Expand Down
2 changes: 1 addition & 1 deletion src/quacc/calculators/espresso/espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def read_results(self, directory: Path | str) -> dict[str, Any]:
"""
results = {}
if self.binary == "pw":
atoms = read(directory / self.outputname, format="espresso-out")
atoms = read(Path(directory) / self.outputname, format="espresso-out")
results = dict(atoms.calc.properties())
elif self.binary in ["ph", "phcg"]:
with Path(directory, self.outputname).open() as fd:
Expand Down
2 changes: 1 addition & 1 deletion src/quacc/calculators/espresso/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from ase.atoms import Atoms

from quacc.utils.files import Filenames, SourceDirectory
from quacc.types import Filenames, SourceDirectory

LOGGER = logging.getLogger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions src/quacc/calculators/qchem/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
if TYPE_CHECKING:
from pymatgen.io.qchem.inputs import QCInput

from quacc.calculators.qchem.qchem import Results
from quacc.types import QchemResults


def write_qchem(
Expand Down Expand Up @@ -53,7 +53,7 @@ def write_qchem(
qc_input.write_file(directory / "mol.qin")


def read_qchem(directory: Path | str) -> tuple[Results, list[float]]:
def read_qchem(directory: Path | str) -> tuple[QchemResults, list[float]]:
"""
Read Q-Chem log files.
Expand All @@ -74,7 +74,7 @@ def read_qchem(directory: Path | str) -> tuple[Results, list[float]]:
warnings.simplefilter("ignore", category=UserWarning)
task_doc = TaskDoc.from_directory(directory, validate_lot=False).model_dump()

results: Results = {
results: QchemResults = {
"energy": task_doc["output"]["final_energy"] * units.Hartree,
"taskdoc": task_doc,
}
Expand Down
15 changes: 3 additions & 12 deletions src/quacc/calculators/qchem/qchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@
from quacc.calculators.qchem.qchem_custodian import run_custodian

if TYPE_CHECKING:
from typing import Any, ClassVar, Literal, TypedDict
from typing import Any, ClassVar, Literal

from ase.atoms import Atoms
from numpy.typing import NDArray

class Results(TypedDict, total=False):
"""
Type hint for the `results` attribute in [quacc.calculators.qchem.qchem.QChem][].
"""

energy: float # electronic energy in eV
forces: NDArray # forces in eV/A
hessian: NDArray # Hessian in eV/A^2/amu
taskdoc: dict[str, Any] # Output from `emmet.core.qc_tasks.TaskDoc`
from quacc.types import QchemResults


class QChem(FileIOCalculator):
Expand All @@ -36,7 +27,7 @@ class QChem(FileIOCalculator):
"hessian",
"taskdoc",
]
results: ClassVar[Results] = {}
results: ClassVar[QchemResults] = {}

def __init__(
self,
Expand Down
31 changes: 16 additions & 15 deletions src/quacc/calculators/qchem/qchem_custodian.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@

from monty.dev import requires

from quacc import get_settings
from quacc import QuaccDefault, get_settings

if TYPE_CHECKING:
from pathlib import Path

has_ob = bool(find_spec("openbabel"))
from quacc.types import DefaultSetting


_DEFAULT_SETTING = ()
has_ob = bool(find_spec("openbabel"))


@requires(
has_ob, "Openbabel must be installed. Try conda install -c conda-forge openbabel"
)
def run_custodian(
qchem_cmd: str = _DEFAULT_SETTING,
qchem_cores: int = _DEFAULT_SETTING,
qchem_local_scratch: str | Path = _DEFAULT_SETTING,
qchem_use_error_handlers: bool = _DEFAULT_SETTING,
qchem_custodian_max_errors: int = _DEFAULT_SETTING,
qchem_nbo_exe: str | Path = _DEFAULT_SETTING,
qchem_cmd: str | DefaultSetting = QuaccDefault,
qchem_cores: int | DefaultSetting = QuaccDefault,
qchem_local_scratch: str | Path | DefaultSetting = QuaccDefault,
qchem_use_error_handlers: bool | DefaultSetting = QuaccDefault,
qchem_custodian_max_errors: int | DefaultSetting = QuaccDefault,
qchem_nbo_exe: str | Path | DefaultSetting = QuaccDefault,
directory: str | Path | None = None,
) -> list[list[dict]]:
"""
Expand Down Expand Up @@ -65,26 +66,26 @@ def run_custodian(

# Set defaults
qchem_cores = (
settings.QCHEM_NUM_CORES if qchem_cores == _DEFAULT_SETTING else qchem_cores
settings.QCHEM_NUM_CORES if qchem_cores == QuaccDefault else qchem_cores
)
qchem_cmd = settings.QCHEM_CMD if qchem_cmd == _DEFAULT_SETTING else qchem_cmd
qchem_cmd = settings.QCHEM_CMD if qchem_cmd == QuaccDefault else qchem_cmd
qchem_local_scratch = (
settings.QCHEM_LOCAL_SCRATCH
if qchem_local_scratch == _DEFAULT_SETTING
if qchem_local_scratch == QuaccDefault
else qchem_local_scratch
)
qchem_use_error_handlers = (
settings.QCHEM_USE_ERROR_HANDLERS
if qchem_use_error_handlers == _DEFAULT_SETTING
if qchem_use_error_handlers == QuaccDefault
else qchem_use_error_handlers
)
qchem_custodian_max_errors = (
settings.QCHEM_CUSTODIAN_MAX_ERRORS
if qchem_custodian_max_errors == _DEFAULT_SETTING
if qchem_custodian_max_errors == QuaccDefault
else qchem_custodian_max_errors
)
qchem_nbo_exe = (
settings.QCHEM_NBO_EXE if qchem_nbo_exe == _DEFAULT_SETTING else qchem_nbo_exe
settings.QCHEM_NBO_EXE if qchem_nbo_exe == QuaccDefault else qchem_nbo_exe
)

# Error handlers for Q-Chem
Expand Down
3 changes: 1 addition & 2 deletions src/quacc/calculators/vasp/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from ase.atoms import Atoms
from pymatgen.io.vasp.sets import DictSet

from quacc.utils.files import SourceDirectory
from quacc.utils.kpts import PmgKpts
from quacc.types import PmgKpts, SourceDirectory

if has_atomate2:
from atomate2.vasp.jobs.base import BaseVaspMaker
Expand Down
29 changes: 14 additions & 15 deletions src/quacc/calculators/vasp/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ase.calculators.vasp import setups as ase_setups
from ase.constraints import FixAtoms

from quacc import get_settings
from quacc import QuaccDefault, get_settings
from quacc.calculators.vasp.io import load_vasp_yaml_calc
from quacc.calculators.vasp.params import (
get_param_swaps,
Expand All @@ -30,7 +30,7 @@

from ase.atoms import Atoms

_DEFAULT_SETTING = ()
from quacc.types import DefaultSetting


class Vasp(Vasp_):
Expand All @@ -43,11 +43,12 @@ def __init__(
self,
input_atoms: Atoms,
preset: None | str = None,
use_custodian: bool = _DEFAULT_SETTING,
incar_copilot: Literal["off", "on", "aggressive"] = _DEFAULT_SETTING,
copy_magmoms: bool = _DEFAULT_SETTING,
preset_mag_default: float = _DEFAULT_SETTING,
mag_cutoff: float = _DEFAULT_SETTING,
use_custodian: bool | DefaultSetting = QuaccDefault,
incar_copilot: Literal["off", "on", "aggressive"]
| DefaultSetting = QuaccDefault,
copy_magmoms: bool | DefaultSetting = QuaccDefault,
preset_mag_default: float | DefaultSetting = QuaccDefault,
mag_cutoff: float | DefaultSetting = QuaccDefault,
elemental_magmoms: dict[str, float] | None = None,
pmg_kpts: (
dict[Literal["line_density", "kppvol", "kppa"], float]
Expand Down Expand Up @@ -112,28 +113,26 @@ def __init__(
# Set defaults
use_custodian = (
self._settings.VASP_USE_CUSTODIAN
if use_custodian == _DEFAULT_SETTING
if use_custodian == QuaccDefault
else use_custodian
)
incar_copilot = (
self._settings.VASP_INCAR_COPILOT
if incar_copilot == _DEFAULT_SETTING
if incar_copilot == QuaccDefault
else incar_copilot
)
copy_magmoms = (
self._settings.VASP_COPY_MAGMOMS
if copy_magmoms == _DEFAULT_SETTING
if copy_magmoms == QuaccDefault
else copy_magmoms
)
preset_mag_default = (
self._settings.VASP_PRESET_MAG_DEFAULT
if preset_mag_default == _DEFAULT_SETTING
if preset_mag_default == QuaccDefault
else preset_mag_default
)
mag_cutoff = (
self._settings.VASP_MAG_CUTOFF
if mag_cutoff == _DEFAULT_SETTING
else mag_cutoff
self._settings.VASP_MAG_CUTOFF if mag_cutoff == QuaccDefault else mag_cutoff
)

# Assign variables to self
Expand Down Expand Up @@ -281,7 +280,7 @@ def _cleanup_params(self) -> None:

def _run(
self,
command: list[str] | None = None,
command: str | None = None,
out: Path | str | None = None,
directory: Path | str | None = None,
) -> int:
Expand Down
Loading

0 comments on commit 25de1f2

Please sign in to comment.