Skip to content

Commit

Permalink
Bugfix: initial version of dftbplus.ini
Browse files Browse the repository at this point in the history
* The initial version of dftbplus.ini was not generated correctly if it was
  missing. This caused a crash when running DFTB+.
  • Loading branch information
paulsaxe committed Jul 29, 2024
1 parent 15ad5a1 commit 8e0ab0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -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+
Expand Down
35 changes: 18 additions & 17 deletions dftbplus_step/dftbplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import importlib
import json
import logging
import os
from pathlib import Path
import pprint # noqa: F401
import shutil
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down

0 comments on commit 8e0ab0b

Please sign in to comment.