00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _VASPPLUGIN_H_
00012 #define _VASPPLUGIN_H_
00013
00014 #include <stdio.h>
00015 #include <math.h>
00016 #include "molfile_plugin.h"
00017
00018 #define LINESIZE 1024
00019 #define MAXATOMTYPES 100
00020
00021 #ifndef M_PI
00022 #define M_PI 3.14159265358979323846
00023 #endif
00024
00025 typedef struct {
00026 FILE *file;
00027 char *filename;
00028 char *titleline;
00029 int version;
00030 int numatoms;
00031 int eachatom[MAXATOMTYPES];
00032 molfile_atom_t *atomlist;
00033
00034 float cell[3][3];
00035 float rotmat[3][3];
00036
00037
00038 int nvolsets;
00039 molfile_volumetric_t *vol;
00040 } vasp_plugindata_t;
00041
00042
00043
00044 static vasp_plugindata_t *vasp_plugindata_malloc()
00045 {
00046 vasp_plugindata_t *data = (vasp_plugindata_t *)malloc(sizeof(vasp_plugindata_t));
00047
00048 if (!data) {
00049 fprintf(stderr, "\n\nVASP plugin) ERROR: cannot allocate memory for plugin data.\n");
00050 return NULL;
00051 }
00052
00053 data->file = NULL;
00054 data->filename = NULL;
00055 data->titleline = NULL;
00056 data->atomlist = NULL;
00057 data->vol = NULL;
00058
00059 return data;
00060 }
00061
00062
00063
00064 static void vasp_plugindata_free(vasp_plugindata_t *data)
00065 {
00066 if (!data) return;
00067
00068 if (data->file) fclose(data->file);
00069 if (data->filename) free(data->filename);
00070 if (data->titleline) free(data->titleline);
00071 if (data->atomlist) free(data->atomlist);
00072 if (data->vol) free(data->vol);
00073 free(data);
00074 data = NULL;
00075 }
00076
00077
00078
00079 static void vasp_buildrotmat(vasp_plugindata_t *data)
00080 {
00081 float const *const a = data->cell[0];
00082 float const *const b = data->cell[1];
00083
00084
00085 const double len = sqrt(a[0]*a[0] + a[1]*a[1]);
00086 const double phi = atan2((double) a[2], (double) len);
00087 const double theta = atan2((double) a[1], (double) a[0]);
00088
00089 const double cph = cos(phi);
00090 const double cth = cos(theta);
00091 const double sph = sin(phi);
00092 const double sth = sin(theta);
00093
00094
00095 const double psi = atan2(-sph*cth*b[0] - sph*sth*b[1] + cph*b[2],-sth*b[0] + cth*b[1]);
00096 const double cps = cos(psi);
00097 const double sps = sin(psi);
00098
00099 data->rotmat[0][0] = cph*cth;
00100 data->rotmat[0][1] = cph*sth;
00101 data->rotmat[0][2] = sph;
00102 data->rotmat[1][0] = -sth*cps - sph*cth*sps;
00103 data->rotmat[1][1] = cth*cps - sph*sth*sps;
00104 data->rotmat[1][2] = cph*sps;
00105 data->rotmat[2][0] = sth*sps - sph*cth*cps;
00106 data->rotmat[2][1] = -cth*sps - sph*sth*cps;
00107 data->rotmat[2][2] = cph*cps;
00108 }
00109
00110
00111 static void vasp_timestep_unitcell(molfile_timestep_t *ts, vasp_plugindata_t *data)
00112 {
00113 if (!ts || !data) return;
00114
00115 ts->A = sqrt(data->cell[0][0]*data->cell[0][0]+data->cell[0][1]*data->cell[0][1]+data->cell[0][2]*data->cell[0][2]);
00116 ts->B = sqrt(data->cell[1][0]*data->cell[1][0]+data->cell[1][1]*data->cell[1][1]+data->cell[1][2]*data->cell[1][2]);
00117 ts->C = sqrt(data->cell[2][0]*data->cell[2][0]+data->cell[2][1]*data->cell[2][1]+data->cell[2][2]*data->cell[2][2]);
00118
00119 ts->gamma = acos((data->cell[0][0]*data->cell[1][0]+data->cell[0][1]*data->cell[1][1]+data->cell[0][2]*data->cell[1][2])/(ts->A*ts->B))*180.0/M_PI;
00120 ts->beta = acos((data->cell[0][0]*data->cell[2][0]+data->cell[0][1]*data->cell[2][1]+data->cell[0][2]*data->cell[2][2])/(ts->A*ts->C))*180.0/M_PI;
00121 ts->alpha = acos((data->cell[1][0]*data->cell[2][0]+data->cell[1][1]*data->cell[2][1]+data->cell[1][2]*data->cell[2][2])/(ts->B*ts->C))*180.0/M_PI;
00122 }
00123
00124 #endif