1 /* Steven Andrews, started 10/22/2001.
2  This is the header for data structures for the Smoldyn program.
3  See documentation called SmoldynManual.pdf and SmoldynCodeDoc.pdf, and the Smoldyn
4  website, which is at www.smoldyn.org.
5  Copyright 2003-2016 by Steven Andrews.  This work is distributed under the terms
6  of the Gnu Lesser General Public License (LGPL). */
7 
8 #ifndef __smoldyn_h__
9 #define __smoldyn_h__
10 
11 #ifdef __cplusplus
12 
13 #ifdef ENABLE_PYTHON_CALLBACK
14 #define MAX_PY_CALLBACK 10
15 #include "../python/CallbackFunc.h"
16 #endif
17 
18 #endif // -----  not __CPLUSPLUS  -----
19 
20 //
21 // A macro to mark a variable unused. Supresses compiler warnings.
22 //
23 #define UNUSED(x)  (void)(x)
24 
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <time.h>
29 
30 #include "smoldynconfigure.h" // generated by CMake from smoldynconfigure.h.in
31 
32 #ifdef WINDOWS_BUILD
33 #define LLUFORMAT "%I64u" // MinGW doesn't use standard printf formatting
34 #else
35 #define LLUFORMAT "%llu"
36 #endif
37 
38 #ifdef OPTION_VTK
39 #include "../source/NextSubVolume/vtkwrapper.h"
40 #endif
41 
42 #ifdef __cplusplus
43 
44 #ifdef OPTION_VCELL
45 #include <string>
46 typedef struct VolumeSamples* VolumeSamplesPtr;
47 class AbstractMesh;
48 class ValueProvider;
49 class ValueProviderFactory;
50 using std::string;
51 #endif
52 
53 #endif // -----  not __cplusplus  -----
54 
55 /****************************************************************************/
56 /********************************** General *********************************/
57 /****************************************************************************/
58 
59 #define DIMMAX 3          // maximum system dimensionality
60 #define VERYCLOSE 1.0e-12 // distance that's safe from round-off error
61 #define VERYLARGE 1.0e+20 // distance that's large but safe from overflow error
62 
63 enum StructCond
64 {
65     SCinit,
66     SClists,
67     SCparams,
68     SCok
69 };
70 
71 /****************************************************************************/
72 /*************** Data structures for included libraries *********************/
73 /****************************************************************************/
74 
75 /*** string2.h ***/
76 
77 #ifndef __string2_h
78 #define __string2_h
79 
80 #define STRCHAR 256
81 #define STRCHARLONG 4000
82 
83 #endif
84 
85 /*** queue.h ***/
86 
87 #ifndef __queue_h
88 #define __queue_h
89 
90 #include <limits.h>
91 #if !defined(LLONG_MAX) || defined(WIN32)
92 typedef long int Q_LONGLONG;
93 #define Q_LLONG_MAX LONG_MAX
94 #define Q_LLI "%li"
95 #else
96 typedef long long int Q_LONGLONG;
97 #define Q_LLONG_MAX LLONG_MAX
98 #define Q_LLI "%lli"
99 #endif
100 
101 enum Q_types
102 {
103     Qusort,
104     Qvoid,
105     Qint,
106     Qdouble,
107     Qlong
108 };
109 
110 typedef struct qstruct
111 {
112     enum Q_types type;
113     void** kv;
114     int* ki;
115     double* kd;
116     Q_LONGLONG* kl;
117     int (*keycmp)(void*, void*);
118     void** x;
119     int n;
120     int f;
121     int b;
122 } * queue;
123 
124 #endif
125 
126 /***  List.h ***/
127 
128 #ifndef __list_h
129 #define __list_h
130 
131 typedef struct liststructli
132 {
133     int max;
134     int n;
135     long int* xs;
136 } * listptrli;
137 
138 typedef struct liststructv
139 {
140     int max;
141     int n;
142     void** xs;
143 } * listptrv;
144 
145 #endif
146 
147 /*** SimCommand.h ***/
148 
149 #ifndef __SimCommand_h__
150 #define __SimCommand_h__
151 
152 enum CMDcode
153 {
154     CMDok,
155     CMDwarn,
156     CMDpause,
157     CMDstop,
158     CMDabort,
159     CMDnone,
160     CMDcontrol,
161     CMDobserve,
162     CMDmanipulate,
163     CMDctrlORobs,
164     CMDall
165 };
166 
167 typedef struct cmdstruct
168 {
169     struct cmdsuperstruct* cmds;       // owning command superstructure
170     double on;                         // first command run time
171     double off;                        // last command run time
172     double dt;                         // time interval between commands
173     double xt;                         // multiplicative time interval
174     Q_LONGLONG oni;                    // first command run iteration
175     Q_LONGLONG offi;                   // last command run iteration
176     Q_LONGLONG dti;                    // iterations between commands
177     Q_LONGLONG invoke;                 // number of times command has run
178     char* str;                         // command string
179     char* erstr;                       // storage space for error string
180     int i1, i2, i3;                    // integers for generic use
181     double f1, f2, f3;                 // doubles for generic use
182     void *v1, *v2, *v3;                // pointers for generic use
183     void (*freefn)(struct cmdstruct*); // free command memory
184 } * cmdptr;
185 
186 typedef struct cmdsuperstruct
187 {
188     queue cmd;                                   // queue of normal run-time commands
189     queue cmdi;                                  // queue of integer time commands
190     enum CMDcode (*cmdfn)(void*, cmdptr, char*); // function that runs commands
191     void* cmdfnarg;                              // function argument (e.g. sim)
192     int iter;            // number of times integer commands have run
193     int maxfile;         // number of files allocated
194     int nfile;           // number of output files
195     char root[STRCHAR];  // file path
196     char froot[STRCHAR]; // more file path, used after root
197     char** fname;        // file name [fid]
198     int* fsuffix;        // file suffix [fid]
199     int* fappend;        // 0 for overwrite, 1 for append [fid]
200     FILE** fptr;         // file pointers [fid]
201     double flag;         // global command structure flag
202     int precision;       // precision for output commands
203     char outformat;      // output format, 's' or 'c'
204 } * cmdssptr;
205 
206 #endif
207 
208 /*** nsvc.h ***/
209 
210 #ifndef NSVC_H_
211 #define NSVC_H_
212 
213 #ifdef NSVC_CPP
214 #include "Kairos.h"
215 #include <string.h>
216 using Kairos::NextSubvolumeMethod;
217 
218 #if defined(HAVE_VTK)
219 #include <vtkUnstructuredGrid.h>
220 #else
221 typedef struct vtkUnstructuredGrid vtkUnstructuredGrid;
222 #endif
223 #else
224 typedef struct vtkUnstructuredGrid vtkUnstructuredGrid;
225 typedef struct NextSubvolumeMethod NextSubvolumeMethod;
226 #endif
227 
228 #endif
229 
230 /********************************* Molecules ********************************/
231 
232 #define MSMAX 5
233 #define MSMAX1 6
234 enum MolecState
235 {
236     MSsoln,
237     MSfront,
238     MSback,
239     MSup,
240     MSdown,
241     MSbsoln,
242     MSall,
243     MSnone,
244     MSsome
245 };
246 enum MolListType
247 {
248     MLTsystem,
249     MLTport,
250     MLTnone
251 };
252 #define PDMAX 6
253 enum PatternData
254 {
255     PDalloc,
256     PDnresults,
257     PDnspecies,
258     PDmatch,
259     PDsubst,
260     PDrule
261 };
262 
263 typedef struct moleculestruct
264 {
265     unsigned long long serno; // serial number
266     int list;                 // destination list number (ll)
267     double* pos;              // dim dimensional vector for position [d]
268     double* posx;             // dim dimensional vector for old position [d]
269     double* via;              // location of last surface interaction [d]
270     double* posoffset;        // position offset arising from jumps [d]
271     int ident;                // species of molecule; 0 is empty (i)
272     enum MolecState mstate;   // physical state of molecule (ms)
273     struct boxstruct* box;    // pointer to box which molecule is in
274     struct panelstruct* pnl;  // panel that molecule is bound to if any
275     struct panelstruct* pnlx; // old panel that molecule was bound to if any
276 } * moleculeptr;
277 
278 typedef struct molsuperstruct
279 {
280     enum StructCond condition;  // structure condition
281     struct simstruct* sim;      // simulation structure
282     int maxspecies;             // maximum number of species
283     int nspecies;               // number of species, including empty mols.
284     char** spname;              // names of molecular species [i]
285     int maxpattern;             // maximum number of patterns
286     int npattern;               // actual number of patterns
287     char** patlist;             // list of patterns [pat]
288     int** patindex;             // species indices for patterns [pat][j]
289     char** patrname;            // pattern reaction name if any [pat]
290     double** difc;              // diffusion constants [i][ms]
291     double** difstep;           // rms diffusion step [i][ms]
292     double*** difm;             // diffusion matrix [i][ms][d]
293     double*** drift;            // drift vector [i][ms][d]
294     double***** surfdrift;      // surface drift [i][ms][s][ps][d]
295     double** display;           // display size of molecule [i][ms]
296     double*** color;            // RGB color vector [i][ms]
297     int** exist;                // flag for if molecule could exist [i][ms]
298     moleculeptr* dead;          // list of dead molecules [m]
299     int maxdlimit;              // maximum allowed size of dead list
300     int maxd;                   // size of dead molecule list
301     int nd;                     // total number of molecules in dead list
302     int topd;                   // index for dead list; above are resurrected
303     int maxlist;                // allocated number of live lists
304     int nlist;                  // number of live lists
305     int** listlookup;           // lookup table for live lists [i][ms]
306     char** listname;            // names of molecule lists [ll]
307     enum MolListType* listtype; // types of molecule lists [ll]
308     moleculeptr** live;         // live molecule lists [ll][m]
309     int* maxl;                  // size of molecule lists [ll]
310     int* nl;                    // number of molecules in live lists [ll]
311     int* topl;                  // live list index; above are reborn [ll]
312     int* sortl;                 // live list index; above need sorting [ll]
313     int* diffuselist;           // 1 if any listed molecs diffuse [ll]
314     unsigned long serno;        // serial number for next resurrected molec.
315     int ngausstbl;              // number of elements in gausstbl
316     double* gausstbl;           // random numbers for diffusion
317     int* expand;                // expansion with rule-based modeling [i]
318     long int touch;             // counter for molecule modification
319 } * molssptr;
320 
321 /*********************************** Walls **********************************/
322 
323 typedef struct wallstruct
324 {
325     int wdim;               // dimension number of perpendicular to wall
326     int side;               // low side of space (0) or high side (1)
327     double pos;             // position of wall along dim axis
328     char type;              // properties of wall
329     struct wallstruct* opp; // pointer to opposite wall
330 } * wallptr;
331 
332 /********************************* Reactions ********************************/
333 
334 #define MAXORDER 3
335 
336 // NOTE:
337 // Increasing MAXPRODUCT value to 256
338 // see https://github.com/ssandrews/Smoldyn/issues/18 for details.
339 #define MAXPRODUCT 256
340 
341 enum RevParam
342 {
343     RPnone,
344     RPirrev,
345     RPconfspread,
346     RPbounce,
347     RPpgem,
348     RPpgemmax,
349     RPpgemmaxw,
350     RPratio,
351     RPunbindrad,
352     RPpgem2,
353     RPpgemmax2,
354     RPratio2,
355     RPoffset,
356     RPfixed
357 };
358 enum SpeciesRepresentation
359 {
360     SRparticle,
361     SRlattice,
362     SRboth,
363     SRnone,
364     SRfree
365 };
366 
367 #ifdef OPTION_VCELL
368 class ValueProvider;
369 typedef ValueProvider* valueproviderptr;
370 #endif
371 
372 typedef struct rxnstruct
373 {
374     struct rxnsuperstruct* rxnss;       // pointer to superstructure
375     char* rname;                        // pointer to name of reaction
376     int* rctident;                      // list of reactant identities [rct]
377     enum MolecState* rctstate;          // list of reactant states [rct]
378     int* permit;                        // permissions for reactant states [ms]
379     int nprod;                          // number of products
380     int* prdident;                      // list of product identities [prd]
381     enum MolecState* prdstate;          // list of product states [prd]
382     enum SpeciesRepresentation* rctrep; // reactant particle/lattice [rct]
383     enum SpeciesRepresentation* prdrep; // product particle/lattice [prd]
384     long int* prdserno;                 // list of product serno rules [prd]
385     int* prdintersurf;                  // list of product intersurface rules [prd]
386     listptrli logserno;                 // list of serial nums for logging reaction
387     char* logfile;                      // filename for logging reaction
388 #ifdef OPTION_VCELL
389     valueproviderptr rateValueProvider; // requested reaction rate
390 #endif
391     double rate;                // requested reaction rate
392     int multiplicity;           // rate multiplier
393     double bindrad2;            // squared binding radius, if appropriate
394     double prob;                // reaction probability
395     double chi;                 // diffusion-limited fraction
396     double tau;                 // characteristic reaction time
397     enum RevParam rparamt;      // type of parameter in rpar
398     double rparam;              // parameter for reaction of products
399     double unbindrad;           // unbinding radius, if appropriate
400     double** prdpos;            // product position vectors [prd][d]
401     int disable;                // 1 if reaction is disabled
402     struct compartstruct* cmpt; // compartment reaction occurs in, or NULL
403     struct surfacestruct* srf;  // surface reaction on, or NULL
404 } * rxnptr;
405 
406 typedef struct rxnsuperstruct
407 {
408     enum StructCond condition; // structure condition
409     struct simstruct* sim;     // simulation structure
410     int order;                 // order of reactions listed: 0, 1, or 2
411     int maxspecies;            // maximum number of species
412     int maxlist;               // copy of maximum number of molecule lists
413     int* nrxn;                 // number of rxns for each reactant set [i]
414     int** table;               // lookup table for reaction numbers [i][j]
415     int maxrxn;                // allocated number of reactions
416     int totrxn;                // total number of reactions listed
417     char** rname;              // names of reactions [r]
418     rxnptr* rxn;               // list of reactions [r]
419     int* rxnmollist;           // live lists that have reactions [ll]
420 } * rxnssptr;
421 
422 /********************************** Rules ***********************************/
423 
424 enum RuleType
425 {
426     RTreaction,
427     RTdifc,
428     RTdifm,
429     RTdrift,
430     RTsurfdrift,
431     RTmollist,
432     RTdispsize,
433     RTcolor,
434     RTsurfaction,
435     RTsurfrate,
436     RTsurfrateint,
437     RTnone
438 };
439 
440 typedef struct rulestruct
441 {
442     struct rulesuperstruct* ruless; // pointer to superstructure
443     enum RuleType ruletype;         // type of rule
444     char* rulename;                 // pointer to name of rule
445     char* rulepattern;              // pattern for the rule
446     int rulenresults;               // number of results in index used by rule
447     int* ruledetailsi;              // list of species states and restrictions
448     double* ruledetailsf;           // floating point details
449     double rulerate;                // rate constant
450     rxnptr rulerxn;                 // template reaction for reaction rules
451 } * ruleptr;
452 
453 typedef struct rulesuperstruct
454 {
455     struct simstruct* sim; // simulation structure
456     int maxrule;           // allocated size of rule list
457     int nrule;             // actual size of rule list
458     char** rulename;       // list of rule names
459     ruleptr* rule;         // list of rules
460     int ruleonthefly;      // for expanding rules on the fly
461 } * rulessptr;
462 
463 /********************************* Surfaces *********************************/
464 
465 #define PSMAX 6 // maximum number of panel shapes
466 
467 enum PanelFace
468 {
469     PFfront,
470     PFback,
471     PFnone,
472     PFboth
473 };
474 enum PanelShape
475 {
476     PSrect,
477     PStri,
478     PSsph,
479     PScyl,
480     PShemi,
481     PSdisk,
482     PSall,
483     PSnone
484 };
485 
486 enum SrfAction
487 {
488     SAreflect,
489     SAtrans,
490     SAabsorb,
491     SAjump,
492     SAport,
493     SAmult,
494     SAno,
495     SAnone,
496     SAadsorb,
497     SArevdes,
498     SAirrevdes,
499     SAflip
500 };
501 enum DrawMode
502 {
503     DMno = 0,
504     DMvert = 1,
505     DMedge = 2,
506     DMve = 3,
507     DMface = 4,
508     DMvf = 5,
509     DMef = 6,
510     DMvef = 7,
511     DMnone
512 };
513 enum SMLflag
514 {
515     SMLno = 0,
516     SMLdiffuse = 1,
517     SMLreact = 2,
518     SMLsrfbound = 4
519 };
520 
521 typedef struct surfactionstruct
522 {
523     int* srfnewspec; // surface convert mol. species [ms]
524     double* srfrate; // surface action rate [ms]
525 #ifdef OPTION_VCELL
526     valueproviderptr* srfRateValueProvider; // rate for surface actions: asorption,
527                                             // desorption, transmission...etc.
528 #endif
529     double* srfprob;    // surface action probability [ms]
530     double* srfcumprob; // surface cumulative probability [ms]
531     int* srfdatasrc;    // surface data source [ms]
532     double* srfrevprob; // probability of reverse action [ms]
533 } * surfactionptr;
534 
535 typedef struct panelstruct
536 {
537     char* pname;                  // panel name (reference, not owned)
538     enum PanelShape ps;           // panel shape
539     struct surfacestruct* srf;    // surface that owns this panel
540     int npts;                     // number of defining points
541     double** point;               // defining points, [number][d]
542     double** oldpoint;            // prior defining points, [number][d]
543     double front[DIMMAX];         // front parameters, which depend on the shape
544     double oldfront[DIMMAX];      // prior front parameters [d]
545     struct panelstruct* jumpp[2]; // panel to jump to, if appropriate [face]
546     enum PanelFace jumpf[2];      // face to jump to, if appropriate [face]
547     int maxneigh;                 // maximum number of neighbor panels
548     int nneigh;                   // number of neighbor panels
549     struct panelstruct** neigh;   // list of neighbor panels [p]
550     double* emitterabsorb[2];     // absorption for emitters [face][i]
551 } * panelptr;
552 
553 typedef struct surfacestruct
554 {
555     char* sname;                      // surface name (reference, not owned)
556     struct surfacesuperstruct* srfss; // owning surface superstructure
557     int selfindex;                    // index of self
558     enum SrfAction*** action;         // action for molecules [i][ms][face]
559     surfactionptr*** actdetails;      // action details [i][ms][face]
560     int neighhop;                     // whether molecules hop between neighbors
561     double fcolor[4];                 // RGBA color vector for front
562     double bcolor[4];                 // RGBA color vector for back
563     double edgepts;                   // thickness of edge for drawing
564     unsigned int edgestipple[2];      // edge stippling [factor,pattern]
565     enum DrawMode fdrawmode;          // polygon drawing mode for front
566     enum DrawMode bdrawmode;          // polygon drawing mode for back
567     double fshiny;                    // front shininess
568     double bshiny;                    // back shininess
569     int maxpanel[PSMAX];              // allocated number of panels [ps]
570     int npanel[PSMAX];                // actual number of panels [ps]
571     char** pname[PSMAX];              // names of panels [ps][p]
572     panelptr* panels[PSMAX];          // list of panels [ps][p]
573     struct portstruct* port[2];       // port, if any, for each face [face]
574     double totarea;                   // total surface area
575     int totpanel;                     // total number of panels
576     double* areatable;                // cumulative panel areas [pindex]
577     panelptr* paneltable;             // sequential list of panels [pindex]
578     int* maxemitter[2];               // maximum number of emitters [face][i]
579     int* nemitter[2];                 // number of emitters [face][i]
580     double** emitteramount[2];        // emitter amounts [face][i][emit]
581     double*** emitterpos[2];          // emitter positions [face][i][emit][d]
582     int maxmollist;                   // allocated number of molecule live lists
583     int nmollist;                     // number of molecule live lists
584     int* maxmol;                      // allocated size of live lists [ll]
585     int* nmol;                        // number of molecules in live lists [ll]
586     moleculeptr** mol;                // live molecules on the surface [ll][m]
587 } * surfaceptr;
588 
589 typedef struct surfacesuperstruct
590 {
591     enum StructCond condition; // structure condition
592     struct simstruct* sim;     // simulation structure
593     int maxspecies;            // maximum number of molecular species
594     int maxsrf;                // maximum number of surfaces
595     int nsrf;                  // number of surfaces
596     double epsilon;            // max deviation of surface-point from surface
597     double margin;             // panel margin away from edge
598     double neighdist;          // neighbor distance value
599     char** snames;             // surface names [s]
600     surfaceptr* srflist;       // list of surfaces [s]
601     int maxmollist;            // number of molecule lists allocated
602     int nmollist;              // number of molecule lists used
603     enum SMLflag* srfmollist;  // flags for molecule lists to check [ll]
604 } * surfacessptr;
605 
606 /*********************************** Boxes **********************************/
607 
608 typedef struct boxstruct
609 {
610     int* indx;                // dim dimensional index of the box [d]
611     int nneigh;               // number of neighbors in list
612     int midneigh;             // logical middle of neighbor list
613     struct boxstruct** neigh; // all box neighbors, using sim. accuracy
614     int* wpneigh;             // wrapping code of neighbors in list
615     int nwall;                // number of walls in box
616     wallptr* wlist;           // list of walls that cross the box
617     int maxpanel;             // allocated number of panels in box
618     int npanel;               // number of surface panels in box
619     panelptr* panel;          // list of panels in box
620     int* maxmol;              // allocated size of live lists [ll]
621     int* nmol;                // number of molecules in live lists [ll]
622     moleculeptr** mol;        // lists of live molecules in the box [ll][m]
623 } * boxptr;
624 
625 typedef struct boxsuperstruct
626 {
627     enum StructCond condition; // structure condition
628     struct simstruct* sim;     // simulation structure
629     int nlist;                 // copy of number of molecule lists
630     double mpbox;              // requested number of molecules per box
631     double boxsize;            // requested box width
632     double boxvol;             // actual box volumes
633     int nbox;                  // total number of boxes
634     int* side;                 // number of boxes on each side of space
635     double* min;               // position vector for low corner of space
636     double* size;              // length of each side of a box
637     boxptr* blist;             // actual array of boxes
638 } * boxssptr;
639 
640 /******************************* Compartments *******************************/
641 
642 enum CmptLogic
643 {
644     CLequal,
645     CLequalnot,
646     CLand,
647     CLor,
648     CLxor,
649     CLandnot,
650     CLornot,
651     CLnone
652 };
653 
654 typedef struct compartstruct
655 {
656     struct compartsuperstruct* cmptss; // compartment superstructure
657     char* cname;                       // compart. name (reference, not owned)
658     int selfindex;                     // index of self	//?? needs documenting
659     int nsrf;                          // number of bounding surfaces
660     surfaceptr* surflist;              // list of bounding surfaces [s]
661     int npts;                          // number of inside-defining points
662     double** points;                   // list of inside-defining points [k][d]
663     int ncmptl;                        // number of logic compartments
664     struct compartstruct** cmptl;      // list of logic compartments [cl]
665     enum CmptLogic* clsym;             // compartment logic symbol [cl]
666     double volume;                     // volume of compartment
667     int maxbox;                        // maximum number of boxes in compartment
668     int nbox;                          // number of boxes inside compartment
669     boxptr* boxlist;                   // list of boxes inside compartment [b]
670     double* boxfrac;                   // fraction of box volume that's inside [b]
671     double* cumboxvol;                 // cumulative cmpt. volume of boxes [b]
672 } * compartptr;
673 
674 typedef struct compartsuperstruct
675 {
676     enum StructCond condition; // structure condition
677     struct simstruct* sim;     // simulation structure
678     int maxcmpt;               // maximum number of compartments
679     int ncmpt;                 // actual number of compartments
680     char** cnames;             // compartment names [c]
681     compartptr* cmptlist;      // list of compartments [c]
682 } * compartssptr;
683 
684 /*********************************** Ports **********************************/
685 
686 typedef struct portstruct
687 {
688     struct portsuperstruct* portss; // port superstructure
689     char* portname;                 // port name (reference, not owned)
690     surfaceptr srf;                 // porting surface (ref.)
691     enum PanelFace face;            // active face of porting surface
692     int llport;                     // live list number for buffer
693 } * portptr;
694 
695 typedef struct portsuperstruct
696 {
697     enum StructCond condition; // structure condition
698     struct simstruct* sim;     // simulation structure
699     int maxport;               // maximum number of ports
700     int nport;                 // actual number of ports
701     char** portnames;          // port names
702     portptr* portlist;         // list of ports
703 } * portssptr;
704 
705 /*********************************** lattice **********************************/
706 
707 enum LatticeType
708 {
709     LATTICEnone,
710     LATTICEnsv,
711     LATTICEpde
712 };
713 
714 typedef struct latticestruct
715 {
716     struct latticesuperstruct* latticess; // lattice superstructure
717     char* latticename;                    // lattice name (reference, not owned)
718     enum LatticeType type;                // type of lattice
719     double min[DIMMAX];                   // lower spatial boundaries
720     double max[DIMMAX];                   // upper spatial boundaries
721     double dx[DIMMAX];                    // lattice lengthscale (subvolume width)
722     char btype[DIMMAX];                   // boundary type (r)eflective or (p)eriodic
723     portptr port;                         // interface port (ref.)
724     int** convert;           // convert to particle at port, 0 or 1 [lat.species][face] ??
725     int maxreactions;        // maximum number of reactions
726     int nreactions;          // number of reactions
727     rxnptr* reactionlist;    // list of reactions
728     int* reactionmove;       // 0 or 1 for moving reactions
729     int maxsurfaces;         // maximum number of surface
730     int nsurfaces;           // number of surface
731     surfaceptr* surfacelist; // list of surface
732     int maxspecies;          // maximum number of species
733     int nspecies;            // number of species
734     int* species_index;      // species indices
735     int* maxmols;            // allocated size of molecule list [lat.species]
736     int* nmols;              // number of individual molecules [lat.species]
737     double*** mol_positions; // molecule positions [lat.species][nmols][dim]
738 #ifdef OPTION_NSV
739     NextSubvolumeMethod* nsv; // nsv class
740     NextSubvolumeMethod* pde; // pde class
741 #else
742     void* nsv;
743     void* pde;
744 #endif
745 } * latticeptr;
746 
747 typedef struct latticesuperstruct
748 {
749     enum StructCond condition; // structure condition
750     struct simstruct* sim;     // simulation structure
751     int maxlattice;            // maximum number of lattices
752     int nlattice;              // actual number of lattices
753     char** latticenames;       // lattice names
754     latticeptr* latticelist;   // list of lattices
755 } * latticessptr;
756 
757 /********************************* Filaments ********************************/
758 
759 enum FilamentDynamics
760 {
761     FDnone,
762     FDrigidbeads,
763     FDrigidsegments,
764     FDrouse,
765     FDalberts,
766     FDnedelec
767 };
768 enum FilamentBiology
769 {
770     FBactin,
771     FBmicrotubule,
772     FBintermediate,
773     FBdsDNA,
774     FBssDNA,
775     FBother,
776     FBnone
777 };
778 
779 typedef struct beadstruct
780 {
781     double xyz[3];    // bead coordinates
782     double xyzold[3]; // bead coordinates for prior time
783 } * beadptr;
784 
785 typedef struct segmentstruct
786 {
787     double xyzfront[3]; // Coords. for segment front
788     double xyzback[3];  // Coords. for segment back
789     double len;         // segment length
790     double ypr[3];      // relative ypr angles
791     double dcm[9];      // relative dcm
792     double adcm[9];     // absolute segment orientation
793     double thk;         // thickness of segment
794 } * segmentptr;
795 
796 typedef struct filamentstruct
797 {
798     struct filamenttypestruct* filtype; // filament type structure
799     char* filname;                      // filament name (reference, not owned)
800     int maxbs;                          // number of beads or segments allocated
801     int nbs;                            // number of beads or segments
802     int frontbs;                        // index of front bead or segment
803     beadptr* beads;                     // array of beads if any
804     segmentptr* segments;               // array of segments if any
805     struct filamentstruct* frontend;    // what front attaches to if anything
806     struct filamentstruct* backend;     // what back attaches to if anything
807     int maxbranch;                      // max number of branches off this filament
808     int nbranch;                        // number of branches off this filament
809     int* branchspots;                   // list of bead or segments where branches are
810     struct filamentstruct** branches;   // list of branching filaments
811     int maxmonomer;                     // number of monomers allocated
812     int nmonomer;                       // number of monomers
813     int frontmonomer;                   // index of front monomer
814     char* monomers;                     // monomer codes
815 } * filamentptr;
816 
817 typedef struct filamenttypestruct
818 {
819     struct filamentsuperstruct* filss; // filament superstructure
820     char* ftname;                      // filament type name (reference, not owned)
821     enum FilamentDynamics dynamics;    // dynamics for the filament
822     int isbead;                        // 1 for bead model, 0 for segments
823     enum FilamentBiology biology;      // Biological name for filament type
824     double bundlevalue;                // number of microfilaments in bundle
825     double color[4];                   // filament color
826     double edgepts;                    // thickness of edge for drawing
827     unsigned int edgestipple[2];       // edge stippling [factor, pattern]
828     enum DrawMode drawmode;            // polygon drawing mode
829     double shiny;                      // shininess
830     double stdlen;                     // minimum energy segment length
831     double stdypr[3];                  // minimum energy bend angle
832     double klen;                       // force constant for length
833     double kypr[3];                    // force constant for angle
834     double kT;                         // thermodynamic temperature, [0,inf)
835     double treadrate;                  // treadmilling rate constant
836     double viscosity;                  // viscosity
837     double filradius;                  // bead or segment radius
838     int maxface;                       // number of filament faces allocated
839     int nface;                         // number of filament faces
840     char** facename;                   // list of face names
841     double facetwist;                  // twisting rate of faces along filament
842     int maxfil;                        // maximum number of filaments
843     int nfil;                          // actual number of filaments
844     filamentptr* fillist;              // list of filaments
845     char** filnames;                   // names of filaments
846 } * filamenttypeptr;
847 
848 typedef struct filamentsuperstruct
849 {
850     enum StructCond condition; // structure condition
851     struct simstruct* sim;     // simulation structure
852     int maxtype;               // maximum number of filament types
853     int ntype;                 // actual number of filament types
854     char** ftnames;            // filament type names
855     filamenttypeptr* filtypes; // list of filament types
856 } * filamentssptr;
857 
858 /* OLD FILAMENTS
859 typedef struct filamentstruct
860 {
861     struct filamentsuperstruct* filss; // filament superstructure
862     char* fname;                       // filament name
863     double color[4];                   // filament color
864     double edgepts;                    // thickness of edge for drawing
865     unsigned int edgestipple[2];       // edge stippling [factor, pattern]
866     enum DrawMode drawmode;            // polygon drawing mode
867     double shiny;                      // shininess
868     int maxseg;                        // number of segments allocated
869     int nseg;                          // number of segments
870     int front;                         // front index
871     int back;                          // back index
872     double** sxyz;                     // Coords. for segment ends [seg][3]
873     double* slen;                      // segment length [seg]
874     double** sypr;                     // relative ypr angles [seg][3]
875     double** sdcm;                     // relative dcm [seg][9]
876     double** sadcm;                    // absolute segment orientation [seg][9]
877     double* sthk;                      // thickness of segment [nmax], [0,inf)
878     double stdlen;                     // minimum energy segment length
879     double stdypr[3];                  // minimum energy bend angle
880     double klen;                       // force constant for length
881     double kypr[3];                    // force constant for angle
882     double kT;                         // thermodynamic temperature, [0,inf)
883     double treadrate;                  // treadmilling rate constant
884 } * filamentptr;
885 
886 typedef struct filamentsuperstruct
887 {
888     enum StructCond condition; // structure condition
889     struct simstruct* sim;     // simulation structure
890     int maxfil;                // maximum number of filaments
891     int nfil;                  // actual number of filaments
892     char** fnames;             // filament names
893     filamentptr* fillist;      // list of filaments
894 } * filamentssptr;
895 */
896 
897 /******************************** BioNetGen *********************************/
898 
899 typedef struct bngstruct
900 {
901     struct bngsuperstruct* bngss; // bng superstructure
902     char* bngname;                // bng name
903     int bngindex;                 // index of this bng structure
904     double unirate;               // multiplier for unimolecular rxn rates
905     double birate;                // multiplier for bimolecular rxn rates
906 
907     int maxparams;       // maximum number of numeric parameters
908     int nparams;         // actual number of numeric parameters
909     char** paramnames;   // names of parameters [index]
910     char** paramstrings; // strings for parameter values [index]
911     double* paramvalues; // actual parameter values [index]
912 
913     int maxmonomer;                     // maximum number of monomers
914     int nmonomer;                       // actual number of monomers
915     char** monomernames;                // names of monomers [index]
916     int* monomercount;                  // monomer count work space [index]
917     double* monomerdifc;                // diffusion coefficient of monomer [index]
918     double* monomerdisplaysize;         // display size of monomer [index]
919     double** monomercolor;              // color of monomer [index][RGB]
920     enum MolecState* monomerstate;      // default monomer state [index]
921     int bngmaxsurface;                  // local copy of nsurface
922     enum SrfAction*** monomeraction;    // monomer surface actions [index][srf][face]
923     surfactionptr*** monomeractdetails; // monomer action details [index][srf][face]
924 
925     int maxbspecies;           // maximum number of bng species
926     int nbspecies;             // actual number of bng species
927     char** bsplongnames;       // complete bng species names [index]
928     char** bspshortnames;      // shortened bng species names [index]
929     enum MolecState* bspstate; // default species state [index]
930     char** bspcountstr;        // strings for initial bng species counts [index]
931     double* bspcount;          // actual initial bng species counts [index]
932     int* spindex;              // smoldyn index of this species [index]
933 
934     int maxbrxns;        // maximum number of bng reactions
935     int nbrxns;          // acutal number of bng reactions
936     char** brxnreactstr; // strings for reactants [index]
937     char** brxnprodstr;  // strings for products [index]
938     char** brxnratestr;  // strings for reaction rates [index]
939     int** brxnreact;     // reactant bng species indices [index][rct]
940     int** brxnprod;      // product bng species indices [index][prd]
941     int* brxnorder;      // order of bng reaction [index]
942     int* brxnnprod;      // number of products of bng reaction [index]
943     rxnptr* brxn;        // pointer to this reaction [index]
944 } * bngptr;
945 
946 typedef struct bngsuperstruct
947 {
948     enum StructCond condition; // structure condition
949     struct simstruct* sim;     // simulation structure
950     char* BNG2path;            // path and name of BNG2.pl executable
951     int maxbng;                // maximum number of bng networks
952     int nbng;                  // actual number of bng networks
953     char** bngnames;           // names of bng networks
954     bngptr* bnglist;           // list of bng networks
955 } * bngssptr;
956 
957 /********************************* Graphics ********************************/
958 
959 #define MAXLIGHTS 8 // must be ? GL_MAX_LIGHTS
960 enum LightParam
961 {
962     LPambient,
963     LPdiffuse,
964     LPspecular,
965     LPposition,
966     LPon,
967     LPoff,
968     LPauto,
969     LPnone
970 };
971 
972 typedef struct graphicssuperstruct
973 {
974     enum StructCond condition;             // structure condition
975     struct simstruct* sim;                 // simulation structure
976     int graphics;                          // graphics: 0=none, 1=opengl, 2=good opengl
977     int runmode;                           // 0=Smoldyn, 1=Libsmoldyn
978     int currentit;                         // current number of simulation time steps
979     int graphicit;                         // number of time steps per graphics update
980     unsigned int graphicdelay;             // minimum delay (in ms) for graphics updates
981     int tiffit;                            // number of time steps per tiff save
982     double framepts;                       // thickness of frame for graphics
983     double gridpts;                        // thickness of virtual box grid for graphics
984     double framecolor[4];                  // frame color [c]
985     double gridcolor[4];                   // grid color [c]
986     double backcolor[4];                   // background color [c]
987     double textcolor[4];                   // text color [c]
988     int maxtextitems;                      // allocated size of item list
989     int ntextitems;                        // actual size of item list
990     char** textitems;                      // items to display with text [item]
991     enum LightParam roomstate;             // on, off, or auto (on)
992     double ambiroom[4];                    // global ambient light [c]
993     enum LightParam lightstate[MAXLIGHTS]; // on, off, or auto (off) [lt]
994     double ambilight[MAXLIGHTS][4];        // ambient light color [lt][c]
995     double difflight[MAXLIGHTS][4];        // diffuse light color [lt][c]
996     double speclight[MAXLIGHTS][4];        // specular light color [lt][c]
997     double lightpos[MAXLIGHTS][4];         // light positions [lt][d]
998 } * graphicsssptr;
999 
1000 /******************************** Simulation *******************************/
1001 
1002 #define ETMAX 11
1003 enum SmolStruct
1004 {
1005     SSmolec,
1006     SSwall,
1007     SSrxn,
1008     SSrule,
1009     SSsurf,
1010     SSbox,
1011     SScmpt,
1012     SSport,
1013     SSfilament,
1014     SScmd,
1015     SSsim,
1016     SScheck,
1017     SSall,
1018     SSnone
1019 };
1020 enum EventType
1021 {
1022     ETwall,
1023     ETsurf,
1024     ETdesorb,
1025     ETrxn0,
1026     ETrxn1,
1027     ETrxn2intra,
1028     ETrxn2inter,
1029     ETrxn2wrap,
1030     ETrxn2hybrid,
1031     ETimport,
1032     ETexport
1033 };
1034 
1035 typedef int (*diffusefnptr)(struct simstruct*);
1036 typedef int (*surfaceboundfnptr)(struct simstruct*, int);
1037 typedef int (*surfacecollisionsfnptr)(struct simstruct*, int, int);
1038 typedef int (*assignmols2boxesfnptr)(struct simstruct*, int, int);
1039 typedef int (*zeroreactfnptr)(struct simstruct*);
1040 typedef int (*unimolreactfnptr)(struct simstruct*);
1041 typedef int (*bimolreactfnptr)(struct simstruct*, int);
1042 typedef int (*checkwallsfnptr)(struct simstruct*, int, int, boxptr);
1043 
1044 typedef struct simstruct
1045 {
1046     enum StructCond condition; // structure condition
1047     FILE* logfile;             // file to send output
1048     char* filepath;            // configuration file path
1049     char* filename;            // configuration file name
1050     char* flags;               // command-line options from user
1051     time_t clockstt;           // clock starting time of simulation
1052     double elapsedtime;        // elapsed time of simulation
1053     long int randseed;         // random number generator seed
1054     int eventcount[ETMAX];     // counter for simulation events
1055     int maxvar;                // allocated user-settable variables
1056     int nvar;                  // number of user-settable variables
1057     char** varnames;           // names of user-settable variables [v]
1058     double* varvalues;         // values of user-settable variables [v]
1059 
1060     int dim; // dimensionality of space.
1061 
1062     double accur;  // accuracy, on scale from 0 to 10
1063     double time;   // current time in simulation
1064     double tmin;   // simulation start time
1065     double tmax;   // simulation end time
1066     double tbreak; // simulation break time
1067     double dt;     // simulation time step
1068 
1069     bool quitatend; // simulation quits at the end
1070 
1071     rxnssptr rxnss[MAXORDER]; // reaction superstructures
1072     rulessptr ruless;         // rule superstructure
1073     molssptr mols;            // molecule superstructure
1074     wallptr* wlist;           // list of walls
1075     surfacessptr srfss;       // surface superstructure
1076     boxssptr boxs;            // box superstructure
1077 
1078     compartssptr cmptss; // compartment superstructure
1079 
1080     portssptr portss; // port superstructure
1081 
1082     latticessptr latticess; // lattice superstructure
1083 
1084     bngssptr bngss; // bionetget superstructure
1085 
1086     filamentssptr filss; // filament superstructure
1087 
1088     cmdssptr cmds; // command superstructure
1089 
1090     graphicsssptr graphss; // graphics superstructure
1091 
1092     diffusefnptr diffusefn; // function for molecule diffusion
1093 
1094     surfaceboundfnptr surfaceboundfn;           // function for surface-bound molecules
1095     surfacecollisionsfnptr surfacecollisionsfn; // function for surface collisons
1096     assignmols2boxesfnptr assignmols2boxesfn;   // function that assigns molecs to boxes
1097     zeroreactfnptr zeroreactfn;                 // function for zero order reactions
1098     unimolreactfnptr unimolreactfn;             // function for first order reactions
1099     bimolreactfnptr bimolreactfn;               // function for second order reactions
1100     checkwallsfnptr checkwallsfn; // function for molecule collisions with walls
1101 
1102 #ifdef ENABLE_PYTHON_CALLBACK
1103 #ifdef __cplusplus
1104     CallbackFunc* callbacks[MAX_PY_CALLBACK]; // Python callback.
1105     unsigned int ncallbacks;                  // number of callbacks.
1106     size_t simstep;
1107 #endif // __cplusplsu
1108 #endif
1109 
1110 #ifdef OPTION_VCELL
1111     VolumeSamplesPtr volumeSamplesPtr;
1112     ValueProviderFactory* valueProviderFactory;
1113     AbstractMesh* mesh;
1114 #endif
1115 } * simptr;
1116 
1117 /*********************************** VCell *********************************/
1118 
1119 #ifdef OPTION_VCELL
1120 
1121 #ifdef __cplusplus
1122 
1123 struct CompartmentIdentifierPair
1124 {
1125     char name[128];
1126     unsigned char pixel; // the compartmentID
1127 };
1128 
1129 typedef struct VolumeSamples
1130 {
1131     int num[3];                // number of mesh points in X, Y,Z
1132     double size[3];            // actual size in X, Y, Z (e.g. in micron)
1133     double origin[3];          // origin of the X, Y, Z
1134     unsigned char* volsamples; // compartmentID for each mesh point center
1135     int nCmptIDPair;           // number of compartments
1136     CompartmentIdentifierPair* compartmentIDPairPtr; // ID vs. comptName pairs.
1137 } * VolumeSamplesPtr;
1138 
1139 class ValueProviderFactory;
1140 class AbstractMesh;
1141 
1142 class ValueProvider
1143 {
1144   public:
~ValueProvider()1145     virtual ~ValueProvider(){};
1146     virtual double getConstantValue() = 0;
1147     virtual double getValue(double t, double x, double y, double z, rxnptr rxn) = 0;
1148     virtual double getValue(double t,
1149       double x,
1150       double y,
1151       double z,
1152       rxnptr rxn,
1153       char* panelName) = 0;
1154     virtual double getValue(double t,
1155       double x,
1156       double y,
1157       double z,
1158       surfactionptr actiondetails,
1159       char* panelName) = 0;
1160 };
1161 
1162 class ValueProviderFactory
1163 {
1164   public:
~ValueProviderFactory()1165     virtual ~ValueProviderFactory(){};
1166     virtual ValueProvider* createValueProvider(string& rateExp) = 0;
setSimptr(simptr sim)1167     void setSimptr(simptr sim) { this->sim = sim; }
getSimptr()1168     simptr getSimptr() { return this->sim; }
1169 
1170   private:
1171     simptr sim;
1172 };
1173 
1174 class AbstractMesh
1175 {
1176   public:
~AbstractMesh()1177     virtual ~AbstractMesh(){};
1178     virtual void getCenterCoordinates(int volIndex, double* coords) = 0;
1179     virtual void getDeltaXYZ(double* delta) = 0;
1180     virtual void getNumXYZ(int* num) = 0;
1181 };
1182 
1183 #endif // not __cplusplus
1184 
1185 #endif
1186 
1187 #endif
1188