1 /*
2 
3  *****************************************************************************
4  * Author:                                                                   *
5  * ------                                                                    *
6  *  Anton Kokalj                                  Email: Tone.Kokalj@ijs.si  *
7  *  Department of Physical and Organic Chemistry  Phone: x 386 1 477 3523    *
8  *  Jozef Stefan Institute                          Fax: x 386 1 477 3811    *
9  *  Jamova 39, SI-1000 Ljubljana                                             *
10  *  SLOVENIA                                                                 *
11  *                                                                           *
12  * Source: $XCRYSDEN_TOPDIR/C/struct.h
13  * ------                                                                    *
14  * Copyright (c) 1996-2003 by Anton Kokalj                                   *
15  * ------                                                                    *
16  * Modified by Eric Verfaillie ericverfaillie@yahoo.fr EV                    *
17  * may 2004                                                                  *
18  * modifcations are near EV comments                                         *
19   *****************************************************************************
20 
21 */
22 
23 /*
24    handle this near & far bug (needed for CYGWIN)
25 */
26 #ifndef STRUCT_H_
27 #define STRUCT_H_
28 
29 #ifdef NEAR_BUG
30 #ifdef near
31 #undef near
32 #endif
33 #ifdef far
34 #undef far
35 #endif
36 #endif /* NEAR_BUG */
37 
38 /*****************************************************************************/
39 /* XC_CPP_* are pre-processor flags */
40 #define XC_CPP_STRUCT
41 
42 #ifndef FREE_ARG
43 #  define FREE_ARG char*
44 #endif
45 
46 #define XC_CPP_GLH
47 #include <GL/gl.h>
48 
49 #ifndef MAX
50 #define MAX(a,b) ( (a)>(b)?(a):(b) )
51 #endif
52 #ifndef MIN
53 #define MIN(x,y) ( (x)<(y) ? (x) : (y) )
54 #endif
55 #ifndef ABS
56 #define ABS(x)   ( (x)>0?(x):-(x)  )
57 #endif
58 
59 #define DOT_V3(a,b)  ( (a)[0]*(b)[0] + (a)[1]*(b)[1] + (a)[2]*(b)[2] )
60 #define NORM_V3(v)   ( sqrt( (v)[0]*(v)[0] + (v)[1]*(v)[1] + (v)[2]*(v)[2] ) )
61 
62 #define LOAD_NULL_V(n, vec) \
63 do { \
64   register int __iv; \
65   for (__iv=0; __iv<n; __iv++) (vec)[__iv] = 0; \
66 } while(0)
67 
68 #define COPY_V(n, dst, src) \
69 do { \
70   register int __iv; \
71   for (__iv=0; __iv<n; __iv++) (dst)[__iv] = (src)[__iv]; \
72 } while(0)
73 
74 #define COPY_AND_SCALE_V(n, dst, scale, src) \
75 do { \
76   register int __iv; \
77   for (__iv=0; __iv<n; __iv++) (dst)[__iv] = scale * (src)[__iv]; \
78 } while(0)
79 
80 #define CLAMP_V(n, value, v) \
81 do { \
82   register int __iv; \
83   for (__iv=0; __iv<n; __iv++) \
84     v[__iv] = v[__iv] > value ? value : v[__iv]; \
85 } while(0);
86 
87 /*
88   I think this is not needed ...
89 
90   #define COPY_V_(n, dst, src) \
91   do { \
92   int __iv; \
93   for (__iv=0; __iv<n; __iv++) dst[__iv] = src[__iv]; \
94   } while(0)
95 
96 */
97 #define COPY_M33(dst, src) \
98 do { \
99   (dst)[0][0] = (src)[0][0]; (dst)[0][1] = (src)[0][1]; (dst)[0][2] = (src)[0][2]; \
100   (dst)[1][0] = (src)[1][0]; (dst)[1][1] = (src)[1][1]; (dst)[1][2] = (src)[1][2]; \
101   (dst)[2][0] = (src)[2][0]; (dst)[2][1] = (src)[2][1]; (dst)[2][2] = (src)[2][2]; \
102 } while(0)
103 
104 #define INVERT_M33(type, inverse, direct) \
105 do { \
106   type _d_e_t_, _m33_[3][3];                                           \
107                                                                        \
108   _m33_[0][0] = (direct)[1][1]*(direct)[2][2] - (direct)[1][2]*(direct)[2][1]; \
109   _m33_[0][1] = (direct)[1][2]*(direct)[2][0] - (direct)[1][0]*(direct)[2][2]; \
110   _m33_[0][2] = (direct)[1][0]*(direct)[2][1] - (direct)[2][0]*(direct)[1][1]; \
111   _m33_[1][1] = (direct)[0][0]*(direct)[2][2] - (direct)[0][2]*(direct)[2][0]; \
112   _m33_[1][2] = (direct)[2][0]*(direct)[0][1] - (direct)[0][0]*(direct)[2][1]; \
113   _m33_[2][2] = (direct)[0][0]*(direct)[1][1] - (direct)[0][1]*(direct)[1][0]; \
114   _m33_[1][0] = (direct)[2][1]*(direct)[0][2] - (direct)[0][1]*(direct)[2][2]; \
115   _m33_[2][0] = (direct)[0][1]*(direct)[1][2] - (direct)[1][1]*(direct)[0][2]; \
116   _m33_[2][1] = (direct)[0][2]*(direct)[1][0] - (direct)[0][0]*(direct)[1][2]; \
117                                                                        \
118   _d_e_t_ =                                                            \
119     (direct)[0][0]*_m33_[0][0] +                                       \
120     (direct)[0][1]*_m33_[0][1] +                                       \
121     (direct)[0][2]*_m33_[0][2];                                        \
122                                                                        \
123   /* make a check for zero devision */                                 \
124   /* ... here ... */                                                   \
125                                                                        \
126   (inverse)[0][0] = _m33_[0][0] / _d_e_t_;                             \
127   (inverse)[1][1] = _m33_[1][1] / _d_e_t_;                             \
128   (inverse)[2][2] = _m33_[2][2] / _d_e_t_;                             \
129   (inverse)[0][1] = _m33_[1][0] / _d_e_t_;                             \
130   (inverse)[0][2] = _m33_[2][0] / _d_e_t_;                             \
131   (inverse)[1][2] = _m33_[2][1] / _d_e_t_;                             \
132   (inverse)[1][0] = _m33_[0][1] / _d_e_t_;                             \
133   (inverse)[2][0] = _m33_[0][2] / _d_e_t_;                             \
134   (inverse)[2][1] = _m33_[1][2] / _d_e_t_;                             \
135 } while(0)
136 
137 #define XC_OK        1
138 #define XC_ERROR     0
139 #define XC_TRUE      1
140 #define XC_FALSE     0
141 #define XC_LEFT      1
142 #define XC_RIGHT     0
143 #define XC_YES       1
144 #define XC_NO        0
145 #define XC_ALLOWED   1
146 #define XC_FORBIDDEN 0
147 #define MAXNAT       100   /* maximum atomic number */
148 #define MINDIS       0.0001  /* minimum disitance between atoms (in A) allowed */
149 #define MINTOL       1.0e-15
150 #define MINTOL_F     1.0e-5
151 
152 #ifndef PI
153 #  define PI           3.14159265358979323844
154 #endif
155 #define PI12         1.57079632679489661922
156 #define RAD2DEG      57.295779513084
157 #define OUTLINE      1.0   /* this is for linewidth when rendering balls */
158 #define CIRCLE       6     /* determine how precise/smooth a 2Dballs are drawn
159 		            * CIRCLE = 1 -> maximum smoothness
160 		            */
161 #define FRAME_PAT    0xAAAA /* this is stipple pattern for frames */
162 
163 #define MAXSEL       25     /* maximum number of selected atoms */
164 #define N_SELECT_OBJ 2*MAXSEL     /* maximum number of selected objects (atoms+bonds) */
165 
166 /*============================================================================
167  * define flags for vorius objects
168  * this is used for glLists
169  */
170 #define N_LIST_PRIMITIVES 11
171 
172 #define POINT           0
173 #define BALL            1
174 #define OUTLINEBALL     2
175 
176 #define SPHEREWIRE	3
177 #define CYLINDERWIRE	4
178 #define CONEWIRE        5
179 #define BONDWIRE        6
180 
181 #define SPHERESOLID	7
182 #define CYLINDERSOLID	8
183 #define CONESOLID       9
184 #define BONDSOLID      10
185 
186 #define PIPEBALL       11
187 
188 /*****************************************************************************
189  * WARNING::                                                                 *
190  *          here below are few "global" variables and this are the only      *
191  *          variables that are not structures; all the others are structures *
192  *****************************************************************************/
193 
194 /*===============================================================*/
195 /* --- ATOMS & BONDS --- ATOMS & BONDS --- BEGIN --- BEGIN ---   */
196 /*===============================================================*/
197 #define MAX_BONDS 30
198 
199 int nbonds, natoms, nframes; /* number of bonds, number of atoms,
200 				       number of "crystal frame-pieces" */
201 
202 int tmp_nobjects;  /* number of objects to display:
203 		  nobjects = if(nbonds) + if(natoms) + if(nframes) */
204 int nobjects; /* total number of objects:
205 		 nobjects = nbonds + natoms + nframes */
206 
207 double *xat, *yat, *zat;           /* XYZ coordinates of atoms */
208 double (*fv)[3];                     /* force vector */
209 double *xbond, *ybond, *zbond;     /* XYZ of first end of a bond
210 				    * First End of a bond is always at atom
211 				    */
212 double *xbond2, *ybond2, *zbond2;  /* second end of a bond */
213 
214 #define BOND_ATOM_TO_MIDBOND 1
215 #define BOND_MIDBOND_TO_ATOM 2
216 #define BOND_ATOM_TO_ATOM    4
217 
218 
219 #define VORONOI_DEFAULT     0
220 #define VORONOI_WIGNERSEITZ 1
221 #define VORONOI_BZ          2
222 
223 
224 #define CENTERED_LABEL -999.999
225 
226 
227 
228 int *bondend; /* how the bond is oriented, ie. from atom to midbond or
229 		 from midbond to atom !!! */
230 
231 int *frametype;   /* flag for frame type (I/O connectivity) */
232 double *xframe, *yframe, *zframe;   /* XYZ of first end of a frame
233 				     * First End of a frame is always at atom
234 				     */
235 double *xframe2, *yframe2, *zframe2; /* second end of a frame */
236 
237 
238 double *zbmid; /* center of a bond in Z-direction */
239 
240 int *nat;  /* atomic number of an atom */
241 int *sqn;  /* sequential number of an atom */
242 int *natbond; /* to determine to what kind of an atom the bond bellong;
243 	       * all the rest of the attrib. will be derived from
244 	       * this parameter
245 	       */
246 int *sqnbond; /* will replace natbond;
247 	       * to determine to what kind of an atom the bond bellong;
248 	       * all the rest of the attrib. will be derived from
249 	       * this parameter
250 	       */
251 int *iwksp;   /* this is for Z-orientation (F77_INDEXX1) */
252 double mx, my, mz; /* geometrical centre of structure is always moved to
253 		    * (0,0,0); (mx,my,mz) is translation vector for that
254 		    */
255 
256 typedef struct {
257   double mx, my, mz;
258 } MX_MY_MZ;
259 MX_MY_MZ mx_my_mz;
260 
261 char displayMode2D[4];
262 
263 /*GLuint *primitive_Lists[N_LIST_PRIMITIVES]; */ /* holds the glLists ID for
264 					            various primitives */
265 
266 /*=========================================================================*/
267 /*     above were 1st part of global variables that are not structures     */
268 /*=========================================================================*/
269 
270 /* definitions for iso_objects:: */
271 #define ISOOBJ_BASE    0   /* base isosurface or colorplane/isolines */
272 #define ISOOBJ_PLANE1  1
273 #define ISOOBJ_PLANE2  2
274 #define ISOOBJ_PLANE3  3
275 #define MAX_ISOOBJECTS 4   /* for example: isosurface & three colorplanes */
276 
277 /* -------PARAMETERS NEEDED FOR STRUCTURE DISPLAY -----------------*/
278 typedef struct {
279   double x;                 /* xcViewPort's x */
280   double y;                 /* xcViewPort's y */
281   double sizex;          /* xcViewPort's size when X-croped */
282   double sizey;          /* xcViewPort's size when Y-croped */
283   double size;              /* xcViewPort's size when not croped */
284   int stropened;         /* when structure is opened this parameter is
285 			    set to 1
286 			  */
287   int canvassize;       /* size of a canvas in screen units
288 		           if height < width ==> canvassize = height
289 		           if Ycnv > Xcnv ==> canvassize = width
290 		         */
291   int width;            /* canvas width */
292   int height;           /* canvas height */
293   double VPfactor;      /* VPf.VPfactor = VPf.size / VPf.structsize; */
294   float scrAnX;         /* "screen units to angstroms" factor for X-dir. */
295   float scrAnY;         /* "screen units  to angstroms" factor for Y-dir. */
296   int WFlinewidth;      /* linewidth for WireFrame */
297   int WF3Dlinewidth;    /* linewidth for WireFrame */
298   int PLlinewidth;      /* linewidth for PointLine */
299   int OUTlinewidth;
300   int PLradius;         /* Point radius for PointLine */
301 
302   int framewidth;       /* linewidth for crystal-frames */
303 
304   double rcovf;         /* rcov[] = rcovf * rcovdef[]; this is scale factor
305 			   for chemical connectivity criteria */
306   /* double scrf; */         /* scrf == how biger is canvas than structure */
307   /* THIS IS FOR BALLSTICK MODE */
308   double ballf;         /* scale for balls; rball = ballf * rcov */
309   double rodf;          /* rod/bond scale factor;
310 		           rrod = ballf * rcov[H] * rodf */
311   double atradf;        /* scaled factor for balls and spacefills;
312 		           it's howmany times are spacefills/balls greater
313 		           than rcov or vdw
314 		         */
315   double tessFactor;    /* tessellation factor for xcPrimitives */
316   double framef;        /* analogous to ballf, rodf, just for frames */
317   GLboolean xyzOn;      /* true when coordinate sistem is displayed */
318   GLboolean labelsOn;   /* true when atomic labels are displayed */
319   GLboolean framesOn;   /* TRUE when "crystal" frames are displayed */
320   GLboolean selection;  /* true when we are in "selection" */
321   GLboolean atomadd;    /* true when we use "cell-adding selection" for
322                            cell-adding type of ATOMINSE crystal command */
323   GLboolean projmade;
324   GLboolean isosurf[MAX_ISOOBJECTS]; /*
325                               when isosurface is displayed, this is true */
326   GLboolean colorplane[MAX_ISOOBJECTS]; /*
327                               when "colorplane is displayed, this is true */
328   GLboolean isoline[MAX_ISOOBJECTS]; /*
329                               when "isoline-plane" is displayed this is true */
330   GLboolean wignerseitz; /* render wigner-seitz cell */
331   GLboolean supercell;   /* in supercell mode -> render vectors and
332 			    cell-cage */
333   GLboolean isospacesel2D; /* we are in IsoSpaceSel mode -> for isoplane case a
334 			      parallelogram is drawn; for isosurface case a
335 			      parallelepiped is drawn */
336   GLboolean isospacesel3D;
337   GLboolean force;     /* render the forces */
338   GLboolean Hbond;     /* render H-bonds */
339   GLboolean unibond;
340   GLboolean fog;
341   GLboolean antialias;
342   GLboolean perspective;
343   double    perspective_fovy;
344   double    perspective_far;
345   double    perspective_size;
346 
347   /* NEW; version 0.4.x on */
348   int       *surface;      /* new implementation of isosurfaces allow an
349 			      arbitrary isosurfaces to be displayed;
350 			      hence we need a logical pointer */
351   int       *surfaceInd;   /* mapping from mols->isosurf_index */
352   void      **surfacePtr;  /* pointer to MOL_SURF structure */
353   int       nsurface;
354   int       dispLattice;   /* do we want to display lattice (generated
355 			      separately, not read from FRAMES XSF section */
356   int       dispLatType;   /* display type for dispLattice */
357 } StructPar;
358 
359 StructPar VPf; /* all parameters for structure(molecule, crystal..) display
360 		* + state parameters are here */
361 
362 /*******************************/
363 /* this is for VPf.dispLatType */
364 #define CELL_WIRE           0
365 #define CELL_ROD            1
366 #define CELL_SOLID          2
367 #define CELL_SOLID_AND_WIRE 3
368 #define CELL_SOLID_AND_ROD  4
369 /*******************************/
370 
371 typedef struct {
372   double structsize;     /* each atomic structure has it's own size;
373 		          * STRUCTSIZE is a parameter for this
374 			  */
375   double isosize;        /* size of isoXXX; xc_isoexpand is taken into account
376                           */
377   double wignerseitzsize; /* size of wigner-seitz cells */
378   double isospaceselsize; /* size for iso_space_selelection
379 			     parallelogram/parallelopiped */
380   /* used for cryXXX stuff */
381   float o_shift[3];  /* origin shift; geometrical center of picture should be
382 			in the middle of MODELVIEW */
383 } ModelPar;
384 ModelPar MVf;
385 /*
386  * this definitions here are used for ResetVar(int var)
387  */
388 #define R_ATRAD                0
389 #define R_RCOV                 10000
390 #define R_RBALL                1
391 #define R_RROD                 2
392 #define R_ATCOL                3
393 #define R_WFLINEWIDTH          4
394 #define R_WF3DLINEWIDTH        10004
395 #define R_OUTLINEWIDTH         10005
396 #define R_PLLINEWIDTH          5
397 #define R_PLRADIUS             6
398 #define R_SCRF                 7
399 #define R_ALL                  8
400 #define R_FRAMECOL             9
401 #define R_FRAMELINEWIDTH       10
402 #define R_FRAMERODF            11
403 #define R_BACKGROUND           23
404 #define R_TESSELLATION         24
405 #define R_UNIBOND              25
406 #define R_UNIBONDCOLOR         26
407 #define R_PERSPECTIVE          27
408 #define R_PERSPECTIVEBACK      28
409 #define R_PERSPECTIVEFOVY      29
410 #define R_PERSPECTIVEFRONT     10029
411 #define R_FOG                  30
412 #define R_ANTIALIAS            31
413 #define R_AMBIENT_BY_DIFFUSE   32
414 #define R_CURRENTFILEFORMAT    33
415 #define R_HBOND                34
416 #define R_FORCE_RODTHICKF      35
417 #define R_FORCE_ARRTHICKF      36
418 #define R_FORCE_ARRLENF        37
419 #define R_FORCE_COLOR          38
420 #define R_XYZ_AXIS_COLOR       39
421 #define R_XYZ_XYPLANE_COLOR    40
422 
423 /*
424  * this definitions here are used for LoadNewValue(int var, double ....)
425  */
426 #define L_SPACE_COV            0
427 #define L_SPACE_VDW            1
428 #define L_BALL_COV             2
429 #define L_BALL_VDW             3
430 #define L_RCOV_ONE             10004
431 #define L_ATRAD_ONE            4
432 #define L_ATRAD_SCALE          5
433 #define L_BALLF                6
434 #define L_RODF                 7
435 #define L_ATCOL_ONE            8
436 #define L_WFLINEWIDTH          9
437 #define L_WF3DLINEWIDTH        10009
438 #define L_OUTLINEWIDTH         10010
439 #define L_PLLINEWIDTH          10
440 #define L_PLRADIUS             11
441 #define L_SCRF                 12
442 #define L_COV_SCALE            13
443 #define L_XYZ_ON               14  /* for coordinate sistem */
444 #define L_LABELS_ON            15  /* for atomic labels */
445 #define L_FRAME_ON             16
446 #define L_FRAMECOL             17
447 #define L_FRAMELINEWIDTH       18
448 #define L_FRAMERODF            19
449 #define L_LINEFRAME            20
450 #define L_TR_XTRANSL           21
451 #define L_TR_YTRANSL           22
452 #define L_BACKGROUND           23
453 #define L_TESSELLATION         24
454 #define L_UNIBOND              25
455 #define L_UNIBONDCOLOR         26
456 #define L_PERSPECTIVE          27
457 #define L_PERSPECTIVEBACK      28
458 #define L_PERSPECTIVEFOVY      29
459 #define L_PERSPECTIVEFRONT     10029
460 #define L_FOG                  30
461 #define L_ANTIALIAS            31
462 #define L_AMBIENT_BY_DIFFUSE   32
463 #define L_CURRENTFILEFORMAT    33
464 #define L_HBOND                34
465 #define L_FORCE_RODTHICKF      35
466 #define L_FORCE_ARRTHICKF      36
467 #define L_FORCE_ARRLENF        37
468 #define L_FORCE_COLOR          38
469 #define L_XYZ_AXIS_COLOR       39
470 #define L_XYZ_XYPLANE_COLOR    40
471 
472 
473 /*
474  * this definitions here are used for GetDefault(int var)
475  */
476 #define D_SCRF                 0
477 #define D_BALLF                1
478 #define D_RODF                 2
479 #define D_COVF                 3
480 #define D_ALL                  4
481 #define D_WFLINEWIDTH          5
482 #define D_WF3DLINEWIDTH        10005
483 #define D_OUTLINEWIDTH         10006
484 #define D_PLLINEWIDTH          6
485 #define D_PLRADIUS             7
486 #define D_ATCOL_ONE            8
487 #define D_ATRAD_SCALE          9
488 #define D_RCOV_ONE             10004
489 #define D_ATRAD_ONE            10
490 #define D_FRAMECOL             11
491 #define D_FRAMELINEWIDTH       12
492 #define D_FRAMERODF            13
493 #define D_MAXSTRUCTSIZE        14
494 #define D_BACKGROUND           23
495 #define D_TESSELLATION         24
496 #define D_UNIBOND              25
497 #define D_UNIBONDCOLOR         26
498 #define D_PERSPECTIVE          27
499 #define D_PERSPECTIVEBACK      28
500 #define D_PERSPECTIVEFOVY      29
501 #define D_PERSPECTIVEFRONT     10029
502 #define D_FOG                  30
503 #define D_ANTIALIAS            31
504 #define D_AMBIENT_BY_DIFFUSE   32
505 #define D_CURRENTFILEFORMAT    33
506 #define D_HBOND                34
507 #define D_FORCE_RODTHICKF      35
508 #define D_FORCE_ARRTHICKF      36
509 #define D_FORCE_ARRLENF        37
510 #define D_FORCE_COLOR          38
511 #define D_XYZ_AXIS_COLOR       39
512 #define D_XYZ_XYPLANE_COLOR    40
513 
514 
515 
516 /* this is used just by GetValue */
517 #define GET_NATOMS       100
518 #define GET_NAT          101
519 #define GET_SS_MINX      115
520 #define GET_SS_MINY      116
521 #define GET_SS_MINZ      117
522 #define GET_SS_MAXX      118
523 #define GET_SS_MAXY      119
524 #define GET_SS_MAXZ      120
525 #define GET_AT_MINX      10115
526 #define GET_AT_MINY      10116
527 #define GET_AT_MINZ      10117
528 #define GET_AT_MAXX      10118
529 #define GET_AT_MAXY      10119
530 #define GET_AT_MAXZ      10120
531 #define GET_ATOMLABEL_LABEL       121
532 #define GET_ATOMLABEL_BRIGHTCOLOR 122
533 #define GET_ATOMLABEL_DARKCOLOR   123
534 #define GET_ATOMLABEL_DO_DISPLAY  124
535 #define GET_ATOMLABEL_ALL_ID      125 /* flag for the ID's of all atoms than have cutom-labels */
536 #define GET_GLOBALATOMLABEL_BRIGHTCOLOR 126
537 #define GET_GLOBALATOMLABEL_DARKCOLOR   127
538 #define GET_GLOBALATOMLABEL_DO_DISPLAY  128
539 
540 #define GET_FOG_COLORMODE   130
541 #define GET_FOG_COLOR       131
542 #define GET_FOG_MODE        132
543 #define GET_FOG_DENSITY     133
544 #define GET_FOG_ORT_START_F 134
545 #define GET_FOG_ORT_END_F   135
546 #define GET_FOG_PERSP_F1    136
547 #define GET_FOG_PERSP_F2    137
548 
549 #define GET_ANTIALIAS_DEGREE 140
550 #define GET_ANTIALIAS_OFFSET 141
551 
552 #define GET_ALAT             150
553 
554 
555 #define SET_ATOMLABEL_DO_DISPLAY       200
556 #define SET_GLOBALATOMLABEL_DO_DISPLAY 201
557 #define SET_DO_NOT_DISPLAY_ATOMLABEL   202 /* apply to all atomic lables global and custom */
558 
559 #define SET_FOG_COLORMODE   210
560 #define SET_FOG_COLOR       211
561 #define SET_FOG_MODE        212
562 #define SET_FOG_DENSITY     213
563 #define SET_FOG_ORT_START_F 214
564 #define SET_FOG_ORT_END_F   215
565 #define SET_FOG_PERSP_F1    216
566 #define SET_FOG_PERSP_F2    217
567 
568 #define SET_ANTIALIAS_DEGREE 220
569 #define SET_ANTIALIAS_OFFSET 221
570 
571 /* ========================================================================= */
572 /* "defines" for xcMaybeDelete3DLists & ReDisplay--------------------------- */
573 #define DELETE3D_NONE         0
574 #define DELETE3D_BALL         1
575 #define DELETE3D_SPACE        2
576 #define DELETE3D_BOND         4
577 #define DELETE3D_FRAME        8
578 #define DELETE3D_LINEFRAME   16
579 #define DELETE3D_BALL_LABEL  32
580 #define DELETE3D_SPACE_LABEL 64
581 #define DELETE3D_ALL        127
582 
583 #define REMAKE3D_NONE         0
584 #define REMAKE3D_BALL         1
585 #define REMAKE3D_SPACE        2
586 #define REMAKE3D_BOND         4
587 #define REMAKE3D_FRAME        8
588 #define REMAKE3D_LINEFRAME   16
589 #define REMAKE3D_BALL_LABEL  32
590 #define REMAKE3D_SPACE_LABEL 64
591 #define REMAKE3D_ALL        127
592 
593 
594 /* --------------------------- */
595 /* --- some default values --- */
596 #define DEF_ZOOM  1.7
597 #define DEF_SCRF  1.5
598 #define DEF_BALLF 0.4
599 #define DEF_RODF  0.6
600 #define DEF_LineWidthWF   1
601 #define DEF_LineWidthWF3D 1
602 #define DEF_LineWidthOUT  1
603 #define DEF_LineWidthPL   1
604 #define DEF_RadiusPL      6
605 #define DEF_RCOVF         1.05     /* rcovdef is scaled by this factor and
606 				      this is criteria for chemmical
607 				      connectivity */
608 #define DEF_ATRADF          1.40
609 #define DEF_FRAMEWIDTH      1
610 #define DEF_FRAMERODF       0.1
611 #define DEF_TESSELLATION    30.0
612 #define DEF_UNIBOND         0
613 #define DEF_PERSPECTIVE     0
614 #define DEF_PERSPECTIVEFOVY  2.5
615 #define DEF_PERSPECTIVEBACK  3.0
616 #define DEF_PERSPECTIVEFRONT 1.0
617 #define DEF_FOG             0
618 #define DEF_ANTIALIAS       0
619 #define DEF_HBOND           0
620 
621 /* ---------- TRANSLATION & ZOOM TRANSFORMATION ------- */
622 typedef struct {
623   double xtransl;
624   double ytransl;
625   double zoom;
626   float  rotx;
627   float  roty;
628   float  rotz;
629   int    xrotold; /* this is for xc_rot2; B1-Motion rotation */
630   int    yrotold;
631   int    trXold; /* this is for xc_transl2; B2-Motion translation */
632   int    trYold;
633   int    b1motion; /* do we have B1-Motion; boolean */
634   int    b2motion; /* do we have B2-Motion; boolean */
635   int    shiftB1motion;
636 } Transform;
637 Transform tr;
638 
639 
640 typedef struct {
641   int *sqn;            /* sequential number of an atom (ex. atom n. 14) */
642   int *sqnat;          /* sequential number of an atom of a kind (ex. atom n. O3) */
643   GLfloat (*col)[3];   /* color for each atom; each displayed atom can have
644 			  its own color */
645   int natomkind;
646   int atomkind[MAXNAT+1];  /* array of elements that are in structure */
647 } AtomAtrib;
648 AtomAtrib atm;
649 
650 /* this is for flags - to recognise objects */
651 #define ATOM    0
652 #define SELATOM 1
653 #define BOND    2
654 #define SELLINE 3
655 #define SELBOND 4
656 #define FRAME   5
657 
658 /* when we orientate objects some objects must be above the others in case,
659  * that they are in the same plane
660  */
661 #define Z_OFFSET(x)       ( (0.0001 * x) )
662 
663 #define XC_NONE  0
664 #define XC_BOND  1
665 #define XC_ATOM  2
666 #define XC_LABEL 2   /* XC_ATOM and XC_LABEL are synonyms */
667 #define XC_FRAME 4
668 #define XC_HBOND 5
669 
670 /* ========================================================================
671  * --- AtomBond -- when we open structure, all data about structure goes in
672  * AtomBond
673  */
674 typedef struct {
675   int flag;    /* flag for ATOM or BOND or FRAME*/
676   int nat;     /* corresponding atomic number
677 		* from NAT all other atribbutes are assigned */
678   int sqn;     /* sequential number of atom; from sqn other attribbutes are
679 		  assigned */
680   int bondend;
681   GLuint list1; /* identifier for OUTLINEBALL list to use when
682 		   rendering balls */
683   GLuint list2; /* identifier for BALL list to use when
684 		   rendering balls */
685   double x1;
686   double y1;   /* for ATOMS only X1 Y1 Z1 are needed */
687   double z1;
688   double x2;   /* for BONDS also X2 Y2 Z2 are neede */
689   double y2;
690   double z2;
691 } AtomBond;
692 AtomBond *coor;  /* coordinates in original units
693 		  * on this coordinates I perform rotations,
694 		  * but never do Z-sorting;
695 		  * first goes nbonds, than natoms
696 		  */
697 
698 /* for Z-orientation */
699 double *zorient;  /* for ATOMs z == z1
700 		   * for BONDs z == 0.5 * (z1 + z2) + little
701 		   * z is center of object for Z coord. */
702 
703 /*****************************************************************************/
704 /* someday make the structure from that */
705 double rcov[MAXNAT + 1];  /* covalent radii */
706 extern double rvdw[MAXNAT + 1];  /* Van der Waals radii */
707 double atrad[MAXNAT + 1]; /* radii used to render atoms, balls; it's possible
708 			     to use rcov[], rvdw[], or some custom radii */
709 double rball[MAXNAT + 1]; /* balls radii: rball[]= VPf.ballf * atrad[]; */
710 double rrod;   /* rod's radius rrod= VPf.ballf * VPf.rodf * rcov[H] */
711 double rframe; /* crystal frame's radius */
712 extern GLfloat DefAtCol[MAXNAT + 1][3]; /* default atomic color */
713 float atcol[MAXNAT + 1][3];   /* atomic color used for rendering; it's possible
714 			      to define a custom colors or use default one */
715 extern GLfloat DefFrameCol[3];
716 float framecol[3];
717 extern GLclampf DefBg[4], DefUnibondCol[4];
718 GLclampf bg[4], unibondCol[4];
719 
720 
721 /*****************************************************************************/
722 /* THIS IS to manege 2D/3D */
723 #define XC_2D 0
724 #define XC_3D 1
725 GLboolean dimType;
726 
727 /* ========================================================================= */
728 /* Options; various boolean flags, for managing display options ------------ */
729 typedef struct {
730   GLboolean pipemode;
731   GLboolean stickmode; /* TK_r */
732   GLboolean ballmode; /* TK_b */
733   GLboolean spacefillmode; /* TK_f */
734   GLboolean smooth; /* if (smooth) -> GL_SMOOTH else GL_FLAT*/
735   GLboolean solid; /* if (solidmode) -> SOLID else WIRE */
736   GLboolean lineframe; /* if true LineFrameList is displyed, else
737 			  either SolidFrameList, either WireFrameList */
738   GLboolean anaglyph; /* EV if (anglyphmode) -> ANAGLYPH else NULL  */
739   GLboolean stereo;   /* GB do we use the SGI stereo mode */
740 } Options3D;
741 
742 
743 /*****************************************************************************/
744 /* this is for max size in each directions -> so that we can efficiently
745  * determine glOrtho
746  */
747 
748 typedef struct {
749   double x; /* maximum x */
750   double y;
751   double z;
752   double r; /* maximum radius */
753 } MaxSize;
754 
755 MaxSize max, min;
756 
757 /* ========================================================================= */
758 /* this is base for atom-label lists */
759 GLuint atomlabelOffset;
760 GLuint xyzlabelOffset;
761 
762 /* =========================================================================
763  * definition of voriuos vectors; coordinate sistem base-vectors, direct
764  * vectors, reciprocal vectors, ...
765    ========================================================================= */
766 #define CRDS_SIZE 130
767 typedef struct {
768   double crdmajor[4][4]; /* coor-sist major vec */
769   double crdnew[4][4];   /* coor-sist new vec   */
770   double crdold[4][4];   /* coor-sist old vec   */
771   double crdvec[16];
772   double prim[4][4];     /* primitiv-vectors; if we don't have crystal, then
773                           * expample: for slabs, the third vector is
774                           * (0,0,max.z)
775                           */
776   double conv[4][4];     /* conventional-vectors; if not crystal do same as
777                           * with prim[][]
778 			  */
779   double recprim[4][4];  /* reciprocal primitive-vectors */
780   double recconv[4][4];  /* reciprocal conventional-vectors */
781 } Vector;
782 Vector vec;
783 
784 
785 /* ========================================================================= */
786 /* structure for tracking the dimension of orthographic projection
787  */
788 typedef struct {
789   double size;
790   double minx;
791   double maxx;
792   double miny;
793   double maxy;
794   double minz;
795   double maxz;
796   double fi, near, far; /* for PERSPECTIVE */
797 } OrthoProj;
798 
799 
800 /*****************************************************************************/
801 /* this is for file format !!!!! */
802 #define FORMAT_NONE       0
803 #define FORMAT_XSF        1
804 #define FORMAT_XYZ        2
805 #define FORMAT_PDB        3
806 
807 int current_file_format;
808 
809 /*****************************************************************************/
810 /* XC_CPP_* are pre-processor flags */
811 #ifndef XC_CPP_BOOLEAN
812 typedef int boolean;
813 #define XC_CPP_BOOLEAN
814 #endif
815 
816 
817 /*****************************************************************************/
818 /* this is structures that hold XCRYSDEN file format information             */
819 /* XCRYSDEN file-format is defined and made by GENGEOM program               */
820 #define XCR_CELL           0   /* cell is the unit of repetition; look below */
821 #define XCR_TR_ASYM        1   /* translational symetric part is unit of
822                                   repetition                                 */
823 #define XCR_NOCELL         0
824 #define XCR_PRIMCELL       1   /* primitiv cell                              */
825 #define XCR_CONVCELL       2   /* conventional cell                          */
826 #define XCR_PARAPIPEDAL    0   /* parapipedal shape of cell                  */
827 #define XCR_HEXAGONAL      1   /* hexagonal shape of cell                    */
828 #define XCR_BZ             2
829 
830 /* this must be the same as in gengeom.f */
831 #define XCR_CELL_PC   1
832 #define XCR_CELL_AC   2
833 #define XCR_CELL_BC   3
834 #define XCR_CELL_CC   4
835 #define XCR_CELL_FC   5
836 #define XCR_CELL_IC   6
837 #define XCR_CELL_RC   7
838 #define XCR_CELL_HC   8
839 #define XCR_CELL_TNRC 9
840 
841 #define XCR_NCELL_TYPES 10
842 
843 #define XCR_CELL_IPC   1
844 #define XCR_CELL_IAC   2
845 #define XCR_CELL_IBC   2
846 #define XCR_CELL_ICC   2
847 #define XCR_CELL_IFC   4
848 #define XCR_CELL_IIC   2
849 #define XCR_CELL_IRC   3
850 #define XCR_CELL_IHC   3
851 #define XCR_CELL_ITNRC 3
852 
853 typedef struct {
854   int     dim;       /* dimensionality of sistem                             */
855   int     groupn;    /* number of group; it's from c95's ftn34;
856                         actually it's family not group                       */
857   float   cellpos[XCR_NCELL_TYPES][4][3]; /* fractional positions within the cell */
858   int     npos[XCR_NCELL_TYPES]; /* number of atoms(positions) within desired
859 				    cell type                                */
860   boolean ldimgroup; /* true if group-number is present in xcr-file          */
861   boolean lconvvec;  /* true if conv vectors are specified in xcr-file       */
862   boolean lprimvec;  /* true if prim vectors are specified in xcr-file       */
863   boolean lrecprimvec; /* true if prim reciprocal vectors are specified      */
864   boolean lrecconvvec; /* true if conv reciprocal vectors are specified      */
865   boolean lprimcoor; /* true if primcoord are specified in xcr-file          */
866   boolean lconvcoor; /* true if convcoord are specified in xcr-file          */
867   boolean lprimwigner; /* true if primitive Wigner-Seitz cell is specified   */
868   boolean lconvwigner; /* true if conventional Wigner-Seitz cell is specified*/
869   boolean lprimbz;   /* true if primitive Brillouin zone is specified        */
870   boolean lconvbz;   /* true if conventional Brillouin zone is specified     */
871   boolean ldatagrid2D; /* true if DATAGRID2D is specified                    */
872   boolean ldatagrid3D; /* true if DATAGRID3D is specefied                    */
873   boolean lbandgrid2D; /* true if BANDGRID2D is specified                    */
874   boolean lbandgrid3D; /* true if BANDGRID3D is specefied                    */
875   boolean lforce;      /* true if forces were specified                      */
876   /*boolean lHbond;*/      /* true if hydrogen bonds are present                 */
877   int natr;          /* number of atoms in primitiv cell                     */
878   int ncell;         /* "atoms per cell", FC ->4, RC -> 3, etc.              */
879   int     nunit[3];  /* number of units in each directions                   */
880   int     unit;      /* what is the unit "cell" or translational asym. part  */
881   int     celltype;  /* primitiv or convetional                              */
882   int     shape;     /* parapipedal or hexagonal                             */
883   int     *prim_nat; /* atomic numbers of atoms in primcell */
884   int     *conv_nat; /* atomic numbers of atoms in primcell */
885   double  (*prim_coor)[3];  /* Cartesian coordinates of atoms in primcell (in ANGSTROMS) */
886   double  (*prim_fcoor)[3]; /* fractional coordinates of atoms in primcell  */
887   double  (*prim_forc)[3];  /* Cartesian components of atomic forces in primcell */
888   boolean prim_lforc;       /* are forces in PRIMCOORD present */
889   double  (*conv_fcoor)[3];  /* fractional coordinates of atoms in convcell  */
890   double  (*conv_coor)[3];  /* Cartesian coordinates of atoms in convcell (in ANGSTROMS) */
891 } XcrInfo;
892 XcrInfo xcr;
893 
894 
895 /*****************************************************************************/
896 /* here are display-attributes for isosurface and colorplane                 */
897 typedef struct {
898   int       drawstyle;   /* drawstyle for isosurface rendering
899                        * ISOSURF_WIRE or ISOSURF_SOLID      */
900   GLenum    shademodel;
901   int       transparent;
902   GLboolean lighting;    /* lighting NO/OFF */
903 } ISO_ATTRIB;
904 
905 
906 /*****************************************************************************/
907 /* this is structure used for evauating custom Tcl/tk command's options      */
908 #ifdef XC_CPP_GLPARAM  /* xcGLparam.h header file was included               */
909 #   define COM_ISOEXPAND_REPEAT_DEFAULT         0
910 #   define COM_ISOEXPAND_REPEAT_CONVCELL        1
911 #   define COM_ISOEXPAND_REPEAT_PRIMCELL        2
912 #   define COM_ISOEXPAND_SHAPE_DEFAULT          0
913 #   define COM_ISOEXPAND_SHAPE_PARAPIPEDAL      1
914 #   define COM_ISOEXPAND_SHAPE_HEXAGONAL        2
915 #   define COM_ISOEXPAND_EXPAND_WHOLE           0
916 #   define COM_ISOEXPAND_EXPAND_LIST            1
917     typedef GetGlParam GetComOption;
918 #endif
919 
920 /*****************************************************************************/
921 #define WIGNERSEITZ_MAXPOLY    26 /* hope this is enough */
922 #define WIGNERSEITZ_MAXVERTEX  15
923 typedef struct {
924   int   npoly; /* number of polygons */
925   int   nvert[WIGNERSEITZ_MAXPOLY];
926   float max;   /* maximum value of coordinates (either X,Y,Z) */
927   float poly[WIGNERSEITZ_MAXPOLY][WIGNERSEITZ_MAXVERTEX][3];
928   float norm[WIGNERSEITZ_MAXPOLY][WIGNERSEITZ_MAXVERTEX][3];
929 } WIGNERSEITZ;
930 WIGNERSEITZ wsp, wsc;
931 
932 
933 /*****************************************************************************/
934 /*        LINESTIPPLE --- LINESTIPPLE --- LINESTIPPLE --- LINESTIPPLE        */
935 /*****************************************************************************/
936 #define LINESTIPPLE0      0x5555
937 #define LINESTIPPLE1   	  0x6b2d
938 #define LINESTIPPLE2   	  0x6735
939 #define LINESTIPPLE3   	  0xcf5e
940 #define LINESTIPPLE4   	  0xaf57
941 #define LINESTIPPLE5   	  0x3f49
942 #define LINESTIPPLE6   	  0xef4c
943 #define LINESTIPPLE7   	  0xe73a
944 #define LINESTIPPLE8   	  0x4f12
945 #define LINESTIPPLE9   	  0x8f32
946 #define LINESTIPPLE_SOLID 0xffff
947 
948 #define LINESTIPPLE_FACTOR0  1
949 #define LINESTIPPLE_FACTOR1  2
950 #define LINESTIPPLE_FACTOR2  3
951 #define LINESTIPPLE_FACTOR3  4
952 
953 /*************************/
954 /* DATAGRID --- DATAGRID */
955 /*************************/
956 #define DATAGRID_2D       2
957 #define DATAGRID_3D       3
958 #define RECIP_DATAGRID_3D 4
959 #define DATAGRID_MAXSUBINDEX 5000 /* do we need more that 5000 bands for Fermi surface ??? */
960 
961 #ifndef XC_CPP_NO_STDIO /* load DATAGRID only if stdio.h was included */
962 struct DATAGRID {
963   FILE   *fp;
964   int    type;        /* type of DATAGRID, i.e. 2D or 3D */
965   int    index;       /* identifier for *grid */
966   char   *ident;     /* identifier for the user */
967   int    n_of_subgrids; /* number of subgrids (up to DATAGRID_MAXSUBINDEX) */
968   int    n[3];        /* number of points in two/three direction */
969   float  orig[3];   /* xyz of origin */
970   float  vec[3][3]; /* format of vec: [vec#][xyz] */
971   struct DATAGRID *ptr;   /* pointer to previous struct */
972   int    selected[DATAGRID_MAXSUBINDEX];
973   long   fpos[DATAGRID_MAXSUBINDEX];       /* position if the file */
974   float  signfactor[DATAGRID_MAXSUBINDEX]; /* factor for subindex's datagrid */
975   char   *subident[DATAGRID_MAXSUBINDEX];
976   int    lband, nband, *band_index[DATAGRID_MAXSUBINDEX];
977   long   *band_fpos[DATAGRID_MAXSUBINDEX];
978   float  minvalue[DATAGRID_MAXSUBINDEX]; /* minimum value in the grid */
979   float  maxvalue[DATAGRID_MAXSUBINDEX]; /* maximum value in the grid */
980 };
981 #endif
982 
983 /* here are some data about raster font stored in xcLabels.c */
984 typedef struct {
985   GLsizei wid;
986   GLsizei height;
987   GLfloat w2;
988   GLfloat h2;
989   GLfloat wp2;
990   GLfloat hp2;
991 } RasterFontSize;
992 
993 
994 #ifdef _TK
995 typedef struct {
996   GLuint  base;
997   GLsizei width;
998   GLsizei height;
999   GLfloat bright_color[3];
1000   GLfloat dark_color[3];
1001   short   do_display;
1002   char    *label;
1003   Tk_Font tkfont;
1004 } AtomicLabel;
1005 #endif
1006 
1007 /* minimum and maximum coorinates of structure atoms */
1008 typedef struct {
1009   double minX;
1010   double minY;
1011   double minZ;
1012   double maxX;
1013   double maxY;
1014   double maxZ;
1015 } StructSize;
1016 
1017 
1018 /*
1019   Now, just ".mesa" togl is over. We can create an arbitrary nember of togls
1020   and display the structures into them. Everyting is dynmicaly allocated, and
1021   NEW_WIN_CONTEXT is a structure that holds everything !!!
1022 */
1023 #ifdef TOGL_H
1024 
1025 #define FS_SINGLE  0
1026 #define FS_MULTI   1
1027 
1028 struct FS_CONTEXT {
1029   int           ntogl;
1030   struct Togl **toglVector;
1031 };
1032 
1033 struct NEW_WIN_CONTEXTstr {
1034   struct NEW_WIN_CONTEXTstr *ptr;
1035   struct Togl               *togl;
1036   struct FS_CONTEXT         fermiContext;
1037   int           index;
1038   StructPar     VPf;
1039   ModelPar      MVf;
1040   Transform     tr;
1041   StructSize    ss;
1042   Vector        vec;
1043   void          *recprim_cage; /* pointer to CellCage recprim_cage; */
1044   GLclampf      bg[4];
1045   void          (*xcDisplay)(struct Togl *togl);
1046 };
1047 
1048 typedef struct NEW_WIN_CONTEXTstr NEW_WIN_CONTEXT;
1049 #endif
1050 
1051 #define XC_FORCE_TRESHHOLD    0.0005
1052 #define XC_FORCE_LENGTHFACTOR 200
1053 
1054 /* this is for rendering Force Vectors */
1055 typedef struct {
1056   float  (*ScaleFunc)(float value);
1057   float  threshold;
1058   float  lengthfactor;
1059 
1060   float  rod_thickf;     /* vector's thickness factor */
1061   float  arr_thickf; /* thickness factor for the arrow */
1062   float  arr_lenf;   /* length of the arrow */
1063 
1064   float  color[4];
1065 
1066   /*
1067      this is maximum size for atom+force (for making correct
1068      projection/viewport)
1069   */
1070   float max_size;
1071 } ForceVector;
1072 
1073 
1074 /* structure for gluPerspective */
1075 typedef struct {
1076   GLdouble fovy;
1077   GLdouble aspect;
1078   GLdouble near;
1079   GLdouble far;
1080   GLdouble shiftZ;
1081 } PERSPECTIVE;
1082 
1083 /* fog (i.e. depth cuing) */
1084 #define XC_FOG_BGCOLOR     0
1085 #define XC_FOG_CUSTOMCOLOR 1
1086 #define XC_FOG_LINEAR      2
1087 #define XC_FOG_EXP         3
1088 #define XC_FOG_EXP2        4
1089 
1090 typedef struct {
1091   int     colormode; /* can be CUSTOMCOLOR or BGCOLOR */
1092   GLfloat color[4];
1093   GLint   mode;
1094   GLfloat density;
1095   GLfloat ort_start_f;
1096   GLfloat ort_end_f;
1097   GLfloat persp_f1;
1098   GLfloat persp_f2;
1099 } XCfog;
1100 
1101 typedef struct {
1102   int    degree;
1103   float  offset;
1104 } XCantialias;
1105 
1106 
1107 /* 3D vector:     double precision */
1108 typedef double VEC3d[3];
1109 
1110 /* H-bonds */
1111 typedef struct {
1112   int   n;                      /* number of H-bonds                         */
1113   int   max_n;                  /* allocated number of H-bonds               */
1114   int   *H_like_list;           /* lists of H-like atoms                     */
1115   int   *O_like_list;           /* lists of O-like atoms                     */
1116   float  color[4];              /* color of the H-bonds                      */
1117   double length_min;            /* minimum H-bond length                     */
1118   double length_max;            /* maximum H-bond length                     */
1119   double angle_min;             /* minimum-angle; Namely the angle
1120 				   between H-chemical bond and H-bond
1121 				   must be close to 180 degrees
1122 				   (i.e. greater than angle_min)             */
1123   unsigned short line_pattern;  /* line stipple pattern                      */
1124   int    line_patternsize;
1125   float  line_width;
1126   VEC3d  *start_coor;           /* start coordinates of the H-bond           */
1127   VEC3d  *end_coor;             /* end coordinates of the H-bond             */
1128 } H_Bond;
1129 
1130 
1131 int crystal_version; /* what is the version of CRYSTAL program we are using */
1132 
1133 /*
1134   color for the Coordinate system display
1135 */
1136 typedef struct {
1137   float  axis_color[4];
1138   float  xyplane_color[4];
1139 } XYZ_Attrib;
1140 
1141 
1142 /*
1143   movie making
1144 */
1145 
1146 #define MOVIE_MODE_EVERY_SNAPSHOT 0
1147 #define MOVIE_MODE_REALTIME_INTERVAL 1
1148 
1149 typedef struct {
1150   int mode;
1151   int nframe;
1152   int doit;
1153   int printing;
1154   char *dir;
1155 } realTimeMove;
1156 
1157 extern const char *printImage;
1158 
1159 #endif
1160