aizynthfinder.context.scoring package¶
Submodules¶
aizynthfinder.context.scoring.collection module¶
Module containing classes used to score the reaction routes.
- class aizynthfinder.context.scoring.collection.ScorerCollection(config)¶
Bases:
aizynthfinder.context.collection.ContextCollection
Store scorer objects for the aizynthfinder interface.
The scorers can be obtained by name with simple indexing
scorers = ScorerCollection() scorer = scorers['state score']
Scorers defined in this module and that does not require any other argument to initialize than the
config
are auto-loaded.- Parameters
config (Configuration) – the configuration of the tree search
- Return type
None
- create_default_scorers()¶
Setup the scores that only need the config as their input.
- Return type
None
- load(scorer)¶
Add a pre-initialized scorer object to the collection
- Parameters
scorer (aizynthfinder.context.scoring.scorers.Scorer) – the item to add
- Return type
None
- load_from_config(**scorers_config)¶
Load one or several scorers from a configuration dictionary
The keys are the name of scorer class. If a scorer is not defined in the
aizynthfinder.context.scoring
module, the module name can be appended, e.g.mypackage.scoring.AwesomeScore
.The values of the configuration is passed directly to the scorer class along with the
config
parameter.- Raises
ScorerException – if module or class could not be found
- Parameters
scorers_config (Any) –
- Return type
None
- make_subset(subset_names)¶
Make a new scorer collection by taking a subset of this collection. The scorer instances will be shared between the collections
- Parameters
subset_names (List[str]) – the scorers to copy over
- Returns
the newly formed collection
- Return type
- names()¶
Return a list of the names of all the loaded scorers
- Return type
List[str]
- score_vector(item)¶
For the given item, score it with all selected scorers and return a vector
- Parameters
item (_Scoreable) – the item to be scored
- Returns
the vector with the scores
- Return type
Sequence[float]
- weighted_score(item, weights)¶
For the given item, score it with all selected scorers and return a weighted sum of all the scores.
If weights is not the same length as the number of scorers an exception is raised.
If no scorers are selected this will raise an exception
- Parameters
item (_Scoreable) – the item to be scored
weights (Sequence[float]) – the weights of the scorers
- Returns
the weighted sum
- Return type
float
aizynthfinder.context.scoring.scorers module¶
Module containing classes used to score the reaction routes.
- class aizynthfinder.context.scoring.scorers.SquashScaler(slope, xoffset, yoffset)¶
Bases:
object
Squash function loosely adapted from a sigmoid function with parameters to modify and offset the shape
- Parameters
slope (float) – the slope of the midpoint
xoffset (float) – the offset of the midpoint along the x-axis
yoffset (float) – the offset of the curve along the y-axis
- Return type
None
- slope: float¶
- xoffset: float¶
- yoffset: float¶
- class aizynthfinder.context.scoring.scorers.MinMaxScaler(min_val, max_val, reverse, scale_factor=1)¶
Bases:
object
Scaling function that normalises the value between 0 - 1, the reverse variable controls the direction of scaling, reverse should set to be true for rewards that need to be minimised the scale_factor could be used to adjust the scores when they are too small or too big
- Parameters
val – the value that is being scaled
min_val (float) – minimum val param val could take
max_val (float) – maximum val param val could take
scale_factor (float) – scaling factor applied to the minmax scaled output
reverse (bool) –
- Return type
None
- min_val: float¶
- max_val: float¶
- reverse: bool¶
- scale_factor: float = 1¶
- class aizynthfinder.context.scoring.scorers.Scorer(config=None, scaler_params=None)¶
Bases:
abc.ABC
Abstract base class for classes that do scoring on MCTS-like nodes or reaction trees.
The actual scoring is done be calling an instance of a scorer class with a
Node
orReactionTree
object as only argument.scorer = MyScorer() score = scorer(node1)
You can also give a list of such objects to the scorer
scorer = MyScorer() scores = scorer([node1, node2])
- Parameters
config (Optional[Configuration]) – the configuration the tree search
scaler_params (Optional[StrDict]) – the parameter settings of the scaler
- Return type
None
- scorer_name = 'base'¶
- sort(items)¶
Sort nodes or reaction trees in descending order based on the score
- Parameters
items (_Scoreables) – the items to sort
- Returns
the sorted items and their scores
- Return type
Tuple[_Scoreables, Sequence[float], Sequence[int]]
- class aizynthfinder.context.scoring.scorers.StateScorer(config, scaler_params=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring nodes based on the state score
- Parameters
config (Configuration) –
scaler_params (Optional[StrDict]) –
- Return type
None
- scorer_name = 'state score'¶
- class aizynthfinder.context.scoring.scorers.MaxTransformScorerer(config=None, scaler_params=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring nodes based on the maximum transform
- Parameters
config (Optional[Configuration]) –
scaler_params (Optional[StrDict]) –
- Return type
None
- scorer_name = 'max transform'¶
- class aizynthfinder.context.scoring.scorers.FractionInStockScorer(config, scaler_params=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring nodes based on the fraction in stock
- Parameters
config (Configuration) –
scaler_params (Optional[StrDict]) –
- Return type
None
- scorer_name = 'fraction in stock'¶
- class aizynthfinder.context.scoring.scorers.NumberOfReactionsScorer(config=None, scaler_params=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring nodes based on the number of reaction it took to get to a node
- Parameters
config (Optional[Configuration]) –
scaler_params (Optional[StrDict]) –
- Return type
None
- scorer_name = 'number of reactions'¶
- class aizynthfinder.context.scoring.scorers.NumberOfPrecursorsScorer(config=None, scaler_params=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring nodes based on the number of pre-cursors in a node or route
- Parameters
config (Optional[Configuration]) –
scaler_params (Optional[StrDict]) –
- Return type
None
- scorer_name = 'number of pre-cursors'¶
- class aizynthfinder.context.scoring.scorers.NumberOfPrecursorsInStockScorer(config, scaler_params=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring nodes based on the number of pre-cursors in stock a node or route
- Parameters
config (Configuration) –
scaler_params (Optional[StrDict]) –
- Return type
None
- scorer_name = 'number of pre-cursors in stock'¶
- class aizynthfinder.context.scoring.scorers.AverageTemplateOccurrenceScorer(config=None, scaler_params=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring the nodes based on the average occurrence of the templates used to get to a node
- Parameters
config (Optional[Configuration]) –
scaler_params (Optional[StrDict]) –
- Return type
None
- scorer_name = 'average template occurrence'¶
- class aizynthfinder.context.scoring.scorers.PriceSumScorer(config, scaler_params=None, default_cost=1.0, not_in_stock_multiplier=10)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Scorer that sums the prices of all pre-cursors
- Parameters
config (Configuration) –
scaler_params (Optional[StrDict]) –
default_cost (float) –
not_in_stock_multiplier (int) –
- Return type
None
- scorer_name = 'sum of prices'¶
- class aizynthfinder.context.scoring.scorers.RouteCostScorer(config, scaler_params=None, reaction_cost=1, average_yield=0.8, default_cost=1, not_in_stock_multiplier=10)¶
Bases:
aizynthfinder.context.scoring.scorers.PriceSumScorer
Score based on the cost of molecules and reactions. From Badowski et al. Chem Sci. 2019, 10, 4640
- Parameters
config (Configuration) –
scaler_params (Optional[StrDict]) –
reaction_cost (int) –
average_yield (float) –
default_cost (int) –
not_in_stock_multiplier (int) –
- Return type
None
- scorer_name = 'route cost'¶
- class aizynthfinder.context.scoring.scorers.ReactionClassMembershipScorer(config, reaction_class_set, in_set_score=1.0, not_in_set_score=0.1)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Scorer that checks if the reaction classes are in a specified set
The score is calculated as product over each reaction. For each reaction the reaction classification is checked if it is in a given list of classes.
- Parameters
config (Configuration) –
reaction_class_set (Sequence[str]) –
in_set_score (float) –
not_in_set_score (float) –
- Return type
None
- class aizynthfinder.context.scoring.scorers.StockAvailabilityScorer(config, source_score, default_score=0.1)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Scorer that computes score based on the stock availability of the starting material
The score is calculated as a product of a stock score per starting material. The stock score for each molecule is based on the source of the stock, or a default value if the molecule is not in stock.
- Parameters
config (Configuration) –
source_score (StrDict) –
default_score (float) –
- Return type
None
- class aizynthfinder.context.scoring.scorers.CombinedScorer(config, scorers, weights=None)¶
Bases:
aizynthfinder.context.scoring.scorers.Scorer
Class for scoring nodes and reaction trees by combining weighted scores from a list of scorers
If no weights are provided as input, the scorer provides default weights that are equal for all input scorers.
The CombinedScorer cannot be instantiated from the config file as it requires the names of the scorers to combine as input.
- Parameters
config (Configuration) –
scorers (Sequence[str]) –
weights (Optional[Sequence[float]]) –
- Return type
None
Module contents¶
Sub-package containing scoring routines