Skip to content

Commit 423fb8a

Browse files
author
Carlos Eckert
committed
Work done to IonChannel generic function
1 parent 361b14b commit 423fb8a

File tree

4 files changed

+106
-51
lines changed

4 files changed

+106
-51
lines changed

Assets/Scripts/C2M2/NeuronalDynamics/Simulation/IonChannel.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33

44
public class GatingVariable
55
{
6+
// Alpha function for the gating variable
67
public Func<double, double> Alpha { get; set; }
8+
9+
// Beta function for the gating variable
710
public Func<double, double> Beta { get; set; }
11+
12+
// Name of the gating variable (i.e: n, m, h)
813
public string Name { get; set; }
9-
public List<double> Coefficients { get; set; }
14+
//
15+
public List<double> ChannelConstants { get; set; }
16+
public double InitialValue { get; set; }
1017

1118
public GatingVariable(string name, Func<double, double> alpha, Func<double, double> beta)
1219
{
1320
Name = name;
1421
Alpha = alpha;
1522
Beta = beta;
16-
Coefficients = new List<double>();
23+
ChannelConstants = new List<double>();
24+
InitialValue = InitialValue;
1725
}
1826
}
1927

@@ -31,7 +39,6 @@ public IonChannel(string name, double conductance, double reversalPotential)
3139
ReversalPotential = reversalPotential;
3240
GatingVariables = new List<GatingVariable>();
3341
}
34-
3542
public void AddGatingVariable(GatingVariable gatingVariable)
3643
{
3744
GatingVariables.Add(gatingVariable);

Assets/Scripts/C2M2/NeuronalDynamics/Simulation/IonChannel/obj/Debug/net8.0/IonChannel.AssemblyInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[assembly: System.Reflection.AssemblyCompanyAttribute("IonChannel")]
1414
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
1515
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
16-
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+bed9a50b52f2757c8e2930f61c4b8fd3ac41c29d")]
16+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+361b14b31f5b2aa50307dc72e44a360504076790")]
1717
[assembly: System.Reflection.AssemblyProductAttribute("IonChannel")]
1818
[assembly: System.Reflection.AssemblyTitleAttribute("IonChannel")]
1919
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0f2750cddfbea5680889400aec062eef631265d0509eb50adc500f3b464c949f
1+
3510c39156aab660920e3d3e16bb304c6d20e39712337b1fef7b4171c4045928

Assets/Scripts/C2M2/NeuronalDynamics/Simulation/SparseSolverTestv1.cs

+94-46
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,6 @@ public class SparseSolverTestv1 : NDSimulation
6464
/// </summary>
6565
private double cap = 1.0 * 1.0E-2;
6666
/// <summary>
67-
/// [S/m2] potassium conductance per unit area, this is the Potassium conductance per unit area, it is used in this term
68-
/// \f[\bar{g}_{K}n^4(V-V_k)\f]
69-
/// where \f$n\f$ is the state variable, and \f$V_k\f$ is the reversal potential.
70-
/// </summary>
71-
private double gk = 5.0 * 1.0E1;
72-
/// <summary>
73-
/// [S/m2] sodium conductance per unit area, this is the Sodium conductance per unit area, it is used in this term
74-
/// \f[\bar{g}_{Na}m^3h(V-V_{Na})\f]
75-
/// where \f$m,h\f$ are the state variables, and \f$V_{Na}\f$ is the reversal potential for sodium.
76-
/// </summary>
77-
private double gna = 50.0 * 1.0E1;
78-
/// <summary>
79-
/// [S/m2] leak conductance per unit area, this is the leak conductance per unit area, it is used in this term
80-
/// \f[\bar{g}_{l}(V-V_l)\f]
81-
/// \f$V_l\f$ is the leak reversal potential.
82-
/// </summary>
83-
private double gl = 0.0 * 1.0E1;
84-
/// <summary>
85-
/// [V] potassium reversal potential
86-
/// </summary>
87-
private double ek = -90.0 * 1.0E-3;
88-
/// <summary>
89-
/// [V] sodium reversal potential
90-
/// </summary>
91-
private double ena = 50.0 * 1.0E-3;
92-
/// <summary>
93-
/// [V] leak reversal potential
94-
/// </summary>
95-
private double el = -70.0 * 1.0E-3;
96-
/// <summary>
9767
/// [] potassium channel state probability, unitless
9868
/// </summary>
9969
private double ni = 0.0376969;
@@ -380,28 +350,51 @@ protected override void PreSolve()
380350
if (!g.Loading) InitializeNeuronCell();
381351
else BuildVectors(g.U, g.M, g.N, g.H, g.Upre, g.Mpre, g.Npre, g.Hpre);
382352

353+
else BuildVectors(g.U, g.M, g.N, g.H, g.Upre, g.Mpre, g.Npre, g.Hpre);
354+
355+
///<c>R</c> this is the reaction vector for the reaction solve
356+
R = Vector.Build.Dense(Neuron.nodes.Count);
357+
358+
tempState = Vector.Build.Dense(Neuron.nodes.Count, 0);
359+
///<c>reactConst</c> this is a small list for collecting the conductances and reversal potential which is sent to the reaction solve routine
360+
// reactConst = new List<double> { gk, gna, gl, ek, ena, el };
361+
362+
/// this sets the target time step size
363+
timeStep = SetTargetTimeStep(cap, 2 * Neuron.MaxRadius,2*Neuron.MinRadius, Neuron.TargetEdgeLength, gna, gk,gl, res, 1.0);
364+
///UnityEngine.Debug.Log("Target Time Step = " + timeStep);
365+
366+
///<c>List<CoordinateStorage<double>> sparse_stencils = makeSparseStencils(Neuron, res, cap, k);</c> Construct sparse RHS and LHS in coordinate storage format, no zeros are stored \n
367+
/// <c>sparse_stencils</c> this is a list which contains only two matrices the LHS and RHS matrices for the Crank-Nicolson solve
368+
sparse_stencils = makeSparseStencils(Neuron, res, cap, timeStep);
369+
///<c>CompressedColumnStorage</c> call Compresses the sparse matrices which are stored in <c>sparse_stencils[0]</c> and <c>sparse_stencils[1]</c>
370+
r_csc = CompressedColumnStorage<double>.OfIndexed(sparse_stencils[0]); //null;
371+
l_csc = CompressedColumnStorage<double>.OfIndexed(sparse_stencils[1]); //null;
372+
///<c>double [] b</c> we define storage for the diffusion solve part
373+
b = new double[Neuron.nodes.Count];
374+
///<c>var lu = SparseLU.Create(l_csc, ColumnOrdering.MinimumDegreeAtA, 0.1);</c> this creates the LU decomposition of the HINES matrix which is defined by <c>l_csc</c>
375+
lu = SparseLU.Create(l_csc, ColumnOrdering.MinimumDegreeAtA, 0.1);
383376

384-
// Define alpha and beta functions for the gating variable (example for potassium channel)
385-
Func<double, double> alpha_n = (voltage) => 0.01 * (voltage + 55) / (1 - Math.Exp(-(voltage + 55) / 10));
386-
Func<double, double> beta_n = (voltage) => 0.125 * Math.Exp(-(voltage + 65) / 80);
377+
// // Define alpha and beta functions for the gating variable (example for potassium channel)
378+
// Func<double, double> alpha_n = (voltage) => 0.01 * (voltage + 55) / (1 - Math.Exp(-(voltage + 55) / 10));
379+
// Func<double, double> beta_n = (voltage) => 0.125 * Math.Exp(-(voltage + 65) / 80);
387380

388-
// Create a gating variable for potassium channel (n gate)
389-
GatingVariable potassiumGate = new GatingVariable("n", alpha_n, beta_n)
390-
{
391-
Coefficients = new List<double> { 1.0 }
392-
};
381+
// // Create a gating variable for potassium channel (n gate)
382+
// GatingVariable potassiumGate = new GatingVariable("n", alpha_n, beta_n)
383+
// {
384+
// Coefficients = new List<double> { 1.0 }
385+
// };
393386

394-
// Create the potassium ion channel
395-
IonChannel potassiumChannel = new IonChannel("Potassium", , );
387+
// // Create the potassium ion channel
388+
// IonChannel potassiumChannel = new IonChannel("Potassium", , );
396389

397-
// Add the gating variable to the potassium channel
398-
potassiumChannel.AddGatingVariable(potassiumGate);
390+
// // Add the gating variable to the potassium channel
391+
// potassiumChannel.AddGatingVariable(potassiumGate);
399392

400-
// Calculate the current at a certain voltage
401-
double voltage = -65;
402-
double current = potassiumChannel.CalculateCurrent(voltage);
393+
// // Calculate the current at a certain voltage
394+
// double voltage = -65;
395+
// double current = potassiumChannel.CalculateCurrent(voltage);
403396

404-
Console.WriteLine($"Potassium channel current at {voltage} mV: {current} A");
397+
// Console.WriteLine($"Potassium channel current at {voltage} mV: {current} A");
405398

406399

407400

@@ -428,6 +421,61 @@ protected override void PreSolve()
428421
lu = SparseLU.Create(l_csc, ColumnOrdering.MinimumDegreeAtA, 0.1);
429422
}
430423

424+
public void InitializeIonChannels()
425+
{
426+
/// <summary>
427+
/// [S/m2] potassium conductance per unit area, this is the Potassium conductance per unit area, it is used in this term
428+
/// \f[\bar{g}_{K}n^4(V-V_k)\f]
429+
/// where \f$n\f$ is the state variable, and \f$V_k\f$ is the reversal potential.
430+
/// </summary>
431+
private double gk = 5.0 * 1.0E1;
432+
/// <summary>
433+
/// [S/m2] sodium conductance per unit area, this is the Sodium conductance per unit area, it is used in this term
434+
/// \f[\bar{g}_{Na}m^3h(V-V_{Na})\f]
435+
/// where \f$m,h\f$ are the state variables, and \f$V_{Na}\f$ is the reversal potential for sodium.
436+
/// </summary>
437+
private double gna = 50.0 * 1.0E1;
438+
/// <summary>
439+
/// [S/m2] leak conductance per unit area, this is the leak conductance per unit area, it is used in this term
440+
/// \f[\bar{g}_{l}(V-V_l)\f]
441+
/// \f$V_l\f$ is the leak reversal potential.
442+
/// </summary>
443+
private double gl = 0.0 * 1.0E1;
444+
/// <summary>
445+
/// [V] potassium reversal potential
446+
/// </summary>
447+
private double ek = -90.0 * 1.0E-3;
448+
/// <summary>
449+
/// [V] sodium reversal potential
450+
/// </summary>
451+
private double ena = 50.0 * 1.0E-3;
452+
/// <summary>
453+
/// [V] leak reversal potential
454+
/// </summary>
455+
private double el = -70.0 * 1.0E-3;
456+
457+
//
458+
private double n_alphaFunction;
459+
private double m_alphaFunction;
460+
private double h_alphaFunction;
461+
private double n_betaFunction;
462+
private double m_betaFunction;
463+
private double h_betaFunction;
464+
465+
466+
467+
IonChannel potassiumChannel = new IonChannel("Potassium Channel", gk, ek);
468+
potassiumChannel.AddGatingVariable(new GatingVariable("n", alpha: n_alphaFunction, beta: n_betaFunction));
469+
470+
IonChannel sodiumChannel = new IonChannel("Sodium Channel", gna, ena);
471+
sodiumChannel.AddGatingVariable(new GatingVariable("m", alpha: m_alphaFunction, beta: m_betaFunction));
472+
sodiumChannel.AddGatingVariable(new GatingVariable("h", alpha: h_alphaFunction, beta: h_betaFunction));
473+
474+
IonChannel leakageChannel = new IonChannel("Leakage Channel", gl, el);
475+
leadChannel.AddGatingVariable(new GatingVariable("n"));
476+
477+
}
478+
431479
/// <summary>
432480
/// This is the main solver, it is running on it own thread.
433481
/// The solver using SBDF2 for time steping, the implicit part is used for the diffusion and the explicit

0 commit comments

Comments
 (0)