1616import yaml
1717from rdkit import Chem
1818
19- from moldrug import __version__ , constraintconf , utils
20- from moldrug .logging_utils import log
19+ from moldrug import __version__
20+ from moldrug .constraintconf import constraintconf
21+ from moldrug .logging_utils import log , LogLevel
22+ from moldrug .opt import GA , Local
23+ from moldrug .utils import decompress_pickle , make_sdf
2124
2225
2326class CommandLineHelper :
@@ -72,9 +75,9 @@ def _set_costfunc(self):
7275 def _set_TypeOfRun (self ):
7376 self ._TypeOfRun_str = self ._split_config ()[0 ]['type' ].lower ()
7477 if self ._TypeOfRun_str == 'ga' :
75- self .TypeOfRun = utils . GA
78+ self .TypeOfRun = GA
7679 elif self ._TypeOfRun_str == 'local' :
77- self .TypeOfRun = utils . Local
80+ self .TypeOfRun = Local
7881 else :
7982 raise NotImplementedError (f"\" { self ._split_config ()[0 ]['type' ]} \" it is not a possible type. "
8083 "Select from: GA or Local" )
@@ -92,7 +95,7 @@ def _translate_config(self):
9295 if any ([os .path .isfile (path ) for path in MainConfig ['seed_mol' ]]):
9396 seed_pop = set ()
9497 for solution in MainConfig ['seed_mol' ]:
95- _ , pop = utils . decompress_pickle (solution )
98+ _ , pop = decompress_pickle (solution )
9699 seed_pop .update (pop )
97100 # Sort
98101 seed_pop = sorted (seed_pop )
@@ -132,8 +135,10 @@ def _translate_config(self):
132135 if 'type' not in MainConfig ['cluster' ] or 'kwargs' not in MainConfig ['cluster' ]:
133136 raise ValueError ("The cluster configuration must contain 'type' and 'kwargs'." )
134137
135- from moldrug .runner import ( # terminates with a message if dask is not installed
136- Runner , RunnerMode )
138+ from moldrug .runner import (
139+ Runner , RunnerMode , dask_available )
140+ if not dask_available :
141+ log ("Dask is not installed and cluster is active" , LogLevel .CRITICAL )
137142
138143 try :
139144 cluster_class = getattr (importlib .import_module ("dask_jobqueue" ), MainConfig ['cluster' ]['type' ])
@@ -220,15 +225,15 @@ def _get_continuation_point(self):
220225 # If there is a continuation file, use this
221226 if os .path .isfile ("cpt.pbz2" ):
222227 pbz2 = 'cpt.pbz2'
223- iter_done = utils . decompress_pickle (pbz2 ).NumGens
228+ iter_done = decompress_pickle (pbz2 ).NumGens
224229 total_iter = 0
225230 for job in self .configuration :
226231 total_iter += self .configuration [job ]['maxiter' ]
227232 if total_iter >= iter_done :
228233 del self .FollowConfig [job ]
229234 break
230235 elif pbz2 :
231- iter_done = utils . decompress_pickle (pbz2 ).NumGens
236+ iter_done = decompress_pickle (pbz2 ).NumGens
232237 else :
233238 iter_done = 0
234239 new_maxiter = total_iter - iter_done
@@ -247,7 +252,7 @@ def _set_init_moldrugClass(self):
247252 self ._get_continuation_point ()
248253
249254 if self .pbz2 :
250- self .moldrugClass = utils . decompress_pickle (self .pbz2 )
255+ self .moldrugClass = decompress_pickle (self .pbz2 )
251256 self .moldrugClass .maxiter = self .new_maxiter
252257 else :
253258 # Initialize the class from scratch
@@ -260,10 +265,10 @@ def save_data(self):
260265 # Saving data
261266 if self ._TypeOfRun_str == 'local' :
262267 self .moldrugClass .pickle ("local_result" , compress = True )
263- utils . make_sdf (self .moldrugClass .pop , sdf_name = "local_pop" )
268+ make_sdf (self .moldrugClass .pop , sdf_name = "local_pop" )
264269 else :
265270 self .moldrugClass .pickle (f"{ self .moldrugClass .deffnm } _result" , compress = True )
266- utils . make_sdf (self .moldrugClass .pop , sdf_name = f"{ self .moldrugClass .deffnm } _pop" )
271+ make_sdf (self .moldrugClass .pop , sdf_name = f"{ self .moldrugClass .deffnm } _pop" )
267272
268273 def __repr__ (self ) -> str :
269274 string = self .args .__repr__ ().replace ('Namespace' , self .__class__ .__name__ )
@@ -306,7 +311,7 @@ def __moldrug_cmd():
306311 help = "To continue the simulation. The moldrug command must be the same "
307312 "and all the output moldrug files must be located "
308313 "in the working directory. This option is only compatible "
309- "with moldrug.utils .GA; otherwise, a RuntimeError will be raised." ,
314+ "with moldrug.opt .GA; otherwise, a RuntimeError will be raised." ,
310315 action = "store_true" ,
311316 dest = "continuation" )
312317 parser .add_argument (
@@ -418,7 +423,7 @@ def __constraintconf_cmd():
418423 type = Union [int , None ],
419424 )
420425 args = parser .parse_args ()
421- constraintconf . constraintconf (
426+ constraintconf (
422427 pdb = args .pdb ,
423428 smi = args .smi ,
424429 fix = args .fix ,
0 commit comments