MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Neuron.cpp File Reference
#include "header.h"
#include "ElementValueFinfo.h"
#include "LookupElementValueFinfo.h"
#include "shell/Shell.h"
#include "shell/Wildcard.h"
#include "ReadCell.h"
#include "utility/Vec.h"
#include "SwcSegment.h"
#include "Spine.h"
#include "Neuron.h"
#include "basecode/global.h"
#include "muParser.h"
+ Include dependency graph for Neuron.cpp:

Go to the source code of this file.

Classes

class  nuParser
 

Functions

static void addPos (unsigned int segIndex, unsigned int eIndex, double spacing, double minSpacing, double dendLength, vector< unsigned int > &seglistIndex, vector< unsigned int > &elistIndex, vector< double > &pos)
 Add entries into the pos vector for a given compartment i. More...
 
static vector< IdaddSpine (Id parentCompt, Id spineProto, double pos, double angle, Vec &x, Vec &y, Vec &z, double size, unsigned int k)
 
static void assignParam (Id obj, const string &field, double val, double len, double dia)
 
static void assignSingleCompartmentParams (ObjId compt, double val, const string &field, double len, double dia)
 
static bool buildFromProto (const string &name, const vector< ObjId > &elist, const vector< double > &val, vector< ObjId > &mech)
 
static double coordSystem (Id soma, Id dend, Vec &x, Vec &y, Vec &z)
 
static void doClassSpecificMessaging (Shell *shell, Id obj, ObjId compt)
 
Id fillSegIndex (const vector< Id > &kids, map< Id, unsigned int > &segIndex)
 
static void fillSegments (vector< SwcSegment > &segs, const map< Id, unsigned int > &segIndex, const vector< Id > &kids)
 
string findArg (const vector< string > &line, const string &field)
 
static Id getComptParent (Id id)
 
static void makeAngleDistrib (const vector< ObjId > &elist, const vector< double > &val, vector< unsigned int > &elistIndex, vector< double > &theta, const vector< string > &line)
 
static void makeSizeDistrib (const vector< ObjId > &elist, const vector< double > &val, vector< unsigned int > &elistIndex, vector< double > &size, const vector< string > &line)
 
bool parseDistrib (vector< vector< string > > &lines, const vector< string > &distrib)
 
static void reorientSpine (vector< Id > &spineCompts, vector< Vec > &coords, Vec &parentPos, double pos, double angle, Vec &x, Vec &y, Vec &z)
 
static void setCompartmentParams (const vector< ObjId > &elist, const vector< double > &val, const string &field, const string &expr)
 
static void setMechParams (const vector< ObjId > &mech, const vector< ObjId > &elist, const vector< double > &val, const string &field, const string &expr)
 
static void traverseCumulativeDistance (SwcSegment &self, vector< SwcSegment > &segs, const vector< Id > &lookupId, double len, double L, double pSoma, double eSoma)
 Recursive function to fill in cumulative distances from soma. More...
 

Variables

static const CinfoneuronCinfo = Neuron::initCinfo()
 

Function Documentation

static void addPos ( unsigned int  segIndex,
unsigned int  eIndex,
double  spacing,
double  minSpacing,
double  dendLength,
vector< unsigned int > &  seglistIndex,
vector< unsigned int > &  elistIndex,
vector< double > &  pos 
)
static

Add entries into the pos vector for a given compartment i.

Definition at line 1784 of file Neuron.cpp.

References moose::mtrand().

Referenced by Neuron::makeSpacingDistrib().

1790 {
1791  if ( minSpacing < spacing * 0.1 && minSpacing < 1e-7 )
1792  minSpacing = spacing * 0.1;
1793  if ( minSpacing > spacing * 0.5 )
1794  minSpacing = spacing * 0.5;
1795  unsigned int n = 1 + dendLength / minSpacing;
1796  double dx = dendLength / n;
1797  for( unsigned int i = 0; i < n; ++i )
1798  {
1799  // Use global RNG.
1800  if ( moose::mtrand() < dx / spacing )
1801  {
1802  seglistIndex.push_back( segIndex );
1803  elistIndex.push_back( eIndex );
1804  pos.push_back( i * dx + dx*0.5 );
1805  }
1806  }
1807 }
double mtrand(void)
Generate a random double between 0 and 1.
Definition: global.cpp:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static vector< Id > addSpine ( Id  parentCompt,
Id  spineProto,
double  pos,
double  angle,
Vec x,
Vec y,
Vec z,
double  size,
unsigned int  k 
)
static

Utility function to add a single spine to the given parent. Returns vector of added spine contents. parent is parent compartment for this spine. spineProto is just that. pos is position (in metres ) along parent compartment angle is angle (in radians) to rotate spine wrt x in plane xy. Size is size scaling factor, 1 leaves as is. x, y, z are unit vectors. Z is along the parent compt. We first shift the spine over so that it is offset by the parent compt diameter. We then need to reorient the spine which lies along (i,0,0) to lie along x. X is a unit vector so this is done simply by multiplying each coord of the spine by x. Finally we rotate the spine around the z axis by the specified angle k is index of this spine.

Definition at line 1649 of file Neuron.cpp.

References Vec::a0(), Neutral::children(), Eref::data(), Shell::doAddMsg(), Shell::doCopy(), Shell::doDelete(), Shell::doMove(), Id::eref(), Field< A >::get(), Neutral::parent(), reorientSpine(), and SetGet2< A1, A2 >::set().

Referenced by Neuron::installSpines().

1654 {
1655  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
1656  Id parentObject = Neutral::parent( parentCompt );
1657  stringstream sstemp;
1658  sstemp << k;
1659  string kstr = sstemp.str();
1660  Id spine = shell->doCopy( spineProto, parentObject, "_spine" + kstr,
1661  1, false, false );
1662  vector< Id > kids;
1663  Neutral::children( spine.eref(), kids );
1664  double x0 = Field< double >::get( parentCompt, "x0" );
1665  double y0 = Field< double >::get( parentCompt, "y0" );
1666  double z0 = Field< double >::get( parentCompt, "z0" );
1667  double parentRadius = Field< double >::get( parentCompt, "diameter" )/2;
1668  Vec ppos( x0, y0, z0 );
1669  // First, build the coordinates vector for the spine. Assume that its
1670  // major axis is along the unit vector [1,0,0].
1671  vector< Vec > coords;
1672  vector< Id > ret; // Filtered to make sure that it returns only compts
1673  for ( vector< Id >::iterator i = kids.begin(); i != kids.end(); ++i )
1674  {
1675  if ( i->element()->cinfo()->isA( "CompartmentBase" ) )
1676  {
1677  i->element()->setName( i->element()->getName() + kstr );
1678  x0 = Field< double >::get( *i, "x0" ) * size;
1679  y0 = Field< double >::get( *i, "y0" ) * size;
1680  z0 = Field< double >::get( *i, "z0" ) * size;
1681  coords.push_back( Vec( x0 + parentRadius, y0, z0 ) );
1682  double x = Field< double >::get( *i, "x" ) * size;
1683  double y = Field< double >::get( *i, "y" ) * size;
1684  double z = Field< double >::get( *i, "z" ) * size;
1685  double dia = Field< double >::get( *i, "diameter" ) * size;
1686  // Field< double >::set( *i, "diameter", dia );
1687 
1688  double len = sqrt(
1689  (x-x0)*(x-x0) +
1690  (y-y0)*(y-y0) +
1691  (z-z0)*(z-z0) );
1692  SetGet2< double, double >::set( *i, "setGeomAndElec", len, dia );
1693 
1694 
1695  coords.push_back( Vec( x + parentRadius, y, z ) );
1696  // scaleSpineCompt( *i, size );
1697  shell->doMove( *i, parentObject );
1698  ret.push_back( *i );
1699  }
1700  }
1701  // Then, take the projection of this along the x vector passed in.
1702  for( vector< Vec >::iterator i = coords.begin(); i != coords.end(); ++i)
1703  *i = x * i->a0();
1704  shell->doDelete( spine ); // get rid of the holder for the spine copy.
1705  shell->doAddMsg( "Single", parentCompt, "axial", kids[0], "raxial" );
1706  reorientSpine( kids, coords, ppos, pos, angle, x, y, z );
1707 
1708  return ret;
1709 }
char * data() const
Definition: Eref.cpp:41
static ObjId parent(const Eref &e)
Definition: Neutral.cpp:701
Id doCopy(Id orig, ObjId newParent, string newName, unsigned int n, bool toGlobal, bool copyExtMsgs)
Returns the Id of the root of the copied tree upon success.
Definition: ShellCopy.cpp:16
Eref eref() const
Definition: Id.cpp:125
static void children(const Eref &e, vector< Id > &ret)
Definition: Neutral.cpp:342
static void reorientSpine(vector< Id > &spineCompts, vector< Vec > &coords, Vec &parentPos, double pos, double angle, Vec &x, Vec &y, Vec &z)
Definition: Neuron.cpp:1583
Definition: Vec.h:13
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
bool doDelete(ObjId oid)
Definition: Shell.cpp:259
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Definition: Shell.h:43
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2)
Definition: SetGet.h:365
void doMove(Id orig, ObjId newParent)
Definition: Shell.cpp:390

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void assignParam ( Id  obj,
const string &  field,
double  val,
double  len,
double  dia 
)
static

Definition at line 680 of file Neuron.cpp.

References Element::cinfo(), Id::element(), FaradayConst, Cinfo::isA(), PI, and Field< A >::set().

Referenced by setMechParams().

682 {
683  if ( obj.element()->cinfo()->isA( "ChanBase" ) )
684  {
685  if ( field == "Gbar" )
686  {
687  if ( val > 0 )
688  Field< double >::set( obj, "Gbar", val * len * dia * PI );
689  }
690  else if ( field == "Ek" )
691  {
692  Field< double >::set( obj, "Ek", val );
693  }
694  }
695  else if ( obj.element()->cinfo()->isA( "CaConcBase" ) )
696  {
697  Field< double >::set( obj, "length", len );
698  Field< double >::set( obj, "diameter", dia );
699  // cout << "len, dia = " << len << ", " << dia << endl;
700  if ( field == "CaBasal" || field == "tau" || field == "thick" ||
701  field == "floor" || field == "ceiling" )
702  {
703  Field< double >::set( obj, field, val );
704  }
705  else if ( field == "B" )
706  {
707  // The system obeys dC/dt = B*I_Ca - C/tau
708  // So B = arg/( vol * F ). Here the system provides vol and F,
709  // so the arg is just a scale factor over this, typically
710  // to be thought of in terms of buffering. Small B is more
711  // buffering. This field is deprecated but used in legacy
712  // GENESIS scripts.
713  Field< double >::set( obj, "B", val /
714  ( FaradayConst * len * dia * dia * PI / 4.0 ) );
715  }
716  }
717 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
const double FaradayConst
Definition: consts.cpp:17
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
bool isA(const string &ancestor) const
Definition: Cinfo.cpp:280
const Cinfo * cinfo() const
Definition: Element.cpp:66
const double PI
Definition: consts.cpp:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void assignSingleCompartmentParams ( ObjId  compt,
double  val,
const string &  field,
double  len,
double  dia 
)
static

Definition at line 719 of file Neuron.cpp.

References PI, and Field< A >::set().

Referenced by setCompartmentParams().

721 {
722  if ( field == "initVm" || field == "INITVM" )
723  {
724  Field< double >::set( compt, "initVm", val );
725  return;
726  }
727  if ( field == "Em" || field == "EM" )
728  {
729  Field< double >::set( compt, "Em", val );
730  return;
731  }
732  if ( val > 0.0 )
733  {
734  if ( field == "Rm" || field == "Ra" || field == "Cm" )
735  {
736  Field< double >::set( compt, field, val );
737  }
738  else if ( field == "RM" )
739  {
740  Field< double >::set( compt, "Rm", val / ( len * dia * PI ) );
741  }
742  else if ( field == "RA" )
743  {
744  Field< double >::set( compt, "Ra", val*len*4 / (dia*dia*PI) );
745  }
746  else if ( field == "CM" )
747  {
748  Field< double >::set( compt, "Cm", val * len * dia * PI );
749  }
750  else
751  {
752  cout << "Warning: setCompartmentParam: field '" << field <<
753  "' not found\n";
754  }
755  }
756 }
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
const double PI
Definition: consts.cpp:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool buildFromProto ( const string &  name,
const vector< ObjId > &  elist,
const vector< double > &  val,
vector< ObjId > &  mech 
)
static

Definition at line 647 of file Neuron.cpp.

References Neutral::child(), Eref::data(), doClassSpecificMessaging(), Shell::doCopy(), Id::element(), Id::eref(), nuParser::EXPR, Element::getName(), and nuParser::numVal.

Referenced by Neuron::setChannelDistribution().

651 {
652  Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
653  Id proto( "/library/" + name );
654  if ( proto == Id() )
655  {
656  cout << "Warning: Neuron::buildFromProto: proto '"
657  << name << "' not found, skipping\n";
658  return false;
659  }
660  mech.clear();
661  mech.resize( elist.size() );
662  for ( unsigned int i = 0; i < elist.size(); ++i )
663  {
664  unsigned int j = i * nuParser::numVal;
665  if ( val[ j + nuParser::EXPR ] > 0 )
666  {
667  string name = proto.element()->getName();
668  Id obj = Neutral::child( elist[i].eref(), name );
669  if ( obj == Id() ) // Need to copy it in from proto.
670  {
671  obj = shell->doCopy( proto, elist[i], name, 1, false, false );
672  doClassSpecificMessaging( shell, obj, elist[i] );
673  }
674  mech[i] = obj;
675  }
676  }
677  return true;
678 }
char * data() const
Definition: Eref.cpp:41
static void doClassSpecificMessaging(Shell *shell, Id obj, ObjId compt)
Definition: Neuron.cpp:619
Id doCopy(Id orig, ObjId newParent, string newName, unsigned int n, bool toGlobal, bool copyExtMsgs)
Returns the Id of the root of the copied tree upon success.
Definition: ShellCopy.cpp:16
static Id child(const Eref &e, const string &name)
Definition: Neutral.cpp:665
Eref eref() const
Definition: Id.cpp:125
static char name[]
Definition: mfield.cpp:401
Definition: Id.h:17
static const unsigned int numVal
Definition: Neuron.cpp:88
Definition: Shell.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static double coordSystem ( Id  soma,
Id  dend,
Vec x,
Vec y,
Vec z 
)
static

Utility function to return a coordinate system where z is the direction of a dendritic segment, x is the direction of spines outward from soma and perpendicular to z and y is the perpendicular to x and z.

Definition at line 1546 of file Neuron.cpp.

References Vec::a0(), Vec::a1(), Vec::a2(), Vec::crossProduct(), doubleEq(), EPSILON, Field< A >::get(), and Vec::length().

Referenced by Neuron::installSpines().

1547 {
1548  static const double EPSILON = 1e-20;
1549  double x0 = Field< double >::get( dend, "x0" );
1550  double y0 = Field< double >::get( dend, "y0" );
1551  double z0 = Field< double >::get( dend, "z0" );
1552  double x1 = Field< double >::get( dend, "x" );
1553  double y1 = Field< double >::get( dend, "y" );
1554  double z1 = Field< double >::get( dend, "z" );
1555 
1556  Vec temp( x1-x0, y1-y0, z1-z0 );
1557  double len = temp.length();
1558  z = Vec( temp.a0()/len, temp.a1()/len, temp.a2()/len );
1559 
1560  double sx0 = Field< double >::get( soma, "x0" );
1561  double sy0 = Field< double >::get( soma, "y0" );
1562  double sz0 = Field< double >::get( soma, "z0" );
1563  Vec temp2( x0 - sx0, y0-sy0, z0-sz0 );
1564  Vec y2 = temp.crossProduct( z );
1565  double ylen = y2.length();
1566  double ytemp = 1.0;
1567  while ( ylen < EPSILON )
1568  {
1569  Vec t( ytemp , sqrt( 2.0 ), 0.0 );
1570  y2 = t.crossProduct( z );
1571  ylen = y2.length();
1572  ytemp += 1.0;
1573  }
1574  y = Vec( y2.a0()/ylen, y2.a1()/ylen, y2.a2()/ylen );
1575  x = z.crossProduct( y );
1576  assert( doubleEq( x.length(), 1.0 ) );
1577  return len;
1578 }
double a0() const
Definition: Vec.h:34
double a2() const
Definition: Vec.h:40
Vec crossProduct(const Vec &other) const
Definition: Vec.cpp:26
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
Definition: Vec.h:13
double length() const
Definition: Vec.cpp:18
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
double a1() const
Definition: Vec.h:37
#define EPSILON
Definition: MatrixOps.h:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void doClassSpecificMessaging ( Shell shell,
Id  obj,
ObjId  compt 
)
static

Definition at line 619 of file Neuron.cpp.

References ReadCell::addChannelMessage(), ObjId::bad(), Neutral::child(), Element::cinfo(), Shell::doAddMsg(), Id::element(), Id::eref(), Element::getName(), Cinfo::isA(), Neutral::parent(), ObjId::path(), path, and wildcardFind().

Referenced by buildFromProto().

620 {
621  if ( obj.element()->cinfo()->isA( "ChanBase" ) )
622  {
623  shell->doAddMsg( "Single", compt, "channel", obj, "channel" );
624  // Add the message to the Ca pool if our obj has 'Ca' in its name.
625  if ( obj.element()->getName().find( "Ca" ) != string::npos )
626  {
627  // Don't do it if we have the legacy GENESIS format
628  if ( Neutral::child( obj.eref(), "addmsg1" ) == Id() )
629  {
630  vector< ObjId > elist;
631  string path = Neutral::parent( obj ).path() + "/#[ISA=CaConcBase]";
632  // cout << "OK2 to Add Ca Msg for " << path << endl;
633  wildcardFind( path, elist );
634  if ( elist.size() > 0 )
635  {
636  // cout << "Added Ca Msg for " << obj.path() << ", name = " << obj.element()->getName() << endl;
637  ObjId mid = shell->doAddMsg(
638  "single", obj, "IkOut", elist[0], "current" );
639  assert( !mid.bad());
640  }
641  }
642  }
643  }
645 }
int wildcardFind(const string &path, vector< ObjId > &ret)
Definition: Wildcard.cpp:169
static ObjId parent(const Eref &e)
Definition: Neutral.cpp:701
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
bool bad() const
Definition: ObjId.cpp:18
static Id child(const Eref &e, const string &name)
Definition: Neutral.cpp:665
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
string path() const
Definition: ObjId.cpp:119
bool isA(const string &ancestor) const
Definition: Cinfo.cpp:280
const Cinfo * cinfo() const
Definition: Element.cpp:66
static void addChannelMessage(Id chan)
Definition: ReadCell.cpp:985
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Definition: Shell.cpp:269
Definition: Id.h:17
const string & getName() const
Definition: Element.cpp:56
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Id fillSegIndex ( const vector< Id > &  kids,
map< Id, unsigned int > &  segIndex 
)

Definition at line 1241 of file Neuron.cpp.

References Element::cinfo(), Id::element(), Field< A >::get(), Element::getName(), and Cinfo::isA().

Referenced by Neuron::buildSegmentTree().

1243 {
1244  Id soma;
1245  segIndex.clear();
1246  Id fatty;
1247  double maxDia = 0.0;
1248  unsigned int numKids = 0;
1249  for ( unsigned int i = 0; i < kids.size(); ++i )
1250  {
1251  const Id& k = kids[i];
1252  if ( k.element()->cinfo()->isA( "CompartmentBase" ) )
1253  {
1254  segIndex[ k ] = numKids++;
1255  const string& s = k.element()->getName();
1256  if ( s.find( "soma" ) != s.npos ||
1257  s.find( "Soma" ) != s.npos ||
1258  s.find( "SOMA" ) != s.npos )
1259  {
1260  soma = k;
1261  }
1262  double dia = Field< double >::get( k, "diameter" );
1263  if ( dia > maxDia )
1264  {
1265  maxDia = dia;
1266  fatty = k;
1267  }
1268  }
1269  }
1270  if ( soma != Id() )
1271  return soma;
1272  return fatty; // Fallback.
1273 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
bool isA(const string &ancestor) const
Definition: Cinfo.cpp:280
const Cinfo * cinfo() const
Definition: Element.cpp:66
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
const string & getName() const
Definition: Element.cpp:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void fillSegments ( vector< SwcSegment > &  segs,
const map< Id, unsigned int > &  segIndex,
const vector< Id > &  kids 
)
static

Definition at line 1275 of file Neuron.cpp.

References Element::cinfo(), Id::element(), Field< A >::get(), getComptParent(), and Cinfo::isA().

Referenced by Neuron::buildSegmentTree().

1278 {
1279  segs.clear();
1280  for ( unsigned int i = 0; i < kids.size(); ++i )
1281  {
1282  const Id& k = kids[i];
1283  if ( k.element()->cinfo()->isA( "CompartmentBase" ) )
1284  {
1285  double x = Field< double >::get( k, "x" );
1286  double y = Field< double >::get( k, "y" );
1287  double z = Field< double >::get( k, "z" );
1288  double dia = Field< double >::get( k, "diameter" );
1289  Id pa = getComptParent( k );
1290  unsigned int paIndex = ~0U; // soma
1291  int comptType = 1; // soma
1292  if ( pa != Id() )
1293  {
1294  map< Id, unsigned int >::const_iterator
1295  j = segIndex.find( pa );
1296  if ( j != segIndex.end() )
1297  {
1298  paIndex = j->second;
1299  comptType = 3; // generic dendrite
1300  }
1301  }
1302  // cout << "Seg[" << i << "].xy = " << int(x*1e6) << " " << int(y*1e6) << endl;
1303 
1304  segs.push_back(
1305  SwcSegment( i, comptType, x, y, z, dia/2.0, paIndex ) );
1306  }
1307  }
1308 }
Element * element() const
Synonym for Id::operator()()
Definition: Id.cpp:113
static Id getComptParent(Id id)
Definition: Neuron.cpp:1215
bool isA(const string &ancestor) const
Definition: Cinfo.cpp:280
const Cinfo * cinfo() const
Definition: Element.cpp:66
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string findArg ( const vector< string > &  line,
const string &  field 
)

Definition at line 1716 of file Neuron.cpp.

Referenced by makeAngleDistrib(), makeSizeDistrib(), and Neuron::makeSpacingDistrib().

1717 {
1718  // line has: proto path [field val]...
1719  assert( (line.size() % 2) != 1 );
1720  for ( unsigned int i = 2; i < line.size(); i+=2 )
1721  if ( line[i] == field )
1722  return line[i+1];
1723  string ret = "";
1724  if ( field == "spacing" )
1725  {
1726  ret = "1.0e-6";
1727  }
1728  else if ( field == "spacingDistrib" )
1729  {
1730  ret = "0";
1731  }
1732  else if ( field == "size" )
1733  {
1734  ret = "1";
1735  }
1736  else if ( field == "sizeDistrib" )
1737  {
1738  ret = "0";
1739  }
1740  else if ( field == "angle" )
1741  {
1742  ret = "0";
1743  }
1744  else if ( field == "angleDistrib" )
1745  {
1746  ret = "6.283185307";
1747  }
1748  else if ( field == "rotation" )
1749  {
1750  ret = "0";
1751  }
1752  else if ( field == "rotationDistrib" )
1753  {
1754  ret = "6.283185307"; // 2*PI
1755  }
1756  else if ( field == "shaftLen" )
1757  {
1758  ret = "1.0e-6";
1759  }
1760  else if ( field == "shaftDia" )
1761  {
1762  ret = "0.2e-6";
1763  }
1764  else if ( field == "headLen" )
1765  {
1766  ret = "0.5e-6";
1767  }
1768  else if ( field == "headDia" )
1769  {
1770  ret = "0.5e-6";
1771  }
1772  else if ( field == "theta" )
1773  {
1774  ret = "0";
1775  }
1776  else if ( field == "phi" )
1777  {
1778  ret = "1.5707963268"; // PI/2
1779  }
1780  return ret;
1781 }

+ Here is the caller graph for this function:

static Id getComptParent ( Id  id)
static

Definition at line 1215 of file Neuron.cpp.

References Cinfo::find(), and Cinfo::findFinfo().

Referenced by fillSegments().

1216 {
1217  // raxial points towards soma.
1218  static const Finfo* raxialFinfo =
1219  Cinfo::find( "Compartment" )->findFinfo( "raxialOut" );
1220  static const Finfo* proximalFinfo =
1221  Cinfo::find( "SymCompartment" )->findFinfo( "proximalOut" );
1222 
1223  if ( id.element()->cinfo()->isA( "CompartmentBase" ) )
1224  {
1225  vector< Id > ret;
1226  id.element()->getNeighbors( ret, raxialFinfo );
1227  if ( ret.size() == 1 )
1228  return ret[0];
1229  // If it didn't find an axial, maybe it is a symCompt
1230  if ( id.element()->cinfo()->isA( "SymCompartment" ) )
1231  {
1232  id.element()->getNeighbors( ret, proximalFinfo );
1233  if ( ret.size() == 1 )
1234  return ret[0];
1235  }
1236  }
1237  return Id();
1238 }
static const Cinfo * find(const std::string &name)
Definition: Cinfo.cpp:200
Definition: Id.h:17
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void makeAngleDistrib ( const vector< ObjId > &  elist,
const vector< double > &  val,
vector< unsigned int > &  elistIndex,
vector< double > &  theta,
const vector< string > &  line 
)
static

Definition at line 1888 of file Neuron.cpp.

References nuParser::eval(), findArg(), moose::mtrand(), and nuParser::numVal.

Referenced by Neuron::installSpines().

1893 {
1894  string angleExpr = findArg( line, "angle" );
1895  string angleDistribExpr = findArg( line, "angleDistrib" );
1896  // I won't bother with rotation and rotation distrb for now.
1897  // Easy to add, but on reflection they don't make sense.
1898  theta.clear();
1899  theta.resize( elistIndex.size(), 0.0 );
1900 
1901  try
1902  {
1903  nuParser angleParser( angleExpr );
1904  nuParser distribParser( angleDistribExpr );
1905  unsigned int lastIndex = ~0U;
1906  double angle = 0;
1907  double angleDistrib = 0;
1908  for ( unsigned int k = 0; k < elistIndex.size(); ++k )
1909  {
1910  unsigned int i = elistIndex[k];
1911  if ( i != lastIndex )
1912  {
1913  lastIndex = i;
1914  unsigned int j = i * nuParser::numVal;
1915  angle = angleParser.eval( val.begin() + j );
1916  angleDistrib = distribParser.eval( val.begin() + j);
1917  }
1918 
1919  // Use global RNG.
1920  if ( angleDistrib > 0 )
1921  theta[k] = angle + ( moose::mtrand() - 0.5 ) * angleDistrib;
1922  else
1923  theta[k] = angle;
1924  }
1925  }
1926  catch ( mu::Parser::exception_type& err )
1927  {
1928  cout << err.GetMsg() << endl;
1929  }
1930 }
string findArg(const vector< string > &line, const string &field)
Definition: Neuron.cpp:1716
double mtrand(void)
Generate a random double between 0 and 1.
Definition: global.cpp:97
static const unsigned int numVal
Definition: Neuron.cpp:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void makeSizeDistrib ( const vector< ObjId > &  elist,
const vector< double > &  val,
vector< unsigned int > &  elistIndex,
vector< double > &  size,
const vector< string > &  line 
)
static

Definition at line 1932 of file Neuron.cpp.

References nuParser::eval(), findArg(), moose::mtrand(), and nuParser::numVal.

Referenced by Neuron::installSpines().

1937 {
1938  string sizeExpr = findArg( line, "size" );
1939  string sizeDistribExpr = findArg( line, "sizeDistrib" );
1940  size.clear();
1941  size.resize( elistIndex.size(), 0.0 );
1942 
1943  try
1944  {
1945  nuParser sizeParser( sizeExpr );
1946  nuParser distribParser( sizeDistribExpr );
1947  unsigned int lastIndex = ~0U;
1948  double sz = 1.0;
1949  double sizeDistrib = 0;
1950  for ( unsigned int k = 0; k < elistIndex.size(); ++k )
1951  {
1952  unsigned int i = elistIndex[k];
1953  if ( i != lastIndex )
1954  {
1955  lastIndex = i;
1956  unsigned int j = i * nuParser::numVal;
1957  sz = sizeParser.eval( val.begin() + j );
1958  sizeDistrib = distribParser.eval( val.begin() + j);
1959  }
1960 
1961  // Use global RNG.
1962  if ( sizeDistrib > 0 )
1963  size[k] = sz + ( moose::mtrand() - 0.5 ) * sizeDistrib;
1964  else
1965  size[k] = sz;
1966  }
1967  }
1968  catch ( mu::Parser::exception_type& err )
1969  {
1970  cout << err.GetMsg() << endl;
1971  }
1972 }
string findArg(const vector< string > &line, const string &field)
Definition: Neuron.cpp:1716
double mtrand(void)
Generate a random double between 0 and 1.
Definition: global.cpp:97
static const unsigned int numVal
Definition: Neuron.cpp:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool parseDistrib ( vector< vector< string > > &  lines,
const vector< string > &  distrib 
)

Definition at line 587 of file Neuron.cpp.

Referenced by Neuron::setChannelDistribution(), Neuron::setPassiveDistribution(), and Neuron::setSpineDistribution().

589 {
590  lines.clear();
591  vector< string > temp;
592  for ( unsigned int i = 0; i < distrib.size(); ++i )
593  {
594  if ( distrib[i] == "" )
595  {
596  if ( temp.size() < 4 )
597  {
598  cout << "Warning: Neuron::parseDistrib: <4 args: " <<
599  temp.size() << endl;
600  return false;
601  }
602  if ( temp.size() % 2 == 1 )
603  {
604  cout << "Warning: Neuron::parseDistrib: : odd # of args:"
605  << temp.size() << endl;
606  return false;
607  }
608  lines.push_back( temp );
609  temp.clear();
610  }
611  else
612  {
613  temp.push_back( distrib[i] );
614  }
615  }
616  return true;
617 }

+ Here is the caller graph for this function:

static void reorientSpine ( vector< Id > &  spineCompts,
vector< Vec > &  coords,
Vec parentPos,
double  pos,
double  angle,
Vec x,
Vec y,
Vec z 
)
static

Utility function to change coords of spine so as to reorient it.

Definition at line 1583 of file Neuron.cpp.

References Vec::a0(), Vec::a1(), Vec::a2(), and Field< A >::set().

Referenced by addSpine().

1587 {
1588  double c = cos( angle );
1589  double s = sin( angle );
1590  double omc = 1.0 - c;
1591 
1592  Vec rot0( z.a0()*z.a0()*omc + c,
1593  z.a1()*z.a0()*omc - z.a2()*s ,
1594  z.a2()*z.a0()*omc + z.a1()*s );
1595 
1596  Vec rot1( z.a0()*z.a1()*omc + z.a2()*s,
1597  z.a1()*z.a1()*omc + c,
1598  z.a2()*z.a1()*omc - z.a0()*s );
1599 
1600  Vec rot2( z.a0()*z.a2()*omc - z.a1()*s,
1601  z.a1()*z.a2()*omc + z.a0()*s,
1602  z.a2()*z.a2()*omc + c );
1603 
1604  Vec translation = z * pos + parentPos;
1605  // Vec translation = parentPos;
1606  vector< Vec > ret( coords.size() );
1607  for ( unsigned int i = 0; i < coords.size(); ++i )
1608  {
1609  ret[i] = Vec( rot0.dotProduct( coords[i] ) + translation.a0(),
1610  rot1.dotProduct( coords[i] ) + translation.a1(),
1611  rot2.dotProduct( coords[i] ) + translation.a2() );
1612 
1613  }
1614  assert( spineCompts.size() * 2 == ret.size() );
1615 
1616  for ( unsigned int i = 0; i < spineCompts.size(); ++i )
1617  {
1618  unsigned int j = 2 * i;
1619  Field< double >::set( spineCompts[i], "x0", ret[j].a0() );
1620  Field< double >::set( spineCompts[i], "y0", ret[j].a1() );
1621  Field< double >::set( spineCompts[i], "z0", ret[j].a2() );
1622  // cout << "(" << ret[j].a0() << ", " << ret[j].a1() << ", " << ret[j].a2() << ")";
1623  j = j + 1;
1624  Field< double >::set( spineCompts[i], "x", ret[j].a0() );
1625  Field< double >::set( spineCompts[i], "y", ret[j].a1() );
1626  Field< double >::set( spineCompts[i], "z", ret[j].a2() );
1627  // cout << "(" << ret[j].a0() << ", " << ret[j].a1() << ", " << ret[j].a2() << ")\n";
1628  }
1629 }
double a0() const
Definition: Vec.h:34
double a2() const
Definition: Vec.h:40
static bool set(const ObjId &dest, const string &field, A arg)
Definition: SetGet.h:245
Definition: Vec.h:13
double a1() const
Definition: Vec.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void setCompartmentParams ( const vector< ObjId > &  elist,
const vector< double > &  val,
const string &  field,
const string &  expr 
)
static

Definition at line 758 of file Neuron.cpp.

References assignSingleCompartmentParams(), nuParser::DIA, nuParser::eval(), nuParser::EXPR, nuParser::LEN, and nuParser::numVal.

Referenced by Neuron::setPassiveDistribution().

761 {
762  try
763  {
764  nuParser parser( expr );
765  for ( unsigned int i = 0; i < elist.size(); ++i )
766  {
767  unsigned int j = i * nuParser::numVal;
768  if ( val[ j + nuParser::EXPR ] > 0 )
769  {
770  double len = val[j + nuParser::LEN ];
771  double dia = val[j + nuParser::DIA ];
772  double x = parser.eval( val.begin() + j );
774  x, field, len, dia );
775  }
776  }
777  }
778  catch ( mu::Parser::exception_type& err )
779  {
780  cout << err.GetMsg() << endl;
781  }
782 }
static void assignSingleCompartmentParams(ObjId compt, double val, const string &field, double len, double dia)
Definition: Neuron.cpp:719
static const unsigned int numVal
Definition: Neuron.cpp:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void setMechParams ( const vector< ObjId > &  mech,
const vector< ObjId > &  elist,
const vector< double > &  val,
const string &  field,
const string &  expr 
)
static

Definition at line 784 of file Neuron.cpp.

References assignParam(), nuParser::DIA, nuParser::eval(), nuParser::EXPR, nuParser::LEN, and nuParser::numVal.

Referenced by Neuron::setChannelDistribution().

788 {
789  try
790  {
791  nuParser parser ( expr );
792  for ( unsigned int i = 0; i < elist.size(); ++i )
793  {
794  unsigned int j = i * nuParser::numVal;
795  if ( val[ j + nuParser::EXPR ] > 0 )
796  {
797  double len = val[j + nuParser::LEN ];
798  double dia = val[j + nuParser::DIA ];
799  double x = parser.eval( val.begin() + j );
800  assignParam( mech[i], field, x, len, dia );
801  }
802  }
803  }
804  catch ( mu::Parser::exception_type& err )
805  {
806  cout << err.GetMsg() << endl;
807  }
808 }
static void assignParam(Id obj, const string &field, double val, double len, double dia)
Definition: Neuron.cpp:680
static const unsigned int numVal
Definition: Neuron.cpp:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void traverseCumulativeDistance ( SwcSegment self,
vector< SwcSegment > &  segs,
const vector< Id > &  lookupId,
double  len,
double  L,
double  pSoma,
double  eSoma 
)
static

Recursive function to fill in cumulative distances from soma.

Definition at line 1311 of file Neuron.cpp.

References SwcSegment::distance(), and Field< A >::get().

Referenced by Neuron::updateSegmentLengths().

1315 {
1316  self.setCumulativeDistance( len, L, pSoma, eSoma );
1317  for ( unsigned int i = 0; i < self.kids().size(); ++i )
1318  {
1319  SwcSegment& kid = segs[ self.kids()[i] ];
1320  double segmentLength = kid.distance( self );
1321  double p = pSoma + segmentLength;
1322  Id kidId = lookupId[ self.kids()[i] ];
1323  double Rm = Field< double >::get( kidId, "Rm" );
1324  double Ra = Field< double >::get( kidId, "Ra" );
1325  // Note that sqrt( Rm/Ra ) = lambda/length = 1/L.
1326  double electrotonicLength = sqrt( Ra / Rm );
1327  double e = eSoma + electrotonicLength;
1328  traverseCumulativeDistance( kid, segs, lookupId,
1329  segmentLength, electrotonicLength, p, e );
1330  }
1331 }
static void traverseCumulativeDistance(SwcSegment &self, vector< SwcSegment > &segs, const vector< Id > &lookupId, double len, double L, double pSoma, double eSoma)
Recursive function to fill in cumulative distances from soma.
Definition: Neuron.cpp:1311
double distance(const SwcSegment &other) const
Definition: SwcSegment.h:87
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

const Cinfo* neuronCinfo = Neuron::initCinfo()
static

Definition at line 539 of file Neuron.cpp.

Referenced by Neuron::initCinfo().