Skip to content

Commit

Permalink
delete redundant code in GAmol
Browse files Browse the repository at this point in the history
  • Loading branch information
ale94mleon committed Dec 12, 2022
1 parent 692795e commit a12c8b9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Contrib/adme_models/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:58:50) \n[GCC 10.3.0]"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
15 changes: 11 additions & 4 deletions docs/source/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### Fix
## [3.2.2] - 2020.12.12

### Fixed

- Bug: The initial individual was not printed properly.

### Removed

- Redundant code in `moldrug.utils.GA`

## [3.2.0] - 2022.11.28

### Fix
### Fixed

- Bug: The output error name when constraint fails has a idx prefix. E.g. `33_conf_27_error.pbz2` now is: `idx_33_conf_27_error.pbz2`. Now it is easy to delete all of this files at the end of the simulation if they are not needed. (on the last version the naming was not changing)

Expand All @@ -35,7 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- The output error name when constraint fails has a idx prefix. E.g. 33_conf_27_error.pbz2 now is: idx_33_conf_27_error.pbz2. Now it is easy to delete all of this files at the end of the simulation if they are not needed.

### Fix
### Fixed

- Clean code.
- Improve docs.
Expand Down Expand Up @@ -265,7 +271,8 @@ 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.0...HEAD
[unreleased]: https://github.com/ale94mleon/MolDrug/compare/3.2.2...HEAD
[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
[3.0.3]: https://github.com/ale94mleon/MolDrug/compare/3.0.1...3.0.3
Expand Down
2 changes: 1 addition & 1 deletion moldrug/_version.py
Original file line number Diff line number Diff line change
@@ -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, 1)
__version_tuple__ = version_tuple = (3, 2, 2)
__version__ = version = '.'.join([str(i) for i in __version_tuple__])
35 changes: 20 additions & 15 deletions moldrug/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@ def roulette_wheel_selection(p:List[float]):
ind = np.argwhere(r <= c)
return ind[0][0]


def to_dataframe(individuals:List[Individual]):
"""Create a DataFrame from individuals.
Expand Down Expand Up @@ -1063,7 +1062,7 @@ def __init__(self, seed_mol:Union[Chem.rdchem.Mol, Iterable[Chem.rdchem.Mol]],
ValueError
In case of incorrect definition of mutate_crem_kwargs. It must be None or a dict instance.
"""
self.__moldrug_version = __version__
self.__moldrug_version__ = __version__
if mutate_crem_kwargs is None:
mutate_crem_kwargs = dict()
elif not isinstance(mutate_crem_kwargs, dict):
Expand Down Expand Up @@ -1141,8 +1140,8 @@ def __call__(self, njobs:int = 1):
self.NumCalls += 1

# Check version of MolDrug
if self.__moldrug_version != __version__:
warn.warning(f"{self.__class__.__name__} was initialized with moldrug-{self.__moldrug_version} but was called with moldrug-{__version__}")
if self.__moldrug_version__ != __version__:
warn.warning(f"{self.__class__.__name__} was initialized with moldrug-{self.__moldrug_version__} but was called with moldrug-{__version__}")

# Here we will update if needed some parameters for the crem operations that could change between different calls.
# We need to return the molecule, so we override the possible user definition respect to this keyword
Expand Down Expand Up @@ -1202,10 +1201,7 @@ def __call__(self, njobs:int = 1):
# Creating the arguments
args_list = []
# Make a copy of the self.costfunc_kwargs
kwargs_copy = self.costfunc_kwargs.copy()
if 'wd' in getfullargspec(self.costfunc).args:
costfunc_jobs = tempfile.TemporaryDirectory(prefix='costfunc')
kwargs_copy['wd'] = costfunc_jobs.name
kwargs_copy = self.__make_kwargs_copy__()

for individual in self.pop:
args_list.append((individual, kwargs_copy))
Expand Down Expand Up @@ -1236,8 +1232,6 @@ def __call__(self, njobs:int = 1):
'generated':len(self.pop[:])
}

if 'wd' in getfullargspec(self.costfunc).args: shutil.rmtree(costfunc_jobs.name)

# Print some information of the initial population
print(f"Initial Population: Best Individual: {min(self.pop)}")
print(f"Accepted rate: {self.acceptance[self.NumGens]['accepted']} / {self.acceptance[self.NumGens]['generated']}\n")
Expand Down Expand Up @@ -1296,10 +1290,7 @@ def __call__(self, njobs:int = 1):
# Creating the arguments
args_list = []
# Make a copy of the self.costfunc_kwargs
kwargs_copy = self.costfunc_kwargs.copy()
if 'wd' in getfullargspec(self.costfunc).args:
costfunc_jobs = tempfile.TemporaryDirectory(prefix='costfunc')
kwargs_copy['wd'] = costfunc_jobs.name
kwargs_copy = self.__make_kwargs_copy__()

NumbOfSawIndividuals = len(self.SawIndividuals)
for (i, individual) in enumerate(popc):
Expand All @@ -1324,7 +1315,6 @@ def __call__(self, njobs:int = 1):
f"=========Parellel=========:\n {e1}\n"\
f"==========Serial==========:\n {e2}"
)
if 'wd' in getfullargspec(self.costfunc).args: shutil.rmtree(costfunc_jobs.name)

# Merge, Sort and Select
self.pop += popc
Expand Down Expand Up @@ -1421,6 +1411,21 @@ def mutate(self, individual:Individual):
mol = Chem.AddHs(mol)
return Individual(mol)

def __make_kwargs_copy__(self):
"""Make a copy of the self.costfunc_kwargs.
It creates a temporal directory.
Returns
-------
dict
A copy of self.costfunc_kwargs with wd changed if needed
"""
kwargs_copy = self.costfunc_kwargs.copy()
if 'wd' in getfullargspec(self.costfunc).args:
costfunc_jobs = tempfile.TemporaryDirectory(prefix='costfunc')
kwargs_copy['wd'] = costfunc_jobs.name
return kwargs_copy

def pickle(self, title:str, compress = False):
"""Method to pickle the whole GA class
Expand Down

0 comments on commit a12c8b9

Please sign in to comment.