-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHH-model.cpp
226 lines (164 loc) · 7.88 KB
/
HH-model.cpp
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
/*
FILE NAME: HH-model.cpp
DESCRIPTION: This code uses GSL to calculate the solution to the Hodgking Huxley Model
[!] The system must be normalized to get the feeling of the biophysical behavior
[!] See the txt files to more info about the model
AUTHOR: Daniel Mejia Raigosa
E-MAIL: [email protected]
GITHUB: http://github.com/Daniel-M/Hodgking-Huxley
DATE: 18 November 2014
VERSION: 3.0
LICENSE
This file is part of "Hodgking-Huxley".
"HH-model.cpp" 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.
"HH-model.cpp" 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 "HH-model.cpp". If not, see <http://www.gnu.org/licenses/>.
*/
#include "HH_Includes.hpp"
//using namespace boost::numeric::odeint;
//void hhSolver(int POINTS, double tf, hh_model hhmodel,std::vector<double> y,std::string out_datafile);
// ==========================================================================
// MAIN CODE
// ==========================================================================
//\file HH-model.cpp
/*!
* \brief The Main function of the model
*/
int main(int argc, char **argv){
int POINTS=500;
char verbosity='n',gengraphs='g', automatic='y';
std::string paramfile = "parameters.txt";
std::string iniconfile = "init_cond.txt";
std::string basefile = "results-HH-model";
std::string ext = "txt";
std::string out_datafile = basefile + "." + ext;
// ==========================================================================
double h_step; /// h_step This will be the h_step for integrate, will be redefined on line 333
std::vector<double> parametros; /// parametros[8] Here one stores the ODES parameters for solvig, i.e membrane capacitance, conductances and so on
double t=0.0; /// t Starting time, this variable is a "time buffer"
double tf=25.0; /// tf 25 ms for time integration
// ==========================================================================
// Console commands to run the programm
// ==========================================================================
int c;
extern int optind;
extern char *optarg;
while ((c = getopt(argc, argv, "hvgAt:p:k:i:b:e:")) != -1)
switch (c) {
case 'h':
std::cout << "\nUsage: \n" << argv[0] << " [options] \n" << std::endl;
std::cout <<"\t-h : This help message"<< std::endl;
std::cout <<"\t-v : Set verbosity level,(No verbosity by default)"<< std::endl;
std::cout <<"\t-g : Don't generate PNG graphics,(Graphics by default)"<< std::endl;
std::cout <<"\t-A : Automatic parameters and initial conditions (using built-in defaults)"<< std::endl;
std::cout <<"\t-t# : Integrate from zero to # (In milliseconds),(Default= " << tf << ")" << std::endl;
std::cout <<"\t-p# : Set number of points used (Default " << POINTS << ")" << std::endl;
std::cout <<"\t-i@ : Initial conditions file [-i filename.ext] (Default \"" << iniconfile << "\")" << std::endl;
std::cout <<"\t-k@ : Parameters file [-kfilename.ext] (Default \"" << paramfile << "\")" << std::endl;
std::cout <<"\t-b@ : Set basename for output files [-b basename] (Default \"" << basefile << "\")" << std::endl;
std::cout <<"\t-e@ : Set extension for basename output files [-e ext = basename.ext] (Default \"" << ext << "\")" << std::endl;
std::cout << "\nNOTE: If no options are given, the -A flag is used by default\n" << std::endl;
std::cout << std::endl;
exit(1);
break;
case 'v': verbosity='v';
break;
case 'g': gengraphs='n';
break;
case 'A': automatic='y'; // Automatic mode
break;
case 't': tf=atof(optarg);
break;
case 'p': POINTS = atoi(optarg);
break;
case 'i': iniconfile.assign(optarg);
automatic='n'; //Disable automode
break;
case 'k': paramfile.assign(optarg);
automatic='n'; //Disable automode
break;
case 'b': basefile.assign(optarg);
break;
case 'e': ext.assign(optarg);
break;
case '?':
std::cout << "Unknown option " << std::endl;
std::cout << "Aborting..." << std::endl;
default:
abort ();
}
// Here the solution is stored
// definde here in order to have a container for the initial conditions
std::vector<double> y;
if (automatic=='y')
{
// ==========================================================================
// Initial conditions AUTOMATED
// ==========================================================================
y.push_back(-60); // Initial transmembrane potential, assuming resting potential (-60 mV) *when automated* [-A flag]
y.push_back(0); // Initial state for Gating function m *when automated* [-A flag]
y.push_back(0); // Initial state for Gating function h *when automated* [-A flag]
y.push_back(0); // Initial state for Gating function n *when automated* [-A flag]
// # Membrane capacitance in Farads
// Cm = 0.001;
//
// # Ion conductances in mMho
// gNa = 120;
// gK = 36;
// gL = 0.3;
//
// # Ion equilibrium potentials in mVolts
// vNa = -115;
// vL = 10.613;
// vK = 12;
parametros.push_back(0.01); // Membrane capacitance *when automated* [-A flag]
parametros.push_back(0); // induced current on axon, 0 means no external current *when automated* [-A flag]
parametros.push_back(1.2); // Na conductances *when automated* [-A flag]
parametros.push_back(55.17); // Na Nernst Potential *when automated* [-A flag]
parametros.push_back(0.36); // K Conductance *when automated* [-A flag]
parametros.push_back(-72.14); // K Nernst Potential *when automated* [-A flag]
parametros.push_back(0.003); // Leakage conductance (Due to a Cl current) *when automated* [-A flag]
parametros.push_back(-49.42); // Leakage Nernst potential (Due to a Cl current) *when automated* [-A flag]
}
else
{
// ==========================================================================
// Initial conditions FROM FILE
// ==========================================================================
getInfoFromFile(iniconfile,y);
getInfoFromFile(paramfile,parametros);
}
std::cout << "Initial Conditions" << std::endl;
std::cout << y[0] << std::endl;
std::cout << y[1] << std::endl;
std::cout << y[2] << std::endl;
std::cout << y[3] << std::endl;
std::cout << "Parameters" << std::endl;
std::cout << parametros[0] << std::endl;
std::cout << parametros[1] << std::endl;
std::cout << parametros[2] << std::endl;
std::cout << parametros[3] << std::endl;
std::cout << parametros[4] << std::endl;
std::cout << parametros[5] << std::endl;
std::cout << parametros[6] << std::endl;
std::cout << parametros[7] << std::endl;
// ==========================================================================
// ==========================================================================
// Now the iterative process of solution using ODEINT by Libboost
// ==========================================================================
// ==========================================================================
hh_model hhmodel(parametros);
hhSolver(POINTS, tf, hhmodel, y, out_datafile);
if(gengraphs!='n')
{
mglDrawFunction(parametros,POINTS,out_datafile);
}
exit(0);
}//End of Main Code