-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic-Calcium-simulator.html
More file actions
668 lines (583 loc) · 20.2 KB
/
Copy pathBasic-Calcium-simulator.html
File metadata and controls
668 lines (583 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Interactive Basic Calcium Dynamics Simulator</title>
<!-- Bootstrap CSS (layout & basic styling) -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-J23ES8WVTN"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-J23ES8WVTN');
</script>
<!-- Chart.js (for plotting) -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
margin: 20px;
font-family: sans-serif;
}
h1 {
margin-bottom: 0.5em;
}
.control-section {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
label {
font-weight: 500;
}
.chart-row {
margin-bottom: 30px;
}
/* Minimal chart style: remove major gridlines, keep axis lines only. */
.chartjs-grid line {
display: none;
}
.chartjs-grid path {
display: none;
}
.chartjs-axis-line {
stroke: #333; /* axis line color */
stroke-width: 1;
shape-rendering: crispEdges;
}
</style>
</head>
<body>
<nav class="navbar navbar-light bg-white shadow-sm mb-3">
<div class="container">
<a class="navbar-brand fw-bold" href="index.html">SignalLab</a>
<span class="navbar-text d-none d-md-inline">
Interactive experiments in cell and neural signalling
</span>
</div>
</nav>
<div class="sim-container">
<!-- Title and Intro -->
<div class="row">
<div class="col-12">
<h1 class="mt-3 mb-3">Interactive Basic Calcium Dynamics Simulator</h1>
<p>
This interactive simulator runs a repeating 2-second sweep simulating presynaptic Ca<sup>2+</sup> dynamics in a basic well-mixed single compartment model.
One can use this to explore how different components of Calcium homeostasis such as Ca<sup>2+</sup> extrusion or buffering parameters, and factors such as exogenous Calcium buffers/dyes influence free Ca2+ transients.
</p>
<p>
<strong>Control Options (left)</strong> let you adjust the following:
</p>
<ul>
<li>Under <strong>Calcium Buffers</strong> the kinetic scheme and concentration of Ca2+ buffers and indicators can be altered to match different experimental Calcium indicators</li>
<li>Under <strong>Calcium Extrusion</strong> the rate of Calcium removal can be altered. In this model we encompass all Plasma membrane Calcium removal in a single process</li>
<li>Under <strong>Calcium Influx</strong> the duration of Calcium influx, the number of action potentials and their frequency can be altered. </li>
</ul>
<p>
The top chart shows the <strong>free intracellular Ca<sup>2+</sup></strong> plotted against time, the second and third chart
show the amount of <strong>Calcium Indicator or endogenous buffer bound to Ca<sup>2+</sup></strong>.
</p>
</div>
</div>
<!-- Controls & Plots -->
<div class="row">
<!-- Left column: controls -->
<div class="col-md-4">
<div class="control-section">
<h3>Control Options</h3>
<hr>
<h4><strong>Calcium Buffers</strong></h4>
<!-- Buffer concentration slider (endogenous) -->
<div class="mb-3">
<label for="bufferConcentrationSlider" class="form-label">
Endogenous Buffer (<span id="bufferConcentrationValue">50</span> µM)
</label>
<input
type="range"
class="form-range"
id="bufferConcentrationSlider"
min="0" max="200" step="1"
value="50"
/>
</div>
<!-- Dye dropdown -->
<div class="mb-3">
<label for="dyeSelect" class="form-label">Ca<sup>2+</sup> Indicator</label>
<select class="form-select" id="dyeSelect">
<option value="none">No Ca<sup>2+</sup> Indicator</option>
<option value="ogb50"selected>OGB-1 (High affinity) </option>
<option value="F4">Fluo-4 (mid affinity) </option>
<option value="F5F">Fluo-4FF (low affinity)</option>
<option value="GCs">GCaMP6s</option>
<option value="GCf">GCaMP6f</option>
</select>
</div>
<!-- Buffer type toggle (fast/slow) for the endogenous buffer -->
<div class="mb-3">
<label for="bufferTypeSelect" class="form-label">Endogenous Buffer Type</label>
<select class="form-select" id="bufferTypeSelect">
<option value="fast" selected>Fast (e.g. Calbindin)</option>
<option value="slow">Slow (e.g. Parvalbumin)</option>
</select>
</div>
<!-- Horizontal line to separate sections -->
<hr>
<h4><strong>Calcium Extrusion</strong></h4>
<!-- Extrusion rate slider -->
<div class="mb-3">
<label for="extrusionRateSlider" class="form-label">
Extrusion Rate (<span id="extrusionRateValue">100</span> s<sup>-1</sup>)
</label>
<input
type="range"
class="form-range"
id="extrusionRateSlider"
min="0" max="300" step="1"
value="100"
/>
</div>
<!-- Horizontal line to separate sections -->
<hr>
<h4><strong>Calcium Influx</strong></h4>
<!-- Pulse Duration slider -->
<div class="mb-3">
<label for="pulseDurationSlider" class="form-label">
Ca<sup>2+</sup> Influx Duration
(<span id="pulseDurationValue">0.5</span> ms)
</label>
<input
type="range"
class="form-range"
id="pulseDurationSlider"
min="0" max="10" step="0.5"
value="0.5"
/>
</div>
<!-- Number of pulses slider -->
<div class="mb-3">
<label for="numPulsesSlider" class="form-label">
Number of Ca<sup>2+</sup> Pulses:
<span id="numPulsesValue">1</span>
</label>
<input
type="range"
class="form-range"
id="numPulsesSlider"
min="1" max="8" step="1"
value="4"
/>
</div>
<!-- Frequency selection -->
<div class="mb-3">
<label for="frequencySelect" class="form-label">Pulse Frequency (Hz)</label>
<select class="form-select" id="frequencySelect">
<option value="10" selected>10</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
<!-- Start / Pause / Reset buttons -->
<div class="mb-3">
<button class="btn btn-primary" id="startPauseBtn">Start</button>
<button class="btn btn-secondary" id="resetBtn">Reset</button>
</div>
</div>
</div>
<!-- Right column: charts -->
<div class="col-md-8">
<!-- Chart for Ca2+ -->
<div class="chart-row">
<canvas id="caChart" height="100"></canvas>
</div>
<!-- Chart for bound Calcium indicators -->
<div class="chart-row">
<canvas id="iChart" height="100"></canvas>
</div>
<!-- Chart for bound buffers -->
<div class="chart-row">
<canvas id="bChart" height="100"></canvas>
</div>
</div>
</div>
</div> <!-- /sim-container -->
<!-- Bootstrap JS (optional) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
///////////////////////////////////////////////////////////////////////////////
// GLOBAL PARAMETERS & STATES
///////////////////////////////////////////////////////////////////////////////
// Each sweep runs 0..5 s internally, but we only plot t=1..3 => a 2 s window
const maxTime = 5.0; // total sweep length (internal)
const plotMin = 1.0; // start of displayed window
const plotMax = 3.0; // end of displayed window
// Endogenous Buffer (fast or slow):
const k_on_fast = 1e6; // M^-1 s^-1
const k_off_fast = 100; // s^-1
const k_on_slow = 1e5;
const k_off_slow = 10;
let k_on = k_on_fast;
let k_off = k_off_fast;
let B_total = 50; // µM
// Dye options (approx rates for OGB-1):
const dyeKinetics = {
none: { k_on_dye: 0, k_off_dye: 0, D_total: 0 },
ogb50: { k_on_dye: 1e7, k_off_dye: 120, D_total: 100 },
F4: { k_on_dye: 1e7, k_off_dye: 240, D_total: 100 },
F5F: { k_on_dye: 1e7, k_off_dye: 500, D_total: 100 },
GCs: { k_on_dye: 4.3e6, k_off_dye: 0.69, D_total: 50 },
GCf: { k_on_dye: 9.44e6, k_off_dye: 4, D_total: 50 }
};
let k_on_dye = 0;
let k_off_dye = 0;
let D_total = 0; // µM
// State vars: [Ca, B, CaB, D, CaD]
let Ca = 0.005;
let B = 50;
let CaB = 0;
let D = 0;
let CaD = 0;
// Extrusion rate
let k_extrude = 100; // s^-1
// Multiple pulses
const baseAmplitude = 3000; // µM/s
let numPulses = 4; // 1..10
let freqHz = 10; // 10,20,50,100
let pulseDurationMs = 0.5; // 0..10 ms
let pulses = [];
// Time stepping
const dt = 0.001;
const stepsPerFrame= 20;
let currentTime = 0.0;
let isRunning = false;
let simInterval = null;
// Data arrays for Chart.js
// We'll store data only for t in [1..3].
const caData = [];
const bData = []; // now used for BOUND buffers only
const iData = []; // now used for BOUND indicator only
///////////////////////////////////////////////////////////////////////////////
// UI ELEMENTS
///////////////////////////////////////////////////////////////////////////////
const bufferConcentrationSlider = document.getElementById('bufferConcentrationSlider');
const bufferConcentrationValue = document.getElementById('bufferConcentrationValue');
const extrusionRateSlider = document.getElementById('extrusionRateSlider');
const extrusionRateValue = document.getElementById('extrusionRateValue');
const pulseDurationSlider = document.getElementById('pulseDurationSlider');
const pulseDurationValue = document.getElementById('pulseDurationValue');
const numPulsesSlider = document.getElementById('numPulsesSlider');
const numPulsesValue = document.getElementById('numPulsesValue');
const frequencySelect = document.getElementById('frequencySelect');
const dyeSelect = document.getElementById('dyeSelect');
const bufferTypeSelect = document.getElementById('bufferTypeSelect');
const startPauseBtn = document.getElementById('startPauseBtn');
const resetBtn = document.getElementById('resetBtn');
// Initialize labels
bufferConcentrationValue.textContent = bufferConcentrationSlider.value;
extrusionRateValue.textContent = extrusionRateSlider.value;
pulseDurationValue.textContent = pulseDurationSlider.value;
numPulsesValue.textContent = numPulsesSlider.value;
///////////////////////////////////////////////////////////////////////////////
// CHARTS: Ca2+ and Bound Buffers
///////////////////////////////////////////////////////////////////////////////
function createMinimalChart(canvasId, label, color, yLabel) {
const ctx = document.getElementById(canvasId).getContext('2d');
return new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label,
data: [],
borderColor: color,
backgroundColor: color.replace('1)', '0.1)'),
fill: false,
tension: 0,
pointRadius: 0
}]
},
options: {
animation: false,
responsive: true,
scales: {
x: {
type: 'linear',
// We'll display 0..(plotMax - plotMin) => 0..2
min: 0.6,
max: 1.8,
title: {
display: true,
text: 'Time (s)',
font: {
family: 'Arial', // Font family
size: 16, // Font size in pixels
weight: 'bold', // Font weight (e.g., 'normal', 'bold')
style: 'normal' // Font style (e.g., 'normal', 'italic')
}
},
grid: { display: false }
},
y: {
min: -0.1,
suggestedMax: 4,
title: {
display: true,
text: yLabel,
font: {
family: 'Arial', // Font family
size: 16, // Font size in pixels
weight: 'bold', // Font weight (e.g., 'normal', 'bold')
style: 'normal' // Font style (e.g., 'normal', 'italic')
}
},
grid: { display: false }
}
},
plugins: {
legend: { display: false }
}
}
});
}
// 1) Ca²⁺ chart
const caChart = createMinimalChart('caChart', '[Ca2+]', 'rgba(52, 152, 219, 1) ', 'Free Ca2+ Concentration (µM)');
// 2) Bound buffer chart
const bChart = createMinimalChart('bChart', '[Bound]', 'rgba(231, 76, 60, 1) ', 'Bound Buffers (µM)');
// 3) Bound Indicator chart
const iChart = createMinimalChart('iChart', '[indicator]', 'rgba(46, 204, 113, 1) ', 'Bound Indicator (µM)');
///////////////////////////////////////////////////////////////////////////////
// COMPUTE PULSES
///////////////////////////////////////////////////////////////////////////////
function computePulses() {
pulses = [];
const period = 1 / freqHz; // sec between pulses
const dtPulse = pulseDurationMs / 1000; // s
for (let i = 0; i < numPulses; i++) {
let start = 2.0 + i * period;
let end = start + dtPulse;
// Only add if start < 5 s
if (start < maxTime) {
pulses.push({ start, end });
}
}
}
///////////////////////////////////////////////////////////////////////////////
// DERIVATIVES & RUNGE-KUTTA 4
///////////////////////////////////////////////////////////////////////////////
function derivatives(t, state) {
// [Ca, B, CaB, D, CaD]
const [CaLocal, BLocal, CaBLocal, DLocal, CaDLocal] = state;
// Check pulses
let J_influx = 0.0;
for (let p of pulses) {
if (t >= p.start && t < p.end) {
J_influx = baseAmplitude;
break;
}
}
const k_on_µM = k_on / 1e6;
const k_on_dye_µM = k_on_dye / 1e6;
// Endogenous buffer flux
const forward1 = k_on_µM * CaLocal * BLocal;
const reverse1 = k_off * CaBLocal;
const J_bind1 = forward1 - reverse1;
// Dye buffer flux
const forward2 = k_on_dye_µM * CaLocal * DLocal;
const reverse2 = k_off_dye * CaDLocal;
const J_bind2 = forward2 - reverse2;
// dCa/dt
let dCa = J_influx - (k_extrude * CaLocal) - (J_bind1 + J_bind2);
// Endogenous buffer
let dB = -J_bind1;
let dCaB = J_bind1;
// Dye buffer
let dD = -J_bind2;
let dCaD = J_bind2;
return [dCa, dB, dCaB, dD, dCaD];
}
function rk4Step(t, state, dt) {
const k1 = derivatives(t, state);
const st2 = state.map((val, i) => val + 0.5 * dt * k1[i]);
const k2 = derivatives(t + 0.5*dt, st2);
const st3 = state.map((val, i) => val + 0.5 * dt * k2[i]);
const k3 = derivatives(t + 0.5*dt, st3);
const st4 = state.map((val, i) => val + dt * k3[i]);
const k4 = derivatives(t + dt, st4);
return state.map(
(val, i) => val + (dt/6)*(k1[i] + 2*k2[i] + 2*k3[i] + k4[i])
);
}
///////////////////////////////////////////////////////////////////////////////
// SIMULATION LOOP
///////////////////////////////////////////////////////////////////////////////
function simulationStep() {
if (!isRunning) return;
for (let i = 0; i < stepsPerFrame; i++) {
// End of sweep => auto-restart
if (currentTime >= maxTime) {
restartSweep();
break;
}
// Integration step
let state = [Ca, B, CaB, D, CaD];
state = rk4Step(currentTime, state, dt);
[Ca, B, CaB, D, CaD] = state;
currentTime += dt;
// Only store data if 1 <= t <= 3
if (currentTime >= plotMin && currentTime <= plotMax) {
const xVal = currentTime - plotMin; // so 1 => 0, 3 => 2
caData.push({ x: xVal, y: Ca });
// Bound buffers = CaB
bData.push({ x: xVal, y: (CaB) });
// Bound indicator = CaD
iData.push({ x: xVal, y: (CaD) });
}
}
// Update the three charts
caChart.data.datasets[0].data = caData;
caChart.update();
bChart.data.datasets[0].data = bData;
bChart.update();
iChart.data.datasets[0].data = iData;
iChart.update();
}
///////////////////////////////////////////////////////////////////////////////
// RESTART SWEEP AT t=5 s
///////////////////////////////////////////////////////////////////////////////
function restartSweep() {
currentTime = 0.0;
Ca = 0.05;
B = B_total;
CaB = 0;
D = D_total;
CaD = 0;
// Clear data arrays
caData.length = 0;
bData.length = 0;
iData.length = 0;
}
///////////////////////////////////////////////////////////////////////////////
// RESET
///////////////////////////////////////////////////////////////////////////////
function resetSimulation() {
pauseSimulation();
restartSweep();
caChart.update();
bChart.update();
iChart.update();
}
///////////////////////////////////////////////////////////////////////////////
// START / PAUSE
///////////////////////////////////////////////////////////////////////////////
function startSimulation() {
if (!isRunning) {
isRunning = true;
startPauseBtn.textContent = "Pause";
}
}
function pauseSimulation() {
isRunning = false;
startPauseBtn.textContent = "Start";
}
///////////////////////////////////////////////////////////////////////////////
// DYE PARAMETER
///////////////////////////////////////////////////////////////////////////////
function setDyeParameters(dyeChoice) {
const dy = dyeKinetics[dyeChoice] || dyeKinetics.none;
k_on_dye = dy.k_on_dye;
k_off_dye = dy.k_off_dye;
D_total = dy.D_total;
}
///////////////////////////////////////////////////////////////////////////////
// EVENT LISTENERS
///////////////////////////////////////////////////////////////////////////////
// 1) Endogenous buffer concentration
bufferConcentrationSlider.addEventListener('input', () => {
B_total = parseFloat(bufferConcentrationSlider.value);
bufferConcentrationValue.textContent = B_total;
resetSimulation();
startSimulation();
});
// 2) Extrusion rate
extrusionRateSlider.addEventListener('input', () => {
k_extrude = parseFloat(extrusionRateSlider.value);
extrusionRateValue.textContent = k_extrude;
resetSimulation();
startSimulation();
});
// 3) Pulse duration (ms)
pulseDurationSlider.addEventListener('input', () => {
pulseDurationMs = parseFloat(pulseDurationSlider.value);
pulseDurationValue.textContent = pulseDurationMs;
computePulses();
resetSimulation();
startSimulation();
});
// 4) Number of pulses
numPulsesSlider.addEventListener('input', () => {
numPulses = parseInt(numPulsesSlider.value);
numPulsesValue.textContent = numPulses;
computePulses();
resetSimulation();
startSimulation();
});
// 5) Frequency
frequencySelect.addEventListener('change', () => {
freqHz = parseFloat(frequencySelect.value);
computePulses();
resetSimulation();
startSimulation();
});
// 6) Dye selection
dyeSelect.addEventListener('change', () => {
setDyeParameters(dyeSelect.value);
resetSimulation();
startSimulation();
});
// 7) Buffer type: fast/slow
bufferTypeSelect.addEventListener('change', () => {
const val = bufferTypeSelect.value;
if (val === 'fast') {
k_on = k_on_fast;
k_off = k_off_fast;
} else {
k_on = k_on_slow;
k_off = k_off_slow;
}
resetSimulation();
startSimulation();
});
// 8) Start/Pause
startPauseBtn.addEventListener('click', () => {
if (!isRunning) {
startSimulation();
} else {
pauseSimulation();
}
});
// 9) Reset
resetBtn.addEventListener('click', () => {
resetSimulation();
});
///////////////////////////////////////////////////////////////////////////////
// INIT & MAIN LOOP
///////////////////////////////////////////////////////////////////////////////
function initSimulation() {
setDyeParameters('ogb50');
computePulses();
restartSweep();
startSimulation(); // Automatically start simulation on page load
}
function main() {
simInterval = setInterval(simulationStep, 16); // ~60 frames/s
}
// On page load
initSimulation();
main();
</script>
</body>
</html>