Changeset 40

Show
Ignore:
Timestamp:
02/04/08 14:05:05 (1 year ago)
Author:
apdavison
Message:

Minor improvements to nrnpython/neuron/init.py

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/nrnpython/neuron/__init__.py

    r39 r40  
    1414import nrn 
    1515h  = hoc.HocObject() 
    16  
    17 h('obfunc new_IClamp() { return new IClamp($1) }') 
    18 h('obfunc newlist() { return new List() }') 
    19 h('obfunc newvec() { return new Vector($1) }') 
    20 h('obfunc new_NetConO() { return new NetCon($o1, $o2, $3, $4, $5) }') 
    21 h('obfunc new_NetConP() { return new NetCon("&v($1)", $2, $3, $4, $5) }') 
    22 h('obfunc new_File() { return new File() }') 
    2316 
    2417# ------------------------------------------------------------------------------ 
     
    10699    h('tstop = %g' % tstop) 
    107100    h('while (t < tstop) { fadvance() }') 
    108  
     101    # what about pc.psolve(tstop)? 
    109102# ------------------------------------------------------------------------------ 
    110103# Python wrappers around Hoc objects 
     104# For most objects we use a generic wrapper, created using the factory functions 
     105#   `new_point_process()` or `new_hoc_class()`. 
     106# Where we wish to modify the methods of the Hoc class, or add new methods, 
     107#   we write an explicit Python class. 
    111108# ------------------------------------------------------------------------------ 
    112109 
    113110ExpSyn = new_point_process('ExpSyn') 
     111Exp2Syn = new_point_process('Exp2Syn') 
     112VClamp = new_point_process('VClamp') 
     113SEClamp = new_point_process('SEClamp') 
     114APCount = new_point_process('APCount') 
     115 
    114116ParallelContext = new_hoc_class('ParallelContext') 
    115117NetStim = new_hoc_class('NetStim') 
     118Random = new_hoc_class('Random') 
     119CVode = new_hoc_class('CVode') 
     120 
     121h('obfunc new_IClamp() { return new IClamp($1) }') 
     122h('obfunc newlist() { return new List() }') 
     123h('obfunc newvec() { return new Vector($1) }') 
     124h('obfunc new_NetConO() { return new NetCon($o1, $o2, $3, $4, $5) }') 
     125h('obfunc new_NetConP() { return new NetCon(&v($1), $o2, $3, $4, $5) }') 
     126h('objref nil') 
     127h('obfunc new_NetConO_nil() { return new NetCon($o1, nil) }') 
     128h('obfunc new_NetConP_nil() { return new NetCon(&v($1), nil) }') 
     129h('obfunc new_File() { return new File() }') 
    116130 
    117131class List(Wrapper): 
     
    180194        h.pop_section()                       
    181195 
    182  
    183196class IClamp(object): 
    184197       
     
    212225     
    213226    def __init__(self, source, target, threshold=10, delay=1, weight=0, section=None, position=0.5): 
    214         if section: 
    215             section.push() 
    216             self.hoc_obj = h.new_NetConP(position, target.hoc_obj, threshold, delay, weight) 
    217             h.pop_section() 
    218         else: 
    219             self.hoc_obj = h.new_NetConO(source.hoc_obj, target.hoc_obj, threshold, delay, weight) 
     227        # What about generalising to obtain the NetCon object via pc.gid_connect(), if source is 
     228        # an integer? 
     229        if hasattr(target, 'hoc_obj'): 
     230           target = target.hoc_obj 
     231        if target is None: 
     232            if section: 
     233                section.push() 
     234                self.hoc_obj = h.new_NetConP_nil(position) 
     235                h.pop_section() 
     236            else: 
     237                self.hoc_obj = h.new_NetConO_nil(source.hoc_obj) 
     238        else: 
     239            if section: 
     240                section.push() 
     241                self.hoc_obj = h.new_NetConP(position, target, threshold, delay, weight) 
     242                h.pop_section() 
     243            else: 
     244                self.hoc_obj = h.new_NetConO(source.hoc_obj, target, threshold, delay, weight) 
    220245        self.section = section 
    221246 
     
    232257    def write(self, s): 
    233258        pass 
    234          
    235  
     259