Sampling
Random recipe/selection generators
- 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
Scoring recipes
- class hippo.scoring.Scorer(db: Database, directory: Path | str, pattern: str = '*.json', attributes: list[str] = None, populate: bool = True, load_cache: bool = True, allowed_poses: PoseSet | list[int] | None = None, out_key: str = 'scorer')[source]
Create a scorer object to score sets of recipes
- Parameters:
db –
Databasedirectory – path to directory containing recipe JSONs
attributes – attributes of
Recipeobjects to use for scoringpopulate – Pre-populate query caches and child objects in memory (don’t disable unless you have a good reason)
load_cache – Load cache from existing JSON
allowed_pose_ids – Restrict interaction and subsite calculations to these
PoseIDs
Scorer initialisation
- add_custom_attribute(key: str, function: Callable, weight_reset_warning: bool = True) CustomAttribute[source]
Add a custom scoring attribute
- Parameters:
key – name/key for the attribute
function – function call to get the attribute alue, will be passed
Recipeobjectweight_reset_warning – write a warning to indicate weights have been reset
- add_recipes(json_paths: list, debug: bool = False) None[source]
Add more serialised
Recipeobjects to be scored- Parameters:
json_paths – list of JSON paths
debug – increase verbosity for debugging
- property attribute_keys: list[str]
Return list of
Attribute/CustomAttributenames/keys
- property attributes: list[Attribute | CustomAttribute]
Return list of
Attribute/CustomAttributeobjects
- compare(recipes: list[Recipe] | list[str]) None[source]
Compare attribute values and scores for recipes
- Parameters:
recipes – list of
Recipeobjects or hashes
- classmethod default(db: Database, directory: Path | str, pattern: str = '*.json', skip: list[str] | None = None, load_cache: bool = True, subsites: bool = True, allowed_poses: PoseSet | list[int] | None = None, out_key: str = 'scorer') Scorer[source]
Create a Scorer instance with Default attributes
- property json_path: Path
Path where cache will be written
- property num_attributes: int
Count of attributes
- property num_recipes: int
Number of recipes being evaluated
- plot(keys: list[str], budget: float | None = None) plotly.graph_objects.Figure[source]
Plot any two attributes as a scatter plot
- Parameters:
keys – list two attribute keys to plot
budget – limit
Recipeobjects to below this budget value
- Returns:
plotly Figure object containing a scatter trace
- property recipes: RecipeSet
Return
RecipeSetof recipes being scored
- score(recipe: Recipe, *, debug: bool = False) float[source]
Score a
Recipeobject- Parameters:
recipe –
Recipeto be scoreddebug – increase verbosity for debugging
- Returns:
float score from 0 to 1
- property score_dict: dict[str, float]
Dictionary of scores keyed by
Recipe.hash()
- top_keys(n: int, budget: float | None = None) list[str][source]
Return keys of top n scoring
Recipe
- property weights: list[float]
List of attribute weights
- class hippo.scoring.Attribute(scorer: Scorer, key: str, *, inverse: bool = False, weight: float = 1.0, bins: int = 100)[source]
Scoring Attribute to be used with a
Scorerobject- Parameters:
scorer – associated
Scorerkey – key/name for the attribute
inverse – if true, lower values score higher
weight – adjust scores by this weight
bins – number of scoring bins
Attribute initialisation
- property bins: int
Number of bins
- get_value(recipe: Recipe, serialise_price: bool = True, force: bool = False) float[source]
Get value for a
Recipe- Parameters:
serialise_price – serialise
Priceobjects to their amountforce – force calculation? (don’t use cache)
- property inverse: bool
Is this attribute inverted, lower values will score higher if true
- property key: str
Get name/key
- property max: float
Return maximum of values
- property mean: float
Return mean of value
- property min: float
Return minimum of values
- property percentile_interpolator
Interpolator function
- property std: float
Return standard deviation of values
- property values: list[float]
Return list of values
- property weight: float
Return weight