pgleeson commited on
Commit
cdb94e2
·
1 Parent(s): dd8b826

Initial nml model run

Browse files
app.py CHANGED
@@ -128,11 +128,23 @@ with tab_model:
128
 
129
  from model import run_model
130
 
131
- text = st.text_area("Current injection level:", "100pA")
132
 
133
  submitted = st.form_submit_button("Submit")
134
 
135
  if submitted:
136
- response = run_model(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
- st.info(response)
 
128
 
129
  from model import run_model
130
 
131
+ text = st.text_area("Current injection level:", "4.1 pA")
132
 
133
  submitted = st.form_submit_button("Submit")
134
 
135
  if submitted:
136
+ try:
137
+ response = run_model(text)
138
+ st.info(response)
139
+
140
+ import numpy as np
141
+ import matplotlib.pyplot as plt
142
+
143
+ arr = np.random.normal(1, 1, size=100)
144
+ fig, ax = plt.subplots()
145
+ ax.hist(arr, bins=20)
146
+
147
+ st.pyplot(fig)
148
+ except Exception as e:
149
+ st.info('There was a problem...\n\n%s'%e)
150
 
 
model.py CHANGED
@@ -5,13 +5,46 @@
5
  import os
6
  import re
7
 
 
 
 
8
 
9
- def run_model(text):
10
 
11
- info = 'Running models with: %s'%text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
 
14
 
 
 
15
  return info
16
 
17
 
 
5
  import os
6
  import re
7
 
8
+ from neuromllite.utils import load_simulation_json
9
+ from neuromllite.utils import load_network_json
10
+ from neuromllite.NetworkGenerator import generate_and_run
11
 
12
+ def run_model(text, verbose = False):
13
 
14
+ info = '''Running models with: [%s]...
15
+
16
+ '''%text
17
+
18
+ sim_file = "models/Sim_IClamp_GenericMuscleCell.json"
19
+ net_file = "models/IClamp_GenericMuscleCell.json"
20
+
21
+ sim = load_simulation_json(sim_file)
22
+ net = load_network_json(net_file)
23
+
24
+
25
+ net.parameters["stim_amp"] = text.strip()
26
+
27
+
28
+ if verbose:
29
+ info+="""```%s```
30
+
31
+ """%sim.to_json()
32
+ info+="""```%s```
33
+
34
+ """%net.to_json()
35
+
36
+ traces, events = generate_and_run(sim,
37
+ network=net,
38
+ simulator="jNeuroML",
39
+ base_dir='./models',
40
+ return_results=True)
41
+
42
+ info+="""Results returned: %s"""%(list(traces.keys()))
43
 
44
 
45
 
46
+ print(info)
47
+
48
  return info
49
 
50
 
models/GenericMuscleCell.cell.nml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <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_v2beta5.xsd" id="GenericCell">
2
+ <notes>
3
+
4
+ ...
5
+ </notes>
6
+ <include href="cell_C.xml"/>
7
+
8
+ <fixedFactorConcentrationModel id="CaPool" ion="ca" restingConc="0 mM" decayConstant="20 ms" rho="0.0002 mol_per_m_per_A_per_s"/>
9
+ <cell id="GenericMuscleCell">
10
+ <morphology id="morphology_GenericMuscleCell">
11
+ <segment id="0" name="soma">
12
+ <proximal x="0.000000e+00" y="0.000000e+00" z="0.000000e+00" diameter="5.0"/>
13
+ <distal x="0.000000e+00" y="2.000000e+01" z="0.000000e+00" diameter="5.0"/>
14
+ </segment>
15
+ </morphology>
16
+ <biophysicalProperties id="biophys_GenericMuscleCell">
17
+ <membraneProperties>
18
+ <channelDensity id="Leak_all" ionChannel="Leak" condDensity="0.00105 mS_per_cm2" erev="-44 mV" ion="non_specific"/>
19
+ <channelDensity id="k_slow_all" ionChannel="k_slow" condDensity="0.3 mS_per_cm2" erev="-80 mV" ion="k"/>
20
+ <channelDensity id="ca_simple_all" ionChannel="ca_simple" condDensity="0.25 mS_per_cm2" erev="50 mV" ion="ca"/>
21
+ <spikeThresh value="-20 mV"/>
22
+ <specificCapacitance value=".6860 uF_per_cm2"/>
23
+ <initMembPotential value="-50 mV"/>
24
+ </membraneProperties>
25
+ <intracellularProperties>
26
+ <species id="ca" concentrationModel="CaPool" ion="ca" initialConcentration="0 mM" initialExtConcentration="2E-6 mol_per_cm3"/>
27
+ <resistivity value="0.1 kohm_cm"/>
28
+ </intracellularProperties>
29
+ </biophysicalProperties>
30
+ </cell>
31
+
32
+
33
+ </neuroml>
models/GenericNeuronCell.cell.nml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <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_v2beta5.xsd" id="GenericCell">
2
+ <notes>
3
+ ...
4
+ </notes>
5
+ <include href="cell_C.xml"/>
6
+ <fixedFactorConcentrationModel id="CaPool" ion="ca" restingConc="0 mM" decayConstant="20 ms" rho="0.0002 mol_per_m_per_A_per_s"/>
7
+
8
+ <cell id="GenericNeuronCell">
9
+ <morphology id="morphology_GenericNeuronCell">
10
+ <segment id="0" name="soma">
11
+ <proximal x="0.000000e+00" y="0.000000e+00" z="0.000000e+00" diameter="5.0"/>
12
+ <distal x="0.000000e+00" y="0.000000e+00" z="0.000000e+00" diameter="5.0"/>
13
+ </segment>
14
+ </morphology>
15
+ <biophysicalProperties id="biophys_GenericNeuronCell">
16
+ <membraneProperties>
17
+ <channelDensity id="Leak_all" ionChannel="Leak" condDensity="0.05 mS_per_cm2" erev="-44 mV" ion="non_specific"/>
18
+ <channelDensity id="k_slow_all" ionChannel="k_slow" condDensity="0.1 mS_per_cm2" erev="-80 mV" ion="k"/>
19
+ <channelDensity id="ca_simple_all" ionChannel="ca_simple" condDensity="0.06 mS_per_cm2" erev="50 mV" ion="ca"/>
20
+ <spikeThresh value="-20 mV"/>
21
+ <specificCapacitance value="5 uF_per_cm2"/>
22
+ <initMembPotential value="-50 mV"/>
23
+ </membraneProperties>
24
+ <intracellularProperties>
25
+ <species id="ca" concentrationModel="CaPool" ion="ca" initialConcentration="0 mM" initialExtConcentration="2E-6 mol_per_cm3"/>
26
+ <resistivity value="0.1 kohm_cm"/>
27
+ </intracellularProperties>
28
+ </biophysicalProperties>
29
+ </cell>
30
+
31
+ </neuroml>
models/IClamp_GenericMuscleCell.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "IClamp_GenericMuscleCell": {
3
+ "version": "NeuroMLlite v0.5.9",
4
+ "notes": "A network model: IClamp_GenericMuscleCell",
5
+ "parameters": {
6
+ "stim_amp": "4pA"
7
+ },
8
+ "cells": {
9
+ "GenericMuscleCell": {
10
+ "neuroml2_source_file": "GenericMuscleCell.cell.nml"
11
+ }
12
+ },
13
+ "input_sources": {
14
+ "iclamp_0": {
15
+ "parameters": {
16
+ "amplitude": "stim_amp",
17
+ "delay": "500ms",
18
+ "duration": "2000ms"
19
+ },
20
+ "neuroml2_input": "PulseGenerator"
21
+ }
22
+ },
23
+ "regions": {
24
+ "Worm": {
25
+ "x": 0.0,
26
+ "y": 0.0,
27
+ "z": 0.0,
28
+ "width": 1000.0,
29
+ "height": 100.0,
30
+ "depth": 1000.0
31
+ }
32
+ },
33
+ "populations": {
34
+ "pop_GenericMuscleCell": {
35
+ "size": 1,
36
+ "component": "GenericMuscleCell",
37
+ "properties": {
38
+ "color": "0.8 0 0"
39
+ },
40
+ "random_layout": {
41
+ "region": "Worm"
42
+ }
43
+ }
44
+ },
45
+ "inputs": {
46
+ "Stim_iclamp_0": {
47
+ "input_source": "iclamp_0",
48
+ "population": "pop_GenericMuscleCell",
49
+ "percentage": 100
50
+ }
51
+ },
52
+ "temperature": 34.0
53
+ }
54
+ }
models/IClamp_GenericNeuronCell.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "IClamp_GenericNeuronCell": {
3
+ "version": "NeuroMLlite v0.5.9",
4
+ "notes": "A network model: IClamp_GenericNeuronCell",
5
+ "parameters": {
6
+ "stim_amp": "4pA"
7
+ },
8
+ "cells": {
9
+ "GenericNeuronCell": {
10
+ "neuroml2_source_file": "GenericNeuronCell.cell.nml"
11
+ }
12
+ },
13
+ "input_sources": {
14
+ "iclamp_0": {
15
+ "parameters": {
16
+ "amplitude": "stim_amp",
17
+ "delay": "500ms",
18
+ "duration": "2000ms"
19
+ },
20
+ "neuroml2_input": "PulseGenerator"
21
+ }
22
+ },
23
+ "regions": {
24
+ "Worm": {
25
+ "x": 0.0,
26
+ "y": 0.0,
27
+ "z": 0.0,
28
+ "width": 1000.0,
29
+ "height": 100.0,
30
+ "depth": 1000.0
31
+ }
32
+ },
33
+ "populations": {
34
+ "pop_GenericNeuronCell": {
35
+ "size": 1,
36
+ "component": "GenericNeuronCell",
37
+ "properties": {
38
+ "color": "0 0 0.8"
39
+ },
40
+ "random_layout": {
41
+ "region": "Worm"
42
+ }
43
+ }
44
+ },
45
+ "inputs": {
46
+ "Stim_iclamp_0": {
47
+ "input_source": "iclamp_0",
48
+ "population": "pop_GenericNeuronCell",
49
+ "percentage": 100
50
+ }
51
+ },
52
+ "temperature": 34.0
53
+ }
54
+ }
models/Sim_IClamp_GenericMuscleCell.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Sim_IClamp_GenericMuscleCell": {
3
+ "version": "NeuroMLlite v0.5.9",
4
+ "network": "IClamp_GenericMuscleCell.json",
5
+ "duration": 3000.0,
6
+ "dt": 0.025,
7
+ "seed": 12345,
8
+ "record_traces": {
9
+ "all": "*"
10
+ }
11
+ }
12
+ }
models/Sim_IClamp_GenericNeuronCell.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Sim_IClamp_GenericNeuronCell": {
3
+ "version": "NeuroMLlite v0.5.9",
4
+ "network": "IClamp_GenericNeuronCell.json",
5
+ "duration": 3000.0,
6
+ "dt": 0.025,
7
+ "seed": 12345,
8
+ "record_traces": {
9
+ "all": "*"
10
+ }
11
+ }
12
+ }
models/cell_C.xml ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <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_v2beta4.xsd" id="cell_C">
2
+
3
+ <!-- Note: Not fully valid NML2: <customHGate> -->
4
+
5
+ <!--
6
+
7
+ Parameters C for c302 still under developemnt!!
8
+
9
+ Subject to change without notice!!
10
+
11
+
12
+ The fixed values for the parameters here will have to be replaced by parameters set in parameters_C.py &
13
+ built using libNeuroML classes
14
+
15
+ -->
16
+
17
+
18
+ <ionChannel id="Leak" conductance="10pS" type="ionChannelPassive"/>
19
+
20
+
21
+ <ionChannel id="k_fast" conductance="10pS" type="ionChannelHH" species="k">
22
+
23
+ <notes>K fast channel from Boyle and Cohen 2008</notes>
24
+
25
+ <gateHHtauInf id="p" instances="4">
26
+
27
+ <timeCourse type="fixedTimeCourse" tau="2.25518 ms"/>
28
+ <steadyState type="HHSigmoidVariable" rate="1" scale="7.42636 mV" midpoint="-8.05232 mV"/>
29
+
30
+ </gateHHtauInf>
31
+
32
+ <gateHHtauInf id="q" instances="1">
33
+
34
+ <timeCourse type="fixedTimeCourse" tau="149.963 ms"/>
35
+ <steadyState type="HHSigmoidVariable" rate="1" scale="-9.97468 mV" midpoint="-15.6456 mV"/>
36
+
37
+ </gateHHtauInf>
38
+
39
+ </ionChannel>
40
+
41
+
42
+ <ionChannel id="k_slow" conductance="10pS" type="ionChannelHH" species="k">
43
+
44
+ <notes>K slow channel from Boyle and Cohen 2008</notes>
45
+
46
+ <gateHHtauInf id="n" instances="1">
47
+
48
+ <timeCourse type="fixedTimeCourse" tau="25.0007 ms"/>
49
+ <steadyState type="HHSigmoidVariable" rate="1" scale="15.8512 mV" midpoint="19.8741 mV"/>
50
+
51
+ </gateHHtauInf>
52
+
53
+ </ionChannel>
54
+
55
+
56
+ <ionChannel id="ca_boyle" conductance="10pS" type="ionChannelHH" species="ca">
57
+
58
+ <notes>Ca channel from Boyle and Cohen 2008</notes>
59
+
60
+ <gateHHtauInf id="e" instances="2">
61
+
62
+ <timeCourse type="fixedTimeCourse" tau="0.100027 ms"/>
63
+ <steadyState type="HHSigmoidVariable" rate="1" scale="6.74821 mV" midpoint="-3.3568 mV"/>
64
+
65
+ </gateHHtauInf>
66
+
67
+ <gateHHtauInf id="f" instances="1">
68
+
69
+ <timeCourse type="fixedTimeCourse" tau="150.88 ms"/>
70
+
71
+ <!-- Note!!!
72
+
73
+ f gate is "inactivation" a/c B&C 2008 p172
74
+ but the scale value from Table A1 (kf) is positive (5mV), i.e. steady
75
+ state is zero for v << midpoint and 1 for v >> midpoint
76
+ Couple this with a very slow time course & the ion channel never
77
+ conducts as e^2 x f is always ~0
78
+
79
+ Using -5.03176mV NOT 5mV for k/scale to make this INACTIVATION
80
+
81
+ This is suggested by the value used here:
82
+ https://github.com/openworm/muscle_model/blob/master/BoyleCohen2008/MatlabSupport/Main_Version/data/input.csv#L20
83
+
84
+ see also
85
+ https://github.com/openworm/muscle_model/blob/master/BoyleCohen2008/PythonSupport/Main_Version/compareToNeuroML2.py
86
+ -->
87
+ <steadyState type="HHSigmoidVariable" rate="1" scale="-5.03176 mV" midpoint="25.1815 mV"/>
88
+
89
+ </gateHHtauInf>
90
+
91
+ <customHGate id="h" instances="1" alpha="0.282473" ca_half="6.41889e-8 mM" k="-1.00056e-8 mM"/>
92
+
93
+ </ionChannel>
94
+
95
+ <ionChannel id="ca_simple" conductance="10pS" type="ionChannelHH" species="ca">
96
+
97
+ <notes>Simplified Ca channel</notes>
98
+
99
+ <gateHHtauInf id="e" instances="2">
100
+
101
+ <timeCourse type="fixedTimeCourse" tau="0.100027 ms"/>
102
+ <steadyState type="HHSigmoidVariable" rate="1" scale="6.74821 mV" midpoint="-3.3568 mV"/>
103
+
104
+ </gateHHtauInf>
105
+
106
+ </ionChannel>
107
+
108
+
109
+ <ComponentType name="customHGate"
110
+ extends="gateHHtauInf"
111
+ description="Custom gate for h">
112
+
113
+ <Parameter name="alpha" dimension="none"/>
114
+ <Parameter name="k" dimension="concentration"/>
115
+ <Parameter name="ca_half" dimension="concentration"/>
116
+
117
+
118
+ <Constant name="SEC" dimension="time" value="1s"/>
119
+
120
+
121
+ <Exposure name="tau" dimension="time"/>
122
+ <Exposure name="inf" dimension="none"/>
123
+
124
+ <Requirement name="caConc" dimension="concentration"/>
125
+
126
+ <Dynamics>
127
+
128
+ <DerivedVariable name="rateScale" exposure="rateScale" dimension="none" value="1"/>
129
+
130
+ <DerivedVariable name="inf" dimension="none" exposure="inf" value="1 / (1 + (exp( (ca_half - caConc) / k)))"/>
131
+
132
+
133
+ <DerivedVariable name="tau" dimension="time" exposure="tau" value="0 * SEC"/>
134
+ <DerivedVariable name="q" exposure="q" dimension="none" value="inf"/>
135
+ <DerivedVariable name="fcond" exposure="fcond" dimension="none" value="1 +((q-1) * alpha)"/>
136
+
137
+ </Dynamics>
138
+ </ComponentType>
139
+
140
+
141
+ </neuroml>
requirements.txt CHANGED
@@ -5,4 +5,5 @@ llamaapi
5
  asyncio
6
  langchain_experimental
7
  wormneuroatlas
8
- pprint
 
 
5
  asyncio
6
  langchain_experimental
7
  wormneuroatlas
8
+ neuromllite
9
+ matplotlib