API
PubChem.get_compound — Function
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 as962for water.
Returns
- A JSON object represented by Julia dictionaries and vectors.
Throws
KeyError: The PubChem endpoint responds with HTTP 404 fornameorcid.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"PubChem.extract_properties — Function
extract_properties(data)Extract PubChem compound properties from the JSON object returned by get_compound.
Arguments
data: A compound record returned byget_compound, with the PubChem PUG JSON layout.
Returns
- A
Dictwhose 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"PubChem.@attach_metadata — Macro
@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: OptionalAbstractString,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
specieswith a metadata-annotated symbolic variable. The attached properties can be read withchemical_properties.
Examples
@variables t
@species H2(t)
@attach_metadata H2
chemical_properties(H2)["Molecular_formula"] # "H2"PubChem.molar_ratio — Function
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
Rationalequal to the stoichiometric coefficient ofspecies1divided by that ofspecies2.
Throws
ErrorException: Either species is not a substrate or product ofreaction.
Examples
molar_ratio(reaction, Al, Cl2) # 2//3 for 2Al + 3Cl2 -> 2AlCl3PubChem.moles_by_mass — Function
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 bymolecular_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)PubChem.moles_by_volume — Function
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.120PubChem.limiting_reagent — Function
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 asreaction.substrates.
Returns
A tuple (limiting_species, moles), where moles is the available amount of that species.
Throws
ArgumentError:massesdoes 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...)PubChem.theoretical_yield — Function
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 asreaction.substrates.product::Num: A product symbolic species inreaction.
Returns
The theoretical product mass in grams.
Throws
ArgumentError:massesdoes not support fast scalar indexing.ErrorException:productis not inreaction.
Examples
theoretical_yield(reaction, [2.8, 4.15], AlCl3) # 5.2032...PubChem.chemical_properties — Function
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, anAbstractStringcompound name, or an integer PubChem CID.
Returns
- A
Dictof the properties returned byextract_properties. Symbolic species are read from their attached metadata; names and CIDs are retrieved from PubChem.
Examples
chemical_properties("water")["Molecular_formula"] # "H2O"PubChem.molecular_weight — Function
molecular_weight(species)Return the molecular weight of species in g/mol.
Arguments
species: Any value accepted bychemical_properties.
Returns
- The
"Molecular_weight"property from PubChem.
Throws
ErrorException: The available properties do not contain a molecular weight.
Examples
molecular_weight("water") # 18.015PubChem.molecular_formula — Function
molecular_formula(species)Return the molecular formula of species.
Arguments
species: Any value accepted bychemical_properties.
Returns
- The
"Molecular_formula"property from PubChem.
Throws
ErrorException: The available properties do not contain a molecular formula.
PubChem.molecular_mass — Function
molecular_mass(species)Return the molecular mass of species in unified atomic mass units.
Arguments
species: Any value accepted bychemical_properties.
Returns
- The
"Molecular_mass"property from PubChem.
Throws
ErrorException: The available properties do not contain a molecular mass.
PubChem.IUPAC_Name_Preferred — Function
IUPAC_Name_Preferred(species)Return the preferred IUPAC name of species.
Arguments
species: Any value accepted bychemical_properties.
Returns
- The
"IUPAC_Name_Preferred"property from PubChem.
Throws
ErrorException: The available properties do not contain a preferred IUPAC name.
PubChem.IUPAC_Name_Traditional — Function
IUPAC_Name_Traditional(species)Return the traditional IUPAC name of species.
Arguments
species: Any value accepted bychemical_properties.
Returns
- The
"IUPAC_Name_Traditional"property from PubChem.
Throws
ErrorException: The available properties do not contain a traditional IUPAC name.
PubChem.smiles — Function
smiles(species)Return the SMILES representation of species.
Arguments
species: Any value accepted bychemical_properties.
Returns
- The
"Smiles"property from PubChem.
Throws
ErrorException: The available properties do not contain a SMILES string.
PubChem.charge — Function
charge(species)Return the formal charge of species.
Arguments
species: Any value accepted bychemical_properties.
Returns
- The
"Charge"property from PubChem.
Throws
ErrorException: The available properties do not contain a charge.