Example #1
0
int 
main (void)
{
    extern int Using_Main;	/* is main routine being called? */
    extern char *Graph_File_Name;	/* name of graph input file */
    extern char *Geometry_File_Name;	/* name of coordinate input file */
    extern char *Assign_In_File_Name;	/* name of assignment input input file */
    extern char *PARAMS_FILENAME;	/* name of file with parameter updates */
    extern double EIGEN_TOLERANCE;	/* tolerance for eigen calculations */
    extern int OUTPUT_ASSIGN;	/* whether to write assignment to file */
    extern int DEBUG_MEMORY;	/* debug memory allocation and freeing? */
    extern int DEBUG_TRACE;	/* trace main execution path */
    extern int DEBUG_PARAMS;	/* debug flag for reading parameters */
    extern long RANDOM_SEED;	/* seed for random number generators */
    extern int ECHO;		/* controls amount of output */
    extern int PROMPT;		/* prompt for input or not? */
    extern int PRINT_HEADERS;	/* print lines for output sections? */
    extern int MATCH_TYPE;      /* matching routine to call */
    extern double input_time;	/* times data file input */
    extern double start_time;	/* time partitioning starts */
    FILE     *fin;		/* input file */
    FILE     *fingeom;		/* geometry input file (for inertial method) */
    FILE     *finassign;	/* assignment file if reading in */
    FILE     *params_file;	/* file with parameter value updates */
    double   *goal;		/* desired set sizes */
    float    *x, *y, *z;	/* coordinates for inertial method */
    int      *start;		/* start of edge list for each vertex */
    int      *adjacency;	/* edge list data */
    float    *ewgts;		/* weights for all edges */
    int      *vwgts;		/* weights for all vertices */
    int       global_method;	/* global partitioning method */
    int       local_method;	/* local partitioning method */
    int    *assignment;	/* set number of each vtx (length nvtxs+1) */
    double    eigtol;		/* tolerance in eigenvector calculation */
    int       nvtxs;		/* number of vertices in graph */
    int       ndims;		/* dimension of recursive partitioning */
    int       architecture;	/* 0 => hypercube, d => d-dimensional mesh */
    int       ndims_tot;	/* total number of cube dimensions to divide */
    int       mesh_dims[3];	/* dimensions of mesh of processors */
    long      seed;		/* for random graph mutations */
    int       rqi_flag;		/* use RQI/Symmlq eigensolver? */
    int       vmax;		/* if so, how many vertices to coarsen down to? */
    int       igeom;		/* geometry dimension if inertial method */
    char      graphname[NAME_LENGTH];	/* name of graph input file */
    char      geomname[NAME_LENGTH];	/* name of geometry input file */
    char      inassignname[NAME_LENGTH];	/* assignment input file name */
    char      outassignname[NAME_LENGTH];	/* assignment output file name */
    char      outfilename[NAME_LENGTH];	/* name of output file */
    char     *outassignptr;	/* name or null pointer for output assignment */
    char     *outfileptr;	/* name or null pointer for output file */
    int       another;		/* run another problem? */
    double    time;		/* timing marker */
    int       flag;		/* return code from input routines */
    double    seconds();	/* returns elapsed time in seconds */
    int       affirm();
    int       input_graph(), input_geom();
    void      input_queries(), read_params(), clear_timing();

/*malloc_debug(2);*/

    if (DEBUG_TRACE > 0) {
	printf("<Entering main>\n");
    }

    if (PRINT_HEADERS) {
        printf("\n                    Chaco 2.0\n");
        printf("          Sandia National Laboratories\n\n");
    }

    Using_Main = TRUE;
    another = TRUE;
    params_file = fopen(PARAMS_FILENAME, "r");
    if (params_file == NULL && DEBUG_PARAMS > 1) {
	printf("Parameter file `%s' not found; using default parameters.\n",
	       PARAMS_FILENAME);
    }

    while (another) {

	start_time = time = seconds();

	x = y = z = NULL;
	goal = NULL;
	assignment = NULL;

	read_params(params_file);

	input_queries(&fin, &fingeom, &finassign, graphname, geomname, inassignname,
		      outassignname, outfilename,
		      &architecture, &ndims_tot, mesh_dims,
		      &global_method, &local_method, &rqi_flag, &vmax, &ndims);

	if (global_method == 7)
	    Assign_In_File_Name = inassignname;
	else
	    Assign_In_File_Name = NULL;

	if (OUTPUT_ASSIGN > 0)
	    outassignptr = outassignname;
	else
	    outassignptr = NULL;

	if (ECHO < 0)
	    outfileptr = outfilename;
	else
	    outfileptr = NULL;

	flag = input_graph(fin, graphname, &start, &adjacency, &nvtxs, &vwgts, &ewgts);
	if (flag) {
	    sfree(ewgts);
	    sfree(vwgts);
	    sfree(adjacency);
	    sfree(start);
	    goto skip;
	}

	Graph_File_Name = graphname;

	assignment = smalloc(nvtxs * sizeof(int));
	if (global_method == 7) {
	    flag = input_assign(finassign, inassignname, nvtxs, assignment);
	    if (flag)
		goto skip;
	    Assign_In_File_Name = inassignname;
	}

	if (global_method == 3 ||
	    (MATCH_TYPE == 5 && (global_method == 1 || 
				 (global_method == 2 && rqi_flag)))) {
	    /* Read in geometry data. */
	    flag = input_geom(fingeom, geomname, nvtxs, &igeom, &x, &y, &z);
	    if (flag)
		goto skip;
	    Geometry_File_Name = geomname;
	}
	else {
	    x = y = z = NULL;
	}

	input_time += seconds() - time;

	eigtol = EIGEN_TOLERANCE;
	seed = RANDOM_SEED;

	interface(nvtxs, start, adjacency, vwgts, ewgts, x, y, z,
		  outassignptr, outfileptr,
		  assignment,
		  architecture, ndims_tot, mesh_dims, goal,
		  global_method, local_method, rqi_flag, vmax, ndims,
		  eigtol, seed);

skip:
	if (global_method == 3) {
	    if (z != NULL)
		sfree(z);
	    if (y != NULL)
		sfree(y);
	    if (x != NULL)
		sfree(x);
	}
	sfree(assignment);

	if (DEBUG_MEMORY > 0) {
	    printf("\n");
	}

	if (PROMPT) {
	    another = affirm("\nRun Another Problem");
	}
	else {
	    another = affirm("");
	}
	if (another) {
	    clear_timing();
	    printf("\n------------------------------------------------\n\n");
	    fflush(stdout);
	}
    }
    if (params_file != NULL)
	fclose(params_file);

    if (DEBUG_TRACE > 1) {
	printf("<Leaving main>\n");
    }
    
    return(0);
}
Example #2
0
int main (int argc, char *argv[]) {
  static char usage[] = {
      "Calculate positions of pseudo-atoms in a model for a transmembrane channel and\n" 
      "write output to FILE or pore.pdb and pore.itp.\n\n"
      "  -h\t\t show help\n"
      "  -v\t\t be verbose (= -debuglevel 30 )\n"
      "  -debug <NUM>\t set debuglevel (0..100)\n"
      "  -spec <NUM>\t default species id\n"
      "  -showspec\t show hard coded species\n\n"
      "  -o FILE\t pdb coordinate file\n"
      "  -s FILE\t itp topology file\n"
      "\n"
      "  -f <file>\t read pore description from file (see below)\n"
      "  -R <r>\t Outer radius of the model\n"
      "  -P <r> <l>\t Pore region: inner radius and length\n"
      "  -M <r> <l>\t Mouth region: largest inner radius and length\n"
      "  -b dmin dmax g_min g_max   (repeatable)\n"
      "\t\tform bonds with angle gamma when atoms are no further apart\n"
      "\t\tthan dmax Ang and g_min <= gamma <= g_max, g from [0°..90°] )\n"
      "  -c\t\t only write connectivity to output, no bond length or kB, kA\n" 
      "  -x\t\t neither connectivity nor bond length to output (isolated atoms)\n" 
      "  -kB <c>\t Force constant of bonds, in kJ mol^-1 nm^-2\n"
      "  -kA <c>\t Force constant of angles, in kJ mol^-1 rad^-2\n"
      "  -cc\t\t Center ccordinates on cavitybox, not on unitcell\n"
      "\n"
      "Pore volume calculation (setting any of these switches on profile calculation):\n"
      "In order to enable volume calculation, set -volume explicitly!\n"
      "ATTENTION: all these LENGTHs are in NANO METRE not Angstrom !\n"
      "  -profile [<file>]  calculate the profile in addition to the volume\n"
      "  -z1, -z2 <z>       profile between z1 and z2\n"
      "  -Rmax <r>          integrate out to Rmax (also use for the total volume\n"
      "                     integration if -profile is set)\n"
      "  -npoints <N>       number of points per dimension in the integrals\n"
      "  -T temp            Temperature in Kelvin [300]\n"
      "  -wca               If set, only use the repulsive part of the Lennard-Jones\n"
      "                     potential (split after Weeks, Chandler & Andersen [1971])\n"
      "  -plot              xfarbe output of the potential in z slices\n"
      "  -nzplot            number of plot slices \n"
      "\nDescription of the input file:\n"
      "------------------------------\n"
      "Instead of using -R (RADIUS), -M (MOUTH), and -P (PORE) one can describe the system\n"
      "in a more flexible manner with a geometry in put file. It can contain up to "
      "MAXDOMAINS domains (i.e. MOUTH and PORE lines). Allowed lines:\n"
      "# comment (skipped)\n"
      "# RADIUS is the global outer radius (in Angstrom)  of the cylinder\n"
      "RADIUS r_outer\n"
      "# domain type and radius at the upper and lower end of the domain;\n"
      "# r_lower of domain i and r_upper of domain i+1 are typically identical\n"
      "MOUTH r_upper r_lower length [species]\n"
      "PORE  r_upper r_lower length [species]\n"

      
  };
  int i, n_atoms, n_bonds, n_angles, n_bc;
  int error;
  real vol;
  FILE *fp;

  /* 
     segmentation fault if arrays to large 
     --->> 
           now that I have learned to  calloc I should rewrite this 
           on purely aesthetical grounds !
     <<---- 
  */
  struct pdb_ATOM model[TOTALSITES];
  struct itp_bond bonds[MAXBONDS]; 
  struct itp_angle angles[MAXANGLES];
  struct geom geometry;
  struct std_input in;
  struct potpars  potential = {
    NULL,
    TEMPERATURE,
    NFREEDOM_SPC,
    CSIX_OW_MTH, CTWELVE_OW_MTH, 0.0,
    0, NULL, NULL,
    N_GAUSSLEG
  };
  struct pprofile profile = {
    "LJprofile.dat",
    FALSE,
    FALSE,
    POT_PLOT_SLICES,
    NULL,
    NZPROF,
    1.5,
    -2,2,
    NULL
  };

  /* argument processing */
  /* *** no sanity checks *** */

  n_atoms  = 0;  /* number of sites ('atoms') in the model */
  n_bonds  = 0;  /* number of bonds */
  n_angles = 0;  /* number of angles between bonds */
  n_bc     = 0;  /* number of constraint conditions for generating bonds */

  if (argc < 2) {
    printf("Running with default values.\n\nType %s -h for help.\n", argv[0]);
    debuglevel = IMPORTANT;
  };

  /* initialize defaults */
  in = default_input ();
  potential.u1 = vljcyl;     /* use the full Lennard-Jones potential in
                               the configurational volume calculations
                               by default */
  profile.pp = &potential;

  /* rudimentary opt-processing.. yarch */
  for (i = 1; i < argc; i++)
    {
      if (!strcmp(argv[i], "-debug")) { 
	debuglevel = atoi(argv[++i]);
      } else if (!strcmp(argv[i], "-v")) {
	debuglevel = VERBOSE; 
      } else if (!strcmp(argv[i], "-h")) {
	print_usage(argv[0],usage);
	exit(1);
      } else if (!strcmp(argv[i], "-showspec")) {
	print_species ();
	exit(1);
      } else if (!strcmp(argv[i], "-o")) {
	in.coordfile = argv[++i]; 
      } else if (!strcmp(argv[i], "-s")) {
	in.topofile = argv[++i];
      } else if (!strcmp(argv[i], "-f")) {
	in.datafile = argv[++i]; 
      } else if (!strcmp(argv[i], "-R")) {
	in.r_outer = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-M")) {
	in.r_mouth = atof(argv[++i]);
	in.l_mouth = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-P")) {
	in.r_pore = atof(argv[++i]);
	in.l_pore = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-spec")) {
	in.specid = atoi(argv[++i]);
      } else if (!strcmp(argv[i], "-b")) {
	if (n_bc > MAXBONDCONSTRAINTS) {
	  fatal_error (1,
		       "Error: too many bond constraints, maximum is %d.\n",  
		       MAXBONDCONSTRAINTS);
	}
	in.bc[n_bc].serial    = n_bc;
	in.bc[n_bc].dmin      = atof(argv[++i]);
	in.bc[n_bc].dmax      = atof(argv[++i]);
	in.bc[n_bc].gamma_min = atof(argv[++i]);
	in.bc[n_bc].gamma_max = atof(argv[++i]);
	in.n_bc               = ++n_bc;
      } else if (!strcmp(argv[i], "-c")) {
	in.connectonly  = TRUE;
      } else if (!strcmp(argv[i], "-x")) {
	in.atomsonly    = TRUE;
      } else if (!strcmp(argv[i], "-cc")) {
	in.shiftcbox    = TRUE;
      } else if (!strcmp(argv[i], "-kB")) {
	in.k_bond  = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-kA")) {
	in.k_angle = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-volume")) {
	profile.bSet = TRUE;
      } else if (!strcmp(argv[i], "-z1")) {
	profile.bSet = TRUE;
	profile.z1 = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-z2")) {
	profile.bSet = TRUE;
	profile.z2 = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-Rmax")) {
	profile.bSet = TRUE;
	profile.Rmax = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-profile")) {
	profile.bSet = TRUE;
	if (i < argc-1 && argv[i+1][0] != '-') 
	  strncpy(profile.fn,argv[++i],STRLEN);
      } else if (!strcmp(argv[i], "-npoints")) {
	potential.ngaussleg = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-T")) {
	potential.Temp = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-wca")) {
	potential.u1 = vRljcyl;
      } else if (!strcmp(argv[i], "-plot")) {
	profile.bPlot = TRUE;
      } else if (!strcmp(argv[i], "-nzplot")) {
	profile.bPlot = TRUE;
	profile.nzplot = atoi(argv[++i]);
      } else {
	mesg(OFF,"Unknown option: %s",argv[i]);
      };
    };

  mesg (ALL, "TOTALSITES %d\n", TOTALSITES);
  mesg (ALL,
   "MAXBONDS %d\nsizeof struct bond %d, sizeof bonds[] %d\n", 
    MAXBONDS, sizeof (struct itp_bond), sizeof (bonds));
  mesg (ALL, 
   "MAXANGLES %d\nsizeof struct angle %d, sizeof angles[] %d\n", 
    MAXANGLES, sizeof (struct itp_angle), sizeof (angles));



  error = input_geom (&in, &geometry);
  setup_domain (&geometry);
  unitcell  (&geometry);
  cavitybox (&geometry);

  n_atoms  = do_coordinates (model, &geometry);

  if (!geometry.atomsonly) {
    n_bonds  = do_bonds (bonds, model, &geometry);
    n_angles = do_angles (angles, bonds, &geometry);
  } else {
    n_bonds = n_angles = 0;
  }

  print_geom (&geometry);    
  
  mesg (WARN, "\nNumber of sites:  %d", n_atoms);
  if (!geometry.atomsonly) {
    mesg (WARN, 
    "Number of bonds:  %d within max cut-off %5.2f Ang (no double-counting)", 
	n_bonds, find_dmax (geometry.bc, geometry.nbc));
    mesg (WARN, "Number of angles: %d (no double-counting)\n", n_angles);
  }

  center (model, &geometry);
  
  error = write_topology (model, bonds, angles, &geometry);
  error = write_pdb (model, bonds, &geometry);

  /* 
     calculate pore volume, based on J. S. Rowlinson, J Chem Soc,
     Faraday Trans. 2, 82 (1986), 1801, (which didnt really work), and
     discussion with Andrew Horsefield.  */

  if (profile.bSet) {
    vol = volume(&potential,model,geometry.domain[1],&profile);

    /* pore profile (already calculated in volume ) */
    fp=fopen(profile.fn,"w");
    if (fp) {
      for(i=0;i<NZPROF;i++) {
        fprintf(fp,"%f  %f\n",profile.r[i][0],profile.r[i][1]);
      }
      fclose(fp);
    }
    free(profile.r);
  }

  return error < 0 ? 1 : 0;
};