Teaching Tools

Chemical Integrated Rate Laws :root{ –bg:#0d1117;–surface:#161b22;–surface2:#21262d;–border:#30363d; –accent:#58a6ff;–accent2:#3fb950;–accent3:#f78166;–accent4:#d2a8ff; –text:#e6edf3;–text2:#8b949e;–text3:#6e7681; –amber:#e3b341;–radius:8px;–radius-lg:12px; } *{box-sizing:border-box;margin:0;padding:0;} body{font-family:’Courier New’,Consolas,monospace;background:var(–bg);color:var(–text);min-height:100vh;font-size:14px;} header{background:var(–surface);border-bottom:1px solid var(–border);padding:0 1.5rem;display:flex;align-items:center;gap:1rem;height:52px;position:sticky;top:0;z-index:100;} .logo{display:flex;align-items:center;gap:9px;} .logo-icon{width:28px;height:28px;background:linear-gradient(135deg,#58a6ff,#3fb950);border-radius:6px;display:flex;align-items:center;justify-content:center;font-size:15px;} .logo-text{font-size:14px;font-weight:700;letter-spacing:.06em;} .logo-text span{color:var(–accent);} .tab-bar{display:flex;gap:2px;margin-left:auto;} .tab-btn{background:transparent;border:none;color:var(–text2);padding:5px 16px;border-radius:var(–radius);cursor:pointer;font-family:inherit;font-size:12px;letter-spacing:.03em;transition:all .15s;} .tab-btn:hover{background:var(–surface2);color:var(–text);} .tab-btn.active{background:var(–surface2);color:var(–accent);border:1px solid var(–border);} .app{display:flex;height:calc(100vh – 52px);overflow:hidden;} .tab-panel{display:none;flex:1;min-width:0;overflow:hidden;} .tab-panel.active{display:flex;} .sidebar{width:295px;min-width:295px;height:100%;background:var(–surface);border-right:1px solid var(–border);overflow-y:auto;padding:16px 14px;display:flex;flex-direction:column;gap:11px;flex-shrink:0;} .sidebar::-webkit-scrollbar{width:4px;} .sidebar::-webkit-scrollbar-thumb{background:var(–border);border-radius:2px;} .main{flex:1;min-width:0;height:100%;overflow-y:auto;overflow-x:hidden;padding:16px 16px 48px 16px;display:flex;flex-direction:column;gap:14px;background:var(–bg);} .main::-webkit-scrollbar{width:6px;} .main::-webkit-scrollbar-thumb{background:var(–border);border-radius:3px;} .field-group{display:flex;flex-direction:column;gap:4px;} label{font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(–text2);font-weight:600;} input[type=text],input[type=number],select{background:var(–surface2);border:1px solid var(–border);color:var(–text);padding:6px 9px;border-radius:var(–radius);font-family:inherit;font-size:12px;width:100%;transition:border-color .15s;outline:none;} input:focus,select:focus{border-color:var(–accent);} .radio-group{display:flex;gap:10px;flex-wrap:wrap;} .radio-label{display:flex;align-items:center;gap:5px;font-size:12px;color:var(–text2);cursor:pointer;text-transform:none;letter-spacing:0;font-weight:400;} .radio-label input[type=radio]{accent-color:var(–accent);width:13px;height:13px;} .section-title{font-size:9px;text-transform:uppercase;letter-spacing:.12em;color:var(–text3);border-top:1px solid var(–border);padding-top:9px;margin-top:2px;} .reactant-card{background:var(–surface2);border:1px solid var(–border);border-radius:var(–radius);padding:9px 10px 8px;} .reactant-card.b-card{border-color:var(–accent);} .reactant-card.i-card{border-color:var(–accent4);} .reactant-label{font-size:9px;color:var(–text3);text-transform:uppercase;letter-spacing:.1em;margin-bottom:7px;} .reactant-card.b-card .reactant-label{color:var(–accent);} .reactant-card.i-card .reactant-label{color:var(–accent4);} .btn{padding:8px 14px;border-radius:var(–radius);border:none;font-family:inherit;font-size:12px;font-weight:700;cursor:pointer;transition:all .15s;letter-spacing:.03em;width:100%;} .btn-primary{background:var(–accent);color:#0d1117;} .btn-primary:hover{opacity:.88;transform:translateY(-1px);} .btn-secondary{background:var(–surface2);color:var(–text2);border:1px solid var(–border);} .btn-secondary:hover{border-color:var(–accent2);color:var(–accent2);} /* TOGGLE */ .toggle-row{display:flex;align-items:center;justify-content:space-between;background:var(–surface2);border:1px solid var(–border);border-radius:var(–radius);padding:8px 11px;} .toggle-label-text{font-size:11px;color:var(–text2);} .toggle{position:relative;display:inline-block;width:36px;height:20px;flex-shrink:0;} .toggle input{opacity:0;width:0;height:0;} .slider{position:absolute;cursor:pointer;inset:0;background:var(–border);border-radius:20px;transition:.2s;} .slider:before{content:”;position:absolute;width:14px;height:14px;left:3px;bottom:3px;background:#fff;border-radius:50%;transition:.2s;} input:checked+.slider{background:var(–accent);} input:checked+.slider:before{transform:translateX(16px);} /* HALF LIFE */ .halflife-box{background:var(–surface2);border:1px solid var(–amber);border-radius:var(–radius);padding:8px 11px;display:none;} .halflife-box .hl-label{font-size:9px;color:var(–text3);text-transform:uppercase;letter-spacing:.07em;margin-bottom:3px;} .halflife-box .hl-value{font-size:15px;font-weight:700;color:var(–amber);} /* CHARTS */ .charts-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px;} @media(max-width:860px){.charts-grid{grid-template-columns:1fr;}} .chart-card{background:var(–surface);border:1px solid var(–border);border-radius:var(–radius-lg);padding:14px;} .chart-card h3{font-size:11px;text-transform:uppercase;letter-spacing:.1em;color:var(–text2);margin-bottom:10px;display:flex;align-items:center;gap:6px;flex-wrap:wrap;} .chart-wrap{position:relative;height:220px;} .chart-empty{display:flex;align-items:center;justify-content:center;height:100%;color:var(–text3);font-size:11px;border:1px dashed var(–border);border-radius:var(–radius);} /* TABLE */ .table-card{background:var(–surface);border:1px solid var(–border);border-radius:var(–radius-lg);overflow:visible;padding-bottom:16px;} .table-header{display:flex;align-items:center;justify-content:space-between;padding:10px 14px;border-bottom:1px solid var(–border);} .table-header h3{font-size:11px;text-transform:uppercase;letter-spacing:.1em;color:var(–text2);} .table-wrap{overflow-x:auto;} table{width:100%;border-collapse:collapse;font-size:12px;} thead th{background:var(–surface2);color:var(–text2);padding:7px 12px;text-align:center;font-size:10px;text-transform:uppercase;letter-spacing:.06em;border-bottom:1px solid var(–border);position:sticky;top:0;white-space:nowrap;} tbody tr{border-bottom:1px solid var(–border);transition:background .1s;} tbody tr:hover{background:var(–surface2);} tbody td{padding:6px 12px;text-align:center;color:var(–text);font-family:’Courier New’,monospace;font-size:12px;} tbody tr:last-child{border-bottom:none;} .empty-row td{color:var(–text3);font-style:italic;font-size:11px;} /* ARRHENIUS RESULTS */ .result-box{background:var(–surface2);border:1px solid var(–border);border-radius:var(–radius);padding:8px 11px;font-size:12px;color:var(–accent2);font-family:’Courier New’,monospace;display:none;} .result-box.show{display:block;} /* EXPORT MODAL */ .modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.65);z-index:200;display:flex;align-items:center;justify-content:center;} .modal{background:var(–surface);border:1px solid var(–border);border-radius:var(–radius-lg);padding:22px 24px;width:340px;display:flex;flex-direction:column;gap:14px;} .modal h2{font-size:13px;font-weight:700;color:var(–text);letter-spacing:.06em;} .modal-section{display:flex;flex-direction:column;gap:8px;} .modal-label{font-size:10px;text-transform:uppercase;letter-spacing:.08em;color:var(–text2);font-weight:600;} .format-row{display:flex;gap:8px;} .format-btn{flex:1;padding:8px;border-radius:var(–radius);border:1px solid var(–border);background:var(–surface2);color:var(–text2);font-family:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:all .15s;text-align:center;} .format-btn.selected{border-color:var(–accent);color:var(–accent);background:var(–accent)1a;} .check-label{display:flex;align-items:center;gap:8px;font-size:12px;color:var(–text2);cursor:pointer;} .check-label input[type=checkbox]{accent-color:var(–accent);width:14px;height:14px;} .modal-actions{display:flex;gap:8px;margin-top:4px;} .modal-actions button{flex:1;} .hidden{display:none!important;} /* SPLASH OVERLAY */ #splash-overlay{ position:fixed;inset:0;z-index:9999; display:flex;align-items:center;justify-content:center; background:linear-gradient(135deg,#0d1117 60%,#0a1f2e 100%); opacity:1;pointer-events:all; transition:opacity 0.55s ease; } .splash-inner{text-align:center;animation:splashIn 0.5s ease both;} @keyframes splashIn{ from{opacity:0;transform:scale(.88) translateY(14px);} to{opacity:1;transform:scale(1) translateY(0);} } .splash-logo-img{ height:90px; object-fit:contain; display:block; margin:0 auto 18px; filter:drop-shadow(0 0 18px rgba(255,120,30,0.55)); animation:pulse 1.1s ease infinite alternate; } @keyframes pulse{ from{filter:drop-shadow(0 0 10px rgba(255,120,30,0.3));} to{filter:drop-shadow(0 0 32px rgba(255,120,30,0.85));} } .splash-title span{color:#58a6ff;} .splash-subtitle{ font-size:11px;letter-spacing:.18em;color:#8b949e; text-transform:uppercase;margin-top:6px;font-family:’Courier New’,monospace; } .splash-bar{ width:120px;height:3px;background:var(–border); border-radius:2px;margin:18px auto 0;overflow:hidden; } .splash-bar-fill{ height:100%;width:0;background:linear-gradient(90deg,#58a6ff,#3fb950); border-radius:2px;animation:load 0.9s ease forwards; } @keyframes load{from{width:0;}to{width:100%;}}
GRU LAB
Chemical Kinetics Simulator

Concentration vs Time

Run simulation to see chart

Reaction Rate vs Time

Run simulation to see chart

📋 Data Table

Run simulation to populate table
No data yet

Arrhenius Plot Data Fit

Run calculation to see chart

k vs Temperature

Run calculation to see chart

📋 Arrhenius Data Table

T (K)1/T (K⁻¹)kln(k)
No data yet — click Calculate

v vs [S] — Michaelis-Menten

Click Calculate to see chart

Lineweaver-Burk (1/v vs 1/[S])

Click Calculate to see chart

📋 Enzyme Kinetics Data Table

Click Calculate to populate table
No data yet
// ─── INITIAL SPLASH ────────────────────────────────────────────── window.addEventListener(‘load’, ()=>showSplash()); // ─── STATE ──────────────────────────────────────────────────────── const CH={}; let simData_=null, arrData_=null, enzData_=null, enzDepData_=null; let exportTarget=’sim’, exportFmt=’csv’; const PAL=[‘#58a6ff’,’#3fb950′,’#f78166′,’#d2a8ff’,’#e3b341′,’#06b6d4′,’#fb923c’,’#f472b6′,’#a3e635′]; // ─── SPLASH ─────────────────────────────────────────────────────── function showSplash(cb){ const ov=document.getElementById(‘splash-overlay’); ov.style.opacity=’1′; ov.style.pointerEvents=’all’; setTimeout(()=>{ ov.style.opacity=’0′; ov.style.pointerEvents=’none’; if(cb) cb(); },1100); } // ─── TAB ────────────────────────────────────────────────────────── function switchTab(name,btn){ showSplash(()=>{ document.querySelectorAll(‘.tab-panel’).forEach(p=>p.classList.remove(‘active’)); document.querySelectorAll(‘.tab-btn’).forEach(b=>b.classList.remove(‘active’)); document.getElementById(‘tab-‘+name).classList.add(‘active’); btn.classList.add(‘active’); }); } // ─── VISIBLE CHARTS ─────────────────────────────────────────────── // Returns only canvases that are rendered and fully visible (not hidden by parent) function getVisibleCharts(target){ const allIds={ sim: [‘chart-conc’,’chart-rate’,’chart-ssa-conc’,’chart-ssa-rate’], arr: [‘chart-arrhenius’,’chart-k-T’], enz: [‘chart-enz-mm’,’chart-enz-lb’,’chart-enz-hanes’,’chart-enz-eadie’], }; const ids = allIds[target] || []; return ids.map(id=>{ const c = document.getElementById(id); if(!c) return null; if(c.style.display === ‘none’ || c.style.display === ”) return null; let el = c.parentElement; while(el && el !== document.body){ if(el.classList.contains(‘hidden’)) return null; el = el.parentElement; } if(!CH[id]) return null; const label = id.replace(‘chart-‘,”).replace(/-/g,’ ‘) .replace(/\b\w/g,l=>l.toUpperCase()); return {id, label, src: c.toDataURL(‘image/png’)}; }).filter(Boolean); } // ─── CALCULATE K ───────────────────────────────────────────────── function onCalcKReactionChange(){ // Show/hide extra input blocks based on order const order = document.getElementById(‘reaction-order’).value; setV(‘ck-B0-block’, order === ‘second-ab’); setV(‘ck-consec-block’, order === ‘consec’); setV(‘ck-nth-block’, order === ‘nth’); } function onSimModeChange(){ const calcMode = document.querySelector(‘input[name=”sim-mode”]:checked’).value === ‘calc-k’; setV(‘calc-k-block’, calcMode); if(!calcMode){ document.getElementById(‘calc-k-result’).style.display=’none’; } } function calculateK(){ const order = document.getElementById(‘reaction-order’).value; const A0 = parseFloat(document.getElementById(‘ck-A0’).value); const At = parseFloat(document.getElementById(‘ck-At’).value); const t = parseFloat(document.getElementById(‘ck-t’).value); const tunit = document.querySelector(‘input[name=”ck-tunit”]:checked’).value; const phase = document.querySelector(‘input[name=”phase”]:checked’).value; const cu = phase === ‘liquid’ ? ‘mol/L’ : ‘mol/m³’; if(A0 0′); if(At 0′); if(At >= A0) return alert(‘[A]_t must be less than [A]₀’); if(t 0′); let lines = [], units = [], kVal = null, k2Val = null; // ── ZEROTH ORDER ───────────────────────────────────────────────── if(order === ‘zeroth’){ const k = (A0 – At) / t; kVal = k; units = [`${cu}/${tunit}`]; lines = [ `k = ([A]₀ − [A]_t) / t`, ` = (${A0.toFixed(4)} − ${At.toFixed(4)}) / ${t}`, ` = ${k.toFixed(6)} ${units[0]}` ]; } // ── FIRST ORDER ────────────────────────────────────────────────── else if(order === ‘first’){ const k = Math.log(A0 / At) / t; kVal = k; units = [`${tunit}⁻¹`]; lines = [ `k = ln([A]₀ / [A]_t) / t`, ` = ln(${A0.toFixed(4)} / ${At.toFixed(4)}) / ${t}`, ` = ${k.toFixed(6)} ${units[0]}` ]; } // ── SECOND ORDER A→P ───────────────────────────────────────────── else if(order === ‘second-a’){ const k = (1/At – 1/A0) / t; kVal = k; units = [`${cu}⁻¹·${tunit}⁻¹`]; lines = [ `k = (1/[A]_t − 1/[A]₀) / t`, ` = (1/${At.toFixed(4)} − 1/${A0.toFixed(4)}) / ${t}`, ` = ${k.toFixed(6)} ${units[0]}` ]; } // ── SECOND ORDER A+B→P ───────────────────────────────────────── else if(order === ‘second-ab’){ const B0 = parseFloat(document.getElementById(‘ck-B0′).value); if(isNaN(B0)||B0 0’); if(Math.abs(A0 – B0) < 1e-8){ // Special case [A]₀=[B]₀: same as second-order A→P const k = (1/At – 1/A0) / t; kVal = k; units = [`${cu}⁻¹·${tunit}⁻¹`]; lines = [ `[A]₀ = [B]₀: uses second-order A→P law`, `k = (1/[A]_t − 1/[A]₀) / t`, ` = (1/${At.toFixed(4)} − 1/${A0.toFixed(4)}) / ${t}`, ` = ${k.toFixed(6)} ${units[0]}` ]; } else { // General case: k appears in exponential — solve numerically via Newton-Raphson // [P] = [A]₀-[A]_t; [A]_t = [A]₀ – [P] // From: [A](t) = ([A]₀([A]₀-[B]₀)) / ([A]₀ – [B]₀·e^(([B]₀-[A]₀)kt)) // Rearranging: solve f(k) = A0 – B0*exp((B0-A0)*k*t) – (A0*(A0-B0))/At = 0 const denom_target = A0 * (A0 – B0) / At; // = A0 – B0*exp(…) // So: B0*exp((B0-A0)*k*t) = A0 – denom_target const rhs = A0 – denom_target; if(rhs <= 0) return alert('No valid k found — check input values.'); const k = Math.log(rhs / B0) / ((B0 – A0) * t); kVal = k; units = [`${cu}⁻¹·${tunit}⁻¹`]; lines = [ `[A]₀ ≠ [B]₀: solved from integrated law`, `[A](t) = [A]₀([A]₀−[B]₀) / ([A]₀ − [B]₀·e^{([B]₀−[A]₀)kt})`, `k = ln(([A]₀−[A]₀([A]₀−[B]₀)/[A]_t) / [B]₀)`, ` / (([B]₀−[A]₀)·t)`, ` = ${k.toFixed(6)} ${units[0]}` ]; } } // ── CONSECUTIVE A+B→I→P ────────────────────────────────────────── else if(order === 'consec'){ const It = parseFloat(document.getElementById('ck-It').value); if(isNaN(It)||It<0) return alert('[I]_t must be ≥ 0'); // k₁ from [A](t) = A0·e^{-k₁t} const k1 = Math.log(A0 / At) / t; if(k1 <= 0) return alert('k₁ is not positive — check [A]₀ and [A]_t'); // k₂ from [I](t) = k₁·A0/(k₂−k₁)·(e^{-k₁t}−e^{-k₂t}) // Rearrange: k₂ solved numerically via Newton-Raphson // f(k2) = k1*A0/(k2-k1)*(exp(-k1*t) – exp(-k2*t)) – It = 0 let k2 = k1 * 2; // initial guess const expK1t = Math.exp(-k1 * t); for(let i = 0; i < 200; i++){ if(Math.abs(k2 – k1) < 1e-12) { k2 += 1e-6; continue; } const expK2t = Math.exp(-k2 * t); const fval = k1 * A0 / (k2 – k1) * (expK1t – expK2t) – It; const dfdK2 = k1 * A0 * (-(expK1t – expK2t) / Math.pow(k2-k1,2) + t * expK2t / (k2-k1)); const step = fval / dfdK2; k2 -= step; k2 = Math.max(k2, 1e-10); if(Math.abs(step) < 1e-10) break; } kVal = k1; k2Val = k2; units = [`${tunit}⁻¹`]; lines = [ `k₁ = ln([A]₀ / [A]_t) / t`, ` = ln(${A0.toFixed(4)} / ${At.toFixed(4)}) / ${t}`, ` = ${k1.toFixed(6)} ${units[0]}`, “, `k₂ solved from [I](t) formula (Newton-Raphson)`, ` = ${k2.toFixed(6)} ${units[0]}` ]; } // ── NTH ORDER ──────────────────────────────────────────────────── else if(order === 'nth'){ const n = parseFloat(document.getElementById('ck-n').value); if(isNaN(n)) return alert('Order n must be a number'); let k, formula_str; if(Math.abs(n – 1) < 1e-6){ // Degenerates to first order k = Math.log(A0 / At) / t; formula_str = `n≈1: k = ln([A]₀/[A]_t) / t = ${k.toFixed(6)}`; } else { // [A]^{1-n} = [A]₀^{1-n} + (n-1)·k·t // k = ([A]_t^{1-n} – [A]₀^{1-n}) / ((n-1)·t) const A0pow = Math.pow(A0, 1-n); const Atpow = Math.pow(At, 1-n); k = (Atpow – A0pow) / ((n-1) * t); formula_str = ( `k = ([A]_t^{1-n} − [A]₀^{1-n}) / ((n-1)·t) ` + ` = (${At.toFixed(4)}^{${(1-n).toFixed(2)}} − ${A0.toFixed(4)}^{${(1-n).toFixed(2)}}) / (${(n-1).toFixed(2)}·${t}) ` + ` = ${k.toFixed(6)}` ); } kVal = k; const kUnitPow = n === 0 ? `${cu}/${tunit}` : n === 1 ? `${tunit}⁻¹` : `${cu}^{${(1-n).toFixed(2)}}·${tunit}⁻¹`; units = [kUnitPow]; lines = [formula_str.split('\n')].flat(); lines.push(`Units: L^{1-n}·mol^{n-1}·${tunit}^{-1}`); } if(kVal !== null && kVal <= 0) return alert('Calculated k is not positive. Check your input values.'); // ── Display result ──────────────────────────────────────────────── const box = document.getElementById('calc-k-result'); box.style.display = 'block'; let valueText = kVal !== null ? `k = ${kVal.toFixed(6)}` : ''; if(k2Val !== null) valueText += ` k₂ = ${k2Val.toFixed(6)}`; document.getElementById('calc-k-value').textContent = valueText; document.getElementById('calc-k-units').textContent = units.length ? `Units: ${units[0]}` : ''; document.getElementById('calc-k-formula').textContent = lines.join('\n'); // Auto-fill main simulation inputs if(kVal !== null){ document.getElementById('k').value = kVal.toFixed(6); document.getElementById('A0').value = A0; } if(k2Val !== null && document.getElementById('k2')){ document.getElementById('k2').value = k2Val.toFixed(6); } if(order === 'nth' && document.getElementById('nth-n')){ document.getElementById('nth-n').value = document.getElementById('ck-n').value; } } // ─── REACTION CHANGE ────────────────────────────────────────────── function onReactionChange(){ const v=document.getElementById('reaction-order').value; const isConsec = v==='consec'; setV('b-species-block', v==='second-ab'||isConsec); setV('i-species-block', isConsec); setV('ssa-toggle-row', isConsec); setV('nth-n-block', v==='nth'); if(!isConsec) document.getElementById('ssa-toggle').checked=false; document.getElementById('k-label').textContent=v==='consec'?'k₁ (A+B→I)':'Rate Constant k'; if(!isConsec) setV('ssa-chart-row',false); onCalcKReactionChange(); } function setV(id,show){ document.getElementById(id).classList.toggle('hidden',!show); } // ─── UTILS ──────────────────────────────────────────────────────── function arange(s,e,st){ const a=[]; for(let v=s;v<=e+1e-9;v+=st) a.push(Math.round(v*1e9)/1e9); return a; } function fmt(v){ if(typeof v!=='number') return v; if(v===0) return '0.000000'; if(Math.abs(v)<1e-4) return v.toExponential(4); return v.toFixed(6); } function mkChart(id,cfg){ if(CH[id]){CH[id].destroy();delete CH[id];} CH[id]=new Chart(document.getElementById(id).getContext('2d'),cfg); } function showCanvas(eid,cid){ const e=document.getElementById(eid),c=document.getElementById(cid); if(e) e.style.display='none'; if(c) c.style.display='block'; } function ds(label,data,ci,dashed=false){ return{label,data, borderColor:PAL[ci%PAL.length], backgroundColor:PAL[ci%PAL.length]+'18', borderWidth:dashed?1.5:2, borderDash:dashed?[6,4]:[], pointRadius:dashed?0:3, pointHoverRadius:dashed?0:5, tension:.35,fill:false}; } function tooltipPlugin(xL,yL){ return{enabled:true,mode:'index',intersect:false, backgroundColor:'#1c2230',borderColor:'#58a6ff',borderWidth:1, titleColor:'#58a6ff',bodyColor:'#e6edf3',padding:10,cornerRadius:6, titleFont:{family:'Courier New',size:11,weight:'bold'}, bodyFont:{family:'Courier New',size:12}, displayColors:true,boxWidth:10,boxHeight:10, callbacks:{ title(its){return xL+': '+Number(its[0].label??its[0].parsed.x).toFixed(4);}, label(it){const y=it.parsed.y;return ' '+it.dataset.label+': '+(Math.abs(y)` ${d.label} `).join(”); } function fillTable(thdId,tbdId,cols,rows){ if(thdId){const th=document.getElementById(thdId);if(th) th.innerHTML=’‘+cols.map(c=>`${c}`).join(”)+’‘;} const tb=document.getElementById(tbdId);if(!tb) return; tb.innerHTML=”; rows.forEach(r=>{const tr=document.createElement(‘tr’);tr.innerHTML=r.map(v=>`${fmt(v)}`).join(”);tb.appendChild(tr);}); } function showHL(val,tunit){ const d=document.getElementById(‘half-life-display’); if(val===null){d.style.display=’none’;return;} d.style.display=’block’; document.getElementById(‘half-life-value’).textContent=`t½ = ${(tunit===’min’?val/60:val).toFixed(5)} ${tunit}`; } // ─── SIMULATION ─────────────────────────────────────────────────── function runSimulation(){ const order =document.getElementById(‘reaction-order’).value; const phase =document.querySelector(‘input[name=”phase”]:checked’).value; const tunit =document.querySelector(‘input[name=”tunit”]:checked’).value; const An =document.getElementById(‘reactant’).value||’A’; const Pn =document.getElementById(‘product’).value||’P’; const Bn =document.getElementById(‘b-species’).value||’B’; const In =document.getElementById(‘i-species’).value||’I’; const A0 =parseFloat(document.getElementById(‘A0’).value); const B0 =parseFloat(document.getElementById(‘B0’).value)||0; const k =parseFloat(document.getElementById(‘k’).value); const k2v =parseFloat(document.getElementById(‘k2’).value)||0.5; const tStart=parseFloat(document.getElementById(‘t-start’).value); const tEnd =parseFloat(document.getElementById(‘t-end’).value); const tStep =parseFloat(document.getElementById(‘t-step’).value); const nVal =parseFloat(document.getElementById(‘nth-n’).value)||2; const ssaOn =document.getElementById(‘ssa-toggle’).checked; if(k 0′); if(tStep 0′); if(tEndt*60):dispT; let cols,rows,concDS=[],rateDS=[],tHalf=null; // ── ZEROTH ── if(order===’zeroth’){ const A=tSec.map(t=>Math.max(A0-k*t,0)); const P=A.map(a=>A0-a); const R=tSec.map(()=>k); tHalf=A0/(2*k); cols=[`Time (${tunit})`,`[${An}] (${cu})`,`[${Pn}] (${cu})`,`Rate (${ru})`]; rows=dispT.map((t,i)=>[t,A[i],P[i],R[i]]); concDS=[ds(An,A,0),ds(Pn,P,1)]; rateDS=[ds(‘Rate’,R,2)]; } // ── FIRST ── else if(order===’first’){ const A=tSec.map(t=>A0*Math.exp(-k*t)); const P=A.map(a=>A0-a); const R=A.map(a=>k*a); tHalf=Math.log(2)/k; cols=[`Time (${tunit})`,`[${An}] (${cu})`,`[${Pn}] (${cu})`,`Rate (${ru})`]; rows=dispT.map((t,i)=>[t,A[i],P[i],R[i]]); concDS=[ds(An,A,0),ds(Pn,P,1)]; rateDS=[ds(‘Rate’,R,2)]; } // ── SECOND A→P ── else if(order===’second-a’){ const A=tSec.map(t=>A0/(1+k*A0*t)); const P=A.map(a=>A0-a); const R=A.map(a=>k*a*a); tHalf=1/(k*A0); cols=[`Time (${tunit})`,`[${An}] (${cu})`,`[${Pn}] (${cu})`,`Rate (${ru})`]; rows=dispT.map((t,i)=>[t,A[i],P[i],R[i]]); concDS=[ds(An,A,0),ds(Pn,P,1)]; rateDS=[ds(‘Rate’,R,2)]; } // ── SECOND A+B→P ── else if(order===’second-ab’){ const Al=[],Bl=[],Pl=[],Rl=[]; tSec.forEach(t=>{ let A_t,B_t,Pv; if(Math.abs(A0-B0)<1e-10){ // Special case [A]0=[B]0: use second-order A→P integrated law // [A] = [A]0 / (1 + k·[A]0·t) // [P] = k·[A]0²·t / (1 + k·[A]0·t) A_t = A0 / (1 + k*A0*t); B_t = A_t; Pv = (k * A0 * A0 * t) / (1 + k*A0*t); } else { const ex=Math.exp((B0-A0)*k*t); const dn=A0-B0*ex; if(Math.abs(dn)[t,Al[i],Bl[i],Pl[i],Rl[i]]); // B always shown in different colour (index 3 = purple) so it’s distinct from A(0) and P(1) concDS=[ds(An,Al,0),ds(Bn,Bl,3),ds(Pn,Pl,1)]; rateDS=[ds(‘Rate’,Rl,2)]; } // ── CONSECUTIVE A+B→I→P ── else if(order===’consec’){ const k1=k, k2=k2v; // Exact analytical: pseudo-first-order consecutive // [A](t) = A0·exp(-k1·t) // [B](t) = B0·exp(-k1·t) (B decays at same rate as A) // [I](t) = k1·A0/(k2-k1)·(exp(-k1·t) – exp(-k2·t)) [I(0)=0 enforced] // [P](t) = A0 – [A] – [I] const Aex=tSec.map(t=>A0*Math.exp(-k1*t)); // B(t): show if B0 > 0, decays at same rate const showB=B0>0; const Bex=showB?tSec.map(t=>B0*Math.exp(-k1*t)):null; const Iex=tSec.map((t,i)=>{ if(i===0) return 0; // enforce I(0)=0 at first time point if(Math.abs(k2-k1)Math.max(A0-Aex[i]-Iex[i],0)); const Rex=Iex.map(iv=>k2*iv); if(ssaOn){ // SSA: [I]_ss = k1·[A]/k2 const Issa=tSec.map((t,i)=>i===0?0:k1*Aex[i]/k2); const Pssa=tSec.map((_,i)=>Math.max(A0-Aex[i]-Issa[i],0)); const Rssa=Issa.map(iv=>k2*iv); // Main chart: exact (solid) + SSA (dashed) concDS=[ds(An,Aex,0),ds(In,Iex,1),ds(Pn,Pex,2)]; if(showB) concDS.push(ds(Bn,Bex,5)); // B in distinct cyan (index 5) concDS.push(ds(In+’ (SSA)’,Issa,6,true),ds(Pn+’ (SSA)’,Pssa,7,true)); rateDS=[ds(‘Rate (exact)’,Rex,4),ds(‘Rate (SSA)’,Rssa,8,true)]; // SSA-only charts setV(‘ssa-chart-row’,true); const ssaCDS=[ds(An,Aex,0),ds(In,Issa,1),ds(Pn,Pssa,2)]; if(showB) ssaCDS.push(ds(Bn,Bex,5)); // B cyan in SSA chart too const ssaRDS=[ds(‘Rate (SSA)’,Rssa,4)]; document.getElementById(‘ssa-conc-title’).innerHTML=’SSA Concentration vs Time ‘+legHTML(ssaCDS)+’‘; document.getElementById(‘ssa-rate-title’).innerHTML=’SSA Rate vs Time ‘+legHTML(ssaRDS)+’‘; mkChart(‘chart-ssa-conc’,{type:’line’,data:{labels:dispT,datasets:ssaCDS},options:chartOpts(‘Time (‘+tunit+’)’,`Concentration (${cu})`)}); mkChart(‘chart-ssa-rate’,{type:’line’,data:{labels:dispT,datasets:ssaRDS},options:chartOpts(‘Time (‘+tunit+’)’,`Rate (${ru})`)}); // Table: exact values cols=showB ?[`Time (${tunit})`,`[${An}] (${cu})`,`[${Bn}] (${cu})`,`[${In}] (${cu})`,`[${Pn}] (${cu})`,`Rate (${ru})`] :[`Time (${tunit})`,`[${An}] (${cu})`,`[${In}] (${cu})`,`[${Pn}] (${cu})`,`Rate (${ru})`]; rows=showB ?dispT.map((t,i)=>[t,Aex[i],Bex[i],Iex[i],Pex[i],Rex[i]]) :dispT.map((t,i)=>[t,Aex[i],Iex[i],Pex[i],Rex[i]]); } else { // SSA OFF: exact solid lines + SSA dashed overlay on main chart const Issa=tSec.map((t,i)=>i===0?0:k1*Aex[i]/k2); const Pssa=tSec.map((_,i)=>Math.max(A0-Aex[i]-Issa[i],0)); const Rssa=Issa.map(iv=>k2*iv); concDS=[ds(An,Aex,0),ds(In,Iex,1),ds(Pn,Pex,2)]; if(showB) concDS.push(ds(Bn,Bex,5)); // B in distinct cyan colour (index 5) concDS.push(ds(In+’ (SSA)’,Issa,6,true),ds(Pn+’ (SSA)’,Pssa,7,true)); rateDS=[ds(‘Rate (exact)’,Rex,4),ds(‘Rate (SSA)’,Rssa,8,true)]; setV(‘ssa-chart-row’,false); cols=showB ?[`Time (${tunit})`,`[${An}] (${cu})`,`[${Bn}] (${cu})`,`[${In}] (${cu})`,`[${Pn}] (${cu})`,`Rate (${ru})`] :[`Time (${tunit})`,`[${An}] (${cu})`,`[${In}] (${cu})`,`[${Pn}] (${cu})`,`Rate (${ru})`]; rows=showB ?dispT.map((t,i)=>[t,Aex[i],Bex[i],Iex[i],Pex[i],Rex[i]]) :dispT.map((t,i)=>[t,Aex[i],Iex[i],Pex[i],Rex[i]]); } } // ── NTH ORDER ── else if(order===’nth’){ const n=nVal; let A; if(Math.abs(n-1)A0*Math.exp(-k*t)); } else { A=tSec.map(t=>{ const base=Math.pow(A0,1-n)+(n-1)*k*t; return base>0?Math.pow(base,1/(1-n)):0; }); } const R=A.map(a=>k*Math.pow(Math.max(a,0),n)); const P=A.map(a=>Math.max(A0-a,0)); tHalf=Math.abs(n-1)[t,A[i],P[i],R[i]]); concDS=[ds(An,A,0),ds(Pn,P,1)]; rateDS=[ds(‘Rate’,R,2)]; } // ── RENDER ── simData_={columns:cols,rows}; document.getElementById(‘conc-chart-title’).innerHTML=`Concentration vs Time ${legHTML(concDS)}`; document.getElementById(‘rate-chart-title’).innerHTML=`Reaction Rate vs Time ${legHTML(rateDS)}`; showCanvas(‘conc-empty’,’chart-conc’); showCanvas(‘rate-empty’,’chart-rate’); mkChart(‘chart-conc’,{type:’line’,data:{labels:dispT,datasets:concDS},options:chartOpts(‘Time (‘+tunit+’)’,`Concentration (${cu})`)}); mkChart(‘chart-rate’,{type:’line’,data:{labels:dispT,datasets:rateDS},options:chartOpts(‘Time (‘+tunit+’)’,`Rate (${ru})`)}); fillTable(‘sim-thead’,’sim-tbody’,cols,rows); showHL(tHalf,tunit); } // ─── ARRHENIUS MODE CHANGE ────────────────────────────────────── function onArrModeChange(){ const single = document.querySelector(‘input[name=”arr-mode”]:checked’).value === ‘single’; setV(‘arr-range-block’, !single); setV(‘arr-single-block’, single); document.getElementById(‘arr-calc-btn’).textContent = single ? ‘▶ Calculate k’ : ‘▶ Calculate’; // Hide results from previous mode [‘arr-slope’,’arr-intercept’,’arr-equation’].forEach(id=>{ const e=document.getElementById(id); e.textContent=”; e.classList.remove(‘show’); }); document.getElementById(‘arr-single-result’).style.display=’none’; // Hide charts when switching to single mode if(single){ document.getElementById(‘arr-empty1′).style.display=’flex’; document.getElementById(‘arr-empty2′).style.display=’flex’; const c1=document.getElementById(‘chart-arrhenius’); const c2=document.getElementById(‘chart-k-T’); if(c1) c1.style.display=’none’; if(c2) c2.style.display=’none’; } } // ─── ARRHENIUS ──────────────────────────────────────────────────── function runArrhenius(){ const mode = document.querySelector(‘input[name=”arr-mode”]:checked’).value; // ── SINGLE TEMPERATURE MODE ─────────────────────────────────────── if(mode === ‘single’){ const T = parseFloat(document.getElementById(‘arr-T-single’).value); const EaIn= parseFloat(document.getElementById(‘arr-Ea’).value); const eaU = document.querySelector(‘input[name=”ea-unit”]:checked’).value; const Af = parseFloat(document.getElementById(‘arr-A’).value); const R = parseFloat(document.getElementById(‘arr-R’).value); if(T 0 K’); if(Af 0′); if(R 0′); const Ea = eaU === ‘kJ’ ? EaIn * 1000 : EaIn; const k = Af * Math.exp(-Ea / (R * T)); const lnk = Math.log(k); const exp_arg = -Ea / (R * T); // Show result box const box = document.getElementById(‘arr-single-result’); box.style.display = ‘block’; document.getElementById(‘arr-single-k’).textContent = `k = ${k.toExponential(4)} s⁻¹`; document.getElementById(‘arr-single-lnk’).textContent = `ln(k) = ${lnk.toFixed(6)}`; document.getElementById(‘arr-single-formula’).textContent = `k = A · e^(−Eₐ/RT) ` + ` = ${Af.toExponential(3)} × e^(${exp_arg.toFixed(4)}) ` + ` = ${k.toExponential(4)} s⁻¹ ` + `Eₐ = ${(Ea/1000).toFixed(3)} kJ/mol ` + `T = ${T} K ` + `R = ${R} J mol⁻¹ K⁻¹`; return; } // ── RANGE MODE ──────────────────────────────────────────────────── const Ts =parseFloat(document.getElementById(‘arr-t-start’).value); const Te =parseFloat(document.getElementById(‘arr-t-end’).value); const Tst=parseFloat(document.getElementById(‘arr-t-step’).value); const EaIn=parseFloat(document.getElementById(‘arr-Ea’).value); const eaU=document.querySelector(‘input[name=”ea-unit”]:checked’).value; const Af =parseFloat(document.getElementById(‘arr-A’).value); const R =parseFloat(document.getElementById(‘arr-R’).value); if(Tst<=0) return alert('Temperature step must be positive'); if(Te Start’); if(Af<=0) return alert('Frequency factor A must be positive'); if(RAf*Math.exp(-Ea/(R*t))); const invT=T.map(t=>1/t); const lnk=k.map(v=>Math.log(v)); const nn=invT.length; const sx=invT.reduce((a,b)=>a+b,0),sy=lnk.reduce((a,b)=>a+b,0); const sxy=invT.reduce((a,v,i)=>a+v*lnk[i],0),sx2=invT.reduce((a,v)=>a+v*v,0); const slope=(nn*sxy-sx*sy)/(nn*sx2-sx*sx); const intercept=(sy-slope*sx)/nn; const fit=invT.map(x=>slope*x+intercept); const show=(id,txt)=>{const e=document.getElementById(id);e.textContent=txt;e.classList.add(‘show’);}; show(‘arr-slope’, `Slope = ${slope.toFixed(6)}`); show(‘arr-intercept’,`Intercept = ${intercept.toFixed(6)}`); show(‘arr-equation’, `ln(k) = ${slope.toFixed(4)}·(1/T) + ${intercept.toFixed(4)}`); arrData_={columns:[‘T (K)’,’1/T (K⁻¹)’,’k’,’ln(k)’],rows:T.map((t,i)=>[t,invT[i],k[i],lnk[i]])}; document.getElementById(‘arr-empty1′).style.display=’none’; document.getElementById(‘arr-empty2′).style.display=’none’; document.getElementById(‘chart-arrhenius’).style.display=’block’; document.getElementById(‘chart-k-T’).style.display=’block’; mkChart(‘chart-arrhenius’,{type:’scatter’, data:{datasets:[ {label:’Data’,data:invT.map((x,i)=>({x,y:lnk[i]})),borderColor:PAL[0],backgroundColor:PAL[0]+’66’,pointRadius:5,pointHoverRadius:7}, {label:’Fit’, data:invT.map((x,i)=>({x,y:fit[i]})),type:’line’,borderColor:PAL[2],borderWidth:2,pointRadius:0,backgroundColor:’transparent’,tension:0} ]}, options:chartOpts(‘1/T (K⁻¹)’,’ln(k)’)}); mkChart(‘chart-k-T’,{type:’line’,data:{labels:T,datasets:[ds(‘k’,k,1)]},options:chartOpts(‘Temperature (K)’,’k (s⁻¹)’)}); fillTable(null,’arr-tbody’,arrData_.columns,arrData_.rows); } // ─── EXPORT MODAL ───────────────────────────────────────────────── function openModal(which){ exportTarget=which; exportFmt=’csv’; document.getElementById(‘fmt-csv’).classList.add(‘selected’); document.getElementById(‘fmt-pdf’).classList.remove(‘selected’); document.getElementById(‘csv-opts’).classList.remove(‘hidden’); document.getElementById(‘pdf-opts’).classList.add(‘hidden’); document.getElementById(‘export-modal’).classList.remove(‘hidden’); } function closeModal(){ document.getElementById(‘export-modal’).classList.add(‘hidden’); } function selectFmt(f){ exportFmt=f; document.getElementById(‘fmt-csv’).classList.toggle(‘selected’,f===’csv’); document.getElementById(‘fmt-pdf’).classList.toggle(‘selected’,f===’pdf’); document.getElementById(‘csv-opts’).classList.toggle(‘hidden’,f!==’csv’); document.getElementById(‘pdf-opts’).classList.toggle(‘hidden’,f!==’pdf’); } function doExport(){ if(exportFmt===’csv’) doCSV(); else doPDF(); closeModal(); } function doCSV(){ const store=exportTarget===’sim’?simData_:exportTarget===’arr’?arrData_:exportTarget===’enz-dep’?enzDepData_:enzData_; if(!store) return alert(‘Run the simulation first.’); const includeGraphs=document.getElementById(‘csv-include-graphs’).checked; const lines=[store.columns.join(‘,’),…store.rows.map(r=>r.map(v=>typeof v===’number’?v.toFixed(6):v).join(‘,’))]; const csvBlob=new Blob([lines.join(‘\n’)],{type:’text/csv’}); if(!includeGraphs){ // Just download CSV dlBlob(csvBlob,`kinetics_${exportTarget}_${Date.now()}.csv`); } else { // Export CSV + chart images in a simple HTML page (zip not available without libraries) // Collect chart images const imgs=getVisibleCharts(exportTarget); // Build a combined HTML file with table + images const sName={sim:’Integrated Rate Laws’,arr:’Arrhenius Analysis’,enz:’Enzyme Kinetics’}[exportTarget]||”; let html=`GRU LAB Export body{font-family:monospace;padding:24px;background:#fff;max-width:960px;margin:auto;} .gru-header{display:flex;align-items:center;gap:12px;border-bottom:3px solid #1d6a8a; padding-bottom:12px;margin-bottom:20px;} .gru-icon{width:38px;height:38px;background:linear-gradient(135deg,#58a6ff,#3fb950); border-radius:7px;display:flex;align-items:center;justify-content:center; font-size:20px;color:#fff;font-weight:900;} .gru-name{font-size:20px;font-weight:900;letter-spacing:.1em;color:#0d1b2a;} .gru-name span{color:#1d6a8a;} .gru-sub{font-size:9px;color:#666;letter-spacing:.08em;} .meta{font-size:10px;color:#888;margin-bottom:20px;} table{border-collapse:collapse;width:100%;margin-bottom:30px;} th,td{border:1px solid #ccc;padding:6px 10px;text-align:center;font-size:11px;} th{background:#e8f4f8;font-weight:700;color:#0d1b2a;} tr:nth-child(even) td{background:#f8fbfd;} img{max-width:100%;margin-bottom:20px;border:1px solid #ccc;border-radius:6px;} h2{font-size:12px;font-weight:700;color:#1d6a8a;text-transform:uppercase; letter-spacing:.07em;margin:20px 0 8px;border-left:3px solid #1d6a8a;padding-left:6px;} .footer{margin-top:24px;font-size:9px;color:#aaa;text-align:center;border-top:1px solid #eee;padding-top:8px;}
GRU LAB
Section: ${sName}  |  Exported: ${new Date().toLocaleString()}
`; html+=`

Data Table

${store.columns.map(c=>``).join(”)}`; store.rows.forEach(r=>{html+=`${r.map(v=>``).join(”)}`;}); html+=`
${c}
${fmt(v)}
`; imgs.forEach(im=>{html+=`

${im.label}

`;}); html+=``; dlBlob(new Blob([html],{type:’text/html’}),`kinetics_${exportTarget}_${Date.now()}.html`); } } function doPDF(){ const store=exportTarget===’sim’?simData_:exportTarget===’arr’?arrData_:exportTarget===’enz-dep’?enzDepData_:enzData_; if(!store) return alert(‘Run the simulation first.’); const imgs=getVisibleCharts(exportTarget); const tableRows=store.rows.map(r=>`${r.map(v=>`${fmt(v)}`).join(”)}`).join(”); const tableHead=`${store.columns.map(c=>`${c}`).join(”)}`; const imgHTML=imgs.map(im=>`
${im.label.toUpperCase()}
`).join(”); const sectionName={sim:’Integrated Rate Laws’,arr:’Arrhenius Analysis’,enz:’Enzyme Kinetics’}[exportTarget]||”; const w=window.open(”,’_blank’); w.document.write(` GRU LAB — Kinetics Report *{box-sizing:border-box;} body{font-family:’Courier New’,monospace;padding:28px 32px;color:#111;max-width:980px;margin:auto;} .gru-header{display:flex;align-items:center;justify-content:space-between; border-bottom:3px solid #1d6a8a;padding-bottom:14px;margin-bottom:18px;} .gru-logo{display:flex;align-items:center;gap:12px;} .gru-icon{width:44px;height:44px;background:linear-gradient(135deg,#58a6ff,#3fb950); border-radius:8px;display:flex;align-items:center;justify-content:center; font-size:22px;color:#fff;font-weight:900;} .gru-name{font-size:22px;font-weight:900;letter-spacing:.12em;color:#0d1b2a;} .gru-name span{color:#1d6a8a;} .gru-sub{font-size:10px;color:#666;letter-spacing:.08em;text-transform:uppercase;margin-top:2px;} .gru-meta{text-align:right;font-size:10px;color:#666;line-height:1.7;} h2{font-size:13px;font-weight:700;color:#1d6a8a;text-transform:uppercase; letter-spacing:.08em;margin:24px 0 10px;border-left:3px solid #1d6a8a;padding-left:8px;} table{border-collapse:collapse;width:100%;margin-bottom:32px;font-size:11px;} th{background:#e8f4f8;border:1px solid #bbb;padding:6px 10px;text-align:center; font-weight:700;color:#0d1b2a;} td{border:1px solid #ddd;padding:5px 10px;text-align:center;} tr:nth-child(even) td{background:#f8fbfd;} .chart-block{margin-bottom:28px;page-break-inside:avoid;} .chart-title{font-size:11px;font-weight:700;text-transform:uppercase; letter-spacing:.08em;color:#1d6a8a;margin-bottom:8px;} img{width:100%;border:1px solid #ddd;border-radius:4px;} .print-btn{text-align:center;margin-top:20px;padding-top:16px;border-top:1px solid #ddd;} .footer{margin-top:32px;font-size:9px;color:#aaa;text-align:center; border-top:1px solid #eee;padding-top:10px;} @media print{body{padding:10px;}.print-btn{display:none;}}
Section: ${sectionName}
Generated: ${new Date().toLocaleString()}
Document: Kinetics Report
${imgHTML}

Data Table

${tableHead}${tableRows}
`); w.document.close(); } function dlBlob(blob,name){ const a=document.createElement(‘a’); a.href=URL.createObjectURL(blob); a.download=name; a.click(); } // ─── ENZYME KINETICS ────────────────────────────────────────────── let enzVmax_ = 100, enzKm_ = 5; // store for kcat calc function onEnzModelChange(){ const m = document.getElementById(‘enz-model’).value; setV(‘enz-inhib-block’, m === ‘mm-comp’ || m === ‘mm-noncomp’); } function onEnzSModeChange(){ const single = document.querySelector(‘input[name=”enz-s-mode”]:checked’).value === ‘single’; setV(‘enz-s-range-inputs’, !single); setV(‘enz-s-single-inputs’, single); } function updateKcat(){ const Et = parseFloat(document.getElementById(‘enz-Et’).value)||1; const kcat = (enzVmax_ / Et).toFixed(4); document.getElementById(‘enz-kcat-val’).textContent = `kcat = ${kcat} s⁻¹`; } // Linear regression helper function linReg(xs, ys){ const n=xs.length; const sx=xs.reduce((a,b)=>a+b,0), sy=ys.reduce((a,b)=>a+b,0); const sxy=xs.reduce((a,v,i)=>a+v*ys[i],0), sx2=xs.reduce((a,v)=>a+v*v,0); const slope=(n*sxy-sx*sy)/(n*sx2-sx*sx); const intercept=(sy-slope*sx)/n; // R² const yMean=sy/n; const ssTot=ys.reduce((a,v)=>a+(v-yMean)**2,0); const ssRes=ys.reduce((a,v,i)=>a+(v-(slope*xs[i]+intercept))**2,0); const r2=1-ssRes/ssTot; return {slope,intercept,r2}; } function runEnzyme(){ const model = document.getElementById(‘enz-model’).value; const k3 = parseFloat(document.getElementById(‘enz-k3’).value); const Et0 = parseFloat(document.getElementById(‘enz-Et0’).value); // µM const Km = parseFloat(document.getElementById(‘enz-Km’).value); const Iconc = parseFloat(document.getElementById(‘enz-I’).value)||0; const Ki = parseFloat(document.getElementById(‘enz-Ki’).value)||1; const sStart = parseFloat(document.getElementById(‘enz-s-start’).value); const sEnd = parseFloat(document.getElementById(‘enz-s-end’).value); const nPts = parseInt(document.getElementById(‘enz-s-n’).value)||30; if(k3 0′); if(Et0 0′); if(Km 0′); if(sEnd Start’); // ── Core equation: v = k3·[E]0·[S] / (Km + [S]) // Vmax = k3 · [E]0 (convert [E]0 from µM to µmol/L = µmol/L, same units) const Vmax = k3 * Et0; // µmol/L/s (k3 in s⁻¹, Et0 in µM = µmol/L) enzVmax_ = Vmax; enzKm_ = Km; // Hide all result boxes [‘enz-result-v’,’enz-result-vmax’,’enz-result-km’, ‘enz-result-lb-slope’,’enz-result-lb-intcpt’,’enz-result-lb-r2′,’enz-result-lb-km’,’enz-result-lb-vmax’, ‘enz-result-hw-slope’,’enz-result-hw-intcpt’,’enz-result-hw-r2′,’enz-result-hw-km’,’enz-result-hw-vmax’, ‘enz-result-eh-slope’,’enz-result-eh-intcpt’,’enz-result-eh-r2′,’enz-result-eh-km’,’enz-result-eh-vmax’, ‘enz-result-app’] .forEach(id=>{ const e=document.getElementById(id); if(e){e.textContent=”; e.classList.remove(‘show’);} }); document.getElementById(‘enz-result-kcat’).style.display=’none’; const showR=(id,txt)=>{ const e=document.getElementById(id); e.textContent=txt; e.classList.add(‘show’); }; // Substrate array for v vs [S] curve const S = Array.from({length:nPts},(_,i)=>sStart+(sEnd-sStart)*i/(nPts-1)); // ── MICHAELIS-MENTEN ───────────────────────────────────────────── if(model===’mm’){ const sMode = document.querySelector(‘input[name=”enz-s-mode”]:checked’).value; const isSingle = sMode === ‘single’; // ── Helper: run RK4 depletion ────────────────────────────────── // Returns {tDep, sDep, vDep} arrays in minutes function runDepletion(S0_dep, dtMin){ const VmaxMin = Vmax * 60; // µmol/L/s → µmol/L/min const dtF = dtMin / 50; // fine integration step const finT=[], finS=[], finV=[]; let sd = S0_dep; let t = 0; const THRESHOLD = S0_dep * 0.001; // stop at 0.1% of S0 while(sd > THRESHOLD){ finT.push(+t.toFixed(6)); finS.push(sd); finV.push(VmaxMin * sd / (Km + sd)); const f = ss => -VmaxMin * ss / (Km + ss); const k1r=f(sd), k2r=f(sd+dtF/2*k1r), k3r=f(sd+dtF/2*k2r), k4r=f(sd+dtF*k3r); sd = Math.max(sd + dtF/6*(k1r+2*k2r+2*k3r+k4r), 0); t += dtF; if(finT.length > 50000) break; // safety cap } // Add final near-zero point finT.push(+t.toFixed(6)); finS.push(sd); finV.push(VmaxMin*sd/(Km+sd)); // Thin to ≤200 display points const stride = Math.max(1, Math.floor(finT.length/200)); return { tDep: finT.filter((_,i)=>i%stride===0), sDep: finS.filter((_,i)=>i%stride===0), vDep: finV.filter((_,i)=>i%stride===0), }; } if(isSingle){ // ── SINGLE [S]0 MODE ──────────────────────────────────────── const S0_dep = parseFloat(document.getElementById(‘enz-s-single’).value)||20; const dtMin = parseFloat(document.getElementById(‘enz-dep-step’).value)||1; // Generate S range from 0.01*S0 to S0 for kinetics curve const S = Array.from({length:50},(_,i)=>S0_dep*0.01 + S0_dep*0.99*i/49); const v = S.map(s => k3 * Et0 * s / (Km + s)); const vmaxLine = S.map(()=>Vmax); const invS=S.map(s=>1/s), invV=v.map(vi=>1/vi); const hanesY=S.map((s,i)=>s/v[i]); const eadieX=v.map((vi,i)=>vi/S[i]); // Linearisation stats const lb=linReg(invS,invV); const lbFit=invS.map(x=>lb.slope*x+lb.intercept); const lbVmax=lb.intercept!==0?1/lb.intercept:NaN; const lbKm=lb.slope*lbVmax; const hw=linReg(S,hanesY); const hwFit=S.map(x=>hw.slope*x+hw.intercept); const hwVmax=hw.slope!==0?1/hw.slope:NaN; const hwKm=hw.intercept*hwVmax; const eh=linReg(eadieX,v); const ehFit=eadieX.map((x,i)=>eh.slope*x+eh.intercept); const ehVmax=eh.intercept; const ehKm=-eh.slope; // Results const vAtS0 = k3 * Et0 * S0_dep / (Km + S0_dep); showR(‘enz-result-v’, `v at [S]₀ = ${vAtS0.toFixed(4)} µmol/L/s`); showR(‘enz-result-vmax’, `Vmax = ${Vmax.toFixed(4)} µmol/L/s`); showR(‘enz-result-km’, `Km = ${Km.toFixed(4)} mM`); showR(‘enz-result-lb-slope’, `Slope = ${lb.slope.toFixed(6)} (= Km/Vmax)`); showR(‘enz-result-lb-intcpt’,`Y-int = ${lb.intercept.toFixed(6)} (= 1/Vmax)`); showR(‘enz-result-lb-r2’, `R² = ${lb.r2.toFixed(6)}`); showR(‘enz-result-lb-km’, `Km (LB) = ${lbKm.toFixed(4)} mM`); showR(‘enz-result-lb-vmax’, `Vmax (LB)= ${lbVmax.toFixed(4)} µmol/L/s`); showR(‘enz-result-hw-slope’, `Slope = ${hw.slope.toFixed(6)} (= 1/Vmax)`); showR(‘enz-result-hw-intcpt’,`Y-int = ${hw.intercept.toFixed(6)} (= Km/Vmax)`); showR(‘enz-result-hw-r2’, `R² = ${hw.r2.toFixed(6)}`); showR(‘enz-result-hw-km’, `Km (HW) = ${hwKm.toFixed(4)} mM`); showR(‘enz-result-hw-vmax’, `Vmax (HW)= ${hwVmax.toFixed(4)} µmol/L/s`); showR(‘enz-result-eh-slope’, `Slope = ${eh.slope.toFixed(6)} (= -Km)`); showR(‘enz-result-eh-intcpt’,`Y-int = ${eh.intercept.toFixed(6)} (= Vmax)`); showR(‘enz-result-eh-r2’, `R² = ${eh.r2.toFixed(6)}`); showR(‘enz-result-eh-km’, `Km (EH) = ${ehKm.toFixed(4)} mM`); showR(‘enz-result-eh-vmax’, `Vmax (EH)= ${ehVmax.toFixed(4)} µmol/L/s`); document.getElementById(‘enz-result-kcat’).style.display=’block’; document.getElementById(‘enz-Et’).value = Et0; updateKcat(); // Charts 1-4 (kinetics) document.getElementById(‘enz-chart1-title’).innerHTML= `v vs [S] — Michaelis-Menten ${legHTML([ds(‘v’,v,4),ds(‘Vmax’,vmaxLine,4,true)])}`; showCanvas(‘enz-empty1′,’chart-enz-mm’); mkChart(‘chart-enz-mm’,{type:’line’,data:{labels:S.map(s=>s.toFixed(3)),datasets:[ ds(‘v (µmol/L/s)’,v,4), ds(‘Vmax’,vmaxLine,4,true) ]},options:chartOpts(‘[S] (mM)’,’v (µmol/L/s)’)}); document.getElementById(‘enz-chart2-title’).textContent=’Lineweaver-Burk (1/v vs 1/[S])’; showCanvas(‘enz-empty2′,’chart-enz-lb’); mkChart(‘chart-enz-lb’,{type:’scatter’,data:{datasets:[ {label:’1/v’,data:invS.map((x,i)=>({x,y:invV[i]})),borderColor:PAL[0],backgroundColor:PAL[0]+’66’,pointRadius:5,pointHoverRadius:7}, {label:’LB fit’,data:invS.map((x,i)=>({x,y:lbFit[i]})),type:’line’,borderColor:PAL[2],borderWidth:2,pointRadius:0,backgroundColor:’transparent’,tension:0} ]},options:chartOpts(‘1/[S] (mM⁻¹)’,’1/v (L·s/µmol)’)}); setV(‘enz-linear-row’,true); mkChart(‘chart-enz-hanes’,{type:’scatter’,data:{datasets:[ {label:'[S]/v’,data:S.map((x,i)=>({x,y:hanesY[i]})),borderColor:PAL[1],backgroundColor:PAL[1]+’66’,pointRadius:4,pointHoverRadius:6}, {label:’fit’,data:S.map((x,i)=>({x,y:hwFit[i]})),type:’line’,borderColor:PAL[6],borderWidth:2,pointRadius:0,backgroundColor:’transparent’,tension:0} ]},options:chartOpts(‘[S] (mM)’,'[S]/v (mM·L·s/µmol)’)}); mkChart(‘chart-enz-eadie’,{type:’scatter’,data:{datasets:[ {label:’v vs v/[S]’,data:eadieX.map((x,i)=>({x,y:v[i]})),borderColor:PAL[3],backgroundColor:PAL[3]+’66’,pointRadius:4,pointHoverRadius:6}, {label:’fit’,data:eadieX.map((x,i)=>({x,y:ehFit[i]})),type:’line’,borderColor:PAL[7],borderWidth:2,pointRadius:0,backgroundColor:’transparent’,tension:0} ]},options:chartOpts(‘v/[S] (µmol/L/s/mM)’,’v (µmol/L/s)’)}); // Run depletion until [S] → 0 const dep = runDepletion(S0_dep, dtMin); setV(‘enz-depletion-row’, true); setV(‘enz-dep-table-card’, true); mkChart(‘chart-enz-dep-s’,{type:’line’,data:{labels:dep.tDep.map(t=>t.toFixed(3)), datasets:[ds(‘[S] (mM)’,dep.sDep,5)]},options:chartOpts(‘Time (min)’,'[S] (mM)’)}); mkChart(‘chart-enz-dep-v’,{type:’line’,data:{labels:dep.tDep.map(t=>t.toFixed(3)), datasets:[ds(‘v (µmol/L/min)’,dep.vDep,1)]},options:chartOpts(‘Time (min)’,’v (µmol/L/min)’)}); // Kinetics table const cols=[‘[S] (mM)’,’v (µmol/L/s)’,’1/[S] (mM⁻¹)’,’1/v (L·s/µmol)’,'[S]/v’,’v/[S]’]; const rows=S.map((s,i)=>[s,v[i],invS[i],invV[i],hanesY[i],eadieX[i]]); enzData_={columns:cols,rows}; fillTable(‘enz-thead’,’enz-tbody’,cols,rows); document.getElementById(‘enz-table-title’).textContent=’📋 Michaelis-Menten Data Table’; // Depletion table (time-based) const depCols=[‘Time (min)’,'[S] (mM)’,’v (µmol/L/min)’]; const depRows=dep.tDep.map((t,i)=>[t, dep.sDep[i], dep.vDep[i]]); enzDepData_={columns:depCols,rows:depRows}; fillTable(‘enz-dep-thead’,’enz-dep-tbody’,depCols,depRows); } else { // ── RANGE MODE ────────────────────────────────────────────── const S = Array.from({length:nPts},(_,i)=>sStart+(sEnd-sStart)*i/(nPts-1)); const v = S.map(s => k3 * Et0 * s / (Km + s)); const vmaxLine = S.map(()=>Vmax); const invS=S.map(s=>1/s), invV=v.map(vi=>1/vi); const hanesY=S.map((s,i)=>s/v[i]); const eadieX=v.map((vi,i)=>vi/S[i]); // Linearisation stats const lb=linReg(invS,invV); const lbFit=invS.map(x=>lb.slope*x+lb.intercept); const lbVmax=lb.intercept!==0?1/lb.intercept:NaN; const lbKm=lb.slope*lbVmax; const hw=linReg(S,hanesY); const hwFit=S.map(x=>hw.slope*x+hw.intercept); const hwVmax=hw.slope!==0?1/hw.slope:NaN; const hwKm=hw.intercept*hwVmax; const eh=linReg(eadieX,v); const ehFit=eadieX.map((x,i)=>eh.slope*x+eh.intercept); const ehVmax=eh.intercept; const ehKm=-eh.slope; // Results const vAtKm = k3 * Et0 * Km / (Km + Km); showR(‘enz-result-v’, `v at [S]=Km = ${vAtKm.toFixed(4)} µmol/L/s`); showR(‘enz-result-vmax’, `Vmax = ${Vmax.toFixed(4)} µmol/L/s`); showR(‘enz-result-km’, `Km = ${Km.toFixed(4)} mM`); showR(‘enz-result-lb-slope’, `Slope = ${lb.slope.toFixed(6)} (= Km/Vmax)`); showR(‘enz-result-lb-intcpt’,`Y-int = ${lb.intercept.toFixed(6)} (= 1/Vmax)`); showR(‘enz-result-lb-r2’, `R² = ${lb.r2.toFixed(6)}`); showR(‘enz-result-lb-km’, `Km (LB) = ${lbKm.toFixed(4)} mM`); showR(‘enz-result-lb-vmax’, `Vmax (LB)= ${lbVmax.toFixed(4)} µmol/L/s`); showR(‘enz-result-hw-slope’, `Slope = ${hw.slope.toFixed(6)} (= 1/Vmax)`); showR(‘enz-result-hw-intcpt’,`Y-int = ${hw.intercept.toFixed(6)} (= Km/Vmax)`); showR(‘enz-result-hw-r2’, `R² = ${hw.r2.toFixed(6)}`); showR(‘enz-result-hw-km’, `Km (HW) = ${hwKm.toFixed(4)} mM`); showR(‘enz-result-hw-vmax’, `Vmax (HW)= ${hwVmax.toFixed(4)} µmol/L/s`); showR(‘enz-result-eh-slope’, `Slope = ${eh.slope.toFixed(6)} (= -Km)`); showR(‘enz-result-eh-intcpt’,`Y-int = ${eh.intercept.toFixed(6)} (= Vmax)`); showR(‘enz-result-eh-r2’, `R² = ${eh.r2.toFixed(6)}`); showR(‘enz-result-eh-km’, `Km (EH) = ${ehKm.toFixed(4)} mM`); showR(‘enz-result-eh-vmax’, `Vmax (EH)= ${ehVmax.toFixed(4)} µmol/L/s`); document.getElementById(‘enz-result-kcat’).style.display=’block’; document.getElementById(‘enz-Et’).value = Et0; updateKcat(); // Charts 1-4 document.getElementById(‘enz-chart1-title’).innerHTML= `v vs [S] — Michaelis-Menten ${legHTML([ds(‘v’,v,4),ds(‘Vmax’,vmaxLine,4,true)])}`; showCanvas(‘enz-empty1′,’chart-enz-mm’); mkChart(‘chart-enz-mm’,{type:’line’,data:{labels:S.map(s=>s.toFixed(2)),datasets:[ ds(‘v (µmol/L/s)’,v,4), ds(‘Vmax’,vmaxLine,4,true) ]},options:chartOpts(‘[S] (mM)’,’v (µmol/L/s)’)}); document.getElementById(‘enz-chart2-title’).textContent=’Lineweaver-Burk (1/v vs 1/[S])’; showCanvas(‘enz-empty2′,’chart-enz-lb’); mkChart(‘chart-enz-lb’,{type:’scatter’,data:{datasets:[ {label:’1/v’,data:invS.map((x,i)=>({x,y:invV[i]})),borderColor:PAL[0],backgroundColor:PAL[0]+’66’,pointRadius:5,pointHoverRadius:7}, {label:’LB fit’,data:invS.map((x,i)=>({x,y:lbFit[i]})),type:’line’,borderColor:PAL[2],borderWidth:2,pointRadius:0,backgroundColor:’transparent’,tension:0} ]},options:chartOpts(‘1/[S] (mM⁻¹)’,’1/v (L·s/µmol)’)}); setV(‘enz-linear-row’,true); mkChart(‘chart-enz-hanes’,{type:’scatter’,data:{datasets:[ {label:'[S]/v’,data:S.map((x,i)=>({x,y:hanesY[i]})),borderColor:PAL[1],backgroundColor:PAL[1]+’66’,pointRadius:4,pointHoverRadius:6}, {label:’fit’,data:S.map((x,i)=>({x,y:hwFit[i]})),type:’line’,borderColor:PAL[6],borderWidth:2,pointRadius:0,backgroundColor:’transparent’,tension:0} ]},options:chartOpts(‘[S] (mM)’,'[S]/v (mM·L·s/µmol)’)}); mkChart(‘chart-enz-eadie’,{type:’scatter’,data:{datasets:[ {label:’v vs v/[S]’,data:eadieX.map((x,i)=>({x,y:v[i]})),borderColor:PAL[3],backgroundColor:PAL[3]+’66’,pointRadius:4,pointHoverRadius:6}, {label:’fit’,data:eadieX.map((x,i)=>({x,y:ehFit[i]})),type:’line’,borderColor:PAL[7],borderWidth:2,pointRadius:0,backgroundColor:’transparent’,tension:0} ]},options:chartOpts(‘v/[S] (µmol/L/s/mM)’,’v (µmol/L/s)’)}); // Depletion: run from sEnd until [S]→0 automatically const dep = runDepletion(sEnd, (5*Km/(Vmax*60))/200); setV(‘enz-depletion-row’, true); setV(‘enz-dep-table-card’, true); mkChart(‘chart-enz-dep-s’,{type:’line’,data:{labels:dep.tDep.map(t=>t.toFixed(3)), datasets:[ds(‘[S] (mM)’,dep.sDep,5)]},options:chartOpts(‘Time (min)’,'[S] (mM)’)}); mkChart(‘chart-enz-dep-v’,{type:’line’,data:{labels:dep.tDep.map(t=>t.toFixed(3)), datasets:[ds(‘v (µmol/L/min)’,dep.vDep,1)]},options:chartOpts(‘Time (min)’,’v (µmol/L/min)’)}); // Kinetics table (range) const cols=[‘[S] (mM)’,’v (µmol/L/s)’,’1/[S] (mM⁻¹)’,’1/v (L·s/µmol)’,'[S]/v’,’v/[S]’]; const rows=S.map((s,i)=>[s,v[i],invS[i],invV[i],hanesY[i],eadieX[i]]); enzData_={columns:cols,rows}; fillTable(‘enz-thead’,’enz-tbody’,cols,rows); document.getElementById(‘enz-table-title’).textContent=’📋 Michaelis-Menten Data Table’; // Depletion table const depCols=[‘Time (min)’,'[S] (mM)’,’v (µmol/L/min)’]; const depRows=dep.tDep.map((t,i)=>[t, dep.sDep[i], dep.vDep[i]]); enzDepData_={columns:depCols,rows:depRows}; fillTable(‘enz-dep-thead’,’enz-dep-tbody’,depCols,depRows); } // ── COMPETITIVE INHIBITION ─────────────────────────────────────── } else if(model===’mm-comp’){ const v0 = S.map(s => k3*Et0*s/(Km+s)); // Competitive: Km_app = Km(1+[I]/Ki), Vmax unchanged const appKm = Km*(1+Iconc/Ki); const appVmax = Vmax; const vi = S.map(s => k3*Et0*s/(appKm+s)); const labelI = `Competitive [I]=${Iconc} mM`; showR(‘enz-result-vmax’, `Vmax = ${Vmax.toFixed(4)} µmol/L/s (unchanged)`); showR(‘enz-result-km’, `Km (app) = ${appKm.toFixed(4)} mM`); showR(‘enz-result-slope’,`Km (true) = ${Km.toFixed(4)} mM`); showR(‘enz-result-intcpt’,`k₃ = ${k3.toFixed(4)} s⁻¹ | [E]₀ = ${Et0.toFixed(4)} µM`); showR(‘enz-result-app’, `Ki = ${Ki.toFixed(4)} mM | [I] = ${Iconc.toFixed(4)} mM`); // Chart 1: v vs [S] inhibition comparison document.getElementById(‘enz-chart1-title’).innerHTML= `v vs [S] — Competitive Inhibition ${legHTML([ds(‘No inhibitor’,v0,4),ds(labelI,vi,2)])}`; showCanvas(‘enz-empty1′,’chart-enz-mm’); mkChart(‘chart-enz-mm’,{type:’line’,data:{labels:S.map(s=>s.toFixed(2)),datasets:[ ds(‘No inhibitor’,v0,4), ds(labelI,vi,2) ]},options:chartOpts(‘[S] (mM)’,’v (µmol/L/s)’)}); // Chart 2: Lineweaver-Burk for both const invS=S.map(s=>1/s); const invV0=v0.map(x=>1/x), invVI=vi.map(x=>1/x); const lb0=linReg(invS,invV0), lbI=linReg(invS,invVI); document.getElementById(‘enz-chart2-title’).textContent=’Lineweaver-Burk (Competitive Inhibition)’; showCanvas(‘enz-empty2′,’chart-enz-lb’); mkChart(‘chart-enz-lb’,{type:’scatter’,data:{datasets:[ {label:’No inh.’,data:invS.map((x,i)=>({x,y:invV0[i]})),borderColor:PAL[4],backgroundColor:PAL[4]+’55’,pointRadius:4,pointHoverRadius:6}, {label:’LB fit (no inh)’,data:invS.map((x,i)=>({x,y:lb0.slope*x+lb0.intercept})),type:’line’,borderColor:PAL[4],borderWidth:1.5,pointRadius:0,backgroundColor:’transparent’,tension:0,borderDash:[5,3]}, {label:’With inh.’,data:invS.map((x,i)=>({x,y:invVI[i]})),borderColor:PAL[2],backgroundColor:PAL[2]+’55’,pointRadius:4,pointHoverRadius:6}, {label:’LB fit (inh)’,data:invS.map((x,i)=>({x,y:lbI.slope*x+lbI.intercept})),type:’line’,borderColor:PAL[2],borderWidth:1.5,pointRadius:0,backgroundColor:’transparent’,tension:0,borderDash:[5,3]} ]},options:chartOpts(‘1/[S] (mM⁻¹)’,’1/v (L·s/µmol)’)}); // Hide linearisation row for inhibition view setV(‘enz-linear-row’,false); const cols=[‘[S] (mM)’,’v₀ (no inh)’,’v (competitive)’,’1/[S]’,’1/v₀’,’1/v (inh)’]; const rows=S.map((s,i)=>[s,v0[i],vi[i],invS[i],invV0[i],invVI[i]]); enzData_={columns:cols,rows}; fillTable(‘enz-thead’,’enz-tbody’,cols,rows); document.getElementById(‘enz-table-title’).textContent=’📋 Competitive Inhibition Data Table’; // ── NON-COMPETITIVE INHIBITION ──────────────────────────────────── } else if(model===’mm-noncomp’){ const v0 = S.map(s => k3*Et0*s/(Km+s)); // Non-competitive: Km unchanged, Vmax_app = Vmax/(1+[I]/Ki) const alpha = 1 + Iconc/Ki; const appVmax = Vmax / alpha; const vi = S.map(s => appVmax*s/(Km+s)); const labelI = `Non-competitive [I]=${Iconc} mM`; showR(‘enz-result-vmax’, `Vmax (app) = ${appVmax.toFixed(4)} µmol/L/s`); showR(‘enz-result-km’, `Km = ${Km.toFixed(4)} mM (unchanged)`); showR(‘enz-result-slope’, `α = 1 + [I]/Ki = ${alpha.toFixed(4)}`); showR(‘enz-result-intcpt’,`k₃ = ${k3.toFixed(4)} s⁻¹ | [E]₀ = ${Et0.toFixed(4)} µM`); showR(‘enz-result-app’, `Ki = ${Ki.toFixed(4)} mM | [I] = ${Iconc.toFixed(4)} mM`); // Chart 1: v vs [S] comparison document.getElementById(‘enz-chart1-title’).innerHTML = `v vs [S] — Non-competitive Inhibition ${legHTML([ds(‘No inhibitor’,v0,4),ds(labelI,vi,2)])}`; showCanvas(‘enz-empty1′,’chart-enz-mm’); mkChart(‘chart-enz-mm’,{type:’line’,data:{labels:S.map(s=>s.toFixed(2)),datasets:[ ds(‘No inhibitor’,v0,4), ds(labelI,vi,2) ]},options:chartOpts(‘[S] (mM)’,’v (µmol/L/s)’)}); // Chart 2: Lineweaver-Burk (lines intersect on x-axis: same -1/Km, different y-intercepts) const invS=S.map(s=>1/s); const invV0=v0.map(x=>1/x), invVI=vi.map(x=>1/x); const lb0=linReg(invS,invV0), lbI=linReg(invS,invVI); document.getElementById(‘enz-chart2-title’).textContent=’Lineweaver-Burk (Non-competitive Inhibition)’; showCanvas(‘enz-empty2′,’chart-enz-lb’); mkChart(‘chart-enz-lb’,{type:’scatter’,data:{datasets:[ {label:’No inh.’,data:invS.map((x,i)=>({x,y:invV0[i]})),borderColor:PAL[4],backgroundColor:PAL[4]+’55’,pointRadius:4,pointHoverRadius:6}, {label:’LB fit (no inh)’,data:invS.map((x,i)=>({x,y:lb0.slope*x+lb0.intercept})),type:’line’,borderColor:PAL[4],borderWidth:1.5,pointRadius:0,backgroundColor:’transparent’,tension:0,borderDash:[5,3]}, {label:’With inh.’,data:invS.map((x,i)=>({x,y:invVI[i]})),borderColor:PAL[2],backgroundColor:PAL[2]+’55’,pointRadius:4,pointHoverRadius:6}, {label:’LB fit (inh)’,data:invS.map((x,i)=>({x,y:lbI.slope*x+lbI.intercept})),type:’line’,borderColor:PAL[2],borderWidth:1.5,pointRadius:0,backgroundColor:’transparent’,tension:0,borderDash:[5,3]} ]},options:chartOpts(‘1/[S] (mM⁻¹)’,’1/v (L·s/µmol)’)}); setV(‘enz-linear-row’,false); setV(‘enz-depletion-row’,false); setV(‘enz-dep-table-card’,false); const cols=[‘[S] (mM)’,’v₀ (no inh)’,’v (non-comp)’,’1/[S]’,’1/v₀’,’1/v (inh)’]; const rows=S.map((s,i)=>[s,v0[i],vi[i],invS[i],invV0[i],invVI[i]]); enzData_={columns:cols,rows}; fillTable(‘enz-thead’,’enz-tbody’,cols,rows); document.getElementById(‘enz-table-title’).textContent=’📋 Non-competitive Inhibition Data Table’; } }