00001 #include "GABA_BResponseODE.h" 00002 00003 00004 GABA_BResponseODE::GABA_BResponseODE(): ODESystem( 2 ) 00005 { 00006 solver = NULL; 00007 00008 k1 = 9.0*10e4; // [mM^-1 s^-1] 00009 k2 = 1.2; // [s^-1] 00010 k3 = 180.0; // [s^-1] 00011 k4 = 34.0; // [s^-1] 00012 kd = 100.0; // [mM] 00013 n = 4; 00014 00015 dead_time = 1e-3; // [s] 00016 Cdur = 0.3e-3; // [s] 00017 Cmax = 0.5; // [mM] 00018 } 00019 00020 00021 GABA_BResponseODE::~GABA_BResponseODE() 00022 { 00023 if( solver ) 00024 delete solver; 00025 } 00026 00027 00028 int GABA_BResponseODE::init() 00029 { 00030 setSystem( this ); 00031 if( ! solver ) 00032 solver = new odeiv::AdaptiveStepSolver( *this, odeiv::RungeKutta4() ); 00033 return 0; 00034 } 00035 00036 00037 int GABA_BResponseODE::reset(double dt) 00038 { 00039 if( ! solver ) 00040 init(); 00041 00042 r=0.0; 00043 s=0.0; 00044 00045 time_count=-dead_time-dt; 00046 00047 psr=0.0; 00048 C=0.0; 00049 00050 // y0[0]...r, y0[1]...s 00051 double y0[2]; 00052 y0[0]=r; y0[1]=s; 00053 y[0]=r; y[1]=s; 00054 00055 solver->reset( dt, *this, y0 ); 00056 00057 return FiniteSpikeResponse::reset(dt); 00058 } 00059 00060 00061 void GABA_BResponseODE::derivatives(double t, const double y[], double f[]) 00062 { 00063 // y[0] ... r, y[1] ... s 00064 r = y[0]; 00065 s = y[1]; 00066 00067 r = solver->y(0); 00068 s = solver->y(1); 00069 00070 f[0] = k1*C*(1-r) - k2*r; 00071 f[1] = k3*r - k4*s; 00072 } 00073 00074 00075 int GABA_BResponseODE::advance(AdvanceInfo const &ai) 00076 { 00077 time_count -= ai.dt.in_sec(); 00078 00079 if(time_count <= 0.0) 00080 C=0.0; 00081 00082 solver->advance( ai.t.in_sec(), ai.dt.in_sec(), *this ); 00083 00084 r = solver->y(0); 00085 s = solver->y(1); 00086 00087 psr = g_max / ( 1.0 + kd / pow(s, n) ); 00088 00089 return advanceReturn(); 00090 } 00091 00092 00093 int GABA_BResponseODE::spikeHit( spikeport_t port, SpikeEvent const& spike ) 00094 { 00095 if( port == 0 ) { 00096 if(time_count < -dead_time) { 00097 C = Cmax; 00098 time_count = Cdur; 00099 // g_max=spike.weight; 00100 } 00101 else { 00102 cerr << "spike missed" << endl; 00103 } 00104 } 00105 00106 return spikeHitReturn( AdvanceInfo( spike.dt ) ); 00107 } 00108 00109 00110 int GABA_BResponseODE::psrLength(double dt) const 00111 { 00112 // TODO: replace this simple approximation 00113 const double tau = 0.200; 00114 return (int)( (double)PSR_MULTIPLE_TAU * tau / dt + 0.5 ); 00115 }