// Main container for the widget.
atomStructureWidget = {
const widgetId = "atom-structure-widget-v2";
const container = html`<div id="${widgetId}"></div>`;
// --- 1. CSS STYLING ---
const style = html`<style>
/* ===== LIGHT MODE STYLES ===== */
#${widgetId} {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background-color: #ffffff;
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 1rem;
max-width: 700px;
margin: 1rem auto;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
#${widgetId} svg {
display: block;
width: 100%;
height: auto;
background-color: #ffffff;
cursor: pointer;
transition: opacity 0.2s ease;
}
#${widgetId} svg:hover {
opacity: 0.9;
}
#${widgetId} .scale-bar {
stroke: #343a40;
stroke-width: 2;
}
#${widgetId} .label {
font-size: 16px;
fill: #212529;
font-family: inherit;
pointer-events: none;
user-select: none;
}
#${widgetId} .inset-box {
fill: #f8f9fa;
stroke: #adb5bd;
stroke-width: 1.5;
}
#${widgetId} .magnify-lines {
stroke: #6c757d;
stroke-width: 0.75;
stroke-opacity: 0.8;
}
#${widgetId} .proton, #${widgetId} .neutron {
stroke-width: 1.5;
}
#${widgetId} .proton {
fill: #e63946;
stroke: #c22531;
}
#${widgetId} .neutron {
fill: #457b9d;
stroke: #335d7a;
}
/* Show light cloud, hide dark cloud in light mode */
#${widgetId} .electron-cloud-light {
display: block;
}
#${widgetId} .electron-cloud-dark {
display: none;
}
/* ===== DARK MODE STYLES ===== */
/* Container styling */
body.quarto-dark #${widgetId} {
background-color: #1a1b26;
border-color: #363849;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
body.quarto-dark #${widgetId} svg {
background-color: #1a1b26;
}
/* CRITICAL: Override global svg circle rule with higher specificity */
/* Global rule: body.quarto-dark svg circle (0,1,3) */
/* Our rule targets ONLY the central nucleus dot (r="2.0") */
/* Override ONLY for central nucleus dot - exclude electron clouds and particles */
body.quarto-dark #${widgetId} svg circle[r="2.0"] {
stroke: unset !important;
filter: unset !important;
}
/* Hide light cloud, show dark cloud in dark mode */
body.quarto-dark #${widgetId} .electron-cloud-light {
display: none !important;
}
body.quarto-dark #${widgetId} .electron-cloud-dark {
display: block !important;
}
/* Electron clouds: explicitly preserve their gradient fills and remove stroke */
body.quarto-dark #${widgetId} svg .electron-cloud-light {
fill: url(#electron-cloud-gradient-light) !important;
stroke: none !important;
}
body.quarto-dark #${widgetId} svg .electron-cloud-dark {
fill: url(#electron-cloud-gradient-dark) !important;
stroke: none !important;
}
/* Central nucleus dot: Enhanced red with glow */
body.quarto-dark #${widgetId} svg circle[r="2.0"] {
fill: #ff4757 !important;
stroke: none !important;
filter: drop-shadow(0 0 6px rgba(255, 71, 87, 0.9)) !important;
}
/* Protons: Override global rule, set red color, preserve blur filter */
body.quarto-dark #${widgetId} svg .proton {
fill: #ff4757 !important;
stroke: #ee2f3a !important;
stroke-width: 1.5 !important;
filter: url(#fuzzy-glow) !important;
}
/* Neutrons: Override global rule, set blue color, preserve blur filter */
body.quarto-dark #${widgetId} svg .neutron {
fill: #5f8dd3 !important;
stroke: #4a7cb8 !important;
stroke-width: 1.5 !important;
filter: url(#fuzzy-glow) !important;
}
/* Scale bars: Cyan with glow */
body.quarto-dark #${widgetId} .scale-bar {
stroke: #00d9ff !important;
filter: drop-shadow(0 0 2px rgba(0, 217, 255, 0.4));
}
/* Text labels: Light with cyan glow */
body.quarto-dark #${widgetId} .label {
fill: #e8ecf8 !important;
filter: drop-shadow(0 0 3px rgba(0, 217, 255, 0.3));
}
/* Inset box: Dark background with cyan border and glow */
body.quarto-dark #${widgetId} .inset-box {
fill: #24273a !important;
stroke: #00d9ff !important;
filter: drop-shadow(0 0 4px rgba(0, 217, 255, 0.2));
}
/* Magnifying lines: Cyan with glow */
body.quarto-dark #${widgetId} .magnify-lines {
stroke: #00d9ff !important;
stroke-opacity: 0.6 !important;
filter: drop-shadow(0 0 2px rgba(0, 217, 255, 0.3));
}
</style>`;
// --- 2. SVG AND D3 SETUP ---
const width = 700;
const height = 600;
const svg = d3.create("svg")
.attr("viewBox", `0 0 ${width} ${height}`)
.attr("aria-labelledby", "atom-title")
.attr("aria-describedby", "atom-desc")
.html(`<title id="atom-title">Diagram of an Atom</title>
<desc id="atom-desc">A diagram showing a central nucleus surrounded by a diffuse electron cloud. An inset box shows a magnified view of the nucleus containing protons and neutrons.</desc>`);
const defs = svg.append("defs");
// --- 3. CREATE GRADIENTS AND FILTERS ---
// Light mode gradient: Black for fuzzy black cloud (smoother with more stops)
const cloudGradientLight = defs.append("radialGradient")
.attr("id", "electron-cloud-gradient-light");
cloudGradientLight.append("stop").attr("offset", "0%").attr("stop-color", "#000000").attr("stop-opacity", 0.65);
cloudGradientLight.append("stop").attr("offset", "10%").attr("stop-color", "#000000").attr("stop-opacity", 0.5);
cloudGradientLight.append("stop").attr("offset", "25%").attr("stop-color", "#000000").attr("stop-opacity", 0.3);
cloudGradientLight.append("stop").attr("offset", "40%").attr("stop-color", "#000000").attr("stop-opacity", 0.1);
cloudGradientLight.append("stop").attr("offset", "50%").attr("stop-color", "#000000").attr("stop-opacity", 0.0);
// Dark mode gradient: Cyan for fuzzy cyan cloud (smoother with more stops)
const cloudGradientDark = defs.append("radialGradient")
.attr("id", "electron-cloud-gradient-dark");
cloudGradientDark.append("stop").attr("offset", "0%").attr("stop-color", "#00d9ff").attr("stop-opacity", 0.55);
cloudGradientDark.append("stop").attr("offset", "10%").attr("stop-color", "#00d9ff").attr("stop-opacity", 0.45);
cloudGradientDark.append("stop").attr("offset", "25%").attr("stop-color", "#00d9ff").attr("stop-opacity", 0.28);
cloudGradientDark.append("stop").attr("offset", "40%").attr("stop-color", "#00d9ff").attr("stop-opacity", 0.1);
cloudGradientDark.append("stop").attr("offset", "50%").attr("stop-color", "#00d9ff").attr("stop-opacity", 0.0);
// Gaussian blur filter for the fuzzy glow of protons/neutrons
const glowFilter = defs.append("filter")
.attr("id", "fuzzy-glow")
.attr("x", "-50%").attr("y", "-50%")
.attr("width", "200%").attr("height", "200%");
glowFilter.append("feGaussianBlur")
.attr("in", "SourceGraphic")
.attr("stdDeviation", 8);
// --- 4. DRAW THE MAIN ATOM ---
const atomCenterX = width / 2;
const atomCenterY = height / 2 + 50;
const atomRadius = 450;
// Electron cloud - LIGHT MODE (black gradient)
svg.append("circle")
.attr("cx", atomCenterX)
.attr("cy", atomCenterY)
.attr("r", atomRadius)
.attr("class", "electron-cloud-light")
.style("fill", "url(#electron-cloud-gradient-light)");
// Electron cloud - DARK MODE (cyan gradient)
svg.append("circle")
.attr("cx", atomCenterX)
.attr("cy", atomCenterY)
.attr("r", atomRadius)
.attr("class", "electron-cloud-dark")
.style("fill", "url(#electron-cloud-gradient-dark)");
// Central nucleus dot
svg.append("circle")
.attr("cx", atomCenterX)
.attr("cy", atomCenterY)
.attr("r", 2.0)
.style("fill", "#e63946");
// Atom scale bar (200 pm)
const atomScaleBar = { x1: atomCenterX - 210, x2: atomCenterX + 210, y: height - 25 };
svg.append("line")
.attr("x1", atomScaleBar.x1).attr("y1", atomScaleBar.y)
.attr("x2", atomScaleBar.x2).attr("y2", atomScaleBar.y)
.attr("class", "scale-bar");
svg.append("text").text("200 pm")
.attr("x", atomCenterX).attr("y", atomScaleBar.y + 20)
.attr("text-anchor", "middle").attr("class", "label");
// --- 5. DRAW THE MAGNIFYING LINES (DRAWN FIRST, SO THEY ARE IN THE BACK) ---
const inset = { x: width - 260, y: 40, width: 220, height: 200 };
const linesGroup = svg.append("g").attr("class", "magnify-lines");
linesGroup.append("line").attr("x1", atomCenterX).attr("y1", atomCenterY).attr("x2", inset.x).attr("y2", inset.y);
linesGroup.append("line").attr("x1", atomCenterX).attr("y1", atomCenterY).attr("x2", inset.x + inset.width).attr("y2", inset.y);
linesGroup.append("line").attr("x1", atomCenterX).attr("y1", atomCenterY).attr("x2", inset.x).attr("y2", inset.y + inset.height);
linesGroup.append("line").attr("x1", atomCenterX).attr("y1", atomCenterY).attr("x2", inset.x + inset.width).attr("y2", inset.y + inset.height);
// --- 6. DRAW THE INSET NUCLEUS VIEW (DRAWN LAST, SO IT IS ON TOP) ---
const insetGroup = svg.append("g")
.attr("transform", `translate(${inset.x}, ${inset.y})`);
// Inset background and border
insetGroup.append("rect")
.attr("width", inset.width).attr("height", inset.height)
.attr("rx", 5).attr("class", "inset-box");
const insetCenter = { x: inset.width / 2, y: inset.height / 2 - 10 };
const particleRadius = 25;
const particleOffset = particleRadius * 0.9;
const particles = [
{ type: 'proton', cx: insetCenter.x - particleOffset, cy: insetCenter.y - particleOffset },
{ type: 'neutron', cx: insetCenter.x + particleOffset, cy: insetCenter.y - particleOffset },
{ type: 'neutron', cx: insetCenter.x - particleOffset, cy: insetCenter.y + particleOffset },
{ type: 'proton', cx: insetCenter.x + particleOffset, cy: insetCenter.y + particleOffset }
];
particles.forEach(p => {
insetGroup.append("circle").attr("cx", p.cx).attr("cy", p.cy).attr("r", particleRadius).attr("class", p.type).style("filter", "url(#fuzzy-glow)");
insetGroup.append("circle").attr("cx", p.cx).attr("cy", p.cy).attr("r", particleRadius * 0.7).attr("class", p.type);
});
// Inset scale bar (2 fm)
const insetScaleBar = { x1: inset.width/2 - 50, x2: inset.width/2 + 50, y: inset.height - 40 }; // Moved line up
insetGroup.append("line").attr("x1", insetScaleBar.x1).attr("y1", insetScaleBar.y).attr("x2", insetScaleBar.x2).attr("y2", insetScaleBar.y).attr("class", "scale-bar");
insetGroup.append("text").text("2 fm").attr("x", inset.width/2).attr("y", insetScaleBar.y + 20).attr("text-anchor", "middle").attr("class", "label"); // MODIFICATION: Moved text below line
// --- 7. ASSEMBLE THE WIDGET ---
container.append(style);
const svgNode = svg.node();
container.append(svgNode);
// --- 8. ADD CLICK HANDLER FOR OPENING IN NEW TAB ---
svgNode.addEventListener("click", function() {
// Serialize a CLONE that carries an inline fallback size. An SVG with only a viewBox
// and no width/height has no intrinsic size, so if the document's <style> fails to
// apply, WebKit falls back to the 300x150 default replaced-element size in the
// top-left corner. An inline style survives that; and because every rule in the
// stylesheet below is !important, this loses to them whenever the stylesheet does
// apply, so it changes nothing in the working case.
const svgClone = this.cloneNode(true);
svgClone.setAttribute("style",
`width:100%;height:auto;display:block;aspect-ratio:${width} / ${height}`);
const svgString = svgClone.outerHTML;
// Detect current theme
const isDarkMode = document.body.classList.contains('quarto-dark');
// Theme-specific CSS for the new window
const themeCSS = isDarkMode ? `
/* Dark mode SVG styling */
.electron-cloud-light {
display: none;
}
.electron-cloud-dark {
display: block;
}
svg circle[r="2.0"] {
fill: #ff4757;
filter: drop-shadow(0 0 6px rgba(255, 71, 87, 0.9));
}
svg .proton {
fill: #ff4757;
stroke: #ee2f3a;
}
svg .neutron {
fill: #5f8dd3;
stroke: #4a7cb8;
}
svg .scale-bar {
stroke: #00d9ff;
filter: drop-shadow(0 0 2px rgba(0, 217, 255, 0.4));
}
svg .label {
fill: #e8ecf8;
filter: drop-shadow(0 0 3px rgba(0, 217, 255, 0.3));
}
svg .inset-box {
fill: #24273a;
stroke: #00d9ff;
filter: drop-shadow(0 0 4px rgba(0, 217, 255, 0.2));
}
svg .magnify-lines {
stroke: #00d9ff;
stroke-opacity: 0.6;
filter: drop-shadow(0 0 2px rgba(0, 217, 255, 0.3));
}
` : `
/* Light mode SVG styling */
.electron-cloud-light {
display: block;
}
.electron-cloud-dark {
display: none;
}
svg .scale-bar {
stroke: #343a40;
stroke-width: 2;
}
svg .label {
font-size: 16px;
fill: #212529;
font-family: inherit;
}
svg .inset-box {
fill: #f8f9fa;
stroke: #adb5bd;
stroke-width: 1.5;
}
svg .magnify-lines {
stroke: #6c757d;
stroke-width: 0.75;
stroke-opacity: 0.8;
}
svg .proton {
fill: #e63946;
stroke: #c22531;
stroke-width: 1.5;
}
svg .neutron {
fill: #457b9d;
stroke: #335d7a;
stroke-width: 1.5;
}
`;
// Open a REAL document rather than document.write()-ing into an already-created
// about:blank. WebKit applies neither a <style> nor a <meta name="viewport"> that
// arrives that way, so on iOS the drawing lost its stylesheet entirely. Every other
// SVG on the site opens assets/svg-viewer.html, an ordinary page over http, which is
// why this widget was the only one affected. A blob: URL is likewise parsed as an
// ordinary same-origin document, head and all.
const viewerDoc = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Helium Atom Structure</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
body {
background: ${isDarkMode ? '#1a1b26' : '#ffffff'};
display: flex;
justify-content: center;
align-items: center;
padding: 1rem;
}
svg {
display: block;
max-width: 100%;
max-height: 100%;
}
/* Desktop: 100% height with max-width 100% */
@media (min-width: 768px) {
svg {
height: calc(100vh - 2rem) !important;
width: auto !important;
}
}
/* Mobile: full viewport width, height from the viewBox ratio.
The SVG carries only a viewBox (no width/height attributes), so
"height: auto" alone can resolve to the default replaced-element
height on mobile Safari instead of the aspect ratio. aspect-ratio
states it explicitly. The two max-* clamps and the html overflow
from the base rules must also be released or they cap the width. */
@media (max-width: 767px) {
html, body {
height: auto;
overflow: visible;
}
body {
align-items: flex-start;
padding: 1rem;
}
svg {
width: calc(100vw - 2rem) !important;
height: auto !important;
max-width: none !important;
max-height: none !important;
aspect-ratio: ${width} / ${height};
}
}
${themeCSS}
</style>
</head>
<body>${svgString}</body>
</html>
`;
const blobUrl = URL.createObjectURL(new Blob([viewerDoc], { type: "text/html" }));
window.open(blobUrl, "_blank");
// Revoking immediately can race the new tab's load, so give it a generous window.
setTimeout(() => URL.revokeObjectURL(blobUrl), 60000);
});
return container;
}The Atom: The Building Blocks of Matter
How the atomic model evolved from Dalton’s hard spheres to a nucleus of protons and neutrons surrounded by electrons. Includes subatomic particle properties.
Chemistry seeks to answer a basic question: what is matter made of? For millennia, philosophers argued that matter could be endlessly divided. But in the early 1800s, scientific evidence began to support a different theory: that all matter is composed of discrete building blocks. These are the atoms.
This chapter explores the atom. We will start with our modern understanding of its structure, then trace the experimental work that led us there.
From Philosophy to Science: The Atomic Model
The Ancient Idea of the Atom
The concept of the atom is over two thousand years old. Around 400 BC, the Greek philosopher Democritus proposed that if you were to cut a piece of matter in half again and again, you would eventually reach a point where it could not be cut any further. He called these ultimate, indivisible particles atomos, a Greek word meaning “uncuttable.”
For over two millennia, this idea remained a philosophical curiosity. Democritus and his followers had no way to test it. Their concept of the atom was based on logic and reason, not experimental evidence. The idea that matter was composed of indivisible particles would persist until science developed the tools to look closer.
Dalton’s Foundational Theory
The scientific journey began in the early 1800s with English schoolteacher John Dalton. In his influential 1808 book, A New System of Chemical Philosophy, he transformed the ancient idea of atoms into a scientific theory based on experimental observations. His theory had several key points:
John Dalton: English chemist, physicist, and meteorologist (1766–1844) (Source: Wikipedia)
- All matter is made of tiny, indivisible particles called atoms.
- Atoms of a given element are identical in mass and properties.
- Atoms of different elements have different masses and properties.
- Atoms combine in simple, whole number ratios to form compounds.
Dalton’s theory explained many chemical observations. However, as we now know, some of his initial postulates were incorrect. We know atoms are divisible into smaller particles, and we know from isotopes that atoms of a given element are not all identical in mass. Science refines its models over time, and Dalton’s theory was the first step in building the modern picture.
Over the next century, a series of experiments would reveal that atoms are not indivisible spheres but complex structures with internal components.
The Modern View of the Atom
Our current model of the atom, refined over a century of discovery, is composed of three types of subatomic particles:
- Protons are particles that carry a positive (1+) electrical charge.
- Neutrons are neutral particles, carrying no electrical charge.
- Electrons are particles that carry a negative (1−) electrical charge.
Each of these particles was identified through a different line of experiments, traced in The Electron and The Nucleus; how the electrons are arranged around the nucleus is the subject of Electron Configurations.
Electrical charge is a property of matter. Like charges repel each other, while opposite charges attract.
The protons and neutrons are packed together in the atom’s dense, central core, known as the nucleus. The electrons are not part of the nucleus. Instead, they exist in a probabilistic distribution of space surrounding the nucleus, visualized as the electron cloud. Unlike a planet orbiting the sun, an electron has no fixed path; the cloud shows where it is likely to be found, not a route it follows. It is the attraction between the positively charged protons in the nucleus and the negatively charged electrons surrounding it that holds the atom together. In a neutral atom, the number of electrons is exactly equal to the number of protons. The positive and negative charges cancel, giving an overall charge of zero. An atom that gains or loses electrons carries a net charge and is called an ion.
The diagram below illustrates the structure of the helium atom. The nucleus contains two protons (red) and two neutrons (blue) surrounded by a diffuse electron cloud (black). The nucleus has a diameter roughly 10 000 to 100 000 times smaller than the overall atom (depending on the element) and occupies roughly 10−12 to 10−15 of the atom’s total volume (roughly the cube of the diameter ratio, since volume scales as length3).
A Closer Look at Subatomic Particles
The mass of a single atom is tiny, on the order of 10−27 kg. To avoid working with such unwieldy numbers, chemists use a more convenient unit called the dalton (Da), also known as the unified atomic mass unit (u). These two names are used interchangeably. One dalton is defined as exactly one-twelfth the mass of an unbound carbon-12 atom at rest in its electronic ground state. Its value in SI kilograms is determined experimentally (see Isotopes for the CODATA value). In the table below, the proton and neutron have masses very close to 1 Da.
NoteThe dalton and the 2019 SI Redefinition
The dalton (1 Da = 1 u) is defined as exactly one-twelfth the mass of a carbon-12 atom. This definition is exact. The value of the dalton in kilograms, however, is determined experimentally. Since the 2019 SI redefinition fixed the Avogadro constant to an exact value, the dalton-to-kilogram conversion is no longer exact by definition. The current CODATA 2022 value is
\[1~\mathrm{Da} \approx 1.660\,539\,068\,92(52) \times 10^{-27}~\mathrm{kg}\]
where the digits in parentheses indicate experimental uncertainty in the last two places. See Isotopes for the full atomic-mass framework and The Mole for how this affects the connection between atomic and molar masses.
The charge of a proton and electron are equal in magnitude but opposite in sign. Their relative charge of 1+ and 1− is a convenient simplification we will use frequently.
ImportantA Note on the ‘amu’
While this text uses the modern unified atomic mass unit (u), or dalton (Da), you will frequently encounter the term atomic mass unit (amu) in other chemistry resources.
The ‘amu’ is a legacy term from an older, slightly different standard. The modern, internationally accepted unit (the dalton) is based on the mass of a carbon-12 atom. For the purposes of this book, the numerical difference is negligible, and you can consider them effectively equivalent:
\[1~\mathrm{amu} \approx 1~\mathrm{u} = 1~\mathrm{Da}\]
This text will use the modern “u” or “dalton” (Da), but recognize the term “amu” when you see it. Read From amu to u: The Story of the Atomic Mass Unit to find out the historical context for this change and to understand the subtle difference.
While Dalton’s model provided a framework, it treated atoms as simple, solid spheres. The true nature of the atom, however, would be revealed by experiments exploring the relationship between matter and a force that was still mysterious in its own right: electricity.