diff --git a/docs/source/CHANGELOG.md b/docs/source/CHANGELOG.md index 0af346a..9cd67eb 100644 --- a/docs/source/CHANGELOG.md +++ b/docs/source/CHANGELOG.md @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [3.3.0] + +### Changed + +- `moldrug.utils.__tar_errors__` by `moldrug.utils.tar_errors`. +- Default value of `moldrug.utils.tar_errors` is `error` instead of `.error`. +- `moldrug.constraintconf.generate_conformers` outputs warnings and errors to `error` instead of `.error`. +- `moldrug.fitness.__vinadock` by `moldrug.fitness._vinadock`. +- `moldrug.fitness._vinadock` outputs warnings and errors to `error` instead of `.error`. + +### Fixed + +- The use of `moldrug.utils.tar_errors` inside of `moldrug.utils.Local` and `moldrug.utils.GA`. +- Clean code. + ## [3.2.5] - 2020.12.20 ### Fixed @@ -279,8 +294,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Minor code cleaning. - Better code covered during testing -[unreleased]: https://github.com/ale94mleon/MolDrug/compare/3.2.5...HEAD -[3.2.4]: https://github.com/ale94mleon/MolDrug/compare/3.2.2...3.2.5 +[unreleased]: https://github.com/ale94mleon/MolDrug/compare/3.3.0...HEAD +[3.3.0]: https://github.com/ale94mleon/MolDrug/compare/3.2.5...3.3.0 +[3.2.5]: https://github.com/ale94mleon/MolDrug/compare/3.2.2...3.2.5 [3.2.2]: https://github.com/ale94mleon/MolDrug/compare/3.2.0...3.2.2 [3.2.0]: https://github.com/ale94mleon/MolDrug/compare/3.1.0...3.2.0 [3.1.0]: https://github.com/ale94mleon/MolDrug/compare/3.0.3...3.1.0 diff --git a/moldrug/_version.py b/moldrug/_version.py index 11077de..f82690d 100644 --- a/moldrug/_version.py +++ b/moldrug/_version.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # We will use semantic version (major, minor, patch) -__version_tuple__ = version_tuple = (3, 2, 5) +__version_tuple__ = version_tuple = (3, 3, 0) __version__ = version = '.'.join([str(i) for i in __version_tuple__]) \ No newline at end of file diff --git a/moldrug/constraintconf.py b/moldrug/constraintconf.py index a4714fb..054ff7b 100644 --- a/moldrug/constraintconf.py +++ b/moldrug/constraintconf.py @@ -127,8 +127,8 @@ def generate_conformers(mol: Chem.rdchem.Mol, current directory generate_conformers_error.log with the nature of the Exception. """ # Creating the error directory if needed - if not os.path.isdir('.error'): - os.makedirs('.error') + if not os.path.isdir('error'): + os.makedirs('error') # if SMILES to be fixed are not given, assume to the MCS if ref_smi: if not Chem.MolFromSmiles(ref_smi): @@ -170,8 +170,8 @@ def generate_conformers(mol: Chem.rdchem.Mol, except Exception as e: print(e) cwd = os.getcwd() - warnings.warn(f"generate_conformers failed. Check the file {os.path.join(cwd, '.error/generate_conformers_error.pbz2')}") - compressed_pickle('.error/generate_conformers_error', e) + warnings.warn(f"generate_conformers failed. Check the file {os.path.join(cwd, 'error/generate_conformers_error.pbz2')}") + compressed_pickle('error/generate_conformers_error', e) mol.RemoveAllConformers() return mol diff --git a/moldrug/fitness.py b/moldrug/fitness.py index 094a83a..48b8222 100644 --- a/moldrug/fitness.py +++ b/moldrug/fitness.py @@ -238,8 +238,8 @@ def __vinadock( constraint_type = constraint_type.lower() # Creating the error directory if needed - if not os.path.isdir('.error'): - os.makedirs('.error') + if not os.path.isdir('error'): + os.makedirs('error') # Creating the working directory if needed if not os.path.exists(wd): os.makedirs(wd) @@ -297,7 +297,7 @@ def __vinadock( # Make a copy to the vina command string and add the out (is needed) and ligand options cmd_vina_str_tmp = cmd_vina_str[:] cmd_vina_str_tmp += f" --ligand {os.path.join(wd, f'{Individual.idx}_conf_{conf.GetId()}.pdbqt')}" - + if constraint_type == 'local_only': cmd_vina_str_tmp += f" --out {os.path.join(wd, f'{Individual.idx}_conf_{conf.GetId()}_out.pdbqt')}" try: @@ -318,7 +318,7 @@ def __vinadock( 'boxcenter': boxcenter, 'boxsize': boxsize, } - utils.compressed_pickle(f'.error/idx_{Individual.idx}_conf_{conf.GetId()}_error', error) + utils.compressed_pickle(f'error/idx_{Individual.idx}_conf_{conf.GetId()}_error', error) warnings.warn(f"\nVina failed! Check: idx_{Individual.idx}_conf_{conf.GetId()}_error.pbz2 file in error.\n") vina_score_pdbqt = (np.inf, preparator.write_pdbqt_string()) return vina_score_pdbqt @@ -365,7 +365,7 @@ def __vinadock( 'boxcenter': boxcenter, 'boxsize': boxsize, } - utils.compressed_pickle(f'.error/{Individual.idx}_error', error) + utils.compressed_pickle(f'error/{Individual.idx}_error', error) warnings.warn(f"\nVina failed! Check: {Individual.idx}_error.pbz2 file in error.\n") vina_score_pdbqt = (np.inf, 'VinaFailed') diff --git a/moldrug/utils.py b/moldrug/utils.py index 30cf27e..4b5b6d7 100644 --- a/moldrug/utils.py +++ b/moldrug/utils.py @@ -467,7 +467,7 @@ def import_sascorer(): """ # In order to import sascorer from RDConfig.RDContribDir from rdkit.Chem import RDConfig - import os, importlib.util as importlib_util + import importlib.util as importlib_util spec=importlib_util.spec_from_file_location('sascorer', os.path.join(RDConfig.RDContribDir, 'SA_Score', 'sascorer.py')) sascorer = importlib_util.module_from_spec(spec) spec.loader.exec_module(sascorer) @@ -826,7 +826,7 @@ def make_sdf(individuals:List[Individual], sdf_name = 'out'): print(f"{individual} does not have a valid pdbqt: {individual.pdbqt}.") print(f"File {sdf_name}.sdf was createad!") -def __make_kwargs_copy__(costfunc, costfunc_kwargs,): +def _make_kwargs_copy(costfunc, costfunc_kwargs,): """Make a copy of the self.costfunc_kwargs. It creates a temporal directory. @@ -841,13 +841,15 @@ def __make_kwargs_copy__(costfunc, costfunc_kwargs,): kwargs_copy['wd'] = costfunc_jobs_tmp_dir.name return kwargs_copy, costfunc_jobs_tmp_dir -def __tar_errors__(error_path:str = '.error'): - """Clena of errors the working directory +def tar_errors(error_path:str = 'error'): + """Clean errors in the working directory. + Convert to error.tar.gz the error_path + and delete the directory. Parameters ---------- error_path : str - Where the error are storged. + Where the errors are storged. """ if os.path.isdir(error_path): if os.listdir(error_path): @@ -946,7 +948,7 @@ def __call__(self, njobs:int = 1, pick:int = None): # Creating the arguments args_list = [] # Make a copy of the self.costfunc_kwargs - kwargs_copy, costfunc_jobs_tmp_dir = __make_kwargs_copy__(self.costfunc, self.costfunc_kwargs) + kwargs_copy, costfunc_jobs_tmp_dir = _make_kwargs_copy(self.costfunc, self.costfunc_kwargs) for individual in self.pop: args_list.append((individual, kwargs_copy)) @@ -959,7 +961,7 @@ def __call__(self, njobs:int = 1, pick:int = None): # Clean directory costfunc_jobs_tmp_dir.cleanup() # Tar errors - __tar_errors__('error') + tar_errors('error') # Printing how long was the simulation print(f"Finished at {datetime.datetime.now().strftime('%c')}.\n") @@ -1231,7 +1233,7 @@ def __call__(self, njobs:int = 1): args_list = [] # Make a copy of the self.costfunc_kwargs # Make a copy of the self.costfunc_kwargs - kwargs_copy, costfunc_jobs_tmp_dir = __make_kwargs_copy__(self.costfunc, self.costfunc_kwargs) + kwargs_copy, costfunc_jobs_tmp_dir = _make_kwargs_copy(self.costfunc, self.costfunc_kwargs) for individual in self.pop: args_list.append((individual, kwargs_copy)) @@ -1254,7 +1256,7 @@ def __call__(self, njobs:int = 1): # Clean directory costfunc_jobs_tmp_dir.cleanup() - + # Adding generation information for individual in self.pop: individual.genID = self.NumGens @@ -1323,7 +1325,7 @@ def __call__(self, njobs:int = 1): # Creating the arguments args_list = [] # Make a copy of the self.costfunc_kwargs - kwargs_copy, costfunc_jobs_tmp_dir = __make_kwargs_copy__(self.costfunc, self.costfunc_kwargs) + kwargs_copy, costfunc_jobs_tmp_dir = _make_kwargs_copy(self.costfunc, self.costfunc_kwargs) NumbOfSawIndividuals = len(self.SawIndividuals) for (i, individual) in enumerate(popc): @@ -1348,6 +1350,7 @@ def __call__(self, njobs:int = 1): f"=========Parellel=========:\n {e1}\n"\ f"==========Serial==========:\n {e2}" ) + # Clean directory costfunc_jobs_tmp_dir.cleanup() @@ -1397,7 +1400,7 @@ def __call__(self, njobs:int = 1): print(f"\n{50*'=+'}\n") # Tar errors - __tar_errors__('error') + tar_errors('error') # Printing how long was the simulation print(f"Total time ({self.maxiter} generations): {time.time() - ts:>5.2f} (s).\nFinished at {datetime.datetime.now().strftime('%c')}.\n") diff --git a/tests/test_moldrug.py b/tests/test_moldrug.py index 0a67631..b8a52a2 100644 --- a/tests/test_moldrug.py +++ b/tests/test_moldrug.py @@ -247,7 +247,7 @@ def test_fitness_module(): boxcenter = boxes.r_x0161['A']['boxcenter'], boxsize = boxes.r_x0161['A']['boxsize'],) # Clean - utils.__tar_errors__() + utils.tar_errors() os.remove('error.tar.gz') def test_home(): @@ -346,7 +346,7 @@ def test_constraintconf(): out = os.path.join(tmp_path.name, 'conf.sdf') ) # Clean - utils.__tar_errors__() + utils.tar_errors() def test_generate_conformers(): from moldrug.constraintconf import generate_conformers @@ -354,12 +354,12 @@ def test_generate_conformers(): ref = Chem.MolFromSmiles('O=S(=O)(Nc1ccc(Cl)cc1)c1ccsc1C(O)O') mol = Chem.MolFromSmiles('CN(C)S(=O)(=O)c1cc(NS(=O)(=O)c2ccsc2C(O)O)ccc1Cl') - AllChem.EmbedMolecule(ref) + AllChem.EmbedMolecule(ref) AllChem.MMFFOptimizeMolecule(ref) generate_conformers(Chem.RemoveHs(mol), Chem.RemoveHs(ref), 50) # Clean - utils.__tar_errors__() + utils.tar_errors() if __name__ == '__main__':