aizynthfinder.context.stock package¶
Submodules¶
aizynthfinder.context.stock.queries module¶
Module containing classes that interfaces different stocks query classes
- class aizynthfinder.context.stock.queries.StockQueryMixin¶
Bases:
object
Mixin class for all query classes, providing a default interface to some methods that might not be possible to implement for each query class.
- amount(mol)¶
Returns the maximum amount of the molecule in stock
- Parameters:
mol (Molecule) – the query molecule
- Raises:
StockException – if the amount cannot be computed
- Returns:
the amount
- Return type:
float
- availability_string(mol)¶
Returns the sources of the molecule
- Parameters:
mol (Molecule) – the query molecule
- Raises:
StockException – if the string cannot be computed
- Returns:
a comma-separated list of sources
- Return type:
str
- cached_search(mol)¶
Finds the entries of the molecule in the stock and cache them if necessary.
- Parameters:
mol (Molecule) – the query molecule
- Returns:
if the molecule is in stock
- Return type:
bool
- clear_cache()¶
Clear the internal search cache if available
- Return type:
None
- price(mol)¶
Returns the minimum price of the molecule in stock
- Parameters:
mol (Molecule) – the query molecule
- Raises:
StockException – if the price cannot be computed
- Return type:
float
- class aizynthfinder.context.stock.queries.InMemoryInchiKeyQuery(path, inchi_key_col='inchi_key', price_col=None)¶
Bases:
StockQueryMixin
A stock query class that is based on an in-memory list of pre-computed inchi-keys.
- This list can be instantiated from
A Pandas dataframe in HDF5 or CSV format
A text file with an inchi key on each row
The dataframe must have a column with InChIkeys that by default is “inchi_key”. The HDF5 file must have a dataset called “table”.
If the source is a dataframe, then optionally it can contain prices and this columns can be specified with the “price_column” argument.
- Parameters:
path (str) – the path to the file with inchi-keys
inchi_key_col (str) – the name of the column of the InChI keys
path
inchi_key_col
price_col (Optional[str])
- Paramater price_col:
the name of the column with the optional prices
- property stock_inchikeys: Set[str]¶
Return the InChiKeys in this stock
- price(mol)¶
Returns the minimum price of the molecule in stock
- Parameters:
mol (Molecule) – the query molecule
- Raises:
StockException – if the price cannot be computed
- Return type:
float
- class aizynthfinder.context.stock.queries.MongoDbInchiKeyQuery(host=None, database='stock_db', collection='molecules')¶
Bases:
StockQueryMixin
A stock query class that is looking up inchi keys in a Mongo database.
- The documents in the database collection should have at least 2 fields:
inchi_key: the inchi key of the molecule
source: the original source of the molecule
- Variables:
client – the Mongo client
database – the database instance
molecules – the collection of documents
- Parameters:
host (Optional[str]) – the database host, defaults to None
database (str) – the database name, defaults to “stock_db”
collection (str) – the database collection, defaults to “molecules”
host
database
collection
- availability_string(mol)¶
Returns the sources of the molecule
- Parameters:
mol (Molecule) – the query molecule
- Raises:
StockException – if the string cannot be computed
- Returns:
a comma-separated list of sources
- Return type:
str
- class aizynthfinder.context.stock.queries.MolbloomFilterQuery(path, smiles_based=False)¶
Bases:
StockQueryMixin
A stock query class that is based on an a molbloom filter for SMILES strings or InChI keys
- Parameters:
path (str) – the path to the saved bloom filter
smiles_based (bool) – if True will use SMILES for lookup instead of InChI keys
path
smiles_based
aizynthfinder.context.stock.stock module¶
Module containing classes that interfaces different stock classes
- class aizynthfinder.context.stock.stock.Stock¶
Bases:
ContextCollection
A collection of molecules that are in stock
A molecule can be queried on the stock with:
my_mol = Molecule(smiles="CCO") my_mol in stock
One can obtain individual stocks with:
sub_stock = stock["key"]
One can obtain the number of molecules in the selected stock with:
number_of_molecules = len(stock)
- property stop_criteria: dict¶
Return a copy of the stop criteria used by the stock
- amount(mol)¶
Calculate the maximum amount of a molecule in stock
- Parameters:
mol (Molecule) – the molecule to query
- Raises:
StockException – if the amount could not be computed
- Returns:
the maximum amount
- Return type:
float
- availability_list(mol)¶
Return a list of what stocks a given mol is available
If the molecule is not in stock it will return any empty list
- Parameters:
mol (Molecule) – The molecule to query
- Returns:
string with a list of stocks that mol was found in
- Return type:
List[str]
- availability_string(mol)¶
Return a string of what stocks a given mol is available
If the molecule is not in stock it will return “Not in stock”
- Parameters:
mol (Molecule) – The molecule to query
- Returns:
string with a list of stocks that mol was found in
- Return type:
str
- exclude(mol)¶
Exclude a molecule from the stock. When this molecule is queried it will return False, regardless if the molecule is in the stock.
- Parameters:
mol (Molecule) – the molecule to exclude
- Return type:
None
- load(source, key)¶
Add a pre-initialized stock query object to the stock
- Parameters:
source (StockQueryMixin) – the item to add
key (str) – The key that will be used to select the stock
- Return type:
None
- load_from_config(**config)¶
Load one or more stock queries from a configuration
The key can be “stop_criteria” in case the config is given to the set_stop_criteria method
The format should be key:
type: name of the stock class or custom_package.custom_model.CustomClass path: path to the stock file other settings or params
or key: path_to_model
- Parameters:
config (Any) – the configuration
- Return type:
None
- price(mol)¶
Calculate the minimum price of a molecule in stock
- Parameters:
mol (Molecule) – the molecule to query
- Raises:
StockException – if the price could not be computed
- Returns:
the minimum price
- Return type:
float
- reset_exclusion_list()¶
Remove all molecules in the exclusion list
- Return type:
None
- select(value, append=False)¶
Select one or more stock queries
- Parameters:
value (Union[str, List[str]]) – the key of the stocks to select
append (bool) – if True and
value
is a single key append it to the current selection
- Return type:
None
- set_stop_criteria(criteria=None)¶
Set criteria that stop the search
The keys of the criteria can be “price” or “amount” which accepts numerical settings, or “counts” that should be dictionary of maximum allowed count for each atomic symbol.
Example:
criteria = { "price": 5, "amount": 100, "counts": { "C": 6, "O": 4 } }
- Parameters:
criteria (Optional[Dict]) – the criteria settings
- Return type:
None
- smiles_in_stock(smiles)¶
Check if the SMILES is in the currently selected stocks
- Parameters:
smiles (str) – SMILES string (must be RDKit sanitizable)
- Returns:
if the SMILES was on stock
- Return type:
bool
Module contents¶
Sub-package containing stock routines