Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

mmcif.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2016 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.7 $       $Date: 2016/11/28 05:01:54 $
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, "mmcifplugin) 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 plugin;
00113 
00114 VMDPLUGIN_API int VMDPLUGIN_init() {
00115   memset(&plugin, 0, sizeof(molfile_plugin_t));
00116   plugin.abiversion = vmdplugin_ABIVERSION;
00117   plugin.type = MOLFILE_PLUGIN_TYPE;
00118   plugin.name = "mmcif";
00119   plugin.prettyname = "mmCIF";
00120   plugin.author = "John Stone";
00121   plugin.majorv = 0;
00122   plugin.minorv = 2;
00123   plugin.is_reentrant = VMDPLUGIN_THREADSAFE;
00124   plugin.filename_extension = "cif";
00125   plugin.open_file_read = open_mmcif_read;
00126   plugin.read_structure = read_mmcif_structure;
00127   plugin.read_next_timestep = read_mmcif_timestep;
00128   plugin.close_file_read = close_mmcif_read;
00129   return VMDPLUGIN_SUCCESS;
00130 }
00131 
00132 VMDPLUGIN_API int VMDPLUGIN_register(void *v, vmdplugin_register_cb cb) {
00133   (*cb)(v, (vmdplugin_t *)&plugin);
00134   return VMDPLUGIN_SUCCESS;
00135 }
00136 
00137 VMDPLUGIN_API int VMDPLUGIN_fini() {
00138   return VMDPLUGIN_SUCCESS;
00139 }
00140 
00141 
00142 #ifdef TEST_PLUGIN
00143 
00144 int main(int argc, char *argv[]) {
00145   molfile_timestep_t timestep;
00146   void *v;
00147   int natoms;
00148   int i, nsets, set;
00149 
00150   while (--argc) {
00151     ++argv;
00152     v = open_mmcif_read(*argv, "mmcif", &natoms);
00153     if (!v) {
00154       fprintf(stderr, "open_mmcif_read failed for file %s\n", *argv);
00155       return 1;
00156     }
00157     fprintf(stderr, "open_mmcif_read succeeded for file %s\n", *argv);
00158     fprintf(stderr, "number of atoms: %d\n", natoms);
00159 
00160     i = 0;
00161     timestep.coords = (float *)malloc(3*sizeof(float)*natoms);
00162     while (!read_mmcif_timestep(v, natoms, &timestep)) {
00163       i++;
00164     }
00165     fprintf(stderr, "ended read_next_timestep on frame %d\n", i);
00166 
00167     close_mmcif_read(v);
00168   }
00169   return 0;
00170 }
00171 
00172 #endif
00173 
00174 
00175 
00176 
00177 

Generated on Thu Mar 28 03:08:13 2024 for VMD Plugins (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002