15 #include "../utility/utility.h"
23 #include "../shell/Shell.h"
24 #include "../shell/Wildcard.h"
31 unsigned int chopLine(
const string& line, vector< string >& ret )
34 stringstream ss( line );
42 string lower(
const string& input )
45 for (
unsigned int i = 0; i < input.length(); ++i )
46 ret[i] = tolower( ret[i] );
61 transientTime_( 1.0 ),
65 initdumpVersion_( 3 ),
66 moveOntoCompartment_( true ),
67 numCompartments_( 0 ),
76 shell_( reinterpret_cast<
Shell* >(
Id().eref().data() ) )
126 string modelPath = pa.
path() +
"/" + modelname;
128 modelPath =
"/" + modelname;
132 Id kinetics( modelPath +
"/kinetics" );
133 if ( kinetics ==
Id() ) {
138 assert( kinetics !=
Id() );
141 assert( graphs !=
Id() );
145 assert( geometry !=
Id() );
149 assert( groups !=
Id() );
170 if ( compts.size() > 3 ) {
171 cout <<
"Warning: ReadKkit::makeSolverOnCompt: Cannot handle " <<
172 compts.size() <<
" chemical compartments\n";
175 vector< Id > stoichVec;
220 const string& method )
224 assert( ret.size() > 0 );
226 Id compt( mgr.
path() +
"/kinetics" );
227 assert( compt !=
Id() );
228 string simpath2 = mgr.
path() +
"/##[ISA=StimulusTable]," +
229 mgr.
path() +
"/##[ISA=PulseGen]";
230 string m =
lower( method );
277 const string& filename,
278 const string& modelname,
279 Id pa,
const string& methodArg )
281 string method = methodArg;
282 ifstream fin( filename.c_str() );
284 cerr <<
"ReadKkit::read: could not open file " << filename << endl;
288 if ( method.substr(0, 4) ==
"old_" ) {
290 method = method.substr( 4 );
295 assert( mgr !=
Id() );
312 assert(kinetics !=
Id());
314 assert( cInfo !=
Id() );
350 vector< ObjId > plots;
351 string plotpath =
basePath_ +
"/graphs/##[TYPE=Table2]," +
352 basePath_ +
"/moregraphs/##[TYPE=Table2]";
354 for ( vector< ObjId >::iterator
355 i = plots.begin(); i != plots.end(); ++i )
357 filename, i->element()->getName() );
365 string::size_type pos;
369 while ( getline( fin, temp ) ) {
374 if ( temp.length() == 0 )
376 pos = temp.find_last_not_of(
"\t " );
377 if ( pos == string::npos ) {
383 if ( temp[pos] ==
'\\' ) {
394 pos = line.find_first_not_of(
"\t " );
395 if ( pos == string::npos )
398 line = line.substr( pos );
399 if ( line.substr( 0, 2 ) ==
"//" )
401 if ( (pos = line.find(
"//")) != string::npos )
402 line = line.substr( 0, pos );
403 if ( line.substr( 0, 2 ) ==
"/*" ) {
405 line = line.substr( 2 );
409 pos = line.find(
"*/" );
410 if ( pos != string::npos ) {
412 if ( line.length() > pos + 2 )
413 line = line.substr( pos + 2 );
417 if ( parseMode ==
DATA )
419 else if ( parseMode ==
INIT ) {
441 vector< string > argv;
443 if ( argv.size() < 3 )
446 if ( argv[0] ==
"FASTDT" ) {
447 fastdt_ = atof( argv[2].c_str() );
450 if ( argv[0] ==
"SIMDT" ) {
451 simdt_ = atof( argv[2].c_str() );
454 if ( argv[0] ==
"CONTROLDT" ) {
458 if ( argv[0] ==
"PLOTDT" ) {
459 plotdt_ = atof( argv[2].c_str() );
462 if ( argv[0] ==
"MAXTIME" ) {
466 if ( argv[0] ==
"TRANSIENT_TIME" ) {
470 if ( argv[0] ==
"VARIABLE_DT_FLAG" ) {
474 if ( argv[0] ==
"DEFAULT_VOL" ) {
478 if ( argv[0] ==
"VERSION" ) {
483 if ( argv[0] ==
"initdump" ) {
493 vector< string > argv;
496 if ( argv[0] ==
"simundump" )
498 else if ( argv[0] ==
"addmsg" )
500 else if ( argv[0] ==
"call" )
502 else if ( argv[0] ==
"simobjdump" )
504 else if ( argv[0] ==
"xtextload" )
506 else if ( argv[0] ==
"loadtab" )
512 string::size_type pos = path.find_last_of(
"/" );
513 assert( pos != string::npos );
515 head =
basePath_ + path.substr( 0, pos );
516 return path.substr( pos + 1 );
530 string cleanDigit=
"/";
533 size_t sindex = path.find(
'/',Iindex+1);
534 if (sindex == string::npos)
535 {
if (isdigit((path.substr(Iindex+1,sindex-Iindex-1))[0]) )
537 cleanDigit += path.substr(Iindex+1,sindex-Iindex-1);
540 if (isdigit((path.substr(Iindex+1,sindex-Iindex-1))[0]))
542 cleanDigit += path.substr(Iindex+1,sindex-Iindex);
545 string ret = cleanDigit;
548 for (
unsigned int i = 0; i < cleanDigit.length(); ++i ) {
552 else if ( c ==
'[' || c ==
']' || c ==
'@' || c ==
' ')
562 void assignArgs( map< string, int >& argConv,
const vector< string >& args )
564 for (
unsigned int i = 2; i != args.size(); ++i )
565 argConv[ args[i] ] = i + 2;
569 {
if ( args[1] ==
"kpool" )
571 else if ( args[1] ==
"kreac" )
573 else if ( args[1] ==
"kenz" )
575 else if ( args[1] ==
"group" )
577 else if ( args[1] ==
"xtab" )
579 else if ( args[1] ==
"stim" )
581 else if ( args[1] ==
"kchan" )
588 if ( args.size() > 3 ) {
589 unsigned int len = args[1].length();
590 if ( ( args[1].substr( len - 5 ) ==
"notes" ) &&
591 args[2] ==
"LOAD" ) {
592 if ( args[3].length() == 0 )
595 string objName =
cleanPath(args[1].substr( 0, len - 5 ));
601 for (
unsigned int i = 3; i < args.size(); ++i ) {
602 unsigned int innerLength = args[i].length();
603 if ( innerLength == 0 )
605 unsigned int start = 0;
606 unsigned int end = innerLength;
607 if ( args[i][0] ==
'\"' )
609 if ( args[i][innerLength - 1] ==
'\"' )
610 end = innerLength - 1 - start;
612 notes += space + args[i].substr( start, end );
626 {
if ( args[1] ==
"kpool" )
628 else if ( args[1] ==
"kreac" )
630 else if ( args[1] ==
"kenz" )
632 else if ( args[1] ==
"text" )
634 else if ( args[1] ==
"xplot" )
636 else if ( args[1] ==
"xgraph" )
638 else if ( args[1] ==
"group" )
640 else if ( args[1] ==
"geometry" )
642 else if ( args[1] ==
"stim" )
644 else if ( args[1] ==
"xcoredraw" )
646 else if ( args[1] ==
"xtree" )
648 else if ( args[1] ==
"xtext" )
650 else if ( args[1] ==
"doqcsinfo" )
652 else if ( args[1] ==
"kchan" )
654 else if ( args[1] ==
"xtab" )
657 cout <<
"ReadKkit::undump: Do not know how to build '" << args[1] <<
672 string tail =
pathTail( clean, head );
674 assert( pa !=
Id() );
676 double kf = atof( args[
reacMap_[
"kf" ] ].c_str() );
677 double kb = atof( args[
reacMap_[
"kb" ] ].c_str() );
686 reacIds_[ clean.substr( 10 ) ] = reac;
702 static const double TINY = 1e-3;
704 for (
unsigned int i = 0 ; i <
vols_.size(); ++i ) {
705 if ( fabs(
vols_[i] - vol ) / ( fabs(
vols_[i] ) + fabs( vol ) ) < TINY ) {
710 vols_.push_back( vol );
711 vector< Id > temp( 1, pool );
716 const pair< unsigned int, double >& A,
717 const pair< unsigned int, double >& B )
719 return A.second < B.second;
725 vector< pair< unsigned int, double > > p( vols.size() );
726 for (
unsigned int i = 0; i < vols.size(); ++i ) {
728 p[i].second = vols[i];
731 vector< unsigned int > ret( vols.size() );
732 for (
unsigned int i = 0; i < vols.size(); ++i ) {
733 ret[ vols.size() -i -1 ] = p[i].first;
743 assert( kinetics !=
Id() );
748 for (
unsigned int j = 0 ; j < volOrder.size(); ++j ) {
749 unsigned int i = volOrder[j];
754 assert( kinId !=
Id() );
761 ss <<
"compartment_" << j;
764 if ( comptId ==
Id() )
791 static const Finfo* subFinfo =
797 if ( subVec.size() == 0 )
812 for ( map< string, Id >::iterator i =
reacIds_.begin();
815 if ( compt !=
Id() ) {
830 static const Finfo* enzFinfo =
836 assert( enzVec.size() == 1 );
837 vector< Id > meshEntries;
887 string tail =
pathTail( clean, head );
889 assert ( pa !=
Id() );
891 double k1 = atof( args[
enzMap_[
"k1" ] ].c_str() );
892 double k2 = atof( args[
enzMap_[
"k2" ] ].c_str() );
893 double k3 = atof( args[
enzMap_[
"k3" ] ].c_str() );
895 double nComplexInit =
896 atof( args[
enzMap_[
"nComplexInit" ] ].c_str() );
898 bool isMM = atoi( args[
enzMap_[
"usecomplex" ] ].c_str());
911 assert( enz !=
Id () );
912 string mmEnzPath = clean.substr( 10 );
916 double Km = ( k2 + k3 ) / k1;
926 assert( enz !=
Id () );
927 string enzPath = clean.substr( 10 );
938 double Km = (k2+k3)/(k1 *
KKIT_NA * vol );
941 string cplxName = tail +
"_cplx";
942 string cplxPath = enzPath +
"/" + cplxName;
944 assert( cplx !=
Id () );
954 ObjId( enz, 0 ),
"cplx",
955 ObjId( cplx, 0 ),
"reac" );
956 assert( ret !=
ObjId() );
976 map< string, int >& m,
const vector< string >& args )
979 assert( info !=
Id() );
981 double x = atof( args[ m[
"x" ] ].c_str() );
982 double y = atof( args[ m[
"y" ] ].c_str() );
988 args[ m[
"xtree_textfg_req" ] ] );
997 assert( pa !=
Id() );
999 assert( group !=
Id() );
1019 string tail =
pathTail( clean, head );
1021 assert( pa !=
Id() );
1023 double nInit = atof( args[
poolMap_[
"nInit" ] ].c_str() );
1024 double vsf = atof( args[
poolMap_[
"vol" ] ].c_str() );
1031 double vol = 1.0e3 * vsf /
KKIT_NA;
1032 int slaveEnable = atoi( args[
poolMap_[
"slave_enable" ] ].c_str() );
1033 double diffConst = atof( args[
poolMap_[
"DiffConst" ] ].c_str() );
1037 if ( diffConst < 0 )
1041 if ( slaveEnable == 0 ) {
1043 }
else if ( slaveEnable & 4 ) {
1053 assert( pool !=
Id() );
1055 poolIds_[ clean.substr( 10 ) ] = pool;
1080 map< string, Id >::iterator i =
poolIds_.find( src );
1087 string cplx = src +
'/' +
pathTail( src, head ) +
"_cplx";
1093 cout <<
"Error: ReadKkit::findSumTotSrc: Cannot find source pool '" << src << endl;
1100 map< string, Id >::iterator i =
poolIds_.find( dest );
1102 Id destId = i->second;
1106 if ( destId.element()->cinfo()->name() ==
"Pool" ) {
1112 ObjId( sumId, 0 ),
"valueOut",
1113 ObjId( destId, 0 ),
"setN" );
1114 assert( ret !=
ObjId() );
1119 if ( sumId ==
Id() ) {
1120 cout <<
"Error: ReadKkit::buildSumTotal: could not make Function on '"
1131 ObjId( srcId, 0 ),
"nOut",
1133 assert( ret !=
ObjId() );
1137 for (
unsigned int i = 0; i < numVars; ++i ) {
1138 ss <<
"x" << i <<
"+";
1140 ss <<
"x" << numVars;
1151 string tail =
pathTail( clean, head );
1153 assert( pa !=
Id() );
1155 double level1 = atof( args[
stimMap_[
"firstLevel" ] ].c_str() );
1156 double width1 = atof( args[
stimMap_[
"firstWidth" ] ].c_str() );
1157 double delay1 = atof( args[
stimMap_[
"firstDelay" ] ].c_str() );
1158 double level2 = atof( args[
stimMap_[
"secondLevel" ] ].c_str() );
1159 double width2 = atof( args[
stimMap_[
"secondWidth" ] ].c_str() );
1160 double delay2 = atof( args[
stimMap_[
"secondLevel" ] ].c_str() );
1161 double baselevel = atof( args[
stimMap_[
"baseLevel" ] ].c_str() );
1164 assert( stim !=
Id() );
1165 string stimPath = clean.substr( 10 );
1186 string tail =
pathTail( clean, head );
1188 assert( pa !=
Id() );
1192 double permeability = atof( args[
chanMap_[
"perm"] ].c_str() );
1195 assert( chan !=
Id() );
1196 string chanPath = clean.substr( 10 );
1215 assert( pa !=
Id() );
1217 assert( graph !=
Id() );
1227 string graph =
pathTail( head, temp );
1230 assert( pa !=
Id() );
1233 assert( plot !=
Id() );
1235 temp = graph +
"/" + tail;
1249 string tail =
pathTail( clean, head );
1252 assert( pa !=
Id() );
1255 int mode = atoi( args[
tableMap_[
"step_mode" ] ].c_str() );
1259 assert( tab !=
Id() );
1260 double stepSize = atof( args[
tableMap_[
"stepsize" ] ].c_str() );
1264 double input = atof( args[
tableMap_[
"input" ] ].c_str() );
1271 string temp = clean.substr( 10 );
1282 unsigned int start = 0;
1283 if ( args[1].substr( 0, 5 ) ==
"-cont" || args[1] ==
"-end" ) {
1286 assert( tab !=
Id() );
1290 assert( args.size() >= start );
1292 assert( tab !=
Id() );
1296 double xmin = atof( args[5].c_str() );
1297 double xmax = atof( args[6].c_str() );
1305 for (
unsigned int i = start; i < args.size(); ++i ) {
1312 if ( args[1] ==
"-end" )
1319 const string& src,
const map< string, Id >& m1,
const string& srcMsg,
1320 const string& dest,
const map< string, Id >& m2,
const string& destMsg,
1323 map< string, Id >::const_iterator i = m1.find( src );
1324 assert( i != m1.end() );
1325 Id srcId = i->second;
1327 i = m2.find( dest );
1328 assert( i != m2.end() );
1329 Id destId = i->second;
1334 ObjId( srcId, 0 ), srcMsg,
1335 ObjId( destId, 0 ), destMsg );
1336 assert( ret !=
ObjId() );
1339 ObjId( srcId, 0 ), srcMsg,
1340 ObjId( destId, 0 ), destMsg );
1341 assert( ret !=
ObjId() );
1348 string src =
cleanPath( args[1] ).substr( 10 );
1349 string dest =
cleanPath( args[2] ).substr( 10 );
1351 if ( args[3] ==
"REAC" ) {
1352 if ( args[4] ==
"A" && args[5] ==
"B" ) {
1358 else if ( args[4] ==
"B" && args[5] ==
"A" ) {
1365 else if ( args[4] ==
"sA" && args[5] ==
"B" ) {
1373 else if ( args[3] ==
"ENZYME" ) {
1386 else if ( args[3] ==
"MM_PRD" ) {
1392 else if ( args[3] ==
"NUMCHAN" ) {
1396 else if ( args[3] ==
"PLOT" ) {
1400 string graph =
pathTail( head, temp );
1401 temp = graph +
"/" + dest;
1402 map< string, Id >::const_iterator i =
plotIds_.find( temp );
1404 Id plot = i->second;
1411 cout <<
"Error: ReadKkit: Unable to find src for plot: " <<
1412 src <<
", " << dest << endl;
1416 vector< Id > enzcplx;
1417 i->second.element()->getNeighbors( enzcplx,
1418 i->second.element()->cinfo()->findFinfo(
"cplxOut" ) );
1419 assert( enzcplx.size() == 1 );
1425 if ( args[4] ==
"Co" || args[4] ==
"CoComplex" ) {
1427 plot,
"requestOut", pool,
"getConc" );
1428 assert( ret !=
ObjId() );
1429 }
else if ( args[4] ==
"n" || args[4] ==
"nComplex") {
1431 plot,
"requestOut", pool,
"getN" );
1432 assert( ret !=
ObjId() );
1434 cout <<
"Unknown PLOT msg field '" << args[4] <<
"'\n";
1437 else if ( args[3] ==
"SUMTOTAL" ) {
1440 else if ( args[3] ==
"SLAVE" ) {
1441 if ( args[4] ==
"output" ) {
1451 assert( destId !=
Id() );
1457 map< string, Id >* nameMap;
1460 assert( srcId !=
Id() );
1461 string output =
"output";
1468 cout <<
"Error: Unknown source for SLAVE msg: (" << src <<
1469 ", " << dest <<
")\n";
1474 map< Id, int >::iterator i =
poolFlags_.find( destId );
1475 if ( i ==
poolFlags_.end() || !( i->second & 2 ) ) {
1482 double CONCSCALE = 0.001;
1487 }
else if ( nameMap == &
stimIds_ ) {
1517 for ( map< string, Id >::iterator i =
poolIds_.begin();
1519 Id pool = i->second;
1533 for ( map< string, Id >::iterator i =
reacIds_.begin();
1535 Id reac = i->second;
1544 unsigned int numSub =
1546 unsigned int numPrd =
1550 kf *= pow( NA_RATIO, numSub - 1.0 );
1553 kb *= pow( NA_RATIO, numPrd - 1.0 );
1565 for ( map< string, Id >::iterator i =
mmEnzIds_.begin();
1576 numKm *= pow( NA_RATIO, -numSub );
1591 for ( map< string, Id >::iterator i =
enzIds_.begin();
1601 k1 *= pow( NA_RATIO, numSub );
int wildcardFind(const string &path, vector< ObjId > &ret)
Id buildGroup(const vector< string > &args)
unsigned int version_
Default volume for new compartments.
Id buildTable(const vector< string > &args)
void doStart(double runtime, bool notify=false)
void convertReacRatesToConcUnits()
Convert Reac rates, initially in n units.
void assignArgs(map< string, int > &argConv, const vector< string > &args)
void undump(const vector< string > &args)
vector< double > tabEntries_
This holds the vector of array entries for loadtab.
double transientTime_
Simulation run time.
double defaultVol_
Use both fast and sim dts.
Id baseId_
Base path into which entire kkit model will go.
void assignEnzCompartments()
double maxtime_
Timestep for updating plots.
unsigned int initdumpVersion_
KKit version.
static SrcFinfo0 * group()
void readData(const string &line)
double getMaxTime() const
double fastdt_
Base Id onto which entire kkit model will go.
void convertEnzRatesToConcUnits()
Id buildGeometry(const vector< string > &args)
map< string, int > stimMap_
Element * element() const
Synonym for Id::operator()()
Id buildStim(const vector< string > &args)
bool volCompare(const pair< unsigned int, double > &A, const pair< unsigned int, double > &B)
map< string, int > tableMap_
void doSetClock(unsigned int tickNum, double dt)
void makeSolverOnCompt(Shell *s, const vector< ObjId > &compts, bool isGsolve)
bool getMoveOntoCompartment() const
std::string path(const std::string &separator="/") const
void setupSlaveMsg(const string &src, const string &dest)
unsigned int value() const
string pathTail(const string &path, string &head) const
map< string, Id > chanIds_
void separateVols(Id pool, double vol)
double plotdt_
Timestep for updating control graphics.
map< string, Id > poolIds_
unsigned int loadTab(const vector< string > &args)
void innerRead(ifstream &fin)
map< string, Id > tabIds_
map< string, Id > reacIds_
vector< vector< Id > > volCategories_
List of Ids in each unique volume.
Id findSumTotSrc(const string &src)
virtual void zombieSwap(const Cinfo *zCinfo)
virtual func, this base version must be called by all derived classes
unsigned int getVersion() const
static Id child(const Eref &e, const string &name)
void dumpPlots(const string &filename)
int simpleWildcardFind(const string &path, vector< ObjId > &ret)
void innerAddMsg(const string &src, const map< string, Id > &m1, const string &srcMsg, const string &dest, const map< string, Id > &m2, const string &destMsg, bool isBackward=0)
bool useVariableDt_
Time to run model at fastdt.
map< string, Id > enzIds_
static bool set(const ObjId &dest, const string &field, A arg)
Id lastTab_
This keeps track of the last Table used in loadtab.
ObjId doFind(const string &path) const
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
map< string, int > groupMap_
vector< pair< Id, Id > > enzCplxMols_
unsigned int numCompartments_
void convertParametersToConcUnits()
static SrcFinfo1< double > * output()
map< string, int > poolMap_
void objdump(const vector< string > &args)
void convertMMenzRatesToConcUnits()
map< Id, double > poolVols_
string lower(const string &input)
double getDefaultVol() const
void addmsg(const vector< string > &args)
Id buildPlot(const vector< string > &args)
void setMethod(Shell *s, Id mgr, double simdt, double plotdt, const string &method)
Id buildReac(const vector< string > &args)
static const Cinfo * initCinfo()
void convertPoolAmountToConcUnits()
Convert pool amounts. Initially given in n, but scaling issue.
map< string, Id > stimIds_
bool moveOntoCompartment_
Initdump too has a version.
static const Cinfo * initCinfo()
void textload(const vector< string > &args)
double simdt_
fast numerical timestep from kkit.
vector< unsigned int > findVolOrder(const vector< double > &vols)
map< string, int > chanMap_
ParseMode readInit(const string &line)
Id buildEnz(const vector< string > &args)
Id buildChan(const vector< string > &args)
vector< double > vols_
This keeps track of unique volumes.
bool isA(const string &ancestor) const
map< string, int > reacMap_
const Cinfo * cinfo() const
Id buildText(const vector< string > &args)
unsigned int chopLine(const string &line, vector< string > &ret)
string getBasePath() const
Id buildInfo(Id parent, map< string, int > &m, const vector< string > &args)
Id read(const string &filename, const string &cellname, Id parent, const string &solverClass="Stoich")
Id buildCompartment(const vector< string > &args)
void setMoveOntoCompartment(bool v)
Id makeStandardElements(Id pa, const string &modelname)
Id buildPool(const vector< string > &args)
map< string, Id > plotIds_
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
Id findParentComptOfReac(Id reac)
void assignReacCompartments()
static bool set(const ObjId &dest, const string &field, A arg)
void call(const vector< string > &args)
Id buildGraph(const vector< string > &args)
unsigned int getNeighbors(vector< Id > &ret, const Finfo *finfo) const
void doUseClock(string path, string field, unsigned int tick)
static A get(const ObjId &dest, const string &field)
double controldt_
regular numerical timestep from kkit.
static void positionCompt(ObjId compt, double side, bool shiftUp)
std::string trim(const std::string myString, const string &delimiters)
void assignMMenzCompartments()
string cleanPath(const string &path) const
map< Id, int > poolFlags_
map< string, Id > mmEnzIds_
map< string, int > enzMap_
void assignPoolCompartments()
static const double KKIT_NA
static const Cinfo * initCinfo()
const Finfo * findFinfo(const string &name) const
static const double EPSILON
double lookupVolumeFromMesh(const Eref &e)
void buildSumTotal(const string &src, const string &dest)
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2)
void doMove(Id orig, ObjId newParent)