diff --git a/bluepyopt/ephys/create_hoc.py b/bluepyopt/ephys/create_hoc.py index 316fe36..a5ebfa0 100644 --- a/bluepyopt/ephys/create_hoc.py +++ b/bluepyopt/ephys/create_hoc.py @@ -30,7 +30,7 @@ def _generate_channels_by_location(mechs): """Create a OrderedDictionary of all channel mechs for hoc template.""" channels = OrderedDict((location, []) for location in LOCATION_ORDER) for mech in mechs: - name = mech.prefix + name = mech.suffix for location in mech.locations: # TODO this is dangerous, implicitely assumes type of location channels[location.seclist_name].append(name) diff --git a/bluepyopt/ephys/examples/simplecell/simplecell.py b/bluepyopt/ephys/examples/simplecell/simplecell.py index bb21c5f..d30596a 100644 --- a/bluepyopt/ephys/examples/simplecell/simplecell.py +++ b/bluepyopt/ephys/examples/simplecell/simplecell.py @@ -15,7 +15,7 @@ seclist_name='somatic') hh_mech = ephys.mechanisms.NrnMODMechanism( name='hh', - prefix='hh', + suffix='hh', locations=[somatic_loc]) diff --git a/bluepyopt/ephys/mechanisms.py b/bluepyopt/ephys/mechanisms.py index 8736aee..88e29dc 100644 --- a/bluepyopt/ephys/mechanisms.py +++ b/bluepyopt/ephys/mechanisms.py @@ -49,7 +49,7 @@ class NrnMODMechanism(Mechanism, serializer.DictMixin): 'name', 'comment', 'mod_path', - 'prefix', + 'suffix', 'locations', 'preloaded', ) @@ -58,32 +58,41 @@ def __init__( self, name, mod_path=None, - prefix=None, + suffix=None, locations=None, preloaded=True, deterministic=True, + prefix=None, comment=''): """Constructor Args: name (str): name of this object mod_path (str): path to the MOD file (not used for the moment) - prefix (str): prefix of this mechanism in the MOD file + suffix (str): suffix of this mechanism in the MOD file locations (list of Locations): a list of Location objects pointing to where this mechanism should be added to. preloaded (bool): should this mechanism be side-loaded by BluePyOpt, or was it already loaded and compiled by the user ? (not used for the moment) + prefix (str): Deprecated. Use suffix instead. """ super(NrnMODMechanism, self).__init__(name, comment) self.mod_path = mod_path - self.prefix = prefix + self.suffix = suffix self.locations = locations self.preloaded = preloaded self.cell_model = None self.deterministic = deterministic + if prefix is not None and suffix is not None: + raise TypeError('NrnMODMechanism: it is not allowed to set both ' + 'prefix and suffix in constructor: %s %s' % + (self.prefix, self.suffix)) + elif prefix is not None: + self.suffix = self.prefix + def instantiate(self, sim=None, icell=None): """Instantiate""" @@ -91,9 +100,9 @@ def instantiate(self, sim=None, icell=None): isec_list = location.instantiate(sim=sim, icell=icell) for isec in isec_list: try: - isec.insert(self.prefix) + isec.insert(self.suffix) except ValueError as e: - raise ValueError(str(e) + ': ' + self.prefix) + raise ValueError(str(e) + ': ' + self.suffix) self.instantiate_determinism( self.deterministic, icell, @@ -101,17 +110,17 @@ def instantiate(self, sim=None, icell=None): sim) logger.debug( - 'Inserted %s in %s', self.prefix, [ + 'Inserted %s in %s', self.suffix, [ str(location) for location in self.locations]) def instantiate_determinism(self, deterministic, icell, isec, sim): """Instantiate enable/disable determinism""" - if 'Stoch' in self.prefix: + if 'Stoch' in self.suffix: setattr( isec, 'deterministic_%s' % - (self.prefix), + (self.suffix), 1 if deterministic else 0) if not deterministic: @@ -120,19 +129,19 @@ def instantiate_determinism(self, deterministic, icell, isec, sim): for iseg in isec: seg_name = '%s.%.19g' % (short_secname, iseg.x) getattr(sim.neuron.h, - "setdata_%s" % self.prefix)(iseg.x, sec=isec) + "setdata_%s" % self.suffix)(iseg.x, sec=isec) seed_id1 = icell.gid seed_id2 = self.hash_py(seg_name) getattr( sim.neuron.h, - "setRNG_%s" % self.prefix)(seed_id1, seed_id2) + "setRNG_%s" % self.suffix)(seed_id1, seed_id2) else: if not deterministic: # can't do this for non-Stoch channels raise TypeError( 'Deterministic can only be set to False for ' 'Stoch channel, not %s' % - self.prefix) + self.suffix) def destroy(self, sim=None): """Destroy mechanism instantiation""" @@ -143,7 +152,7 @@ def __str__(self): """String representation""" return "%s: %s at %s" % ( - self.name, self.prefix, + self.name, self.suffix, [str(location) for location in self.locations]) @staticmethod @@ -172,25 +181,37 @@ def generate_reinitrng_hoc_block(self): reinitrng_hoc_block = '' - if 'Stoch' in self.prefix: + if 'Stoch' in self.suffix: # TODO this is dangerous, implicitely assumes type of location for location in self.locations: if self.deterministic: reinitrng_hoc_block += \ 'forsec %(seclist_name)s { ' \ - 'deterministic_%(prefix)s = 1 }\n' % { + 'deterministic_%(suffix)s = 1 }\n' % { 'seclist_name': location.seclist_name, - 'prefix': self.prefix} + 'suffix': self.suffix} else: reinitrng_hoc_block += \ 'forsec %(seclist_name)s { %(mech_reinitrng)s }\n' % { 'seclist_name': location.seclist_name, 'mech_reinitrng': self.mech_reinitrng_block_template % { - 'prefix': self.prefix}} + 'suffix': self.suffix}} return reinitrng_hoc_block + @property + def prefix(self): + """Deprecated, prefix is now replaced by suffix""" + + return self.suffix + + @prefix.setter + def prefix(self, value): + """Deprecated, prefix is now replaced by suffix""" + + self.suffix = value + hash_hoc_string = \ """ func hash_str() {localobj sf strdef right @@ -224,9 +245,9 @@ def generate_reinitrng_hoc_block(self): mech_reinitrng_block_template = """ for (x, 0) { - setdata_%(prefix)s(x) + setdata_%(suffix)s(x) sf.tail(secname(), "\\\\.", name) sprint(full_str, "%%s.%%.19g", name, x) - setRNG_%(prefix)s(0, hash_str(full_str)) + setRNG_%(suffix)s(0, hash_str(full_str)) } """ diff --git a/bluepyopt/ephys/parameters.py b/bluepyopt/ephys/parameters.py index 98f54fb..9d2f2c3 100644 --- a/bluepyopt/ephys/parameters.py +++ b/bluepyopt/ephys/parameters.py @@ -65,8 +65,7 @@ def destroy(self, sim=None): class NrnGlobalParameter(NrnParameter, DictMixin): """Parameter set in the global namespace of neuron""" - SERIALIZED_FIELDS = ('name', 'value', 'frozen', 'bounds', 'param_name', - ) + SERIALIZED_FIELDS = ('name', 'value', 'frozen', 'bounds', 'param_name',) def __init__( self, @@ -180,7 +179,7 @@ def __str__(self): self.param_name, self.value if self.frozen else self.bounds) -# TODO change mech_prefix and mech_param to param_name, and maybe add +# TODO change mech_suffix and mech_param to param_name, and maybe add # NrnRangeMechParameter diff --git a/bluepyopt/tests/disable_simplecell_scoop.py b/bluepyopt/tests/disable_simplecell_scoop.py index fc60a75..abd6636 100644 --- a/bluepyopt/tests/disable_simplecell_scoop.py +++ b/bluepyopt/tests/disable_simplecell_scoop.py @@ -41,7 +41,7 @@ def disabled_scoop(): seclist_name='somatic') hh_mech = nrpel.mechanisms.NrnMODMechanism(name='hh', - prefix='hh', + suffix='hh', locations=[somatic_loc]) cm_param = nrpel.parameters.NrnSectionParameter(name='cm', diff --git a/bluepyopt/tests/test_ephys/test_mechanisms.py b/bluepyopt/tests/test_ephys/test_mechanisms.py index 8019eca..bdacda5 100644 --- a/bluepyopt/tests/test_ephys/test_mechanisms.py +++ b/bluepyopt/tests/test_ephys/test_mechanisms.py @@ -34,7 +34,7 @@ def test_nrnmod_instantiate(): test_mech = ephys.mechanisms.NrnMODMechanism( 'test.pas', - prefix='pas', + suffix='pas', locations=[simplecell.somatic_loc]) simple_cell.instantiate(sim=sim) diff --git a/bluepyopt/tests/test_ephys/utils.py b/bluepyopt/tests/test_ephys/utils.py index 1cde88f..1bdf51e 100644 --- a/bluepyopt/tests/test_ephys/utils.py +++ b/bluepyopt/tests/test_ephys/utils.py @@ -1,3 +1,5 @@ +"""EPhys test utils""" + from bluepyopt import ephys from bluepyopt.ephys.parameters import (NrnGlobalParameter, NrnSectionParameter, NrnRangeParameter, ) @@ -5,25 +7,47 @@ def make_mech(): + """Create mechanism""" basal = ephys.locations.NrnSeclistLocation('basal', seclist_name='basal') apical = ephys.locations.NrnSeclistLocation('apical', seclist_name='apical') - return ephys.mechanisms.NrnMODMechanism('Ih', prefix='Ih', locations=[basal, apical, ]) + return ephys.mechanisms.NrnMODMechanism( + 'Ih', + suffix='Ih', + locations=[ + basal, + apical, + ]) def make_parameters(): - value, frozen, bounds, param_name = 65, False, [0, 100.0], 'gSKv3_1bar_SKv3_1' + """Create parameters""" + value, frozen, bounds, param_name = 65, False, [ + 0, 100.0], 'gSKv3_1bar_SKv3_1' value_scaler = ephys.parameterscalers.NrnSegmentLinearScaler() locations = (NrnSeclistLocation('Location0', 'somatic'), - NrnSeclistLocation('Location1', 'apical'), - ) + NrnSeclistLocation('Location1', 'apical'),) parameters = ( - NrnGlobalParameter('NrnGlobalParameter', value, frozen, bounds, param_name), + NrnGlobalParameter( + 'NrnGlobalParameter', + value, + frozen, + bounds, + param_name), NrnSectionParameter( - 'NrnSectionParameter', value, frozen, bounds, param_name, value_scaler, locations), + 'NrnSectionParameter', + value, + frozen, + bounds, + param_name, + value_scaler, + locations), NrnRangeParameter( - 'NrnRangeParameter', value, frozen, bounds, param_name, value_scaler, locations), + 'NrnRangeParameter', + value, + frozen, + bounds, + param_name, + value_scaler, + locations), ) return parameters - - - diff --git a/examples/l5pc/l5_config.zip b/examples/l5pc/l5_config.zip index 4739ec6..60cb572 100644 Binary files a/examples/l5pc/l5_config.zip and b/examples/l5pc/l5_config.zip differ diff --git a/examples/l5pc/l5pc_model.py b/examples/l5pc/l5pc_model.py index 06a2025..5177422 100644 --- a/examples/l5pc/l5pc_model.py +++ b/examples/l5pc/l5pc_model.py @@ -51,7 +51,7 @@ def define_mechanisms(): mechanisms.append(ephys.mechanisms.NrnMODMechanism( name='%s.%s' % (channel, sectionlist), mod_path=None, - prefix=channel, + suffix=channel, locations=[seclist_loc], preloaded=True)) diff --git a/examples/simplecell/simplecell.ipynb b/examples/simplecell/simplecell.ipynb index aba43b5..4b993d3 100644 --- a/examples/simplecell/simplecell.ipynb +++ b/examples/simplecell/simplecell.ipynb @@ -129,7 +129,7 @@ "source": [ "hh_mech = ephys.mechanisms.NrnMODMechanism(\n", " name='hh',\n", - " prefix='hh',\n", + " suffix='hh',\n", " locations=[somatic_loc])" ] }, @@ -139,7 +139,7 @@ "collapsed": true }, "source": [ - "The 'name' field can be chosen by the user, this name should be unique. The 'prefix' points to the same field in the NMODL file of the channel. 'locations' specifies which sections the mechanism will be added to.\n", + "The 'name' field can be chosen by the user, this name should be unique. The 'suffix' points to the same field in the NMODL file of the channel. 'locations' specifies which sections the mechanism will be added to.\n", "\n", "### Creating parameters\n", "\n", @@ -814,7 +814,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.12" } }, "nbformat": 4, diff --git a/examples/stochkv/stochkvcell.py b/examples/stochkv/stochkvcell.py index d407e6f..1859d85 100644 --- a/examples/stochkv/stochkvcell.py +++ b/examples/stochkv/stochkvcell.py @@ -31,12 +31,12 @@ def run_stochkv_model(deterministic=False): seclist_name='somatic') stochkv_mech = ephys.mechanisms.NrnMODMechanism( name='StochKv', - prefix='StochKv', + suffix='StochKv', locations=[somatic_loc], deterministic=deterministic) pas_mech = ephys.mechanisms.NrnMODMechanism( name='pas', - prefix='pas', + suffix='pas', locations=[somatic_loc]) gkbar_param = ephys.parameters.NrnSectionParameter( name='gkbar_StochKv',