validate_react_trig.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* To compile: gcc validate_react_trig.c react_trig.c */
  2. /* To run: ./a.out */
  3. /* Constructs a bunch of potential reaction triggers and tests them. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "mcell_structs.h"
  7. #include "react.h"
  8. struct volume *world;
  9. int main()
  10. {
  11. int i,j;
  12. struct rxn *rxp;
  13. struct molecule *m1,*m2;
  14. struct surface_molecule *s1,*s2;
  15. struct wall *w1,*w2;
  16. struct abstract_molecule *pA,*pB,*pC,*pD;
  17. world = malloc(sizeof(struct volume));
  18. world->n_species = 9;
  19. world->species_list = malloc( world->n_species * sizeof(struct species*) );
  20. for (i=0,j=1;i<world->n_species;i++,j*=2)
  21. {
  22. world->species_list[i] = malloc( sizeof(struct species) );
  23. world->species_list[i]->hashval = j;
  24. }
  25. world->species_list[0]->flags = 0; /* Not used. */
  26. world->species_list[1]->flags = 0; /* GEN_MOL */
  27. world->species_list[2]->flags = IS_SURFACE; /* GEN_SURF */
  28. world->species_list[3]->flags = 0; /* A (free) */
  29. world->species_list[4]->flags = 0; /* B (free) */
  30. world->species_list[5]->flags = ON_SURFACE; /* C (surf) */
  31. world->species_list[6]->flags = ON_SURFACE; /* D (surf) */
  32. world->species_list[7]->flags = ON_GRID; /* E (grid) */
  33. world->species_list[8]->flags = IS_SURFACE; /* S (membrane) */
  34. world->n_reactions = 10;
  35. world->reaction_hash = malloc( j * sizeof(struct rxn*) );
  36. for (i=0;i<j;i++) world->reaction_hash[i] = NULL;
  37. /* Trigger A */
  38. i = world->species_list[3]->hashval;
  39. world->reaction_hash[i] = malloc( sizeof(struct rxn) );
  40. rxp = world->reaction_hash[i];
  41. rxp->next = NULL;
  42. rxp->n_reactants = 1;
  43. rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
  44. rxp->players[0] = world->species_list[3];
  45. rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
  46. rxp->geometries[0] = 0;
  47. /* Trigger A:0 B:0 */
  48. i = world->species_list[3]->hashval + world->species_list[4]->hashval;
  49. world->reaction_hash[i] = malloc( sizeof(struct rxn) );
  50. rxp = world->reaction_hash[i];
  51. rxp->next = NULL;
  52. rxp->n_reactants = 2;
  53. rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
  54. rxp->players[0] = world->species_list[3];
  55. rxp->players[1] = world->species_list[4];
  56. rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
  57. rxp->geometries[0] = 0;
  58. rxp->geometries[1] = 0;
  59. /* Trigger: B:1 C:1 */
  60. i = world->species_list[4]->hashval + world->species_list[5]->hashval;
  61. world->reaction_hash[i] = malloc( sizeof(struct rxn) );
  62. rxp = world->reaction_hash[i];
  63. rxp->next = NULL;
  64. rxp->n_reactants = 2;
  65. rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
  66. rxp->players[0] = world->species_list[4];
  67. rxp->players[1] = world->species_list[5];
  68. rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
  69. rxp->geometries[0] = 1;
  70. rxp->geometries[1] = 1;
  71. /* Trigger: B:1 C:-1 */
  72. i = world->species_list[4]->hashval + world->species_list[5]->hashval;
  73. world->reaction_hash[i]->next = malloc( sizeof(struct rxn) );
  74. rxp = world->reaction_hash[i]->next;
  75. rxp->next = NULL;
  76. rxp->n_reactants = 2;
  77. rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
  78. rxp->players[0] = world->species_list[4];
  79. rxp->players[1] = world->species_list[5];
  80. rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
  81. rxp->geometries[0] = 1;
  82. rxp->geometries[1] = -1;
  83. /* Trigger: A:1 C:1 W:-1 */
  84. i = world->species_list[3]->hashval + world->species_list[5]->hashval;
  85. world->reaction_hash[i] = malloc( sizeof(struct rxn) );
  86. rxp = world->reaction_hash[i];
  87. rxp->next = NULL;
  88. rxp->n_reactants = 3;
  89. rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
  90. rxp->players[0] = world->species_list[3];
  91. rxp->players[1] = world->species_list[5];
  92. rxp->players[2] = world->species_list[8];
  93. rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
  94. rxp->geometries[0] = 1;
  95. rxp->geometries[1] = 1;
  96. rxp->geometries[2] = -1;
  97. /* Trigger: A GEN_SURF */
  98. i = world->species_list[3]->hashval + world->species_list[2]->hashval;
  99. world->reaction_hash[i] = malloc( sizeof(struct rxn) );
  100. rxp = world->reaction_hash[i];
  101. rxp->next = NULL;
  102. rxp->n_reactants = 2;
  103. rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
  104. rxp->players[0] = world->species_list[3];
  105. rxp->players[1] = world->species_list[2];
  106. rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
  107. rxp->geometries[0] = 0;
  108. rxp->geometries[1] = 0;
  109. /* Trigger: B:-1 W:-1 */
  110. i = world->species_list[4]->hashval + world->species_list[8]->hashval;
  111. world->reaction_hash[i] = malloc( sizeof(struct rxn) );
  112. rxp = world->reaction_hash[i];
  113. rxp->next = NULL;
  114. rxp->n_reactants = 2;
  115. rxp->players = malloc( rxp->n_reactants * sizeof(struct species*) );
  116. rxp->players[0] = world->species_list[4];
  117. rxp->players[1] = world->species_list[8];
  118. rxp->geometries = malloc( rxp->n_reactants * sizeof(short) );
  119. rxp->geometries[0] = -1;
  120. rxp->geometries[1] = -1;
  121. m1 = malloc( sizeof(struct molecule) );
  122. m1->properties = world->species_list[3];
  123. m2 = malloc( sizeof(struct molecule) );
  124. m2->properties = world->species_list[4];
  125. s1 = malloc( sizeof(struct molecule) );
  126. s1->properties = world->species_list[5];
  127. s2 = malloc( sizeof(struct molecule) );
  128. s2->properties = world->species_list[6];
  129. w1 = malloc( sizeof(struct wall) );
  130. w1->wall_type = world->species_list[8];
  131. w2 = malloc( sizeof(struct wall) );
  132. w2->wall_type = world->species_list[2];
  133. s1->curr_wall = w1;
  134. s2->curr_wall = w2;
  135. pA = (struct abstract_molecule*)m1;
  136. pB = (struct abstract_molecule*)m2;
  137. pC = (struct abstract_molecule*)s1;
  138. pD = (struct abstract_molecule*)s2;
  139. rxp = trigger_unimolecular(pA->properties->hashval , pA);
  140. printf("%x returned (A , expect hit)\n",(int)rxp);
  141. rxp = trigger_unimolecular(pB->properties->hashval , pB);
  142. printf("%x returned (B , expect miss)\n",(int)rxp);
  143. rxp = trigger_bimolecular(pA->properties->hashval,pB->properties->hashval,pA,pB,0,0);
  144. printf("%x returned (A + B, expect hit)\n",(int)rxp);
  145. rxp = trigger_bimolecular(pB->properties->hashval,pA->properties->hashval,pB,pA,0,0);
  146. printf("%x returned (B + A, expect hit)\n",(int)rxp);
  147. rxp = trigger_bimolecular(pA->properties->hashval,pA->properties->hashval,pA,pA,0,0);
  148. printf("%x returned (A + A, expect miss)\n",(int)rxp);
  149. rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,0,0);
  150. printf("%x returned (B + C, expect miss)\n",(int)rxp);
  151. rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,1,1);
  152. printf("%x returned (B' + C', expect hit(1))\n",(int)rxp);
  153. rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,-1,-1);
  154. printf("%x returned (B, + C,, expect hit(1))\n",(int)rxp);
  155. rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,1,-1);
  156. printf("%x returned (B' + C,, expect hit(2))\n",(int)rxp);
  157. rxp = trigger_bimolecular(pB->properties->hashval,pC->properties->hashval,pB,pC,-1,1);
  158. printf("%x returned (B, + C', expect hit(2))\n",(int)rxp);
  159. rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,1,1);
  160. printf("%x returned (A' + C', expect miss)\n",(int)rxp);
  161. rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,-1,1);
  162. printf("%x returned (A, + C', expect miss)\n",(int)rxp);
  163. rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,1,-1);
  164. printf("%x returned (A' + C,, expect miss)\n",(int)rxp);
  165. rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,-1,-1);
  166. printf("%x returned (A, + C,, expect hit)\n",(int)rxp);
  167. s1->curr_wall = w2;
  168. rxp = trigger_bimolecular(pA->properties->hashval,pC->properties->hashval,pA,pC,-1,-1);
  169. printf("%x returned (A, + C, wrong wall type, expect miss)\n",(int)rxp);
  170. rxp = trigger_intersect(pA->properties->hashval,pA,1,w1);
  171. printf("%x returned (A + S, expect generic hit)\n",(int)rxp);
  172. rxp = trigger_intersect(pA->properties->hashval,pA,1,w2);
  173. printf("%x returned (A + gS, expect generic hit)\n",(int)rxp);
  174. rxp = trigger_intersect(pB->properties->hashval,pB,1,w1);
  175. printf("%x returned (B' + S, expect hit)\n",(int)rxp);
  176. rxp = trigger_intersect(pB->properties->hashval,pB,-1,w1);
  177. printf("%x returned (B, + S, expect miss)\n",(int)rxp);
  178. rxp = trigger_intersect(pB->properties->hashval,pB,1,w2);
  179. printf("%x returned (B' + gS, expect miss)\n",(int)rxp);
  180. }