SDA (SDA flex)  7.2
Simulation of Diffusional Association
DTgrd.hpp
Go to the documentation of this file.
1 
10 #ifndef DTGRD_HPP_
11 #define DTGRD_HPP_
12 
13 #include <stdlib.h>
14 #include <iostream>
15 #include <fstream>
16 #include <string.h>
17 #include <sstream>
18 #include <iomanip>
19 #include <math.h>
20 #include <sys/stat.h>
21 #include <vector>
22 #include "UHBDgrd.hpp"
23 
24 template<typename T1>
25 class DT_FILE
26 {
27 public:
28  DT_FILE (int);
29  DT_FILE (int, bool);
30  DT_FILE (int, int, int, int);
32 
33 private:
35  bool pqr_flag;
36 
37  int LengthX;
38  int LengthY;
39  int LengthZ;
40 
43 
44  std::vector<T1> Value;
45  std::vector<int> xcoord;
46  std::vector<int> ycoord;
47  std::vector<int> zcoord;
48  std::vector<int> acc;
49  std::vector<int> acc2D;
50  std::vector<int> acc3D;
51  std::vector<int> proj1D;
52  std::vector<int> proj2D;
53 
54  int check_neighbours(bool ***, bool ***, int, int, int);
55  bool *** exterior_grid(bool ***);
56  int write_dtgrdfilebody_ascii(FILE *);
57  int write_dtgrdfilebody_binary(FILE *);
58 
59 public:
60  void UHBD_upload(char *, char *, float, float);
61  void exclusion(char *, float, float);
62  void exclusion(char *);
63  int Generate_DTGrid(bool ***, T1 ***);
64 
65  int print_layer(bool ***, int, int);
66  int write_dtgrdfile_ascii(FILE *);
67  int write_dtgrdfile_binary(FILE *);
68  int write_dtgrdfile_ascii_nouhbd(FILE *);
70 };
71 
73 
79 template <typename T1>
81  grid_type_flag = flag;
82  uhbd_alloc = 0;
83  pqr_flag = false;
84 }
85 
87 
94 template <typename T1>
95 DT_FILE<T1>::DT_FILE(int flag, bool pqr_fl){
96  grid_type_flag = flag;
97  uhbd_alloc = 0;
98  pqr_flag = pqr_fl;
99 }
100 
102 
111 template <typename T1>
112 DT_FILE<T1>::DT_FILE(int flag, int i, int j, int k){
113  grid_type_flag = flag;
114  LengthX = i;
115  LengthY = j;
116  LengthZ = k;
117  uhbd_alloc = 0;
118 }
119 
121 
130 template <typename T1>
131 void DT_FILE<T1>::UHBD_upload(char * PDBFILE, char * UHBDFILE, float probe_size, float skin_size){
132  uhbd = new UHBD<T1>(PDBFILE, UHBDFILE, pqr_flag, probe_size);
133  // 5 given below is the number of layers inside the vdw surface to be added to the molecular skin
134  uhbd->Generate_Skin(skin_size, 5);
135  LengthX = uhbd->dim.i;
136  LengthY = uhbd->dim.j;
137  LengthZ = uhbd->dim.k;
138  uhbd_alloc = 1;
139 
140  Generate_DTGrid(uhbd->Skin,uhbd->Grid);
141 }
142 
144 
155 template <typename T1>
156 void DT_FILE<T1>::exclusion(char * PDBFILE, float probe_size, float spacing){
157  uhbd = new UHBD<T1>(PDBFILE, probe_size, pqr_flag, spacing);
158 
159  LengthX = uhbd->dim.i;
160  LengthY = uhbd->dim.j;
161  LengthZ = uhbd->dim.k;
162  uhbd_alloc = 1;
163 
164  Generate_DTGrid(uhbd->Skin,uhbd->Grid);
165 }
166 
168 
177 template <typename T1>
178 void DT_FILE<T1>::exclusion(char * UHBDFILE){
179  uhbd = new UHBD<T1>(UHBDFILE);
180 
181  LengthX = uhbd->dim.i;
182  LengthY = uhbd->dim.j;
183  LengthZ = uhbd->dim.k;
184  uhbd_alloc = 1;
185 
186  Generate_DTGrid(uhbd->Grid,uhbd->Grid);
187 }
188 
190 
201 template <typename T1>
202 int DT_FILE<T1>::check_neighbours(bool *** Exterior, bool *** Skin_Grid, int x, int y, int z){
203 
204  if (x >= LengthX or y >= LengthY or z >= LengthZ )
205  return 0;
206 
207  if (x < 0 or y < 0 or z < 0 )
208  return 0;
209 
210  if (Skin_Grid[x][y][z] == false){
211  if (Exterior[x][y][z] == false){
212  Exterior[x][y][z] = true;
213  check_neighbours(Exterior, Skin_Grid, x+1, y, z);
214  check_neighbours(Exterior, Skin_Grid, x-1, y, z);
215  check_neighbours(Exterior, Skin_Grid, x, y+1, z);
216  check_neighbours(Exterior, Skin_Grid, x, y-1, z);
217  check_neighbours(Exterior, Skin_Grid, x, y, z+1);
218  check_neighbours(Exterior, Skin_Grid, x, y, z-1);
219  }
220  }
221  return 0;
222 }
223 
225 
233 template <typename T1>
234 int DT_FILE<T1>::print_layer(bool *** Exterior, int dimension, int layer){
235 
236  if (dimension == 0){
237  for (int i=0;i<LengthX;i++){
238  for (int j=0;j<LengthY;j++){
239  if (Exterior[i][j][layer] == true)
240  std::cout << "X";
241  else
242  std::cout << " ";
243  }
244  std::cout << std::endl;
245  }
246  }
247  else if (dimension == 1){
248  for (int j=0;j<LengthY;j++){
249  for (int k=0;k<LengthZ;k++){
250  if (Exterior[layer][j][k] == true)
251  std::cout << "X";
252  else
253  std::cout << " ";
254  }
255  std::cout << std::endl;
256  }
257  }
258  else if (dimension == 2){
259  for (int i=0;i<LengthX;i++){
260  for (int k=0;k<LengthZ;k++){
261  if (Exterior[i][layer][k] == true)
262  std::cout << "X";
263  else
264  std::cout << " ";
265  }
266  std::cout << std::endl;
267  }
268  }
269  else {
270  std::cout << "Check the dimension flag!!" << std::endl;
271  }
272  return 0;
273 }
274 
276 
291 template <typename T1>
292 bool *** DT_FILE<T1>::exterior_grid(bool *** Skin_Grid){
293  bool *** Exterior;
294  Exterior = new bool ** [LengthX];
295  for (int i=0;i<LengthX;i++){
296  Exterior[i] = new bool * [LengthY];
297  for (int j=0;j<LengthY;j++){
298  Exterior[i][j] = new bool [LengthZ];
299  }
300  }
301 
302  for (int i=0;i<LengthX;i++){
303  for (int j=0;j<LengthY;j++){
304  for (int k=0;k<LengthZ;k++){
305  Exterior[i][j][k] = false;
306  }
307  }
308  }
309 
310  for (int i=0;i<LengthX;i++){
311  for (int j=0;j<LengthY;j++){
312  if (Skin_Grid[i][j][0] == false){
313  if (Exterior[i][j][0] == false){
314  Exterior[i][j][0] = true;
315  check_neighbours(Exterior, Skin_Grid, i+1, j, 0);
316  check_neighbours(Exterior, Skin_Grid, i-1, j, 0);
317  check_neighbours(Exterior, Skin_Grid, i, j+1, 0);
318  check_neighbours(Exterior, Skin_Grid, i, j-1, 0);
319  check_neighbours(Exterior, Skin_Grid, i, j, 1);
320  }
321  }
322  if (Skin_Grid[i][j][LengthZ-1] == false){
323  if (Exterior[i][j][LengthZ-1] == false){
324  Exterior[i][j][LengthZ-1] = true;
325  check_neighbours(Exterior, Skin_Grid, i+1, j, LengthZ-1);
326  check_neighbours(Exterior, Skin_Grid, i-1, j, LengthZ-1);
327  check_neighbours(Exterior, Skin_Grid, i, j+1, LengthZ-1);
328  check_neighbours(Exterior, Skin_Grid, i, j-1, LengthZ-1);
329  check_neighbours(Exterior, Skin_Grid, i, j, LengthZ-2);
330  }
331  }
332  }
333  }
334  for (int j=0;j<LengthY;j++){
335  for (int k=0;k<LengthZ;k++){
336  if (Skin_Grid[0][j][k] == false){
337  if (Exterior[0][j][k] == false){
338  Exterior[0][j][k] = true;
339  check_neighbours(Exterior, Skin_Grid, 0, j, k+1);
340  check_neighbours(Exterior, Skin_Grid, 0, j, k-1);
341  check_neighbours(Exterior, Skin_Grid, 0, j+1, k);
342  check_neighbours(Exterior, Skin_Grid, 0, j-1, k);
343  check_neighbours(Exterior, Skin_Grid, 1, j, k);
344  }
345  }
346  if (Skin_Grid[LengthX-1][j][k] == false){
347  if (Exterior[LengthX-1][j][k] == false){
348  Exterior[LengthX-1][j][k] = true;
349  check_neighbours(Exterior, Skin_Grid, LengthX-1, j, k+1);
350  check_neighbours(Exterior, Skin_Grid, LengthX-1, j, k-1);
351  check_neighbours(Exterior, Skin_Grid, LengthX-1, j+1, k);
352  check_neighbours(Exterior, Skin_Grid, LengthX-1, j-1, k);
353  check_neighbours(Exterior, Skin_Grid, LengthX-2, j, k);
354  }
355  }
356  }
357  }
358 
359  for (int i=0;i<LengthX;i++){
360  for (int k=0;k<LengthZ;k++){
361  if (Skin_Grid[i][0][k] == false){
362  if (Exterior[i][0][k] == false){
363  Exterior[i][0][k] = true;
364  check_neighbours(Exterior, Skin_Grid, i, 0, k+1);
365  check_neighbours(Exterior, Skin_Grid, i, 0, k-1);
366  check_neighbours(Exterior, Skin_Grid, i+1, 0, k);
367  check_neighbours(Exterior, Skin_Grid, i-1, 0, k);
368  check_neighbours(Exterior, Skin_Grid, i, 1, k);
369  }
370  }
371  if (Skin_Grid[i][LengthY-1][k] == false){
372  if (Exterior[i][LengthY-1][k] == false){
373  Exterior[i][LengthY-1][k] = true;
374  check_neighbours(Exterior, Skin_Grid, i, LengthY-1, k+1);
375  check_neighbours(Exterior, Skin_Grid, i, LengthY-1, k-1);
376  check_neighbours(Exterior, Skin_Grid, i+1, LengthY-1, k);
377  check_neighbours(Exterior, Skin_Grid, i-1, LengthY-1, k);
378  check_neighbours(Exterior, Skin_Grid, i, LengthY-2, k);
379  }
380  }
381  }
382  }
383  return Exterior;
384 }
386 
393 template <typename T1>
394 int DT_FILE<T1>::Generate_DTGrid(bool *** Skin_Grid, T1 *** UHBD_Grid){
395 
396  std::cout << "Generating the DT-Grid structure ..." << std::endl;
397  int componentY, componentZ;
398  int prev_componentY, prev_componentZ;
399 
400  prev_componentY = -1;
401 
402  for (int i=0;i<LengthX;i++){
403  prev_componentZ = -1;
404  componentY = 0;
405  for (int j=0; j<LengthY; j++){
406  componentZ = 0;
407  for (int k=0; k<LengthZ; k++){
408  if (grid_type_flag == 0){
409  if (Skin_Grid[i][j][k] == true){
410  if (k==0){
411  componentZ += 1;
412  zcoord.push_back(k);
413  acc.push_back(0);
414  proj1D.push_back(0);
415  proj1D.push_back(((int) zcoord.size())-1);
416  }
417  else{
418  if (Skin_Grid[i][j][k-1] == false){
419  componentZ += 1;
420  zcoord.push_back(k);
421  acc.push_back(0);
422  if (componentZ == 1){
423  proj1D.push_back(0);
424  proj1D.push_back(((int) zcoord.size())-1);
425  }
426  }
427  }
428  }
429  }
430  else{
431  if (Skin_Grid[i][j][k] == true){
432  Value.push_back(UHBD_Grid[i][j][k]);
433 
434  if (k==0){
435  componentZ += 1;
436  zcoord.push_back(k);
437  acc.push_back(((int) Value.size())-1);
438  proj1D.push_back(((int) Value.size())-1);
439  proj1D.push_back(((int) zcoord.size())-1);
440  }
441  else{
442  if (Skin_Grid[i][j][k-1] == false){
443  componentZ += 1;
444  zcoord.push_back(k);
445  acc.push_back(((int) Value.size())-1);
446  if (componentZ == 1){
447  proj1D.push_back(((int) Value.size())-1);
448  proj1D.push_back(((int) zcoord.size())-1);
449  }
450  }
451  }
452  }
453  }
454 
455  if (k == (LengthZ-1)){
456  if (Skin_Grid[i][j][k] == true){
457  zcoord.push_back(k);
458  }
459  else{
460  if (Skin_Grid[i][j][k-1] == true){
461  zcoord.push_back((k-1));
462  }
463  }
464  }
465  else{
466  if (k != 0){
467  if (Skin_Grid[i][j][k-1] == true){
468  if (Skin_Grid[i][j][k] == false){
469  zcoord.push_back((k-1));
470  }
471  }
472  }
473  }
474  }
475 
476  if (j==0){
477  if (componentZ > 0){
478  ycoord.push_back(j);
479  acc2D.push_back(((int) proj1D.size())-2);
480  componentY += 1;
481  proj2D.push_back(((int) proj1D.size())-2);
482  proj2D.push_back(((int) ycoord.size())-1);
483 
484  }
485  }
486  else{
487  if (prev_componentZ == 0){
488  if (componentZ > 0){
489  ycoord.push_back(j);
490  acc2D.push_back(((int) proj1D.size())-2);
491  componentY += 1;
492  if (componentY == 1){
493  proj2D.push_back(((int) proj1D.size())-2);
494  proj2D.push_back(((int) ycoord.size())-1);
495  }
496  }
497  }
498  }
499  if (j == (LengthY-1)){
500  if (componentZ > 0){
501  ycoord.push_back(j);
502  }
503  else{
504  if (prev_componentZ > 0){
505  ycoord.push_back(j-1);
506  }
507  }
508  }
509  else{
510  if (prev_componentZ > 0){
511  if (componentZ == 0){
512  ycoord.push_back(j-1);
513  }
514  }
515  }
516  prev_componentZ = componentZ;
517  }
518  if (i == 0){
519  if (componentY > 0){
520  xcoord.push_back(i);
521  acc3D.push_back(((int) proj2D.size())-2);
522  }
523  }
524  else{
525  if (prev_componentY == 0){
526  if (componentY > 0){
527  xcoord.push_back(i);
528  acc3D.push_back(((int) proj2D.size())-2);
529  }
530  }
531  }
532  if (i == (LengthX-1)){
533  if (componentY > 0){
534  xcoord.push_back(i);
535  }
536  else{
537  if (prev_componentY > 0){
538  xcoord.push_back(i-1);
539  }
540  }
541  }
542  else{
543  if (prev_componentY > 0){
544  if (componentY == 0){
545  xcoord.push_back(i-1);
546  }
547  }
548  }
549  prev_componentY = componentY;
550  }
551  std::cout << "DT-Grid structure is generated successfully!" << std::endl;
552  return 0;
553 }
554 
556 
564 template <typename T1>
566 {
567  //Write the uhbd file header first
568  std::cout << "Writing the DT-Grid (ASCII) to the output file ..." << std::endl;
569  //std::cout << uhbd->Title << std::endl;
570  fprintf(output_file, "%72s\n", uhbd->Title);
571  fprintf(output_file, "%12.5E%12.5E%7d%7d%7d%7d%7d\n", uhbd->scale, \
572  uhbd->dummy1, 3, uhbd->idummy1, uhbd->idummy2, uhbd->one, uhbd->idummy3);
573  fprintf(output_file, "%7d%7d%7d%12.5E%12.5E%12.5E%12.5E\n", uhbd->dim.i, uhbd->dim.j, \
574  uhbd->dim.k, uhbd->spacing, uhbd->o.x, uhbd->o.y, uhbd->o.z);
575  fprintf(output_file, "%12.5E%12.5E%12.5E%12.5E\n", uhbd->dummy2, uhbd->dummy3, uhbd->dummy4, uhbd->dummy5);
576  fprintf(output_file, "%12.5E%12.5E%7d%7d\n", uhbd->dummy6, uhbd->dummy7, uhbd->idummy4, uhbd->idummy5);
577 
578  write_dtgrdfilebody_ascii(output_file); //call to write the body of the grid file
579  return 0;
580 }
581 
583 
591 template <typename T1>
593 {
594  int binary_dt_type = 2;
595  int flag_binary = 160;
596  //WRITE THE UHBD FILE HEADER FIRST
597  std::cout << "Writing the DT-Grid (Binary) to the output file ..." << std::endl;
598  fwrite(&flag_binary, sizeof(int),1,output_file);
599  fwrite(uhbd->Title,sizeof(char), 72, output_file);
600  fwrite(&(uhbd->scale), sizeof(float),1,output_file);
601  fwrite(&(uhbd->dummy1), sizeof(float),1,output_file);
602  fwrite(&binary_dt_type, sizeof(int),1,output_file);
603  fwrite(&(uhbd->idummy1), sizeof(int),1,output_file);
604  fwrite(&(uhbd->idummy2), sizeof(int),1,output_file);
605  fwrite(&(uhbd->one), sizeof(int),1,output_file);
606  fwrite(&(uhbd->idummy3), sizeof(int),1,output_file);
607  fwrite(&(uhbd->dim.i), sizeof(int),1,output_file);
608  fwrite(&(uhbd->dim.j), sizeof(int),1,output_file);
609  fwrite(&(uhbd->dim.k), sizeof(int),1,output_file);
610  fwrite(&(uhbd->spacing), sizeof(float),1,output_file);
611  fwrite(&(uhbd->o.x), sizeof(float),1,output_file);
612  fwrite(&(uhbd->o.y), sizeof(float),1,output_file);
613  fwrite(&(uhbd->o.z), sizeof(float),1,output_file);
614  fwrite(&(uhbd->dummy2), sizeof(float),1,output_file);
615  fwrite(&(uhbd->dummy3), sizeof(float),1,output_file);
616  fwrite(&(uhbd->dummy4), sizeof(float),1,output_file);
617  fwrite(&(uhbd->dummy5), sizeof(float),1,output_file);
618  fwrite(&(uhbd->dummy6), sizeof(float),1,output_file);
619  fwrite(&(uhbd->dummy7), sizeof(float),1,output_file);
620  fwrite(&(uhbd->idummy4), sizeof(int),1,output_file);
621  fwrite(&(uhbd->idummy5), sizeof(int),1,output_file);
622 
623  write_dtgrdfilebody_binary(output_file);
624  return 0;
625 }
626 
628 
634 template <typename T1>
636 {
637  char output_file_name [] = "sphere.grd"; // the input file name is not used! why? to be checked.
638  char Title [] = "Sphere ";
639 
640  float scale = 1.0, spacing = 0.1;
641  float dummy1 = 0.0, dummy2 = 0.0, dummy3 = 0.0, dummy4 = 0.0, dummy5 = 0.0, dummy6 = 0.0, dummy7 = 0.0;
642  float o_x = 0.0, o_y = 0.0, o_z = 0.0;
643  int idummy1 = 0, idummy2 = 0, idummy3 = 0, idummy4 = 0, idummy5 = 0;
644  int one = 1, dimi = LengthX, dimj = LengthY, dimk = LengthZ;
645 
646  std::cout << "Writing the DT-Grid (ASCII) to the output file ..." << std::endl;
647  fprintf(output_file, "%72s\n", Title);
648  fprintf(output_file, "%12.5E%12.5E%7d%7d%7d%7d%7d\n", scale, dummy1, 3, idummy1, idummy2, one, idummy3);
649  fprintf(output_file, "%7d%7d%7d%12.5E%12.5E%12.5E%12.5E\n", dimi, dimj, dimk, spacing, o_x, o_y, o_z);
650  fprintf(output_file, "%12.5E%12.5E%12.5E%12.5E\n", dummy2, dummy3, dummy4, dummy5);
651  fprintf(output_file, "%12.5E%12.5E%7d%7d\n", dummy6, dummy7, idummy4, idummy5);
652 
653  write_dtgrdfilebody_ascii(output_file);
654  return 0;
655 }
656 
658 
665 template <typename T1>
667 {
668  char Title [] = "Sphere ";
669 
670  float scale = 1.0, spacing = 0.1;
671  float dummy1 = 0.0, dummy2 = 0.0, dummy3 = 0.0, dummy4 = 0.0, dummy5 = 0.0, dummy6 = 0.0, dummy7 = 0.0;
672  float o_x = 0.0, o_y = 0.0, o_z = 0.0;
673  int idummy1 = 0, idummy2 = 0, idummy3 = 0, idummy4 = 0, idummy5 = 0;
674  int one = 1, dimi = LengthX, dimj = LengthY, dimk = LengthZ;
675 
676  int binary_dt_type = 2;
677  int flag_binary = 160;
678  std::cout << "Writing the DT-Grid to the output file ..." << std::endl;
679  fwrite(&flag_binary, sizeof(int),1,output_file);
680  fwrite(Title,sizeof(char), 72, output_file);
681  fwrite(&(scale), sizeof(float),1,output_file);
682  fwrite(&(dummy1), sizeof(float),1,output_file);
683  fwrite(&binary_dt_type, sizeof(int),1,output_file);
684  fwrite(&(idummy1), sizeof(int),1,output_file);
685  fwrite(&(idummy2), sizeof(int),1,output_file);
686  fwrite(&(one), sizeof(int),1,output_file);
687  fwrite(&(idummy3), sizeof(int),1,output_file);
688  fwrite(&(dimi), sizeof(int),1,output_file);
689  fwrite(&(dimj), sizeof(int),1,output_file);
690  fwrite(&(dimk), sizeof(int),1,output_file);
691  fwrite(&(spacing), sizeof(float),1,output_file);
692  fwrite(&(o_x), sizeof(float),1,output_file);
693  fwrite(&(o_y), sizeof(float),1,output_file);
694  fwrite(&(o_z), sizeof(float),1,output_file);
695  fwrite(&(dummy2), sizeof(float),1,output_file);
696  fwrite(&(dummy3), sizeof(float),1,output_file);
697  fwrite(&(dummy4), sizeof(float),1,output_file);
698  fwrite(&(dummy5), sizeof(float),1,output_file);
699  fwrite(&(dummy6), sizeof(float),1,output_file);
700  fwrite(&(dummy7), sizeof(float),1,output_file);
701  fwrite(&(idummy4), sizeof(int),1,output_file);
702  fwrite(&(idummy5), sizeof(int),1,output_file);
703  write_dtgrdfilebody_binary(output_file);
704  return 0;
705 }
706 
708 
713 template <typename T1>
715 {
716  //THE DT-GRID HEADER PART
717  fprintf(output_file, "%8d%12d\n", grid_type_flag, (int) Value.size());
718  fprintf(output_file, "%10d%10d%10d\n", (int) xcoord.size(), (int) ycoord.size(), (int) zcoord.size());
719  fprintf(output_file, "%10d%10d%10d\n", (int) acc.size(), (int) acc2D.size(), (int) acc3D.size());
720  fprintf(output_file, "%10d%10d\n", ((int) proj1D.size())+2, ((int) proj2D.size())+2);
721 
722  // DT-GRID FILE BODY TEXT
723  int counter;
724  typename std::vector<T1>::iterator itf;
725  std::vector<int>::iterator it;
726 
727  if (grid_type_flag == 1){
728  counter= 0;
729  for (itf = Value.begin(); itf != Value.end(); itf++){
730  fprintf(output_file, "\t%E", (float) *itf);
731  counter++;
732  if (counter == 6){
733  fprintf(output_file, "\n");
734  counter = 0;
735  }
736  }
737  fprintf(output_file, "\n");
738  }
739  else{
740  //no value to be written!
741  }
742 
743  counter = 0;
744  for (it = zcoord.begin(); it != zcoord.end(); it++){
745  fprintf(output_file, "\t%d", *it);
746  counter++;
747  if (counter == 12){
748  fprintf(output_file, "\n");
749  counter = 0;
750  }
751  }
752 
753  counter = 0;
754  fprintf(output_file, "\n");
755  for (it = acc.begin(); it != acc.end(); it++){
756  fprintf(output_file, "\t%d", *it);
757  counter++;
758  if (counter == 12){
759  fprintf(output_file, "\n");
760  counter = 0;
761  }
762  }
763 
764  counter = 0;
765  fprintf(output_file, "\n");
766  for (it = proj1D.begin(); it != proj1D.end(); it++){
767  if (fmod(counter,2) == 0)
768  fprintf(output_file, "\t%d", *it);
769  else
770  fprintf(output_file, "\t%d", (*it)/2);
771  counter++;
772  if (counter == 12){
773  fprintf(output_file, "\n");
774  counter = 0;
775  }
776  }
777 
778  it--;
779  it--;
780  fprintf(output_file, "\t%d", *it);
781  it++;
782  fprintf(output_file, "\t%d", (*it)/2+1);
783 
784  //fprintf(output_file, "\t%d", (int) Value.size());
785  //fprintf(output_file, "\t%d", ((int) zcoord.size())/2 - 1);
786 
787 
788  counter = 0;
789  fprintf(output_file, "\n");
790  for (it = ycoord.begin(); it != ycoord.end(); it++){
791  fprintf(output_file, "\t%d", *it);
792  counter++;
793  if (counter == 12){
794  fprintf(output_file, "\n");
795  counter = 0;
796  }
797  }
798 
799  counter = 0;
800  fprintf(output_file, "\n");
801  for (it = acc2D.begin(); it != acc2D.end(); it++){
802  fprintf(output_file, "\t%d", (*it)/2);
803  counter++;
804  if (counter == 12){
805  fprintf(output_file, "\n");
806  counter = 0;
807  }
808  }
809 
810  counter = 0;
811  fprintf(output_file, "\n");
812  for (it = proj2D.begin(); it != proj2D.end(); it++){
813  fprintf(output_file, "\t%d", (*it)/2);
814  counter++;
815  if (counter == 12){
816  fprintf(output_file, "\n");
817  counter = 0;
818  }
819  }
820 
821  it--;
822  it--;
823  fprintf(output_file, "\t%d", (*it)/2);
824  it++;
825  fprintf(output_file, "\t%d", (*it)/2+1);
826 
827  //fprintf(output_file, "\t%d", ((int) proj1D.size())/2);
828  //fprintf(output_file, "\t%d", ((int)ycoord.size())/2 - 1);
829 
830  counter = 0;
831  fprintf(output_file, "\n");
832  for (it = xcoord.begin(); it != xcoord.end(); it++){
833  fprintf(output_file, "\t%d", *it);
834  counter++;
835  if (counter == 12){
836  fprintf(output_file, "\n");
837  counter = 0;
838  }
839  }
840 
841  counter = 0;
842  fprintf(output_file, "\n");
843  for (it = acc3D.begin(); it != acc3D.end(); it++){
844  fprintf(output_file, "\t%d", (*it)/2);
845  counter++;
846  if (counter == 12){
847  fprintf(output_file, "\n");
848  counter = 0;
849  }
850  }
851  fprintf(output_file, "\n");
852  return 0;
853 }
854 
856 
861 template <typename T1>
863 {
864  //THE DT-GRID HEADER PART
865  int dt_header_buffer [10] = {grid_type_flag, (int) Value.size(), (int) xcoord.size(), (int) ycoord.size(), \
866  (int) zcoord.size(), (int) acc.size(), (int) acc2D.size(), (int) acc3D.size(), \
867  ((int) proj1D.size())+2, ((int) proj2D.size())+2};
868  fwrite(dt_header_buffer, sizeof(int), 10, output_file);
869 
870  // DT-GRID FILE BODY TEXT
871  typename std::vector<T1>::iterator itf;
872  std::vector<int>::iterator it;
873 
874  int counter;
875  float itf_val;
876  int it_val;
877 
878  if (grid_type_flag == 1){
879  itf_val = 0;
880  for (itf = Value.begin(); itf != Value.end(); itf++){
881  itf_val = (float) *itf;
882  fwrite(&itf_val, sizeof(float),1, output_file);
883  }
884  }
885  else{
886  //nothing to write for excluded volume grids!
887  }
888 
889  it_val = 0;
890  for (it = zcoord.begin(); it != zcoord.end(); it++){
891  it_val = *it;
892  fwrite(&it_val, sizeof(int),1, output_file);
893  }
894 
895  it_val = 0;
896  for (it = acc.begin(); it != acc.end(); it++){
897  it_val = *it;
898  fwrite(&it_val, sizeof(int),1, output_file);
899  }
900 
901  counter = 0;
902  it_val = 0;
903  for (it = proj1D.begin(); it != proj1D.end(); it++){
904  if (fmod(counter,2) == 0){
905  it_val = *it;
906  fwrite(&it_val, sizeof(int),1, output_file);
907  }
908  else{
909  it_val = *it / 2;
910  fwrite(&it_val, sizeof(int),1, output_file);
911  }
912  counter++;
913  }
914 
915  /*
916  * it--;
917  * it--;
918  * it_val = *it;
919  * it++;
920  * it_val = (*it)/2+1;
921  */
922 
923  it_val = (int) Value.size();
924  fwrite(&it_val, sizeof(int),1, output_file);
925 
926  it_val = ((int) zcoord.size() / 2) - 1;
927  fwrite(&it_val, sizeof(int),1, output_file);
928 
929  it_val = 0;
930  for (it = ycoord.begin(); it != ycoord.end(); it++){
931  it_val = *it;
932  fwrite(&it_val, sizeof(int),1, output_file);
933  }
934 
935  it_val = 0;
936  for (it = acc2D.begin(); it != acc2D.end(); it++){
937  it_val = *it / 2;
938  fwrite(&it_val, sizeof(int),1, output_file);
939  }
940 
941  it_val = 0;
942  for (it = proj2D.begin(); it != proj2D.end(); it++){
943  it_val = *it / 2;
944  fwrite(&it_val, sizeof(int),1, output_file);
945  }
946  /*
947  * it--;
948  * it--;
949  * it_val = *it / 2;
950  * it++;
951  * it_val = *it / 2 + 1;
952  */
953 
954  it_val = (int) proj1D.size() / 2;
955  fwrite(&it_val, sizeof(int),1, output_file);
956 
957  it_val = ((int) ycoord.size() / 2) - 1;
958  fwrite(&it_val, sizeof(int),1, output_file);
959 
960  it_val = 0;
961  for (it = xcoord.begin(); it != xcoord.end(); it++){
962  it_val = *it;
963  fwrite(&it_val, sizeof(int),1, output_file);
964  }
965 
966  it_val = 0;
967  for (it = acc3D.begin(); it != acc3D.end(); it++){
968  it_val = *it / 2;
969  fwrite(&it_val, sizeof(int),1, output_file);
970  }
971 
972  return 0;
973 }
974 
975 #endif /* DTGRD_HPP_ */
Define a 3D UHBD grid and functions to read-write its format files.
Definition: DTgrd.hpp:26
int LengthY
number of points along x axis (in uhbd grid)
Definition: DTgrd.hpp:38
int grid_type_flag
Definition: DTgrd.hpp:34
bool *** exterior_grid(bool ***)
Create the exterior grid.
Definition: DTgrd.hpp:292
std::vector< int > ycoord
icoord array (min and max indices of connected components in x direction)
Definition: DTgrd.hpp:46
int print_layer(bool ***, int, int)
Print a 2D slice for an exterior grid.
Definition: DTgrd.hpp:234
bool pqr_flag
0 for excluded volume, 1 for data grid
Definition: DTgrd.hpp:35
std::vector< int > acc
icoord array (min and max indices of connected components in z direction)
Definition: DTgrd.hpp:48
int write_dtgrdfilebody_binary(FILE *)
Write the DT-Grid body into the DT-Grid file in Binary format.
Definition: DTgrd.hpp:862
int LengthX
input pqr or pdb?
Definition: DTgrd.hpp:37
void exclusion(char *, float, float)
Create a UHBD object for excluded volume type interactions.
Definition: DTgrd.hpp:156
void UHBD_upload(char *, char *, float, float)
Create a UHBD object using the uhbd-file input.
Definition: DTgrd.hpp:131
DT_FILE(int)
DT_FILE constructor - 1.
Definition: DTgrd.hpp:80
int write_dtgrdfile_ascii_nouhbd(FILE *)
Write dt-grid file for test cases.
Definition: DTgrd.hpp:635
std::vector< int > proj2D
projection array to bridge 1D and 2D DT-Grids
Definition: DTgrd.hpp:52
int write_dtgrdfile_binary_nouhbd(FILE *)
Write dt-grid file for test cases.
Definition: DTgrd.hpp:666
int write_dtgrdfilebody_ascii(FILE *)
Write the DT-Grid body into the DT-Grid file in ASCII format.
Definition: DTgrd.hpp:714
std::vector< int > acc2D
acc pointer array for one dimensional DT-Grid
Definition: DTgrd.hpp:49
int write_dtgrdfile_ascii(FILE *)
Write the DT-Grid structure into the DT-Grid file in ASCII format.
Definition: DTgrd.hpp:565
std::vector< int > xcoord
'value' array of the DT-Grid
Definition: DTgrd.hpp:45
int check_neighbours(bool ***, bool ***, int, int, int)
projection array to bridge 2D and 3D DT-Grids
Definition: DTgrd.hpp:202
int write_dtgrdfile_binary(FILE *)
Write the DT-Grid structure into the DT-Grid file in binary format.
Definition: DTgrd.hpp:592
std::vector< int > zcoord
icoord array (min and max indices of connected components in y direction)
Definition: DTgrd.hpp:47
int uhbd_alloc
a uhbd object for the input UHBD file
Definition: DTgrd.hpp:42
std::vector< T1 > Value
Definition: DTgrd.hpp:44
std::vector< int > acc3D
acc pointer array for two dimensional DT-Grid
Definition: DTgrd.hpp:50
UHBD< T1 > * uhbd
number of points along z axis (in uhbd grid)
Definition: DTgrd.hpp:41
int Generate_DTGrid(bool ***, T1 ***)
Generate the DT-Grid structure!
Definition: DTgrd.hpp:394
std::vector< int > proj1D
acc pointer array for three dimensional DT-Grid
Definition: DTgrd.hpp:51
int LengthZ
number of points along y axis (in uhbd grid)
Definition: DTgrd.hpp:39
Definition: UHBDgrd.hpp:25
real(kind=8), parameter k
Definition: mod_gouy_chapman.f90:34
Imprint/Privacy