aizynthfinder.context.policy package

Submodules

aizynthfinder.context.policy.expansion_strategies module

Module containing classes that implements different expansion policy strategies

class aizynthfinder.context.policy.expansion_strategies.ExpansionStrategy(key, config, **kwargs)

Bases: ABC

A base class for all expansion strategies.

The strategy can be used by either calling the get_actions method of by calling the instantiated class with a list of molecule.

expander = MyExpansionStrategy("dummy", config)
actions, priors = expander.get_actions(molecules)
actions, priors = expander(molecules)
Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • kwargs (str)

abstract get_actions(molecules, cache_molecules=None)

Get all the probable actions of a set of molecules

Parameters:
  • molecules (Sequence[TreeMolecule]) – the molecules to consider

  • cache_molecules (Optional[Sequence[TreeMolecule]]) – additional molecules to submit to the expansion policy but that only will be cached for later use

Returns:

the actions and the priors of those actions

Return type:

Tuple[List[RetroReaction], List[float]]

reset_cache()

Reset the prediction cache

Return type:

None

class aizynthfinder.context.policy.expansion_strategies.MultiExpansionStrategy(key, config, **kwargs)

Bases: ExpansionStrategy

A base class for combining multiple expansion strategies.

The strategy can be used by either calling the get_actions method or by calling the instantiated class with a list of molecules.

Variables:
  • expansion_strategy_keys – the keys of the selected expansion strategies

  • additive_expansion – a conditional setting to specify whether all the actions and priors of the selected expansion strategies should be combined or not. Defaults to False.

  • expansion_strategy_weights – a list of weights for each expansion strategy. The weights should sum to one. Exception is the default, where unity weight is associated to each strategy.

Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • expansion_strategies – the keys of the selected expansion strategies. All keys of the selected expansion strategies must exist in the expansion policies listed in config

  • kwargs (Any)

get_actions(molecules, cache_molecules=None)

Get all the probable actions of a set of molecules, using the selected policies.

The default implementation combines all the actions and priors of the selected expansion strategies into two lists respectively if the ‘additive_expansion’ setting is set to True. This function can be overridden by a sub class to combine different expansion strategies in different ways.

Parameters:
  • molecules (Sequence[TreeMolecule]) – the molecules to consider

  • cache_molecules (Optional[Sequence[TreeMolecule]]) – additional molecules to submit to the expansion policy but that only will be cached for later use

Returns:

the actions and the priors of those actions

Raises:

PolicyException: if the policy isn’t selected

Return type:

Tuple[List[RetroReaction], List[float]]

class aizynthfinder.context.policy.expansion_strategies.TemplateBasedExpansionStrategy(key, config, **kwargs)

Bases: ExpansionStrategy

A template-based expansion strategy that will return TemplatedRetroReaction objects upon expansion.

Variables:
  • template_column – the column in the template file that contains the templates

  • cutoff_cumulative – the accumulative probability of the suggested templates

  • cutoff_number – the maximum number of templates to returned

  • use_rdchiral – a boolean to apply templates with RDChiral

  • use_remote_models – a boolean to connect to remote TensorFlow servers

  • rescale_prior – a boolean to apply softmax to the priors

  • chiral_fingerprints – if True will base expansion on chiral fingerprint

  • mask – a boolean vector of masks for the reaction templates. The length of the vector should be equal to the number of templates. It is set to None if no mask file is provided as input.

Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • model – the source of the policy model

  • template – the path to a HDF5 file with the templates

  • kwargs (str)

Raises:

PolicyException – if the length of the model output vector is not same as the number of templates

get_actions(molecules, cache_molecules=None)

Get all the probable actions of a set of molecules, using the selected policies and given cutoffs

Parameters:
  • molecules (Sequence[TreeMolecule]) – the molecules to consider

  • cache_molecules (Optional[Sequence[TreeMolecule]]) – additional molecules to submit to the expansion policy but that only will be cached for later use

Returns:

the actions and the priors of those actions

Return type:

Tuple[List[RetroReaction], List[float]]

reset_cache()

Reset the prediction cache

Return type:

None

class aizynthfinder.context.policy.expansion_strategies.TemplateBasedDirectExpansionStrategy(key, config, **kwargs)

Bases: TemplateBasedExpansionStrategy

A template-based expansion strategy that will return SmilesBasedRetroReaction objects upon expansion by directly applying the template

Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • source – the source of the policy model

  • templatefile – the path to a HDF5 file with the templates

  • kwargs (str)

Raises:

PolicyException – if the length of the model output vector is not same as the number of templates

get_actions(molecules, cache_molecules=None)

Get all the probable actions of a set of molecules, using the selected policies and given cutoffs

Parameters:
  • molecules (Sequence[TreeMolecule]) – the molecules to consider

  • cache_molecules (Optional[Sequence[TreeMolecule]]) – additional molecules to submit to the expansion policy but that only will be cached for later use

Returns:

the actions and the priors of those actions

Return type:

Tuple[List[RetroReaction], List[float]]

aizynthfinder.context.policy.filter_strategies module

Module containing classes that implements different filter policy strategies

class aizynthfinder.context.policy.filter_strategies.FilterStrategy(key, config, **kwargs)

Bases: ABC

A base class for all filter strategies.

The filter can be applied by either calling the apply method of by calling the instantiated class with a reaction.

filter = MyFilterStrategy("dummy", config)
filter.apply(reaction)
filter(reaction)
Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • kwargs (Any)

abstract apply(reaction)

Apply the filter on the reaction. If the reaction should be rejected a RejectionException is raised

Parameters:

reaction (RetroReaction) – the reaction to filter

Raises:

if the reaction should be rejected.

Return type:

None

class aizynthfinder.context.policy.filter_strategies.BondFilter(key, config, **kwargs)

Bases: FilterStrategy

Check if focussed bonds to freeze stay frozen in a reaction.

Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • kwargs (Any)

apply(reaction)

Apply the filter on the reaction. If the reaction should be rejected a RejectionException is raised

Parameters:

reaction (RetroReaction) – the reaction to filter

Raises:

if the reaction should be rejected.

Return type:

None

class aizynthfinder.context.policy.filter_strategies.QuickKerasFilter(key, config, **kwargs)

Bases: FilterStrategy

Filter quick-filter trained on artificial negative data

Variables:
  • use_remote_models – a boolean to connect to remote TensorFlow servers. Defaults to False.

  • filter_cutoff – the cut-off value

Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • model – the source of the policy model

  • kwargs (Any)

apply(reaction)

Apply the filter on the reaction. If the reaction should be rejected a RejectionException is raised

Parameters:

reaction (RetroReaction) – the reaction to filter

Raises:

if the reaction should be rejected.

Return type:

None

feasibility(reaction)

Computes if a given reaction is feasible by given the reaction fingerprint to a network model

Parameters:

reaction (RetroReaction) – the reaction to query

Returns:

if the reaction is feasible

Return type:

Tuple[bool, float]

class aizynthfinder.context.policy.filter_strategies.ReactantsCountFilter(key, config, **kwargs)

Bases: FilterStrategy

Check that the number of reactants is was expected from the template

Parameters:
  • key (str) – the key or label

  • config (Configuration) – the configuration of the tree search

  • kwargs (Any)

apply(reaction)

Apply the filter on the reaction. If the reaction should be rejected a RejectionException is raised

Parameters:

reaction (RetroReaction) – the reaction to filter

Raises:

if the reaction should be rejected.

Return type:

None

aizynthfinder.context.policy.policies module

Module containing classes that interfaces neural network policies

class aizynthfinder.context.policy.policies.ExpansionPolicy(config)

Bases: ContextCollection

An abstraction of an expansion policy.

This policy provides actions that can be applied to a molecule

Parameters:

config (Configuration) – the configuration of the tree search

get_actions(molecules, cache_molecules=None)

Get all the probable actions of a set of molecules, using the selected policies

Parameters:
  • molecules (Sequence[TreeMolecule]) – the molecules to consider

  • cache_molecules (Sequence[TreeMolecule]) – additional molecules that potentially are sent to the expansion model but for which predictions are not returned

Returns:

the actions and the priors of those actions

Raises:

PolicyException: if the policy isn’t selected

Return type:

Tuple[List[RetroReaction], List[float]]

load(source)

Add a pre-initialized expansion strategy object to the policy

Parameters:

source (ExpansionStrategy) – the item to add

Return type:

None

load_from_config(**config)

Load one or more expansion policy from a configuration

The format should be key:

type: name of the expansion class or custom_package.custom_model.CustomClass model: path_to_model template: path_to_templates other settings or params

or key:

  • path_to_model

  • path_to_templates

Parameters:

config (Any) – the configuration

Return type:

None

reset_cache()

Reset the cache on all loaded policies

Return type:

None

class aizynthfinder.context.policy.policies.FilterPolicy(config)

Bases: ContextCollection

An abstraction of a filter policy.

This policy provides a query on a reaction to determine whether it should be rejected

Parameters:

config (Configuration) – the configuration of the tree search

apply(reaction)

Apply the all the selected filters on the reaction. If the reaction should be rejected a RejectionException is raised

Parameters:

reaction (RetroReaction) – the reaction to filter

Raises:

if the reaction should be rejected or if a policy is selected

Return type:

None

load(source)

Add a pre-initialized filter strategy object to the policy

Parameters:

source (FilterStrategy) – the item to add

Return type:

None

load_from_config(**config)

Load one or more filter policy from a configuration

The format should be key:

type: name of the filter class or custom_package.custom_model.CustomClass model: path_to_model other settings or params

or key: path_to_model

Parameters:

config (Any) – the configuration

Return type:

None

reset_cache()

Reset filtering cache.

Return type:

None

aizynthfinder.context.policy.utils module

Module containing helper routines for policies

Module contents

Sub-package containing policy routines