Skip to content

Commit 3ad39e0

Browse files
committed
Fixed bug in setting up packmol.ini.
1 parent 7a2b201 commit 3ad39e0

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

HISTORY.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
=======
22
History
33
=======
4+
2024.7.25 -- Bugfix: initial setup of packmol.ini fil
5+
* The initial setup of the packmol.ini file did not add the information for
6+
Conda. This release fixes that problem.
7+
48
2024.6.29 -- Bugfix: bonding incorrect in some cases.
59
* The use of PDB with Packmol could in some cases lead to multiple bonds in the
610
wrong place. This release fixes that problem.

packmol_step/packmol.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import importlib
77
import logging
88
import math
9+
import os
910
from pathlib import Path
1011
import pprint
1112
import shutil
@@ -16,7 +17,7 @@
1617
from molsystem import SystemDB
1718
import seamm
1819
import seamm_util
19-
from seamm_util import ureg, Q_, units_class # noqa: F401
20+
from seamm_util import Configuration, ureg, Q_, units_class # noqa: F401
2021
import seamm_util.printing as printing
2122
from seamm_util.printing import FormattedText as __
2223
import packmol_step
@@ -220,14 +221,19 @@ def run(self):
220221
ini_dir = Path(seamm_options["root"]).expanduser()
221222
path = ini_dir / "packmol.ini"
222223

223-
if path.exists():
224-
full_config.read(ini_dir / "packmol.ini")
225-
226-
# If the section we need doesn't exists, get the default
227-
if not path.exists() or executor_type not in full_config:
224+
# If the config file doesn't exists, get the default
225+
if not path.exists():
228226
resources = importlib.resources.files("packmol_step") / "data"
229227
ini_text = (resources / "packmol.ini").read_text()
230-
full_config.read_string(ini_text)
228+
txt_config = Configuration(path)
229+
txt_config.from_string(ini_text)
230+
231+
# Work out the conda info needed
232+
txt_config.set_value("local", "conda", os.environ["CONDA_EXE"])
233+
txt_config.set_value("local", "conda-environment", "seamm-packmol")
234+
txt_config.save()
235+
236+
full_config.read(ini_dir / "packmol.ini")
231237

232238
# Getting desperate! Look for an executable in the path
233239
if executor_type not in full_config:
@@ -239,17 +245,12 @@ def run(self):
239245
"in the path!"
240246
)
241247
else:
242-
full_config[executor_type] = {
243-
"installation": "local",
244-
"code": str(path),
245-
}
246-
247-
# If the ini file does not exist, write it out!
248-
if not path.exists():
249-
with path.open("w") as fd:
250-
full_config.write(fd)
251-
printer.normal(f"Wrote the Packmol configuration file to {path}")
252-
printer.normal("")
248+
txt_config = Configuration(path)
249+
txt_config.add_section(executor_type)
250+
txt_config.add_value(executor_type, "installation", "local")
251+
txt_config.add_value(executor_type, "code", str(path))
252+
txt_config.save()
253+
full_config.read(ini_dir / "packmol.ini")
253254

254255
config = dict(full_config.items(executor_type))
255256

0 commit comments

Comments
 (0)