MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
WriteKkit.cpp File Reference
#include <iomanip>
#include <fstream>
#include "../shell/Wildcard.h"
#include "header.h"
#include "../utility/utility.h"
#include "PoolBase.h"
#include "Pool.h"
#include "BufPool.h"
#include "ReacBase.h"
#include "EnzBase.h"
#include "lookupVolumeFromMesh.h"
#include <sstream>
#include <set>
+ Include dependency graph for WriteKkit.cpp:

Go to the source code of this file.

Functions

double estimateDefaultVol (Id model)
 Returns an estimate of the default volume used in the model. More...
 
double estimateSimTimes (double &simDt, double &plotDt)
 
Id getEnzCplx (Id id)
 
Id getEnzMol (Id id)
 
unsigned int getSlaveEnable (Id id)
 
void storeCplxEnzMsgs (Id enz, vector< string > &msgs, Id comptid)
 
void storeEnzMsgs (Id enz, vector< string > &msgs, Id comptid)
 
void storeFunctionMsgs (Id func, vector< string > &msgs, map< double, pair< Id, int > > &compt_vol)
 
void storeMMenzMsgs (Id enz, vector< string > &msgs, Id comptid)
 
void storePlotMsgs (Id tab, vector< string > &msgs, Id pool, string bg, Id comptid)
 
void storeReacMsgs (Id reac, vector< string > &msgs, Id comptid)
 
string trimPath (Id id, Id comptid)
 
void writeEnz (ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
 
void writeFooter (ofstream &fout)
 
void writeGroup (ofstream &fout, Id model)
 
void writeGui (ofstream &fout)
 
void writeHeader (ofstream &fout, double simdt, double plotdt, double maxtime, double defaultVol)
 
void writeKkit (Id model, const string &fname)
 
void writeMsgs (ofstream &fout, const vector< string > &msgs)
 
void writePlot (ofstream &fout, Id id, string colour, string textcolour, double x, double y)
 
void writePool (ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid, int comptIndex)
 
void writeReac (ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
 

Function Documentation

double estimateDefaultVol ( Id  model)

Returns an estimate of the default volume used in the model.

Definition at line 477 of file WriteKkit.cpp.

References Field< A >::get().

Referenced by writeKkit().

478 {
479  vector< Id > children =
480  Field< vector< Id > >::get( model, "children" );
481  vector< double > vols;
482  double maxVol = 0;
483  for ( vector< Id >::iterator i = children.begin();
484  i != children.end(); ++i )
485  {
486  if ( i->element()->cinfo()->isA( "ChemCompt" ) )
487  {
488  double v = Field< double >::get( *i, "volume" );
489  if ( i->element()->getName() == "kinetics" )
490  return v;
491  vols.push_back( v );
492  if ( maxVol < v )
493  maxVol = v;
494  }
495  }
496  if ( maxVol > 0 )
497  return maxVol;
498  return 1.0e-15;
499 }
Definition: SetGet.h:236
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:

double estimateSimTimes ( double &  simDt,
double &  plotDt 
)

A bunch of heuristics to find good SimTimes to use for kkit. Returns runTime.

Definition at line 455 of file WriteKkit.cpp.

References Field< A >::get().

Referenced by writeKkit().

456 {
457  double runTime = Field< double >::get( Id( 1 ), "runTime" );
458  if ( runTime <= 0 )
459  runTime = 100.0;
460  vector< double > dts =
461  Field< vector< double> >::get( Id( 1 ), "dts" );
462 
463  simDt = dts[11];
464  plotDt = dts[18];
465  cout << "estimatesimtimes" << simDt << plotDt;
466  if ( plotDt <= 0 )
467  plotDt = runTime / 200.0;
468  if ( simDt == 0 )
469  simDt = 0.01;
470  if ( simDt > plotDt )
471  simDt = plotDt / 100;
472 
473  return runTime;
474 }
Definition: SetGet.h:236
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:

Id getEnzCplx ( Id  id)

Definition at line 120 of file WriteKkit.cpp.

Referenced by writeEnz().

121 {
122  vector < Id > srct = LookupField <string,vector < Id> >::get(id, "neighbors","cplxDest");
123  return srct[0];
124 }

+ Here is the caller graph for this function:

Id getEnzMol ( Id  id)

Definition at line 126 of file WriteKkit.cpp.

Referenced by writeEnz().

127 {
128  vector < Id > srct = LookupField <string,vector < Id> >::get(id, "neighbors","enzDest");
129  return srct[0];
130 }

+ Here is the caller graph for this function:

unsigned int getSlaveEnable ( Id  id)

Definition at line 206 of file WriteKkit.cpp.

References Cinfo::findFinfo(), and PoolBase::initCinfo().

207 {
208  static const Finfo* setNinitFinfo =
209  PoolBase::initCinfo()->findFinfo( "set_nInit" );
210  static const Finfo* setConcInitFinfo =
211  PoolBase::initCinfo()->findFinfo( "set_concInit" );
212  unsigned int ret = 0;
213  vector< Id > src;
214  if ( id.element()->cinfo()->isA( "BufPool" ) )
215  {
216  if ( id.element()->getNeighbors( src, setConcInitFinfo ) > 0 )
217  {
218  ret = 2;
219  }
220  else if ( id.element()->getNeighbors( src, setNinitFinfo ) > 0 )
221  {
222  ret = 4;
223  }
224  }
225  else
226  {
227  return 0;
228  }
229  if ( ret == 0 )
230  return 4; // Just simple buffered molecule
231  if ( src[0].element()->cinfo()->isA( "StimulusTable" ) )
232  return ret; // Following a table, this is fine.
233 
234  // Fallback: I have no idea what sent it the input, assume it is legit.
235  return ret;
236 }
static const Cinfo * initCinfo()
Definition: PoolBase.cpp:19
const Finfo * findFinfo(const string &name) const
Definition: Cinfo.cpp:224
Definition: Finfo.h:12

+ Here is the call graph for this function:

void storeCplxEnzMsgs ( Id  enz,
vector< string > &  msgs,
Id  comptid 
)

Definition at line 351 of file WriteKkit.cpp.

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

Referenced by storeEnzMsgs().

352 {
353  Id enzparentId = Field <ObjId> :: get(enz,"parent");
354  string enzPar = Field <string> :: get(enzparentId,"name");
355  string enzName = Field<string> :: get(enz,"name");
356 
357  vector < Id > srct = LookupField <string,vector < Id> >::get(enz, "neighbors","sub");
358  for (vector <Id> :: iterator rsub = srct.begin(); rsub != srct.end(); rsub++)
359  {
360  string s = "addmsg /kinetics" + trimPath(*rsub, comptid) + " /kinetics" + trimPath(enz, comptid) + " SUBSTRATE n";
361  msgs.push_back( s );
362  s = "addmsg /kinetics" + trimPath(enz, comptid) + " /kinetics" + trimPath( *rsub, comptid ) + " REAC sA B";
363  msgs.push_back( s );
364  }
365  vector < Id > prct = LookupField <string,vector < Id> >::get(enz, "neighbors","prd");
366  for (vector <Id> :: iterator rprd = prct.begin(); rprd != prct.end(); rprd++)
367  {
368  string s = "addmsg /kinetics" + trimPath( enz, comptid ) + " /kinetics" + trimPath(*rprd, comptid) + " MM_PRD pA";
369  msgs.push_back( s );
370  }
371  vector < Id > enzC = LookupField <string,vector < Id> >::get(enz, "neighbors","enzOut");
372  for (vector <Id> :: iterator enzCl = enzC.begin(); enzCl != enzC.end(); enzCl++)
373  {
374  string s = "addmsg /kinetics" + trimPath( *enzCl, comptid ) + " /kinetics" + trimPath(enz, comptid) + " ENZYME n";
375  msgs.push_back( s );
376  s = "addmsg /kinetics" + trimPath( enz, comptid ) + " /kinetics" + trimPath(*enzCl, comptid) + " REAC eA B";
377  msgs.push_back( s );
378  }
379 }
Definition: SetGet.h:236
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void storeEnzMsgs ( Id  enz,
vector< string > &  msgs,
Id  comptid 
)

Definition at line 381 of file WriteKkit.cpp.

References storeCplxEnzMsgs(), and storeMMenzMsgs().

Referenced by writeKkit().

382 {
383  string enzClass = Field < string > :: get(enz,"className");
384  if (enzClass == "ZombieMMenz" or enzClass == "MMenz")
385  storeMMenzMsgs(enz, msgs, comptid);
386  else
387  storeCplxEnzMsgs( enz, msgs, comptid );
388 }
Definition: SetGet.h:236
void storeMMenzMsgs(Id enz, vector< string > &msgs, Id comptid)
Definition: WriteKkit.cpp:323
void storeCplxEnzMsgs(Id enz, vector< string > &msgs, Id comptid)
Definition: WriteKkit.cpp:351

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void storeFunctionMsgs ( Id  func,
vector< string > &  msgs,
map< double, pair< Id, int > > &  compt_vol 
)

Definition at line 413 of file WriteKkit.cpp.

References Id::eref(), Neutral::parent(), trimPath(), and Id::value().

Referenced by writeKkit().

414 {
415  // Get the msg sources into this Function object.
416  ObjId poolPath = Neutral::parent( func.eref() );
417  double poolvol = Field < double > :: get(poolPath,"Volume");
418  Id poolParentId = compt_vol[poolvol].first;
419  string poolParent = Field <string> :: get(compt_vol[poolvol].first,"name");
420  Id xi(func.value()+1);
421  vector < Id > func_input = LookupField <string,vector < Id> >::get(xi, "neighbors","input");
422 
423  for (vector <Id> :: iterator funcIp = func_input.begin(); funcIp != func_input.end(); funcIp++)
424  {
425  string funcIp_path = Field < string > :: get(*funcIp,"path");
426  double vol = Field < double > :: get(*funcIp,"Volume");
427  Id parentId = compt_vol[vol].first;
428  string parentname = Field <string> :: get(parentId,"name");
429  string s = "addmsg /kinetics" + trimPath(*funcIp, parentId)+ " /kinetics" + trimPath(poolPath,poolParentId) +
430  " SUMTOTAL n nInit";
431  msgs.push_back(s);
432  }
433 }
static ObjId parent(const Eref &e)
Definition: Neutral.cpp:701
unsigned int value() const
Definition: Id.cpp:197
Definition: SetGet.h:236
Definition: ObjId.h:20
Eref eref() const
Definition: Id.cpp:125
Definition: Id.h:17
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void storeMMenzMsgs ( Id  enz,
vector< string > &  msgs,
Id  comptid 
)

Definition at line 323 of file WriteKkit.cpp.

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

Referenced by storeEnzMsgs().

324 {
325  Id enzparentId = Field <ObjId> :: get(enz,"parent");
326  string enzPar = Field <string> :: get(enzparentId,"name");
327  string enzName = Field<string> :: get(enz,"name");
328 
329  vector < Id > srct = LookupField <string,vector < Id> >::get(enz, "neighbors","sub");
330  for (vector <Id> :: iterator rsub = srct.begin(); rsub != srct.end(); rsub++)
331  {
332  string s = "addmsg /kinetics" + trimPath(*rsub, comptid) + " /kinetics" + trimPath(enz, comptid) + " SUBSTRATE n";
333  msgs.push_back( s );
334  s = "addmsg /kinetics" + trimPath(enz, comptid) + " /kinetics" + trimPath( *rsub, comptid ) + " REAC sA B";
335  msgs.push_back( s );
336  }
337  vector < Id > prct = LookupField <string,vector < Id> >::get(enz, "neighbors","prd");
338  for (vector <Id> :: iterator rprd = prct.begin(); rprd != prct.end(); rprd++)
339  {
340  string s = "addmsg /kinetics" + trimPath( enz, comptid ) + " /kinetics" + trimPath(*rprd, comptid) + " MM_PRD pA";
341  msgs.push_back( s );
342  }
343  vector < Id > enzC = LookupField <string,vector < Id> >::get(enz, "neighbors","enzDest");
344  for (vector <Id> :: iterator enzCl = enzC.begin(); enzCl != enzC.end(); enzCl++)
345  {
346  string s = "addmsg /kinetics" + trimPath( *enzCl, comptid ) + " /kinetics" + trimPath(enz, comptid) + " ENZYME n";
347  msgs.push_back( s );
348  }
349 }
Definition: SetGet.h:236
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void storePlotMsgs ( Id  tab,
vector< string > &  msgs,
Id  pool,
string  bg,
Id  comptid 
)

Definition at line 435 of file WriteKkit.cpp.

References Id::path(), and trimPath().

Referenced by writeKkit().

436 {
437  string tabPath = tab.path();
438  string poolPath = Field <string> :: get(pool,"path");
439  string poolName = Field <string> :: get(pool,"name");
440 
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;
448  msgs.push_back( s );
449 }
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
Definition: SetGet.h:236
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void storeReacMsgs ( Id  reac,
vector< string > &  msgs,
Id  comptid 
)

Definition at line 390 of file WriteKkit.cpp.

References trimPath().

Referenced by writeKkit().

391 {
392  vector < Id > srct = LookupField <string,vector < Id> >::get(reac, "neighbors","sub");
393  for (vector <Id> :: iterator rsub = srct.begin(); rsub != srct.end(); rsub++)
394  {
395  string s = "addmsg /kinetics" + trimPath(*rsub, comptid) + " /kinetics" + trimPath(reac, comptid) + " SUBSTRATE n";
396  msgs.push_back( s );
397  s = "addmsg /kinetics" + trimPath(reac, comptid) + " /kinetics" + trimPath( *rsub, comptid ) + " REAC A B";
398  msgs.push_back( s );
399  }
400  vector < Id > prct = LookupField <string,vector < Id> >::get(reac, "neighbors","prd");
401  for (vector <Id> :: iterator rprd = prct.begin(); rprd != prct.end(); rprd++)
402  {
403  string rpath = Field <string> :: get(reac,"path");
404  string cpath = Field <string> :: get(comptid,"path");
405  string prdPath = Field <string> :: get(*rprd,"path");
406  string s = "addmsg /kinetics" + trimPath( *rprd, comptid ) + " /kinetics" + trimPath(reac, comptid) + " PRODUCT n";
407  msgs.push_back( s );
408  s = "addmsg /kinetics" + trimPath(reac, comptid) + " /kinetics" + trimPath( *rprd,comptid ) + " REAC B A";
409  msgs.push_back( s );
410  }
411 }
Definition: SetGet.h:236
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

string trimPath ( Id  id,
Id  comptid 
)

Definition at line 79 of file WriteKkit.cpp.

References Field< A >::get().

Referenced by storeCplxEnzMsgs(), storeFunctionMsgs(), storeMMenzMsgs(), storePlotMsgs(), storeReacMsgs(), writeEnz(), writePool(), and writeReac().

80 {
81  string msgpath = Field <string> :: get(id,"path");
82  ObjId compartment(msgpath);
83  string path1;
84  cout << " trimpath " << msgpath <<endl;
85  // triming the string compartment Level
86  while( Field<string>::get(compartment,"className") != "CubeMesh"
87  && Field<string>::get(compartment,"className") != "CylMesh"
88  )
89  compartment = Field<ObjId> :: get(compartment, "parent");
90  string cmpt = Field < string > :: get(compartment,"name");
91  if (cmpt != "kinetics")
92  {
93  std::size_t found = msgpath.find(cmpt);
94  if (found !=std::string::npos)
95  path1 = msgpath.substr(found-1,msgpath.length());
96  else
97  {
98  path1 = msgpath;
99  }
100  }
101  else
102  {
103  std :: size_t found = msgpath.find(cmpt);
104  if (found !=std::string::npos)
105  {
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());
110  else
111  {
112  path1 = msgpath;
113  }
114  }
115  }
116  cout << " path " << path1 << endl;
117  return path1;
118 }
Definition: SetGet.h:236
Definition: ObjId.h:20
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:

void writeEnz ( ofstream &  fout,
Id  id,
string  colour,
string  textcolour,
double  x,
double  y,
Id  comptid 
)

Definition at line 131 of file WriteKkit.cpp.

References Field< A >::get(), getEnzCplx(), getEnzMol(), NA, path, and trimPath().

Referenced by writeKkit().

134 {
135  string path = id.path();
136  string comptname = Field < string > :: get(comptid,"name");
137  string poolpath = trimPath(id,comptid);
138 
139 
140  double k1 = 0;
141  double k2 = 0;
142  double k3 = 0;
143  double nInit = 0;
144  double concInit = 0;
145  double n = 0;
146  double conc = 0;
147  Id enzMol = getEnzMol( id );
148  assert( enzMol != Id() );
149  double vol = Field< double >::get( enzMol, "volume" ) * NA * 1e-3;
150  unsigned int isMichaelisMenten = 0;
151  string enzClass = Field < string > :: get(id,"className");
152  if (enzClass == "ZombieMMenz" or enzClass == "MMenz")
153  {
154  k1 = Field < double > :: get (id,"numKm");
155  k3 = Field < double > :: get (id,"kcat");
156  k2 = 4.0*k3;
157  k1 = (k2 + k3) / k1;
158  isMichaelisMenten = 1;
159  }
160  else if (enzClass == "ZombieEnz" or enzClass == "Enz")
161  {
162  k1 = Field< double >::get( id, "k1" );
163  k2 = Field< double >::get( id, "k2" );
164  k3 = Field< double >::get( id, "k3" );
165  Id cplx = getEnzCplx( id );
166  assert( cplx != Id() );
167  nInit = Field< double >::get( cplx, "nInit" );
168  n = Field< double >::get( cplx, "n" );
169  concInit = Field< double >::get( cplx, "concInit" );
170  conc = Field< double >::get( cplx, "conc" );
171  }
172  fout << "simundump kenz /kinetics" << poolpath << " 0 " <<
173  concInit << " " <<
174  conc << " " <<
175  nInit << " " <<
176  n << " " <<
177  vol << " " <<
178  k1 << " " <<
179  k2 << " " <<
180  k3 << " " <<
181  0 << " " <<
182  isMichaelisMenten << " " <<
183  "\"\"" << " " <<
184  colour << " " << textcolour << " \"\"" <<
185  " " << x << " " << y << " 0\n";
186 }
Id getEnzCplx(Id id)
Definition: WriteKkit.cpp:120
const double NA
Definition: consts.cpp:15
Definition: SetGet.h:236
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
Id getEnzMol(Id id)
Definition: WriteKkit.cpp:126
static char path[]
Definition: mfield.cpp:403
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void writeFooter ( ofstream &  fout)

Definition at line 317 of file WriteKkit.cpp.

Referenced by writeKkit().

318 {
319  fout << "\nenddump\n";
320  fout << "complete_loading\n";
321 }

+ Here is the caller graph for this function:

void writeGroup ( ofstream &  fout,
Id  model 
)

Definition at line 506 of file WriteKkit.cpp.

References Field< A >::get(), group(), Id::path(), path, and wildcardFind().

Referenced by writeKkit().

507 {
508  vector < ObjId> group;
509  int x = 10;
510  int y = 20;
511  int num = wildcardFind( model.path() + "/##[TYPE=Neutral]", group );
512  for ( vector< ObjId >::iterator itr = group.begin(); itr != group.end(); itr++)
513  {
514  string path = Field<string>::get(*itr,"path");
515  size_t pos = path.find( "/kinetics" );
516  if (pos != std::string::npos)
517  {
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";
522  }
523  }
524 }
int wildcardFind(const string &path, vector< ObjId > &ret)
Definition: Wildcard.cpp:169
static SrcFinfo0 * group()
Definition: Group.cpp:17
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static char path[]
Definition: mfield.cpp:403

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void writeGui ( ofstream &  fout)

Definition at line 305 of file WriteKkit.cpp.

Referenced by writeKkit().

306 {
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";
315 }

+ Here is the caller graph for this function:

void writeHeader ( ofstream &  fout,
double  simdt,
double  plotdt,
double  maxtime,
double  defaultVol 
)

Definition at line 28 of file WriteKkit.cpp.

Referenced by writeKkit().

30 {
31  time_t rawtime;
32  time( &rawtime );
33 
34  fout <<
35  "//genesis\n"
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"
49  "kparms\n\n";
50 
51  fout <<
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";
76  //"simundump geometry /kinetics/geometry 0 1.6667e-19 3 sphere \"\" white black 0 0 0\n\n";
77 }

+ Here is the caller graph for this function:

void writeKkit ( Id  model,
const string &  fname 
)

Definition at line 525 of file WriteKkit.cpp.

References estimateDefaultVol(), estimateSimTimes(), Field< A >::get(), Id::path(), path, storeEnzMsgs(), storeFunctionMsgs(), storePlotMsgs(), storeReacMsgs(), wildcardFind(), writeEnz(), writeFooter(), writeGroup(), writeGui(), writeHeader(), writeMsgs(), writePlot(), writePool(), and writeReac().

Referenced by Shell::doSaveModel(), and testWriteKkit().

526 {
527  ofstream fout( fname.c_str(), ios::out );
528  vector< ObjId > chemCompt;
529  vector< string > msgs;
530  double simDt;
531  double plotDt;
532 
533  double runTime = estimateSimTimes( simDt, plotDt );
534  double defaultVol = estimateDefaultVol( model );
535  writeHeader( fout, simDt, plotDt, runTime, defaultVol );
536  string bg = "cyan";
537  string fg = "black";
538  double x = 0;
539  double y = 0;
540 
541  map < double, pair<Id, int> > compt_vol;
542 
543  unsigned int num = wildcardFind( model.path() + "/##[ISA=ChemCompt]", chemCompt );
544  if ( num == 0 )
545  {
546  cout << "Warning: writeKkit:: No model found on " << model <<
547  endl;
548  return;
549  }
550  for ( vector< ObjId >::iterator itr = chemCompt.begin(); itr != chemCompt.end(); itr++)
551  {
552  vector < unsigned int>dims;
553  unsigned int dims_size;
554  dims_size = 1;
555  unsigned index = 0;
556  string comptPath = Field<string>::get(*itr,"path");
557  string comptname = Field<string>::get(*itr,"name");
558  if (comptname != "kinetics")
559  {
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";
563  }
564  double size = Field<double>::get(ObjId(*itr,index),"Volume");
565  unsigned int ndim = Field<unsigned int>::get(ObjId(*itr,index),"NumDimensions");
566  ostringstream geometry;
567  int vecIndex = itr-chemCompt.begin();
568  if (vecIndex > 0)
569  geometry << "simundump geometry /kinetics" << "/geometry[" << vecIndex <<"] 0 " << size << " " << ndim << " sphere " <<" \"\" white black 0 0 0\n";
570  else
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)));
574  } // compartmentclose
575  writeGroup(fout, model);
576  map<double, pair<Id, int> >::iterator compt;
577  for (compt = compt_vol.begin(); compt != compt_vol.end(); compt++)
578  {
579  string comptPath = Field<string>::get(compt->second.first,"path");
580  // Species
581  vector< ObjId > Compt_spe;
582  wildcardFind(comptPath+"/##[ISA=PoolBase]",Compt_spe);
583  int species_size = 1;
584  string objname;
585  for (vector <ObjId> :: iterator itrp = Compt_spe.begin(); itrp != Compt_spe.end(); itrp++)
586  {
587  string path = Field <string> :: get (*itrp,"path");
588  Id enzPoolparent = Field <ObjId> :: get(*itrp,"parent");
589  string enzpoolClass = Field <string> :: get(enzPoolparent,"className");
590  if (enzpoolClass != "ZombieEnz" or enzpoolClass != "Enz")
591  {
592  Id annotaId( path+"/info");
593  if ( annotaId != Id() )
594  {
595  double x = Field <double> :: get(annotaId,"x");
596  double y = Field <double> :: get(annotaId,"y");
597  string fg = Field <string> :: get(annotaId,"textColor");
598  string bg = Field <string> :: get(annotaId,"color");
599  writePool(fout, *itrp,bg,fg,x,y,compt->second.first,compt->second.second);
600  }
601  }
602  } //species is closed
603  vector< ObjId > Compt_Func;
604  wildcardFind(comptPath+"/##[ISA=Function]",Compt_Func);
605  for (vector <ObjId> :: iterator itrF= Compt_Func.begin(); itrF != Compt_Func.end(); itrF++)
606  {
607  storeFunctionMsgs( *itrF, msgs,compt_vol);
608  }
609  // Reaction
610  vector< ObjId > Compt_Reac;
611  wildcardFind(comptPath+"/##[ISA=ReacBase]",Compt_Reac);
612  for (vector <ObjId> :: iterator itrR= Compt_Reac.begin(); itrR != Compt_Reac.end(); itrR++)
613  {
614  string path = Field<string> :: get(*itrR,"path");
615  Id annotaId( path+"/info");
616  string noteClass = Field<string> :: get(annotaId,"className");
617  string notes;
618  double x = Field <double> :: get(annotaId,"x");
619  double y = Field <double> :: get(annotaId,"y");
620  string fg = Field <string> :: get(annotaId,"textColor");
621  string bg = Field <string> :: get(annotaId,"color");
622  writeReac( fout, *itrR, bg, fg, x, y, compt->second.first);
623  storeReacMsgs( *itrR, msgs, compt->second.first );
624  }// reaction
625  vector< ObjId > Compt_Enz;
626  wildcardFind(comptPath+"/##[ISA=EnzBase]",Compt_Enz);
627  for (vector <ObjId> :: iterator itrE= Compt_Enz.begin(); itrE != Compt_Enz.end(); itrE++)
628  {
629  string path = Field<string> :: get(*itrE,"path");
630  Id annotaId( path+"/info");
631  string noteClass = Field<string> :: get(annotaId,"className");
632  string notes;
633  double x = Field <double> :: get(annotaId,"x");
634  double y = Field <double> :: get(annotaId,"y");
635  string fg = Field <string> :: get(annotaId,"textColor");
636  string bg = Field <string> :: get(annotaId,"color");
637  writeEnz( fout, *itrE, bg, fg, x, y, compt->second.first);
638  storeEnzMsgs( *itrE, msgs, compt->second.first);
639  }// reaction
640 
641  } //compatment loop
642  writeGui ( fout);
643 
644  /* Table */
645 
646  vector< ObjId > table;
647  wildcardFind(model.path()+"/##[ISA=Table2]",table);
648  for (vector <ObjId> :: iterator itrT= table.begin(); itrT != table.end(); itrT++)
649  {
650  string tabPath = Field <string> :: get(*itrT,"path");
651  vector < Id > tabSrc = LookupField <string,vector < Id> >::get(*itrT, "neighbors","requestOut");
652  for (vector <Id> :: iterator tabItem= tabSrc.begin(); tabItem != tabSrc.end(); tabItem++)
653  {
654  string path = Field <string> :: get(*tabItem,"path");
655  double vol = Field < double> :: get (*tabItem,"Volume");
656  //Trying to find the compartment name via volume
657  //otherwise if we go via parent, sometimes it might
658  // get groupname so maped compartment Id and volume
659 
660  Id parentId = compt_vol[vol].first;
661  string parentname = Field <string> :: get(parentId,"name");
662  Id annotaId(path+"/info");
663  double x = Field <double> :: get(annotaId,"x");
664  double y = Field <double> :: get(annotaId,"y");
665  string bg = Field <string> :: get(annotaId,"textColor");
666  string fg = Field <string> :: get(annotaId,"color");
667  writePlot( fout, *itrT, bg, fg, x, y );
668  storePlotMsgs( *itrT, msgs,*tabItem,fg, parentId);
669 
670  }
671  }// table
672  writeMsgs( fout, msgs );
673  writeFooter( fout );
674 }
int wildcardFind(const string &path, vector< ObjId > &ret)
Definition: Wildcard.cpp:169
void writeMsgs(ofstream &fout, const vector< string > &msgs)
Definition: WriteKkit.cpp:500
double estimateSimTimes(double &simDt, double &plotDt)
Definition: WriteKkit.cpp:455
double estimateDefaultVol(Id model)
Returns an estimate of the default volume used in the model.
Definition: WriteKkit.cpp:477
void writeReac(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
Definition: WriteKkit.cpp:188
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
Definition: SetGet.h:236
void writeGroup(ofstream &fout, Id model)
Definition: WriteKkit.cpp:506
Definition: ObjId.h:20
void writeFooter(ofstream &fout)
Definition: WriteKkit.cpp:317
void storeEnzMsgs(Id enz, vector< string > &msgs, Id comptid)
Definition: WriteKkit.cpp:381
void storeReacMsgs(Id reac, vector< string > &msgs, Id comptid)
Definition: WriteKkit.cpp:390
void writePool(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid, int comptIndex)
Definition: WriteKkit.cpp:238
void storePlotMsgs(Id tab, vector< string > &msgs, Id pool, string bg, Id comptid)
Definition: WriteKkit.cpp:435
void writePlot(ofstream &fout, Id id, string colour, string textcolour, double x, double y)
Definition: WriteKkit.cpp:288
void writeEnz(ofstream &fout, Id id, string colour, string textcolour, double x, double y, Id comptid)
Definition: WriteKkit.cpp:131
void storeFunctionMsgs(Id func, vector< string > &msgs, map< double, pair< Id, int > > &compt_vol)
Definition: WriteKkit.cpp:413
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
static char path[]
Definition: mfield.cpp:403
void writeGui(ofstream &fout)
Definition: WriteKkit.cpp:305
void writeHeader(ofstream &fout, double simdt, double plotdt, double maxtime, double defaultVol)
Definition: WriteKkit.cpp:28

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void writeMsgs ( ofstream &  fout,
const vector< string > &  msgs 
)

Definition at line 500 of file WriteKkit.cpp.

Referenced by writeKkit().

501 {
502  for ( vector< string >::const_iterator i = msgs.begin();
503  i != msgs.end(); ++i )
504  fout << *i << endl;
505 }

+ Here is the caller graph for this function:

void writePlot ( ofstream &  fout,
Id  id,
string  colour,
string  textcolour,
double  x,
double  y 
)

Definition at line 288 of file WriteKkit.cpp.

References path.

Referenced by writeKkit().

291 {
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 ) {
297  return;
298  }
299  }
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";
303 }
static char path[]
Definition: mfield.cpp:403

+ Here is the caller graph for this function:

void writePool ( ofstream &  fout,
Id  id,
string  colour,
string  textcolour,
double  x,
double  y,
Id  comptid,
int  comptIndex 
)

Definition at line 238 of file WriteKkit.cpp.

References Field< A >::get(), NA, and trimPath().

Referenced by writeKkit().

241 {
242  string poolPar = Field <string> :: get(comptid,"name");
243  string pooltype = Field < string > :: get(id,"className");
244  double diffConst = Field< double >::get( id, "diffConst" );
245  double concInit = Field< double >::get( id, "concInit" );
246  //double conc = Field< double >::get( id, "conc" );
247  double nInit = Field< double >::get( id, "nInit" );
248  //double n = Field< double >::get( id, "n" );
249  double volume = Field< double >::get( id, "volume" );
250  string geometry;
251  stringstream geometryTemp ;
252  unsigned int slave_enable = 0;
253  if (pooltype == "BufPool" or pooltype == "ZombieBufPool")
254  {
255  vector< Id > children = Field< vector< Id > >::get( id, "children" );
256  if (children.size() == 0)
257  slave_enable = 4;
258  for ( vector< Id >::iterator i = children.begin(); i != children.end(); ++i )
259  {
260  string funcpath = Field <string> :: get(*i,"path");
261  string clsname = Field <string> :: get(*i,"className");
262  if (clsname == "Function" or clsname == "ZombieFunction")
263  slave_enable = 0;
264  else
265  slave_enable = 4;
266 
267  }
268  }
269  if (comptIndex > 0)
270  geometryTemp << "/geometry[" << comptIndex <<"]";
271  else
272  geometryTemp << "/geometry";
273 
274  // simobjdump kpool DiffConst CoInit Co n nInit mwt nMin vol slave_enable
275 
276  fout << "simundump kpool /kinetics" << trimPath(id,comptid) << " 0 " <<
277  diffConst << " " <<
278  0 << " " <<
279  0 << " " <<
280  0 << " " <<
281  nInit << " " <<
282  0 << " " << 0 << " " << // mwt, nMin
283  volume * NA * 1e-3 << " " << // volscale
284  slave_enable << //GENESIS FIELD HERE.
285  " /kinetics"<< geometryTemp.str() << " " <<
286  colour << " " << textcolour << " " << x << " " << y << " 0\n";
287 }
const double NA
Definition: consts.cpp:15
Definition: SetGet.h:236
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void writeReac ( ofstream &  fout,
Id  id,
string  colour,
string  textcolour,
double  x,
double  y,
Id  comptid 
)

Definition at line 188 of file WriteKkit.cpp.

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

Referenced by writeKkit().

191 {
192  string reacPar = Field <string> :: get(comptid,"name");
193  string reacname = Field<string> :: get(id, "name");
194  double kf = Field< double >::get( id, "numKf" );
195  double kb = Field< double >::get( id, "numKb" );
196 
197  unsigned int numSub =
198  Field< unsigned int >::get( id, "numSubstrates" );
199  unsigned int numPrd =
200  Field< unsigned int >::get( id, "numProducts" );
201  fout << "simundump kreac /kinetics" << trimPath(id,comptid) << " 0 " <<
202  kf << " " << kb << " \"\" " <<
203  colour << " " << textcolour << " " << x << " " << y << " 0\n";
204 }
Definition: SetGet.h:236
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
string trimPath(Id id, Id comptid)
Definition: WriteKkit.cpp:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function: