void ZombieFunction::setSolver( Id ksolve, Id dsolve ) { if ( ksolve.element()->cinfo()->isA( "Ksolve" ) || ksolve.element()->cinfo()->isA( "Gsolve" ) ) { Id sid = Field< Id >::get( ksolve, "stoich" ); _stoich = ObjId( sid, 0 ).data(); if ( _stoich == 0 ) cout << "Warning:ZombieFunction::setSolver: Empty Stoich on Ksolve" << ksolve.path() << endl; } else if ( ksolve == Id() ) { _stoich = 0; } else { cout << "Warning:ZombieFunction::setSolver: solver class " << ksolve.element()->cinfo()->name() << " not known.\nShould be Ksolve or Gsolve\n"; _stoich = 0; } /* if ( dsolve.element()->cinfo()->isA( "Dsolve" ) ) { dsolve_= ObjId( dsolve, 0 ).data(); } else if ( dsolve == Id() ) { dsolve_ = 0; } else { cout << "Warning:ZombieFunction::vSetSolver: solver class " << dsolve.element()->cinfo()->name() << " not known.\nShould be Dsolve\n"; dsolve_ = 0; } */ }
////////////////////////////////////////////////////////////////// // The read functions. ////////////////////////////////////////////////////////////////// Id makeStandardElements( Id pa, const string& modelname ) { Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() ); //cout << " kkit read " << pa << " " << modelname << " "<< MooseGlobal; string modelPath = pa.path() + "/" + modelname; if ( pa == Id() ) modelPath = "/" + modelname; Id mgr( modelPath ); if ( mgr == Id() ) mgr = shell->doCreate( "Neutral", pa, modelname, 1, MooseGlobal ); Id kinetics( modelPath + "/kinetics" ); if ( kinetics == Id() ) { kinetics = shell->doCreate( "CubeMesh", mgr, "kinetics", 1, MooseGlobal ); SetGet2< double, unsigned int >::set( kinetics, "buildDefaultMesh", 1e-15, 1 ); } assert( kinetics != Id() ); Id graphs = shell->doCreate( "Neutral", mgr, "graphs", 1, MooseGlobal); assert( graphs != Id() ); Id moregraphs = shell->doCreate( "Neutral", mgr, "moregraphs", 1, MooseGlobal ); Id geometry = shell->doCreate( "Neutral", mgr, "geometry", 1, MooseGlobal ); assert( geometry != Id() ); Id groups = shell->doCreate( "Neutral", mgr, "groups", 1, MooseGlobal ); assert( groups != Id() ); return mgr; }
bool HHGate::checkOriginal( Id id, const string& field ) const { if ( id == originalGateId_ ) return 1; cout << "Warning: HHGate: attempt to set field '" << field << "' on " << id.path() << "\nwhich is not the original Gate element. Ignored.\n"; return 0; }
void HSolve::setSeed( Id seed ) { if ( !seed()->cinfo()->isA( "Compartment" ) ) { cerr << "Error: HSolve::setSeed(): Seed object '" << seed.path() << "' is not derived from type 'Compartment'." << endl; return; } seed_ = seed; }
void ZombieCaConc::vSetSolver( const Eref& e, Id hsolve ) { if ( !hsolve.element()->cinfo()->isA( "HSolve" ) ) { cout << "Error: ZombieCaConc::vSetSolver: Object: " << hsolve.path() << " is not an HSolve. Aborted\n"; hsolve_ = 0; return; } hsolve_ = reinterpret_cast< HSolve* >( hsolve.eref().data() ); }
/** * @brief Add a table to streamer. * * @param table Id of table. */ void Streamer::addTable( Id table ) { // If this table is not already in the vector, add it. for( size_t i = 0; i < tableIds_.size(); i++) if( table.path() == tableIds_[i].path() ) return; /* Already added. */ Table* t = reinterpret_cast<Table*>(table.eref().data()); tableIds_.push_back( table ); tables_.push_back( t ); tableTick_.push_back( table.element()->getTick() ); // NOTE: If user can make sure that names are unique in table, using name is // better than using the full path. if( t->getColumnName().size() > 0 ) columns_.push_back( t->getColumnName( ) ); else columns_.push_back( moose::moosePathToUserPath( table.path() ) ); }
void HHChannel2D::innerDestroyGate( const string& gateName, HHGate2D** gatePtr, Id chanId ) { if ( *gatePtr == 0 ) { cout << "Warning: HHChannel2D::destroyGate: '" << gateName << "' on Element '" << chanId.path() << "' not present\n"; return; } delete (*gatePtr); *gatePtr = 0; }
void HHChannel2D::innerCreateGate( const string& gateName, HHGate2D** gatePtr, Id chanId, Id gateId ) { //Shell* shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() ); if ( *gatePtr ) { cout << "Warning: HHChannel2D::createGate: '" << gateName << "' on Element '" << chanId.path() << "' already present\n"; return; } *gatePtr = new HHGate2D( chanId, gateId ); }
void Cell::setupf( Id cell ) { cout << "Cell::setup()" << endl; cout << ".... cell path: " << cell.path() << endl; //~ return; // Delete existing solver string solverPath = cell.path() + "/" + solverName_; Id solver( solverPath ); if ( solver.path() == solverPath ) solver.destroy(); if ( method_ == "ee" ) return; // Find any compartment that is a descendant of this cell Id seed = findCompt( cell ); if ( seed == Id() ) // No compartment found. return; setupSolver( cell, seed ); }
void testHSolvePassiveSingleComp() { Shell * shell = reinterpret_cast< Shell* >( ObjId( Id(), 0 ).data() ); vector< int > dims( 1, 1 ); vector<Id> to_cleanup; Id nid = create_testobject(to_cleanup, "Neuron", Id(), "n", dims ); Id comptId = create_testobject(to_cleanup, "Compartment", nid, "compt", dims ); Id hsolve = create_testobject(to_cleanup, "HSolve", nid, "solver", dims); Field<string>::set(hsolve, "target", nid.path()); to_cleanup.push_back(nid); clear_testobjects(to_cleanup); cout << "." << flush; }
void ZombieMMenz::setSolver( Id solver, Id orig ) { static const DestFinfo* enz = dynamic_cast< const DestFinfo* >( EnzBase::initCinfo()->findFinfo( "enzDest" ) ); static const SrcFinfo* sub = dynamic_cast< const SrcFinfo* >( EnzBase::initCinfo()->findFinfo( "toSub" ) ); static const SrcFinfo* prd = dynamic_cast< const SrcFinfo* >( EnzBase::initCinfo()->findFinfo( "toPrd" ) ); assert( enz ); assert( sub ); assert( prd ); stoich_ = reinterpret_cast< Stoich* >( solver.eref().data() ); /// Now set up the RateTerm vector< Id > subvec; vector< Id > prdvec; unsigned int rateIndex = stoich_->convertIdToReacIndex( orig ); unsigned int num = orig.element()->getNeighbours( subvec, enz ); unsigned int enzIndex = stoich_->convertIdToPoolIndex( subvec[0] ); MMEnzymeBase* meb; double numKm = 1.0; // Dummy default initial values, later to be reset double kcat = 1.0; /* double numKm = base->zGetNumKm( orig.eref(), 0 ); double kcat = base->zGetKcat( orig.eref(), 0 ); */ num = orig.element()->getNeighbours( subvec, sub ); if ( num == 1 ) { unsigned int subIndex = stoich_->convertIdToPoolIndex( subvec[0] ); meb = new MMEnzyme1( numKm, kcat, enzIndex, subIndex ); } else if ( num > 1 ) { vector< unsigned int > v; for ( unsigned int i = 0; i < num; ++i ) v.push_back( stoich_->convertIdToPoolIndex( subvec[i] ) ); ZeroOrder* rateTerm = new NOrder( 1.0, v ); meb = new MMEnzyme( numKm, kcat, enzIndex, rateTerm ); } else { cout << "Error: ZombieMMenz::zombify: No substrates for " << orig.path() << endl; cout << "Will ignore and continue, but don't be surprised if " "simulation fails.\n"; // assert( 0 ); return; } num = orig.element()->getNeighbours( prdvec, prd ); stoich_->installMMenz( meb, rateIndex, subvec, prdvec ); }
/** * Identify parent Id from path that can optionally have the * model name as the last part. Pass back the parent Id, * and the model name. * Returns true on success. * Cases: * First set: we want to fill in "model" as modelName * "" where we want <cwe>/model * "/" where we want /model. * "/foo" where foo exists, so we want /foo/model * "foo" where <cwe>/foo exists, and we want <cwe>/foo/model * Second set: the last part of the path has the model name. * "bar" where we want <cwe>/bar * "/bar" where we want /bar * "/foo/bar" where we want /foo/bar * "foo/bar" where we want <cwe>/foo/bar */ bool findModelParent( Id cwe, const string& path, Id& parentId, string& modelName ) { modelName = "model"; string fullPath = path; if ( path.length() == 0 ) { parentId = cwe; return 1; } if ( path == "/" ) { parentId = Id(); return 1; } if ( path[0] != '/' ) { string temp = cwe.path(); if ( temp[temp.length() - 1] == '/' ) fullPath = temp + path; else fullPath = temp + "/" + path; } Id paId( fullPath ); if ( paId == Id() ) // Path includes new model name { string::size_type pos = fullPath.find_last_of( "/" ); assert( pos != string::npos ); string head = fullPath.substr( 0, pos ); Id ret( head ); // When head = "" it means paId should be root. if ( ret == Id() && head != "" && head != "/root" ) return 0; parentId = ret; modelName = fullPath.substr( pos + 1 ); return 1; } else // Path is an existing element. { parentId = Neutral::parent( paId ).id; modelName = paId.element()->getName(); return 1; } return 0; }
void Gsolve::setDsolve( Id dsolve ) { if ( dsolve == Id () ) { dsolvePtr_ = 0; dsolve_ = Id(); } else if ( dsolve.element()->cinfo()->isA( "Dsolve" ) ) { dsolve_ = dsolve; dsolvePtr_ = reinterpret_cast< ZombiePoolInterface* >( dsolve.eref().data() ); } else { cout << "Warning: Gsolve::setDsolve: Object '" << dsolve.path() << "' should be class Dsolve, is: " << dsolve.element()->cinfo()->name() << endl; } }
/** * @brief Remove a table from Streamer. * * @param table. Id of table. */ void Streamer::removeTable( Id table ) { int matchIndex = -1; for (size_t i = 0; i < tableIds_.size(); i++) if( table.path() == tableIds_[i].path() ) { matchIndex = i; break; } if( matchIndex > -1 ) { tableIds_.erase( tableIds_.begin() + matchIndex ); tables_.erase( tables_.begin() + matchIndex ); columns_.erase( columns_.begin() + matchIndex ); } }
/** * The 'getOriginals' flag requests Id:s of the prototype gates from which * copies were created, instead of Id:s of the copied gates. Default is true. */ int HSolveUtils::gates( Id channel, vector< Id >& ret, bool getOriginals ) { // dump("HSolveUtils::gates() is not tested with new hsolve api", "FIXME"); unsigned int oldSize = ret.size(); static string gateName[] = { string( "gateX[0]" ), string( "gateY[0]" ), string( "gateZ[0]" ) }; static string powerField[] = { string( "Xpower" ), string( "Ypower" ), string( "Zpower" ) }; unsigned int nGates = 3; // Number of possible gates for ( unsigned int i = 0; i < nGates; i++ ) { double power = Field< double >::get ( channel, powerField[i] ); if ( power > 0.0 ) { // string gatePath = moose::joinPath(channel.path(), gateName[i]); string gatePath = moose::fixPath( channel.path() ) + "/" + gateName[i]; Id gate( gatePath ); string gPath = moose::fixPath(gate.path()); errorSS.str(""); errorSS << "Got " << gatePath << " expected " << gPath; SIMPLE_ASSERT_MSG(gPath == gatePath, errorSS.str().c_str()); if ( getOriginals ) { HHGate* g = reinterpret_cast< HHGate* >( gate.eref().data() ); gate = g->originalGateId(); } ret.push_back( gate ); } } return ret.size() - oldSize; }
void setMethod( Shell* s, Id mgr, double simdt, double plotdt, const string& method ) { Id compt( mgr.path() + "/kinetics" ); assert( compt != Id() ); string cpath = compt.path(); string simpath = cpath + "/##[]"; string simpath2 = cpath + "/##[ISA=StimulusTable]," + cpath + "/##[ISA=PulseGen]"; string m = lower( method ); if ( m == "rk4" ) { cout << "Warning, not yet implemented. Using rk5 instead\n"; m = "rk5"; } if ( m == "ksolve" || m == "gsl" || m == "rk5" || m == "rkf" || m == "rk" ) { Id ksolve = s->doCreate( "Ksolve", compt, "ksolve", 1 ); Id stoich = s->doCreate( "Stoich", compt, "stoich", 1 ); Field< Id >::set( stoich, "compartment", compt ); Field< Id >::set( stoich, "ksolve", ksolve ); Field< string >::set( stoich, "path", simpath ); simpath2 += "," + cpath + "/ksolve"; s->doUseClock( simpath2, "process", 4 ); s->doSetClock( 4, plotdt ); } else if ( m == "gssa" || m == "gsolve" || m == "gillespie" || m == "stochastic" ) { Id gsolve = s->doCreate( "Gsolve", compt, "gsolve", 1 ); Id stoich = s->doCreate( "Stoich", compt, "stoich", 1 ); Field< Id >::set( stoich, "compartment", compt ); Field< Id >::set( stoich, "ksolve", gsolve ); Field< string >::set( stoich, "path", simpath ); simpath2 += "," + cpath + "/gsolve"; s->doUseClock( simpath2, "process", 4 ); s->doSetClock( 4, plotdt ); } else if ( m == "ee" || m == "neutral" ) { s->doUseClock( simpath, "process", 4 ); s->doSetClock( 4, simdt ); } else { cout << "ReadKkit::setMethod: option " << method << " not known, using Exponential Euler (ee)\n"; s->doUseClock( simpath, "process", 4 ); s->doSetClock( 4, simdt ); } }
/** * The readcell function implements the old GENESIS cellreader * functionality. Although it is really a parser operation, I * put it here in Kinetics because the cell format is independent * of parser and is likely to remain a legacy for a while. */ Id ReadKkit::read( const string& filename, const string& modelname, Id pa, const string& methodArg ) { string method = methodArg; ifstream fin( filename.c_str() ); if (!fin){ cerr << "ReadKkit::read: could not open file " << filename << endl; return Id(); } if ( method.substr(0, 4) == "old_" ) { moveOntoCompartment_ = false; method = method.substr( 4 ); } Shell* s = reinterpret_cast< Shell* >( ObjId().data() ); Id mgr = makeStandardElements( pa, modelname ); assert( mgr != Id() ); baseId_ = mgr; basePath_ = mgr.path(); enzCplxMols_.resize( 0 ); innerRead( fin ); assignPoolCompartments(); assignReacCompartments(); assignEnzCompartments(); assignMMenzCompartments(); convertParametersToConcUnits(); s->doSetClock( 8, plotdt_ ); string plotpath = basePath_ + "/graphs/##[TYPE=Table]," + basePath_ + "/moregraphs/##[TYPE=Table]"; s->doUseClock( plotpath, "process", 8 ); setMethod( s, mgr, simdt_, plotdt_, method ); s->doReinit(); return mgr; }
/** * The 'getOriginals' flag requests Id:s of the prototype gates from which * copies were created, instead of Id:s of the copied gates. Default is true. */ int HSolveUtils::gates( Id channel, vector< Id >& ret, bool getOriginals ) { unsigned int oldSize = ret.size(); static string gateName[] = { string( "gateX[0]" ), string( "gateY[0]" ), string( "gateZ[0]" ) }; static string powerField[] = { string( "Xpower" ), string( "Ypower" ), string( "Zpower" ) }; unsigned int nGates = 3; // Number of possible gates for ( unsigned int i = 0; i < nGates; i++ ) { double power = HSolveUtils::get< HHChannel, double >( channel, powerField[ i ] ); if ( power > 0.0 ) { string gatePath = channel.path() + "/" + gateName[ i ]; Id gate( gatePath ); assert( gate.path() == gatePath ); if ( getOriginals ) { HHGate* g = reinterpret_cast< HHGate* >( gate.eref().data() ); gate = g->originalGateId(); } ret.push_back( gate ); } } return ret.size() - oldSize; }
void SbmlReader ::findModelParent( Id cwe, const string& path, Id& parentId, string& modelName ) { //Taken from LoadModels.cpp //If path exist example /model when come from GUI it creates model under /model/filename // i.e. because by default we creat genesis,sbml models under '/model', which is created before and path exist // at the time it comes to SbmlReader.cpp //When run directly (command line readSBML() )it ignores the path and creates under '/' and filename takes as "SBMLtoMoose" //modelName = "test"; cout << "here " << path; string fullPath = path; if ( path.length() == 0 ) parentId = cwe; if ( path == "/" ) parentId = Id(); if ( path[0] != '/' ) { string temp = cwe.path(); if ( temp[temp.length() - 1] == '/' ) fullPath = temp + path; else fullPath = temp + "/" + path; } Id paId( fullPath ); if ( paId == Id() ) { // Path includes new model name string::size_type pos = fullPath.find_last_of( "/" ); assert( pos != string::npos ); string head = fullPath.substr( 0, pos ); Id ret( head ); // When head = "" it means paId should be root. if ( ret == Id() && head != "" && head != "/root" ) ;//return 0; parentId = ret; modelName = fullPath.substr( pos + 1 ); } else { // Path is an existing element. parentId = paId; } }
/** * This takes the baseclass for an MMEnzyme and builds the * MMenz into the Stoich. */ void GslStoich::installMMenz( Id enzId, Id enzMolId, const vector< Id >& subs, const vector< Id >& prds ) { MMEnzymeBase* meb; unsigned int enzIndex = coreStoich()->convertIdToPoolIndex( enzMolId ); unsigned int enzSiteIndex = coreStoich()->convertIdToReacIndex( enzId ); if ( subs.size() == 1 ) { unsigned int subIndex = coreStoich()->convertIdToPoolIndex( subs[0] ); meb = new MMEnzyme1( 1, 1, enzIndex, subIndex ); } else if ( subs.size() > 1 ) { vector< unsigned int > v; for ( unsigned int i = 0; i < subs.size(); ++i ) v.push_back( coreStoich()->convertIdToPoolIndex( subs[i] ) ); ZeroOrder* rateTerm = new NOrder( 1.0, v ); meb = new MMEnzyme( 1, 1, enzIndex, rateTerm ); } else { cout << "Error: GslStoich::installEnzyme: No substrates for " << enzId.path() << endl; return; } coreStoich_.installMMenz( meb, enzSiteIndex, subs, prds ); }
Id SigNeur::findSoma( const vector< Id >& compts ) { double maxDia = 0; Id maxCompt; vector< Id > somaCompts; // Theoretically possible to have an array. for ( vector< Id >::const_iterator i = compts.begin(); i != compts.end(); ++i ) { string className = i->eref()->className(); if ( className == "Compartment" || className == "SymCompartment" ) { string name = i->eref().e->name(); if ( name == "soma" || name == "Soma" || name == "SOMA" ) somaCompts.push_back( *i ); double dia; get< double >( i->eref(), "diameter", dia ); if ( dia > maxDia ) maxCompt = *i; } } if ( somaCompts.size() == 1 ) // First, go by name. return somaCompts[0]; if ( somaCompts.size() == 0 & maxCompt.good() ) //if no name, use maxdia return maxCompt; if ( somaCompts.size() > 1 ) { // Messy but unlikely cases. if ( maxCompt.good() ) { if ( find( somaCompts.begin(), somaCompts.end(), maxCompt ) != somaCompts.end() ) return maxCompt; else cout << "Error, soma '" << somaCompts.front().path() << "' != biggest compartment '" << maxCompt.path() << "'\n"; } return somaCompts[0]; // Should never happen, but an OK response. } cout << "Error: SigNeur::findSoma failed to find soma\n"; return Id(); }
// static func to convert id into a string. string Id::id2str( Id id ) { return id.path(); }
string SigNeur::__get_cellProto() const { Id cellProto; get < Id > (id_(), "cellProto", cellProto); return cellProto.path(); }
string SigNeur::__get_dend() const { Id dend; get < Id > (id_(), "dend",dend); return dend.path(); }
string SigNeur::__get_dendProto() const { Id dendProto; get < Id > (id_(), "dendProto", dendProto); return dendProto.path(); }
string SigNeur::__get_somaProto() const { Id somaProto; get < Id > (id_(), "somaProto",somaProto); return somaProto.path(); }
string SigNeur::__get_cell() const { Id cell; get < Id > (id_(), "cell",cell); return cell.path(); }
string SigNeur::__get_spine() const { Id spine; get < Id > (id_(), "spine",spine); return spine.path(); }
string SigNeur::__get_spineProto() const { Id spineProto; get < Id > (id_(), "spineProto",spineProto); return spineProto.path(); }
string SigNeur::__get_soma() const { Id soma; get < Id > (id_(), "soma",soma); return soma.path(); }