From 51a45e5bdb0bfff108d4e5d1842721cb8cede8a6 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Wed, 6 Mar 2024 10:02:11 -0800 Subject: [PATCH 1/9] Don't call a subprocess with VASP custodian --- src/quacc/calculators/vasp/vasp.py | 45 +++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/quacc/calculators/vasp/vasp.py b/src/quacc/calculators/vasp/vasp.py index 29eb4bb442..7c8e2cebfd 100644 --- a/src/quacc/calculators/vasp/vasp.py +++ b/src/quacc/calculators/vasp/vasp.py @@ -2,9 +2,8 @@ from __future__ import annotations -import inspect import os -import sys +import subprocess from pathlib import Path from typing import TYPE_CHECKING @@ -13,7 +12,6 @@ from ase.calculators.vasp import setups as ase_setups from ase.constraints import FixAtoms -from quacc.calculators.vasp import vasp_custodian from quacc.calculators.vasp.io import load_vasp_yaml_calc from quacc.calculators.vasp.params import ( get_param_swaps, @@ -23,6 +21,7 @@ set_auto_dipole, set_pmg_kpts, ) +from quacc.calculators.vasp.vasp_custodian import run_custodian from quacc.schemas.prep import set_magmoms from quacc.utils.dicts import sort_dict @@ -181,10 +180,6 @@ def _manage_environment(self) -> str: "VASP_VDW setting was not provided, yet you requested a vdW functional." ) - if self.use_custodian: - run_vasp_custodian_file = Path(inspect.getfile(vasp_custodian)).resolve() - return f"{sys.executable} {run_vasp_custodian_file}" - # Return vanilla ASE command vasp_cmd = ( SETTINGS.VASP_GAMMA_CMD @@ -290,3 +285,39 @@ def _cleanup_params(self) -> None: self.user_calc_params = sort_dict( normalize_params(remove_unused_flags(self.user_calc_params)) ) + + def _run( + self, + command: list[str] | None = None, + out: Path | str | None = None, + directory: Path | str | None = None, + ) -> int: + """ + Override the Vasp calculator's run method to use Custodian if necessary. + + Parameters + ---------- + command + The command to run the VASP calculation. If None, will use the + self.command attribute. + out + The stdout file path. + directory + The directory to run the calculation in. If None, will use the + self.directory attribute. + + Returns + ------- + int + The return code. + """ + if command is None: + command = self.command + if directory is None: + directory = self.directory + + if self.use_custodian: + run_custodian() + return 0 + else: + return subprocess.call(command, shell=True, stdout=out, cwd=directory) From 6799c1314fe1c826f02991a685f1082561ff8e54 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Wed, 6 Mar 2024 12:19:01 -0800 Subject: [PATCH 2/9] Update test_vasp.py --- tests/core/calculators/vasp/test_vasp.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/core/calculators/vasp/test_vasp.py b/tests/core/calculators/vasp/test_vasp.py index 2f63b84a5a..9df8487fa3 100644 --- a/tests/core/calculators/vasp/test_vasp.py +++ b/tests/core/calculators/vasp/test_vasp.py @@ -903,3 +903,8 @@ def test_run(monkeypatch, tmp_path): atoms = bulk("Cu") calc = Vasp(atoms, xc="PBE", use_custodian=False) assert calc._run() > 0 + + atoms = bulk("Cu") + calc = Vasp(atoms, xc="PBE", use_custodian=True) + with pytest.raises(FileNotFoundError): + calc._run() From 8a91d09ee7eedaa6dec6e44f0feace2004e5a75c Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 11 Mar 2024 10:14:02 -0700 Subject: [PATCH 3/9] Update vasp.py --- src/quacc/calculators/vasp/vasp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quacc/calculators/vasp/vasp.py b/src/quacc/calculators/vasp/vasp.py index 7c8e2cebfd..bc8bf8465a 100644 --- a/src/quacc/calculators/vasp/vasp.py +++ b/src/quacc/calculators/vasp/vasp.py @@ -317,7 +317,7 @@ def _run( directory = self.directory if self.use_custodian: - run_custodian() + run_custodian(directory=directory) return 0 else: return subprocess.call(command, shell=True, stdout=out, cwd=directory) From 8f1176bee5390b5e59ba8d5a03c3a089e9ca97af Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 11 Mar 2024 10:15:01 -0700 Subject: [PATCH 4/9] Update vasp_custodian.py --- src/quacc/calculators/vasp/vasp_custodian.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/quacc/calculators/vasp/vasp_custodian.py b/src/quacc/calculators/vasp/vasp_custodian.py index 277ecae034..e891af7ab7 100644 --- a/src/quacc/calculators/vasp/vasp_custodian.py +++ b/src/quacc/calculators/vasp/vasp_custodian.py @@ -68,6 +68,7 @@ def run_custodian( vasp_custodian_handlers: list[str] | None = None, vasp_custodian_validators: list[str] | None = None, scratch_dir: str | None = None, + directory: str | None = "./" vasp_job_kwargs: VaspJobKwargs | None = None, custodian_kwargs: CustodianKwargs | None = None, ) -> list[list[dict]]: @@ -202,6 +203,7 @@ def run_custodian( validators=validators, max_errors=vasp_custodian_max_errors, scratch_dir=scratch_dir, + directory=directory, **custodian_kwargs, ) From ed8ae5c0cad72457f073cac434f152aa185cb718 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 11 Mar 2024 10:16:01 -0700 Subject: [PATCH 5/9] Update requirements.txt --- tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index 54afc90d54..b007bc1747 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,6 +1,6 @@ git+https://gitlab.com/ase/ase.git cclib==1.8 -custodian[qchem,vasp]==2024.2.15 +git+https://github.com/materialsproject/custodian.git emmet-core==0.78.7 maggma==0.63.4 monty==2024.2.26 From dba8d2b967328b98c3d9698f9b601e3382ce04ab Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 11 Mar 2024 10:17:03 -0700 Subject: [PATCH 6/9] Update vasp_custodian.py --- src/quacc/calculators/vasp/vasp_custodian.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/quacc/calculators/vasp/vasp_custodian.py b/src/quacc/calculators/vasp/vasp_custodian.py index e891af7ab7..5697a4d852 100644 --- a/src/quacc/calculators/vasp/vasp_custodian.py +++ b/src/quacc/calculators/vasp/vasp_custodian.py @@ -68,7 +68,7 @@ def run_custodian( vasp_custodian_handlers: list[str] | None = None, vasp_custodian_validators: list[str] | None = None, scratch_dir: str | None = None, - directory: str | None = "./" + directory: str | None = "./", vasp_job_kwargs: VaspJobKwargs | None = None, custodian_kwargs: CustodianKwargs | None = None, ) -> list[list[dict]]: From 5bf2fc2309df759d2b97d1b7e6ba8b0d2bc45e2e Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 11 Mar 2024 14:40:52 -0700 Subject: [PATCH 7/9] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d3ab4f44ad..ad65085424 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ requires-python = ">=3.9, <3.13" dependencies = [ "ase>3.22.1", # for Atoms object and calculators "cclib>=1.8", # for I/O parsing of molecular DFT codes - "custodian[qchem,vasp]>=2024.2.15", # for automated error corrections + "git+https://github.com/materialsproject/custodian.git", # for automated error corrections "emmet-core>=0.78.0", # for pre-made schemas "maggma>=0.57.0", # for database handling "monty>=2024.2.26", # miscellaneous Python utilities From 153a18ce266116ed1b7f9888d965f77a3b587c44 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 11 Mar 2024 14:47:06 -0700 Subject: [PATCH 8/9] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ad65085424..91e3e34698 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ requires-python = ">=3.9, <3.13" dependencies = [ "ase>3.22.1", # for Atoms object and calculators "cclib>=1.8", # for I/O parsing of molecular DFT codes - "git+https://github.com/materialsproject/custodian.git", # for automated error corrections + "custodian @ git+https://github.com/materialsproject/custodian", # for automated error corrections "emmet-core>=0.78.0", # for pre-made schemas "maggma>=0.57.0", # for database handling "monty>=2024.2.26", # miscellaneous Python utilities From 97719d585779ff687572eac8d4a628b7bef0f4e4 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Tue, 12 Mar 2024 12:15:30 -0700 Subject: [PATCH 9/9] Bump custodian --- pyproject.toml | 2 +- tests/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 91e3e34698..546f023628 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ requires-python = ">=3.9, <3.13" dependencies = [ "ase>3.22.1", # for Atoms object and calculators "cclib>=1.8", # for I/O parsing of molecular DFT codes - "custodian @ git+https://github.com/materialsproject/custodian", # for automated error corrections + "custodian>=2024.3.12", # for automated error corrections "emmet-core>=0.78.0", # for pre-made schemas "maggma>=0.57.0", # for database handling "monty>=2024.2.26", # miscellaneous Python utilities diff --git a/tests/requirements.txt b/tests/requirements.txt index b007bc1747..742aa79aaf 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,6 +1,6 @@ git+https://gitlab.com/ase/ase.git cclib==1.8 -git+https://github.com/materialsproject/custodian.git +custodian==2024.3.12 emmet-core==0.78.7 maggma==0.63.4 monty==2024.2.26