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

biomoccaplugin.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: biomoccaplugin.C,v $
00013  *      $Author: johns $       $Locker:  $             $State: Exp $
00014  *      $Revision: 1.6 $       $Date: 2016/11/28 05:01:53 $
00015  *
00016  ***************************************************************************/
00017 
00018 /* 
00019  * Biomocca volumetric map file reader
00020  *   Biomocca is written by the CEG at UIUC:
00021  *     http://www.ceg.uiuc.edu/
00022  *
00023  * File format (simple ASCII text): 
00024  * Xcenter Ycenter Zcenter (in Angstroms)
00025  * Nx(number of cells on the x axis)  Ny  Nz
00026  * d (cell spacing, in Angstroms)
00027  * Voxel values (-1, 0, 1, ...) stored in Z/Y/X fortran style order
00028  *
00029  * Meaning of voxel values: 
00030  * -1 for lipid
00031  *  0 for channel or solvent baths
00032  *  1 stands for the protein
00033  */
00034 
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <math.h>
00038 #include <string.h>
00039 
00040 #if defined(_AIX)
00041 #include <strings.h>
00042 #endif
00043 
00044 #include "molfile_plugin.h"
00045 
00046 typedef struct {
00047   FILE *fd;
00048   int nsets;
00049   molfile_volumetric_t *vol;
00050 } biomocca_t;
00051 
00052 
00053 static void *open_biomocca_read(const char *filepath, const char *filetype,
00054     int *natoms) {
00055   FILE *fd;
00056   biomocca_t *biomocca;
00057   float scale;
00058   int xsize, ysize, zsize;
00059   float orig[3];
00060   
00061   fd = fopen(filepath, "r");
00062   if (!fd) {
00063     printf("biomoccaplugin) Error opening file.\n");
00064     return NULL;
00065   }
00066 
00067   if (fscanf(fd, "%f %f %f", orig, orig+1, orig+2) != 3) {
00068     printf("biomoccaplugin) Error reading grid origin.\n");
00069     return NULL;
00070   }
00071 
00072   /* get the number of grid points */
00073   if (fscanf(fd, "%d %d %d", &xsize, &ysize, &zsize) != 3) {
00074     printf("biomoccaplugin) Error reading grid dimensions.\n");
00075     return NULL;
00076   }
00077 
00078   /* get the voxel scale */
00079   if (fscanf(fd, "%f", &scale) != 1) {;
00080     printf("biomoccaplugin) Error reading voxel scale.\n");
00081     return NULL;
00082   }
00083 
00084   /* allocate and initialize the biomocca structure */
00085   biomocca = new biomocca_t;
00086   biomocca->fd = fd;
00087   biomocca->vol = NULL;
00088   *natoms = MOLFILE_NUMATOMS_NONE;
00089   biomocca->nsets = 1; /* this file contains only one data set */
00090 
00091   biomocca->vol = new molfile_volumetric_t[1];
00092   strcpy(biomocca->vol[0].dataname, "BioMocca map");
00093 
00094   /* Set the unit cell origin and basis vectors */
00095   for (int i=0; i<3; i++) {
00096     biomocca->vol[0].origin[i] = orig[i];
00097     biomocca->vol[0].xaxis[i] = 0.0;
00098     biomocca->vol[0].yaxis[i] = 0.0;
00099     biomocca->vol[0].zaxis[i] = 0.0;
00100   }
00101 
00102   biomocca->vol[0].xaxis[0] = scale * (xsize-1);
00103   biomocca->vol[0].yaxis[1] = scale * (ysize-1);
00104   biomocca->vol[0].zaxis[2] = scale * (zsize-1);
00105 
00106   biomocca->vol[0].origin[0] -= 0.5 * biomocca->vol[0].xaxis[0];
00107   biomocca->vol[0].origin[1] -= 0.5 * biomocca->vol[0].yaxis[1];
00108   biomocca->vol[0].origin[2] -= 0.5 * biomocca->vol[0].zaxis[2];
00109 
00110   biomocca->vol[0].xsize = xsize;
00111   biomocca->vol[0].ysize = ysize;
00112   biomocca->vol[0].zsize = zsize;
00113 
00114   biomocca->vol[0].has_color = 0; /* BioMocca maps contain no color info */
00115 
00116   return biomocca;
00117 }
00118 
00119 static int read_biomocca_metadata(void *v, int *nsets, 
00120   molfile_volumetric_t **metadata) {
00121   biomocca_t *biomocca = (biomocca_t *)v;
00122   *nsets = biomocca->nsets; 
00123   *metadata = biomocca->vol;  
00124 
00125   return MOLFILE_SUCCESS;
00126 }
00127 
00128 static int read_biomocca_data(void *v, int set, float *datablock,
00129                          float *colorblock) {
00130   biomocca_t *biomocca = (biomocca_t *)v;
00131   FILE *fd = biomocca->fd;
00132   int x, y, z, xsize, ysize, zsize, xysize;
00133 
00134   xsize = biomocca->vol[0].xsize;
00135   ysize = biomocca->vol[0].ysize;
00136   zsize = biomocca->vol[0].zsize;
00137   xysize = xsize * ysize;
00138 
00139   for (x=0; x<xsize; x++) {
00140     for (y=0; y<ysize; y++) {
00141       for (z=0; z<zsize; z++) {
00142         if (fscanf(fd, "%f", datablock + z*xysize + y*xsize + x) != 1) {
00143           printf("biomoccaplugin) Failed reading biomocca map data\n");
00144           return MOLFILE_ERROR;
00145         }
00146   
00147       }
00148     }
00149   }
00150 
00151   return MOLFILE_SUCCESS;
00152 }
00153 
00154 static void close_biomocca_read(void *v) {
00155   biomocca_t *biomocca = (biomocca_t *)v;
00156   
00157   fclose(biomocca->fd);
00158   if (biomocca->vol != NULL)
00159     delete [] biomocca->vol; 
00160   delete biomocca;
00161 }
00162 
00163 /*
00164  * Initialization stuff here
00165  */
00166 static molfile_plugin_t plugin;
00167 
00168 VMDPLUGIN_API int VMDPLUGIN_init(void) { 
00169   memset(&plugin, 0, sizeof(molfile_plugin_t)); 
00170   plugin.abiversion = vmdplugin_ABIVERSION;
00171   plugin.type = MOLFILE_PLUGIN_TYPE;
00172   plugin.name = "biomocca";
00173   plugin.prettyname = "Biomocca Volumetric Map";
00174   plugin.author = "John Stone";
00175   plugin.majorv = 0;
00176   plugin.minorv = 2;
00177   plugin.is_reentrant = VMDPLUGIN_THREADSAFE;
00178   plugin.filename_extension = "bmcg";
00179   plugin.open_file_read = open_biomocca_read;
00180   plugin.read_volumetric_metadata = read_biomocca_metadata;
00181   plugin.read_volumetric_data = read_biomocca_data;
00182   plugin.close_file_read = close_biomocca_read;
00183  
00184   return VMDPLUGIN_SUCCESS; 
00185 }
00186 
00187 VMDPLUGIN_API int VMDPLUGIN_fini(void) { return VMDPLUGIN_SUCCESS; }
00188 
00189 VMDPLUGIN_API int VMDPLUGIN_register(void *v, vmdplugin_register_cb cb) {
00190   (*cb)(v, (vmdplugin_t *)&plugin);
00191   return VMDPLUGIN_SUCCESS;
00192 }
00193 

Generated on Fri Jan 24 02:56:14 2020 for VMD Plugins (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002