-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg-waveform.cpp
More file actions
714 lines (662 loc) · 27.2 KB
/
g-waveform.cpp
File metadata and controls
714 lines (662 loc) · 27.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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
/*
Copyright (C) 2011 Georgia Institute of Technology
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* README
* This module takes an external ASCII formatted file as input. The file should have
* four columns with units in Amps and Siemens:
* absolute_current AMPA GABA (NMDA)
* There should be one value for each time step and the total length of the stimulus
* is determined by using the real-time period specified in the System->Control Panel.
* If you change the real-time period, the length of the trial is recomputed. This
* module automatically pauses itself when the protocol is complete.
*
* If you are using the Data Recorder, be sure to open the Data Recorder AFTER you open
* this module or RTXI will crash. This module increments the trial number in the Data
* Recorder so that each trial will be a separate structure in the HDF5 file. If you do
* not open the Data Recorder, the module will still run as designed. This module will
* automatically start and stop the Data Recorder. You must make sure to specify a data
* filename and select the data you want to save.
*
* Use the checkboxes to select a combination of dynamic clamp stimuli and/or TTL pulses.
* The dynamic clamp stimuli can be further filtered by using the checkboxes to make only
* certain conductances (or current) active. The dynamic clamp output and the TTL pulses
* are on two separate channels and must be assigned to the correct DAQ channels using
* the System->Connector.
*
* There are both internal and external holding current parameters. The internal one is
* specified using the "Holding Current (pA)" field in this module's GUI and is active
* between repeated trials. When the external holding current is activated using the
* checkbox, you must provide the instance ID of the correct holding current module in
* the "Ihold ID" field. You will probably want to manually start the external Ihold
* module first. When this dynamic clamp module unpauses, it will pause the
* Ihold module, and vice versa.
*/
#include <g-waveform.h>
#include <basicplot.h>
#include <main_window.h>
extern "C" Plugin::Object *createRTXIPlugin(void)
{
return new Gwaveform();
}
static DefaultGUIModel::variable_t
vars[] = {
{ "Vm (mV)", "Membrane Potential", DefaultGUIModel::INPUT, },
{ "Command", "Total Current", DefaultGUIModel::OUTPUT, }, // output(0)
{ "AMPA Current", "AMPA Current", DefaultGUIModel::OUTPUT, }, // output(1)
{ "GABA Current", "GABA Current", DefaultGUIModel::OUTPUT, }, // output(2)
{ "NMDA Current", "NMDA Current", DefaultGUIModel::OUTPUT, }, // output(3)
{ "Laser TTL", "Laser TTL", DefaultGUIModel::OUTPUT, }, // output(4)
{
"Length (s)",
"Length of trial is computed from the real-time period and the file size",
DefaultGUIModel::STATE,
},
{ "Comment", "Comment", DefaultGUIModel::COMMENT },
{
"Stimulus File Name",
"ASCII file containing conductance waveform with values in siemens",
DefaultGUIModel::COMMENT
},
{
"Data File Name",
"ASCII file containing conductance waveform with values in siemens",
DefaultGUIModel::COMMENT
},
{
"Ihold ID", "Instance ID of holding current module",
DefaultGUIModel::PARAMETER | DefaultGUIModel::INTEGER,
},
{
"AMPA Rev (mV)", "Reversal Potential (mV) for AMPA",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"AMPA Gain", "Gain to multiply AMPA conductance values by",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"GABA Rev (mV)", "Reversal Potential (mV) for GABA",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"GABA Gain", "Gain to multiply GABA conductance values by",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"NMDA Rev (mV)", "Reversal Potential (mV) for NMDA",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"NMDA P1", "NMDA P1", DefaultGUIModel::PARAMETER
| DefaultGUIModel::DOUBLE,
},
{
"NMDA P2", "NMDA P2", DefaultGUIModel::PARAMETER
| DefaultGUIModel::DOUBLE,
},
{
"NMDA Gain", "Gain to multiply NMDA conductance values by",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"Wait time (s)", "Time to wait between trials",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"Holding Current (pA)",
"Current to inject while waiting between trials",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"Laser TTL Duration (s)", "Duration of pulse",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"Laser TTL Pulses (#)", "Number of pulses",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"Laser TTL Freq (Hz)", "Frequency measured between pulse onsets",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"Laser TTL Delay (s)", "Time within trial to start pulse train",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE,
},
{
"Repeat", "Number of trials", DefaultGUIModel::PARAMETER
| DefaultGUIModel::DOUBLE,
},
{ "Time (s)", "Time (s)", DefaultGUIModel::STATE, },
};
static size_t num_vars = sizeof(vars) / sizeof(DefaultGUIModel::variable_t);
Gwaveform::Gwaveform(void) : DefaultGUIModel("Gwaveform", ::vars, ::num_vars)
{
DefaultGUIModel::createGUI(vars, num_vars);
customizeGUI();
initParameters();
update( INIT );
refresh();
QTimer::singleShot(0, this, SLOT(resizeMe()));
}
void Gwaveform::customizeGUI(void)
{
setWhatsThis(
"<p><b>Waveform:</b><br>This module takes an external ASCII formatted file as input. The file should have"
" four columns with units in Amps and Siemens: absolute_current AMPA GABA (NMDA)<br><br>"
" There should be one value for each time step and the total length of the stimulus"
" is determined by using the real-time period specified in the System->Control Panel."
" If you change the real-time period, the length of the trial is recomputed. This"
" module automatically pauses itself when the protocol is complete.<br><br>"
" If you are using the Data Recorder, be sure to open the Data Recorder AFTER you open"
" this module or RTXI will crash. This module increments the trial number in the Data"
" Recorder so that each trial will be a separate structure in the HDF5 file. If you do"
" not open the Data Recorder, the module will still run as designed. This module will"
" automatically start and stop the Data Recorder. You must make sure to specify a data"
" filename and select the data you want to save.<br><br>"
" Use the checkboxes to select a combination of dynamic clamp stimuli and/or TTL pulses."
" The dynamic clamp stimuli can be further filtered by using the checkboxes to make only"
" certain conductances (or current) active. The dynamic clamp output and the TTL pulses"
" are on two separate channels and must be assigned to the correct DAQ channels using"
" the System->Connector.<br><br>"
" There are both internal and external holding current parameters. The internal one is"
" specified using the 'Holding Current (pA)' field in this module's GUI and is active"
" between repeated trials. When the external holding current is activated using the"
" checkbox, you must provide the instance ID of the correct holding current module in"
" the 'Ihold ID' field. You will probably want to manually start the external Ihold"
" module first. When this dynamic clamp module unpauses, it will pause the"
" Ihold module, and vice versa."
"</p>");
QGridLayout *customLayout = DefaultGUIModel::getLayout();
// create custom GUI components
QGroupBox *fileBox = new QGroupBox("File:");
QHBoxLayout *fileBoxLayout = new QHBoxLayout;
fileBox->setLayout(fileBoxLayout);
QButtonGroup *fileButtons = new QButtonGroup;
QPushButton *loadBttn = new QPushButton("Load File");
QPushButton *previewBttn = new QPushButton("Preview File");
fileBoxLayout->addWidget(loadBttn);
fileBoxLayout->addWidget(previewBttn);
fileButtons->addButton(loadBttn);
fileButtons->addButton(previewBttn);
QObject::connect(loadBttn, SIGNAL(clicked()), this, SLOT(loadFile()));
QObject::connect(previewBttn, SIGNAL(clicked()), this, SLOT(previewFile()));
QGroupBox *optionRow1 = new QGroupBox("Active Conductances");
QHBoxLayout *optionRow1Layout = new QHBoxLayout;
optionRow1->setLayout(optionRow1Layout);
optionRow1->setToolTip("Select which conductances will be active in the protocol");
QCheckBox *currentCheckBox = new QCheckBox("Current");
QCheckBox *ampaCheckBox = new QCheckBox("AMPA");
QCheckBox *gabaCheckBox = new QCheckBox("GABA");
QCheckBox *nmdaCheckBox = new QCheckBox("NMDA");
optionRow1Layout->addWidget(currentCheckBox);
optionRow1Layout->addWidget(ampaCheckBox);
optionRow1Layout->addWidget(gabaCheckBox);
optionRow1Layout->addWidget(nmdaCheckBox);
currentCheckBox->setChecked(false); // set some defaults
ampaCheckBox->setChecked(true);
gabaCheckBox->setChecked(true);
nmdaCheckBox->setChecked(false);
QObject::connect(currentCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleCurrent(bool)));
QObject::connect(ampaCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleAMPA(bool)));
QObject::connect(gabaCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleGABA(bool)));
QObject::connect(nmdaCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleNMDA(bool)));
QGroupBox *optionRow2 = new QGroupBox("Active Stimuli");
QHBoxLayout *optionRow2Layout = new QHBoxLayout;
optionRow2->setLayout(optionRow2Layout);
optionRow2->setToolTip("Select which stimuli will be active in the protocol");
QCheckBox *clampCheckBox = new QCheckBox("Dynamic Clamp");
QCheckBox *laserCheckBox = new QCheckBox("Laser TTL");
IholdCheckBox = new QCheckBox("Ext. Holding Current");
optionRow2Layout->addWidget(clampCheckBox);
optionRow2Layout->addWidget(laserCheckBox);
optionRow2Layout->addWidget(IholdCheckBox);
clampCheckBox->setChecked(true); // set some defaults
laserCheckBox->setChecked(false);
IholdCheckBox->setChecked(false);
IholdCheckBox->setEnabled(false);
QObject::connect(clampCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleClamp(bool)));
QObject::connect(laserCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleLaserTTL(bool)));
QObject::connect(IholdCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleIhold(bool)));
QGroupBox *optionRow3 = new QGroupBox("Data Recorder");
QHBoxLayout *optionRow3Layout = new QHBoxLayout;
optionRow3->setLayout(optionRow3Layout);
optionRow3->setToolTip("Select whether to sync with the data recorder");
QCheckBox *recordCheckBox = new QCheckBox("Sync Data");
optionRow3Layout->addWidget(recordCheckBox);
recordCheckBox->setChecked(true); // set some defaults
recordCheckBox->setEnabled(true);
QObject::connect(recordCheckBox, SIGNAL(toggled(bool)), this, SLOT(toggleRecord(bool)));
QObject::connect(DefaultGUIModel::pauseButton, SIGNAL(toggled(bool)), DefaultGUIModel::modifyButton, SLOT(setEnabled(bool)));
DefaultGUIModel::pauseButton->setToolTip("Start/Stop dynamic clamp protocol");
DefaultGUIModel::modifyButton->setToolTip("Commit changes to parameter values");
DefaultGUIModel::unloadButton->setToolTip("Close plugin");
// add custom GUI components to layout above default_gui_model components
customLayout->addWidget(fileBox, 0, 0);
// add custom components to layout below default_gui_model components
customLayout->addWidget(optionRow1, 2, 0);
customLayout->addWidget(optionRow2, 3, 0);
customLayout->addWidget(optionRow3, 4, 0);
setLayout(customLayout);
}
Gwaveform::~Gwaveform(void) {}
void Gwaveform::execute(void)
{
Vm = input(0); // input is in V
systime = count * dt; // module running time, s
if (trial < maxtrials) { // run trial
if (trialtimecount * dt < delay) {
output(0) = Ihold;
} else {
if (clampon == true) { // determine injected current
if (ampaon == true) {
output(1) = -1 * AMPAwave[idx] * (Vm - AMPArev) * AMPAgain;
} else {
output(1) = 0;
}
if (gabaon == true) {
output(2) = -1 * GABAwave[idx] * (Vm - GABArev) * GABAgain;
} else {
output(2) = 0;
}
if (nmdaon == true) {
output(3) = -1 * NMDAwave[idx] * (Vm - NMDArev) * 1 / (1 + P1
* exp(-P2 * Vm)) * NMDAgain;
} else {
output(3) = 0;
}
output(0) = output(1) + output(2) + output(3);
if (currenton == true) {
output(0) = output(0) + currentwave[idx];
}
} else if (clampon == false) {
output(1) = 0;
output(2) = 0;
output(3) = 0;
output(0) = 0;
}
if (laserTTLon == true) { // determine TTL stimulus
output(4) = laserStim[idx];
} else if (laserTTLon == false) {
output(4) = 0;
}
if (laserTTLon == true or clampon == true)
idx++;
} // end single trial
} else { // all trials are done, send signal to holding current module, and pause
if (recordon) DataRecorder::stopRecording();
output(5) = 1;
pause(true);
} // end protocol
count++; // increment count to measure total module running time
trialtimecount++; // increment count to measure time within single trial
if (systime > triallength * (trial + 1)) {
if (recordon) DataRecorder::stopRecording();
trial++;
trialtimecount = 0;
idx = 0;
if (recordon) DataRecorder::startRecording();
}
}
void Gwaveform::update(Gwaveform::update_flags_t flag)
{
switch (flag) {
case INIT:
setState("Length (s)", stimlength); // initialized in s, display in s
setComment("Comment", userComment);
setComment("Stimulus File Name", gFile);
setComment("Data File Name", dFile);
setParameter("Ihold ID", QString::number(IholdID));
setParameter("GABA Rev (mV)", QString::number(GABArev * 1000)); // convert from V to mV
setParameter("GABA Gain", QString::number(GABAgain));
setParameter("AMPA Rev (mV)", QString::number(AMPArev * 1000)); // convert from V to mV
setParameter("AMPA Gain", QString::number(AMPAgain));
setParameter("NMDA Rev (mV)", QString::number(NMDArev * 1000)); // convert from V to mV
setParameter("NMDA Gain", QString::number(NMDAgain));
setParameter("NMDA P1", QString::number(P1));
setParameter("NMDA P2", QString::number(P2));
setParameter("Wait time (s)", QString::number(delay));
setParameter("Holding Current (pA)", QString::number(Ihold * 1e12)); // convert from A to pA
setParameter("Repeat", QString::number(maxtrials)); // initially 1
setParameter("Laser TTL Duration (s)", QString::number(laserDuration)); // initially 1
setParameter("Laser TTL Pulses (#)", QString::number(laserNumPulses)); // initially 1
setParameter("Laser TTL Freq (Hz)", QString::number(laserFreq)); // initially 1
setParameter("Laser TTL Delay (s)", QString::number(laserDelay)); // initially 1
setState("Time (s)", systime);
DataRecorder::openFile(dFile);
break;
case MODIFY:
gFile = getComment("Stimulus File Name");
dFile = getComment("Data File Name");
userComment = getComment("Comment");
printf("Saving to new file: %s\n", dFile.toStdString().data());
DataRecorder::openFile(dFile);
IholdID = getParameter("Ihold ID").toInt();
if (IholdID > 0 && IholdID != getID()) {
IholdModule
= dynamic_cast<DefaultGUIModel*> (Settings::Manager::getInstance()->getObject(
IholdID));
IholdCheckBox->setEnabled(true);
} else {
IholdCheckBox->setEnabled(false);
}
GABArev = getParameter("GABA Rev (mV)").toDouble() / 1000; // convert from mV to V
GABAgain = getParameter("GABA Gain").toDouble();
AMPArev = getParameter("AMPA Rev (mV)").toDouble() / 1000; // convert from mV to V
AMPAgain = getParameter("AMPA Gain").toDouble();
NMDArev = getParameter("NMDA Rev (mV)").toDouble() / 1000; // convert from mV to V
NMDAgain = getParameter("NMDA Gain").toDouble();
P1 = getParameter("NMDA P1").toDouble();
P2 = getParameter("NMDA P2").toDouble();
delay = getParameter("Wait time (s)").toDouble();
Ihold = getParameter("Holding Current (pA)").toDouble() * 1e-12; // convert from pA to A
maxtrials = getParameter("Repeat").toDouble();
bookkeep();
if (getParameter("Laser TTL Duration (s)").toDouble() >= (getParameter(
"Laser TTL Freq (Hz)").toDouble())) {
QMessageBox::critical(
this,
"Dynamic Clamp",
tr(
"The laser TTL pulses will overlap with the specified pulse duration and frequency.\n"));
} else if (1 / getParameter("Laser TTL Freq (Hz)").toDouble()
* (getParameter("Laser TTL Pulses (#)").toDouble() - 1) + getParameter(
"Laser TTL Duration (s)").toDouble() + getParameter(
"Laser TTL Delay (s)").toDouble() > stimlength) {
QMessageBox::critical(this, "Dynamic Clamp", tr(
"The laser TTL pulse train is too long for the trial length.\n"));
} else {
laserDuration = getParameter("Laser TTL Duration (s)").toDouble();
laserFreq = getParameter("Laser TTL Freq (Hz)").toDouble();
laserNumPulses = getParameter("Laser TTL Pulses (#)").toDouble();
laserDelay = getParameter("Laser TTL Delay (s)").toDouble();
makeLaserTTL();
}
loadFile(gFile);
break;
case PAUSE:
output(0) = 0; // stop command in case pause occurs in the middle of command
printf("Protocol paused.\n");
if (Iholdon) {
IholdModule->setActive(true);
IholdModule->refresh();
}
break;
case UNPAUSE:
bookkeep();
output(5) = 1;
if (recordon) DataRecorder::startRecording();
printf("Starting protocol.\n");
if (Iholdon) {
IholdModule->setActive(false);
IholdModule->refresh();
}
break;
case PERIOD:
dt = RT::System::getInstance()->getPeriod() * 1e-9;
printf("New real-time period: %f\n", dt);
stimlength = GABAwave.size() * dt;
loadFile(gFile);
default:
break;
}
}
// custom functions
void Gwaveform::initParameters()
{
stimlength = 0; // seconds
maxtrials = 1;
Ihold = 0; // Amps
delay = 1; // seconds
GABArev = -.070; // V
GABAgain = 1;
AMPArev = 0; // V
AMPAgain = 1;
NMDArev = 0; // V
NMDAgain = 1;
P1 = .002;
P2 = .109;
dt = RT::System::getInstance()->getPeriod() * 1e-9; // s
gFile = "No file loaded.";
dFile = "default.h5";
userComment = "None.";
laserDuration = .25; // s
laserNumPulses = 1;
laserFreq = 1; // Hz
laserDelay = .5; // s
currenton = false;
ampaon = true;
gabaon = true;
nmdaon = false;
clampon = true;
laserTTLon = false;
IholdID = 0;
Iholdon = false;
recordon = true;
ready = false;
pauseButton->setEnabled(ready);
bookkeep();
makeLaserTTL();
}
void Gwaveform::bookkeep()
{
trial = 0;
count = 0;
trialtimecount = 0;
systime = 0;
idx = 0;
triallength = stimlength + delay;
}
void Gwaveform::toggleCurrent(bool on)
{
currenton = on;
}
void Gwaveform::toggleAMPA(bool on)
{
ampaon = on;
}
void Gwaveform::toggleGABA(bool on)
{
gabaon = on;
}
void Gwaveform::toggleNMDA(bool on)
{
nmdaon = on;
}
void Gwaveform::toggleClamp(bool on)
{
clampon = on;
}
void Gwaveform::toggleLaserTTL(bool on)
{
laserTTLon = on;
}
void Gwaveform::toggleIhold(bool on)
{
Iholdon = on;
}
void Gwaveform::toggleRecord(bool on)
{
recordon = on;
}
void Gwaveform::makeLaserTTL()
{
laserStim.clear();
for (int i = 0; i < laserDelay / dt; i++) { // initial delay in trial before starting laser
laserStim.push_back(0);
}
for (int n = 0; n < laserNumPulses; n++) {
for (int i = 0; i < laserDuration / dt; i++) {
laserStim.push_back(5);
}
// fill in zeros for frequency
for (int i = 0; i < ((1 / laserFreq) - laserDuration) / dt; i++) {
laserStim.push_back(0);
}
}
double remainder = stimlength - (laserDelay + 1 / laserFreq * (laserNumPulses
- 1) + laserDuration);
for (int i = 0; i < remainder / dt; i++) { // pad the rest of the stimlength
laserStim.push_back(0);
}
for (int i = 0; i < delay / dt; i++) { // overall delay in trial
laserStim.push_back(0);
}
}
void Gwaveform::loadFile()
{
QFileDialog* fd = new QFileDialog(this,"Conductance waveform file");
fd->setFileMode(QFileDialog::AnyFile);
fd->setViewMode(QFileDialog::Detail);
QString fileName;
if (fd->exec() == QDialog::Accepted) {
QStringList fileNames = fd->selectedFiles();
if (!fileNames.isEmpty()) fileName = fileNames.takeFirst();
printf("Loading new file: %s\n", fileName.toStdString().data());
gFile = fileName;
setComment("Stimulus File Name", fileName);
currentwave.clear();
GABAwave.clear();
AMPAwave.clear();
NMDAwave.clear();
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
double value;
while (!stream.atEnd()) {
stream >> value;
currentwave.push_back(value);
stream >> value;
AMPAwave.push_back(value);
stream >> value;
GABAwave.push_back(value);
stream >> value;
NMDAwave.push_back(value);
}
}
stimlength = GABAwave.size() * dt;
setState("Length (s)", stimlength); // initialized in s, display in s
// pad waveform to account for wait between trials
for (int i = 0; i < delay / dt; i++) {
currentwave.push_back(0);
GABAwave.push_back(0);
AMPAwave.push_back(0);
NMDAwave.push_back(0);
}
ready = true;
} else {
setComment("Stimulus File Name", "No file loaded.");
ready = false;
}
pauseButton->setEnabled(ready);
}
void Gwaveform::loadFile(QString fileName)
{
if (fileName == "No file loaded.") {
printf("No file name specified. \n");
setComment("Stimulus File Name", fileName);
ready = false;
return;
} else {
printf("Loading new file: %s\n", fileName.toStdString().data());
currentwave.clear();
GABAwave.clear();
AMPAwave.clear();
NMDAwave.clear();
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
double value;
while (!stream.atEnd()) {
stream >> value;
currentwave.push_back(value);
stream >> value;
AMPAwave.push_back(value);
stream >> value;
GABAwave.push_back(value);
stream >> value;
NMDAwave.push_back(value);
}
}
stimlength = GABAwave.size() * dt;
setState("Length (s)", stimlength); // initialized in s, display in s
// pad waveform with to account for wait between trials
for (int i = 0; i < delay / dt; i++) {
currentwave.push_back(0);
GABAwave.push_back(0);
AMPAwave.push_back(0);
NMDAwave.push_back(0);
}
ready = true;
setComment("Stimulus File Name", fileName);
}
pauseButton->setEnabled(ready);
}
void Gwaveform::previewFile()
{
double* time = new double[static_cast<int> (GABAwave.size())];
double* currentData = new double[static_cast<int> (currentwave.size())];
double* gabaData = new double[static_cast<int> (GABAwave.size())];
double* ampaData = new double[static_cast<int> (AMPAwave.size())];
double* nmdaData = new double[static_cast<int> (NMDAwave.size())];
for (int i = 0; i < GABAwave.size(); i++) {
time[i] = dt * i;
currentData[i] = currentwave[i];
gabaData[i] = GABAwave[i];
ampaData[i] = AMPAwave[i];
nmdaData[i] = NMDAwave[i];
}
PlotDialog *current = new PlotDialog(this, "Current", time, currentData,
currentwave.size());
current->show();
PlotDialog *gaba = new PlotDialog(this, "GABA Conductance", time, gabaData,
GABAwave.size());
gaba->show();
PlotDialog *ampa = new PlotDialog(this, "AMPA Conductance", time, ampaData,
AMPAwave.size());
ampa->show();
PlotDialog *nmda = new PlotDialog(this, "NMDA Conductance", time, nmdaData,
NMDAwave.size());
nmda->show();
}
bool Gwaveform::OpenFile(QString FName)
{
dataFile.setFileName(FName);
if (dataFile.exists()) {
switch (QMessageBox::warning(this, "Dynamic Clamp", tr(
"This file already exists: %1.\n").arg(FName), "Overwrite", "Append",
"Cancel", 0, 2)) {
case 0: // overwrite
dataFile.remove();
if (!dataFile.open(QIODevice::Unbuffered | QIODevice::WriteOnly)) {
return false;
}
break;
case 1: // append
if (!dataFile.open(QIODevice::Unbuffered | QIODevice::WriteOnly | QIODevice::Append)) {
return false;
}
break;
case 2: // cancel
return false;
break;
}
} else {
if (!dataFile.open(QIODevice::Unbuffered | QIODevice::WriteOnly))
return false;
}
stream.setDevice(&dataFile);
// stream.setPrintableData(false); // write binary
printf("File opened: %s\n", FName.toStdString().data());
return true;
}