def test_fig2a_txt(qcprog): """ Execution (a; txt) cp infile . && xcfour > outfile rungms infile > outfile nwchem infile > outfile psi4 infile outfile """ sin = _fig2_ins[qcprog]["a"] from qcelemental.util import which from qcengine.util import execute if qcprog == "cfour": success, dexe = execute([which("xcfour")], {"ZMAT": sin}) if qcprog == "gamess": success, dexe = execute([which("rungms"), "input"], {"input.inp": sin}) if qcprog == "nwchem": success, dexe = execute([which("nwchem"), "input"], {"input": sin}) if qcprog == "psi4": success, dexe = execute([which("psi4"), "input", "-o", "stdout"], {"input": sin}) pprint.pprint(dexe, width=180) assert success assert _the_short_fig2_energy in dexe["stdout"]
def execute( self, inputs: Dict[str, Any], extra_outfiles: Optional[List[str]] = None, extra_commands: Optional[List[str]] = None, scratch_name: Optional[str] = None, timeout: Optional[int] = None, ) -> Tuple[bool, Dict[str, Any]]: """ Run the gaussian single point job and fchk conversion """ # collect together inputs infiles = inputs["infiles"] outfiles = ["gaussian.log", "lig.chk"] if extra_outfiles is not None: outfiles.extend(extra_outfiles) gaussian_version = self.get_version() commands = [gaussian_version, "gaussian.com"] scratch_directory = inputs["scratch_directory"] # remember before formatting lig.chk is binary, run calculation exe_success, proc = execute( command=commands, infiles=infiles, outfiles=outfiles, scratch_directory=scratch_directory, as_binary=["lig.chk"], ) if exe_success: # now we need to run the conversion of the chk file commands = ["formchk", "lig.chk", "lig.fchk"] infiles = {"lig.chk": proc["outfiles"]["lig.chk"]} chk_success, proc_chk = execute( command=commands, infiles=infiles, outfiles=["lig.fchk"], scratch_directory=scratch_directory, as_binary=["lig.chk"], ) # now we want to put this out file into the main proc proc["outfiles"]["lig.fchk"] = proc_chk["outfiles"]["lig.fchk"] # we can dump the chk file del proc["outfiles"]["lig.chk"] return exe_success, proc
def execute(self, inputs, extra_outfiles=None, extra_commands=None, scratch_name=None, timeout=None): exe_success, proc = uti.execute(inputs["commands"], infiles = inputs["infiles"], outfiles = ["tc.out"], scratch_location = inputs["scratch_location"], timeout = timeout ) proc["outfiles"]["tc.out"] = proc["stdout"] return exe_success, proc
def ctest_runner(inputdatloc, extra_infiles: List = None, outfiles: List = None): """Called from a mock PyTest function, this takes a full path ``inputdatloc`` to an ``"input.dat"`` file set up for CTest and submits it to the ``psi4`` executable. Any auxiliary files with names listed in ``extra_infiles`` that reside alongside ``inputdatloc`` are placed in the Psi4 execution directory. """ from qcengine.util import execute import psi4 # Pass runtime env through to `execute` # * appending Psi4 import path (after all, it worked previous line) since partial/relative paths not robust psiimport = Path(psi4.__file__).parent.parent env = os.environ.copy() if "PYTHONPATH" in env: env["PYTHONPATH"] += os.pathsep + str(psiimport) else: env["PYTHONPATH"] = str(psiimport) ctestdir = Path(inputdatloc).resolve().parent if (ctestdir / "input.dat").exists(): inputdat = "input.dat" elif (ctestdir / "input.py").exists(): inputdat = "input.py" infiles = [inputdat] if extra_infiles: infiles.extend(extra_infiles) infiles_with_contents = {(Path(fl).name if Path(fl).is_absolute() else fl): (ctestdir / fl).read_text() for fl in infiles} # Note: The simple `command = ["psi4", "input.dat"]` works fine for Linux and Mac but not for Windows. # L/M/W ok with `command = [which("psi4"), "input.dat"]` where `which` on Windows finds the psi4.bat file that points to the psi4 python script. -or- # L/M/W ok with `command = [sys.executable, psi4.executable, "input.dat"]` aka `python /full/path/bin/psi4 input.dat`. # Latter chosen as `psi4.executable` is path computed by `import psi4`, so assured correspondence. # Note: The input.py in json/, python/, and psi4numpy/ are not being treated best. # Properly, as in CTest, it's `command = [sys.executable, "input.py"]`. # Have to either have 3-item `command` or pass PYTHONPATH through env. Since some tests (fsapt) "import psi4" internally, doing both. # The "exe" rerouting is for Windows conda package Scripts/psi4.exe file. It gives an encoding error if Python in command. # * Toggle `scratch_messy` to examine scratch contents. if Path(psi4.executable).suffix == ".exe": command = [psi4.executable, inputdat] else: command = [sys.executable, psi4.executable, inputdat] _, output = execute(command, infiles_with_contents, outfiles, environment=env, scratch_messy=False) success = output["proc"].poll() == 0 assert success, output["stdout"] + output["stderr"]
def execute(self, inputs, extra_outfiles=None, extra_commands=None, scratch_name=None, timeout=None): binaries = [] for filename in extra_outfiles: if filename in ['scr/ca0', 'scr/cb0','scr/c0']: binaries.append(filename) exe_success, proc = uti.execute(inputs["commands"], infiles = inputs["infiles"], outfiles = extra_outfiles, as_binary = binaries, scratch_directory=inputs["scratch_directory"], timeout = timeout ) proc["outfiles"]["tc.out"] = proc["stdout"] return exe_success, proc