unit uNeuronTypes;

interface

uses
  classes, Winapi.Windows, Winapi.Messages, SysUtils, System.Generics.Collections;

(*
  Category	                Variable    Units
  --------                  --------    -------
  Time	                    t, dt      	[ms]
  Voltage	                  v	          [mV]
  Current	                  ina, ik     [mA/cm2]
  Concentration 	          ko, ki      [mM]
  Specific capacitance	    cm	        [uf/cm2]
  Length	                  diam, L	    [um]
  Conductance	              g           [S/cm2]
  Cytoplasmic resistivity	  Ra	        [ohm X cm]
  Resistance	              Ri          [10E6 ohm]
*)
// D:\NeuronSimulators\Neuron\StandardCell
// From NEURON's default units
//
const

  // Basic units
  mS = 1; // Millisecond  T I M E
  mV = 1; // Millivolt    V O L T A G E
  mA = 1; // Milliamp     C U R R E N T
  kOhm = 1; // Kiliohms   R E S I S T A N C E
  uM = 1; // Micrometer   L E N G T H
  uF = 1; // Microfrad    C A P A C I T A N C E

  nOhm = kOhm * 1E-12; // NanOhm
  Ohm = kOhm * 1E+3; // Ohm
  mOhm = kOhm * 1E-3; // Megohm

  nM = uM * 1E+6; // Nanometer
  cM = uM * 1E-4; // Centimeter
  mM = uM * 1E-3; // Millimeter
  M = uM * 1E-6; // Meters
  kM = uM * 1E-9; // Kilometer

  pF = uF * 1E+6; // Picofrad
  nF = uF * 1E+3; // Nanofrad
  F = uF * 1E-6; // Frad

  pV = mV * 1E+9; // Picovolt
  nV = mV * 1E+6; // Nanovolt
  V = mV * 1E-3; // Volt

  pA = mA * 1E-9; // Picoamp
  nA = mA * 1E-6; // Nanoamp
  A = mA * 1E+6; // Amp

  nS = mS * 1E+9; // Nanosecond
  uS = mS * 1E+6; // Microsecond
  S = mS * 1E+3; // Second
  //
  // // BoGo chap 13 and Cable defaults/
  // RMSpecific = 10;  // ohm meter^2
  // CMSpecific = 1;   // Frad meter^2
  // RASpecific = 0.1; // ohm meter
  // TM = RMSpecific * CMSpecific; // = 10 normally

  Send = True;
  Receive = Not Send;

  CsbVRestID = 0;
  CsbVRest = CsbVRestID + 1;

  CsbBodyPlanID = CsbVRest + 1;
  CsbBodyPlan = CsbBodyPlanID + 1;

  CsbNeuronTypeID = CsbBodyPlan + 1;
  CsbNeuronType = CsbNeuronTypeID + 1;

  CsbMessageID = CsbNeuronType + 1;
  CsbMessage = CsbMessageID + 1;

  Yes = 'Yes';
  No = 'No';
  Rising = True;
  Falling = Not Rising;

  WM_ResetFunction = WM_APP + 1;
  WM_setFunction = WM_ResetFunction + 1;
  WM_bAPFunction = WM_setFunction + 1;

  Draw = True;
  Erase = False;

  CLabelBlueLeft = 1;
  CLabelBlueRight = CLabelBlueLeft + 1;

  CLabelRedRight = CLabelBlueRight + 1;
  CLabelRedLeft = CLabelRedRight + 1;

  CLabelGreenRight = CLabelRedLeft + 1;
  CLabelGreenLeft = CLabelGreenRight + 1;

  CLabelBlackRight = CLabelGreenLeft + 1;
  CLabelBlackLeft = CLabelBlackRight + 1;

  CalNone = 0;
  CalBlue = CalNone + 1;
  CalRed = CalBlue + 1;
  CalGreen = CalRed + 1;
  CalBlack = CalGreen + 1;
  CalBlueItems = CalBlack + 1;
  CalRedItems = CalBlueItems + 1;
  CalGreenItems = CalRedItems + 1;
  CalBlackItems = CalGreenItems + 1;
  Input = True;

  CRmDefault_Ohm = 3183111111; // Kohm arbitrary set for scopes and Synapse's
  C_EPSP_SingleEvent = 3.25; // The measurable depolarization from a single Excitory synaptic event.
  C_IPSP_SingleEvent = -1.0; // The measurable change in polarization from a single Inhibitory synaptic event.

Type
  TPhysicsOutput = Record
    MembraneCap_uF: Single;
    Lamda_cM: Single;
    Tau_mS: Single;
    MembraneAxial_Ohm: Single;
    Membrane_Ohm: Single;
  End;

type
  TmSec = Integer;

type
  TInputRec = Record
    Input_V: Single;
    InputI_pA: Single; // [pA]
    SynapseName: String;
    EventTime: Integer;
  End;

type
  TSourceIcon = Record
    Name: String;
    Port: String;
    X: Integer; // Location of source port on Icon body
    Y: Integer;
  End;

type
  TSinkIcon = Record
    Name: String;
    Port: String;
    X: Integer; // Location of sink port on Icon body
    Y: Integer;
  End;

Type
  PResetMessage = ^TResetMessage;

  TResetMessage = Record
    ResetX: boolean;
    ResetY: boolean;
    ID: Integer;
  end;

Type
  PbAPMessage = ^TbAPMessage; // Backpropagation message sent from Soma

  TbAPMessage = Record
    Source: String;
    bAP_Amplitude_mV: Single; // Peak spike voltage
    LengthCumulative: Single;
    MembraneTriggerTick: Integer;
    MembraneResetTick: Integer;
    SomaName: String;
  End;

Type
  PSetMessage = ^TSetMessage;

  TSetMessage = Record
    Command: boolean; // Send = True (part A), Receive = False (part B)
    Input_mV: Variant; // Input from source [mV]
    SinkInput_Ohm: Single;
    // SourceRa: Single;
    Tick: Integer;
    SourceName: string;
    SinkName: string;
    IPSP: boolean;
    ID: Integer;
  end;

Type
  PsetSTDPMessage = ^TsetSTDPMessage;

  TsetSTDPMessage = Record
    Weight: Integer; // As % weight
  end;

Type
  PTagRec = ^TTagRec;

  TTagRec = Record
    Membrane_mV: Variant;
    RecoveryOut_mA: Variant;
    Membrane_Ohm: Variant; // Rm of the Sink
    MembraneAxial_Ohm: Variant; // Ra of the Source
    Test: Integer;
    // class constructor Create;// Class constructor ONLY in 10.4 Sydney
  End;

type
  TConnect = record
    Source: String;
    Sink: String;
  end;

type
  TNeuronParmas = record
    MembraneCap_pF: Single; // Membraine capacitance
    Reset_mV: Single; // resting membrane potential (mV) usually -60 mV
    Trigger_mV: Single; // Instantaneous Firing threshold for this neuron
    k: Single; // k=0.7 for v <= Vt and k = 7.0 for v > Vt (Page 49)
    A: Single; // Recovery time constant
    b: Single; // u=amplifying (b<0) or resonate (b>0)
    c: Single; // After spike resetting point
    d: Single; // Total of outward minus inward currents activated during the spiked
  end;

implementation

end.
