Skip to content

Commit

Permalink
Switch from pkg_resource, and added defaults for the executable.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsaxe committed Feb 9, 2024
1 parent 16d1bdc commit 489f691
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions mopac_step/mopac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 489f691

Please sign in to comment.