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_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)