1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690 |
- #!/usr/bin/env python3
- """
- Post process and add biophysics to cells.
- We make any updates to the morphology, and add biophysics.
- File: NeuroML2/postprocess_cells.py
- Copyright 2022 Ankur Sinha
- Author: Ankur Sinha <sanjay DOT ankur AT gmail DOT com>
- """
- import random
- import sys
- import neuroml
- import numpy
- from neuroml.loaders import read_neuroml2_file
- from neuroml.neuro_lex_ids import neuro_lex_ids
- from pyneuroml.analysis import generate_current_vs_frequency_curve
- from pyneuroml.lems.LEMSSimulation import LEMSSimulation
- from pyneuroml.plot.PlotMorphology import plot_2D
- from pyneuroml.pynml import run_lems_with_jneuroml_neuron, write_neuroml2_file
- random.seed(1412)
- def load_and_setup_cell(cellname: str):
- """Load a cell, and clean it to prepare it for further modifications.
- These operations are common for all cells.
- :param cellname: name of cell.
- the file containing the cell should then be <cell>.morph.cell.nml
- :returns: document with cell
- :rtype: neuroml.NeuroMLDocument
- """
- celldoc = read_neuroml2_file(
- f"{cellname}.morph.cell.nml"
- ) # type: neuroml.NeuroMLDocument
- cell = celldoc.cells[0] # type: neuroml.Cell
- celldoc.networks = []
- cell.id = cellname
- cell.notes = cell.notes.replace("NeuronTemplate_0_0", cellname)
- cell.notes += ". Reference: Yao, H. K.; Guet-McCreight, A.; Mazza, F.; Moradi Chameh, H.; Prevot, T. D.; Griffiths, J. D.; Tripathy, S. J.; Valiante, T. A.; Sibille, E. & Hay, E. Reduced inhibition in depression impairs stimulus processing in human cortical microcircuits Cell Reports, Elsevier, 2022, 38"
- # create default groups if they don't exist
- [
- default_all_group,
- default_soma_group,
- default_dendrite_group,
- default_axon_group,
- ] = cell.setup_default_segment_groups(
- use_convention=True,
- default_groups=["all", "soma_group", "dendrite_group", "axon_group"],
- )
- # populate default groups
- for sg in cell.morphology.segment_groups:
- if "soma" in sg.id and sg.id != "soma_group":
- default_soma_group.add(neuroml.Include(segment_groups=sg.id))
- if "axon" in sg.id and sg.id != "axon_group":
- default_axon_group.add(neuroml.Include(segment_groups=sg.id))
- if "dend" in sg.id and sg.id != "dendrite_group":
- default_dendrite_group.add(neuroml.Include(segment_groups=sg.id))
- cell.optimise_segment_groups()
- return celldoc
- def postprocess_HL23PYR():
- """Post process HL23PYR and add biophysics."""
- cellname = "HL23PYR"
- celldoc = load_and_setup_cell(cellname)
- cell = celldoc.cells[0] # type: neuroml.Cell
- # apical dendrites are in groups called apic_
- # basal dendrites are in groups called dend_
- # populate the complete dendrite group, and new groups for all apical and
- # basal dendrites
- default_dendrite_group = cell.get_segment_group("dendrite_group")
- basal_group = cell.add_segment_group(
- "basal_dendrite_group",
- neuro_lex_id=neuro_lex_ids["dend"],
- notes="Basal dendrites",
- )
- apical_group = cell.add_segment_group(
- "apical_dendrite_group",
- neuro_lex_id=neuro_lex_ids["dend"],
- notes="Apical dendrite_group",
- )
- # create new global myelin group
- myelin_group = cell.add_segment_group("myelin_group", notes="Myelin group")
- for sg in cell.morphology.segment_groups:
- if "apic_" in sg.id:
- apical_group.add(neuroml.Include(segment_groups=sg.id))
- if "dend_" in sg.id:
- basal_group.add(neuroml.Include(segment_groups=sg.id))
- if "myelin_" in sg.id and sg.id != "myelin_group":
- myelin_group.add(neuroml.Include(segment_groups=sg.id))
- # myelin groups are not included in the all segment group when adding
- # biophys
- all_segment_group = cell.get_segment_group("all") # type neuroml.SegmentGroup
- all_minus_myelin = cell.add_segment_group(
- "all_minus_myelin", notes="All without myelin"
- )
- for inc in all_segment_group.includes:
- if "myelin" not in inc.segment_groups:
- all_minus_myelin.includes.append(inc)
- for sg in all_segment_group.members:
- if "myelin" not in sg.segment:
- all_minus_myelin.members.append(sg)
- # optimise dendrite group
- default_dendrite_group.includes = []
- default_dendrite_group.includes.append(
- neuroml.Include(segment_groups=apical_group.id)
- )
- default_dendrite_group.includes.append(
- neuroml.Include(segment_groups=basal_group.id)
- )
- cell.optimise_segment_groups()
- cell.reorder_segment_groups()
- # biophysics
- # include calcium dynamics component
- celldoc.add(neuroml.IncludeType(href="CaDynamics_E2_NML2.nml"), validate=False)
- # all
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="pas",
- ion_channel="pas",
- cond_density="0.0000954 S_per_cm2",
- erev="-80 mV",
- group_id="all_minus_myelin",
- ion="non_specific",
- ion_chan_def_file="channels/pas.channel.nml",
- )
- cell.set_resistivity("0.1 kohm_cm", group_id="all_minus_myelin")
- cell.set_specific_capacitance("1 uF_per_cm2", group_id="all_minus_myelin")
- cell.set_init_memb_potential("-80mV")
- # 10mV is default for Neuron spike threshold in NetCon
- # https://www.neuron.yale.edu/neuron/static/py_doc/modelspec/programmatic/network/netcon.html
- cell.biophysical_properties.membrane_properties.spike_threshes.append(neuroml.SpikeThresh(value="10mV", segment_groups='all'))
- # myelin
- cell.set_specific_capacitance("0.02 uF_per_cm2", group_id="myelin_group")
- cell.set_resistivity("0.1 kohm_cm", group_id="myelin_group")
- # write passive cell
- write_neuroml2_file(celldoc, f"{cellname}.pas.cell.nml")
- # somatic
- soma_group = cell.get_segment_group("soma_group")
- sgid = soma_group.id
- print(f"Adding channels to {sgid}")
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_somatic",
- ion_channel="SK",
- cond_density="0.000853 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_somatic",
- ion_channel="K_T",
- cond_density="0.0605 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_somatic",
- ion_channel="K_P",
- cond_density="0.000208 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_somatic",
- ion_channel="Kv3_1",
- cond_density="0.0424 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih_somatic",
- ion_channel="Ih",
- cond_density="0.000148 S_per_cm2",
- erev="-45 mV",
- group_id=sgid,
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_somatic",
- ion_channel="Im",
- cond_density="0.000306 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_somatic",
- ion_channel="NaTg_PYR_somatic",
- cond_density="0.272 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- # Ca
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_PYR_somatic",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- # https://www.neuron.yale.edu/neuron/static/new_doc/modelspec/programmatic/ions.html
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_somatic",
- ion_channel="Ca_HVA",
- cond_density="0.00155 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_somatic",
- ion_channel="Ca_LVA",
- cond_density="0.00296 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # Apical
- sg = cell.get_segment_group("apical_dendrite_group")
- cell.set_specific_capacitance("2 uF_per_cm2", group_id=sg.id)
- # Add parameter that we use to distribute Ih
- sg.add(
- "InhomogeneousParameter",
- id="PathLengthOverApicDends",
- variable="p",
- metric="Path Length from root",
- proximal=sg.component_factory("ProximalDetails", translation_start="0"),
- )
- # distribute Ih
- cdnonuniform = cell.add_channel_density_v(
- "ChannelDensityNonUniform",
- nml_cell_doc=celldoc,
- id="Ih_apical",
- ion_channel="Ih",
- ion="hcn",
- erev="-45 mV",
- )
- varparam = cdnonuniform.add(
- "VariableParameter",
- parameter="condDensity",
- segment_groups=sg.id,
- validate=False,
- )
- # TODO: clarify unit conversions
- # 606.3464 is the value of getLongestBranch("apic")
- # run test_HL23PYR.hoc, and then run:
- # > access HL23PYR.apic
- # > HL23PYR.soma distance()
- # > HL23PYR.getLongestBranch("apic")
- inhomogeneous_value = varparam.add(
- "InhomogeneousValue",
- inhomogeneous_parameters="PathLengthOverApicDends",
- value="1E9 * (0.148 * 1E-8) * ((2.087 * exp( 3.6161 * (p/606.3464))) - 0.8696)",
- )
- # Basal
- basal_group = cell.get_segment_group("basal_dendrite_group")
- sgid = basal_group.id
- cell.set_specific_capacitance("2 uF_per_cm2", group_id=sgid)
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih_basal",
- ion_channel="Ih",
- cond_density="0.000000709 S_per_cm2",
- erev="-45 mV",
- group_id=sgid,
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- # Axonal
- axon_group = cell.get_segment_group("axon_group")
- sgid = axon_group.id
- print(f"Adding channels to {sgid}")
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_axonal",
- ion_channel="SK",
- cond_density="0.0145 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_axonal",
- ion_channel="K_T",
- cond_density="0.0424 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_axonal",
- ion_channel="K_P",
- cond_density="0.338 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_axonal",
- ion_channel="Im",
- cond_density="0.000 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_axonal",
- ion_channel="Kv3_1",
- cond_density="0.941 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_axonal",
- ion_channel="NaTg_PYR_axonal",
- cond_density="1.38 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Nap_axonal",
- ion_channel="Nap",
- cond_density="0.00842 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/Nap.channel.nml",
- )
- # Ca
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_axonal",
- ion_channel="Ca_HVA",
- cond_density="0.0003060000 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_axonal",
- ion_channel="Ca_LVA",
- cond_density="0.0439000000 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_PYR_axonal",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih_axonal",
- ion_channel="Ih",
- cond_density="0.00001 S_per_cm2",
- erev="-45 mV",
- group_id=sgid,
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- # L1 validation
- # cell.validate(recursive=True)
- # cell.summary(morph=False, biophys=True)
- # use pynml writer to also run L2 validation
- write_neuroml2_file(celldoc, f"{cellname}.cell.nml")
- def postprocess_HL23PV():
- """Post process HL23PV and add biophysics.
- Each cell needs its biophysics to be added, so we do each cell separately.
- """
- cellname = "HL23PV"
- celldoc = load_and_setup_cell(cellname)
- cell = celldoc.cells[0] # type: neuroml.Cell
- print("Segment groups:")
- for sg in cell.morphology.segment_groups:
- print(f"** {sg.id} **")
- print(cell.get_all_segments_in_group(sg.id))
- print()
- # biophysics
- # include calcium dynamics component
- celldoc.add(neuroml.IncludeType(href="CaDynamics_E2_NML2.nml"), validate=False)
- # all
- # Note: ion for passive channel must be "non_specific" for NEURON
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="pas",
- ion_channel="pas",
- cond_density="0.00011830111773572024 S_per_cm2",
- erev="-83.92924122901199 mV",
- group_id="all",
- ion="non_specific",
- ion_chan_def_file="channels/pas.channel.nml",
- )
- cell.set_resistivity("0.1 kohm_cm", group_id="all")
- cell.set_specific_capacitance("2 uF_per_cm2", group_id="all")
- cell.set_init_memb_potential("-80mV")
- # 10mV is default for Neuron spike threshold in NetCon
- # https://www.neuron.yale.edu/neuron/static/py_doc/modelspec/programmatic/network/netcon.html
- cell.biophysical_properties.membrane_properties.spike_threshes.append(neuroml.SpikeThresh(value="10mV", segment_groups='all'))
- # write passive cell before adding active properties
- write_neuroml2_file(celldoc, f"{cellname}.pas.cell.nml")
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih",
- ion_channel="Ih",
- cond_density="2.7671764064314368e-05 S_per_cm2",
- erev="-45 mV",
- group_id="all",
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- # somatic
- soma_group = cell.get_segment_group("soma_group")
- sgid = soma_group.id
- print(f"Adding channels to {sgid}")
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_somatic",
- ion_channel="NaTg_PV",
- cond_density="0.49958525078702043 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Nap_somatic",
- ion_channel="Nap",
- cond_density="0.008795461417521086 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/Nap.channel.nml",
- )
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_somatic",
- ion_channel="K_P",
- cond_density="9.606092478937705e-06 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_somatic",
- ion_channel="K_T",
- cond_density="0.0011701702607527396 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_somatic",
- ion_channel="Kv3_1",
- cond_density="2.9921080101237565 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_somatic",
- ion_channel="Im",
- cond_density="0.04215865946497755 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_somatic",
- ion_channel="SK",
- cond_density="3.7265770903193036e-06 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- # Ca
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_PV_somatic",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- # https://www.neuron.yale.edu/neuron/static/new_doc/modelspec/programmatic/ions.html
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_somatic",
- ion_channel="Ca_HVA",
- cond_density="0.00017953651378188165 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_somatic",
- ion_channel="Ca_LVA",
- cond_density="0.09250008555398015 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # axonal
- sgs = cell.get_segment_group("axon_group")
- sgid = sgs.id
- print(f"Adding channels to {sgid}")
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_axonal",
- ion_channel="NaTg_PV",
- cond_density="0.10914576408883477 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Nap_axonal",
- ion_channel="Nap",
- cond_density="0.001200899579358837 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/Nap.channel.nml",
- )
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_axonal",
- ion_channel="K_P",
- cond_density="0.6854776593761795 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_axonal",
- ion_channel="K_T",
- cond_density="0.07603372775662909 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_axonal",
- ion_channel="Kv3_1",
- cond_density="2.988867483754507 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_axonal",
- ion_channel="Im",
- cond_density="0.029587905136596156 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_axonal",
- ion_channel="SK",
- cond_density="0.5121938998281017 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- # Ca
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_axonal",
- ion_channel="Ca_HVA",
- cond_density="0.002961469262723619 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_axonal",
- ion_channel="Ca_LVA",
- cond_density="5.9457835817342756e-05 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_PV_axonal",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- # L1 validation
- cell.validate(recursive=True)
- cell.summary(morph=True, biophys=True)
- # use pynml writer to also run L2 validation
- write_neuroml2_file(celldoc, f"{cellname}.cell.nml")
- def postprocess_HL23SST():
- """Post process HL23SST and add biophysics.
- Each cell needs its biophysics to be added, so we do each cell separately.
- """
- cellname = "HL23SST"
- celldoc = load_and_setup_cell(cellname)
- cell = celldoc.cells[0] # type: neuroml.Cell
- # basal dendrites are in groups called dend_
- # populate the complete dendrite group, and new groups for all apical and
- # basal dendrites
- default_dendrite_group = cell.get_segment_group("dendrite_group")
- basal_group = cell.add_segment_group(
- "basal_dendrite_group",
- neuro_lex_id=neuro_lex_ids["dend"],
- notes="Basal dendrites",
- )
- # create new global myelin group
- myelin_group = cell.add_segment_group("myelin_group", notes="Myelin group")
- for sg in cell.morphology.segment_groups:
- if "dend_" in sg.id:
- basal_group.add(neuroml.Include(segment_groups=sg.id))
- if "myelin_" in sg.id and sg.id != "myelin_group":
- myelin_group.add(neuroml.Include(segment_groups=sg.id))
- # myelin groups are not included in the all segment group when adding
- # biophys
- all_segment_group = cell.get_segment_group("all") # type neuroml.SegmentGroup
- all_minus_myelin = cell.add_segment_group(
- "all_minus_myelin", notes="All without myelin"
- )
- for inc in all_segment_group.includes:
- if "myelin" not in inc.segment_groups:
- all_minus_myelin.includes.append(inc)
- for sg in all_segment_group.members:
- if "myelin" not in sg.segment:
- all_minus_myelin.members.append(sg)
- # optimise dendrite group
- default_dendrite_group.includes = []
- default_dendrite_group.includes.append(
- neuroml.Include(segment_groups=basal_group.id)
- )
- cell.optimise_segment_groups()
- cell.reorder_segment_groups()
- print("Segment groups:")
- for sg in cell.morphology.segment_groups:
- print(f"** {sg.id} **")
- print(cell.get_all_segments_in_group(sg.id))
- print()
- # biophysics
- # include calcium dynamics component
- celldoc.add(neuroml.IncludeType(href="CaDynamics_E2_NML2.nml"), validate=False)
- # all
- # Note: ion for passive channel must be "non_specific" for NEURON
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="pas",
- ion_channel="pas",
- cond_density="0.0000232 S_per_cm2",
- erev="-81.5 mV",
- group_id="all_minus_myelin",
- ion="non_specific",
- ion_chan_def_file="channels/pas.channel.nml",
- )
- cell.set_resistivity("0.1 kohm_cm", group_id="all_minus_myelin")
- cell.set_specific_capacitance("1 uF_per_cm2", group_id="all_minus_myelin")
- cell.set_init_memb_potential("-80mV")
- # myelin
- cell.set_specific_capacitance("0.02 uF_per_cm2", group_id="myelin_group")
- cell.set_resistivity("0.1 kohm_cm", group_id="myelin_group")
- # 10mV is default for Neuron spike threshold in NetCon
- # https://www.neuron.yale.edu/neuron/static/py_doc/modelspec/programmatic/network/netcon.html
- cell.biophysical_properties.membrane_properties.spike_threshes.append(neuroml.SpikeThresh(value="10mV", segment_groups='all'))
- # write passive cell
- write_neuroml2_file(celldoc, f"{cellname}.pas.cell.nml")
- # somatic
- soma_group = cell.get_segment_group("soma_group")
- sgid = soma_group.id
- print(f"Adding channels to {sgid}")
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_somatic",
- ion_channel="NaTg_SST_somatic",
- cond_density="0.127 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- # hcn
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih_somatic",
- ion_channel="Ih",
- cond_density="0.0000431 S_per_cm2",
- erev="-45 mV",
- group_id=sgid,
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_somatic",
- ion_channel="K_P",
- cond_density="0.0111 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_somatic",
- ion_channel="K_T",
- cond_density="0.00000 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_somatic",
- ion_channel="Kv3_1",
- cond_density="0.871 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_somatic",
- ion_channel="Im",
- cond_density="0.000158 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_somatic",
- ion_channel="SK",
- cond_density="0.00 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- # Ca
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_SST_somatic",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- # https://www.neuron.yale.edu/neuron/static/new_doc/modelspec/programmatic/ions.html
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_somatic",
- ion_channel="Ca_HVA",
- cond_density="0.00355 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_somatic",
- ion_channel="Ca_LVA",
- cond_density="0.00314 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # Basal
- basal_group = cell.get_segment_group("basal_dendrite_group")
- sgid = basal_group.id
- cell.set_specific_capacitance("1 uF_per_cm2", group_id=sgid)
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih_basal",
- ion_channel="Ih",
- cond_density="0.0000949 S_per_cm2",
- erev="-45 mV",
- group_id=sgid,
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- # axonal
- sgs = cell.get_segment_group("axon_group")
- sgid = sgs.id
- print(f"Adding channels to {sgid}")
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_axonal",
- ion_channel="NaTg_SST_axonal",
- cond_density="0.343 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Nap_axonal",
- ion_channel="Nap",
- cond_density="0.000444 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/Nap.channel.nml",
- )
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_axonal",
- ion_channel="K_P",
- cond_density="0.0295 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_axonal",
- ion_channel="K_T",
- cond_density="0.023 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_axonal",
- ion_channel="Kv3_1",
- cond_density="0.984 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_axonal",
- ion_channel="Im",
- cond_density="0.000317 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_axonal",
- ion_channel="SK",
- cond_density="0.00113 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- # Ca
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_axonal",
- ion_channel="Ca_HVA",
- cond_density="0.00145 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_axonal",
- ion_channel="Ca_LVA",
- cond_density="0.0627 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_SST_axonal",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- # HCN
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih_axonal",
- ion_channel="Ih",
- cond_density="0.00001 S_per_cm2",
- erev="-45 mV",
- group_id=sgid,
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- # L1 validation
- cell.validate(recursive=True)
- cell.summary(morph=True, biophys=True)
- # use pynml writer to also run L2 validation
- write_neuroml2_file(celldoc, f"{cellname}.cell.nml")
- def postprocess_HL23VIP():
- """Post process HL23VIP and add biophysics.
- Each cell needs its biophysics to be added, so we do each cell separately.
- """
- cellname = "HL23VIP"
- celldoc = load_and_setup_cell(cellname)
- cell = celldoc.cells[0] # type: neuroml.Cell
- print("Segment groups:")
- for sg in cell.morphology.segment_groups:
- print(f"** {sg.id} **")
- print(cell.get_all_segments_in_group(sg.id))
- print()
- # biophysics
- # include calcium dynamics component
- celldoc.add(neuroml.IncludeType(href="CaDynamics_E2_NML2.nml"), validate=False)
- # all
- # Note: ion for passive channel must be "non_specific" for NEURON
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="pas",
- ion_channel="pas",
- cond_density="2.5756438955642182e-05 S_per_cm2",
- erev="-79.74132024971513 mV",
- group_id="all",
- ion="non_specific",
- ion_chan_def_file="channels/pas.channel.nml",
- )
- cell.set_resistivity("0.1 kohm_cm", group_id="all")
- cell.set_specific_capacitance("2 uF_per_cm2", group_id="all")
- cell.set_init_memb_potential("-80mV")
- # 10mV is default for Neuron spike threshold in NetCon
- # https://www.neuron.yale.edu/neuron/static/py_doc/modelspec/programmatic/network/netcon.html
- cell.biophysical_properties.membrane_properties.spike_threshes.append(neuroml.SpikeThresh(value="10mV", segment_groups='all'))
- # write passive cell
- write_neuroml2_file(celldoc, f"{cellname}.pas.cell.nml")
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Ih",
- ion_channel="Ih",
- cond_density="4.274951616063423e-05 S_per_cm2",
- erev="-45 mV",
- group_id="all",
- ion="hcn",
- ion_chan_def_file="channels/Ih.channel.nml",
- )
- # somatic
- soma_group = cell.get_segment_group("soma_group")
- sgid = soma_group.id
- print(f"Adding channels to {sgid}")
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_somatic",
- ion_channel="NaTg_VIP_somatic",
- cond_density="0.11491205828369114 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Nap_somatic",
- ion_channel="Nap",
- cond_density="0.0001895305240694194 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/Nap.channel.nml",
- )
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_somatic",
- ion_channel="K_P",
- cond_density="0.0009925418924114282 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_somatic",
- ion_channel="K_T",
- cond_density="0.009051981253674193 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_somatic",
- ion_channel="Kv3_1",
- cond_density="0.31215653649208114 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_somatic",
- ion_channel="Im",
- cond_density="0.0003679378262289559 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_somatic",
- ion_channel="SK",
- cond_density="0.1655502166633749 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- # Ca
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_VIP_somatic",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- # https://www.neuron.yale.edu/neuron/static/new_doc/modelspec/programmatic/ions.html
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_somatic",
- ion_channel="Ca_HVA",
- cond_density="4.384846294634834e-05 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_somatic",
- ion_channel="Ca_LVA",
- cond_density="0.0034472458995879864 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # axonal
- sgs = cell.get_segment_group("axon_group")
- sgid = sgs.id
- print(f"Adding channels to {sgid}")
- # Na
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="NaTg_axonal",
- ion_channel="NaTg_VIP_axonal",
- cond_density="0.20112200814143477 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/NaTg/NaTg.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Nap_axonal",
- ion_channel="Nap",
- cond_density="0.0006248906854665301 S_per_cm2",
- erev="50 mV",
- group_id=sgid,
- ion="na",
- ion_chan_def_file="channels/Nap.channel.nml",
- )
- # K
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_P_axonal",
- ion_channel="K_P",
- cond_density="0.26489876414660096 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_P.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="K_T_axonal",
- ion_channel="K_T",
- cond_density="0.014364427062274185 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/K_T.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Kv3_1_axonal",
- ion_channel="Kv3_1",
- cond_density="0.0011201608191112877 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Kv3_1.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="Im_axonal",
- ion_channel="Im",
- cond_density="0.00013891465461042372 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/Im.channel.nml",
- )
- cell.add_channel_density(
- nml_cell_doc=celldoc,
- cd_id="SK_axonal",
- ion_channel="SK",
- cond_density="0.7027792087501376 S_per_cm2",
- erev="-85 mV",
- group_id=sgid,
- ion="k",
- ion_chan_def_file="channels/SK.channel.nml",
- )
- # Ca
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_HVA_axonal",
- ion_channel="Ca_HVA",
- cond_density="2.819397237794038e-05 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_HVA.channel.nml",
- )
- cell.add_channel_density_v(
- "ChannelDensityNernst",
- nml_cell_doc=celldoc,
- id="Ca_LVA_axonal",
- ion_channel="Ca_LVA",
- cond_density="0.010354001513952075 S_per_cm2",
- segment_groups=sgid,
- ion="ca",
- ion_chan_def_file="channels/Ca_LVA.channel.nml",
- )
- # external concentration is set to defaults that NEURON
- # starts with
- # internal concentration is set to minCai in mod file
- cell.add_intracellular_property(
- "Species",
- validate=False,
- id="ca",
- concentration_model="CaDynamics_E2_NML2_VIP_axonal",
- ion="ca",
- initial_concentration="1e-4 mM",
- initial_ext_concentration="2.0E-6 mol_per_cm3",
- segment_groups=sgid,
- )
- # L1 validation
- cell.validate(recursive=True)
- cell.summary(morph=True, biophys=True)
- # use pynml writer to also run L2 validation
- write_neuroml2_file(celldoc, f"{cellname}.cell.nml")
- def analyse_HL23PYR(hyperpolarising: bool = True, depolarising: bool = True):
- """Generate various curves for HL23PYR cells
- :returns: None
- """
- cellname = "HL23PYR"
- if hyperpolarising:
- # hyper-polarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- custom_amps_nA=list(numpy.arange(-0.05, -0.1, -0.01)),
- temperature="34 degC",
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_voltage_traces=True,
- plot_iv=True,
- plot_if=False,
- simulator="jNeuroML_NEURON",
- analysis_delay=300.0,
- analysis_duration=400.0,
- )
- if depolarising:
- # depolarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- plot_voltage_traces=True,
- spike_threshold_mV=-10.0,
- # custom_amps_nA=list(numpy.arange(0, 0.3, 0.05)),
- custom_amps_nA=[0.2],
- temperature="34 degC",
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_iv=True,
- simulator="jNeuroML_NEURON",
- analysis_delay=50.0,
- analysis_duration=200.0,
- )
- def analyse_HL23PV(hyperpolarising: bool = True, depolarising: bool = True):
- """Generate various curves for HL23PV cells
- :returns: None
- """
- cellname = "HL23PV"
- if hyperpolarising:
- # hyper-polarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- custom_amps_nA=list(numpy.arange(-0.05, -0.1, -0.01)),
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_voltage_traces=True,
- plot_iv=True,
- plot_if=False,
- simulator="jNeuroML_NEURON",
- analysis_delay=300.0,
- analysis_duration=400.0,
- )
- if depolarising:
- # depolarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- plot_voltage_traces=True,
- spike_threshold_mV=-10.0,
- custom_amps_nA=list(numpy.arange(0, 0.3, 0.01)),
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_iv=True,
- simulator="jNeuroML_NEURON",
- analysis_delay=300.0,
- analysis_duration=400.0,
- )
- def analyse_HL23SST(hyperpolarising: bool = True, depolarising: bool = True):
- """Generate various curves for HL23SST cells
- :returns: None
- """
- cellname = "HL23SST"
- if hyperpolarising:
- # hyper-polarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- custom_amps_nA=list(numpy.arange(-0.05, -0.1, -0.01)),
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_voltage_traces=True,
- plot_iv=True,
- plot_if=False,
- simulator="jNeuroML_NEURON",
- analysis_delay=300.0,
- analysis_duration=400.0,
- )
- if depolarising:
- # depolarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- plot_voltage_traces=True,
- spike_threshold_mV=-10.0,
- # custom_amps_nA=list(numpy.arange(0, 0.3, 0.01)),
- custom_amps_nA=[0.2],
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_iv=True,
- simulator="jNeuroML_NEURON",
- analysis_delay=300.0,
- analysis_duration=400.0,
- )
- def analyse_HL23VIP(hyperpolarising: bool = True, depolarising: bool = True):
- """Generate various curves for HL23VIP cells
- :returns: None
- """
- cellname = "HL23VIP"
- if hyperpolarising:
- # hyper-polarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- custom_amps_nA=list(numpy.arange(-0.05, -0.1, -0.01)),
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_voltage_traces=True,
- plot_iv=True,
- plot_if=False,
- simulator="jNeuroML_NEURON",
- analysis_delay=300.0,
- analysis_duration=400.0,
- )
- if depolarising:
- # depolarising inputs
- generate_current_vs_frequency_curve(
- nml2_file=f"{cellname}.cell.nml",
- cell_id=cellname,
- plot_voltage_traces=True,
- spike_threshold_mV=-10.0,
- # custom_amps_nA=list(numpy.arange(0, 0.3, 0.01)),
- custom_amps_nA=[0.2],
- pre_zero_pulse=200,
- post_zero_pulse=300,
- plot_iv=True,
- simulator="jNeuroML_NEURON",
- analysis_delay=300.0,
- analysis_duration=400.0,
- )
- def simulate_test_network(cells: list = []):
- """Create and simulate a test network
- WIP: does not simulate it yet.
- :param cells: list of cell names to simulate
- :type cells: list of strings
- :returns: None
- """
- net_doc = neuroml.NeuroMLDocument.component_factory("NeuroMLDocument", id="HL23")
- network = net_doc.add(
- "Network",
- id="HL23Net",
- type="networkWithTemperature",
- temperature="34 degC",
- validate=False,
- ) # type: neuroml.Network
- for cell in cells:
- # a document for the cell with input for OMV test
- cell_net_doc = neuroml.NeuroMLDocument.component_factory(
- "NeuroMLDocument", id=f"{cell}"
- )
- cell_network = cell_net_doc.add(
- "Network",
- id=f"{cell}Net",
- type="networkWithTemperature",
- temperature="34 degC",
- validate=False,
- ) # type: neuroml.Network
- cell_net_doc.add("IncludeType", href=f"{cell}.cell.nml")
- cell_pop = cell_network.add(
- "Population",
- id=f"{cell}_pop",
- type="populationList",
- component=f"{cell}",
- validate=False,
- ) # type: neuroml.Population
- cell_pop.add(
- "Property",
- tag="color",
- value=f"{random.random()} {random.random()} {random.random()}",
- )
- cell_pop.add("Property", tag="region", value="L23")
- cell_pop.add(
- "Instance",
- id="0",
- location=cell_pop.component_factory(
- "Location",
- x="0",
- y="0",
- z="0",
- ),
- )
- # to match the test_*hoc NEURON files
- cell_net_doc.add(
- "PulseGenerator",
- id=f"pg_{cell}",
- notes="Simple pulse generator",
- delay="50ms",
- duration="200ms",
- amplitude="0.2nA",
- )
- cell_inputs = cell_network.add(
- "InputList",
- id=f"stim_iclamp_{cell}",
- populations=f"{cell}_pop",
- component=f"pg_{cell}",
- validate=False,
- )
- cell_inputs.add(
- "Input", id=0, target=f"../{cell}_pop/0", destination="synapses"
- )
- cell_net_doc.validate(True)
- write_neuroml2_file(cell_net_doc, f"{cell}.net.nml")
- cell_net_sim = LEMSSimulation(
- f"{cell}_sim", duration=300.0, dt=0.01, target=cell_network.id
- )
- cell_net_sim.include_neuroml2_file(f"{cell}.net.nml")
- cell_net_sim.create_output_file(
- id=f"{cell}_net_output", file_name=f"{cell}_net.dat"
- )
- cell_net_sim.add_column_to_output_file(
- output_file_id=f"{cell}_net_output",
- column_id=f"{cell}_pop_0_v",
- quantity=f"{cell}_pop/0/{cell}/0/v",
- )
- # Save LEMS simulation to file
- cell_sim_file = cell_net_sim.save_to_file()
- # Run the simulation using the NEURON simulator
- run_lems_with_jneuroml_neuron(
- cell_sim_file, max_memory="8G", nogui=True, plot=False, skip_run=False
- )
- # network with all 4 cells
- net_doc.add("IncludeType", href=f"{cell}.cell.nml")
- pop = network.add(
- "Population",
- id=f"{cell}_pop",
- type="populationList",
- component=f"{cell}",
- validate=False,
- ) # type: neuroml.Population
- pop.add(
- "Property",
- tag="color",
- value=f"{random.random()} {random.random()} {random.random()}",
- )
- pop.add("Property", tag="region", value="L23")
- pop.add(
- "Instance",
- id="0",
- location=pop.component_factory(
- "Location",
- x=f"{random.randint(0, 200)}",
- y=f"{random.randint(0, 200)}",
- z=f"{random.randint(0, 200)}",
- ),
- )
- net_doc.add(
- "PulseGenerator",
- id=f"pg_{cell}",
- notes="Simple pulse generator",
- delay="50ms",
- duration="200ms",
- amplitude="0.2nA",
- )
- network.add("ExplicitInput", target="pop0[0]", input=f"pg_{cell}")
- net_doc.validate(True)
- write_neuroml2_file(net_doc, "HL23.net.nml")
- # plot_2D("HL23.net.nml", plane2d="xy")
- if __name__ == "__main__":
- cellnames = ["HL23PV", "HL23PYR", "HL23SST", "HL23VIP"]
- if "-postprocall" in sys.argv:
- postprocess_HL23VIP()
- postprocess_HL23PV()
- postprocess_HL23PYR()
- postprocess_HL23SST()
- """
- postprocess_HL23VIP()
- analyse_HL23VIP(True, True)
- simulate_test_network(cellnames)
- postprocess_HL23PV()
- analyse_HL23PV(True, True)
- postprocess_HL23PYR()
- analyse_HL23PYR(False, True)
- analyse_HL23SST(True, True)
- """
- postprocess_HL23SST()
|