<Type id="BallCell"
    x="0"
    y="0"
    size="0"
    style="table"
    display="icon"
    standalone="true"
    continuous="true"
    allowShapes="false"
    physical="false"
    typicalSize="2.0"
    sizeUnit="mm">
   <info>This is a simple test cell without any inputs or outputs. It combines a population of channels with a current stimulus (which may be left blank).</info>
   <tag>a compact cell with ion channels</tag>
   <plugs/>
   <sockets>
      <Socket id="potential"
          x="0.0114"
          y="0.764"
          size="0.136"
          conveyable="ScalarState"
          direction="send"
          access="external">
         <info>Exports the membrane potential of the cell as a plain scalar quantity (units are mV).</info>
         <tag>potential in the cell relative to external medium</tag>
      </Socket>
      <Socket id="spike"
          x="0.742"
          y="0.0153"
          size="0.123"
          conveyable="Event"
          direction="send"
          access="external">
         <info>info...</info>
         <tag>spike output</tag>
      </Socket>
      <Socket id="current"
          x="-0.833"
          y="0.316"
          size="0.141"
          conveyable="ControlledCurrent"
          direction="receive"
          access="external">
         <info>info...</info>
         <tag>current injections</tag>
      </Socket>
      <Socket id="potential"
          x="-0.835"
          y="-0.232"
          size="0.125"
          conveyable="Potential"
          direction="receive"
          access="external">
         <info>info...</info>
         <tag>driviing potentials</tag>
      </Socket>
   </sockets>
   <fields>
      <Float id="radius"
          x="1.72"
          y="1.12"
          size="0.150"
          label="Radius"
          initialValue="5.00"
          min="2.00"
          max="20.0"
          strictLimits="false"
          scale="log"
          figures="3"
          unit="micron">
         <info>The radius of the cell.</info>
         <tag>cell radius</tag>
      </Float>
      <Float id="cMem"
          x="1.72"
          y="-0.0766"
          size="0.150"
          label="Membrane capacitance"
          initialValue="1.00"
          min="0.500"
          max="1.50"
          strictLimits="false"
          scale="linear"
          figures="3"
          unit="microF/cm2">
         <info>The capacitance of the membrane per unit area. See the full CellModel component for details.</info>
         <tag>membrane capacitance</tag>
      </Float>
      <Float id="v0"
          x="1.74"
          y="0.498"
          size="0.150"
          label="initial potential"
          initialValue="-70.0"
          min="-100"
          max="0"
          strictLimits="false"
          scale="linear"
          figures="3"
          unit="mV">
         <info>info...</info>
         <tag>potential to start the cell at</tag>
      </Float>
      <QuantifiedList id="channelDensities"
          x="1.75"
          y="-0.766"
          size="0.150"
          label="Channel densities"
          targetLocation="global"
          initialValue="0"
          min="0"
          max="100"
          strictLimits="false"
          scale="linear"
          figures="3"
          unit="/micron^2">
         <info>info...</info>
         <targetTypes>
            <item value="org/ccneuro/channel/KSChannel.xml"/>
         </targetTypes>
      </QuantifiedList>
      <Float id="threshold"
          x="2.53"
          y="1.14"
          size="0.198"
          label="Threshold"
          initialValue="-20.0"
          min="-50.0"
          max="0"
          strictLimits="false"
          scale="log"
          figures="3"
          unit="mV">
         <info>Each time the potential moves above the threshold a spike is emitted. This has no effect on the internal dynamics of the cell.</info>
         <tag>threshold potential for emitting spikes</tag>
      </Float>
      <Choice id="stochasticity"
          x="2.54"
          y="0.129"
          size="0.300"
          label="Stochasticity"
          initialSelection="0">
         <info>This sets the meaning of the channel densities. They can either be treated as continuous quantities, or (multiplied by the area) as giving a discrete number of individual channels. -p- The mixed options allow the interpretation to depend on how many channels there are: stochastic for small numbers and continuous for large ones.</info>
         <tag>whether channels are treated stochastically or continuously</tag>
         <options>
            <item value="continuous"/>
            <item value="mixed10"/>
            <item value="mixed30"/>
            <item value="mixed100"/>
            <item value="stochastic"/>
         </options>
         <labels>
            <item value="fully continuous"/>
            <item value="mixed switch at 10"/>
            <item value="mixed switch at 30"/>
            <item value="mixed switch at 100"/>
            <item value="fully stochastic"/>
         </labels>
      </Choice>
   </fields>
   <icon>
      <Disc x="0.000"
          y="0.000"
          rx="0.8000"
          ry="0.8000"
          lineColor="#000000"
          lineWidth="1.000"
          fillColor="#cccccc"/>
   </icon>
   <structureScript>
<![CDATA[import org.catcmb.bionum.cell.*;
 
public void structureInit() {
   int stochSwitch = 0;
   int ps = getStochasticity();
   if (ps == MIXED10) {
       stochSwitch = 10;
   } else if (ps == MIXED30) {
       stochSwitch = 30;
   }  else if (ps == MIXED100) {
       stochSwitch = 100;
   } else if (ps == STOCHASTIC) {
       stochSwitch = 9999;
   }
   CellBuilder.get().addCellType(this,  radius, cMem, channelDensities,  
                  threshold, stochSwitch); 
}

 ]]>
</structureScript>
   <itemScript>
<![CDATA[
import org.catcmb.bionum.cell.*;

CompactChannelCell cell;
boolean belowThreshold;
 

public void init() {
   cell = CellBuilder.get().makeCell(p); 
}

 
public void advanceTo(TimePoint tp) {
      
      cell.setImposedCurrent(read_current());
      cell.setAppliedPotential(read_potential());

      cell.advanceTo(tp);

     // check if we've crossed the threshold for emitting a spike;
    double v = cell.getPotential();
    show_potential(v);
    if (v > p.getThreshold()) {
        if (belowThreshold) {
           belowThreshold = false;
           send_spike();
       } else {
           belowThreshold = true;
       }
   }
}
 ]]>
</itemScript>
</Type>

