Macro Library chemistry

A collection of chemistry routines

Version 0.3 October 19, 2021

chem_disp

chem_disp(compound)
formats a compound for display in as HTML

chem_mathdisp

chem_mathdisp(compound)
formats a compound for better display in math mode

chem_eqndisp

chem_eqndisp(reactants, products, coefficients, [arrow, phases])

Generates a display string for a chemical reaction.


chem_isotopedisp

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

chem_getsymbol(atomic number)
returns the chemical symbol given the atomic number

chem_getnumber

chem_getnumber(symbol)
returns the atomic number given the chemical symbol

chem_getname

chem_getname(atomic number)
returns the chemical name given the atomic number

chem_getweight

chem_getweight(atomic number)
returns the chemical standard atomic weight given the atomic number

chem_getmeltingpoint

chem_getmeltingpoint(atomic number)
returns the melting point given the atomic number
beware: some elements return weird non-numeric values

chem_getboilingpoint

chem_getboilingpoint(atomic number)
returns the boiling point given the atomic number
beware: some elements return weird non-numeric values

chem_getfamily

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

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

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

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

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

chem_decomposecompound(compound)
breaks a compound into an array of elements and an array of atom counts

chem_getcompoundmolmass

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

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

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

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

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

chem_balancereaction(reactants, products)

Balances a chemical reaction, returning an array of coefficients for the compounds