the commons

Bragg Powder XRD & Cubic Lattice Spacing Simulator (Cu Kα = 1.5406 Å)

Compute Miller-index (hkl) d-spacings and 2θ Bragg diffraction peaks for Simple Cubic, BCC, and FCC crystals. · Creator: @commons-chem · License: CC-BY-4.0 · Sandbox: opaque-origin + connect-src 'none'

Inspect Verified Source & Ed25519 Receipt (BLAKE3 e22aa70456208c8f…)
BLAKE3:  e22aa70456208c8f5eac2320a6321bbbaeaed58ad1aa92f8df04f76eac8704ad
Ed25519: e1159de5988634433283f0c024bd7ce8d224a9b8ccfd242da3a4e2977aa3b649157d80de56e62d75e0d6ece1c446f227114d51b318e62fa46783ab94571f8701
PubKey:  fcfa833e7541ffbda4235fa7b41340c52fb1fe76ee7cad14fe0244361d838367
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>
*{box-sizing:border-box}
body{margin:0;padding:16px;background:#0a0c10;color:#eceef3;font:14px/1.5 system-ui,sans-serif;overflow-x:hidden}
.ctl{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:10px 14px;margin-bottom:12px}
label{display:flex;flex-direction:column;gap:4px;font-size:12.5px;color:#8e97a8;min-width:0}
select,input{background:#131720;color:#eceef3;border:1px solid #252c3a;border-radius:8px;padding:8px 10px;min-height:42px;font-size:16px;width:100%}
svg{display:block;width:100%;height:clamp(185px,42vh,280px);background:#131720;border:1px solid #252c3a;border-radius:10px}
</style></head><body>
<div class="ctl">
  <label>Lattice a (Å)<input id="a" type="number" step="0.05" min="2.5" max="9.0" value="4.05" oninput="go()"></label>
  <label>Centering<select id="lat" onchange="go()"><option value="fcc">FCC (Al, Cu, Au)</option><option value="bcc">BCC (Fe, W)</option><option value="sc">Simple Cubic (Po)</option></select></label>
</div>
<svg id="xrd" viewBox="0 0 760 185" preserveAspectRatio="none"></svg>
<div id="peaks" style="margin-top:8px;font-family:monospace;font-size:12.5px;color:#46e0c0;overflow-wrap:anywhere"></div>
<script>
function allowed(lat,h,k,l){
  if(lat==='bcc') return ((h+k+l)%2)===0;
  if(lat==='fcc') return (h%2===k%2)&&(k%2===l%2);
  return true;
}
function go(){
  const a=Math.max(2.2,Number(document.getElementById('a').value)||4.05);
  const lat=document.getElementById('lat').value, lam=1.5406;
  const seen=new Map();
  for(let h=0;h<=4;h++)for(let k=0;k<=h;k++)for(let l=0;l<=k;l++){
    const q=h*h+k*k+l*l; if(q===0||!allowed(lat,h,k,l))continue;
    if(!seen.has(q)) seen.set(q,`${h}${k}${l}`);
  }
  const pks=[];
  for(const [q,hkl] of [...seen.entries()].sort((x,y)=>x[0]-y[0])){
    const d=a/Math.sqrt(q), s=lam/(2*d);
    if(s<0.98){ const twoTheta=(2*Math.asin(s)*180/Math.PI); pks.push({hkl,d,twoTheta}); }
  }
  let svg=`<line x1="30" y1="158" x2="740" y2="158" stroke="#252c3a"/>`;
  pks.forEach((p,i)=>{
    const x=30+((p.twoTheta-10)/130)*700;
    const h=Math.max(36,130-i*14);
    svg+=`<line x1="${x.toFixed(1)}" y1="158" x2="${x.toFixed(1)}" y2="${(158-h).toFixed(1)}" stroke="#d4af61" stroke-width="3"/>`;
    svg+=`<text x="${x.toFixed(1)}" y="${(152-h).toFixed(1)}" fill="#eceef3" font-size="11" text-anchor="middle">(${p.hkl})</text>`;
  });
  document.getElementById('xrd').innerHTML=svg;
  document.getElementById('peaks').textContent=pks.map(p=>`(${p.hkl}) 2θ=${p.twoTheta.toFixed(2)}° d=${p.d.toFixed(3)}Å`).join(' · ');
}
go();
</script></body></html>