Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pydantic types in config file #994

Merged
merged 11 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/quacc/calculators/custodian/qchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def run_custodian(
qchem_cores: int = 1,
qchem_cmd: str | None = None,
qchem_local_scratch: str | None = None,
qchem_local_scratch: str | Path | None = None,
qchem_use_error_handlers: bool | None = None,
qchem_custodian_max_errors: int | None = None,
qchem_nbo_exe: str | Path | None = None,
Expand Down
46 changes: 24 additions & 22 deletions src/quacc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class QuaccSettings(BaseSettings):
by using the "QUACC" prefix. e.g. QUACC_SCRATCH_DIR=/path/to/scratch.
"""

CONFIG_FILE: Path = Field(
_DEFAULT_CONFIG_FILE_PATH,
description=(
"Path to the YAML file to load alternative quacc configuration "
"defaults from."
),
)

# --8<-- [start:settings]

# ---------------------------
Expand All @@ -54,14 +62,7 @@ class QuaccSettings(BaseSettings):
# General Settings
# ---------------------------

CONFIG_FILE: Union[str, Path] = Field(
_DEFAULT_CONFIG_FILE_PATH,
description=(
"Path to the YAML file to load alternative quacc configuration "
"defaults from."
),
)
RESULTS_DIR: Union[str, Path] = Field(
RESULTS_DIR: Path = Field(
Path.cwd(),
description=(
"Directory to store I/O-based calculation results in."
Expand All @@ -71,7 +72,7 @@ class QuaccSettings(BaseSettings):
"In this case, the `RESULTS_DIR` will be a subdirectory of that directory."
),
)
SCRATCH_DIR: Union[str, Path] = Field(
SCRATCH_DIR: Path = Field(
Path.cwd() / ".scratch",
description="Scratch directory for calculations.",
)
Expand Down Expand Up @@ -105,8 +106,8 @@ class QuaccSettings(BaseSettings):
# ---------------------------
# ORCA Settings
# ---------------------------
ORCA_CMD: Union[str, Path] = Field(
"orca",
ORCA_CMD: Path = Field(
Path("orca"),
description=(
"Path to the ORCA executable. This must be the full, absolute path "
"for parallel calculations to work."
Expand Down Expand Up @@ -170,7 +171,7 @@ class QuaccSettings(BaseSettings):
"in atoms.set_initial_magnetic_moments()."
),
)
VASP_PRESET_DIR: Union[str, Path] = Field(
VASP_PRESET_DIR: Path = Field(
resources.files(vasp_defaults),
description="Path to the VASP preset directory",
)
Expand Down Expand Up @@ -225,8 +226,8 @@ class QuaccSettings(BaseSettings):
"qchem", description="Command to run the standard version of Q-Chem."
)

QCHEM_LOCAL_SCRATCH: Union[str, Path] = Field(
Path("/tmp") if Path("/tmp").exists() else Path.cwd(),
QCHEM_LOCAL_SCRATCH: Path = Field(
Path("/tmp") if Path("/tmp").exists() else Path.cwd() / ".qchem_scratch",
description="Compute-node local scratch directory in which Q-Chem should perform IO.",
)

Expand All @@ -241,31 +242,32 @@ class QuaccSettings(BaseSettings):
)

# NBO Settings
QCHEM_NBO_EXE: Union[str, Path] = Field(
QCHEM_NBO_EXE: Optional[Path] = Field(
None, description="Full path to the NBO executable."
)

# ---------------------------
# NewtonNet Settings
# ---------------------------
NEWTONNET_MODEL_PATH: Union[Union[str, Path], List[Union[str, Path]]] = Field(
NEWTONNET_MODEL_PATH: Union[Path, List[Path]] = Field(
"best_model_state.tar", description="Path to NewtonNet .tar model"
)
NEWTONNET_CONFIG_PATH: Union[Union[str, Path], List[Union[str, Path]]] = Field(
NEWTONNET_CONFIG_PATH: Union[Path, List[Path]] = Field(
"config.yml", description="Path to NewtonNet YAML settings file"
)

# --8<-- [end:settings]

@validator("CONFIG_FILE", "RESULTS_DIR", "SCRATCH_DIR")
def resolve_paths(cls, v):
return Path(v).expanduser().resolve()

@validator("RESULTS_DIR", "SCRATCH_DIR")
def make_paths(cls, v):
def resolve_and_make_paths(cls, v):
v = v.expanduser().resolve()
os.makedirs(v, exist_ok=True)
return v

@validator("ORCA_CMD")
def expand_paths(cls, v):
return v.expanduser()

class Config:
"""Pydantic config settings."""

Expand Down
2 changes: 1 addition & 1 deletion tests/recipes/compiled_recipes/test_real_orca_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from quacc import SETTINGS

has_orca = bool(which(SETTINGS.ORCA_CMD))
has_orca = bool(which("orca"))

pytestmark = pytest.mark.skipif(
not has_orca or SETTINGS.WORKFLOW_ENGINE != "local",
Expand Down