home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09964.iso / apps / ammp95.zip / VNOE.C < prev    next >
C/C++ Source or Header  |  1995-12-04  |  3KB  |  115 lines

  1. /* vnoe.c
  2. *
  3. *  build a virtual noe tree
  4. *
  5. *  scan an input structure and generate distance terms
  6. *  input a pdb file 
  7. *  input a close distance cut-off and a far distance cut-off
  8. *  
  9. *  generate noel terms with different formal short and long constants
  10. *
  11. *  skip
  12. *   hydrogens (?)
  13. *   0.,0.,0. atoms 
  14. */
  15. #include <stdio.h>
  16. #define ANSI 1
  17. /* misc includes - ANSI and some are just to be safe */
  18. #include <stdio.h>
  19. #include <ctype.h>
  20. #include <math.h>
  21. #include <string.h>
  22. #ifdef ANSI
  23. #include <stdlib.h>
  24. #endif
  25.  
  26. #define MAX_ATOM  800
  27.  
  28. #ifdef WINDOWS
  29. #endif
  30. int main()
  31. {
  32.     FILE *input,*output,*fopen();
  33.     char *fgets();
  34.     char keep[80],work[80]; /* buffers for reading */
  35.  
  36.     char aname[10],atype[MAX_ATOM][10];
  37.     int i,j,ifile;
  38.     int inres;
  39.     int myres[MAX_ATOM];
  40.     float x[MAX_ATOM], y[MAX_ATOM],z[MAX_ATOM], r;    
  41.     float r_out,r_in, dr;
  42.  
  43.     printf("Please enter the coordinate file name:\n");
  44. /* strip out the file name and put it in the right place for opening */
  45.           fgets( keep,80,stdin );
  46.           for(i= 0; i<80; i++)
  47.                      if( keep[i] != ' ') break;
  48.           for( ifile = i; ifile < 80 ; ifile++)
  49.                      {
  50.                      if( keep[ifile] == ' ' ) break;
  51.                      if( keep[ifile] == '\0' ) break;
  52.                      if( keep[ifile] == '\n' ) break;
  53.                      work[ifile -i ] = keep[ifile];
  54.                      work[ifile -i +1 ] = '\0';
  55.                      }
  56.     input = fopen( work, "r");
  57.  
  58.     printf("Please enter the output file name:\n");
  59. /* strip out the file name and put it in the right place for opening */
  60.           fgets( keep,80,stdin );
  61.           for(i= 0; i<80; i++)
  62.                      if( keep[i] != ' ') break;
  63.           for( ifile = i; ifile < 80 ; ifile++)
  64.                      {
  65.                      if( keep[ifile] == ' ' ) break;
  66.                      if( keep[ifile] == '\0' ) break;
  67.                      if( keep[ifile] == '\n' ) break;
  68.                      work[ifile -i ] = keep[ifile];
  69.                      work[ifile -i +1 ] = '\0';
  70.                      }
  71.     output = fopen( work, "w");
  72.  
  73.  
  74.     inres = 0;
  75.     while( fgets( keep,80,input) != NULL )
  76.     {
  77.     if( keep[0] == 'A' || keep[0] == 'H') 
  78.     {
  79.  
  80.     sscanf( &keep[22],"%d",&myres[inres]);
  81.           sscanf(&keep[29],"%f %f %f",&x[inres],&y[inres],&z[inres]);
  82.           sscanf(&keep[11],"%s",&atype[inres][0]);
  83. /*          sscanf(&keep[17],"%s",&aname[0]); */
  84. /* skip zeros */
  85.     if( x[inres] != 0. && y[inres] != 0. && z[inres] != 0.)
  86.     inres ++;
  87.  
  88.     } /* if ATOM or HETATM */
  89.     }/* end of the while( fgets())*/
  90.     fclose(input );
  91. /* now do the work */
  92. /* get r_in, r_out dr temp hard wire */
  93.     r_in = 4.; r_out = 15.; dr = 0.;
  94.     r_out *= r_out;
  95.     r_in *= r_in;
  96.     for( i=0; i< inres; i++)
  97.     {
  98.     fprintf( output,"serial i %d %s;\n", myres[i],&atype[i][0]);
  99.         for( j=i+1; j< inres; j++)
  100.         {
  101.         r  = (x[i]-x[j])*(x[i]-x[j]);
  102.         r += (y[i]-y[j])*(y[i]-y[j]);
  103.         r += (z[i]-z[j])*(z[i]-z[j]);
  104.     if( r >= r_in && r <= r_out)
  105.     {
  106.     fprintf( output,"serial j %d %s;\n", myres[j],&atype[j][0]);
  107.     r = sqrt(r);
  108.     fprintf( output,"noel i j %f %f %f klow khigh;\n", r,dr,dr);
  109.     } /* if(r >= ... */
  110.         }/* j */
  111.     }/* i */
  112.     fclose(output );
  113.  
  114. }/* end of main */
  115.