1
1
"""This module implements basic kinds of jobs for QChem runs."""
2
2
3
+ from __future__ import annotations
4
+
3
5
import copy
4
6
import os
5
7
import shutil
@@ -100,8 +102,15 @@ def __init__(
100
102
print ("SLURM_CPUS_ON_NODE not in environment" )
101
103
102
104
@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
+ """
105
114
self ._input_path = os .path .join (directory , self .input_file )
106
115
self ._output_path = os .path .join (directory , self .output_file )
107
116
multi = {"openmp" : "-nt" , "mpi" : "-np" }
@@ -111,8 +120,12 @@ def current_command(self, directory="./"):
111
120
command = self .qchem_command + command
112
121
return " " .join (command )
113
122
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
+ """
116
129
self ._input_path = os .path .join (directory , self .input_file )
117
130
if self .backup :
118
131
shutil .copy (self ._input_path , os .path .join (directory , f"{ self .input_file } .orig" ))
@@ -132,8 +145,12 @@ def setup(self, directory="./"):
132
145
raise RuntimeError ("Trying to run NBO7 without providing NBOEXE in fworker! Exiting..." )
133
146
os .environ ["NBOEXE" ] = self .nboexe
134
147
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
+ """
137
154
self ._input_path = os .path .join (directory , self .input_file )
138
155
self ._output_path = os .path .join (directory , self .output_file )
139
156
self ._qclog_path = os .path .join (directory , self .qclog_file )
@@ -155,10 +172,13 @@ def postprocess(self, directory="./"):
155
172
except FileNotFoundError :
156
173
pass
157
174
158
- def run (self ):
175
+ def run (self , directory : str | Path = "./" ):
159
176
"""
160
177
Perform the actual QChem run.
161
178
179
+ Args:
180
+ directory (str): The directory to run in. Defaults to "./".
181
+
162
182
Returns:
163
183
(subprocess.Popen) Used for monitoring.
164
184
"""
@@ -172,7 +192,7 @@ def run(self):
172
192
os .makedirs (local_scratch , exist_ok = True )
173
193
shutil .move (os .path .join (os .environ ["QCSCRATCH" ], "53.0" ), local_scratch )
174
194
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
176
196
177
197
@classmethod
178
198
def opt_with_frequency_flattener (
0 commit comments