Chemical Structure
A molecule's skeletal formula, drawn from a SMILES string as crisp SVG. It follows the theme, scales to its box, and colors heteroatoms the conventional way, or not at all.
Install
npx shadcn@latest add @nelumbo/chemical-structureUsage
import { ChemicalStructure } from "@/components/ui/chemical-structure"<ChemicalStructure smiles="CN1C=NC2=C1C(=O)N(C(=O)N2C)C" name="Caffeine" showFormula />Basic
Give it a SMILES string; name adds a caption and names the image for screen readers, and showFormula adds the molecular formula.
A small library
Neurotransmitters, sugars, antibiotics, energy carriers and a kinase inhibitor. Drawings lay themselves out; rings, charges and stereo come from the SMILES.
Adenosine receptor antagonist
Acetylates COX-1 and COX-2
Catecholamine neurotransmitter
5-HT, an indoleamine
Pyranose ring, all equatorial
β-lactam fused to a thiazolidine
Adenosine triphosphate
BCR-ABL kinase inhibitor
Element or mono
color "element" colors heteroatom labels the conventional way: nitrogen blue, oxygen red, sulfur amber. "mono" keeps the whole drawing in the text color, for print or when color means something else on the page.
Highlighted atoms
highlight takes atom-map numbers from the SMILES, the :1 in [NH:1], and draws a soft halo behind those atoms. Here, the amide nitrogen and carbonyl carbon of paracetamol, the bond that amidases cleave.
<ChemicalStructure smiles="C[C:2](=O)[NH:1]C1=CC=C(O)C=C1" highlight={[1, 2]} />Try it
The drawing updates as you type, and an invalid SMILES shows a short message instead of breaking the page.
Try your own SMILES. This one is (S)-ibuprofen, the active enantiomer; its stereocenter is drawn as a wedge.
Props
| Prop | Type | Default | Notes |
|---|---|---|---|
smiles | string | — | The molecule, as SMILES. |
name | string | — | Caption, and the accessible name. |
label | string | "Chemical structure" | Accessible name when there is no name. |
color | "element" | "mono" | "element" | Conventional heteroatom colors, or all text color. |
highlight | number[] | [] | Atom-map numbers to draw a halo behind. |
showFormula | boolean | false | Shows the molecular formula. |
explicitHydrogens | boolean | false | Draws every hydrogen. |
terminalCarbons | boolean | false | Labels terminal carbons (CH3) instead of leaving bare line ends. |
bondLength | number | 30 | Bond length in px at 1×; the drawing still scales to its box. |