Recipes & Routes
- class hippo.recipe.Recipe(db: Database, *, products: IngredientSet | None = None, reactants: IngredientSet | None = None, intermediates: IngredientSet | None = None, reactions: ReactionSet | None = None, compounds: IngredientSet | None = None)[source]
A Recipe stores data corresponding to a specific synthetic recipe involving several products, reactants, intermediates, and reactions.
Recipe initialisation
- add_ingredient(ingredient: Ingredient, amount: float = 1)[source]
Add an
Ingredientobject for direct purchase (no associated reactions)
- add_to_all_reactants(amount: float = 20) None[source]
Increment all reactants by this amount
- Parameters:
amount – amount in
mg(Default value = 20)
- property combined_compound_ids: set[int]
Combined
CompoundIDs fromRecipe.product_compounds()andRecipe.compounds()
- property combined_compounds: CompoundSet
Combined product and no-chem compounds
- property compounds: IngredientSet
Product
IngredientSet
- draw(color_mapper=None, node_size=300, graph_only=False)[source]
draw graph of the reaction network
- Parameters:
color_mapper – (Default value = None)
node_size – (Default value = 300)
graph_only – (Default value = False)
- property empty: bool
Is this Recipe empty?
- classmethod from_compounds(compounds: CompoundSet, amount: float = 1, debug: bool = False, pick_cheapest: bool = True, permitted_reactions=None, quoted_only: bool = False, supplier: None | str = None, solve_combinations: bool = True, pick_first: bool = False, warn_multiple_solutions: bool = True, pick_cheapest_inner_routes: bool = False, unavailable_reaction: str = 'error', reaction_checking_cache: dict[int, bool] | None = None, reaction_reactant_cache: dict[int, bool] | None = None, use_routes: bool = False, **kwargs)[source]
Create recipe(s) to synthesis products in the
CompoundSet- Parameters:
compounds – set of compounds to find routes for
solve_combinations – bool: combinatorially combine all individual routes (Default value = True)
pick_first – return the first solution without comparison (Default value = False)
warn_multiple_solutions – warn if a compound has multiple routes (Default value = True)
pick_cheapest_inner_routes – for each compound choose the cheapest route (Default value = False)
reaction – reaction to create recipe from
amount – amount in
mg(Default value = 1)debug – bool: increase verbosity for debugging (Default value = False)
pick_cheapest – bool: choose the cheapest solution (Default value = True)
permitted_reactions – once consider reactions in this set (Default value = None)
quoted_only – bool: only allow reactants with quotes (Default value = False)
supplier – None | str: optionally restrict quotes to only this supplier (Default value = None)
unavailable_reaction – define the behaviour for when a reaction has unavailable reactants (Default value = ‘error’)
- classmethod from_json(db: Database, path: str | Path, debug: bool = True, allow_db_mismatch: bool = False, clear_quotes: bool = False, data: dict = None, db_mismatch_warning: bool = True)[source]
Load a serialised recipe from a JSON file
- Parameters:
db – database to link
path – path to JSON
debug – increase verbosity (Default value = True)
allow_db_mismatch – allow a database mismatch (Default value = False)
clear_quotes – ignore reactant quotes (Default value = False)
data – serialised data (Default value = None)
- classmethod from_reactants(reactants: CompoundSet | IngredientSet, amount: float = 1, debug: bool = False, return_products: bool = False, supplier: str | None = None, pick_cheapest: bool = False, use_routes: bool = False, **kwargs) list[Recipe] | Recipe | CompoundSet[source]
Find the maximal recipe from a given set of reactants
- Parameters:
reactants –
CompoundSetorIngredientSetfor the reactants. Ingredient amounts are ignoredamount – amount of each product needed (Default value = 1)
debug – increase verbosity (Default value = False)
return_products – return products instead of recipe (Default value = False)
kwargs – passed to
Recipe.from_reactions()
- classmethod from_reaction(reaction, amount=1, *, debug: bool = False, pick_cheapest: bool = True, permitted_reactions: ReactionSet | None = None, quoted_only: bool = False, supplier: None | str = None, unavailable_reaction: str = 'error', reaction_checking_cache: dict[int, bool] = None, reaction_reactant_cache: dict[int, bool] = None, inner: bool = False, get_ingredient_quotes: bool = True) Recipe | list[Recipe][source]
Create a
Recipefrom aReactionand its upstream dependencies- Parameters:
reaction – reaction to create recipe from
amount – amount in
mg(Default value = 1)debug – bool: increase verbosity for debugging (Default value = False)
pick_cheapest – bool: choose the cheapest solution (Default value = True)
permitted_reactions – once consider reactions in this set (Default value = None)
quoted_only – bool: only allow reactants with quotes (Default value = False)
supplier – None | str: optionally restrict quotes to only this supplier (Default value = None)
unavailable_reaction – define the behaviour for when a reaction has unavailable reactants (Default value = ‘error’)
inner – used to indicate that this is a recursive call (Default value = False)
get_ingredient_quotes – get quotes for ingredients in this recipe
- classmethod from_reactions(reactions: ReactionSet, amount: float = 1, pick_cheapest: bool = True, permitted_reactions: ReactionSet | None = None, final_products_only: bool = True, return_products: bool = False, supplier: str | None = None, use_routes: bool = False, debug: bool = False, **kwargs) Recipe | list[Recipe] | CompoundSet[source]
Create a
Recipefrom aReactionSetand its upstream dependencies- Parameters:
reactions – reactions to create recipe from
amount – amount in
mg(Default value = 1)debug – bool: increase verbosity for debugging (Default value = False)
pick_cheapest – bool: choose the cheapest solution (Default value = True)
permitted_reactions – once consider reactions in this set (Default value = None)
final_products_only – don’t get routes to intermediates (Default value = True)
return_products – return the
CompoundSetof products instead (Default value = False)
- get_dict(*, price: bool = True, reactant_supplier: bool = True, compound_supplier: bool = True, database: bool = True, timestamp: bool = True, compound_ids_only: bool = False, products: bool = True, serialise_price: bool = False)[source]
Serialise this recipe object
Store
Path to database
Timestamp
Reactants (& their quotes, amounts)
Intermediates (& their quotes)
Products (& their poses/scores/fingerprints)
Reactions
Total Price
Lead time
- param price:
include the price (Default value = True)
- param reactant_supplier:
include the supplier (Default value = True)
- param database:
include the database (Default value = True)
- param timestamp:
add a timestamp (Default value = True)
- param compound_ids_only:
ID’s only (instead of full
IngredientSet.df) (Default value = False)- param products:
include products (Default value = True)
- param serialise_price:
serialise
Priceobject (Default value = False)
- get_ingredient(id) Ingredient[source]
Get an ingredient by its compound ID
- Parameters:
id – compound ID
- get_price(supplier: str | None = None) Price[source]
get the reactants price. See
IngredientSet.get_price()- Parameters:
supplier – restrict quotes to this supplier
- property hash: str
Return the unique hash string
- property interactions: InteractionSet
Product pose interactions
- property intermediates: IngredientSet
Intermediates
IngredientSet
- property num_compounds: int
Return the number of compounds
- property num_intermediates
Return the number of intermediates
- property num_products: int
Return the number of products
- property num_reactants
Return the number of reactants
- property num_reaction_types
Return the number of reactions
- property num_reactions
Return the number of reactions
- property product: Ingredient
Return single product (if there’s only one)
- property product_compounds: CompoundSet
Product compounds
- property products: IngredientSet
Product
IngredientSet
- property reactants
Reactant
IngredientSet
- property reactions: ReactionSet
Intermediates
IngredientSet
- sankey(title: str | None = None) graph_objects.Figure[source]
draw a plotly Sankey diagram
- Parameters:
title – (Default value = None)
- property score
Return the Recipe score
- summary(price: bool = True) None[source]
Print a summary of this recipe
- Parameters:
price – print the price (Default value = True)
- to_syndirella(out_key: str | Path, poses: PoseSet, *, separate: bool = False) DataFrame[source]
Generate inputs for running syndirella elaboration
- property type: str
Get Recipe type (EMPTY/MIXED/CHEM/NOCHEM)
- write_CAR_csv(file: str | Path, return_df: bool = False) DataFrame | None[source]
Prepares CSVs for use with CAR.
Attention
This method requires a populated route table. For a workaround use
CompoundSet.write_CAR_csv()insteadColumns:
target-name
no-steps
concentration = None
amount-required
batch-tag
per reaction
reactant-1-1
reactant-2-1
reaction-product-smiles-1
reaction-name-1
reaction-recipe-1
reaction-groupby-column-1
- Parameters:
file – file to write to
return_df – return the dataframe (Default value = False)
- write_chemistry_csv(file: str | Path, return_df: bool = True) pd.DataFrame | None[source]
Detailed CSV output synthetis information for chemistry types in this set
- write_json(file: str | Path, *, extra: dict | None = None, indent: str = '\t', **kwargs) None[source]
Serialise this recipe object and write it to disk
- Parameters:
file – write to this path
extra – extra data to serialise
indent – indentation whitespace (Default value = ‘ ‘)
- write_product_csv(file: str | Path, return_df: bool = False) pd.DataFrame | None[source]
Detailed CSV output including product information for selection and synthesis
- write_reactant_csv(file: str | Path, return_df: bool = False) DataFrame | None[source]
Detailed CSV output including reactant information for purchasing and information on the downstream synthetic use
Reactant
ID
SMILES
Inchikey
Quote
Supplier
Catalogue
Entry
Lead-time
Quoted amount
Quote currency
Quote price
Quote purity
Downstream
num_reaction_dependencies
num_product_dependencies
reaction_dependencies
product_dependencies
- class hippo.recipe.Route(db, *, route_id: int, product: IngredientSet, reactants: IngredientSet, intermediates: IngredientSet, reactions: ReactionSet)[source]
A recipe with a single product, that is stored in the database
Route initialisation
- classmethod from_json(db: Database, path: str | Path, data: dict = None) Route[source]
Load a serialised route from a JSON file
- Parameters:
db – database to link
path – path to JSON
data – serialised data (Default value = None)
- property id: int
Route ID
- property product: Ingredient
Product ingredient
- class hippo.recipe.RouteSet(db: Database, routes: list[Route])[source]
A set of Route objects
RouteSet initialisation
- balanced_pop(permitted_clusters: set[tuple] | None = None, debug: bool = False) Route[source]
Pop a route from this set, while maintaining the balance of scaffold clusters populations
- property cluster_map: dict[tuple, set]
Create a dictionary grouping routes by their scaffold/base cluster.
- property db
Get associated database
- classmethod from_ids(db: Database, ids: list | set)[source]
Generate a routeset from a set of
RouteIDs- Parameters:
db – database to link
ids –
Routedatabase IDs
- classmethod from_json(db: Database, path: str | Path, data: dict = None) RouteSet[source]
Load a serialised routeset from a JSON file
- Parameters:
db – database to link
path – path to JSON
data – serialised data (Default value = None)
- classmethod from_product_ids(db: Database, ids: list | set)[source]
Generate a routeset from a set of product
CompoundIDs- Parameters:
db – database to link
ids –
Compounddatabase IDs
- property products: CompoundSet
Return a
CompoundSetof all the route products
Remove routes that don’t have all reactants available from given suppliers
- class hippo.rgen.RandomRecipeGenerator(db, *, max_lead_time=None, suppliers: list | None = None, start_with: Recipe | CompoundSet | IngredientSet | None = None, route_pool: RouteSet | None = None, out_key: str | None = None)[source]
Class to create randomly sampled Recipe from a HIPPO Database
RandomRecipeGenerator initialisation
- classmethod from_json(db: Database, path: Path | str)[source]
Construct the RandomRecipeGenerator from a JSON file
- generate(budget: float = 10000, currency: str = 'EUR', max_products: int = 1000, max_reactions: int = 1000, debug: bool = False, max_iter: int | None = None, shuffle: bool = True, balance_clusters: bool = False, permitted_clusters: None | set = None)[source]
Generate random recipe
- Parameters:
budget – maximum budget (Default value = 10000)
currency – currency (Default value = ‘EUR’)
max_products – maximum number of products (Default value = 1000)
max_reactions – maximum number of reactions (Default value = 1000)
debug – increase verbosity for debugging (Default value = True)
max_iter – maximum number of iterations (Default value = None)
shuffle – randomly shuffle recipe pool (Default value = True)
balance_clusters – balance selection across scaffold clusters (Default value = False)
permitted_clusters – restrict selection to provided set of clusters (Default value = False)
- get_route_pool(mini_test=False)[source]
Construct the pool of routes that will be randomly sampled from
- Parameters:
mini_test – (Default value = False)
- property route_pool
Get the RouteSet of all product reaction routes considered by this generator
- class hippo.rgen.RandomSelectionGenerator(db, *, suppliers: list | None = None, amount: float = 1.0, start_with: Recipe | CompoundSet | IngredientSet = None, compounds: CompoundSet | None = None, quoted_only: bool = True)[source]
Class to create randomly sampled (no-chemistry) Recipe from a HIPPO Database
RandomSelectionGenerator initialisation
- property amount: float
Amount to quote each compound for
- property compound_pool: CompoundTable | CompoundSet
The pool of compounds that will be chosen from
- classmethod from_json(db: Database, path: Path | str) RandomSelectionGenerator[source]
Construct the RandomRecipeGenerator from a JSON file
- generate(budget: float = 10000, currency: str = 'EUR', max_iter: int | None = None, max_compounds: int = 1000, debug: bool = False, shuffle: bool = True)[source]
Generate random selection
- Parameters:
budget – maximum budget
currency – currency
max_iter – maximum number of iterations
max_compounds – maximum number of compounds
debug – Increase verbosity for debugging
shuffle – Randomise order of compound pool
- get_compound_pool(compounds: CompoundSet | None) CompoundTable | CompoundSet[source]
Get pool of compounds to select from
- get_starting_recipe(start_with: Recipe | CompoundSet | IngredientSet) Recipe[source]
Process start_with into Recipe object
- property quoted_only: bool
Only consider compounds with quotes