00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include <stdio.h>
00055 #include <stdlib.h>
00056 #include <string.h>
00057 #include <ctype.h>
00058 #include "molfile_plugin.h"
00059 #include "periodic_table.h"
00060
00061 typedef struct {
00062 FILE *file;
00063 int numatoms;
00064 molfile_atom_t *atomlist;
00065 } mmcifdata;
00066
00067 static void *open_mmcif_read(const char *filename, const char *filetype,
00068 int *natoms) {
00069
00070 return NULL;
00071 }
00072
00073 static int read_mmcif_structure(void *mydata, int *optflags,
00074 molfile_atom_t *atoms) {
00075
00076 return MOLFILE_ERROR;
00077 }
00078
00079 static int read_mmcif_timestep(void *mydata, int natoms, molfile_timestep_t *ts) {
00080 mmcifdata *data = (mmcifdata *)mydata;
00081
00082
00083 return MOLFILE_ERROR;
00084 }
00085
00086 static void close_mmcif_read(void *mydata) {
00087 mmcifdata *data = (mmcifdata *)mydata;
00088 fclose(data->file);
00089 free(data);
00090 }
00091
00092
00093 static void *open_mmcif_write(const char *filename, const char *filetype,
00094 int natoms) {
00095 FILE *fd;
00096 mmcifdata *data;
00097
00098 fd = fopen(filename, "w");
00099 if (!fd) {
00100 fprintf(stderr, "Error) Unable to open mmcif file %s for writing\n",
00101 filename);
00102 return NULL;
00103 }
00104
00105 data = (mmcifdata *)malloc(sizeof(mmcifdata));
00106 data->numatoms = natoms;
00107 data->file = fd;
00108 return data;
00109 }
00110
00111
00112 static molfile_plugin_t mmcifplugin = {
00113 vmdplugin_ABIVERSION,
00114 MOLFILE_PLUGIN_TYPE,
00115 "mmcif",
00116 "mmCIF",
00117 "John E. Stone",
00118 0,
00119 1,
00120 VMDPLUGIN_THREADSAFE,
00121 "cif",
00122 open_mmcif_read,
00123 read_mmcif_structure,
00124 0,
00125 read_mmcif_timestep,
00126 close_mmcif_read,
00127 0,
00128 0,
00129 0,
00130 0,
00131 0,
00132 0,
00133 0
00134 };
00135
00136 VMDPLUGIN_API int VMDPLUGIN_init() {
00137 return VMDPLUGIN_SUCCESS;
00138 }
00139
00140 VMDPLUGIN_API int VMDPLUGIN_register(void *v, vmdplugin_register_cb cb) {
00141 (*cb)(v, (vmdplugin_t *)&mmcifplugin);
00142 return VMDPLUGIN_SUCCESS;
00143 }
00144
00145 VMDPLUGIN_API int VMDPLUGIN_fini() {
00146 return VMDPLUGIN_SUCCESS;
00147 }
00148
00149
00150 #ifdef TEST_PLUGIN
00151
00152 int main(int argc, char *argv[]) {
00153 molfile_timestep_t timestep;
00154 void *v;
00155 int natoms;
00156 int i, nsets, set;
00157
00158 while (--argc) {
00159 ++argv;
00160 v = open_mmcif_read(*argv, "mmcif", &natoms);
00161 if (!v) {
00162 fprintf(stderr, "open_mmcif_read failed for file %s\n", *argv);
00163 return 1;
00164 }
00165 fprintf(stderr, "open_mmcif_read succeeded for file %s\n", *argv);
00166 fprintf(stderr, "number of atoms: %d\n", natoms);
00167
00168 i = 0;
00169 timestep.coords = (float *)malloc(3*sizeof(float)*natoms);
00170 while (!read_mmcif_timestep(v, natoms, ×tep)) {
00171 i++;
00172 }
00173 fprintf(stderr, "ended read_next_timestep on frame %d\n", i);
00174
00175 close_mmcif_read(v);
00176 }
00177 return 0;
00178 }
00179
00180 #endif
00181
00182
00183
00184
00185