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 found(raise_error: bool = False) -> bool: """Whether MRChem harness is ready for operation. Parameters ---------- raise_error: bool Passed on to control negative return between False and ModuleNotFoundError raised. Returns ------- bool If mrchem and mrchem.x are found, returns True. If raise_error is False and MRChem is missing, returns False. If raise_error is True and MRChem is missing, the error message is raised. """ mrchem_x = which( "mrchem.x", return_bool=True, raise_error=raise_error, raise_msg="Please install via https://mrchem.readthedocs.io", ) mrchem = which( "mrchem", return_bool=True, raise_error=raise_error, raise_msg="Please install via https://mrchem.readthedocs.io", ) return mrchem and mrchem_x
def found(raise_error: bool = False) -> bool: psithon = which("psi4", return_bool=True) psiapi = which_import("psi4", return_bool=True) if psithon and not psiapi: with popen([which("psi4"), "--module"]) as exc: exc["proc"].wait(timeout=30) if "module does not exist" in exc["stderr"]: pass else: sys.path.append(exc["stdout"].split()[-1]) if psiapi and not psithon: psiimport = str(Path(which_import("psi4")).parent.parent) env = os.environ.copy() env["PYTHONPATH"] = psiimport with popen( ["python", "-c", "import psi4; print(psi4.executable[:-5])"], popen_kwargs={"env": env}) as exc: exc["proc"].wait(timeout=30) os.environ["PATH"] += os.pathsep + exc["stdout"].split()[-1] if psithon or psiapi: return True return which( "psi4", return_bool=True, raise_error=raise_error, raise_msg="Please install via `conda install psi4 -c psi4`.", )
def found(raise_error: bool = False) -> bool: """ Check if gaussian can be found via the command line, check for g09 and g16. """ gaussian09 = which("g09", return_bool=True) gaussian16 = which("g16", return_bool=True) return gaussian09 or gaussian16
def is_dftd3_new_enough(version_feature_introduced): if not which('dftd3', return_bool=True): return False # Note: anything below v3.2.1 will return the help menu here. but that's fine as version compare evals to False. command = [which('dftd3'), '-version'] proc = subprocess.run(command, stdout=subprocess.PIPE) candidate_version = proc.stdout.decode('utf-8').strip() return parse_version(candidate_version) >= parse_version(version_feature_introduced)
def is_dftd3_new_enough(version_feature_introduced): if not which('dftd3', return_bool=True): return False # Note: anything below v3.2.1 will return the help menu here. but that's fine as version compare evals to False. command = [which('dftd3'), '-version'] proc = subprocess.run(command, stdout=subprocess.PIPE) candidate_version = proc.stdout.decode('utf-8').strip() return parse_version(candidate_version) >= parse_version( version_feature_introduced)
def get_version(self) -> str: self.found(raise_error=True) which_terachem = which('terachem') if which_terachem not in self.version_cache: with popen([which('terachem'), '--version']) as exc: exc["proc"].wait(timeout=5) self.version_cache[which_terachem] = exc["stdout"].split()[2].strip('K') candidate_version = self.version_cache[which_terachem] return safe_version(candidate_version)
def load_options(options): """Initialize program options defaults onto `options`.""" load_qcdb_defaults(options) if which('xcfour') and which_import('psi4'): load_cfour_defaults_from_psi4(options) if which('nwchem'): load_nwchem_defaults(options) if which('rungms'): load_gamess_defaults(options) if which('psi4') and which_import('psi4'): load_psi4_defaults(options) if which_import('resp'): resp.load_defaults(nu_options)
def get_version(self) -> str: """ Work out which version of gaussian we should be running. """ if which("g09", return_bool=True, raise_error=False): return "g09" else: which( "g16", return_bool=True, raise_error=True, raise_msg= "Gaussian 09/16 can not be found make sure they are available.", ) return "g16"
def get_version(self) -> str: self.found(raise_error=True) version = None which_prog = which("gcp") if which_prog not in self.version_cache: # option not (yet) available, instead find in help output command = [which_prog, "-version"] import subprocess proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) for ln in proc.stdout.decode("utf-8").splitlines(): if re.match(".*Version", ln): version = ln.split()[2] if version is None: raise UnknownError(f"Could not identify GCP version") # pending upcoming gcp update # self.version_cache[which_prog] = safe_version( # proc.stdout.decode("utf-8").strip()) self.version_cache[which_prog] = safe_version(version) return self.version_cache[which_prog]
def found(raise_error: bool = False) -> bool: return which( "mctc-gcp", return_bool=True, raise_error=raise_error, raise_msg="Please install via `conda install gcp-correction -c conda-forge`.", )
def found(raise_error: bool = False) -> bool: return which( "terachem", return_bool=True, raise_error=raise_error, raise_msg="Please install via http://www.petachem.com/index.html", )
def get_version(self) -> str: # excuse missing Q-Chem for QCEngineRecords tests found = self.found() if not found: return safe_version("0.0.0") self.found(raise_error=True) # Get the node configuration config = get_config() which_prog = which("qchem") if which_prog not in self.version_cache: success, exc = execute( [which_prog, "v.in"], {"v.in": "$rem\n"}, scratch_directory=config.scratch_directory, environment=self._get_qc_path(), timeout=15, ) mobj = re.search(r"Q-Chem\s+([\d.]+)\s+for", exc["stdout"]) if not mobj: mobj = re.search(r"Q-Chem version:\s+([\d.]+)\s+", exc["stdout"]) if mobj: self.version_cache[which_prog] = safe_version(mobj.group(1)) # if "QC not defined" in exc["stdout"]: else: return safe_version("0.0.0") return self.version_cache[which_prog]
def load_program_options(options: Keywords) -> None: """Initialize program keywords with defaults onto `options`.""" load_qcdb_keywords(options) if which("xcfour"): load_cfour_keywords(options) if which("nwchem"): load_nwchem_keywords(options) if which("rungms"): load_gamess_keywords(options) if which("psi4") and which_import("psi4"): load_psi4_keywords(options) if which_import("resp_qcdb"): pass resp.load_keywords(nu_options)
def found(raise_error: bool = False) -> bool: """Whether NWChem harness is ready for operation, with both the QC program and any particular dependencies found. Parameters ---------- raise_error: bool Passed on to control negative return between False and ModuleNotFoundError raised. Returns ------- bool If both nwchem and its harness dependency networkx are found, returns True. If raise_error is False and nwchem or networkx are missing, returns False. If raise_error is True and nwchem or networkx are missing, the error message for the first missing one is raised. """ qc = which( "nwchem", return_bool=True, raise_error=raise_error, raise_msg= "Please install via http://www.nwchem-sw.org/index.php/Download", ) dep = which_import( "networkx", return_bool=True, raise_error=raise_error, raise_msg= "For NWChem harness, please install via `conda install networkx -c conda-forge`.", ) return qc and dep
def found(raise_error=False) -> bool: is_found = which("terachem", return_bool=True) if not is_found and raise_error: raise ModuleNotFoundError("Could not find TeraChem in the Python path.") else: return is_found
def found(raise_error=False) -> bool: is_found = which('dftd3', return_bool=True) if not is_found and raise_error: raise ImportError("Could not find DFTD3 in the shell path.") else: return is_found
def build_input(self, input_model: 'ResultInput', config: 'JobConfig', template: Optional[str] = None) -> Dict[str, Any]: gamessrec = { 'infiles': {}, 'scratch_directory': config.scratch_directory, } opts = copy.deepcopy(input_model.keywords) # Handle memory # for gamess, [GiB] --> [MW] opts['system__mwords'] = int(config.memory * (1024**3) / 8e6) # Handle molecule molcmd, moldata = input_model.molecule.to_string(dtype='gamess', units='Bohr', return_data=True) opts.update(moldata['keywords']) # Handle calc type and quantum chemical method opts.update(muster_modelchem(input_model.model.method, input_model.driver.derivative_int())) # Handle basis set # * for gamess, usually insufficient b/c either ngauss or ispher needed opts['basis__gbasis'] = input_model.model.basis # Handle conversion from schema (flat key/value) keywords into local format optcmd = format_keywords(opts) gamessrec['infiles']['gamess.inp'] = optcmd + molcmd gamessrec['command'] = [which("rungms"), "gamess"] # rungms JOB VERNO NCPUS >& JOB.log & return gamessrec
def psi4_which(command, *, return_bool: bool = False, raise_error: bool = False, raise_msg: str = None) -> Union[bool, None, str]: """Test to see if a command is available in Psi4 search path. Returns ------- str or None By default, returns command path if command found or `None` if not. Environment is $PSIPATH:$PATH, less any None values. bool When `return_bool=True`, returns whether or not found. Raises ------ ModuleNotFoundError When `raises_error=True` and command not found. """ lenv = (os.pathsep.join([ os.path.abspath(x) for x in os.environ.get('PSIPATH', '').split(os.pathsep) if x != '' ]) + os.pathsep + os.environ.get('PATH', '')) return which(command=command, return_bool=return_bool, raise_error=raise_error, raise_msg=raise_msg, env=lenv)
def build_input( self, input_model: AtomicInput, config: "TaskConfig", template: Optional[str] = None ) -> Dict[str, Any]: gamessrec = {"infiles": {}, "scratch_directory": config.scratch_directory} opts = copy.deepcopy(input_model.keywords) # Handle memory # for gamess, [GiB] --> [MW] opts["system__mwords"] = int(config.memory * (1024 ** 3) / 8e6) # Handle molecule molcmd, moldata = input_model.molecule.to_string(dtype="gamess", units="Bohr", return_data=True) opts.update(moldata["keywords"]) # Handle calc type and quantum chemical method opts.update(muster_modelchem(input_model.model.method, input_model.driver.derivative_int())) # Handle basis set # * for gamess, usually insufficient b/c either ngauss or ispher needed opts["basis__gbasis"] = input_model.model.basis # Handle conversion from schema (flat key/value) keywords into local format optcmd = format_keywords(opts) gamessrec["infiles"]["gamess.inp"] = optcmd + molcmd gamessrec["command"] = [which("rungms"), "gamess"] # rungms JOB VERNO NCPUS >& JOB.log & return gamessrec
def found(raise_error: bool = False) -> bool: return which( "mp2d", return_bool=True, raise_error=raise_error, raise_msg="Please install via `conda install mp2d -c psi4`", )
def found(raise_error: bool = False) -> bool: return which( "nwchem", return_bool=True, raise_error=raise_error, raise_msg="Please install via http://www.nwchem-sw.org/index.php/Download", )
def found(raise_error: bool = False) -> bool: """Whether Madness harness is ready for operation, with both the QC program and any particular dependencies found. Parameters ---------- raise_error: bool Passed on to control negative return between False and ModuleNotFoundError raised. Returns ------- bool If both m-a-d-n-e-s-s and its harness dependency networkx are found, returns True. If raise_error is False and nwchem or networkx are missing, returns False. If raise_error is True and nwchem or networkx are missing, the error message for the first missing one is raised. """ qc = which( "moldft", return_bool=True, raise_error=raise_error, raise_msg= "Please install via https://github.com/m-a-d-n-e-s-s/madness", ) # dep = which_import( # "networkx", # return_bool=True, # raise_error=raise_error, # raise_msg="For NWChem harness, please install via `conda install networkx -c conda-forge`.", # ) return qc # and dep
def found(self, raise_error: bool = False) -> bool: return which( "qchem", return_bool=True, raise_error=raise_error, raise_msg="Please install by visiting the Q-Chem website.", )
def get_version(self) -> str: self.found(raise_error=True) # Get the node configuration config = get_config() # Run MADNESS which_prog = which("moldft") if config.use_mpiexec: command = create_mpi_invocation(which_prog, config) else: command = [which_prog] command.append("v.moldft") if which_prog not in self.version_cache: success, output = execute( command, { "v.moldft": "dft\nxc lda\nend\ngeometry\nBe 0.0 0.0 0.0\n\nend\n" }, scratch_directory=config.scratch_directory, ) if success: for line in output["stdout"].splitlines(): if "multiresolution suite" in line: version = line.strip().split()[1] self.version_cache[which_prog] = safe_version(version) else: raise UnknownError(output["stderr"]) return self.version_cache[which_prog]
def get_version(self) -> str: self.found(raise_error=True) # Get the node configuration config = get_config() # Run NWChem which_prog = which("nwchem") if config.use_mpiexec: command = create_mpi_invocation(which_prog, config) else: command = [which_prog] command.append("v.nw") if which_prog not in self.version_cache: success, output = execute(command, {"v.nw": ""}, scratch_directory=config.scratch_directory) if success: for line in output["stdout"].splitlines(): if "nwchem branch" in line: branch = line.strip().split()[-1] if "nwchem revision" in line: revision = line.strip().split()[-1] self.version_cache[which_prog] = safe_version(branch + "+" + revision) else: raise UnknownError(output["stderr"]) return self.version_cache[which_prog]
def found(raise_error: bool = False) -> bool: return which( "define", return_bool=True, raise_error=raise_error, raise_msg="Please install via http://www.cosmologic.de/turbomole/home.html", )
def found(raise_error: bool = False) -> bool: return which( "dftd3", return_bool=True, raise_error=raise_error, raise_msg="Please install via `conda install dftd3 -c psi4`.", )
def found(raise_error: bool = False) -> bool: return which( "rungms", return_bool=True, raise_error=raise_error, raise_msg="Please install via https://www.msg.chem.iastate.edu/GAMESS/GAMESS.html", )
def get_version(self) -> str: self.found(raise_error=True) name_space = { "molpro_uri": "http://www.molpro.net/schema/molpro-output" } which_prog = which("molpro") if which_prog not in self.version_cache: success, output = execute( [which_prog, "version.inp", "-d", ".", "-W", "."], infiles={"version.inp": ""}, outfiles=["version.out", "version.xml"], ) if success: tree = ET.ElementTree( ET.fromstring(output["outfiles"]["version.xml"])) root = tree.getroot() version_tree = root.find( "molpro_uri:job/molpro_uri:platform/molpro_uri:version", name_space) year = version_tree.attrib["major"] minor = version_tree.attrib["minor"] molpro_version = year + "." + minor self.version_cache[which_prog] = safe_version(molpro_version) return self.version_cache[which_prog]
def found(raise_error: bool = False) -> bool: """Whether Psi4 harness is ready for operation. Parameters ---------- raise_error: bool Passed on to control negative return between False and ModuleNotFoundError raised. Returns ------- bool If psi4 (psithon or psiapi) is found, returns True. If raise_error is False and psi4 is missing, returns False. If raise_error is True and psi4 is missing, the error message is raised. """ psithon = which("psi4", return_bool=True) psiapi = which_import("psi4", return_bool=True) if psithon and not psiapi: with popen([which("psi4"), "--module"]) as exc: exc["proc"].wait(timeout=30) if "module does not exist" in exc["stderr"]: pass # --module argument only in Psi4 DDD branch else: sys.path.append(exc["stdout"].split()[-1]) if psiapi and not psithon: psiimport = str(Path(which_import("psi4")).parent.parent) env = os.environ.copy() env["PYTHONPATH"] = psiimport with popen( ["python", "-c", "import psi4; print(psi4.executable[:-5])"], popen_kwargs={"env": env}) as exc: exc["proc"].wait(timeout=30) os.environ["PATH"] += os.pathsep + exc["stdout"].split()[-1] if psithon or psiapi: return True return which( "psi4", return_bool=True, raise_error=raise_error, raise_msg= "Please install via `conda install psi4 -c psi4`. Check it's in your PATH with `which psi4`.", )
def psi4_which(command, *, return_bool: bool = False, raise_error: bool = False, raise_msg: str = None) -> Union[bool, None, str]: """Test to see if a command is available in Psi4 search path. Returns ------- str or None By default, returns command path if command found or `None` if not. Environment is $PSIPATH:$PATH, less any None values. bool When `return_bool=True`, returns whether or not found. Raises ------ ModuleNotFoundError When `raises_error=True` and command not found. """ lenv = (os.pathsep.join([os.path.abspath(x) for x in os.environ.get('PSIPATH', '').split(os.pathsep) if x != '']) + os.pathsep + os.environ.get('PATH', '')) return which(command=command, return_bool=return_bool, raise_error=raise_error, raise_msg=raise_msg, env=lenv)
hardware_nvidia_gpu = pytest.mark.skipif(is_nvidia_gpu_present() is False, reason='Psi4 not detecting Nvidia GPU via `nvidia-smi`. Install one') using_memory_profiler = pytest.mark.skipif( which_import('memory_profiler', return_bool=True) is False, reason='Not detecting module memory_profiler. Install package if necessary and add to envvar PYTHONPATH') using_psi4 = pytest.mark.skipif( False, reason='Not detecting module psi4. Install package if necessary and add to envvar PYTHONPATH') using_qcdb = pytest.mark.skipif( True, reason='Not detecting common driver. Install package if necessary and add to envvar PYTHONPATH') using_dftd3 = pytest.mark.skipif( which('dftd3', return_bool=True) is False, reason='Not detecting executable dftd3. Install package if necessary and add to envvar PATH or PSIPATH') using_dftd3_321 = pytest.mark.skipif(is_dftd3_new_enough("3.2.1") is False, reason='DFTD3 does not include 3.2.1 features. Update package and add to PATH') using_gcp = pytest.mark.skipif( which("gcp", return_bool=True) is False, reason="Not detecting executable gcp. Install package if necessary and add to envvar PATH") using_mp2d = pytest.mark.skipif( which('mp2d', return_bool=True) is False, reason='Not detecting executable mp2d. Install package if necessary and add to envvar PATH') #using_psi4_libxc = pytest.mark.skipif(is_psi4_new_enough("1.2a1.dev100") is False, # reason="Psi4 does not include DFT rewrite to use Libxc. Update to development head")