Code Monkey home page Code Monkey logo

arborize's People

Contributors

alessiomarta avatar dependabot[bot] avatar helveg avatar stefanocasali984 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

arborize's Issues

Simplify name of mechid synapses

The following syntax is allowed:

"synapse_types": {
 ("AMPA", "long_variant_name"): { ... }
 }

but the synapse name is ("AMPA", "long_variant_name"), which could be simplified to "AMPA", given that we check for and deal with collisions.

BluePyOpt integration/conversion/mixin

Similarly to how the BSB can be integrated with Blender I'd like to make an integration with BluePyOpt where a simple model.for_bluepyopt(**candidate, constraints=, output_handler=, ...) prepares the NeuronModel class for use within BluePyOpt, where **candidate is the candidate type descr of the candidate to test (usually no cand or a special test cand) and constraints can be ranges for parameters in section_types or synapse mechanisms and the output_handler is a way to save the results in a certain format that preferably can immediately be used as Arborize candidates.

issue with bluepyopt_build function

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/home/benozzo/dbbs_lab/test_opt/venv/lib/python3.9/site-packages/pebble/pool/process.py", line 169, in task_scheduler_loop
pool_manager.schedule(task)
File "/home/benozzo/dbbs_lab/test_opt/venv/lib/python3.9/site-packages/pebble/pool/process.py", line 218, in schedule
self.worker_manager.dispatch(task)
File "/home/benozzo/dbbs_lab/test_opt/venv/lib/python3.9/site-packages/pebble/pool/process.py", line 351, in dispatch
self.pool_channel.send(WorkerTask(task.id, task.payload))
File "/home/benozzo/dbbs_lab/test_opt/venv/lib/python3.9/site-packages/pebble/pool/channel.py", line 70, in send
return self.writer.send(obj)
File "/usr/lib/python3.9/multiprocessing/connection.py", line 211, in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "/usr/lib/python3.9/multiprocessing/reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
AttributeError: Can't pickle local object 'bluepyopt_build..ArborizeMorphology'

when running the optimization
moving back to what was in /origin/feature/optimization works

Detect Sections on NeuronModel that aren't in morphology arrays

Every Section on a NeuronModel should be part of any of the 3 main arrays soma, dendrites (or dend) and axon after construction. If the Section isn't part of these it won't be listed in self.sections and other tools might skip it. In order to warn the user make a __setattr__ function that checks if a value is a Section, list or dict of Sections and stores a weakref to it. Then when the model boots, all of these Sections should be in the aforementioned arrays, or a warning needs to be thrown.

Remove `labels`, make them builder functions

There is no need for specification of labels in a class dict, it could all be done by provided functions:

{
  "from": "axon",
  "diam": lambda d: d > 0.6
}

can be replaced by

morphologies = [(swc("morphology.swc"), diam_gt(0.6, filter=label_filter("axon")))]

Example package

To promote proper packaging (and subsequent quality assurance such as testing) we should provide and promote an example package

Problems with the cell definition and setting parameters

Hi, I am having some problems in building a cell with appropriate parameters defined in the definition.
The definition is the following:

from arborize import define_model
from arborize import bsb_schematic
from bsb.morphologies import Morphology
from arborize import neuron_build
import numpy as np
from patch import p

definitionGrCWT = define_model({
    "synapse_types": {
        "AMPA": {
            "mechanism": ("AMPA", "granule"),
            "attributes": {
                "tau_facil": 5,
                "tau_rec": 8,
                "tau_1": 1,
                "gmax": 1400,
                "U": 0.43,
            },
        },
        "NMDA": {
            "mechanism": ("NMDA", "granule"),
            "attributes": {
                "tau_facil": 5,
                "tau_rec": 8,
                "tau_1": 1,
                "gmax": 23500,
                "U": 0.43,
            },
        },
        "GABA": {"mechanism": ("GABA", "granule"), "attributes": {"U": 0.35}}
    },
    "cable_types": {

        "soma": {
            "cable": {"Ra": 100, "cm": 2},
            "ions": {"k": {"e": -80.993}, "ca": {"e": 137.5}},      #ek might be -88, before was -80.993
            "mechanisms": {
                "Leak": {"e": -60, "gmax": 0.00029038073716},
                "Kv3_4": {"gkbar": 0.00076192450952},
                "Kv4_3": {"gkbar": 0.00281496839061},
                "Kir2_3": {"gkbar": 0.00074725514702},
                "Ca": {"gcabar": 0.00060938071784},
                "Kv1_1": {"gbar": 0.00569738264555},
                "Kv1_5": {"gKur": 0.00083407556714},
                "Kv2_2": {"gKv2_2bar": 1.203410852e-05},
                ("cdp5", "CR"): {},
            },
        },
        "dendrites": {
            "cable": {"Ra": 100, "cm": 2.5},
            "ions": {"k": {"e": -80.993}, "ca": {"e": 137.5}},      # ek might be -88
            "mechanisms": {
                "Leak": {"e": -60, "gmax": 0.00025029700737},
                ("Leak", "GABA"): {"ggaba" : 0.0},  #Set to 0
                "Ca": {"gcabar": 0.00500128008459},
                "Kca1_1": {"gbar": 0.01001807454651},
                "Kv1_1": {"gbar": 0.00381819207934},
                ("cdp5", "CR"): {},
            },
        },
        "axon": {"cable": {}, "ions": {}, "mechanisms": {}},
        "ascending_axon": {
            "cable": {"Ra": 100, "cm": 1},
            "ions": {"na": {"e": 87.39}, "k": {"e": -80.993}, "ca": {"e": 137.5}},      # ek might be -88
            "mechanisms": {
                ("Na", "granule_cell"): {"gnabar": 0.02630163681502},
                "Kv3_4": {"gkbar": 0.00237386061632},
                "Leak": {"e": -60, "gmax": 9.364092125e-05},
                "Ca": {"gcabar": 0.00068197420273},
                ("cdp5", "CR"): {},
            },
        },
        "axon_initial_segment": {
            "cable": {"Ra": 100, "cm": 1},
            "ions": {"na": {"e": 87.39}, "k": {"e": -80.993}, "ca": {"e": 137.5}},        # ek might be -88
            "mechanisms": {
                ("Na", "granule_cell_FHF"): {"gnabar": 1.28725006737226},
                "Kv3_4": {"gkbar": 0.00649595340654},
                "Leak": {"e": -60, "gmax": 0.00029276697557},
                "Ca": {"gcabar": 0.00031198539472},
                "Km": {"gkbar": 0.00056671971737},
                ("cdp5", "CR"): {},
            },
        },
        "axon_hillock": {
            "cable": {"Ra": 100, "cm": 2},
            "ions": {"na": {"e": 87.39}, "k": {"e": -80.993}, "ca": {"e": 137.5}},                      # ek might be -88
            "mechanisms": {
                "Leak": {"e": -60, "gmax": 0.0003695818972},
                ("Na", "granule_cell_FHF"): {"gnabar": 0.00928805851462},
                "Kv3_4": {"gkbar": 0.02037346310915},
                "Ca": {"gcabar": 0.00057726155447},
                ("cdp5", "CR"): {},
            },
        },
        "parallel_fiber": {
            "cable": {"Ra": 100, "cm": 1},
            "ions": {"na": {"e": 87.39}, "k": {"e": -80.993}, "ca": {"e": 137.5}},                      # ek might be -88
            "mechanisms": {
                ("Na", "granule_cell"): {"gnabar": 0.01771848449261},
                "Kv3_4": {"gkbar": 0.00817568047037},
                "Leak": {"e": -60, "gmax": 3.5301616e-07},
                "Ca": {"gcabar": 0.0002085683353},
                ("cdp5", "CR"): {},
            },
        },
    },
})


tagsGrC = {
    16: ["axon", "axon_hillock"],
    17: ["axon", "axon_initial_segment"],
    18: ["axon", "ascending_axon"],
    19: ["axon", "parallel_fiber"],
}

Then I build the cell:

morpho = Morphology.from_swc("Morphologies/GranuleCell.swc", tags=tagsGrC)
schematic = bsb_schematic(morpho, definitionGrCWT)
cell = neuron_build(schematic)

Then I try to check if everything is ok, for instance at the level of the soma:

cell.soma[0].psection()

And I obtain the following output:

{'point_processes': {}, 'density_mechs': {'glia__dbbs_mod_collection__Kir2_3__0': {'Aalpha_d': [0.13289], 'Kalpha_d': [-24.3902], 'V0alpha_d': [-83.94], 'Abeta_d': [0.16994], 'Kbeta_d': [35.714], 'V0beta_d': [-83.94], 'gkbar': [0.00074725514702], 'ik': [0.0], 'd_inf': [0.0], 'tau_d': [0.0], 'g': [0.0], 'alpha_d': [0.0], 'beta_d': [0.0], 'd': [0.0]}, 'glia__dbbs_mod_collection__Kv1_1__0': {'gateCurrent': [0.0], 'gbar': [0.00569738264555], 'gunit': [16.0], 'ik': [0.0], 'i': [0.0], 'igate': [0.0], 'g': [0.0], 'nc': [0.0], 'ninf': [0.0], 'taun': [0.0], 'n': [0.0]}, 'glia__dbbs_mod_collection__cdp5__CR': {'Nannuli': [10.9495], 'cainull': [4.5e-05], 'Buffnull2': [60.9091], 'rf3': [0.1435], 'rf4': [0.0014], 'CRnull': [0.9], 'TotalPump': [1e-09], 'ica_pmp': [0.0], 'vrat': [0.0], 'ca': [0.0], 'mg': [0.0], 'Buff1': [0.0], 'Buff1_ca': [0.0], 'Buff2': [0.0], 'Buff2_ca': [0.0], 'BTC': [0.0], 'BTC_ca': [0.0], 'DMNPE': [0.0], 'DMNPE_ca': [0.0], 'CR': [0.0], 'CR_1C_0N': [0.0], 'CR_2C_0N': [0.0], 'CR_2C_1N': [0.0], 'CR_1C_1N': [0.0], 'CR_0C_1N': [0.0], 'CR_0C_2N': [0.0], 'CR_1C_2N': [0.0], 'CR_2C_2N': [0.0], 'CR_1V': [0.0], 'pump': [0.0], 'pumpca': [0.0]}, 'glia__dbbs_mod_collection__Ca__granule_cell': {'Aalpha_s': [0.04944], 'Kalpha_s': [15.873], 'V0alpha_s': [-29.06], 'Abeta_s': [0.08298], 'Kbeta_s': [-25.641], 'V0beta_s': [-18.66], 'Aalpha_u': [0.0013], 'Kalpha_u': [-18.183], 'V0alpha_u': [-48.0], 'Abeta_u': [0.0013], 'Kbeta_u': [83.33], 'V0beta_u': [-48.0], 'gcabar': [0.00060938071784], 'ica': [0.0], 's_inf': [0.0], 'u_inf': [0.0], 'tau_s': [0.0], 'tau_u': [0.0], 'g': [0.0], 'alpha_s': [0.0], 'beta_s': [0.0], 'alpha_u': [0.0], 'beta_u': [0.0], 's': [0.0], 'u': [0.0]}, 'glia__dbbs_mod_collection__Kv2_2__0': {'gKv2_2bar': [1.203410852e-05], 'BBiD': [10.0], 'ik': [0.0], 'gKv2_2': [0.0], 'm': [0.0], 'h': [0.0]}, 'glia__dbbs_mod_collection__Kv4_3__0': {'Aalpha_a': [0.8147], 'Kalpha_a': [-23.3271], 'V0alpha_a': [-9.17203], 'Abeta_a': [0.1655], 'Kbeta_a': [19.4718], 'V0beta_a': [-18.2791], 'Aalpha_b': [0.0368], 'Kalpha_b': [12.8433], 'V0alpha_b': [-111.332], 'Abeta_b': [0.0345], 'Kbeta_b': [-8.90123], 'V0beta_b': [-49.9537], 'V0_ainf': [-38.0], 'K_ainf': [-17.0], 'V0_binf': [-78.8], 'K_binf': [8.4], 'gkbar': [0.00281496839061], 'ik': [0.0], 'a_inf': [0.0], 'b_inf': [0.0], 'tau_a': [0.0], 'tau_b': [0.0], 'g': [0.0], 'alpha_a': [0.0], 'beta_a': [0.0], 'alpha_b': [0.0], 'beta_b': [0.0], 'a': [0.0], 'b': [0.0]}, 'glia__dbbs_mod_collection__Leak__0': {'gmax': [0.00029038073716], 'e': [-60.0], 'il': [0.0]}, 'glia__dbbs_mod_collection__Kv1_5__0': {'gKur': [0.00083407556714], 'Tauact': [1.0], 'Tauinactf': [1.0], 'Tauinacts': [1.0], 'gnonspec': [0.0], 'ik': [0.0], 'minf': [0.0], 'ninf': [0.0], 'uinf': [0.0], 'mtau': [0.0], 'ntau': [0.0], 'utau': [0.0], 'ino': [0.0], 'm': [0.0], 'n': [0.0], 'u': [0.0]}, 'glia__dbbs_mod_collection__Kv3_4__0': {'gkbar': [0.00076192450952], 'ik': [0.0], 'minf': [0.0], 'mtau': [0.0], 'hinf': [0.0], 'htau': [0.0], 'm': [0.0], 'h': [0.0]}}, 'ions': {'na': {'ena': [50.0], 'nai': [10.0], 'nao': [140.0], 'ina': [0.0], 'dina_dv_': [0.0]}, 'k': {'ek': [-77.0], 'ki': [54.4], 'ko': [2.5], 'ik': [0.0], 'dik_dv_': [0.0]}, 'ca': {'eca': [132.4579341637009], 'cai': [5e-05], 'cao': [2.0], 'ica': [0.0], 'dica_dv_': [0.0]}, 'no': {'eno': [0.0], 'noi': [1.0], 'noo': [1.0], 'ino': [0.0], 'dino_dv_': [0.0]}}, 'morphology': {'L': 5.622320175170898, 'diam': [5.800000190734863], 'pts3d': [(0.0, 0.0, 0.0, 5.800000190734863), (0.0, 5.622320175170898, 0.0, 5.800000190734863)], 'parent': None, 'trueparent': None}, 'nseg': 1, 'Ra': 100.0, 'cm': [1.0], 'regions': set(), 'species': set(), 'name': 'SBDEAEIOZX_1_interval (0.0-1)', 'hoc_internal_name': '__nrnsec_0x555681876560', 'cell': None}

But this does not really match what I asked in the definition. For instance I defined the cm as 2, but it was actually set 1. Something strange occurs for ek, and probably for other parameters. What is wrong with my definition?

Convert Builders to pipes

"Historically" we started out just using NEURON's import3d and the builders reflect this by mimicking their interface.

This can be simplified if we:

  • Disallow strings and instead require a file type wrapper function like swc('morphology')
  • Allow any callable
  • "Treat" every element:
    • Any root tuple gets treated as a call to a new pipe function that replaces the ComboBuilder, and any tuple passed to the pipe function is also converted to a call to the pipe function.

In the end this should allow most morphology CandidateType backends to describe a full pipe as a string that can be evaluated to build the model sections.

Candidates

A candidate is a one-to-many relationship with the model. Every model can define their own CandidateTypes with morphology, section_types and synapses being the standard types. Whether candidates of different types can be used together is governed by a CandidateRelation. Each relation is passed the full combination of types and can discard those it doesn't need and govern those it does apply to and return whether that combination is allowed or not. After verifying that all CandidateRelations are valid the full combination of candidate types is given to each candidate type for lookup.

The purpose is that both type and relation know how to lookup candidates either in a dependent (eg. you need to know the morphology to know which electrophysiology candidates to load) or independent manner (there's just 2 big lists of morphos and physios). The model can then just factorize itself based on which CandidateType and CandidateRelations are present as class attributes (eg which kwargs to wrap the constructor in). The types can only be set in the constructor, as the model loads itself during the constructor and needs to be completely ready for use afterwards.

Each different storage backend should provide their own set of type and relation objects, I think out of the box we should only provide a handler that uses a directory for morphologies and an HDF5 file for electro & synapses.

Post-processing should be possible through pipes: The base candidate type class should contain a pipe kwarg that gets called on the lookup result.

The lookup results of the 3 main types are supposed to be:

  • morphology: anything that can be turned into a builder, so what currently would've been inside of the morphologies array.
  • section_types: the dictionary of types that currently would've been inside of the section_types dictionary.
  • synapses: the dictionary of synapses that currently would've been inside of the synapses dictionary.

Default values of rev_pot, int_con, ext_con are missing for "h"

In class default_ions_dict, default values of rev_pot, int_con, ext_con are defined only for "na", "k", "ca" but not for "h", which is used in the definitions of basket, purkinje and stellate cells. The default value of the reverse potential is -34 mV, but I have no idea of the default values of int_con and ext_con.

Purkinje cell does not receive default values of int_con and ext_con

Hi, I am still facing some problems when I try to build the Purkinje cell model from the definition.
It seems that the Purkinje cell model does not have default values for int_con and ext_con, whereas the granule cell does have it and I do not need to introduce these values in the definition.

My code is:

from arborize import bsb_schematic
from bsb.morphologies import Morphology
from bsb.plotting import plot_morphology
from arborize import neuron_build
import numpy as np
from patch import p

from models.Purkinje_cell.purkinje_cell import definitionPCWT, tagsPC

morpho = Morphology.from_swc(
            "Morphologies/PurkinjeCell.swc", tags=tagsPC)
schematic = bsb_schematic(morpho, definitionPCWT)
cell = neuron_build(schematic)

And this is the error that I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/builders/_neuron.py", line 135, in neuron_build
    schematic.freeze()
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/schematic.py", line 128, in freeze
    self._flatten_branches(self.roots)
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/schematic.py", line 143, in _flatten_branches
    raise ModelDefinitionError(
arborize.exceptions.ModelDefinitionError: location (0.0) labelled 'soma' misses value for ('na', 'int_con')

I am currently using arborize 4.0.0a5 version. Default values are expected to work as for the granule cell model. Can you help me?

Thanks

unable to access density mechanism to record currents

I am trying to access density mechanism to record currents from one specific ion channel.
Using arborize, it seems to me that only point processes could be accessed, but not density mechanisms such as ica or ina and so on and so forth.

In brief, I have tried different methods to access density mechanism, but none worked.

# METHOD 1 (choose between A and B)
# A
ica = p.record(m.ascending_axon[0]._ref_ica_glia__dbbs_mod_collection__Ca__granule_cell)

# B
ica = p.record(m.ascending_axon[0]._ref_ica)
        
# METHOD 2
loc = cell.get_location((1,8))
mech = loc.mechanisms[('Ca')]
ica = mech.get_parameter('_ref_ica')

print(ica, type(ica))

I leave you here some files that might be useful to do test on this issue.
Test density mechanism.zip

Add prefix hash in arbor catalogue

Catalogues of different models should never collide, so make sure to change the catalogue interface a bit so that the result is prefixed with a hash.

Users should:

  • Declare a make_catalogue function.

Arborize should:

  • Call that function only once per model/(or per package?) and prefix it with the hash.
    • Hash made from sorted names and parameters (hopefully enough to avoid collision)
  • Make the hashed catalogue available through get_catalogue.
  • Transparently translate all mechanism definitions into hash-prefixed instructions.

Consumers should:

  • Call get_catalogue and merge it into their recipe catalogue, ignoring RuntimeErrors that signify collision.

This approach gives users the possibility to use very standard catalogues - for example the default catalogue - and gives consumers the possibility to safely merge partially overlapping the catalogues of multiple users.

Define better behavior/error for missing label

Traceback (most recent call last):
  File "C:\Users\robin\AppData\Local\Programs\Python\Python37\Scripts\scaffold-script.py", line 11, in <module>
    load_entry_point('dbbs-scaffold', 'console_scripts', 'scaffold')()
  File "c:\users\robin\documents\git\scaffold-model\scaffold\cli.py", line 25, in scaffold_cli
    start_cli()
  File "c:\users\robin\documents\git\scaffold-model\scaffold\cli.py", line 214, in start_cli
    scaffoldInstance.run_simulation(cl_args.simulation)
  File "c:\users\robin\documents\git\scaffold-model\scaffold\core.py", line 274, in run_simulation
    simulation, simulator = self.prepare_simulation(simulation_name)
  File "c:\users\robin\documents\git\scaffold-model\scaffold\core.py", line 290, in prepare_simulation
    simulator = simulation.prepare()
  File "c:\users\robin\documents\git\scaffold-model\scaffold\simulators\neuron.py", line 126, in prepare
    self.create_neurons()
  File "c:\users\robin\documents\git\scaffold-model\scaffold\simulators\neuron.py", line 150, in create_neurons
    instance = cell_model.model_class(**kwargs)
  File "c:\users\robin\documents\git\arborize\arborize\core.py", line 60, in __init__
    self._init_section(section)
  File "c:\users\robin\documents\git\arborize\arborize\core.py", line 107, in _init_section
    self._init_section_label(section, label)
  File "c:\users\robin\documents\git\arborize\arborize\core.py", line 112, in _init_section_label
    definition = self.__class__.section_types[label]
KeyError: 'axon'

Problems in building the Purkinje cell

I found some problems with the Purkinje cell. After the last release, I am not able anymore to build the cell. I will give you the definition and the commands that I am writing in the CLI:


definitionPCWT = define_model({
    "synapse_types": {
        "AMPA": {
            "mechanism": "AMPA",
            "parameters": {
                "tau_facil": 54,
                "tau_rec": 35.1,
                "tau_1": 6,
                "gmax": 1200,
                "U": 0.13,
            },
        },
        "GABA": {
            "mechanism": "GABA",
            "parameters": {
                "tau_facil": 4,
                "tau_rec": 15,
                "tau_1": 1,
                "Erev": -70,
                "gmax": 2600,
                "U": 0.35,
            },
        },
    },
    "cable_types": {
        "soma": {
            "cable": {"Ra": 122, "cm": 1},
            "ions": {
                "na": {"rev_pot": 60},
                "k": {"rev_pot": -88},
                "h": {"rev_pot": -34.4},
                "ca": {"rev_pot": 137.52625}
                },
            "mechanisms": {
                "Leak": {"e": -61, "gmax": 0.001},
                "Nav1_6": {"gbar": 0.19835422387652},
                "Kv1_1": {"gbar": 0.00185494695569},
                "Kv3_4": {"gkbar": 0.05684366437809},
                "Kir2_3": {"gkbar": 2.100544604e-05},
                "Cav2_1": {"pcabar": 0.0001530123689},
                "Cav3_1": {"pcabar": 4.19659246e-06},
                "Cav3_2": {"gcabar": 0.00067268089296},
                "Cav3_3": {"pcabar": 0.00015401124325},
                "Kca1_1": {"gbar": 0.00877088561313},
                "Kca2_2": {"gkbar": 0.00085748826176},
                "Kca3_1": {"gkbar": 0.00978230722317},
                "HCN1": {"gbar": 0.00192222696826},
                ("cdp5", "CAM"): {"TotalPump": 2e-08},
            },
            "synapses": {
                "GABA": {
                    "mechanism": "GABA",
                    "parameters": {
                        "tau_facil": 4,
                        "tau_rec": 15,
                        "tau_1": 1,
                        "Erev": -70,
                        "gmax": 2600,
                        "U": 0.35,
                    },
                },
            },
        },
        "dendrites": {
            "cable": {
                # "cm": lambda d: (11.510294 * math.exp(-1.376463 * d) + 2.120503),
                # Formula for cm varied from 2 to 6, aprroximated with avg
                "cm": 5.577701084442752,
                "Ra": 122,
            },
            "ions": {
                "na": {"rev_pot": 60},
                "k": {"rev_pot": -88},
                "h": {"rev_pot": -34.4},
                "ca": {"rev_pot": 137.52625},
            },
            "mechanisms": {
                "Leak": {"e": -61, "gmax": 0.0003},
                "Kv1_1": {"gbar": 0.00105296938319},
                "Kv1_5": {"gKur": 0.00018237109331},
                "Kv3_3": {"gbar": 0.01192448545734},
                "Kv4_3": {"gkbar": 0.00082020749325},
                "Cav2_1": {"pcabar": 0.001594103024736},
                "Cav3_3": {"pcabar": 0.00013000262047},
                "Kca1_1": {"gbar": 0.03803999223084},
                "HCN1": {"gbar": 2.49811225e-06},
                ("cdp5", "CAM"): {"TotalPump": 5e-08},
            },
            "synapses": {
                "AMPA": {
                    "mechanism": "AMPA",
                    "parameters": {
                        "tau_facil": 54,
                        "tau_rec": 35.1,
                        "tau_1": 6,
                        "gmax": 1200,
                        "U": 0.13,
                    },
                },
            },
        },
        "basal_dendrites": {
            "cable": {"Ra": 122, "cm": 1},
            "ions": {
                "na": {"rev_pot": 60}, "k": {"rev_pot": -88}, "ca": {"rev_pot": 137.52625}
                },
            "mechanisms": {
                "Leak": {"e": -61, "gmax": 0.0003},
                "Kir2_3": {"gkbar": 1.135399111e-05},
                "Cav3_1": {"pcabar": 4.0066819e-06},
                "Cav3_2": {"gcabar": 0.00194175819441},
                "Kca2_2": {"gkbar": 0.00078534639818},
                "Kca3_1": {"gkbar": 0.00330481139341},
            },
        },
        "sodium_dendrites": {
            "cable": {"Ra": 122, "cm": 1},
            "ions": {
                "na": {"rev_pot": 60}, "k": {"rev_pot": -88}, "ca": {"rev_pot": 137.52625}
                },
            "mechanisms": {
                "Leak": {"e": -61, "gmax": 0.0003},
                "Kir2_3": {"gkbar": 1.135399111e-05},
                "Cav3_1": {"pcabar": 4.0066819e-06},
                "Cav3_2": {"gcabar": 0.00194175819441},
                "Kca2_2": {"gkbar": 0.00078534639818},
                "Kca3_1": {"gkbar": 0.00330481139341},
                "Nav1_6": {"gbar": 0.01568012827236},
            },
        },
        "aa_targets": {"cable": {}, "ions": {}, "mechanisms": {}},
        "pf_targets": {"cable": {}, "ions": {}, "mechanisms": {}},
        "sc_targets": {"cable": {}, "ions": {}, "mechanisms": {}},
        "AIS": {
            "cable": {"Ra": 122, "cm": 1},
            "ions": {
                "na": {"rev_pot": 60}, "k": {"rev_pot": -88}, "ca": {"rev_pot": 137.52625}
                },
            "mechanisms": {
                "Leak": {"e": -61, "gmax": 0.0003},
                "Nav1_6": {"gbar": 0.76520432560779},
                "Kv3_4": {"gkbar": 0.01470016164534},
                "Cav2_1": {"pcabar": 0.00028786836482},
                "Cav3_1": {"pcabar": 6.43429659e-06},
                ("cdp5", "CAM"): {"TotalPump": 2e-08},
            },
        },
        "axon": {"cable": {}, "ions": {}, "mechanisms": {}},
        "AIS_K": {
            "cable": {"Ra": 122, "cm": 1},
            "ions": {
                "k": {"rev_pot": -88}
                },
            "mechanisms": {
                "Leak": {"e": -61, "gmax": 0.0003},
                "Kv1_1": {"gbar": 0.01011038066089},
            },
        },
        "axonmyelin": {
            "cable": {"Ra": 122, "cm": 1.87e-11},
            "ions": {},
            "mechanisms": {"pas": {"e": -61, "g": 5.6e-09}},
        },
        "nodes": {
            "cable": {"Ra": 122, "cm": 1},
            "ions": {
                "na": {"rev_pot": 60}, "k": {"rev_pot": -88}, "ca": {"rev_pot": 137.52625}
                },
            "mechanisms": {
                "Leak": {"e": -61, "gmax": 0.0003},
                "Nav1_6": {"gbar": 0.02749309338198},
                "Kv3_4": {"gkbar": 0.02227585026371},
                "Cav2_1": {"pcabar": 0.00012353396215},
                "Cav3_1": {"pcabar": 1.508814156e-05},
                ("cdp5", "CAM"): {"TotalPump": 5e-07},
            },
        },
    },
})


tagsPC = {
    16: ["axon", "AIS"],
    17: ["axon", "AIS_K"],
    18: ["axon", "axonmyelin"],
    19: ["axon", "nodes"],
    20: ["dendrites", "basal_dendrites"],
    21: ["dendrites", "pf_targets", "sc_targets"],
    22: ["dendrites", "aa_targets", "sc_targets"],
}

After the definition I continue in this way:

morpho = Morphology.from_swc("Morphologies/PurkinjeCell.swc", tags=tagsPC)
schematic = bsb_schematic(morpho, definitionPCWT)
cell = neuron_build(schematic)

And then it returns this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/builders/_neuron.py", line 131, in neuron_build
    schematic.freeze()
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/schematic.py", line 128, in freeze
    self._flatten_branches(self.roots)
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/schematic.py", line 147, in _flatten_branches
    self._flatten_branches(branch.children)
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/schematic.py", line 147, in _flatten_branches
    self._flatten_branches(branch.children)
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/schematic.py", line 134, in _flatten_branches
    branch.definition = self._makedef(branch.labels)
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/schematic.py", line 160, in _makedef
    return CableType.anchor(
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/definitions.py", line 142, in anchor
    def_.merge(def_right)
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/definitions.py", line 147, in merge
    self._mergedict(self.ions, def_right.ions)
  File "/mnt/c/Users/pc/.vscode/Thesis_2/arborize/arborize/definitions.py", line 154, in _mergedict
    dself[key].merge(dother[key])
AttributeError: 'Ion' object has no attribute 'merge' 

Doing a bit of debugging it seems that the error stands in "dendrites". Its ion description is identical to the one of the "soma", but the one of the dendrites give problems. I discovered this removing/commenting the ions in each section, and the only one that gives problems is that of "dendrites". Hope it could help. If there is somenthing wrong in my code let me know, please.
Thank you.

Fix nseg setting

Setting the nseg to 1 + int(section.L / 40) * 2 should be an optional builder function, not baked in to override by default.

Add `label_resolution` class attribute

We allow for labels to be added to the sections, but it might also be useful for other tools to allow for more fine grained labelling per x3d, y3d & z3d rather than per section. We could let the user decide with a label_resolution class attribute being "section"(default) or "segment". We'd also need to have a way to reduce the segment labels to section labels, which will be trickier, or perhaps allow both sec and seg labelling, instead adding a label_segments=True flag? If a reduction of seg labels is still appropriate a class method could be set to handle it after segment labelling is complete.

Cache labelling results

As @claudiacasellato suggested it could be beneficial to cache the labelling results; there are some considerations however:

  • When multiple candidate types (#10) are considered the number of different combinatorial possibilities might surpass the cell count or atleast reduce caching efficiency.
  • Caching many sets of labels might significantly increase the memory footprint and is useless to be retained during simulation.

The first consideration can be adressed by allowing a class attribute cache_labels = False to be set on the model by users who know they won't benefit from it. The second would require either a monkey patch of Patch so that when the simulated is started a cleanup phase can be held and the cache can be discarded. Another solution is a function the user can call to throw away the label cache. The manual function would allow people that don't use patch (but this isn't endorsed) to still throw away the cache before starting their sims. (And solution 1 could use this function during the cleanup phase)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.