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.

repr(self) str[source]

ANSI Formatted string representation

str(self) str[source]

Unformatted string representation

add_ingredient(ingredient: Ingredient, amount: float = 1)[source]

Add an Ingredient object 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)

check_integrity(debug: bool = False) bool[source]

Verify integrity of this recipe

property combined_compounds: CompoundSet

Combined product and no-chem compounds

property compounds: IngredientSet

Product IngredientSet

copy() Recipe[source]

Copy this recipe

property db: Database

`.Database:

Type:

Associated

Type:

class

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:
  • reactantsCompoundSet or IngredientSet for the reactants. Ingredient amounts are ignored

  • amount – 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 Recipe from a Reaction and 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 Recipe from a ReactionSet and 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 CompoundSet of 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 Price object (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

get_routes() RouteSet[source]

Get routes

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_reactions

Return the number of reactions

property poses: PoseSet

Product poses

property price: Price

Get the price of the reactants

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)

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() instead

Columns:

  • 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, product, reactants, intermediates, reactions)[source]

A recipe with a single product, that is stored in the database

repr(self) str[source]

ANSI Formatted string representation

str(self) str[source]

Unformatted string representation

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)

get_dict() dict[source]

Serialisable dictionary

property id: int

Route ID

property price: Price

Get the price of the reactants

property product: Ingredient

Product ingredient

property product_compound: Compound

Product compound

class hippo.recipe.RouteSet(db, routes)[source]

A set of Route objects

len(self) int[source]

Number of routes in this set

repr(self) str[source]

ANSI Formatted string representation

str(self) str[source]

Unformatted string representation

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.

Returns:

A dictionary mapping a tuple of scaffold Compound IDs to a set of Route ID’s to their superstructures.

copy() RouteSet[source]

Copy this RouteSet

property data: dict[int, Route]

Get internal data dictionary

property db

Get associated database

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)

property ids: list[int]

Return the Route IDs

pop() Route[source]

Pop the last route from the set and return it’s object

pop_id() int[source]

Pop the last route from the set and return it’s id

property product_ids: list[int]

Get the Compound ID’s of the products

property products: CompoundSet

Return a CompoundSet of all the route products

property routes: list[Route]

Get route objects

set_db_pointers(db: Database) None[source]
Parameters:

db

shuffle()[source]

Randomly shuffle the routes in this set

property str_ids: str

Return an SQL formatted tuple string of the Route ID’s

class hippo.rgen.RandomRecipeGenerator(db, *, max_lead_time=None, suppliers: list | None = None, start_with: Recipe | CompoundSet | IngredientSet = None)[source]

Class to create randomly sampled Recipe from a HIPPO Database

str(self) str[source]

Unformatted string representation

classmethod from_json(db: Database, path: Path | str)[source]

Construct the RandomRecipeGenerator from a JSON file

Parameters:
  • db

  • path

generate(budget: float = 10000, currency: str = 'EUR', max_products=1000, max_reactions=1000, debug=False, max_iter=None, shuffle=True, balance_clusters: bool = False, permitted_clusters: None | set = None)[source]
Parameters:
  • budget – float: (Default value = 10000)

  • currency – str: (Default value = ‘EUR’)

  • max_products – (Default value = 1000)

  • max_reactions – (Default value = 1000)

  • debug – (Default value = True)

  • max_iter – (Default value = None)

  • pick_inner_cheapest (#) – (Default value = True)

  • add_size (#) – (Default value = 1)

  • shuffle – (Default value = True)

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