forked from ModelDBRepository/2017403
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial script to generate cells in nml
- Loading branch information
Showing
8 changed files
with
386 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.3.1.xsd" id="AIY"> | ||
<notes>A cell from Nicoletti et al. 2019</notes> | ||
<include href="leak.channel.nml"/> | ||
<cell id="AIY"> | ||
<notes>AIY cell from Nicoletti et al. 2019</notes> | ||
<morphology id="morphology"> | ||
<segment id="0" name="soma"> | ||
<proximal x="0.0" y="0.0" z="0.0" diameter="9.159353339761484"/> | ||
<distal x="0.0" y="9.159353339761484" z="0.0" diameter="9.159353339761484"/> | ||
</segment> | ||
<segmentGroup id="soma_group" neuroLexId="GO:0043025"> | ||
<notes>Default soma segment group for the cell</notes> | ||
<member segment="0"/> | ||
</segmentGroup> | ||
<segmentGroup id="all"> | ||
<notes>Default segment group for all segments in the cell</notes> | ||
<member segment="0"/> | ||
</segmentGroup> | ||
</morphology> | ||
<biophysicalProperties id="biophys"> | ||
<membraneProperties> | ||
<channelDensity id="leak_chans" ionChannel="leak" condDensity="0.14 S_per_m2" erev="-89.57mV" ion="non_specific"/> | ||
<spikeThresh value="0mV"/> | ||
<specificCapacitance value="1.6 F_per_m2"/> | ||
<initMembPotential value="-70mV"/> | ||
</membraneProperties> | ||
<intracellularProperties> | ||
<resistivity value="0.1 kohm_cm"/> | ||
</intracellularProperties> | ||
</biophysicalProperties> | ||
</cell> | ||
</neuroml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 id="ca" ion="ca" concentrationModel="CaDynamics" initialConcentration="1e-4 mM" initialExtConcentration="2 mM"/> | ||
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.3.1.xsd" id="IClamp_AIY"> | ||
<notes>Generated by NeuroMLlite v0.6.0 | ||
Generated network: IClamp_AIY | ||
Generation seed: 1234 | ||
NeuroMLlite parameters: | ||
stim_amp = 10pA | ||
stim_delay = 100ms | ||
stim_duration = 200ms</notes> | ||
<include href="AIY.cell.nml"/> | ||
<pulseGenerator id="iclamp_0" delay="100ms" duration="200ms" amplitude="10pA"/> | ||
<network id="IClamp_AIY" type="networkWithTemperature" temperature="34.0degC"> | ||
<notes>A network model: IClamp_AIY</notes> | ||
<property tag="recommended_dt_ms" value="0.025"/> | ||
<property tag="recommended_duration_ms" value="400.0"/> | ||
<population id="pop_AIY" component="AIY" size="1" type="populationList"> | ||
<property tag="color" value="0.8 0 0"/> | ||
<property tag="region" value="Worm"/> | ||
<instance id="0"> | ||
<location x="966.453535692138757" y="44.073259917535268" z="7.491470058587191"/> | ||
</instance> | ||
</population> | ||
<inputList id="Stim_iclamp_0" population="pop_AIY" component="iclamp_0"> | ||
<input id="0" target="../pop_AIY/0/AIY" destination="synapses"/> | ||
</inputList> | ||
</network> | ||
</neuroml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<Lems> | ||
|
||
<!-- | ||
This LEMS file has been automatically generated using PyNeuroML v1.3.12 (libNeuroML v0.6.6) | ||
--> | ||
|
||
<!-- Specify which component to run --> | ||
<Target component="Sim_IClamp_AIY" reportFile="report.Sim_IClamp_AIY.txt"/> | ||
|
||
<!-- Include core NeuroML2 ComponentType definitions --> | ||
<Include file="Cells.xml"/> | ||
<Include file="Networks.xml"/> | ||
<Include file="Simulation.xml"/> | ||
|
||
<Include file="PyNN.xml"/> | ||
<Include file="IClamp_AIY.net.nml"/> | ||
<Include file="AIY.cell.nml"/> | ||
|
||
<Simulation id="Sim_IClamp_AIY" length="400.0ms" step="0.025ms" target="IClamp_AIY" seed="12345"> <!-- Note seed: ensures same random numbers used every run --> | ||
<Display id="pop_AIY_0_biophys/membraneProperties/leak_chans/gDensity" title="Plots of pop_AIY_0_biophys/membraneProperties/leak_chans/gDensity" timeScale="1ms" xmin="-40.0" xmax="440.00000000000006" ymin="-1" ymax="1"> | ||
<Line id="pop_AIY_0_AIY_biophys_membraneProperties_leak_chans_gDensity" quantity="pop_AIY/0/AIY/biophys/membraneProperties/leak_chans/gDensity" scale="1" color="#d54f33" timeScale="1ms"/> | ||
</Display> | ||
|
||
<Display id="pop_AIY_0_biophys/membraneProperties/leak_chans/iDensity" title="Plots of pop_AIY_0_biophys/membraneProperties/leak_chans/iDensity" timeScale="1ms" xmin="-40.0" xmax="440.00000000000006" ymin="-1" ymax="1"> | ||
<Line id="pop_AIY_0_AIY_biophys_membraneProperties_leak_chans_iDensity" quantity="pop_AIY/0/AIY/biophys/membraneProperties/leak_chans/iDensity" scale="1" color="#0534e4" timeScale="1ms"/> | ||
</Display> | ||
|
||
<Display id="pop_AIY_0_caConc" title="Plots of pop_AIY_0_caConc" timeScale="1ms" xmin="-40.0" xmax="440.00000000000006" ymin="-1" ymax="1"> | ||
<Line id="pop_AIY_0_AIY_caConc" quantity="pop_AIY/0/AIY/caConc" scale="1" color="#98e752" timeScale="1ms"/> | ||
</Display> | ||
|
||
<Display id="pop_AIY_v" title="Plots of pop_AIY_v" timeScale="1ms" xmin="-40.0" xmax="440.00000000000006" ymin="-80" ymax="40"> | ||
<Line id="pop_AIY_0_AIY_v" quantity="pop_AIY/0/AIY/v" scale="1mV" color="#bca074" timeScale="1ms"/> | ||
</Display> | ||
|
||
<OutputFile id="Sim_IClamp_AIY_pop_AIY_v_dat" fileName="Sim_IClamp_AIY.pop_AIY.v.dat"> | ||
<OutputColumn id="pop_AIY_0_AIY_v" quantity="pop_AIY/0/AIY/v"/> | ||
</OutputFile> | ||
|
||
<OutputFile id="pop_AIY_0_biophys_membraneProperties_leak_chans_gDensity_dat" fileName="pop_AIY_0.biophys_membraneProperties_leak_chans_gDensity.dat"> | ||
<OutputColumn id="pop_AIY_0_AIY_biophys_membraneProperties_leak_chans_gDensity" quantity="pop_AIY/0/AIY/biophys/membraneProperties/leak_chans/gDensity"/> | ||
</OutputFile> | ||
|
||
<OutputFile id="pop_AIY_0_biophys_membraneProperties_leak_chans_iDensity_dat" fileName="pop_AIY_0.biophys_membraneProperties_leak_chans_iDensity.dat"> | ||
<OutputColumn id="pop_AIY_0_AIY_biophys_membraneProperties_leak_chans_iDensity" quantity="pop_AIY/0/AIY/biophys/membraneProperties/leak_chans/iDensity"/> | ||
</OutputFile> | ||
|
||
<OutputFile id="pop_AIY_0_caConc_dat" fileName="pop_AIY_0.caConc.dat"> | ||
<OutputColumn id="pop_AIY_0_AIY_caConc" quantity="pop_AIY/0/AIY/caConc"/> | ||
</OutputFile> | ||
|
||
</Simulation> | ||
|
||
</Lems> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mv *dat *txt LEMS_Test*.xml *.mod *nrn.py *.hoc /tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<neuroml xmlns="http://www.neuroml.org/schema/neuroml2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2.3.1.xsd" id="leak"> | ||
<notes>An ion channel from Nicoletti et al. 2024</notes> | ||
<ionChannelHH id="leak" species="non_specific" conductance="10pS"> | ||
<notes>leak channel from Nicoletti et al. 2024</notes> | ||
</ionChannelHH> | ||
</neuroml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
# Format the code | ||
black *.py | ||
|
||
python GenerateNeuroML.py -jnml | ||
|
||
|
||
omv all -V | ||
|