Compounds

Compound

class hippo.compound.Compound(animal: HIPPO, db: Database, id: int, inchikey: str, alias: str, smiles: str, mol: Mol | bytes | None = None, metadata: dict | None = None)[source]

A Compound represents a ligand/small molecule with stereochemistry removed and no atomic coordinates. I.e. it represents the chemical structure. It’s name is always an InChiKey. If a compound is an elaboration it can have a Compound.bases() property which is another Compound. Compound objects are target-agnostic and can be linked to any number of catalogue entries (Quote) or synthetic pathways (Reaction).

Attention

Compound objects should not be created directly. Instead use HIPPO.register_compound() or HIPPO.compounds(). See Getting started with HIPPO and Adding data into HIPPO.

self == other bool[source]

Compare compounds

repr(self) str[source]

ANSI Formatted string representation

str(self) str[source]

Unformatted string representation

add_base(base: Compound | int, commit: bool = True) None[source]

Add a base Compound this molecule is derived from.

Parameters:
  • base – The base Compound or its ID.

  • commit – Commit the changes to the Database, defaults to True

add_stock(amount: float, *, purity: float | None = None, entry: str | None = None, location: str | None = None, return_quote: bool = True) int | Quote[source]

Register a certain quantity of compound stock in the Database.

Parameters:
  • amount – Amount in mg

  • purity – Purity fraction 0 < purity <= 1, defaults to None

  • location – String describing where this stock is located, defaults to None

  • return_quote – If True a Quote object is returned instead of its ID, defaults to True

Returns:

The inserted Quote object or ID (see return_quote)

add_tag(tag: str) None[source]

Add this tag to every member of the set

property alias: str

Returns the compound’s alias

as_ingredient(amount: float, max_lead_time: float = None, supplier: str = None, get_quote: bool = True, quote_none: str = 'quiet') Ingredient[source]

Convert this compound into an Ingredient object with an associated amount (in mg) and Quote if available.

Parameters:
  • amount – Amount in mg

  • supplier – Only search for quotes with the given supplier, defaults to None

  • max_lead_time – Only search for quotes with lead times less than this (in days), defaults to None

property atomtype_dict: dict[str, int]

Get a dictionary with atomtypes as keys and corresponding quantities/counts as values.

property bases: CompoundSet | None

Returns the base compound for this elaboration

property best_placed_pose: Pose

Returns the compound’s pose with the lowest distance score

classify(draw: bool = True) list[tuple[str, int]][source]

Find RDKit Fragments within the compound molecule and draw them

Parameters:

draw – Draw the annotated molecule, defaults to True

Returns:

A list of tuples containing a descriptor (str) and count (int) pair

property db: Database

Returns a pointer to the parent database

property dict: dict

Returns a dictionary of this compound. See Compound.get_dict()

draw(align_substructure: bool = False) None[source]

Display this compound (and its base if it has one)

Attention

This method is only intended for use within a Jupyter Notebook.

Parameters:

align_substructure – Align the two drawing by their common substructure, defaults to False

property elabs

Returns the base compound for this elaboration

property formula: str

Get the chemical formula

get_base_ids() list[int][source]

Get a list of Compound ID’s that this object is a superstructure of

get_dict(*, mol: bool = True, alias: bool = True, inchikey: bool = True, metadata: bool = True, poses: bool = True, count_by_target: bool = False, num_reactant: bool = True, num_reactions: bool = True, bases: bool = True, elabs: bool = True, tags: bool = True) dict[source]

Returns a dictionary representing this Compound

Parameters:
  • mol – Include a rdkit.Chem.Mol object, defaults to True

  • metadata – Include metadata, defaults to True

  • poses – Include dictionaries of associated Pose objects, defaults to True

  • count_by_target – Include counts by protein Target, defaults to False. Only applicable when count_by_target = True.

  • num_reactant – include num_reactant column

  • num_reactions – include num_reactions column

  • bases – include bases column

  • elabs – include elabs column

  • tags – include tags column

Returns:

A dictionary

get_inspirations(debug: bool = True, none: str = 'warning') PoseSet[source]

Since inspirations map Pose objects to each other rather than Compound objects, this only works if there are poses registerd for this compound or it’s elaborations/superstructures.

Returns:

a PoseSet object

get_poses() PoseSet[source]

Get the associated Pose objects.

get_quotes(min_amount: float | None = None, supplier: str | None = None, max_lead_time: float | None = None, none: str = 'quiet', pick_cheapest: bool = False, df: bool = False) list[Quote][source]

Get all quotes associated to this compound

Parameters:
  • min_amount – Only return quotes with amounts greater than this, defaults to None

  • supplier – Only return quotes with the given supplier, defaults to None

  • max_lead_time – Only return quotes with lead times less than this (in days), defaults to None

  • none – Define the behaviour when no quotes are found. Choose error to raise print an error.

  • pick_cheapest – If True only the cheapest Quote is returned, defaults to False

  • df – Returns a DataFrame of the quoting data, defaults to False

Returns:

List of Quote objects, DataFrame, or single Quote. See pick_cheapest and df parameters

get_reactions(as_reactant: bool = False, permitted_reactions: ReactionSet = None, none: str = 'error') ReactionSet[source]

Get the associated Reaction objects. By default this function returns all reaction resulting in this Compound as a product, unless as_reactant is set to True.

Parameters:
  • as_reactant – Search for Reaction objects using this Compound as a reactant instead of a product, defaults to False

  • permitted_reactions – Provide a ReactionSet by which to filter the results

  • none – Define the behaviour when no quotes are found. Choose error to raise print an error, defaults to 'error'

get_recipes(*, amount: float = 1, debug: bool = False, pick_cheapest: bool = False, quoted_only: bool = False, supplier: None | str = None, **kwargs)[source]

Get Recipe objects that result in this compound. See Recipe.from_compounds()

get_superstructure_ids() list[int][source]

Get a list of Compound ID’s that this object is a substructure of

get_tags() TagSet[source]

Get the tags assigned to this compound

property id: int

Returns the compound’s database ID

property inchikey: str

Returns the compound’s InChiKey

property is_base: bool

Is this Compound the basis for any elaborations?

property is_elab: bool

Is this Compound the based on any other compound?

property is_product: bool

Is this Compound a product of at least one reaction

property metadata: MetaData

Returns the compound’s metadata dict

property mol: Mol

Returns the compound’s RDKit Molecule

property molecular_weight: float

Get the molecular weight

murcko_scaffold(generic: bool = False)[source]

Get the rdkit MurckoScaffold for this compound

property name: str

Returns the compound’s InChiKey

property num_atoms_added: int | list[int] | None

Calculate the number of atoms added relative to the base compound

property num_bases: int

Get the number of base compounds for this elaboration

property num_heavy_atoms: int

Get the number of heavy atoms

property num_poses: int

Returns the number of associated poses

property num_reactant: int

Returns the number of associated reactions (reactant)

property num_reactions: int

Returns the number of associated reactions (product)

property num_rings: int

Get the number of rings

place(*, reference: ~hippo.pose.Pose, inspirations: list[~hippo.pose.Pose] | None = None, max_ddG: float = 0.0, max_RMSD: float = 2.0, output_dir: str = 'wictor_place', tags: list[str] = None, metadata: <property object at 0x74862add0770> = None, overwrite: bool = False) Pose[source]

Generate a new pose for this compound using Fragmenstein.

Parameters:
  • reference – Choose the Pose to use as the reference protein conformation

  • inspirations – Choose the (virtual) hits to to define the ligand reference, defaults to the reference’s inspirations

  • max_ddG – Maximum ddG value permitted for a valid ligand conformation, defaults to 0.0

  • max_RMSD – Maximum RMSD value permitted for a valid ligand conformation, defaults to 2.0

  • output_dir – Output directory for Fragmenstein files, defaults to wictor_place

  • tags – Tags to assign to the created pose, defaults to []

  • metadata – A dictionary of metadata to assign to this compound, defaults to {}

  • overwrite – Delete old poses, defaults to False

property poses: PoseSet

Returns the compound’s poses

property reaction: Reaction

Returns the reaction resulting in this compound (will return first if multiple, with a warning)

property reactions: ReactionSet

Returns the reactions resulting in this compound

set_alias(alias: str, commit=True) None[source]

Set this Compound’s alias.

Parameters:
  • alias – The alias

  • commit – Commit the changes to the Database, defaults to True

property smiles: str

Returns the compound’s (flattened) smiles

summary(metadata: bool = True, draw: bool = True, tags: bool = True) None[source]

Print a summary of this compound

Parameters:
  • metadata – Include metadata, defaults to True

  • draw – Include a 2D molecule drawing, defaults to True

property table

Returns the name of the Database table

property tags: TagSet

Returns the compound’s tags

Ingredient

class hippo.compound.Ingredient(db, compound, amount, quote, max_lead_time=None, supplier=None)[source]

An ingredient is a Compound with a fixed quanitity and an attached quote.

Ingredient schema

Attention

Ingredient objects should not be created directly. Instead use Compound.as_ingredient().

self == other bool[source]

Equality operator

getattr(self, key: str)[source]

For missing attributes try getting from associated Compound

repr(self) str[source]

ANSI Formatted string representation

str(self) str[source]

Plain string representation

property amount: float

Returns the amount (in mg)

property compound: Compound

Returns the associated Compound

property compound_id: int

Returns the ID of the associated Compound

property compound_price_amount_str: str

String representation including Compound, Price, and amount.

property db: Database

Returns the parent Database

get_cheapest_quote_id(min_amount: float | None = None, supplier: str | None = None, max_lead_time: float | None = None, none: str = 'quiet') int | None[source]

Query quotes associated to this ingredient, and return the cheapest

Parameters:
  • min_amount – Only return quotes with amounts greater than this, defaults to None

  • supplier – Only return quotes with the given supplier, defaults to None

  • max_lead_time – Only return quotes with lead times less than this (in days), defaults to None

  • none – Define the behaviour when no quotes are found. Choose error to raise print an error.

get_quotes(**kwargs) list[Quote][source]

Wrapper for Compound.get_quotes()

property id: int

Returns the ID of the associated Compound

property lead_time: float | None

Returns the lead time (in days) of the associated Quote

property max_lead_time: float

Returns the max_lead_time (in days) from the original quote query

property price: Price | None

Returns the Price of the associated Quote

property quote: Quote

Returns the associated Quote

property quote_id: int

Returns the ID of the associated Quote

property smiles: str

Returns the SMILES of the associated Compound

property supplier: str

Returns the supplier from the original quote query

CompoundTable: All Compounds

class hippo.cset.CompoundTable(db: Database)[source]

Class representing all Compound objects in the ‘compound’ table of the Database.

Attention

CompoundTable objects should not be created directly. Instead use the HIPPO.compounds() property. See Getting started with HIPPO and Adding data into HIPPO.

Use as an iterable

Iterate through Compound objects in the table:

for compound in animal.compounds:
        ...

Selecting compounds in the table

The CompoundTable can be indexed with Compound IDs, names, aliases, or list/sets/tuples/slices thereof:

ctable = animal.compounds

# indexing individual compounds
comp = ctable[13]                            # using the ID
comp = ctable["BSYNRYMUTXBXSQ-UHFFFAOYSA-N"] # using the InChIKey
comp = ctable["aspirin"]                     # using the alias

# getting a subset of compounds
cset = ctable[13,15,18]      # using IDs (tuple)
cset = ctable[[13,15,18]]    # using IDs (list)
cset = ctable[set(13,15,18)] # using IDs (set)
cset = ctable[13:18]         # using a slice

Tags and base compounds can also be used to filter:

cset = animal.compounds(tag='hits') # select compounds tagged with 'hits'
cset = animal.compounds(base=comp)  # select elaborations of comp
self(*, tag: str = None, base: int | Compound = None, smiles: str | None = None, **kwargs) CompoundSet | Compound | None[source]

Filter compounds by a given tag, base, or it’s SMILES string. See CompoundTable.get_by_tag() and CompoundTable.get_by_base()

Parameters:
  • tag – optional tag to filter by

  • base – optional Compound ID or object to filter by

  • base – optional SMILES string to filter by

Returns:

CompoundSet if searching by tag or base, else Compound object

self[key: int | str | tuple | list | set | slice] Compound[source]

Get a member Pose object or subset PoseSet thereof.

Parameters:

key – Can be an integer ID, negative integer index, alias or inchikey string, list/set/tuple of IDs, or slice of IDs

iter(self)[source]

Iterate through all compounds

len(self) int[source]

Total number of compounds

repr(self) str[source]

ANSI ormatted string representation

str(self) str[source]

Unformatted string representation

property bases: CompoundSet

Returns a CompoundSet of all compounds that are the basis for a set of elaborations

property db: Database

Returns the associated Database

draw() None[source]

2D grid of drawings of molecules in this set

Attention

This method instantiates a CompoundSet containing all compounds, it is recommended to instead select a subset for display. This method is only intended for use within a Jupyter Notebook.

property elabs: CompoundSet

Returns a CompoundSet of all compounds that are a an elaboration of an existing base

get_by_base(base: Compound | int) CompoundSet[source]

Get all compounds that elaborate the given base compound

Parameters:

baseCompound object or ID to search by

get_by_metadata(key: str, value: str | None = None)[source]

Get all child compounds by their metadata. If no value is passed, then simply containing the key in the metadata dictionary is sufficient

Parameters:
  • key – metadata key

  • value – metadata value (Default value = None)

get_by_metadata_substring_match(substring: str) CompoundSet[source]

Get CompoundSet of poses with metadata JSON containing substring

get_by_smiles(smiles: str, **kwargs) Compound | None[source]

Get a member compound by its smiles

get_by_tag(tag: str, inverse: bool = False) CompoundSet[source]

Get all child compounds with a certain tag

Parameters:

tag – tag to filter by

property ids: list[int]

Returns the IDs of child compounds

property inchikeys: list[str]

Returns the inchikeys of all compounds

interactive() None[source]

Interactive widget to navigate compounds in the table

Attention

This method instantiates a CompoundSet containing all compounds, it is recommended to instead select a subset for display. This method is only intended for use within a Jupyter Notebook.

property intermediates: CompoundSet

Returns a CompoundSet of all compounds that are products and reactants

property names: list[str]

Returns the names of child compounds

property num_bases: int

Returns the number of compounds that are the basis for a set of elaborations

property num_elabs: int

Returns the number of compounds that are a an elaboration of an existing base

property num_intermediates: int

Returns the number of intermediates (see CompoundTable.intermediates())

property num_products: int

Returns the number of products (see CompoundTable.products())

property num_reactants: int

Returns the number of reactants (see CompoundTable.reactants())

plot_tsnee(**kwargs) go.Figure[source]

Plot a tanimoto similarity plot of these compounds

property products: CompoundSet

Returns a CompoundSet of all compounds that are a product of a reaction but not a reactant

property reactants: CompoundSet

Returns a CompoundSet of all compounds that are used as a reactants

property str_ids: str

Return an SQL formatted tuple string of the Compound IDs

summary() None[source]

Print a summary of this compound set

property table: str

Returns the name of the Database table

property tags: set[str]

Returns the set of unique tags present in this compound set

write_smiles_csv(file: str) None[source]

Write a CSV of the smiles contained in this set to a file

Parameters:

file – path of the CSV file

CompoundSet: Set of Compounds

class hippo.cset.CompoundSet(db: Database, indices: list = None, sort: bool = True, name: str | None = None)[source]

Object representing a subset of the ‘compound’ table in the Database.

Attention

CompoundSet objects should not be created directly. Instead use the HIPPO.compounds() property. See Getting started with HIPPO and Adding data into HIPPO.

Use as an iterable

Iterate through Compound objects in the set:

cset = animal.compounds[:100]

for compound in cset:
        ...

Check membership

To determine if a Compound is present in the set:

is_member = compound in cset

Selecting compounds in the set

The CompoundSet can be indexed like standard Python lists by their indices

cset = animal.compounds[1:100]

# indexing individual compounds
comp = cset[0]  # get the first compound
comp = cset[1]  # get the second compound
comp = cset[-1] # get the last compound

# getting a subset of compounds using a slice
cset2 = cset[13:18] # using a slice

Tags and base compounds can also be used to filter:

cset = animal.compounds(tag='hits') # select compounds tagged with 'hits'
cset = animal.compounds(base=comp)  # select elaborations of comp
self + other: Compound | CompoundSet | IngredientSet | int CompoundSet[source]

Add a Compound object or ID to this set, or add multiple at once when other is a CompoundSet or IngredientSet

other: Compound | Ingredient | int in self[source]

Check if compound or ingredient is a member of this set

self[key: int | slice] Compound | CompoundSet[source]

Get compounds or subsets thereof from this set

Parameters:

key – integer index or slice of indices

iter(self)[source]

Iterate through compounds in this set

len(self) int[source]

The number of compounds in this set

repr(self) str[source]

ANSI ormatted string representation

str(self) str[source]

Unformatted string representation

self - other: CompoundSet | IngredientSet CompoundSet[source]

Subtract a Compound object or ID to this set, or subtract multiple at once when other is a CompoundSet or IngredientSet

self ^ other: CompoundSet[source]

Exclusive OR set operation, returns all compounds in either set but not both

add(compound: Compound | int) None[source]

Add a compound to this set

Parameters:

compound – compound to be added

add_tag(tag: str) None[source]

Add this tag to every member of the set

as_ingredientset(amount: float | list[float] = 1, supplier: str | list | None = None) IngredientSet[source]

Get an IngredientSet for these compounds

property atomtype_dict: dict[str, int]

Get a dictionary with atomtypes as keys and corresponding quantities/counts as values

property avg_num_atoms_added: float

Calculate the average number of atoms added w.r.t the base

Returns:

average number of atoms added values for compounds which have a base

property bases: CompoundSet

Get the base compounds that have at least one elaboration in this set

Returns:

CompoundSet

property best_placed_poses: PoseSet

Get the best placed pose for each compound in this set

copy() CompoundSet[source]

Returns a copy of this set

count_by_tag(tag: str) CompoundSet[source]

Count all child compounds with a certain tag

Parameters:

tag – tag to filter by

draw() None[source]

Draw a grid of all contained molecules.

Attention

This method is only intended for use within a Jupyter Notebook.

property elab_df: pd.DataFrame

Get a DataFrame summarising the elaborations in this CompoundSet

property elaboration_balance: float

Measure of how evenly elaborations are distributed across bases in this set

property elabs: CompoundSet

Returns a CompoundSet of all compounds that are a an elaboration of an existing base

property formula: str

Get the combined chemical formula for all compounds

get_all_possible_reactants(debug: bool = False) CompoundSet[source]

Recursively searches for all the reactants that could possible be needed to synthesise these compounds.

Parameters:

debug – Increased verbosity for debugging (Default value = False)

get_all_possible_reactions(debug: bool = False) ReactionSet[source]

Recursively searches for all the reactants that could possible be needed to synthesise these compounds.

Parameters:

debug – Increased verbosity for debugging (Default value = False)

get_by_base(base: Compound | int, none: str = 'error') CompoundSet[source]

Get all compounds that elaborate the given base compound

Parameters:

baseCompound object or ID to search by

get_by_metadata(key: str, value: str | None = None) CompoundSet[source]

Get all child compounds with by their metadata. If no value is passed, then simply containing the key in the metadata dictionary is sufficient

Parameters:
  • key – metadata key

  • value – metadata value (Default value = None)

get_by_metadata_substring_match(substring: str) CompoundSet[source]

Get CompoundSet of poses with metadata JSON containing substring

get_by_tag(tag: str, inverse: bool = False) CompoundSet[source]

Get all child compounds with a certain tag

get_df(smiles: bool = True, inchikey: bool = False, alias: bool = True, mol: bool = False, metadata: bool = False, expand_metadata: bool = True, poses: bool = False, num_reactant: bool = False, num_reactions: bool = False, num_poses: bool = False, tags: bool = False, bases: bool = False, elabs: bool = False, routes: bool = False, debug: bool = False, **kwargs) DataFrame[source]

Get a DataFrame representation of this set

Parameters:
  • smiles – include SMILES column (Default value = True)

  • inchikey – include InChIKey column (Default value = False)

  • alias – include alias column (Default value = True)

  • mol – include rdkit.Chem.Mol in output (Default value = False)

  • metadata – include metadata in output (Default value = False)

  • expand_metadata – create separate column for each metadata key (Default value = True)

  • poses – include poses in output (Default value = False)

  • num_reactant – include num_poses column

  • num_reactant – include num_reactant column (number of reactions where compound is a reactant)

  • num_reactions – include num_reactions column (number of reactions where compound is a product)

  • tags – include tags column

  • bases – include bases column

  • elabs – include elabs column

# :param count_by_target: count poses by target (Default value = False)

get_dict() dict[source]

Get a dictionary object with all serialisable data needed to reconstruct this set

get_quoted(*, supplier: str = 'any') CompoundSet[source]

Get all member compounds that have a quote from given supplier

Parameters:

supplier – supplier name (Default value = ‘any’)

get_recipes(amount: float = 1, debug: bool = False, pick_cheapest: bool = False, permitted_reactions: ReactionSet | None = None, quoted_only: bool = False, supplier: None | str = None, **kwargs)[source]

Generate the Recipe to make these compounds.

See Recipe.from_compounds()

get_risk_diversity(debug: bool = False) float[source]

Calculate the average spread of risk (#atoms added) for each base in this set

Returns:

average of the standard deviations of number of atoms added for each base

get_routes(permitted_reactions: None | ReactionSet = None, debug: bool = True) RouteSet[source]

Get a RoutSet to products in this set.

Parameters:

permitted_reactions – optionally restrict reactions to those in this ReactionSet

get_unquoted(*, supplier: str = 'any') CompoundSet[source]

Get all member compounds that do not have a quote from given supplier

Parameters:

supplier – supplier name (Default value = ‘any’)

grid() None[source]

Draw a grid of all contained molecules.

Attention

This method is only intended for use within a Jupyter Notebook.

property id_num_poses_dict: dict[int, int]

Get a dictionary mapping compound ids to the number of poses

property ids: list[int]

Returns the ids of compounds in this set

property inchikeys: list[str]

Returns the inchikeys of compounds in this set

property indices: list[int]

Returns the ids of compounds in this set

interactive(function: Callable | None = None) None[source]

Creates a ipywidget to interactively navigate this PoseSet.

property mols: list[Chem.Mol]

Returns the molecules of child compounds

property name: str | None

Returns the name of set

property names: list[str]

Returns the aliases of compounds in this set

property num_atoms_added: list[int]

Calculate the number of atoms added w.r.t the base

Returns:

list of number of atoms added values

property num_bases_elaborated: int

Count the number of base compounds that have at least one elaboration in this set

Returns:

number of base compounds

property num_heavy_atoms: int

Get the total number of heavy atoms

property num_poses: int

Count the poses associated to this set of compounds

property num_rings

Get the total number of molecular rings

plot_tsnee(**kwargs) go.Figure[source]

Plot a tanimoto similarity plot of these compounds

pop() Compound[source]

Pop the last compound in this set

pop_id() int[source]

Pop the last compound id in this set

property poses: PoseSet

Get the poses associated to this set of compounds

property reaction_ids: list[int]

Returns a list of Reaction IDs that result in members of this set

property risk_diversity: float

Calculate the average spread of risk (#atoms added) for each base in this set

Returns:

average of the standard deviations of number of atoms added for each base

shuffle() None[source]

Randomises the order of compounds in this set

shuffled() CompoundSet[source]

Returns a randomised copy of this set

property smiles: list[str]

Returns the smiles of child compounds

property str_ids: str

Return an SQL formatted tuple string of the Compound IDs

summary() None[source]

Print a summary of this compound set

property table: str

Get the name of the database table

tag_summary() pd.DataFrame[source]

Print a summary table of tags with compound counts

property tags: set[str]

Returns the set of unique tags present in this compound set

write_CAR_csv(file: str | Path, amount: float = 1, return_df: bool = False, quoted_only: bool = False, get_ingredient_quotes: bool = True, **kwargs) DataFrame | None[source]

List of reactions for CAR

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 – output file

  • amount – amount of each product in mg

  • quoted_only – only choose reactants that have quotes

  • supplier – only choose reactants that have quotes from this supplier

  • kwargs – passed to Recipe.from_reaction()

  • return_df – return a DataFrame (Default value = False)

write_postera_csv(file, *, supplier: str = 'Enamine', prefix: str = 'fragment') None[source]

Write a CSV formatted for upload to Postera’s Manifold

Parameters:
  • file – path of the CSV file

  • supplier – supplier to use for quotes, (Default value = ‘Enamine’)

  • prefix – prefix to metadata columns, (Default value = ‘fragment’)

write_smiles_csv(file: str, tags: bool = True) None[source]

Write a CSV of the smiles contained in this set to a file

Parameters:

file – path of the CSV file

IngredientSet: Set of Ingredients

class hippo.cset.IngredientSet(db: Database, ingredients: None | list[Ingredient] = None, supplier: str | list | None = None, debug: bool = False)[source]

An Ingredient is a Compound with a fixed quanitity and an attached quote, the IngredientSet is a object representing multiple ingredients.

Attention

IngredientSet objects should not be created directly. Instead they are returned by several methods when working with Quoting and Random Recipe Generation.

Selecting ingredients in the set

The IngredientSet can be indexed like a Python list:

ingredient = ingredient_set[0] # first ingredient

To get the ingredient for a specific Compound ID:

ingredient = ingredient_set(compound_id=13)
self + other[source]

Add another IngredientSet this set

self(*, compound_id: int | None = None, tag: str | None = None) IngredientSet | Ingredient | CompoundSet[source]

Get members based on a compound_id or tag

other: Compound | Ingredient | int in self[source]

Check if compound or ingredient is a member of this set

getattr(self, key: str)[source]

For missing attributes try getting from associated CompoundSet

self[key: int] Ingredient[source]

Get a member by it’s index

iter(self)[source]

Iterate through the ingredients

len(self)[source]

The number of ingredients in this set

repr(self) str[source]

ANSI ormatted string representation

str(self) str[source]

Unformatted string representation

add(ingredient: Ingredient | None = None, *, compound_id: int | None = None, amount: float | None = None, quote_id: int | None = None, supplier: str | list[str] | None = None, max_lead_time: float | None = None, quoted_amount: float | None = None, debug: bool = False) None[source]

Add an Ingredient to this set

Parameters:
  • ingredientIngredient to be added, if None must specify other parameters, (Default value = None)

  • compound_idCompound ID (Default value = None)

  • amount – amount in mg (Default value = None)

  • quote_idQuote ID (Default value = None)

  • supplier – supplier name string or list (Default value = None)

  • max_lead_time – maximum lead-time for quoting (in days) (Default value = None)

  • quoted_amount – amount of associated Quote (Default value = None)

  • debug – increase verbosity for debugging (Default value = False)

property compound_ids: list[int]

Compound IDs for all ingredients

property compounds: CompoundSet

CompoundSet of all compounds in this set

copy() IngredientSet[source]

Return a copy of this IngredientSet

property db: Database

Linked HIPPO Database

property df: DataFrame

Access the raw DataFrame

draw() None[source]

Wrapper for CompoundSet.draw()

classmethod from_compounds(*, compounds: CompoundSet | None = None, ids: list[int] | None = None, db: Database | None = None, amount: float | list[float] = 1, supplier: str | list | None = None) IngredientSet[source]

Create an IngredientSet from a CompoundSet or IDs

Parameters:
  • compoundsCompoundSet to use, if None must provide ids and db (Default value = None)

  • ids – Compound IDs (Default value = None)

  • db – HIPPO Database (Default value = None)

  • amount – Amount(s) in mg (Default value = 1)

  • supplier – supplier to use for all quoting, (Default value = None)

classmethod from_ingredient_df(db: Database, df: DataFrame, supplier: str | list | None = None) IngredientSet[source]

Create an IngredientSet from a DataFrame

Parameters:
  • db – HIPPO Database

  • df – DataFrame of Ingredients

  • supplier – supplier to use for all quoting, (Default value = None)

classmethod from_ingredient_dicts(db: Database, dicts: list[dict], supplier: str | list | None = None) IngredientSet[source]

Create an IngredientSet from Ingredient dictionaries

Parameters:
  • db – HIPPO Database

  • dicts – List of individual ingredient dictionaries

  • supplier – supplier to use for all quoting, (Default value = None)

classmethod from_json(db: Database, path: None | str, supplier: str | list | None = None, data: None | dict = None) IngredientSet[source]

Create an IngredientSet from JSON data or a JSON file

Parameters:
  • db – HIPPO Database

  • path – path to JSON data (can be None if data provided)

  • supplier – supplier to use for all quoting, (Default value = None)

  • data – optional JSON data to parse, (Default value = None)

get_dict(data_orient: str = 'list') dict[source]

Get serialisable dictionary

Parameters:

data_orient – passed to pandas.DataFrame.to_dict (Default value = ‘list’)

get_price(supplier: str | list[str] = None, none: str = 'error', debug: bool = False) Price[source]

Calculate the price with a given supplier

Parameters:

supplier – supplier to use for all quoting, (Default value = None)

property id_amount_pairs: list[tuple]

Get a list of compound ID and amount pairs

property ids: list[int]

Compound IDs for all ingredients

property inchikeys: list[str]

InChI-keys for all ingredients

interactive(**kwargs) None[source]

Wrapper for CompoundSet.interactive()

pop() Ingredient[source]

Pop the last compound in this set

property price: Price

Total price of these ingredients

property price_df: DataFrame

DataFrame including prices

set_amounts(amount: float | list[float]) None[source]

Set the amount(s) for all ingredients in this set, and update quotes

Parameters:

amount – amount in mg

shuffle() None[source]

Randomises the order of compounds in this set

property smiles: list[str]

SMILES for all ingredients

property str_compound_ids: str

Return an SQL formatted tuple string of the Compound IDs

property supplier: str | list[str]

Supplier(s)