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

mmcif.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: mmcif.C,v $
00013  *      $Author: johns $       $Locker:  $             $State: Exp $
00014  *      $Revision: 1.3 $       $Date: 2006/02/23 19:36:45 $
00015  *
00016  ***************************************************************************/
00017 
00018 /*
00019  *  mmCIF molecule file format (a subset of the STAR file format):
00020  *    http://mmcif.rcsb.org/mmcif-early/background/index.html#1
00021  *    http://mmcif.rcsb.org/mmcif-early/workshop/mmCIF-tutorials/
00022  *
00023  *  mmCIF reserved keywords: data_ loop_ global_ save_ stop_
00024  *
00025  *  STAR file syntax and rules (superset of mmCIF):
00026  *    http://journals.iucr.org/iucr-top/cif/standard/cifstd4.html
00027  *
00028  *  STAR syntactic entities: 
00029  *    Text string: string of characters bounded by blanks, single quotes (') 
00030  *                 double quotes ("), or by semi-colons (;) as the first 
00031  *                 character of a line
00032  *
00033  *    Data name:   a text string starting with an underline (_) character 
00034  *
00035  *    Data item:   a text string not starting with an underline, but preceded 
00036  *                 by a data name to identify it 
00037  * 
00038  *    Data loop:   a list of data names, preceded by loop_ and followed by 
00039  *                 a repeated list of data items 
00040  *
00041  *    Data block:  a collection of data names (looped or not) and data items 
00042  *                 that are preceded by a data_ code record. A data name must 
00043  *                 be unique within a data block. A data block is terminated 
00044  *                 by another data_ statement or the end of file 
00045  * 
00046  *    Data file:   a collection of data blocks; the block codes must be 
00047  *                 unique within a data file  
00048  *
00049  *  CIF restrictions to STAR syntax:
00050  *    http://journals.iucr.org/iucr-top/cif/standard/cifstd5.html
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   // XXX not finished yet
00070   return NULL;
00071 }
00072 
00073 static int read_mmcif_structure(void *mydata, int *optflags, 
00074                               molfile_atom_t *atoms) {
00075   // XXX not finished yet 
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   // XXX not finished yet 
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 /* registration stuff */
00112 static molfile_plugin_t mmcifplugin = {
00113   vmdplugin_ABIVERSION,
00114   MOLFILE_PLUGIN_TYPE,                         /* type */
00115   "mmcif",                                     /* short name */
00116   "mmCIF",                                     /* pretty name */
00117   "John E. Stone",                             /* author */
00118   0,                                           /* major version */
00119   1,                                           /* minor version */
00120   VMDPLUGIN_THREADSAFE,                        /* is reentrant */
00121   "cif",                                       /* file extension */
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,                            /* read_volumetric_metadata */
00132   0,                            /* read_volumetric_data */
00133   0                             /* read_rawgraphics */
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, &timestep)) {
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 

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