Macro Library chemistry
A collection of chemistry routines
Version 0.3 October 19, 2021
chem_disp(compound)
formats a compound for display in as HTML
chem_mathdisp(compound)
formats a compound for better display in math mode
chem_eqndisp(reactants, products, coefficients, [arrow, phases])
Generates a display string for a chemical reaction.
- reactants: array of compounds
- products: array of compounds
- coefficients: array of coefficients for both reactants and products. The output of
chem_balancereaction can be used for this.
- arrow: optional, a string for the arrow in the reaction. Defaults to
->
- phases: optional, an array of phases for both reactants and products.
chem_isotopedisp(element,super,sub,[noitalic])
formats a math display string for an isotope with the given element,
superscript, and subscript. Set noitalic to true to un-italic element.
chem_getsymbol(atomic number)
returns the chemical symbol given the atomic number
chem_getnumber(symbol)
returns the atomic number given the chemical symbol
chem_getname(atomic number)
returns the chemical name given the atomic number
chem_getweight(atomic number)
returns the chemical standard atomic weight given the atomic number
chem_getmeltingpoint(atomic number)
returns the melting point given the atomic number
beware: some elements return weird non-numeric values
chem_getboilingpoint(atomic number)
returns the boiling point given the atomic number
beware: some elements return weird non-numeric values
chem_getfamily(atomic number)
returns the family given the atomic number
Values may be: "", "Noble gas", "Alkaline", "Alkaline Earth", "Halogen",
"Transition Metal", "Lanthanide", or "Actinide"
chem_randelementbyfamily(family)
returns the atomic number of a random element from a family
Valid families are: "Other", "Noble gas", "Alkaline", "Alkaline Earth",
"Halogen", "Transition Metal", "Lanthanide", or "Actinide"
chem_diffrandelementsbyfamily(family, n)
returns an array of n atomic numbers for random elements from a family
Valid families are: "Other", "Noble gas", "Alkaline", "Alkaline Earth",
"Halogen", "Transition Metal", "Lanthanide", or "Actinide"
chem_getrandcompound(type)
returns an array of (compound name, compound formula)
valid types are: twobasic, twosub, threeplus, parens
if type is not supplied, compound is chosen randomly from all
chem_getdiffrandcompounds(n,type)
returns an array n arrays of (compound name, compound formula)
valid types are: twobasic, twosub, threeplus, parens
if type is not supplied, compound is chosen randomly from all
chem_decomposecompound(compound)
breaks a compound into an array of elements and an array of atom counts
chem_getcompoundmolmass(compound, [round])
gets the molecular mass of the given compound
round: decimals to round the individual atoms' molecular mass to during calculuations
default: no additional rounding (4 decimal place accuracy)
special value: .5. Rounds all values to whole numbers, except Cl and Cu to nearest .5
chem_randcation([group,name type,include uncommon])
group name: simple, basic (simple + NH_4), polyvalent, or all. Default = all
name type: "common" (iron (II)) or "alternate" (ferrous) default = common
include uncommon: set true to include francium, radium, cadmium, etc.
returns array(symbol, charge, name)
chem_randanion([group,name type,include uncommon])
group name: simple, polyatomic, or all. Default = all
name type: "common" (bicarbonate) or "alternate" (hydrogen carbonate) default = common
include uncommon: set true to include selenide, peroxide
returns array(symbol, charge, name)
chem_makeioniccompound(cation, anion)
takes a cation and anion
these are the array returned by chem_randcation and chem_randanion
returns array(formula, name)
chem_getsolubility(cation, anion)
takes a cation array and anion array (from chem_randcation and chem_randanion)
and returns solubility information from https://en.wikipedia.org/wiki/Solubility_chart
Currently missing data for
Cations: Cd, Fr, Ra, Cr 2+, Mn 3+, Co 3+, Ni 3+, Cu 1+, Au 1+, Sn 4+, Pb 4+, Hg_2
Anions: N, P, C, Se, ClO, ClO_2, ClO_3, HCO_3, H_2PO_4, HSO_3, HSO_4, IO_3, MnO_4, NO_2, CrO_4, Cr_2O_7, HPO_4, SO_3, SiO_3, AsO_4, PO_3, O_2
returns array(stateName, abbreviation)
chem_balancereaction(reactants, products)
Balances a chemical reaction, returning an array of coefficients for the compounds
- reactants: array of compounds
- products: array of compounds