Rxd MultipleGeometry

Extending NEURON to handle reaction-diffusion problems.

Moderators: hines, wwlytton, ramcdougal

Post Reply
fidel.santamaria
Posts: 1
Joined: Tue Jun 10, 2014 12:57 pm

Rxd MultipleGeometry

Post by fidel.santamaria »

I'm using RXD,

I'm trying to setup different geometries for different compartments. For example, a soma with 20 % cytosol and a dendrite with 80 %. I am trying to use MultipleGeometry but get an error.

When I use this, the simulation looks OK
self.rxd.set_solve_type(self.somaA, dimension=3)
self.r_soma = self.rxd.Region(self.h.allsec(), name='cyt', nrn_region='i', geometry = self.rxd.FractionalVolume(volume_fraction = 0.3, surface_fraction = 1 ))

When I try either of these statements, the simulation crashes

self.r_soma = self.rxd.Region([self.somaA, self.dend], name='cyt', nrn_region='i',
geometry = self.rxd.MultipleGeometry(secs = [self.somaA, self.dend],geos=[self.rxd.FractionalVolume(volume_fraction = 0.3, surface_fraction = 0 ), self.rxd.FractionalVolume(volume_fraction = 0.5, surface_fraction = 1)] ))
self.r_soma = self.rxd.Region([self.somaA, self.dend], name='cyt', nrn_region='i',
geometry = self.rxd.MultipleGeometry(secs = [self.somaA, self.dend],geos=[self.rxd.inside, self.rxd.inside]))

Here's the code:

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr  9 10:04:36 2025

@author: Fidel Santamaria fidel.santamaria@utsa.edu
"""
from neuron import h,rxd
import matplotlib.pyplot as plt


class myCell:
    def __init__(self,name,h,r):
        self.name = name
        self.h = h
        self.rxd = r
        #self.h.load_file('parcom.hoc')
        self.h.execute('v_init=-61')
        self.h.execute('tstop = 100')
        self.h.v_init   = -65 #-61
        self.stim = []
        self.SaveDt = 0.02
    
    def addIClamp(self, comp, stepV):
        #breakpoint()
        self.stim.append(stepV[0])
        self.stim[stepV[0]] = self.h.IClamp(0.5, sec=self.somaA)
        self.stim[stepV[0]].delay = stepV[1]
        self.stim[stepV[0]].dur = stepV[2]
        self.stim[stepV[0]].amp = stepV[3]
        
    def recordVsoma(self):
        #breakpoint()
        self.vm_soma = self.h.Vector()
        self.rec_t=self.h.Vector()
        self.vm_soma.record(self.somaA(0.5)._ref_v, self.SaveDt)
        self.rec_t.record(self.h._ref_t,self.SaveDt)
        self.vm_soma.label("somaA")
        self.rec_t.label("time")
        
    def recordCafromList(self,listname,list,segpos=[]):
        setattr(self,listname,[])
        ca2s=getattr(self,listname)
        segposV=[]
        #breakpoint()
        if len(segpos)==1:
            segposV+= len(list) * [segpos[0]]
        elif len(segpos)==len(list):
            segposV=segpos
        # breakpoint()
        for counter,thisSection in enumerate(list):
            #breakpoint()
            d2r=getattr(self,thisSection)
            ca2s.append(self.h.Vector())
           
            ca2s[-1].record(d2r(segposV[counter])._ref_cai,self.SaveDt) #smooth dend
            ca2s[-1].label(thisSection)

    def myInit(self, vinit=-1000):
        if vinit == -1000:
            self.h.finitialize()
            print('Voltage not initilized')
        else:
            self.h.finitialize(vinit)
            print('Voltage initialized at ', vinit)
        self.h.fcurrent()
        self.h.frecord_init()
        
    def run(self, time):
        self.h.tstop = time
        #self.h.run()
        print('Running starting from ',self.h.t)
        while self.h.t < time:
            self.h.fadvance()   

    def runSteps(self,amp):
        preT=5
        preStimT=45
        postT=100
        postStimT=50
        sm.addIClamp('soma',[0,preT+preStimT,postT,0]); #the stim 10 ms after start recording
        
        runT=preT+preStimT+postT+postStimT
        self.recordVsoma()
        self.recordCafromList('Dend4Ca',self.somaList+self.dendList,[0.9, 0])
        self.myInit(self.h.v_init)
        self.run(preT)
        
        #initial condition
        for w in sm.ca_soma.nodes(sm.somaA(0.9)):
            w.concentration=1e-3

        print
        print('Input current ', amp)
        sm.h.tstop=runT
        sm.stim[0].amp=amp
        sm.run(runT)
    
    def simpleCell(self):
        #breakpoint()
        #myparam=self.myParam
    
        self.somaA = self.h.Section(name = 'somaA')
        self.dend = self.h.Section(name = 'dend')
        self.dend.connect(self.somaA(1))
        
        self.somaA.nseg=20
        self.dend.nseg=20
        self.somaA.L = self.somaA.diam = 12.6157 # Makes a soma of 500 microns squared.
        self.dend.L = 200 # microns
        self.dend.diam = 1 # microns
        
        
        for sec in self.h.allsec():
            sec.Ra = 100    # Axial resistance in Ohm * cm
            sec.cm = 1      # Membrane capacitance in micro Farads / cm^2
        
        # Insert active Hodgkin-Huxley current in the soma
        self.somaA.insert('hh')
        # soma.insert('pas')
        for seg in self.somaA:
            seg.hh.gnabar = 0.12  # Sodium conductance in S/cm2
            seg.hh.gkbar = 0.036  # Potassium conductance in S/cm2
            seg.hh.gl = 0.0003    # Leak conductance in S/cm2
            seg.hh.el = -54.3     # Reversal potential in mV
           
        
        # Insert passive current in the dendrite
        self.dend.insert('pas')
        for seg in self.dend:
            seg.pas.g = 0.001  # Passive conductance in S/cm2
            seg.pas.e = -65    # Leak reversal potential mV
    
        self.somaList=[]
        self.somaList.append('somaA')
        self.dendList=[]
        self.dendList.append('dend')
    
        # regions
        sec3d=self.h.allsec()
        #self.rxd.set_solve_type(sec3d, dimension=3)
        self.rxd.set_solve_type(self.somaA, dimension=3)
        self.rxd.set_solve_type(self.dend, dimension=1)
        self.rxd.nthread(16)
        
        # Trying different Region setups
        # r_soma = self.rxd.Region(self.h.allsec(), nrn_region='i')
        self.r_soma = self.rxd.Region(self.h.allsec(), name='cyt', nrn_region='i', geometry = self.rxd.FractionalVolume(volume_fraction = 0.3, surface_fraction = 1 ))
        
        # self.r_soma = self.rxd.Region([self.somaA, self.dend], name='cyt', nrn_region='i', 
        #                                 geometry = self.rxd.MultipleGeometry(secs = [self.somaA, self.dend],geos=[self.rxd.FractionalVolume(volume_fraction = 0.3, surface_fraction = 0 ), self.rxd.FractionalVolume(volume_fraction = 0.5, surface_fraction = 1)] ))
        # self.r_soma = self.rxd.Region([self.somaA, self.dend], name='cyt', nrn_region='i', 
        #                                geometry = self.rxd.MultipleGeometry(secs = [self.somaA, self.dend],geos=[self.rxd.inside, self.rxd.inside]))
        
        
        #r_dend = self.rxd.Region(self.h.allsec(), name='cyt', nrn_region='i', geometry = self.rxd.FractionalVolume(volume_fraction = 0.8, surface_fraction = 1))
        
        dCa=0.233
        initCa=4.5e-5
        self.ca_soma=self.rxd.Species(self.r_soma, d=dCa, initial=initCa, name="ca", charge=2)
        #self.ca_dend=self.rxd.Species(r_dend, d=dCa, initial=initCa, name="ca", charge=2)
        #bistable_reaction = rxd.Rate(ca, -ca * (1 - ca) * (0.01 - ca))
        


sm=myCell('c1',h,rxd)
sm.simpleCell()      
fname = 'Example'

thisSim=sm.runSteps(0.3)

    
    
thisV=sm.vm_soma.to_python()
thist=sm.rec_t.to_python()
fig=plt.figure()
ax=fig.add_subplot(1,2,1)
ax.plot(thist,thisV)
ax.set_title(fname,fontsize=12)
ax.set_xlabel('Time')

ax2=fig.add_subplot(1,2,2)
ax2.plot(thist,sm.Dend4Ca[0].to_python())
ax2.plot(thist,sm.Dend4Ca[1].to_python())
ax2.set_title(fname,fontsize=12)
ax2.set_xlabel('Time')
Post Reply