Molecule¶
Represents a chemical molecule as a symbolic expression of atoms and bonds.
The canonical form is Molecule[{atoms…}, {bonds…}, {metadata…}]. An atom is a
bare element symbol, or Atom["El", "Prop" -> value, …] when it carries extra
properties. A molecule can be constructed from a chemical name (whose hydrogens
are materialized as explicit atoms):
… from a SMILES string (organic-subset hydrogens stay implicit):
… or from explicit atom and bond lists (also kept implicit):
Aromatic rings, formal charges, and isotopes are supported. A bracket-atom
hydrogen count rides along as a HydrogenCount property:
MoleculeQ¶
Tests whether an expression is a valid molecule:
AtomList and BondList¶
Return the atoms and bonds of a molecule:
$ wo 'BondList[Molecule["ammonia"]]'
{Bond[{1, 2}, Single], Bond[{1, 3}, Single], Bond[{1, 4}, Single]}
BondQ¶
BondQ[mol, bond] tests whether bond is a bond of mol. The atom pair is
unordered, and it indexes the same hydrogen-complete atom list AtomList
returns — so ethanol's implicit hydrogens (atoms 4 to 9) are addressable:
Omitting the bond type matches a bond of any type; giving one requires an exact match:
ConnectedMoleculeQ and ConnectedMoleculeComponents¶
ConnectedMoleculeQ[mol] tests whether the atoms of mol are all joined by
bonds. A . in a SMILES string separates fragments, so a salt is not
connected:
ConnectedMoleculeComponents[mol] returns each connected fragment as its own
molecule, with the bonds renumbered against the fragment's atoms:
$ wo 'ConnectedMoleculeComponents[Molecule["CC.O"]]'
{Molecule[{C, C}, {Bond[{1, 2}, Single]}, {}], Molecule[{O}, {}, {}]}
Both take any specification Molecule accepts, not just a molecule:
MoleculeValue¶
Computes properties of a molecule
("AtomCount", "BondCount", "AtomList", "BondList",
"MolecularFormula", and "NetCharge"). The molecular formula is returned as a
typeset Row of element symbols with the counts as subscripts:
$ wo 'MoleculeValue[Molecule["caffeine"], "MolecularFormula"]'
Subscript[C, 8]Subscript[H, 10]Subscript[N, 4]Subscript[O, 2]
Properties can also be accessed by applying the molecule to a property name:
Structure diagram¶
In visual hosts (the playground and Woxi Studio) a molecule displays as its 2-D
structure diagram. The same diagram is available anywhere via
ExportString[mol, "SVG"], a standalone SVG document (with an XML declaration):
It is a structure drawing, not a text summary, so it carries no Formula:
label:
MoleculePlot¶
MoleculePlot[mol] draws the full 2-D skeletal structure diagram as a
Graphics object. Atoms are laid out with a spring embedder; single, double,
triple, and aromatic bonds, heteroatom labels, formal charges, and isotope
mass numbers are all drawn. It accepts a molecule or any specification
Molecule itself accepts:
Bonds are drawn as vector polylines rather than <line> elements, matching the
markup wolframscript emits, so a benzene diagram contains no <line>: