Guides / Identifiers and formats

molecular-formulaisomersexact-massrdkit

Molecular formula versus structure, what each can tell you

A molecular formula counts atoms and fixes mass. A structure fixes connectivity and shape, and so properties. Caffeine shows how far a formula gets you.

Updated 5 min read

A molecular formula counts the atoms of each element in a molecule and therefore fixes its molecular weight and exact mass. A structure fixes how those atoms are connected and arranged in space, and it is the connectivity and arrangement, not the counts, that decide solubility, potency, metabolism and everything else you compute. Caffeine's formula C8H10N4O2 tells you its mass and that it has six rings and double bonds in total. It cannot tell you which of the many compounds with that formula you are holding.

What a formula fixes

A formula is written in the Hill system, carbon first, hydrogen second, then the other elements in alphabetical order. Caffeine is C8H10N4O2, aspirin C9H8O4, ibuprofen C13H18O2 and paracetamol C8H9NO2. From the counts you get the molecular weight by summing average atomic masses, and the exact mass by summing the masses of the most abundant isotopes.

You also get the degree of unsaturation, the number of rings plus double bonds, from a textbook relation. For a compound of carbon, hydrogen, nitrogen, oxygen and halogens, it equals the carbon count, minus half the hydrogen and halogen count, plus half the nitrogen count, plus one. For caffeine that is 8 minus 5 plus 2 plus 1, which is 6. Caffeine has two rings, two carbonyls, one carbon-nitrogen double bond and one carbon-carbon double bond, six in total. That check is useful when a formula arrives from a mass spectrum and you want to know whether a proposed structure can be right.

A formula also tells you immediately whether a record is a salt or a hydrate, because a chlorine with no obvious place, a sodium or a calcium, or extra H2O appears in the counts. The guide on salts and parent compounds covers how to deal with that.

What a formula cannot fix

Isomers share a formula and share nothing else that matters. Ethanol and dimethyl ether are both C2H6O. One is a liquid you can drink and the other is a gas. Paracetamol and methyl anthranilate are both C8H9NO2. One is an analgesic and the other is a fragrance ingredient. For a drug-sized formula such as C13H18O2, the number of chemically sensible structures is very large, and the number of plausible drug-like ones is still large.

Within a single connectivity, stereoisomers share a formula as well. Both enantiomers of ibuprofen are C13H18O2, and so is the racemate. Hydrogen-bond donors and acceptors, polar surface area, logP and every rule-of-five quantity depend on which atoms are bonded to which, so none of them can be computed from a formula alone. The guide on hydrogen-bond donors and acceptors shows how much the count depends on connectivity rather than on element totals.

A formula is a sum. A structure is a sentence.

Average mass, exact mass and what a mass spectrometer sees

Molecular weight, in the everyday sense, is the average mass over natural isotope abundance. Carbon counts as 12.011 because about one atom in a hundred is carbon-13. Exact or monoisotopic mass uses the most abundant isotope of each element, with carbon at exactly 12.000. For caffeine the average molecular weight is about 194.19 and the monoisotopic mass about 194.080. The difference grows with the number of carbons and is why a high-resolution mass spectrum can narrow a peak to a handful of formulae.

A mass spectrum therefore gives you a formula, or a short list of formulae, and never a structure. Fragmentation patterns, chromatographic retention and ultimately NMR or a crystal structure settle the connectivity. When a paper reports an exact mass as evidence of identity, it is evidence of formula, which is a necessary but not sufficient condition.

Computing both in RDKit

RDKit derives the formula and both masses from the structure, which is the only direction the derivation can go.

from rdkit import Chem
from rdkit.Chem import Descriptors, rdMolDescriptors

caffeine = Chem.MolFromSmiles("Cn1cnc2c1c(=O)n(C)c(=O)n2C")
print(rdMolDescriptors.CalcMolFormula(caffeine))    # C8H10N4O2
print(round(Descriptors.MolWt(caffeine), 2))        # 194.19
print(round(Descriptors.ExactMolWt(caffeine), 4))   # 194.0804

ethanol = Chem.MolFromSmiles("CCO")
ether = Chem.MolFromSmiles("COC")
same_formula = rdMolDescriptors.CalcMolFormula(ethanol) == rdMolDescriptors.CalcMolFormula(ether)
same_structure = Chem.MolToSmiles(ethanol) == Chem.MolToSmiles(ether)
print(same_formula, same_structure)   # True False

The last line is the whole article in miniature. Same formula, different structure, and only the structure comparison tells them apart.

Use the formula as a check and the structure as the identity

The formula earns its place as a cheap consistency test at every hand-off. When you resolve a name to a database record, compare the formula you expected with the formula of the structure that came back. A mismatch flags a salt, a hydrate, a different tautomer drawn with a different hydrogen count, or simply the wrong compound. The guide on PubChem CIDs versus names builds that check into a short resolution routine. When you read an SDF, compare the formula computed from the structure block with the formula in the data fields, because depositors sometimes update one and not the other.

For identity, use the structure, carried as a canonical SMILES or an InChIKey. Molecule Analysis shows the formula, the molecular weight and the structure together as soon as a compound resolves, so the check takes a glance. The guide on molecular weight and heavy-atom count explains what the mass is good for once you trust it.

Key points

Questions people ask

Can two different molecules have the same molecular formula?
Yes, and most formulae of drug size belong to very many structures. Ethanol and dimethyl ether are both C2H6O, and paracetamol and methyl anthranilate are both C8H9NO2. Only the structure distinguishes them.
What is the difference between molecular weight and exact mass?
Molecular weight averages over natural isotope abundance, with carbon at 12.011. Exact or monoisotopic mass uses the most abundant isotope of each element, with carbon at exactly 12.000. For caffeine they are about 194.19 and 194.080.
Can I get a structure from a molecular formula?
No. A formula gives the atom counts and the number of rings plus double bonds, which constrains the candidates but does not pick one. Mass spectrometry gives formulae, and connectivity needs NMR, a crystal structure or a reference compound.
How does RDKit compute a molecular formula?
Pass a molecule to rdMolDescriptors.CalcMolFormula, which counts atoms including implicit hydrogens and writes the result in Hill order. Descriptors.MolWt and Descriptors.ExactMolWt give the average and monoisotopic masses from the same structure.

Further reading

In practice: The ADMET dashboard resolves a name, a PubChem CID or a SMILES to one compound and shows the identifiers side by side, so a mismatch is visible before anything is computed.

← All guides