API

PubChem.get_compoundFunction
get_compound(name::AbstractString | cid::Integer)

Retrieve PubChem's JSON compound record by name or compound identifier.

Arguments

  • name::AbstractString: A PubChem-recognized compound name, such as "water".
  • cid::Integer: A PubChem Compound Identifier (CID), such as 962 for water.

Returns

  • A JSON object represented by Julia dictionaries and vectors.

Throws

  • KeyError: The PubChem endpoint responds with HTTP 404 for name or cid.
  • Downloads.RequestError: The request cannot be completed for another HTTP or network reason.

Examples

water = get_compound(962)
properties = extract_properties(water)
properties["Molecular_formula"] # "H2O"
source
PubChem.extract_propertiesFunction
extract_properties(data)

Extract PubChem compound properties from the JSON object returned by get_compound.

Arguments

  • data: A compound record returned by get_compound, with the PubChem PUG JSON layout.

Returns

  • A Dict whose available keys are "IUPAC_Name_Preferred", "IUPAC_Name_Traditional", "Molecular_weight", "Molecular_formula", "Molecular_mass", "Smiles", and "Charge". PubChem omits some properties for some compounds, so all keys except "Charge" are conditional on the response.

Examples

properties = extract_properties(get_compound("water"))
properties["IUPAC_Name_Preferred"] # "oxidane"
source
PubChem.@attach_metadataMacro
@attach_metadata species [name_or_cid]

Fetch chemical properties from PubChem and attach them as ModelingToolkit metadata to species.

Arguments

  • species: A ModelingToolkit or Catalyst symbolic species variable.
  • name_or_cid: Optional AbstractString, Symbol, or integer CID identifying the compound. When omitted, the species name is used as the PubChem query.

Returns

  • The macro expands to an assignment that replaces species with a metadata-annotated symbolic variable. The attached properties can be read with chemical_properties.

Examples

@variables t
@species H2(t)
@attach_metadata H2
chemical_properties(H2)["Molecular_formula"] # "H2"
source
PubChem.molar_ratioFunction
molar_ratio(reaction::Reaction, species1, species2)

Return the stoichiometric ratio of species1 to species2 in reaction.

Arguments

  • reaction::Reaction: A Catalyst reaction containing both species.
  • species1: The numerator species.
  • species2: The denominator species.

Returns

  • A Rational equal to the stoichiometric coefficient of species1 divided by that of species2.

Throws

  • ErrorException: Either species is not a substrate or product of reaction.

Examples

molar_ratio(reaction, Al, Cl2) # 2//3 for 2Al + 3Cl2 -> 2AlCl3
source
PubChem.moles_by_massFunction
moles_by_mass(species, mass)

Calculate the amount of species from a supplied mass.

Arguments

  • species: A metadata-annotated symbolic species, compound name, or PubChem CID accepted by molecular_weight.
  • mass: Mass in grams.

Returns

  • mass / molecular_weight(species) in moles.

Examples

@variables t
@species MnO2(t)
@attach_metadata MnO2

moles_by_mass(MnO2, 95)
source
PubChem.moles_by_volumeFunction
moles_by_volume(molarity, volume)

Calculate the number of moles in a solution from molarity and volume.

Arguments

  • molarity: Amount concentration in mol/L.
  • volume: Solution volume in L.

Returns

  • The product molarity * volume, preserving the arithmetic type selected by the input values.

Examples

moles_by_volume(0.400, 0.300) == 0.120
source
PubChem.limiting_reagentFunction
limiting_reagent(reaction::Reaction, masses::AbstractVector)

Find the substrate with the fewest available moles in a reaction.

Arguments

  • reaction::Reaction: A balanced Catalyst reaction.
  • masses::AbstractVector: Substrate masses in grams, in the same order as reaction.substrates.

Returns

A tuple (limiting_species, moles), where moles is the available amount of that species.

Throws

  • ArgumentError: masses does not support fast scalar indexing. GPU arrays are not supported because the calculation scans values on the host.

Examples

limiting_reagent(reaction, [2.8, 4.15]) # (Cl2, 0.0585...)
source
PubChem.theoretical_yieldFunction
theoretical_yield(reaction::Reaction, masses::AbstractVector, product::Num)

Calculate the theoretical mass yield of a product from substrate masses.

Arguments

  • reaction::Reaction: A balanced Catalyst reaction.
  • masses::AbstractVector: Substrate masses in grams, ordered as reaction.substrates.
  • product::Num: A product symbolic species in reaction.

Returns

The theoretical product mass in grams.

Throws

  • ArgumentError: masses does not support fast scalar indexing.
  • ErrorException: product is not in reaction.

Examples

theoretical_yield(reaction, [2.8, 4.15], AlCl3) # 5.2032...
source
PubChem.chemical_propertiesFunction
chemical_properties(species)

Return PubChem chemical properties for a symbolic species or a PubChem query.

Arguments

  • species: A metadata-annotated Catalyst or ModelingToolkit symbolic species, an AbstractString compound name, or an integer PubChem CID.

Returns

  • A Dict of the properties returned by extract_properties. Symbolic species are read from their attached metadata; names and CIDs are retrieved from PubChem.

Examples

chemical_properties("water")["Molecular_formula"] # "H2O"
source
PubChem.molecular_weightFunction
molecular_weight(species)

Return the molecular weight of species in g/mol.

Arguments

Returns

  • The "Molecular_weight" property from PubChem.

Throws

  • ErrorException: The available properties do not contain a molecular weight.

Examples

molecular_weight("water") # 18.015
source
PubChem.molecular_formulaFunction
molecular_formula(species)

Return the molecular formula of species.

Arguments

Returns

  • The "Molecular_formula" property from PubChem.

Throws

  • ErrorException: The available properties do not contain a molecular formula.
source
PubChem.molecular_massFunction
molecular_mass(species)

Return the molecular mass of species in unified atomic mass units.

Arguments

Returns

  • The "Molecular_mass" property from PubChem.

Throws

  • ErrorException: The available properties do not contain a molecular mass.
source
PubChem.IUPAC_Name_PreferredFunction
IUPAC_Name_Preferred(species)

Return the preferred IUPAC name of species.

Arguments

Returns

  • The "IUPAC_Name_Preferred" property from PubChem.

Throws

  • ErrorException: The available properties do not contain a preferred IUPAC name.
source
PubChem.IUPAC_Name_TraditionalFunction
IUPAC_Name_Traditional(species)

Return the traditional IUPAC name of species.

Arguments

Returns

  • The "IUPAC_Name_Traditional" property from PubChem.

Throws

  • ErrorException: The available properties do not contain a traditional IUPAC name.
source
PubChem.smilesFunction
smiles(species)

Return the SMILES representation of species.

Arguments

Returns

  • The "Smiles" property from PubChem.

Throws

  • ErrorException: The available properties do not contain a SMILES string.
source
PubChem.chargeFunction
charge(species)

Return the formal charge of species.

Arguments

Returns

  • The "Charge" property from PubChem.

Throws

  • ErrorException: The available properties do not contain a charge.
source