From 3ad39e03faf5612e9f240fe6ddd6d8531847491d Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Thu, 25 Jul 2024 12:10:00 -0400 Subject: [PATCH] Fixed bug in setting up packmol.ini. --- HISTORY.rst | 4 ++++ packmol_step/packmol.py | 37 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index a9ecf5d..c437e64 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,10 @@ ======= History ======= +2024.7.25 -- Bugfix: initial setup of packmol.ini fil + * The initial setup of the packmol.ini file did not add the information for + Conda. This release fixes that problem. + 2024.6.29 -- Bugfix: bonding incorrect in some cases. * The use of PDB with Packmol could in some cases lead to multiple bonds in the wrong place. This release fixes that problem. diff --git a/packmol_step/packmol.py b/packmol_step/packmol.py index 4685901..66b6d9c 100644 --- a/packmol_step/packmol.py +++ b/packmol_step/packmol.py @@ -6,6 +6,7 @@ import importlib import logging import math +import os from pathlib import Path import pprint import shutil @@ -16,7 +17,7 @@ from molsystem import SystemDB import seamm import seamm_util -from seamm_util import ureg, Q_, units_class # noqa: F401 +from seamm_util import Configuration, ureg, Q_, units_class # noqa: F401 import seamm_util.printing as printing from seamm_util.printing import FormattedText as __ import packmol_step @@ -220,14 +221,19 @@ def run(self): ini_dir = Path(seamm_options["root"]).expanduser() path = ini_dir / "packmol.ini" - if path.exists(): - full_config.read(ini_dir / "packmol.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("packmol_step") / "data" ini_text = (resources / "packmol.ini").read_text() - full_config.read_string(ini_text) + txt_config = 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-packmol") + txt_config.save() + + full_config.read(ini_dir / "packmol.ini") # Getting desperate! Look for an executable in the path if executor_type not in full_config: @@ -239,17 +245,12 @@ def run(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 Packmol configuration file to {path}") - printer.normal("") + txt_config = Configuration(path) + txt_config.add_section(executor_type) + txt_config.add_value(executor_type, "installation", "local") + txt_config.add_value(executor_type, "code", str(path)) + txt_config.save() + full_config.read(ini_dir / "packmol.ini") config = dict(full_config.items(executor_type))