• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

tools/mesh/dx2mol.c

00001 
00002 /* ///////////////////////////////////////////////////////////////////////////
00003 // File:     dx2mol.c
00004 //
00005 // Purpose:  Convert OpenDx format potential to MolMol format
00006 //
00007 // Author:   Jung-Hsin Lin (bits added/modified by Nathan Baker)
00008 //           Additional changes by Fred Damberger
00009 //
00010 // rcsid="$Id: dx2mol.c 1154 2007-10-08 20:20:27Z sobolevnrm $"
00012 
00013 #include "apbscfg.h"
00014 #include "maloc/maloc.h"
00015 #include "apbs/apbs.h"  
00016 
00017 VEMBED(rcsid="$Id: dx2mol.c 1154 2007-10-08 20:20:27Z sobolevnrm $")
00018 
00019 int main(int argc, char **argv) {
00020 
00021     /* *************** VARIABLES ******************* */
00022     int u, i, j, k, nx, ny, nz;
00023     int n;
00024     double avg;
00025     double hy, hx, hzed, xmin, ymin, zmin;
00026     Vio *sock;
00027     Vgrid *grid;
00028     char *inpath = VNULL;
00029     char *outpath = VNULL;
00030     char *iodev = "FILE";
00031     char *iofmt = "ASC";
00032     char *thost = VNULL;
00033     char *usage = "\n\n\
00034     -----------------------------------------------------------------------\n\
00035     dx2mol (Contributed by Jung-Hsin Lin)\n\
00036     \n\
00037     For converting the OpenDX format of the electrostatic potential to the\n\
00038     MOLMOL format. MOLMOL is a popular free molecular display program\n\
00039     (http://www.mol.biol.ethz.ch/wuthrich/software/molmol/).\n\
00040     \n\
00041     Usage:  dx2mol file1.dx file2.pot\n\
00042             where file1.dx is a file in OpenDX format and file2.pot is the\n\
00043             file to be written in MOLMOL format.\n\
00044     -----------------------------------------------------------------------\n\
00045     \n";
00046  
00047  
00048     /* *************** CHECK INVOCATION ******************* */
00049     Vio_start();
00050     if (argc != 3) {
00051         Vnm_print(2, "\n*** Syntax error: got %d arguments, expected 3.\n\n",argc);
00052         Vnm_print(2,"%s\n", usage);
00053         return -1;
00054     } else {
00055         inpath = argv[1];
00056         outpath = argv[2];
00057     }
00058 
00059     /* Read DX format file */ 
00060     grid = Vgrid_ctor(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, VNULL);
00061     Vgrid_readDX(grid, "FILE", "ASC", VNULL, inpath);
00062     nx = grid->nx;
00063     ny = grid->ny;
00064     nz = grid->nz;
00065     hx = grid->hx;
00066     hy = grid->hy;
00067     hzed = grid->hzed;
00068     xmin = grid->xmin;
00069     ymin = grid->ymin;
00070     zmin = grid->zmin;
00071 
00072     /* Intialize socket for writing */
00073     sock = Vio_ctor(iodev,iofmt,thost, outpath, "w");
00074     if (sock == VNULL) {
00075         Vnm_print(2, "Problem opening virtual socket %s\n",
00076           outpath);
00077         return -1;
00078     }
00079     if (Vio_connect(sock, 0) < 0) {
00080         Vnm_print(2, "Problem connecting virtual socket %s\n",
00081           outpath);
00082         return -1;
00083     }
00084 
00085     /* Write out data */
00086     Vio_printf(sock, "%8.3f %4d %5.3f\n",xmin,nx,hx); 
00087     Vio_printf(sock, "%8.3f %4d %5.3f\n",ymin,ny,hy); 
00088     Vio_printf(sock, "%8.3f %4d %5.3f\n",zmin,nz,hzed); 
00089 
00090     n = 0;
00091     for (k=0; k<nz; k++) {
00092         for (j=0; j<ny; j++) {
00093             for (i=0; i<nz; i++) {
00094                 n++;
00095                 u = nx*ny*k + nx*j + i;
00096                 Vio_printf(sock, "%10.3e ", grid->data[u]);
00097                 if (n == 10) {
00098                     Vio_printf(sock, "\n");
00099                     n = 0;
00100                 }
00101             }
00102         }
00103     }
00104 
00105     /* Close off the socket */
00106     Vio_connectFree(sock);
00107     Vio_dtor(&sock);
00108 
00109     return 0;
00110 }

Generated on Wed Oct 20 2010 11:12:19 for APBS by  doxygen 1.7.2