6
6
import importlib
7
7
import logging
8
8
import math
9
+ import os
9
10
from pathlib import Path
10
11
import pprint
11
12
import shutil
16
17
from molsystem import SystemDB
17
18
import seamm
18
19
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
20
21
import seamm_util .printing as printing
21
22
from seamm_util .printing import FormattedText as __
22
23
import packmol_step
@@ -220,14 +221,19 @@ def run(self):
220
221
ini_dir = Path (seamm_options ["root" ]).expanduser ()
221
222
path = ini_dir / "packmol.ini"
222
223
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 ():
228
226
resources = importlib .resources .files ("packmol_step" ) / "data"
229
227
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" )
231
237
232
238
# Getting desperate! Look for an executable in the path
233
239
if executor_type not in full_config :
@@ -239,17 +245,12 @@ def run(self):
239
245
"in the path!"
240
246
)
241
247
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" )
253
254
254
255
config = dict (full_config .items (executor_type ))
255
256
0 commit comments