Skip to content

Instantly share code, notes, and snippets.

@tarelli
Last active December 19, 2015 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarelli/5867248 to your computer and use it in GitHub Desktop.
Save tarelli/5867248 to your computer and use it in GitHub Desktop.
Geppetto integration sample scripts
import numpy
import pylab as pl
from matplotlib import pyplot as plt
import time
class muscle_simulation():
#sample script inspired from https://github.com/openworm/Smoothed-Particle-Hydrodynamics/blob/integrated_electrophysiology/src/main_sim.py
def __init__(self,increment=1.0):
#create pre- and post- synaptic sections
self.increment = increment
self.pre = h.Section()
self.post = h.Section()
for sec in self.pre,self.post:
sec.insert('hh')
#inject current in the pre-synaptic section
self.stim = h.IClamp(0.5, sec=self.pre)
self.stim.amp = 70.0
self.stim.delay = 1500.0
self.stim.dur = 500.0
#create a synapse in the pre-synaptic section
self.syn = h.ExpSyn(0.5,sec=self.post)
#connect the pre-synaptic section to the synapse object:
self.nc = h.NetCon(self.pre(0.5)._ref_v, self.syn)
self.nc.weight[0] = 10.0
#let's do some manaical experimentation of the most evil kind:
self.calcium_level = 0
self.vector['calcium_level']=[self.calcium_level]
self.voltage_plot, = plt.plot([],[])
#plt.show()
def addition_rate(self):
opening = abs(post_v+65)
opening = (opening**2/(opening**2+opening))
current = opening*(1-self.state.calcium_level)/100
return current
def removal_rate(self):
opening = abs(20-post_v)
opening = (opening**2/(opening**2+opening))
current = opening*(self.calcium_level)/100
return -current
def run(self,do_plot = True):
#run and return resting potential
t_now = h.t
self.calcium_level += self.addition_rate()+self.removal_rate()
self.vector['calcium_level'].append(self.calcium_level)
self.muscle_contraction = self.calcium_level
<?xml version="1.0" encoding="UTF-8"?>
<tns:simulation xmlns:tns="http://www.openworm.org/simulationSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openworm.org/simulationSchema ../../src/main/resources/schema/simulationSchema.xsd ">
<tns:configuration>
<tns:outputFormat>RAW</tns:outputFormat>
</tns:configuration>
<tns:entities>
<tns:entity>
<tns:id>muscle_cell</tns:id>
<tns:aspects>
<tns:aspect>
<tns:modelInterpreter>lemsModelInterpreter</tns:modelInterpreter>
<tns:modelURL>https://dl.dropboxusercontent.com/u/7538688/GeppettoSimulations/SingleComponentHH/LEMS_NML2_Ex5_DetCell.xml?dl=1</tns:modelURL>
<tns:simulator>jLemsSimulator</tns:simulator>
<tns:id>example1</tns:id>
<tns:group>group1</tns:group>
</tns:aspect>
<tns:aspect>
<tns:modelInterpreter>lemsModelInterpreter</tns:modelInterpreter>
<tns:modelURL>https://dl.dropboxusercontent.com/u/7538688/GeppettoSimulations/SingleComponentHH/LEMS_NML2_Ex5_DetCell.xml?dl=1</tns:modelURL>
<tns:simulator>jLemsSimulator</tns:simulator>
<tns:id>example1</tns:id>
<tns:group>group1</tns:group>
</tns:aspect>
</tns:aspects>
<tns:scripts>
<tns:script>
<tns:statesMap>
<tns:element state="hhpop[0].v" var="pre_v"></tns:element>
<tns:element state="hhpop[1].v" var="post_v"></tns:element>
<tns:element state="hhpop[1].i" var="sync_i"></tns:element>
<tns:element state="hhpop[0].bioPhys1.membraneProperties.caChans.ca.m.q" var="calcium_level"></tns:element>
<tns:element state="muscle[0].contraction" var="muscle_contraction"></tns:element>
</tns:statesMap>
<tns:URL>https://dl.dropboxusercontent.com/u/7538688/electrofluid.py</tns:scriptURL>
</tns:script>
</tns:scripts>
</tns:entity>
<tns:entities>
<tns:name>example1</tns:name>
</tns:simulation>
1) timesteps need to have a minimum common denominator (e.g. 2ms, 4ms)
2) internal variables for the integration script
a) geppetto defines an interface for a method that gets exceuted every time there is an integration
3) the user needs to specify the exchange of information clock
timestep_simA = 2E-6 //from TimeConfiguration, unrelated to the script
timestep_simB = 1E-3 //from TimeConfiguration, unrelated to the script
"sampling" integer simA = 5 //from TimeConfiguration, unrelated to the script
"sampling" integer simB = 2 //from TimeConfiguration, unrelated to the script
timestep_script (by default the fastest clock) = 2s
- should not be faster than the fastest clock
- can be as slow as the user desires
- all clocks have a minimum common denominator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment