|
| 1 | +from neuroml import NeuroMLDocument |
| 2 | +from neuroml.utils import component_factory |
| 3 | + |
| 4 | +from pyneuroml import pynml |
| 5 | +from pyneuroml.xppaut import parse_script |
| 6 | +from pprint import pprint |
| 7 | + |
| 8 | +from neuroml import GateHHRates |
| 9 | +from neuroml import IncludeType |
| 10 | +import sympy |
| 11 | +from sympy.parsing.sympy_parser import parse_expr |
| 12 | +import math |
| 13 | + |
| 14 | + |
| 15 | +colors = {"AIY": "0.8 0 0"} |
| 16 | +cell_params = {} |
| 17 | + |
| 18 | +cell = "AIY" |
| 19 | +cell_params[cell] = {"surf": 65.89e-8} # surface in cm^2 form neuromorpho AIYL |
| 20 | + |
| 21 | +conductances = [ "leak", |
| 22 | + "slo1iso", |
| 23 | + "kqt1", |
| 24 | + "egl19", |
| 25 | + "slo1egl19", |
| 26 | + "nca", |
| 27 | + "irk", |
| 28 | + "eleak", |
| 29 | + "cm", |
| 30 | +] |
| 31 | + |
| 32 | +g0 = [0.14, 1, 0.2, 0.1, 0.92, 0.06, 0.5, -89.57, 1.6] |
| 33 | + |
| 34 | + |
| 35 | +for a in zip(conductances, g0): |
| 36 | + print(f"Setting {a[0]} = {a[1]} for {cell}") |
| 37 | + cell_params[cell][a[0]] = a[1] |
| 38 | + |
| 39 | + |
| 40 | +def generate_nmllite( |
| 41 | + cell, |
| 42 | + duration=11000, |
| 43 | + config="IClamp", |
| 44 | + parameters=None, |
| 45 | + stim_delay=1000, |
| 46 | + stim_duration=5000, |
| 47 | + channels_to_include=[], |
| 48 | +): |
| 49 | + from neuromllite import Cell, InputSource |
| 50 | + |
| 51 | + # from neuromllite.NetworkGenerator import * |
| 52 | + from neuromllite.utils import create_new_model |
| 53 | + |
| 54 | + reference = "%s_%s" % (config, cell) |
| 55 | + |
| 56 | + cell_id = "%s" % cell |
| 57 | + cell_nmll = Cell(id=cell_id, neuroml2_source_file="%s.cell.nml" % (cell)) |
| 58 | + |
| 59 | + ################################################################################ |
| 60 | + ### Add some inputs |
| 61 | + |
| 62 | + if "IClamp" in config: |
| 63 | + if not parameters: |
| 64 | + parameters = {} |
| 65 | + parameters["stim_amp"] = "30pA" |
| 66 | + parameters["stim_delay"] = "%sms" % stim_delay |
| 67 | + parameters["stim_duration"] = "%sms" % stim_duration |
| 68 | + |
| 69 | + input_source = InputSource( |
| 70 | + id="iclamp_0", |
| 71 | + neuroml2_input="PulseGenerator", |
| 72 | + parameters={ |
| 73 | + "amplitude": "stim_amp", |
| 74 | + "delay": "stim_delay", |
| 75 | + "duration": "stim_duration", |
| 76 | + }, |
| 77 | + ) |
| 78 | + |
| 79 | + else: |
| 80 | + if not parameters: |
| 81 | + parameters = {} |
| 82 | + parameters["average_rate"] = "100 Hz" |
| 83 | + parameters["number_per_cell"] = "10" |
| 84 | + |
| 85 | + input_source = InputSource( |
| 86 | + id="pfs0", |
| 87 | + neuroml2_input="PoissonFiringSynapse", |
| 88 | + parameters={ |
| 89 | + "average_rate": "average_rate", |
| 90 | + "synapse": syn_exc.id, |
| 91 | + "spike_target": "./%s" % syn_exc.id, |
| 92 | + }, |
| 93 | + ) |
| 94 | + |
| 95 | + sim, net = create_new_model( |
| 96 | + reference, |
| 97 | + duration, |
| 98 | + dt=0.025, # ms |
| 99 | + temperature=34, # degC |
| 100 | + default_region="Worm", |
| 101 | + parameters=parameters, |
| 102 | + cell_for_default_population=cell_nmll, |
| 103 | + color_for_default_population=colors[cell], |
| 104 | + input_for_default_population=input_source, |
| 105 | + ) |
| 106 | + sim.record_variables = {"caConc": {"all": "*"}} |
| 107 | + for c in channels_to_include: |
| 108 | + not_on_rmd = ["kvs1", "kqt3", "egl2"] |
| 109 | + if c == "ca": |
| 110 | + c = "sk" |
| 111 | + |
| 112 | + if c != "egl36" and cell != "AWCon" and not (c in not_on_rmd and cell == "RMD"): |
| 113 | + sim.record_variables["biophys/membraneProperties/%s_chans/gDensity" % c] = { |
| 114 | + "all": "*" |
| 115 | + } |
| 116 | + sim.record_variables["biophys/membraneProperties/%s_chans/iDensity" % c] = { |
| 117 | + "all": "*" |
| 118 | + } |
| 119 | + if ( |
| 120 | + c != "leak" |
| 121 | + and c != "nca" |
| 122 | + and not (c == "egl36" and cell == "AWCon") |
| 123 | + and not (c in not_on_rmd and cell == "RMD") |
| 124 | + ): |
| 125 | + sim.record_variables[ |
| 126 | + "biophys/membraneProperties/%s_chans/%s/m/q" % (c, c) |
| 127 | + ] = {"all": "*"} |
| 128 | + if ( |
| 129 | + c != "leak" |
| 130 | + and c not in ["nca", "kir", "sk", "egl36", "kqt3", "egl2"] |
| 131 | + and not (c in not_on_rmd and cell == "RMD") |
| 132 | + ): |
| 133 | + sim.record_variables[ |
| 134 | + "biophys/membraneProperties/%s_chans/%s/h/q" % (c, c) |
| 135 | + ] = {"all": "*"} |
| 136 | + |
| 137 | + if cell == "AWCon" and c in ["kqt3"]: |
| 138 | + sim.record_variables[ |
| 139 | + "biophys/membraneProperties/%s_chans/%s/s/q" % (c, c) |
| 140 | + ] = {"all": "*"} |
| 141 | + sim.record_variables[ |
| 142 | + "biophys/membraneProperties/%s_chans/%s/w/q" % (c, c) |
| 143 | + ] = {"all": "*"} |
| 144 | + |
| 145 | + sim.to_json_file() |
| 146 | + |
| 147 | + return sim, net |
| 148 | + |
| 149 | + |
| 150 | +def create_cells(channels_to_include, duration=700, stim_delay=310, stim_duration=500): |
| 151 | + for cell_id in cell_params.keys(): |
| 152 | + # Create the nml file and add the ion channels |
| 153 | + cell_doc = NeuroMLDocument( |
| 154 | + id=cell_id, notes="A cell from Nicoletti et al. 2019" |
| 155 | + ) |
| 156 | + cell_fn = "%s.cell.nml" % cell_id |
| 157 | + |
| 158 | + # Define a cell |
| 159 | + cell = cell_doc.add( |
| 160 | + "Cell", id=cell_id, notes="%s cell from Nicoletti et al. 2019" % cell_id |
| 161 | + ) |
| 162 | + """ |
| 163 | + volume_um3 = xpps[cell_id]["parameters"]["vol"] |
| 164 | + diam = 1.7841242 |
| 165 | + end_area = math.pi * diam * diam / 4 |
| 166 | + length = volume_um3 / end_area |
| 167 | + surface_area_curved = length * math.pi * diam""" |
| 168 | + |
| 169 | + surf = cell_params[cell_id]["surf"] |
| 170 | + # vol = 7.42e-12 # total volume |
| 171 | + L = math.sqrt(surf / math.pi) |
| 172 | + rsoma = L * 1e4 |
| 173 | + |
| 174 | + cell.add_segment( |
| 175 | + prox=[0, 0, 0, rsoma], |
| 176 | + dist=[0, rsoma, 0, rsoma], |
| 177 | + name="soma", |
| 178 | + parent=None, |
| 179 | + fraction_along=1.0, |
| 180 | + seg_type="soma", |
| 181 | + ) |
| 182 | + |
| 183 | + cell.add_membrane_property("SpikeThresh", value="0mV") |
| 184 | + |
| 185 | + cell.set_specific_capacitance("%s uF_per_cm2" % (cell_params[cell_id]["cm"])) |
| 186 | + |
| 187 | + cell.set_init_memb_potential("-65mV") |
| 188 | + |
| 189 | + # This value is not really used as it's a single comp cell model |
| 190 | + cell.set_resistivity("0.1 kohm_cm") |
| 191 | + |
| 192 | + |
| 193 | + for channel_id in channels_to_include: |
| 194 | + |
| 195 | + density_scaled = (cell_params[cell_id][channel_id]*1e-9)/(surf) |
| 196 | + |
| 197 | + print(cell_params[cell_id]) |
| 198 | + cell.add_channel_density( |
| 199 | + cell_doc, |
| 200 | + cd_id="%s_chans" % channel_id, |
| 201 | + cond_density="%s S_per_cm2" % density_scaled, |
| 202 | + erev="%smV" % cell_params[cell_id]["eleak"], |
| 203 | + ion="non_specific", |
| 204 | + ion_channel="%s" % channel_id, |
| 205 | + ion_chan_def_file="%s.channel.nml" % channel_id, |
| 206 | + ) |
| 207 | + |
| 208 | + """ |
| 209 | + cell_doc.includes.append(IncludeType(href="CaDynamics.nml")) |
| 210 | + # <species id="ca" ion="ca" concentrationModel="CaDynamics" initialConcentration="1e-4 mM" initialExtConcentration="2 mM"/> |
| 211 | + species = component_factory( |
| 212 | + "Species", |
| 213 | + id="ca", |
| 214 | + ion="ca", |
| 215 | + concentration_model="CaDynamics_%s" % cell_id, |
| 216 | + initial_concentration="5e-5 mM", |
| 217 | + initial_ext_concentration="2 mM", |
| 218 | + ) |
| 219 | +
|
| 220 | + cell.biophysical_properties.intracellular_properties.add(species)""" |
| 221 | + |
| 222 | + cell.info(show_contents=True) |
| 223 | + |
| 224 | + cell_doc.validate(recursive=True) |
| 225 | + pynml.write_neuroml2_file( |
| 226 | + nml2_doc=cell_doc, nml2_file_name=cell_fn, validate=True |
| 227 | + ) |
| 228 | + |
| 229 | + sim, net = generate_nmllite( |
| 230 | + cell_id, |
| 231 | + duration=duration, |
| 232 | + config="IClamp", |
| 233 | + parameters=None, |
| 234 | + stim_delay=stim_delay, |
| 235 | + stim_duration=stim_duration, |
| 236 | + channels_to_include=channels_to_include, |
| 237 | + ) |
| 238 | + |
| 239 | + ################################################################################ |
| 240 | + ### Run in some simulators |
| 241 | + |
| 242 | + from neuromllite.NetworkGenerator import check_to_generate_or_run |
| 243 | + import sys |
| 244 | + |
| 245 | + check_to_generate_or_run(sys.argv, sim) |
| 246 | + |
| 247 | + |
| 248 | +if __name__ == "__main__": |
| 249 | + create_cells( |
| 250 | + channels_to_include=["leak"], |
| 251 | + duration=11000, |
| 252 | + stim_delay=1000, |
| 253 | + stim_duration=5000, |
| 254 | + ) |
0 commit comments