Code: Select all
soma = h.Section(name='soma')
// soma.insert( lots of mechanisms )
for seg in soma:
for mech in seg:
print(mech)
Code: Select all
NEURON {
...
RANGE gbar, g, ica
}
PARAMETER {
gbar = 0.00001 (S/cm2)
}
Code: Select all
soma = h.Section(name='soma')
// soma.insert( lots of mechanisms )
for seg in soma:
for mech in seg:
print(mech)
Code: Select all
NEURON {
...
RANGE gbar, g, ica
}
PARAMETER {
gbar = 0.00001 (S/cm2)
}
Not what I see. Givenmech contains parameters like 'gbar', 'g', 'ica' and so on.
Code: Select all
soma = h.Section(name='soma')
soma.insert('hh')
Code: Select all
for seg in soma:
for mech in seg:
print(mech)
Code: Select all
k_ion
na_ion
hh
Code: Select all
soma = h.Section(name='soma')
soma.insert('hh')
for seg in soma:
for mech in seg:
if mech.name() == 'hh':
filtered = []
for n in dir(mech):
v = getattr(mech, n)
if n.startswith('__') or n in ('next', 'name', 'is_ion', 'segment',):
continue
filtered.append(n)
print(filtered)
# ['el', 'gk', 'gkbar', 'gl', 'gna', 'gnabar', 'h', 'il', 'm', 'n']
Code: Select all
PARAMETER {
gnabar = .12 (S/cm2) <0,1e9>
gkbar = .036 (S/cm2) <0,1e9>
gl = .0003 (S/cm2) <0,1e9>
el = -54.3 (mV)
Code: Select all
from neuron import h
import re
def get_parameters(mech_name):
mech = h.MechanismType(0)
mech.select(mech_name)
parameters = {}
code = mech.code().split('\n')
inside_comment = False
inside_parameter = False
for line in code:
line = line.strip()
lineupper = line.upper()
if not line:
continue
if line[0] in ('?', ':'):
continue
if lineupper.startswith('COMMENT'):
inside_comment = True
elif lineupper.startswith('ENDCOMMENT'):
if not inside_comment:
raise('Parse error')
inside_comment = False
elif not inside_comment:
if lineupper.startswith('PARAMETER'):
inside_parameter = True
elif lineupper.startswith('}') and inside_parameter:
inside_parameter = False
elif inside_parameter:
# discard any comments
# NB: colon can also appear as part of a CURIE in other parts of a mod file
# but not in the PARAMETERS block
line = line.split(':')[0].strip()
if not line:
continue
varname, value, metadata = re.match('(\w+)\s*=\s*(-?[0-9\.]+)\s*(.*)', line).groups()
parameters[varname] = {'value': value}
if metadata:
parsed_metadata = re.match(r'(\((([\w/])+)\))?\s*(.*)', metadata).groups()
if parsed_metadata[1] is not None:
parameters[varname]['units'] = parsed_metadata[1]
if parsed_metadata[-1]:
parameters[varname]['bounds'] = parsed_metadata[-1]
return parameters
Code: Select all
import pprint
pprint.pprint(get_parameters('hh'))
Code: Select all
{'el': {'units': 'mV', 'value': '-54.3'},
'gkbar': {'bounds': '<0,1e9>', 'units': 'S/cm2', 'value': '.036'},
'gl': {'bounds': '<0,1e9>', 'units': 'S/cm2', 'value': '.0003'},
'gnabar': {'bounds': '<0,1e9>', 'units': 'S/cm2', 'value': '.12'}}
Code: Select all
from neuron import h
ms = h.MechanismStandard("hh", 1)
parm_name = h.ref("")
for i in range(ms.count()):
ms.name(parm_name, i)
print(parm_name[0])
Code: Select all
from neuron import h
from nmodl import dsl
mech_type = h.MechanismType(0)
mech_type.select('hh')
code = mech_type.code()
driver = dsl.NmodlDriver()
modast = driver.parse_string(code)
lookup_visitor = dsl.visitor.AstLookupVisitor()
param_block = lookup_visitor.lookup(modast, dsl.ast.AstNodeType.PARAM_ASSIGN)
params = {}
for param in param_block:
name = param.name.value.value
value = None
if param.value is not None:
value = param.value.value
params[name] = value
return params
Code: Select all
varname, value, metadata = re.match('(\w+)\s*=\s*(-?[0-9\.]+)\s*(.*)', line).groups()
Code: Select all
varname, value, metadata = re.match(r'(\w+)\s*(?:=\s*(-?[0-9.]+)\s*)?(.*)', line).groups()
Code: Select all
ms = h.MechanismStandard(mech_name, 1)
param_name = h.ref('')
param_names = []
for i in range(ms.count()):
ms.name(param_name, i)
param_names.append(param_name[0])
param_names = [name.split('_' + mech_name)[0] for name in param_names]