13 #include "../shell/Wildcard.h"
16 #include "../utility/utility.h"
29 double simdt,
double plotdt,
double maxtime,
double defaultVol)
36 "// kkit Version 11 flat dumpfile\n\n";
37 fout <<
"// Saved on " << ctime( &rawtime ) << endl;
38 fout <<
"include kkit {argv 1}\n";
39 fout <<
"FASTDT = " << simdt << endl;
40 fout <<
"SIMDT = " << simdt << endl;
41 fout <<
"CONTROLDT = " << plotdt << endl;
42 fout <<
"PLOTDT = " << plotdt << endl;
43 fout <<
"MAXTIME = " << maxtime << endl;
44 fout <<
"TRANSIENT_TIME = 2\n"
45 "VARIABLE_DT_FLAG = 0\n";
46 fout <<
"DEFAULT_VOL = " << defaultVol << endl;
47 fout <<
"VERSION = 11.0\n"
48 "setfield /file/modpath value ~/scripts/modules\n"
52 "initdump -version 3 -ignoreorphans 1\n"
53 "simobjdump table input output alloced step_mode stepsize x y z\n"
54 "simobjdump xtree path script namemode sizescale\n"
55 "simobjdump xcoredraw xmin xmax ymin ymax\n"
56 "simobjdump xtext editable\n"
57 "simobjdump xgraph xmin xmax ymin ymax overlay\n"
58 "simobjdump xplot pixflags script fg ysquish do_slope wy\n"
59 "simobjdump group xtree_fg_req xtree_textfg_req plotfield expanded movealone \\\n"
60 " link savename file version md5sum mod_save_flag x y z\n"
61 "simobjdump geometry size dim shape outside xtree_fg_req xtree_textfg_req x y z\n"
62 "simobjdump kpool DiffConst CoInit Co n nInit mwt nMin vol slave_enable \\\n"
63 " geomname xtree_fg_req xtree_textfg_req x y z\n"
64 "simobjdump kreac kf kb notes xtree_fg_req xtree_textfg_req x y z\n"
65 "simobjdump kenz CoComplexInit CoComplex nComplexInit nComplex vol k1 k2 k3 \\\n"
66 " keepconc usecomplex notes xtree_fg_req xtree_textfg_req link x y z\n"
67 "simobjdump stim level1 width1 delay1 level2 width2 delay2 baselevel trig_time \\\n"
68 " trig_mode notes xtree_fg_req xtree_textfg_req is_running x y z\n"
69 "simobjdump xtab input output alloced step_mode stepsize notes editfunc \\\n"
70 " xtree_fg_req xtree_textfg_req baselevel last_x last_y is_running x y z\n"
71 "simobjdump kchan perm gmax Vm is_active use_nernst notewriteReacs xtree_fg_req \\\n"
72 " xtree_textfg_req x y z\n"
73 "simobjdump transport input output alloced step_mode stepsize dt delay clock \\\n"
74 " kf xtree_fg_req xtree_textfg_req x y z\n"
75 "simobjdump proto x y z\n";
82 ObjId compartment(msgpath);
84 cout <<
" trimpath " << msgpath <<endl;
91 if (cmpt !=
"kinetics")
93 std::size_t found = msgpath.find(cmpt);
94 if (found !=std::string::npos)
95 path1 = msgpath.substr(found-1,msgpath.length());
103 std :: size_t found = msgpath.find(cmpt);
104 if (found !=std::string::npos)
106 string pathC = msgpath.substr(found-1,msgpath.length());
107 std :: size_t slash = pathC.find(
'/',found);
108 if (slash !=std::string::npos)
109 path1 = pathC.substr(slash,pathC.length());
116 cout <<
" path " << path1 << endl;
132 string colour,
string textcolour,
133 double x,
double y,
Id comptid )
135 string path =
id.path();
137 string poolpath =
trimPath(
id,comptid);
148 assert( enzMol !=
Id() );
150 unsigned int isMichaelisMenten = 0;
152 if (enzClass ==
"ZombieMMenz" or enzClass ==
"MMenz")
158 isMichaelisMenten = 1;
160 else if (enzClass ==
"ZombieEnz" or enzClass ==
"Enz")
166 assert( cplx !=
Id() );
172 fout <<
"simundump kenz /kinetics" << poolpath <<
" 0 " <<
182 isMichaelisMenten <<
" " <<
184 colour <<
" " << textcolour <<
" \"\"" <<
185 " " << x <<
" " << y <<
" 0\n";
189 string colour,
string textcolour,
190 double x,
double y,
Id comptid )
197 unsigned int numSub =
199 unsigned int numPrd =
201 fout <<
"simundump kreac /kinetics" <<
trimPath(
id,comptid) <<
" 0 " <<
202 kf <<
" " << kb <<
" \"\" " <<
203 colour <<
" " << textcolour <<
" " << x <<
" " << y <<
" 0\n";
208 static const Finfo* setNinitFinfo =
210 static const Finfo* setConcInitFinfo =
212 unsigned int ret = 0;
214 if (
id.element()->cinfo()->isA(
"BufPool" ) )
216 if (
id.element()->getNeighbors( src, setConcInitFinfo ) > 0 )
220 else if (
id.element()->getNeighbors( src, setNinitFinfo ) > 0 )
231 if ( src[0].element()->cinfo()->isA(
"StimulusTable" ) )
239 string colour,
string textcolour,
240 double x,
double y,
Id comptid,
int comptIndex )
251 stringstream geometryTemp ;
252 unsigned int slave_enable = 0;
253 if (pooltype ==
"BufPool" or pooltype ==
"ZombieBufPool")
256 if (children.size() == 0)
258 for ( vector< Id >::iterator i = children.begin(); i != children.end(); ++i )
262 if (clsname ==
"Function" or clsname ==
"ZombieFunction")
270 geometryTemp <<
"/geometry[" << comptIndex <<
"]";
272 geometryTemp <<
"/geometry";
276 fout <<
"simundump kpool /kinetics" <<
trimPath(
id,comptid) <<
" 0 " <<
282 0 <<
" " << 0 <<
" " <<
283 volume *
NA * 1e-3 <<
" " <<
285 " /kinetics"<< geometryTemp.str() <<
" " <<
286 colour <<
" " << textcolour <<
" " << x <<
" " << y <<
" 0\n";
289 string colour,
string textcolour,
292 string path =
id.path();
293 size_t pos = path.find(
"/graphs" );
294 if ( pos == string::npos ) {
295 pos = path.find(
"/moregraphs" );
296 if ( pos == string::npos ) {
300 path = path.substr( pos );
301 fout <<
"simundump xplot " << path <<
" 3 524288 \\\n" <<
302 "\"delete_plot.w <s> <d>; edit_plot.D <w>\" " << textcolour <<
" 0 0 1\n";
307 fout <<
"simundump xgraph /graphs/conc1 0 0 99 0.001 0.999 0\n"
308 "simundump xgraph /graphs/conc2 0 0 100 0 1 0\n"
309 "simundump xgraph /moregraphs/conc3 0 0 100 0 1 0\n"
310 "simundump xgraph /moregraphs/conc4 0 0 100 0 1 0\n"
311 "simundump xcoredraw /edit/draw 0 -6 4 -2 6\n"
312 "simundump xtree /edit/draw/tree 0 \\\n"
313 " /kinetics/#[],/kinetics/#[]/#[],/kinetics/#[]/#[]/#[][TYPE!=proto],/kinetics/#[]/#[]/#[][TYPE!=linkinfo]/##[] \"edit_elm.D <v>; drag_from_edit.w <d> <S> <x> <y> <z>\" auto 0.6\n"
314 "simundump xtext /file/notes 0 1\n";
319 fout <<
"\nenddump\n";
320 fout <<
"complete_loading\n";
330 for (vector <Id> :: iterator rsub = srct.begin(); rsub != srct.end(); rsub++)
332 string s =
"addmsg /kinetics" +
trimPath(*rsub, comptid) +
" /kinetics" +
trimPath(enz, comptid) +
" SUBSTRATE n";
334 s =
"addmsg /kinetics" +
trimPath(enz, comptid) +
" /kinetics" +
trimPath( *rsub, comptid ) +
" REAC sA B";
338 for (vector <Id> :: iterator rprd = prct.begin(); rprd != prct.end(); rprd++)
340 string s =
"addmsg /kinetics" +
trimPath( enz, comptid ) +
" /kinetics" +
trimPath(*rprd, comptid) +
" MM_PRD pA";
344 for (vector <Id> :: iterator enzCl = enzC.begin(); enzCl != enzC.end(); enzCl++)
346 string s =
"addmsg /kinetics" +
trimPath( *enzCl, comptid ) +
" /kinetics" +
trimPath(enz, comptid) +
" ENZYME n";
358 for (vector <Id> :: iterator rsub = srct.begin(); rsub != srct.end(); rsub++)
360 string s =
"addmsg /kinetics" +
trimPath(*rsub, comptid) +
" /kinetics" +
trimPath(enz, comptid) +
" SUBSTRATE n";
362 s =
"addmsg /kinetics" +
trimPath(enz, comptid) +
" /kinetics" +
trimPath( *rsub, comptid ) +
" REAC sA B";
366 for (vector <Id> :: iterator rprd = prct.begin(); rprd != prct.end(); rprd++)
368 string s =
"addmsg /kinetics" +
trimPath( enz, comptid ) +
" /kinetics" +
trimPath(*rprd, comptid) +
" MM_PRD pA";
372 for (vector <Id> :: iterator enzCl = enzC.begin(); enzCl != enzC.end(); enzCl++)
374 string s =
"addmsg /kinetics" +
trimPath( *enzCl, comptid ) +
" /kinetics" +
trimPath(enz, comptid) +
" ENZYME n";
376 s =
"addmsg /kinetics" +
trimPath( enz, comptid ) +
" /kinetics" +
trimPath(*enzCl, comptid) +
" REAC eA B";
384 if (enzClass ==
"ZombieMMenz" or enzClass ==
"MMenz")
393 for (vector <Id> :: iterator rsub = srct.begin(); rsub != srct.end(); rsub++)
395 string s =
"addmsg /kinetics" +
trimPath(*rsub, comptid) +
" /kinetics" +
trimPath(reac, comptid) +
" SUBSTRATE n";
397 s =
"addmsg /kinetics" +
trimPath(reac, comptid) +
" /kinetics" +
trimPath( *rsub, comptid ) +
" REAC A B";
401 for (vector <Id> :: iterator rprd = prct.begin(); rprd != prct.end(); rprd++)
406 string s =
"addmsg /kinetics" +
trimPath( *rprd, comptid ) +
" /kinetics" +
trimPath(reac, comptid) +
" PRODUCT n";
408 s =
"addmsg /kinetics" +
trimPath(reac, comptid) +
" /kinetics" +
trimPath( *rprd,comptid ) +
" REAC B A";
418 Id poolParentId = compt_vol[poolvol].first;
419 string poolParent =
Field <string> :: get(compt_vol[poolvol].first,
"name");
423 for (vector <Id> :: iterator funcIp = func_input.begin(); funcIp != func_input.end(); funcIp++)
427 Id parentId = compt_vol[vol].first;
429 string s =
"addmsg /kinetics" +
trimPath(*funcIp, parentId)+
" /kinetics" +
trimPath(poolPath,poolParentId) +
437 string tabPath = tab.
path();
441 size_t pos = tabPath.find(
"/graphs" );
442 if ( pos == string::npos )
443 pos = tabPath.find(
"/moregraphs" );
444 assert( pos != string::npos );
445 tabPath = tabPath.substr( pos );
446 string s =
"addmsg /kinetics" +
trimPath( poolPath, comptid) +
" " + tabPath +
447 " PLOT Co *" + poolName +
" *" + bg;
460 vector< double > dts =
465 cout <<
"estimatesimtimes" << simDt << plotDt;
467 plotDt = runTime / 200.0;
470 if ( simDt > plotDt )
471 simDt = plotDt / 100;
479 vector< Id > children =
481 vector< double > vols;
483 for ( vector< Id >::iterator i = children.begin();
484 i != children.end(); ++i )
486 if ( i->element()->cinfo()->isA(
"ChemCompt" ) )
489 if ( i->element()->getName() ==
"kinetics" )
500 void writeMsgs( ofstream& fout,
const vector< string >& msgs )
502 for ( vector< string >::const_iterator i = msgs.begin();
503 i != msgs.end(); ++i )
508 vector < ObjId>
group;
512 for ( vector< ObjId >::iterator itr = group.begin(); itr != group.end(); itr++)
515 size_t pos = path.find(
"/kinetics" );
516 if (pos != std::string::npos)
518 path = path.substr( pos );
519 fout <<
"simundump group " << path <<
" 0 " <<
520 "blue" <<
" " <<
"green" <<
" x 0 0 \"\" defaultfile \\\n";
521 fout <<
" defaultfile.g 0 0 0 " << x <<
" " << y <<
" 0\n";
527 ofstream fout( fname.c_str(), ios::out );
528 vector< ObjId > chemCompt;
529 vector< string > msgs;
535 writeHeader( fout, simDt, plotDt, runTime, defaultVol );
541 map < double, pair<Id, int> > compt_vol;
543 unsigned int num =
wildcardFind( model.
path() +
"/##[ISA=ChemCompt]", chemCompt );
546 cout <<
"Warning: writeKkit:: No model found on " << model <<
550 for ( vector< ObjId >::iterator itr = chemCompt.begin(); itr != chemCompt.end(); itr++)
552 vector < unsigned int>dims;
553 unsigned int dims_size;
558 if (comptname !=
"kinetics")
560 fout <<
"simundump group /kinetics/" << comptname <<
" 0 " <<
561 "blue" <<
" " <<
"green" <<
" x 0 0 \"\" defaultfile \\\n";
562 fout <<
" defaultfile.g 0 0 0 " << rand() % 10 + 1 <<
" " << rand() % 10 + 1 <<
" 0\n";
566 ostringstream geometry;
567 int vecIndex = itr-chemCompt.begin();
569 geometry <<
"simundump geometry /kinetics" <<
"/geometry[" << vecIndex <<
"] 0 " << size <<
" " << ndim <<
" sphere " <<
" \"\" white black 0 0 0\n";
571 geometry <<
"simundump geometry /kinetics" <<
"/geometry 0 " << size <<
" " << ndim <<
" sphere " <<
" \"\" white black 0 0 0\n";
572 fout << geometry.str();
573 compt_vol.insert(make_pair(size,make_pair(*itr,vecIndex)));
576 map<double, pair<Id, int> >::iterator compt;
577 for (compt = compt_vol.begin(); compt != compt_vol.end(); compt++)
581 vector< ObjId > Compt_spe;
583 int species_size = 1;
585 for (vector <ObjId> :: iterator itrp = Compt_spe.begin(); itrp != Compt_spe.end(); itrp++)
589 string enzpoolClass =
Field <string> :: get(enzPoolparent,
"className");
590 if (enzpoolClass !=
"ZombieEnz" or enzpoolClass !=
"Enz")
592 Id annotaId( path+
"/info");
593 if ( annotaId !=
Id() )
599 writePool(fout, *itrp,bg,fg,x,y,compt->second.first,compt->second.second);
603 vector< ObjId > Compt_Func;
605 for (vector <ObjId> :: iterator itrF= Compt_Func.begin(); itrF != Compt_Func.end(); itrF++)
610 vector< ObjId > Compt_Reac;
612 for (vector <ObjId> :: iterator itrR= Compt_Reac.begin(); itrR != Compt_Reac.end(); itrR++)
615 Id annotaId( path+
"/info");
622 writeReac( fout, *itrR, bg, fg, x, y, compt->second.first);
625 vector< ObjId > Compt_Enz;
627 for (vector <ObjId> :: iterator itrE= Compt_Enz.begin(); itrE != Compt_Enz.end(); itrE++)
630 Id annotaId( path+
"/info");
637 writeEnz( fout, *itrE, bg, fg, x, y, compt->second.first);
646 vector< ObjId > table;
648 for (vector <ObjId> :: iterator itrT= table.begin(); itrT != table.end(); itrT++)
652 for (vector <Id> :: iterator tabItem= tabSrc.begin(); tabItem != tabSrc.end(); tabItem++)
660 Id parentId = compt_vol[vol].first;
662 Id annotaId(path+
"/info");
int wildcardFind(const string &path, vector< ObjId > &ret)
unsigned int getSlaveEnable(Id id)
void writeMsgs(ofstream &fout, const vector< string > &msgs)
static ObjId parent(const Eref &e)
double estimateSimTimes(double &simDt, double &plotDt)
static SrcFinfo0 * group()
double estimateDefaultVol(Id model)
Returns an estimate of the default volume used in the model.
void writeReac(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
std::string path(const std::string &separator="/") const
unsigned int value() const
static const Cinfo * initCinfo()
void writeGroup(ofstream &fout, Id model)
void storeMMenzMsgs(Id enz, vector< string > &msgs, Id comptid)
void writeFooter(ofstream &fout)
void writeKkit(Id model, const string &fname)
void storeEnzMsgs(Id enz, vector< string > &msgs, Id comptid)
void storeReacMsgs(Id reac, vector< string > &msgs, Id comptid)
void writePool(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid, int comptIndex)
void storePlotMsgs(Id tab, vector< string > &msgs, Id pool, string bg, Id comptid)
void writePlot(ofstream &fout, Id id, string colour, string textcolour, double x, double y)
void storeCplxEnzMsgs(Id enz, vector< string > &msgs, Id comptid)
void writeEnz(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
void storeFunctionMsgs(Id func, vector< string > &msgs, map< double, pair< Id, int > > &compt_vol)
static A get(const ObjId &dest, const string &field)
string trimPath(Id id, Id comptid)
void writeGui(ofstream &fout)
const Finfo * findFinfo(const string &name) const
void writeHeader(ofstream &fout, double simdt, double plotdt, double maxtime, double defaultVol)