Advertisement
Guest User

Untitled

a guest
Jul 17th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. int main (int argc, char *argv[])
  2. {
  3. char filename[256], tmp_str[256];
  4. int error, i, index, j, k, label[2];
  5. float label_fl;
  6. FILE *f_inp;
  7.  
  8. char input[256], logfile[256], output[256];
  9. float cell[3], *coords, *crit;
  10. int *agl, *connect, from, *label_atom, *label_mol, log, num_atoms, num_mol,
  11. *num_mol_agl, num_of_inter, *stat, *stat_all, step, to, *true_label_mol,
  12. type_agl[2], *type_atoms, type_inter, quiet;
  13. /* input - mask of input files
  14. * logfile - log file name
  15. * output - output file name
  16. *
  17. * cell - cell dimension
  18. * coords - massive of coordinates
  19. * crit - massive of criteria
  20. *
  21. * agl - massive of aglomerates
  22. * connect - connectivity graph for all molecules
  23. * from - start point
  24. * label_atom - types of atom for interaction
  25. * label_mol - massive of numbers of molecule for atoms
  26. * log - status of log-mode
  27. * num_atoms - number of atoms for writing coordinates
  28. * num_mol - number of molecules for writing coordinates
  29. * num_mol_agl - massive of numbers of molecule in aglomerates
  30. * num_of_inter - number of different interactions
  31. * stat - massive of statistics
  32. * stat_all - massive of summary statistics
  33. * step - $(to - from + 1)
  34. * to - finish point
  35. * true_label_mol - massive of true numbers of molecule for atoms
  36. * type_agl - massive of numbers of aglomerate types
  37. * type_atoms - massive of atom types for atoms
  38. * type_inter - type interaction (number of molecules for interaction)
  39. * quiet - status of quiet-mode
  40. */
  41.  
  42. set_defaults (cell, &from, input, &log, &num_of_inter, output, &to, type_agl,
  43. &type_inter, &quiet);
  44.  
  45. // reading number of interactions
  46. for (i=1; i<argc; i++)
  47. if ((argv[i][0] == '-') && (argv[i][1] == 'r'))
  48. num_of_inter++;
  49. if (num_of_inter > 0)
  50. {
  51. crit = (float *) malloc ( 16 * num_of_inter * sizeof (float));
  52. for (i=0; i<16*num_of_inter; i++)
  53. crit[i] = 0.0;
  54. num_of_inter = 0;
  55. }
  56.  
  57. // reading arguments
  58. for (i=1; i<argc; i++)
  59. {
  60. if ((argv[i][0] == '-') && (argv[i][1] == 'h'))
  61. {
  62. printf (" statgen\n");
  63. printf ("Program for analyze molecular dynamic trajectories\n");
  64. printf ("Version : 1.0.0 License : GPL\n");
  65. printf (" Alekseev Evgeniy aka arcanis\n");
  66. printf (" E-mail : esalexeev@gmail.com\n\n");
  67. printf ("Usage:\n");
  68. printf ("statgen -i INPUT -s FIRST,LAST -c X,Y,Z -a ... -r ... -o OUTPUT [ -l LOGFILE ] [ -q ] [ -h ]\n\n");
  69. printf ("Parametrs:\n");
  70. printf (" -i - mask of input files\n");
  71. printf (" -s - trajectory steps (integer)\n");
  72. printf (" -c - cell size (float), A\n");
  73. printf (" -a - atom types (integer). Format: 'ATOM1' or 'ATOM1,ATOM2' or etc\n");
  74. printf (" -r - criteria (float), A. Format: '0-0:2.4,0-1:3.0' means 0-0-interaction\n");
  75. printf (" (<2.4 A) and 0-1 (<3.0) are needed. This flag can be used multiple times\n");
  76. printf (" -o - output file name\n");
  77. printf (" -l - log enable\n");
  78. printf (" -q - quiet enable\n");
  79. printf (" -h - show this help and exit\n");
  80. return 0;
  81. }
  82. else if ((argv[i][0] == '-') && (argv[i][1] == 'i'))
  83. // mask of input files
  84. {
  85. strcpy (input, argv[i+1]);
  86. i++;
  87. }
  88. else if ((argv[i][0] == '-') && (argv[i][1] == 's'))
  89. // steps
  90. {
  91. sscanf (argv[i+1], "%i,%i", &from, &to);
  92. if (from > to)
  93. {
  94. to += from;
  95. from = to - from;
  96. to -= from;
  97. }
  98. step = to - from + 1;
  99. i++;
  100. }
  101. else if ((argv[i][0] == '-') && (argv[i][1] == 'c'))
  102. // cell size
  103. {
  104. sscanf (argv[i+1], "%f,%f,%f", &cell[0], &cell[1], &cell[2]);
  105. i++;
  106. }
  107. else if ((argv[i][0] == '-') && (argv[i][1] == 'a'))
  108. // atom types
  109. {
  110. type_inter = 1;
  111. for (j=0; j<strlen(argv[i+1]); j++)
  112. if (argv[i+1][j] == ',')
  113. type_inter++;
  114.  
  115. label_atom = (int *) malloc (type_inter * sizeof (int));
  116. switch (type_inter)
  117. {
  118. case 1:
  119. sscanf (argv[i+1], "%i", &label_atom[0]);
  120. break;
  121. case 2:
  122. sscanf (argv[i+1], "%i,%i", &label_atom[0], &label_atom[1]);
  123. break;
  124. case 3:
  125. sscanf (argv[i+1], "%i,%i,%i", &label_atom[0], &label_atom[1], &label_atom[2]);
  126. break;
  127. case 4:
  128. sscanf (argv[i+1], "%i,%i,%i,%i", &label_atom[0], &label_atom[1], &label_atom[2], &label_atom[3]);
  129. break;
  130. }
  131.  
  132. i++;
  133. }
  134. else if ((argv[i][0] == '-') && (argv[i][1] == 'r'))
  135. // criteria
  136. {
  137. index = 0;
  138. sscanf (&argv[i+1][index], "%i-%i:%f%s", &label[0], &label[1], &label_fl, tmp_str);
  139. crit[16*num_of_inter+4*label[0]+label[1]] = label_fl;
  140. crit[16*num_of_inter+4*label[1]+label[0]] = label_fl;
  141. for (j=index; j<strlen(argv[i+1]); j++)
  142. if (argv[i+1][j] == ',')
  143. {
  144. index = j+1;
  145. sscanf (&argv[i+1][index], "%i-%i:%f%s", &label[0], &label[1], &label_fl, tmp_str);
  146. crit[16*num_of_inter+4*label[0]+label[1]] = label_fl;
  147. crit[16*num_of_inter+4*label[1]+label[0]] = label_fl;
  148. }
  149.  
  150. num_of_inter++;
  151. i++;
  152. }
  153. else if ((argv[i][0] == '-') && (argv[i][1] == 'o'))
  154. // output file
  155. {
  156. strcpy (output, argv[i+1]);
  157. i++;
  158. }
  159. else if ((argv[i][0] == '-') && (argv[i][1] == 'l'))
  160. // log mode
  161. {
  162. log = 1;
  163. strcpy (logfile, argv[i+1]);
  164. i++;
  165. }
  166. else if ((argv[i][0] == '-') && (argv[i][1] == 'q'))
  167. // quiet mode
  168. {
  169. quiet = 1;
  170. }
  171. }
  172.  
  173. // error checking
  174. error = error_checking (cell, from, input, num_of_inter, output, to, type_inter);
  175. if (error > 1)
  176. {
  177. printf ("Something wrong (error code: %i)!\nSee 'statgen -h' for more details\n", error);
  178. return 1;
  179. }
  180.  
  181. // processing
  182. // initial variables
  183. k = strlen (input);
  184. strcpy (filename, input);
  185. filename[k] = '.';
  186. filename[k+1] = conv (from, 3);
  187. filename[k+2] = conv (from, 2);
  188. filename[k+3] = conv (from, 1);
  189. filename[k+4] = '\0';
  190. f_inp = fopen (filename, "r");
  191. if (f_inp == NULL)
  192. return 1;
  193. fscanf (f_inp, "%i", &num_atoms);
  194. fclose (f_inp);
  195. coords = (float *) malloc (3 * 8 * num_atoms * sizeof (float));
  196. label_mol = (int *) malloc (8 * num_atoms * sizeof (int));
  197. true_label_mol = (int *) malloc (8 * num_atoms * sizeof (int));
  198. type_atoms = (int *) malloc (8 * num_atoms * sizeof (int));
  199.  
  200. // head
  201. printing_head (output, log, quiet, input, from, to, cell, type_inter, label_atom,
  202. num_of_inter, crit);
  203.  
  204. // main cycle
  205. for (i=from; i<to+1; i++)
  206. {
  207. // reading coordinates
  208. filename[k+1] = conv (i, 3);
  209. filename[k+2] = conv (i, 2);
  210. filename[k+3] = conv (i, 1);
  211. filename[k+4] = '\0';
  212. error = reading_coords (filename, type_inter, label_atom, cell, &num_mol,
  213. &num_atoms, true_label_mol, label_mol, type_atoms, coords);
  214.  
  215. // initializate variables
  216. if (i == from)
  217. {
  218. agl = (int *) malloc (num_mol * num_mol * sizeof (int));
  219. connect = (int *) malloc (num_mol * num_mol * sizeof (int));
  220. num_mol_agl = (int *) malloc (num_mol * sizeof (int));
  221. stat = (int *) malloc (num_mol * sizeof (int));
  222. stat_all = (int *) malloc (num_mol * sizeof (int));
  223. }
  224.  
  225. for (j=0; j<num_mol; j++)
  226. {
  227. num_mol_agl[j] = j;
  228. printf ("%i - %i\n", j, num_mol_agl[j]);
  229. }
  230.  
  231. // analyze
  232. error = 1;
  233. error = create_matrix (num_mol, num_atoms, label_mol, type_atoms, coords,
  234. num_of_inter, crit, connect);
  235. if (error == 0)
  236. {
  237. error = 1;
  238. error = proc_matrix (num_mol, connect, num_mol_agl, agl, stat, stat_all);
  239. if (error == 0)
  240. printing_agl (filename, output, connect, num_mol, true_label_mol,
  241. num_mol_agl, agl, stat, type_agl);
  242. }
  243.  
  244. }
  245. num_mol_agl[num_mol-1] = num_mol;
  246. printf ("%i - %i\n", num_mol-1, num_mol_agl[num_mol]);
  247.  
  248. // tail
  249. summary_statistic (output, step, num_mol, type_agl, stat_all);
  250. printf ("%i - %i\n", num_mol-1, num_mol_agl[num_mol]);
  251.  
  252. // free memory
  253. free (agl);
  254. free (connect);
  255. free (coords);
  256. free (crit);
  257. free (label_mol);
  258. // memory crash here
  259. free (num_mol_agl);
  260. // free (stat);
  261. // free (stat_all);
  262. free (true_label_mol);
  263. free (type_atoms);
  264.  
  265. return 0;
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement