diff --git a/.gitignore b/.gitignore index 88e84a6..e33861b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ x86_64 /__pycache__ .DS_Store /NeuroML/*.dat +/NeuroML/report.*.txt +/NeuroML/IClamp_AIY.json +/NeuroML/Sim_IClamp_AIY.json diff --git a/NeuroML/AIY.cell.nml b/NeuroML/AIY.cell.nml new file mode 100644 index 0000000..963d376 --- /dev/null +++ b/NeuroML/AIY.cell.nml @@ -0,0 +1,32 @@ + + A cell from Nicoletti et al. 2019 + + + AIY cell from Nicoletti et al. 2019 + + + + + + + Default soma segment group for the cell + + + + Default segment group for all segments in the cell + + + + + + + + + + + + + + + + diff --git a/NeuroML/GenerateNeuroML.py b/NeuroML/GenerateNeuroML.py new file mode 100644 index 0000000..cc291ec --- /dev/null +++ b/NeuroML/GenerateNeuroML.py @@ -0,0 +1,251 @@ +from neuroml import NeuroMLDocument +from neuroml.utils import component_factory + +from pyneuroml import pynml +from pyneuroml.xppaut import parse_script +from pprint import pprint + +from neuroml import GateHHRates +from neuroml import IncludeType +import sympy +from sympy.parsing.sympy_parser import parse_expr +import math + + +colors = {"AIY": "0.8 0 0"} + +conductances = [ + "leak", + "slo1iso", + "kqt1", + "egl19", + "slo1egl19", + "nca", + "irk", + "eleak", + "cm", +] +g0 = [0.14, 1, 0.2, 0.1, 0.92, 0.06, 0.5, -89.57, 1.6] + +cell_params = {} + +cell = "AIY" +cell_params[cell] = {} +for a in zip(conductances, g0): + print(f"Setting {a[0]} = {a[1]} for {cell}") + cell_params[cell][a[0]] = a[1] + + +def generate_nmllite( + cell, + duration=700, + config="IClamp", + parameters=None, + stim_delay=310, + stim_duration=500, + channels_to_include=[], +): + from neuromllite import Cell, InputSource + + # from neuromllite.NetworkGenerator import * + from neuromllite.utils import create_new_model + + reference = "%s_%s" % (config, cell) + + cell_id = "%s" % cell + cell_nmll = Cell(id=cell_id, neuroml2_source_file="%s.cell.nml" % (cell)) + + ################################################################################ + ### Add some inputs + + if "IClamp" in config: + if not parameters: + parameters = {} + parameters["stim_amp"] = "10pA" + parameters["stim_delay"] = "%sms" % stim_delay + parameters["stim_duration"] = "%sms" % stim_duration + + input_source = InputSource( + id="iclamp_0", + neuroml2_input="PulseGenerator", + parameters={ + "amplitude": "stim_amp", + "delay": "stim_delay", + "duration": "stim_duration", + }, + ) + + else: + if not parameters: + parameters = {} + parameters["average_rate"] = "100 Hz" + parameters["number_per_cell"] = "10" + + input_source = InputSource( + id="pfs0", + neuroml2_input="PoissonFiringSynapse", + parameters={ + "average_rate": "average_rate", + "synapse": syn_exc.id, + "spike_target": "./%s" % syn_exc.id, + }, + ) + + sim, net = create_new_model( + reference, + duration, + dt=0.025, # ms + temperature=34, # degC + default_region="Worm", + parameters=parameters, + cell_for_default_population=cell_nmll, + color_for_default_population=colors[cell], + input_for_default_population=input_source, + ) + sim.record_variables = {"caConc": {"all": "*"}} + for c in channels_to_include: + not_on_rmd = ["kvs1", "kqt3", "egl2"] + if c == "ca": + c = "sk" + + if c != "egl36" and cell != "AWCon" and not (c in not_on_rmd and cell == "RMD"): + sim.record_variables["biophys/membraneProperties/%s_chans/gDensity" % c] = { + "all": "*" + } + sim.record_variables["biophys/membraneProperties/%s_chans/iDensity" % c] = { + "all": "*" + } + if ( + c != "leak" + and c != "nca" + and not (c == "egl36" and cell == "AWCon") + and not (c in not_on_rmd and cell == "RMD") + ): + sim.record_variables[ + "biophys/membraneProperties/%s_chans/%s_%s/m/q" % (c, cell, c) + ] = {"all": "*"} + if ( + c != "leak" + and c not in ["nca", "kir", "sk", "egl36", "kqt3", "egl2"] + and not (c in not_on_rmd and cell == "RMD") + ): + sim.record_variables[ + "biophys/membraneProperties/%s_chans/%s_%s/h/q" % (c, cell, c) + ] = {"all": "*"} + + if cell == "AWCon" and c in ["kqt3"]: + sim.record_variables[ + "biophys/membraneProperties/%s_chans/%s_%s/s/q" % (c, cell, c) + ] = {"all": "*"} + sim.record_variables[ + "biophys/membraneProperties/%s_chans/%s_%s/w/q" % (c, cell, c) + ] = {"all": "*"} + + sim.to_json_file() + + return sim, net + + +def create_cells(channels_to_include, duration=700, stim_delay=310, stim_duration=500): + for cell_id in cell_params.keys(): + # Create the nml file and add the ion channels + cell_doc = NeuroMLDocument( + id=cell_id, notes="A cell from Nicoletti et al. 2019" + ) + cell_fn = "%s.cell.nml" % cell_id + + # Define a cell + cell = cell_doc.add( + "Cell", id=cell_id, notes="%s cell from Nicoletti et al. 2019" % cell_id + ) + """ + volume_um3 = xpps[cell_id]["parameters"]["vol"] + diam = 1.7841242 + end_area = math.pi * diam * diam / 4 + length = volume_um3 / end_area + surface_area_curved = length * math.pi * diam""" + + surf = 65.89e-8 # surface in cm^2 form neuromorpho AIYL + vol = 7.42e-12 # total volume + L = math.sqrt(surf / math.pi) + rsoma = L * 1e4 + + cell.add_segment( + prox=[0, 0, 0, rsoma * 2], + dist=[0, rsoma * 2, 0, rsoma * 2], + name="soma", + parent=None, + fraction_along=1.0, + seg_type="soma", + ) + + cell.add_membrane_property("SpikeThresh", value="0mV") + + cell.set_specific_capacitance("%s F_per_m2" % (cell_params[cell_id]["cm"])) + + cell.set_init_memb_potential("-70mV") + + # This value is not really used as it's a single comp cell model + cell.set_resistivity("0.1 kohm_cm") + + density_factor = 1 + + for channel_id in channels_to_include: + print(cell_params[cell_id]) + cell.add_channel_density( + cell_doc, + cd_id="%s_chans" % channel_id, + cond_density="%s S_per_m2" % cell_params[cell_id][channel_id], + erev="%smV" % cell_params[cell_id]["eleak"], + ion="non_specific", + ion_channel="%s" % channel_id, + ion_chan_def_file="%s.channel.nml" % channel_id, + ) + + """ + cell_doc.includes.append(IncludeType(href="CaDynamics.nml")) + # + species = component_factory( + "Species", + id="ca", + ion="ca", + concentration_model="CaDynamics_%s" % cell_id, + initial_concentration="5e-5 mM", + initial_ext_concentration="2 mM", + ) + + cell.biophysical_properties.intracellular_properties.add(species)""" + + cell.info(show_contents=True) + + cell_doc.validate(recursive=True) + pynml.write_neuroml2_file( + nml2_doc=cell_doc, nml2_file_name=cell_fn, validate=True + ) + + sim, net = generate_nmllite( + cell_id, + duration=duration, + config="IClamp", + parameters=None, + stim_delay=stim_delay, + stim_duration=stim_duration, + channels_to_include=channels_to_include, + ) + + ################################################################################ + ### Run in some simulators + + from neuromllite.NetworkGenerator import check_to_generate_or_run + import sys + + check_to_generate_or_run(sys.argv, sim) + + +if __name__ == "__main__": + create_cells( + channels_to_include=["leak"], + duration=400, + stim_delay=100, + stim_duration=200, + ) diff --git a/NeuroML/IClamp_AIY.net.nml b/NeuroML/IClamp_AIY.net.nml new file mode 100644 index 0000000..e1c8a96 --- /dev/null +++ b/NeuroML/IClamp_AIY.net.nml @@ -0,0 +1,26 @@ + + Generated by NeuroMLlite v0.6.0 + Generated network: IClamp_AIY + Generation seed: 1234 + NeuroMLlite parameters: + stim_amp = 10pA + stim_delay = 100ms + stim_duration = 200ms + + + + A network model: IClamp_AIY + + + + + + + + + + + + + + diff --git a/NeuroML/LEMS_Sim_IClamp_AIY.xml b/NeuroML/LEMS_Sim_IClamp_AIY.xml new file mode 100644 index 0000000..3f387fb --- /dev/null +++ b/NeuroML/LEMS_Sim_IClamp_AIY.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NeuroML/clean.sh b/NeuroML/clean.sh new file mode 100755 index 0000000..1707ecd --- /dev/null +++ b/NeuroML/clean.sh @@ -0,0 +1 @@ +mv *dat *txt LEMS_Test*.xml *.mod *nrn.py *.hoc /tmp diff --git a/NeuroML/leak.channel.nml b/NeuroML/leak.channel.nml new file mode 100644 index 0000000..0ff4bee --- /dev/null +++ b/NeuroML/leak.channel.nml @@ -0,0 +1,6 @@ + + An ion channel from Nicoletti et al. 2024 + + leak channel from Nicoletti et al. 2024 + + diff --git a/NeuroML/regenerateAndTest.sh b/NeuroML/regenerateAndTest.sh new file mode 100755 index 0000000..f3e63b2 --- /dev/null +++ b/NeuroML/regenerateAndTest.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -ex + +# Format the code +black *.py + +python GenerateNeuroML.py -jnml + + +omv all -V +