From 5fd38ee2fd370fcf682a0979a83e91c570ff18d2 Mon Sep 17 00:00:00 2001 From: Joshua Meyers Date: Fri, 25 Feb 2022 16:54:54 +0000 Subject: [PATCH] add job-name to generate_optimized_molecules --- README.md | 1 + guacamol/__init__.py | 2 +- guacamol/goal_directed_benchmark.py | 21 +++++++++++++++------ guacamol/goal_directed_generator.py | 9 +++++++-- tests/test_goal_directed_benchmark.py | 3 ++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0de08bc..d8d1909 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/guacamol/__init__.py b/guacamol/__init__.py index 86716a7..906d362 100644 --- a/guacamol/__init__.py +++ b/guacamol/__init__.py @@ -1 +1 @@ -__version__ = "0.5.5" +__version__ = "0.6.0" diff --git a/guacamol/goal_directed_benchmark.py b/guacamol/goal_directed_benchmark.py index 73b2e49..a4f9338 100644 --- a/guacamol/goal_directed_benchmark.py +++ b/guacamol/goal_directed_benchmark.py @@ -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__) @@ -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) diff --git a/guacamol/goal_directed_generator.py b/guacamol/goal_directed_generator.py index 640b1b6..62ef11f 100644 --- a/guacamol/goal_directed_generator.py +++ b/guacamol/goal_directed_generator.py @@ -10,8 +10,12 @@ 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. @@ -19,6 +23,7 @@ def generate_optimized_molecules(self, scoring_function: ScoringFunction, number 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. diff --git a/tests/test_goal_directed_benchmark.py b/tests/test_goal_directed_benchmark.py index 8cdf641..4afebaa 100644 --- a/tests/test_goal_directed_benchmark.py +++ b/tests/test_goal_directed_benchmark.py @@ -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