<commit_before># Author: <NAME>
# Wed Nov 12 11:02:01 GMT 2008

#===============================================================================
# This create the MSP neuron and set all the variable.
#===============================================================================

import neuron
from math import cos, sin, fabs, pi, radians


class Branch:
    
    def __init__(self, hoc):
        self.h = hoc
        self.mid = []
        self.dist = []
    
    def create(self, numMidDends, numDistDends):
        # Create the distal section
        self.prox = self.h.Section()
        
        # Create the Mid Dend 
        for i in xrange(numMidDends):       # Middle Dends
            
            mid_dend = self.h.Section()
            self.mid.append(mid_dend)
            mid_dend.connect(self.prox)
            
        for j in xrange(numDistDends):      # Distal Dends
            dist_dend = self.h.Section()
            self.dist.append(dist_dend)
            if j < 2:
                dist_dend.connect(self.mid[0])
            else:
                dist_dend.connect(self.mid[1])
            





class MediumSpinyNeuron:
    
    def __init__(self):
        self.h = neuron.h
        self.topology()
        for branch in self.branches:
            self.geom(branch)
        #self.shape3d() # Disabled untill BUG fixed
        
        # TODO Set the 3D geometry properly
        
        
    def topology(self):
        self.soma = self.h.Section()
        self.branches = []
        numProxDends = 4 # Proximal Dends
        for i in xrange(numProxDends):
            branch = Branch(self.h)
            branch.create(2,4)

            #self.createBranch(2, 4)
            # Connnecting in a symmetrical way
            if i < 2 :
                branch.prox.connect(self.soma, 0) 
            else:
                branch.prox.connect(self.soma, 1)
            self.branches.append(branch)
        

                
    def geom(self, branch):
        
        # Soma
        self.setGeoms(self.soma, 16, 16)
        # Prox
        self.setGeoms(branch.prox, 20, 2.25)
        # Mid
        for mid in branch.mid:
            self.setGeoms(mid, 24.23, 1.10)
        # Dist
        for dist in branch.dist:
            self.setGeoms(dist, 395.2, 0.72)

    def calcCoords(self, r, phi, theta):
        x = r * sin (radians(phi)) * cos (radians(theta))
        y = r * sin (radians(phi)) * sin (radians(theta))
        z = r * cos(radians(phi))
#        x = r * cos(theta)
#        y = r * sin(theta)
#        z = 0
        coords = (x,y,z)
        return x,y,z
    
    def add3dpoint(self, sec, x_start, y_start, z_start, x,y,z):
        sec.push()
        #self.h.pt3dclear()
        self.h.pt3dadd(x_start,y_start, z_start, sec.L)
        self.h.pt3dadd(x,y,z, sec.L)
        self.h.pop_section()
        print "%s x0: %f y0: %f z0: %f x: %f y: %f z: %f" %(sec.name(), x_start, 
                                                            y_start, z_start, x, y, z)
    
    def shape3d(self):
        
        # Soma<commit_msg>Added the real dimension of the neuron. The increase of volume should be obtain automatically inserting the right number of spines<commit_after># Author: <NAME>
# Wed Nov 12 11:02:01 GMT 2008

#===============================================================================
# This create the MSP neuron and set all the variable.
#===============================================================================

import neuron
from math import cos, sin, fabs, pi, radians


class Branch:
    
    def __init__(self, hoc):
        self.h = hoc
        self.mid = []
        self.dist = []
    
    def create(self, numMidDends, numDistDends):
        # Create the distal section
        self.prox = self.h.Section()
        
        # Create the Mid Dend 
        for i in xrange(numMidDends):       # Middle Dends
            
            mid_dend = self.h.Section()
            self.mid.append(mid_dend)
            mid_dend.connect(self.prox)
            
        for j in xrange(numDistDends):      # Distal Dends
            dist_dend = self.h.Section()
            self.dist.append(dist_dend)
            if j < 2:
                dist_dend.connect(self.mid[0])
            else:
                dist_dend.connect(self.mid[1])
            





class MediumSpinyNeuron:
    
    def __init__(self):
        self.h = neuron.h
        self.topology()
        for branch in self.branches:
            self.geom(branch)
        #self.shape3d() # Disabled untill BUG fixed
        
        # TODO Set the 3D geometry properly
        
        
    def topology(self):
        self.soma = self.h.Section()
        self.branches = []
        numProxDends = 4 # Proximal Dends
        for i in xrange(numProxDends):
            branch = Branch(self.h)
            branch.create(2,4)

            #self.createBranch(2, 4)
            # Connnecting in a symmetrical way
            if i < 2 :
                branch.prox.connect(self.soma, 0) 
            else:
                branch.prox.connect(self.soma, 1)
            self.branches.append(branch)
        

                
    def geom(self, branch):
        """Wilson 1992 Single Neuron Computation
           dendritic diam(um) * (1+spine/dend ratio)
           also O'Donnell 1993 Synapse
           Koch/Segev Methods in Neuronal Modeling pg 122-3, 1998
           
           """
        # Soma
        self.setGeoms(self.soma, 16, 16)
        # Prox
        self.setGeoms(branch.prox, 20, 2.25) 
        # Mid
        for mid in branch.mid:
            self.setGeoms(mid, 24.23, 1.10) # L = 20        diam = 1 * (1+0.3)
        # Dist
        for dist in branch.dist:
            self.setGeoms(dist, 395.2, 0.72) #L = 190    diam = 0.5 * (1+2) 

    def calcCoords(self, r, phi, theta):
        x = r * sin (radians(phi)) * cos (radians(theta))
        y = r * sin (radians(phi)) * sin (radians(theta))
        z = r * cos(radians(phi))
#        x = r * cos(theta)
#        y = r * sin(theta)
#        z = 0
        coords = (x,y,z)
        return x,y,z
    
    def add3dpoint(self, sec, x_start, y_start, z_start, x,y,z):
        sec.push()
        #self.h.pt3dclear()
        self.h.pt3dadd(x_start,y_start, z_start, sec.L)
        self.h.pt3dadd(x,y,z, sec.L)
        self.h.pop_section()
        print "%s x0: %f y0: %f z0: %f x: %f y: %f z: %f" %(sec.name(), x_start, 
                                                            y_start, z_start, x, y, z)
    
    def shape3d(self):
        
        # Soma
{'fraction_non_alphanumeric': 0.15287990196078433, 'fraction_numerical': 0.022058823529411766, 'mean_word_length': 1.5888183980967485, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1264276', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2060, 'n_words': 510}