%------------------------------------------------------------------------------------------
%
% Title: 	Calcium Signals in Small Structures
% Filename:	CaSignal_Exp7ASphere.par
% Author: 	Ronald van Elburg
% 
% Associated Paper:
% Cornelisse LN, van Elburg RAJ, Meredith RM, Yuste R, Mansvelder HD (2007) 
% High Speed Two-Photon Imaging of Calcium Dynamics in Dendritic Spines: 
% Consequences for Spine Calcium Kinetics and Buffer Capacity. 
% PLoS ONE 2(10): e1073 doi:10.1371/journal.pone.0001073
%
%
%
%
%------------------------------------------------------------------------------------------


Structure			= Sphere_Structure% Make it a sphere
 
	
% Calcium Current:
	CurrentAmplitude=n_ions*Surface_Structure*E21OVERAvagrado/(sqrt_of_pi*pulselength)
	t_actionpotential1=10
	t_actionpotential2=30
	t_actionpotential3=50
	t_actionpotential4=70
	t_actionpotential5=90
	CalciumCurrent:= CurrentAmplitude*(exp(-((t-t_actionpotential1)/pulselength)^2)+ exp(-((t-t_actionpotential2)/pulselength)^2) +exp(-((t-t_actionpotential3)/pulselength)^2)+exp(-((t-t_actionpotential4)/pulselength)^2)+exp(-((t-t_actionpotential5)/pulselength)^2))
		


path = ".\"   		% If running under Windows, specify here the path to the
                           			% directory containing the script imported below
file = path "CaSignal_main.par"

include file               			% Import the simulation parameters from the main script


% Auxilary variables for monitoring concentrations at different distances from the membrane

	NoOfSteps = 6    % number of shells in the output (NOT IN THE SIMULATION, THERE THE GRIDSIZE DEFINES THE COMPARTMENTS)
	dR=R_Structure/NoOfSteps
	
	R1k=(NoOfSteps-0.5)*dR
	R2k=(NoOfSteps-1.5)*dR
	R3k=(NoOfSteps-2.5)*dR
	R4k=(NoOfSteps-3.5)*dR
	R5k=(NoOfSteps-4.5)*dR
	R6k=(NoOfSteps-5.5)*dR
	
CaBoundary:=Ca[R_Source]
	Ca1 := Ca[R1k] ; Dye1 := Dye[R1k] 	; BndDye1 := Total_Dye-Dye[R1k] 	;EndoB1 := EndogenousBuffer	[R1k]
	Ca2 := Ca[R2k] ; Dye2 := Dye[R2k] 	; BndDye2 := Total_Dye-Dye[R2k] 	;EndoB2 := EndogenousBuffer	[R2k]
	Ca3 := Ca[R3k] ; Dye3 := Dye[R3k]  	; BndDye3 := Total_Dye-Dye[R3k]  	;EndoB3 := EndogenousBuffer	[R3k]
	Ca4 := Ca[R4k] ; Dye4 := Dye[R4k] 	; BndDye4 := Total_Dye-Dye[R4k] 	;EndoB4 := EndogenousBuffer	[R4k]
	Ca5 := Ca[R5k] ; Dye5 := Dye[R5k] 	; BndDye5 := Total_Dye-Dye[R5k] 	;EndoB5 := EndogenousBuffer	[R5k]
	Ca6 := Ca[R6k] ; Dye6 := Dye[R6k] 	; BndDye6 := Total_Dye-Dye[R6k] 	;EndoB6 := EndogenousBuffer	[R6k]
	CaAverage:=Ca[] ; DyeAverage:=Dye[] ; BndDyeAverage:=Total_Dye-Dye[] 	;EndoBAverage := EndogenousBuffer	[]
	
% Exporting the variables defined above to file
	Exp='7A'
	
		
	plot point.mute  CaBoundary "Output\Exp""Exp""\CSE""Exp""S_CaBoundary"
	plot point.mute  Ca1 "Output\Exp""Exp""\CSE""Exp""S_Ca1"
	plot point.mute  Ca2 "Output\Exp""Exp""\CSE""Exp""S_Ca2"
	plot point.mute  Ca3 "Output\Exp""Exp""\CSE""Exp""S_Ca3"
	plot point.mute  Ca4 "Output\Exp""Exp""\CSE""Exp""S_Ca4"
	plot point.mute  Ca5 "Output\Exp""Exp""\CSE""Exp""S_Ca5"
	plot point.mute  Ca6 "Output\Exp""Exp""\CSE""Exp""S_Ca6"
	plot point.mute  CaAverage "Output\Exp""Exp""\CSE""Exp""S_CaAverage"
	
	plot point.mute  Dye1 "Output\Exp""Exp""\CSE""Exp""S_Dye1"
	plot point.mute  Dye2 "Output\Exp""Exp""\CSE""Exp""S_Dye2"
	plot point.mute  Dye3 "Output\Exp""Exp""\CSE""Exp""S_Dye3"
	plot point.mute  Dye4 "Output\Exp""Exp""\CSE""Exp""S_Dye4"
	plot point.mute  Dye5 "Output\Exp""Exp""\CSE""Exp""S_Dye5"
	plot point.mute  Dye6 "Output\Exp""Exp""\CSE""Exp""S_Dye6"
	plot point.mute  DyeAverage "Output\Exp""Exp""\CSE""Exp""S_DyeAverage"
	
	plot point.mute  BndDye1 "Output\Exp""Exp""\CSE""Exp""S_BndDye1"
	plot point.mute  BndDye2 "Output\Exp""Exp""\CSE""Exp""S_BndDye2"
	plot point.mute  BndDye3 "Output\Exp""Exp""\CSE""Exp""S_BndDye3"
	plot point.mute  BndDye4 "Output\Exp""Exp""\CSE""Exp""S_BndDye4"
	plot point.mute  BndDye5 "Output\Exp""Exp""\CSE""Exp""S_BndDye5"
	plot point.mute  BndDye6 "Output\Exp""Exp""\CSE""Exp""S_BndDye6"
	plot point.mute  BndDyeAverage "Output\Exp""Exp""\CSE""Exp""S_BndDyeAverage"
	
	plot point.mute  EndoB1 "Output\Exp""Exp""\CSE""Exp""S_EndoB1"
	plot point.mute  EndoB2 "Output\Exp""Exp""\CSE""Exp""S_EndoB2"
	plot point.mute  EndoB3 "Output\Exp""Exp""\CSE""Exp""S_EndoB3"
	plot point.mute  EndoB4 "Output\Exp""Exp""\CSE""Exp""S_EndoB4"
	plot point.mute  EndoB5 "Output\Exp""Exp""\CSE""Exp""S_EndoB5"
	plot point.mute  EndoB6 "Output\Exp""Exp""\CSE""Exp""S_EndoB6"
	plot point.mute  EndoBAverage "Output\Exp""Exp""\CSE""Exp""S_EndoBAverage"
	
	plot point.mute CalciumCurrent "Output\Exp""Exp""\CSE""Exp""S_CalciumCurrent"
	


% The adaptive integration method fails for the fast calcium change
% to overcome this problem we run the first 100 ms with a fixed timestep 
% of 0.001 ms, then after the fast changes we switch to the adaptive method 
% for optimal performance.

Run  100.0  1.0e-3 ; current CalciumCurrent

Run  adaptive 400.0  1.0e-3 accuracy; current CalciumCurrent