Skip to content

Commit

Permalink
Don't call a subprocess with Q-Chem Custodian (#1851)
Browse files Browse the repository at this point in the history
## Summary of Changes

Call Custodian directly rather than via a subprocess for Q-Chem.

Requires:
- materialsproject/custodian#323
- Custodian > 2024.2.15

### Checklist

- [X] I have read the ["Guidelines"
section](https://quantum-accelerators.github.io/quacc/dev/contributing.html#guidelines)
of the contributing guide. Don't lie! 😉
- [X] My PR is on a custom branch and is _not_ named `main`.
- [X] I have added relevant, comprehensive [unit
tests](https://quantum-accelerators.github.io/quacc/dev/contributing.html#unit-tests).

### Notes

- Your PR will likely not be merged without proper and thorough tests.
- If you are an external contributor, you will see a comment from
[@buildbot-princeton](https://github.com/buildbot-princeton). This is
solely for the maintainers.
- When your code is ready for review, ping one of the [active
maintainers](https://quantum-accelerators.github.io/quacc/about/contributors.html#active-maintainers).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Andrew-S-Rosen and pre-commit-ci[bot] authored Mar 12, 2024
1 parent 0322807 commit ce61d8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
27 changes: 3 additions & 24 deletions src/quacc/calculators/qchem/qchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

from __future__ import annotations

import inspect
import sys
from pathlib import Path
from typing import TYPE_CHECKING

from ase.calculators.calculator import FileIOCalculator

from quacc.calculators.qchem import qchem_custodian
from quacc.calculators.qchem.io import read_qchem, write_qchem
from quacc.calculators.qchem.params import cleanup_attrs, make_qc_input
from quacc.calculators.qchem.qchem_custodian import run_custodian
Expand Down Expand Up @@ -242,14 +238,11 @@ def __init__(
# Set default params
self._set_default_params()

# Get Q-Chem executable command
command = self._manage_environment()

# Instantiate the calculator
super().__init__(
restart=None,
label=None,
command=command,
command="",
atoms=self.atoms,
profile=None,
**self.fileiocalculator_kwargs,
Expand Down Expand Up @@ -287,8 +280,7 @@ def write_input(
prev_orbital_coeffs=self.prev_orbital_coeffs,
)

@staticmethod
def execute() -> int:
def execute(self) -> int:
"""
Execute Q-Chem.

Expand All @@ -298,7 +290,7 @@ def execute() -> int:
The return code.
"""

run_custodian()
run_custodian(directory=self.directory)
return 0

def read_results(self) -> None:
Expand All @@ -314,19 +306,6 @@ def read_results(self) -> None:
self.results = results
self.prev_orbital_coeffs = prev_orbital_coeffs

@staticmethod
def _manage_environment() -> str:
"""
Return the command to run the Q-Chem calculator via Custodian.
Returns
-------
str
The command flag to run Q-Chem with Custodian.
"""

qchem_custodian_script = Path(inspect.getfile(qchem_custodian)).resolve()
return f"{sys.executable} {qchem_custodian_script}"

def _set_default_params(self) -> None:
"""
Store the parameters that have been passed to the Q-Chem calculator in
Expand Down
4 changes: 4 additions & 0 deletions src/quacc/calculators/qchem/qchem_custodian.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def run_custodian(
qchem_use_error_handlers: bool | None = None,
qchem_custodian_max_errors: int | None = None,
qchem_nbo_exe: str | Path | None = None,
directory: str | Path = "./",
) -> Popen:
"""
Function to run QChem Custodian.
Expand All @@ -45,6 +46,8 @@ def run_custodian(
in settings.
qchem_nbo_exe
The full path to the NBO executable.
directory
The runtime directory.

Returns
-------
Expand Down Expand Up @@ -94,6 +97,7 @@ def run_custodian(
jobs,
max_errors=qchem_custodian_max_errors,
terminate_on_nonzero_returncode=False,
directory=directory,
)

return c.run()
Expand Down

0 comments on commit ce61d8a

Please # to comment.