Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job-name to generate_optimized_molecules #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ docker run --rm -it -v `pwd`:/guacamol -w /guacamol guacamol-deps python -m gua
- 15 Oct 2020: pin dependencies since FCD does not
- 10 Nov 2021: relax pinned versions of keras, tensorflow & h5py dependencies
- 20 Dec 2021: expose forbidden symbols argument for custom smiles dataset filtering
- 25 Feb 2022: added `job_name` argument to `generate_optimized_molecules`

## Leaderboard

Expand Down
2 changes: 1 addition & 1 deletion guacamol/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.5"
__version__ = "0.6.0"
21 changes: 15 additions & 6 deletions guacamol/goal_directed_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import inspect
import logging
import time
from typing import Any, Dict, List, Tuple, Optional

import numpy as np
from typing import Any, Dict, List, Tuple, Optional

from guacamol.goal_directed_generator import GoalDirectedGenerator
from guacamol.goal_directed_score_contributions import ScoreContributionSpecification, compute_global_score
from guacamol.scoring_function import ScoringFunction, ScoringFunctionWrapper
from guacamol.goal_directed_generator import GoalDirectedGenerator
from guacamol.utils.chemistry import canonicalize_list, remove_duplicates, calculate_internal_pairwise_similarities

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -67,10 +68,18 @@ def assess_model(self, model: GoalDirectedGenerator) -> GoalDirectedBenchmarkRes
"""
number_molecules_to_generate = max(self.contribution_specification.top_counts)
start_time = time.time()
molecules = model.generate_optimized_molecules(scoring_function=self.wrapped_objective,
number_molecules=number_molecules_to_generate,
starting_population=self.starting_population
)

if 'job_name' in inspect.getfullargspec(model.generate_optimized_molecules).args:
# version 0.6.0 and above
molecules = model.generate_optimized_molecules(scoring_function=self.wrapped_objective,
number_molecules=number_molecules_to_generate,
starting_population=self.starting_population,
job_name=self.name)
else:
# backwards compatability
molecules = model.generate_optimized_molecules(scoring_function=self.wrapped_objective,
number_molecules=number_molecules_to_generate,
starting_population=self.starting_population)
end_time = time.time()

canonicalized_molecules = canonicalize_list(molecules, include_stereocenters=False)
Expand Down
9 changes: 7 additions & 2 deletions guacamol/goal_directed_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ class GoalDirectedGenerator(metaclass=ABCMeta):
"""

@abstractmethod
def generate_optimized_molecules(self, scoring_function: ScoringFunction, number_molecules: int,
starting_population: Optional[List[str]] = None) -> List[str]:
def generate_optimized_molecules(self,
scoring_function: ScoringFunction,
number_molecules: int,
starting_population: Optional[List[str]] = None,
job_name: Optional[str] = None,
) -> List[str]:
"""
Given an objective function, generate molecules that score as high as possible.

Args:
scoring_function: scoring function
number_molecules: number of molecules to generate
starting_population: molecules to start the optimization from (optional)
job_name: name of optimization job (optionally used by generators to save intermediate details/epochs/gens)

Returns:
A list of SMILES strings for the generated molecules.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_goal_directed_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self, molecules: List[str]) -> None:
self.molecules = molecules

def generate_optimized_molecules(self, scoring_function: ScoringFunction, number_molecules: int,
starting_population: Optional[List[str]] = None) -> List[str]:
starting_population: Optional[List[str]] = None, job_name: Optional[str] = None,
) -> List[str]:
assert number_molecules == len(self.molecules)
return self.molecules

Expand Down