Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

gromacsplugin.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2006 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: gromacsplugin.C,v $
00013  *      $Author: johns $       $Locker:  $             $State: Exp $
00014  *      $Revision: 1.45 $       $Date: 2008/01/09 20:31:06 $
00015  *
00016  ***************************************************************************/
00017 
00018 #include "largefiles.h"   /* platform dependent 64-bit file I/O defines */
00019 
00020 #include <math.h>
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <ctype.h>
00025 #include "Gromacs.h"
00026 #include "molfile_plugin.h"
00027 
00028 #if defined(_AIX)
00029 #include <strings.h>
00030 #endif
00031 
00032 #ifndef M_PI
00033 #define M_PI           3.14159265358979323846
00034 #endif
00035 
00036 #if defined(WIN32) || defined(WIN64)
00037 #define strcasecmp stricmp
00038 #endif
00039 
00040 typedef struct {
00041   md_file *mf;
00042   int natoms;
00043   int step;
00044 } gmxdata;
00045 
00046 static void *open_gro_read(const char *filename, const char *,
00047     int *natoms) {
00048 
00049     md_file *mf;
00050     md_header mdh;
00051     gmxdata *gmx;
00052 
00053     mf = mdio_open(filename, MDFMT_GRO);
00054     if (!mf) {
00055         fprintf(stderr, "gromacsplugin) Cannot open file '%s', %s\n",
00056                 filename, mdio_errmsg(mdio_errno()));
00057         return NULL;
00058     }
00059 
00060     // read in the header data (careful not to rewind!)
00061     if (gro_header(mf, mdh.title, MAX_MDIO_TITLE,
00062     &mdh.timeval, &mdh.natoms, 0) < 0) {
00063         fprintf(stderr, "gromacsplugin) Cannot read header fromm '%s', %s\n",
00064                 filename, mdio_errmsg(mdio_errno()));
00065             // XXX should free the file handle...
00066         return NULL;
00067     }
00068     *natoms = mdh.natoms;
00069     gmx = new gmxdata;
00070     gmx->mf = mf;
00071     gmx->natoms = mdh.natoms;
00072     return gmx;
00073 }
00074 
00075 static int read_gro_structure(void *mydata, int *optflags,
00076     molfile_atom_t *atoms) {
00077 
00078   md_atom ma;
00079   char buf[MAX_GRO_LINE + 1];
00080   gmxdata *gmx = (gmxdata *)mydata;
00081  
00082   *optflags = MOLFILE_NOOPTIONS; // no optional data
00083 
00084   // read in each atom and add it into the molecule
00085   for (int i = 0; i < gmx->natoms; i++) {
00086     molfile_atom_t *atom = atoms+i; 
00087     if (gro_rec(gmx->mf, &ma) < 0) {
00088       fprintf(stderr, "gromacsplugin) Error reading atom %d from file, %s\n", 
00089               i+1, mdio_errmsg(mdio_errno()));
00090       return MOLFILE_ERROR;
00091     }
00092     strcpy(atom->name, ma.atomname);
00093     strcpy(atom->type, ma.atomname);
00094     strcpy(atom->resname, ma.resname);
00095     atom->resid = atoi(ma.resid);
00096     atom->chain[0] = '\0';
00097     atom->segid[0] = '\0';
00098   }
00099   
00100   if (mdio_readline(gmx->mf, buf, MAX_GRO_LINE + 1, 0) < 0) {
00101     fprintf(stderr, "gromacsplugin) Warning, error reading box, %s\n", 
00102             mdio_errmsg(mdio_errno())); 
00103   }
00104 
00105   rewind(gmx->mf->f);
00106   return MOLFILE_SUCCESS;
00107 }
00108 
00109 static int read_gro_timestep(void *v, int natoms, molfile_timestep_t *ts) {
00110   gmxdata *gmx = (gmxdata *)v;
00111   md_ts mdts;
00112   memset(&mdts, 0, sizeof(md_ts));
00113   mdts.natoms = natoms;
00114  
00115   if (mdio_timestep(gmx->mf, &mdts) < 0) 
00116     return MOLFILE_ERROR;
00117   if (ts) {
00118     memcpy(ts->coords, mdts.pos, 3 * sizeof(float) * gmx->natoms);
00119     if (mdts.box) {
00120       ts->A = mdts.box->A;
00121       ts->B = mdts.box->B;
00122       ts->C = mdts.box->C;
00123       ts->alpha = mdts.box->alpha;
00124       ts->beta = mdts.box->beta;
00125       ts->gamma = mdts.box->gamma;
00126     }
00127   }
00128   mdio_tsfree(&mdts);
00129   return MOLFILE_SUCCESS;
00130 }
00131 
00132 static void close_gro_read(void *v) {
00133   gmxdata *gmx = (gmxdata *)v;
00134   mdio_close(gmx->mf);
00135   delete gmx;
00136 }
00137 
00138 static void *open_g96_read(const char *filename, const char *,
00139     int *natoms) {
00140 
00141     md_file *mf;
00142     md_header mdh;
00143     char gbuf[MAX_G96_LINE + 1];
00144 
00145     mf = mdio_open(filename, MDFMT_G96);
00146     if (!mf) {
00147         fprintf(stderr, "gromacsplugin) Cannot open file '%s', %s\n",
00148                 filename, mdio_errmsg(mdio_errno()));
00149         return NULL;
00150     }
00151     
00152         // read in the header data
00153         if (g96_header(mf, mdh.title, MAX_MDIO_TITLE, &mdh.timeval) < 0) {
00154             fprintf(stderr, "gromacsplugin) Cannot read header from '%s', %s\n",
00155                     filename, mdio_errmsg(mdio_errno()));
00156             return NULL;
00157         }
00158 
00159         // First, look for a timestep block
00160         if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0) {
00161             fprintf(stderr, "gromacsplugin) Cannot read header from '%s', %s\n",
00162                     filename, mdio_errmsg(mdio_errno()));
00163             return NULL;
00164         }
00165         if (!strcasecmp(gbuf, "TIMESTEP")) {
00166             // Read in the value line and the END line, and the next
00167             if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0 ||
00168                 mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0 ||
00169                 mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0) {
00170               fprintf(stderr, "gromacsplugin) Cannot read header from '%s', %s\n",
00171                       filename, mdio_errmsg(mdio_errno()));
00172               return NULL;
00173             }
00174         }
00175         if (strcasecmp(gbuf, "POSITION") && strcasecmp(gbuf, "REFPOSITION")) {
00176           fprintf(stderr, "gromacsplugin) No structure information in file %s\n", filename);
00177           return NULL;
00178         }
00179         *natoms = g96_countatoms(mf); 
00180        
00181         gmxdata *gmx = new gmxdata;
00182         gmx->mf = mf;
00183         gmx->natoms = *natoms; 
00184         return gmx;
00185 }
00186 
00187 static int read_g96_structure(void *mydata, int *optflags,
00188     molfile_atom_t *atoms) {
00189   
00190     char gbuf[MAX_G96_LINE + 1];
00191     gmxdata *gmx = (gmxdata *)mydata;
00192     md_atom ma;
00193     md_file *mf = gmx->mf;
00194     
00195     *optflags = MOLFILE_NOOPTIONS; // no optional data
00196 
00197         for (int i = 0; i < gmx->natoms; i++) {
00198             molfile_atom_t *atom = atoms+i; 
00199             if (g96_rec(mf, &ma) < 0) {
00200                 fprintf(stderr, "gromacsplugin) Error reading atom %d from file, %s\n",
00201                   i+1, mdio_errmsg(mdio_errno()));
00202                 return MOLFILE_ERROR;
00203             }
00204             strcpy(atom->name, ma.atomname);
00205             strcpy(atom->type, ma.atomname);
00206             strcpy(atom->resname, ma.resname);
00207             atom->resid = atoi(ma.resid);
00208             atom->chain[0] = '\0';
00209             atom->segid[0] = '\0';
00210         }
00211         
00212         if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0) {
00213             fprintf(stderr, "gromacsplugin) Warning, error reading END record, %s\n",
00214                 mdio_errmsg(mdio_errno()));
00215         }
00216 
00217             // ... another problem: there may or may not be a VELOCITY
00218             // block or a BOX block, so we need to read one line beyond
00219             // the POSITION block to determine this. If neither VEL. nor
00220             // BOX are present we've read a line too far and infringed
00221             // on the next timestep, so we need to keep track of the
00222             // position now for a possible fseek() later to backtrack.
00223             long fpos = ftell(mf->f);
00224 
00225             // Now we must read in the velocities and the box, if present
00226             if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) >= 0) {
00227 
00228                 // Is there a velocity block present ?
00229                 if (!strcasecmp(gbuf, "VELOCITY") || !strcasecmp(gbuf, "VELOCITYRED")) {
00230                         // Ignore all the coordinates - VMD doesn't use them
00231                         for (;;) {
00232                                 if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0)
00233                                         return MOLFILE_ERROR;
00234                                 if (!strcasecmp(gbuf, "END")) break;
00235                         }
00236     
00237                         // Again, record our position because we may need
00238                         // to fseek here later if we read too far.
00239                         fpos = ftell(mf->f);
00240     
00241                         // Go ahead and read the next line.
00242                         if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0)
00243                     return MOLFILE_ERROR;
00244                 }
00245     
00246                 // Is there a box present ?
00247                 if (!strcasecmp(gbuf, "BOX")) {
00248                         // Ignore the box coordinates at this time.
00249                         if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0)
00250                     return MOLFILE_ERROR;
00251                         if (mdio_readline(mf, gbuf, MAX_G96_LINE + 1) < 0)
00252                     return MOLFILE_ERROR;
00253                         if (strcasecmp(gbuf, "END")) 
00254                     return MOLFILE_ERROR;
00255                 }
00256                 else {
00257                         // We have read too far, so fseek back to the
00258                         // last known safe position so we don't return
00259                         // with the file pointer set infringing on the
00260                         // next timestep data.
00261                         fseek(mf->f, fpos, SEEK_SET);
00262                 }
00263         }
00264         else {
00265             // Go ahead and rewind for good measure
00266             fseek(mf->f, fpos, SEEK_SET);
00267         }
00268         rewind(mf->f);
00269         return MOLFILE_SUCCESS;
00270 }
00271 
00272 static int read_g96_timestep(void *v, int natoms, molfile_timestep_t *ts) {
00273 
00274   gmxdata *gmx = (gmxdata *)v;
00275   md_ts mdts;
00276   memset(&mdts, 0, sizeof(md_ts));
00277   mdts.natoms = natoms;
00278 
00279   if (mdio_timestep(gmx->mf, &mdts) < 0) 
00280     return MOLFILE_ERROR;
00281   if (ts) {
00282     memcpy(ts->coords, mdts.pos, 3 * sizeof(float) * gmx->natoms);
00283     if (mdts.box) {
00284       ts->A = mdts.box->A;
00285       ts->B = mdts.box->B;
00286       ts->C = mdts.box->C;
00287       ts->alpha = mdts.box->alpha;
00288       ts->beta = mdts.box->beta;
00289       ts->gamma = mdts.box->gamma;
00290     }
00291   }
00292   mdio_tsfree(&mdts);
00293   return MOLFILE_SUCCESS;
00294 }
00295 
00296 static void close_g96_read(void *v) {
00297   gmxdata *gmx = (gmxdata *)v;
00298   mdio_close(gmx->mf);
00299   delete gmx;
00300 }
00301   
00302 
00303 //
00304 // TRR and XTC files
00305 //
00306 
00307 static void *open_trr_read(const char *filename, const char *filetype,
00308     int *natoms) {
00309 
00310     md_file *mf;
00311     md_header mdh;
00312     gmxdata *gmx;
00313     int format;
00314   
00315     if (!strcmp(filetype, "trr")) 
00316       format = MDFMT_TRR;
00317     else if (!strcmp(filetype, "trj")) 
00318       format = MDFMT_TRJ;
00319     else if (!strcmp(filetype, "xtc")) 
00320       format = MDFMT_XTC;
00321     else
00322       return NULL;
00323 
00324     mf = mdio_open(filename, format);
00325     if (!mf) {
00326         fprintf(stderr, "gromacsplugin) Cannot open file '%s', %s\n",
00327                 filename, mdio_errmsg(mdio_errno()));
00328         return NULL;
00329     }
00330     if (mdio_header(mf, &mdh) < 0) {
00331         mdio_close(mf);
00332         fprintf(stderr, "gromacsplugin) Cannot read header fromm '%s', %s\n",
00333                 filename, mdio_errmsg(mdio_errno()));
00334         return NULL;
00335     }
00336     *natoms = mdh.natoms;
00337     gmx = new gmxdata;
00338     gmx->mf = mf;
00339     gmx->natoms = mdh.natoms;
00340     return gmx;
00341 }
00342 
00343 static int read_trr_timestep(void *v, int natoms, molfile_timestep_t *ts) {
00344   gmxdata *gmx = (gmxdata *)v;
00345   md_ts mdts;
00346   memset(&mdts, 0, sizeof(md_ts));
00347   mdts.natoms = natoms;
00348 
00349   if (mdio_timestep(gmx->mf, &mdts) < 0) {
00350     if (mdio_errno() == MDIO_EOF || mdio_errno() == MDIO_IOERROR) {
00351       // XXX Lame, why does mdio treat IOERROR like EOF?  
00352       return MOLFILE_ERROR;
00353     }
00354     fprintf(stderr, "gromacsplugin) Error reading timestep, %s\n", 
00355             mdio_errmsg(mdio_errno()));
00356     return MOLFILE_ERROR;
00357   }
00358   if (mdts.natoms != natoms) {
00359     fprintf(stderr, "gromacsplugin) Timestep in file contains wrong number of atoms\n");
00360     fprintf(stderr, "gromacsplugin) Found %d, expected %d\n", mdts.natoms, natoms);
00361     mdio_tsfree(&mdts);
00362     return MOLFILE_ERROR;
00363   }
00364    
00365   if (ts) {
00366     memcpy(ts->coords, mdts.pos, 3 * sizeof(float) * gmx->natoms);
00367     if (mdts.box) {
00368       ts->A = mdts.box->A;
00369       ts->B = mdts.box->B;
00370       ts->C = mdts.box->C;
00371       ts->alpha = mdts.box->alpha;
00372       ts->beta = mdts.box->beta;
00373       ts->gamma = mdts.box->gamma;
00374     }
00375   }
00376   mdio_tsfree(&mdts);
00377   return MOLFILE_SUCCESS;
00378 }
00379 
00380 static void close_trr_read(void *v) {
00381   gmxdata *gmx = (gmxdata *)v;
00382   mdio_close(gmx->mf);
00383   delete gmx;
00384 }
00385 
00386 // open file for writing
00387 static void *open_trr_write(const char *filename, const char *filetype,
00388     int natoms) {
00389 
00390     md_file *mf;
00391     gmxdata *gmx;
00392     int format;
00393   
00394     if (!strcmp(filetype, "trr")) 
00395       format = MDFMT_TRR;
00396     else if (!strcmp(filetype, "xtc")) 
00397       format = MDFMT_XTC;
00398     else
00399       return NULL;
00400 
00401     mf = mdio_open(filename, format, MDIO_WRITE);
00402     if (!mf) {
00403         fprintf(stderr, "gromacsplugin) Cannot open file '%s', %s\n",
00404                 filename, mdio_errmsg(mdio_errno()));
00405         return NULL;
00406     }
00407     gmx = new gmxdata;
00408     gmx->mf = mf;
00409     gmx->natoms = natoms;
00410     // set some parameters for the output stream:
00411     // start at step 0, convert to big-endian, write single precision.
00412     gmx->step   = 0;
00413     gmx->mf->rev = host_is_little_endian();
00414     gmx->mf->prec = sizeof(float);
00415     return gmx;
00416 }
00417 
00418 // write a trr timestep. the file format has a header with each record
00419 static int write_trr_timestep(void *mydata, const molfile_timestep_t *ts) 
00420 {
00421   const float nm=0.1;
00422   
00423   gmxdata *gmx = (gmxdata *)mydata;
00424   
00425   // determine and write header from structure info.
00426   // write trr header. XXX: move this to Gromacs.h ??
00427   if (gmx->mf->fmt == MDFMT_TRR) {
00428     int i;
00429 
00430     if ( put_trx_int(gmx->mf, TRX_MAGIC)            // ID
00431          || put_trx_string(gmx->mf, "GMX_trn_file") // version
00432          || put_trx_int(gmx->mf, 0)                 // ir_size (ignored)
00433          || put_trx_int(gmx->mf, 0)                 // e_size (ignored)
00434          || put_trx_int(gmx->mf, 9*sizeof(float))   // box
00435          || put_trx_int(gmx->mf, 0)                 // vir_size (ignored)
00436          || put_trx_int(gmx->mf, 0)                 // pres_size (ignored)
00437          || put_trx_int(gmx->mf, 0)                 // top_size (ignored)
00438          || put_trx_int(gmx->mf, 0)                 // sym_size (ignored)
00439          || put_trx_int(gmx->mf, 3*sizeof(float)*gmx->natoms) // coordinates 
00440          || put_trx_int(gmx->mf, 0)                 // no velocities
00441          || put_trx_int(gmx->mf, 0)                 // no forces
00442          || put_trx_int(gmx->mf, gmx->natoms)       // number of atoms
00443          || put_trx_int(gmx->mf, gmx->step)         // current step number
00444          || put_trx_int(gmx->mf, 0)                 // nre (ignored)
00445          || put_trx_real(gmx->mf, 0.1*gmx->step)    // current time. (dummy value: 0.1)
00446          || put_trx_real(gmx->mf, 0.0))             // current lambda
00447       return MOLFILE_ERROR;
00448 
00449     // set up box according to the VMD unitcell conventions.
00450     // the a-vector is collinear with the x-axis and
00451     // the b-vector is in the xy-plane. 
00452     const float sa = sin((double)ts->alpha/180.0*M_PI);
00453     const float ca = cos((double)ts->alpha/180.0*M_PI);
00454     const float cb = cos((double)ts->beta/180.0*M_PI);
00455     const float cg = cos((double)ts->gamma/180.0*M_PI);
00456     const float sg = sin((double)ts->gamma/180.0*M_PI);
00457     float box[9];
00458     box[0] = ts->A;    box[1] = 0.0;      box[2] = 0.0;
00459     box[3] = ts->B*ca; box[4] = ts->B*sa; box[5] = 0.0;
00460     box[6] = ts->C*cb; box[7] = ts->C*(ca - cb*cg)/sg;
00461     box[8] = ts->C*sqrt((double)(1.0 + 2.0*ca*cb*cg 
00462                                  - ca*ca - cb*cb - cg*cg)/(1.0 - cg*cg));
00463 
00464     for (i=0; i<9; ++i) {
00465       if (put_trx_real(gmx->mf, box[i]*nm))
00466         return MOLFILE_ERROR;
00467     }
00468 #ifdef TEST_TRR_PLUGIN
00469     fprintf(stderr, "gromacsplugin) box is:\n %f %f %f\n %f %f %f\n %f %f %f\n\n",
00470             box[0], box[1], box[2], box[3], box[4], box[5], box[6], box[7], box[8]);
00471 #endif
00472 
00473     // write coordinates
00474     for (i=0; i<(3*gmx->natoms); ++i) {
00475       if (put_trx_real(gmx->mf, ts->coords[i]*nm))
00476         return MOLFILE_ERROR;
00477     }
00478   } else {
00479     fprintf(stderr, "gromacsplugin) only .trr is supported for writing\n");
00480     return MOLFILE_ERROR;
00481   }
00482 
00483   ++ gmx->step;
00484   return MOLFILE_SUCCESS;
00485   }
00486 
00487 
00488 static void close_trr_write(void *v) {
00489   gmxdata *gmx = (gmxdata *)v;
00490   mdio_close(gmx->mf);
00491   delete gmx;
00492 }
00493 
00494 #define GROMACS_PLUGIN_MAJOR_VERSION 0
00495 #define GROMACS_PLUGIN_MINOR_VERSION 9
00496 
00497 //
00498 // plugin registration stuff below
00499 //
00500 static molfile_plugin_t gro_plugin = {
00501   vmdplugin_ABIVERSION,               // ABI version
00502   MOLFILE_PLUGIN_TYPE,                // type of plugin
00503   "gro",                              // short name of plugin
00504   "Gromacs GRO",                      // pretty name of plugin
00505   "David Norris, Justin Gullingsrud", // authors
00506   GROMACS_PLUGIN_MAJOR_VERSION,       // major version
00507   GROMACS_PLUGIN_MINOR_VERSION,       // minor version
00508   VMDPLUGIN_THREADUNSAFE,             // is not reentrant
00509   "gro",                              // filename extension
00510   open_gro_read,
00511   read_gro_structure,
00512   0,
00513   read_gro_timestep,
00514   close_gro_read,
00515   0,                                  // open_write
00516   0,                                  // write_structure
00517   0,                                  // write_timestep
00518   0,                                  // close_write
00519   0,                                  // read_volumetric_metadata
00520   0,                                  // read_volumetric_data
00521   0                                   // read_rawgraphics
00522 };
00523 
00524 static molfile_plugin_t g96_plugin = {
00525   vmdplugin_ABIVERSION,               // ABI version
00526   MOLFILE_PLUGIN_TYPE,                // type of plugin
00527   "g96",                              // short name of plugin
00528   "Gromacs g96",                      // pretty name of plugin
00529   "David Norris, Justin Gullingsrud", // authors
00530   GROMACS_PLUGIN_MAJOR_VERSION,       // major version
00531   GROMACS_PLUGIN_MINOR_VERSION,       // minor version
00532   VMDPLUGIN_THREADUNSAFE,             // is not reentrant
00533   "g96",                              // filename extension
00534   open_g96_read,
00535   read_g96_structure,
00536   0,
00537   read_g96_timestep,
00538   close_g96_read,
00539   0,                                  // open_write
00540   0,                                  // write_structure
00541   0,                                  // write_timestep
00542   0,                                  // close_write
00543   0,                                  // read_volumetric_metadata
00544   0,                                  // read_volumetric_data
00545   0                                   // read_rawgraphics
00546 };
00547 
00548 static molfile_plugin_t trr_plugin = {
00549   vmdplugin_ABIVERSION,               // ABI version
00550   MOLFILE_PLUGIN_TYPE,                // type of plugin
00551   "trr",                              // short name of plugin
00552   "Gromacs TRR Trajectory",           // pretty name of plugin
00553   "David Norris, Justin Gullingsrud, Axel Kohlmeyer", // authors
00554   GROMACS_PLUGIN_MAJOR_VERSION,       // major version
00555   GROMACS_PLUGIN_MINOR_VERSION,       // minor version
00556   VMDPLUGIN_THREADUNSAFE,             // is not reentrant
00557   "trr",                              // filename extension
00558   open_trr_read,
00559   0,
00560   0,
00561   read_trr_timestep,
00562   close_trr_read,
00563   open_trr_write,
00564   0,                            // write_structure
00565   write_trr_timestep,
00566   close_trr_write,
00567   0,                            // read_volumetric_metadata
00568   0,                            // read_volumetric_data
00569   0                             // read_rawgraphics
00570 };
00571 
00572 static molfile_plugin_t xtc_plugin = {
00573   vmdplugin_ABIVERSION,                // ABI version
00574   MOLFILE_PLUGIN_TYPE,                 // type of plugin
00575   "xtc",                               // short name of plugin
00576   "Gromacs XTC Compressed Trajectory", // pretty name of plugin
00577   "David Norris, Justin Gullingsrud",  // authors
00578   GROMACS_PLUGIN_MAJOR_VERSION,        // major version
00579   GROMACS_PLUGIN_MINOR_VERSION,        // minor version
00580   VMDPLUGIN_THREADUNSAFE,              // is not reentrant
00581   "xtc",                               // filename extension
00582   open_trr_read,
00583   0,
00584   0,
00585   read_trr_timestep,
00586   close_trr_read,
00587   0,                                  // open_write
00588   0,                                  // write_structure
00589   0,                                  // write_timestep
00590   0,                                  // close_write
00591   0,                                  // read_volumetric_metadata
00592   0,                                  // read_volumetric_data
00593   0                                   // read_rawgraphics
00594 };
00595 
00596 static molfile_plugin_t trj_plugin = {
00597   vmdplugin_ABIVERSION,                // ABI version
00598   MOLFILE_PLUGIN_TYPE,                 // type of plugin
00599   "trj",                               // short name of plugin
00600   "Gromacs TRJ Trajectory", // pretty name of plugin
00601   "David Norris, Justin Gullingsrud",  // authors
00602   GROMACS_PLUGIN_MAJOR_VERSION,        // major version
00603   GROMACS_PLUGIN_MINOR_VERSION,        // minor version
00604   VMDPLUGIN_THREADUNSAFE,              // is not reentrant
00605   "trj",                               // filename extension
00606   open_trr_read,
00607   0,
00608   0,
00609   read_trr_timestep,
00610   close_trr_read,
00611   0,                                  // open_write
00612   0,                                  // write_structure
00613   0,                                  // write_timestep
00614   0,                                  // close_write
00615   0,                                  // read_volumetric_metadata
00616   0,                                  // read_volumetric_data
00617   0                                   // read_rawgraphics
00618 };
00619 
00620 VMDPLUGIN_API int VMDPLUGIN_init() { 
00621   return 0; 
00622 }
00623 
00624 VMDPLUGIN_API int VMDPLUGIN_register(void *v, vmdplugin_register_cb cb) {
00625   (*cb)(v, (vmdplugin_t *)&gro_plugin);
00626   (*cb)(v, (vmdplugin_t *)&g96_plugin);
00627   (*cb)(v, (vmdplugin_t *)&trr_plugin);
00628   (*cb)(v, (vmdplugin_t *)&trj_plugin);
00629   (*cb)(v, (vmdplugin_t *)&xtc_plugin);
00630   return 0;
00631 }
00632 
00633 VMDPLUGIN_API int VMDPLUGIN_fini() {
00634   return 0;
00635 }
00636 
00637   
00638 #ifdef TEST_G96_PLUGIN
00639 
00640 int main(int argc, char *argv[]) {
00641   int natoms;
00642   
00643   molfile_timestep_t timestep;
00644   void *v;
00645   int i;
00646 
00647   if (argc < 2) return 1;
00648   while (--argc) {
00649     ++argv;
00650     v = open_g96_read(*argv, "g96", &natoms);
00651     if (!v) {
00652       fprintf(stderr, "open_g96_read failed for file %s\n", *argv);
00653       return 1;
00654     }
00655     timestep.coords = (float *)malloc(3*sizeof(float)*natoms);
00656     i = 0;
00657     while(!read_g96_timestep(v, natoms, &timestep)) {
00658       ++i;
00659     }
00660     fprintf(stderr, "ended read_g96_timestep on step %d\n", i);
00661     free(timestep.coords);
00662     close_g96_read(v);
00663   }
00664   return 0;
00665 }
00666 
00667 #endif
00668 
00669 #ifdef TEST_TRR_PLUGIN
00670 
00671 int main(int argc, char *argv[]) {
00672   int natoms;
00673   
00674   molfile_timestep_t timestep;
00675   void *v, *w;
00676   int i;
00677 
00678   if (argc != 3) return 1;
00679   v = open_trr_read(argv[1], "trr", &natoms);
00680   if (!v) {
00681     fprintf(stderr, "open_trr_read failed for file %s\n", argv[1]);
00682     return 1;
00683   }
00684   timestep.coords = (float *)malloc(3*sizeof(float)*natoms);
00685   w = open_trr_write(argv[2], "trr", natoms);
00686   if (!w) {
00687     fprintf(stderr, "open_trr_write failed for file %s\n", argv[2]);
00688     return 1;
00689   }
00690   
00691   i = 0;
00692   while(!read_trr_timestep(v, natoms, &timestep)) {
00693     ++i;
00694     if (write_trr_timestep(w, &timestep)) {
00695       fprintf(stderr, "write error\n");
00696       return 1;
00697     }
00698   }
00699   
00700   fprintf(stderr, "ended read_trr_timestep on step %d\n", i);
00701   free(timestep.coords);
00702   close_trr_read(v);
00703   close_trr_write(w);
00704   return 0;
00705 }
00706 
00707 #endif
00708 

Generated on Thu Aug 28 01:40:09 2008 for VMD Plugins (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002