00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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, "parmplugin) 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
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
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
00073 return MOLFILE_SUCCESS;
00074 }
00075
00076 static int read_parm_bonds(void *v, int *nbonds, int **fromptr, int **toptr,
00077 float **bondorderptr, int **bondtype,
00078 int *nbondtypes, char ***bondtypename) {
00079 parmdata *p = (parmdata *)v;
00080 ReadPARM *rp = p->rp;
00081 int i, j;
00082 int numbonds = rp->get_parm_nbonds();
00083 p->from = (int *)malloc(numbonds*sizeof(int));
00084 p->to = (int *)malloc(numbonds*sizeof(int));
00085 j = 0;
00086 for (i=0; i<numbonds; i++) {
00087 int a1, a2;
00088 rp->get_parm_bond(i, (&a1)-i, (&a2)-i);
00089 if ( a1 <= p->natoms && a2 <= p->natoms) {
00090 p->from[j] = a1;
00091 p->to[j] = a2;
00092 j++;
00093 } else {
00094 printf("parmplugin) skipping bond (%d %d)\n", a1, a2);
00095 }
00096 }
00097 *nbonds = j;
00098 *fromptr = p->from;
00099 *toptr = p->to;
00100 *bondorderptr = NULL;
00101 *bondtype = NULL;
00102 *nbondtypes = 0;
00103 *bondtypename = NULL;
00104
00105 return MOLFILE_SUCCESS;
00106 }
00107
00108
00109 static void close_parm_read(void *mydata) {
00110 parmdata *p = (parmdata *)mydata;
00111 p->rp->close_parm_file(p->parm);
00112 if (p->from) free(p->from);
00113 if (p->to) free(p->to);
00114 delete p->rp;
00115 }
00116
00117
00118
00119
00120
00121 static molfile_plugin_t plugin;
00122
00123 VMDPLUGIN_API int VMDPLUGIN_init(void) {
00124 memset(&plugin, 0, sizeof(molfile_plugin_t));
00125 plugin.abiversion = vmdplugin_ABIVERSION;
00126 plugin.type = MOLFILE_PLUGIN_TYPE;
00127 plugin.name = "parm";
00128 plugin.prettyname = "AMBER Parm";
00129 plugin.author = "Justin Gullingsrud, John Stone";
00130 plugin.majorv = 4;
00131 plugin.minorv = 4;
00132 plugin.is_reentrant = VMDPLUGIN_THREADSAFE;
00133 plugin.filename_extension = "parm";
00134 plugin.open_file_read = open_parm_read;
00135 plugin.read_structure = read_parm_structure;
00136 plugin.read_bonds = read_parm_bonds;
00137 plugin.close_file_read = close_parm_read;
00138 return VMDPLUGIN_SUCCESS;
00139 }
00140
00141 VMDPLUGIN_API int VMDPLUGIN_register(void *v, vmdplugin_register_cb cb) {
00142 (*cb)(v, (vmdplugin_t *)&plugin);
00143 return 0;
00144 }
00145
00146 VMDPLUGIN_API int VMDPLUGIN_fini(void) { return VMDPLUGIN_SUCCESS; }
00147