from __future__ import division
from scipy import pi
import phhotoreceptor.Conductance as Conductance
__author__ = 'Francisco J. H. Heras'classElectricalCompartment:
"""Electrical compartment. It is the basic building block, and then it is inherited in axons and bodies. Can have conductances, conductance, etc"""def__init__(self, area, Cm, RA):
self.area = area #cm2
self.Cm = Cm #uF/cm2
self.C = Cm * self.area #uF
self.RA = RA # specific intracellular resistivity (kOhm*cm) .1-> standard; .08 -> Hateren&Laughlin 90 (for LMC)
self.reset_voltage_channels()
self.reset_leak_conductances() #It should be a diccionary of Conductancedefreset_voltage_channels(self): #Clears the array of conductances
self.voltage_channels = []
defadd_voltage_channel(self,voltage_channel): #Adds a new voltage channel to the photoreceptor
self.voltage_channels.append(voltage_channel)
voltage_channel.add_parent(self) #Parent can be also appended when the channel is createddefreset_leak_conductances(self): #Clears the dictionary of leak conductances
self.leak_conductances = {}
defadd_leak_conductance(self,ion_name,g): #Adds a new leak conductance to the dictionary
leak_conductance = Conductance.VoltageIndependent(ion_name,g)
self.leak_conductances[ion_name] = leak_conductance
leak_conductance.add_parent(self)
defupdate_membrane_voltage(self, I_total, dt):
dV = I_total / self.C * dt
self.V_m += dV
return self.V_m
defchange_voltage(self,V_m):
self.V_m = V_m #change membrane potentialdefreset_voltage(self,V_m):
self.V_m = V_m #change membrane potentialfor channel in self.voltage_channels:
channel.initialise_mh() # and reset all channels to their rest value at that voltagedeffreeze_conductance(self,index):
if index == None:
self.freeze_all_conductances()
else :
self.voltage_channels[index].freeze_conductance()
deffreeze_inactivation(self,index):
if index == None:
self.freeze_all_inactivations()
else :
self.voltage_channels[index].freeze_inactivation()
deffreeze_all_conductances(self):
for channel in self.voltage_channels:
channel.freeze_conductance()
defunfreeze_all_conductances(self):
for channel in self.voltage_channels:
channel.unfreeze_conductance()
deffreeze_all_inactivations(self):
for channel in self.voltage_channels:
channel.freeze_inactivation()
defunfreeze_all_inactivations(self):
for channel in self.voltage_channels:
channel.unfreeze_inactivation()
## Calculate various resistances and currentsdefvoltage_dependent_inward_current(self):
current = 0for channel in self.voltage_channels:
current += channel.current(self.V_m)
return current
definward_current_not_coming_from_conductances(self):
return0definternally_generated_inward_current(self):
current = self.inward_current_not_coming_from_conductances()
for channel in self.voltage_channels:
current += channel.current(self.V_m)
for conductance in self.leak_conductances.values():
current += conductance.current(self.V_m)
return current
deftotal_leak_conductance(self):
total = 0for leak in self.leak_conductances.values():
total += leak.g()
return total #mSdeftotal_voltage_independent_conductance(self):
return self.total_leak_conductance()
deftotal_voltage_dependent_conductance(self):
total = 0for channel in self.voltage_channels:
total += channel.g() #mSreturn total
deftotal_K_conductance(self): #temporary: in use in some scripts
total = 0for channel in self.voltage_channels:
total += channel.g()*channel.ion_current_fraction[0] #mSfor conductance in self.leak_conductances.values():
total += conductance.g()*conductance.ion_current_fraction[0] #mSreturn total
deftotal_voltage_dependent_conductance_inf(self,V): # at rest
total = 0for channel in self.voltage_channels:
total += channel.g_inf(V) #mSreturn total
defresistance(self):
return1/(self.total_voltage_dependent_conductance() + self.total_voltage_independent_conductance())
defimpedance(self,f): #f-> Frequency in Hz, V-> Membrane voltage"""Calculates impedances (using the RrL approximation)"""
omega_ms = f*2*pi/1000
g_array_K = self.C*omega_ms*1j + self.total_voltage_independent_conductance() #mS from light+leak and capacitance(uF)for channel in self.voltage_channels:
g_array_K += channel.admitance(f, self.V_m)
return1/g_array_K #kOhm