Skip to content

Commit

Permalink
fixed #535
Browse files Browse the repository at this point in the history
uses regex to convert a^b -> pow(a,b)
  • Loading branch information
sg-s committed Jul 11, 2020
1 parent c9684f0 commit f79e685
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 45 deletions.
11 changes: 10 additions & 1 deletion +xolotl/conductance.m
Expand Up @@ -70,14 +70,23 @@ function generateCPPFile(self, name)
f = func2str(self.(props{i}));
f = strrep(f,'@(V,Ca)',' ');
else
error('Unrecognised function signature.')
error('Unrecognized function signature.')
end

if any(strfind(f,'NaN'))
f = ' 1';
end


% remove ^ and convert to pow
if any(strfind(f,'^'))
caretpos = strfind(f,'^');
basepos = max(regexpi(f(1:caretpos-1),'\W'))+1:caretpos-1;
temp = regexp(f(caretpos+1:end),'[^0-9.]')-1;
exponentpos = (caretpos+1:caretpos+temp(1));
f = strrep(f,f(basepos(1):exponentpos(end)),['pow(',f(basepos),',',f(exponentpos),')']);
end

this_line = strrep(this_line,['$' props{i}], f);

else
Expand Down
73 changes: 29 additions & 44 deletions examples/demo_conductance.m
Expand Up @@ -12,59 +12,38 @@
end


channels = x.AB.find('conductance');
% construct a new ACurrent based on the Liu ACurrent
[m_inf, h_inf, tau_m, tau_h] = xolotl.getGatingFunctions(x.AB.ACurrent.cpp_class_path);

% A CaS CaT H KCa Kd leak NaV
all_p = [3 3 3 1 4 4 0 3];
all_q = [1 1 1 0 0 0 0 1];
is_Ca = [0 1 1 0 0 0 0 0];

for i = 1:length(channels)
% specify a conductance using the function we read out
conductance = xolotl.conductance;
conductance.m_inf = m_inf;
conductance.h_inf = h_inf;
conductance.tau_m = tau_m;
conductance.tau_h = tau_h;
conductance.default_E = x.AB.ACurrent.E;
conductance.p = 3;
conductance.q = 1;

if strcmp(channels{i},'Leak')
continue
end
% make a new C++ file
conductance.generateCPPFile('ACurrent');


[m_inf, h_inf, tau_m, tau_h] = xolotl.getGatingFunctions(x.AB.(channels{i}).cpp_class_path);

temp = xolotl.conductance;
temp.m_inf = m_inf;
temp.h_inf = h_inf;
temp.tau_m = tau_m;
temp.tau_h = tau_h;
% now construct a new object using this channels

temp.default_E = x.AB.(channels{i}).E;
x2 = xolotl.examples.neurons.BurstingNeuron('prefix','liu');
x2.AB.ACurrent.destroy;
x2.AB.add('custom/ACurrent','gbar',246);

temp.p = all_p(i);
temp.q = all_q(i);
temp.is_Ca = logical(is_Ca(i));

temp.generateCPPFile(channels{i});


end

% now construct a new object using these channels

x2 = xolotl;
x2.add('compartment','AB','A',x.AB.A);
x2.AB.add('prinz/CalciumMech','f',1.496);

x2.AB.add('custom/NaV','gbar',@() 115/x.AB.A,'E',30);
x2.AB.add('custom/CaT','gbar',@() 1.44/x.AB.A,'E',30);
x2.AB.add('custom/CaS','gbar',@() 1.7/x.AB.A,'E',30);
x2.AB.add('custom/ACurrent','gbar',@() 15.45/x.AB.A,'E',-80);
x2.AB.add('custom/KCa','gbar',@() 61.54/x.AB.A,'E',-80);
x2.AB.add('custom/Kd','gbar',@() 38.31/x.AB.A,'E',-80);
x2.AB.add('custom/HCurrent','gbar',@() .6343/x.AB.A,'E',-20);
x2.AB.add('Leak','gbar',@() 0.0622/x.AB.A,'E',-50);

x.sim_dt = .1;
x.dt = .1;
x.reset;
x.approx_channels = 0;
V = x.integrate;
time = (1:length(V))*x.dt*1e-3;

x2.t_end = x.t_end;
x2.sim_dt = .1;
Expand All @@ -73,10 +52,16 @@
x2.reset;
V2 = x2.integrate;

figure, hold on
plot(V)
plot(V2)
figure('outerposition',[300 300 1200 600],'PaperUnits','points','PaperSize',[1200 600]); hold on
subplot(2,1,1); hold on
plot(time,V,'k')
title('Using original ACurrent channel')
ylabel('Voltage (mV)')

figlib.pretty()
subplot(2,1,2); hold on
plot(time,V2,'r')
title('Using generated ACurrent channel')
xlabel('Time (s)')
ylabel('Voltage (mV)')

% corelib.assert(sum(V2 - V)==0,'Something went wrong')
figlib.pretty()

0 comments on commit f79e685

Please sign in to comment.