def loadTTreeTestChannel(self): """ Load the T-tree morphology in memory with h-current 6--5--4--7--8 | | 1 """ v_eq = -75. self.dt = 0.025 self.tmax = 100. # for frequency derivation self.ft = ke.FourrierTools(np.arange(0., self.tmax, self.dt)) # load the morphology test_chan = channelcollection.TestChannel2() fname = os.path.join(MORPHOLOGIES_PATH_PREFIX, 'Tsovtree.swc') self.greenstree = GreensTree(fname, types=[1, 3, 4]) self.greenstree.addCurrent(test_chan, 50., -23.) self.greenstree.fitLeakCurrent(v_eq, 10.) self.greenstree.setCompTree() self.greenstree.setImpedance(self.ft.s) # copy greenstree parameters into NEURON simulation tree self.neurontree = NeuronSimTree(dt=self.dt, t_calibrate=100., v_init=v_eq, factor_lambda=25.) self.greenstree.__copy__(self.neurontree) self.neurontree.treetype = 'computational'
def testMembraneFunctions(self): self.loadTree(reinitialize=1) self.tree.setPhysiology(1., 100 * 1e-6) # passive parameters c_m = 1. r_a = 100. * 1e-6 e_eq = -75. self.tree.setPhysiology(c_m, r_a) self.tree.setEEq(e_eq) # channel p_open = .9 * .3**3 * .5**2 + .1 * .4**2 * .6**1 # TestChannel2 g_chan, e_chan = 100., 100. channel = channelcollection.TestChannel2() self.tree.addCurrent(channel, g_chan, e_chan) # fit the leak current self.tree.fitLeakCurrent(-30., 10.) # test if fit was correct for node in self.tree: tau_mem = c_m / (node.currents['L'][0] + g_chan * p_open) * 1e3 assert np.abs(tau_mem - 10.) < 1e-10 e_eq = (node.currents['L'][0]*node.currents['L'][1] + \ g_chan*p_open*e_chan) / (node.currents['L'][0] + g_chan*p_open) assert np.abs(e_eq - (-30.)) < 1e-10 # test if warning is raised for impossible to reach time scale with pytest.warns(UserWarning): tree = copy.deepcopy(self.tree) tree.fitLeakCurrent(-30., 100000.) # total membrane conductance g_pas = self.tree[1].currents['L'][0] + g_chan * p_open # make passive membrane tree = copy.deepcopy(self.tree) tree.asPassiveMembrane() # test if fit was correct for node in tree: assert np.abs(node.currents['L'][0] - g_pas) < 1e-10 # test if channels storage is empty assert len(tree.channel_storage) == 0 # test if computational root was removed assert tree._computational_root is None
def loadTTreeTestChannelSoma(self): """ Load the T-tree morphology in memory with h-current 6--5--4--7--8 | | 1 """ v_eq = -75. self.dt = 0.025 self.tmax = 100. # for frequency derivation self.ft = ke.FourrierTools(np.arange(0., self.tmax, self.dt)) # load the morphology print('>>> loading T-tree <<<') test_chan = channelcollection.TestChannel2() fname = 'test_morphologies/Tsovtree.swc' self.greenstree = GreensTree(fname, types=[1, 3, 4]) self.greenstree.addCurrent(test_chan, 50., 23., node_arg=[self.greenstree[1]]) self.greenstree.fitLeakCurrent(v_eq, 10.) # for node in self.greenstree: # print node.getGTot(channel_storage=self.greenstree.channel_storage) # print node.currents self.greenstree.setCompTree() self.greenstree.setImpedance(self.ft.s) # copy greenstree parameters into NEURON simulation tree self.neurontree = NeuronSimTree(dt=self.dt, t_calibrate=100., v_init=v_eq, factor_lambda=25.) self.greenstree.__copy__(self.neurontree) self.neurontree.treetype = 'computational'
def testPhysiologySetting(self): self.loadTree(reinitialize=1) d2s = {1: 0., 4: 50., 5: 125., 6: 175., 7: 125., 8: 175.} # passive parameters as float c_m = 1. r_a = 100. * 1e-6 self.tree.setPhysiology(c_m, r_a) for node in self.tree: assert np.abs(node.c_m - c_m) < 1e-10 assert np.abs(node.r_a - r_a) < 1e-10 # passive parameters as function c_m = lambda x: .5 * x + 1. r_a = lambda x: np.exp(0.01 * x) * 100 * 1e-6 self.tree.setPhysiology(c_m, r_a) for node in self.tree: assert np.abs(node.c_m - c_m(d2s[node.index])) < 1e-10 assert np.abs(node.r_a - r_a(d2s[node.index])) < 1e-10 # passive parameters as incomplete dict r_a = 100. * 1e-6 c_m = {1: 1., 4: 1.2} with pytest.raises(KeyError): self.tree.setPhysiology(c_m, r_a) # passive parameters as complete dict c_m.update({5: 1.1, 6: 0.9, 7: 0.8, 8: 1.}) self.tree.setPhysiology(c_m, r_a) for node in self.tree: assert np.abs(node.c_m - c_m[node.index]) < 1e-10 # equilibrium potential as float e_eq = -75. self.tree.setEEq(e_eq) for node in self.tree: assert np.abs(node.e_eq - e_eq) < 1e-10 # equilibrium potential as dict e_eq = {1: -75., 4: -74., 5: -73., 6: -72., 7: -71., 8: -70.} self.tree.setEEq(e_eq) for node in self.tree: assert np.abs(node.e_eq - e_eq[node.index]) < 1e-10 # equilibrium potential as function e_eq = lambda x: -70. + 0.1 * x self.tree.setEEq(e_eq) for node in self.tree: assert np.abs(node.e_eq - e_eq(d2s[node.index])) < 1e-10 # as wrong type with pytest.raises(TypeError): self.tree.setEEq([]) self.tree.setPhysiology([], []) # leak as float g_l, e_l = 100., -75. self.tree.setLeakCurrent(g_l, e_l) for node in self.tree: g, e = node.currents['L'] assert np.abs(g - g_l) < 1e-10 assert np.abs(e - e_l) < 1e-10 # equilibrium potential as dict g_l = {1: 101., 4: 103., 5: 105., 6: 107., 7: 108., 8: 109.} e_l = {1: -75., 4: -74., 5: -73., 6: -72., 7: -71., 8: -70.} self.tree.setLeakCurrent(g_l, e_l) for node in self.tree: g, e = node.currents['L'] assert np.abs(g - g_l[node.index]) < 1e-10 assert np.abs(e - e_l[node.index]) < 1e-10 # equilibrium potential as function g_l = lambda x: 100. + 0.05 * x e_l = lambda x: -70. + 0.05 * x self.tree.setLeakCurrent(g_l, e_l) for node in self.tree: g, e = node.currents['L'] assert np.abs(g - g_l(d2s[node.index])) < 1e-10 assert np.abs(e - e_l(d2s[node.index])) < 1e-10 # as wrong type with pytest.raises(TypeError): self.tree.setLeakCurrent([]) # gmax as potential as float e_rev = 100. g_max = 100. channel = channelcollection.TestChannel2() self.tree.addCurrent(channel, g_max, e_rev) for node in self.tree: g_m = node.currents['TestChannel2'][0] assert np.abs(g_m - g_max) < 1e-10 # equilibrium potential as dict g_max = {1: 101., 4: 103., 5: 104., 6: 106., 7: 107., 8: 110.} self.tree.addCurrent(channel, g_max, e_rev) for node in self.tree: g_m = node.currents['TestChannel2'][0] assert np.abs(g_m - g_max[node.index]) < 1e-10 # equilibrium potential as function g_max = lambda x: 100. + 0.005 * x**2 self.tree.addCurrent(channel, g_max, e_rev) for node in self.tree: g_m = node.currents['TestChannel2'][0] assert np.abs(g_m - g_max(d2s[node.index])) < 1e-10 # test is channel is stored assert isinstance( self.tree.channel_storage[channel.__class__.__name__], channelcollection.TestChannel2) # check if error is thrown if an ionchannel is not give with pytest.raises(IOError): self.tree.addCurrent('TestChannel2', g_max, e_rev)