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

Add missing directory kwarg on QCJob run() method #323

Merged
merged 2 commits into from
Mar 12, 2024
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: 2 additions & 0 deletions .github/workflows/linting.yml → .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip

- name: Run pre-commit
run: |
pip install pre-commit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: pytest
env:
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
MPLBACKEND: "Agg"
MPLBACKEND: Agg
run: pytest --cov=custodian --color=yes tests

- name: Upload coverage reports to Codecov
Expand Down
36 changes: 28 additions & 8 deletions custodian/qchem/jobs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""This module implements basic kinds of jobs for QChem runs."""

from __future__ import annotations

import copy
import os
import shutil
Expand Down Expand Up @@ -100,8 +102,15 @@ def __init__(
print("SLURM_CPUS_ON_NODE not in environment")

@property
def current_command(self, directory="./"):
"""The command to run QChem."""
def current_command(self, directory: str | Path = "./"):
"""The command to run QChem.

Args:
directory (str): The directory to run in. Defaults to "./".

Returns:
(str) The command to run QChem.
"""
self._input_path = os.path.join(directory, self.input_file)
self._output_path = os.path.join(directory, self.output_file)
multi = {"openmp": "-nt", "mpi": "-np"}
Expand All @@ -111,8 +120,12 @@ def current_command(self, directory="./"):
command = self.qchem_command + command
return " ".join(command)

def setup(self, directory="./"):
"""Sets up environment variables necessary to efficiently run QChem."""
def setup(self, directory: str | Path = "./"):
"""Sets up environment variables necessary to efficiently run QChem.

Args:
directory (str): The directory to run in. Defaults to "./".
"""
self._input_path = os.path.join(directory, self.input_file)
if self.backup:
shutil.copy(self._input_path, os.path.join(directory, f"{self.input_file}.orig"))
Expand All @@ -132,8 +145,12 @@ def setup(self, directory="./"):
raise RuntimeError("Trying to run NBO7 without providing NBOEXE in fworker! Exiting...")
os.environ["NBOEXE"] = self.nboexe

def postprocess(self, directory="./"):
"""Renames and removes scratch files after running QChem."""
def postprocess(self, directory: str | Path = "./"):
"""Renames and removes scratch files after running QChem.

Args:
directory (str): The directory to run in. Defaults to "./".
"""
self._input_path = os.path.join(directory, self.input_file)
self._output_path = os.path.join(directory, self.output_file)
self._qclog_path = os.path.join(directory, self.qclog_file)
Expand All @@ -155,10 +172,13 @@ def postprocess(self, directory="./"):
except FileNotFoundError:
pass

def run(self):
def run(self, directory: str | Path = "./"):
"""
Perform the actual QChem run.

Args:
directory (str): The directory to run in. Defaults to "./".

Returns:
(subprocess.Popen) Used for monitoring.
"""
Expand All @@ -172,7 +192,7 @@ def run(self):
os.makedirs(local_scratch, exist_ok=True)
shutil.move(os.path.join(os.environ["QCSCRATCH"], "53.0"), local_scratch)
with open(self.qclog_file, "w") as qclog:
return subprocess.Popen(self.current_command, stdout=qclog, shell=True) # pylint: disable=R1732
return subprocess.Popen(self.current_command, cwd=directory, stdout=qclog, shell=True) # pylint: disable=R1732

@classmethod
def opt_with_frequency_flattener(
Expand Down
Loading