diff --git a/mopac_step/mopac.py b/mopac_step/mopac.py index 56796ae..11aa844 100644 --- a/mopac_step/mopac.py +++ b/mopac_step/mopac.py @@ -5,12 +5,13 @@ import calendar import configparser import datetime +import importlib import logging import os import os.path from pathlib import Path -import pkg_resources import pprint +import shutil import string import molsystem @@ -25,8 +26,8 @@ printer = printing.getPrinter("mopac") # Add MOPAC's properties to the standard properties -path = Path(pkg_resources.resource_filename(__name__, "data/")) -csv_file = path / "properties.csv" +resources = importlib.resources.files("mopac_step") / "data" +csv_file = resources / "properties.csv" molsystem.add_properties_from_file(csv_file) @@ -262,16 +263,36 @@ def run(self, printer=printer): executor = self.flowchart.executor - # Read configuration file for MOPAC - ini_dir = Path(seamm_options["root"]).expanduser() - full_config = configparser.ConfigParser() - full_config.read(ini_dir / "mopac.ini") + # Read configuration file for MOPAC if it exists executor_type = executor.name + full_config = configparser.ConfigParser() + ini_dir = Path(seamm_options["root"]).expanduser() + path = ini_dir / "mopac.ini" + + if path.exists(): + full_config.read(ini_dir / "mopac.ini") + + # If the section we need doesn't exists, get the default + if not path.exists() or executor_type not in full_config: + resources = importlib.resources.files("mopac_step") / "data" + ini_text = (resources / "mopac.ini").read_text() + full_config.read_string(ini_text) + + # Getting desperate! Look for an executable in the path if executor_type not in full_config: - raise RuntimeError( - f"No section for '{executor_type}' in MOPAC ini file " - f"({ini_dir / 'mopac.ini'})" - ) + path = shutil.which("mopac") + if path is None: + raise RuntimeError( + f"No section for '{executor_type}' in MOPAC ini file " + f"({ini_dir / 'mopac.ini'}), nor in the defaults, nor " + "in the path!" + ) + else: + full_config[executor_type] = { + "installation": "local", + "code": str(path) + } + config = dict(full_config.items(executor_type)) return_files = [