Validating a channel model IV curve with data from an experiment


In [1]:
import rickpy
rickpy.use_dev_packages(['scidash/sciunit','scidash/neuronunit','neuroml/pyNeuroML'])

# Imports and preliminaries.  
%matplotlib inline
import os,sys
import numpy as np
import quantities as pq

CW_HOME = os.path.split(os.path.realpath(os.path.pardir))[0] # Location of your ChannelWorm repo
sys.path.insert(1,CW_HOME)

from channelworm.fitter.initiators import Initiator

Compare the IV curve predicted from the channel model to that observed from the data


In [2]:
from neuronunit.tests.channel import IVCurvePeakTest
from neuronunit.models.channel import ChannelModel

In [3]:
# Instantiate the model
channel_model_name = 'EGL-19.channel'
channel_id = 'ca_boyle'
channel_file_path = os.path.join(CW_HOME,'models','%s.nml' % channel_model_name)

model = ChannelModel(channel_file_path,channel_index=0,name=channel_model_name.split('.')[0])

In [4]:
# Get the experiment data from ChannelWorm and instantiate the test

import os, sys
import django

sys.path.append(os.path.join(CW_HOME,'channelworm')) # Change the path if needed
os.environ.setdefault(
    "DJANGO_SETTINGS_MODULE",
    "web_app.settings"
)
django.setup()

from channelworm.ion_channel.models import GraphData

doi = '10.1083/jcb.200203055'
fig = '2B'
sample_data = GraphData.objects.get(graph__experiment__reference__doi=doi, graph__figure_ref_address=fig)
obs = list(zip(*sample_data.asarray())) 
observation = {'i/C':obs[1]*pq.A/pq.F, 'v':obs[0]*pq.mV}
cell_capacitance = 1e-13 * pq.F # Capacitance is arbitrary if IV curves are scaled.  
observation['i'] = observation['i/C']*cell_capacitance

test = IVCurvePeakTest(observation, scale=True)

In [5]:
# Judge the model output against the experimental data
score = test.judge(model)
score.summarize()
print("The score was computed according to '%s' with raw value %s and pass cutoff %s" \
    % (score.description,score.raw,test.converter.cutoff))
print('The scaling factor for the model IV curve was %.3g' % score.related_data['scale_factor'])


pyNeuroML >>> Generating LEMS file to investigate ca_boyle in /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/models/EGL-19.channel.nml, -100mV->100mV, 6.3degC
pyNeuroML >>> Loading LEMS file: /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/LEMS_Test_ca_boyle.xml and running with jNeuroML
pyNeuroML >>> Executing: (java -Xmx400M  -Djava.awt.headless=true -jar  "/Users/rgerkin/Dropbox/dev/neuroml/pyNeuroML/pyneuroml/lib/jNeuroML-0.8.0-jar-with-dependencies.jar"  "/Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/LEMS_Test_ca_boyle.xml"  -nogui) in directory: .
pyNeuroML >>> Command completed. Output: 
pyNeuroML >>>   jNeuroML >>   jNeuroML v0.8.0
pyNeuroML >>>   jNeuroML >>  Loading: /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/LEMS_Test_ca_boyle.xml with jLEMS, NO GUI mode...
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Loading LEMS file from: /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/LEMS_Test_ca_boyle.xml
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Reading from: /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/LEMS_Test_ca_boyle.xml
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Finished 40000 steps in 3.492 seconds (sim duration: 100.0ms; dt: 0.0025ms)
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.e.inf.lems.dat 857630
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.e.tau.lems.dat 848483
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.f.inf.lems.dat 802077
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.f.tau.lems.dat 728480
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_min100.lems.dat 937004
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_min80.lems.dat 967943
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_min60.lems.dat 968239
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_min40.lems.dat 953985
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_min20.lems.dat 949250
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_0.lems.dat 647931
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_20.lems.dat 995022
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_40.lems.dat 991260
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_60.lems.dat 988454
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_80.lems.dat 984435
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.i_100.lems.dat 980531
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Written to the file /Users/rgerkin/Dropbox/dev/openworm/ChannelWorm/tests/sciunit/./ca_boyle.rampV.lems.dat 765867
pyNeuroML >>>   jNeuroML >>  INFO Jul 19,2016 22:30  (INFO) Finished reading, building, running and displaying LEMS model
pyNeuroML >>>   jNeuroML >>  
=== Model EGL-19 achieved score Fail on test 'IV Curve Test'. ===
The score was computed according to 'The sum-squared difference in the observed and predicted current values over the range of the tested holding potentials.' with raw value 3.087 and pass cutoff 1.0 pA**2
The scaling factor for the model IV curve was 0.924

In [6]:
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams.update({'font.size':14, 'lines.linewidth':3})
score.plot()
plt.tight_layout()
plt.savefig('/Users/rgerkin/Desktop/iv_curves.eps',format='eps')