Skip to content

Commit 26b828b

Browse files
Andrew-S-Rosenjanosh
andauthoredMar 12, 2024
Add missing directory kwarg on QCJob run() method (materialsproject#323)
* Add missing `directory` kwarg on QCJob `run()` method * add doc strings and type annos --------- Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
1 parent 30576c6 commit 26b828b

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed
 

‎.github/workflows/linting.yml ‎.github/workflows/lint.yml

+2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ jobs:
1313
- uses: actions/checkout@v4
1414
with:
1515
fetch-depth: 0
16+
1617
- name: Set up Python
1718
uses: actions/setup-python@v5
1819
with:
1920
python-version: 3.11
2021
cache: pip
22+
2123
- name: Run pre-commit
2224
run: |
2325
pip install pre-commit

‎.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: pytest
5252
env:
5353
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
54-
MPLBACKEND: "Agg"
54+
MPLBACKEND: Agg
5555
run: pytest --cov=custodian --color=yes tests
5656

5757
- name: Upload coverage reports to Codecov

‎custodian/qchem/jobs.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""This module implements basic kinds of jobs for QChem runs."""
22

3+
from __future__ import annotations
4+
35
import copy
46
import os
57
import shutil
@@ -100,8 +102,15 @@ def __init__(
100102
print("SLURM_CPUS_ON_NODE not in environment")
101103

102104
@property
103-
def current_command(self, directory="./"):
104-
"""The command to run QChem."""
105+
def current_command(self, directory: str | Path = "./"):
106+
"""The command to run QChem.
107+
108+
Args:
109+
directory (str): The directory to run in. Defaults to "./".
110+
111+
Returns:
112+
(str) The command to run QChem.
113+
"""
105114
self._input_path = os.path.join(directory, self.input_file)
106115
self._output_path = os.path.join(directory, self.output_file)
107116
multi = {"openmp": "-nt", "mpi": "-np"}
@@ -111,8 +120,12 @@ def current_command(self, directory="./"):
111120
command = self.qchem_command + command
112121
return " ".join(command)
113122

114-
def setup(self, directory="./"):
115-
"""Sets up environment variables necessary to efficiently run QChem."""
123+
def setup(self, directory: str | Path = "./"):
124+
"""Sets up environment variables necessary to efficiently run QChem.
125+
126+
Args:
127+
directory (str): The directory to run in. Defaults to "./".
128+
"""
116129
self._input_path = os.path.join(directory, self.input_file)
117130
if self.backup:
118131
shutil.copy(self._input_path, os.path.join(directory, f"{self.input_file}.orig"))
@@ -132,8 +145,12 @@ def setup(self, directory="./"):
132145
raise RuntimeError("Trying to run NBO7 without providing NBOEXE in fworker! Exiting...")
133146
os.environ["NBOEXE"] = self.nboexe
134147

135-
def postprocess(self, directory="./"):
136-
"""Renames and removes scratch files after running QChem."""
148+
def postprocess(self, directory: str | Path = "./"):
149+
"""Renames and removes scratch files after running QChem.
150+
151+
Args:
152+
directory (str): The directory to run in. Defaults to "./".
153+
"""
137154
self._input_path = os.path.join(directory, self.input_file)
138155
self._output_path = os.path.join(directory, self.output_file)
139156
self._qclog_path = os.path.join(directory, self.qclog_file)
@@ -155,10 +172,13 @@ def postprocess(self, directory="./"):
155172
except FileNotFoundError:
156173
pass
157174

158-
def run(self):
175+
def run(self, directory: str | Path = "./"):
159176
"""
160177
Perform the actual QChem run.
161178
179+
Args:
180+
directory (str): The directory to run in. Defaults to "./".
181+
162182
Returns:
163183
(subprocess.Popen) Used for monitoring.
164184
"""
@@ -172,7 +192,7 @@ def run(self):
172192
os.makedirs(local_scratch, exist_ok=True)
173193
shutil.move(os.path.join(os.environ["QCSCRATCH"], "53.0"), local_scratch)
174194
with open(self.qclog_file, "w") as qclog:
175-
return subprocess.Popen(self.current_command, stdout=qclog, shell=True) # pylint: disable=R1732
195+
return subprocess.Popen(self.current_command, cwd=directory, stdout=qclog, shell=True) # pylint: disable=R1732
176196

177197
@classmethod
178198
def opt_with_frequency_flattener(

0 commit comments

Comments
 (0)
Please sign in to comment.