From 8e0ab0b9986086a442386009613038536c801142 Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Mon, 29 Jul 2024 15:29:06 -0400 Subject: [PATCH] Bugfix: initial version of dftbplus.ini * The initial version of dftbplus.ini was not generated correctly if it was missing. This caused a crash when running DFTB+. --- HISTORY.rst | 4 ++++ dftbplus_step/dftbplus.py | 35 ++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 776a2bc..bf746a2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,10 @@ ======= History ======= +2024.7.29 -- Bugfix: initial version of dftbplus.ini + * The initial version of dftbplus.ini was not generated correctly if it was + missing. This caused a crash when running DFTB+. + 2024.4.24 -- Finalized support for Docker containers * Fixed issues and tested running in containers. * Add CI to make a Docker image for DFTB+ diff --git a/dftbplus_step/dftbplus.py b/dftbplus_step/dftbplus.py index 5194c6f..694ae52 100644 --- a/dftbplus_step/dftbplus.py +++ b/dftbplus_step/dftbplus.py @@ -8,6 +8,7 @@ import importlib import json import logging +import os from pathlib import Path import pprint # noqa: F401 import shutil @@ -491,14 +492,19 @@ def get_exe_config(self): ini_dir = Path(self.global_options["root"]).expanduser() path = ini_dir / "dftbplus.ini" - if path.exists(): - full_config.read(ini_dir / "dftbplus.ini") - - # If the section we need doesn't exists, get the default - if not path.exists() or executor_type not in full_config: + # If the config file doesn't exists, get the default + if not path.exists(): resources = importlib.resources.files("dftbplus_step") / "data" ini_text = (resources / "dftbplus.ini").read_text() - full_config.read_string(ini_text) + txt_config = seamm_util.Configuration(path) + txt_config.from_string(ini_text) + + # Work out the conda info needed + txt_config.set_value("local", "conda", os.environ["CONDA_EXE"]) + txt_config.set_value("local", "conda-environment", "seamm-dftbplus") + txt_config.save() + + full_config.read(ini_dir / "dftbplus.ini") # Getting desperate! Look for an executable in the path if executor_type not in full_config: @@ -510,17 +516,12 @@ def get_exe_config(self): "in the path!" ) else: - full_config[executor_type] = { - "installation": "local", - "code": str(path), - } - - # If the ini file does not exist, write it out! - if not path.exists(): - with path.open("w") as fd: - full_config.write(fd) - printer.normal(f"Wrote the DFTB+ configuration file to {path}") - printer.normal("") + txt_config = seamm_util.Configuration(path) + txt_config.add_section(executor_type) + txt_config.set_value(executor_type, "installation", "local") + txt_config.set_value(executor_type, "code", str(path)) + txt_config.save() + full_config.read(ini_dir / "dftbplus.ini") self._exe_config = dict(full_config.items(executor_type)) # Use the matching version of the seamm-dftbplus image by default.