Skip to content

Commit

Permalink
Fixed bug in setting up packmol.ini.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsaxe committed Jul 25, 2024
1 parent 7a2b201 commit 3ad39e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 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.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.
Expand Down
37 changes: 19 additions & 18 deletions packmol_step/packmol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import importlib
import logging
import math
import os
from pathlib import Path
import pprint
import shutil
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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))

Expand Down

0 comments on commit 3ad39e0

Please sign in to comment.