@@ -54,40 +54,183 @@ def __init__(self, logger=logger):
54
54
logger .debug ("Initializing the PACKMOL installer object." )
55
55
56
56
self .section = "packmol-step"
57
- self .path_name = "packmol-path"
58
57
self .executables = ["packmol" ]
59
58
self .resource_path = Path (pkg_resources .resource_filename (__name__ , "data/" ))
59
+
60
+ # The environment.yaml file for Conda installations.
61
+ logger .debug (f"data directory: { self .resource_path } " )
62
+ self .environment_file = self .resource_path / "seamm-packmol.yml"
63
+
64
+ def check (self ):
65
+ """Check the status of the Packmol installation."""
66
+ print ("Checking the Packmol installation." )
67
+
60
68
# What Conda environment is the default?
61
- data = self .configuration .get_values (self .section )
69
+ path = self .configuration .path .parent / "packmol.ini"
70
+ if not path .exists ():
71
+ text = (self .resource_path / "packmol.ini" ).read_text ()
72
+ path .write_text (text )
73
+ print (f" The packmol.ini file did not exist. Created { path } " )
74
+
75
+ self .exe_config .path = path
76
+
77
+ # Get the current values
78
+ data = self .exe_config .get_values ("local" )
79
+
62
80
if "conda-environment" in data and data ["conda-environment" ] != "" :
63
81
self .environment = data ["conda-environment" ]
64
82
else :
65
83
self .environment = "seamm-packmol"
66
84
67
- # The environment.yaml file for Conda installations.
68
- path = Path (pkg_resources .resource_filename (__name__ , "data/" ))
69
- logger .debug (f"data directory: { path } " )
70
- self .environment_file = path / "seamm-packmol.yml"
85
+ super ().check ()
86
+
87
+ def install (self ):
88
+ """Install Packmol in a conda environment."""
89
+ print ("Installing Packmol." )
90
+
91
+ # What Conda environment is the default?
92
+ path = self .configuration .path .parent / "packmol.ini"
93
+ if not path .exists ():
94
+ text = (self .resource_path / "packmol.ini" ).read_text ()
95
+ path .write_text (text )
96
+ print (f" The packmol.ini file did not exist. Created { path } " )
97
+
98
+ self .exe_config .path = path
99
+
100
+ # Get the current values
101
+ data = self .exe_config .get_values ("local" )
102
+
103
+ if "conda-environment" in data and data ["conda-environment" ] != "" :
104
+ self .environment = data ["conda-environment" ]
105
+ else :
106
+ self .environment = "seamm-packmol"
107
+
108
+ super ().install ()
109
+
110
+ def show (self ):
111
+ """Show the status of the Packmol installation."""
112
+ print ("Showing the Packmol installation." )
113
+
114
+ # What Conda environment is the default?
115
+ path = self .configuration .path .parent / "packmol.ini"
116
+ if not path .exists ():
117
+ text = (self .resource_path / "packmol.ini" ).read_text ()
118
+ path .write_text (text )
119
+ print (f" The packmol.ini file does not exist at { path } " )
120
+ print (" The 'check' command will create it if Packmol is installed." )
121
+ print (" Otherwise 'install' will install Packmol." )
122
+ return
123
+
124
+ self .exe_config .path = path
125
+
126
+ if not self .exe_config .section_exists ("local" ):
127
+ print (
128
+ " Packmol is not configured: there is no 'local' section in "
129
+ f" { path } ."
130
+ )
131
+ return
132
+
133
+ # Get the current values
134
+ data = self .exe_config .get_values ("local" )
135
+
136
+ if "conda-environment" in data and data ["conda-environment" ] != "" :
137
+ self .environment = data ["conda-environment" ]
138
+ else :
139
+ self .environment = "seamm-packmol"
71
140
72
- def exe_version (self , path ):
141
+ super ().show ()
142
+
143
+ def uninstall (self ):
144
+ """Uninstall the Packmol installation."""
145
+ print ("Uninstall the Packmol installation." )
146
+
147
+ # What Conda environment is the default?
148
+ path = self .configuration .path .parent / "packmol.ini"
149
+ if not path .exists ():
150
+ text = (self .resource_path / "packmol.ini" ).read_text ()
151
+ path .write_text (text )
152
+ print (
153
+ f"""" The packmol.ini file does not exist at { path }
154
+ Perhaps Packmol is not installed, but if it is the 'check' command may locate it
155
+ and create the ini file, after which 'uninstall' will remove it."""
156
+ )
157
+ return
158
+
159
+ self .exe_config .path = path
160
+
161
+ if not self .exe_config .section_exists ("local" ):
162
+ print (
163
+ f"""" The packmol.ini file at { path } does not have local section.
164
+ Perhaps Packmol is not installed, but if it is the 'check' command may locate it
165
+ and update the ini file, after which 'uninstall' will remove it."""
166
+ )
167
+ return
168
+
169
+ # Get the current values
170
+ data = self .exe_config .get_values ("local" )
171
+
172
+ if "conda-environment" in data and data ["conda-environment" ] != "" :
173
+ self .environment = data ["conda-environment" ]
174
+ else :
175
+ self .environment = "seamm-packmol"
176
+
177
+ super ().uninstall ()
178
+
179
+ def update (self ):
180
+ """Updates the Packmol installation."""
181
+ print ("Updating the Packmol installation." )
182
+
183
+ # What Conda environment is the default?
184
+ path = self .configuration .path .parent / "packmol.ini"
185
+ if not path .exists ():
186
+ text = (self .resource_path / "packmol.ini" ).read_text ()
187
+ path .write_text (text )
188
+ print (f" The packmol.ini file did not exist. Created { path } " )
189
+
190
+ self .exe_config .path = path
191
+
192
+ # Get the current values
193
+ data = self .exe_config .get_values ("local" )
194
+
195
+ if "conda-environment" in data and data ["conda-environment" ] != "" :
196
+ self .environment = data ["conda-environment" ]
197
+ else :
198
+ self .environment = "seamm-packmol"
199
+
200
+ super ().update ()
201
+
202
+ def exe_version (self , config ):
73
203
"""Get the version of the PACKMOL executable.
74
204
75
205
Parameters
76
206
----------
77
- path : pathlib.Path
78
- Path to the executable.
207
+ config : dict
208
+ Dictionary of options for running Packmol
79
209
80
210
Returns
81
211
-------
82
- str
212
+ "Packmol", str
83
213
The version reported by the executable, or 'unknown'.
84
214
"""
215
+ environment = config ["conda-environment" ]
216
+ conda = config ["conda" ]
217
+ if environment [0 ] == "~" :
218
+ environment = str (Path (environment ).expanduser ())
219
+ command = f"'{ conda } ' run --live-stream -p '{ environment } '"
220
+ elif Path (environment ).is_absolute ():
221
+ command = f"'{ conda } ' run --live-stream -p '{ environment } '"
222
+ else :
223
+ command = f"'{ conda } ' run --live-stream -n '{ environment } '"
224
+ command += " packmol -log none"
225
+
226
+ logger .debug (f" Running { command } " )
85
227
try :
86
228
result = subprocess .run (
87
- [ str ( path ), "-log" , "none" ] ,
229
+ command ,
88
230
stdin = subprocess .DEVNULL ,
89
231
capture_output = True ,
90
232
text = True ,
233
+ shell = True ,
91
234
)
92
235
except Exception :
93
236
version = "unknown"
@@ -103,4 +246,4 @@ def exe_version(self, path):
103
246
version = value
104
247
break
105
248
106
- return version
249
+ return "Packmol" , version
0 commit comments