CCL Home Page
Up Directory CCL write_geo
#include "utility.h"
#include "newgeo.h"

int write_geo(geo_type)
/*============================================================================*/
/* FILENAME: WRITE_GEO.C
/* WRITTEN: J.R.HURST
/* MODIFICATIONS:
/*	12 OCT 1993 MVG: ADDED WRITE_GENERIC_CART.
/*	 2 APR 1992 MVG: ADDED WRITE_SYBYL_MOL2.
*/
  int geo_type;		/* Type of geometry */
  {
  char line[130];	/* Multipurpose character string */
  FILE* outfile;	/* file for input of structure */
  int i;		/* loop variable */
  char prompt[80];
  char rawfile[130];	/* COPY OF RAW FILENAME AS ENTERED BY USER. */
  int status;
  char message[100];	/* ERROR MESSAGE. */

  void exit();

  /* QUERY USER FOR THE TYPE OF GEO FILE TO BE WRITTEN IF NOT EXPRESS MODE. */
  if (!express_mode)
    {
    if ((geo_type=get_output_type()) == TYPE_NONE) return(0);
    }

  /* GENERATE THE DEFAULT OUTPUT FILE NAME FROM THE INPUT FILE NAME. */
  strcpy(output_file_name,input_file_name);	/* START WITH THE INPUT FILE NAME. */
  if (geo_type==TYPE_AMPAC_INTERNAL || geo_type==TYPE_AMPAC_CART) new_extension(output_file_name,".ampac");
  else if (geo_type==TYPE_MOPAC_INTERNAL || geo_type==TYPE_MOPAC_CART) new_extension(output_file_name,".mopac");
  else if (geo_type==TYPE_CADPAC_INTERNAL || geo_type==TYPE_CADPAC_CART) new_extension(output_file_name,".i");
  else if (geo_type==TYPE_GAUSSIAN_INTERNAL) new_extension(output_file_name,".i");
  else if (geo_type==TYPE_SYBYL_MOL) new_extension(output_file_name,".mol");
  else if (geo_type==TYPE_SYBYL_MOL2) new_extension(output_file_name,".mol2");
  else if (geo_type==TYPE_PRDDOE_INPUT) new_extension(output_file_name,".ext");
  else if (geo_type==TYPE_MM2_INPUT) new_extension(output_file_name,".mm2");
  else if (geo_type==TYPE_MM3_INPUT) new_extension(output_file_name,".mm3");
  else if (geo_type==TYPE_UNICHEM_STRUCTURE) new_extension(output_file_name,".ucm");
  else if (geo_type==TYPE_MACROMODEL_STRUCTURE) new_extension(output_file_name,".mmod");
  else if (geo_type==TYPE_GENERIC_CART) new_extension(output_file_name,".cart");
  else new_extension(output_file_name,".unknown");

  /* QUERY USER FOR THE FILE NAME TO BE WRITTEN IF NOT EXPRESS MODE. */
  if (!express_mode)
    {
    printf("\n");
    strcpy(prompt,"Enter file name to write [");
    strcat(prompt,output_file_name);
    strcat(prompt,"]");
    status=gstring(prompt,NULL_OK,line);
    if (status==ABORT_ENTRY) return(0);
    else if (status==NULL_ENTRY) strcpy(rawfile,output_file_name);
    else strcpy(rawfile,line);	/* SAVE THE RAW FILENAME. */
    }
  else strcpy(rawfile,output_file_name);

  /* WRITE OUT THE FILE ACCORDING TO THE GEOMETRY TYPE. */
  switch(geo_type)
    {
    case TYPE_SYBYL_MOL:
      if ((outfile=file_opened(rawfile,".mol","w",output_file_name))==NULL)
        {
        sprintf(message,"File %s could not be opened",output_file_name);
        return(errmsg(message,FALSE));
        }
      if (write_sybyl_mol(outfile)) break;
      else return(FALSE);

    case TYPE_SYBYL_MOL2:
      if ((outfile=file_opened(rawfile,".mol2","w",output_file_name))==NULL)
        {
        sprintf(message,"File %s could not be opened",output_file_name);
        return(errmsg(message,FALSE));
        }
      if (write_sybyl_mol2(outfile)) break;
      else return(FALSE);

    case TYPE_MM2_INPUT:
      if ((outfile=file_opened(rawfile,".mm2","w",output_file_name))==NULL)
        {
        sprintf(message,"File %s could not be opened",output_file_name);
        return(errmsg(message,FALSE));
        }
      if (write_mm2_input(TYPE_MM2_INPUT,outfile)) break;
      else return(FALSE);

    case TYPE_MM3_INPUT:
      if ((outfile=file_opened(rawfile,".mm3","w",output_file_name))==NULL)
        {
        sprintf(message,"File %s could not be opened",output_file_name);
        return(errmsg(message,FALSE));
        }
      if (write_mm2_input(TYPE_MM3_INPUT,outfile)) break;
      else return(FALSE);

    default:
      printf("Error: Unknown geo_type (%d) in write_geo.\n",geo_type);
      exit(PROGRAM_FAILED);
    }

  if (geo_type!=TYPE_PRDDOE_INPUT) fclose(outfile);

  return(TRUE);
  }

int get_output_type()
/*============================================================================*/
  {
  int status;
  char choice;

  void clear_screen();		/* CLEAR SCREEN, POSSIBLY DISPLAY FILES. */

  /* SELECT AN OUTPUT GEOMETRY FILE TYPE TO WRITE. */
  clear_screen(NO_DISPLAY_FILES);
  if (!express_mode) printf("              === WRITE A FILE ===\n\n");
  else printf("     === EXPRESS MODE OUTPUT FILE TYPE SELECTION ===\n\n");
  printf("A) SYBYL mol file\n");
  printf("B) CADPAC internal coordinates input file\n");
  printf("C) CADPAC cartesian coordinates input file\n");
  printf("D) AMPAC internal coordinates input file\n");
  printf("E) AMPAC cartesian coordinates input file\n");
  printf("F) MOPAC internal coordinates input file\n");
  printf("G) MOPAC cartesian coordinates input file\n");
  printf("H) GAUSSIAN internal coordinates input file\n");
  printf("I) PRDDOE input file\n");
  printf("J) MM2 input file\n");
  printf("K) MM3 input file\n");
  printf("L) UNICHEM structure file\n");
  printf("M) MACROMODEL structure file\n");
  printf("N) SYBYL mol2 file\n");
  printf("O) Generic cartesian coordinate file\n\n");

  if (!express_mode) gchoice("Enter file type to write","abcdefghijklmno",NULL_NOT_OK,&choice);
  else gchoice("Enter output type of all files on command line","abcdefghijklmno",NULL_NOT_OK,&choice);

  /* DETERMINE WHICH OPTION WAS CHOSEN. */
  if (choice=='A') return(TYPE_SYBYL_MOL);
  else if (choice=='B') return(TYPE_CADPAC_INTERNAL);
  else if (choice=='C') return(TYPE_CADPAC_CART);
  else if (choice=='D') return(TYPE_AMPAC_INTERNAL);
  else if (choice=='E') return(TYPE_AMPAC_CART);
  else if (choice=='F') return(TYPE_MOPAC_INTERNAL);
  else if (choice=='G') return(TYPE_MOPAC_CART);
  else if (choice=='H') return(TYPE_GAUSSIAN_INTERNAL);
  else if (choice=='I') return(TYPE_PRDDOE_INPUT);
  else if (choice=='J') return(TYPE_MM2_INPUT);
  else if (choice=='K') return(TYPE_MM3_INPUT);
  else if (choice=='L') return(TYPE_UNICHEM_STRUCTURE);
  else if (choice=='M') return(TYPE_MACROMODEL_STRUCTURE);
  else if (choice=='N') return(TYPE_SYBYL_MOL2);
  else if (choice=='O') return(TYPE_GENERIC_CART);
  else return(TYPE_NONE);
  }
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 4641 times since Sat Apr 17 21:58:50 1999 GMT