Skip to content

Commit da5b96c

Browse files
author
Dilawar Singh
committed
Getting previous changes (see Jefferey email and gitlab Others/Jefferey
folder.)
1 parent 1af4b64 commit da5b96c

File tree

4 files changed

+148
-112
lines changed

4 files changed

+148
-112
lines changed

biophysics/CaConc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* without diffusion. It uses a simple exponential return of Ca
1717
* to baseline, with influxes from ion channels. It solves the
1818
* equation:
19-
* dC/dt = B*Ik - C/tau
20-
* where Ca = Ca_base + C.
19+
*
20+
* dC/dt = B*Ik - C/tau, where Ca = Ca_base + C.
2121
*
2222
* From the GENESIS notes:
2323
* In SI units, where concentration is moles/m^3

biophysics/CaConcBase.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ const Cinfo* CaConcBase::initCinfo()
6464
// ConncentrationModel.
6565
// FIXME: If it is not needed after neuroml2 is fully supported, remove it
6666
// else remove this fixme.
67-
static ElementValueFinfo< CaConcBase, double > conc( "conc",
67+
static ElementValueFinfo< CaConcBase, double > conc("conc",
6868
"Calcium concentration (alias for Ca)",
6969
&CaConcBase::setCa,
7070
&CaConcBase::getCa);
7171

72-
static ElementValueFinfo< CaConcBase, double > CaBasal( "CaBasal",
72+
static ElementValueFinfo< CaConcBase, double > CaBasal("CaBasal",
7373
"Basal Calcium concentration.",
7474
&CaConcBase::setCaBasal,
7575
&CaConcBase::getCaBasal);
7676

77-
static ElementValueFinfo< CaConcBase, double > Ca_base( "Ca_base",
77+
static ElementValueFinfo< CaConcBase, double > Ca_base("Ca_base",
7878
"Basal Calcium concentration, synonym for CaBasal",
7979
&CaConcBase::setCaBasal,
8080
&CaConcBase::getCaBasal);
8181

82-
static ElementValueFinfo< CaConcBase, double > tau( "tau",
82+
static ElementValueFinfo< CaConcBase, double > tau("tau",
8383
"Settling time for Ca concentration",
8484
&CaConcBase::setTau,
8585
&CaConcBase::getTau);
8686

87-
static ElementValueFinfo< CaConcBase, double > B( "B",
87+
static ElementValueFinfo< CaConcBase, double > B("B",
8888
"Volume scaling factor. "
8989
"Deprecated. This is a legacy field from GENESIS and exposes "
9090
"internal calculations. Please do not use. \n"
@@ -127,29 +127,29 @@ const Cinfo* CaConcBase::initCinfo()
127127
///////////////////////////////////////////////////////
128128

129129
static DestFinfo current( "current",
130-
"Calcium Ion current, due to be converted to conc.",
131-
new EpFunc1< CaConcBase, double >( &CaConcBase::current )
132-
);
130+
"Calcium Ion current, due to be converted to conc.",
131+
new EpFunc1< CaConcBase, double >( &CaConcBase::current )
132+
);
133133

134134
static DestFinfo currentFraction( "currentFraction",
135-
"Fraction of total Ion current, that is carried by Ca2+.",
136-
new EpFunc2< CaConcBase, double, double >( &CaConcBase::currentFraction )
137-
);
135+
"Fraction of total Ion current, that is carried by Ca2+.",
136+
new EpFunc2< CaConcBase, double, double >( &CaConcBase::currentFraction )
137+
);
138138

139139
static DestFinfo increase( "increase",
140-
"Any input current that increases the concentration.",
141-
new EpFunc1< CaConcBase, double >( &CaConcBase::increase )
142-
);
140+
"Any input current that increases the concentration.",
141+
new EpFunc1< CaConcBase, double >( &CaConcBase::increase )
142+
);
143143

144144
static DestFinfo decrease( "decrease",
145-
"Any input current that decreases the concentration.",
146-
new EpFunc1< CaConcBase, double >( &CaConcBase::decrease )
147-
);
145+
"Any input current that decreases the concentration.",
146+
new EpFunc1< CaConcBase, double >( &CaConcBase::decrease )
147+
);
148148

149149
static DestFinfo basal( "basal",
150-
"Synonym for assignment of basal conc.",
151-
new EpFunc1< CaConcBase, double >( &CaConcBase::setCaBasal )
152-
);
150+
"Synonym for assignment of basal conc.",
151+
new EpFunc1< CaConcBase, double >( &CaConcBase::setCaBasal )
152+
);
153153

154154
static Finfo* CaConcBaseFinfos[] =
155155
{

biophysics/CaConcBase.h

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -37,91 +37,91 @@
3737

3838
class CaConcBase
3939
{
40-
public:
41-
CaConcBase();
42-
///////////////////////////////////////////////////////////////
43-
// Message handling functions
44-
///////////////////////////////////////////////////////////////
45-
void reinit( const Eref&, ProcPtr info );
46-
void process( const Eref&, ProcPtr info );
40+
public:
41+
CaConcBase();
42+
///////////////////////////////////////////////////////////////
43+
// Message handling functions
44+
///////////////////////////////////////////////////////////////
45+
void reinit( const Eref&, ProcPtr info );
46+
void process( const Eref&, ProcPtr info );
4747

48-
void current( const Eref& e, double I );
49-
void currentFraction( const Eref& e, double I, double fraction );
50-
void increase( const Eref& e, double I );
51-
void decrease( const Eref& e, double I );
52-
///////////////////////////////////////////////////////////////
53-
// Virtual Message handling functions
54-
///////////////////////////////////////////////////////////////
55-
virtual void vReinit( const Eref&, ProcPtr info ) = 0;
56-
virtual void vProcess( const Eref&, ProcPtr info ) = 0;
48+
void current( const Eref& e, double I );
49+
void currentFraction( const Eref& e, double I, double fraction );
50+
void increase( const Eref& e, double I );
51+
void decrease( const Eref& e, double I );
52+
///////////////////////////////////////////////////////////////
53+
// Virtual Message handling functions
54+
///////////////////////////////////////////////////////////////
55+
virtual void vReinit( const Eref&, ProcPtr info ) = 0;
56+
virtual void vProcess( const Eref&, ProcPtr info ) = 0;
5757

58-
virtual void vCurrent( const Eref& e, double I ) = 0;
59-
virtual void vCurrentFraction( const Eref& e, double I, double fraction ) = 0;
60-
virtual void vIncrease( const Eref& e, double I ) = 0;
61-
virtual void vDecrease( const Eref& e, double I ) = 0;
62-
///////////////////////////////////////////////////////////////
63-
// Field handling functions
64-
///////////////////////////////////////////////////////////////
65-
void setCa( const Eref& e, double val );
66-
double getCa( const Eref& e ) const;
67-
void setCaBasal( const Eref& e, double val );
68-
double getCaBasal( const Eref& e ) const;
69-
void setTau( const Eref& e, double val );
70-
double getTau( const Eref& e ) const;
71-
void setB( const Eref& e, double val );
72-
double getB( const Eref& e ) const;
73-
void setCeiling( const Eref& e, double val );
74-
double getCeiling( const Eref& e ) const;
75-
void setFloor( const Eref& e, double val );
76-
double getFloor( const Eref& e ) const;
77-
void setThickness( const Eref& e, double val );
78-
double getThickness( const Eref& e ) const;
79-
void setLength( const Eref& e, double val );
80-
double getLength( const Eref& e ) const;
81-
void setDiameter( const Eref& e, double val );
82-
double getDiameter( const Eref& e ) const;
83-
///////////////////////////////////////////////////////////////
84-
// Virtual Field handling functions
85-
///////////////////////////////////////////////////////////////
86-
virtual void vSetCa( const Eref& e, double val ) = 0;
87-
virtual double vGetCa( const Eref& e ) const = 0;
88-
virtual void vSetCaBasal( const Eref& e, double val ) = 0;
89-
virtual double vGetCaBasal( const Eref& e ) const = 0;
90-
virtual void vSetTau( const Eref& e, double val ) = 0;
91-
virtual double vGetTau( const Eref& e ) const = 0;
92-
virtual void vSetB( const Eref& e, double val ) = 0;
93-
virtual double vGetB( const Eref& e ) const = 0;
94-
virtual void vSetCeiling( const Eref& e, double val ) = 0;
95-
virtual double vGetCeiling( const Eref& e ) const = 0;
96-
virtual void vSetFloor( const Eref& e, double val ) = 0;
97-
virtual double vGetFloor( const Eref& e ) const = 0;
58+
virtual void vCurrent( const Eref& e, double I ) = 0;
59+
virtual void vCurrentFraction( const Eref& e, double I, double fraction ) = 0;
60+
virtual void vIncrease( const Eref& e, double I ) = 0;
61+
virtual void vDecrease( const Eref& e, double I ) = 0;
62+
///////////////////////////////////////////////////////////////
63+
// Field handling functions
64+
///////////////////////////////////////////////////////////////
65+
void setCa( const Eref& e, double val );
66+
double getCa( const Eref& e ) const;
67+
void setCaBasal( const Eref& e, double val );
68+
double getCaBasal( const Eref& e ) const;
69+
void setTau( const Eref& e, double val );
70+
double getTau( const Eref& e ) const;
71+
void setB( const Eref& e, double val );
72+
double getB( const Eref& e ) const;
73+
void setCeiling( const Eref& e, double val );
74+
double getCeiling( const Eref& e ) const;
75+
void setFloor( const Eref& e, double val );
76+
double getFloor( const Eref& e ) const;
77+
void setThickness( const Eref& e, double val );
78+
double getThickness( const Eref& e ) const;
79+
void setLength( const Eref& e, double val );
80+
double getLength( const Eref& e ) const;
81+
void setDiameter( const Eref& e, double val );
82+
double getDiameter( const Eref& e ) const;
83+
///////////////////////////////////////////////////////////////
84+
// Virtual Field handling functions
85+
///////////////////////////////////////////////////////////////
86+
virtual void vSetCa( const Eref& e, double val ) = 0;
87+
virtual double vGetCa( const Eref& e ) const = 0;
88+
virtual void vSetCaBasal( const Eref& e, double val ) = 0;
89+
virtual double vGetCaBasal( const Eref& e ) const = 0;
90+
virtual void vSetTau( const Eref& e, double val ) = 0;
91+
virtual double vGetTau( const Eref& e ) const = 0;
92+
virtual void vSetB( const Eref& e, double val ) = 0;
93+
virtual double vGetB( const Eref& e ) const = 0;
94+
virtual void vSetCeiling( const Eref& e, double val ) = 0;
95+
virtual double vGetCeiling( const Eref& e ) const = 0;
96+
virtual void vSetFloor( const Eref& e, double val ) = 0;
97+
virtual double vGetFloor( const Eref& e ) const = 0;
9898

99-
///////////////////////////////////////////////////////////////
100-
// Utility function in case length, dia or thickness is updated
101-
void updateDimensions( const Eref& e );
99+
///////////////////////////////////////////////////////////////
100+
// Utility function in case length, dia or thickness is updated
101+
void updateDimensions( const Eref& e );
102102

103-
/// Used to set up the solver. Dummy for regular classes.
104-
virtual void vSetSolver( const Eref& e, Id hsolve );
103+
/// Used to set up the solver. Dummy for regular classes.
104+
virtual void vSetSolver( const Eref& e, Id hsolve );
105105

106-
/**
107-
* Swaps Cinfos in order to make Zombies.
108-
*/
109-
static void zombify( Element* orig, const Cinfo* zClass,
110-
Id hsolve );
106+
/**
107+
* Swaps Cinfos in order to make Zombies.
108+
*/
109+
static void zombify( Element* orig, const Cinfo* zClass,
110+
Id hsolve );
111111

112-
/*
113-
* This Finfo is used to send out Ca concentration to channels.
114-
*
115-
* It is exposed here so that HSolve can also use it to send out
116-
* Ca concentration to the recipients.
117-
*/
118-
static SrcFinfo1< double >* concOut();
112+
/*
113+
* This Finfo is used to send out Ca concentration to channels.
114+
*
115+
* It is exposed here so that HSolve can also use it to send out
116+
* Ca concentration to the recipients.
117+
*/
118+
static SrcFinfo1< double >* concOut();
119119

120-
static const Cinfo* initCinfo();
121-
private:
122-
double thickness_;
123-
double diameter_;
124-
double length_;
120+
static const Cinfo* initCinfo();
121+
private:
122+
double thickness_;
123+
double diameter_;
124+
double length_;
125125
};
126126

127127

python/moose/neuroml2/reader.py

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# For update/log, please see git-blame documentation or browse the github
1313
# repo https://github.com/BhallaLab/moose-core
1414

15-
import os
1615
import math
1716
import numpy as np
1817
from moose.neuroml2.hhfit import exponential2
@@ -25,10 +24,10 @@
2524
logger_ = logging.getLogger('moose.nml2')
2625

2726
try:
28-
import neuroml as nml
2927
import neuroml.loaders as loaders
3028
from pyneuroml import pynml
31-
except:
29+
except Exception as e:
30+
print(e)
3231
print(
3332
"********************************************************************")
3433
print("* ")
@@ -42,7 +41,37 @@
4241
print(
4342
"********************************************************************")
4443

45-
# Utility functions
44+
45+
def _unique(ls):
46+
res = [ ]
47+
for l in ls:
48+
if l not in res:
49+
res.append(l)
50+
return res
51+
52+
def _isConcDep(ct):
53+
"""_isConcDep
54+
Check if componet is dependant on concentration. Most HHGates are
55+
dependant on voltage.
56+
57+
:param ct: ComponentType
58+
:type ct: nml.ComponentType
59+
60+
:return: True if Component is depenant on conc, False otherwise.
61+
"""
62+
if 'ConcDep' in ct.extends:
63+
return True
64+
return False
65+
66+
def _findCaConcVariableName():
67+
"""_findCaConcVariableName
68+
Find a suitable CaConc for computing HHGate tables.
69+
This is a hack, though it is likely to work in most cases.
70+
"""
71+
caConcs = moose.wildcardFind( '/library/##[TYPE=CaConc]' )
72+
assert len(caConcs) >= 1, "No moose.CaConc found. Currently moose \
73+
supports HHChannel which depends only on moose.CaConc ."
74+
return caConcs[0].name
4675

4776

4877
def sarea(comp):
@@ -161,6 +190,9 @@ def __init__(self, verbose=False):
161190
self.seg_id_to_comp_name = {}
162191
self.paths_to_chan_elements = {}
163192

193+
# Just in case.
194+
self._variables = {}
195+
164196

165197
def read(self, filename, symmetric=True):
166198
self.doc = loaders.read_neuroml2_file(filename,
@@ -439,14 +471,18 @@ def calculateRateFn(self, ratefn, vmin, vmax, tablen=3000, vShift='0mV'):
439471
logger_.info("Using %s to evaluate rate" % ct.name)
440472
rate = []
441473
for v in tab:
442-
vars = {
443-
'v': '%sV' % v,
444-
'vShift': vShift,
445-
'temperature': self._getTemperature()
446-
}
447-
for k in self.nml_concs_to_moose:
448-
vars.update({k: self.nml_concs_to_moose[k].conc})
449-
vals = pynml.evaluate_component(ct, req_variables=vars)
474+
# Note: MOOSE HHGate are either voltage of concentration
475+
# dependant. Here we figure out if nml description of gate is
476+
# concentration dependant or not.
477+
if _isConcDep(ct):
478+
# Concentration dependant. Concentration can't be negative.
479+
# Find a suitable CaConc from the /library. Currently only
480+
# Ca dependant channels are allowed.
481+
caConcName = _findCaConcVariableName()
482+
req_vars = {caConcName:'%g'%max(0,v),'vShift':vShift,'temperature':self._getTemperature()}
483+
else:
484+
req_vars.update( self._variables )
485+
vals = pynml.evaluate_component(ct, req_variables=req_vars)
450486
'''print(vals)'''
451487
if 'x' in vals:
452488
rate.append(vals['x'])

0 commit comments

Comments
 (0)