123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- /* To compile: gcc validate_react_trig.c react_trig.c */
- /* To run: ./a.out */
- /* Constructs a bunch of potential reaction triggers and tests them. */
- #include <stdio.h>
- #include <stdlib.h>
- #include "mcell_structs.h"
- #include "react.h"
- struct volume *world;
- int main()
- {
- int i,j;
- struct rxn *rxp;
- struct molecule *m1,*m2;
- struct surface_molecule *s1,*s2;
- struct wall *w1,*w2;
- struct abstract_molecule *pA,*pB,*pC,*pD;
-
- world = malloc(sizeof(struct volume));
-
- world->n_species = 9;
-
- world->species_list = malloc( world->n_species * sizeof(struct species*) );
- for (i=0,j=1;i<world->n_species;i++,j*=2)
- {
- world->species_list[i] = malloc( sizeof(struct species) );
- world->species_list[i]->hashval = j;
- }
-
- world->species_list[0]->flags = 0; /* Not used. */
- world->species_list[1]->flags = 0; /* GEN_MOL */
- world->species_list[2]->flags = IS_SURFACE; /* GEN_SURF */
- world->species_list[3]->flags = 0; /* A (free) */
- world->species_list[4]->flags = 0; /* B (free) */
- world->species_list[5]->flags = ON_SURFACE; /* C (surf) */
- world->species_list[6]->flags = ON_SURFACE; /* D (surf) */
- world->species_list[7]->flags = ON_GRID; /* E (grid) */
- world->species_list[8]->flags = IS_SURFACE; /* S (membrane) */
-
- world->n_reactions = 10;
-
- world->reaction_hash = malloc( j * sizeof(struct rxn*) );
- for (i=0;i<j;i++) world->reaction_hash[i] = NULL;
-
- /* Trigger A */
- i = world->species_list[3]->hashval;
- world->reaction_hash[i] = malloc( sizeof(struct rxn) );
- rxp = world->reaction_hash[i];
- rxp->next = NULL;
- rxp->n_reactants = 1;
- rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
- rxp->players[0] = world->species_list[3];
- rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
- rxp->geometries[0] = 0;
-
- /* Trigger A:0 B:0 */
- i = world->species_list[3]->hashval + world->species_list[4]->hashval;
- world->reaction_hash[i] = malloc( sizeof(struct rxn) );
- rxp = world->reaction_hash[i];
- rxp->next = NULL;
- rxp->n_reactants = 2;
- rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
- rxp->players[0] = world->species_list[3];
- rxp->players[1] = world->species_list[4];
- rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
- rxp->geometries[0] = 0;
- rxp->geometries[1] = 0;
-
- /* Trigger: B:1 C:1 */
- i = world->species_list[4]->hashval + world->species_list[5]->hashval;
- world->reaction_hash[i] = malloc( sizeof(struct rxn) );
- rxp = world->reaction_hash[i];
- rxp->next = NULL;
- rxp->n_reactants = 2;
- rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
- rxp->players[0] = world->species_list[4];
- rxp->players[1] = world->species_list[5];
- rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
- rxp->geometries[0] = 1;
- rxp->geometries[1] = 1;
-
- /* Trigger: B:1 C:-1 */
- i = world->species_list[4]->hashval + world->species_list[5]->hashval;
- world->reaction_hash[i]->next = malloc( sizeof(struct rxn) );
- rxp = world->reaction_hash[i]->next;
- rxp->next = NULL;
- rxp->n_reactants = 2;
- rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
- rxp->players[0] = world->species_list[4];
- rxp->players[1] = world->species_list[5];
- rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
- rxp->geometries[0] = 1;
- rxp->geometries[1] = -1;
-
- /* Trigger: A:1 C:1 W:-1 */
- i = world->species_list[3]->hashval + world->species_list[5]->hashval;
- world->reaction_hash[i] = malloc( sizeof(struct rxn) );
- rxp = world->reaction_hash[i];
- rxp->next = NULL;
- rxp->n_reactants = 3;
- rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
- rxp->players[0] = world->species_list[3];
- rxp->players[1] = world->species_list[5];
- rxp->players[2] = world->species_list[8];
- rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
- rxp->geometries[0] = 1;
- rxp->geometries[1] = 1;
- rxp->geometries[2] = -1;
-
- /* Trigger: A GEN_SURF */
- i = world->species_list[3]->hashval + world->species_list[2]->hashval;
- world->reaction_hash[i] = malloc( sizeof(struct rxn) );
- rxp = world->reaction_hash[i];
- rxp->next = NULL;
- rxp->n_reactants = 2;
- rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
- rxp->players[0] = world->species_list[3];
- rxp->players[1] = world->species_list[2];
- rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
- rxp->geometries[0] = 0;
- rxp->geometries[1] = 0;
- /* Trigger: B:-1 W:-1 */
- i = world->species_list[4]->hashval + world->species_list[8]->hashval;
- world->reaction_hash[i] = malloc( sizeof(struct rxn) );
- rxp = world->reaction_hash[i];
- rxp->next = NULL;
- rxp->n_reactants = 2;
- rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
- rxp->players[0] = world->species_list[4];
- rxp->players[1] = world->species_list[8];
- rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
- rxp->geometries[0] = -1;
- rxp->geometries[1] = -1;
-
-
- m1 = malloc( sizeof(struct molecule) );
- m1->properties = world->species_list[3];
-
- m2 = malloc( sizeof(struct molecule) );
- m2->properties = world->species_list[4];
-
- s1 = malloc( sizeof(struct molecule) );
- s1->properties = world->species_list[5];
-
- s2 = malloc( sizeof(struct molecule) );
- s2->properties = world->species_list[6];
-
- w1 = malloc( sizeof(struct wall) );
- w1->wall_type = world->species_list[8];
-
- w2 = malloc( sizeof(struct wall) );
- w2->wall_type = world->species_list[2];
-
- s1->curr_wall = w1;
- s2->curr_wall = w2;
- pA = (struct abstract_molecule*)m1;
- pB = (struct abstract_molecule*)m2;
- pC = (struct abstract_molecule*)s1;
- pD = (struct abstract_molecule*)s2;
-
- rxp = trigger_unimolecular(pA->properties->hashval , pA);
- printf("%x returned (A , expect hit)\n",(int)rxp);
-
- rxp = trigger_unimolecular(pB->properties->hashval , pB);
- printf("%x returned (B , expect miss)\n",(int)rxp);
-
- rxp = trigger_bimolecular(pA->properties->hashval,pB->properties->hashval,pA,pB,0,0);
- printf("%x returned (A + B, expect hit)\n",(int)rxp);
-
- rxp = trigger_bimolecular(pB->properties->hashval,pA->properties->hashval,pB,pA,0,0);
- printf("%x returned (B + A, expect hit)\n",(int)rxp);
-
- rxp = trigger_bimolecular(pA->properties->hashval,pA->properties->hashval,pA,pA,0,0);
- printf("%x returned (A + A, expect miss)\n",(int)rxp);
-
- rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,0,0);
- printf("%x returned (B + C, expect miss)\n",(int)rxp);
-
- rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,1,1);
- printf("%x returned (B' + C', expect hit(1))\n",(int)rxp);
-
- rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,-1,-1);
- printf("%x returned (B, + C,, expect hit(1))\n",(int)rxp);
- rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,1,-1);
- printf("%x returned (B' + C,, expect hit(2))\n",(int)rxp);
-
- rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,-1,1);
- printf("%x returned (B, + C', expect hit(2))\n",(int)rxp);
-
- rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,1,1);
- printf("%x returned (A' + C', expect miss)\n",(int)rxp);
-
- rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,-1,1);
- printf("%x returned (A, + C', expect miss)\n",(int)rxp);
- rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,1,-1);
- printf("%x returned (A' + C,, expect miss)\n",(int)rxp);
- rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,-1,-1);
- printf("%x returned (A, + C,, expect hit)\n",(int)rxp);
-
- s1->curr_wall = w2;
- rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,-1,-1);
- printf("%x returned (A, + C, wrong wall type, expect miss)\n",(int)rxp);
-
- rxp = trigger_intersect(pA->properties->hashval,pA,1,w1);
- printf("%x returned (A + S, expect generic hit)\n",(int)rxp);
-
- rxp = trigger_intersect(pA->properties->hashval,pA,1,w2);
- printf("%x returned (A + gS, expect generic hit)\n",(int)rxp);
- rxp = trigger_intersect(pB->properties->hashval,pB,1,w1);
- printf("%x returned (B' + S, expect hit)\n",(int)rxp);
-
- rxp = trigger_intersect(pB->properties->hashval,pB,-1,w1);
- printf("%x returned (B, + S, expect miss)\n",(int)rxp);
-
- rxp = trigger_intersect(pB->properties->hashval,pB,1,w2);
- printf("%x returned (B' + gS, expect miss)\n",(int)rxp);
- }
|