void full_free_atomgrp(struct atomgrp *ag)
{
	int i;
	for (i = 0; i < ag->natoms; i++)
		free_atom(ag->atoms + i);	// free bonded pointers of each atom
	free(ag->atoms);	// free all the atoms in the ag
	free(ag->activelist);	// free list of active atoms
	if (ag->nbact > 0)
		free(ag->bact);	// free active bond pointers
	free(ag->bonds);	// free bonds
	if (ag->nangact > 0)
		free(ag->angact);	// free active angle pointers
	free(ag->angs);		// free angles
	if (ag->ntoract > 0)
		free(ag->toract);	// free active torsion pointers
	free(ag->tors);		// free torsions
	if (ag->nimpact > 0)
		free(ag->impact);	// free active improper pointers
	free(ag->imps);		// free impropers
	if (ag->idres != NULL) {
		for (i = 0; i < ag->nres; i++)
			free(ag->idres[i]);	//free residue names
	}
	free(ag->idres);	//free pointers to residue names
	free(ag->iares);	//free array of first atom in residues
	free(ag->rot);
	free(ag->res_type);
	free(ag->atypenn);
	free(ag->atom_group_name);

	free(ag);		// free the ag itself
}
void full_free_atomgrp (struct atomgrp* ag)
{
        int i;
        for(i=0; i<ag->natoms; i++)
              free_atom(ag->atoms+i); // free bonded pointers of each atom
	free (ag->atoms); // free all the atoms in the ag
        free (ag->activelist);// free list of active atoms
        free (ag->bact); // free active bond pointers
        free (ag->bonds); // free bonds        
        free (ag->angact); // free active angle pointers
        free (ag->angs); // free angles
        free (ag->toract); // free active torsion pointers
        free (ag->tors); // free torsions
        free (ag->impact); // free active improper pointers
        free (ag->imps); // free impropers
        for(i=0; i<ag->nres; i++)
              free (ag->idres[i]);    //free residue names
        free (ag->idres);  //free pointers to residue names
        free (ag->iares);  //free array of first atom in residues 

	free (ag); // free the ag itself
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
  Atoms *atom;

  LatticeDim lattice_dim;
  Lattice *cpu_lattice;
  Vec3 min_ext, max_ext;	/* Bounding box of atoms */
  Vec3 lo, hi;			/* Bounding box with padding  */

  float h = 0.5f;		/* Lattice spacing */
  float cutoff = 12.f;		/* Cutoff radius */
  float exclcutoff = 1.f;	/* Radius for exclusion */
  float padding = 0.5f;		/* Bounding box padding distance */

  int n;

  struct pb_Parameters *parameters;
  struct pb_TimerSet timers;

  /* Read input parameters */
  parameters = pb_ReadParameters(&argc, argv);
  if (parameters == NULL) {
    exit(1);
  }

  /* Expect one input file */
  if (pb_Parameters_CountInputs(parameters) != 1) {
    fprintf(stderr, "Expecting one input file\n");
    exit(1);
  }

  pb_InitializeTimerSet(&timers);
  pb_SwitchToTimer(&timers, pb_TimerID_IO);

  {
    const char *pqrfilename = parameters->inpFiles[0];

    if (!(atom = read_atom_file(pqrfilename))) {
      fprintf(stderr, "read_atom_file() failed\n");
      exit(1);
    }
    printf("read %d atoms from file '%s'\n", atom->size, pqrfilename);
  }
  pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE);

  /* find extent of domain */
  get_atom_extent(&min_ext, &max_ext, atom);
  printf("extent of domain is:\n");
  printf("  minimum %g %g %g\n", min_ext.x, min_ext.y, min_ext.z);
  printf("  maximum %g %g %g\n", max_ext.x, max_ext.y, max_ext.z);

  printf("padding domain by %g Angstroms\n", padding);
  lo = (Vec3) {min_ext.x - padding, min_ext.y - padding, min_ext.z - padding};
  hi = (Vec3) {max_ext.x + padding, max_ext.y + padding, max_ext.z + padding};
  printf("domain lengths are %g by %g by %g\n", hi.x-lo.x, hi.y-lo.y, hi.z-lo.z);

  lattice_dim = lattice_from_bounding_box(lo, hi, h);
  cpu_lattice = create_lattice(lattice_dim);
  printf("\n");

  /*
   * CPU kernel
   */
  if (cpu_compute_cutoff_potential_lattice(cpu_lattice, cutoff, atom)) {
    fprintf(stderr, "Computation failed\n");
    exit(1);
  }

  /*
   * Zero the lattice points that are too close to an atom.  This is
   * necessary for numerical stability.
   */
  if (remove_exclusions(cpu_lattice, exclcutoff, atom)) {
    fprintf(stderr, "remove_exclusions() failed for cpu lattice\n");
    exit(1);
  }

  /* Print output */
  pb_SwitchToTimer(&timers, pb_TimerID_IO);
  if (parameters->outFile) {
    write_lattice_summary(parameters->outFile, cpu_lattice);
  }
  pb_SwitchToTimer(&timers, pb_TimerID_COMPUTE);

  /* Cleanup */
  destroy_lattice(cpu_lattice);
  free_atom(atom);

  pb_SwitchToTimer(&timers, pb_TimerID_NONE);
  pb_PrintTimerSet(&timers);
  pb_FreeParameters(parameters);

  return 0;
}