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

parmplugin.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: parmplugin.C,v $
00013  *      $Author: johns $       $Locker:  $             $State: Exp $
00014  *      $Revision: 1.28 $       $Date: 2006/02/23 19:36:45 $
00015  *
00016  ***************************************************************************/
00017 
00018 #include <string.h>
00019 #include "ReadPARM.h"
00020 #include "molfile_plugin.h"
00021 
00022 typedef struct {
00023   ReadPARM *rp;
00024   FILE *parm;
00025   int natoms;
00026   int *from, *to;
00027 } parmdata;
00028 
00029 static void *open_parm_read(const char *filename, const char *, 
00030     int *natoms) {
00031  
00032   FILE *parm;
00033   ReadPARM *rp = new ReadPARM;
00034   if(!(parm = rp->open_parm_file(filename))) {
00035     fprintf(stderr, "Cannot open parm file '%s'\n", filename);
00036     delete rp;
00037     return NULL;
00038   }
00039   
00040   if (rp->readparm(parm) != 0) {
00041     delete rp;
00042     // XXX should we call close_parm_file???
00043     return NULL; 
00044   }
00045   *natoms = rp->get_parm_natoms();
00046   
00047   parmdata *p = new parmdata;
00048   memset(p, 0, sizeof(parmdata));
00049   p->rp = rp;
00050   p->parm = parm;
00051   p->natoms = *natoms;
00052   return p;
00053 }
00054 
00055 static int read_parm_structure(void *mydata, int *optflags,
00056     molfile_atom_t *atoms) {
00057   
00058   parmdata *p = (parmdata *)mydata;
00059   ReadPARM *rp = p->rp;
00060   rp->get_parm_boxInfo();
00061   int i;
00062  
00063   *optflags = MOLFILE_CHARGE | MOLFILE_MASS;
00064 
00065   for (i=0; i<p->natoms; i++) {
00066     molfile_atom_t *atom = atoms+i;
00067     // XXX Why isn't there a return code for error on read????
00068     rp->get_parm_atom(i, atom->name, atom->type, atom->resname, atom->segid, 
00069         &atom->resid, &atom->charge, &atom->mass);
00070     atom->chain[0] = '\0';
00071   }
00072   // XXX amber box info not supported in the API
00073   return MOLFILE_SUCCESS;
00074 }
00075 
00076 static int read_parm_bonds(void *v, int *nbonds, int **fromptr, int **toptr, float **bondorderptr) {
00077   parmdata *p = (parmdata *)v;
00078   ReadPARM *rp = p->rp;
00079   int i, j;
00080   int numbonds = rp->get_parm_nbonds();
00081   p->from = (int *)malloc(numbonds*sizeof(int));
00082   p->to = (int *)malloc(numbonds*sizeof(int));
00083   j = 0;
00084   for (i=0; i<numbonds; i++) {
00085     int a1, a2;
00086     rp->get_parm_bond(i, (&a1)-i, (&a2)-i);
00087     if ( a1 <= p->natoms && a2 <= p->natoms) {
00088       p->from[j] = a1;
00089       p->to[j] = a2;
00090       j++;
00091     } else {
00092       printf("skipping bond (%d %d)\n", a1, a2); 
00093     }
00094   }
00095   *nbonds = j;
00096   *fromptr = p->from;
00097   *toptr = p->to;
00098   *bondorderptr = NULL; // PARM files don't have bond order information
00099   return MOLFILE_SUCCESS;
00100 }
00101 
00102 
00103 static void close_parm_read(void *mydata) {
00104   parmdata *p = (parmdata *)mydata;
00105   p->rp->close_parm_file(p->parm);
00106   if (p->from) free(p->from);
00107   if (p->to) free(p->to);
00108   delete p->rp;
00109 }
00110  
00111 /*
00112  * Initialization stuff down here
00113  */
00114 
00115 static molfile_plugin_t plugin =  {
00116   vmdplugin_ABIVERSION,                                 // ABI version
00117   MOLFILE_PLUGIN_TYPE,                                  // type
00118   "parm",                                               // short name
00119   "AMBER Parm",                                         // pretty name
00120   "Justin Gullingsrud, John E. Stone",                  // author
00121   0,                                                    // major version
00122   4,                                                    // minor version
00123   VMDPLUGIN_THREADSAFE,                                 // is_reentrant
00124   "parm",                                               // filename extension
00125   open_parm_read,        /* open_file_read   */
00126   read_parm_structure,   /* read_structure   */
00127   read_parm_bonds,
00128   0,                     /* read_next_timestep */
00129   close_parm_read        /* close_file_read    */
00130 };
00131 
00132 VMDPLUGIN_API int VMDPLUGIN_init(void) { return VMDPLUGIN_SUCCESS; }
00133 VMDPLUGIN_API int VMDPLUGIN_fini(void) { return VMDPLUGIN_SUCCESS; }
00134 VMDPLUGIN_API int VMDPLUGIN_register(void *v, vmdplugin_register_cb cb) {
00135   (*cb)(v, (vmdplugin_t *)&plugin);
00136   return 0;
00137 }
00138 

Generated on Wed Mar 22 13:15:30 2006 for VMD Plugins (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002