Example #1
0
void electric_point_charge(struct Structure This_Structure, float grid_span, int grid_size, float *grid) {
    /************/

    /* Counters */

    int residue, atom;

    /* Co-ordinates */

    int x, y, z;
    int x_low, x_high, y_low, y_high, z_low, z_high;

    float a, b, c;
    float x_corner, y_corner, z_corner;
    float w;

    /* Variables */

    float one_span;

    /************/

    for (x = 0; x < grid_size; x++) {
        for (y = 0; y < grid_size; y++) {
            for (z = 0; z < grid_size; z++) {
                grid[gaddress(x, y, z, grid_size)] = (float)0;
            }
        }
    }

    /************/

    one_span = grid_span / (float)grid_size;

    for (residue = 1; residue <= This_Structure.length; residue++) {
        for (atom = 1; atom <= This_Structure.Residue[residue].size; atom++) {
            if (This_Structure.Residue[residue].Atom[atom].charge != 0) {
                x_low = gord(This_Structure.Residue[residue].Atom[atom].coord[1] - (one_span / 2),
                             grid_span,
                             grid_size);
                y_low = gord(This_Structure.Residue[residue].Atom[atom].coord[2] - (one_span / 2),
                             grid_span,
                             grid_size);
                z_low = gord(This_Structure.Residue[residue].Atom[atom].coord[3] - (one_span / 2),
                             grid_span,
                             grid_size);

                x_high = x_low + 1;
                y_high = y_low + 1;
                z_high = z_low + 1;

                a = This_Structure.Residue[residue].Atom[atom].coord[1] -
                    gcentre(x_low, grid_span, grid_size) - (one_span / 2);
                b = This_Structure.Residue[residue].Atom[atom].coord[2] -
                    gcentre(y_low, grid_span, grid_size) - (one_span / 2);
                c = This_Structure.Residue[residue].Atom[atom].coord[3] -
                    gcentre(z_low, grid_span, grid_size) - (one_span / 2);

                for (x = x_low; x <= x_high; x++) {
                    x_corner = one_span * ((float)(x - x_high) + .5);

                    for (y = y_low; y <= y_high; y++) {
                        y_corner = one_span * ((float)(y - y_high) + .5);

                        for (z = z_low; z <= z_high; z++) {
                            z_corner = one_span * ((float)(z - z_high) + .5);

                            w = ((x_corner + a) * (y_corner + b) * (z_corner + c)) /
                                (8.0 * x_corner * y_corner * z_corner);

                            grid[gaddress(x, y, z,
                                          grid_size)] +=
                                (float)(w * This_Structure.Residue[residue].Atom[atom].charge);
                        }
                    }
                }
            }
        }
    }

    /************/
}
Example #2
0
void discretise_structure( struct Structure This_Structure , float grid_span , int grid_size , float *grid ) {

/************/

  /* Counters */

  int	residue , atom ;

  /* Co-ordinates */

  int	x , y , z ;
  int	steps , x_step , y_step , z_step ;

  float		x_centre , y_centre , z_centre ;

  /* Variables */

  float         distance , one_span ;

/************/

  one_span = grid_span / (float)grid_size ;

  distance = 1.8 ;

/************/

  for( x = 0 ; x < grid_size ; x ++ ) {
    for( y = 0 ; y < grid_size ; y ++ ) {
      for( z = 0 ; z < grid_size ; z ++ ) {

        grid[gaddress(x,y,z,grid_size)] = (float)0 ;

      }
    }
  }

/************/

  steps = (int)( ( distance / one_span ) + 1.5 ) ;

  for( residue = 1 ; residue <= This_Structure.length ; residue ++ ) {
    for( atom = 1 ; atom <= This_Structure.Residue[residue].size ; atom ++ ) {

      x = gord( This_Structure.Residue[residue].Atom[atom].coord[1] , grid_span , grid_size ) ;
      y = gord( This_Structure.Residue[residue].Atom[atom].coord[2] , grid_span , grid_size ) ;
      z = gord( This_Structure.Residue[residue].Atom[atom].coord[3] , grid_span , grid_size ) ;

      for( x_step = max( ( x - steps ) , 0 ) ; x_step <= min( ( x + steps ) , ( grid_size - 1 ) ) ; x_step ++ ) {

        x_centre  = gcentre( x_step , grid_span , grid_size ) ;

        for( y_step = max( ( y - steps ) , 0 ) ; y_step <= min( ( y + steps ) , ( grid_size - 1 ) ) ; y_step ++ ) {

          y_centre  = gcentre( y_step , grid_span , grid_size ) ;

          for( z_step = max( ( z - steps ) , 0 ) ; z_step <= min( ( z + steps ) , ( grid_size - 1 ) ) ; z_step ++ ) {

            z_centre  = gcentre( z_step , grid_span , grid_size ) ;

            if( pythagoras( This_Structure.Residue[residue].Atom[atom].coord[1] , This_Structure.Residue[residue].Atom[atom].coord[2] , This_Structure.Residue[residue].Atom[atom].coord[3] , x_centre , y_centre , z_centre ) < distance ) grid[gaddress(x_step,y_step,z_step,grid_size)] = (float)1 ;

          }
        }
      }

    }
  }

/************/

  return ;

}
Example #3
0
File: geo.c Project: mmase/wgrib2
double *gauss2lats(int nlat, double *ylat) {
  
  const double xlim = 1.0E-7;
  
  double *cosc  = (double *) malloc(sizeof(double) * (nlat + 1));
  double *sinc  = (double *) malloc(sizeof(double) * (nlat + 1));
  double *colat = (double *) malloc(sizeof(double) * (nlat + 1));
  
  int nzero = (nlat / 2);
  
  int i;
  double fi = nlat;
  double fi1 = fi + 1.0;
  double a = fi * fi1/sqrt(4.0*fi1*fi1 - 1.0);
  double b = fi1 * fi/sqrt(4.0*fi*fi - 1.0);

    double g, gm, gp, gt, delta, d;

  for (i = 1; i <= nzero; i++) {
    cosc[i] = sin((i - 0.5)*M_PI/nlat + M_PI*0.5);
  }
  
  for (i = 1; i <= nzero; i++) {
    g = gord(nlat, cosc[i]);
    gm = gord(nlat - 1, cosc[i]);
    gp = gord(nlat + 1, cosc[i]);
    gt = (cosc[i]*cosc[i] - 1.0)/(a * gp - b * gm);
    delta = g*gt;
    cosc[i] = cosc[i] - delta;
    
    while ( fabs(delta) > xlim ) {
      g = gord(nlat,cosc[i]);
      gm = gord(nlat - 1, cosc[i]);
      gp = gord(nlat + 1, cosc[i]);
      gt = (cosc[i]*cosc[i] - 1.0)/(a * gp - b * gm);
      delta = g*gt;
      cosc[i] = cosc[i] - delta;
      
    } /* end while */
    
  } /* end for */
  
  for (i = 1; i <= nzero; i++) {
    colat[i] = acos(cosc[i]);
    sinc[i] = sin(colat[i]);
  }
  
  /*
   * ... deal with equator if odd number of points
   */
  if ( ( nlat % 2) != 0 ) {
    i = nzero + 1;
    cosc[i] = 0.0;
    d = gord(nlat - 1, cosc[i]);
    d = d*d*fi*fi;
    colat[i] = M_PI * 0.5;
    sinc[i] = 1.0;
  } /* end if() */
  
  /*
   *  ... deal with southern hemisphere by symmetry
   */
  for (i = nlat - nzero + 1; i <= nlat; i++) {
    cosc[i]  = -cosc[nlat + 1 - i];
    colat[i] = M_PI - colat[nlat + 1 - i];
    sinc[i]  = sinc[nlat + 1 - i];
  } /* end for(i) */
  
  for (i = 1; i <= nlat; i++) {
    ylat[i-1] = todegrees(acos(sinc[i]));
    if ( i > (nlat / 2) ) ylat[i-1] = -ylat[i-1];
    /* change from N-S to S-N */
    ylat[i-1] = -ylat[i-1];
  }

  free(cosc);
  free(sinc);
  free(colat);
  
  return ylat;
  
} /* end gauss2lats() */