aizynthfinder.context package

Subpackages

Submodules

aizynthfinder.context.collection module

Module containing a class that is the base class for all collection classes (stock, policies, scorers)

class aizynthfinder.context.collection.ContextCollection

Bases: abc.ABC

Abstract base class for a collection of items that can be loaded and then (de-)selected.

One can obtain individual items with:

an_item = collection["key"]

And delete items with

del collection["key"]
Return type

None

property items: List[str]

The available item keys

property selection: Union[List[str], str, None]

The keys of the selected item(s)

deselect(key=None)

Deselect one or all items

If no key is passed, all items will be deselected.

Parameters

key (Optional[str]) – the key of the item to deselect, defaults to None

Raises

KeyError – if the key is not among the selected ones

Return type

None

abstract load(*_)

Load an item. Needs to be implemented by a sub-class

Parameters

_ (Any) –

Return type

None

abstract load_from_config(**config)

Load items from a configuration. Needs to be implemented by a sub-class

Parameters

config (Any) –

Return type

None

select(value, append=False)

Select one or more items.

If this is a single selection collection, only a single value is accepted. If this is a multiple selection collection it will overwrite the selection completely, unless append is True and a single key is given.

Parameters
  • value (Union[str, List[str]]) – the key or keys of the item(s) to select

  • append (bool) – if True will append single keys to existing selection

Raises
  • ValueError – if this a single collection and value is multiple keys

  • KeyError – if at least one of the keys are not corresponding to a loaded item

Return type

None

select_all()

Select all loaded items

Return type

None

select_first()

Select the first loaded item

Return type

None

select_last()

Select the last loaded item

Return type

None

aizynthfinder.context.config module

Module containing a class for encapsulating the settings of the tree search

class aizynthfinder.context.config.Configuration(search=<factory>, post_processing=<factory>)

Bases: object

Encapsulating the settings of the tree search, including the policy, the stock, the loaded scorers and various parameters.

Parameters
  • search (aizynthfinder.context.config._SearchConfiguration) –

  • post_processing (aizynthfinder.context.config._PostprocessingConfiguration) –

Return type

None

search: aizynthfinder.context.config._SearchConfiguration
post_processing: aizynthfinder.context.config._PostprocessingConfiguration
stock: aizynthfinder.context.stock.stock.Stock
expansion_policy: aizynthfinder.context.policy.policies.ExpansionPolicy
filter_policy: aizynthfinder.context.policy.policies.FilterPolicy
scorers: aizynthfinder.context.scoring.collection.ScorerCollection
classmethod from_dict(source)

Loads a configuration from a dictionary structure. The parameters not set in the dictionary are taken from the default values. The policies and stocks specified are directly loaded.

Parameters

source (StrDict) – the dictionary source

Returns

a Configuration object with settings from the source

Return type

Configuration

classmethod from_file(filename)

Loads a configuration from a yaml file. The parameters not set in the yaml file are taken from the default values. The policies and stocks specified in the yaml file are directly loaded. The parameters in the yaml file may also contain environment variables as values.

Parameters

filename (str) – the path to a yaml file

Returns

a Configuration object with settings from the yaml file

Raises
ValueError: if parameter’s value expects an environment variable that

does not exist in the current environment

Return type

aizynthfinder.context.config.Configuration

Module contents