1 #ifdef VMS
2 #include "decw$include:xlib.h"
3 #include "decw$include:xutil.h"
4 #include "decw$include:xos.h"
5 #include "decw$include:keysym.h"
6 #include "decw$include:cursorfont.h"
7 #include "decw$include:xatom.h"
8 #include <descrip.h>
9 #include <processes.h>
10 #define fork vfork
11 #else
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 #include <X11/Xos.h>
15 #include <X11/keysym.h>
16 #include <X11/cursorfont.h>
17 #include <X11/Xatom.h>
18 #ifdef DOGL
19 #include <GL/glx.h>
20 #include <GL/gl.h>
21 #include <GL/glu.h>
22 #endif
23 #if defined(DARWIN) || defined(FREEBSD) || defined(__DragonFly__)
24 #else
25 #include <malloc.h>
26 #endif
27 #endif
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <signal.h>
33 #include <stddef.h>
34 #include <errno.h>
35 #include <unistd.h>
36 #include <stdint.h>
37 #include <sys/stat.h>
38 sigset_t block_alarm;
39 sigset_t waiting_mask;
40 sigset_t base_mask;
41 
42 #ifdef HASTIMER
43 #include <sys/time.h>
44 static struct itimerval it[3],ot;
45 #endif
46 
47 #ifdef CRAY
48 #include <fortran.h>
49 #endif
50 
51 #if defined(CRAY) || defined(DARWIN)
52 typedef char BMap;
53 #else
54 typedef unsigned char BMap;
55 #endif
56 
57 #define ABS(a) (((a) > 0) ? (a) : (-(a)))
58 #define SIGN(a) (((a) > 0) ? 1 : -1)
59 #define MAXI(a,b)      ((a)>=(b)?(a):(b))
60 #define MINI(a,b)      ((a)<=(b)?(a):(b))
61 
62 #define FONT "-*-fixed-medium-r-semicondensed-*-13-*-*-*-*-*-*-*"
63 #define LFONT "-*-helvetica-bold-r-*-*-24-*-*-*-*-*-*-*"
64 /*#define LFONT "-*-*-*-*-*-*-20-*-*-*-*-*-*-*"*/
65 #define SFONT "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*"
66 #define DenWindow 0
67 #define OpenWindow 1
68 #define MovePen 2
69 #define DrawLine 3
70 #define DrawString 4
71 #define ClearScreen 6
72 #define SolidLine 8
73 #define DashedLine 9
74 #define LineWidth 10
75 #define MolWindow 15
76 #define ParseNorbs 16
77 #define ChangeColor 99
78 #define FillPoly 100
79 
80 static char *selstr =
81 	"To Select: Hold mouse button down while dragging the cursor";
82 static char *dselstr =
83 	"To DeSelect: Hold mouse button down while dragging the cursor";
84 static int SelRes = -3;
85 static int SelDel = 0;
86 static int xison = 0;
87 static int DoFreq = 0;
88 static int DoEig = 0;
89 static int *movie;
90 static int *iuhf;
91 static int ibeta;
92 static int lhoh = -1;
93 static double *esp;
94 static double *pol;
95 static double *pol2;
96 static double *dmao;
97 static int *nor;
98 typedef struct {
99 	double *cl;
100 	double *rij;
101 	double *qpix;
102 	double *qpjx;
103 	double *dmao;
104 	int *nor;
105 	int *iord;
106 	int *iir; } BOYSPNT;
107 static BOYSPNT boy = { NULL,NULL,NULL,NULL,NULL,NULL };
108 typedef struct {
109 	double *xden;
110 	double *yden;
111 	double *zden;
112 	} FSTGRD;
113 static FSTGRD fsgrd = { NULL,NULL,NULL};
114 static int *ipsa;
115 static int *icpsa;
116 static int *idtpsa;
117 static double cntval = 0.01;
118 typedef struct { double r; double g; double b; } RGB;
119 static RGB *mapcol;
120 static unsigned long mappedcols[5];
121 static double *valcol;
122 static double *espvdw;
123 static int *cubetyp;
124 static float *frmul;
125 static int *normc;
126 static int has_box = 0;
127 
128 
129 typedef struct {
130 		 int natc;
131 		 int norg;
132 		 int icent;
133 		 int inorm;
134 		 int ncon;
135 		 int nspg;
136 		 int kz;
137 		 int ichx;
138 		 int icrtp;
139 		 int nopr;
140 		 short int ir[3][3][192];
141 		 short int it[3][192];
142 		 double xyzc[6];
143 		 double cellc[6];
144                } CELLSTRU;
145 static CELLSTRU *cell;
146 
147 typedef struct { int iclon;
148 		 int iclpnt[4];
149                } CELLSTRUC;
150 static CELLSTRUC *cellpnt;
151 static char *CellStr[] = {" O"," A"," B"," C"};
152 
153 typedef struct {
154 		 int ipoints;
155 		 int ipnt;
156                } PNTSTRU;
157 static PNTSTRU *pnt;
158 
159 typedef struct {
160 		 int *nzm;
161 		 int *nso;
162 		 int *nio;
163 		 int *nzo;
164 		 int *ioropt;
165 		 int *ifor;
166 		 int *ixyz98;
167 		 int *iopr;
168 		 int *isymm;
169 		 int *irc;
170 		 int *imp2;
171 		 int *icntp;
172 		 int *msucc;
173 		 int *ioni;
174 		 int *mopopt;
175 		 int *isbin;
176 		 int *irtype;
177 		 int *ipdbgro;
178 		 int *ifav;
179 		 int *ioxyz;
180 		 int *iconv;
181 		 int *ircus;
182 		 int *nscnd;
183 		 int *iscst;
184 		 int *ialtyp;
185                } PPOISTRU;
186 static PPOISTRU ptrpoi;
187 
188 typedef struct {
189 		 int nzm;
190 		 int nso;
191 		 int nio;
192 		 int nzo;
193 		 int ioropt;
194 		 int ifor;
195 		 int ixyz98;
196 		 int iopr;
197 		 int isymm;
198 		 int irc;
199 		 int imp2;
200 		 int icntp;
201 		 int msucc;
202 		 int ioni;
203 		 int mopopt;
204 		 int isbin;
205 		 int irtype;
206 		 int ipdbgro;
207 		 int ifav;
208 		 int ioxyz;
209 		 int iconv;
210 		 int ircus;
211 		 int nscnd;
212 		 int iscst;
213 		 int ialtyp;
214                } POISTRU;
215 static POISTRU poi;
216 
217 typedef struct {
218 		 double abc[3];
219 		 int ibox;
220 		 int icell;
221 		 int igfmap;
222                } PBCSTRUC;
223 static PBCSTRUC *pbc;
224 
225 typedef struct {
226 		 int type;
227 		 float rad;
228 		 float vec1[3];
229 		 float vec2[3];
230 		 float cor[3];
231 		 int size;
232 		 int incl;
233                } PHARMSTRUC;
234 
235 typedef struct {
236 		 int nfeat;
237 		 int *ixp;
238 		 int *iyp;
239 		 double *rzp;
240 		 PHARMSTRUC *array;
241 		 int NSelFeat;
242 		 char **str;
243 		 int *index;
244 	       } PHARMFSTRUC;
245 
246 static PHARMFSTRUC pharm = {0,NULL,NULL,NULL,NULL,0,NULL,NULL};
247 
248 static char *FeatStr[] = {"Aromatic","HydrogenDonor","HydrogenAcceptor","PositiveIon","NegativeIon","Hydrophobic"};
249 /*
250 aro orange
251 don purple
252 acc blue
253 pos dark blue
254 neg red
255 hyd green
256 */
257 static int FeatCol[] = {1,2,3,4,5,6};
258 
259 typedef struct {
260 		 int type;
261 		 float x1;
262 		 float y1;
263 		 float x2;
264 		 float y2;
265 		 float poly[6];
266 		 int col;
267 		 char *str;
268                } SVGSTRUC;
269 
270 typedef struct { int ncmd;
271 		 float w;
272 		 float h;
273 		 SVGSTRUC *array;
274                } SVGFSTRUC;
275 
276 typedef struct { int UpSVG;
277 		 int NUpSVG;
278 		 int CurSVG;
279 		 int ReadSVG;
280 		 int istruct;
281 		 int pid;
282 		} BckSVG;
283 
284 static BckSVG bcksvg = {0,0,0,0,0,0};
285 
286 #define DCKDEBUG 0
287 static int debugdck = DCKDEBUG;
288 
289 static int DCKSVG = 0;
290 static SVGFSTRUC *DCKsvg;
291 
292 static Bool DCKLIGPROC = 0;
293 static Bool DCKPROTPROC = -1;
294 static Bool DCKBYPASS = 0;
295 static Bool DCKINVOKE = 0;
296 static int DoDockCenter = 0;
297 static int IntSurfDone = 0;
298 static int DoIntSurf = 0;
299 static float CNTDCK[3];
300 static double DCKRadius = 3.5;
301 static float OPTRadius = 10.0;
302 
303 static char ogDockStr[] = "Click on an ligand atom to define docking center\n\
304 Use the mouse wheel to increase the docking radius\n\
305 When done hit the esc key";
306 static char ogXYZStr[] =
307 	"Supply the name of the XYZ file containing the structure\n\
308 to align to the current molecule.\n \n\
309  - Use the standard rotation, translation and zoom in/out.\n\
310  - Use the Esc to switch between rotation of part or the whole structure\n\
311  - Use the Tab to enter the select mode; select 3 couples of atoms to align\n\
312    A couple= atom structure1 (red), atom structure2 (white)";
313 static char ogOVRLStr[] =
314 	"Supply the name of the PDB file containing the ligand\n\
315 to align to the current molecule.\n \n\
316  - Use the standard rotation, translation and zoom in/out.\n\
317      Cntrl+mouse       = Zoom / Z-translation,\n\
318      Shift+mouse       = X/Y-translation\n\
319      Cntrl+Shift+mouse = Z-rotation\n\
320  - Use the Esc to switch between rotation of part or the whole structure\n\
321  - Use the arrow keys  in addition to the mouse for rotation\n\
322  - Use the Keypad keys in addition to the mouse for translation\n\n\
323    Translation X-axis:      KP_4, KP_6  \n\
324    Translation Y-axis:      KP_8, KP_2  \n\
325    Translation Z-axis:      KP_1, KP_3  \n\
326    Rotation    Z-axis:      KP_7, KP_9  \n\n\
327  - DONT FORGET to switch on the NUMLOCK key when using the Keypad keys\n\
328  - Use the Coarse icon (between the arrow buttons) to change the step/angle\n\
329    increment ";
330 static char ogLigStr[] =
331 	"Select a ligand Molecule on screen by clicking one of its atoms\n\n\
332  - Use the standard rotation, translation and zoom in/out.\n\
333      Cntrl+mouse       = Zoom / Z-translation,\n\
334      Shift+mouse       = X/Y-translation\n\
335      Cntrl+Shift+mouse = Z-rotation\n\
336  - Use the Esc to switch between rotation of part or the whole structure\n\
337  - Use the arrow keys  in addition to the mouse for rotation\n\
338  - Use the Keypad keys in addition to the mouse for translation\n\n\
339    Translation X-axis:      KP_4, KP_6  \n\
340    Translation Y-axis:      KP_8, KP_2  \n\
341    Translation Z-axis:      KP_1, KP_3  \n\
342    Rotation    Z-axis:      KP_7, KP_9  \n\n\
343  - DONT FORGET to switch on the NUMLOCK key when using the Keypad keys\n\
344  - Use the Coarse icon (between the arrow buttons) to change the step/angle\n\
345    increment ";
346 
347 void ogIntSurf();
348 void ogLigSurf();
349 #ifdef DOGL
350 void ogDockSphere();
351 #endif
352 int GetLig();
353 void ProcLig(int imode);
354 void drwdock();
355 void createDock();
356 void IntSurfGetlig();
357 void change_iso(int iop);
358 
359 void click_nmr_spec(int indx);
360 void prep_nmr();
361 void rubber(int iopt);
362 void RedrawStatus();
363 void RedrawONIStatus();
364 void UpdateZME();
365 void SetQZME();
366 void GetQZME();
367 void UnMapZME();
368 void map_prop();
369 void FindZRangeFromBox(int isel);
370 void SwitchOffAnim();
371 void AnimLinks(double vartmp);
372 void DeActZME();
373 void ButtonsCOL(int i);
374 void CreateCellPar();
375 void InitCellDelTrans(int dtopt);
376 void InitMovie(int x,int y);
377 void aaexp(char *aastr,int sl);
378 void calc_spectrum(int iupd);
379 void reswat();
380 void initflx();
381 void UpdateSTRC();
382 void initMLT();
383 void motion_screen(int *inct,int *incp);
384 void ogwrmol(double *r, double *adjus, int *natoms, int *nat,
385         double *xsym, double *ysym, double *zsym, double *vdwr);
386 void DeleteSurface(int isrf);
387 void save_rgb(char *rgbfile);
388 void save_bmp(char *rgbfile);
389 void molsrf(int SurfCol,int SrfArr,int MapSrf);
390 void opt3rot();
391 void SetExplButton(Window win,int x,int y);
392 void ToGIF(Drawable win,char *filename);
393 void LigandStruct(int het);
394 void wrtall();
395 void plcnrm();
396 void getrad(double *t,double *coo,int *iatoms,double *dret);
397 void javch3(int *ih);
398 void avch3();
399 void DeleteOMAP();
400 void movexy(float xval,float yval);
401 void drawxy(float xval,float yval);
402 void DrawBox(double x,double y,int xt,int yt,int r,int icol,int ifill,int iconv);
403 void ResetColors();
404 void def_colors();
405 void FakeCMap();
406 void drawstring(float xval,float yval,char *strval,int nval);
407 void dashline();
408 void changepen(float pen);
409 void gl2DInit();
410 void gl2DEnd();
411 void CreatewinC(char *geom);
412 void CreatewinMC(char *geom);
413 void createauthor();
414 void createRama();
415 void createconv();
416 void createfr(int dowin);
417 void creategeom();
418 void createscore();
419 void createpmf();
420 void CreateONI();
421 void CreateFLR();
422 void actde(int inactid,int inactf,int iwin);
423 void DirBox(Window hwin,int vis);
424 void RedrawwinC(int x,int y,int w,int h);
425 void ULineString(Window hwin,char *str,int x,int y);
426 void LineString(Window hwin,char *str,int x,int y);
427 void DrawTriangle(double x,double y,int xt,int yt,int r,int icol,int ifill,int iconv);
428 void DrawRama();
429 void StatusStr(int iwin,int dobell);
430 void domamb(char *jobstr);
431 void bckpoi(int istruct);
432 void ActOnErr(int zline,int boxnum,char *errstr);
433 void InsertEmptyLines(int ires,int row,int nlines,int seq_len,int nprot,int *iprot);
434 void FindZRange(int ires);
435 void ApplSel(int iop);
436 void ScrollBut(int i);
437 void maparr(float *flarr,double *dblarr,int *intarr,short int *shintarr,int iopt);
438 void ActVar(int isel,int itype,int butnr);
439 void activeZME(int *type,int *row,int *column);
440 void MkDistWin(int *asel,int opt,float val);
441 void PlotColIndex();
442 void OnTop();
443 void InitCOL();
444 void RButtonsCOL(int i);
445 void SetRadius();
446 void UpdateCP();
447 void InitISO(int x,int y);
448 void RedrawISO();
449 void InitATM(int x,int y);
450 void UpdateATM();
451 void UpdateSeqStat();
452 void InitSEQ(int x,int y);
453 void InitTNK(int x,int y);
454 void rearr(int *itarr,int *arr);
455 void rearrs(int *itarr,short int *arr);
456 void rearrd(double *itarr,double *arr);
457 void rearrz(int *itarr);
458 void make_aa();
459 void FreeAll(int delpix);
460 void DeleteAll();
461 void EditCOL();
462 void SetPalCol(int updateshades);
463 void UpdateDPT();
464 void InitDPT();
465 void WriteCML();
466 void InitMAP();
467 void InitVIR();
468 void write_spectrum(char *fname, int orient, int opt);
469 void InitDelay();
470 void InitPar();
471 void inistrc();
472 void inistr();
473 void iniselh();
474 void InitSRCH(int x,int y);
475 void InitANIM(int x,int y);
476 void inichg(int iopt);
477 void initPHRM();
478 void initPSRCH(char *query);
479 void WinName(Window win,char *wname);
480 void BuildList(double *r,double *cnst,int *nnpts1,int *nnpts2,int *iorb,double *dens);
481 void DeleteActiveSurfaces();
482 void allocvert(int siz,int first);
483 void EnableFog();
484 void chncol(int ich,int col,int iupd);
485 void showresrot(int sol);
486 void mvhlpat(int nlines,int *nato1);
487 void CombineStructs(int str2,int notaligned,int new_struct);
488 int DoCan(int x,int y,char *strval,int docan);
489 int dos2u(char *path);
490 
491 #if defined(VMS) || defined(UNDERSC)
492 void curs(int *on);
493 void almgrd();
494 void wrtres();
495 void stowat(int *ino);
496 void initsrf();
497 void dlystr();
498 void bldlst();
499 void tpsa();
500 void getpdb(int *ires,int *ipdb,int *ihpdb);
501 void mkcon(int *ipdb,int *aminotyp,int *irs,int *ihpdb,int *i,int *j);
502 void dfires();
503 void plinzz(int *isel,int *istat);
504 void dumlin(int *isel,double *blv,double *alphv,double *betv);
505 void sollin();
506 void dpomap(int *iopt);
507 void qupd();
508 void cwidth(float *linpass);
509 void ststip();
510 void unstip();
511 void doexp();
512 void dlogo();
513 void crsco();
514 void cpmf();
515 void upsco();
516 void molstr(struct dsc$descriptor_s *str, int *nstr, int *iwin);
517 void drwstr(int *xvl,int *yvl,struct dsc$descriptor_s *strvl,int *sl,int *ind);
518 void drwqstr(int *xvl,int *yvl,int *ian,double *q,int *ind);
519 void cpstr(char *ostr,struct dsc$descriptor_s *str,int nlen);
520 void strcp(struct dsc$descriptor_s *str,char *ostr,int nlen);
521 void upzme();
522 void addchg();
523 void allorb(int *ZSizep,int *first);
524 void allgrd(int *ZSizep);
525 void allgeo(int *ZSizep,int *first);
526 void allcoo(int *ZSizep,int *first);
527 void srfclr();
528 #else
529 #ifdef CRAY
530 void CURS(int *on);
531 void ALMGRD();
532 void WRTRES();
533 void STOWAT(int *ino);
534 void INITSRF();
535 void DLYSTR();
536 void BLDLST();
537 void TPSA();
538 void GETPDB(int *ires,int *ipdb,int *ihpdb);
539 void MKCON(int *ipdb,int *aminotyp,int *irs,int *ihpdb,int *i,int *j);
540 void DFIRES();
541 void PLINZZ(int *isel,int *istat);
542 void DUMLIN(int *isel,double *blv,double *alphv,double *betv);
543 void SOLLIN();
544 void DPOMAP(int *iopt);
545 void QUPD();
546 void CWIDTH(float *linpass);
547 void STSTIP();
548 void UNSTIP();
549 void DOEXP();
550 void DLOGO();
551 void CRSCO();
552 void CPMF();
553 void UPSCO();
554 void MOLSTR(_fcd str, int *nstr, int *iwin);
555 void DRWSTR(int *xvl,int *yvl,_fcd strvl,int *sl,int *ind);
556 void DRWQSTR(int *xvl,int *yvl,int *ian,double *q,int *ind);
557 void cpstr(char *ostr,_fcd str,int nlen);
558 void strcp(_fcd str,char *ostr,int nlen);
559 void UPZME();
560 void ADDCHG();
561 void ALLORB(int *ZSizep,int *first);
562 void ALLGRD(int *ZSizep);
563 void ALLGEO(int *ZSizep,int *first);
564 void ALLCOO(int *ZSizep,int *first);
565 void SRFCLR();
566 #else
567 void curs_(int *on);
568 void almgrd_();
569 void wrtres_();
570 void stowat_(int *ino);
571 void initsrf_();
572 void dlystr_();
573 void bldlst_();
574 void tpsa_();
575 void getpdb_(int *ires,int *ipdb,int *ihpdb);
576 void mkcon_(int *ipdb,int *aminotyp,int *irs,int *ihpdb,int *i,int *j);
577 void dfires_();
578 void plinzz_(int *isel,int *istat);
579 void dumlin_(int *isel,double *blv,double *alphv,double *betv);
580 void sollin_();
581 void dpomap_(int *iopt);
582 void qupd_();
583 void cwidth_(float *linpass);
584 void ststip_();
585 void unstip_();
586 void doexp_();
587 void dlogo_();
588 void crsco_();
589 void cpmf_();
590 void upsco_();
591 void molstr_(char *str, int *nstr, int *iwin);
592 void drwstr_(int *xvl,int *yvl,char *strvl,int *sl,int *ind);
593 void drwqstr_(int *xvl,int *yvl,int *ian,double *q,int *ind);
594 void cpstr(char *ostr,char *str,int nlen);
595 void strcp(char *str,char *ostr,int nlen);
596 void upzme_();
597 void addchg_();
598 void allorb_(int *ZSizep,int *first);
599 void allgrd_(int *ZSizep);
600 void allgeo_(int *ZSizep,int *first);
601 void allcoo_(int *ZSizep,int *first);
602 void srfclr_();
603 #endif
604 #endif
605 
606 #define MEXCL 10
607 
608 typedef struct { double qexcl[MEXCL];
609 		 int ianexc[MEXCL];
610 		} METSTRU;
611 
612 static METSTRU *mets;
613 
614 static char *alphbet[] = {"alpha","beta"};
615 static char *strsnd[] = {"HELIXOUT","STRANDTOP","RNA","COIL"};
616 static char *rwopt[] = {"Read","Write"};
617 static char *cubeopt[] = {"Gaussian","Vasp","Jaguar"};
618 static char *labels[] = {"atom","atom+number","ForceF.Type","atom+charge","PDBsymbol","Residue","Nuc. Shld."};
619 static char *labhet[] = {"atom","atom+number","ForceF.Type","atom+charge","Residue"};
620 #ifdef MPFIT
621 static char *pots[] = {"True Electrost. Pot.","Multipole Derived","Charges Derived","Topol. PSA","Write Surface","Read Surface","Surface OFF","ESP charges","DMA El.Pot.Charges","Mull.Charges","Read ESP Charges","EEM charges","Gasteiger","Dipole On/Off","Solv. Acc. Surf","Elec. Dens. Map","Pharmacophore Editor","GRID kont","Ramachandran","Fit MultiPoles"};
622 #else
623 static char *pots[] = {"True Electrost. Pot.","Multipole Derived","Charges Derived","Topol. PSA","Write Surface","Read Surface","Surface OFF","ESP charges","DMA El.Pot.Charges","Mull.Charges","Read ESP Charges","EEM charges","Gasteiger","Dipole On/Off","Solv. Acc. Surf","Elec. Dens. Map","Pharmacophore Editor","GRID kont","Ramachandran"};
624 #endif
625 static char *eems[] = {"EEM NPA","EEM Mull","EEM PESP","EEM ESFF","Gasteiger"};
626 static char *pots2[] = {"True Electrost. Pot.","Multipole Derived","Charges Derived"};
627 static char *readgrd[] = {"Replace Grid","Subtract"};
628 static char *surftyp[] = {"Van der Waals","IsoDensity (Slow)","DMAPSA"};
629 static char *hyds[] = {"Excl. All Hydrogens","Excl. H except H-bond","(Re)calculate H-bond","H-bond parameters","Opt. H positions"};
630 static char *postopt[] = {"Mono","Color"};
631 static char *srfopt[] = {"Mono-colored surface","Elec. Pot. Mapped"};
632 static char *srf2opt[] = {"Elec. Density Surf.","Solv. Acc. Surf."};
633 static char *dumopt[] = {"Include Dummies","Exclude Dummies"};
634 static char *vrmlopt[] = {"VRML1.0","VRML2.0","Povray","OpenGL"};
635 static char *vrml2dopt[] = {"VRML2.0","OpenGL"};
636 static char *denopt[] = {"Normal","Color Mapped"};
637 static char *xyzopt[] = {"XYZ","Mol2","MSF","Tinker","Tinker QM/MM"};
638 static char *mapopt[] = {"XYZ file","Mol2 file","MSF","Tinker .xyz","Optimise with Sybyl","Optimise with Quanta","Optimise with Tinker"};
639 static char *wropt[] = {"Z-Mat Gamess","Z-Mat Gaussian","Z-Mat MOPAC","XYZ","Mol2","MSF","Tinker","Tinker QM/MM","PDB","CSSR","MSI","Molden Format","mol","CML","AMBFOR","WFN"};
640 static char *pdbwh[]={ "Write with Hydrogens", "Write without H","Write Displayed Res. Only"};
641 static char *palopt[] = {"Background Mode","BackGround Color","Def. BackGround","Atom Colors","Color Editor","Reset Colors","Shade Depth","Surfaces","Chains","Blur","Occlusion","Shadows"};
642 static char *occlopt[] = {"Best","Good"};
643 static char *bgopt[] = {"Solid Color","Gradient Color"};
644 static char *spdopt[] = {"Normal Density","Spin Density"};
645 static int *ivdwpl;
646 static char *vdwstr[]={ "Sticks", "Space Filling", "Ball & Sticks"};
647 static char *alnopt[]={ "Align 2 molecules", "Interactive Docking","Incremental Docking"};
648 static char *dckopt[]={ "Read from PDB file", "Pick Molecule on Screen"};
649 static char *rsopt[]={ "640x480", "1280x720"};
650 #define MAXRES 1000
651 static int npdbres = 0;
652 static char *pdbres[MAXRES];
653 static int ieemopt = 1;
654 static int *icolps;
655 static int *idelx;
656 static int *ivtwo;
657 static int *ixyz;
658 static int *iixyz;
659 static int *ipnt;
660 static int *iwropt;
661 static int denmode = 0;
662 static int inactMC;
663 static int inafMC;
664 static int *ispd;
665 static int *ibgcol;
666 static int *ibgclo;
667 static int *ibgmod;
668 static int *igffrm;
669 static int iupres[500];
670 static int nupres = 0;
671 
672 static int  CheckForConfig();
673 static Bool IsConfig();
674 
675 static int idum1;
676 static int startx;
677 static int starty;
678 static int moving = 0;
679 static int gmoving = 0;
680 static int *ball;
681 static int btype = 0;
682 
683 double dveclen(double *a);
684 void vecnrm(float *v);
685 void crossprd(double *v1,double *v2,double *d);
686 void CROSS(double *v1,double *v2,double *v3);
687 void improduct(double *a, double *b, double *c);
688 void onerot(int ires,int print);
689 void poldrw(XPoint *points,int *npoints,int *icol,int *icon,int *isgrey);
690 void presetp();
691 void createspec(int dowin);
692 void RedrawwinMC(int x,int y,int w,int h);
693 void RedrawRESwin();
694 void RedrawCOMMwin();
695 void RedrawDIST();
696 void RedrawSUB();
697 void RedrawCOL();
698 void RedrawMOV();
699 void RedrawECOL();
700 void RedrawMAP();
701 void RedrawVIR();
702 void RedrawONI();
703 void RedrawFLR();
704 void RedrawDEL();
705 void RedrawFLX();
706 void RedrawPAR();
707 void RedrawSTRC();
708 void RedrawSELH();
709 void RedrawSRCH();
710 void RedrawANIM();
711 void RedrawSTR();
712 void RedrawCHG();
713 void RedrawSRF();
714 void RedrawMLT();
715 void RedrawDPT();
716 void RedrawATM();
717 void RedrawTNK();
718 void RedrawCT();
719 void RedrawCP();
720 void RedrawSEQ();
721 void RedrawPHRM();
722 void RedrawPSRCH();
723 void InitZME();
724 void RedrawZME();
725 void EndOMAP();
726 int PressZME(int butnr,int x,int y);
727 void butje(Window bwin,int x,int y,int w,int h,int r,int bgcol,int sh_ind,int iopt,Pixmap pix,int pw,int ph,int rec);
728 void doclr();
729 void drwspec();
730 void drwcnv();
731 void drwpmf();
732 void glpnt(int wide,int high,double x,double y,int *xr,int *yr,int iframe);
733 void drwsco();
734 void Timer(int msec,int timopt);
735 void UpdHet();
736 void UpdHet2(int nlin);
737 void OpenPHRME();
738 void exit_casel();
739 #if defined(VMS) || defined(UNDERSC)
740 void drwgeo();
741 #else
742 #ifdef CRAY
743 void DRWGEO();
744 #else
745 void drwgeo_();
746 #endif
747 #endif
748 void clrsave();
749 void drwgl(Window gwin,int wide,int high,double x1,double y1,double x2,double y2,int icol,int icross,int iframe,int isdash);
750 void RedrawWin();
751 void Key(unsigned char key);
752 static Bool gijsup = 0;
753 static Bool ramaup = 0;
754 static Bool dockup = 0;
755 static Bool cnvup = 0;
756 static Bool geoup = 0;
757 static Bool distup = 0;
758 static Bool FRup = 0;
759 static Bool specup = 0;
760 static Bool scoup = 0;
761 static Bool pmfup = 0;
762 static double scomax, scomin;
763 static int qboxup = 0;
764 static int qbopt = 0;
765 static int qbinct = 0;
766 static int qbcomm = 0;
767 static int qbres = 0;
768 static int pdb = 0;
769 static int *icalc;
770 static int *ipdbon;
771 static int frfor = 0;
772 static int coarse = 1;
773 static Bool do3dx = 0;
774 static int *dospa;
775 static int *do3d;
776 static int *ambchg;
777 static int *backb;
778 static Bool isdash = 0;
779 static Bool hbon = 0;
780 static Bool denm = 1;
781 static int setcmap = 0;
782 static int ZERO = 0;
783 static int ONE = 1;
784 static int MONE = -1;
785 static int TWO = 2;
786 static int THREE = 3;
787 static int FOUR = 4;
788 static int FIVE = 5;
789 static int EIGHTEEN = 18;
790 static int SEVENTYSEVEN = 77;
791 static double THRESH = 3.5;
792 static Colormap cmap;
793 static int StarNetOld = 0;
794 static int StarNet = 0;
795 #define ball_width 7
796 #define ball_height 7
797 static BMap ball_bits[] = {
798    0x1c, 0x3e, 0x7f, 0x7f, 0x7f, 0x3e, 0x1c};
799 #define bigsmall_width 17
800 #define bigsmall_height 17
801 static BMap bigsmall_bits[] = {
802    0x80, 0xff, 0x01, 0x80, 0x00, 0x01, 0xfe, 0x0f, 0x01, 0x82, 0x08, 0x01,
803    0x82, 0x08, 0x01, 0x82, 0x08, 0x01, 0x82, 0x08, 0x01, 0x82, 0xff, 0x01,
804    0x02, 0x08, 0x00, 0x02, 0x08, 0x00, 0x02, 0x08, 0x00, 0x02, 0x08, 0x00,
805    0x02, 0x08, 0x00, 0x02, 0x08, 0x00, 0x02, 0x08, 0x00, 0xfe, 0x0f, 0x00,
806    0x00, 0x00, 0x00};
807 #define skull_width 17
808 #define skull_height 17
809 static BMap skull_bits[] = {
810    0xe0, 0x0f, 0x00, 0xf0, 0x1f, 0x00, 0xf8, 0x3f, 0x00, 0xfc, 0x7f, 0x00,
811    0x9e, 0xf3, 0x00, 0x8e, 0xe3, 0x00, 0x8e, 0xe3, 0x00, 0xfe, 0xfe, 0x00,
812    0x7c, 0x7c, 0x00, 0x78, 0x3c, 0x00, 0xf1, 0x1f, 0x01, 0xf1, 0x1f, 0x01,
813    0x52, 0x95, 0x00, 0x44, 0x45, 0x00, 0xf8, 0x3f, 0x00, 0xfc, 0x7f, 0x00,
814    0x07, 0xc0, 0x01};
815 #define ff_width 17
816 #define ff_height 17
817 static BMap ff_bits[] = {
818    0x00, 0x00, 0x00, 0xf8, 0x03, 0x00, 0xf8, 0x03, 0x00, 0x18, 0xfc, 0x00,
819    0x0c, 0xfc, 0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x06, 0x00, 0x7c, 0x06, 0x00,
820    0x7e, 0x06, 0x00, 0x06, 0x3e, 0x00, 0x06, 0x3f, 0x00, 0x06, 0x03, 0x00,
821    0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x83, 0x01, 0x00, 0x80, 0x01, 0x00,
822    0x80, 0x01, 0x00};
823 #define mlf_width 17
824 #define mlf_height 17
825 static BMap mlf_bits[] = {
826    0x00, 0x00, 0x00, 0x0e, 0xe0, 0x00, 0x1c, 0x70, 0x00, 0x3c, 0x78, 0x00,
827    0x7c, 0x7c, 0x00, 0xec, 0x6e, 0x00, 0xcc, 0x67, 0x00, 0x8c, 0x63, 0x00,
828    0x0c, 0x61, 0x00, 0x0c, 0x60, 0x00, 0x0c, 0x60, 0x00, 0x0c, 0x60, 0x00,
829    0x0c, 0x60, 0x00, 0x0c, 0x60, 0x00, 0x0c, 0x60, 0x00, 0x1e, 0xf0, 0x00,
830    0x00, 0x00, 0x00};
831 #define hbit_width 17
832 #define hbit_height 17
833 static BMap hbit_bits[] = {
834    0x00, 0x00, 0x00, 0x70, 0xe0, 0x00, 0x70, 0xe0, 0x00, 0x70, 0xe0, 0x00,
835    0x38, 0x70, 0x00, 0x38, 0x70, 0x00, 0x38, 0x70, 0x00, 0x38, 0x70, 0x00,
836    0xfc, 0x3f, 0x00, 0xfc, 0x3f, 0x00, 0x1c, 0x38, 0x00, 0x1c, 0x38, 0x00,
837    0x0e, 0x1c, 0x00, 0x0e, 0x1c, 0x00, 0x0e, 0x1c, 0x00, 0x0e, 0x1c, 0x00,
838    0x07, 0x0e, 0x00};
839 #define orig_width 17
840 #define orig_height 17
841 static BMap orig_bits[] = {
842    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
843    0x10, 0x01, 0x00, 0x20, 0x01, 0x00, 0x40, 0x01, 0x00, 0x80, 0x01, 0x00,
844    0xfe, 0xff, 0x00, 0x00, 0x03, 0x00, 0x00, 0x05, 0x00, 0x00, 0x09, 0x00,
845    0x00, 0x11, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00,
846    0x00, 0x00, 0x00};
847 #define cell_width 17
848 #define cell_height 17
849 static BMap cell_bits[] = {
850    0x00, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x30, 0xc0, 0x00, 0x08, 0xa0, 0x00,
851    0x24, 0x90, 0x00, 0xfe, 0x8f, 0x00, 0x02, 0x88, 0x00, 0x22, 0x88, 0x00,
852    0x02, 0x88, 0x00, 0x22, 0x88, 0x00, 0x02, 0x88, 0x00, 0xe2, 0xeb, 0x00,
853    0x12, 0x48, 0x00, 0x0a, 0x28, 0x00, 0x06, 0x18, 0x00, 0xfe, 0x0f, 0x00,
854    0x00, 0x00, 0x00};
855 #define surf_width 17
856 #define surf_height 17
857 static BMap surf_bits[] = {
858    0x92, 0x92, 0x00, 0x12, 0x91, 0x00, 0x24, 0x48, 0x00, 0x44, 0x44, 0x00,
859    0x98, 0x23, 0x00, 0x74, 0x30, 0x00, 0xf2, 0x0c, 0x00, 0x2a, 0x1f, 0x00,
860    0x45, 0x63, 0x00, 0xaa, 0x88, 0x00, 0x92, 0xb6, 0x00, 0x6c, 0x22, 0x01,
861    0x50, 0x49, 0x01, 0x40, 0x22, 0x01, 0x80, 0xb6, 0x00, 0x80, 0x88, 0x00,
862    0x00, 0x63, 0x00};
863 #define ogl_width 17
864 #define ogl_height 17
865 static BMap ogl_bits[] = {
866    0x00, 0xa0, 0x01, 0x40, 0xe0, 0x01, 0xe0, 0xc0, 0x01, 0xd0, 0x81, 0x01,
867    0xc8, 0x03, 0x00, 0xc4, 0x07, 0x00, 0xc2, 0xff, 0x00, 0x41, 0xc0, 0x00,
868    0xe2, 0xbf, 0x00, 0x24, 0xa0, 0x00, 0xa8, 0xa0, 0x00, 0x30, 0xa0, 0x00,
869    0xa0, 0xa0, 0x00, 0x20, 0xa0, 0x00, 0xa0, 0xaa, 0x00, 0x20, 0x60, 0x00,
870    0xe0, 0x3f, 0x00};
871 #define foto_width 17
872 #define foto_height 17
873 static BMap foto_bits[] = {
874    0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x1c, 0x00, 0x00, 0xfe, 0xff, 0x00,
875    0xfe, 0xff, 0x00, 0x7e, 0xfc, 0x00, 0xbe, 0xfb, 0x00, 0x5e, 0xf4, 0x00,
876    0x5e, 0xf4, 0x00, 0x5e, 0xf4, 0x00, 0xbe, 0xfb, 0x00, 0x7e, 0xfc, 0x00,
877    0xfe, 0xff, 0x00, 0xfe, 0xff, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00,
878    0x00, 0x00, 0x00};
879 #define palette_width 17
880 #define palette_height 17
881 static BMap palette_bits[] = {
882    0x00, 0x80, 0x01, 0x00, 0xb0, 0x01, 0xf8, 0x78, 0x00, 0xfc, 0xfd, 0x00,
883    0xfc, 0xfd, 0x00, 0xc6, 0xff, 0x00, 0x82, 0xff, 0x00, 0x86, 0xff, 0x00,
884    0xc6, 0xff, 0x00, 0xfe, 0xff, 0x00, 0xfe, 0xff, 0x00, 0xfe, 0x7f, 0x00,
885    0xfc, 0x7f, 0x00, 0xfc, 0x7f, 0x00, 0xfc, 0x3f, 0x00, 0xf2, 0x1f, 0x00,
886    0xe1, 0x07, 0x00};
887 #define g_width 17
888 #define g_height 17
889 static BMap g_bits[] = {
890    0xc0, 0x07, 0x00, 0x30, 0x18, 0x00, 0x0c, 0x60, 0x00, 0x04, 0x40, 0x00,
891    0x02, 0x80, 0x00, 0x22, 0x88, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01,
892    0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x11, 0x10, 0x01, 0x22, 0x88, 0x00,
893    0xc2, 0x87, 0x00, 0x04, 0x40, 0x00, 0x0c, 0x60, 0x00, 0x30, 0x18, 0x00,
894    0xc0, 0x07, 0x00};
895 #define vrml_width 17
896 #define vrml_height 17
897 static BMap vrml_bits[] = {
898    0x00, 0x00, 0x00, 0xe6, 0xc3, 0x00, 0x66, 0xc6, 0x00, 0x66, 0xc4, 0x00,
899    0x66, 0xc6, 0x00, 0xec, 0x63, 0x00, 0x6c, 0x63, 0x00, 0x78, 0x36, 0x00,
900    0x78, 0x36, 0x00, 0x30, 0x18, 0x00, 0x30, 0x18, 0x00, 0x60, 0x0c, 0x00,
901    0x60, 0x0c, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0x80, 0x03, 0x00,
902    0x80, 0x03, 0x00};
903 #define align_width 17
904 #define align_height 17
905 static BMap align_bits[] = {
906    0x20, 0x00, 0x00, 0x70, 0x04, 0x00, 0x98, 0x04, 0x00, 0x0d, 0x0f, 0x00,
907    0x06, 0x13, 0x00, 0x86, 0xa3, 0x00, 0xc6, 0x42, 0x00, 0xc6, 0x42, 0x00,
908    0xc6, 0x42, 0x00, 0xc6, 0x42, 0x00, 0xc6, 0x42, 0x00, 0xcd, 0x41, 0x00,
909    0xd8, 0x40, 0x00, 0xf0, 0xa1, 0x00, 0x20, 0x13, 0x00, 0x20, 0x0e, 0x00,
910    0x00, 0x04, 0x00};
911 #define map_width 24
912 #define map_height 16
913 static BMap map_bits[] = {
914    0xff, 0x01, 0x00, 0xff, 0xff, 0x0f, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff,
915    0xff, 0xff, 0xff, 0x3f, 0x00, 0xc0, 0x1f, 0x00, 0x40, 0x1f, 0x00, 0x60,
916    0x0f, 0x00, 0x20, 0x0f, 0x00, 0x30, 0x07, 0x00, 0x10, 0x07, 0x00, 0x18,
917    0x03, 0x00, 0x08, 0x03, 0x00, 0x0c, 0xff, 0xff, 0x07, 0xff, 0xff, 0x07};
918 #define mol_width 169
919 #define mol_height 52
920 static BMap mol_bits[] = {
921  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
922  0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
923  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x00,
924  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
925  0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0xfc,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
926  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01,0xfe,0x00,0x03,
927  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
928  0x00,0x00,0x00,0x06,0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
929  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xfe,0x40,0x00,0x00,
930  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
931  0x00,0x00,0x10,0xfe,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
932  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xfe,0x20,0x00,0x00,0x00,
933  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
934  0x00,0x20,0xfe,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
935  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xfe,0x20,0x00,0x00,0x00,0x00,
936  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
937  0x20,0xfe,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
938  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xfe,0x20,0x00,0x00,0x00,0x00,0x00,
939  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,
940  0xfe,0x20,0x00,0xc0,0x3f,0xc0,0x1f,0x00,0xff,0x00,0xf8,0x00,0x80,0xff,0x1f,
941  0x80,0xff,0xff,0xf1,0x03,0xf8,0x20,0xfe,0x20,0x00,0xc0,0x3f,0xe0,0x1f,0xe0,
942  0xff,0x07,0xf8,0x00,0x80,0xff,0x7f,0x80,0xff,0xff,0xf1,0x03,0xf8,0x20,0xfe,
943  0x20,0x00,0xc0,0x3f,0xe0,0x1f,0xf0,0xff,0x0f,0xf8,0x00,0x80,0xff,0xff,0x80,
944  0xff,0xff,0xf0,0x03,0xf8,0x20,0xfe,0x20,0x00,0xe0,0x3f,0xe0,0x1f,0xf8,0xff,
945  0x0f,0xfc,0x00,0xc0,0xff,0xff,0xc0,0xff,0xff,0xf8,0x07,0xfc,0x20,0xfe,0x20,
946  0x00,0xe0,0x3f,0xf0,0x0f,0xfc,0xe1,0x1f,0x7c,0x00,0xc0,0x07,0xfe,0xc1,0x07,
947  0x00,0xf8,0x07,0x7c,0x20,0xfe,0x20,0x00,0xe0,0x3f,0xf0,0x0f,0x7e,0x80,0x1f,
948  0x7c,0x00,0xc0,0x07,0xf8,0xc1,0x07,0x00,0xf8,0x07,0x7c,0x20,0xfe,0x20,0x00,
949  0xe0,0x3f,0xf8,0x0f,0x3f,0x00,0x3f,0x7c,0x00,0xc0,0x07,0xf0,0xc1,0x07,0x00,
950  0xf8,0x0f,0x7c,0x20,0xfe,0x20,0x00,0xe0,0x3f,0xb8,0x0f,0x1f,0x00,0x3f,0x7c,
951  0x00,0xc0,0x07,0xf0,0xc1,0x07,0x00,0xf8,0x0f,0x7c,0x20,0xfe,0x20,0x00,0xf0,
952  0x3d,0xbc,0x8f,0x0f,0x00,0x3e,0x7e,0x00,0xe0,0x07,0xf0,0xe1,0x03,0x00,0xfc,
953  0x1f,0x7e,0x20,0xfe,0x20,0x00,0xf0,0x3d,0xdc,0x87,0x0f,0x00,0x3e,0x3e,0x00,
954  0xe0,0x03,0xf0,0xe1,0x03,0x00,0x7c,0x1f,0x3e,0x20,0xfe,0x20,0x00,0xf0,0x3d,
955  0xde,0xc7,0x07,0x00,0x3e,0x3e,0x00,0xe0,0x03,0xf0,0xe1,0xff,0x3f,0x7c,0x1e,
956  0x3e,0x20,0xfe,0x20,0x00,0xf0,0x3d,0xde,0xc7,0x07,0x00,0x3e,0x3e,0x00,0xe0,
957  0x03,0xf0,0xe1,0xff,0x3f,0x7c,0x3e,0x3e,0x20,0xfe,0x20,0x00,0xf0,0x3d,0xce,
958  0xc7,0x03,0x00,0x3e,0x3e,0x00,0xe0,0x03,0xf0,0xe1,0xff,0x1f,0x7c,0x3e,0x3e,
959  0x20,0xfe,0x20,0x00,0xf8,0x3c,0xef,0xe7,0x03,0x00,0x1f,0x3f,0x00,0xf0,0x03,
960  0xf8,0xf1,0xff,0x1f,0x7e,0x3c,0x3f,0x20,0xfe,0x20,0x00,0xf8,0x3c,0xe7,0xe3,
961  0x03,0x00,0x1f,0x1f,0x00,0xf0,0x01,0xf8,0xf0,0x01,0x00,0x3e,0x7c,0x1f,0x20,
962  0xfe,0x20,0x00,0xf8,0xbc,0xe7,0xe3,0x03,0x80,0x1f,0x1f,0x00,0xf0,0x01,0xf8,
963  0xf0,0x01,0x00,0x3e,0x7c,0x1f,0x20,0xfe,0x20,0x00,0xf8,0xbc,0xe7,0xe3,0x03,
964  0x80,0x0f,0x1f,0x00,0xf0,0x01,0x7c,0xf0,0x01,0x00,0x3e,0x78,0x1f,0x20,0xfe,
965  0x20,0x00,0xf8,0xfc,0xe3,0xe3,0x07,0xc0,0x0f,0x1f,0x00,0xf0,0x01,0x7c,0xf0,
966  0x01,0x00,0x3e,0xf8,0x1f,0x20,0xfe,0x20,0x00,0x7c,0xfc,0xf3,0xe1,0x07,0xe0,
967  0x87,0x0f,0x00,0xf8,0x00,0x3e,0xf8,0x00,0x00,0x3f,0xf0,0x0f,0x20,0xfe,0x20,
968  0x00,0x7c,0xfc,0xf1,0xc1,0x0f,0xf0,0x83,0x0f,0x00,0xf8,0x00,0x3f,0xf8,0x00,
969  0x00,0x1f,0xf0,0x0f,0x20,0xfe,0x20,0x00,0x7c,0xfc,0xf1,0xc1,0x3f,0xfc,0x83,
970  0x0f,0x00,0xf8,0xc0,0x1f,0xf8,0x00,0x00,0x1f,0xf0,0x0f,0x20,0xfe,0x20,0x00,
971  0x7c,0xfc,0xf0,0x81,0xff,0xff,0x81,0xff,0x7f,0xf8,0xff,0x0f,0xf8,0xff,0x1f,
972  0x1f,0xe0,0x0f,0x20,0xfe,0x20,0x00,0x7e,0xfc,0xf0,0x01,0xff,0xff,0xc0,0xff,
973  0x7f,0xfc,0xff,0x07,0xfc,0xff,0x9f,0x1f,0xe0,0x0f,0x20,0xfe,0x20,0x00,0x3e,
974  0xfc,0xf8,0x00,0xfe,0x3f,0xc0,0xff,0x3f,0xfc,0xff,0x03,0xfc,0xff,0x8f,0x0f,
975  0xe0,0x07,0x20,0xfe,0x20,0x00,0x3e,0x7c,0xf8,0x00,0xf8,0x0f,0xc0,0xff,0x3f,
976  0xfc,0xff,0x00,0xfc,0xff,0x8f,0x0f,0xc0,0x07,0x20,0xfe,0x20,0x00,0x00,0x00,
977  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
978  0x00,0x20,0xfe,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
979  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xfe,0x20,0x00,0x00,0x00,0x00,
980  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
981  0x20,0xfe,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
982  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xfe,0x20,0x00,0x00,0x00,0x00,0x00,
983  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,
984  0xfe,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
985  0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xfe,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
986  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xfe,
987  0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
988  0x00,0x00,0x00,0x00,0x00,0x10,0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
989  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xfe,0x00,
990  0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
991  0x00,0x00,0x00,0x00,0x06,0xfe,0x00,0xfc,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
992  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x01,0xfe,0x00,0x00,
993  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
994  0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
995  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,
996  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
997  0x00,0x00,0x00,0xfe};
998 #define icon_bitmap_width 100
999 #define icon_bitmap_height 70
1000 static BMap icon_bitmap_bits[] = {
1001    0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1002    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
1003    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00,
1004    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00,
1005    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
1006    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00,
1007    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
1008    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1009    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1010    0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1011    0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1012    0x00, 0xe0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1013    0x00, 0x00, 0x70, 0xa2, 0xec, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1014    0x00, 0x00, 0x00, 0x0e, 0x14, 0xe1, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
1015    0x00, 0x00, 0x00, 0x00, 0xa7, 0xd2, 0x0b, 0x19, 0x00, 0x00, 0x00, 0x00,
1016    0x00, 0x00, 0x00, 0x00, 0xc0, 0x12, 0x04, 0x50, 0x76, 0x00, 0x00, 0x00,
1017    0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xa9, 0x2a, 0x25, 0xd0, 0x01, 0x00,
1018    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x05, 0x40, 0x88, 0x92, 0x06,
1019    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xa8, 0x8a, 0x22, 0x24,
1020    0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x02, 0x10, 0x88,
1021    0xa8, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x54, 0x4b,
1022    0x25, 0x25, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x81,
1023    0x48, 0x10, 0xb0, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5e,
1024    0x35, 0x12, 0x45, 0x25, 0xd2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1025    0x02, 0x88, 0x54, 0x88, 0x88, 0xc8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
1026    0x00, 0xb2, 0x22, 0x80, 0x12, 0x52, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00,
1027    0x00, 0x00, 0x42, 0x8a, 0x2a, 0xa4, 0x08, 0xc5, 0x04, 0x00, 0x00, 0x00,
1028    0x00, 0x00, 0x00, 0x5e, 0x10, 0x41, 0x01, 0x51, 0x91, 0x06, 0x00, 0x00,
1029    0x00, 0x00, 0x00, 0x00, 0x9b, 0x4a, 0x16, 0xd4, 0x84, 0x54, 0x0c, 0x00,
1030    0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x22, 0xa1, 0x32, 0x52, 0x09, 0x0d,
1031    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x44, 0x14, 0x88, 0x08, 0x52,
1032    0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xa8, 0xa2, 0x22, 0xaa,
1033    0x80, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x83, 0x06, 0x89,
1034    0x02, 0x15, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x15, 0x58,
1035    0x70, 0x54, 0x51, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x61,
1036    0x21, 0x05, 0x21, 0x94, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26,
1037    0x9e, 0x45, 0x48, 0x94, 0x02, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1038    0x4a, 0x26, 0x18, 0x91, 0x21, 0xa8, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00,
1039    0x80, 0xa3, 0x94, 0x42, 0x22, 0x4a, 0x8d, 0x70, 0x00, 0x00, 0x00, 0x00,
1040    0x00, 0xf8, 0x3f, 0x11, 0x29, 0x84, 0x90, 0x64, 0x6a, 0x00, 0x00, 0x00,
1041    0x00, 0x00, 0xfe, 0x7e, 0xac, 0x8c, 0x52, 0x25, 0x81, 0x55, 0x00, 0x00,
1042    0x00, 0x00, 0x00, 0xbf, 0x7f, 0x1d, 0xa1, 0x0f, 0x48, 0x2a, 0x60, 0x00,
1043    0x00, 0x00, 0x00, 0x80, 0xf7, 0xed, 0x39, 0x04, 0xa0, 0x52, 0x84, 0x4a,
1044    0x00, 0x00, 0x00, 0x00, 0xc0, 0xfd, 0xff, 0x53, 0xa9, 0x04, 0x93, 0x29,
1045    0x59, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xdf, 0x6e, 0x25, 0x12, 0xa9, 0x04,
1046    0x4a, 0x4a, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf7, 0xf3, 0xc3, 0x46, 0x40,
1047    0x58, 0x10, 0x51, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xbe, 0x7f, 0xb4, 0x68,
1048    0xf5, 0x82, 0xc5, 0x64, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf6, 0xdd, 0x21,
1049    0x02, 0x08, 0x68, 0x54, 0x38, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x7e,
1050    0xb5, 0xb4, 0x42, 0x13, 0x05, 0x29, 0x00, 0x00, 0x00, 0x00, 0x80, 0xee,
1051    0xdf, 0x90, 0x01, 0x17, 0x42, 0x69, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x80,
1052    0x0e, 0x3c, 0x26, 0xaa, 0xa0, 0x56, 0x89, 0x32, 0x00, 0x00, 0x00, 0x00,
1053    0x00, 0xfb, 0x77, 0x89, 0xc1, 0x3d, 0x48, 0x4a, 0x1c, 0x00, 0x00, 0x00,
1054    0x00, 0x00, 0xfe, 0x23, 0x21, 0x2c, 0x80, 0x8a, 0x92, 0x0a, 0x00, 0x00,
1055    0x00, 0x00, 0x00, 0x00, 0xe0, 0x8c, 0xe1, 0xea, 0x51, 0x68, 0x0e, 0x00,
1056    0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xf1, 0x0c, 0x00, 0x8c, 0x96, 0x04,
1057    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x26, 0xd1, 0xcb, 0xa1, 0x20,
1058    0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x59, 0x0a, 0x10, 0x2e,
1059    0xad, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x91, 0xd0, 0x75,
1060    0xe1, 0xc5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x25,
1061    0x81, 0xaa, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
1062    0x12, 0x3e, 0x20, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1063    0x5a, 0xa5, 0xa0, 0x95, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1064    0x00, 0x46, 0x48, 0x0a, 0xc9, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
1065    0x00, 0x00, 0xdc, 0x16, 0x7f, 0x12, 0x0e, 0x3f, 0x00, 0x00, 0x00, 0x00,
1066    0x00, 0x00, 0x00, 0x18, 0x51, 0x80, 0xb3, 0x07, 0xfc, 0x00, 0x00, 0x00,
1067    0x00, 0x00, 0x00, 0x00, 0x70, 0x1a, 0x29, 0xa5, 0x01, 0xe0, 0x07, 0x00,
1068    0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x49, 0x07, 0xe2, 0x00, 0x00, 0x1f,
1069    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x2a, 0x50, 0x3f, 0x00, 0x00,
1070    0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00,
1071    0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x00,
1072    0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1073    0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1074    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1075    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1076    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1077 #define gijsface_width 160
1078 #define gijsface_height 144
1079 static BMap gijsface_bits[] = {
1080    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1081    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1082    0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1083    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1084    0x1c, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1085    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00,
1086    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1087    0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1088    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
1089    0x07, 0x24, 0xf0, 0x07, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1090    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x3e, 0xfe, 0xff,
1091    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1092    0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x00, 0x00, 0x00,
1093    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
1094    0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1095    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1096    0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1097    0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
1098    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff,
1099    0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1100    0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1101    0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1102    0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00,
1103    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
1104    0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1105    0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1106    0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1107    0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
1108    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff,
1109    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
1110    0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1111    0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1112    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00,
1113    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff,
1114    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
1115    0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1116    0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0,
1117    0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00,
1118    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xfe, 0xff, 0xff, 0xff,
1119    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
1120    0x00, 0x00, 0x00, 0x60, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1121    0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0,
1122    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00,
1123    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0xff, 0xff, 0xff, 0xff,
1124    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
1125    0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1126    0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
1127    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00,
1128    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff,
1129    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
1130    0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1131    0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
1132    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00,
1133    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff,
1134    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00,
1135    0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1136    0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
1137    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
1138    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff,
1139    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00,
1140    0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0xff, 0xff,
1141    0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
1142    0xff, 0xff, 0x0f, 0xf8, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03,
1143    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x0f, 0x00,
1144    0x90, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00,
1145    0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x03, 0x00, 0x00, 0xfe, 0xff, 0xff,
1146    0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
1147    0xff, 0xff, 0x03, 0x00, 0x00, 0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07,
1148    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x00, 0x00,
1149    0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
1150    0x00, 0x00, 0x00, 0xfc, 0xff, 0x7f, 0x00, 0x10, 0x00, 0xf0, 0xff, 0xff,
1151    0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc,
1152    0xff, 0x3f, 0x00, 0x80, 0x00, 0x04, 0xfb, 0xff, 0xff, 0xff, 0xff, 0x0f,
1153    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x3f, 0x00, 0x00,
1154    0x00, 0x80, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00,
1155    0x00, 0x00, 0x00, 0xfc, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x08, 0xfe, 0xff,
1156    0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc,
1157    0xff, 0x1f, 0x00, 0x00, 0x00, 0x8e, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x3f,
1158    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00,
1159    0x00, 0x00, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
1160    0x00, 0x00, 0x00, 0xfe, 0xff, 0x07, 0x00, 0x00, 0x00, 0x20, 0xfc, 0xff,
1161    0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
1162    0xff, 0x03, 0x00, 0x00, 0x00, 0x4c, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f,
1163    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00, 0x00,
1164    0x00, 0x38, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00,
1165    0x00, 0x00, 0x00, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0c, 0xfc, 0xff,
1166    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
1167    0xff, 0x01, 0x00, 0x00, 0x00, 0x78, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff,
1168    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00,
1169    0x00, 0x0a, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
1170    0x00, 0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0xff,
1171    0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff,
1172    0x7f, 0x00, 0x00, 0x00, 0x80, 0x0c, 0x6c, 0xff, 0xff, 0xff, 0xff, 0xff,
1173    0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00,
1174    0x00, 0x02, 0xb2, 0xbb, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00,
1175    0x00, 0x00, 0xc0, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x9b,
1176    0xfe, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
1177    0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xfd, 0xff, 0xff, 0xff,
1178    0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x3f, 0x00, 0x00, 0x00,
1179    0x00, 0x04, 0x00, 0x10, 0x6e, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00,
1180    0x00, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28,
1181    0xee, 0xf9, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
1182    0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xdb, 0x7f, 0xf9, 0xff, 0xff,
1183    0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00,
1184    0x00, 0x00, 0x10, 0x60, 0xf7, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00,
1185    0x00, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x09,
1186    0x14, 0xfe, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
1187    0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xc1, 0x1d, 0xf8, 0xff, 0xff,
1188    0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x1f, 0x00, 0x00, 0x00,
1189    0x00, 0x00, 0xe0, 0xff, 0xa7, 0xf7, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00,
1190    0x00, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
1191    0xff, 0xf7, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
1192    0x0f, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1193    0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00,
1194    0x01, 0xe8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00,
1195    0x00, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff,
1196    0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff,
1197    0x0f, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1198    0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x0f, 0xf8, 0x3f, 0x1e,
1199    0xe2, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,
1200    0x00, 0x00, 0xf0, 0xff, 0x0f, 0xfe, 0xff, 0xff, 0xa3, 0xff, 0xff, 0xff,
1201    0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
1202    0x87, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1203    0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xe7, 0xff, 0xff, 0xff,
1204    0xc1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00,
1205    0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff,
1206    0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
1207    0xff, 0xff, 0xff, 0xff, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x2f, 0xff, 0xff,
1208    0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff,
1209    0x00, 0xfc, 0xff, 0xff, 0xff, 0x2f, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00,
1210    0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfe, 0xff, 0xff,
1211    0xff, 0xbf, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff,
1212    0xc7, 0xff, 0xff, 0x7f, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xbf, 0xff, 0xff,
1213    0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x83, 0x7f, 0xfe, 0x1f,
1214    0x00, 0xf7, 0xff, 0xff, 0xff, 0x13, 0xfd, 0xff, 0xff, 0x0f, 0x00, 0x00,
1215    0x00, 0x00, 0xfe, 0xff, 0x83, 0x7f, 0xfc, 0x1f, 0x00, 0xff, 0xff, 0xff,
1216    0xcd, 0x1f, 0xfd, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
1217    0x03, 0x12, 0xfc, 0x07, 0x00, 0xf3, 0xbf, 0xff, 0x01, 0x80, 0xfd, 0xff,
1218    0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x03, 0x00, 0xe0, 0x07,
1219    0x00, 0xe7, 0xff, 0xff, 0x11, 0x00, 0xfd, 0xff, 0xff, 0x0f, 0x00, 0x00,
1220    0x00, 0x80, 0xff, 0xff, 0x03, 0x00, 0x20, 0x03, 0x80, 0xff, 0xbf, 0x9f,
1221    0x60, 0x00, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff,
1222    0x03, 0x00, 0x00, 0x00, 0x00, 0xca, 0xbf, 0x1d, 0x20, 0x00, 0xfc, 0xff,
1223    0xff, 0x03, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00,
1224    0x80, 0x0b, 0xa4, 0x02, 0x10, 0x80, 0xf8, 0xff, 0xff, 0x03, 0x00, 0x00,
1225    0x00, 0x00, 0xfe, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xff, 0x84, 0x02,
1226    0x80, 0x42, 0xf8, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
1227    0x03, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x8f, 0x05, 0x00, 0x82, 0xf8, 0xff,
1228    0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00,
1229    0x40, 0xff, 0x0b, 0x00, 0x10, 0x80, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00,
1230    0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x80, 0x49, 0x18, 0x00,
1231    0x1e, 0xe0, 0xfc, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
1232    0x03, 0x00, 0x00, 0x00, 0x80, 0x23, 0xfc, 0x03, 0x80, 0xc2, 0xe0, 0xff,
1233    0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00,
1234    0x80, 0x4b, 0x1e, 0xc0, 0x08, 0x21, 0xfc, 0xff, 0x7f, 0x00, 0x00, 0x00,
1235    0x00, 0x00, 0xf8, 0xff, 0x07, 0x00, 0x00, 0x00, 0x40, 0xeb, 0x1f, 0x80,
1236    0x00, 0xc1, 0xf9, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff,
1237    0x07, 0x00, 0x00, 0x00, 0x80, 0xff, 0x07, 0x00, 0x40, 0x0c, 0xec, 0xff,
1238    0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x07, 0x00, 0x00, 0x00,
1239    0x80, 0xff, 0x3f, 0x80, 0x00, 0xff, 0xfa, 0xf8, 0xff, 0x07, 0x00, 0x00,
1240    0x00, 0x00, 0xe0, 0xff, 0x07, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f, 0x80,
1241    0x00, 0xef, 0xfc, 0xf8, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
1242    0x07, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xff, 0x03, 0x60, 0xe5, 0xf8, 0xf9,
1243    0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x0f, 0x00, 0x00, 0x00,
1244    0x00, 0x48, 0xff, 0xeb, 0xe8, 0x03, 0xea, 0xe9, 0xff, 0x3f, 0x00, 0x00,
1245    0x00, 0x00, 0x00, 0x3c, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x2f,
1246    0x40, 0x02, 0xf8, 0xed, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78,
1247    0x0e, 0x00, 0x00, 0x00, 0xf0, 0x6f, 0xff, 0x05, 0x90, 0x3d, 0xee, 0xe5,
1248    0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
1249    0xfc, 0xff, 0xff, 0xdd, 0x88, 0xfd, 0xfc, 0xf5, 0xff, 0x7f, 0x00, 0x00,
1250    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe1, 0xff, 0xff, 0xff, 0x7f,
1251    0x00, 0x26, 0xea, 0xf8, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1252    0x00, 0x00, 0x80, 0xe0, 0xff, 0xff, 0x7f, 0xf8, 0xfd, 0x87, 0xf8, 0xf8,
1253    0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
1254    0xff, 0xff, 0x7f, 0x19, 0x0d, 0x81, 0xf8, 0xfd, 0xff, 0xff, 0x03, 0x00,
1255    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x3f, 0xac,
1256    0x0f, 0x1c, 0xf4, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
1257    0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xe4, 0xc2, 0x7f, 0xfc, 0xff,
1258    0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
1259    0xf8, 0xff, 0xff, 0xf7, 0x80, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0x07, 0x00,
1260    0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xb1,
1261    0x4f, 0xc0, 0xfc, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0,
1262    0x01, 0x00, 0x00, 0x00, 0xfc, 0xfe, 0xff, 0xbf, 0x4f, 0x1f, 0xff, 0xff,
1263    0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00,
1264    0x00, 0xf8, 0xff, 0x3f, 0xcb, 0xf7, 0xfc, 0xff, 0xff, 0xff, 0x03, 0x00,
1265    0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x7c,
1266    0x68, 0xcf, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0xf0,
1267    0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x3f, 0x44, 0x9b, 0xfc, 0xff,
1268    0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x20, 0x7f, 0x00, 0x00, 0x00,
1269    0x00, 0xfc, 0xcf, 0xbf, 0x4c, 0x9f, 0xfc, 0xff, 0xff, 0xff, 0x03, 0x00,
1270    0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff,
1271    0xcc, 0xed, 0xfe, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
1272    0xff, 0x00, 0x00, 0x80, 0xfa, 0xff, 0xff, 0xff, 0x9c, 0x9f, 0xff, 0xff,
1273    0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xf3,
1274    0xff, 0xff, 0xff, 0xff, 0xc0, 0xd9, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x00,
1275    0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x80, 0xff, 0xff, 0xff, 0xdf, 0xff,
1276    0xe1, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1277    0xf0, 0x00, 0x80, 0x0f, 0x00, 0xc0, 0x8d, 0xff, 0xa0, 0xfe, 0xff, 0xff,
1278    0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00, 0x01,
1279    0x00, 0xc0, 0x00, 0xf8, 0x40, 0xfd, 0xff, 0xff, 0xff, 0xbf, 0x00, 0x00,
1280    0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0xf8, 0xe0, 0xf8,
1281    0xfc, 0xf7, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1282    0xc0, 0x01, 0x00, 0x00, 0xf0, 0xff, 0x5f, 0xfa, 0xff, 0xfd, 0xff, 0xff,
1283    0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00,
1284    0xf0, 0xff, 0xff, 0xdb, 0xbf, 0xff, 0xfd, 0xff, 0xff, 0x7f, 0x00, 0x00,
1285    0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0xff, 0xff, 0x9f, 0x73,
1286    0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1287    0x00, 0x07, 0x00, 0x00, 0xff, 0xff, 0xbf, 0xf1, 0xf5, 0xff, 0xfc, 0xff,
1288    0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00,
1289    0xfc, 0xff, 0x2f, 0x38, 0xf7, 0xff, 0xf9, 0xff, 0xff, 0x07, 0x00, 0x00,
1290    0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0xc0, 0xbf, 0x60, 0xfe,
1291    0xfd, 0xff, 0xfb, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1292    0x00, 0x1f, 0x00, 0x00, 0xc0, 0x12, 0xe0, 0xbf, 0xf7, 0xff, 0xfd, 0xff,
1293    0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00,
1294    0x00, 0x00, 0xf6, 0xff, 0xfc, 0xff, 0xf9, 0xff, 0xff, 0xff, 0x00, 0x00,
1295    0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xdc, 0xf8,
1296    0xff, 0xff, 0xf9, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
1297    0x80, 0x7f, 0x00, 0x00, 0x00, 0xc0, 0xf9, 0xff, 0xff, 0xff, 0xf9, 0xff,
1298    0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xfb, 0x00, 0x00,
1299    0x00, 0xc0, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
1300    0x00, 0x00, 0x00, 0x00, 0x80, 0xf3, 0x03, 0x00, 0x00, 0xdc, 0xff, 0xff,
1301    0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00,
1302    0x00, 0xf3, 0x07, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1303    0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x1f, 0x00,
1304    0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1305    0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x3f, 0x00, 0xc0, 0xff, 0xff, 0xff,
1306    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
1307    0x00, 0xf7, 0xff, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1308    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xe1,
1309    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1310    0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1311    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
1312    0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1313    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
1314    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1315    0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1316    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
1317    0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1318    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff,
1319    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1320 
1321 #define hourglass_width 13
1322 #define hourglass_height 19
1323 static BMap hourglass_bits[] = {
1324    0xfe, 0x0f, 0xfe, 0x0f, 0x5c, 0x05, 0xac, 0x04, 0x5c, 0x04, 0x2c, 0x02,
1325    0x58, 0x01, 0xb0, 0x00, 0x60, 0x00, 0xe0, 0x00, 0x60, 0x00, 0xb0, 0x00,
1326    0x58, 0x01, 0x2c, 0x02, 0x5c, 0x04, 0xac, 0x04, 0x5c, 0x05, 0xfe, 0x0f,
1327    0xfe, 0x0f};
1328 /*
1329    0xfe, 0x0f, 0xfe, 0x0f, 0x54, 0x05, 0xac, 0x04, 0x54, 0x04, 0x2c, 0x02,
1330    0x58, 0x01, 0xb0, 0x00, 0x60, 0x00, 0xa0, 0x00, 0x60, 0x00, 0xb0, 0x00,
1331    0x58, 0x01, 0x2c, 0x02, 0x54, 0x04, 0xac, 0x04, 0x54, 0x05, 0xfe, 0x0f,
1332    0xfe, 0x0f};
1333 */
1334 
1335 #define stipple_width 16
1336 #define stipple_height 16
1337 
1338 static BMap stipple_bits[] = {
1339    0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
1340    0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
1341    0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55};
1342 
1343 static Pixmap hlfgrey = (Pixmap) NULL;
1344 
1345 #define hlfgrey_width 8
1346 #define hlfgrey_height 8
1347 static BMap hlfgrey_bits[] = {
1348    0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa};
1349 
1350 static Pixmap qwgrey = (Pixmap) NULL;
1351 #define qwgrey_width 8
1352 #define qwgrey_height 8
1353 static BMap qwgrey_bits[] = {
1354    0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44};
1355 
1356 static Pixmap tqwgrey = (Pixmap) NULL;
1357 #define tqwgrey_width 8
1358 #define tqwgrey_height 8
1359 static BMap tqwgrey_bits[] = {
1360    0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb, 0xee, 0xbb};
1361 
1362 static Pixmap upPix,  downPix,  lPix, rPix, molPix, gPix,fastPix,slowPix,blastPix,SkullPix,OrigPix,FotoPix,ColPix,CellPix,SurfPix,VRMLPix,HPix,AlignPix,FFPix,BigPix, ballPix, HourPix, MLFPix, OGLPix, movPix,stopPix,mapPix;
1363 
1364 #define down_width 16
1365 #define down_height 16
1366 static BMap down_bits[] = {
1367    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x10, 0x04, 0x10, 0x04,
1368    0x10, 0x04, 0x1e, 0x3c, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x20, 0x02,
1369    0x40, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00};
1370 
1371 #define up_width 16
1372 #define up_height 16
1373 static BMap up_bits[] = {
1374    0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x40, 0x01, 0x20, 0x02, 0x10, 0x04,
1375    0x08, 0x08, 0x04, 0x10, 0x1e, 0x3c, 0x10, 0x04, 0x10, 0x04, 0x10, 0x04,
1376    0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1377 #define l_width 16
1378 #define l_height 16
1379 static BMap l_bits[] = {
1380    0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01, 0x40, 0x01, 0x20, 0x1f,
1381    0x10, 0x10, 0x08, 0x10, 0x04, 0x10, 0x08, 0x10, 0x10, 0x10, 0x20, 0x1f,
1382    0x40, 0x01, 0x80, 0x01, 0x00, 0x01, 0x00, 0x00};
1383 #define r_width 16
1384 #define r_height 16
1385 static BMap r_bits[] = {
1386    0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x01, 0x80, 0x02, 0xf8, 0x04,
1387    0x08, 0x08, 0x08, 0x10, 0x08, 0x20, 0x08, 0x10, 0x08, 0x08, 0xf8, 0x04,
1388    0x80, 0x02, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00};
1389 #define pace_width 16
1390 #define pace_height 16
1391 static BMap slow_bits[] = {
1392    0xe0, 0x03, 0x18, 0x0c, 0x04, 0x10, 0x02, 0x20, 0x02, 0x20, 0x01, 0x40,
1393    0x01, 0x40, 0x81, 0x40, 0x81, 0x40, 0x81, 0x41, 0x82, 0x21, 0x82, 0x21,
1394    0x84, 0x13, 0x98, 0x0f, 0xe0, 0x03, 0x00, 0x00};
1395 static BMap fast_bits[] = {
1396    0xe0, 0x03, 0x18, 0x0c, 0x04, 0x10, 0x02, 0x20, 0x02, 0x20, 0x01, 0x40,
1397    0x01, 0x40, 0x81, 0x40, 0x81, 0x41, 0x81, 0x43, 0x82, 0x27, 0x82, 0x2f,
1398    0x84, 0x1f, 0x98, 0x0f, 0xe0, 0x03, 0x00, 0x00};
1399 static BMap blast_bits[] = {
1400    0xe0, 0x03, 0x18, 0x0c, 0x04, 0x10, 0x02, 0x20, 0x02, 0x20, 0x01, 0x40,
1401    0x01, 0x40, 0x81, 0x7f, 0x81, 0x7f, 0x81, 0x7f, 0x82, 0x3f, 0x82, 0x3f,
1402    0x84, 0x1f, 0x98, 0x0f, 0xe0, 0x03, 0x00, 0x00};
1403 
1404 #define film_width 17
1405 #define film_height 17
1406 static char film_bits[] = {
1407    0x00, 0x00, 0x0, 0x00, 0x07, 0x0, 0xb8, 0x0f, 0x0, 0xfc, 0x0f, 0x0, 0xfc,
1408    0x07, 0x0, 0xf8, 0x03, 0x0, 0xfc, 0xcf, 0x0, 0x04, 0xf8, 0x0, 0xf4, 0xfb,
1409    0x0, 0xf4, 0xfb, 0x0, 0xf6, 0xfb, 0x0, 0x06, 0xc8, 0x0, 0xfc, 0x0f, 0x0,
1410    0xe0, 0x01, 0x0, 0xa0, 0x01, 0x0, 0xe0, 0x01, 0x0, 0x00, 0x00, 0x0 };
1411 
1412 #define stop_width 16
1413 #define stop_height 16
1414 static BMap stop_bits[] = {
1415   0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e,
1416   0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e,
1417   0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, };
1418 
1419 #define MAX_COLORS  256
1420 #ifndef COLOR_OFFSET
1421 #define COLOR_OFFSET 0.25
1422 #endif
1423 static float coloff = COLOR_OFFSET;
1424 
1425 static Display *display;
1426 static int screen;
1427 static unsigned long colors[MAX_COLORS];
1428 static unsigned short colorr[MAX_COLORS];
1429 static unsigned short colorg[MAX_COLORS];
1430 static unsigned short colorb[MAX_COLORS];
1431 static int colcells = 16;
1432 static int IBGcolor = 0;
1433 static int OBGcolor = 0;
1434 static int BGmode = 0;
1435 #define SHCOLNUM 7
1436 static int shcolors[SHCOLNUM] = {190,193,196,199,202,205,208};
1437 static int rimcols[7] = {0,0,3,1,6,10,5};
1438 #define LIGHT  1
1439 #define MEDIUM 0
1440 #define DARK   2
1441 
1442 #define MAXSAVE 100000
1443 #define MXSAVESTR 1000
1444 static struct{float xxval;
1445               float yyval;
1446 	      XPoint *points;
1447 	      int npoints;
1448 	      int icol;
1449 	      int icon;
1450 	      int isgrey;
1451               int evtype;} savecom[MAXSAVE] = {0.0,0.0,NULL,0,0};
1452 
1453 static int count = 0;
1454 static int scount = 0;
1455 static int cnt = 0;
1456 static int ihlp ;
1457 static int hold = 0;
1458 static int holdt = 0;
1459 static int holdp = 0;
1460 static char savestr[MXSAVESTR][255];
1461 static int nsavestr[MXSAVESTR];
1462 
1463 static Bool monoscr = 0;
1464 static int linwid = 1;
1465 static int linmax = 10;
1466 
1467 static float xoff = 0.0;
1468 static float yoff = 0.0;
1469 static float scale = 1.0;
1470 static int MotionCount = 0;
1471 static int ZoomX1, ZoomY1;
1472 static int ZoomX2, ZoomY2;
1473 static int ZoomW, ZoomH;
1474 static int inited = 0;
1475 static Bool ZoomEnable = True, ZoomSelection = False;
1476 static Bool Select = True;
1477 static Cursor ZoomCursor;
1478 static Cursor AtomCursor;
1479 static Cursor WaitCursor;
1480 static int *jring;
1481 static int *isimpl;
1482 static int *fancy;
1483 static int *istaro;
1484 static int *atcol;
1485 static int *shade;
1486 static int *persp;
1487 static int TRANS;
1488 static int TRANSb;
1489 static int DoShadow = 0;
1490 static int DoLines = 0;
1491 static int DoBlur = 0;
1492 static int DoSSAO = 0;
1493 static int DoShad = 0;
1494 static int DoMIPMAP = 1;
1495 static int DoIntel = 0;
1496 static int SSAO_type = 1;
1497 static int aflag = 0,anum,acnt;
1498 static int bflag = 0;
1499 static int cflag = 0;
1500 static int dflag = 0;
1501 static int eflag = 0;
1502 static int doalign = 0;
1503 static int bretval = 320;
1504 static int omapr = 0;
1505 static int omapfol = 0;
1506 static int omaplck = 0;
1507 static int omaphlp = 0;
1508 static int omapCa = -1;
1509 static int omapPandN = 0;
1510 #define MINDIFF 15
1511 static int asel[6];
1512 static int aselkeep[2];
1513 static int monmode = 2;
1514 static float aret;
1515 static float toangs = 0.52917706e0;
1516 
1517 static Window win,winC,subC,winMC,subMC,winau,wincnv,wingeo,winspec,subSPEC,winsco,winpmf,winrama,subMOV,windock;
1518 static Window Fwin,RESwin,COMMwin,DISTwin,subDIST,SUBwin,CPwin,CTwin;
1519 static Window rootW;
1520 static GC gc;
1521 static GC gc1;
1522 static Pixmap stipple;
1523 static Pixmap gijs;
1524 static Pixmap molback;
1525 static Pixmap distpix;
1526 static Pixmap bckwin;
1527 static Pixmap colmap;
1528 static int dstpxini = 0;
1529 static unsigned int BckW = 100;
1530 static unsigned int BckH = 20;
1531 static Drawable molcur;
1532 XSizeHints size_hints;
1533 XTextProperty windowProp;
1534 XIconSize *size_list;
1535 XEvent report;
1536 XEvent event;
1537 XGCValues values;
1538 XWindowAttributes xwa;
1539 static XFontStruct *mfinfo;
1540 static XFontStruct *labinfo;
1541 static XFontStruct *slabinfo;
1542 Pixmap icon_pixmap;
1543 Region region;
1544 void filecall(char *str);
1545 void fwincall(char *str);
1546 void substrcall(char *str);
1547 void getpdbcall(char *str);
1548 void obsrch(char *str);
1549 void killob();
1550 static int addfile = 0;
1551 static int poszset = 0;
1552 static float poszbck = 0;
1553 static KeySym ks;
1554 
1555 static int xlx, yly ;			/* more statics for     */
1556 static int start_xlx, start_yly;	/* line drawing		*/
1557 static int isgl2D = 0;
1558 static unsigned int width, height;		/* window size		*/
1559 static float Aspect = 1.0;
1560 static int Mwidth, Mheight;		/* window size		*/
1561 
1562 static int wx = 10, wy = 30;	/* window location	*/
1563 static unsigned int border_width = 0;	/* no border 		*/
1564 
1565 unsigned int icon_width, icon_height;
1566 unsigned long foreground_pixel;
1567 static XSetWindowAttributes xswa;
1568 static XVisualInfo *vi;
1569 #define FFOGD 2.0
1570 #define FFOGDS 4.0
1571 static int has_opengl = 0;
1572 
1573 static char *window_name  = "MOLDEN";
1574 static char *icon_name    = "Molden";
1575 static char *display_name = NULL;
1576 static char *unknown  = "Unknown";
1577 
1578 #define MAXSTRLEN 80
1579 #define MAXPATHLEN 1024
1580 #define MAXSTRLMW 40
1581 #define MAXNAMES 10000
1582 #define MAXDIRS 500
1583 #define MAXDIRLEN 1024
1584 #define DEFSTRNAME ""
1585 #define DEFAUTHGEOM  "-100+100"
1586 #define DEFCNVGEOM  "-10+10"
1587 #define DEFPMFGEOM  "-10+440"
1588 #define DEFCNV2GEOM  "-410+10"
1589 #define DEFQBOXGEOM  "-400-400"
1590 #define DEFPOPGEOM  "-200+200"
1591 #define DEFQX	3
1592 #define DEFQY	3
1593 #define QBOXWIDE  450
1594 #define QBOXHIGH   40
1595 #define QBOXTX    340
1596 #define QBOXZM    290
1597 #define QBOXRF    290
1598 #define QBOXRFD   331
1599 #define QBOXFR      4
1600 #define QBOXBORD    4
1601 #define CNVOFFX    30
1602 #define CNVOFFY    30
1603 #define CNVBORD    10
1604 #define DBHIGH     46
1605 #define DBWIDE    236
1606 
1607 
1608 static int CNVWIDE = 300;
1609 static int CNVHIGH = 300;
1610 static int gwi = 300;
1611 static int ghi = 300;
1612 static int rwi = 300;
1613 static int rhi = 300;
1614 static int rwiold = 300;
1615 static int rhiold = 300;
1616 static int nwframes = 0;
1617 static int nhframes = 0;
1618 
1619 
1620 #define SBOXWIDE  600
1621 #define SBOXHIGH  400
1622 #define SBOXOFFX  52
1623 #define SBOXBLEN  200
1624 #define SBOXOFFL  SBOXOFFX+SBOXBLEN+10
1625 static int SUBup = 0;
1626 static int *ipdbwh;
1627 
1628 #ifdef DOQUEUE
1629 static int nques = 4;
1630 static int qopt = 0;
1631 static char *ques[] = {"short","medium","long","power"};
1632 static int quetims[] = {9,105,325,650};
1633 #endif
1634 
1635 static char *subwname[]  = {"Submit Gamess-UK Job","Submit Gaussian Job","Submit Mopac Job"};
1636 
1637 static char *topt1[] = {"Single Point","Geometry Optimisation",
1638 "Cart. Geom. Optimisation","Transition State","Frequency (Numerical)",
1639 "Frequency (Analytical)","SDCI","Polarisability","HyperPolarisability",
1640 "Magnetisability","Raman Intensities","IR Intensities","Localised Orbitals"};
1641 static char *topt2[] = {"Single Point","Geometry Optimisation","Transition State","Frequency"};
1642 static char *topt3[] = {"Single Point","Geometry Optimisation","Transition State","Frequency","Geometry Opt. & Frequency"};
1643 static char *topt4[] = {"Single Point","Geometry Optimisation","Transition State","Frequency","Geometry Opt. & Frequency"};
1644 static char **toph[4] = {topt1,topt2,topt3,topt4};
1645 static int topn[4] = {13,4,5,5};
1646 static char **topt;
1647 static int toptn;
1648 static char *tkey1[] = {" "," "," "," "," "," "," "," "," "," "," "," "," "};
1649 static char *tkey2[] = {" ","Opt","Opt=TS","Freq"};
1650 static char *tkey2b[] = {" ","Opt=Z-matrix","Opt=(TS,Z-matrix)","Freq"};
1651 static char *tkey3[] = {"1SCF","EF","TS","FORCE LET","FORCE"};
1652 static char *tkey4[] = {"1SCF","EF","TS","FORCE LET","FORCE"};
1653 static char **tkeyh[4] = {tkey1,tkey2,tkey3,tkey4};
1654 static char **tkey;
1655 static int itopt[4] = {1,1,1,1};
1656 
1657 static char *mopt1[] = {"RHF","Direct RHF","UHF","GVB n","MP2","Direct MP2","MP3","CASSCF"};
1658 static char *mopt2[] = {"HF","RHF","UHF","ROHF","MP2","MP4","QCISD","CASSCF","LSDA","BHandH","BHandHLYP","Becke 3 LYP","AM1","dreiding","Amber"};
1659 static char *mopt3[] = {"PM3","AM1","MNDO","MINDO3","PM6","PM7","RM1"};
1660 static char *mopt4[] = {"RHF","UHF","DFT LDA","DFT PBE","DFT B3LYP"};
1661 static char **moph[4] = {mopt1,mopt2,mopt3,mopt4};
1662 static int mopn[4] = {8,15,7,5};
1663 static char **mopt;
1664 static int moptn;
1665 static char *mkey1[] = {" "," "," "," "," "," "," "," "};
1666 static char *mkey2[] = {"HF","RHF","UHF","ROHF","MP2","MP4","QCISD","CASSCF(4,6)","SVWN","BHandH","BHandHLYP","Becke3LYP","AM1","dreiding","Amber"};
1667 static char *mkey3[] = {"PM3","AM1","MNDO","MINDO3","PM6","PM7","RM1"};
1668 static char *mkey4[] = {"RHF","UHF","DFT LDA","DFT PBE","DFT B3LYP"};
1669 static char **mkeyh[4] = {mkey1,mkey2,mkey3,mkey4};
1670 static char **mkey;
1671 static int imopt[4] = {0,0,1,0};
1672 
1673 static char *bopt1[] = {"STO-3G","3-21G","4-31G","6-31G","6-31G*","6-31G**","MINI1","MINI4","MIDI1","MIDI4","DZ","TZV","TZVP","ECPMIN","ECPDZ","ECPTZV","ECPTZVP"};
1674 static char *bopt2[] = {"STO-3G","3-21G","4-31G","6-31g","6-31G*","6-31G**","6-31+G*","LANL2DZ"};
1675 static char *bopt3[] = {" "};
1676 static char *bopt4[] = {"STO-3G","3-21G","4-31G","6-31g","6-31G*","6-31G**","6-31+G*","6-311G**"};
1677 static char **boph[4] = {bopt1,bopt2,bopt3,bopt4};
1678 static int bopn[4] = {17,8,1,8};
1679 static char **bopt;
1680 static int boptn;
1681 static char *bkey1[] = {"STO-3G","3-21G","4-31G","6-31G","6-31G*","6-31G**","6-31+G*","LANL2DZ"};
1682 static char *bkey2[] = {"STO-3G","3-21G","4-31G","6-31G","6-31G*","6-31G**","6-31+G*","LANL2DZ"};
1683 static char *bkey3[] = {" "};
1684 static char *bkey4[] = {"STO-3G","3-21G","4-31G","6-31G","6-31G*","6-31G**","6-31+G*","6-311G**"};
1685 static char **bkeyh[4] = {bkey1,bkey2,bkey3,bkey4};
1686 static char **bkey;
1687 static int ibopt[4] = {0,0,0,0};
1688 
1689 
1690 static char *spopt[] = {"Singlet","Doublet","Triplet","Quartet","Quintet","Sextet","Septet","Octet"};
1691 static int ispopt = 0;
1692 
1693 static char *molopt1[] = {"No extra keys","Molden G94/98","Molden G92"};
1694 static char *molopt2[] = {"No extra keys","extra keys"};
1695 static char *molopt3[] = {"ecce key","no keys"};
1696 static char **molopt;
1697 static int imolopt[4] = {1,1,1,1};
1698 
1699 static char *copt[] = {"-3","-2","-1","0","1","2","3","other"};
1700 static int icopt = 3;
1701 
1702 static char *resopt[] = {"Dont Save EDs","ed3","ed2","ed2 + ed3","Restart HF","Restart CASSCF","Restart MCSCF","Restart CI","Restart MRDCI","Restart FULLCI"};
1703 static char *reskey[] = {" ","-t ed3","-t ed2","-t ed2 -t ed3","-r hf","-r casscf","-r mcscf","-r ci","-r mrdci","-r fullci"};
1704 static int iresopt = 0;
1705 
1706 static int iscfd = 1;
1707 static int ihess = 1;
1708 static char scfdir[] = "SCF=Direct";
1709 static char nullstr[] = " ";
1710 static int jmode;
1711 static int izmat = 1;
1712 static int ioniom = 0;
1713 static int ionon = 0;
1714 
1715 #define SUBLEN1 80
1716 #define SUBLEN2 15
1717 static char rungam[SUBLEN1];
1718 #ifdef VMS
1719 static struct dsc$descriptor_s *glin1;
1720 static struct dsc$descriptor_s *glin2;
1721 static struct dsc$descriptor_s *gtitl;
1722 static struct dsc$descriptor_s *jname;
1723 static struct dsc$descriptor_s *qname;
1724 static struct dsc$descriptor_s *ename;
1725 static struct dsc$descriptor_s *vfile;
1726 static struct dsc$descriptor_s *mfile;
1727 static struct dsc$descriptor_s *gfile;
1728 static struct dsc$descriptor_s *oglfile;
1729 static struct dsc$descriptor_s *povfile;
1730 static struct dsc$descriptor_s *tnkjn;
1731 static struct dsc$descriptor_s *tmpfil;
1732 #else
1733 #ifdef CRAY
1734 static _fcd glin1;
1735 static _fcd glin2;
1736 static _fcd gtitl;
1737 static _fcd jname;
1738 static _fcd qname;
1739 static _fcd ename;
1740 static _fcd vfile;
1741 static _fcd mfile;
1742 static _fcd gfile;
1743 static _fcd oglfile;
1744 static _fcd povfile;
1745 static _fcd tnkjn;
1746 static _fcd tmpfil;
1747 #else
1748 static char *glin1;
1749 static char *glin2;
1750 static char *gtitl;
1751 static char *jname;
1752 static char *qname;
1753 static char *ename;
1754 static char *vfile;
1755 static char *mfile;
1756 static char *gfile;
1757 static char *oglfile;
1758 static char *povfile;
1759 static char *tnkjn;
1760 static char *tmpfil;
1761 #endif
1762 #endif
1763 
1764 #define MAXCMD 256
1765 static char cmdstr[MAXCMD];
1766 static int cycle = 0;
1767 static int delcyclefile = 0;
1768 /*static int fndfile = 0;*/
1769 volatile sig_atomic_t fndfile;
1770 /*static int uping = 0;*/
1771 #define CHUNK 5
1772 volatile sig_atomic_t uping;
1773 static volatile sig_atomic_t nomemf = 0;
1774 volatile sig_atomic_t DoSVGExpose;
1775 static int tnkfrk = 0;
1776 static int tnkpid = 0;
1777 static int tnkupd = 0;
1778 volatile sig_atomic_t tnkupf = 0;
1779 static int tnkesc = 0;
1780 static int tnkloop = 0;
1781 static int handle = 0;
1782 static int tnk_single = 0;
1783 static int opttim = 0;
1784 static int icyco = 0;
1785 static int TIMi = 100;
1786 #define NCYCO 5
1787 static long timo[NCYCO];
1788 static double newen;
1789 static int hasmpi = 0;
1790 static char mpicmd[MAXCMD];
1791 static char mpilib[MAXCMD];
1792 static char npth[MAXCMD];
1793 static int maxproc = 0;
1794 static int useproc = 1;
1795 static int usempi = 0;
1796 
1797 static unsigned long infofg, infobg;
1798 static unsigned long Black, White;
1799 static Window QBox, PopUp, FrBox,EBox, PopOk;
1800 static char   strname[MAXSTRLEN];
1801 static char   molwstr[MAXSTRLMW] = " ";
1802 static char   densstr[MAXSTRLMW] = " ";
1803 static char   *qboxprmt;
1804 static char   stemp[MAXSTRLEN];
1805 static char   atemp[MAXSTRLEN];
1806 static char   chgtmp[MAXSTRLEN];
1807 static char   pchgtmp[MAXSTRLEN];
1808 static char   resfil[MAXSTRLEN];
1809 static char   qrb_title[MAXCMD] = " ";
1810 static char   organism[MAXCMD] = " ";
1811 static int norbs;
1812 
1813 #define gray50_width 8
1814 #define gray50_height 8
1815 static BMap gray50_bits[] = {
1816    0x33, 0xcc, 0x33, 0xcc, 0x33, 0xcc, 0x33, 0xcc};
1817 
1818 typedef void (*ptr_void_proc)();
1819 
1820 typedef struct { Window win;            /* parent window */
1821                  int x,y,w,h;           /* size of button rectangle */
1822                  int lit;               /* if true, invert colors */
1823                  int active;            /* if false, stipple gray */
1824                  int toggle;            /* if true, clicking toggles state */
1825                  int boggle;            /* if true, clicking toggles state */
1826                  int lastused;          /* lastused */
1827 		 int fg;		/* foreground color index */
1828                  int bg;		/* colors */
1829                  char *str;             /* string in button */
1830                  char *explstr;         /* string with explanation */
1831                  Pixmap pix;            /* use pixmap instead of string */
1832                  int pw,ph;             /* size of pixmap */
1833                  int style;             /* ... */
1834                  int fwidth;            /* width of frame */
1835                } BSTRU;
1836 
1837 void DrwBut(BSTRU *bp);
1838 void ActBut(BSTRU *bp,int act);
1839 void TogDown(BSTRU *bp);
1840 void TogUp(BSTRU *bp);
1841 void SelBut(BSTRU *bp);
1842 void DefBut(BSTRU *bp,Window win,int x,int y,int w,int h,
1843 	char *str,unsigned long bg,int fg);
1844 
1845 typedef struct { Window win;            /* parent window */
1846 		 int x,y;		/* pos. of scroll rectangle */
1847                  unsigned int w,h;      /* size of scroll rectangle */
1848 		 int *wn;		/* number of elements in list */
1849 		 int *wpos;		/* position of window in list */
1850 		 int wh;		/* hight of the rectangle in elements */
1851 		 ptr_void_proc callback;/* callback routine */
1852                } SCRSTRU;
1853 
1854 static SCRSTRU zscroll;
1855 
1856 #define SCRMIN 10
1857 
1858 void DefScroll(SCRSTRU *sc,Window win,int x,int y,unsigned int w,
1859 	unsigned int h,int *wn,int *wpos,int wh,ptr_void_proc callback);
1860 void RedrawScroll(SCRSTRU *sc);
1861 
1862 typedef struct {char   **list;		/* pointer to list of strings */
1863 		float  *rlst;		/* pointer to float array */
1864 		double  *flst;		/* pointer to double array */
1865 		int *ilst;		/* pointer into list */
1866 		int *slst;		/* pointer into selected list */
1867 		SVGFSTRUC *svgs;	/* list of svg's for each file */
1868 		int *nents;		/* number of entries in list */
1869 		} LSTRU;
1870 
1871 typedef struct {char   **list;		/* pointer to list of strings */
1872 		int nents;		/* number of entries in list */
1873 		} LSSTRU;
1874 
1875 typedef struct { Window win;            /* parent window */
1876                  int x,y;		/* size of list rectangle */
1877                  unsigned int w,h;      /* size of list rectangle */
1878 		 unsigned int wwin;	/* size of parent window */
1879 		 int mxents;		/* max entries in visible window on list*/
1880 		 LSTRU list;
1881 		 char *label;		/* tabel header */
1882 		 int lpnt;		/* position of window in list */
1883 		 int select;		/* selected entry */
1884 		 BSTRU arrbut[2];	/* pointer to arrbuttons */
1885 		 SCRSTRU scrbar;	/* scrollbar */
1886                } LISTSTRU;
1887 
1888 typedef struct { Window win;            /* parent window */
1889 		 Window Callwin;
1890 		 LISTSTRU flist;
1891 		 LISTSTRU dirlist;
1892 		 BSTRU rbut[6];
1893 		 char  *files[MAXNAMES];
1894 		 char  *dirs[MAXDIRS];
1895 		 char  lastdir[MAXDIRLEN];
1896 		 char  label[MAXSTRLEN];
1897 		 char  substr[MAXSTRLEN];
1898 		 char *pntr;
1899 		 int nfiles;
1900 		 int ndirs;
1901 		 int qbrfile;
1902 		 int inct;
1903 		 int parse;
1904 		 int subopt;
1905                } FSELSTRU;
1906 
1907 void RedrawList(LISTSTRU *lp);
1908 void getfiles(FSELSTRU *fs, char* dirname);
1909 void RedrawLBox(LISTSTRU *lp);
1910 void DefList(LISTSTRU *lp,Window win,int x,int y,unsigned int w,unsigned int h,
1911 	char *label,int mx,char **lstr,float *rlist,double *flst,int *slist,
1912 	int *nentries,SVGFSTRUC *svgs);
1913 void RedrawPopUp(LSSTRU *List);
1914 int DoPopUp(Window ParentWin,int x,int y,LSSTRU *List,int *iopt,int icent);
1915 
1916 static int nbytes_select;
1917 static char *select_pointer;
1918 typedef struct { Window win;            /* parent window */
1919 		 int pop;		/* is it a popup */
1920 		 int active;		/* is it active  */
1921 		 int changed;		/* is it changed  */
1922 		 int fake;		/* is it a fake empty box  */
1923                  int x,y;		/* size of list rectangle */
1924                  unsigned int w,h;      /* size of list rectangle */
1925 		 int col;		/* color of rectangle */
1926 		 int bgcol;		/* background color of fake rectangle */
1927                  char *prompt;          /* prompt string */
1928 		 int qbopt;		/* what is the answer, any of 3 below */
1929                  char *str; /* query string */
1930 		 int strmax;		/* maximum length of string */
1931 		 int wnd_start;		/* the start of the visible protion of he string */
1932 		 int wlen;		/* length in char of the windows */
1933 		 int curpos;		/* insertion position */
1934 		 int	*iflt;		/* int answer */
1935 		 short int	*i2flt;	/* short int answer */
1936 		 float	*qflt;		/* float answer */
1937 		 double	*dflt;		/* double answer */
1938 		 int qbinct;		/* option to be given to fortran */
1939                  char *explstr;         /* string with explanation */
1940 		 ptr_void_proc callback;/* callback routine */
1941                } QBOXSTRU;
1942 
1943 void PromptBox(QBOXSTRU *qp);
1944 
1945 void qboxstr(QBOXSTRU *qp,Window *win,int active,int fake,int bgcol,int x,int y,int w,int h,int col,char *prompt,char *defstr,int strmax,int iopt,int qinct,int mxstr,ptr_void_proc callback);
1946 
1947 #define mxvalc 10
1948 typedef struct { double edge;
1949 		 double ctval[mxvalc];
1950 		 double pxyz[3];
1951                  int nvalc,nspts,istyp;
1952                } SRFSTRU;
1953 
1954 static SRFSTRU *surface;
1955 
1956 typedef struct { Window win;            /* parent window */
1957 		 int x,y;		/* pos. of scroll rectangle */
1958                  unsigned int w,h;      /* size of scroll rectangle */
1959 		 int sh;		/* slider height */
1960 		 int *wn;		/* max slider position */
1961 		 int *wpos;		/* slider position */
1962 		 float *ratio;		/* ratio */
1963 		 ptr_void_proc callback;/* callback routine */
1964                } SLIDESTRU;
1965 
1966 void DefSlide(SLIDESTRU *sc,Window win,int x,int y,unsigned int w,unsigned int h,int sh,int *wn,int *wpos,float *rat,ptr_void_proc callback);
1967 void RedrawSlide(SLIDESTRU *sc);
1968 
1969 #define NOBJS 46
1970 typedef struct {
1971 		Window *win;
1972 		Window *subwin;
1973 		int *winup;
1974 		BSTRU *butarr;
1975 		int numbut;
1976 		ptr_void_proc init;
1977 		ptr_void_proc redraw;
1978                } WSTRU;
1979 
1980 #if defined(DARWIN) || defined(FREEBSD) || defined(__DragonFly__)
1981 static WSTRU WinObj[NOBJS];
1982 #else
1983 static WSTRU WinObj[NOBJS] = {{.win = NULL, .winup = NULL, .butarr = NULL, .win = NULL, .redraw = NULL}};
1984 #endif
1985 
1986 static char **mlftit = NULL;
1987 static int mxtits = 0;
1988 static int ntits = 0;
1989 static double *scle;
1990 static double *adjuss;
1991 static double *rng1;
1992 static double *rng2;
1993 static double *vlcnt;
1994 static double *vlcnt2;
1995 static double *valcnt;
1996 
1997 typedef struct { double hdmin;
1998 		 double hdmax;
1999 		 float hamin;
2000 		 float hamax;
2001                } HBSTRU;
2002 
2003 static HBSTRU *hbpars;
2004 
2005 typedef struct { int button;
2006 		 Window win;
2007 		 BSTRU *barr;
2008 		 QBOXSTRU *qarr;
2009 		 int borq;
2010 		 int active;
2011 		 int *winup;
2012                } EXPLSTRU;
2013 
2014 static EXPLSTRU expldat = {-1,-1,NULL,NULL,0,0,NULL};
2015 
2016 static char *cellopts[] = {"Molecule","Mol+Cell","Packed-Cell 1",
2017 "Packed-Cell 2","Packed-1+Surf","Packed-2+Surf","Multiple-Cells",
2018 "Multiple-CellsA","Multiple-CellsB","Multiple-CellsC","Multiple-CellsAB",
2019 "Multiple-CellsAC","Multiple-CellsBC","Cell Rot On/Off",
2020 "Edit Cell Parameters","Delete Sel. Atoms","Move Sel. Atoms","SuperCell", "Optimise xtinker","Write"};
2021 static int ncell = 20;
2022 static char *cellwopts[] = {"Write DMAREL","Write CRYSTAL95","Write SHELX","Write VASP","write PLUTON","write MOPAC Tv","write CPMD","write CIF"};
2023 static int nwcell = 8;
2024 static double CellTran[] = {0.0,0.0,0.0};
2025 static char *xtinkopts[] = {"Charges","Multipoles"};
2026 static char *ambwopts[] = {"Without Cell","With Cell"};
2027 
2028 static char *cellpars[] = {"A    ","B    ","C    ","ALPHA","BETA ","GAMMA","SpaceGroupNumber","SpaceGroupName"};
2029 static char *cellvec[] = {"A","B","C"};
2030 static int CPact[5][6] = {
2031   {1,1,1,1,1,1},
2032   {1,1,1,0,1,0},
2033   {1,1,1,0,0,0},
2034   {1,0,1,0,0,0},
2035   {1,0,0,0,0,0}
2036 };
2037 static int CPup = 0;
2038 static int CPopt = 0;
2039 #define CPBOXWIDE  250
2040 #define CPBOXHIGH  310
2041 #define CPBOXOFFX  20
2042 #define CPBOXOFFY  20
2043 
2044 static int CTdel = 0;
2045 static int CTup = 0;
2046 static int CTsdone = 0;
2047 static int CTdsdone = 0;
2048 static int CTconn = 1;
2049 #define CTBOXWIDE  260
2050 #define CTBOXHIGH  140
2051 #define CTBOXOFFX  15
2052 #define CTBOXOFFY  20
2053 
2054 #define GLTOL 5
2055 
2056 #define MAXPNT 2000
2057 typedef struct { double fmaxt,frmst,dmaxt,drmst,fgmin,fgmax,dgmin,dgmax,enmax,enmin;
2058                  int ngeoms;
2059                  int nepnts;
2060                  int gcvav;
2061 		 int ifmxav,ifrmav,idmxav,idrmav,ieav,ifrav,mxpnt;
2062                } GEO1STRU;
2063 
2064 static GEO1STRU *geo1ptr;
2065 
2066 typedef struct { double formax[MAXPNT];
2067                  double forrms[MAXPNT];
2068                  double dismax[MAXPNT];
2069                  double disrms[MAXPNT];
2070                  double epoints[MAXPNT];
2071                  int isav[MAXPNT];
2072                } GEO2STRU;
2073 
2074 static GEO2STRU *geo2ptr;
2075 
2076 typedef struct { double *formax;
2077                  double *forrms;
2078                  double *dismax;
2079                  double *disrms;
2080                  double *epoints;
2081                  int *isav;
2082 		 int mxorg;
2083                } GEOPSTRU;
2084 
2085 static GEOPSTRU geopntr;
2086 static GEOPSTRU TMPgeopntr;
2087 
2088 static GEOPSTRU *geop = &geopntr;
2089 
2090 #define MAXITER 1000
2091 typedef struct { double convg1[MAXITER];
2092                  double convg2[MAXITER];
2093                  double cnvmax,cnvmin;
2094                  int jstrt1,jend1;
2095                  int jstrt2,jend2;
2096                  int icvav1,icvav2;
2097                } CNVSTRU;
2098 
2099 static CNVSTRU *cnvptr;
2100 
2101 #define MXAMB 1590
2102 #define MXGFF  72
2103 #define MXAMBC 49
2104 typedef struct { double ambchg[MXAMB];
2105                  double ambvw1[MXAMBC];
2106                  double ambvw2[MXAMBC];
2107                  double gfvdw[MXGFF][2];
2108 		 int ambvdt[MXAMB];
2109                  double cysneg[9];
2110                } CHGVDWSTRU;
2111 
2112 static CHGVDWSTRU *chgvdwptr;
2113 
2114 #define MAXAT 1000
2115 
2116 typedef struct {
2117 	int swap;
2118 	int prec;
2119 	int box;
2120 	int vir;
2121 	int pres;
2122 	int x;
2123 	int v;
2124 	int f;
2125 	int natoms;
2126 	int nframes;
2127 	long *fpos;
2128 	FILE *fptr;
2129        } sttrr;
2130 
2131 static sttrr strx = {0,0,0,0,0,0,0,0,0,0,NULL,NULL};
2132 
2133 typedef struct {
2134 	int etot;
2135 	FILE *fptr;
2136        } stedr;
2137 
2138 static stedr stre;
2139 
2140 void DoBackbone();
2141 void cltrr();
2142 
2143 static Bool Selecting = 0;
2144 
2145 
2146 typedef struct { double *variable;
2147 		 double varinit;
2148 		 double varincr[3];
2149 		 int isel;
2150 		 int vartype;
2151 		 int vdirection;
2152 		 int frame;
2153 		 int nframe;
2154 		 int on;
2155 		 int part;
2156 		 int ssdone;
2157                } ANIMSTRU;
2158 
2159 static ANIMSTRU animptr = {NULL,0.0,{0.01,5.0,5.0},0,0,1,0,60,0,0,0};
2160 
2161 static int ANIMNXT = 0;
2162 
2163 typedef struct { int ihasd;
2164 		 int isgau;
2165 		 int ido5d;
2166 		 int ido7f;
2167 		 int ido9g;
2168 		 int ihasg;
2169                } GAUSTRU;
2170 static GAUSTRU *slagau;
2171 
2172 #define MAXFAT 1000
2173 #define MAXFRQ MAXFAT*3
2174 typedef struct { float freq[MAXFRQ];
2175 		 float a[MAXFAT][3];
2176 		 double fcoo[MAXFAT][3];
2177 		 double frint[MAXFRQ];
2178 		 double ramint[MAXFRQ];
2179 		 int nfreq;
2180 		 int ihasi;
2181                } FRQSTRU;
2182 static FRQSTRU *FRQ;
2183 
2184 typedef struct { double bl[MAXAT];
2185 		 double alph[MAXAT];
2186 		 double bet[MAXAT];
2187 		 int ibl[MAXAT];
2188 		 int ialph[MAXAT];
2189 		 int ibet[MAXAT];
2190 		 int ianz[MAXAT];
2191 		 int iz[MAXAT][4];
2192 		 int imap[MAXAT];
2193                } ZMATSTRU;
2194 
2195 static ZMATSTRU *zmatptr;
2196 
2197 typedef struct { double *bl;
2198 		 double *alph;
2199 		 double *bet;
2200 		 int *ibl;
2201 		 int *ialph;
2202 		 int *ibet;
2203 		 int *nz;
2204 		 int *ianz;
2205 		 int *iz;
2206 		 int *imap;
2207 		 int *ihaszm;
2208 		 int *mxzat;
2209 		 int mxzorg;
2210 		} ZMSTRU;
2211 
2212 static ZMSTRU zmptr;
2213 static ZMSTRU TMPzmptr;
2214 static ZMSTRU *zmptrp = &zmptr;
2215 
2216 
2217 typedef struct { int ipart;
2218 		 int imn;
2219 		 int imx;
2220 		 int idcur;
2221 		} ZMPARTSTRU;
2222 
2223 static ZMPARTSTRU *zmpart;
2224 
2225 typedef struct { int ianz;
2226 		 int iz[4];
2227 		 double bl;
2228 		 double alph;
2229 		 double bet;
2230 		} ZLINESTRU;
2231 
2232 void CopyFrag(ZLINESTRU *frag,int frglen,int linkoffset);
2233 void MoveFrag(ZLINESTRU *frag,ZLINESTRU *destiny,int frglen,int destoff);
2234 void AddFrag(ZLINESTRU *frag,int fraglen,double covang,double dih,
2235 	int addrow,int update,int pdbt,int doadd);
2236 
2237 typedef struct { double cstoc[MAXAT][3];
2238 		 double czstoc[MAXAT][3];
2239 		 double astoc[MAXAT];
2240 		 double bstoc[MAXAT];
2241 		 int ianstc[MAXAT];
2242                } TSTOCSTRU;
2243 
2244 static TSTOCSTRU *tstoc;
2245 
2246 typedef struct { double *cstoc;
2247 		 double *czstoc;
2248 		 double *astoc;
2249 		 double *bstoc;
2250 		 int *ianstc;
2251                } STOCSTRU;
2252 
2253 static STOCSTRU stoc;
2254 static STOCSTRU TMPstoc;
2255 static STOCSTRU *stocp = &stoc;
2256 
2257 void FreeZmt(ZMSTRU tzmt,STOCSTRU tstoc,
2258 QBOXSTRU *tbox1,QBOXSTRU *tbox2,QBOXSTRU *tbox3,QBOXSTRU *tbox4,QBOXSTRU *tbox5);
2259 #define MAXORB 256
2260 
2261 typedef struct { double qd[MAXORB][MAXORB];
2262                  double pd[MAXORB];
2263                  double gd[MAXORB][3];
2264                  double hd[MAXORB][6];
2265                } TORBSTRU;
2266 
2267 static TORBSTRU *torb;
2268 
2269 typedef struct { double *qd;
2270 		 double *pd;
2271 		 double *gd;
2272 		 double *hd;
2273                } ORBSTRU;
2274 
2275 static ORBSTRU orb;
2276 static ORBSTRU TMPorb;
2277 static ORBSTRU *orbp = &orb;
2278 
2279 typedef struct { double *focc;
2280 		 double *focb;
2281 		 double *vectrs;
2282 		 double *vectrb;
2283 		 double *p;
2284 		 double *paa;
2285 		 double *averag;
2286 		 double *phi;
2287 		 double *dphi;
2288 		 double *dxpsi;
2289 		 double *dypsi;
2290 		 double *dzpsi;
2291 		 float *eiga;
2292 		 float *eigb;
2293 		 float *stoalfa;
2294 		 float *stobnorm;
2295 		 int *ncols;
2296 		 int *ncolb;
2297 		 int *nocc;
2298 		 int *nocb;
2299 		 int *naorbs;
2300 		 int *mxorb;
2301 		 int *istos;
2302 		 int mxorg;
2303                } DORBSTRU;
2304 
2305 static DORBSTRU dorb;
2306 static DORBSTRU TMPdorb;
2307 static DORBSTRU *dorbp = &dorb;
2308 
2309 #define NUMPRM 1600
2310 #define NUMCEX NUMPRM*3
2311 
2312 typedef struct { double exx[NUMCEX];
2313 		 double c1[NUMCEX];
2314 		 double c2[NUMCEX];
2315 		 double c3[NUMCEX];
2316 		 double c4[NUMCEX];
2317 		 double c5[NUMCEX];
2318 		 int shladf[NUMPRM];
2319 		 double gx[NUMPRM];
2320 		 double gy[NUMPRM];
2321 		 double gz[NUMPRM];
2322 		 int jan[NUMPRM];
2323 		 int shella[NUMPRM];
2324 		 int shelln[NUMPRM];
2325 		 int shellt[NUMPRM];
2326 		 int shellc[NUMPRM];
2327 		 int aos[NUMPRM];
2328 		 int nshell;
2329 		 int maxtyp;
2330                } BASSTRU;
2331 static BASSTRU *BAS;
2332 
2333 #define NUMATM 2000
2334 
2335 typedef struct { int ipseud;
2336 		 int ivale[NUMATM];
2337                } PSEUDSTRU;
2338 static PSEUDSTRU *PSEUD;
2339 
2340 typedef struct { int nfirst[NUMATM];
2341 		 int nlast[NUMATM];
2342 		 int npq[NUMATM];
2343 		 int pqn[NUMATM];
2344 		 double emus[NUMATM];
2345 		 double emup[NUMATM];
2346 		 double emud[NUMATM];
2347 		 double consts[NUMATM];
2348 		 double constp[NUMATM];
2349 		 double constd[NUMATM];
2350 		 int npqref[54];
2351                } MOPSTRU;
2352 static MOPSTRU *MOP;
2353 
2354 typedef struct { double px;
2355 		 double py;
2356 		 double pz;
2357 		 double cx;
2358 		 double cy;
2359 		 double cz;
2360 		 double r[3];
2361 		 double v1[3];
2362 		 double v2[3];
2363 		 int iplat;
2364                } PLANESTRU;
2365 static PLANESTRU *plane;
2366 
2367 typedef struct { double ca;
2368 		 double cb;
2369 		 double sa;
2370 		 double sb;
2371 		 double cc;
2372 		 double sc;
2373                } EULSTRU;
2374 static EULSTRU *eul;
2375 
2376 typedef struct { double xsym[NUMATM];
2377 		 double ysym[NUMATM];
2378 		 double zsym[NUMATM];
2379 		 int isym[NUMATM];
2380                } PROJSTRU;
2381 static PROJSTRU *proj;
2382 
2383 typedef struct {
2384 		 double nucshld[NUMATM];
2385 		 int ihsnmr;
2386                } NMRSTRU;
2387 static NMRSTRU *nmrptr;
2388 static double *jcoupl = NULL;
2389 
2390 typedef struct { double *denn;
2391 		 double *pmnn;
2392 		 double *dens;
2393 		 double *denst;
2394 		 double *edx;
2395 		 double *edy;
2396 		 double *rz;
2397 		 double *bucket;
2398 		 int *iedlog;
2399 		 int *ix;
2400 		 int *iy;
2401 		 int *mx3d;
2402 		 int *mx3d2;
2403 		 int mxorg;
2404                } GRDSTRU;
2405 
2406 static GRDSTRU sgrd;
2407 static GRDSTRU TMPsgrd;
2408 
2409 typedef struct { double *fmap;
2410 		 int *mx3d;
2411 		 int mxorg;
2412                } MGRDSTRU;
2413 
2414 static MGRDSTRU mgrd;
2415 static MGRDSTRU TMPmgrd;
2416 static int *mapit;
2417 static int *ipsi;
2418 
2419 #define MAXMOL 100
2420 #define MXMFMOL 100
2421 
2422 typedef struct { int nmols;
2423 		 int imol;
2424 		 int iendmf;
2425 		 int ielin;
2426 		 int maxmol;
2427 		 int *mollin;
2428 		} MFSTRU;
2429 
2430 static MFSTRU *mfdata;
2431 
2432 #define MXPLEV 5
2433 typedef struct { double grdw;
2434 		 double plevel[MXPLEV];
2435 		 int ipcol[MXPLEV+1];
2436 		 int nplev;
2437 		} POTSTRU;
2438 
2439 static POTSTRU *potcom;
2440 
2441 typedef struct { int nps1;
2442 		 int nps2;
2443 		 int nps3;
2444 		 int srfmap;
2445 		 int srfloc;
2446 		 int ifogl;
2447 		 int itsrf;
2448 		} HSRFSTRU;
2449 
2450 static HSRFSTRU *hlpsrf;
2451 
2452 typedef struct { int ito;
2453 		 int imo;
2454 		 int ibo;
2455 		 int itotc;
2456 		 int imult;
2457 		 int ibatch;
2458 		 int ihs;
2459 		 int itm;
2460 		 int iwxyz;
2461 		 int icopth;
2462 		 int icoptm;
2463 		 int icoptl;
2464 		 int ispopth;
2465 		 int ispoptm;
2466 		 int ispoptl;
2467 		 int iextopt;
2468 		} JOBSTRU;
2469 
2470 static JOBSTRU *jobcom;
2471 
2472 typedef struct { double rx[3];
2473 		 double ry[3];
2474 		 double rz[3];
2475 		 double t[3];
2476 		 double td[3];
2477 		} ROTSTRU;
2478 
2479 static ROTSTRU *rotptr;
2480 
2481 typedef struct { double xv;
2482 		 double yv;
2483 		 double zv;
2484 		 double c0;
2485 		 double pincr;
2486 		} POSSTRU;
2487 
2488 static POSSTRU *posptr;
2489 
2490 typedef struct {
2491 		 double scal;
2492 		 double fscal;
2493 		 double scali;
2494 		 double smag;
2495 		 int iscupd;
2496                } SCALSTRU;
2497 
2498 static SCALSTRU *scalptr;
2499 
2500 #define NUMCAL 50000
2501 #define MXCHAI 50
2502 #define MXRES 42
2503 #define MXHETA 150
2504 #define MXALN 20
2505 
2506 typedef struct {
2507 		 double rphi[NUMCAL];
2508 		 double rpsi[NUMCAL];
2509 		 int icalf[NUMCAL][6];
2510 		 int ncalf;
2511 		 int ianf[MXCHAI];
2512 		 int islu[MXCHAI];
2513 		 int nchain;
2514 		 int iamino[NUMCAL];
2515 		 int ihet[MXHETA];
2516 		 int iclhet[MXHETA];
2517 		 int reson[NUMCAL];
2518 		 int issdon;
2519 		 int icxp[NUMCAL];
2520 		 int icyp[NUMCAL];
2521 		 int iams[NUMCAL];
2522 		 int ihets[MXHETA];
2523 		 int ibck[4];
2524 		 int isal[NUMCAL];
2525 		 int irsnr[NUMCAL];
2526 		 int lab[NUMCAL];
2527 		 int ihashb;
2528 		 int ishoh;
2529 		 int ision;
2530 		 int achain[NUMCAL];
2531 		} CALFSTRU;
2532 
2533 static CALFSTRU *calfptr;
2534 
2535 typedef struct { int ihashz;
2536 		 int ihetq[MXHETA];
2537 		 int ihqset[MXHETA];
2538 		 int ihhadd[MXHETA];
2539 		 int labhet[MXHETA];
2540 		 int ilcset;
2541 		 int ligcat[MXHETA];
2542 		} CLFSTRU;
2543 
2544 static CLFSTRU *clfstrptr;
2545 
2546 #define MXINRS 100
2547 typedef struct { int incomp[MXINRS];
2548 		 int nincmp;
2549 		} INCOMPLSTRU;
2550 
2551 static INCOMPLSTRU *incompl;
2552 
2553 typedef struct { int nalign;
2554 		 int istst[MXALN];
2555 		 int istch[MXALN];
2556 		 int istres[MXALN];
2557 		 int istcol[MXALN];
2558 		 char *istptr[MXALN];
2559 		} ALNSTRU;
2560 
2561 static ALNSTRU *alnptr;
2562 
2563 typedef struct { int iener;
2564 		 float energy;
2565 		} ENERSTRU;
2566 
2567 static ENERSTRU *eneptr;
2568 
2569 typedef struct { int Allocated[MXHETA];
2570 		 char  *HetAtm[MXHETA];
2571 		 int NHetAtm;
2572 		} HETATMSTRU;
2573 static HETATMSTRU hetptr = {.Allocated = {0},.HetAtm = {NULL},.NHetAtm = 0};
2574 
2575 #define MXHETLAB 5000
2576 typedef struct { int iat[MXHETLAB];
2577 		 char  *HetLab[MXHETLAB];
2578 		 int NHetLab;
2579 		} HETLABSTRU;
2580 static HETLABSTRU hetlab = {.NHetLab = 0};
2581 
2582 typedef struct {
2583 		 int isndcl[4];
2584 		 int iamicl[MXRES];
2585 		 int ichcol[MXCHAI];
2586 		} CLFHSTR;
2587 
2588 static CLFHSTR *clfhptr;
2589 
2590 static int *iftyp;
2591 
2592 typedef struct { double *coo;
2593 		 double *rzp;
2594 		 double *qat;
2595 		 int *isurf;
2596 		 int *icont;
2597 		 int *lwrit;
2598 		 int *lring;
2599 		 int *ianz;
2600 		 int *iaton;
2601 		 int *iatclr;
2602 		 int *iresid;
2603 		 int *ixp;
2604 		 int *iyp;
2605 		 int *iconn;
2606 		 int *inat;
2607 		 short int *ityp;
2608 		 short int *ipdbt;
2609 		 int *mxnat;
2610 		 int *iatoms;
2611 		 int *ncont;
2612 		 int mxorg;
2613                } COOSTRU;
2614 
2615 static COOSTRU xyz;
2616 static COOSTRU TMPxyz;
2617 static COOSTRU DCKxyz;
2618 static int ndocka;
2619 static int MapConformers;
2620 static COOSTRU *xyzp = &xyz;
2621 static double *COOt = NULL;
2622 
2623 void FreeCoo(COOSTRU txyz);
2624 void Compress_Tri_L();
2625 /* static dimension density coordinates*/
2626 
2627 
2628 typedef struct { double xyz[NUMATM][3];
2629 	} XYZSTRU;
2630 static XYZSTRU *XYZ;
2631 
2632 typedef struct {
2633 		int natoms;
2634 		int norbs;
2635 		int nelecs;
2636 		int nat[NUMATM];
2637 	} NATSTRU;
2638 static NATSTRU *NAT;
2639 
2640 typedef struct { double dipo[3];
2641 		 int ihasq;
2642 		 int ihsdp;
2643 		 int iqon;
2644 		 int idipon;
2645                } CHGDIP;
2646 
2647 static CHGDIP *qdpptr;
2648 
2649 #define MXEL 100
2650 
2651 
2652 
2653 typedef struct {
2654 	char *str;
2655 	int *line_index;
2656 	int size;
2657 	int nlines;
2658 	int nfiles;
2659 	int currl; } FILEOP;
2660 
2661 #define MAXSTRUCT 100
2662 typedef struct { COOSTRU coo;
2663 		 CALFSTRU calf;
2664 		 CLFSTRU clfstr;
2665 		 ALNSTRU alnstr;
2666 		 ROTSTRU rot;
2667 		 POSSTRU pos;
2668 		 SCALSTRU scal;
2669 		 CELLSTRU cell;
2670 		 CELLSTRUC cellpnt;
2671 		 CNVSTRU cnv;
2672 		 GEO1STRU geo;
2673 		 GEOPSTRU geop;
2674 		 POISTRU poi;
2675 		 XYZSTRU XYZ;
2676 		 NATSTRU NAT;
2677 		 ZMSTRU zmt;
2678 		 QBOXSTRU *IANZbox;
2679 		 QBOXSTRU *BLbox;
2680 		 QBOXSTRU *ALPHbox;
2681 		 QBOXSTRU *BETbox;
2682 		 QBOXSTRU *IZbox;
2683 		 STOCSTRU stoc;
2684 		 DORBSTRU dorb;
2685 		 ORBSTRU orb;
2686 		 BASSTRU bas;
2687 		 GAUSTRU gau;
2688 		 MOPSTRU mop;
2689 		 FRQSTRU frq;
2690 		 PSEUDSTRU pseud;
2691 		 PLANESTRU plane;
2692 		 EULSTRU eul;
2693 		 PROJSTRU proj;
2694 		 MFSTRU mfdata;
2695 		 POTSTRU potcom;
2696 		 ZMPARTSTRU zmpart;
2697 		 JOBSTRU jobcom;
2698 		 CHGDIP qdpptr;
2699 		 HSRFSTRU hlpsrf;
2700 		 HETLABSTRU hetlab;
2701 		 NMRSTRU nmr;
2702 		 PBCSTRUC pbc;
2703 		 double *jcoupl;
2704 		 sttrr strx;
2705 		 int ipoints;
2706 		 HETATMSTRU  hetatm;
2707 		 char *frsym[MAXFRQ];
2708 		 char **mlftit;
2709 		 int ntits;
2710 		 int mxtits;
2711 		 SVGFSTRUC *svgs;
2712 		 BckSVG bcksvg;
2713 		 int svgdone;
2714 		 char *fname;
2715 		 char *pdbcode;
2716 		 int iatoms;
2717 		 int mxnat;
2718 		 int pdb;
2719 		 int backb;
2720 		 int iftyp;
2721 		 int natorg;
2722 		 int nz;
2723 		 int ihaszm;
2724 		 int mxzat;
2725 		 int ncols;
2726 		 int ncolb;
2727 		 int nocc;
2728 		 int nocb;
2729 		 int naorbs;
2730 		 int mxorb;
2731 		 int uhf;
2732 		 int spd;
2733 		 int ipsi;
2734 		 int inact;
2735 		 int inaf;
2736 		 int atcol;
2737 		 int ZMEAA;
2738 		 int doesp;
2739 		 int fftyp;
2740 		 int irtcel;
2741 		 int normc;
2742 		 int icst;
2743 		 int ibox;
2744 		 int igfmap;
2745 		 int iresrd;
2746 		 int fancy;
2747 		 int ihasex;
2748 		 double uscl;
2749 		 double adjus;
2750 		 int ihasmf;
2751 		 FILEOP memfil;
2752                } STRUSTRU;
2753 
2754 static STRUSTRU *COO[MAXSTRUCT] = {NULL};
2755 static char  *strfiles[MAXSTRUCT];
2756 
2757 static int nstruct = 0;
2758 static int istruct = 0;
2759 static int sstruct = 0;
2760 
2761 static int *multstruct;
2762 
2763 static FILEOP fileop = {NULL, NULL, 0, 0, 0, 0};
2764 typedef struct { float vert[3]; int type;} VRTSTRU;
2765 
2766 double dst_coo(COOSTRU *xyzp1,COOSTRU *xyzp2,int nato1,int nato2);
2767 
2768 #ifdef DOGL
2769 #define MAXSURF 500
2770 #else
2771 #define MAXSURF 15
2772 #endif
2773 
2774 static int SSon[MAXSTRUCT][MAXSURF];
2775 static int SStyp[MAXSTRUCT][MAXSURF];
2776 static int Schain[MAXSTRUCT][MAXSURF];
2777 static int clp[MAXSTRUCT][MAXSURF];
2778 static int trns[MAXSTRUCT][MAXSURF];
2779 static int SSdone[MAXSTRUCT];
2780 static int NSurf[MAXSTRUCT];
2781 static int NMols[MAXSTRUCT];
2782 static int CMols[MAXSTRUCT];
2783 static double scl[MAXSTRUCT];
2784 static char *sndstr[MAXSTRUCT][MAXSURF];
2785 static int nwater[MAXSTRUCT];
2786 static double *watcoo[MAXSTRUCT];
2787 static int *watanz[MAXSTRUCT];
2788 static int *watres[MAXSTRUCT];
2789 static int *watcon[MAXSTRUCT];
2790 static int *watmap[MAXSTRUCT];
2791 static double *watqat[MAXSTRUCT];
2792 static short int *wattyp[MAXSTRUCT];
2793 
2794 #define MXVERT 5000
2795 #define MXVERT2 10000
2796 #define MXVERT3 100000
2797 #define MXVERT4 200000
2798 #define MXVERT5 300000
2799 #define MXVERT6 400000
2800 #define MXVERT7 500000
2801 #define MXVERT8 1000000
2802 #define MXVERT9 2000000
2803 #define MXVERT10 3000000
2804 #define MXVERT11 4000000
2805 #define MXVERT12 5000000
2806 static int dovrt = 1;
2807 static VRTSTRU *srfvert[MAXSTRUCT][MAXSURF];
2808 static int nvert[MAXSTRUCT][MAXSURF];
2809 static int nvrtmx[MAXSTRUCT][MAXSURF];
2810 
2811 static float diffuseColor[MAXSTRUCT][MAXSURF][4];
2812 static float diffColor[MAXSURF][4] =
2813 {
2814   {0.15,0.15,1.0,0.8},
2815   {1.0 ,0.1 ,0.1,0.8},
2816   {1.0,1.0,0.0,0.8},
2817   {1.0,0.5,0.5,0.8},
2818   {1.0,0.5,0.5,0.8},
2819   {1.0,0.5,0.5,0.8},
2820   {1.0,0.5,0.5,0.8},
2821   {1.0,0.5,0.5,0.8},
2822   {1.0,0.5,0.5,0.8},
2823   {1.0,0.5,0.5,0.8},
2824   {1.0,1.0,1.0,0.8},
2825   {1.0,0.5,0.5,0.8},
2826   {1.0,0.5,0.5,0.8},
2827   {1.0,0.5,0.5,0.8},
2828   {1.0,0.5,0.5,0.8}
2829 };
2830 
2831 static float ambientColor[4] = {0.1,0.1,0.1,0.1};
2832 static float ambientDColor[4] = {0.2,0.2,0.2,0.2};
2833 static float specColor[4] = {0.8,0.8,0.8,1.0};
2834 static float specularColor[MAXSURF][4] =
2835          { {0.8,0.8,0.8,1.0} , {0.8,0.8,0.8,1.0}, {0.9,0.8,0.8,1.0},
2836            {0.8,0.8,0.8,1.0} , {0.8,0.8,0.8,1.0}, {0.9,0.8,0.8,1.0},
2837            {0.8,0.8,0.8,1.0} , {0.8,0.8,0.8,1.0}, {0.9,0.8,0.8,1.0},
2838            {0.8,0.8,0.8,1.0} , {0.8,0.8,0.8,1.0}, {0.9,0.8,0.8,1.0},
2839 };
2840 
2841 typedef struct {int nhelx;
2842 		int nbeta;
2843 		int nrna;
2844 		int ncoil;
2845 		int start[4];
2846 		int end[4];
2847 	} RIBIND;
2848 
2849 static RIBIND RIBindex[MAXSTRUCT];
2850 
2851 #define NHETRES -4
2852 static char *fragments[] = {"Read","-CH3","-CH=CH2","-HC=O","-COOH","-NH2","-OH","-CHCH","-CycloHexane","-Phenyl","-CycloPentane","-Pyrrole","-Cl","-Br","-I","-OCH3","-SH","-NO2","CH4","Period. Chain","Amino Acid","Sequence"};
2853 static int nfrag = 22;
2854 static char *fragmnts[] = {"-CH3","-CH=CH2","-HC=O","-COOH","-NH2","-OH","-CHCH","-CycloHexane","-Phenyl","-CycloPentane","-Pyrrole","-Cl","-Br","-I","-OCH3","-SH","-NO2","CH4","ACE","FOR","NME","NH2"};
2855 static int nfrags = 18;
2856 static char *Periodic[] = {"Translation","Screw Axis"};
2857 static char *ChainLength[] = {"1","2","3","4","5","6","7","8","9","10"};
2858 static char *AminoAcids[] = {"GLY","ALA","SER","CYS","THR","ILE","VAL","MET",
2859 "ASP","ASN","LEU","LYS","GLU","GLN","PRO","ARG","HIS","PHE","TYR","TRP",
2860 "ASX","GLX","HYP","A","C","G","T","U","1MA","5MC","OMC","1MG","2MG","M2G",
2861 "7MG","OMG","YG","I","+U","H2U","5MU","PSU"};
2862 static char *AAlet[] = {"G","A","S","C","T","I","V","M","D","N","L","K","E",
2863 "Q","P","R","H","F","Y","W","?","?","?","A","C","G","T","U","?","?","?","?","?","?","?","?","?","I","?","?","?","?"};
2864 static int NAminos = 20;
2865 static char *AminoCaps[] = {"GLY","ALA","SER","CYS","THR","ILE","VAL","MET",
2866 "ASP","ASN","LEU","LYS","GLU","GLN","PRO","ARG","HIS","PHE","TYR","TRP",
2867 "ACE","FOR","NME","NH2"};
2868 static char *AmiOpt[] = {"Add","Delete","Insert","Replace"};
2869 static char *HetOpt[] = {"Center","Label On/OFF","Contacts","Contacts+Surf","Calculate Charges","Delete Molecule","Mol.->Structure","Add Hydrogens","Color","Add to Surface"};
2870 static char *HisOpt[] = {"HIP","HID","HIE"};
2871 static char *AmiBOpt[] = {"Switch On/Off","Select Range","Label On/Off","Center","Contacts","Contacts+Surf","Add to Surface","Rotamer","Fit Rotamer","Best Rotamer","Change Rot. Libr.","Add to Flex. Resid.","Delete","Insert","Replace","Cap Residue","Add"};
2872 static char *AmiNQOpt[] = {"Switch On/Off","Select Range","Label On/Off","Center","Contacts","Flip","Contacts+Surf","Add to Surface","Rotamer","Fit Rotamer","Best Rotamer","Change Rot. Libr.","Add to Flex. Resid.","Delete","Insert","Replace","Cap Residue","Add"};
2873 static char *AmiHOpt[] = {"Switch On/Off","Select Range","Label On/Off","Center","Contacts","Prot. State","Contacts+Surf","Add to Surface","Rotamer","Fit Rotamer","Best Rotamer","Change Rot. Libr.","Add to Flex. Resid.","Delete","Insert","Replace","Cap Residue","Add"};
2874 static char *AmiBOptS[] = {"Switch On/Off","Select Range","Label On/Off","Center","Contacts","Rotamer","Fit Rotamer","Best Rotamer","Change Rot. Libr.","Add to Flex. Resid.","Delete","Insert","Replace","Cap Residue","Add"};
2875 static char *AmiNQOptS[] = {"Switch On/Off","Select Range","Label On/Off","Center","Contacts","Flip","Rotamer","Fit Rotamer","Best Rotamer","Change Rot. Libr.","Add to Flex. Resid.","Delete","Insert","Replace","Cap Residue","Add"};
2876 static char *AmiHOptS[] = {"Switch On/Off","Select Range","Label On/Off","Center","Contacts","Prot. State","Rotamer","Fit Rotamer","Best Rotamer","Change Rot. Libr.","Add to Flex. Resid.","Delete","Insert","Replace","Cap Residue","Add"};
2877 static char *Rotamers[] = {
2878 "Rotamer1","Rotamer2","Rotamer3","Rotamer4","Rotamer5","Rotamer6","Rotamer7",
2879 "Rotamer8","Rotamer9","Rotamer10", "Rotamer11","Rotamer12","Rotamer13","Rotamer14",
2880 "Rotamer15","Rotamer16","Rotamer17","Rotamer18","Rotamer19","Rotamer20","Rotamer21",
2881 "Rotamer22","Rotamer23","Rotamer24","Rotamer25","Rotamer26","Rotamer27","Rotamer28",
2882 "Rotamer29","Rotamer30","Rotamer31","Rotamer32","Rotamer33","Rotamer34","Rotamer35",
2883 "Rotamer36","Rotamer37","Rotamer38","Rotamer39","Rotamer40","Rotamer41","Rotamer42",
2884 "Rotamer43","Rotamer44","Rotamer45","Rotamer46","Rotamer47","Rotamer48","Rotamer49",
2885 "Rotamer50","Rotamer51","Rotamer52","Rotamer53","Rotamer54","Rotamer55","Rotamer56",
2886 "Rotamer57","Rotamer58","Rotamer59","Rotamer60","Rotamer61","Rotamer62","Rotamer63",
2887 "Rotamer64","Rotamer65","Rotamer66","Rotamer67","Rotamer68","Rotamer69","Rotamer70",
2888 "Rotamer71","Rotamer72","Rotamer73","Rotamer74","Rotamer75","Rotamer76","Rotamer77",
2889 "Rotamer78","Rotamer79","Rotamer80","Rotamer81"
2890 };
2891 static char *RotLib[] = {"Richardson","Dunbrack"};
2892 #define MAXSEQ 1000
2893 static int Sequence[MAXSEQ];
2894 static int NSeq = 0;
2895 static char SeqStat[64] = " ";
2896 static int LastAmino = -1;
2897 static int InsertAmino = -1;
2898 static int ReplaceAmino = 0;
2899 static int CurAmino = -1;
2900 static int DisAmino = -1;
2901 static int DisDir = 0;
2902 static int DisHlp = 1;
2903 #define MXEXP 20
2904 static int oque[MXEXP] = {MXEXP*0};
2905 static int oqlen = 0;
2906 static int oqpos = 0;
2907 
2908 static char *Chains[] = {
2909 "Chain1","Chain2","Chain3","Chain4","Chain5","Chain6","Chain7",
2910 "Chain8","Chain9","Chain10", "Chain11","Chain12","Chain13","Chain14",
2911 "Chain15","Chain16","Chain17","Chain18","Chain19","Chain20"};
2912 
2913 static char *Processors[] = {
2914 	" 1"," 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10",
2915 	"11","12","13","14","15","16","17","18","19","20",
2916 	"21","22","23","24","25","26","27","28","29","30",
2917 	"31","32","33","34","35","36","37","38","39","40",
2918 	"41","42","43","44","45","46","47","48","49","50"};
2919 #define BENZLEN 11
2920 #define CCBENZ 1.40
2921 #define CHBENZ 1.089
2922 
2923 static ZLINESTRU benzyl[BENZLEN] = { {6,{0,0,0,0},0.0,0.0,0.0},
2924 				{6,{1,0,0,0},CCBENZ,0.0,0.0},
2925 				{6,{2,1,0,0},CCBENZ,120.0,0.0},
2926 				{6,{3,2,1,0},CCBENZ,120.0,0.0},
2927 				{6,{4,3,2,0},CCBENZ,120.0,0.0},
2928 				{6,{5,4,3,0},CCBENZ,120.0,0.0},
2929 				{1,{2,1,3,0},CHBENZ,120.0,180.0},
2930 				{1,{3,2,4,0},CHBENZ,120.0,180.0},
2931 				{1,{4,3,5,0},CHBENZ,120.0,180.0},
2932 				{1,{5,4,3,0},CHBENZ,120.0,180.0},
2933 				{1,{6,5,4,0},CHBENZ,120.0,180.0}
2934 				};
2935 
2936 #define PENT 14
2937 #define CCPENT 1.546
2938 #define CHPENT 1.103
2939 static ZLINESTRU cyclopentane[PENT] = { {6,{0,0,0,0},0.0,0.0,0.0},
2940 				{6,{1,0,0,0},CCPENT,0.0,0.0},
2941 				{6,{2,1,0,0},CCPENT,102.5,0.0},
2942 				{6,{3,2,1,0},CCPENT,102.5,45.42},
2943 				{6,{4,3,2,0},CCPENT,102.5,-36.20},
2944 				{1,{2,3,4,0},CHPENT,109.47,-71.2},
2945 				{1,{2,3,4,0},CHPENT,109.47,167.0},
2946 				{1,{3,2,1,0},CHPENT,109.47,-71.2},
2947 				{1,{3,2,1,0},CHPENT,109.47,167.0},
2948 				{1,{4,3,2,0},CHPENT,109.47,-160.0},
2949 				{1,{4,3,2,0},CHPENT,109.47,80.9},
2950 				{1,{5,4,3,0},CHPENT,109.47,-106.8},
2951 				{1,{5,4,3,0},CHPENT,109.47,133.2},
2952 				{1,{1,2,3,0},CHPENT,109.47,80.9}
2953 				};
2954 
2955 #define PYRROLE 9
2956 #define CHPYRR 1.090
2957 static ZLINESTRU pyrrole[PYRROLE] = { {7,{0,0,0,0},0.0,0.0,0.0},
2958 				{6,{1,0,0,0},1.301,0.0,0.0},
2959 				{6,{2,1,0,0},1.335,107.6,0.0},
2960 				{6,{3,2,1,0},1.469,105.5,0.0},
2961 				{6,{1,2,3,0},1.301,113.9,0.0},
2962 				{1,{5,1,2,0},CHPYRR,126.6,180.0},
2963 				{1,{4,3,2,0},CHPYRR,127.3,180.0},
2964 				{1,{3,2,1,0},CHPYRR,127.3,180.0},
2965 				{1,{2,1,5,0},CHPYRR,126.6,180.0},
2966 				};
2967 
2968 static ZLINESTRU CHCH2[5] =   { {6,{0,0,0,0},0.0,0.0,0.0},
2969 				{6,{1,0,0,0},1.335,0.0,0.0},
2970 				{1,{1,2,0,0},1.089,120.0,0.0},
2971 				{1,{2,1,3,0},1.089,120.0,0.0},
2972 				{1,{2,1,3,0},1.089,120.0,180.0}
2973 				};
2974 
2975 static ZLINESTRU COOH[4] =   {  {6,{0,0,0,0},0.0,0.0,0.0},
2976 				{8,{1,0,0,0},1.400,0.0,0.0},
2977 				{8,{1,2,0,0},1.220,120.0,0.0},
2978 				{1,{2,1,3,0},0.950,109.471,0.0}
2979 				};
2980 
2981 static ZLINESTRU CHO[3] =   {   {6,{0,0,0,0},0.0,0.0,0.0},
2982 				{8,{1,0,0,0},1.220,0.0,0.0},
2983 				{1,{1,2,0,0},1.089,120.0,0.0}
2984 				};
2985 
2986 static ZLINESTRU OH[2] =    {   {8,{0,0,0,0},0.0,0.0,0.0},
2987 				{1,{1,0,0,0},0.947,0.0,0.0}
2988 				};
2989 
2990 static ZLINESTRU CHCH[5] =   {  {6,{0,0,0,0},0.0,0.0,0.0},
2991 				{99,{1,0,0,0},1.0,0.0,0.0},
2992 				{6,{1,2,0,0},1.189,90.0,0.0},
2993 				{99,{3,1,2,0},1.0,90.0,0.0},
2994 				{1,{3,4,1,0},1.051,90.0,180.0}
2995 				};
2996 
2997 static ZLINESTRU CL[1] =    {   {17,{0,0,0,0},0.0,0.0,0.0}
2998 				};
2999 
3000 static ZLINESTRU BR[1] =    {   {35,{0,0,0,0},0.0,0.0,0.0}
3001 				};
3002 
3003 static ZLINESTRU I[1] =    {   {53,{0,0,0,0},0.0,0.0,0.0}
3004 				};
3005 
3006 static ZLINESTRU OCH3[5] =   {  {8,{0,0,0,0},0.0,0.0,0.0},
3007 				{6,{1,0,0,0},1.400,0.0,0.0},
3008 				{1,{2,1,0,0},1.089,109.471,0.0},
3009 				{1,{2,1,3,0},1.089,109.471,120.0},
3010 				{1,{2,1,3,0},1.089,109.471,-120.0}
3011 				};
3012 
3013 static ZLINESTRU SH[2] =    {   {16,{0,0,0,0},0.0,0.0,0.0},
3014 				{1,{1,0,0,0},0.947,0.0,0.0}
3015 				};
3016 
3017 static ZLINESTRU NO2[3] =   {   {7,{0,0,0,0},0.0,0.0,0.0},
3018 				{8,{1,0,0,0},1.210,0.0,0.0},
3019 				{8,{1,2,0,0},1.210,125.25,0.0}
3020 				};
3021 
3022 static ZLINESTRU NH2[3] =   {   {7,{0,0,0,0},0.0,0.0,0.0},
3023 				{1,{1,0,0,0},1.010,0.0,0.0},
3024 				{1,{1,2,0,0},1.010,120.0,0.0}
3025 				};
3026 
3027 static ZLINESTRU CH4[5] =   {   {6,{0,0,0,0},0.0,0.0,0.0},
3028 				{1,{1,0,0,0},1.089,0.0,0.0},
3029 				{1,{1,2,0,0},1.089,109.471,0.0},
3030 				{1,{1,2,3,0},1.089,109.471,120.0},
3031 				{1,{1,2,3,0},1.089,109.471,-120.0}
3032 				};
3033 
3034 static ZLINESTRU SCREW[2] = {	{99,{0,0,0,0},0.0,0.0,0.0},
3035 				{99,{1,0,0,0},10.0,0.0,0.0}
3036 				};
3037 
3038 static ZLINESTRU BACK[6] = {	{7,{0,0,0,0},0.0,0.0,0.0},
3039 				{6,{1,0,0,0},1.460,0.0,0.0},
3040 				{6,{2,1,0,0},1.510,111.6,0.0},
3041 				{8,{3,2,1,0},1.220,121.0,113.0},
3042 				{8,{3,2,4,0},1.220,122.5,180.0},
3043 				{1,{1,2,3,0},1.020,121.0,61.0}
3044 			    };
3045 
3046 static short int BACK_TYP[5] = { 2,3,38,4,1};
3047 
3048 static ZLINESTRU BACKHS[2] = {  {1,{1,2,6,0},1.020,107.9,120.0},
3049 				{1,{1,2,6,0},1.020,107.9,-120.0}
3050 			     };
3051 
3052 static short int BACKHS_TYP[2] = {2,3};
3053 
3054 typedef struct { double rots[4]; double ener[1];} ROTSSTRU;
3055 
3056 static ZLINESTRU GLY[2] = {     {1,{2,3,1,0},1.100,109.3,121.6},
3057 				{1,{2,3,1,0},1.100,109.3,-121.6}
3058 			   };
3059 static short int GLY_TYP[2] = { 4,5};
3060 static int GLY_CHI[4] = {-1,-1,-1,-1};
3061 static ROTSSTRU GLY_ROT[1] = {
3062 				{ 0.0, 0.0, 0.0, 0.0, 0.0}
3063 				};
3064 
3065 
3066 static ZLINESTRU ALA[5] = {     {6,{2,3,1,0},1.536,110.1,122.910},
3067 				{1,{2,3,1,0},1.100,108.234,-118.193},
3068 				{1,{7,2,3,0},1.100,110.3,179.999},
3069 				{1,{7,2,3,0},1.100,110.3,60.0},
3070 				{1,{7,2,3,0},1.100,110.3,-60.326}
3071 			   };
3072 static short int ALA_TYP[5] = { 5,4,7,8,9};
3073 static int ALA_CHI[4] = {-1,-1,-1,-1};
3074 static ROTSSTRU ALA_ROT[1] = {
3075 				{ 0.0, 0.0, 0.0, 0.0, 0.0}
3076 				};
3077 
3078 
3079 static ZLINESTRU SER[6] = {     {6,{2,3,1,0},1.530,110.1,122.8},
3080 				{8,{7,2,1,0},1.417,111.1,62.0},
3081 				{1,{2,3,1,0},1.100,108.2,-118.2},
3082 				{1,{7,2,8,0},1.100,108.8,-121.8},
3083 				{1,{7,2,8,0},1.100,108.8,121.8},
3084 				{1,{8,7,2,0},1.000,109.5,180.0}
3085 			   };
3086 static short int SER_TYP[6] = { 5,31,4,7,8,10 };
3087 static int SER_CHI[4] = {2,6,-1,-1};
3088 static ROTSSTRU SER_ROT[3] = {
3089 				{  62.0, 180.0, 0.0, 0.0, 0.00},
3090 				{-177.0, 180.0, 0.0, 0.0, 0.47},
3091 				{ -65.0, 180.0, 0.0, 0.0, 0.77}
3092 				};
3093 
3094 static ROTSSTRU SER_ROTD[3] = {
3095 				{  65.3, 180.0, 0.0, 0.0, 0.00},
3096 				{ 179.0, 180.0, 0.0, 0.0, 0.41},
3097 				{ -63.9, 180.0, 0.0, 0.0, 0.28}
3098 				};
3099 
3100 
3101 static ZLINESTRU CYS[6] = {     {6,{2,3,1,0},1.530,110.1,122.8},
3102 				{16,{7,2,1,0},1.822,114.4,-65.0},
3103 				{1,{2,3,1,0},1.100,108.2,-118.2},
3104 				{1,{7,2,8,0},1.100,108.8,-121.8},
3105 				{1,{7,2,8,0},1.100,108.8,121.8},
3106 				{1,{8,7,2,0},1.300,109.5,0.0}
3107 			   };
3108 static short int CYS_TYP[6] = { 5,37,4,7,8,10 };
3109 static int CYS_CHI[4] = {2,6,-1,-1};
3110 static ROTSSTRU CYS_ROT[3] = {
3111 				{  62.0,  0.0, 0.0, 0.0, 0.47},
3112 				{-177.0,  0.0, 0.0, 0.0, 0.39},
3113 				{ -65.0,  0.0, 0.0, 0.0, 0.00}
3114 				};
3115 
3116 static ROTSSTRU CYS_ROTD[3] = {
3117 				{  63.7,  0.0, 0.0, 0.0, 0.75},
3118 				{-177.3,  0.0, 0.0, 0.0, 0.43},
3119 				{ -64.3,  0.0, 0.0, 0.0, 0.00}
3120 				};
3121 
3122 
3123 static ZLINESTRU THR[9] = {     {6,{2,3,1,0},1.540,109.1,123.4},
3124 				{8,{7,2,1,0},1.433,109.6,62.0},
3125 				{6,{7,2,8,0},1.521,110.5,-120.0},
3126 				{1,{2,3,1,0},1.100,108.2,-118.2},
3127 				{1,{7,2,8,0},1.100,108.5,120.2},
3128 				{1,{8,7,2,0},1.000,109.5,60.0},
3129 				{1,{9,7,2,0},1.100,109.5,180.0},
3130 				{1,{9,7,13,0},1.100,109.5,120.0},
3131 				{1,{9,7,13,0},1.100,109.5,-120.0}
3132 			   };
3133 static short int THR_TYP[9] = { 5,32,8,4,7,13,16,17,18};
3134 static int THR_CHI[4] = {2,6,-1,-1};
3135 static ROTSSTRU THR_ROT[3] = {
3136 				{  62.0,  60.0, 0.0, 0.0, 0.00},
3137 				{-175.0,  60.0, 0.0, 0.0, 1.16},
3138 				{ -65.0,  60.0, 0.0, 0.0, 0.07}
3139 				};
3140 
3141 static ROTSSTRU THR_ROTD[3] = {
3142 				{  61.1,  60.0, 0.0, 0.0, 0.00},
3143 				{-173.3,  60.0, 0.0, 0.0, 1.11},
3144 				{ -60.4,  60.0, 0.0, 0.0, 0.07}
3145 				};
3146 
3147 
3148 static ZLINESTRU ILE[14] = {    {6,{2,3,1,0},1.540,109.1,123.4},
3149 				{6,{7,2,1,0},1.530,110.4,-65.0},
3150 				{6,{7,2,8,0},1.521,110.5,-120.0},
3151 				{6,{8,7,2,0},1.512,113.8,170.0},
3152 				{1,{2,3,1,0},1.100,108.2,-118.2},
3153 				{1,{7,2,8,0},1.100,107.8,120.0},
3154 				{1,{8,7,10,0},1.100,109.0,121.8},
3155 				{1,{8,7,10,0},1.100,109.0,-121.8},
3156 				{1,{9,7,2,0}, 1.100,109.5,180.0},
3157 				{1,{9,7,15,0},1.100,109.5,120.0},
3158 				{1,{9,7,15,0},1.100,109.5,-120.0},
3159 				{1,{10,8,7,0},1.100,109.5,180.0},
3160 				{1,{10,8,18,0},1.100,109.5,120.0},
3161 				{1,{10,8,18,0},1.100,109.5,-120.0}
3162 			   };
3163 static short int ILE_TYP[14] = { 5,7,8,10,4,7,13,14,16,17,18,22,23,24 };
3164 static int ILE_CHI[4] = {2,4,-1,-1};
3165 static ROTSSTRU ILE_ROT[7] = {
3166 				{  62.0, 100.0, 0.0, 0.0, 2.72},
3167 				{  62.0, 170.0, 0.0, 0.0, 0.90},
3168 				{-177.0,  66.0, 0.0, 0.0, 1.97},
3169 				{-177.0, 165.0, 0.0, 0.0, 1.22},
3170 				{ -65.0, 100.0, 0.0, 0.0, 2.34},
3171 				{ -65.0, 170.0, 0.0, 0.0, 0.00},
3172 				{ -57.0, -60.0, 0.0, 0.0, 0.84}
3173 				};
3174 
3175 static ROTSSTRU ILE_ROTD[9] = {
3176 				{  60.6,  85.4, 0.0, 0.0, 2.78},
3177 				{  61.1, 171.0, 0.0, 0.0, 0.97},
3178 				{  61.7, -80.0, 0.0, 0.0, 4.11},
3179 				{-167.9,  66.8, 0.0, 0.0, 1.86},
3180 				{-171.4, 167.4, 0.0, 0.0, 1.36},
3181 				{-165.5, -78.0, 0.0, 0.0, 3.76},
3182 				{ -67.1,  83.0, 0.0, 0.0, 2.30},
3183 				{ -63.8, 170.1, 0.0, 0.0, 0.00},
3184 				{ -59.2, -61.0, 0.0, 0.0, 0.81}
3185 				};
3186 
3187 
3188 static ZLINESTRU VAL[11] = {    {6,{2,3,1,0},1.540,109.1,123.4},
3189 				{6,{7,2,1,0},1.521,110.5,-65.0},
3190 				{6,{7,2,8,0},1.521,110.5,-120.0},
3191 				{1,{2,3,1,0},1.100,108.2,-118.2},
3192 				{1,{7,2,8,0},1.100,107.7,120.0},
3193 				{1,{8,7,2,0},1.100,109.5,180.0},
3194 				{1,{8,7,12,0},1.100,109.5,120.0},
3195 				{1,{8,7,12,0},1.100,109.5,-120.0},
3196 				{1,{9,7,8,0}, 1.100,109.5,180.0},
3197 				{1,{9,7,15,0},1.100,109.5,120.0},
3198 				{1,{9,7,15,0},1.100,109.5,-120.0}
3199 			   };
3200 static short int VAL_TYP[11] = { 5,7,8,4,7,13,14,15,16,17,18};
3201 static int VAL_CHI[4] = {2,-1,-1,-1};
3202 static ROTSSTRU VAL_ROT[3] = {
3203 				{  63.0, 0.0, 0.0, 0.0, 1.44},
3204 				{ 175.0, 0.0, 0.0, 0.0, 0.00},
3205 				{ -60.0, 0.0, 0.0, 0.0, 0.77}
3206 				};
3207 
3208 static ROTSSTRU VAL_ROTD[3] = {
3209 				{  65.5, 0.0, 0.0, 0.0, 1.36},
3210 				{ 175.9, 0.0, 0.0, 0.0, 0.00},
3211 				{ -61.7, 0.0, 0.0, 0.0, 0.81}
3212 				};
3213 
3214 
3215 static ZLINESTRU MET[12] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3216 				{6,{7,2,1,0},1.520,114.1,-65.0},
3217 				{16,{8,7,2,0},1.801,112.8,-65.0},
3218 				{6,{9,8,7,0},1.791,100.9,-70.0},
3219 				{1,{2,3,1,0},1.100,108.2,-118.2},
3220 				{1,{7,2,8,0},1.100,109.4,108.9},
3221 				{1,{7,2,8,0},1.100,109.4,-108.9},
3222 				{1,{8,7,9,0},1.100,109.2,121.6},
3223 				{1,{8,7,9,0},1.100,109.2,-121.6},
3224 				{1,{10,9,8,0}, 1.100,109.5,180.0},
3225 				{1,{10,9,16,0},1.100,109.5,120.0},
3226 				{1,{10,9,16,0},1.100,109.5,-120.0}
3227 			   };
3228 static short int MET_TYP[12] = { 5,6,36,12,4,7,8,10,11,28,29,30};
3229 static int MET_CHI[4] = {2,3,4,-1};
3230 static ROTSSTRU MET_ROT[13] = {
3231 				{  62.0, 180.0,  75.0, 0.0, 1.28},
3232 				{  62.0, 180.0, -75.0, 0.0, 1.08},
3233 				{-177.0,  65.0,  75.0, 0.0, 0.74},
3234 				{-177.0,  65.0, 180.0, 0.0, 1.46},
3235 				{-177.0, 180.0,  75.0, 0.0, 0.78},
3236 				{-177.0, 180.0, 180.0, 0.0, 1.08},
3237 				{-177.0, 180.0, -75.0, 0.0, 0.63},
3238 				{ -67.0, 180.0,  75.0, 0.0, 0.07},
3239 				{ -67.0, 180.0, 180.0, 0.0, 0.53},
3240 				{ -67.0, 180.0, -75.0, 0.0, 0.35},
3241 				{ -65.0, -65.0, 103.0, 0.0, 1.15},
3242 				{ -65.0, -65.0, 180.0, 0.0, 1.39},
3243 				{ -65.0, -65.0, -70.0, 0.0, 0.00}
3244 				};
3245 
3246 static ROTSSTRU MET_ROTD[27] = {
3247 				{  60.8,   78.3,   73.3, 0.0, 2.33},
3248 				{  57.6,   78.1,  177.7, 0.0, 2.60},
3249 				{  59.4,   77.8,  -97.4, 0.0, 9.99},
3250 				{  64.4, -178.3,   76.1, 0.0, 1.20},
3251 				{  64.9, -176.0, -175.0, 0.0, 1.53},
3252 				{  63.4,  179.1,  -71.8, 0.0, 1.17},
3253 				{  72.5,  -70.1,   99.6, 0.0, 9.99},
3254 				{  72.2,  -70.4,  174.3, 0.0, 3.75},
3255 				{  72.6,  -72.0,  -71.4, 0.0, 2.69},
3256 				{-176.0,   64.0,   72.5, 0.0, 0.58},
3257 				{-174.5,   69.3, -166.1, 0.0, 1.42},
3258 				{-172.4,   76.6,  -96.9, 0.0, 1.76},
3259 				{-177.8,  179.2,   72.1, 0.0, 0.59},
3260 				{-177.4,  174.6,  177.3, 0.0, 0.99},
3261 				{-174.6,  179.7,  -71.6, 0.0, 0.52},
3262 				{-178.7,  -73.7,   99.6, 0.0, 9.99},
3263 				{-178.2,  -78.4,  173.0, 0.0, 2.39},
3264 				{-178.8,  -82.3,  -73.4, 0.0, 1.41},
3265 				{ -78.6,   67.3,   73.0, 0.0, 2.08},
3266 				{ -78.9,   69.3, -175.6, 0.0, 2.69},
3267 				{ -77.7,   70.6,  -98.9, 0.0, 3.34},
3268 				{ -67.4,  178.0,   70.4, 0.0, 0.06},
3269 				{ -67.3,  179.2, -177.6, 0.0, 0.39},
3270 				{ -67.7, -176.3,  -73.7, 0.0, 0.30},
3271 				{ -65.8,  -64.9,   99.6, 0.0, 1.04},
3272 				{ -62.7,  -64.0,  171.9, 0.0, 1.02},
3273 				{ -65.8,  -61.8,  -69.4, 0.0, 0.00}
3274 				};
3275 
3276 
3277 static ZLINESTRU ASP[7] = {     {6,{2,3,1,0},1.530,110.1,122.8},
3278 				{6,{7,2,1,0},1.516,112.6,-70.0},
3279 				{8,{8,7,2,0},1.250,118.4,-15.0},
3280 				{8,{8,7,9,0},1.250,118.4,180.0},
3281 				{1,{2,3,1,0},1.100,108.2,-118.2},
3282 				{1,{7,2,8,0},1.100,109.3,121.6},
3283 				{1,{7,2,8,0},1.100,109.3,-121.6}
3284 			   };
3285 static short int ASP_TYP[7] = { 5,6,29,30,4,7,8};
3286 static int ASP_CHI[4] = {2,3,-1,-1};
3287 
3288 static ROTSSTRU ASP_ROT[5] = {
3289 				{  62.0, -10.0, 0.0, 0.0, 0.95},
3290 				{  62.0,  30.0, 0.0, 0.0, 0.98},
3291 				{-177.0,   0.0, 0.0, 0.0, 0.49},
3292 				{-177.0,  65.0, 0.0, 0.0, 1.27},
3293 				{ -70.0, -15.0, 0.0, 0.0, 0.00}
3294 				};
3295 
3296 static ROTSSTRU ASP_ROTD[9] = {
3297 				{  57.1,   54.3, 0.0, 0.0, 1.60},
3298 				{  62.5,    1.3, 0.0, 0.0, 0.61},
3299 				{  62.4,  -55.8, 0.0, 0.0, 1.30},
3300 				{-173.6,   58.5, 0.0, 0.0, 0.75},
3301 				{-172.3,   -0.8, 0.0, 0.0, 0.33},
3302 				{-167.9,  -55.7, 0.0, 0.0, 1.09},
3303 				{ -69.1,   65.0, 0.0, 0.0, 1.65},
3304 				{ -72.1,  -12.7, 0.0, 0.0, 0.00},
3305 				{ -65.4,  -49.8, 0.0, 0.0, 0.27}
3306 				};
3307 
3308 
3309 static ZLINESTRU ASN[9] = {     {6,{2,3,1,0},1.530,110.1,122.8},
3310 				{6,{7,2,1,0},1.516,112.6,-65.0},
3311 				{8,{8,7,2,0},1.230,120.8,-21.0},
3312 				{7,{8,7,9,0},1.327,116.4,180.0},
3313 				{1,{2,3,1,0},1.100,108.2,-118.2},
3314 				{1,{7,2,8,0},1.100,109.3,121.6},
3315 				{1,{7,2,8,0},1.100,109.3,-121.6},
3316 				{1,{10,8,7,0}, 1.000,120.0,0.0},
3317 				{1,{10,8,14,0},1.000,120.0,180.0}
3318 			   };
3319 static short int ASN_TYP[9] = { 5,6,29,21,4,7,8,25,26};
3320 static int ASN_CHI[4] = {2,3,-1,-1};
3321 
3322 static ROTSSTRU ASN_ROT[7] = {
3323 				{  62.0, -10.0, 0.0, 0.0, 1.02},
3324 				{  62.0,  30.0, 0.0, 0.0, 0.88},
3325 				{-174.0, -20.0, 0.0, 0.0, 0.70},
3326 				{-177.0,  30.0, 0.0, 0.0, 0.55},
3327 				{ -65.0, -20.0, 0.0, 0.0, 0.00},
3328 				{ -65.0, -75.0, 0.0, 0.0, 0.94},
3329 				{ -65.0, 120.0, 0.0, 0.0, 1.36}
3330 				};
3331 
3332 static ROTSSTRU ASN_ROTD[18] = {
3333 				{  50.3, -115.0, 0.0, 0.0, 2.98},
3334 				{  64.5,  -53.9, 0.0, 0.0, 1.41},
3335 				{  64.6,    1.5, 0.0, 0.0, 0.82},
3336 				{  60.0,   57.0, 0.0, 0.0, 1.22},
3337 				{  68.9,  101.9, 0.0, 0.0, 2.57},
3338 				{  69.3,  175.1, 0.0, 0.0, 3.76},
3339 				{-176.0, -114.6, 0.0, 0.0, 1.31},
3340 				{-173.5,  -66.3, 0.0, 0.0, 1.11},
3341 				{-170.8,  -20.2, 0.0, 0.0, 0.81},
3342 				{-169.3,   24.3, 0.0, 0.0, 0.62},
3343 				{-171.9,   60.6, 0.0, 0.0, 0.97},
3344 				{-160.3,  121.5, 0.0, 0.0, 2.49},
3345 				{ -77.3, -137.6, 0.0, 0.0, 2.27},
3346 				{ -65.7,  -63.9, 0.0, 0.0, 0.25},
3347 				{ -70.4,  -23.2, 0.0, 0.0, 0.00},
3348 				{ -79.5,   34.3, 0.0, 0.0, 1.85},
3349 				{ -77.3,   96.5, 0.0, 0.0, 1.13},
3350 				{ -64.7,  139.8, 0.0, 0.0, 1.32}
3351 				};
3352 
3353 
3354 static ZLINESTRU LEU[14] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3355 				{6,{7,2,1,0},1.530,116.3,-65.0},
3356 				{6,{8,7,2,0},1.521,110.7,174.0},
3357 				{6,{8,7,9,0},1.521,110.7,119.9},
3358 				{1,{2,3,1,0},1.100,108.2,-118.2},
3359 				{1,{7,2,8,0},1.100,108.3,122.2},
3360 				{1,{7,2,8,0},1.100,108.3,-122.2},
3361 				{1,{8,7,9,0},1.100,107.5,-120.1},
3362 				{1,{9,8,7,0}, 1.100,109.5,180.0},
3363 				{1,{9,8,15,0},1.100,109.5,120.0},
3364 				{1,{9,8,15,0},1.100,109.5,-120.0},
3365 				{1,{10,8,7,0}, 1.100,109.5,180.0},
3366 				{1,{10,8,18,0},1.100,109.5,120.0},
3367 				{1,{10,8,18,0},1.100,109.5,-120.0}
3368 			   };
3369 static short int LEU_TYP[14] = { 5,6,10,11,4,7,8,10,22,23,24,25,26,27};
3370 static int LEU_CHI[4] = {2,3,-1,-1};
3371 static ROTSSTRU LEU_ROT[5] = {
3372 				{  62.0,  80.0, 0.0, 0.0, 2.55},
3373 				{-177.0,  65.0, 0.0, 0.0, 0.43},
3374 				{-172.0, 145.0, 0.0, 0.0, 2.05},
3375 				{ -85.0,  65.0, 0.0, 0.0, 1.90},
3376 				{ -65.0, 175.0, 0.0, 0.0, 0.00}
3377 				};
3378 
3379 static ROTSSTRU LEU_ROTD[9] = {
3380 				{  58.7,  80.7, 0.0, 0.0, 2.63},
3381 				{  71.8, 164.6, 0.0, 0.0, 3.05},
3382 				{  58.2, -73.6, 0.0, 0.0, 4.69},
3383 				{-179.2,  63.0, 0.0, 0.0, 0.46},
3384 				{-164.9, 170.7, 0.0, 0.0, 1.89},
3385 				{-169.8, -73.1, 0.0, 0.0, 2.99},
3386 				{ -86.1,  54.6, 0.0, 0.0, 1.68},
3387 				{ -64.7, 174.5, 0.0, 0.0, 0.00},
3388 				{ -81.5, -55.0, 0.0, 0.0, 2.55}
3389 				};
3390 
3391 
3392 static ZLINESTRU LYS[17] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3393 				{6,{7,2,1,0},1.520,114.1,-67.0},
3394 				{6,{8,7,2,0},1.520,111.3,180.0},
3395 				{6,{9,8,7,0},1.520,111.3,180.0},
3396 				{7,{10,9,8,0},1.490,111.9,180.0},
3397 				{1,{2,3,1,0},1.100,108.2,-118.2},
3398 				{1,{7,2,8,0},1.100,108.9,121.9},
3399 				{1,{7,2,8,0},1.100,108.9,-121.9},
3400 				{1,{8,7,9,0},1.100,109.6,121.4},
3401 				{1,{8,7,9,0},1.100,109.6,-121.4},
3402 				{1,{9,8,10,0},1.100,109.6,121.4},
3403 				{1,{9,8,10,0},1.100,109.6,-121.4},
3404 				{1,{10,9,11,0},1.100,109.5,121.5},
3405 				{1,{10,9,11,0},1.100,109.5,-121.5},
3406 				{1,{11,10,9,0}, 1.000,109.5,180.0},
3407 				{1,{11,10,21,0},1.000,109.5,120.0},
3408 				{1,{11,10,21,0},1.000,109.5,-120.0}
3409 			   };
3410 static short int LYS_TYP[17] = { 5,6,9,12,27,4,7,8,10,11,19,20,28,29,40,41,42};
3411 static int LYS_CHI[4] = {2,3,4,5};
3412 static ROTSSTRU LYS_ROT[27] = {
3413 				{  62.0, 180.0,  68.0, 180.0, 2.10},
3414 				{  62.0, 180.0, 180.0,  65.0, 1.74},
3415 				{  62.0, 180.0, 180.0, 180.0, 1.21},
3416 				{  62.0, 180.0, 180.0, -65.0, 1.97},
3417 				{  62.0, 180.0, -68.0, 180.0, 2.25},
3418 				{-177.0,  68.0, 180.0,  65.0, 1.79},
3419 				{-177.0,  68.0, 180.0, 180.0, 1.15},
3420 				{-177.0,  68.0, 180.0, -65.0, 2.10},
3421 				{-177.0, 180.0,  68.0,  65.0, 1.73},
3422 				{-177.0, 180.0,  68.0, 180.0, 1.30},
3423 				{-177.0, 180.0, 180.0,  65.0, 0.90},
3424 				{-177.0, 180.0, 180.0, 180.0, 0.19},
3425 				{-177.0, 180.0, 180.0, -65.0, 1.07},
3426 				{-177.0, 180.0, -68.0, 180.0, 1.43},
3427 				{-177.0, 180.0, -68.0, -65.0, 2.25},
3428 				{ -90.0,  68.0, 180.0, 180.0, 2.38},
3429 				{ -67.0, 180.0,  68.0,  65.0, 1.73},
3430 				{ -67.0, 180.0,  68.0, 180.0, 1.05},
3431 				{ -67.0, 180.0, 180.0,  65.0, 0.99},
3432 				{ -67.0, 180.0, 180.0, 180.0, 0.00},
3433 				{ -67.0, 180.0, 180.0, -65.0, 0.82},
3434 				{ -67.0, 180.0, -68.0, 180.0, 1.02},
3435 				{ -67.0, 180.0, -68.0, -65.0, 1.73},
3436 				{ -62.0, -68.0, 180.0,  65.0, 1.90},
3437 				{ -62.0, -68.0, 180.0, 180.0, 0.63},
3438 				{ -62.0, -68.0, 180.0, -65.0, 1.49},
3439 				{ -62.0, -68.0, -68.0, 180.0, 1.84}
3440 				};
3441 
3442 static ROTSSTRU LYS_ROTD[81] = {
3443 				{  66.8,  76.3,  66.4,  71.1, 9.99},
3444 				{  66.9,  76.7,  66.8, 175.9, 3.85},
3445 				{  57.5,  74.0,  85.8, -83.1, 4.09},
3446 				{  65.7,  78.2, 174.6,  62.6, 3.85},
3447 				{  68.9,  76.7, 177.2, 175.3, 4.09},
3448 				{  68.9,  77.8,-177.5, -68.4, 3.55},
3449 				{  66.8,  82.3, -86.0,  74.7, 9.99},
3450 				{  69.5,  85.2, -93.8,-177.2, 4.50},
3451 				{  66.8,  82.3, -83.6, -67.0, 9.99},
3452 				{  65.8, 175.6,  68.3,  68.9, 2.67},
3453 				{  64.7, 175.2,  70.9, 174.9, 2.23},
3454 				{  68.4,-179.3,  87.4, -84.8, 3.44},
3455 				{  65.9,-178.1, 173.2,  66.9, 2.00},
3456 				{  66.0,-179.4,-179.5, 179.9, 1.19},
3457 				{  65.6,-178.1,-175.9, -68.7, 2.03},
3458 				{  67.2,-175.2, -71.5,  74.3, 3.55},
3459 				{  64.3,-172.4, -68.2,-176.8, 2.10},
3460 				{  67.2,-173.7, -70.3, -68.0, 2.57},
3461 				{  67.2, -83.2,  80.8,  69.9, 4.50},
3462 				{  64.1, -83.7,  88.2, 177.6, 4.50},
3463 				{  66.9, -81.3,  88.3, -80.2, 9.99},
3464 				{  71.8, -79.7,-178.6,  65.4, 4.09},
3465 				{  69.4, -80.1,-178.3, 177.0, 3.27},
3466 				{  64.2, -81.9, 174.4, -65.5, 3.68},
3467 				{  66.9, -76.7, -78.3,  74.7, 9.99},
3468 				{  63.7, -77.8, -67.7, 179.7, 3.68},
3469 				{  67.5, -77.5, -75.5, -67.1, 4.50},
3470 				{-178.7,  68.1,  65.3,  66.2, 3.08},
3471 				{-172.9,  65.9,  71.0, 179.7, 2.33},
3472 				{-179.1,  68.7,  81.0, -81.3, 3.35},
3473 				{-178.4,  67.8, 170.7,  67.0, 1.98},
3474 				{-177.7,  70.3, 175.8, 179.3, 1.21},
3475 				{-174.2,  66.7,-178.3, -65.6, 2.05},
3476 				{-170.3,  87.2, -90.8,  76.8, 3.68},
3477 				{-172.6,  88.2, -91.5,-177.5, 2.94},
3478 				{-173.8,  86.5, -86.4, -69.3, 3.68},
3479 				{-174.3, 174.4,  72.8,  70.5, 1.98},
3480 				{-177.5, 173.7,  71.5, 177.8, 1.35},
3481 				{-172.2, 168.9,  87.1, -78.4, 2.51},
3482 				{-176.7, 176.0, 175.4,  65.1, 1.10},
3483 				{-177.2, 177.1, 179.5, 179.9, 0.32},
3484 				{-177.1, 177.0,-176.6, -67.4, 1.13},
3485 				{ 179.6,-178.0, -75.8,  70.6, 2.67},
3486 				{-175.0,-177.3, -70.2,-176.8, 1.35},
3487 				{-175.4,-178.7, -71.0, -65.1, 2.04},
3488 				{-162.4, -81.9,  82.2,  74.2, 4.50},
3489 				{-163.0, -83.1,  95.7,-178.9, 3.68},
3490 				{-164.5, -82.8,  88.3, -80.2, 9.99},
3491 				{-161.2, -77.8,-177.5,  66.4, 3.08},
3492 				{-165.2, -87.2,-177.2,-178.9, 2.32},
3493 				{-166.1, -83.0,-177.8, -67.3, 3.08},
3494 				{-160.1, -90.5, -80.9,  68.3, 4.09},
3495 				{-166.8, -96.6, -69.4, 178.4, 3.14},
3496 				{-168.0, -93.8, -76.0, -65.7, 3.44},
3497 				{ -88.0,  81.2,  68.0,  69.3, 3.55},
3498 				{ -80.9,  81.3,  66.9,-179.6, 2.94},
3499 				{ -86.8,  86.0,  84.3, -83.2, 3.85},
3500 				{ -80.7,  75.7, 176.2,  62.3, 2.43},
3501 				{ -81.0,  74.0,-178.3, 177.9, 2.12},
3502 				{ -87.6,  74.5, 178.0, -61.8, 2.51},
3503 				{ -86.6,  83.2, -85.6,  68.2, 4.09},
3504 				{ -82.6,  71.2, -96.3,-172.0, 3.55},
3505 				{ -85.8,  78.0, -86.1, -66.3, 4.50},
3506 				{ -70.1, 178.9,  73.0,  72.3, 1.70},
3507 				{ -68.5, 176.2,  69.4, 177.3, 1.13},
3508 				{ -70.3, 174.9,  84.2, -76.5, 2.49},
3509 				{ -67.1,-178.4, 177.7,  66.5, 0.89},
3510 				{ -67.1,-179.4,-179.4, 179.5, 0.00},
3511 				{ -66.8,-178.0,-177.5, -65.9, 0.87},
3512 				{ -66.8,-174.8, -76.5,  78.2, 2.29},
3513 				{ -67.6,-175.0, -72.6,-176.5, 1.07},
3514 				{ -65.1,-174.8, -72.3, -65.7, 1.66},
3515 				{ -64.8, -75.8,  85.4,  76.5, 3.55},
3516 				{ -62.3, -76.6,  91.0,-179.6, 2.53},
3517 				{ -62.3, -83.2,  88.3, -84.3, 3.68},
3518 				{ -63.5, -67.5,-177.9,  64.3, 1.52},
3519 				{ -62.2, -66.1,-177.3,-177.9, 0.72},
3520 				{ -60.1, -67.0,-174.3, -69.4, 1.38},
3521 				{ -65.2, -68.9, -76.9,  78.3, 2.98},
3522 				{ -63.4, -66.5, -70.5,-179.8, 1.73},
3523 				{ -60.5, -68.5, -73.1, -72.7, 2.39}
3524 				};
3525 
3526 
3527 
3528 static ZLINESTRU GLU[10] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3529 				{6,{7,2,1,0},1.521,114.1,-67.0},
3530 				{6,{8,7,2,0},1.516,112.5,180.0},
3531 				{8,{9,8,7,0}, 1.250,118.4,-10.0},
3532 				{8,{9,8,10,0},1.250,118.4,180.0},
3533 				{1,{2,3,1,0},1.100,108.2,-118.2},
3534 				{1,{7,2,8,0},1.100,108.9,121.8},
3535 				{1,{7,2,8,0},1.100,108.9,-121.8},
3536 				{1,{8,7,9,0},1.100,109.3,121.6},
3537 				{1,{8,7,9,0},1.100,109.3,-121.6}
3538 			   };
3539 static short int GLU_TYP[10] = { 5,6,9,34,35,4,7,8,10,11};
3540 static int GLU_CHI[4] = {2,3,4,-1};
3541 
3542 static ROTSSTRU GLU_ROT[8] = {
3543 				{  62.0, 180.0, -20.0, 0.0, 1.07},
3544 				{  70.0, -80.0,   0.0, 0.0, 1.61},
3545 				{-177.0,  65.0,  10.0, 0.0, 0.99},
3546 				{-177.0, 180.0,   0.0, 0.0, 0.19},
3547 				{-177.0, -80.0, -25.0, 0.0, 1.98},
3548 				{ -65.0,  85.0,   0.0, 0.0, 1.01},
3549 				{ -67.0, 180.0, -10.0, 0.0, 0.00},
3550 				{ -65.0, -65.0, -40.0, 0.0, 0.53}
3551 				};
3552 
3553 static ROTSSTRU GLU_ROTD[27] = {
3554 				{  54.3,  83.1,  49.0, 0.0, 2.95},
3555 				{  54.5,  88.3,   6.4, 0.0, 2.66},
3556 				{  50.8,  78.6, -61.4, 0.0, 3.82},
3557 				{  64.2,-178.4,  58.7, 0.0, 1.47},
3558 				{  64.6,-177.4,   1.7, 0.0, 1.23},
3559 				{  65.3,-176.6, -58.5, 0.0, 1.47},
3560 				{  58.6, -93.4,  51.0, 0.0, 2.06},
3561 				{  68.3, -81.5,   2.6, 0.0, 1.52},
3562 				{  65.1, -74.4, -51.1, 0.0, 2.69},
3563 				{-172.8,  62.1,  52.1, 0.0, 1.07},
3564 				{-178.4,  67.8,   9.7, 0.0, 0.93},
3565 				{-174.2,  72.2, -65.1, 0.0, 2.02},
3566 				{-177.6, 175.8,  57.3, 0.0, 0.66},
3567 				{-177.3, 177.9,  -0.2, 0.0, 0.28},
3568 				{-175.2, 179.2, -57.4, 0.0, 0.73},
3569 				{-155.8, -76.6,  63.4, 0.0, 3.05},
3570 				{-169.0, -86.3, -14.5, 0.0, 1.99},
3571 				{-166.0, -80.1, -49.5, 0.0, 1.83},
3572 				{ -66.3,  71.1,  52.3, 0.0, 1.35},
3573 				{ -66.2,  82.2,   1.9, 0.0, 0.92},
3574 				{ -66.8,  91.0, -54.1, 0.0, 1.90},
3575 				{ -68.3, 179.3,  56.0, 0.0, 0.58},
3576 				{ -67.7, 177.8,  -2.2, 0.0, 0.00},
3577 				{ -65.3,-178.2, -54.7, 0.0, 0.44},
3578 				{ -64.1, -79.0,  64.0, 0.0, 1.60},
3579 				{ -64.2, -71.2,  -9.8, 0.0, 0.62},
3580 				{ -67.7, -60.7, -52.4, 0.0, 0.48}
3581 				};
3582 
3583 static ZLINESTRU GLN[12] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3584 				{6,{7,2,1,0},1.521,114.1,-67.0},
3585 				{6,{8,7,2,0},1.516,112.5,180.0},
3586 				{8,{9,8,7,0},1.231,120.9,-25.0},
3587 				{7,{9,8,10,0},1.329,116.3,180.0},
3588 				{1,{2,3,1,0},1.100,108.2,-118.2},
3589 				{1,{7,2,8,0},1.100,108.9,121.8},
3590 				{1,{7,2,8,0},1.100,108.9,-121.8},
3591 				{1,{8,7,9,0},1.100,109.3,121.6},
3592 				{1,{8,7,9,0},1.100,109.3,-121.6},
3593 				{1,{11,9,8,0}, 1.000,120.0,0.0},
3594 				{1,{11,9,17,0},1.000,120.0,180.0}
3595 			   };
3596 static short int GLN_TYP[12] = { 5,6,9,34,24,4,7,8,10,11,34,35};
3597 static int GLN_CHI[4] = {2,3,4,-1};
3598 
3599 static ROTSSTRU GLN_ROT[9] = {
3600 				{  62.0, 180.0,  20.0, 0.0, 1.25},
3601 				{  70.0, -75.0,   0.0, 0.0, 1.78},
3602 				{-177.0,  65.0,-100.0, 0.0, 1.82},
3603 				{-177.0,  65.0,  60.0, 0.0, 0.81},
3604 				{-177.0, 180.0,   0.0, 0.0, 0.46},
3605 				{ -65.0,  85.0,   0.0, 0.0, 1.50},
3606 				{ -67.0, 180.0, -25.0, 0.0, 0.00},
3607 				{ -65.0, -65.0, -40.0, 0.0, 0.52},
3608 				{ -65.0, -65.0, 100.0, 0.0, 1.56}
3609 				};
3610 
3611 static ROTSSTRU GLN_ROTD[36] = {
3612 				{  64.1,  74.9,-124.0, 0.0, 9.99},
3613 				{  64.9,  86.9, -33.0, 0.0, 3.22},
3614 				{  62.5,  84.6,  38.5, 0.0, 2.24},
3615 				{  67.7,  84.8, 117.2, 0.0, 3.76},
3616 				{  61.5,-174.9,-179.8, 0.0, 2.37},
3617 				{  64.0,-177.6, -79.1, 0.0, 1.53},
3618 				{  65.1,-177.5,  -4.1, 0.0, 1.23},
3619 				{  65.4,-177.1,  79.5, 0.0, 1.39},
3620 				{  64.1, -82.4,-111.9, 0.0, 9.99},
3621 				{  66.3, -76.0, -34.4, 0.0, 2.16},
3622 				{  64.8, -89.6,  38.2, 0.0, 1.72},
3623 				{  57.6, -79.7, 123.9, 0.0, 2.75},
3624 				{-174.0,  60.6,-124.1, 0.0, 1.60},
3625 				{-175.4,  74.1, -37.5, 0.0, 1.61},
3626 				{-176.1,  65.7,  44.6, 0.0, 0.51},
3627 				{-178.1,  70.4, 109.0, 0.0, 2.70},
3628 				{-175.5, 178.6,-179.1, 0.0, 1.89},
3629 				{-178.0, 176.1, -77.6, 0.0, 0.95},
3630 				{-177.0, 177.3,   1.0, 0.0, 0.39},
3631 				{-176.6,-179.4,  74.8, 0.0, 0.83},
3632 				{-165.2, -77.7,-112.0, 0.0, 3.52},
3633 				{-169.4, -81.4, -34.9, 0.0, 1.61},
3634 				{-165.7, -83.7,  46.1, 0.0, 2.94},
3635 				{-170.6, -75.8, 125.3, 0.0, 2.65},
3636 				{ -70.8,  73.4,-123.8, 0.0, 2.40},
3637 				{ -64.6,  86.7, -35.4, 0.0, 1.69},
3638 				{ -68.4,  74.8,  37.4, 0.0, 1.30},
3639 				{ -72.0,  83.7, 110.1, 0.0, 3.02},
3640 				{ -66.9, 179.0,-177.9, 0.0, 1.28},
3641 				{ -66.8,-179.7, -76.8, 0.0, 0.41},
3642 				{ -67.5, 177.6,  -1.1, 0.0, 0.00},
3643 				{ -65.8,-178.9,  75.3, 0.0, 0.53},
3644 				{ -66.1, -82.1,-111.8, 0.0, 2.43},
3645 				{ -63.4, -63.2, -46.3, 0.0, 0.13},
3646 				{ -67.0, -76.5,  44.4, 0.0, 1.26},
3647 				{ -68.5, -61.2, 119.9, 0.0, 1.19}
3648 				};
3649 
3650 static ZLINESTRU PRO[10] = {    {6,{2,3,1,0},1.530,112.2,115.146},
3651 				{6,{6,2,1,0},1.512,104.1,-27.9},
3652 				{6,{7,6,2,0},1.518,103.0,39.0},
3653 				{1,{2,3,1,0},1.100,104.1,-122.6},
3654 				{1,{6,2,7,0},1.100,111.4,120.3},
3655 				{1,{6,2,7,0},1.100,111.4,-120.3},
3656 				{1,{7,6,8,0},1.100,111.7,120.1},
3657 				{1,{7,6,8,0},1.100,111.7,-120.1},
3658 				{1,{8,7,1,0},1.100,111.8,120.0},
3659 				{1,{8,7,1,0},1.100,111.8,-120.0}
3660 			   };
3661 static short int PRO_TYP[10] = { 5,6,9,4,7,8,10,11,19,20};
3662 static int PRO_CHI[4] = {2,3,-1,-1};
3663 
3664 /* definitie */
3665 static ROTSSTRU PRO_ROT[2] = {
3666 				{ -27.943,  39.047, 0.0, 0.0, 0.00},
3667 				{  27.570, -35.774, 0.0, 0.0, 0.01}
3668 				};
3669 
3670 static ROTSSTRU PRO_ROTD[2] = {
3671 				{ 27.0, -34.6, 0.0, 0.0, 0.00},
3672 				{-25.1,  36.3, 0.0, 0.0, 0.02}
3673 				};
3674 
3675 static ZLINESTRU ARG[19] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3676 				{6,{7,2,1,0},1.520,114.1,-67.0},
3677 				{6,{8,7,2,0},1.520,111.3,180.0},
3678 				{7,{9,8,7,0},1.459,112.0,180.0},
3679 				{6,{10,9,8,0},1.330,124.2,180.0},
3680 				{7,{11,10,9,0},1.326,120.0,0.0},
3681 				{7,{11,10,12,0},1.326,120.0,180.0},
3682 				{1,{2,3,1,0},1.100,108.2,-118.2},
3683 				{1,{7,2,8,0},1.100,108.9,121.9},
3684 				{1,{7,2,8,0},1.100,108.9,-121.9},
3685 				{1,{8,7,9,0},1.100,109.6,121.4},
3686 				{1,{8,7,9,0},1.100,109.6,-121.4},
3687 				{1,{9,8,10,0},1.100,109.4,121.5},
3688 				{1,{9,8,10,0},1.100,109.4,-121.5},
3689 				{1,{10,9,11,0}, 1.000,118.0,180.0},
3690 				{1,{12,11,10,0},1.000,120.0,0.0},
3691 				{1,{12,11,22,0},1.000,120.0,180.0},
3692 				{1,{13,11,10,0},1.000,120.0,0.0},
3693 				{1,{13,11,24,0},1.000,120.0,180.0}
3694 			   };
3695 static short int ARG_TYP[19] = { 5,6,9,22,17,25,26,4,7,8,10,11,19,20,28,55,56,58,59};
3696 static int ARG_CHI[4] = {2,3,4,5};
3697 static ROTSSTRU ARG_ROT[34] = {
3698 				{  62.0, 180.0,  65.0,  85.0, 2.01},
3699 				{  62.0, 180.0,  65.0,-175.0, 1.24},
3700 				{  62.0, 180.0, 180.0,  85.0, 1.02},
3701 				{  62.0, 180.0, 180.0, 180.0, 1.02},
3702 				{  62.0, 180.0, 180.0, -85.0, 1.06},
3703 				{  62.0, 180.0, -65.0, 175.0, 1.60},
3704 				{  62.0, 180.0, -65.0, -85.0, 1.71},
3705 				{-177.0,  65.0,  65.0,  85.0, 1.24},
3706 				{-177.0,  65.0,  65.0,-175.0, 1.43},
3707 				{-177.0,  65.0, 180.0,  85.0, 0.89},
3708 				{-177.0,  65.0, 180.0, 180.0, 1.06},
3709 				{-177.0, 180.0,  65.0,  85.0, 0.59},
3710 				{-177.0, 180.0,  65.0,-175.0, 0.76},
3711 				{-177.0, 180.0,  65.0,-105.0, 1.36},
3712 				{-177.0, 180.0, 180.0,  85.0, 0.92},
3713 				{-177.0, 180.0, 180.0, 180.0, 0.59},
3714 				{-177.0, 180.0, 180.0, -85.0, 0.73},
3715 				{-177.0, 180.0, -65.0, 105.0, 1.30},
3716 				{-177.0, 180.0, -65.0, 175.0, 1.14},
3717 				{-177.0, 180.0, -65.0, -85.0, 0.69},
3718 				{ -67.0, 180.0,  65.0,  85.0, 0.83},
3719 				{ -67.0, 180.0,  65.0,-175.0, 0.41},
3720 				{ -67.0, 180.0,  65.0,-105.0, 1.51},
3721 				{ -67.0, 180.0, 180.0,  85.0, 0.57},
3722 				{ -67.0, 180.0, 180.0, 180.0, 0.00},
3723 				{ -67.0, 180.0, 180.0, -85.0, 0.31},
3724 				{ -67.0, 180.0, -65.0, 105.0, 1.06},
3725 				{ -67.0, 180.0, -65.0, 175.0, 0.37},
3726 				{ -67.0,-167.0, -65.0, -85.0, 0.30},
3727 				{ -62.0, -68.0, 180.0,  85.0, 1.51},
3728 				{ -62.0, -68.0, 180.0, 180.0, 0.95},
3729 				{ -62.0, -68.0, 180.0, -85.0, 0.83},
3730 				{ -62.0, -68.0, -65.0, 175.0, 1.24},
3731 				{ -62.0, -68.0, -65.0, -85.0, 0.95}
3732 				};
3733 
3734 static ROTSSTRU ARG_ROTD[81] = {
3735 				{  55.4,  79.7,  62.4,  82.3, 3.50},
3736 				{  59.2,  85.4,  68.2,-166.2, 2.95},
3737 				{  54.5,  79.4,  64.6,-103.2, 9.99},
3738 				{  54.5,  86.6, 178.2,  85.5, 3.26},
3739 				{  53.9,  87.8,-178.5, 178.1, 2.60},
3740 				{  53.5,  87.8,-176.0, -81.1, 3.09},
3741 				{  54.5,  83.5, -78.4, 102.9, 9.99},
3742 				{  50.0,  82.4, -92.5, 169.0, 3.50},
3743 				{  54.5,  83.5, -77.1, -84.1, 9.99},
3744 				{  62.0, 177.8,  64.9,  84.4, 1.80},
3745 				{  64.1,-175.8,  68.0,-172.6, 1.39},
3746 				{  65.1,-178.6,  61.1,-104.5, 2.43},
3747 				{  65.3, 180.0, 178.0,  85.7, 1.16},
3748 				{  66.5,-177.6,-178.9,-177.2, 1.12},
3749 				{  66.4,-175.2,-177.5, -82.5, 1.22},
3750 				{  63.8,-171.9, -64.5, 102.9, 2.67},
3751 				{  63.4,-176.5, -66.7, 173.2, 1.44},
3752 				{  62.9, 179.9, -69.2, -82.5, 1.95},
3753 				{  65.2, -85.1,  84.2,  84.5, 3.91},
3754 				{  63.2, -85.5,  80.7,-172.0, 3.91},
3755 				{  63.6, -82.1,  71.6,-103.2, 9.99},
3756 				{  63.6, -78.2,-179.8,  85.7, 9.99},
3757 				{  57.6, -83.1,-176.1,-178.4, 2.95},
3758 				{  68.7, -75.7,-177.8, -85.7, 3.09},
3759 				{  63.6, -77.9, -77.1, 102.9, 9.99},
3760 				{  63.7, -78.1, -64.2, 169.9, 2.84},
3761 				{  63.8, -78.2, -59.5, -83.3, 3.50},
3762 				{-176.5,  65.8,  60.2,  80.8, 1.69},
3763 				{ 179.4,  65.8,  65.3,-170.9, 1.47},
3764 				{-173.6,  68.1,  67.3,-103.0, 2.95},
3765 				{ 179.3,  66.2,-178.6,  85.1, 1.45},
3766 				{-177.0,  67.4, 177.0, 171.0, 1.21},
3767 				{ 178.1,  66.9,-178.7, -85.3, 1.71},
3768 				{-176.1,  81.2, -80.9, 103.3, 3.91},
3769 				{-175.6,  79.6, -90.4, 172.4, 2.10},
3770 				{-178.7,  78.6, -78.3, -84.6, 2.84},
3771 				{-177.3, 178.6,  64.9,  80.8, 0.72},
3772 				{-174.1, 176.8,  67.8,-167.7, 0.66},
3773 				{-176.7, 178.8,  63.4,-103.7, 1.36},
3774 				{-176.8, 177.6, 178.8,  85.2, 0.92},
3775 				{-176.9, 176.3, 178.8,-179.4, 0.46},
3776 				{-177.5, 176.5,-177.8, -85.2, 0.78},
3777 				{-174.4, 178.1, -63.4, 105.1, 1.23},
3778 				{-175.4, 179.7, -64.8, 165.2, 0.78},
3779 				{-175.6, 179.6, -65.0, -82.6, 0.80},
3780 				{-169.7, -83.6,  80.9,  82.5, 9.99},
3781 				{-166.0, -82.2,  78.0,-172.4, 3.91},
3782 				{-169.7, -83.6,  71.6,-103.2, 9.99},
3783 				{-171.4, -85.4,-174.0,  84.2, 3.26},
3784 				{-171.3, -87.2,-179.0,-176.1, 2.26},
3785 				{-171.0, -84.3,-176.8, -81.1, 2.67},
3786 				{-170.0, -92.9, -72.5, 104.0, 3.26},
3787 				{-170.2, -91.1, -67.4, 170.0, 2.10},
3788 				{-165.9, -84.4, -59.4, -82.3, 2.75},
3789 				{ -79.0,  87.7,  66.3,  84.2, 2.60},
3790 				{ -83.1,  81.9,  69.8,-178.0, 2.23},
3791 				{ -80.8,  86.2,  67.4,-101.7, 3.91},
3792 				{ -78.6,  73.8,-179.4,  85.1, 2.75},
3793 				{ -85.8,  70.4, 174.6, 179.0, 1.69},
3794 				{ -80.8,  79.3, 177.3, -81.8, 2.23},
3795 				{ -82.6,  77.9, -78.4, 102.9, 9.99},
3796 				{ -85.1,  77.1, -91.5, 168.7, 3.50},
3797 				{ -81.6,  78.0, -79.6, -84.1, 3.91},
3798 				{ -66.2, 179.5,  66.1,  84.3, 0.66},
3799 				{ -66.7, 178.5,  65.6,-170.1, 0.37},
3800 				{ -67.2,-178.5,  63.1,-101.8, 1.59},
3801 				{ -66.9, 179.7, 178.7,  86.7, 0.51},
3802 				{ -67.7, 179.1,-179.0, 176.3, 0.00},
3803 				{ -68.1,-179.7,-176.3, -82.7, 0.38},
3804 				{ -68.9,-175.6, -68.5, 102.2, 1.36},
3805 				{ -67.0, 179.5, -67.9, 173.2, 0.30},
3806 				{ -68.4,-170.6, -64.5, -85.4, 0.44},
3807 				{ -63.9, -76.1,  80.0,  79.6, 1.95},
3808 				{ -64.3, -80.3,  78.7,-165.9, 1.95},
3809 				{ -62.5, -80.5,  71.6,-105.6, 3.26},
3810 				{ -62.6, -68.9, 179.4,  83.8, 1.30},
3811 				{ -62.7, -72.4,-177.9,-177.8, 0.85},
3812 				{ -63.2, -69.8,-175.2, -87.0, 0.87},
3813 				{ -64.9, -74.5, -79.7,  95.0, 2.39},
3814 				{ -63.6, -67.9, -65.0, 169.4, 1.13},
3815 				{ -62.8, -68.8, -60.8, -83.5, 1.00}
3816 				};
3817 
3818 static ZLINESTRU HIS[13] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3819 				{6,{7,2,1,0},1.497,113.8,-65.0},
3820 				{7,{8,7,2,0},1.378,122.7,-69.0},
3821 				{6,{9,8,7,0},1.321,109.3,180.0},
3822 				{7,{10,9,8,0},1.318,108.5,0.0},
3823 				{6,{11,10,9,0},1.373,108.9,0.0},
3824 				{1,{2,3,1,0},1.100,108.2,-118.2},
3825 				{1,{7,2,8,0},1.100,108.9,121.8},
3826 				{1,{7,2,8,0},1.100,108.9,-121.8},
3827 				{1,{9,8,10,0},  1.000,125.3,180.0},
3828 				{1,{10,9,8,0}, 1.100,125.7,180.0},
3829 				{1,{12,11,10,0},1.100,126.4,180.0}
3830 			   };
3831 static short int HIS_TYP[13] = { 5,6,20,13,24,11,4,7,8,22,31,25};
3832 static int HIS_CHI[4] = {2,3,-1,-1};
3833 static ROTSSTRU HIS_ROT[8] = {
3834 				{  62.0, -75.0, 0.0, 0.0, 0.73},
3835 				{  62.0,  80.0, 0.0, 0.0, 1.13},
3836 				{-177.0,-165.0, 0.0, 0.0, 1.02},
3837 				{-177.0, -80.0, 0.0, 0.0, 0.59},
3838 				{-177.0,  60.0, 0.0, 0.0, 0.36},
3839 				{ -65.0, -70.0, 0.0, 0.0, 0.00},
3840 				{ -65.0, 165.0, 0.0, 0.0, 0.81},
3841 				{ -65.0,  80.0, 0.0, 0.0, 0.48}
3842 				};
3843 
3844 static ROTSSTRU HIS_ROTD[9] = {
3845 				{  63.0,  85.6,  0.0,   0.0, 1.09},
3846 				{  64.8, 166.2,  0.0,   0.0, 2.37},
3847 				{  65.4, -79.5,  0.0,   0.0, 0.85},
3848 				{-178.4,  71.5,  0.0,   0.0, 0.39},
3849 				{-172.8,-170.3,  0.0,   0.0, 1.02},
3850 				{-172.6, -83.8,  0.0,   0.0, 0.53},
3851 				{ -66.0,  85.6,  0.0,   0.0, 0.42},
3852 				{ -68.1, 168.7,  0.0,   0.0, 0.60},
3853 				{ -63.7, -72.9,  0.0,   0.0, 0.00}
3854 				};
3855 
3856 static ZLINESTRU PHE[15] = {    {6,{2,3,1,0},1.530,110.4,122.8},
3857 				{6,{7,2,1,0},1.501,113.8,-65.0},
3858 				{6,{8,7,2,0},1.384,120.7,-85.0},
3859 				{6,{9,8,7,0},1.382,120.7,180.0},
3860 				{6,{10,9,8,0},1.378,120.1,0.0},
3861 				{6,{11,10,9,0},1.378,119.7,0.0},
3862 				{6,{12,11,10,0},1.381,120.0,0.0},
3863 				{1,{2,3,1,0},1.100,108.2,-118.2},
3864 				{1,{7,2,8,0},1.100,108.9,121.8},
3865 				{1,{7,2,8,0},1.100,108.9,-121.8},
3866 				{1,{9,8,7,0},1.100,119.6,0.0},
3867 				{1,{10,9,8,0},1.100,119.9,180.0},
3868 				{1,{11,10,9,0},1.100,120.1,180.0},
3869 				{1,{12,11,10,0},1.100,120.0,180.0},
3870 				{1,{13,12,11,0},1.100,119.5,180.0}
3871 			   };
3872 static short int PHE_TYP[15] = { 5,6,10,13,17,14,11,4,7,8,22,31,40,34,25};
3873 static int PHE_CHI[4] = {2,3,-1,-1};
3874 static ROTSSTRU PHE_ROT[4] = {
3875 				{  62.0,  90.0, 0.0, 0.0, 0.73},
3876 				{-177.0,  80.0, 0.0, 0.0, 0.14},
3877 				{ -65.0, -85.0, 0.0, 0.0, 0.00},
3878 				{ -65.0, -30.0, 0.0, 0.0, 0.95}
3879 				};
3880 
3881 static ROTSSTRU PHE_ROTD[6] = {
3882 				{  63.0,  90.4, 0.0, 0.0, 0.86},
3883 				{  62.0,  -6.5, 0.0, 0.0, 3.71},
3884 				{-178.8,  78.1, 0.0, 0.0, 0.23},
3885 				{-174.2,  21.2, 0.0, 0.0, 1.90},
3886 				{ -66.9,  97.7, 0.0, 0.0, 0.00},
3887 				{ -68.8, -15.3, 0.0, 0.0, 1.04}
3888 				};
3889 
3890 
3891 static ZLINESTRU TYR[16] = {    {6,{2,3,1,0},1.530,110.4,122.8},
3892 				{6,{7,2,1,0},1.501,113.8,-65.0},
3893 				{6,{8,7,2,0},1.389,120.8,-85.0},
3894 				{6,{9,8,7,0},1.381,121.2,180.0},
3895 				{6,{10,9,8,0},1.390,119.4,0.0},
3896 				{6,{11,10,9,0},1.382,120.4,0.0},
3897 				{6,{12,11,10,0},1.382,119.4,0.0},
3898 				{8,{11,10,9,0},1.376,119.7,180.0},
3899 				{1,{2,3,1,0},1.100,108.2,-118.2},
3900 				{1,{7,2,8,0},1.100,108.9,121.8},
3901 				{1,{7,2,8,0},1.100,108.9,-121.8},
3902 				{1,{9,8,7,0},1.100,119.4,0.0},
3903 				{1,{10,9,8,0},1.100,120.3,180.0},
3904 				{1,{12,11,10,0},1.100,120.3,180.0},
3905 				{1,{13,12,11,0},1.100,119.4,180.0},
3906 				{1,{14,11,10,0},1.000,109.5,0.0}
3907 			   };
3908 static short int TYR_TYP[16] = { 5,6,10,13,17,14,11,33,4,7,8,22,31,34,25,52};
3909 static int TYR_CHI[4] = {2,3,-1,-1};
3910 /* 1 te veel ?  alex ?*/
3911 static ROTSSTRU TYR_ROT[5] = {
3912 				{  62.0,  90.0, 0.0, 0.0, 0.72},
3913 				{-177.0,  80.0, 0.0, 0.0, 0.14},
3914 				{ -65.0, -85.0, 0.0, 0.0, 0.00},
3915 				{ -65.0, -30.0, 0.0, 0.0, 0.95},
3916 				{ -65.0,  30.0, 0.0, 0.0, 0.00}
3917 				};
3918 static ROTSSTRU TYR_ROTD[6] = {
3919 				{  63.6,  90.2, 0.0, 0.0, 0.83},
3920 				{  69.7,  -9.5, 0.0, 0.0, 3.55},
3921 				{-179.6,  77.5, 0.0, 0.0, 0.22},
3922 				{-174.2,  21.0, 0.0, 0.0, 1.90},
3923 				{ -65.8,  97.8, 0.0, 0.0, 0.00},
3924 				{ -67.2, -16.7, 0.0, 0.0, 1.17}
3925 				};
3926 
3927 
3928 static ZLINESTRU TRP[19] = {    {6,{2,3,1,0},1.530,110.1,122.8},
3929 				{6,{7,2,1,0},1.498,113.6,-65.0},
3930 				{6,{8,7,2,0},1.365,126.9,95.0},
3931 				{7,{9,8,7,0},1.374,110.2,180.0},
3932 				{6,{10,9,8,0},1.375,108.7,0.0},
3933 				{6,{11,10,9,0},1.409,107.6,0.0},
3934 				{6,{12,11,10,0},1.397,118.9,180.0},
3935 				{6,{13,12,11,0},1.382,118.6,0.0},
3936 				{6,{14,13,12,0},1.406,121.3,0.0},
3937 				{6,{15,14,13,0},1.370,121.2,0.0},
3938 				{1,{2,3,1,0},1.100,108.2,-118.2},
3939 				{1,{7,2,8,0},1.100,109.0,121.8},
3940 				{1,{7,2,8,0},1.100,109.0,-121.8},
3941 				{1,{9,8,7,0},1.100,124.9,0.0},
3942 				{1,{10,9,8,0},1.000,125.7,180.0},
3943 				{1,{13,12,10,0},1.100,120.7,180.0},
3944 				{1,{14,13,12,0},1.100,119.4,180.0},
3945 				{1,{15,14,13,0},1.100,119.4,180.0},
3946 				{1,{16,15,14,0},1.100,121.2,180.0}
3947 			   };
3948 static short int TRP_TYP[19] = { 5,6,10,23,14,11,15,19,16,18,4,7,8,22,31,37,49,58,46};
3949 static int TRP_CHI[4] = {2,3,-1,-1};
3950 static ROTSSTRU TRP_ROT[7] = {
3951 				{  62.0, -90.0, 0.0, 0.0, 0.63},
3952 				{  62.0,  90.0, 0.0, 0.0, 1.03},
3953 				{-177.0,-105.0, 0.0, 0.0, 0.40},
3954 				{-177.0,  90.0, 0.0, 0.0, 0.34},
3955 				{ -65.0, -90.0, 0.0, 0.0, 1.09},
3956 				{ -65.0,  -5.0, 0.0, 0.0, 0.83},
3957 				{ -65.0,  95.0, 0.0, 0.0, 0.00}
3958 				};
3959 static ROTSSTRU TRP_ROTD[9] = {
3960 				{  61.2, -89.9,   0.0,   0.0, 0.67},
3961 				{  66.0,  -6.3,   0.0,   0.0, 2.37},
3962 				{  61.5,  89.2,   0.0,   0.0, 1.04},
3963 				{-177.3,-104.9,   0.0,   0.0, 0.38},
3964 				{-175.1,  17.3,   0.0,   0.0, 0.99},
3965 				{-179.8,  84.7,   0.0,   0.0, 0.51},
3966 				{ -70.1, -92.2,   0.0,   0.0, 1.04},
3967 				{ -68.6,  -4.2,   0.0,   0.0, 0.51},
3968 				{ -67.4, 100.3,   0.0,   0.0, 0.00}
3969 				};
3970 
3971 
3972 static ZLINESTRU ACE[6] =   {   {6,{0,0,0,0},0.0,0.0,0.0},
3973 				{8,{1,0,0,0},1.220,0.0,0.0},
3974 				{6,{1,2,0,0},1.335,120.0,0.0},
3975 				{1,{3,1,2,0},1.089,109.471,180.0},
3976 				{1,{3,1,2,0},1.089,109.471,60.0},
3977 				{1,{3,1,2,0},1.089,109.471,-60.0}
3978 				};
3979 
3980 static ZLINESTRU FOR[3] =   {   {6,{0,0,0,0},0.0,0.0,0.0},
3981 				{8,{1,0,0,0},1.220,0.0,0.0},
3982 				{1,{1,2,0,0},1.089,120.0,0.0}
3983 				};
3984 
3985 static ZLINESTRU NME[6] =   {  {7,{0,0,0,0},0.0,0.0,0.0},
3986 				{6,{1,0,0,0},1.300,0.0,0.0},
3987 				{1,{1,2,0,0},1.020,120.0,0.0},
3988 				{1,{2,1,3,0},1.089,109.471,180.0},
3989 				{1,{2,1,4,0},1.089,109.471,120.0},
3990 				{1,{2,1,4,0},1.089,109.471,-120.0}
3991 				};
3992 
3993 static ZLINESTRU AMINO[28];
3994 
3995 typedef struct { ZLINESTRU *zmat;
3996 		 short int *ipdbt;
3997 		 int *chis;
3998 		 ROTSSTRU *rots;
3999 		 int zlines;
4000 		 int nrots;
4001 		} AMINOSTRU;
4002 
4003 static AMINOSTRU aminozmtr[20] = {
4004 	{GLY,GLY_TYP,GLY_CHI,GLY_ROT,2,0}, {ALA,ALA_TYP,ALA_CHI,ALA_ROT,5,0},
4005 	{SER,SER_TYP,SER_CHI,SER_ROT,6,3}, {CYS,CYS_TYP,CYS_CHI,CYS_ROT,6,3},
4006 	{THR,THR_TYP,THR_CHI,THR_ROT,9,3}, {ILE,ILE_TYP,ILE_CHI,ILE_ROT,14,5},
4007 	{VAL,VAL_TYP,VAL_CHI,VAL_ROT,11,3},{MET,MET_TYP,MET_CHI,MET_ROT,12,13},
4008 	{ASP,ASP_TYP,ASP_CHI,ASP_ROT,7,5}, {ASN,ASN_TYP,ASN_CHI,ASN_ROT,9,7},
4009 	{LEU,LEU_TYP,LEU_CHI,LEU_ROT,14,5},{LYS,LYS_TYP,LYS_CHI,LYS_ROT,17,27},
4010 	{GLU,GLU_TYP,GLU_CHI,GLU_ROT,10,8},{GLN,GLN_TYP,GLN_CHI,GLN_ROT,12,9},
4011 	{PRO,PRO_TYP,PRO_CHI,PRO_ROT,10,2},{ARG,ARG_TYP,ARG_CHI,ARG_ROT,19,34},
4012 	{HIS,HIS_TYP,HIS_CHI,HIS_ROT,12,8},{PHE,PHE_TYP,PHE_CHI,PHE_ROT,15,4},
4013 	{TYR,TYR_TYP,TYR_CHI,TYR_ROT,16,5},{TRP,TRP_TYP,TRP_CHI,TRP_ROT,19,7}
4014 	};
4015 
4016 static AMINOSTRU aminozmtd[20] = {
4017 	{GLY,GLY_TYP,GLY_CHI,GLY_ROT,2,0}, {ALA,ALA_TYP,ALA_CHI,ALA_ROT,5,0},
4018 	{SER,SER_TYP,SER_CHI,SER_ROTD,6,3}, {CYS,CYS_TYP,CYS_CHI,CYS_ROTD,6,3},
4019 	{THR,THR_TYP,THR_CHI,THR_ROTD,9,3}, {ILE,ILE_TYP,ILE_CHI,ILE_ROTD,14,9},
4020 	{VAL,VAL_TYP,VAL_CHI,VAL_ROTD,11,3},{MET,MET_TYP,MET_CHI,MET_ROTD,12,27},
4021 	{ASP,ASP_TYP,ASP_CHI,ASP_ROTD,7,9}, {ASN,ASN_TYP,ASN_CHI,ASN_ROTD,9,18},
4022 	{LEU,LEU_TYP,LEU_CHI,LEU_ROTD,14,9},{LYS,LYS_TYP,LYS_CHI,LYS_ROTD,17,81},
4023 	{GLU,GLU_TYP,GLU_CHI,GLU_ROTD,10,27},{GLN,GLN_TYP,GLN_CHI,GLN_ROTD,12,36},
4024 	{PRO,PRO_TYP,PRO_CHI,PRO_ROTD,10,2},{ARG,ARG_TYP,ARG_CHI,ARG_ROTD,19,81},
4025 	{HIS,HIS_TYP,HIS_CHI,HIS_ROTD,12,9},{PHE,PHE_TYP,PHE_CHI,PHE_ROTD,15,6},
4026 	{TYR,TYR_TYP,TYR_CHI,TYR_ROTD,16,6},{TRP,TRP_TYP,TRP_CHI,TRP_ROTD,19,9}
4027 	};
4028 
4029 static AMINOSTRU *aminozmt = aminozmtr;
4030 
4031 
4032 /* start dimension dynamic molecule coordinates*/
4033 
4034 #define NUMAT 20000
4035 #define MXCON 10
4036 #define NUMADD 50000
4037 static int addat = NUMADD;
4038 
4039 typedef struct { double coo[NUMAT][3];
4040 		 double rzp[NUMAT];
4041 		 int ianz[NUMAT];
4042 		 int iaton[NUMAT];
4043 		 int iatclr[NUMAT];
4044 		 int iresid[NUMAT];
4045 		 int ixp[NUMAT];
4046 		 int iyp[NUMAT];
4047 		 int iconn[NUMAT][MXCON+1];
4048                } ATOMSTRU;
4049 
4050 static ATOMSTRU *atomptr;
4051 
4052 #define MXDRES 40
4053 #define MXROT 81
4054 #define MXROTRES 10
4055 
4056 typedef struct { double estat[MXROT][MXDRES];
4057 		 int ndrs;
4058 		 int idrs[MXDRES];
4059 		 int lrots[MXDRES];
4060 		 } PMFROTSTRU;
4061 
4062 static PMFROTSTRU *pmfrot;
4063 
4064 #define MXSYM 103
4065 #define MXHSYM 64
4066 
4067 static int ipdb[MXSYM];
4068 static int ihpdb[MXHSYM*3];
4069 
4070 double vln( double *a);
4071 
4072 /* This is a sin, I know :-) */
4073 
4074 static int NW_MKBACK = 0;
4075 
4076 void ogsarr();
4077 void ogres(int ires, int iopt,int iupd);
4078 void DrCircle(int cx,int cy,float r,int nseg);
4079 static int vis = 0;
4080 
4081 #include "rots.h"
4082 
4083 typedef struct { double etot;
4084 		 int ndrs;
4085 		 int mx;
4086 		 int mn;
4087 		 int idrs[MXDRES];
4088 		 int rot[MXDRES];
4089 		 } RESROTSTRU;
4090 
4091 static RESROTSTRU resrot[MXROTRES];
4092 static int nresrot = 0;
4093 static double flxen[MXROTRES];
4094 
4095 static int *iresflx = NULL;
4096 typedef struct { double vo[3];
4097 		 double r[3];
4098 		 double v1[3];
4099 		 double v2[3];
4100 		 double v3[3];
4101 		 double wo[3];
4102 		 double sl[3];
4103 		 int isl;
4104                } COMSRFSTRU;
4105 
4106 static COMSRFSTRU *comsrfptr;
4107 
4108 typedef struct { float fc[NUMAT][3];
4109                } FCSTRU;
4110 
4111 static FCSTRU *fcptr;
4112 
4113 #define MAXDM 20
4114 typedef struct { double rdm[MAXDM];
4115 		 int idmon[MAXDM][2];
4116 		 int ndm;
4117                } MONSTRU;
4118 
4119 static MONSTRU *monptr;
4120 
4121 
4122 #define MXEL 100
4123 typedef struct {
4124 		 double vdwr[MXEL];
4125 		 double vrad[MXEL];
4126 		 int icol[MXEL];
4127                } ELMSTRU;
4128 
4129 static ELMSTRU *elmptr;
4130 
4131 typedef struct  { int *iamino;
4132 		  int phi;
4133 		  int psi;
4134 		  int omega;
4135 		  int chi1;
4136 		  int chi2;
4137 		  int chi3;
4138 		  int chi4;
4139 		} AASTRU;
4140 
4141 static AASTRU aaptr[NUMCAL];
4142 
4143 static int *ResChanged = NULL;
4144 static int CurrRes = 0;
4145 static double xyzpdb[MXSYM][3];
4146 static double xyzhpdb[MXHSYM*3][3];
4147 
4148 #define MXCOLNAM 20
4149 static char  *ColNam[MXCOLNAM];
4150 static int NColNam = 0;
4151 
4152 void dummyproc();
4153 static void DoExpl();
4154 static void ogunsel();
4155 static void handle_explalarm();
4156 static void handle_svgfile();
4157 static void DoSvgfile();
4158 static void SvgExpose();
4159 void DrawSVG(int x,int y,int w0,int h0,SVGFSTRUC svgfile,Window win);
4160 void InitOmap(int opt);
4161 void dispsf(void);
4162 void ogbox();
4163 void ogelem();
4164 void ogsetel20(int j);
4165 void ogsetel20_bs(int j);
4166 void ogsetel12(int j);
4167 void ogsetel12_bs(int j);
4168 void ogfeatures();
4169 void GetPDBWWW(char *het, char *retstr);
4170 int GetOMAPWWW(char *het, char *retstr);
4171 int PDBquery(char *het);
4172 void LigandHydroPBE(int ihet);
4173 void LigandHydroQ(int DoHyd,int DoChg,int DoFF,int CHGtot);
4174 void LigandQ(int ihet);
4175 void LigandHydro(int het);
4176 int Ligand2Amino(int ihet);
4177 int ParseFile(char *strname, char *shortname);
4178 static int hasWGET = 0;
4179 int CheckWGET();
4180 void update_struct();
4181 void oghet(int iopt);
4182 void oglines();
4183 void ogsel();
4184 #if defined(VMS) || defined(UNDERSC)
4185 void ogmon();
4186 #else
4187 #ifdef CRAY
4188 void OGMON();
4189 #else
4190 void ogmon_();
4191 #endif
4192 #endif
4193 void ogforces();
4194 void ogmoll(int iopt);
4195 void ogbck(int isec);
4196 void ResetRes();
4197 void ressel();
4198 void ogdipole();
4199 void zmt2cor(int ires, int iopt);
4200 void moused(int button, unsigned int state, int x, int y);
4201 void mouseu(int button, int state, int x, int y);
4202 void motion(int x, int y, int iopt);
4203 void Reshape(int update);
4204 void empty_model(int sel,int updis);
4205 void empty_ribb();
4206 void MoveOne(int i);
4207 void initOpengl();
4208 void initthe();
4209 void initnthe();
4210 void initOne(int i);
4211 void setobg();
4212 void DelHet(int het);
4213 void znorm(double rpts, double cnst, double *dens, double *vn,
4214 	   int npts1, int npts2, int i, int j);
4215 void printString(int x, int y, int init, char *s);
4216 void makeRasterFont(Display *dpy);
4217 
4218 #include <math.h>
4219 
4220 #include <fcntl.h>
4221 #if defined(__APPLE__)
4222 #include <copyfile.h>
4223 #elif defined(__FreeBSD__) || defined(__DragonFly__)
4224 #include <sys/types.h>
4225 #include <sys/socket.h>
4226 #include <sys/uio.h>
4227 #else
4228 #include <sys/sendfile.h>
4229 #endif
4230 
OSCopyFile(const char * source,const char * destination)4231 int OSCopyFile(const char* source, const char* destination)
4232 {
4233     int input, output;
4234     if ((input = open(source, O_RDONLY)) == -1)
4235     {
4236         return -1;
4237     }
4238     if ((output = creat(destination, 0660)) == -1)
4239     {
4240         close(input);
4241         return -1;
4242     }
4243 
4244     //Here we use kernel-space copying for performance reasons
4245 #if defined(__APPLE__)
4246     //fcopyfile works on FreeBSD and OS X 10.5+
4247     int result = fcopyfile(input, output, 0, COPYFILE_ALL);
4248 #elif defined(__FreeBSD__) || defined(__DragonFly__)
4249     off_t bytesCopied = 0;
4250     struct stat fileinfo = {0};
4251     fstat(input, &fileinfo);
4252     int result = sendfile(output, input, 0/*ofset*/, fileinfo.st_size, 0/*hdtr*/, &bytesCopied, 0/*flags*/);
4253 #else
4254     //sendfile will work with non-socket output (i.e. regular file) on Linux 2.6.33+
4255     off_t bytesCopied = 0;
4256     struct stat fileinfo = {0};
4257     fstat(input, &fileinfo);
4258     int result = sendfile(output, input, &bytesCopied, fileinfo.st_size);
4259 #endif
4260 
4261     close(input);
4262     close(output);
4263 
4264     return result;
4265 }
4266 
cross(float * a,float * b,float * c)4267 void cross(float *a,float *b, float *c)
4268 {
4269 /*
4270 
4271        calculates cross product:   a x b = c
4272                                    -   -   -
4273 */
4274 
4275       c[0] = a[1]*b[2] - a[2]*b[1];
4276       c[1] = a[2]*b[0] - a[0]*b[2];
4277       c[2] = a[0]*b[1] - a[1]*b[0];
4278 
4279 }
4280 
veclen(float * a)4281 float veclen(float *a)
4282 {
4283       float vl;
4284       double tot;
4285 
4286       tot = a[0]*a[0]+a[1]*a[1]+a[2]*a[2];
4287 
4288       vl = 0.0;
4289       if (tot > 0.0) vl = (float) sqrt(tot);
4290 
4291       return(vl);
4292 
4293 }
4294 
dimprod(double * a,double * b,double * c)4295 void dimprod(double *a, double *b, double *c)
4296 {
4297       int i;
4298       double rimp, al, bl;
4299 
4300       rimp = 0.0;
4301 
4302       for (i=0; i<3; i++) rimp = rimp + a[i]*b[i];
4303 
4304       al = dveclen(a);
4305       bl = dveclen(b);
4306 
4307       if (al > 0.0 && bl > 0.0) {
4308          *c = rimp / (al*bl);
4309       } else {
4310          *c = 0.0;
4311       }
4312 
4313 }
4314 
improd(float * a,float * b,double * c)4315 void improd(float *a, float *b, double *c)
4316 {
4317       int i;
4318       float rimp, al, bl;
4319 
4320       rimp = 0.0;
4321 
4322       for (i=0; i<3; i++) rimp = rimp + a[i]*b[i];
4323 
4324       al = veclen(a);
4325       bl = veclen(b);
4326 
4327       if (al > 0.0 && bl > 0.0) {
4328          *c = (double) rimp / (veclen(a)*veclen(b));
4329       } else {
4330          *c = 0.0;
4331       }
4332 
4333 }
4334 
IMPRD(float * a,float * b,float * c,int norm)4335 void IMPRD(float *a, float *b, float *c,int norm)
4336 {
4337       int i;
4338       float rimp, al, bl;
4339 
4340       rimp = 0.0;
4341 
4342       for (i=0; i<3; i++) rimp = rimp + a[i]*b[i];
4343 
4344       al = veclen(a);
4345       bl = veclen(b);
4346 
4347       if (al > 0.0 && bl > 0.0) {
4348 	 if (norm) {
4349             *c = rimp / (veclen(a)*veclen(b));
4350 	 } else {
4351             *c = rimp;
4352 	 }
4353       } else {
4354          *c = 0.0;
4355       }
4356 
4357 }
4358 
vsubt(float * a,float * b,float * c)4359 void vsubt(float *a, float *b, float *c)
4360 {
4361       int i;
4362 
4363       for (i=0; i<3; i++) c[i] = a[i] - b[i];
4364 }
4365 
4366 #ifdef DOGL
4367 static GLXContext cx;
4368 const char *glExtensions;
4369 static int attributeList[] = {GLX_RGBA, GLX_DEPTH_SIZE,16,
4370 GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None};
4371 static GLuint theDens;
4372 static GLfloat gxlx, gyly ;			/* more statics for     */
4373 static GLfloat gstart_xlx, gstart_yly;	/* line drawing		*/
4374 static float CV[6][3] = {
4375   {0.4,0.0,0.0},
4376   {0.0,0.4,0.0},
4377   {0.0,0.0,0.4},
4378   {-0.4,0.0,0.0},
4379   {0.0,-0.4,0.0},
4380   {0.0,0.0,-0.4}
4381 };
4382 void dimprod(double *a, double *b, double *c);
4383 static GLfloat posx = 0.0;
4384 static GLfloat posy = 0.0;
4385 static GLfloat posz = -20.0;
4386 typedef struct {
4387 	GLfloat fogcolor[4];
4388 	GLint fstart;
4389 	GLint fend;
4390 	GLfloat fscale;} FOG;
4391 
4392 static FOG fog;
4393 
4394 static GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0};
4395 static GLfloat gradcol[2][4] = { {0.0, 0.0, 0.9, 1.0}, {1.0, 1.0, 1.0, 1.0}};
4396 static float AxesXYZ[4][3] =
4397 {
4398   {0.0,0.0,0.0},
4399   {1.0,0.0,0.0},
4400   {0.0,1.0,0.0},
4401   {0.0,0.0,1.0}
4402 };
4403 
4404 static int AxesProj[4][2];
4405 
4406 static GLfloat AxesCol[4][4] =
4407 {
4408   {0.0,0.0,0.0,1.0},
4409   {1.0,0.0,0.0,1.0},
4410   {0.0,1.0,0.0,1.0},
4411   {0.0,0.0,1.0,1.0}
4412 };
4413 
4414 static char *AxesStr[] = {"O","X","Y","Z"};
4415 
4416 static int has_shader = 0;
4417 static int has_fbo = 0;
4418 #ifdef GL_COLOR_ATTACHMENT0_EXT
4419 static int fbo_type = GL_RGBA32F_ARB;
4420 #else
4421 static int fbo_type = 4;
4422 #endif
4423 
4424 #define NUM_PROG 13
4425 GLenum program[NUM_PROG];
4426 GLenum vertex_shader[NUM_PROG], fragment_shader[NUM_PROG];
4427 
4428 #define NUM_FBOS 4
4429 struct FBO {
4430         GLuint frame[NUM_FBOS], depth[NUM_FBOS],
4431 	texid[NUM_FBOS],texid1[NUM_FBOS],texid2[NUM_FBOS],texid3[NUM_FBOS];
4432 };
4433 
4434 struct FBO fbo;
4435 
4436 char vertex_shader_source0[] = "\
4437 uniform int doshad;\n\
4438 uniform int dofog;\n\
4439 varying float Blur;\n\
4440 varying vec3 vertex_normal;\n\
4441 varying vec3 eyeVec;\n\
4442 varying vec4 ShadowCoord;\n\
4443 \n\
4444 void main() {\n\
4445 	vertex_normal = normalize(gl_NormalMatrix * gl_Normal).xyz;\n\
4446 	eyeVec = -vec3(gl_ModelViewMatrix * gl_Vertex);\n\
4447 	Blur = clamp(abs(eyeVec.z - 10.0) / 60.0, 0.0, 1.0);\n\
4448 	gl_FrontColor = gl_Color;\n\
4449 	gl_BackColor = gl_Color;\n\
4450 	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n\
4451 	gl_FogFragCoord = abs(eyeVec.z);\n\
4452 	ShadowCoord = vec4(0.0);\n\
4453         vec4 clipVertex = gl_ModelViewMatrix*gl_Vertex;\n\
4454         for (int i = 0; i < 6; i++) {\n\
4455 	    gl_ClipDistance[i] = dot(clipVertex, gl_ClipPlane[i]);\n\
4456 	}\n\
4457 	if (doshad == 1) {\n\
4458 	   ShadowCoord = gl_TextureMatrix[7]*gl_Vertex;\n\
4459 	   gl_FrontColor = gl_Color;\n\
4460 	}\n\
4461 }\n";
4462 
4463 char vertex_shader_source0b[] = "\
4464 #version 130\n\
4465 uniform int doshad;\n\
4466 uniform int dofog;\n\
4467 varying float Blur;\n\
4468 varying vec3 vertex_normal;\n\
4469 varying vec3 eyeVec;\n\
4470 varying vec4 ShadowCoord;\n\
4471 out float gl_ClipDistance[6];\n\
4472 \n\
4473 void main() {\n\
4474 	vertex_normal = normalize(gl_NormalMatrix * gl_Normal).xyz;\n\
4475 	eyeVec = -vec3(gl_ModelViewMatrix * gl_Vertex);\n\
4476 	Blur = clamp(abs(eyeVec.z - 10.0) / 60.0, 0.0, 1.0);\n\
4477 	gl_FrontColor = gl_Color;\n\
4478 	gl_BackColor = gl_Color;\n\
4479 	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n\
4480 	gl_FogFragCoord = abs(eyeVec.z);\n\
4481 	ShadowCoord = vec4(0.0);\n\
4482         vec4 clipVertex = gl_ModelViewMatrix*gl_Vertex;\n\
4483         for (int i = 0; i < 6; i++) {\n\
4484 	    gl_ClipDistance[i] = dot(clipVertex, gl_ClipPlane[i]);\n\
4485 	}\n\
4486 	if (doshad == 1) {\n\
4487 	   ShadowCoord = gl_TextureMatrix[7]*gl_Vertex;\n\
4488 	   gl_FrontColor = gl_Color;\n\
4489 	}\n\
4490 }\n";
4491 
4492 char fragment_shader_source0[] = "\
4493 uniform int colmat;\n\
4494 uniform int dofog;\n\
4495 uniform int doblur;\n\
4496 uniform int dossao;\n\
4497 uniform int dotrns;\n\
4498 uniform int doshad;\n\
4499 uniform sampler2D ShadowMap;\n\
4500 varying vec3 vertex_normal;\n\
4501 varying vec3 eyeVec;\n\
4502 varying float Blur;\n\
4503 varying vec4 ShadowCoord;\n\
4504 vec4 ShadowCoordPostW;\n\
4505 \n\
4506 float chebyshevUpperBound( float distance)\n\
4507 {\n\
4508 	vec2 moments = texture2D(ShadowMap,ShadowCoordPostW.xy).rg;\n\
4509 	float lit = 0.0;\n\
4510 \n\
4511 	if (distance <= moments.x) return 1.0 ;\n\
4512 \n\
4513 	float E_x2 = moments.y;\n\
4514 	float Ex_2 = moments.x*moments.x;\n\
4515 	float vsmEps = 0.00003;\n\
4516 	float litFactor = 0.0;\n\
4517 	if (distance <= moments.x) {\n\
4518 	   litFactor = 1.0;\n\
4519 	}\n\
4520 	float variance = min(max(E_x2-Ex_2,0.0)+vsmEps,1.0);\n\
4521 	variance = max(variance,0.00002);\n\
4522 \n\
4523 	float d = (distance - moments.x)/distance;\n\
4524 	//float p = variance / (variance + d*d);\n\
4525 	float p = variance / (variance + 0.008*abs(d));\n\
4526         lit = max(p, float (distance <= moments.x));\n\
4527 \n\
4528 	//return smoothstep(0.2,1, max(litFactor,p));\n\
4529 	return lit;\n\
4530 }\n\
4531 \n\
4532 void main() {\n\
4533    vec3 lightDir = normalize(vec3(gl_LightSource[2].position));\n\
4534    vec3 eyeVecNormal = normalize(eyeVec);\n\
4535    vec3 reflectVec = normalize(-reflect(lightDir, vertex_normal));\n\
4536    vec3 vnorm = vertex_normal;\n\
4537    if (!gl_FrontFacing) {\n\
4538        vnorm.x = -1.0*vnorm.x;\n\
4539        vnorm.y = -1.0*vnorm.y;\n\
4540        vnorm.z = -1.0*vnorm.z;\n\
4541    }\n\
4542    vec4 diff = gl_LightSource[2].diffuse * max(dot(vnorm,lightDir),0.0);\n\
4543    vec4 specularf = gl_FrontMaterial.specular * pow(max(dot(reflectVec, eyeVecNormal), 0.0), gl_FrontMaterial.shininess);\n\
4544    vec4 specularb = vec4(0.0,0.0,0.0,0.0);\n\
4545 \n\
4546    vec4 fcolor;\n\
4547    vec4 Colb;\n\
4548    vec4 Colf;\n\
4549    if (doshad == 1) {\n\
4550    ShadowCoordPostW = ShadowCoord / ShadowCoord.w;\n\
4551    ShadowCoordPostW.z += 0.00005;\n\
4552    }\n\
4553    float fogFactor = (gl_Fog.end-gl_FogFragCoord)*gl_Fog.scale;\n\
4554    if (colmat == 1) {\n\
4555 	if (dossao == 1) {\n\
4556 	   fcolor = gl_Color*(gl_LightSource[2].ambient+diff);\n\
4557 	} else {\n\
4558 	   fcolor = gl_Color*(gl_LightSource[2].ambient+diff+specularf);\n\
4559 	}\n\
4560 	if (dotrns == 1) {\n\
4561 	   fcolor.w = 0.6;\n\
4562 	} else {\n\
4563 	   fcolor.w = gl_FrontMaterial.diffuse.w;\n\
4564 	}\n\
4565    } else { \n\
4566 	vec4 ambientf = gl_LightSource[2].ambient * gl_FrontMaterial.ambient;\n\
4567 	vec4 diffusef = diff * gl_FrontMaterial.diffuse;\n\
4568 	reflectVec = normalize(-reflect(lightDir, -vnorm));\n\
4569 	vec4 ambientb = gl_LightSource[2].ambient * gl_BackMaterial.ambient;\n\
4570 	specularb = gl_BackMaterial.specular * pow(max(dot(reflectVec, eyeVecNormal), 0.0), gl_BackMaterial.shininess);\n\
4571 	vec4 diffuseb= gl_LightSource[2].diffuse * max(dot(-vnorm,lightDir),0.0) * gl_BackMaterial.diffuse;\n\
4572 \n\
4573 	if (dossao == 1) {\n\
4574 	   //vec4 Colb = ambientb + specularb + diffuseb;\n\
4575 	   //vec4 Colf = ambientf + specularf + diffusef;\n\
4576 	   Colb = ambientb + diffuseb;\n\
4577 	   Colf = ambientf + diffusef;\n\
4578 	   fcolor = (Colb + Colf);\n\
4579 	} else {\n\
4580 	   Colb = ambientb + specularb + diffuseb;\n\
4581 	   Colf = ambientf + specularf + diffusef;\n\
4582 	   fcolor = (Colb + Colf);\n\
4583 	}\n\
4584    } \n\
4585 \n\
4586    float shadow = 1.0;\n\
4587    if (doshad == 1) {\n\
4588        shadow = chebyshevUpperBound(ShadowCoordPostW.z);\n\
4589        if (shadow < 0.5) shadow = 0.5;\n\
4590    }\n\
4591    gl_FragData[1] = vec4(shadow)*fcolor;\n\
4592    gl_FragData[2] = (specularb+specularf);\n\
4593 \n\
4594    if (dofog == 1) {\n\
4595       fcolor = mix(gl_Fog.color, vec4(shadow)*fcolor, fogFactor);\n\
4596       gl_FragData[2].w = fogFactor;\n\
4597    }\n\
4598 \n\
4599    gl_FragData[0] = vec4(shadow)*fcolor;\n\
4600 \n\
4601    if (doblur == 1) {\n\
4602       gl_FragData[0].a = Blur;\n\
4603    }\n\
4604    \n\
4605 }\n";
4606 
4607 char vertex_shader_source1[] = "\
4608 \n\
4609 void main(void)\n\
4610 {\n\
4611 	gl_Position = ftransform();\n\
4612 	gl_TexCoord[0] = gl_MultiTexCoord0;\n\
4613 }\n";
4614 
4615 char fragment_shader_source1[] = "\
4616 uniform sampler2D gdepth;\n\
4617 uniform int dofog;\n\
4618 uniform int Width;\n\
4619 uniform int Height;\n\
4620 uniform int ssaotyp;\n\
4621 \n\
4622 #define PI 3.14159265\n\
4623 \n\
4624 float near = 1.0; //Z-near\n\
4625 float far = 600.0; //Z-far\n\
4626 int samples;\n\
4627 int rings;\n\
4628 \n\
4629 vec2 texCoord = gl_TexCoord[0].st;\n\
4630 \n\
4631 vec2 rand(in vec2 coord) {\n\
4632    float noiseX = (fract(sin(dot(coord ,vec2(12.9898,78.233))) * 43758.5453));\n\
4633    float noiseY = (fract(sin(dot(coord ,vec2(12.9898,78.233)*2.0)) * 43758.5453));\n\
4634    if (ssaotyp == 1) {\n\
4635       return vec2(noiseX,noiseY)*0.0004;\n\
4636    } else {\n\
4637       return vec2(noiseX,noiseY)*0.004;\n\
4638    }\n\
4639 }\n\
4640 \n\
4641 float LinearizeDepth(vec2 uv) {\n\
4642   float z = texture2D(gdepth, uv).x;\n\
4643   return (2.0 * near) / (far + near - z * (far - near));\n\
4644 }\n\
4645 \n\
4646 float compareDepths( in float depth1, in float depth2 ) {\n\
4647    float aoCap = 1.0;\n\
4648    float aoMultiplier = 150.0;\n\
4649    float depthTolerance = 0.0000;\n\
4650    float aorange = 600.0;\n\
4651    float diff = sqrt(clamp(1.0-(depth1-depth2) / (aorange/(far-near)),0.0,1.0));\n\
4652    float ao = min(aoCap,max(0.0,depth1-depth2-depthTolerance) * aoMultiplier) * diff;\n\
4653    if (ssaotyp != 1) {\n\
4654 	if (diff < 0.9) ao = 0.0;\n\
4655    }\n\
4656    return ao;\n\
4657 }\n\
4658 \n\
4659 void main(void)\n\
4660 {\n\
4661    float depth = LinearizeDepth(texCoord);\n\
4662    float d;\n\
4663    float aspect = float(Width)/float(Height);\n\
4664    vec2 noise = rand(texCoord);\n\
4665    float nmul = 1.0;\n\
4666    samples = 6;\n\
4667    rings = 6;\n\
4668    if (ssaotyp == 0) nmul = 20.0;\n\
4669    if (ssaotyp == 0) samples = 3;\n\
4670 \n\
4671    float w = (1.0 / float(Width))/clamp(depth,0.05,1.0)+nmul*(noise.x*(1.0-noise.x));\n\
4672    float h = (1.0 / float(Height))/clamp(depth,0.05,1.0)+nmul*(noise.y*(1.0-noise.y));\n\
4673 \n\
4674    float pw;\n\
4675    float ph;\n\
4676    float ao;\n\
4677    float s = 0.0;\n\
4678 \n\
4679    for (int i = -rings ; i < rings; i += 1) {\n\
4680       for (int j = -samples ; j < samples; j += 1) {\n\
4681 	float step = PI*2.0 / float(samples*i);\n\
4682 	pw = (cos(float(j)*step)*float(i));\n\
4683 	ph = (sin(float(j)*step)*float(i))*aspect;\n\
4684 	d = LinearizeDepth(vec2(texCoord.s+pw*w,texCoord.t+ph*h));\n\
4685 	ao += compareDepths(depth,d);\n\
4686 	s += 1.0;\n\
4687       }\n\
4688    }\n\
4689 \n\
4690    ao /= s;\n\
4691    ao = 1.0-ao;\n\
4692 \n\
4693    gl_FragColor = vec4(ao,ao,ao,1.0);\n\
4694 }\n";
4695 
4696 char vertex_shader_source2[] = "\
4697 void main(void)\n\
4698 {\n\
4699 	gl_Position = ftransform();\n\
4700 	gl_TexCoord[0] = gl_MultiTexCoord0;\n\
4701 }\n";
4702 
4703 char fragment_shader_source2[] = "\
4704 uniform sampler2D Tex0;\n\
4705 \n\
4706 void main (void)\n\
4707 {\n\
4708 	gl_FragData[0] = texture2D(Tex0, gl_TexCoord[0].st);\n\
4709 	//gl_FragData[0] = vec4(texture2D(Tex0, gl_TexCoord[0].st).rgb, Blur);\n\
4710 }\n";
4711 
4712 char vertex_shader_source3[] = "\
4713 varying vec2 Tap[4], TapNeg[3];\n\
4714 uniform int Width;\n\
4715 \n\
4716 void main(void)\n\
4717 {\n\
4718 	vec2 horzTapOffs[7];\n\
4719 	vec2 TexCoord = gl_MultiTexCoord0.st;\n\
4720 \n\
4721 	float dx = 1.0/float(Width);\n\
4722 	horzTapOffs[0] = vec2(0.0, 0.0);\n\
4723 	horzTapOffs[1] = vec2(1.3366 * dx, 0.0);\n\
4724 	horzTapOffs[2] = vec2(3.4295 * dx, 0.0);\n\
4725 	horzTapOffs[3] = vec2(5.4264 * dx, 0.0);\n\
4726 	horzTapOffs[4] = vec2(7.4359 * dx, 0.0);\n\
4727 	horzTapOffs[5] = vec2(9.4436 * dx, 0.0);\n\
4728 	horzTapOffs[6] = vec2(11.4401 * dx, 0.0);\n\
4729 \n\
4730 	Tap[0] = TexCoord;\n\
4731 	Tap[1] = TexCoord + horzTapOffs[1];\n\
4732 	Tap[2] = TexCoord + horzTapOffs[2];\n\
4733 	Tap[3] = TexCoord + horzTapOffs[3];\n\
4734 \n\
4735 	TapNeg[0] = TexCoord - horzTapOffs[1];\n\
4736 	TapNeg[1] = TexCoord - horzTapOffs[2];\n\
4737 	TapNeg[2] = TexCoord - horzTapOffs[3];\n\
4738 \n\
4739 	gl_Position = ftransform();\n\
4740 	gl_TexCoord[0] = gl_MultiTexCoord0;\n\
4741 }\n";
4742 
4743 char fragment_shader_source3[] = "\
4744 varying vec2 Tap[4], TapNeg[3];\n\
4745 uniform sampler2D Tex0;\n\
4746 uniform int Width;\n\
4747 \n\
4748 void main (void)\n\
4749 {\n\
4750 	vec2 horzTapOffs[7];\n\
4751 	vec2 Tap4[3], TapNeg4[3];\n\
4752 \n\
4753 	// Thresholds for computing sample weights\n\
4754 	const vec4 Thresh0 = vec4(0.1, 0.3, 0.5, -0.01);\n\
4755 	const vec4 Thresh1 = vec4(0.6, 0.7, 0.8, 0.9);\n\
4756 \n\
4757 	// Samples\n\
4758 	vec4 s[7], Weights4;\n\
4759 	vec3 Weights3, ColorSum;\n\
4760 	float WeightSum;\n\
4761 \n\
4762 	float dx = 1.0/float(Width);\n\
4763 	horzTapOffs[0] = vec2(0.0, 0.0);\n\
4764 	horzTapOffs[1] = vec2(1.3366 * dx, 0.0);\n\
4765  	horzTapOffs[2] = vec2(3.4295 * dx, 0.0);\n\
4766 	horzTapOffs[3] = vec2(5.4264 * dx, 0.0);\n\
4767 	horzTapOffs[4] = vec2(7.4359 * dx, 0.0);\n\
4768 	horzTapOffs[5] = vec2(9.4436 * dx, 0.0);\n\
4769 	horzTapOffs[6] = vec2(11.4401 * dx, 0.0);\n\
4770 \n\
4771 \n\
4772 	// Sample taps with coordinates from VS\n\
4773 	s[0] = texture2D(Tex0, Tap[0]);\n\
4774 	s[1] = texture2D(Tex0, Tap[1]);\n\
4775 	s[2] = texture2D(Tex0, Tap[2]);\n\
4776 	s[3] = texture2D(Tex0, Tap[3]);\n\
4777 	s[4] = texture2D(Tex0, TapNeg[0]);\n\
4778 	s[5] = texture2D(Tex0, TapNeg[1]);\n\
4779 	s[6] = texture2D(Tex0, TapNeg[2]);\n\
4780 \n\
4781 	// Compute weights for 4 first samples (including center tap)\n\
4782 	// by thresholding blurriness (in sample alpha)\n\
4783 	Weights4.x = clamp(s[1].a - Thresh0.x, 0.0, 1.0);\n\
4784 	Weights4.y = clamp(s[2].a - Thresh0.y, 0.0, 1.0);\n\
4785 	Weights4.z = clamp(s[3].a - Thresh0.x, 0.0, 1.0);\n\
4786 	Weights4.w = clamp(s[0].a - Thresh0.w, 0.0, 1.0);\n\
4787 \n\
4788 	// Accumulate weighted samples\n\
4789 	ColorSum = vec3(s[0] * Weights4.x + s[1] * Weights4.y + s[2] * Weights4.z + s[3] * Weights4.w);\n\
4790 \n\
4791 	// Sum weights using DOT\n\
4792 	WeightSum = dot(Weights4, vec4(1.0));\n\
4793 \n\
4794 	// Compute weights for 3 remaining samples\n\
4795 	Weights3.x = clamp(s[4].a - Thresh0.x, 0.0, 1.0);\n\
4796 	Weights3.y = clamp(s[5].a - Thresh0.y, 0.0, 1.0);\n\
4797 	Weights3.z = clamp(s[6].a - Thresh0.z, 0.0, 1.0);\n\
4798 \n\
4799 	// Accumulate weighted samples\n\
4800 	ColorSum += vec3(s[4] * Weights3.x + s[4] * Weights3.y + s[6] * Weights3.z);\n\
4801 \n\
4802 	// Sum weights using DOT\n\
4803 	WeightSum += dot(Weights3, vec3(1.0));\n\
4804 \n\
4805 	// Compute tex coords for other taps\n\
4806 	Tap4[0] = Tap[0] + horzTapOffs[4];\n\
4807 	Tap4[1] = Tap[0] + horzTapOffs[5];\n\
4808 	Tap4[2] = Tap[0] + horzTapOffs[6];\n\
4809 	TapNeg4[0] = Tap[0] - horzTapOffs[4];\n\
4810 	TapNeg4[1] = Tap[0] - horzTapOffs[5];\n\
4811 	TapNeg4[2] = Tap[0] - horzTapOffs[6];\n\
4812 \n\
4813 	// Sample the taps\n\
4814 	s[0] = texture2D(Tex0, Tap4[0]);\n\
4815 	s[1] = texture2D(Tex0, Tap4[1]);\n\
4816 	s[2] = texture2D(Tex0, Tap4[2]);\n\
4817 	s[3] = texture2D(Tex0, TapNeg4[0]);\n\
4818 	s[4] = texture2D(Tex0, TapNeg4[1]);\n\
4819 	s[5] = texture2D(Tex0, TapNeg4[2]);\n\
4820 \n\
4821 	// Compute weights for 3 samples\n\
4822 	Weights3.x = clamp(s[0].a - Thresh1.x, 0.0, 1.0);\n\
4823 	Weights3.y = clamp(s[1].a - Thresh1.y, 0.0, 1.0);\n\
4824 	Weights3.z = clamp(s[2].a - Thresh1.z, 0.0, 1.0);\n\
4825 	\n\
4826 	// Accumulate weighted samples\n\
4827 	ColorSum += vec3(s[0] * Weights3.x + s[1] * Weights3.y + s[2] * Weights3.z);\n\
4828 \n\
4829 	// Sum weights using DOT\n\
4830 	WeightSum += dot(Weights3, vec3(1.0));\n\
4831 \n\
4832 	// Compute weights for 3 samples\n\
4833 	Weights3.x = clamp(s[3].a - Thresh1.x, 0.0, 1.0);\n\
4834 	Weights3.y = clamp(s[4].a - Thresh1.y, 0.0, 1.0);\n\
4835 	Weights3.z = clamp(s[5].a - Thresh1.z, 0.0, 1.0);\n\
4836 \n\
4837 	// Accumulate weighted samples\n\
4838 	ColorSum += vec3(s[3] * Weights3.x + s[4] * Weights3.y + s[5] * Weights3.z);\n\
4839 \n\
4840 	// Sum weights using DOT\n\
4841 	WeightSum += dot(Weights3, vec3(1.0));\n\
4842 \n\
4843 	// Divide weighted sum of samples by sum of all weights\n\
4844 	ColorSum /= WeightSum;\n\
4845 	WeightSum = clamp(WeightSum,0.0,1.0);\n\
4846 \n\
4847 	// Color and weights sum output\n\
4848 	gl_FragData[0] = vec4(ColorSum, WeightSum);\n\
4849 }\n";
4850 
4851 char vertex_shader_source4[] = "\
4852 varying vec2 Tap[4], TapNeg[3];\n\
4853 uniform int Height;\n\
4854 \n\
4855 void main(void)\n\
4856 {\n\
4857 	vec2 vertTapOffs[7];\n\
4858 	vec2 TexCoord = gl_MultiTexCoord0.st;\n\
4859 \n\
4860 	float dy = 1.0/float(Height);\n\
4861 	vertTapOffs[0] = vec2(0.0, 0.0);\n\
4862 	vertTapOffs[1] = vec2(0.0, 1.3366 * dy);\n\
4863 	vertTapOffs[2] = vec2(0.0, 3.4295 * dy);\n\
4864 	vertTapOffs[3] = vec2(0.0, 5.4264 * dy);\n\
4865 	vertTapOffs[4] = vec2(0.0, 7.4359 * dy);\n\
4866 	vertTapOffs[5] = vec2(0.0, 9.4436 * dy);\n\
4867 	vertTapOffs[6] = vec2(0.0, 11.4401 * dy);\n\
4868 \n\
4869 	Tap[0] = TexCoord;\n\
4870 	Tap[1] = TexCoord + vertTapOffs[1];\n\
4871 	Tap[2] = TexCoord + vertTapOffs[2];\n\
4872 	Tap[3] = TexCoord + vertTapOffs[3];\n\
4873 \n\
4874 	TapNeg[0] = TexCoord - vertTapOffs[1];\n\
4875 	TapNeg[1] = TexCoord - vertTapOffs[2];\n\
4876 	TapNeg[2] = TexCoord - vertTapOffs[3];\n\
4877 \n\
4878 	gl_Position = ftransform();\n\
4879 	gl_TexCoord[0] = gl_MultiTexCoord0;\n\
4880 }\n";
4881 
4882 char fragment_shader_source4[] = "\
4883 varying vec2 Tap[4], TapNeg[3];\n\
4884 uniform sampler2D Tex0;\n\
4885 uniform int Height;\n\
4886 \n\
4887 void main (void)\n\
4888 {\n\
4889 	vec2 vertTapOffs[7];\n\
4890 	vec2 Tap4[3], TapNeg4[3];\n\
4891 \n\
4892 	const vec4 Weights0 = vec4(0.080, 0.075, 0.070, 0.100);\n\
4893 	const vec4 Weights1 = vec4(0.065, 0.060, 0.055, 0.050);\n\
4894 \n\
4895 	// Samples\n\
4896 	vec4 s[7];\n\
4897 	// Acumulated color and weights\n\
4898 	vec4 ColorWeightSum;\n\
4899 \n\
4900 	float dy = 1.0/float(Height);\n\
4901 	vertTapOffs[0] = vec2(0.0, 0.0);\n\
4902 	vertTapOffs[1] = vec2(0.0, 1.3366 * dy);\n\
4903 	vertTapOffs[2] = vec2(0.0, 3.4295 * dy);\n\
4904 	vertTapOffs[3] = vec2(0.0, 5.4264 * dy);\n\
4905 	vertTapOffs[4] = vec2(0.0, 7.4359 * dy);\n\
4906 	vertTapOffs[5] = vec2(0.0, 9.4436 * dy);\n\
4907 	vertTapOffs[6] = vec2(0.0, 11.4401 * dy);\n\
4908 \n\
4909 \n\
4910 	// Sample taps with coordinates from VS\n\
4911 	s[0] = texture2D(Tex0, Tap[0]);\n\
4912 	s[1] = texture2D(Tex0, Tap[1]);\n\
4913 	s[2] = texture2D(Tex0, Tap[2]);\n\
4914 	s[3] = texture2D(Tex0, Tap[3]);\n\
4915 	s[4] = texture2D(Tex0, TapNeg[0]);\n\
4916 	s[5] = texture2D(Tex0, TapNeg[1]);\n\
4917 	s[6] = texture2D(Tex0, TapNeg[2]);\n\
4918 \n\
4919 	// Modulate sampled color values by the weights stored\n\
4920 	// in the alpha channel of each sample\n\
4921 	s[0].rgb = s[0].rgb * s[0].a;\n\
4922 	s[1].rgb = s[1].rgb * s[1].a;\n\
4923 	s[2].rgb = s[2].rgb * s[2].a;\n\
4924 	s[3].rgb = s[3].rgb * s[3].a;\n\
4925 	s[4].rgb = s[4].rgb * s[4].a;\n\
4926 	s[5].rgb = s[5].rgb * s[5].a;\n\
4927 	s[6].rgb = s[6].rgb * s[6].a;\n\
4928 \n\
4929 	// Aggregate all samples weighting them with pre-defined\n\
4930 	// kernel weights, weight sum in alpha\n\
4931 	ColorWeightSum = s[0] * Weights0.w +\n\
4932       (s[1] + s[4]) * Weights0.x +\n\
4933       (s[2] + s[5]) * Weights0.y +\n\
4934       (s[3] + s[6]) * Weights0.z;\n\
4935 \n\
4936 	// Compute tex coords for other taps\n\
4937 	Tap4[0] = Tap[0] + vertTapOffs[4];\n\
4938 	Tap4[1] = Tap[0] + vertTapOffs[5];\n\
4939 	Tap4[2] = Tap[0] + vertTapOffs[6];\n\
4940 	TapNeg4[0] = Tap[0] - vertTapOffs[4];\n\
4941 	TapNeg4[1] = Tap[0] - vertTapOffs[5];\n\
4942 	TapNeg4[2] = Tap[0] - vertTapOffs[6];\n\
4943 \n\
4944 	// Sample the taps\n\
4945 	s[0] = texture2D(Tex0, Tap4[0]);\n\
4946 	s[1] = texture2D(Tex0, Tap4[1]);\n\
4947 	s[2] = texture2D(Tex0, Tap4[2]);\n\
4948 	s[3] = texture2D(Tex0, TapNeg4[0]);\n\
4949 	s[4] = texture2D(Tex0, TapNeg4[1]);\n\
4950 	s[5] = texture2D(Tex0, TapNeg4[2]);\n\
4951 \n\
4952 	// Modulate sampled color values by the weights stored\n\
4953 	// in the alpha channel of each sample\n\
4954 	s[0].rgb = s[0].rgb * s[0].a;\n\
4955 	s[1].rgb = s[1].rgb * s[1].a;\n\
4956 	s[2].rgb = s[2].rgb * s[2].a;\n\
4957 	s[3].rgb = s[3].rgb * s[3].a;\n\
4958 	s[4].rgb = s[4].rgb * s[4].a;\n\
4959 	s[5].rgb = s[5].rgb * s[5].a;\n\
4960 \n\
4961 	 // Aggregate all samples weighting them with pre-defined\n\
4962 	// kernel weights, weight sum in alpha\n\
4963 	ColorWeightSum += (s[1] + s[3]) * Weights1.x +\n\
4964       (s[1] + s[4]) * Weights1.y +\n\
4965       (s[2] + s[5]) * Weights1.z;\n\
4966 \n\
4967 	// Average combined sample for all samples in the kernel\n\
4968 	ColorWeightSum.rgb /= ColorWeightSum.a;\n\
4969 \n\
4970 	// Final sum output\n\
4971 	gl_FragData[0] = ColorWeightSum;\n\
4972 }\n";
4973 
4974 char vertex_shader_source5[] = "\
4975 void main(void)\n\
4976 {\n\
4977 	gl_Position = ftransform();\n\
4978 	gl_TexCoord[0] = gl_MultiTexCoord0;\n\
4979 	gl_TexCoord[1] = gl_MultiTexCoord1;\n\
4980 }\n";
4981 
4982 char fragment_shader_source5[] = "\
4983 uniform sampler2D Tex0, Tex1;\n\
4984 \n\
4985 void main (void)\n\
4986 {\n\
4987 	vec4 Fullres = texture2D(Tex0, gl_TexCoord[0].st);\n\
4988 	vec4 Blurred = texture2D(Tex1, gl_TexCoord[1].st);\n\
4989 \n\
4990 	// HLSL linear interpolation function\n\
4991 	gl_FragData[0] = Fullres + Fullres.a * (Blurred - Fullres);\n\
4992 }\n";
4993 
4994 
4995 char vertex_shader_source6[] = "\
4996 void main(void)\n\
4997 {\n\
4998 	gl_Position = ftransform();\n\
4999 	gl_TexCoord[0] = gl_MultiTexCoord0;\n\
5000 }\n";
5001 
5002 char fragment_shader_source6[] = "\
5003 uniform sampler2D Tex0;\n\
5004 \n\
5005 void main (void)\n\
5006 {\n\
5007 	vec4 colorMap = texture2D(Tex0, gl_TexCoord[0].st);\n\
5008 	gl_FragColor = colorMap;\n\
5009 }\n";
5010 
5011 char vertex_shader_source7[] = "\
5012 \n\
5013 varying vec4 v_position;\n\
5014 void main(void)\n\
5015 {\n\
5016 	gl_Position = ftransform();\n\
5017 	v_position = gl_Position;\n\
5018 	gl_TexCoord[0] = gl_MultiTexCoord0;\n\
5019 }\n";
5020 
5021 char fragment_shader_source7[] = "\
5022 uniform sampler2D gnormals;\n\
5023 uniform sampler2D gdepth;\n\
5024 uniform sampler2D gdiffuse;\n\
5025 uniform sampler2D grandom;\n\
5026 \n\
5027 float LinearizeDepth(vec2 uv) {\n\
5028   float n = 1.0;\n\
5029   float f = 100.0;\n\
5030   float z = texture2D(gdepth, uv).x;\n\
5031   return (2.0 * n) / (f + n - z * (f - n));\n\
5032 }\n\
5033 \n\
5034 vec3 readNormal(vec2 coord) {\n\
5035    vec3 v1 = vec3(1.0);\n\
5036    vec3 vout = normalize(texture2D(gnormals, coord).stp*2.0  - v1);  \n\
5037    return vout;\n\
5038 }\n\
5039 \n\
5040 vec3 posFromDepth(vec2 coord) {\n\
5041    float d = texture2D(gdepth, coord).r;\n\
5042    vec3 tray = vec3(gl_ProjectionMatrixInverse*\n\
5043 	vec4((coord.x-0.5)*2.0,(coord.y-0.5)*2.0,1.0,0.0));\n\
5044    return tray*d;\n\
5045 }\n\
5046 \n\
5047 //Ambient Occlusion form factor:    \n\
5048 \n\
5049 float aoFF(in vec3 ddiff,in vec3 cnorm, in float c1, in float c2) {\n\
5050    vec3 vv = normalize(ddiff);\n\
5051    float rd = length(ddiff);\n\
5052    return (1.0-\n\
5053 	clamp(dot(readNormal(gl_TexCoord[0].st+vec2(c1,c2)),-vv),0.0,1.0)) *\n\
5054 	clamp(dot(cnorm,vv),0.0,1.0)*(1.0 - 1.0/sqrt(1.0/(rd*rd) + 1.0));\n\
5055 }\n\
5056 \n\
5057 //GI form factor:    \n\
5058 \n\
5059 float giFF(vec3 ddiff, vec3 cnorm, float c1, float c2) {\n\
5060    vec3 vv = normalize(ddiff);\n\
5061    float rd = length(ddiff);\n\
5062    return 1.0*\n\
5063 	clamp(dot(readNormal(gl_TexCoord[0].st+vec2(c1,c2)),-vv),0.0,1.0)*\n\
5064 	clamp(dot(cnorm,vv),0.0,1.0)/ (rd*rd+1.0);\n\
5065 }\n\
5066 \n\
5067 void main() {\n\
5068 \n\
5069     //read current normal,position and color.\n\
5070 \n\
5071     vec3 n = readNormal(gl_TexCoord[0].st);\n\
5072     vec3 p = posFromDepth(gl_TexCoord[0].st);\n\
5073     vec3 col = vec3(texture2D(gdiffuse, gl_TexCoord[0].st));\n\
5074 \n\
5075     //randomization texture\n\
5076 \n\
5077     vec2 fres = vec2(800.0/64.0*5.0,800.0/64.0*5.0);\n\
5078     vec3 random = vec3(texture2D(grandom, gl_TexCoord[0].st*fres.xy));\n\
5079     random = random*2.0-vec3(1.0);\n\
5080 \n\
5081     //initialize variables:\n\
5082 \n\
5083     float ao = 0.0;\n\
5084     vec3 gi = vec3(0.0,0.0,0.0);\n\
5085     float incx = 1.0/800.0*0.1;\n\
5086     float incy = 1.0/800.0*0.1;\n\
5087     float pw = incx;\n\
5088     float ph = incy;\n\
5089     float cdepth = LinearizeDepth(gl_TexCoord[0].st);\n\
5090 \n\
5091     for (float i=0.0; i<3.0; ++i) {\n\
5092 \n\
5093        float npw = (pw+0.0007*random.x)/cdepth;\n\
5094        float nph = (ph+0.0007*random.y)/cdepth;\n\
5095 \n\
5096        vec3 ddiff  = posFromDepth(gl_TexCoord[0].st+vec2(npw,nph))-p;\n\
5097        vec3 ddiff2 = posFromDepth(gl_TexCoord[0].st+vec2(npw,-nph))-p;\n\
5098        vec3 ddiff3 = posFromDepth(gl_TexCoord[0].st+vec2(-npw,nph))-p;\n\
5099        vec3 ddiff4 = posFromDepth(gl_TexCoord[0].st+vec2(-npw,-nph))-p;\n\
5100        vec3 ddiff5 = posFromDepth(gl_TexCoord[0].st+vec2(0.0,nph))-p;\n\
5101        vec3 ddiff6 = posFromDepth(gl_TexCoord[0].st+vec2(0.0,-nph))-p;\n\
5102        vec3 ddiff7 = posFromDepth(gl_TexCoord[0].st+vec2(npw,0.0))-p;\n\
5103        vec3 ddiff8 = posFromDepth(gl_TexCoord[0].st+vec2(-npw,0.0))-p;\n\
5104 \n\
5105        ao+=  aoFF(ddiff ,n,npw,nph);\n\
5106        ao+=  aoFF(ddiff2,n,npw,-nph);\n\
5107        ao+=  aoFF(ddiff3,n,-npw,nph);\n\
5108        ao+=  aoFF(ddiff4,n,-npw,-nph);\n\
5109        ao+=  aoFF(ddiff5,n,0.0,nph);\n\
5110        ao+=  aoFF(ddiff6,n,0.0,-nph);\n\
5111        ao+=  aoFF(ddiff7,n,npw,0.0);\n\
5112        ao+=  aoFF(ddiff8,n,-npw,0.0);\n\
5113 \n\
5114        gi+=  giFF(ddiff,n,npw,nph)*\n\
5115 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(npw,nph)).rgb;\n\
5116        gi+=  giFF(ddiff2,n,npw,-nph)*\n\
5117 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(npw,-nph)).rgb;\n\
5118        gi+=  giFF(ddiff3,n,-npw,nph)*\n\
5119 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(-npw,nph)).rgb;\n\
5120        gi+=  giFF(ddiff4,n,-npw,-nph)*\n\
5121 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(-npw,-nph)).rgb;\n\
5122        gi+=  giFF(ddiff5,n,0.0,nph)*\n\
5123 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(0.0,nph)).rgb;\n\
5124        gi+=  giFF(ddiff6,n,0.0,-nph)*\n\
5125 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(0.0,-nph)).rgb;\n\
5126        gi+=  giFF(ddiff7,n,npw,0.0)*\n\
5127 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(npw,0.0)).rgb;\n\
5128        gi+=  giFF(ddiff8,n,-npw,0.0)*\n\
5129 		texture2D(gdiffuse, gl_TexCoord[0].st+vec2(-npw,0.0)).rgb;\n\
5130 \n\
5131        //increase sampling area:\n\
5132 \n\
5133        pw += incx;\n\
5134        ph += incy;\n\
5135     }\n\
5136     ao/=24.0;\n\
5137     gi/=24.0;\n\
5138 \n\
5139     //gl_FragColor = vec4(col-vec3(ao)+gi*5.0,1.0);\n\
5140     gl_FragColor = vec4(col-vec3(ao),1.0);\n\
5141 }\n";
5142 
5143 char fragment_shader_source8[] = "\
5144 uniform sampler2D sampler0;\n\
5145 uniform int width;\n\
5146 uniform int height;\n\
5147 \n\
5148 void main(void)\n\
5149 {\n\
5150     vec2 tc_offset[9];\n\
5151     vec4 sample[9];\n\
5152     float xinc,yinc;\n\
5153 \n\
5154     xinc = 1.0/float(width);\n\
5155     yinc = 1.0/float(height);\n\
5156     for (int i = 0; i < 2; i++) {\n\
5157 	for (int j = 0; j < 2; j++) {\n\
5158 	   tc_offset[(i*3)+j] = \n\
5159 		vec2((float(i)-1.0)*xinc,(float(j)-1.0)*yinc);\n\
5160 	}\n\
5161     }\n\
5162     for (int i = 0; i < 9; i++) {\n\
5163         sample[i] = texture2D(sampler0,\n\
5164                               gl_TexCoord[0].st + tc_offset[i]);\n\
5165     }\n\
5166 \n\
5167     gl_FragColor = (sample[0] + (2.0*sample[1]) + sample[2] + \n\
5168                     (2.0*sample[3]) + sample[4] + (2.0*sample[5]) + \n\
5169                     sample[6] + (2.0*sample[7]) + sample[8]) / 13.0;\n\
5170 }\n";
5171 
5172 char fragment_shader_source9[] = "\
5173 uniform sampler2D gcolor;\n\
5174 uniform sampler2D glum;\n\
5175 uniform sampler2D aotex;\n\
5176 uniform int dofog;\n\
5177 vec2 texCoord = gl_TexCoord[0].st;\n\
5178 void main(void)\n\
5179 {\n\
5180    float fogFactor = texture2D(glum,texCoord).w;\n\
5181    vec3 color = texture2D(gcolor,texCoord).rgb;\n\
5182    vec3 luminance = texture2D(glum,texCoord).rgb;\n\
5183    vec3 ao = texture2D(aotex,texCoord).rgb;\n\
5184    vec4 fcolor = vec4(color*ao+luminance,1.0);\n\
5185    if (dofog == 1) {\n\
5186 	fcolor = mix(gl_Fog.color, fcolor, fogFactor);\n\
5187    }\n\
5188    gl_FragColor = fcolor;\n\
5189 }\n";
5190 
5191 char vertex_shader_source10[] = "\
5192 varying vec4 ShadowCoord;\n\
5193 \n\
5194 void main()\n\
5195 {\n\
5196         ShadowCoord = gl_TextureMatrix[7] * gl_Vertex;\n\
5197         gl_Position = ftransform();\n\
5198         gl_FrontColor = gl_Color;\n\
5199 }\n";
5200 
5201 char fragment_shader_source10[] = "\
5202 uniform sampler2D ShadowMap;\n\
5203 varying vec4 ShadowCoord;\n\
5204 vec4 ShadowCoordPostW;\n\
5205 \n\
5206 float chebyshevUpperBound( float distance)\n\
5207 {\n\
5208 	vec2 moments = texture2D(ShadowMap,ShadowCoordPostW.xy).rg;\n\
5209 	float lit = 0.0;\n\
5210 \n\
5211 	if (distance <= moments.x) return 1.0 ;\n\
5212 \n\
5213 	float variance = moments.y - (moments.x*moments.x);\n\
5214 	//variance = max(variance,0.00002);\n\
5215 	variance = max(variance,0.02);\n\
5216 \n\
5217 	float d = distance - moments.x;\n\
5218 	float p_max = variance / (variance + d*d);\n\
5219         lit = max(p_max, float (distance <= moments.x));\n\
5220 \n\
5221 	return lit;\n\
5222 }\n\
5223 \n\
5224 void main()\n\
5225 {\n\
5226 	ShadowCoordPostW = ShadowCoord / ShadowCoord.w;\n\
5227 	float shadow = chebyshevUpperBound(ShadowCoordPostW.z);\n\
5228 	gl_FragColor = vec4(shadow ) *gl_Color;\n\
5229 }\n";
5230 
5231 char vertex_shader_source11[] = "\
5232 varying vec4 v_position;\n\
5233 \n\
5234 void main()\n\
5235 {\n\
5236 	gl_Position = ftransform();\n\
5237 	v_position = gl_Position;\n\
5238 }\n";
5239 
5240 char fragment_shader_source11[] = "\
5241 varying vec4 v_position;\n\
5242 \n\
5243 void main()\n\
5244 {\n\
5245 	float depth = v_position.z / v_position.w;\n\
5246 	depth = depth * 0.5 + 0.5;\n\
5247 	float moment1 = depth;\n\
5248 	float moment2 = depth * depth;\n\
5249 	float dx = dFdx(depth);\n\
5250 	float dy = dFdy(depth);\n\
5251 	moment2 += 0.25*(dx*dx+dy*dy);\n\
5252 	//moment2 += (dx*dx+dy*dy);\n\
5253 \n\
5254 	gl_FragColor = vec4( moment1,moment2, 0.0, 0.0 );\n\
5255 }\n";
5256 
5257 char vertex_shader_source12[] = "\
5258 \n\
5259 void main()\n\
5260 {\n\
5261 	gl_Position = ftransform();\n\
5262 	gl_TexCoord[0] =  gl_MultiTexCoord0;\n\
5263 }\n";
5264 
5265 char fragment_shader_source12[] = "\
5266 uniform int width;\n\
5267 uniform int height;\n\
5268 uniform sampler2D tex;\n\
5269 \n\
5270 void main()\n\
5271 {\n\
5272 	vec4 color = vec4(0.0);\n\
5273 	float scx = 1.0 / float(width);\n\
5274 	float scy = 1.0 / float(height);\n\
5275 \n\
5276 	color += texture2D(tex, gl_TexCoord[0].st + vec2(-3.0*scx,-3.0*scy)) * 0.015625;\n\
5277 	color += texture2D(tex, gl_TexCoord[0].st + vec2(-2.0*scx,-2.0*scy))*0.09375;\n\
5278 	color += texture2D(tex, gl_TexCoord[0].st + vec2(-1.0*scx,-1.0*scy))*0.234375;\n\
5279 	color += texture2D(tex, gl_TexCoord[0].st + vec2(0.0 , 0.0) )*0.3125;\n\
5280 	color += texture2D(tex, gl_TexCoord[0].st + vec2(1.0*scx,1.0*scy))*0.234375;\n\
5281 	color += texture2D(tex, gl_TexCoord[0].st + vec2(2.0*scx,2.0*scy))*0.09375;\n\
5282 	color += texture2D(tex, gl_TexCoord[0].st + vec2(3.0*scx,-3.0*scy)) * 0.015625;\n\
5283 \n\
5284 	gl_FragColor = color;\n\
5285 }\n";
5286 
5287 char *vert_shader[NUM_PROG] = {vertex_shader_source0,vertex_shader_source1,vertex_shader_source2,vertex_shader_source3,vertex_shader_source4,vertex_shader_source5,vertex_shader_source6,vertex_shader_source7,vertex_shader_source7,vertex_shader_source7,vertex_shader_source10,vertex_shader_source11,vertex_shader_source12};
5288 char *v_shader[NUM_PROG] = {vertex_shader_source0b,vertex_shader_source1,vertex_shader_source2,vertex_shader_source3,vertex_shader_source4,vertex_shader_source5,vertex_shader_source6,vertex_shader_source7,vertex_shader_source7,vertex_shader_source7,vertex_shader_source10,vertex_shader_source11,vertex_shader_source12};
5289 
5290 char *frag_shader[NUM_PROG] = {fragment_shader_source0,fragment_shader_source1,fragment_shader_source2,fragment_shader_source3,fragment_shader_source4,fragment_shader_source5,fragment_shader_source6,fragment_shader_source7,fragment_shader_source8,fragment_shader_source9,fragment_shader_source10,fragment_shader_source11,fragment_shader_source12};
5291 
5292 #ifdef GL_ARB_shader_objects
printInfoLog(GLhandleARB obj)5293 void printInfoLog(GLhandleARB obj)
5294 	{
5295 	    int infologLength = 0;
5296 	    int charsWritten = 0;
5297 	    int status;
5298 	    char *infoLog;
5299 
5300 	    glGetObjectParameterivARB(obj, GL_OBJECT_COMPILE_STATUS_ARB,&status);
5301 	    //printf(" compile status %d\n",status);
5302 	    glGetObjectParameterivARB(obj, GL_OBJECT_INFO_LOG_LENGTH_ARB,
5303 						 &infologLength);
5304 
5305 
5306 	    if (infologLength > 0) {
5307 
5308 		infoLog = (char *) malloc(sizeof(char)*infologLength);
5309 
5310 
5311 		glGetInfoLogARB(obj, infologLength, &charsWritten, infoLog);
5312 
5313 		//printf("%s\n",infoLog);
5314 		free(infoLog);
5315 	    }
5316 	}
5317 #endif
5318 
5319 GLint rndid;
5320 GLint colmat;
5321 GLint DoShadLoc;
5322 GLint dofog;
5323 GLint dofog2;
5324 GLint dofog3;
5325 GLint doblur;
5326 GLint dossao;
5327 GLint dotrns;
5328 #ifdef GL_COLOR_ATTACHMENT0_EXT
5329 GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT};
5330 #endif
5331 
5332 #ifdef GL_ARB_shader_objects
load_shader(GLenum * program,int prg)5333 int load_shader(GLenum *program, int prg)
5334 {
5335 
5336 	program[prg] = glCreateProgramObjectARB();
5337 	vertex_shader[prg] = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
5338 	fragment_shader[prg] = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
5339 
5340 	glShaderSourceARB(fragment_shader[prg], 1, &frag_shader[prg], NULL);
5341 	glShaderSourceARB(vertex_shader[prg], 1, &vert_shader[prg], NULL);
5342 	if (DoIntel && prg == 0) {
5343 	   glShaderSourceARB(vertex_shader[prg], 1, &v_shader[prg], NULL);
5344 	}
5345 
5346 	glCompileShaderARB(vertex_shader[prg]);
5347 	printInfoLog((GLhandleARB) vertex_shader[prg]);
5348 	glCompileShaderARB(fragment_shader[prg]);
5349 	printInfoLog((GLhandleARB) fragment_shader[prg]);
5350 
5351 	glAttachObjectARB(program[prg], vertex_shader[prg]);
5352 	glAttachObjectARB(program[prg], fragment_shader[prg]);
5353 
5354 	glLinkProgramARB(program[prg]);
5355 }
5356 
del_shader()5357 void del_shader()
5358 {
5359     int i;
5360 
5361     for (i = 0; i < NUM_PROG; i++) {
5362 	glDeleteObjectARB(vertex_shader[i]);
5363 	glDeleteObjectARB(fragment_shader[i]);
5364 	glDeleteObjectARB(program[i]);
5365     }
5366 }
5367 
check_shader(const char * ext)5368 int check_shader(const char *ext)
5369 {
5370    GLint loc;
5371 
5372    if (!ext || !ext[0]) return 0;
5373 
5374    if (strstr(ext,"GL_ARB_vertex_shader")
5375 	&& strstr(ext,"GL_ARB_fragment_shader")) {
5376 
5377 	load_shader(program,0);
5378 	load_shader(program,1);
5379 	load_shader(program,2);
5380 	load_shader(program,3);
5381 	load_shader(program,4);
5382 	load_shader(program,5);
5383 	load_shader(program,6);
5384 	load_shader(program,7);
5385 	load_shader(program,8);
5386 	load_shader(program,9);
5387 	load_shader(program,10);
5388 	load_shader(program,11);
5389 	load_shader(program,12);
5390 
5391 /* passing Uniforms */
5392 
5393 	glUseProgramObjectARB(program[0]);
5394 
5395 	colmat   = glGetUniformLocationARB(program[0], "colmat");
5396 	dofog    = glGetUniformLocationARB(program[0], "dofog");
5397 	doblur   = glGetUniformLocationARB(program[0], "doblur");
5398 	dossao   = glGetUniformLocationARB(program[0], "dossao");
5399 	dotrns   = glGetUniformLocationARB(program[0], "dotrns");
5400 	DoShadLoc   = glGetUniformLocationARB(program[0], "doshad");
5401 	loc      = glGetUniformLocationARB(program[0], "ShadowMap");
5402 	glUniform1iARB(loc, 7);
5403 
5404 	glUniform1iARB(colmat, 0);
5405 	glUniform1iARB(dofog, 0);
5406 	glUniform1iARB(doblur, 0);
5407 	glUniform1iARB(dossao, 0);
5408 	glUniform1iARB(dotrns, 0);
5409 	glUniform1iARB(DoShadLoc, 0);
5410 
5411 	glUseProgramObjectARB(program[1]);
5412 
5413 	loc    = glGetUniformLocationARB(program[1], "gdepth");
5414 	glUniform1iARB(loc, 0);
5415 	dofog2 = glGetUniformLocationARB(program[1], "dofog");
5416 	glUniform1iARB(dofog2, 0);
5417 	loc    = glGetUniformLocationARB(program[1], "Width");
5418 	glUniform1iARB(loc, width);
5419 	loc    = glGetUniformLocationARB(program[1], "Height");
5420 	glUniform1iARB(loc, height);
5421 	loc    = glGetUniformLocationARB(program[1], "ssaotyp");
5422 	glUniform1iARB(loc, SSAO_type);
5423 
5424 	glUseProgramObjectARB(program[3]);
5425 	loc   = glGetUniformLocationARB(program[3], "Width");
5426 	glUniform1iARB(loc, width*2);
5427 
5428 	glUseProgramObjectARB(program[4]);
5429 	loc   = glGetUniformLocationARB(program[4], "Height");
5430 	glUniform1iARB(loc, height*2);
5431 
5432 	glUseProgramObjectARB(program[5]);
5433 	loc   = glGetUniformLocationARB(program[5], "Tex0");
5434 	glUniform1iARB(loc, 0);
5435 	loc   = glGetUniformLocationARB(program[5], "Tex1");
5436 	glUniform1iARB(loc, 1);
5437 
5438 	glUseProgramObjectARB(program[6]);
5439 	loc   = glGetUniformLocationARB(program[6], "Tex0");
5440 	glUniform1iARB(loc, 0);
5441 
5442 	glUseProgramObjectARB(program[8]);
5443 	loc   = glGetUniformLocationARB(program[8], "width");
5444 	glUniform1iARB(loc, width);
5445 	loc   = glGetUniformLocationARB(program[8], "height");
5446 	glUniform1iARB(loc, height);
5447 
5448 	glUseProgramObjectARB(program[9]);
5449 	loc    = glGetUniformLocationARB(program[9], "gcolor");
5450 	glUniform1iARB(loc, 0);
5451 	loc    = glGetUniformLocationARB(program[9], "glum");
5452 	glUniform1iARB(loc, 1);
5453 	loc    = glGetUniformLocationARB(program[9], "aotex");
5454 	glUniform1iARB(loc, 2);
5455 	dofog3 = glGetUniformLocationARB(program[9], "dofog");
5456 	glUniform1iARB(dofog3, 0);
5457 
5458 	glUseProgramObjectARB(program[10]);
5459 	loc    = glGetUniformLocationARB(program[10], "ShadowMap");
5460 	glUniform1iARB(loc, 7);
5461 
5462 	glUseProgramObjectARB(program[8]);
5463 
5464 	loc   = glGetUniformLocationARB(program[8], "width");
5465 	glUniform1iARB(loc, width);
5466 	loc   = glGetUniformLocationARB(program[8], "height");
5467 	glUniform1iARB(loc, height);
5468 
5469 	glUseProgramObjectARB(program[9]);
5470 	loc    = glGetUniformLocationARB(program[9], "tex");
5471 	glUniform1iARB(loc, 7);
5472 
5473 	glUseProgramObjectARB(0);
5474 
5475 	return(1);
5476    }
5477 
5478    return(0);
5479 }
5480 #endif
5481 
5482 #ifdef GL_COLOR_ATTACHMENT0_EXT
init_fbo(struct FBO * fbo,int fbo_type,const char * ext)5483 int init_fbo(struct FBO *fbo,int fbo_type,const char *ext)
5484 {
5485    int i,maxColorBuffers,maxBuffers;
5486    GLenum status;
5487 
5488    if (!ext || !ext[0]) return(0);
5489 
5490    if (strstr(ext,"GL_EXT_framebuffer_object") &&
5491 	strstr(ext,"GL_ARB_texture_float")) {
5492 
5493 	glGetIntegerv( GL_MAX_COLOR_ATTACHMENTS_EXT, &maxColorBuffers );
5494 	if (maxColorBuffers < 4) return(0);
5495 
5496 #if defined(GL_ARB_draw_buffers)
5497 	glGetIntegerv( GL_MAX_DRAW_BUFFERS, &maxBuffers );
5498 	if (maxBuffers < NUM_FBOS || maxBuffers <= 0) {
5499 	    fprintf(stderr,"maxBuffers %d < NUM_FBOS %d\n",maxBuffers,NUM_FBOS);
5500 	    return(0);
5501 	}
5502 #else
5503 	return(0);
5504 #endif
5505 
5506 	glGenFramebuffersEXT(1, &(fbo->frame[0]));
5507 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->frame[0]);
5508 
5509 	glGenRenderbuffersEXT(1, &(fbo->depth[0]));
5510 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo->depth[0]);
5511 	//glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
5512 	//	width, height);
5513 	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
5514 		width, height);
5515 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
5516 					GL_DEPTH_ATTACHMENT_EXT,
5517 					GL_RENDERBUFFER_EXT,fbo->depth[0]);
5518 
5519 	glGenTextures(1, &fbo->texid[0]);
5520 	glBindTexture(GL_TEXTURE_2D, fbo->texid[0]);
5521 	glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
5522 		width, height, 0,
5523 		GL_RGBA, GL_FLOAT, NULL);
5524 	if (DoMIPMAP) glGenerateMipmapEXT(GL_TEXTURE_2D);
5525 
5526 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
5527 			GL_LINEAR);
5528 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
5529 			GL_LINEAR_MIPMAP_LINEAR);
5530 	glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
5531 	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
5532 	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
5533 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
5534 		GL_TEXTURE_2D, fbo->texid[0], 0);
5535 
5536 	glGenTextures(1, &fbo->texid1[0]);
5537 	glBindTexture(GL_TEXTURE_2D, fbo->texid1[0]);
5538 	glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
5539 		width, height, 0,
5540 		GL_RGBA, GL_FLOAT, NULL);
5541 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5542 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5543 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT,
5544 		GL_TEXTURE_2D, fbo->texid1[0], 0);
5545 
5546 	glGenTextures(1, &fbo->texid2[0]);
5547 	glBindTexture(GL_TEXTURE_2D, fbo->texid2[0]);
5548 	glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
5549 		width, height, 0,
5550 		GL_RGBA, GL_FLOAT, NULL);
5551 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5552 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5553 
5554 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT,
5555 		GL_TEXTURE_2D, fbo->texid2[0], 0);
5556 
5557 	glGenTextures(1, &fbo->texid3[0]);
5558 	glBindTexture(GL_TEXTURE_2D, fbo->texid3[0]);
5559 	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
5560 		width, height, 0,
5561 		GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
5562 
5563 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5564 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5565 	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
5566 	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
5567 	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
5568 		GL_TEXTURE_2D, fbo->texid3[0], 0);
5569 
5570 	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
5571 	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
5572 		/*printf("FBO[0] Error: 0x%x\n", status);*/
5573 		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5574 		return(0);
5575 	}
5576 
5577 	for (i = 1; i < NUM_FBOS; i++) {
5578 		glGenFramebuffersEXT(1, &(fbo->frame[i]));
5579 		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->frame[i]);
5580 
5581 		glGenTextures(1, &fbo->texid[i]);
5582 
5583 		glBindTexture(GL_TEXTURE_2D, fbo->texid[i]);
5584 		glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
5585 			width, height,
5586 			0, GL_RGBA, GL_FLOAT, NULL);
5587 
5588 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
5589 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
5590 		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
5591 		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
5592 
5593 		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
5594 		  GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo->texid[i], 0);
5595 
5596 		status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
5597 		if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
5598 			/*printf("FBO[%d] Error: 0x%x\n", i, status);*/
5599 			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5600 			return(0);
5601 		}
5602 	}
5603 
5604 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5605 	return(1);
5606    }
5607    return(0);
5608 }
5609 
del_fbo(struct FBO * fbo)5610 void del_fbo(struct FBO *fbo)
5611 {
5612   int i;
5613 
5614   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5615   glDeleteRenderbuffersEXT(1, &(fbo->depth[0]));
5616   glDeleteTextures(1, &fbo->texid1[0]);
5617   glDeleteTextures(1, &fbo->texid2[0]);
5618   glDeleteTextures(1, &fbo->texid3[0]);
5619 
5620   for (i = 0; i < NUM_FBOS; i++) {
5621 	glDeleteTextures(1, &fbo->texid[i]);
5622 	glDeleteFramebuffersEXT(1, &(fbo->frame[i]));
5623   }
5624 
5625 }
5626 #endif
5627 
DoQuad()5628 void DoQuad()
5629 {
5630   glBegin(GL_QUADS);
5631 	glTexCoord2f(0.0f, 0.0f);
5632 	glVertex2d(-1, -1);
5633 	glTexCoord2f(1.0f, 0.0f);
5634 	glVertex2d(1, -1);
5635 	glTexCoord2f( 1.0f, 1.0f);
5636 	glVertex2d(1, 1);
5637 	glTexCoord2f(0.0f, 1.0f);
5638 	glVertex2d(-1, 1);
5639   glEnd();
5640 }
5641 
DoQuad2()5642 void DoQuad2()
5643 {
5644   glBegin(GL_QUADS);
5645 	glTexCoord2d(0,0);
5646 	glVertex2f(-width/2,-height/2);
5647 	glTexCoord2d(1,0);
5648 	glVertex2f( width/2,-height/2);
5649 	glTexCoord2d(1,1);
5650 	glVertex2f( width/2, height/2);
5651 	glTexCoord2d(0,1);
5652 	glVertex2f(-width/2, height/2);
5653   glEnd();
5654 }
5655 
setupMatrices(pos_x,pos_y,pos_z,lookx,looky,lookz)5656 void setupMatrices(pos_x,pos_y,pos_z,lookx,looky,lookz)
5657 float pos_x;
5658 float pos_y;
5659 float pos_z;
5660 float lookx;
5661 float looky;
5662 float lookz;
5663 {
5664 	glMatrixMode(GL_PROJECTION);
5665 	glLoadIdentity();
5666 	if (*persp) {
5667 	   glFrustum(-0.2*Aspect,0.2*Aspect,-0.2,0.2,0.3,600.0);
5668 	} else {
5669 	   glOrtho(1.0*Aspect,-1.0*Aspect,1.0,-1.0,-10.0,300.0);
5670 	}
5671 	glMatrixMode(GL_MODELVIEW);
5672 	glLoadIdentity();
5673 	gluLookAt(pos_x,pos_y,pos_z,
5674 		  0.0,0.0,0.0,0.0,1.0,0.0);
5675 }
5676 
blurShadowMap()5677 void blurShadowMap()
5678 {
5679 	GLint loc;
5680 
5681 #ifdef GL_COLOR_ATTACHMENT0_EXT
5682         glDepthMask(GL_FALSE);
5683         glDisable(GL_DEPTH_TEST);
5684 
5685         glPushMatrix();
5686         glLoadIdentity();
5687         glMatrixMode(GL_PROJECTION);
5688         glPushMatrix();
5689         glLoadIdentity();
5690 
5691 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo.frame[1]);
5692 	glUseProgramObjectARB(program[12]);
5693 	loc   = glGetUniformLocationARB(program[12], "width");
5694 	glUniform1iARB(loc, width);
5695 	loc   = glGetUniformLocationARB(program[12], "height");
5696 	glUniform1iARB(loc, 0);
5697 
5698 	glActiveTexture(GL_TEXTURE0);
5699 	glBindTexture(GL_TEXTURE_2D,fbo.texid[0]);
5700 
5701 	DoQuad();
5702 
5703 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo.frame[0]);
5704 	loc   = glGetUniformLocationARB(program[12], "width");
5705 	glUniform1iARB(loc, 0);
5706 	loc   = glGetUniformLocationARB(program[12], "height");
5707 	glUniform1iARB(loc, height);
5708 
5709 	glBindTexture(GL_TEXTURE_2D,fbo.texid[1]);
5710 
5711 	DoQuad();
5712 
5713 	glPopMatrix();
5714 	glMatrixMode(GL_MODELVIEW);
5715 	glPopMatrix();
5716 
5717 	glEnable(GL_DEPTH_TEST);
5718 	glDepthMask(GL_TRUE);
5719 #endif
5720 }
5721 
DepthBlur()5722 void DepthBlur()
5723 {
5724 	GLint loc;
5725 
5726 #ifdef GL_COLOR_ATTACHMENT0_EXT
5727 
5728         glMatrixMode(GL_PROJECTION);
5729         glLoadIdentity();
5730         glMatrixMode(GL_MODELVIEW);
5731         glLoadIdentity();
5732 
5733 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[2]);
5734 	glDrawBuffers(1,buffers);
5735 	glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
5736 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5737 	glActiveTexture(GL_TEXTURE0);
5738 	glBindTexture(GL_TEXTURE_2D, fbo.texid[0]);
5739 	glUseProgramObjectARB(program[2]);
5740 
5741 	DoQuad();
5742 
5743 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[3]);
5744 	glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
5745 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5746 	glBindTexture(GL_TEXTURE_2D, fbo.texid[2]);
5747 	glUseProgramObjectARB(program[3]);
5748 	loc   = glGetUniformLocationARB(program[3], "Width");
5749 	glUniform1iARB(loc, width*2);
5750 
5751 	DoQuad();
5752 
5753 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[2]);
5754 	glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
5755 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5756 	glBindTexture(GL_TEXTURE_2D, fbo.texid[3]);
5757 	glUseProgramObjectARB(program[4]);
5758 	loc   = glGetUniformLocationARB(program[4], "Height");
5759 	glUniform1iARB(loc, height*2);
5760 
5761 	DoQuad();
5762 
5763 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5764 	glDrawBuffer(GL_BACK);
5765 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5766 	glActiveTexture(GL_TEXTURE0);
5767 	glBindTexture(GL_TEXTURE_2D, fbo.texid[0]);
5768 	glActiveTexture(GL_TEXTURE1);
5769 	glBindTexture(GL_TEXTURE_2D, fbo.texid[2]);
5770 	glUseProgramObjectARB(program[5]);
5771 
5772 	glBegin(GL_QUADS);
5773 		glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);
5774 		glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f);
5775 		glVertex2d(-1, -1);
5776 		glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f);
5777 		glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 0.0f);
5778 		glVertex2d(1, -1);
5779 		glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f);
5780 		glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 1.0f);
5781 		glVertex2d(1, 1);
5782 		glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f);
5783 		glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1.0f);
5784 		glVertex2d(-1, 1);
5785 	glEnd();
5786 
5787 	glXSwapBuffers(display, win);
5788 #endif
5789 }
5790 
SSAO()5791 void SSAO()
5792 {
5793 	GLint loc;
5794 
5795 #ifdef GL_COLOR_ATTACHMENT0_EXT
5796 	glDepthMask(GL_FALSE);
5797 	glDisable(GL_DEPTH_TEST);
5798 
5799 	glPushMatrix();
5800 	glLoadIdentity();
5801 	glMatrixMode(GL_PROJECTION);
5802 	glPushMatrix();
5803 	glLoadIdentity();
5804 
5805 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[1]);
5806 	glDrawBuffers(1,buffers);
5807 	glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
5808 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5809 	glActiveTexture(GL_TEXTURE0);
5810 	glBindTexture(GL_TEXTURE_2D, fbo.texid3[0]);
5811 
5812 	glUseProgramObjectARB(program[1]);
5813 	if (*shade) {
5814 	   glUniform1iARB(dofog2, 1);
5815 	} else {
5816 	   glUniform1iARB(dofog2, 0);
5817 	}
5818 
5819 	DoQuad();
5820 
5821 	if (SSAO_type) {
5822 
5823 	   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[2]);
5824 	   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5825 	   glBindTexture(GL_TEXTURE_2D, fbo.texid[1]);
5826 	   glUseProgramObjectARB(program[8]);
5827 
5828 	   DoQuad();
5829 
5830 	} else {
5831 
5832 	   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[2]);
5833 	   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5834 	   glBindTexture(GL_TEXTURE_2D, fbo.texid[1]);
5835 	   glUseProgramObjectARB(program[3]);
5836 	   loc   = glGetUniformLocationARB(program[3], "Width");
5837 	   glUniform1iARB(loc, width);
5838 
5839 	   DoQuad();
5840 
5841 	   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[1]);
5842 	   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5843 	   glBindTexture(GL_TEXTURE_2D, fbo.texid[2]);
5844 	   glUseProgramObjectARB(program[4]);
5845 	   loc   = glGetUniformLocationARB(program[4], "Height");
5846 	   glUniform1iARB(loc, height);
5847 
5848 	   DoQuad();
5849 
5850 	}
5851 
5852 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
5853 	glDrawBuffer(GL_BACK);
5854 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
5855 	glActiveTexture(GL_TEXTURE0);
5856 	glBindTexture(GL_TEXTURE_2D, fbo.texid1[0]);
5857 	glActiveTexture(GL_TEXTURE1);
5858 	glBindTexture(GL_TEXTURE_2D, fbo.texid2[0]);
5859 	glActiveTexture(GL_TEXTURE2);
5860 
5861 	if (SSAO_type) {
5862 	   glBindTexture(GL_TEXTURE_2D, fbo.texid[2]);
5863 	} else {
5864 	   glBindTexture(GL_TEXTURE_2D, fbo.texid[1]);
5865 	}
5866 
5867 	glUseProgramObjectARB(program[9]);
5868 	if (*shade) {
5869 	   glUniform1iARB(dofog3, 1);
5870 	} else {
5871 	   glUniform1iARB(dofog3, 0);
5872 	}
5873 
5874 	glBegin(GL_QUADS);
5875 		glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 0.0f);
5876 		glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 0.0f);
5877 		glVertex2d(-1, -1);
5878 		glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 0.0f);
5879 		glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 0.0f);
5880 		glVertex2d(1, -1);
5881 		glMultiTexCoord2f(GL_TEXTURE0, 1.0f, 1.0f);
5882 		glMultiTexCoord2f(GL_TEXTURE1, 1.0f, 1.0f);
5883 		glVertex2d(1, 1);
5884 		glMultiTexCoord2f(GL_TEXTURE0, 0.0f, 1.0f);
5885 		glMultiTexCoord2f(GL_TEXTURE1, 0.0f, 1.0f);
5886 		glVertex2d(-1, 1);
5887 	glEnd();
5888 
5889 	glPopMatrix();
5890 	glMatrixMode(GL_MODELVIEW);
5891 	glPopMatrix();
5892 
5893 	glEnable(GL_DEPTH_TEST);
5894 	glDepthMask(GL_TRUE);
5895 	glXSwapBuffers(display, win);
5896 #endif
5897 }
5898 
5899 GLint shadowMapTexture;
5900 GLdouble lightProj[16], lightView[16];
5901 GLdouble TexMat[16];
5902 GLfloat amb_dif[4] = {0.2f, 0.2f, 0.2f, 1.0f};
5903 GLfloat blk[4] = {0.0f, 0.0f, 0.0f, 0.0f};
5904 GLfloat wht[4] = {1.0f, 1.0f, 1.0f, 1.0f};
5905 static float lightPos[] = { 2.0f, 3.0f, -2.0f, 0.0f };
5906 
invmat(mati,mato)5907 void invmat(mati,mato)
5908 double mati[16];
5909 double mato[16];
5910 {
5911    int i,j;
5912 
5913    mato[0]  = mati[0];
5914    mato[5]  = mati[5];
5915    mato[10] = mati[10];
5916    mato[1]  = mati[4];
5917    mato[4]  = mati[1];
5918    mato[2]  = mati[8];
5919    mato[8]  = mati[2];
5920    mato[6]  = mati[9];
5921    mato[9]  = mati[6];
5922 
5923    mato[3]  = mati[3];
5924    mato[7]  = mati[7];
5925    mato[11] = mati[11];
5926    mato[15] = mati[15];
5927 
5928    mato[12] = -mati[12];
5929    mato[13] = -mati[13];
5930    mato[14] = -mati[14];
5931 }
5932 
5933 static double mView[16];
5934 static double Lproj[16];
5935 
5936 static GLdouble RR[4][4] = {
5937 {1.0,0.0,0.0,0.0}, {0.0,1.0,0.0,0.0}, {0.0,0.0,1.0,0.0}, {0.0,0.0,0.0,1.0}
5938 };
5939 
MultInvTextMat()5940 void MultInvTextMat()
5941 {
5942 	double mV[16];
5943 	static double mViewi[16];
5944 	glGetDoublev(GL_MODELVIEW_MATRIX, mV);
5945 	invmat(mV,mViewi);
5946 	glMatrixMode(GL_TEXTURE);
5947 	glActiveTexture(GL_TEXTURE7);
5948 	glLoadIdentity();
5949 	glMultMatrixd (Lproj);
5950 	glMultMatrixd (mView);
5951 	glMultMatrixd (mViewi);
5952 	glMultMatrixd ((const GLdouble *) RR);
5953 	glMatrixMode(GL_MODELVIEW);
5954 }
5955 
startTranslate(float x,float y,float z)5956 void startTranslate(float x,float y,float z)
5957 {
5958         glPushMatrix();
5959 
5960         glMatrixMode(GL_TEXTURE);
5961         glActiveTexture(GL_TEXTURE7);
5962 	glLoadIdentity();
5963 	glMultMatrixd(TexMat);
5964         glTranslatef(x,y,z);
5965 
5966         glMatrixMode(GL_MODELVIEW);
5967         glPopMatrix();
5968 }
5969 
RotateShad(RR)5970 void RotateShad(RR)
5971 const GLdouble *RR;
5972 {
5973 	glMultMatrixd((const GLdouble *) RR);
5974         glPushMatrix();
5975 
5976         glMatrixMode(GL_TEXTURE);
5977         glActiveTexture(GL_TEXTURE7);
5978 	glMultMatrixd((const GLdouble *) RR);
5979 
5980         glMatrixMode(GL_MODELVIEW);
5981         glPopMatrix();
5982 
5983 }
5984 
setTextureMatrix(void)5985 void setTextureMatrix(void)
5986 {
5987 	const GLdouble bias[16] = {
5988 		0.5, 0.0, 0.0, 0.0,
5989 		0.0, 0.5, 0.0, 0.0,
5990 		0.0, 0.0, 0.5, 0.0,
5991 		0.5, 0.5, 0.5, 1.0};
5992 
5993 	glGetDoublev(GL_MODELVIEW_MATRIX, mView);
5994 	glGetDoublev(GL_PROJECTION_MATRIX, Lproj);
5995 
5996 	glMatrixMode(GL_TEXTURE);
5997 	glActiveTexture(GL_TEXTURE7);
5998 
5999 	glLoadIdentity();
6000 	glLoadMatrixd(bias);
6001 
6002 	glMultMatrixd (Lproj);
6003 	glMultMatrixd (mView);
6004 	glGetDoublev(GL_TEXTURE_MATRIX, TexMat);
6005 
6006 	glMatrixMode(GL_MODELVIEW);
6007 }
6008 
6009 #endif
6010 
6011 #define RESUND -20000
6012 static int rsold = RESUND;
6013 static int bckx,bcky;
6014 
6015 void ogind();
6016 
6017 static int update_model = 1;
6018 static int update_res = -1;
6019 static int update_sel = 1;
6020 static int update_casel = 0;
6021 
6022 static char *VRMLFname;
6023 
6024 static char *GEOMstr;
6025 static int GEOMset = 0;
6026 
6027 static BSTRU qboxclose[2];
6028 
6029 static int ISOup = 0;
6030 static Window ISOwin;
6031 #define ISOWINW 250
6032 #define ISOWINH 290
6033 #define ISOOffx 10
6034 #define NBUTISO 2
6035 static BSTRU isobut[NBUTISO];
6036 static int ISOt = 0;
6037 
6038 #define NBUTDCK 4
6039 static BSTRU dockbut[NBUTDCK];
6040 
6041 static char dcklig[MAXPATHLEN] = "dock.xyz";
6042 static char dckout[MAXPATHLEN] = "dock.mol2";
6043 static int dcksol = 20;
6044 
6045 static char  *nofor[1] = {"       "};
6046 static int Nnofor = 1;
6047 
6048 #define MXMM3 164
6049 static char  *mm3[MXMM3];
6050 static int Nmm3 = 0;
6051 
6052 static int mm3ptr[] = {
6053 4,20,22,23,27,35,43,47,72,123,50,162,25,26,0,
6054 1,2,3,21,28,29,37,49,55,56,57,66,67,70,105,
6055 112,113,159,160,161,7,8,9,36,38,39,42,44,45,71,
6056 106,107,108,109,110,142,143,145,149,150,154,163,5,6,40,
6057 46,48,68,69,74,75,76,77,78,79,80,81,82,83,84,
6058 85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,
6059 100,101,102,114,115,116,117,118,119,120,144,147,148,158,10,
6060 51,58,18,24,59,152,14,15,16,17,41,73,103,104,153,
6061 11,52,124,60,61,64,65,62,63,30,33,12,53,125,31,
6062 34,13,54,126,127,128,129,130,131,132,133,134,135,136,137,
6063 138,139,140,141,32,19,111,121,122,146,151,155,156,157
6064 };
6065 
6066 static int mm3atnr[] = {
6067 1,1,1,1,1,1,1,1,1,1,2,3,5,5,6,
6068 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6069 6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,
6070 7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,
6071 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
6072 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
6073 8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,
6074 10,12,14,15,15,15,16,16,16,16,16,16,16,16,16,
6075 17,18,20,26,26,27,27,28,28,32,34,35,36,38,50,
6076 52,53,54,56,57,58,59,60,61,62,63,64,65,66,67,
6077 68,69,70,71,82,0,0,0,0,0,0,0,0,0
6078 };
6079 
6080 /* static int mm3ptr[] = {
6081  4,20,22,23,27,43,47,72,123,35,50,25,26,0,1,
6082  2,3,21,28,29,37,49,55,56,57,66,67,70,105,112,
6083  113,155,156,157,7,8,9,36,38,39,42,44,45,71,106,
6084  107,108,109,110,142,143,145,149,150,154,5,6,40,46,48,
6085  68,69,74,75,76,77,78,79,80,81,82,83,84,85,86,
6086  87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,
6087  102,114,115,116,117,118,119,120,144,147,148,158,10,51,58,
6088  18,24,59,152,14,15,16,17,41,73,103,104,153,11,52,
6089  124,60,61,64,65,62,63,30,12,33,53,125,31,13,34,
6090  54,126,127,128,129,130,131,132,133,134,135,136,137,138,139,
6091  140,141,32,19,111,121,122,146,151
6092 };
6093 
6094 static int mm3atnr[] = {
6095  1,1,1,1,1,1,1,1,1,1,2,5,5,6,6,6,6,6,6,6,6,6,6,6,6,
6096  6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
6097  7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
6098  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
6099  8,7,9,10,12,14,15,15,15,16,16,16,16,16,16,16,16,16,17,18,
6100  20,26,26,27,27,28,28,32,35,34,36,38,50,53,52,54,56,57,58,
6101  59,60,61,62,63,64,65,66,67,68,69,70,71,82,0,0,0,0,0,0
6102 }; */
6103 
6104 static int gffatnr[] = {
6105  0,6,6,6,6,6,6,6,6,6,
6106  6,6,6,6,6,6,6,6,1,1,
6107  1,1,1,1,1,1,1,1,1,1,
6108  1,9,17,35,53,7,7,7,7,7,
6109  7,7,7,7,7,7,7,7,8,8,
6110  8,8,15,15,15,15,15,15,15,15,
6111  15,15,15,16,16,16,16,16,16,16,16,6
6112 };
6113 
6114 #define MXCHTP 136
6115 
6116 static char  *chmtnk[MXCHTP];
6117 static int Nchmtnk = 0;
6118 
6119 static int chmptr[] = {
6120 /* Hydrogen */
6121 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,82,
6122 83,84,85,86,87,88,115,116,117,118,119,
6123 /* Carbon */
6124 19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
6125 37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,
6126 55,56,57,58,59,60,61,89,90,91,92,93,94,95,96,97,98,120,
6127 121,122,123,124,125,126,127,128,129,
6128 /* Nitrogen */
6129 62,63,64,65,66,67,68,69,70,71,72,99,130,
6130 /* Oxygen */
6131 73,74,75,76,77,78,100,101,102,103,104,131,132,133,134,
6132 /* Other atoms */
6133 79,80,81,105,106,107,108,109,110,111,112,113,114,135
6134 /* 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,82,
6135 19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
6136 37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,
6137 55,56,57,58,59,60,61,83,84,85,86,87,88,62,63,64,65,66,
6138 67,68,69,70,71,72,89,73,74,75,76,77,78,90,91,92,93,79,
6139 80,81,94,95,96,97,98,9980,81,94,95,96,97,98,99 */
6140 };
6141 
6142 static int chmatnr[] = {
6143 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
6144 1,1,1,1,1,
6145 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6146 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6147 6,6,6,6,6,6,6,6,6,6,6,
6148 7,7,7,7,7,7,7,7,7,7,7,7,7,
6149 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
6150 16,16,16,16,26,2,10,11,12,17,19,20,30,15
6151 };
6152 
6153 static char  *ambstr[MXAMB];
6154 static int Nambstr = 0;
6155 
6156 static int ambatnr[] = {
6157 7,6,6,1,8,1,7,6,6,1,8,1,6,1,7,6,6,1,8,1,
6158 6,1,6,1,6,1,7,6,6,1,8,1,6,1,6,1,6,1,6,1,
6159 7,6,6,1,8,1,6,1,6,1,6,1,6,1,7,6,6,1,8,1,
6160 6,1,8,1,7,6,6,1,8,1,6,1,8,1,6,1,7,6,6,1,
6161 8,1,6,1,16,1,7,6,6,1,8,1,6,1,16,7,6,6,8,1,
6162 6,1,6,1,6,1,7,6,6,1,8,1,6,1,6,6,1,6,1,6,
6163 1,7,6,6,1,8,1,6,1,6,6,1,6,1,6,8,1,7,6,6,
6164 1,8,1,6,1,6,6,1,6,7,1,6,6,1,6,1,6,1,6,1,
6165 7,6,6,1,8,1,6,1,6,7,1,6,1,6,1,7,1,7,6,6,
6166 1,8,1,6,1,6,7,1,6,1,6,1,7,7,6,6,1,8,1,6,
6167 1,6,7,6,1,6,1,7,1,7,6,6,1,8,1,6,1,6,8,7,
6168 6,6,1,8,1,6,1,6,8,7,1,7,6,6,1,8,1,6,1,6,
6169 1,6,8,7,6,6,1,8,1,6,1,6,1,6,8,7,1,7,6,6,
6170 1,8,1,6,1,6,1,16,6,1,7,6,6,1,8,1,6,1,6,1,
6171 6,1,6,1,7,1,7,6,6,1,8,1,6,1,6,1,6,1,7,1,
6172 6,7,1,7,6,6,1,8,1,6,1,6,1,6,1,7,1,7,6,6,
6173 1,8,6,1,7,6,6,1,8,1,6,1,6,1,6,8,6,1,8,6,
6174 1,6,8,7,1,7,1,6,1,7,6,6,1,8,1,7,6,6,1,8,
6175 1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,
6176 6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,
6177 1,8,1,7,6,6,1,8,1,6,1,7,6,6,1,8,1,7,6,6,
6178 1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,
6179 1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,
6180 6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,
6181 1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,
6182 7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,
6183 6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,
6184 8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,8,1,7,
6185 6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,
6186 1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,
6187 1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,
6188 6,6,1,8,1,7,6,6,1,8,1,7,6,6,1,8,1,7,6,6,
6189 1,8,1,7,6,6,1,8,8,1,3,11,19,37,55,12,20,30,17,
6190 7,6,6,1,8,1,6,1,6,8,8,1,
6191 7,6,6,1,8,1,6,1,6,1,6,8,8,1,
6192 7,6,6,1,8,1,6,1,6,1,6,1,7,1,
6193 299*0,
6194 8,6,1,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,6,7,
6195 6,7,6,7,6,1,7,1,1,1,8,6,1,1,6,1,8,6,1,6,
6196 1,6,1,8,1,8,7,6,6,7,6,7,6,7,6,1,7,1,1,8,
6197 1,8,6,1,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,7,
6198 6,6,6,8,7,1,1,1,1,8,6,1,1,6,1,8,6,1,6,1,
6199 6,1,8,1,8,7,6,7,6,6,6,8,1,8,1,1,8,6,1,1,
6200 6,1,8,6,1,6,1,6,1,1,8,7,6,6,7,6,7,6,7,6,
6201 1,7,1,1,1,8,6,1,1,6,1,8,6,1,6,1,6,1,1,8,
6202 7,6,6,7,6,7,6,7,6,1,7,1,1,8,1,8,6,1,1,6,
6203 1,8,6,1,6,1,6,1,1,8,7,6,7,6,6,6,8,7,1,1,
6204 1,1,8,6,1,1,6,1,8,6,1,6,1,6,1,1,8,7,6,7,
6205 6,6,6,8,1,8,6,1,1,15,8,8,1,8,15,8,8,1,8,15,
6206 8,15,8,8,1,8,15,8,8,1,8,15,8,
6207 8,6,1,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,6,7,6,7,6,7,6,1,7,1,1,6,1,
6208 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,7,6,6,6,1,8,7,1,6,1,
6209 8,6,1,6,1,8,6,1,6,1,6,1,8,8,7,6,8,7,6,7,1,6,1,6,1,6,1,
6210 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,6,7,6,1,7,6,7,1,6,8,6,1,6,1,
6211 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,6,7,6,7,6,7,6,8,1,1,7,6,1,
6212 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,6,7,6,7,6,7,6,8,1,1,7,1,6,1,
6213 8,6,1,6,1,8,6,1,6,1,6,1,8,8,7,6,6,7,6,7,6,7,6,8,1,1,7,1,6,1,
6214 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,6,7,6,7,6,7,6,8,7,6,6,1,6,1,6,1,6,1,6,1,6,1,6,8,8,6,1,7,1,6,8,8,6,1,
6215 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,7,6,6,6,8,8,1,1,1,
6216 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,7,6,7,6,6,6,8,8,1,1,6,1,
6217 8,6,1,6,1,8,6,1,6,1,6,1,8,1,8,6,6,7,6,7,6,8,8,1,1,1
6218 };
6219 
6220 
6221 #define MXMOL2 41
6222 static char  *mol2[MXMOL2];
6223 static int Nmol2 = 0;
6224 
6225 #define MXGMX 53
6226 static char  *gmx[MXGMX];
6227 static int Ngmx = 0;
6228 
6229 #define MXGMX2 57
6230 static char  *gmx2[MXGMX2];
6231 static int Ngmx2 = 0;
6232 
6233 #define MXG43 49
6234 static char  *g43[MXG43];
6235 static int Ng43 = 0;
6236 
6237 #define MXAMO 201
6238 static char  *amostr[MXAMO];
6239 static int Namostr = 0;
6240 
6241 #define MXMSF 235
6242 static char  *chmsf[MXMSF];
6243 static int Nchmsf = 0;
6244 
6245 #define MXTRR 512
6246 static char  *grostr[MXTRR];
6247 static int Ngrostr = 0;
6248 
6249 #define MXGFF 72
6250 static char  *gffext[MXGFF];
6251 static int Ngffext = 0;
6252 
6253 static char  *exepath[1];
6254 static int Nexepath = 0;
6255 
6256 static int isnul = 0;
6257 static char **typs[12] = { nofor,mm3,chmtnk,ambstr,amostr,mol2,chmsf,ambstr,NULL,gmx,gmx2,g43};
6258 static char **typsn[12] = { nofor,mm3,chmtnk,ambstr,amostr,mol2,chmsf,gffext,NULL,gmx,gmx2,g43};
6259 static int *Ntyps[12] = { &Nnofor,&Nmm3,&Nchmtnk,&Nambstr,&Namostr,&Nmol2,&Nchmsf,&Nambstr,&isnul,&Ngmx,&Ngmx2,&Ng43};
6260 static int *Ntypsn[12] = { &Nnofor,&Nmm3,&Nchmtnk,&Nambstr,&Namostr,&Nmol2,&Nchmsf,&Ngffext,&isnul,&Ngmx,&Ngmx2,&Ng43};
6261 static int ffsgn[12] = { 1,1,1,1,1,1,1,-1,1,1,1,1};
6262 static int *ffptr[12] = { NULL,mm3ptr,chmptr,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
6263 static int *ffatnr[12] = { NULL,mm3atnr,chmatnr,ambatnr,NULL,NULL,NULL,gffatnr,NULL,NULL,NULL,NULL};
6264 
6265 #define MXSG 238
6266 static char  *spacegr[MXSG];
6267 static int Nspgr = 0;
6268 
6269 static char  *achain[NUMCAL];
6270 static int ncal = 0;
6271 
6272 static int ATMup = 0;
6273 static Window ATMwin;
6274 static Window subATM;
6275 #define ATMWINW 250
6276 #define ATMWINH 350
6277 #define ATMOffx 10
6278 #define NBUTATM 6
6279 static BSTRU butATM[NBUTATM];
6280 static int ATMt = 0;
6281 static int itcopt = 3;
6282 static char *ForceFields[] = {"No Force Field","Tinker MM3","Tinker Charmm","Tinker Amber","Tink AmoebaPRO","Sybyl","Quanta Charmm","Amber/GAFF","PMF","Gromacs","Gromacs2","Gromos96"};
6283 static int *fftyp;
6284 static int ATMsel = 0;
6285 static int ATMselp = 0;
6286 
6287 static int SEQup = 0;
6288 static Window SEQwin;
6289 #define SEQWINW 430
6290 #define SEQWINH 220
6291 #define SEQOffx 15
6292 #define SEQRESY  40
6293 #define SEQSTATY 105
6294 #define SEQCONFY 150
6295 #define SEQBROWY 180
6296 #define NBUTSEQ 25
6297 static BSTRU butSEQ[NBUTSEQ];
6298 static char *Conformations[] = {"Alpha-Helix","Beta","Turn"};
6299 static double phis[3] = {-58.0, -139.0, -60.0};
6300 static double psis[3] = {-47.0, 135.0, -30.0};
6301 static double phi_angle = -58.0;
6302 static double psi_angle = -47.0;
6303 static int iconform = 0;
6304 
6305 static int TNKup = 0;
6306 static Window TNKwin, subTNK;
6307 #define TNKWINW 430
6308 #define TNKWINH 205
6309 #define TNKOffx 15
6310 #define TNKRESY  17
6311 #define TNKBWIDE 30
6312 #define TNKBROWY 165
6313 #define NBUTTNK 11
6314 static int ntnkb = NBUTTNK-2;
6315 static BSTRU butTNK[NBUTTNK];
6316 static char *TnkProgs[] = {"minimize","optimize","newton","dynamic","Xtinker","newton-ts"};
6317 static char *AmbProgs[] = {"ambfor","ambmd","crys. opt"};
6318 static char *grdFlags[] = {"-g","-t"};
6319 static char *iterFlags[] = {"-c","-s"};
6320 static char **Progs = TnkProgs;
6321 static int nprogs = 6;
6322 static int *tnkprg;
6323 static double mxgrads[] = {0.01,0.01,0.01,0.0,0.01};
6324 static double *currgrd;
6325 static double *uscl;
6326 static int *archfrq;
6327 static int *arch;
6328 static int *tnkbg;
6329 static int AddChrg = 1;
6330 static int Box = 0;
6331 static int Cutoff = 1;
6332 static int *tnkit;
6333 static int *iqopt;
6334 static int *ibell;
6335 static int *natorg;
6336 static int *irtcel;
6337 static int *irtval;
6338 static int *ifntcl;
6339 
6340 static SCRSTRU dptscr[2];
6341 static int dptwn[3];
6342 static int dptwpos[3];
6343 static BSTRU butdpt[2];
6344 static int DPTup = 0;
6345 static Window DPTwin;
6346 
6347 static SLIDESTRU omapscr[6];
6348 static int omapwn[6];
6349 static int omapwpos[6];
6350 static float omaprat[6];
6351 static int omapsrf;
6352 static BSTRU butomap[4];
6353 static double omapt[3];
6354 static double omapcnt1;
6355 static double omapcnt2;
6356 static int OMAPup = 0;
6357 static int OMAPtype = 0;
6358 static Window OMAPwin;
6359 static Window subOMAP;
6360 static double slab[3] = {10.0,10.0,10.0};
6361 static double EQ[3] = {0.0,0.0,0.0};
6362 static double extnt[3] = {0.0,0.0,0.0};
6363 static double vox[3] = {0.0,0.0,0.0};
6364 
6365 static SCRSTRU ecolscr[3];
6366 static int ecolwn[3];
6367 static int ecolwpos[3];
6368 static int activecolor = 1;
6369 static BSTRU butecol[1];
6370 static int ECOLup = 0;
6371 static Window ECOLwin;
6372 #define ECOLWINW 250
6373 #define ECOLWINH 180
6374 void colcall(char* str);
6375 
6376 static int COLup = 0;
6377 static Window COLwin;
6378 #define NBUTSC 2
6379 static BSTRU colbut[NBUTSC];
6380 #define COLWINW 513
6381 #define COLWINH 400
6382 #define COLWINIW 464
6383 #define COLWINIH 361
6384 #define COLFRBord 20
6385 #define COLBord 10
6386 #define COLOffx 10
6387 #define COLOffy 50
6388 #define COLWINHT COLOffy-COLFRBord+COLWINH
6389 static int ipropopt = 0;
6390 static int propat = 0;
6391 static char *propopts[] = {"Atom Color","VDW radius","Display radius","ESP VDW radius"};
6392 #define PATMCOL 0
6393 #define PVDWRAD 1
6394 #define PDISRAD 2
6395 #define PESPRAD 3
6396 
6397 static int MAPup = 0;
6398 static Window MAPwin;
6399 #define NBUTSM 7
6400 static BSTRU mapbut[NBUTSM];
6401 #define MAPWINW 513
6402 #define MAPWINH 400
6403 #define MAPOFFX  130
6404 #define MAPOFFY  130
6405 static char *mapstr[] = {"Red        < ","Yellow       ","Green        ","Light Blue   ","Blue       > "};
6406 static double *mapval;
6407 static int *imapopt;
6408 static char *mapopts[] = {"Molden Gridfile","Gaussian Cube"};
6409 static int iviropt = 2;
6410 static char *viropts[] = {"VRML2.0","OpenGL file","OpenGL screen"};
6411 
6412 static int VIRup = 0;
6413 static Window VIRwin;
6414 static BSTRU virbut[2];
6415 #define VIRWINW 513
6416 #define VIRWINH 170
6417 
6418 static int DELup = 0;
6419 static Window DELAYwin;
6420 static BSTRU delbut[3];
6421 #define DELWINW 300
6422 #define DELWINH 120
6423 static int DelayRemember = 0;
6424 static int *ideltm;
6425 
6426 static int MLTup = 0;
6427 static int MLTwide = 0;
6428 static Window MLTwin, subMLT;
6429 #define NMLTBUT 4
6430 static BSTRU mltbut[NMLTBUT];
6431 static int Nmltb = NMLTBUT;
6432 #define MLTWINW 350
6433 #define MLTWINH 300
6434 #define MLTWIDE 120
6435 static LISTSTRU mltlist;
6436 
6437 static int PHRMup = 0;
6438 static Window PHRMwin, subPHRM;
6439 static int FeatSel = -1;
6440 #define PHRMBUT 8
6441 static BSTRU PHRMbut[PHRMBUT];
6442 #define PHRMWINW 360
6443 #define PHRMWINH 375
6444 static LISTSTRU PHRMlist;
6445 static int PHRMloc = -1;
6446 static int OBloc = -1;
6447 
6448 static int PSRCHup = 0;
6449 static Window PSRCHwin, subPSRCH;
6450 static char *PSRCHquery;
6451 #define PSRCHBUT 4
6452 static BSTRU PSRCHbut[PSRCHBUT];
6453 #define PSRCHWINW 360
6454 #define PSRCHWINH 150
6455 
6456 static int SRFup = 0;
6457 static Window SRFwin, subSRF;
6458 static BSTRU srfbut[6];
6459 #define SRFWINW 310
6460 #define SRFWINH 200
6461 static float cursrfcol[2][4] = {{0.0,0.0,1.0,0.8},{1.0,0.0,0.0,0.8}};
6462 static int cursrfcoli = 0;
6463 static int idorad = 0;
6464 
6465 static int FLXup = 0;
6466 static Window FLXwin;
6467 static BSTRU flxbut[9];
6468 #define FLXWINW 320
6469 #define FLXWINH 250
6470 static short int *itypBackup = NULL;
6471 static int *idoh;
6472 static int *itot;
6473 
6474 static int PARup = 0;
6475 static Window PARwin;
6476 static BSTRU parbut[3];
6477 #define PARWINW 320
6478 #define PARWINH 250
6479 
6480 static int CHGup = 0;
6481 static int CHGret = 0;
6482 static int CHGopt = 0;
6483 static int CHGstat = 0;
6484 static int CHGother = 0;
6485 static Window CHGwin;
6486 static BSTRU chgbut[3];
6487 #define CHGWINW 350
6488 #define CHGWINH 150
6489 
6490 static int STRup = 0;
6491 static int STRCup = 0;
6492 static Window STRwin, STRCwin, subSTR, subSTRC;
6493 static BSTRU strbut[5];
6494 #define STRCBN 14
6495 static BSTRU strcbut[STRCBN];
6496 #define STRWINW 250
6497 #define STRWINH 265
6498 #define STRSH 150
6499 #define STRX 10
6500 #define STRW 205
6501 
6502 static int SELHup = 0;
6503 static Window SELHwin, subSELH;
6504 #define SELHBN 7
6505 static BSTRU selhbut[SELHBN];
6506 #define SELHWINW 230
6507 #define SELHWINH 200
6508 static int HINC;
6509 static int HRES;
6510 static int HLIG;
6511 static int HFLP;
6512 static int HHIS;
6513 static int HWAT;
6514 
6515 static int SRCHup = 0;
6516 static Window SRCHwin, subSRCH;
6517 #define SRCHBN 3
6518 static BSTRU butSRCH[SRCHBN];
6519 #define SRCHWINW 300
6520 #define SRCHWINH 350
6521 
6522 static int ANIMup = 0;
6523 static Window ANIMwin, subANIM;
6524 #define ANIMBN 5
6525 static BSTRU butANIM[ANIMBN];
6526 #define ANIMWINW 190
6527 #define ANIMWINH 86
6528 
6529 static int Movup = 0;
6530 static Window MOVwin;
6531 static BSTRU movbut[5];
6532 static int rmsnap = 1;
6533 static int timsnap = 0;
6534 static int record = 0;
6535 static int tmpfmt = 0;
6536 static int tmpmxg = 0;
6537 static int Tbeg = 0;
6538 static int Tend = 0;
6539 #define MOVWINW 250
6540 #define MOVWINH 150
6541 
6542 static int ONIup = 0;
6543 static Window ONIwin, subONI;
6544 #define NBUTSO 24
6545 #define OMETHH  0
6546 #define OBASSH  1
6547 #define OALLH   2
6548 #define OSELH   3
6549 #define OMETHL  4
6550 #define OBASSL  5
6551 #define OALLL   6
6552 #define OSELL   7
6553 #define OMETHM  8
6554 #define OBASSM  9
6555 #define OALLM  10
6556 #define OSELM  11
6557 #define OSEL   12
6558 #define OUSEL  13
6559 #define OCOLO  14
6560 #define OSELR  15
6561 #define OCLOS  16
6562 #define OCHARH 17
6563 #define OMULTH 18
6564 #define OCHARM 19
6565 #define OMULTM 20
6566 #define OCHARL 21
6567 #define OMULTL 22
6568 #define OAMBCH 23
6569 static BSTRU onbut[NBUTSO];
6570 #define OBOXWIDE 350
6571 #define OBOXHIGH 350
6572 #define OBOXOFFX 10
6573 #define OBOXBLEN 100
6574 #define ONIHCOL 12
6575 #define ONIMCOL 9
6576 #define ONILCOL 1
6577 static char olev[3][MAXSTRLEN];
6578 static int imopth = 0;
6579 static int imoptl = 0;
6580 static int imoptm = 0;
6581 static int ibopth = 0;
6582 static int iboptl = 0;
6583 static int iboptm = 0;
6584 static int lnkat = 0;
6585 
6586 static int FLRup = 0;
6587 static Window FLRwin, subFLR;
6588 #define NBUTSF  10
6589 #define FRIGD   0
6590 #define FSELR   1
6591 #define FFLEX   2
6592 #define FSELF   3
6593 #define FSEL    4
6594 #define FUSEL   5
6595 #define FSELA   6
6596 #define FCLOS   7
6597 #define FBACK   8
6598 #define FCONT   9
6599 static BSTRU flrbut[NBUTSF];
6600 
6601 #define FBOXWIDE 350
6602 #define FBOXHIGH 250
6603 #define FBOXOFFX 10
6604 #define FBOXBLEN 100
6605 
6606 #define FRIGCOL 12
6607 #define FLEXCOL 9
6608 
6609 static int bckrig = 0;
6610 
6611 static QBOXSTRU IANZboxes[MAXAT];
6612 static QBOXSTRU IZboxes[MAXAT][4];
6613 static QBOXSTRU BLboxes[MAXAT];
6614 static QBOXSTRU ALPHboxes[MAXAT];
6615 static QBOXSTRU BETboxes[MAXAT];
6616 static QBOXSTRU EXPbox[1];
6617 static QBOXSTRU TMPbox;
6618 
6619 static QBOXSTRU *IANZbox = IANZboxes;
6620 static QBOXSTRU *BLbox = BLboxes;
6621 static QBOXSTRU *ALPHbox = ALPHboxes;
6622 static QBOXSTRU *BETbox = BETboxes;
6623 static QBOXSTRU *IZbox = (QBOXSTRU *) IZboxes;
6624 static char *IANZstr =
6625 	"Element string. To change element\ntype new element and hit Enter/Return";
6626 static char *IZstr =
6627 	"Previously defined atoms used to define\nbondlength, bondangle and dihedral of current atom\nTo edit: Click with 1st mouse button to activate,\ntype previously defined atom number and hit Enter/Return\n4th field can be ignored";
6628 static char *BLstr =
6629 	"Bondlength between current atom and\natom specified in first connectivity field.\nTo edit: Click with 1st mouse button to activate,\n         type new bondlength and hit Enter/Return\nClick with 2nd mouse button for actions with this variable";
6630 static char *ALPHstr =
6631 	"Bondangle between current atom and\natoms specified in first two connectivity fields.\nTo edit: Click with 1st mouse button to activate,\n         type new bondangle and hit Enter/Return\nClick with 2nd mouse button for actions with this variable";
6632 static char *BETstr =
6633 	"Dihedral angle between current atom and\natoms specified in first three connectivity fields.\nTo edit: Click with 1st mouse button to activate,\n         type new angle and hit Enter/Return\nClick with 2nd mouse button for actions with this variable";
6634 
6635 static Window ZMEwin, subZM;
6636 static int ZMEbig = 1;
6637 #define ZMEWINW 513
6638 #define ZMEQHIGH 40
6639 #define ZMESHIGH 40
6640 #define ZMEFRBord 20
6641 #define ZMEBord 10
6642 #define ZMETab1 35
6643 #define ZMETab2 5
6644 #define ZMETab3 5
6645 #define ZME_window_high 8
6646 static int ZMEiz, ZMEizs, ZMEanW, ZMEconW, ZMEbutW, ZMEvarW, ZMEvarWs, ZMEiz4W;
6647 static int ZMEZWIDE;
6648 #define ZMEZHIGH ZME_window_high*ZMEQHIGH+2*ZMEFRBord+ZMEBord
6649 #define ZMEZOffx 10
6650 #define ZMEZOffy 50
6651 #define ZMESCR 5
6652 #define ZMEBOFFY 10
6653 #define ZMEBHIGH 160
6654 #define ZMEBWIDE 30
6655 #define ZMEButOffy ZMEZOffy-ZMEFRBord+ZMEZHIGH+ZMEBOFFY
6656 #define ZMEWOffy ZMEZOffy-ZMEFRBord+ZMEZHIGH+ZMEBHIGH+ZMESHIGH
6657 #define ZMEWHIGH 120
6658 #define ZMEWBOFF 80
6659 #define ZMEWINH ZMEZOffy-ZMEFRBord+ZMEZHIGH+ZMEBHIGH+ZMESHIGH+ZMEWHIGH-3
6660 #define ZMEBW2  ZMEWINW/2-2*ZMEZOffx
6661 #define ZMEBW4  (ZMEBW2-ZMEZOffx)/2
6662 #define ZMBCOL -15
6663 
6664 static int ZMEup = 0;
6665 static int ZME_window_pos;
6666 static int ZMEmode = 0;
6667 static int ZMEAA = 0;
6668 static int ZMEsel = 0;
6669 static int ZMEatom = 0;
6670 #define MAXZMEERR 70
6671 static char ZMEerr[MAXZMEERR];
6672 static char *zmevaropt[] = {"constant","variable","mark","unmark","animate","link","-link"};
6673 static char *zmevarclr[] = {"constant","variable"};
6674 static char *zmeblform[] = {"%f","%#9.3f"};
6675 static char *zmeform[] = {"%f","%#8.3f"};
6676 static char ZMEups[5];
6677 
6678 #define ZMEBUTTS 23
6679 
6680 static BSTRU ZMEbut[ZMEBUTTS];
6681 
6682 #define ZMEARR1 0
6683 #define ZMEARR2 1
6684 #define ZMEAPPL 2
6685 #define ZMECAN1 3
6686 #define ZMEFRG  4
6687 #define ZMEDEL  5
6688 #define ZMEADD  6
6689 #define ZMEGAM  7
6690 #define ZMEGAU  8
6691 #define ZMEMOP  9
6692 #define ZMECAR  10
6693 #define ZMENWC  11
6694 #define ZMEWRT  12
6695 #define ZMESEL  13
6696 #define ZMEUSEL 14
6697 #define ZMESELA 15
6698 #define ZMENEW  16
6699 #define ZMECANC 17
6700 #define ZMECVAR 18
6701 #define ZMEMAP  19
6702 #define ZMESUB  20
6703 #define ZMEORD  21
6704 #define ZMEUS   22
6705 
6706 static BSTRU ZMEBbut[3];
6707 #define ZMESIN  0
6708 #define ZMEDBL  1
6709 #define ZMETRI  2
6710 
6711 static int ZMEopt = ZMEGAM;
6712 static int ZMEmul = ZMESIN;
6713 static int *igztyp;
6714 static int *igtfil;
6715 
6716 static BSTRU ZMEAAbut[ZME_window_high];
6717 static BSTRU ZMEAASbut[ZME_window_high];
6718 static BSTRU ZMEswitch[2];
6719 
6720 #define TABBUTN 99
6721 static int TabPos[TABBUTN][2] = {
6722 	{0,0},{0,17},
6723 	{1,0},{1,1},{1,12},{1,13},{1,14},{1,15},{1,16},{1,17},
6724 	{2,0},{2,1},{2,12},{2,13},{2,14},{2,15},{2,16},{2,17},
6725 	{3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8},{3,9},{3,10},{3,11},{3,12},{3,13},{3,14},{3,15},{3,16},{3,17},
6726 	{4,0},{4,1},{4,2},{4,3},{4,4},{4,5},{4,6},{4,7},{4,8},{4,9},{4,10},{4,11},{4,12},{4,13},{4,14},{4,15},{4,16},{4,17},
6727 	{5,0},{5,1},{5,2},
6728 	{8,0},{8,1},{8,2},{8,3},{8,4},{8,5},{8,6},{8,7},{8,8},{8,9},{8,10},{8,11},{8,12},{8,13},
6729 	{5,3},{5,4},{5,5},{5,6},{5,7},{5,8},{5,9},{5,10},{5,11},{5,12},{5,13},{5,14},{5,15},{5,16},{5,17},
6730 	{6,0},{6,1},{6,2},
6731 	{9,0},{9,1},{9,2},{9,3},{9,4},{9,5},{9,6},{9,7},{9,8},
6732 	{11,9}
6733 		};
6734 static BSTRU TabBut[TABBUTN];
6735 static BSTRU AtmBut[TABBUTN];
6736 #define ZMETABH 24
6737 #define ZMETABA 22
6738 
6739 /*
6740 Covalent radii based on Pyykko's and Atsumi's work:
6741 http://www.chem.helsinki.fi/~pyykko/Radii09.pdf
6742 */
6743 
6744 #define NUMDIS 98
6745 static int DisAtoms[NUMDIS] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98};
6746 
6747 static float SingleDis[NUMDIS][NUMDIS] = {
6748    {0.64,0.78,1.65,1.34,1.17,1.07,1.03,0.95,0.96,0.99,1.87,1.71,1.58,1.48,1.43,1.35,1.31,1.28,2.28,2.03,1.80,1.68,1.66,1.54,1.51,1.48,1.43,1.42,1.44,1.50,1.56,1.53,1.53,1.48,1.46,1.49,2.42,2.17,1.95,1.86,1.79,1.70,1.60,1.57,1.57,1.52,1.60,1.68,1.74,1.72,1.72,1.68,1.65,1.63,2.64,2.28,2.12,1.95,2.08,2.06,2.05,2.04,2.00,2.01,2.00,1.99,1.98,1.97,1.96,2.02,1.94,1.84,1.78,1.69,1.63,1.61,1.54,1.55,1.56,1.65,1.76,1.76,1.83,1.77,1.79,1.74,2.55,2.33,2.18,2.07,2.01,2.02,2.03,2.04,1.98,1.98,2.00,2.00},
6749    {0.78,0.92,1.79,1.48,1.31,1.21,1.17,1.09,1.10,1.13,2.01,1.85,1.72,1.62,1.57,1.49,1.45,1.42,2.42,2.17,1.94,1.82,1.80,1.68,1.65,1.62,1.57,1.56,1.58,1.64,1.70,1.67,1.67,1.62,1.60,1.63,2.56,2.31,2.09,2.00,1.93,1.84,1.74,1.71,1.71,1.66,1.74,1.82,1.88,1.86,1.86,1.82,1.79,1.77,2.78,2.42,2.26,2.09,2.22,2.20,2.19,2.18,2.14,2.15,2.14,2.13,2.12,2.11,2.10,2.16,2.08,1.98,1.92,1.83,1.77,1.75,1.68,1.69,1.70,1.79,1.90,1.90,1.97,1.91,1.93,1.88,2.69,2.47,2.32,2.21,2.15,2.16,2.17,2.18,2.12,2.12,2.14,2.14},
6750    {1.65,1.79,2.66,2.35,2.18,2.08,2.04,1.96,1.97,2.00,2.88,2.72,2.59,2.49,2.44,2.36,2.32,2.29,3.29,3.04,2.81,2.69,2.67,2.55,2.52,2.49,2.44,2.43,2.45,2.51,2.57,2.54,2.54,2.49,2.47,2.50,3.43,3.18,2.96,2.87,2.80,2.71,2.61,2.58,2.58,2.53,2.61,2.69,2.75,2.73,2.73,2.69,2.66,2.64,3.65,3.29,3.13,2.96,3.09,3.07,3.06,3.05,3.01,3.02,3.01,3.00,2.99,2.98,2.97,3.03,2.95,2.85,2.79,2.70,2.64,2.62,2.55,2.56,2.57,2.66,2.77,2.77,2.84,2.78,2.80,2.75,3.56,3.34,3.19,3.08,3.02,3.03,3.04,3.05,2.99,2.99,3.01,3.01},
6751    {1.34,1.48,2.35,2.04,1.87,1.77,1.73,1.65,1.66,1.69,2.57,2.41,2.28,2.18,2.13,2.05,2.01,1.98,2.98,2.73,2.50,2.38,2.36,2.24,2.21,2.18,2.13,2.12,2.14,2.20,2.26,2.23,2.23,2.18,2.16,2.19,3.12,2.87,2.65,2.56,2.49,2.40,2.30,2.27,2.27,2.22,2.30,2.38,2.44,2.42,2.42,2.38,2.35,2.33,3.34,2.98,2.82,2.65,2.78,2.76,2.75,2.74,2.70,2.71,2.70,2.69,2.68,2.67,2.66,2.72,2.64,2.54,2.48,2.39,2.33,2.31,2.24,2.25,2.26,2.35,2.46,2.46,2.53,2.47,2.49,2.44,3.25,3.03,2.88,2.77,2.71,2.72,2.73,2.74,2.68,2.68,2.70,2.70},
6752    {1.17,1.31,2.18,1.87,1.70,1.60,1.56,1.48,1.49,1.52,2.40,2.24,2.11,2.01,1.96,1.88,1.84,1.81,2.81,2.56,2.33,2.21,2.19,2.07,2.04,2.01,1.96,1.95,1.97,2.03,2.09,2.06,2.06,2.01,1.99,2.02,2.95,2.70,2.48,2.39,2.32,2.23,2.13,2.10,2.10,2.05,2.13,2.21,2.27,2.25,2.25,2.21,2.18,2.16,3.17,2.81,2.65,2.48,2.61,2.59,2.58,2.57,2.53,2.54,2.53,2.52,2.51,2.50,2.49,2.55,2.47,2.37,2.31,2.22,2.16,2.14,2.07,2.08,2.09,2.18,2.29,2.29,2.36,2.30,2.32,2.27,3.08,2.86,2.71,2.60,2.54,2.55,2.56,2.57,2.51,2.51,2.53,2.53},
6753    {1.07,1.21,2.08,1.77,1.60,1.50,1.46,1.38,1.39,1.42,2.30,2.14,2.01,1.91,1.86,1.78,1.74,1.71,2.71,2.46,2.23,2.11,2.09,1.97,1.94,1.91,1.86,1.85,1.87,1.93,1.99,1.96,1.96,1.91,1.89,1.92,2.85,2.60,2.38,2.29,2.22,2.13,2.03,2.00,2.00,1.95,2.03,2.11,2.17,2.15,2.15,2.11,2.08,2.06,3.07,2.71,2.55,2.38,2.51,2.49,2.48,2.47,2.43,2.44,2.43,2.42,2.41,2.40,2.39,2.45,2.37,2.27,2.21,2.12,2.06,2.04,1.97,1.98,1.99,2.08,2.19,2.19,2.26,2.20,2.22,2.17,2.98,2.76,2.61,2.50,2.44,2.45,2.46,2.47,2.41,2.41,2.43,2.43},
6754    {1.03,1.17,2.04,1.73,1.56,1.46,1.42,1.34,1.35,1.38,2.26,2.10,1.97,1.87,1.82,1.74,1.70,1.67,2.67,2.42,2.19,2.07,2.05,1.93,1.90,1.87,1.82,1.81,1.83,1.89,1.95,1.92,1.92,1.87,1.85,1.88,2.81,2.56,2.34,2.25,2.18,2.09,1.99,1.96,1.96,1.91,1.99,2.07,2.13,2.11,2.11,2.07,2.04,2.02,3.03,2.67,2.51,2.34,2.47,2.45,2.44,2.43,2.39,2.40,2.39,2.38,2.37,2.36,2.35,2.41,2.33,2.23,2.17,2.08,2.02,2.00,1.93,1.94,1.95,2.04,2.15,2.15,2.22,2.16,2.18,2.13,2.94,2.72,2.57,2.46,2.40,2.41,2.42,2.43,2.37,2.37,2.39,2.39},
6755    {0.95,1.09,1.96,1.65,1.48,1.38,1.34,1.26,1.27,1.30,2.18,2.02,1.89,1.79,1.74,1.66,1.62,1.59,2.59,2.34,2.11,1.99,1.97,1.85,1.82,1.79,1.74,1.73,1.75,1.81,1.87,1.84,1.84,1.79,1.77,1.80,2.73,2.48,2.26,2.17,2.10,2.01,1.91,1.88,1.88,1.83,1.91,1.99,2.05,2.03,2.03,1.99,1.96,1.94,2.95,2.59,2.43,2.26,2.39,2.37,2.36,2.35,2.31,2.32,2.31,2.30,2.29,2.28,2.27,2.33,2.25,2.15,2.09,2.00,1.94,1.92,1.85,1.86,1.87,1.96,2.07,2.07,2.14,2.08,2.10,2.05,2.86,2.64,2.49,2.38,2.32,2.33,2.34,2.35,2.29,2.29,2.31,2.31},
6756    {0.96,1.10,1.97,1.66,1.49,1.39,1.35,1.27,1.28,1.31,2.19,2.03,1.90,1.80,1.75,1.67,1.63,1.60,2.60,2.35,2.12,2.00,1.98,1.86,1.83,1.80,1.75,1.74,1.76,1.82,1.88,1.85,1.85,1.80,1.78,1.81,2.74,2.49,2.27,2.18,2.11,2.02,1.92,1.89,1.89,1.84,1.92,2.00,2.06,2.04,2.04,2.00,1.97,1.95,2.96,2.60,2.44,2.27,2.40,2.38,2.37,2.36,2.32,2.33,2.32,2.31,2.30,2.29,2.28,2.34,2.26,2.16,2.10,2.01,1.95,1.93,1.86,1.87,1.88,1.97,2.08,2.08,2.15,2.09,2.11,2.06,2.87,2.65,2.50,2.39,2.33,2.34,2.35,2.36,2.30,2.30,2.32,2.32},
6757    {0.99,1.13,2.00,1.69,1.52,1.42,1.38,1.30,1.31,1.34,2.22,2.06,1.93,1.83,1.78,1.70,1.66,1.63,2.63,2.38,2.15,2.03,2.01,1.89,1.86,1.83,1.78,1.77,1.79,1.85,1.91,1.88,1.88,1.83,1.81,1.84,2.77,2.52,2.30,2.21,2.14,2.05,1.95,1.92,1.92,1.87,1.95,2.03,2.09,2.07,2.07,2.03,2.00,1.98,2.99,2.63,2.47,2.30,2.43,2.41,2.40,2.39,2.35,2.36,2.35,2.34,2.33,2.32,2.31,2.37,2.29,2.19,2.13,2.04,1.98,1.96,1.89,1.90,1.91,2.00,2.11,2.11,2.18,2.12,2.14,2.09,2.90,2.68,2.53,2.42,2.36,2.37,2.38,2.39,2.33,2.33,2.35,2.35},
6758    {1.87,2.01,2.88,2.57,2.40,2.30,2.26,2.18,2.19,2.22,3.10,2.94,2.81,2.71,2.66,2.58,2.54,2.51,3.51,3.26,3.03,2.91,2.89,2.77,2.74,2.71,2.66,2.65,2.67,2.73,2.79,2.76,2.76,2.71,2.69,2.72,3.65,3.40,3.18,3.09,3.02,2.93,2.83,2.80,2.80,2.75,2.83,2.91,2.97,2.95,2.95,2.91,2.88,2.86,3.87,3.51,3.35,3.18,3.31,3.29,3.28,3.27,3.23,3.24,3.23,3.22,3.21,3.20,3.19,3.25,3.17,3.07,3.01,2.92,2.86,2.84,2.77,2.78,2.79,2.88,2.99,2.99,3.06,3.00,3.02,2.97,3.78,3.56,3.41,3.30,3.24,3.25,3.26,3.27,3.21,3.21,3.23,3.23},
6759    {1.71,1.85,2.72,2.41,2.24,2.14,2.10,2.02,2.03,2.06,2.94,2.78,2.65,2.55,2.50,2.42,2.38,2.35,3.35,3.10,2.87,2.75,2.73,2.61,2.58,2.55,2.50,2.49,2.51,2.57,2.63,2.60,2.60,2.55,2.53,2.56,3.49,3.24,3.02,2.93,2.86,2.77,2.67,2.64,2.64,2.59,2.67,2.75,2.81,2.79,2.79,2.75,2.72,2.70,3.71,3.35,3.19,3.02,3.15,3.13,3.12,3.11,3.07,3.08,3.07,3.06,3.05,3.04,3.03,3.09,3.01,2.91,2.85,2.76,2.70,2.68,2.61,2.62,2.63,2.72,2.83,2.83,2.90,2.84,2.86,2.81,3.62,3.40,3.25,3.14,3.08,3.09,3.10,3.11,3.05,3.05,3.07,3.07},
6760    {1.58,1.72,2.59,2.28,2.11,2.01,1.97,1.89,1.90,1.93,2.81,2.65,2.52,2.42,2.37,2.29,2.25,2.22,3.22,2.97,2.74,2.62,2.60,2.48,2.45,2.42,2.37,2.36,2.38,2.44,2.50,2.47,2.47,2.42,2.40,2.43,3.36,3.11,2.89,2.80,2.73,2.64,2.54,2.51,2.51,2.46,2.54,2.62,2.68,2.66,2.66,2.62,2.59,2.57,3.58,3.22,3.06,2.89,3.02,3.00,2.99,2.98,2.94,2.95,2.94,2.93,2.92,2.91,2.90,2.96,2.88,2.78,2.72,2.63,2.57,2.55,2.48,2.49,2.50,2.59,2.70,2.70,2.77,2.71,2.73,2.68,3.49,3.27,3.12,3.01,2.95,2.96,2.97,2.98,2.92,2.92,2.94,2.94},
6761    {1.48,1.62,2.49,2.18,2.01,1.91,1.87,1.79,1.80,1.83,2.71,2.55,2.42,2.32,2.27,2.19,2.15,2.12,3.12,2.87,2.64,2.52,2.50,2.38,2.35,2.32,2.27,2.26,2.28,2.34,2.40,2.37,2.37,2.32,2.30,2.33,3.26,3.01,2.79,2.70,2.63,2.54,2.44,2.41,2.41,2.36,2.44,2.52,2.58,2.56,2.56,2.52,2.49,2.47,3.48,3.12,2.96,2.79,2.92,2.90,2.89,2.88,2.84,2.85,2.84,2.83,2.82,2.81,2.80,2.86,2.78,2.68,2.62,2.53,2.47,2.45,2.38,2.39,2.40,2.49,2.60,2.60,2.67,2.61,2.63,2.58,3.39,3.17,3.02,2.91,2.85,2.86,2.87,2.88,2.82,2.82,2.84,2.84},
6762    {1.43,1.57,2.44,2.13,1.96,1.86,1.82,1.74,1.75,1.78,2.66,2.50,2.37,2.27,2.22,2.14,2.10,2.07,3.07,2.82,2.59,2.47,2.45,2.33,2.30,2.27,2.22,2.21,2.23,2.29,2.35,2.32,2.32,2.27,2.25,2.28,3.21,2.96,2.74,2.65,2.58,2.49,2.39,2.36,2.36,2.31,2.39,2.47,2.53,2.51,2.51,2.47,2.44,2.42,3.43,3.07,2.91,2.74,2.87,2.85,2.84,2.83,2.79,2.80,2.79,2.78,2.77,2.76,2.75,2.81,2.73,2.63,2.57,2.48,2.42,2.40,2.33,2.34,2.35,2.44,2.55,2.55,2.62,2.56,2.58,2.53,3.34,3.12,2.97,2.86,2.80,2.81,2.82,2.83,2.77,2.77,2.79,2.79},
6763    {1.35,1.49,2.36,2.05,1.88,1.78,1.74,1.66,1.67,1.70,2.58,2.42,2.29,2.19,2.14,2.06,2.02,1.99,2.99,2.74,2.51,2.39,2.37,2.25,2.22,2.19,2.14,2.13,2.15,2.21,2.27,2.24,2.24,2.19,2.17,2.20,3.13,2.88,2.66,2.57,2.50,2.41,2.31,2.28,2.28,2.23,2.31,2.39,2.45,2.43,2.43,2.39,2.36,2.34,3.35,2.99,2.83,2.66,2.79,2.77,2.76,2.75,2.71,2.72,2.71,2.70,2.69,2.68,2.67,2.73,2.65,2.55,2.49,2.40,2.34,2.32,2.25,2.26,2.27,2.36,2.47,2.47,2.54,2.48,2.50,2.45,3.26,3.04,2.89,2.78,2.72,2.73,2.74,2.75,2.69,2.69,2.71,2.71},
6764    {1.31,1.45,2.32,2.01,1.84,1.74,1.70,1.62,1.63,1.66,2.54,2.38,2.25,2.15,2.10,2.02,1.98,1.95,2.95,2.70,2.47,2.35,2.33,2.21,2.18,2.15,2.10,2.09,2.11,2.17,2.23,2.20,2.20,2.15,2.13,2.16,3.09,2.84,2.62,2.53,2.46,2.37,2.27,2.24,2.24,2.19,2.27,2.35,2.41,2.39,2.39,2.35,2.32,2.30,3.31,2.95,2.79,2.62,2.75,2.73,2.72,2.71,2.67,2.68,2.67,2.66,2.65,2.64,2.63,2.69,2.61,2.51,2.45,2.36,2.30,2.28,2.21,2.22,2.23,2.32,2.43,2.43,2.50,2.44,2.46,2.41,3.22,3.00,2.85,2.74,2.68,2.69,2.70,2.71,2.65,2.65,2.67,2.67},
6765    {1.28,1.42,2.29,1.98,1.81,1.71,1.67,1.59,1.60,1.63,2.51,2.35,2.22,2.12,2.07,1.99,1.95,1.92,2.92,2.67,2.44,2.32,2.30,2.18,2.15,2.12,2.07,2.06,2.08,2.14,2.20,2.17,2.17,2.12,2.10,2.13,3.06,2.81,2.59,2.50,2.43,2.34,2.24,2.21,2.21,2.16,2.24,2.32,2.38,2.36,2.36,2.32,2.29,2.27,3.28,2.92,2.76,2.59,2.72,2.70,2.69,2.68,2.64,2.65,2.64,2.63,2.62,2.61,2.60,2.66,2.58,2.48,2.42,2.33,2.27,2.25,2.18,2.19,2.20,2.29,2.40,2.40,2.47,2.41,2.43,2.38,3.19,2.97,2.82,2.71,2.65,2.66,2.67,2.68,2.62,2.62,2.64,2.64},
6766    {2.28,2.42,3.29,2.98,2.81,2.71,2.67,2.59,2.60,2.63,3.51,3.35,3.22,3.12,3.07,2.99,2.95,2.92,3.92,3.67,3.44,3.32,3.30,3.18,3.15,3.12,3.07,3.06,3.08,3.14,3.20,3.17,3.17,3.12,3.10,3.13,4.06,3.81,3.59,3.50,3.43,3.34,3.24,3.21,3.21,3.16,3.24,3.32,3.38,3.36,3.36,3.32,3.29,3.27,4.28,3.92,3.76,3.59,3.72,3.70,3.69,3.68,3.64,3.65,3.64,3.63,3.62,3.61,3.60,3.66,3.58,3.48,3.42,3.33,3.27,3.25,3.18,3.19,3.20,3.29,3.40,3.40,3.47,3.41,3.43,3.38,4.19,3.97,3.82,3.71,3.65,3.66,3.67,3.68,3.62,3.62,3.64,3.64},
6767    {2.03,2.17,3.04,2.73,2.56,2.46,2.42,2.34,2.35,2.38,3.26,3.10,2.97,2.87,2.82,2.74,2.70,2.67,3.67,3.42,3.19,3.07,3.05,2.93,2.90,2.87,2.82,2.81,2.83,2.89,2.95,2.92,2.92,2.87,2.85,2.88,3.81,3.56,3.34,3.25,3.18,3.09,2.99,2.96,2.96,2.91,2.99,3.07,3.13,3.11,3.11,3.07,3.04,3.02,4.03,3.67,3.51,3.34,3.47,3.45,3.44,3.43,3.39,3.40,3.39,3.38,3.37,3.36,3.35,3.41,3.33,3.23,3.17,3.08,3.02,3.00,2.93,2.94,2.95,3.04,3.15,3.15,3.22,3.16,3.18,3.13,3.94,3.72,3.57,3.46,3.40,3.41,3.42,3.43,3.37,3.37,3.39,3.39},
6768    {1.80,1.94,2.81,2.50,2.33,2.23,2.19,2.11,2.12,2.15,3.03,2.87,2.74,2.64,2.59,2.51,2.47,2.44,3.44,3.19,2.96,2.84,2.82,2.70,2.67,2.64,2.59,2.58,2.60,2.66,2.72,2.69,2.69,2.64,2.62,2.65,3.58,3.33,3.11,3.02,2.95,2.86,2.76,2.73,2.73,2.68,2.76,2.84,2.90,2.88,2.88,2.84,2.81,2.79,3.80,3.44,3.28,3.11,3.24,3.22,3.21,3.20,3.16,3.17,3.16,3.15,3.14,3.13,3.12,3.18,3.10,3.00,2.94,2.85,2.79,2.77,2.70,2.71,2.72,2.81,2.92,2.92,2.99,2.93,2.95,2.90,3.71,3.49,3.34,3.23,3.17,3.18,3.19,3.20,3.14,3.14,3.16,3.16},
6769    {1.68,1.82,2.69,2.38,2.21,2.11,2.07,1.99,2.00,2.03,2.91,2.75,2.62,2.52,2.47,2.39,2.35,2.32,3.32,3.07,2.84,2.72,2.70,2.58,2.55,2.52,2.47,2.46,2.48,2.54,2.60,2.57,2.57,2.52,2.50,2.53,3.46,3.21,2.99,2.90,2.83,2.74,2.64,2.61,2.61,2.56,2.64,2.72,2.78,2.76,2.76,2.72,2.69,2.67,3.68,3.32,3.16,2.99,3.12,3.10,3.09,3.08,3.04,3.05,3.04,3.03,3.02,3.01,3.00,3.06,2.98,2.88,2.82,2.73,2.67,2.65,2.58,2.59,2.60,2.69,2.80,2.80,2.87,2.81,2.83,2.78,3.59,3.37,3.22,3.11,3.05,3.06,3.07,3.08,3.02,3.02,3.04,3.04},
6770    {1.66,1.80,2.67,2.36,2.19,2.09,2.05,1.97,1.98,2.01,2.89,2.73,2.60,2.50,2.45,2.37,2.33,2.30,3.30,3.05,2.82,2.70,2.68,2.56,2.53,2.50,2.45,2.44,2.46,2.52,2.58,2.55,2.55,2.50,2.48,2.51,3.44,3.19,2.97,2.88,2.81,2.72,2.62,2.59,2.59,2.54,2.62,2.70,2.76,2.74,2.74,2.70,2.67,2.65,3.66,3.30,3.14,2.97,3.10,3.08,3.07,3.06,3.02,3.03,3.02,3.01,3.00,2.99,2.98,3.04,2.96,2.86,2.80,2.71,2.65,2.63,2.56,2.57,2.58,2.67,2.78,2.78,2.85,2.79,2.81,2.76,3.57,3.35,3.20,3.09,3.03,3.04,3.05,3.06,3.00,3.00,3.02,3.02},
6771    {1.54,1.68,2.55,2.24,2.07,1.97,1.93,1.85,1.86,1.89,2.77,2.61,2.48,2.38,2.33,2.25,2.21,2.18,3.18,2.93,2.70,2.58,2.56,2.44,2.41,2.38,2.33,2.32,2.34,2.40,2.46,2.43,2.43,2.38,2.36,2.39,3.32,3.07,2.85,2.76,2.69,2.60,2.50,2.47,2.47,2.42,2.50,2.58,2.64,2.62,2.62,2.58,2.55,2.53,3.54,3.18,3.02,2.85,2.98,2.96,2.95,2.94,2.90,2.91,2.90,2.89,2.88,2.87,2.86,2.92,2.84,2.74,2.68,2.59,2.53,2.51,2.44,2.45,2.46,2.55,2.66,2.66,2.73,2.67,2.69,2.64,3.45,3.23,3.08,2.97,2.91,2.92,2.93,2.94,2.88,2.88,2.90,2.90},
6772    {1.51,1.65,2.52,2.21,2.04,1.94,1.90,1.82,1.83,1.86,2.74,2.58,2.45,2.35,2.30,2.22,2.18,2.15,3.15,2.90,2.67,2.55,2.53,2.41,2.38,2.35,2.30,2.29,2.31,2.37,2.43,2.40,2.40,2.35,2.33,2.36,3.29,3.04,2.82,2.73,2.66,2.57,2.47,2.44,2.44,2.39,2.47,2.55,2.61,2.59,2.59,2.55,2.52,2.50,3.51,3.15,2.99,2.82,2.95,2.93,2.92,2.91,2.87,2.88,2.87,2.86,2.85,2.84,2.83,2.89,2.81,2.71,2.65,2.56,2.50,2.48,2.41,2.42,2.43,2.52,2.63,2.63,2.70,2.64,2.66,2.61,3.42,3.20,3.05,2.94,2.88,2.89,2.90,2.91,2.85,2.85,2.87,2.87},
6773    {1.48,1.62,2.49,2.18,2.01,1.91,1.87,1.79,1.80,1.83,2.71,2.55,2.42,2.32,2.27,2.19,2.15,2.12,3.12,2.87,2.64,2.52,2.50,2.38,2.35,2.32,2.27,2.26,2.28,2.34,2.40,2.37,2.37,2.32,2.30,2.33,3.26,3.01,2.79,2.70,2.63,2.54,2.44,2.41,2.41,2.36,2.44,2.52,2.58,2.56,2.56,2.52,2.49,2.47,3.48,3.12,2.96,2.79,2.92,2.90,2.89,2.88,2.84,2.85,2.84,2.83,2.82,2.81,2.80,2.86,2.78,2.68,2.62,2.53,2.47,2.45,2.38,2.39,2.40,2.49,2.60,2.60,2.67,2.61,2.63,2.58,3.39,3.17,3.02,2.91,2.85,2.86,2.87,2.88,2.82,2.82,2.84,2.84},
6774    {1.43,1.57,2.44,2.13,1.96,1.86,1.82,1.74,1.75,1.78,2.66,2.50,2.37,2.27,2.22,2.14,2.10,2.07,3.07,2.82,2.59,2.47,2.45,2.33,2.30,2.27,2.22,2.21,2.23,2.29,2.35,2.32,2.32,2.27,2.25,2.28,3.21,2.96,2.74,2.65,2.58,2.49,2.39,2.36,2.36,2.31,2.39,2.47,2.53,2.51,2.51,2.47,2.44,2.42,3.43,3.07,2.91,2.74,2.87,2.85,2.84,2.83,2.79,2.80,2.79,2.78,2.77,2.76,2.75,2.81,2.73,2.63,2.57,2.48,2.42,2.40,2.33,2.34,2.35,2.44,2.55,2.55,2.62,2.56,2.58,2.53,3.34,3.12,2.97,2.86,2.80,2.81,2.82,2.83,2.77,2.77,2.79,2.79},
6775    {1.42,1.56,2.43,2.12,1.95,1.85,1.81,1.73,1.74,1.77,2.65,2.49,2.36,2.26,2.21,2.13,2.09,2.06,3.06,2.81,2.58,2.46,2.44,2.32,2.29,2.26,2.21,2.20,2.22,2.28,2.34,2.31,2.31,2.26,2.24,2.27,3.20,2.95,2.73,2.64,2.57,2.48,2.38,2.35,2.35,2.30,2.38,2.46,2.52,2.50,2.50,2.46,2.43,2.41,3.42,3.06,2.90,2.73,2.86,2.84,2.83,2.82,2.78,2.79,2.78,2.77,2.76,2.75,2.74,2.80,2.72,2.62,2.56,2.47,2.41,2.39,2.32,2.33,2.34,2.43,2.54,2.54,2.61,2.55,2.57,2.52,3.33,3.11,2.96,2.85,2.79,2.80,2.81,2.82,2.76,2.76,2.78,2.78},
6776    {1.44,1.58,2.45,2.14,1.97,1.87,1.83,1.75,1.76,1.79,2.67,2.51,2.38,2.28,2.23,2.15,2.11,2.08,3.08,2.83,2.60,2.48,2.46,2.34,2.31,2.28,2.23,2.22,2.24,2.30,2.36,2.33,2.33,2.28,2.26,2.29,3.22,2.97,2.75,2.66,2.59,2.50,2.40,2.37,2.37,2.32,2.40,2.48,2.54,2.52,2.52,2.48,2.45,2.43,3.44,3.08,2.92,2.75,2.88,2.86,2.85,2.84,2.80,2.81,2.80,2.79,2.78,2.77,2.76,2.82,2.74,2.64,2.58,2.49,2.43,2.41,2.34,2.35,2.36,2.45,2.56,2.56,2.63,2.57,2.59,2.54,3.35,3.13,2.98,2.87,2.81,2.82,2.83,2.84,2.78,2.78,2.80,2.80},
6777    {1.50,1.64,2.51,2.20,2.03,1.93,1.89,1.81,1.82,1.85,2.73,2.57,2.44,2.34,2.29,2.21,2.17,2.14,3.14,2.89,2.66,2.54,2.52,2.40,2.37,2.34,2.29,2.28,2.30,2.36,2.42,2.39,2.39,2.34,2.32,2.35,3.28,3.03,2.81,2.72,2.65,2.56,2.46,2.43,2.43,2.38,2.46,2.54,2.60,2.58,2.58,2.54,2.51,2.49,3.50,3.14,2.98,2.81,2.94,2.92,2.91,2.90,2.86,2.87,2.86,2.85,2.84,2.83,2.82,2.88,2.80,2.70,2.64,2.55,2.49,2.47,2.40,2.41,2.42,2.51,2.62,2.62,2.69,2.63,2.65,2.60,3.41,3.19,3.04,2.93,2.87,2.88,2.89,2.90,2.84,2.84,2.86,2.86},
6778    {1.56,1.70,2.57,2.26,2.09,1.99,1.95,1.87,1.88,1.91,2.79,2.63,2.50,2.40,2.35,2.27,2.23,2.20,3.20,2.95,2.72,2.60,2.58,2.46,2.43,2.40,2.35,2.34,2.36,2.42,2.48,2.45,2.45,2.40,2.38,2.41,3.34,3.09,2.87,2.78,2.71,2.62,2.52,2.49,2.49,2.44,2.52,2.60,2.66,2.64,2.64,2.60,2.57,2.55,3.56,3.20,3.04,2.87,3.00,2.98,2.97,2.96,2.92,2.93,2.92,2.91,2.90,2.89,2.88,2.94,2.86,2.76,2.70,2.61,2.55,2.53,2.46,2.47,2.48,2.57,2.68,2.68,2.75,2.69,2.71,2.66,3.47,3.25,3.10,2.99,2.93,2.94,2.95,2.96,2.90,2.90,2.92,2.92},
6779    {1.53,1.67,2.54,2.23,2.06,1.96,1.92,1.84,1.85,1.88,2.76,2.60,2.47,2.37,2.32,2.24,2.20,2.17,3.17,2.92,2.69,2.57,2.55,2.43,2.40,2.37,2.32,2.31,2.33,2.39,2.45,2.42,2.42,2.37,2.35,2.38,3.31,3.06,2.84,2.75,2.68,2.59,2.49,2.46,2.46,2.41,2.49,2.57,2.63,2.61,2.61,2.57,2.54,2.52,3.53,3.17,3.01,2.84,2.97,2.95,2.94,2.93,2.89,2.90,2.89,2.88,2.87,2.86,2.85,2.91,2.83,2.73,2.67,2.58,2.52,2.50,2.43,2.44,2.45,2.54,2.65,2.65,2.72,2.66,2.68,2.63,3.44,3.22,3.07,2.96,2.90,2.91,2.92,2.93,2.87,2.87,2.89,2.89},
6780    {1.53,1.67,2.54,2.23,2.06,1.96,1.92,1.84,1.85,1.88,2.76,2.60,2.47,2.37,2.32,2.24,2.20,2.17,3.17,2.92,2.69,2.57,2.55,2.43,2.40,2.37,2.32,2.31,2.33,2.39,2.45,2.42,2.42,2.37,2.35,2.38,3.31,3.06,2.84,2.75,2.68,2.59,2.49,2.46,2.46,2.41,2.49,2.57,2.63,2.61,2.61,2.57,2.54,2.52,3.53,3.17,3.01,2.84,2.97,2.95,2.94,2.93,2.89,2.90,2.89,2.88,2.87,2.86,2.85,2.91,2.83,2.73,2.67,2.58,2.52,2.50,2.43,2.44,2.45,2.54,2.65,2.65,2.72,2.66,2.68,2.63,3.44,3.22,3.07,2.96,2.90,2.91,2.92,2.93,2.87,2.87,2.89,2.89},
6781    {1.48,1.62,2.49,2.18,2.01,1.91,1.87,1.79,1.80,1.83,2.71,2.55,2.42,2.32,2.27,2.19,2.15,2.12,3.12,2.87,2.64,2.52,2.50,2.38,2.35,2.32,2.27,2.26,2.28,2.34,2.40,2.37,2.37,2.32,2.30,2.33,3.26,3.01,2.79,2.70,2.63,2.54,2.44,2.41,2.41,2.36,2.44,2.52,2.58,2.56,2.56,2.52,2.49,2.47,3.48,3.12,2.96,2.79,2.92,2.90,2.89,2.88,2.84,2.85,2.84,2.83,2.82,2.81,2.80,2.86,2.78,2.68,2.62,2.53,2.47,2.45,2.38,2.39,2.40,2.49,2.60,2.60,2.67,2.61,2.63,2.58,3.39,3.17,3.02,2.91,2.85,2.86,2.87,2.88,2.82,2.82,2.84,2.84},
6782    {1.46,1.60,2.47,2.16,1.99,1.89,1.85,1.77,1.78,1.81,2.69,2.53,2.40,2.30,2.25,2.17,2.13,2.10,3.10,2.85,2.62,2.50,2.48,2.36,2.33,2.30,2.25,2.24,2.26,2.32,2.38,2.35,2.35,2.30,2.28,2.31,3.24,2.99,2.77,2.68,2.61,2.52,2.42,2.39,2.39,2.34,2.42,2.50,2.56,2.54,2.54,2.50,2.47,2.45,3.46,3.10,2.94,2.77,2.90,2.88,2.87,2.86,2.82,2.83,2.82,2.81,2.80,2.79,2.78,2.84,2.76,2.66,2.60,2.51,2.45,2.43,2.36,2.37,2.38,2.47,2.58,2.58,2.65,2.59,2.61,2.56,3.37,3.15,3.00,2.89,2.83,2.84,2.85,2.86,2.80,2.80,2.82,2.82},
6783    {1.49,1.63,2.50,2.19,2.02,1.92,1.88,1.80,1.81,1.84,2.72,2.56,2.43,2.33,2.28,2.20,2.16,2.13,3.13,2.88,2.65,2.53,2.51,2.39,2.36,2.33,2.28,2.27,2.29,2.35,2.41,2.38,2.38,2.33,2.31,2.34,3.27,3.02,2.80,2.71,2.64,2.55,2.45,2.42,2.42,2.37,2.45,2.53,2.59,2.57,2.57,2.53,2.50,2.48,3.49,3.13,2.97,2.80,2.93,2.91,2.90,2.89,2.85,2.86,2.85,2.84,2.83,2.82,2.81,2.87,2.79,2.69,2.63,2.54,2.48,2.46,2.39,2.40,2.41,2.50,2.61,2.61,2.68,2.62,2.64,2.59,3.40,3.18,3.03,2.92,2.86,2.87,2.88,2.89,2.83,2.83,2.85,2.85},
6784    {2.42,2.56,3.43,3.12,2.95,2.85,2.81,2.73,2.74,2.77,3.65,3.49,3.36,3.26,3.21,3.13,3.09,3.06,4.06,3.81,3.58,3.46,3.44,3.32,3.29,3.26,3.21,3.20,3.22,3.28,3.34,3.31,3.31,3.26,3.24,3.27,4.20,3.95,3.73,3.64,3.57,3.48,3.38,3.35,3.35,3.30,3.38,3.46,3.52,3.50,3.50,3.46,3.43,3.41,4.42,4.06,3.90,3.73,3.86,3.84,3.83,3.82,3.78,3.79,3.78,3.77,3.76,3.75,3.74,3.80,3.72,3.62,3.56,3.47,3.41,3.39,3.32,3.33,3.34,3.43,3.54,3.54,3.61,3.55,3.57,3.52,4.33,4.11,3.96,3.85,3.79,3.80,3.81,3.82,3.76,3.76,3.78,3.78},
6785    {2.17,2.31,3.18,2.87,2.70,2.60,2.56,2.48,2.49,2.52,3.40,3.24,3.11,3.01,2.96,2.88,2.84,2.81,3.81,3.56,3.33,3.21,3.19,3.07,3.04,3.01,2.96,2.95,2.97,3.03,3.09,3.06,3.06,3.01,2.99,3.02,3.95,3.70,3.48,3.39,3.32,3.23,3.13,3.10,3.10,3.05,3.13,3.21,3.27,3.25,3.25,3.21,3.18,3.16,4.17,3.81,3.65,3.48,3.61,3.59,3.58,3.57,3.53,3.54,3.53,3.52,3.51,3.50,3.49,3.55,3.47,3.37,3.31,3.22,3.16,3.14,3.07,3.08,3.09,3.18,3.29,3.29,3.36,3.30,3.32,3.27,4.08,3.86,3.71,3.60,3.54,3.55,3.56,3.57,3.51,3.51,3.53,3.53},
6786    {1.95,2.09,2.96,2.65,2.48,2.38,2.34,2.26,2.27,2.30,3.18,3.02,2.89,2.79,2.74,2.66,2.62,2.59,3.59,3.34,3.11,2.99,2.97,2.85,2.82,2.79,2.74,2.73,2.75,2.81,2.87,2.84,2.84,2.79,2.77,2.80,3.73,3.48,3.26,3.17,3.10,3.01,2.91,2.88,2.88,2.83,2.91,2.99,3.05,3.03,3.03,2.99,2.96,2.94,3.95,3.59,3.43,3.26,3.39,3.37,3.36,3.35,3.31,3.32,3.31,3.30,3.29,3.28,3.27,3.33,3.25,3.15,3.09,3.00,2.94,2.92,2.85,2.86,2.87,2.96,3.07,3.07,3.14,3.08,3.10,3.05,3.86,3.64,3.49,3.38,3.32,3.33,3.34,3.35,3.29,3.29,3.31,3.31},
6787    {1.86,2.00,2.87,2.56,2.39,2.29,2.25,2.17,2.18,2.21,3.09,2.93,2.80,2.70,2.65,2.57,2.53,2.50,3.50,3.25,3.02,2.90,2.88,2.76,2.73,2.70,2.65,2.64,2.66,2.72,2.78,2.75,2.75,2.70,2.68,2.71,3.64,3.39,3.17,3.08,3.01,2.92,2.82,2.79,2.79,2.74,2.82,2.90,2.96,2.94,2.94,2.90,2.87,2.85,3.86,3.50,3.34,3.17,3.30,3.28,3.27,3.26,3.22,3.23,3.22,3.21,3.20,3.19,3.18,3.24,3.16,3.06,3.00,2.91,2.85,2.83,2.76,2.77,2.78,2.87,2.98,2.98,3.05,2.99,3.01,2.96,3.77,3.55,3.40,3.29,3.23,3.24,3.25,3.26,3.20,3.20,3.22,3.22},
6788    {1.79,1.93,2.80,2.49,2.32,2.22,2.18,2.10,2.11,2.14,3.02,2.86,2.73,2.63,2.58,2.50,2.46,2.43,3.43,3.18,2.95,2.83,2.81,2.69,2.66,2.63,2.58,2.57,2.59,2.65,2.71,2.68,2.68,2.63,2.61,2.64,3.57,3.32,3.10,3.01,2.94,2.85,2.75,2.72,2.72,2.67,2.75,2.83,2.89,2.87,2.87,2.83,2.80,2.78,3.79,3.43,3.27,3.10,3.23,3.21,3.20,3.19,3.15,3.16,3.15,3.14,3.13,3.12,3.11,3.17,3.09,2.99,2.93,2.84,2.78,2.76,2.69,2.70,2.71,2.80,2.91,2.91,2.98,2.92,2.94,2.89,3.70,3.48,3.33,3.22,3.16,3.17,3.18,3.19,3.13,3.13,3.15,3.15},
6789    {1.70,1.84,2.71,2.40,2.23,2.13,2.09,2.01,2.02,2.05,2.93,2.77,2.64,2.54,2.49,2.41,2.37,2.34,3.34,3.09,2.86,2.74,2.72,2.60,2.57,2.54,2.49,2.48,2.50,2.56,2.62,2.59,2.59,2.54,2.52,2.55,3.48,3.23,3.01,2.92,2.85,2.76,2.66,2.63,2.63,2.58,2.66,2.74,2.80,2.78,2.78,2.74,2.71,2.69,3.70,3.34,3.18,3.01,3.14,3.12,3.11,3.10,3.06,3.07,3.06,3.05,3.04,3.03,3.02,3.08,3.00,2.90,2.84,2.75,2.69,2.67,2.60,2.61,2.62,2.71,2.82,2.82,2.89,2.83,2.85,2.80,3.61,3.39,3.24,3.13,3.07,3.08,3.09,3.10,3.04,3.04,3.06,3.06},
6790    {1.60,1.74,2.61,2.30,2.13,2.03,1.99,1.91,1.92,1.95,2.83,2.67,2.54,2.44,2.39,2.31,2.27,2.24,3.24,2.99,2.76,2.64,2.62,2.50,2.47,2.44,2.39,2.38,2.40,2.46,2.52,2.49,2.49,2.44,2.42,2.45,3.38,3.13,2.91,2.82,2.75,2.66,2.56,2.53,2.53,2.48,2.56,2.64,2.70,2.68,2.68,2.64,2.61,2.59,3.60,3.24,3.08,2.91,3.04,3.02,3.01,3.00,2.96,2.97,2.96,2.95,2.94,2.93,2.92,2.98,2.90,2.80,2.74,2.65,2.59,2.57,2.50,2.51,2.52,2.61,2.72,2.72,2.79,2.73,2.75,2.70,3.51,3.29,3.14,3.03,2.97,2.98,2.99,3.00,2.94,2.94,2.96,2.96},
6791    {1.57,1.71,2.58,2.27,2.10,2.00,1.96,1.88,1.89,1.92,2.80,2.64,2.51,2.41,2.36,2.28,2.24,2.21,3.21,2.96,2.73,2.61,2.59,2.47,2.44,2.41,2.36,2.35,2.37,2.43,2.49,2.46,2.46,2.41,2.39,2.42,3.35,3.10,2.88,2.79,2.72,2.63,2.53,2.50,2.50,2.45,2.53,2.61,2.67,2.65,2.65,2.61,2.58,2.56,3.57,3.21,3.05,2.88,3.01,2.99,2.98,2.97,2.93,2.94,2.93,2.92,2.91,2.90,2.89,2.95,2.87,2.77,2.71,2.62,2.56,2.54,2.47,2.48,2.49,2.58,2.69,2.69,2.76,2.70,2.72,2.67,3.48,3.26,3.11,3.00,2.94,2.95,2.96,2.97,2.91,2.91,2.93,2.93},
6792    {1.57,1.71,2.58,2.27,2.10,2.00,1.96,1.88,1.89,1.92,2.80,2.64,2.51,2.41,2.36,2.28,2.24,2.21,3.21,2.96,2.73,2.61,2.59,2.47,2.44,2.41,2.36,2.35,2.37,2.43,2.49,2.46,2.46,2.41,2.39,2.42,3.35,3.10,2.88,2.79,2.72,2.63,2.53,2.50,2.50,2.45,2.53,2.61,2.67,2.65,2.65,2.61,2.58,2.56,3.57,3.21,3.05,2.88,3.01,2.99,2.98,2.97,2.93,2.94,2.93,2.92,2.91,2.90,2.89,2.95,2.87,2.77,2.71,2.62,2.56,2.54,2.47,2.48,2.49,2.58,2.69,2.69,2.76,2.70,2.72,2.67,3.48,3.26,3.11,3.00,2.94,2.95,2.96,2.97,2.91,2.91,2.93,2.93},
6793    {1.52,1.66,2.53,2.22,2.05,1.95,1.91,1.83,1.84,1.87,2.75,2.59,2.46,2.36,2.31,2.23,2.19,2.16,3.16,2.91,2.68,2.56,2.54,2.42,2.39,2.36,2.31,2.30,2.32,2.38,2.44,2.41,2.41,2.36,2.34,2.37,3.30,3.05,2.83,2.74,2.67,2.58,2.48,2.45,2.45,2.40,2.48,2.56,2.62,2.60,2.60,2.56,2.53,2.51,3.52,3.16,3.00,2.83,2.96,2.94,2.93,2.92,2.88,2.89,2.88,2.87,2.86,2.85,2.84,2.90,2.82,2.72,2.66,2.57,2.51,2.49,2.42,2.43,2.44,2.53,2.64,2.64,2.71,2.65,2.67,2.62,3.43,3.21,3.06,2.95,2.89,2.90,2.91,2.92,2.86,2.86,2.88,2.88},
6794    {1.60,1.74,2.61,2.30,2.13,2.03,1.99,1.91,1.92,1.95,2.83,2.67,2.54,2.44,2.39,2.31,2.27,2.24,3.24,2.99,2.76,2.64,2.62,2.50,2.47,2.44,2.39,2.38,2.40,2.46,2.52,2.49,2.49,2.44,2.42,2.45,3.38,3.13,2.91,2.82,2.75,2.66,2.56,2.53,2.53,2.48,2.56,2.64,2.70,2.68,2.68,2.64,2.61,2.59,3.60,3.24,3.08,2.91,3.04,3.02,3.01,3.00,2.96,2.97,2.96,2.95,2.94,2.93,2.92,2.98,2.90,2.80,2.74,2.65,2.59,2.57,2.50,2.51,2.52,2.61,2.72,2.72,2.79,2.73,2.75,2.70,3.51,3.29,3.14,3.03,2.97,2.98,2.99,3.00,2.94,2.94,2.96,2.96},
6795    {1.68,1.82,2.69,2.38,2.21,2.11,2.07,1.99,2.00,2.03,2.91,2.75,2.62,2.52,2.47,2.39,2.35,2.32,3.32,3.07,2.84,2.72,2.70,2.58,2.55,2.52,2.47,2.46,2.48,2.54,2.60,2.57,2.57,2.52,2.50,2.53,3.46,3.21,2.99,2.90,2.83,2.74,2.64,2.61,2.61,2.56,2.64,2.72,2.78,2.76,2.76,2.72,2.69,2.67,3.68,3.32,3.16,2.99,3.12,3.10,3.09,3.08,3.04,3.05,3.04,3.03,3.02,3.01,3.00,3.06,2.98,2.88,2.82,2.73,2.67,2.65,2.58,2.59,2.60,2.69,2.80,2.80,2.87,2.81,2.83,2.78,3.59,3.37,3.22,3.11,3.05,3.06,3.07,3.08,3.02,3.02,3.04,3.04},
6796    {1.74,1.88,2.75,2.44,2.27,2.17,2.13,2.05,2.06,2.09,2.97,2.81,2.68,2.58,2.53,2.45,2.41,2.38,3.38,3.13,2.90,2.78,2.76,2.64,2.61,2.58,2.53,2.52,2.54,2.60,2.66,2.63,2.63,2.58,2.56,2.59,3.52,3.27,3.05,2.96,2.89,2.80,2.70,2.67,2.67,2.62,2.70,2.78,2.84,2.82,2.82,2.78,2.75,2.73,3.74,3.38,3.22,3.05,3.18,3.16,3.15,3.14,3.10,3.11,3.10,3.09,3.08,3.07,3.06,3.12,3.04,2.94,2.88,2.79,2.73,2.71,2.64,2.65,2.66,2.75,2.86,2.86,2.93,2.87,2.89,2.84,3.65,3.43,3.28,3.17,3.11,3.12,3.13,3.14,3.08,3.08,3.10,3.10},
6797    {1.72,1.86,2.73,2.42,2.25,2.15,2.11,2.03,2.04,2.07,2.95,2.79,2.66,2.56,2.51,2.43,2.39,2.36,3.36,3.11,2.88,2.76,2.74,2.62,2.59,2.56,2.51,2.50,2.52,2.58,2.64,2.61,2.61,2.56,2.54,2.57,3.50,3.25,3.03,2.94,2.87,2.78,2.68,2.65,2.65,2.60,2.68,2.76,2.82,2.80,2.80,2.76,2.73,2.71,3.72,3.36,3.20,3.03,3.16,3.14,3.13,3.12,3.08,3.09,3.08,3.07,3.06,3.05,3.04,3.10,3.02,2.92,2.86,2.77,2.71,2.69,2.62,2.63,2.64,2.73,2.84,2.84,2.91,2.85,2.87,2.82,3.63,3.41,3.26,3.15,3.09,3.10,3.11,3.12,3.06,3.06,3.08,3.08},
6798    {1.72,1.86,2.73,2.42,2.25,2.15,2.11,2.03,2.04,2.07,2.95,2.79,2.66,2.56,2.51,2.43,2.39,2.36,3.36,3.11,2.88,2.76,2.74,2.62,2.59,2.56,2.51,2.50,2.52,2.58,2.64,2.61,2.61,2.56,2.54,2.57,3.50,3.25,3.03,2.94,2.87,2.78,2.68,2.65,2.65,2.60,2.68,2.76,2.82,2.80,2.80,2.76,2.73,2.71,3.72,3.36,3.20,3.03,3.16,3.14,3.13,3.12,3.08,3.09,3.08,3.07,3.06,3.05,3.04,3.10,3.02,2.92,2.86,2.77,2.71,2.69,2.62,2.63,2.64,2.73,2.84,2.84,2.91,2.85,2.87,2.82,3.63,3.41,3.26,3.15,3.09,3.10,3.11,3.12,3.06,3.06,3.08,3.08},
6799    {1.68,1.82,2.69,2.38,2.21,2.11,2.07,1.99,2.00,2.03,2.91,2.75,2.62,2.52,2.47,2.39,2.35,2.32,3.32,3.07,2.84,2.72,2.70,2.58,2.55,2.52,2.47,2.46,2.48,2.54,2.60,2.57,2.57,2.52,2.50,2.53,3.46,3.21,2.99,2.90,2.83,2.74,2.64,2.61,2.61,2.56,2.64,2.72,2.78,2.76,2.76,2.72,2.69,2.67,3.68,3.32,3.16,2.99,3.12,3.10,3.09,3.08,3.04,3.05,3.04,3.03,3.02,3.01,3.00,3.06,2.98,2.88,2.82,2.73,2.67,2.65,2.58,2.59,2.60,2.69,2.80,2.80,2.87,2.81,2.83,2.78,3.59,3.37,3.22,3.11,3.05,3.06,3.07,3.08,3.02,3.02,3.04,3.04},
6800    {1.65,1.79,2.66,2.35,2.18,2.08,2.04,1.96,1.97,2.00,2.88,2.72,2.59,2.49,2.44,2.36,2.32,2.29,3.29,3.04,2.81,2.69,2.67,2.55,2.52,2.49,2.44,2.43,2.45,2.51,2.57,2.54,2.54,2.49,2.47,2.50,3.43,3.18,2.96,2.87,2.80,2.71,2.61,2.58,2.58,2.53,2.61,2.69,2.75,2.73,2.73,2.69,2.66,2.64,3.65,3.29,3.13,2.96,3.09,3.07,3.06,3.05,3.01,3.02,3.01,3.00,2.99,2.98,2.97,3.03,2.95,2.85,2.79,2.70,2.64,2.62,2.55,2.56,2.57,2.66,2.77,2.77,2.84,2.78,2.80,2.75,3.56,3.34,3.19,3.08,3.02,3.03,3.04,3.05,2.99,2.99,3.01,3.01},
6801    {1.63,1.77,2.64,2.33,2.16,2.06,2.02,1.94,1.95,1.98,2.86,2.70,2.57,2.47,2.42,2.34,2.30,2.27,3.27,3.02,2.79,2.67,2.65,2.53,2.50,2.47,2.42,2.41,2.43,2.49,2.55,2.52,2.52,2.47,2.45,2.48,3.41,3.16,2.94,2.85,2.78,2.69,2.59,2.56,2.56,2.51,2.59,2.67,2.73,2.71,2.71,2.67,2.64,2.62,3.63,3.27,3.11,2.94,3.07,3.05,3.04,3.03,2.99,3.00,2.99,2.98,2.97,2.96,2.95,3.01,2.93,2.83,2.77,2.68,2.62,2.60,2.53,2.54,2.55,2.64,2.75,2.75,2.82,2.76,2.78,2.73,3.54,3.32,3.17,3.06,3.00,3.01,3.02,3.03,2.97,2.97,2.99,2.99},
6802    {2.64,2.78,3.65,3.34,3.17,3.07,3.03,2.95,2.96,2.99,3.87,3.71,3.58,3.48,3.43,3.35,3.31,3.28,4.28,4.03,3.80,3.68,3.66,3.54,3.51,3.48,3.43,3.42,3.44,3.50,3.56,3.53,3.53,3.48,3.46,3.49,4.42,4.17,3.95,3.86,3.79,3.70,3.60,3.57,3.57,3.52,3.60,3.68,3.74,3.72,3.72,3.68,3.65,3.63,4.64,4.28,4.12,3.95,4.08,4.06,4.05,4.04,4.00,4.01,4.00,3.99,3.98,3.97,3.96,4.02,3.94,3.84,3.78,3.69,3.63,3.61,3.54,3.55,3.56,3.65,3.76,3.76,3.83,3.77,3.79,3.74,4.55,4.33,4.18,4.07,4.01,4.02,4.03,4.04,3.98,3.98,4.00,4.00},
6803    {2.28,2.42,3.29,2.98,2.81,2.71,2.67,2.59,2.60,2.63,3.51,3.35,3.22,3.12,3.07,2.99,2.95,2.92,3.92,3.67,3.44,3.32,3.30,3.18,3.15,3.12,3.07,3.06,3.08,3.14,3.20,3.17,3.17,3.12,3.10,3.13,4.06,3.81,3.59,3.50,3.43,3.34,3.24,3.21,3.21,3.16,3.24,3.32,3.38,3.36,3.36,3.32,3.29,3.27,4.28,3.92,3.76,3.59,3.72,3.70,3.69,3.68,3.64,3.65,3.64,3.63,3.62,3.61,3.60,3.66,3.58,3.48,3.42,3.33,3.27,3.25,3.18,3.19,3.20,3.29,3.40,3.40,3.47,3.41,3.43,3.38,4.19,3.97,3.82,3.71,3.65,3.66,3.67,3.68,3.62,3.62,3.64,3.64},
6804    {2.12,2.26,3.13,2.82,2.65,2.55,2.51,2.43,2.44,2.47,3.35,3.19,3.06,2.96,2.91,2.83,2.79,2.76,3.76,3.51,3.28,3.16,3.14,3.02,2.99,2.96,2.91,2.90,2.92,2.98,3.04,3.01,3.01,2.96,2.94,2.97,3.90,3.65,3.43,3.34,3.27,3.18,3.08,3.05,3.05,3.00,3.08,3.16,3.22,3.20,3.20,3.16,3.13,3.11,4.12,3.76,3.60,3.43,3.56,3.54,3.53,3.52,3.48,3.49,3.48,3.47,3.46,3.45,3.44,3.50,3.42,3.32,3.26,3.17,3.11,3.09,3.02,3.03,3.04,3.13,3.24,3.24,3.31,3.25,3.27,3.22,4.03,3.81,3.66,3.55,3.49,3.50,3.51,3.52,3.46,3.46,3.48,3.48},
6805    {1.95,2.09,2.96,2.65,2.48,2.38,2.34,2.26,2.27,2.30,3.18,3.02,2.89,2.79,2.74,2.66,2.62,2.59,3.59,3.34,3.11,2.99,2.97,2.85,2.82,2.79,2.74,2.73,2.75,2.81,2.87,2.84,2.84,2.79,2.77,2.80,3.73,3.48,3.26,3.17,3.10,3.01,2.91,2.88,2.88,2.83,2.91,2.99,3.05,3.03,3.03,2.99,2.96,2.94,3.95,3.59,3.43,3.26,3.39,3.37,3.36,3.35,3.31,3.32,3.31,3.30,3.29,3.28,3.27,3.33,3.25,3.15,3.09,3.00,2.94,2.92,2.85,2.86,2.87,2.96,3.07,3.07,3.14,3.08,3.10,3.05,3.86,3.64,3.49,3.38,3.32,3.33,3.34,3.35,3.29,3.29,3.31,3.31},
6806    {2.08,2.22,3.09,2.78,2.61,2.51,2.47,2.39,2.40,2.43,3.31,3.15,3.02,2.92,2.87,2.79,2.75,2.72,3.72,3.47,3.24,3.12,3.10,2.98,2.95,2.92,2.87,2.86,2.88,2.94,3.00,2.97,2.97,2.92,2.90,2.93,3.86,3.61,3.39,3.30,3.23,3.14,3.04,3.01,3.01,2.96,3.04,3.12,3.18,3.16,3.16,3.12,3.09,3.07,4.08,3.72,3.56,3.39,3.52,3.50,3.49,3.48,3.44,3.45,3.44,3.43,3.42,3.41,3.40,3.46,3.38,3.28,3.22,3.13,3.07,3.05,2.98,2.99,3.00,3.09,3.20,3.20,3.27,3.21,3.23,3.18,3.99,3.77,3.62,3.51,3.45,3.46,3.47,3.48,3.42,3.42,3.44,3.44},
6807    {2.06,2.20,3.07,2.76,2.59,2.49,2.45,2.37,2.38,2.41,3.29,3.13,3.00,2.90,2.85,2.77,2.73,2.70,3.70,3.45,3.22,3.10,3.08,2.96,2.93,2.90,2.85,2.84,2.86,2.92,2.98,2.95,2.95,2.90,2.88,2.91,3.84,3.59,3.37,3.28,3.21,3.12,3.02,2.99,2.99,2.94,3.02,3.10,3.16,3.14,3.14,3.10,3.07,3.05,4.06,3.70,3.54,3.37,3.50,3.48,3.47,3.46,3.42,3.43,3.42,3.41,3.40,3.39,3.38,3.44,3.36,3.26,3.20,3.11,3.05,3.03,2.96,2.97,2.98,3.07,3.18,3.18,3.25,3.19,3.21,3.16,3.97,3.75,3.60,3.49,3.43,3.44,3.45,3.46,3.40,3.40,3.42,3.42},
6808    {2.05,2.19,3.06,2.75,2.58,2.48,2.44,2.36,2.37,2.40,3.28,3.12,2.99,2.89,2.84,2.76,2.72,2.69,3.69,3.44,3.21,3.09,3.07,2.95,2.92,2.89,2.84,2.83,2.85,2.91,2.97,2.94,2.94,2.89,2.87,2.90,3.83,3.58,3.36,3.27,3.20,3.11,3.01,2.98,2.98,2.93,3.01,3.09,3.15,3.13,3.13,3.09,3.06,3.04,4.05,3.69,3.53,3.36,3.49,3.47,3.46,3.45,3.41,3.42,3.41,3.40,3.39,3.38,3.37,3.43,3.35,3.25,3.19,3.10,3.04,3.02,2.95,2.96,2.97,3.06,3.17,3.17,3.24,3.18,3.20,3.15,3.96,3.74,3.59,3.48,3.42,3.43,3.44,3.45,3.39,3.39,3.41,3.41},
6809    {2.04,2.18,3.05,2.74,2.57,2.47,2.43,2.35,2.36,2.39,3.27,3.11,2.98,2.88,2.83,2.75,2.71,2.68,3.68,3.43,3.20,3.08,3.06,2.94,2.91,2.88,2.83,2.82,2.84,2.90,2.96,2.93,2.93,2.88,2.86,2.89,3.82,3.57,3.35,3.26,3.19,3.10,3.00,2.97,2.97,2.92,3.00,3.08,3.14,3.12,3.12,3.08,3.05,3.03,4.04,3.68,3.52,3.35,3.48,3.46,3.45,3.44,3.40,3.41,3.40,3.39,3.38,3.37,3.36,3.42,3.34,3.24,3.18,3.09,3.03,3.01,2.94,2.95,2.96,3.05,3.16,3.16,3.23,3.17,3.19,3.14,3.95,3.73,3.58,3.47,3.41,3.42,3.43,3.44,3.38,3.38,3.40,3.40},
6810    {2.00,2.14,3.01,2.70,2.53,2.43,2.39,2.31,2.32,2.35,3.23,3.07,2.94,2.84,2.79,2.71,2.67,2.64,3.64,3.39,3.16,3.04,3.02,2.90,2.87,2.84,2.79,2.78,2.80,2.86,2.92,2.89,2.89,2.84,2.82,2.85,3.78,3.53,3.31,3.22,3.15,3.06,2.96,2.93,2.93,2.88,2.96,3.04,3.10,3.08,3.08,3.04,3.01,2.99,4.00,3.64,3.48,3.31,3.44,3.42,3.41,3.40,3.36,3.37,3.36,3.35,3.34,3.33,3.32,3.38,3.30,3.20,3.14,3.05,2.99,2.97,2.90,2.91,2.92,3.01,3.12,3.12,3.19,3.13,3.15,3.10,3.91,3.69,3.54,3.43,3.37,3.38,3.39,3.40,3.34,3.34,3.36,3.36},
6811    {2.01,2.15,3.02,2.71,2.54,2.44,2.40,2.32,2.33,2.36,3.24,3.08,2.95,2.85,2.80,2.72,2.68,2.65,3.65,3.40,3.17,3.05,3.03,2.91,2.88,2.85,2.80,2.79,2.81,2.87,2.93,2.90,2.90,2.85,2.83,2.86,3.79,3.54,3.32,3.23,3.16,3.07,2.97,2.94,2.94,2.89,2.97,3.05,3.11,3.09,3.09,3.05,3.02,3.00,4.01,3.65,3.49,3.32,3.45,3.43,3.42,3.41,3.37,3.38,3.37,3.36,3.35,3.34,3.33,3.39,3.31,3.21,3.15,3.06,3.00,2.98,2.91,2.92,2.93,3.02,3.13,3.13,3.20,3.14,3.16,3.11,3.92,3.70,3.55,3.44,3.38,3.39,3.40,3.41,3.35,3.35,3.37,3.37},
6812    {2.00,2.14,3.01,2.70,2.53,2.43,2.39,2.31,2.32,2.35,3.23,3.07,2.94,2.84,2.79,2.71,2.67,2.64,3.64,3.39,3.16,3.04,3.02,2.90,2.87,2.84,2.79,2.78,2.80,2.86,2.92,2.89,2.89,2.84,2.82,2.85,3.78,3.53,3.31,3.22,3.15,3.06,2.96,2.93,2.93,2.88,2.96,3.04,3.10,3.08,3.08,3.04,3.01,2.99,4.00,3.64,3.48,3.31,3.44,3.42,3.41,3.40,3.36,3.37,3.36,3.35,3.34,3.33,3.32,3.38,3.30,3.20,3.14,3.05,2.99,2.97,2.90,2.91,2.92,3.01,3.12,3.12,3.19,3.13,3.15,3.10,3.91,3.69,3.54,3.43,3.37,3.38,3.39,3.40,3.34,3.34,3.36,3.36},
6813    {1.99,2.13,3.00,2.69,2.52,2.42,2.38,2.30,2.31,2.34,3.22,3.06,2.93,2.83,2.78,2.70,2.66,2.63,3.63,3.38,3.15,3.03,3.01,2.89,2.86,2.83,2.78,2.77,2.79,2.85,2.91,2.88,2.88,2.83,2.81,2.84,3.77,3.52,3.30,3.21,3.14,3.05,2.95,2.92,2.92,2.87,2.95,3.03,3.09,3.07,3.07,3.03,3.00,2.98,3.99,3.63,3.47,3.30,3.43,3.41,3.40,3.39,3.35,3.36,3.35,3.34,3.33,3.32,3.31,3.37,3.29,3.19,3.13,3.04,2.98,2.96,2.89,2.90,2.91,3.00,3.11,3.11,3.18,3.12,3.14,3.09,3.90,3.68,3.53,3.42,3.36,3.37,3.38,3.39,3.33,3.33,3.35,3.35},
6814    {1.98,2.12,2.99,2.68,2.51,2.41,2.37,2.29,2.30,2.33,3.21,3.05,2.92,2.82,2.77,2.69,2.65,2.62,3.62,3.37,3.14,3.02,3.00,2.88,2.85,2.82,2.77,2.76,2.78,2.84,2.90,2.87,2.87,2.82,2.80,2.83,3.76,3.51,3.29,3.20,3.13,3.04,2.94,2.91,2.91,2.86,2.94,3.02,3.08,3.06,3.06,3.02,2.99,2.97,3.98,3.62,3.46,3.29,3.42,3.40,3.39,3.38,3.34,3.35,3.34,3.33,3.32,3.31,3.30,3.36,3.28,3.18,3.12,3.03,2.97,2.95,2.88,2.89,2.90,2.99,3.10,3.10,3.17,3.11,3.13,3.08,3.89,3.67,3.52,3.41,3.35,3.36,3.37,3.38,3.32,3.32,3.34,3.34},
6815    {1.97,2.11,2.98,2.67,2.50,2.40,2.36,2.28,2.29,2.32,3.20,3.04,2.91,2.81,2.76,2.68,2.64,2.61,3.61,3.36,3.13,3.01,2.99,2.87,2.84,2.81,2.76,2.75,2.77,2.83,2.89,2.86,2.86,2.81,2.79,2.82,3.75,3.50,3.28,3.19,3.12,3.03,2.93,2.90,2.90,2.85,2.93,3.01,3.07,3.05,3.05,3.01,2.98,2.96,3.97,3.61,3.45,3.28,3.41,3.39,3.38,3.37,3.33,3.34,3.33,3.32,3.31,3.30,3.29,3.35,3.27,3.17,3.11,3.02,2.96,2.94,2.87,2.88,2.89,2.98,3.09,3.09,3.16,3.10,3.12,3.07,3.88,3.66,3.51,3.40,3.34,3.35,3.36,3.37,3.31,3.31,3.33,3.33},
6816    {1.96,2.10,2.97,2.66,2.49,2.39,2.35,2.27,2.28,2.31,3.19,3.03,2.90,2.80,2.75,2.67,2.63,2.60,3.60,3.35,3.12,3.00,2.98,2.86,2.83,2.80,2.75,2.74,2.76,2.82,2.88,2.85,2.85,2.80,2.78,2.81,3.74,3.49,3.27,3.18,3.11,3.02,2.92,2.89,2.89,2.84,2.92,3.00,3.06,3.04,3.04,3.00,2.97,2.95,3.96,3.60,3.44,3.27,3.40,3.38,3.37,3.36,3.32,3.33,3.32,3.31,3.30,3.29,3.28,3.34,3.26,3.16,3.10,3.01,2.95,2.93,2.86,2.87,2.88,2.97,3.08,3.08,3.15,3.09,3.11,3.06,3.87,3.65,3.50,3.39,3.33,3.34,3.35,3.36,3.30,3.30,3.32,3.32},
6817    {2.02,2.16,3.03,2.72,2.55,2.45,2.41,2.33,2.34,2.37,3.25,3.09,2.96,2.86,2.81,2.73,2.69,2.66,3.66,3.41,3.18,3.06,3.04,2.92,2.89,2.86,2.81,2.80,2.82,2.88,2.94,2.91,2.91,2.86,2.84,2.87,3.80,3.55,3.33,3.24,3.17,3.08,2.98,2.95,2.95,2.90,2.98,3.06,3.12,3.10,3.10,3.06,3.03,3.01,4.02,3.66,3.50,3.33,3.46,3.44,3.43,3.42,3.38,3.39,3.38,3.37,3.36,3.35,3.34,3.40,3.32,3.22,3.16,3.07,3.01,2.99,2.92,2.93,2.94,3.03,3.14,3.14,3.21,3.15,3.17,3.12,3.93,3.71,3.56,3.45,3.39,3.40,3.41,3.42,3.36,3.36,3.38,3.38},
6818    {1.94,2.08,2.95,2.64,2.47,2.37,2.33,2.25,2.26,2.29,3.17,3.01,2.88,2.78,2.73,2.65,2.61,2.58,3.58,3.33,3.10,2.98,2.96,2.84,2.81,2.78,2.73,2.72,2.74,2.80,2.86,2.83,2.83,2.78,2.76,2.79,3.72,3.47,3.25,3.16,3.09,3.00,2.90,2.87,2.87,2.82,2.90,2.98,3.04,3.02,3.02,2.98,2.95,2.93,3.94,3.58,3.42,3.25,3.38,3.36,3.35,3.34,3.30,3.31,3.30,3.29,3.28,3.27,3.26,3.32,3.24,3.14,3.08,2.99,2.93,2.91,2.84,2.85,2.86,2.95,3.06,3.06,3.13,3.07,3.09,3.04,3.85,3.63,3.48,3.37,3.31,3.32,3.33,3.34,3.28,3.28,3.30,3.30},
6819    {1.84,1.98,2.85,2.54,2.37,2.27,2.23,2.15,2.16,2.19,3.07,2.91,2.78,2.68,2.63,2.55,2.51,2.48,3.48,3.23,3.00,2.88,2.86,2.74,2.71,2.68,2.63,2.62,2.64,2.70,2.76,2.73,2.73,2.68,2.66,2.69,3.62,3.37,3.15,3.06,2.99,2.90,2.80,2.77,2.77,2.72,2.80,2.88,2.94,2.92,2.92,2.88,2.85,2.83,3.84,3.48,3.32,3.15,3.28,3.26,3.25,3.24,3.20,3.21,3.20,3.19,3.18,3.17,3.16,3.22,3.14,3.04,2.98,2.89,2.83,2.81,2.74,2.75,2.76,2.85,2.96,2.96,3.03,2.97,2.99,2.94,3.75,3.53,3.38,3.27,3.21,3.22,3.23,3.24,3.18,3.18,3.20,3.20},
6820    {1.78,1.92,2.79,2.48,2.31,2.21,2.17,2.09,2.10,2.13,3.01,2.85,2.72,2.62,2.57,2.49,2.45,2.42,3.42,3.17,2.94,2.82,2.80,2.68,2.65,2.62,2.57,2.56,2.58,2.64,2.70,2.67,2.67,2.62,2.60,2.63,3.56,3.31,3.09,3.00,2.93,2.84,2.74,2.71,2.71,2.66,2.74,2.82,2.88,2.86,2.86,2.82,2.79,2.77,3.78,3.42,3.26,3.09,3.22,3.20,3.19,3.18,3.14,3.15,3.14,3.13,3.12,3.11,3.10,3.16,3.08,2.98,2.92,2.83,2.77,2.75,2.68,2.69,2.70,2.79,2.90,2.90,2.97,2.91,2.93,2.88,3.69,3.47,3.32,3.21,3.15,3.16,3.17,3.18,3.12,3.12,3.14,3.14},
6821    {1.69,1.83,2.70,2.39,2.22,2.12,2.08,2.00,2.01,2.04,2.92,2.76,2.63,2.53,2.48,2.40,2.36,2.33,3.33,3.08,2.85,2.73,2.71,2.59,2.56,2.53,2.48,2.47,2.49,2.55,2.61,2.58,2.58,2.53,2.51,2.54,3.47,3.22,3.00,2.91,2.84,2.75,2.65,2.62,2.62,2.57,2.65,2.73,2.79,2.77,2.77,2.73,2.70,2.68,3.69,3.33,3.17,3.00,3.13,3.11,3.10,3.09,3.05,3.06,3.05,3.04,3.03,3.02,3.01,3.07,2.99,2.89,2.83,2.74,2.68,2.66,2.59,2.60,2.61,2.70,2.81,2.81,2.88,2.82,2.84,2.79,3.60,3.38,3.23,3.12,3.06,3.07,3.08,3.09,3.03,3.03,3.05,3.05},
6822    {1.63,1.77,2.64,2.33,2.16,2.06,2.02,1.94,1.95,1.98,2.86,2.70,2.57,2.47,2.42,2.34,2.30,2.27,3.27,3.02,2.79,2.67,2.65,2.53,2.50,2.47,2.42,2.41,2.43,2.49,2.55,2.52,2.52,2.47,2.45,2.48,3.41,3.16,2.94,2.85,2.78,2.69,2.59,2.56,2.56,2.51,2.59,2.67,2.73,2.71,2.71,2.67,2.64,2.62,3.63,3.27,3.11,2.94,3.07,3.05,3.04,3.03,2.99,3.00,2.99,2.98,2.97,2.96,2.95,3.01,2.93,2.83,2.77,2.68,2.62,2.60,2.53,2.54,2.55,2.64,2.75,2.75,2.82,2.76,2.78,2.73,3.54,3.32,3.17,3.06,3.00,3.01,3.02,3.03,2.97,2.97,2.99,2.99},
6823    {1.61,1.75,2.62,2.31,2.14,2.04,2.00,1.92,1.93,1.96,2.84,2.68,2.55,2.45,2.40,2.32,2.28,2.25,3.25,3.00,2.77,2.65,2.63,2.51,2.48,2.45,2.40,2.39,2.41,2.47,2.53,2.50,2.50,2.45,2.43,2.46,3.39,3.14,2.92,2.83,2.76,2.67,2.57,2.54,2.54,2.49,2.57,2.65,2.71,2.69,2.69,2.65,2.62,2.60,3.61,3.25,3.09,2.92,3.05,3.03,3.02,3.01,2.97,2.98,2.97,2.96,2.95,2.94,2.93,2.99,2.91,2.81,2.75,2.66,2.60,2.58,2.51,2.52,2.53,2.62,2.73,2.73,2.80,2.74,2.76,2.71,3.52,3.30,3.15,3.04,2.98,2.99,3.00,3.01,2.95,2.95,2.97,2.97},
6824    {1.54,1.68,2.55,2.24,2.07,1.97,1.93,1.85,1.86,1.89,2.77,2.61,2.48,2.38,2.33,2.25,2.21,2.18,3.18,2.93,2.70,2.58,2.56,2.44,2.41,2.38,2.33,2.32,2.34,2.40,2.46,2.43,2.43,2.38,2.36,2.39,3.32,3.07,2.85,2.76,2.69,2.60,2.50,2.47,2.47,2.42,2.50,2.58,2.64,2.62,2.62,2.58,2.55,2.53,3.54,3.18,3.02,2.85,2.98,2.96,2.95,2.94,2.90,2.91,2.90,2.89,2.88,2.87,2.86,2.92,2.84,2.74,2.68,2.59,2.53,2.51,2.44,2.45,2.46,2.55,2.66,2.66,2.73,2.67,2.69,2.64,3.45,3.23,3.08,2.97,2.91,2.92,2.93,2.94,2.88,2.88,2.90,2.90},
6825    {1.55,1.69,2.56,2.25,2.08,1.98,1.94,1.86,1.87,1.90,2.78,2.62,2.49,2.39,2.34,2.26,2.22,2.19,3.19,2.94,2.71,2.59,2.57,2.45,2.42,2.39,2.34,2.33,2.35,2.41,2.47,2.44,2.44,2.39,2.37,2.40,3.33,3.08,2.86,2.77,2.70,2.61,2.51,2.48,2.48,2.43,2.51,2.59,2.65,2.63,2.63,2.59,2.56,2.54,3.55,3.19,3.03,2.86,2.99,2.97,2.96,2.95,2.91,2.92,2.91,2.90,2.89,2.88,2.87,2.93,2.85,2.75,2.69,2.60,2.54,2.52,2.45,2.46,2.47,2.56,2.67,2.67,2.74,2.68,2.70,2.65,3.46,3.24,3.09,2.98,2.92,2.93,2.94,2.95,2.89,2.89,2.91,2.91},
6826    {1.56,1.70,2.57,2.26,2.09,1.99,1.95,1.87,1.88,1.91,2.79,2.63,2.50,2.40,2.35,2.27,2.23,2.20,3.20,2.95,2.72,2.60,2.58,2.46,2.43,2.40,2.35,2.34,2.36,2.42,2.48,2.45,2.45,2.40,2.38,2.41,3.34,3.09,2.87,2.78,2.71,2.62,2.52,2.49,2.49,2.44,2.52,2.60,2.66,2.64,2.64,2.60,2.57,2.55,3.56,3.20,3.04,2.87,3.00,2.98,2.97,2.96,2.92,2.93,2.92,2.91,2.90,2.89,2.88,2.94,2.86,2.76,2.70,2.61,2.55,2.53,2.46,2.47,2.48,2.57,2.68,2.68,2.75,2.69,2.71,2.66,3.47,3.25,3.10,2.99,2.93,2.94,2.95,2.96,2.90,2.90,2.92,2.92},
6827    {1.65,1.79,2.66,2.35,2.18,2.08,2.04,1.96,1.97,2.00,2.88,2.72,2.59,2.49,2.44,2.36,2.32,2.29,3.29,3.04,2.81,2.69,2.67,2.55,2.52,2.49,2.44,2.43,2.45,2.51,2.57,2.54,2.54,2.49,2.47,2.50,3.43,3.18,2.96,2.87,2.80,2.71,2.61,2.58,2.58,2.53,2.61,2.69,2.75,2.73,2.73,2.69,2.66,2.64,3.65,3.29,3.13,2.96,3.09,3.07,3.06,3.05,3.01,3.02,3.01,3.00,2.99,2.98,2.97,3.03,2.95,2.85,2.79,2.70,2.64,2.62,2.55,2.56,2.57,2.66,2.77,2.77,2.84,2.78,2.80,2.75,3.56,3.34,3.19,3.08,3.02,3.03,3.04,3.05,2.99,2.99,3.01,3.01},
6828    {1.76,1.90,2.77,2.46,2.29,2.19,2.15,2.07,2.08,2.11,2.99,2.83,2.70,2.60,2.55,2.47,2.43,2.40,3.40,3.15,2.92,2.80,2.78,2.66,2.63,2.60,2.55,2.54,2.56,2.62,2.68,2.65,2.65,2.60,2.58,2.61,3.54,3.29,3.07,2.98,2.91,2.82,2.72,2.69,2.69,2.64,2.72,2.80,2.86,2.84,2.84,2.80,2.77,2.75,3.76,3.40,3.24,3.07,3.20,3.18,3.17,3.16,3.12,3.13,3.12,3.11,3.10,3.09,3.08,3.14,3.06,2.96,2.90,2.81,2.75,2.73,2.66,2.67,2.68,2.77,2.88,2.88,2.95,2.89,2.91,2.86,3.67,3.45,3.30,3.19,3.13,3.14,3.15,3.16,3.10,3.10,3.12,3.12},
6829    {1.76,1.90,2.77,2.46,2.29,2.19,2.15,2.07,2.08,2.11,2.99,2.83,2.70,2.60,2.55,2.47,2.43,2.40,3.40,3.15,2.92,2.80,2.78,2.66,2.63,2.60,2.55,2.54,2.56,2.62,2.68,2.65,2.65,2.60,2.58,2.61,3.54,3.29,3.07,2.98,2.91,2.82,2.72,2.69,2.69,2.64,2.72,2.80,2.86,2.84,2.84,2.80,2.77,2.75,3.76,3.40,3.24,3.07,3.20,3.18,3.17,3.16,3.12,3.13,3.12,3.11,3.10,3.09,3.08,3.14,3.06,2.96,2.90,2.81,2.75,2.73,2.66,2.67,2.68,2.77,2.88,2.88,2.95,2.89,2.91,2.86,3.67,3.45,3.30,3.19,3.13,3.14,3.15,3.16,3.10,3.10,3.12,3.12},
6830    {1.83,1.97,2.84,2.53,2.36,2.26,2.22,2.14,2.15,2.18,3.06,2.90,2.77,2.67,2.62,2.54,2.50,2.47,3.47,3.22,2.99,2.87,2.85,2.73,2.70,2.67,2.62,2.61,2.63,2.69,2.75,2.72,2.72,2.67,2.65,2.68,3.61,3.36,3.14,3.05,2.98,2.89,2.79,2.76,2.76,2.71,2.79,2.87,2.93,2.91,2.91,2.87,2.84,2.82,3.83,3.47,3.31,3.14,3.27,3.25,3.24,3.23,3.19,3.20,3.19,3.18,3.17,3.16,3.15,3.21,3.13,3.03,2.97,2.88,2.82,2.80,2.73,2.74,2.75,2.84,2.95,2.95,3.02,2.96,2.98,2.93,3.74,3.52,3.37,3.26,3.20,3.21,3.22,3.23,3.17,3.17,3.19,3.19},
6831    {1.77,1.91,2.78,2.47,2.30,2.20,2.16,2.08,2.09,2.12,3.00,2.84,2.71,2.61,2.56,2.48,2.44,2.41,3.41,3.16,2.93,2.81,2.79,2.67,2.64,2.61,2.56,2.55,2.57,2.63,2.69,2.66,2.66,2.61,2.59,2.62,3.55,3.30,3.08,2.99,2.92,2.83,2.73,2.70,2.70,2.65,2.73,2.81,2.87,2.85,2.85,2.81,2.78,2.76,3.77,3.41,3.25,3.08,3.21,3.19,3.18,3.17,3.13,3.14,3.13,3.12,3.11,3.10,3.09,3.15,3.07,2.97,2.91,2.82,2.76,2.74,2.67,2.68,2.69,2.78,2.89,2.89,2.96,2.90,2.92,2.87,3.68,3.46,3.31,3.20,3.14,3.15,3.16,3.17,3.11,3.11,3.13,3.13},
6832    {1.79,1.93,2.80,2.49,2.32,2.22,2.18,2.10,2.11,2.14,3.02,2.86,2.73,2.63,2.58,2.50,2.46,2.43,3.43,3.18,2.95,2.83,2.81,2.69,2.66,2.63,2.58,2.57,2.59,2.65,2.71,2.68,2.68,2.63,2.61,2.64,3.57,3.32,3.10,3.01,2.94,2.85,2.75,2.72,2.72,2.67,2.75,2.83,2.89,2.87,2.87,2.83,2.80,2.78,3.79,3.43,3.27,3.10,3.23,3.21,3.20,3.19,3.15,3.16,3.15,3.14,3.13,3.12,3.11,3.17,3.09,2.99,2.93,2.84,2.78,2.76,2.69,2.70,2.71,2.80,2.91,2.91,2.98,2.92,2.94,2.89,3.70,3.48,3.33,3.22,3.16,3.17,3.18,3.19,3.13,3.13,3.15,3.15},
6833    {1.74,1.88,2.75,2.44,2.27,2.17,2.13,2.05,2.06,2.09,2.97,2.81,2.68,2.58,2.53,2.45,2.41,2.38,3.38,3.13,2.90,2.78,2.76,2.64,2.61,2.58,2.53,2.52,2.54,2.60,2.66,2.63,2.63,2.58,2.56,2.59,3.52,3.27,3.05,2.96,2.89,2.80,2.70,2.67,2.67,2.62,2.70,2.78,2.84,2.82,2.82,2.78,2.75,2.73,3.74,3.38,3.22,3.05,3.18,3.16,3.15,3.14,3.10,3.11,3.10,3.09,3.08,3.07,3.06,3.12,3.04,2.94,2.88,2.79,2.73,2.71,2.64,2.65,2.66,2.75,2.86,2.86,2.93,2.87,2.89,2.84,3.65,3.43,3.28,3.17,3.11,3.12,3.13,3.14,3.08,3.08,3.10,3.10},
6834    {2.55,2.69,3.56,3.25,3.08,2.98,2.94,2.86,2.87,2.90,3.78,3.62,3.49,3.39,3.34,3.26,3.22,3.19,4.19,3.94,3.71,3.59,3.57,3.45,3.42,3.39,3.34,3.33,3.35,3.41,3.47,3.44,3.44,3.39,3.37,3.40,4.33,4.08,3.86,3.77,3.70,3.61,3.51,3.48,3.48,3.43,3.51,3.59,3.65,3.63,3.63,3.59,3.56,3.54,4.55,4.19,4.03,3.86,3.99,3.97,3.96,3.95,3.91,3.92,3.91,3.90,3.89,3.88,3.87,3.93,3.85,3.75,3.69,3.60,3.54,3.52,3.45,3.46,3.47,3.56,3.67,3.67,3.74,3.68,3.70,3.65,4.46,4.24,4.09,3.98,3.92,3.93,3.94,3.95,3.89,3.89,3.91,3.91},
6835    {2.33,2.47,3.34,3.03,2.86,2.76,2.72,2.64,2.65,2.68,3.56,3.40,3.27,3.17,3.12,3.04,3.00,2.97,3.97,3.72,3.49,3.37,3.35,3.23,3.20,3.17,3.12,3.11,3.13,3.19,3.25,3.22,3.22,3.17,3.15,3.18,4.11,3.86,3.64,3.55,3.48,3.39,3.29,3.26,3.26,3.21,3.29,3.37,3.43,3.41,3.41,3.37,3.34,3.32,4.33,3.97,3.81,3.64,3.77,3.75,3.74,3.73,3.69,3.70,3.69,3.68,3.67,3.66,3.65,3.71,3.63,3.53,3.47,3.38,3.32,3.30,3.23,3.24,3.25,3.34,3.45,3.45,3.52,3.46,3.48,3.43,4.24,4.02,3.87,3.76,3.70,3.71,3.72,3.73,3.67,3.67,3.69,3.69},
6836    {2.18,2.32,3.19,2.88,2.71,2.61,2.57,2.49,2.50,2.53,3.41,3.25,3.12,3.02,2.97,2.89,2.85,2.82,3.82,3.57,3.34,3.22,3.20,3.08,3.05,3.02,2.97,2.96,2.98,3.04,3.10,3.07,3.07,3.02,3.00,3.03,3.96,3.71,3.49,3.40,3.33,3.24,3.14,3.11,3.11,3.06,3.14,3.22,3.28,3.26,3.26,3.22,3.19,3.17,4.18,3.82,3.66,3.49,3.62,3.60,3.59,3.58,3.54,3.55,3.54,3.53,3.52,3.51,3.50,3.56,3.48,3.38,3.32,3.23,3.17,3.15,3.08,3.09,3.10,3.19,3.30,3.30,3.37,3.31,3.33,3.28,4.09,3.87,3.72,3.61,3.55,3.56,3.57,3.58,3.52,3.52,3.54,3.54},
6837    {2.07,2.21,3.08,2.77,2.60,2.50,2.46,2.38,2.39,2.42,3.30,3.14,3.01,2.91,2.86,2.78,2.74,2.71,3.71,3.46,3.23,3.11,3.09,2.97,2.94,2.91,2.86,2.85,2.87,2.93,2.99,2.96,2.96,2.91,2.89,2.92,3.85,3.60,3.38,3.29,3.22,3.13,3.03,3.00,3.00,2.95,3.03,3.11,3.17,3.15,3.15,3.11,3.08,3.06,4.07,3.71,3.55,3.38,3.51,3.49,3.48,3.47,3.43,3.44,3.43,3.42,3.41,3.40,3.39,3.45,3.37,3.27,3.21,3.12,3.06,3.04,2.97,2.98,2.99,3.08,3.19,3.19,3.26,3.20,3.22,3.17,3.98,3.76,3.61,3.50,3.44,3.45,3.46,3.47,3.41,3.41,3.43,3.43},
6838    {2.01,2.15,3.02,2.71,2.54,2.44,2.40,2.32,2.33,2.36,3.24,3.08,2.95,2.85,2.80,2.72,2.68,2.65,3.65,3.40,3.17,3.05,3.03,2.91,2.88,2.85,2.80,2.79,2.81,2.87,2.93,2.90,2.90,2.85,2.83,2.86,3.79,3.54,3.32,3.23,3.16,3.07,2.97,2.94,2.94,2.89,2.97,3.05,3.11,3.09,3.09,3.05,3.02,3.00,4.01,3.65,3.49,3.32,3.45,3.43,3.42,3.41,3.37,3.38,3.37,3.36,3.35,3.34,3.33,3.39,3.31,3.21,3.15,3.06,3.00,2.98,2.91,2.92,2.93,3.02,3.13,3.13,3.20,3.14,3.16,3.11,3.92,3.70,3.55,3.44,3.38,3.39,3.40,3.41,3.35,3.35,3.37,3.37},
6839    {2.02,2.16,3.03,2.72,2.55,2.45,2.41,2.33,2.34,2.37,3.25,3.09,2.96,2.86,2.81,2.73,2.69,2.66,3.66,3.41,3.18,3.06,3.04,2.92,2.89,2.86,2.81,2.80,2.82,2.88,2.94,2.91,2.91,2.86,2.84,2.87,3.80,3.55,3.33,3.24,3.17,3.08,2.98,2.95,2.95,2.90,2.98,3.06,3.12,3.10,3.10,3.06,3.03,3.01,4.02,3.66,3.50,3.33,3.46,3.44,3.43,3.42,3.38,3.39,3.38,3.37,3.36,3.35,3.34,3.40,3.32,3.22,3.16,3.07,3.01,2.99,2.92,2.93,2.94,3.03,3.14,3.14,3.21,3.15,3.17,3.12,3.93,3.71,3.56,3.45,3.39,3.40,3.41,3.42,3.36,3.36,3.38,3.38},
6840    {2.03,2.17,3.04,2.73,2.56,2.46,2.42,2.34,2.35,2.38,3.26,3.10,2.97,2.87,2.82,2.74,2.70,2.67,3.67,3.42,3.19,3.07,3.05,2.93,2.90,2.87,2.82,2.81,2.83,2.89,2.95,2.92,2.92,2.87,2.85,2.88,3.81,3.56,3.34,3.25,3.18,3.09,2.99,2.96,2.96,2.91,2.99,3.07,3.13,3.11,3.11,3.07,3.04,3.02,4.03,3.67,3.51,3.34,3.47,3.45,3.44,3.43,3.39,3.40,3.39,3.38,3.37,3.36,3.35,3.41,3.33,3.23,3.17,3.08,3.02,3.00,2.93,2.94,2.95,3.04,3.15,3.15,3.22,3.16,3.18,3.13,3.94,3.72,3.57,3.46,3.40,3.41,3.42,3.43,3.37,3.37,3.39,3.39},
6841    {2.04,2.18,3.05,2.74,2.57,2.47,2.43,2.35,2.36,2.39,3.27,3.11,2.98,2.88,2.83,2.75,2.71,2.68,3.68,3.43,3.20,3.08,3.06,2.94,2.91,2.88,2.83,2.82,2.84,2.90,2.96,2.93,2.93,2.88,2.86,2.89,3.82,3.57,3.35,3.26,3.19,3.10,3.00,2.97,2.97,2.92,3.00,3.08,3.14,3.12,3.12,3.08,3.05,3.03,4.04,3.68,3.52,3.35,3.48,3.46,3.45,3.44,3.40,3.41,3.40,3.39,3.38,3.37,3.36,3.42,3.34,3.24,3.18,3.09,3.03,3.01,2.94,2.95,2.96,3.05,3.16,3.16,3.23,3.17,3.19,3.14,3.95,3.73,3.58,3.47,3.41,3.42,3.43,3.44,3.38,3.38,3.40,3.40},
6842    {1.98,2.12,2.99,2.68,2.51,2.41,2.37,2.29,2.30,2.33,3.21,3.05,2.92,2.82,2.77,2.69,2.65,2.62,3.62,3.37,3.14,3.02,3.00,2.88,2.85,2.82,2.77,2.76,2.78,2.84,2.90,2.87,2.87,2.82,2.80,2.83,3.76,3.51,3.29,3.20,3.13,3.04,2.94,2.91,2.91,2.86,2.94,3.02,3.08,3.06,3.06,3.02,2.99,2.97,3.98,3.62,3.46,3.29,3.42,3.40,3.39,3.38,3.34,3.35,3.34,3.33,3.32,3.31,3.30,3.36,3.28,3.18,3.12,3.03,2.97,2.95,2.88,2.89,2.90,2.99,3.10,3.10,3.17,3.11,3.13,3.08,3.89,3.67,3.52,3.41,3.35,3.36,3.37,3.38,3.32,3.32,3.34,3.34},
6843    {1.98,2.12,2.99,2.68,2.51,2.41,2.37,2.29,2.30,2.33,3.21,3.05,2.92,2.82,2.77,2.69,2.65,2.62,3.62,3.37,3.14,3.02,3.00,2.88,2.85,2.82,2.77,2.76,2.78,2.84,2.90,2.87,2.87,2.82,2.80,2.83,3.76,3.51,3.29,3.20,3.13,3.04,2.94,2.91,2.91,2.86,2.94,3.02,3.08,3.06,3.06,3.02,2.99,2.97,3.98,3.62,3.46,3.29,3.42,3.40,3.39,3.38,3.34,3.35,3.34,3.33,3.32,3.31,3.30,3.36,3.28,3.18,3.12,3.03,2.97,2.95,2.88,2.89,2.90,2.99,3.10,3.10,3.17,3.11,3.13,3.08,3.89,3.67,3.52,3.41,3.35,3.36,3.37,3.38,3.32,3.32,3.34,3.34},
6844    {2.00,2.14,3.01,2.70,2.53,2.43,2.39,2.31,2.32,2.35,3.23,3.07,2.94,2.84,2.79,2.71,2.67,2.64,3.64,3.39,3.16,3.04,3.02,2.90,2.87,2.84,2.79,2.78,2.80,2.86,2.92,2.89,2.89,2.84,2.82,2.85,3.78,3.53,3.31,3.22,3.15,3.06,2.96,2.93,2.93,2.88,2.96,3.04,3.10,3.08,3.08,3.04,3.01,2.99,4.00,3.64,3.48,3.31,3.44,3.42,3.41,3.40,3.36,3.37,3.36,3.35,3.34,3.33,3.32,3.38,3.30,3.20,3.14,3.05,2.99,2.97,2.90,2.91,2.92,3.01,3.12,3.12,3.19,3.13,3.15,3.10,3.91,3.69,3.54,3.43,3.37,3.38,3.39,3.40,3.34,3.34,3.36,3.36},
6845    {2.00,2.14,3.01,2.70,2.53,2.43,2.39,2.31,2.32,2.35,3.23,3.07,2.94,2.84,2.79,2.71,2.67,2.64,3.64,3.39,3.16,3.04,3.02,2.90,2.87,2.84,2.79,2.78,2.80,2.86,2.92,2.89,2.89,2.84,2.82,2.85,3.78,3.53,3.31,3.22,3.15,3.06,2.96,2.93,2.93,2.88,2.96,3.04,3.10,3.08,3.08,3.04,3.01,2.99,4.00,3.64,3.48,3.31,3.44,3.42,3.41,3.40,3.36,3.37,3.36,3.35,3.34,3.33,3.32,3.38,3.30,3.20,3.14,3.05,2.99,2.97,2.90,2.91,2.92,3.01,3.12,3.12,3.19,3.13,3.15,3.10,3.91,3.69,3.54,3.43,3.37,3.38,3.39,3.40,3.34,3.34,3.36,3.36}
6846 };
6847 
6848 static float DoubleDis[NUMDIS][NUMDIS] = {
6849    {0.64,0.78,1.56,1.22,1.10,0.99,0.92,0.89,0.91,1.28,1.92,1.64,1.45,1.39,1.34,1.26,1.27,1.39,2.25,1.79,1.48,1.49,1.44,1.43,1.37,1.41,1.35,1.33,1.47,1.52,1.49,1.43,1.46,1.39,1.41,1.53,2.34,1.89,1.62,1.59,1.57,1.53,1.52,1.46,1.42,1.49,1.71,1.76,1.68,1.62,1.65,1.60,1.61,1.67,2.41,1.93,1.71,1.69,1.70,1.69,1.67,1.66,1.66,1.67,1.67,1.65,1.65,1.65,1.63,1.61,1.63,1.60,1.58,1.52,1.51,1.48,1.47,1.44,1.53,1.74,1.74,1.67,1.73,1.67,1.70,1.77,2.50,2.05,1.85,1.75,1.70,1.66,1.68,1.67,1.67,1.68,1.71,1.72},
6850    {0.78,0.92,1.70,1.36,1.24,1.13,1.06,1.03,1.05,1.42,2.06,1.78,1.59,1.53,1.48,1.40,1.41,1.53,2.39,1.93,1.62,1.63,1.58,1.57,1.51,1.55,1.49,1.47,1.61,1.66,1.63,1.57,1.60,1.53,1.55,1.67,2.48,2.03,1.76,1.73,1.71,1.67,1.66,1.60,1.56,1.63,1.85,1.90,1.82,1.76,1.79,1.74,1.75,1.81,2.55,2.07,1.85,1.83,1.84,1.83,1.81,1.80,1.80,1.81,1.81,1.79,1.79,1.79,1.77,1.75,1.77,1.74,1.72,1.66,1.65,1.62,1.61,1.58,1.67,1.88,1.88,1.81,1.87,1.81,1.84,1.91,2.64,2.19,1.99,1.89,1.84,1.80,1.82,1.81,1.81,1.82,1.85,1.86},
6851    {1.56,1.70,2.48,2.14,2.02,1.91,1.84,1.81,1.83,2.20,2.84,2.56,2.37,2.31,2.26,2.18,2.19,2.31,3.17,2.71,2.40,2.41,2.36,2.35,2.29,2.33,2.27,2.25,2.39,2.44,2.41,2.35,2.38,2.31,2.33,2.45,3.26,2.81,2.54,2.51,2.49,2.45,2.44,2.38,2.34,2.41,2.63,2.68,2.60,2.54,2.57,2.52,2.53,2.59,3.33,2.85,2.63,2.61,2.62,2.61,2.59,2.58,2.58,2.59,2.59,2.57,2.57,2.57,2.55,2.53,2.55,2.52,2.50,2.44,2.43,2.40,2.39,2.36,2.45,2.66,2.66,2.59,2.65,2.59,2.62,2.69,3.42,2.97,2.77,2.67,2.62,2.58,2.60,2.59,2.59,2.60,2.63,2.64},
6852    {1.22,1.36,2.14,1.80,1.68,1.57,1.50,1.47,1.49,1.86,2.50,2.22,2.03,1.97,1.92,1.84,1.85,1.97,2.83,2.37,2.06,2.07,2.02,2.01,1.95,1.99,1.93,1.91,2.05,2.10,2.07,2.01,2.04,1.97,1.99,2.11,2.92,2.47,2.20,2.17,2.15,2.11,2.10,2.04,2.00,2.07,2.29,2.34,2.26,2.20,2.23,2.18,2.19,2.25,2.99,2.51,2.29,2.27,2.28,2.27,2.25,2.24,2.24,2.25,2.25,2.23,2.23,2.23,2.21,2.19,2.21,2.18,2.16,2.10,2.09,2.06,2.05,2.02,2.11,2.32,2.32,2.25,2.31,2.25,2.28,2.35,3.08,2.63,2.43,2.33,2.28,2.24,2.26,2.25,2.25,2.26,2.29,2.30},
6853    {1.10,1.24,2.02,1.68,1.56,1.45,1.38,1.35,1.37,1.74,2.38,2.10,1.91,1.85,1.80,1.72,1.73,1.85,2.71,2.25,1.94,1.95,1.90,1.89,1.83,1.87,1.81,1.79,1.93,1.98,1.95,1.89,1.92,1.85,1.87,1.99,2.80,2.35,2.08,2.05,2.03,1.99,1.98,1.92,1.88,1.95,2.17,2.22,2.14,2.08,2.11,2.06,2.07,2.13,2.87,2.39,2.17,2.15,2.16,2.15,2.13,2.12,2.12,2.13,2.13,2.11,2.11,2.11,2.09,2.07,2.09,2.06,2.04,1.98,1.97,1.94,1.93,1.90,1.99,2.20,2.20,2.13,2.19,2.13,2.16,2.23,2.96,2.51,2.31,2.21,2.16,2.12,2.14,2.13,2.13,2.14,2.17,2.18},
6854    {0.99,1.13,1.91,1.57,1.45,1.34,1.27,1.24,1.26,1.63,2.27,1.99,1.80,1.74,1.69,1.61,1.62,1.74,2.60,2.14,1.83,1.84,1.79,1.78,1.72,1.76,1.70,1.68,1.82,1.87,1.84,1.78,1.81,1.74,1.76,1.88,2.69,2.24,1.97,1.94,1.92,1.88,1.87,1.81,1.77,1.84,2.06,2.11,2.03,1.97,2.00,1.95,1.96,2.02,2.76,2.28,2.06,2.04,2.05,2.04,2.02,2.01,2.01,2.02,2.02,2.00,2.00,2.00,1.98,1.96,1.98,1.95,1.93,1.87,1.86,1.83,1.82,1.79,1.88,2.09,2.09,2.02,2.08,2.02,2.05,2.12,2.85,2.40,2.20,2.10,2.05,2.01,2.03,2.02,2.02,2.03,2.06,2.07},
6855    {0.92,1.06,1.84,1.50,1.38,1.27,1.20,1.17,1.19,1.56,2.20,1.92,1.73,1.67,1.62,1.54,1.55,1.67,2.53,2.07,1.76,1.77,1.72,1.71,1.65,1.69,1.63,1.61,1.75,1.80,1.77,1.71,1.74,1.67,1.69,1.81,2.62,2.17,1.90,1.87,1.85,1.81,1.80,1.74,1.70,1.77,1.99,2.04,1.96,1.90,1.93,1.88,1.89,1.95,2.69,2.21,1.99,1.97,1.98,1.97,1.95,1.94,1.94,1.95,1.95,1.93,1.93,1.93,1.91,1.89,1.91,1.88,1.86,1.80,1.79,1.76,1.75,1.72,1.81,2.02,2.02,1.95,2.01,1.95,1.98,2.05,2.78,2.33,2.13,2.03,1.98,1.94,1.96,1.95,1.95,1.96,1.99,2.00},
6856    {0.89,1.03,1.81,1.47,1.35,1.24,1.17,1.14,1.16,1.53,2.17,1.89,1.70,1.64,1.59,1.51,1.52,1.64,2.50,2.04,1.73,1.74,1.69,1.68,1.62,1.66,1.60,1.58,1.72,1.77,1.74,1.68,1.71,1.64,1.66,1.78,2.59,2.14,1.87,1.84,1.82,1.78,1.77,1.71,1.67,1.74,1.96,2.01,1.93,1.87,1.90,1.85,1.86,1.92,2.66,2.18,1.96,1.94,1.95,1.94,1.92,1.91,1.91,1.92,1.92,1.90,1.90,1.90,1.88,1.86,1.88,1.85,1.83,1.77,1.76,1.73,1.72,1.69,1.78,1.99,1.99,1.92,1.98,1.92,1.95,2.02,2.75,2.30,2.10,2.00,1.95,1.91,1.93,1.92,1.92,1.93,1.96,1.97},
6857    {0.91,1.05,1.83,1.49,1.37,1.26,1.19,1.16,1.18,1.55,2.19,1.91,1.72,1.66,1.61,1.53,1.54,1.66,2.52,2.06,1.75,1.76,1.71,1.70,1.64,1.68,1.62,1.60,1.74,1.79,1.76,1.70,1.73,1.66,1.68,1.80,2.61,2.16,1.89,1.86,1.84,1.80,1.79,1.73,1.69,1.76,1.98,2.03,1.95,1.89,1.92,1.87,1.88,1.94,2.68,2.20,1.98,1.96,1.97,1.96,1.94,1.93,1.93,1.94,1.94,1.92,1.92,1.92,1.90,1.88,1.90,1.87,1.85,1.79,1.78,1.75,1.74,1.71,1.80,2.01,2.01,1.94,2.00,1.94,1.97,2.04,2.77,2.32,2.12,2.02,1.97,1.93,1.95,1.94,1.94,1.95,1.98,1.99},
6858    {1.28,1.42,2.20,1.86,1.74,1.63,1.56,1.53,1.55,1.92,2.56,2.28,2.09,2.03,1.98,1.90,1.91,2.03,2.89,2.43,2.12,2.13,2.08,2.07,2.01,2.05,1.99,1.97,2.11,2.16,2.13,2.07,2.10,2.03,2.05,2.17,2.98,2.53,2.26,2.23,2.21,2.17,2.16,2.10,2.06,2.13,2.35,2.40,2.32,2.26,2.29,2.24,2.25,2.31,3.05,2.57,2.35,2.33,2.34,2.33,2.31,2.30,2.30,2.31,2.31,2.29,2.29,2.29,2.27,2.25,2.27,2.24,2.22,2.16,2.15,2.12,2.11,2.08,2.17,2.38,2.38,2.31,2.37,2.31,2.34,2.41,3.14,2.69,2.49,2.39,2.34,2.30,2.32,2.31,2.31,2.32,2.35,2.36},
6859    {1.92,2.06,2.84,2.50,2.38,2.27,2.20,2.17,2.19,2.56,3.20,2.92,2.73,2.67,2.62,2.54,2.55,2.67,3.53,3.07,2.76,2.77,2.72,2.71,2.65,2.69,2.63,2.61,2.75,2.80,2.77,2.71,2.74,2.67,2.69,2.81,3.62,3.17,2.90,2.87,2.85,2.81,2.80,2.74,2.70,2.77,2.99,3.04,2.96,2.90,2.93,2.88,2.89,2.95,3.69,3.21,2.99,2.97,2.98,2.97,2.95,2.94,2.94,2.95,2.95,2.93,2.93,2.93,2.91,2.89,2.91,2.88,2.86,2.80,2.79,2.76,2.75,2.72,2.81,3.02,3.02,2.95,3.01,2.95,2.98,3.05,3.78,3.33,3.13,3.03,2.98,2.94,2.96,2.95,2.95,2.96,2.99,3.00},
6860    {1.64,1.78,2.56,2.22,2.10,1.99,1.92,1.89,1.91,2.28,2.92,2.64,2.45,2.39,2.34,2.26,2.27,2.39,3.25,2.79,2.48,2.49,2.44,2.43,2.37,2.41,2.35,2.33,2.47,2.52,2.49,2.43,2.46,2.39,2.41,2.53,3.34,2.89,2.62,2.59,2.57,2.53,2.52,2.46,2.42,2.49,2.71,2.76,2.68,2.62,2.65,2.60,2.61,2.67,3.41,2.93,2.71,2.69,2.70,2.69,2.67,2.66,2.66,2.67,2.67,2.65,2.65,2.65,2.63,2.61,2.63,2.60,2.58,2.52,2.51,2.48,2.47,2.44,2.53,2.74,2.74,2.67,2.73,2.67,2.70,2.77,3.50,3.05,2.85,2.75,2.70,2.66,2.68,2.67,2.67,2.68,2.71,2.72},
6861    {1.45,1.59,2.37,2.03,1.91,1.80,1.73,1.70,1.72,2.09,2.73,2.45,2.26,2.20,2.15,2.07,2.08,2.20,3.06,2.60,2.29,2.30,2.25,2.24,2.18,2.22,2.16,2.14,2.28,2.33,2.30,2.24,2.27,2.20,2.22,2.34,3.15,2.70,2.43,2.40,2.38,2.34,2.33,2.27,2.23,2.30,2.52,2.57,2.49,2.43,2.46,2.41,2.42,2.48,3.22,2.74,2.52,2.50,2.51,2.50,2.48,2.47,2.47,2.48,2.48,2.46,2.46,2.46,2.44,2.42,2.44,2.41,2.39,2.33,2.32,2.29,2.28,2.25,2.34,2.55,2.55,2.48,2.54,2.48,2.51,2.58,3.31,2.86,2.66,2.56,2.51,2.47,2.49,2.48,2.48,2.49,2.52,2.53},
6862    {1.39,1.53,2.31,1.97,1.85,1.74,1.67,1.64,1.66,2.03,2.67,2.39,2.20,2.14,2.09,2.01,2.02,2.14,3.00,2.54,2.23,2.24,2.19,2.18,2.12,2.16,2.10,2.08,2.22,2.27,2.24,2.18,2.21,2.14,2.16,2.28,3.09,2.64,2.37,2.34,2.32,2.28,2.27,2.21,2.17,2.24,2.46,2.51,2.43,2.37,2.40,2.35,2.36,2.42,3.16,2.68,2.46,2.44,2.45,2.44,2.42,2.41,2.41,2.42,2.42,2.40,2.40,2.40,2.38,2.36,2.38,2.35,2.33,2.27,2.26,2.23,2.22,2.19,2.28,2.49,2.49,2.42,2.48,2.42,2.45,2.52,3.25,2.80,2.60,2.50,2.45,2.41,2.43,2.42,2.42,2.43,2.46,2.47},
6863    {1.34,1.48,2.26,1.92,1.80,1.69,1.62,1.59,1.61,1.98,2.62,2.34,2.15,2.09,2.04,1.96,1.97,2.09,2.95,2.49,2.18,2.19,2.14,2.13,2.07,2.11,2.05,2.03,2.17,2.22,2.19,2.13,2.16,2.09,2.11,2.23,3.04,2.59,2.32,2.29,2.27,2.23,2.22,2.16,2.12,2.19,2.41,2.46,2.38,2.32,2.35,2.30,2.31,2.37,3.11,2.63,2.41,2.39,2.40,2.39,2.37,2.36,2.36,2.37,2.37,2.35,2.35,2.35,2.33,2.31,2.33,2.30,2.28,2.22,2.21,2.18,2.17,2.14,2.23,2.44,2.44,2.37,2.43,2.37,2.40,2.47,3.20,2.75,2.55,2.45,2.40,2.36,2.38,2.37,2.37,2.38,2.41,2.42},
6864    {1.26,1.40,2.18,1.84,1.72,1.61,1.54,1.51,1.53,1.90,2.54,2.26,2.07,2.01,1.96,1.88,1.89,2.01,2.87,2.41,2.10,2.11,2.06,2.05,1.99,2.03,1.97,1.95,2.09,2.14,2.11,2.05,2.08,2.01,2.03,2.15,2.96,2.51,2.24,2.21,2.19,2.15,2.14,2.08,2.04,2.11,2.33,2.38,2.30,2.24,2.27,2.22,2.23,2.29,3.03,2.55,2.33,2.31,2.32,2.31,2.29,2.28,2.28,2.29,2.29,2.27,2.27,2.27,2.25,2.23,2.25,2.22,2.20,2.14,2.13,2.10,2.09,2.06,2.15,2.36,2.36,2.29,2.35,2.29,2.32,2.39,3.12,2.67,2.47,2.37,2.32,2.28,2.30,2.29,2.29,2.30,2.33,2.34},
6865    {1.27,1.41,2.19,1.85,1.73,1.62,1.55,1.52,1.54,1.91,2.55,2.27,2.08,2.02,1.97,1.89,1.90,2.02,2.88,2.42,2.11,2.12,2.07,2.06,2.00,2.04,1.98,1.96,2.10,2.15,2.12,2.06,2.09,2.02,2.04,2.16,2.97,2.52,2.25,2.22,2.20,2.16,2.15,2.09,2.05,2.12,2.34,2.39,2.31,2.25,2.28,2.23,2.24,2.30,3.04,2.56,2.34,2.32,2.33,2.32,2.30,2.29,2.29,2.30,2.30,2.28,2.28,2.28,2.26,2.24,2.26,2.23,2.21,2.15,2.14,2.11,2.10,2.07,2.16,2.37,2.37,2.30,2.36,2.30,2.33,2.40,3.13,2.68,2.48,2.38,2.33,2.29,2.31,2.30,2.30,2.31,2.34,2.35},
6866    {1.39,1.53,2.31,1.97,1.85,1.74,1.67,1.64,1.66,2.03,2.67,2.39,2.20,2.14,2.09,2.01,2.02,2.14,3.00,2.54,2.23,2.24,2.19,2.18,2.12,2.16,2.10,2.08,2.22,2.27,2.24,2.18,2.21,2.14,2.16,2.28,3.09,2.64,2.37,2.34,2.32,2.28,2.27,2.21,2.17,2.24,2.46,2.51,2.43,2.37,2.40,2.35,2.36,2.42,3.16,2.68,2.46,2.44,2.45,2.44,2.42,2.41,2.41,2.42,2.42,2.40,2.40,2.40,2.38,2.36,2.38,2.35,2.33,2.27,2.26,2.23,2.22,2.19,2.28,2.49,2.49,2.42,2.48,2.42,2.45,2.52,3.25,2.80,2.60,2.50,2.45,2.41,2.43,2.42,2.42,2.43,2.46,2.47},
6867    {2.25,2.39,3.17,2.83,2.71,2.60,2.53,2.50,2.52,2.89,3.53,3.25,3.06,3.00,2.95,2.87,2.88,3.00,3.86,3.40,3.09,3.10,3.05,3.04,2.98,3.02,2.96,2.94,3.08,3.13,3.10,3.04,3.07,3.00,3.02,3.14,3.95,3.50,3.23,3.20,3.18,3.14,3.13,3.07,3.03,3.10,3.32,3.37,3.29,3.23,3.26,3.21,3.22,3.28,4.02,3.54,3.32,3.30,3.31,3.30,3.28,3.27,3.27,3.28,3.28,3.26,3.26,3.26,3.24,3.22,3.24,3.21,3.19,3.13,3.12,3.09,3.08,3.05,3.14,3.35,3.35,3.28,3.34,3.28,3.31,3.38,4.11,3.66,3.46,3.36,3.31,3.27,3.29,3.28,3.28,3.29,3.32,3.33},
6868    {1.79,1.93,2.71,2.37,2.25,2.14,2.07,2.04,2.06,2.43,3.07,2.79,2.60,2.54,2.49,2.41,2.42,2.54,3.40,2.94,2.63,2.64,2.59,2.58,2.52,2.56,2.50,2.48,2.62,2.67,2.64,2.58,2.61,2.54,2.56,2.68,3.49,3.04,2.77,2.74,2.72,2.68,2.67,2.61,2.57,2.64,2.86,2.91,2.83,2.77,2.80,2.75,2.76,2.82,3.56,3.08,2.86,2.84,2.85,2.84,2.82,2.81,2.81,2.82,2.82,2.80,2.80,2.80,2.78,2.76,2.78,2.75,2.73,2.67,2.66,2.63,2.62,2.59,2.68,2.89,2.89,2.82,2.88,2.82,2.85,2.92,3.65,3.20,3.00,2.90,2.85,2.81,2.83,2.82,2.82,2.83,2.86,2.87},
6869    {1.48,1.62,2.40,2.06,1.94,1.83,1.76,1.73,1.75,2.12,2.76,2.48,2.29,2.23,2.18,2.10,2.11,2.23,3.09,2.63,2.32,2.33,2.28,2.27,2.21,2.25,2.19,2.17,2.31,2.36,2.33,2.27,2.30,2.23,2.25,2.37,3.18,2.73,2.46,2.43,2.41,2.37,2.36,2.30,2.26,2.33,2.55,2.60,2.52,2.46,2.49,2.44,2.45,2.51,3.25,2.77,2.55,2.53,2.54,2.53,2.51,2.50,2.50,2.51,2.51,2.49,2.49,2.49,2.47,2.45,2.47,2.44,2.42,2.36,2.35,2.32,2.31,2.28,2.37,2.58,2.58,2.51,2.57,2.51,2.54,2.61,3.34,2.89,2.69,2.59,2.54,2.50,2.52,2.51,2.51,2.52,2.55,2.56},
6870    {1.49,1.63,2.41,2.07,1.95,1.84,1.77,1.74,1.76,2.13,2.77,2.49,2.30,2.24,2.19,2.11,2.12,2.24,3.10,2.64,2.33,2.34,2.29,2.28,2.22,2.26,2.20,2.18,2.32,2.37,2.34,2.28,2.31,2.24,2.26,2.38,3.19,2.74,2.47,2.44,2.42,2.38,2.37,2.31,2.27,2.34,2.56,2.61,2.53,2.47,2.50,2.45,2.46,2.52,3.26,2.78,2.56,2.54,2.55,2.54,2.52,2.51,2.51,2.52,2.52,2.50,2.50,2.50,2.48,2.46,2.48,2.45,2.43,2.37,2.36,2.33,2.32,2.29,2.38,2.59,2.59,2.52,2.58,2.52,2.55,2.62,3.35,2.90,2.70,2.60,2.55,2.51,2.53,2.52,2.52,2.53,2.56,2.57},
6871    {1.44,1.58,2.36,2.02,1.90,1.79,1.72,1.69,1.71,2.08,2.72,2.44,2.25,2.19,2.14,2.06,2.07,2.19,3.05,2.59,2.28,2.29,2.24,2.23,2.17,2.21,2.15,2.13,2.27,2.32,2.29,2.23,2.26,2.19,2.21,2.33,3.14,2.69,2.42,2.39,2.37,2.33,2.32,2.26,2.22,2.29,2.51,2.56,2.48,2.42,2.45,2.40,2.41,2.47,3.21,2.73,2.51,2.49,2.50,2.49,2.47,2.46,2.46,2.47,2.47,2.45,2.45,2.45,2.43,2.41,2.43,2.40,2.38,2.32,2.31,2.28,2.27,2.24,2.33,2.54,2.54,2.47,2.53,2.47,2.50,2.57,3.30,2.85,2.65,2.55,2.50,2.46,2.48,2.47,2.47,2.48,2.51,2.52},
6872    {1.43,1.57,2.35,2.01,1.89,1.78,1.71,1.68,1.70,2.07,2.71,2.43,2.24,2.18,2.13,2.05,2.06,2.18,3.04,2.58,2.27,2.28,2.23,2.22,2.16,2.20,2.14,2.12,2.26,2.31,2.28,2.22,2.25,2.18,2.20,2.32,3.13,2.68,2.41,2.38,2.36,2.32,2.31,2.25,2.21,2.28,2.50,2.55,2.47,2.41,2.44,2.39,2.40,2.46,3.20,2.72,2.50,2.48,2.49,2.48,2.46,2.45,2.45,2.46,2.46,2.44,2.44,2.44,2.42,2.40,2.42,2.39,2.37,2.31,2.30,2.27,2.26,2.23,2.32,2.53,2.53,2.46,2.52,2.46,2.49,2.56,3.29,2.84,2.64,2.54,2.49,2.45,2.47,2.46,2.46,2.47,2.50,2.51},
6873    {1.37,1.51,2.29,1.95,1.83,1.72,1.65,1.62,1.64,2.01,2.65,2.37,2.18,2.12,2.07,1.99,2.00,2.12,2.98,2.52,2.21,2.22,2.17,2.16,2.10,2.14,2.08,2.06,2.20,2.25,2.22,2.16,2.19,2.12,2.14,2.26,3.07,2.62,2.35,2.32,2.30,2.26,2.25,2.19,2.15,2.22,2.44,2.49,2.41,2.35,2.38,2.33,2.34,2.40,3.14,2.66,2.44,2.42,2.43,2.42,2.40,2.39,2.39,2.40,2.40,2.38,2.38,2.38,2.36,2.34,2.36,2.33,2.31,2.25,2.24,2.21,2.20,2.17,2.26,2.47,2.47,2.40,2.46,2.40,2.43,2.50,3.23,2.78,2.58,2.48,2.43,2.39,2.41,2.40,2.40,2.41,2.44,2.45},
6874    {1.41,1.55,2.33,1.99,1.87,1.76,1.69,1.66,1.68,2.05,2.69,2.41,2.22,2.16,2.11,2.03,2.04,2.16,3.02,2.56,2.25,2.26,2.21,2.20,2.14,2.18,2.12,2.10,2.24,2.29,2.26,2.20,2.23,2.16,2.18,2.30,3.11,2.66,2.39,2.36,2.34,2.30,2.29,2.23,2.19,2.26,2.48,2.53,2.45,2.39,2.42,2.37,2.38,2.44,3.18,2.70,2.48,2.46,2.47,2.46,2.44,2.43,2.43,2.44,2.44,2.42,2.42,2.42,2.40,2.38,2.40,2.37,2.35,2.29,2.28,2.25,2.24,2.21,2.30,2.51,2.51,2.44,2.50,2.44,2.47,2.54,3.27,2.82,2.62,2.52,2.47,2.43,2.45,2.44,2.44,2.45,2.48,2.49},
6875    {1.35,1.49,2.27,1.93,1.81,1.70,1.63,1.60,1.62,1.99,2.63,2.35,2.16,2.10,2.05,1.97,1.98,2.10,2.96,2.50,2.19,2.20,2.15,2.14,2.08,2.12,2.06,2.04,2.18,2.23,2.20,2.14,2.17,2.10,2.12,2.24,3.05,2.60,2.33,2.30,2.28,2.24,2.23,2.17,2.13,2.20,2.42,2.47,2.39,2.33,2.36,2.31,2.32,2.38,3.12,2.64,2.42,2.40,2.41,2.40,2.38,2.37,2.37,2.38,2.38,2.36,2.36,2.36,2.34,2.32,2.34,2.31,2.29,2.23,2.22,2.19,2.18,2.15,2.24,2.45,2.45,2.38,2.44,2.38,2.41,2.48,3.21,2.76,2.56,2.46,2.41,2.37,2.39,2.38,2.38,2.39,2.42,2.43},
6876    {1.33,1.47,2.25,1.91,1.79,1.68,1.61,1.58,1.60,1.97,2.61,2.33,2.14,2.08,2.03,1.95,1.96,2.08,2.94,2.48,2.17,2.18,2.13,2.12,2.06,2.10,2.04,2.02,2.16,2.21,2.18,2.12,2.15,2.08,2.10,2.22,3.03,2.58,2.31,2.28,2.26,2.22,2.21,2.15,2.11,2.18,2.40,2.45,2.37,2.31,2.34,2.29,2.30,2.36,3.10,2.62,2.40,2.38,2.39,2.38,2.36,2.35,2.35,2.36,2.36,2.34,2.34,2.34,2.32,2.30,2.32,2.29,2.27,2.21,2.20,2.17,2.16,2.13,2.22,2.43,2.43,2.36,2.42,2.36,2.39,2.46,3.19,2.74,2.54,2.44,2.39,2.35,2.37,2.36,2.36,2.37,2.40,2.41},
6877    {1.47,1.61,2.39,2.05,1.93,1.82,1.75,1.72,1.74,2.11,2.75,2.47,2.28,2.22,2.17,2.09,2.10,2.22,3.08,2.62,2.31,2.32,2.27,2.26,2.20,2.24,2.18,2.16,2.30,2.35,2.32,2.26,2.29,2.22,2.24,2.36,3.17,2.72,2.45,2.42,2.40,2.36,2.35,2.29,2.25,2.32,2.54,2.59,2.51,2.45,2.48,2.43,2.44,2.50,3.24,2.76,2.54,2.52,2.53,2.52,2.50,2.49,2.49,2.50,2.50,2.48,2.48,2.48,2.46,2.44,2.46,2.43,2.41,2.35,2.34,2.31,2.30,2.27,2.36,2.57,2.57,2.50,2.56,2.50,2.53,2.60,3.33,2.88,2.68,2.58,2.53,2.49,2.51,2.50,2.50,2.51,2.54,2.55},
6878    {1.52,1.66,2.44,2.10,1.98,1.87,1.80,1.77,1.79,2.16,2.80,2.52,2.33,2.27,2.22,2.14,2.15,2.27,3.13,2.67,2.36,2.37,2.32,2.31,2.25,2.29,2.23,2.21,2.35,2.40,2.37,2.31,2.34,2.27,2.29,2.41,3.22,2.77,2.50,2.47,2.45,2.41,2.40,2.34,2.30,2.37,2.59,2.64,2.56,2.50,2.53,2.48,2.49,2.55,3.29,2.81,2.59,2.57,2.58,2.57,2.55,2.54,2.54,2.55,2.55,2.53,2.53,2.53,2.51,2.49,2.51,2.48,2.46,2.40,2.39,2.36,2.35,2.32,2.41,2.62,2.62,2.55,2.61,2.55,2.58,2.65,3.38,2.93,2.73,2.63,2.58,2.54,2.56,2.55,2.55,2.56,2.59,2.60},
6879    {1.49,1.63,2.41,2.07,1.95,1.84,1.77,1.74,1.76,2.13,2.77,2.49,2.30,2.24,2.19,2.11,2.12,2.24,3.10,2.64,2.33,2.34,2.29,2.28,2.22,2.26,2.20,2.18,2.32,2.37,2.34,2.28,2.31,2.24,2.26,2.38,3.19,2.74,2.47,2.44,2.42,2.38,2.37,2.31,2.27,2.34,2.56,2.61,2.53,2.47,2.50,2.45,2.46,2.52,3.26,2.78,2.56,2.54,2.55,2.54,2.52,2.51,2.51,2.52,2.52,2.50,2.50,2.50,2.48,2.46,2.48,2.45,2.43,2.37,2.36,2.33,2.32,2.29,2.38,2.59,2.59,2.52,2.58,2.52,2.55,2.62,3.35,2.90,2.70,2.60,2.55,2.51,2.53,2.52,2.52,2.53,2.56,2.57},
6880    {1.43,1.57,2.35,2.01,1.89,1.78,1.71,1.68,1.70,2.07,2.71,2.43,2.24,2.18,2.13,2.05,2.06,2.18,3.04,2.58,2.27,2.28,2.23,2.22,2.16,2.20,2.14,2.12,2.26,2.31,2.28,2.22,2.25,2.18,2.20,2.32,3.13,2.68,2.41,2.38,2.36,2.32,2.31,2.25,2.21,2.28,2.50,2.55,2.47,2.41,2.44,2.39,2.40,2.46,3.20,2.72,2.50,2.48,2.49,2.48,2.46,2.45,2.45,2.46,2.46,2.44,2.44,2.44,2.42,2.40,2.42,2.39,2.37,2.31,2.30,2.27,2.26,2.23,2.32,2.53,2.53,2.46,2.52,2.46,2.49,2.56,3.29,2.84,2.64,2.54,2.49,2.45,2.47,2.46,2.46,2.47,2.50,2.51},
6881    {1.46,1.60,2.38,2.04,1.92,1.81,1.74,1.71,1.73,2.10,2.74,2.46,2.27,2.21,2.16,2.08,2.09,2.21,3.07,2.61,2.30,2.31,2.26,2.25,2.19,2.23,2.17,2.15,2.29,2.34,2.31,2.25,2.28,2.21,2.23,2.35,3.16,2.71,2.44,2.41,2.39,2.35,2.34,2.28,2.24,2.31,2.53,2.58,2.50,2.44,2.47,2.42,2.43,2.49,3.23,2.75,2.53,2.51,2.52,2.51,2.49,2.48,2.48,2.49,2.49,2.47,2.47,2.47,2.45,2.43,2.45,2.42,2.40,2.34,2.33,2.30,2.29,2.26,2.35,2.56,2.56,2.49,2.55,2.49,2.52,2.59,3.32,2.87,2.67,2.57,2.52,2.48,2.50,2.49,2.49,2.50,2.53,2.54},
6882    {1.39,1.53,2.31,1.97,1.85,1.74,1.67,1.64,1.66,2.03,2.67,2.39,2.20,2.14,2.09,2.01,2.02,2.14,3.00,2.54,2.23,2.24,2.19,2.18,2.12,2.16,2.10,2.08,2.22,2.27,2.24,2.18,2.21,2.14,2.16,2.28,3.09,2.64,2.37,2.34,2.32,2.28,2.27,2.21,2.17,2.24,2.46,2.51,2.43,2.37,2.40,2.35,2.36,2.42,3.16,2.68,2.46,2.44,2.45,2.44,2.42,2.41,2.41,2.42,2.42,2.40,2.40,2.40,2.38,2.36,2.38,2.35,2.33,2.27,2.26,2.23,2.22,2.19,2.28,2.49,2.49,2.42,2.48,2.42,2.45,2.52,3.25,2.80,2.60,2.50,2.45,2.41,2.43,2.42,2.42,2.43,2.46,2.47},
6883    {1.41,1.55,2.33,1.99,1.87,1.76,1.69,1.66,1.68,2.05,2.69,2.41,2.22,2.16,2.11,2.03,2.04,2.16,3.02,2.56,2.25,2.26,2.21,2.20,2.14,2.18,2.12,2.10,2.24,2.29,2.26,2.20,2.23,2.16,2.18,2.30,3.11,2.66,2.39,2.36,2.34,2.30,2.29,2.23,2.19,2.26,2.48,2.53,2.45,2.39,2.42,2.37,2.38,2.44,3.18,2.70,2.48,2.46,2.47,2.46,2.44,2.43,2.43,2.44,2.44,2.42,2.42,2.42,2.40,2.38,2.40,2.37,2.35,2.29,2.28,2.25,2.24,2.21,2.30,2.51,2.51,2.44,2.50,2.44,2.47,2.54,3.27,2.82,2.62,2.52,2.47,2.43,2.45,2.44,2.44,2.45,2.48,2.49},
6884    {1.53,1.67,2.45,2.11,1.99,1.88,1.81,1.78,1.80,2.17,2.81,2.53,2.34,2.28,2.23,2.15,2.16,2.28,3.14,2.68,2.37,2.38,2.33,2.32,2.26,2.30,2.24,2.22,2.36,2.41,2.38,2.32,2.35,2.28,2.30,2.42,3.23,2.78,2.51,2.48,2.46,2.42,2.41,2.35,2.31,2.38,2.60,2.65,2.57,2.51,2.54,2.49,2.50,2.56,3.30,2.82,2.60,2.58,2.59,2.58,2.56,2.55,2.55,2.56,2.56,2.54,2.54,2.54,2.52,2.50,2.52,2.49,2.47,2.41,2.40,2.37,2.36,2.33,2.42,2.63,2.63,2.56,2.62,2.56,2.59,2.66,3.39,2.94,2.74,2.64,2.59,2.55,2.57,2.56,2.56,2.57,2.60,2.61},
6885    {2.34,2.48,3.26,2.92,2.80,2.69,2.62,2.59,2.61,2.98,3.62,3.34,3.15,3.09,3.04,2.96,2.97,3.09,3.95,3.49,3.18,3.19,3.14,3.13,3.07,3.11,3.05,3.03,3.17,3.22,3.19,3.13,3.16,3.09,3.11,3.23,4.04,3.59,3.32,3.29,3.27,3.23,3.22,3.16,3.12,3.19,3.41,3.46,3.38,3.32,3.35,3.30,3.31,3.37,4.11,3.63,3.41,3.39,3.40,3.39,3.37,3.36,3.36,3.37,3.37,3.35,3.35,3.35,3.33,3.31,3.33,3.30,3.28,3.22,3.21,3.18,3.17,3.14,3.23,3.44,3.44,3.37,3.43,3.37,3.40,3.47,4.20,3.75,3.55,3.45,3.40,3.36,3.38,3.37,3.37,3.38,3.41,3.42},
6886    {1.89,2.03,2.81,2.47,2.35,2.24,2.17,2.14,2.16,2.53,3.17,2.89,2.70,2.64,2.59,2.51,2.52,2.64,3.50,3.04,2.73,2.74,2.69,2.68,2.62,2.66,2.60,2.58,2.72,2.77,2.74,2.68,2.71,2.64,2.66,2.78,3.59,3.14,2.87,2.84,2.82,2.78,2.77,2.71,2.67,2.74,2.96,3.01,2.93,2.87,2.90,2.85,2.86,2.92,3.66,3.18,2.96,2.94,2.95,2.94,2.92,2.91,2.91,2.92,2.92,2.90,2.90,2.90,2.88,2.86,2.88,2.85,2.83,2.77,2.76,2.73,2.72,2.69,2.78,2.99,2.99,2.92,2.98,2.92,2.95,3.02,3.75,3.30,3.10,3.00,2.95,2.91,2.93,2.92,2.92,2.93,2.96,2.97},
6887    {1.62,1.76,2.54,2.20,2.08,1.97,1.90,1.87,1.89,2.26,2.90,2.62,2.43,2.37,2.32,2.24,2.25,2.37,3.23,2.77,2.46,2.47,2.42,2.41,2.35,2.39,2.33,2.31,2.45,2.50,2.47,2.41,2.44,2.37,2.39,2.51,3.32,2.87,2.60,2.57,2.55,2.51,2.50,2.44,2.40,2.47,2.69,2.74,2.66,2.60,2.63,2.58,2.59,2.65,3.39,2.91,2.69,2.67,2.68,2.67,2.65,2.64,2.64,2.65,2.65,2.63,2.63,2.63,2.61,2.59,2.61,2.58,2.56,2.50,2.49,2.46,2.45,2.42,2.51,2.72,2.72,2.65,2.71,2.65,2.68,2.75,3.48,3.03,2.83,2.73,2.68,2.64,2.66,2.65,2.65,2.66,2.69,2.70},
6888    {1.59,1.73,2.51,2.17,2.05,1.94,1.87,1.84,1.86,2.23,2.87,2.59,2.40,2.34,2.29,2.21,2.22,2.34,3.20,2.74,2.43,2.44,2.39,2.38,2.32,2.36,2.30,2.28,2.42,2.47,2.44,2.38,2.41,2.34,2.36,2.48,3.29,2.84,2.57,2.54,2.52,2.48,2.47,2.41,2.37,2.44,2.66,2.71,2.63,2.57,2.60,2.55,2.56,2.62,3.36,2.88,2.66,2.64,2.65,2.64,2.62,2.61,2.61,2.62,2.62,2.60,2.60,2.60,2.58,2.56,2.58,2.55,2.53,2.47,2.46,2.43,2.42,2.39,2.48,2.69,2.69,2.62,2.68,2.62,2.65,2.72,3.45,3.00,2.80,2.70,2.65,2.61,2.63,2.62,2.62,2.63,2.66,2.67},
6889    {1.57,1.71,2.49,2.15,2.03,1.92,1.85,1.82,1.84,2.21,2.85,2.57,2.38,2.32,2.27,2.19,2.20,2.32,3.18,2.72,2.41,2.42,2.37,2.36,2.30,2.34,2.28,2.26,2.40,2.45,2.42,2.36,2.39,2.32,2.34,2.46,3.27,2.82,2.55,2.52,2.50,2.46,2.45,2.39,2.35,2.42,2.64,2.69,2.61,2.55,2.58,2.53,2.54,2.60,3.34,2.86,2.64,2.62,2.63,2.62,2.60,2.59,2.59,2.60,2.60,2.58,2.58,2.58,2.56,2.54,2.56,2.53,2.51,2.45,2.44,2.41,2.40,2.37,2.46,2.67,2.67,2.60,2.66,2.60,2.63,2.70,3.43,2.98,2.78,2.68,2.63,2.59,2.61,2.60,2.60,2.61,2.64,2.65},
6890    {1.53,1.67,2.45,2.11,1.99,1.88,1.81,1.78,1.80,2.17,2.81,2.53,2.34,2.28,2.23,2.15,2.16,2.28,3.14,2.68,2.37,2.38,2.33,2.32,2.26,2.30,2.24,2.22,2.36,2.41,2.38,2.32,2.35,2.28,2.30,2.42,3.23,2.78,2.51,2.48,2.46,2.42,2.41,2.35,2.31,2.38,2.60,2.65,2.57,2.51,2.54,2.49,2.50,2.56,3.30,2.82,2.60,2.58,2.59,2.58,2.56,2.55,2.55,2.56,2.56,2.54,2.54,2.54,2.52,2.50,2.52,2.49,2.47,2.41,2.40,2.37,2.36,2.33,2.42,2.63,2.63,2.56,2.62,2.56,2.59,2.66,3.39,2.94,2.74,2.64,2.59,2.55,2.57,2.56,2.56,2.57,2.60,2.61},
6891    {1.52,1.66,2.44,2.10,1.98,1.87,1.80,1.77,1.79,2.16,2.80,2.52,2.33,2.27,2.22,2.14,2.15,2.27,3.13,2.67,2.36,2.37,2.32,2.31,2.25,2.29,2.23,2.21,2.35,2.40,2.37,2.31,2.34,2.27,2.29,2.41,3.22,2.77,2.50,2.47,2.45,2.41,2.40,2.34,2.30,2.37,2.59,2.64,2.56,2.50,2.53,2.48,2.49,2.55,3.29,2.81,2.59,2.57,2.58,2.57,2.55,2.54,2.54,2.55,2.55,2.53,2.53,2.53,2.51,2.49,2.51,2.48,2.46,2.40,2.39,2.36,2.35,2.32,2.41,2.62,2.62,2.55,2.61,2.55,2.58,2.65,3.38,2.93,2.73,2.63,2.58,2.54,2.56,2.55,2.55,2.56,2.59,2.60},
6892    {1.46,1.60,2.38,2.04,1.92,1.81,1.74,1.71,1.73,2.10,2.74,2.46,2.27,2.21,2.16,2.08,2.09,2.21,3.07,2.61,2.30,2.31,2.26,2.25,2.19,2.23,2.17,2.15,2.29,2.34,2.31,2.25,2.28,2.21,2.23,2.35,3.16,2.71,2.44,2.41,2.39,2.35,2.34,2.28,2.24,2.31,2.53,2.58,2.50,2.44,2.47,2.42,2.43,2.49,3.23,2.75,2.53,2.51,2.52,2.51,2.49,2.48,2.48,2.49,2.49,2.47,2.47,2.47,2.45,2.43,2.45,2.42,2.40,2.34,2.33,2.30,2.29,2.26,2.35,2.56,2.56,2.49,2.55,2.49,2.52,2.59,3.32,2.87,2.67,2.57,2.52,2.48,2.50,2.49,2.49,2.50,2.53,2.54},
6893    {1.42,1.56,2.34,2.00,1.88,1.77,1.70,1.67,1.69,2.06,2.70,2.42,2.23,2.17,2.12,2.04,2.05,2.17,3.03,2.57,2.26,2.27,2.22,2.21,2.15,2.19,2.13,2.11,2.25,2.30,2.27,2.21,2.24,2.17,2.19,2.31,3.12,2.67,2.40,2.37,2.35,2.31,2.30,2.24,2.20,2.27,2.49,2.54,2.46,2.40,2.43,2.38,2.39,2.45,3.19,2.71,2.49,2.47,2.48,2.47,2.45,2.44,2.44,2.45,2.45,2.43,2.43,2.43,2.41,2.39,2.41,2.38,2.36,2.30,2.29,2.26,2.25,2.22,2.31,2.52,2.52,2.45,2.51,2.45,2.48,2.55,3.28,2.83,2.63,2.53,2.48,2.44,2.46,2.45,2.45,2.46,2.49,2.50},
6894    {1.49,1.63,2.41,2.07,1.95,1.84,1.77,1.74,1.76,2.13,2.77,2.49,2.30,2.24,2.19,2.11,2.12,2.24,3.10,2.64,2.33,2.34,2.29,2.28,2.22,2.26,2.20,2.18,2.32,2.37,2.34,2.28,2.31,2.24,2.26,2.38,3.19,2.74,2.47,2.44,2.42,2.38,2.37,2.31,2.27,2.34,2.56,2.61,2.53,2.47,2.50,2.45,2.46,2.52,3.26,2.78,2.56,2.54,2.55,2.54,2.52,2.51,2.51,2.52,2.52,2.50,2.50,2.50,2.48,2.46,2.48,2.45,2.43,2.37,2.36,2.33,2.32,2.29,2.38,2.59,2.59,2.52,2.58,2.52,2.55,2.62,3.35,2.90,2.70,2.60,2.55,2.51,2.53,2.52,2.52,2.53,2.56,2.57},
6895    {1.71,1.85,2.63,2.29,2.17,2.06,1.99,1.96,1.98,2.35,2.99,2.71,2.52,2.46,2.41,2.33,2.34,2.46,3.32,2.86,2.55,2.56,2.51,2.50,2.44,2.48,2.42,2.40,2.54,2.59,2.56,2.50,2.53,2.46,2.48,2.60,3.41,2.96,2.69,2.66,2.64,2.60,2.59,2.53,2.49,2.56,2.78,2.83,2.75,2.69,2.72,2.67,2.68,2.74,3.48,3.00,2.78,2.76,2.77,2.76,2.74,2.73,2.73,2.74,2.74,2.72,2.72,2.72,2.70,2.68,2.70,2.67,2.65,2.59,2.58,2.55,2.54,2.51,2.60,2.81,2.81,2.74,2.80,2.74,2.77,2.84,3.57,3.12,2.92,2.82,2.77,2.73,2.75,2.74,2.74,2.75,2.78,2.79},
6896    {1.76,1.90,2.68,2.34,2.22,2.11,2.04,2.01,2.03,2.40,3.04,2.76,2.57,2.51,2.46,2.38,2.39,2.51,3.37,2.91,2.60,2.61,2.56,2.55,2.49,2.53,2.47,2.45,2.59,2.64,2.61,2.55,2.58,2.51,2.53,2.65,3.46,3.01,2.74,2.71,2.69,2.65,2.64,2.58,2.54,2.61,2.83,2.88,2.80,2.74,2.77,2.72,2.73,2.79,3.53,3.05,2.83,2.81,2.82,2.81,2.79,2.78,2.78,2.79,2.79,2.77,2.77,2.77,2.75,2.73,2.75,2.72,2.70,2.64,2.63,2.60,2.59,2.56,2.65,2.86,2.86,2.79,2.85,2.79,2.82,2.89,3.62,3.17,2.97,2.87,2.82,2.78,2.80,2.79,2.79,2.80,2.83,2.84},
6897    {1.68,1.82,2.60,2.26,2.14,2.03,1.96,1.93,1.95,2.32,2.96,2.68,2.49,2.43,2.38,2.30,2.31,2.43,3.29,2.83,2.52,2.53,2.48,2.47,2.41,2.45,2.39,2.37,2.51,2.56,2.53,2.47,2.50,2.43,2.45,2.57,3.38,2.93,2.66,2.63,2.61,2.57,2.56,2.50,2.46,2.53,2.75,2.80,2.72,2.66,2.69,2.64,2.65,2.71,3.45,2.97,2.75,2.73,2.74,2.73,2.71,2.70,2.70,2.71,2.71,2.69,2.69,2.69,2.67,2.65,2.67,2.64,2.62,2.56,2.55,2.52,2.51,2.48,2.57,2.78,2.78,2.71,2.77,2.71,2.74,2.81,3.54,3.09,2.89,2.79,2.74,2.70,2.72,2.71,2.71,2.72,2.75,2.76},
6898    {1.62,1.76,2.54,2.20,2.08,1.97,1.90,1.87,1.89,2.26,2.90,2.62,2.43,2.37,2.32,2.24,2.25,2.37,3.23,2.77,2.46,2.47,2.42,2.41,2.35,2.39,2.33,2.31,2.45,2.50,2.47,2.41,2.44,2.37,2.39,2.51,3.32,2.87,2.60,2.57,2.55,2.51,2.50,2.44,2.40,2.47,2.69,2.74,2.66,2.60,2.63,2.58,2.59,2.65,3.39,2.91,2.69,2.67,2.68,2.67,2.65,2.64,2.64,2.65,2.65,2.63,2.63,2.63,2.61,2.59,2.61,2.58,2.56,2.50,2.49,2.46,2.45,2.42,2.51,2.72,2.72,2.65,2.71,2.65,2.68,2.75,3.48,3.03,2.83,2.73,2.68,2.64,2.66,2.65,2.65,2.66,2.69,2.70},
6899    {1.65,1.79,2.57,2.23,2.11,2.00,1.93,1.90,1.92,2.29,2.93,2.65,2.46,2.40,2.35,2.27,2.28,2.40,3.26,2.80,2.49,2.50,2.45,2.44,2.38,2.42,2.36,2.34,2.48,2.53,2.50,2.44,2.47,2.40,2.42,2.54,3.35,2.90,2.63,2.60,2.58,2.54,2.53,2.47,2.43,2.50,2.72,2.77,2.69,2.63,2.66,2.61,2.62,2.68,3.42,2.94,2.72,2.70,2.71,2.70,2.68,2.67,2.67,2.68,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.61,2.59,2.53,2.52,2.49,2.48,2.45,2.54,2.75,2.75,2.68,2.74,2.68,2.71,2.78,3.51,3.06,2.86,2.76,2.71,2.67,2.69,2.68,2.68,2.69,2.72,2.73},
6900    {1.60,1.74,2.52,2.18,2.06,1.95,1.88,1.85,1.87,2.24,2.88,2.60,2.41,2.35,2.30,2.22,2.23,2.35,3.21,2.75,2.44,2.45,2.40,2.39,2.33,2.37,2.31,2.29,2.43,2.48,2.45,2.39,2.42,2.35,2.37,2.49,3.30,2.85,2.58,2.55,2.53,2.49,2.48,2.42,2.38,2.45,2.67,2.72,2.64,2.58,2.61,2.56,2.57,2.63,3.37,2.89,2.67,2.65,2.66,2.65,2.63,2.62,2.62,2.63,2.63,2.61,2.61,2.61,2.59,2.57,2.59,2.56,2.54,2.48,2.47,2.44,2.43,2.40,2.49,2.70,2.70,2.63,2.69,2.63,2.66,2.73,3.46,3.01,2.81,2.71,2.66,2.62,2.64,2.63,2.63,2.64,2.67,2.68},
6901    {1.61,1.75,2.53,2.19,2.07,1.96,1.89,1.86,1.88,2.25,2.89,2.61,2.42,2.36,2.31,2.23,2.24,2.36,3.22,2.76,2.45,2.46,2.41,2.40,2.34,2.38,2.32,2.30,2.44,2.49,2.46,2.40,2.43,2.36,2.38,2.50,3.31,2.86,2.59,2.56,2.54,2.50,2.49,2.43,2.39,2.46,2.68,2.73,2.65,2.59,2.62,2.57,2.58,2.64,3.38,2.90,2.68,2.66,2.67,2.66,2.64,2.63,2.63,2.64,2.64,2.62,2.62,2.62,2.60,2.58,2.60,2.57,2.55,2.49,2.48,2.45,2.44,2.41,2.50,2.71,2.71,2.64,2.70,2.64,2.67,2.74,3.47,3.02,2.82,2.72,2.67,2.63,2.65,2.64,2.64,2.65,2.68,2.69},
6902    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6903    {2.41,2.55,3.33,2.99,2.87,2.76,2.69,2.66,2.68,3.05,3.69,3.41,3.22,3.16,3.11,3.03,3.04,3.16,4.02,3.56,3.25,3.26,3.21,3.20,3.14,3.18,3.12,3.10,3.24,3.29,3.26,3.20,3.23,3.16,3.18,3.30,4.11,3.66,3.39,3.36,3.34,3.30,3.29,3.23,3.19,3.26,3.48,3.53,3.45,3.39,3.42,3.37,3.38,3.44,4.18,3.70,3.48,3.46,3.47,3.46,3.44,3.43,3.43,3.44,3.44,3.42,3.42,3.42,3.40,3.38,3.40,3.37,3.35,3.29,3.28,3.25,3.24,3.21,3.30,3.51,3.51,3.44,3.50,3.44,3.47,3.54,4.27,3.82,3.62,3.52,3.47,3.43,3.45,3.44,3.44,3.45,3.48,3.49},
6904    {1.93,2.07,2.85,2.51,2.39,2.28,2.21,2.18,2.20,2.57,3.21,2.93,2.74,2.68,2.63,2.55,2.56,2.68,3.54,3.08,2.77,2.78,2.73,2.72,2.66,2.70,2.64,2.62,2.76,2.81,2.78,2.72,2.75,2.68,2.70,2.82,3.63,3.18,2.91,2.88,2.86,2.82,2.81,2.75,2.71,2.78,3.00,3.05,2.97,2.91,2.94,2.89,2.90,2.96,3.70,3.22,3.00,2.98,2.99,2.98,2.96,2.95,2.95,2.96,2.96,2.94,2.94,2.94,2.92,2.90,2.92,2.89,2.87,2.81,2.80,2.77,2.76,2.73,2.82,3.03,3.03,2.96,3.02,2.96,2.99,3.06,3.79,3.34,3.14,3.04,2.99,2.95,2.97,2.96,2.96,2.97,3.00,3.01},
6905    {1.71,1.85,2.63,2.29,2.17,2.06,1.99,1.96,1.98,2.35,2.99,2.71,2.52,2.46,2.41,2.33,2.34,2.46,3.32,2.86,2.55,2.56,2.51,2.50,2.44,2.48,2.42,2.40,2.54,2.59,2.56,2.50,2.53,2.46,2.48,2.60,3.41,2.96,2.69,2.66,2.64,2.60,2.59,2.53,2.49,2.56,2.78,2.83,2.75,2.69,2.72,2.67,2.68,2.74,3.48,3.00,2.78,2.76,2.77,2.76,2.74,2.73,2.73,2.74,2.74,2.72,2.72,2.72,2.70,2.68,2.70,2.67,2.65,2.59,2.58,2.55,2.54,2.51,2.60,2.81,2.81,2.74,2.80,2.74,2.77,2.84,3.57,3.12,2.92,2.82,2.77,2.73,2.75,2.74,2.74,2.75,2.78,2.79},
6906    {1.69,1.83,2.61,2.27,2.15,2.04,1.97,1.94,1.96,2.33,2.97,2.69,2.50,2.44,2.39,2.31,2.32,2.44,3.30,2.84,2.53,2.54,2.49,2.48,2.42,2.46,2.40,2.38,2.52,2.57,2.54,2.48,2.51,2.44,2.46,2.58,3.39,2.94,2.67,2.64,2.62,2.58,2.57,2.51,2.47,2.54,2.76,2.81,2.73,2.67,2.70,2.65,2.66,2.72,3.46,2.98,2.76,2.74,2.75,2.74,2.72,2.71,2.71,2.72,2.72,2.70,2.70,2.70,2.68,2.66,2.68,2.65,2.63,2.57,2.56,2.53,2.52,2.49,2.58,2.79,2.79,2.72,2.78,2.72,2.75,2.82,3.55,3.10,2.90,2.80,2.75,2.71,2.73,2.72,2.72,2.73,2.76,2.77},
6907    {1.70,1.84,2.62,2.28,2.16,2.05,1.98,1.95,1.97,2.34,2.98,2.70,2.51,2.45,2.40,2.32,2.33,2.45,3.31,2.85,2.54,2.55,2.50,2.49,2.43,2.47,2.41,2.39,2.53,2.58,2.55,2.49,2.52,2.45,2.47,2.59,3.40,2.95,2.68,2.65,2.63,2.59,2.58,2.52,2.48,2.55,2.77,2.82,2.74,2.68,2.71,2.66,2.67,2.73,3.47,2.99,2.77,2.75,2.76,2.75,2.73,2.72,2.72,2.73,2.73,2.71,2.71,2.71,2.69,2.67,2.69,2.66,2.64,2.58,2.57,2.54,2.53,2.50,2.59,2.80,2.80,2.73,2.79,2.73,2.76,2.83,3.56,3.11,2.91,2.81,2.76,2.72,2.74,2.73,2.73,2.74,2.77,2.78},
6908    {1.69,1.83,2.61,2.27,2.15,2.04,1.97,1.94,1.96,2.33,2.97,2.69,2.50,2.44,2.39,2.31,2.32,2.44,3.30,2.84,2.53,2.54,2.49,2.48,2.42,2.46,2.40,2.38,2.52,2.57,2.54,2.48,2.51,2.44,2.46,2.58,3.39,2.94,2.67,2.64,2.62,2.58,2.57,2.51,2.47,2.54,2.76,2.81,2.73,2.67,2.70,2.65,2.66,2.72,3.46,2.98,2.76,2.74,2.75,2.74,2.72,2.71,2.71,2.72,2.72,2.70,2.70,2.70,2.68,2.66,2.68,2.65,2.63,2.57,2.56,2.53,2.52,2.49,2.58,2.79,2.79,2.72,2.78,2.72,2.75,2.82,3.55,3.10,2.90,2.80,2.75,2.71,2.73,2.72,2.72,2.73,2.76,2.77},
6909    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6910    {1.66,1.80,2.58,2.24,2.12,2.01,1.94,1.91,1.93,2.30,2.94,2.66,2.47,2.41,2.36,2.28,2.29,2.41,3.27,2.81,2.50,2.51,2.46,2.45,2.39,2.43,2.37,2.35,2.49,2.54,2.51,2.45,2.48,2.41,2.43,2.55,3.36,2.91,2.64,2.61,2.59,2.55,2.54,2.48,2.44,2.51,2.73,2.78,2.70,2.64,2.67,2.62,2.63,2.69,3.43,2.95,2.73,2.71,2.72,2.71,2.69,2.68,2.68,2.69,2.69,2.67,2.67,2.67,2.65,2.63,2.65,2.62,2.60,2.54,2.53,2.50,2.49,2.46,2.55,2.76,2.76,2.69,2.75,2.69,2.72,2.79,3.52,3.07,2.87,2.77,2.72,2.68,2.70,2.69,2.69,2.70,2.73,2.74},
6911    {1.66,1.80,2.58,2.24,2.12,2.01,1.94,1.91,1.93,2.30,2.94,2.66,2.47,2.41,2.36,2.28,2.29,2.41,3.27,2.81,2.50,2.51,2.46,2.45,2.39,2.43,2.37,2.35,2.49,2.54,2.51,2.45,2.48,2.41,2.43,2.55,3.36,2.91,2.64,2.61,2.59,2.55,2.54,2.48,2.44,2.51,2.73,2.78,2.70,2.64,2.67,2.62,2.63,2.69,3.43,2.95,2.73,2.71,2.72,2.71,2.69,2.68,2.68,2.69,2.69,2.67,2.67,2.67,2.65,2.63,2.65,2.62,2.60,2.54,2.53,2.50,2.49,2.46,2.55,2.76,2.76,2.69,2.75,2.69,2.72,2.79,3.52,3.07,2.87,2.77,2.72,2.68,2.70,2.69,2.69,2.70,2.73,2.74},
6912    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6913    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6914    {1.65,1.79,2.57,2.23,2.11,2.00,1.93,1.90,1.92,2.29,2.93,2.65,2.46,2.40,2.35,2.27,2.28,2.40,3.26,2.80,2.49,2.50,2.45,2.44,2.38,2.42,2.36,2.34,2.48,2.53,2.50,2.44,2.47,2.40,2.42,2.54,3.35,2.90,2.63,2.60,2.58,2.54,2.53,2.47,2.43,2.50,2.72,2.77,2.69,2.63,2.66,2.61,2.62,2.68,3.42,2.94,2.72,2.70,2.71,2.70,2.68,2.67,2.67,2.68,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.61,2.59,2.53,2.52,2.49,2.48,2.45,2.54,2.75,2.75,2.68,2.74,2.68,2.71,2.78,3.51,3.06,2.86,2.76,2.71,2.67,2.69,2.68,2.68,2.69,2.72,2.73},
6915    {1.65,1.79,2.57,2.23,2.11,2.00,1.93,1.90,1.92,2.29,2.93,2.65,2.46,2.40,2.35,2.27,2.28,2.40,3.26,2.80,2.49,2.50,2.45,2.44,2.38,2.42,2.36,2.34,2.48,2.53,2.50,2.44,2.47,2.40,2.42,2.54,3.35,2.90,2.63,2.60,2.58,2.54,2.53,2.47,2.43,2.50,2.72,2.77,2.69,2.63,2.66,2.61,2.62,2.68,3.42,2.94,2.72,2.70,2.71,2.70,2.68,2.67,2.67,2.68,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.61,2.59,2.53,2.52,2.49,2.48,2.45,2.54,2.75,2.75,2.68,2.74,2.68,2.71,2.78,3.51,3.06,2.86,2.76,2.71,2.67,2.69,2.68,2.68,2.69,2.72,2.73},
6916    {1.65,1.79,2.57,2.23,2.11,2.00,1.93,1.90,1.92,2.29,2.93,2.65,2.46,2.40,2.35,2.27,2.28,2.40,3.26,2.80,2.49,2.50,2.45,2.44,2.38,2.42,2.36,2.34,2.48,2.53,2.50,2.44,2.47,2.40,2.42,2.54,3.35,2.90,2.63,2.60,2.58,2.54,2.53,2.47,2.43,2.50,2.72,2.77,2.69,2.63,2.66,2.61,2.62,2.68,3.42,2.94,2.72,2.70,2.71,2.70,2.68,2.67,2.67,2.68,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.61,2.59,2.53,2.52,2.49,2.48,2.45,2.54,2.75,2.75,2.68,2.74,2.68,2.71,2.78,3.51,3.06,2.86,2.76,2.71,2.67,2.69,2.68,2.68,2.69,2.72,2.73},
6917    {1.63,1.77,2.55,2.21,2.09,1.98,1.91,1.88,1.90,2.27,2.91,2.63,2.44,2.38,2.33,2.25,2.26,2.38,3.24,2.78,2.47,2.48,2.43,2.42,2.36,2.40,2.34,2.32,2.46,2.51,2.48,2.42,2.45,2.38,2.40,2.52,3.33,2.88,2.61,2.58,2.56,2.52,2.51,2.45,2.41,2.48,2.70,2.75,2.67,2.61,2.64,2.59,2.60,2.66,3.40,2.92,2.70,2.68,2.69,2.68,2.66,2.65,2.65,2.66,2.66,2.64,2.64,2.64,2.62,2.60,2.62,2.59,2.57,2.51,2.50,2.47,2.46,2.43,2.52,2.73,2.73,2.66,2.72,2.66,2.69,2.76,3.49,3.04,2.84,2.74,2.69,2.65,2.67,2.66,2.66,2.67,2.70,2.71},
6918    {1.61,1.75,2.53,2.19,2.07,1.96,1.89,1.86,1.88,2.25,2.89,2.61,2.42,2.36,2.31,2.23,2.24,2.36,3.22,2.76,2.45,2.46,2.41,2.40,2.34,2.38,2.32,2.30,2.44,2.49,2.46,2.40,2.43,2.36,2.38,2.50,3.31,2.86,2.59,2.56,2.54,2.50,2.49,2.43,2.39,2.46,2.68,2.73,2.65,2.59,2.62,2.57,2.58,2.64,3.38,2.90,2.68,2.66,2.67,2.66,2.64,2.63,2.63,2.64,2.64,2.62,2.62,2.62,2.60,2.58,2.60,2.57,2.55,2.49,2.48,2.45,2.44,2.41,2.50,2.71,2.71,2.64,2.70,2.64,2.67,2.74,3.47,3.02,2.82,2.72,2.67,2.63,2.65,2.64,2.64,2.65,2.68,2.69},
6919    {1.63,1.77,2.55,2.21,2.09,1.98,1.91,1.88,1.90,2.27,2.91,2.63,2.44,2.38,2.33,2.25,2.26,2.38,3.24,2.78,2.47,2.48,2.43,2.42,2.36,2.40,2.34,2.32,2.46,2.51,2.48,2.42,2.45,2.38,2.40,2.52,3.33,2.88,2.61,2.58,2.56,2.52,2.51,2.45,2.41,2.48,2.70,2.75,2.67,2.61,2.64,2.59,2.60,2.66,3.40,2.92,2.70,2.68,2.69,2.68,2.66,2.65,2.65,2.66,2.66,2.64,2.64,2.64,2.62,2.60,2.62,2.59,2.57,2.51,2.50,2.47,2.46,2.43,2.52,2.73,2.73,2.66,2.72,2.66,2.69,2.76,3.49,3.04,2.84,2.74,2.69,2.65,2.67,2.66,2.66,2.67,2.70,2.71},
6920    {1.60,1.74,2.52,2.18,2.06,1.95,1.88,1.85,1.87,2.24,2.88,2.60,2.41,2.35,2.30,2.22,2.23,2.35,3.21,2.75,2.44,2.45,2.40,2.39,2.33,2.37,2.31,2.29,2.43,2.48,2.45,2.39,2.42,2.35,2.37,2.49,3.30,2.85,2.58,2.55,2.53,2.49,2.48,2.42,2.38,2.45,2.67,2.72,2.64,2.58,2.61,2.56,2.57,2.63,3.37,2.89,2.67,2.65,2.66,2.65,2.63,2.62,2.62,2.63,2.63,2.61,2.61,2.61,2.59,2.57,2.59,2.56,2.54,2.48,2.47,2.44,2.43,2.40,2.49,2.70,2.70,2.63,2.69,2.63,2.66,2.73,3.46,3.01,2.81,2.71,2.66,2.62,2.64,2.63,2.63,2.64,2.67,2.68},
6921    {1.58,1.72,2.50,2.16,2.04,1.93,1.86,1.83,1.85,2.22,2.86,2.58,2.39,2.33,2.28,2.20,2.21,2.33,3.19,2.73,2.42,2.43,2.38,2.37,2.31,2.35,2.29,2.27,2.41,2.46,2.43,2.37,2.40,2.33,2.35,2.47,3.28,2.83,2.56,2.53,2.51,2.47,2.46,2.40,2.36,2.43,2.65,2.70,2.62,2.56,2.59,2.54,2.55,2.61,3.35,2.87,2.65,2.63,2.64,2.63,2.61,2.60,2.60,2.61,2.61,2.59,2.59,2.59,2.57,2.55,2.57,2.54,2.52,2.46,2.45,2.42,2.41,2.38,2.47,2.68,2.68,2.61,2.67,2.61,2.64,2.71,3.44,2.99,2.79,2.69,2.64,2.60,2.62,2.61,2.61,2.62,2.65,2.66},
6922    {1.52,1.66,2.44,2.10,1.98,1.87,1.80,1.77,1.79,2.16,2.80,2.52,2.33,2.27,2.22,2.14,2.15,2.27,3.13,2.67,2.36,2.37,2.32,2.31,2.25,2.29,2.23,2.21,2.35,2.40,2.37,2.31,2.34,2.27,2.29,2.41,3.22,2.77,2.50,2.47,2.45,2.41,2.40,2.34,2.30,2.37,2.59,2.64,2.56,2.50,2.53,2.48,2.49,2.55,3.29,2.81,2.59,2.57,2.58,2.57,2.55,2.54,2.54,2.55,2.55,2.53,2.53,2.53,2.51,2.49,2.51,2.48,2.46,2.40,2.39,2.36,2.35,2.32,2.41,2.62,2.62,2.55,2.61,2.55,2.58,2.65,3.38,2.93,2.73,2.63,2.58,2.54,2.56,2.55,2.55,2.56,2.59,2.60},
6923    {1.51,1.65,2.43,2.09,1.97,1.86,1.79,1.76,1.78,2.15,2.79,2.51,2.32,2.26,2.21,2.13,2.14,2.26,3.12,2.66,2.35,2.36,2.31,2.30,2.24,2.28,2.22,2.20,2.34,2.39,2.36,2.30,2.33,2.26,2.28,2.40,3.21,2.76,2.49,2.46,2.44,2.40,2.39,2.33,2.29,2.36,2.58,2.63,2.55,2.49,2.52,2.47,2.48,2.54,3.28,2.80,2.58,2.56,2.57,2.56,2.54,2.53,2.53,2.54,2.54,2.52,2.52,2.52,2.50,2.48,2.50,2.47,2.45,2.39,2.38,2.35,2.34,2.31,2.40,2.61,2.61,2.54,2.60,2.54,2.57,2.64,3.37,2.92,2.72,2.62,2.57,2.53,2.55,2.54,2.54,2.55,2.58,2.59},
6924    {1.48,1.62,2.40,2.06,1.94,1.83,1.76,1.73,1.75,2.12,2.76,2.48,2.29,2.23,2.18,2.10,2.11,2.23,3.09,2.63,2.32,2.33,2.28,2.27,2.21,2.25,2.19,2.17,2.31,2.36,2.33,2.27,2.30,2.23,2.25,2.37,3.18,2.73,2.46,2.43,2.41,2.37,2.36,2.30,2.26,2.33,2.55,2.60,2.52,2.46,2.49,2.44,2.45,2.51,3.25,2.77,2.55,2.53,2.54,2.53,2.51,2.50,2.50,2.51,2.51,2.49,2.49,2.49,2.47,2.45,2.47,2.44,2.42,2.36,2.35,2.32,2.31,2.28,2.37,2.58,2.58,2.51,2.57,2.51,2.54,2.61,3.34,2.89,2.69,2.59,2.54,2.50,2.52,2.51,2.51,2.52,2.55,2.56},
6925    {1.47,1.61,2.39,2.05,1.93,1.82,1.75,1.72,1.74,2.11,2.75,2.47,2.28,2.22,2.17,2.09,2.10,2.22,3.08,2.62,2.31,2.32,2.27,2.26,2.20,2.24,2.18,2.16,2.30,2.35,2.32,2.26,2.29,2.22,2.24,2.36,3.17,2.72,2.45,2.42,2.40,2.36,2.35,2.29,2.25,2.32,2.54,2.59,2.51,2.45,2.48,2.43,2.44,2.50,3.24,2.76,2.54,2.52,2.53,2.52,2.50,2.49,2.49,2.50,2.50,2.48,2.48,2.48,2.46,2.44,2.46,2.43,2.41,2.35,2.34,2.31,2.30,2.27,2.36,2.57,2.57,2.50,2.56,2.50,2.53,2.60,3.33,2.88,2.68,2.58,2.53,2.49,2.51,2.50,2.50,2.51,2.54,2.55},
6926    {1.44,1.58,2.36,2.02,1.90,1.79,1.72,1.69,1.71,2.08,2.72,2.44,2.25,2.19,2.14,2.06,2.07,2.19,3.05,2.59,2.28,2.29,2.24,2.23,2.17,2.21,2.15,2.13,2.27,2.32,2.29,2.23,2.26,2.19,2.21,2.33,3.14,2.69,2.42,2.39,2.37,2.33,2.32,2.26,2.22,2.29,2.51,2.56,2.48,2.42,2.45,2.40,2.41,2.47,3.21,2.73,2.51,2.49,2.50,2.49,2.47,2.46,2.46,2.47,2.47,2.45,2.45,2.45,2.43,2.41,2.43,2.40,2.38,2.32,2.31,2.28,2.27,2.24,2.33,2.54,2.54,2.47,2.53,2.47,2.50,2.57,3.30,2.85,2.65,2.55,2.50,2.46,2.48,2.47,2.47,2.48,2.51,2.52},
6927    {1.53,1.67,2.45,2.11,1.99,1.88,1.81,1.78,1.80,2.17,2.81,2.53,2.34,2.28,2.23,2.15,2.16,2.28,3.14,2.68,2.37,2.38,2.33,2.32,2.26,2.30,2.24,2.22,2.36,2.41,2.38,2.32,2.35,2.28,2.30,2.42,3.23,2.78,2.51,2.48,2.46,2.42,2.41,2.35,2.31,2.38,2.60,2.65,2.57,2.51,2.54,2.49,2.50,2.56,3.30,2.82,2.60,2.58,2.59,2.58,2.56,2.55,2.55,2.56,2.56,2.54,2.54,2.54,2.52,2.50,2.52,2.49,2.47,2.41,2.40,2.37,2.36,2.33,2.42,2.63,2.63,2.56,2.62,2.56,2.59,2.66,3.39,2.94,2.74,2.64,2.59,2.55,2.57,2.56,2.56,2.57,2.60,2.61},
6928    {1.74,1.88,2.66,2.32,2.20,2.09,2.02,1.99,2.01,2.38,3.02,2.74,2.55,2.49,2.44,2.36,2.37,2.49,3.35,2.89,2.58,2.59,2.54,2.53,2.47,2.51,2.45,2.43,2.57,2.62,2.59,2.53,2.56,2.49,2.51,2.63,3.44,2.99,2.72,2.69,2.67,2.63,2.62,2.56,2.52,2.59,2.81,2.86,2.78,2.72,2.75,2.70,2.71,2.77,3.51,3.03,2.81,2.79,2.80,2.79,2.77,2.76,2.76,2.77,2.77,2.75,2.75,2.75,2.73,2.71,2.73,2.70,2.68,2.62,2.61,2.58,2.57,2.54,2.63,2.84,2.84,2.77,2.83,2.77,2.80,2.87,3.60,3.15,2.95,2.85,2.80,2.76,2.78,2.77,2.77,2.78,2.81,2.82},
6929    {1.74,1.88,2.66,2.32,2.20,2.09,2.02,1.99,2.01,2.38,3.02,2.74,2.55,2.49,2.44,2.36,2.37,2.49,3.35,2.89,2.58,2.59,2.54,2.53,2.47,2.51,2.45,2.43,2.57,2.62,2.59,2.53,2.56,2.49,2.51,2.63,3.44,2.99,2.72,2.69,2.67,2.63,2.62,2.56,2.52,2.59,2.81,2.86,2.78,2.72,2.75,2.70,2.71,2.77,3.51,3.03,2.81,2.79,2.80,2.79,2.77,2.76,2.76,2.77,2.77,2.75,2.75,2.75,2.73,2.71,2.73,2.70,2.68,2.62,2.61,2.58,2.57,2.54,2.63,2.84,2.84,2.77,2.83,2.77,2.80,2.87,3.60,3.15,2.95,2.85,2.80,2.76,2.78,2.77,2.77,2.78,2.81,2.82},
6930    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6931    {1.73,1.87,2.65,2.31,2.19,2.08,2.01,1.98,2.00,2.37,3.01,2.73,2.54,2.48,2.43,2.35,2.36,2.48,3.34,2.88,2.57,2.58,2.53,2.52,2.46,2.50,2.44,2.42,2.56,2.61,2.58,2.52,2.55,2.48,2.50,2.62,3.43,2.98,2.71,2.68,2.66,2.62,2.61,2.55,2.51,2.58,2.80,2.85,2.77,2.71,2.74,2.69,2.70,2.76,3.50,3.02,2.80,2.78,2.79,2.78,2.76,2.75,2.75,2.76,2.76,2.74,2.74,2.74,2.72,2.70,2.72,2.69,2.67,2.61,2.60,2.57,2.56,2.53,2.62,2.83,2.83,2.76,2.82,2.76,2.79,2.86,3.59,3.14,2.94,2.84,2.79,2.75,2.77,2.76,2.76,2.77,2.80,2.81},
6932    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6933    {1.70,1.84,2.62,2.28,2.16,2.05,1.98,1.95,1.97,2.34,2.98,2.70,2.51,2.45,2.40,2.32,2.33,2.45,3.31,2.85,2.54,2.55,2.50,2.49,2.43,2.47,2.41,2.39,2.53,2.58,2.55,2.49,2.52,2.45,2.47,2.59,3.40,2.95,2.68,2.65,2.63,2.59,2.58,2.52,2.48,2.55,2.77,2.82,2.74,2.68,2.71,2.66,2.67,2.73,3.47,2.99,2.77,2.75,2.76,2.75,2.73,2.72,2.72,2.73,2.73,2.71,2.71,2.71,2.69,2.67,2.69,2.66,2.64,2.58,2.57,2.54,2.53,2.50,2.59,2.80,2.80,2.73,2.79,2.73,2.76,2.83,3.56,3.11,2.91,2.81,2.76,2.72,2.74,2.73,2.73,2.74,2.77,2.78},
6934    {1.77,1.91,2.69,2.35,2.23,2.12,2.05,2.02,2.04,2.41,3.05,2.77,2.58,2.52,2.47,2.39,2.40,2.52,3.38,2.92,2.61,2.62,2.57,2.56,2.50,2.54,2.48,2.46,2.60,2.65,2.62,2.56,2.59,2.52,2.54,2.66,3.47,3.02,2.75,2.72,2.70,2.66,2.65,2.59,2.55,2.62,2.84,2.89,2.81,2.75,2.78,2.73,2.74,2.80,3.54,3.06,2.84,2.82,2.83,2.82,2.80,2.79,2.79,2.80,2.80,2.78,2.78,2.78,2.76,2.74,2.76,2.73,2.71,2.65,2.64,2.61,2.60,2.57,2.66,2.87,2.87,2.80,2.86,2.80,2.83,2.90,3.63,3.18,2.98,2.88,2.83,2.79,2.81,2.80,2.80,2.81,2.84,2.85},
6935    {2.50,2.64,3.42,3.08,2.96,2.85,2.78,2.75,2.77,3.14,3.78,3.50,3.31,3.25,3.20,3.12,3.13,3.25,4.11,3.65,3.34,3.35,3.30,3.29,3.23,3.27,3.21,3.19,3.33,3.38,3.35,3.29,3.32,3.25,3.27,3.39,4.20,3.75,3.48,3.45,3.43,3.39,3.38,3.32,3.28,3.35,3.57,3.62,3.54,3.48,3.51,3.46,3.47,3.53,4.27,3.79,3.57,3.55,3.56,3.55,3.53,3.52,3.52,3.53,3.53,3.51,3.51,3.51,3.49,3.47,3.49,3.46,3.44,3.38,3.37,3.34,3.33,3.30,3.39,3.60,3.60,3.53,3.59,3.53,3.56,3.63,4.36,3.91,3.71,3.61,3.56,3.52,3.54,3.53,3.53,3.54,3.57,3.58},
6936    {2.05,2.19,2.97,2.63,2.51,2.40,2.33,2.30,2.32,2.69,3.33,3.05,2.86,2.80,2.75,2.67,2.68,2.80,3.66,3.20,2.89,2.90,2.85,2.84,2.78,2.82,2.76,2.74,2.88,2.93,2.90,2.84,2.87,2.80,2.82,2.94,3.75,3.30,3.03,3.00,2.98,2.94,2.93,2.87,2.83,2.90,3.12,3.17,3.09,3.03,3.06,3.01,3.02,3.08,3.82,3.34,3.12,3.10,3.11,3.10,3.08,3.07,3.07,3.08,3.08,3.06,3.06,3.06,3.04,3.02,3.04,3.01,2.99,2.93,2.92,2.89,2.88,2.85,2.94,3.15,3.15,3.08,3.14,3.08,3.11,3.18,3.91,3.46,3.26,3.16,3.11,3.07,3.09,3.08,3.08,3.09,3.12,3.13},
6937    {1.85,1.99,2.77,2.43,2.31,2.20,2.13,2.10,2.12,2.49,3.13,2.85,2.66,2.60,2.55,2.47,2.48,2.60,3.46,3.00,2.69,2.70,2.65,2.64,2.58,2.62,2.56,2.54,2.68,2.73,2.70,2.64,2.67,2.60,2.62,2.74,3.55,3.10,2.83,2.80,2.78,2.74,2.73,2.67,2.63,2.70,2.92,2.97,2.89,2.83,2.86,2.81,2.82,2.88,3.62,3.14,2.92,2.90,2.91,2.90,2.88,2.87,2.87,2.88,2.88,2.86,2.86,2.86,2.84,2.82,2.84,2.81,2.79,2.73,2.72,2.69,2.68,2.65,2.74,2.95,2.95,2.88,2.94,2.88,2.91,2.98,3.71,3.26,3.06,2.96,2.91,2.87,2.89,2.88,2.88,2.89,2.92,2.93},
6938    {1.75,1.89,2.67,2.33,2.21,2.10,2.03,2.00,2.02,2.39,3.03,2.75,2.56,2.50,2.45,2.37,2.38,2.50,3.36,2.90,2.59,2.60,2.55,2.54,2.48,2.52,2.46,2.44,2.58,2.63,2.60,2.54,2.57,2.50,2.52,2.64,3.45,3.00,2.73,2.70,2.68,2.64,2.63,2.57,2.53,2.60,2.82,2.87,2.79,2.73,2.76,2.71,2.72,2.78,3.52,3.04,2.82,2.80,2.81,2.80,2.78,2.77,2.77,2.78,2.78,2.76,2.76,2.76,2.74,2.72,2.74,2.71,2.69,2.63,2.62,2.59,2.58,2.55,2.64,2.85,2.85,2.78,2.84,2.78,2.81,2.88,3.61,3.16,2.96,2.86,2.81,2.77,2.79,2.78,2.78,2.79,2.82,2.83},
6939    {1.70,1.84,2.62,2.28,2.16,2.05,1.98,1.95,1.97,2.34,2.98,2.70,2.51,2.45,2.40,2.32,2.33,2.45,3.31,2.85,2.54,2.55,2.50,2.49,2.43,2.47,2.41,2.39,2.53,2.58,2.55,2.49,2.52,2.45,2.47,2.59,3.40,2.95,2.68,2.65,2.63,2.59,2.58,2.52,2.48,2.55,2.77,2.82,2.74,2.68,2.71,2.66,2.67,2.73,3.47,2.99,2.77,2.75,2.76,2.75,2.73,2.72,2.72,2.73,2.73,2.71,2.71,2.71,2.69,2.67,2.69,2.66,2.64,2.58,2.57,2.54,2.53,2.50,2.59,2.80,2.80,2.73,2.79,2.73,2.76,2.83,3.56,3.11,2.91,2.81,2.76,2.72,2.74,2.73,2.73,2.74,2.77,2.78},
6940    {1.66,1.80,2.58,2.24,2.12,2.01,1.94,1.91,1.93,2.30,2.94,2.66,2.47,2.41,2.36,2.28,2.29,2.41,3.27,2.81,2.50,2.51,2.46,2.45,2.39,2.43,2.37,2.35,2.49,2.54,2.51,2.45,2.48,2.41,2.43,2.55,3.36,2.91,2.64,2.61,2.59,2.55,2.54,2.48,2.44,2.51,2.73,2.78,2.70,2.64,2.67,2.62,2.63,2.69,3.43,2.95,2.73,2.71,2.72,2.71,2.69,2.68,2.68,2.69,2.69,2.67,2.67,2.67,2.65,2.63,2.65,2.62,2.60,2.54,2.53,2.50,2.49,2.46,2.55,2.76,2.76,2.69,2.75,2.69,2.72,2.79,3.52,3.07,2.87,2.77,2.72,2.68,2.70,2.69,2.69,2.70,2.73,2.74},
6941    {1.68,1.82,2.60,2.26,2.14,2.03,1.96,1.93,1.95,2.32,2.96,2.68,2.49,2.43,2.38,2.30,2.31,2.43,3.29,2.83,2.52,2.53,2.48,2.47,2.41,2.45,2.39,2.37,2.51,2.56,2.53,2.47,2.50,2.43,2.45,2.57,3.38,2.93,2.66,2.63,2.61,2.57,2.56,2.50,2.46,2.53,2.75,2.80,2.72,2.66,2.69,2.64,2.65,2.71,3.45,2.97,2.75,2.73,2.74,2.73,2.71,2.70,2.70,2.71,2.71,2.69,2.69,2.69,2.67,2.65,2.67,2.64,2.62,2.56,2.55,2.52,2.51,2.48,2.57,2.78,2.78,2.71,2.77,2.71,2.74,2.81,3.54,3.09,2.89,2.79,2.74,2.70,2.72,2.71,2.71,2.72,2.75,2.76},
6942    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6943    {1.67,1.81,2.59,2.25,2.13,2.02,1.95,1.92,1.94,2.31,2.95,2.67,2.48,2.42,2.37,2.29,2.30,2.42,3.28,2.82,2.51,2.52,2.47,2.46,2.40,2.44,2.38,2.36,2.50,2.55,2.52,2.46,2.49,2.42,2.44,2.56,3.37,2.92,2.65,2.62,2.60,2.56,2.55,2.49,2.45,2.52,2.74,2.79,2.71,2.65,2.68,2.63,2.64,2.70,3.44,2.96,2.74,2.72,2.73,2.72,2.70,2.69,2.69,2.70,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.63,2.61,2.55,2.54,2.51,2.50,2.47,2.56,2.77,2.77,2.70,2.76,2.70,2.73,2.80,3.53,3.08,2.88,2.78,2.73,2.69,2.71,2.70,2.70,2.71,2.74,2.75},
6944    {1.68,1.82,2.60,2.26,2.14,2.03,1.96,1.93,1.95,2.32,2.96,2.68,2.49,2.43,2.38,2.30,2.31,2.43,3.29,2.83,2.52,2.53,2.48,2.47,2.41,2.45,2.39,2.37,2.51,2.56,2.53,2.47,2.50,2.43,2.45,2.57,3.38,2.93,2.66,2.63,2.61,2.57,2.56,2.50,2.46,2.53,2.75,2.80,2.72,2.66,2.69,2.64,2.65,2.71,3.45,2.97,2.75,2.73,2.74,2.73,2.71,2.70,2.70,2.71,2.71,2.69,2.69,2.69,2.67,2.65,2.67,2.64,2.62,2.56,2.55,2.52,2.51,2.48,2.57,2.78,2.78,2.71,2.77,2.71,2.74,2.81,3.54,3.09,2.89,2.79,2.74,2.70,2.72,2.71,2.71,2.72,2.75,2.76},
6945    {1.71,1.85,2.63,2.29,2.17,2.06,1.99,1.96,1.98,2.35,2.99,2.71,2.52,2.46,2.41,2.33,2.34,2.46,3.32,2.86,2.55,2.56,2.51,2.50,2.44,2.48,2.42,2.40,2.54,2.59,2.56,2.50,2.53,2.46,2.48,2.60,3.41,2.96,2.69,2.66,2.64,2.60,2.59,2.53,2.49,2.56,2.78,2.83,2.75,2.69,2.72,2.67,2.68,2.74,3.48,3.00,2.78,2.76,2.77,2.76,2.74,2.73,2.73,2.74,2.74,2.72,2.72,2.72,2.70,2.68,2.70,2.67,2.65,2.59,2.58,2.55,2.54,2.51,2.60,2.81,2.81,2.74,2.80,2.74,2.77,2.84,3.57,3.12,2.92,2.82,2.77,2.73,2.75,2.74,2.74,2.75,2.78,2.79},
6946    {1.72,1.86,2.64,2.30,2.18,2.07,2.00,1.97,1.99,2.36,3.00,2.72,2.53,2.47,2.42,2.34,2.35,2.47,3.33,2.87,2.56,2.57,2.52,2.51,2.45,2.49,2.43,2.41,2.55,2.60,2.57,2.51,2.54,2.47,2.49,2.61,3.42,2.97,2.70,2.67,2.65,2.61,2.60,2.54,2.50,2.57,2.79,2.84,2.76,2.70,2.73,2.68,2.69,2.75,3.49,3.01,2.79,2.77,2.78,2.77,2.75,2.74,2.74,2.75,2.75,2.73,2.73,2.73,2.71,2.69,2.71,2.68,2.66,2.60,2.59,2.56,2.55,2.52,2.61,2.82,2.82,2.75,2.81,2.75,2.78,2.85,3.58,3.13,2.93,2.83,2.78,2.74,2.76,2.75,2.75,2.76,2.79,2.80}
6947 };
6948 
6949 static float TripleDis[NUMDIS][NUMDIS] = {
6950    {0.64,0.78,1.56,1.17,1.05,0.92,0.86,0.85,0.85,1.28,1.92,1.59,1.43,1.34,1.26,1.27,1.25,1.28,2.25,1.65,1.46,1.40,1.38,1.35,1.35,1.34,1.28,1.33,1.52,1.52,1.53,1.46,1.38,1.39,1.42,1.40,2.34,1.71,1.56,1.53,1.48,1.45,1.42,1.35,1.38,1.44,1.69,1.76,1.78,1.64,1.59,1.53,1.57,1.54,2.41,1.81,1.71,1.63,1.60,1.69,1.67,1.66,1.66,1.64,1.67,1.65,1.65,1.65,1.63,1.61,1.63,1.54,1.51,1.47,1.42,1.41,1.39,1.42,1.55,1.74,1.82,1.69,1.67,1.61,1.70,1.65,2.50,1.91,1.72,1.68,1.61,1.50,1.48,1.67,1.67,1.68,1.71,1.72},
6951    {0.78,0.92,1.70,1.31,1.19,1.06,1.00,0.99,0.99,1.42,2.06,1.73,1.57,1.48,1.40,1.41,1.39,1.42,2.39,1.79,1.60,1.54,1.52,1.49,1.49,1.48,1.42,1.47,1.66,1.66,1.67,1.60,1.52,1.53,1.56,1.54,2.48,1.85,1.70,1.67,1.62,1.59,1.56,1.49,1.52,1.58,1.83,1.90,1.92,1.78,1.73,1.67,1.71,1.68,2.55,1.95,1.85,1.77,1.74,1.83,1.81,1.80,1.80,1.78,1.81,1.79,1.79,1.79,1.77,1.75,1.77,1.68,1.65,1.61,1.56,1.55,1.53,1.56,1.69,1.88,1.96,1.83,1.81,1.75,1.84,1.79,2.64,2.05,1.86,1.82,1.75,1.64,1.62,1.81,1.81,1.82,1.85,1.86},
6952    {1.56,1.70,2.48,2.09,1.97,1.84,1.78,1.77,1.77,2.20,2.84,2.51,2.35,2.26,2.18,2.19,2.17,2.20,3.17,2.57,2.38,2.32,2.30,2.27,2.27,2.26,2.20,2.25,2.44,2.44,2.45,2.38,2.30,2.31,2.34,2.32,3.26,2.63,2.48,2.45,2.40,2.37,2.34,2.27,2.30,2.36,2.61,2.68,2.70,2.56,2.51,2.45,2.49,2.46,3.33,2.73,2.63,2.55,2.52,2.61,2.59,2.58,2.58,2.56,2.59,2.57,2.57,2.57,2.55,2.53,2.55,2.46,2.43,2.39,2.34,2.33,2.31,2.34,2.47,2.66,2.74,2.61,2.59,2.53,2.62,2.57,3.42,2.83,2.64,2.60,2.53,2.42,2.40,2.59,2.59,2.60,2.63,2.64},
6953    {1.17,1.31,2.09,1.70,1.58,1.45,1.39,1.38,1.38,1.81,2.45,2.12,1.96,1.87,1.79,1.80,1.78,1.81,2.78,2.18,1.99,1.93,1.91,1.88,1.88,1.87,1.81,1.86,2.05,2.05,2.06,1.99,1.91,1.92,1.95,1.93,2.87,2.24,2.09,2.06,2.01,1.98,1.95,1.88,1.91,1.97,2.22,2.29,2.31,2.17,2.12,2.06,2.10,2.07,2.94,2.34,2.24,2.16,2.13,2.22,2.20,2.19,2.19,2.17,2.20,2.18,2.18,2.18,2.16,2.14,2.16,2.07,2.04,2.00,1.95,1.94,1.92,1.95,2.08,2.27,2.35,2.22,2.20,2.14,2.23,2.18,3.03,2.44,2.25,2.21,2.14,2.03,2.01,2.20,2.20,2.21,2.24,2.25},
6954    {1.05,1.19,1.97,1.58,1.46,1.33,1.27,1.26,1.26,1.69,2.33,2.00,1.84,1.75,1.67,1.68,1.66,1.69,2.66,2.06,1.87,1.81,1.79,1.76,1.76,1.75,1.69,1.74,1.93,1.93,1.94,1.87,1.79,1.80,1.83,1.81,2.75,2.12,1.97,1.94,1.89,1.86,1.83,1.76,1.79,1.85,2.10,2.17,2.19,2.05,2.00,1.94,1.98,1.95,2.82,2.22,2.12,2.04,2.01,2.10,2.08,2.07,2.07,2.05,2.08,2.06,2.06,2.06,2.04,2.02,2.04,1.95,1.92,1.88,1.83,1.82,1.80,1.83,1.96,2.15,2.23,2.10,2.08,2.02,2.11,2.06,2.91,2.32,2.13,2.09,2.02,1.91,1.89,2.08,2.08,2.09,2.12,2.13},
6955    {0.92,1.06,1.84,1.45,1.33,1.20,1.14,1.13,1.13,1.56,2.20,1.87,1.71,1.62,1.54,1.55,1.53,1.56,2.53,1.93,1.74,1.68,1.66,1.63,1.63,1.62,1.56,1.61,1.80,1.80,1.81,1.74,1.66,1.67,1.70,1.68,2.62,1.99,1.84,1.81,1.76,1.73,1.70,1.63,1.66,1.72,1.97,2.04,2.06,1.92,1.87,1.81,1.85,1.82,2.69,2.09,1.99,1.91,1.88,1.97,1.95,1.94,1.94,1.92,1.95,1.93,1.93,1.93,1.91,1.89,1.91,1.82,1.79,1.75,1.70,1.69,1.67,1.70,1.83,2.02,2.10,1.97,1.95,1.89,1.98,1.93,2.78,2.19,2.00,1.96,1.89,1.78,1.76,1.95,1.95,1.96,1.99,2.00},
6956    {0.86,1.00,1.78,1.39,1.27,1.14,1.08,1.07,1.07,1.50,2.14,1.81,1.65,1.56,1.48,1.49,1.47,1.50,2.47,1.87,1.68,1.62,1.60,1.57,1.57,1.56,1.50,1.55,1.74,1.74,1.75,1.68,1.60,1.61,1.64,1.62,2.56,1.93,1.78,1.75,1.70,1.67,1.64,1.57,1.60,1.66,1.91,1.98,2.00,1.86,1.81,1.75,1.79,1.76,2.63,2.03,1.93,1.85,1.82,1.91,1.89,1.88,1.88,1.86,1.89,1.87,1.87,1.87,1.85,1.83,1.85,1.76,1.73,1.69,1.64,1.63,1.61,1.64,1.77,1.96,2.04,1.91,1.89,1.83,1.92,1.87,2.72,2.13,1.94,1.90,1.83,1.72,1.70,1.89,1.89,1.90,1.93,1.94},
6957    {0.85,0.99,1.77,1.38,1.26,1.13,1.07,1.06,1.06,1.49,2.13,1.80,1.64,1.55,1.47,1.48,1.46,1.49,2.46,1.86,1.67,1.61,1.59,1.56,1.56,1.55,1.49,1.54,1.73,1.73,1.74,1.67,1.59,1.60,1.63,1.61,2.55,1.92,1.77,1.74,1.69,1.66,1.63,1.56,1.59,1.65,1.90,1.97,1.99,1.85,1.80,1.74,1.78,1.75,2.62,2.02,1.92,1.84,1.81,1.90,1.88,1.87,1.87,1.85,1.88,1.86,1.86,1.86,1.84,1.82,1.84,1.75,1.72,1.68,1.63,1.62,1.60,1.63,1.76,1.95,2.03,1.90,1.88,1.82,1.91,1.86,2.71,2.12,1.93,1.89,1.82,1.71,1.69,1.88,1.88,1.89,1.92,1.93},
6958    {0.85,0.99,1.77,1.38,1.26,1.13,1.07,1.06,1.06,1.49,2.13,1.80,1.64,1.55,1.47,1.48,1.46,1.49,2.46,1.86,1.67,1.61,1.59,1.56,1.56,1.55,1.49,1.54,1.73,1.73,1.74,1.67,1.59,1.60,1.63,1.61,2.55,1.92,1.77,1.74,1.69,1.66,1.63,1.56,1.59,1.65,1.90,1.97,1.99,1.85,1.80,1.74,1.78,1.75,2.62,2.02,1.92,1.84,1.81,1.90,1.88,1.87,1.87,1.85,1.88,1.86,1.86,1.86,1.84,1.82,1.84,1.75,1.72,1.68,1.63,1.62,1.60,1.63,1.76,1.95,2.03,1.90,1.88,1.82,1.91,1.86,2.71,2.12,1.93,1.89,1.82,1.71,1.69,1.88,1.88,1.89,1.92,1.93},
6959    {1.28,1.42,2.20,1.81,1.69,1.56,1.50,1.49,1.49,1.92,2.56,2.23,2.07,1.98,1.90,1.91,1.89,1.92,2.89,2.29,2.10,2.04,2.02,1.99,1.99,1.98,1.92,1.97,2.16,2.16,2.17,2.10,2.02,2.03,2.06,2.04,2.98,2.35,2.20,2.17,2.12,2.09,2.06,1.99,2.02,2.08,2.33,2.40,2.42,2.28,2.23,2.17,2.21,2.18,3.05,2.45,2.35,2.27,2.24,2.33,2.31,2.30,2.30,2.28,2.31,2.29,2.29,2.29,2.27,2.25,2.27,2.18,2.15,2.11,2.06,2.05,2.03,2.06,2.19,2.38,2.46,2.33,2.31,2.25,2.34,2.29,3.14,2.55,2.36,2.32,2.25,2.14,2.12,2.31,2.31,2.32,2.35,2.36},
6960    {1.92,2.06,2.84,2.45,2.33,2.20,2.14,2.13,2.13,2.56,3.20,2.87,2.71,2.62,2.54,2.55,2.53,2.56,3.53,2.93,2.74,2.68,2.66,2.63,2.63,2.62,2.56,2.61,2.80,2.80,2.81,2.74,2.66,2.67,2.70,2.68,3.62,2.99,2.84,2.81,2.76,2.73,2.70,2.63,2.66,2.72,2.97,3.04,3.06,2.92,2.87,2.81,2.85,2.82,3.69,3.09,2.99,2.91,2.88,2.97,2.95,2.94,2.94,2.92,2.95,2.93,2.93,2.93,2.91,2.89,2.91,2.82,2.79,2.75,2.70,2.69,2.67,2.70,2.83,3.02,3.10,2.97,2.95,2.89,2.98,2.93,3.78,3.19,3.00,2.96,2.89,2.78,2.76,2.95,2.95,2.96,2.99,3.00},
6961    {1.59,1.73,2.51,2.12,2.00,1.87,1.81,1.80,1.80,2.23,2.87,2.54,2.38,2.29,2.21,2.22,2.20,2.23,3.20,2.60,2.41,2.35,2.33,2.30,2.30,2.29,2.23,2.28,2.47,2.47,2.48,2.41,2.33,2.34,2.37,2.35,3.29,2.66,2.51,2.48,2.43,2.40,2.37,2.30,2.33,2.39,2.64,2.71,2.73,2.59,2.54,2.48,2.52,2.49,3.36,2.76,2.66,2.58,2.55,2.64,2.62,2.61,2.61,2.59,2.62,2.60,2.60,2.60,2.58,2.56,2.58,2.49,2.46,2.42,2.37,2.36,2.34,2.37,2.50,2.69,2.77,2.64,2.62,2.56,2.65,2.60,3.45,2.86,2.67,2.63,2.56,2.45,2.43,2.62,2.62,2.63,2.66,2.67},
6962    {1.43,1.57,2.35,1.96,1.84,1.71,1.65,1.64,1.64,2.07,2.71,2.38,2.22,2.13,2.05,2.06,2.04,2.07,3.04,2.44,2.25,2.19,2.17,2.14,2.14,2.13,2.07,2.12,2.31,2.31,2.32,2.25,2.17,2.18,2.21,2.19,3.13,2.50,2.35,2.32,2.27,2.24,2.21,2.14,2.17,2.23,2.48,2.55,2.57,2.43,2.38,2.32,2.36,2.33,3.20,2.60,2.50,2.42,2.39,2.48,2.46,2.45,2.45,2.43,2.46,2.44,2.44,2.44,2.42,2.40,2.42,2.33,2.30,2.26,2.21,2.20,2.18,2.21,2.34,2.53,2.61,2.48,2.46,2.40,2.49,2.44,3.29,2.70,2.51,2.47,2.40,2.29,2.27,2.46,2.46,2.47,2.50,2.51},
6963    {1.34,1.48,2.26,1.87,1.75,1.62,1.56,1.55,1.55,1.98,2.62,2.29,2.13,2.04,1.96,1.97,1.95,1.98,2.95,2.35,2.16,2.10,2.08,2.05,2.05,2.04,1.98,2.03,2.22,2.22,2.23,2.16,2.08,2.09,2.12,2.10,3.04,2.41,2.26,2.23,2.18,2.15,2.12,2.05,2.08,2.14,2.39,2.46,2.48,2.34,2.29,2.23,2.27,2.24,3.11,2.51,2.41,2.33,2.30,2.39,2.37,2.36,2.36,2.34,2.37,2.35,2.35,2.35,2.33,2.31,2.33,2.24,2.21,2.17,2.12,2.11,2.09,2.12,2.25,2.44,2.52,2.39,2.37,2.31,2.40,2.35,3.20,2.61,2.42,2.38,2.31,2.20,2.18,2.37,2.37,2.38,2.41,2.42},
6964    {1.26,1.40,2.18,1.79,1.67,1.54,1.48,1.47,1.47,1.90,2.54,2.21,2.05,1.96,1.88,1.89,1.87,1.90,2.87,2.27,2.08,2.02,2.00,1.97,1.97,1.96,1.90,1.95,2.14,2.14,2.15,2.08,2.00,2.01,2.04,2.02,2.96,2.33,2.18,2.15,2.10,2.07,2.04,1.97,2.00,2.06,2.31,2.38,2.40,2.26,2.21,2.15,2.19,2.16,3.03,2.43,2.33,2.25,2.22,2.31,2.29,2.28,2.28,2.26,2.29,2.27,2.27,2.27,2.25,2.23,2.25,2.16,2.13,2.09,2.04,2.03,2.01,2.04,2.17,2.36,2.44,2.31,2.29,2.23,2.32,2.27,3.12,2.53,2.34,2.30,2.23,2.12,2.10,2.29,2.29,2.30,2.33,2.34},
6965    {1.27,1.41,2.19,1.80,1.68,1.55,1.49,1.48,1.48,1.91,2.55,2.22,2.06,1.97,1.89,1.90,1.88,1.91,2.88,2.28,2.09,2.03,2.01,1.98,1.98,1.97,1.91,1.96,2.15,2.15,2.16,2.09,2.01,2.02,2.05,2.03,2.97,2.34,2.19,2.16,2.11,2.08,2.05,1.98,2.01,2.07,2.32,2.39,2.41,2.27,2.22,2.16,2.20,2.17,3.04,2.44,2.34,2.26,2.23,2.32,2.30,2.29,2.29,2.27,2.30,2.28,2.28,2.28,2.26,2.24,2.26,2.17,2.14,2.10,2.05,2.04,2.02,2.05,2.18,2.37,2.45,2.32,2.30,2.24,2.33,2.28,3.13,2.54,2.35,2.31,2.24,2.13,2.11,2.30,2.30,2.31,2.34,2.35},
6966    {1.25,1.39,2.17,1.78,1.66,1.53,1.47,1.46,1.46,1.89,2.53,2.20,2.04,1.95,1.87,1.88,1.86,1.89,2.86,2.26,2.07,2.01,1.99,1.96,1.96,1.95,1.89,1.94,2.13,2.13,2.14,2.07,1.99,2.00,2.03,2.01,2.95,2.32,2.17,2.14,2.09,2.06,2.03,1.96,1.99,2.05,2.30,2.37,2.39,2.25,2.20,2.14,2.18,2.15,3.02,2.42,2.32,2.24,2.21,2.30,2.28,2.27,2.27,2.25,2.28,2.26,2.26,2.26,2.24,2.22,2.24,2.15,2.12,2.08,2.03,2.02,2.00,2.03,2.16,2.35,2.43,2.30,2.28,2.22,2.31,2.26,3.11,2.52,2.33,2.29,2.22,2.11,2.09,2.28,2.28,2.29,2.32,2.33},
6967    {1.28,1.42,2.20,1.81,1.69,1.56,1.50,1.49,1.49,1.92,2.56,2.23,2.07,1.98,1.90,1.91,1.89,1.92,2.89,2.29,2.10,2.04,2.02,1.99,1.99,1.98,1.92,1.97,2.16,2.16,2.17,2.10,2.02,2.03,2.06,2.04,2.98,2.35,2.20,2.17,2.12,2.09,2.06,1.99,2.02,2.08,2.33,2.40,2.42,2.28,2.23,2.17,2.21,2.18,3.05,2.45,2.35,2.27,2.24,2.33,2.31,2.30,2.30,2.28,2.31,2.29,2.29,2.29,2.27,2.25,2.27,2.18,2.15,2.11,2.06,2.05,2.03,2.06,2.19,2.38,2.46,2.33,2.31,2.25,2.34,2.29,3.14,2.55,2.36,2.32,2.25,2.14,2.12,2.31,2.31,2.32,2.35,2.36},
6968    {2.25,2.39,3.17,2.78,2.66,2.53,2.47,2.46,2.46,2.89,3.53,3.20,3.04,2.95,2.87,2.88,2.86,2.89,3.86,3.26,3.07,3.01,2.99,2.96,2.96,2.95,2.89,2.94,3.13,3.13,3.14,3.07,2.99,3.00,3.03,3.01,3.95,3.32,3.17,3.14,3.09,3.06,3.03,2.96,2.99,3.05,3.30,3.37,3.39,3.25,3.20,3.14,3.18,3.15,4.02,3.42,3.32,3.24,3.21,3.30,3.28,3.27,3.27,3.25,3.28,3.26,3.26,3.26,3.24,3.22,3.24,3.15,3.12,3.08,3.03,3.02,3.00,3.03,3.16,3.35,3.43,3.30,3.28,3.22,3.31,3.26,4.11,3.52,3.33,3.29,3.22,3.11,3.09,3.28,3.28,3.29,3.32,3.33},
6969    {1.65,1.79,2.57,2.18,2.06,1.93,1.87,1.86,1.86,2.29,2.93,2.60,2.44,2.35,2.27,2.28,2.26,2.29,3.26,2.66,2.47,2.41,2.39,2.36,2.36,2.35,2.29,2.34,2.53,2.53,2.54,2.47,2.39,2.40,2.43,2.41,3.35,2.72,2.57,2.54,2.49,2.46,2.43,2.36,2.39,2.45,2.70,2.77,2.79,2.65,2.60,2.54,2.58,2.55,3.42,2.82,2.72,2.64,2.61,2.70,2.68,2.67,2.67,2.65,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.55,2.52,2.48,2.43,2.42,2.40,2.43,2.56,2.75,2.83,2.70,2.68,2.62,2.71,2.66,3.51,2.92,2.73,2.69,2.62,2.51,2.49,2.68,2.68,2.69,2.72,2.73},
6970    {1.46,1.60,2.38,1.99,1.87,1.74,1.68,1.67,1.67,2.10,2.74,2.41,2.25,2.16,2.08,2.09,2.07,2.10,3.07,2.47,2.28,2.22,2.20,2.17,2.17,2.16,2.10,2.15,2.34,2.34,2.35,2.28,2.20,2.21,2.24,2.22,3.16,2.53,2.38,2.35,2.30,2.27,2.24,2.17,2.20,2.26,2.51,2.58,2.60,2.46,2.41,2.35,2.39,2.36,3.23,2.63,2.53,2.45,2.42,2.51,2.49,2.48,2.48,2.46,2.49,2.47,2.47,2.47,2.45,2.43,2.45,2.36,2.33,2.29,2.24,2.23,2.21,2.24,2.37,2.56,2.64,2.51,2.49,2.43,2.52,2.47,3.32,2.73,2.54,2.50,2.43,2.32,2.30,2.49,2.49,2.50,2.53,2.54},
6971    {1.40,1.54,2.32,1.93,1.81,1.68,1.62,1.61,1.61,2.04,2.68,2.35,2.19,2.10,2.02,2.03,2.01,2.04,3.01,2.41,2.22,2.16,2.14,2.11,2.11,2.10,2.04,2.09,2.28,2.28,2.29,2.22,2.14,2.15,2.18,2.16,3.10,2.47,2.32,2.29,2.24,2.21,2.18,2.11,2.14,2.20,2.45,2.52,2.54,2.40,2.35,2.29,2.33,2.30,3.17,2.57,2.47,2.39,2.36,2.45,2.43,2.42,2.42,2.40,2.43,2.41,2.41,2.41,2.39,2.37,2.39,2.30,2.27,2.23,2.18,2.17,2.15,2.18,2.31,2.50,2.58,2.45,2.43,2.37,2.46,2.41,3.26,2.67,2.48,2.44,2.37,2.26,2.24,2.43,2.43,2.44,2.47,2.48},
6972    {1.38,1.52,2.30,1.91,1.79,1.66,1.60,1.59,1.59,2.02,2.66,2.33,2.17,2.08,2.00,2.01,1.99,2.02,2.99,2.39,2.20,2.14,2.12,2.09,2.09,2.08,2.02,2.07,2.26,2.26,2.27,2.20,2.12,2.13,2.16,2.14,3.08,2.45,2.30,2.27,2.22,2.19,2.16,2.09,2.12,2.18,2.43,2.50,2.52,2.38,2.33,2.27,2.31,2.28,3.15,2.55,2.45,2.37,2.34,2.43,2.41,2.40,2.40,2.38,2.41,2.39,2.39,2.39,2.37,2.35,2.37,2.28,2.25,2.21,2.16,2.15,2.13,2.16,2.29,2.48,2.56,2.43,2.41,2.35,2.44,2.39,3.24,2.65,2.46,2.42,2.35,2.24,2.22,2.41,2.41,2.42,2.45,2.46},
6973    {1.35,1.49,2.27,1.88,1.76,1.63,1.57,1.56,1.56,1.99,2.63,2.30,2.14,2.05,1.97,1.98,1.96,1.99,2.96,2.36,2.17,2.11,2.09,2.06,2.06,2.05,1.99,2.04,2.23,2.23,2.24,2.17,2.09,2.10,2.13,2.11,3.05,2.42,2.27,2.24,2.19,2.16,2.13,2.06,2.09,2.15,2.40,2.47,2.49,2.35,2.30,2.24,2.28,2.25,3.12,2.52,2.42,2.34,2.31,2.40,2.38,2.37,2.37,2.35,2.38,2.36,2.36,2.36,2.34,2.32,2.34,2.25,2.22,2.18,2.13,2.12,2.10,2.13,2.26,2.45,2.53,2.40,2.38,2.32,2.41,2.36,3.21,2.62,2.43,2.39,2.32,2.21,2.19,2.38,2.38,2.39,2.42,2.43},
6974    {1.35,1.49,2.27,1.88,1.76,1.63,1.57,1.56,1.56,1.99,2.63,2.30,2.14,2.05,1.97,1.98,1.96,1.99,2.96,2.36,2.17,2.11,2.09,2.06,2.06,2.05,1.99,2.04,2.23,2.23,2.24,2.17,2.09,2.10,2.13,2.11,3.05,2.42,2.27,2.24,2.19,2.16,2.13,2.06,2.09,2.15,2.40,2.47,2.49,2.35,2.30,2.24,2.28,2.25,3.12,2.52,2.42,2.34,2.31,2.40,2.38,2.37,2.37,2.35,2.38,2.36,2.36,2.36,2.34,2.32,2.34,2.25,2.22,2.18,2.13,2.12,2.10,2.13,2.26,2.45,2.53,2.40,2.38,2.32,2.41,2.36,3.21,2.62,2.43,2.39,2.32,2.21,2.19,2.38,2.38,2.39,2.42,2.43},
6975    {1.34,1.48,2.26,1.87,1.75,1.62,1.56,1.55,1.55,1.98,2.62,2.29,2.13,2.04,1.96,1.97,1.95,1.98,2.95,2.35,2.16,2.10,2.08,2.05,2.05,2.04,1.98,2.03,2.22,2.22,2.23,2.16,2.08,2.09,2.12,2.10,3.04,2.41,2.26,2.23,2.18,2.15,2.12,2.05,2.08,2.14,2.39,2.46,2.48,2.34,2.29,2.23,2.27,2.24,3.11,2.51,2.41,2.33,2.30,2.39,2.37,2.36,2.36,2.34,2.37,2.35,2.35,2.35,2.33,2.31,2.33,2.24,2.21,2.17,2.12,2.11,2.09,2.12,2.25,2.44,2.52,2.39,2.37,2.31,2.40,2.35,3.20,2.61,2.42,2.38,2.31,2.20,2.18,2.37,2.37,2.38,2.41,2.42},
6976    {1.28,1.42,2.20,1.81,1.69,1.56,1.50,1.49,1.49,1.92,2.56,2.23,2.07,1.98,1.90,1.91,1.89,1.92,2.89,2.29,2.10,2.04,2.02,1.99,1.99,1.98,1.92,1.97,2.16,2.16,2.17,2.10,2.02,2.03,2.06,2.04,2.98,2.35,2.20,2.17,2.12,2.09,2.06,1.99,2.02,2.08,2.33,2.40,2.42,2.28,2.23,2.17,2.21,2.18,3.05,2.45,2.35,2.27,2.24,2.33,2.31,2.30,2.30,2.28,2.31,2.29,2.29,2.29,2.27,2.25,2.27,2.18,2.15,2.11,2.06,2.05,2.03,2.06,2.19,2.38,2.46,2.33,2.31,2.25,2.34,2.29,3.14,2.55,2.36,2.32,2.25,2.14,2.12,2.31,2.31,2.32,2.35,2.36},
6977    {1.33,1.47,2.25,1.86,1.74,1.61,1.55,1.54,1.54,1.97,2.61,2.28,2.12,2.03,1.95,1.96,1.94,1.97,2.94,2.34,2.15,2.09,2.07,2.04,2.04,2.03,1.97,2.02,2.21,2.21,2.22,2.15,2.07,2.08,2.11,2.09,3.03,2.40,2.25,2.22,2.17,2.14,2.11,2.04,2.07,2.13,2.38,2.45,2.47,2.33,2.28,2.22,2.26,2.23,3.10,2.50,2.40,2.32,2.29,2.38,2.36,2.35,2.35,2.33,2.36,2.34,2.34,2.34,2.32,2.30,2.32,2.23,2.20,2.16,2.11,2.10,2.08,2.11,2.24,2.43,2.51,2.38,2.36,2.30,2.39,2.34,3.19,2.60,2.41,2.37,2.30,2.19,2.17,2.36,2.36,2.37,2.40,2.41},
6978    {1.52,1.66,2.44,2.05,1.93,1.80,1.74,1.73,1.73,2.16,2.80,2.47,2.31,2.22,2.14,2.15,2.13,2.16,3.13,2.53,2.34,2.28,2.26,2.23,2.23,2.22,2.16,2.21,2.40,2.40,2.41,2.34,2.26,2.27,2.30,2.28,3.22,2.59,2.44,2.41,2.36,2.33,2.30,2.23,2.26,2.32,2.57,2.64,2.66,2.52,2.47,2.41,2.45,2.42,3.29,2.69,2.59,2.51,2.48,2.57,2.55,2.54,2.54,2.52,2.55,2.53,2.53,2.53,2.51,2.49,2.51,2.42,2.39,2.35,2.30,2.29,2.27,2.30,2.43,2.62,2.70,2.57,2.55,2.49,2.58,2.53,3.38,2.79,2.60,2.56,2.49,2.38,2.36,2.55,2.55,2.56,2.59,2.60},
6979    {1.52,1.66,2.44,2.05,1.93,1.80,1.74,1.73,1.73,2.16,2.80,2.47,2.31,2.22,2.14,2.15,2.13,2.16,3.13,2.53,2.34,2.28,2.26,2.23,2.23,2.22,2.16,2.21,2.40,2.40,2.41,2.34,2.26,2.27,2.30,2.28,3.22,2.59,2.44,2.41,2.36,2.33,2.30,2.23,2.26,2.32,2.57,2.64,2.66,2.52,2.47,2.41,2.45,2.42,3.29,2.69,2.59,2.51,2.48,2.57,2.55,2.54,2.54,2.52,2.55,2.53,2.53,2.53,2.51,2.49,2.51,2.42,2.39,2.35,2.30,2.29,2.27,2.30,2.43,2.62,2.70,2.57,2.55,2.49,2.58,2.53,3.38,2.79,2.60,2.56,2.49,2.38,2.36,2.55,2.55,2.56,2.59,2.60},
6980    {1.53,1.67,2.45,2.06,1.94,1.81,1.75,1.74,1.74,2.17,2.81,2.48,2.32,2.23,2.15,2.16,2.14,2.17,3.14,2.54,2.35,2.29,2.27,2.24,2.24,2.23,2.17,2.22,2.41,2.41,2.42,2.35,2.27,2.28,2.31,2.29,3.23,2.60,2.45,2.42,2.37,2.34,2.31,2.24,2.27,2.33,2.58,2.65,2.67,2.53,2.48,2.42,2.46,2.43,3.30,2.70,2.60,2.52,2.49,2.58,2.56,2.55,2.55,2.53,2.56,2.54,2.54,2.54,2.52,2.50,2.52,2.43,2.40,2.36,2.31,2.30,2.28,2.31,2.44,2.63,2.71,2.58,2.56,2.50,2.59,2.54,3.39,2.80,2.61,2.57,2.50,2.39,2.37,2.56,2.56,2.57,2.60,2.61},
6981    {1.46,1.60,2.38,1.99,1.87,1.74,1.68,1.67,1.67,2.10,2.74,2.41,2.25,2.16,2.08,2.09,2.07,2.10,3.07,2.47,2.28,2.22,2.20,2.17,2.17,2.16,2.10,2.15,2.34,2.34,2.35,2.28,2.20,2.21,2.24,2.22,3.16,2.53,2.38,2.35,2.30,2.27,2.24,2.17,2.20,2.26,2.51,2.58,2.60,2.46,2.41,2.35,2.39,2.36,3.23,2.63,2.53,2.45,2.42,2.51,2.49,2.48,2.48,2.46,2.49,2.47,2.47,2.47,2.45,2.43,2.45,2.36,2.33,2.29,2.24,2.23,2.21,2.24,2.37,2.56,2.64,2.51,2.49,2.43,2.52,2.47,3.32,2.73,2.54,2.50,2.43,2.32,2.30,2.49,2.49,2.50,2.53,2.54},
6982    {1.38,1.52,2.30,1.91,1.79,1.66,1.60,1.59,1.59,2.02,2.66,2.33,2.17,2.08,2.00,2.01,1.99,2.02,2.99,2.39,2.20,2.14,2.12,2.09,2.09,2.08,2.02,2.07,2.26,2.26,2.27,2.20,2.12,2.13,2.16,2.14,3.08,2.45,2.30,2.27,2.22,2.19,2.16,2.09,2.12,2.18,2.43,2.50,2.52,2.38,2.33,2.27,2.31,2.28,3.15,2.55,2.45,2.37,2.34,2.43,2.41,2.40,2.40,2.38,2.41,2.39,2.39,2.39,2.37,2.35,2.37,2.28,2.25,2.21,2.16,2.15,2.13,2.16,2.29,2.48,2.56,2.43,2.41,2.35,2.44,2.39,3.24,2.65,2.46,2.42,2.35,2.24,2.22,2.41,2.41,2.42,2.45,2.46},
6983    {1.39,1.53,2.31,1.92,1.80,1.67,1.61,1.60,1.60,2.03,2.67,2.34,2.18,2.09,2.01,2.02,2.00,2.03,3.00,2.40,2.21,2.15,2.13,2.10,2.10,2.09,2.03,2.08,2.27,2.27,2.28,2.21,2.13,2.14,2.17,2.15,3.09,2.46,2.31,2.28,2.23,2.20,2.17,2.10,2.13,2.19,2.44,2.51,2.53,2.39,2.34,2.28,2.32,2.29,3.16,2.56,2.46,2.38,2.35,2.44,2.42,2.41,2.41,2.39,2.42,2.40,2.40,2.40,2.38,2.36,2.38,2.29,2.26,2.22,2.17,2.16,2.14,2.17,2.30,2.49,2.57,2.44,2.42,2.36,2.45,2.40,3.25,2.66,2.47,2.43,2.36,2.25,2.23,2.42,2.42,2.43,2.46,2.47},
6984    {1.42,1.56,2.34,1.95,1.83,1.70,1.64,1.63,1.63,2.06,2.70,2.37,2.21,2.12,2.04,2.05,2.03,2.06,3.03,2.43,2.24,2.18,2.16,2.13,2.13,2.12,2.06,2.11,2.30,2.30,2.31,2.24,2.16,2.17,2.20,2.18,3.12,2.49,2.34,2.31,2.26,2.23,2.20,2.13,2.16,2.22,2.47,2.54,2.56,2.42,2.37,2.31,2.35,2.32,3.19,2.59,2.49,2.41,2.38,2.47,2.45,2.44,2.44,2.42,2.45,2.43,2.43,2.43,2.41,2.39,2.41,2.32,2.29,2.25,2.20,2.19,2.17,2.20,2.33,2.52,2.60,2.47,2.45,2.39,2.48,2.43,3.28,2.69,2.50,2.46,2.39,2.28,2.26,2.45,2.45,2.46,2.49,2.50},
6985    {1.40,1.54,2.32,1.93,1.81,1.68,1.62,1.61,1.61,2.04,2.68,2.35,2.19,2.10,2.02,2.03,2.01,2.04,3.01,2.41,2.22,2.16,2.14,2.11,2.11,2.10,2.04,2.09,2.28,2.28,2.29,2.22,2.14,2.15,2.18,2.16,3.10,2.47,2.32,2.29,2.24,2.21,2.18,2.11,2.14,2.20,2.45,2.52,2.54,2.40,2.35,2.29,2.33,2.30,3.17,2.57,2.47,2.39,2.36,2.45,2.43,2.42,2.42,2.40,2.43,2.41,2.41,2.41,2.39,2.37,2.39,2.30,2.27,2.23,2.18,2.17,2.15,2.18,2.31,2.50,2.58,2.45,2.43,2.37,2.46,2.41,3.26,2.67,2.48,2.44,2.37,2.26,2.24,2.43,2.43,2.44,2.47,2.48},
6986    {2.34,2.48,3.26,2.87,2.75,2.62,2.56,2.55,2.55,2.98,3.62,3.29,3.13,3.04,2.96,2.97,2.95,2.98,3.95,3.35,3.16,3.10,3.08,3.05,3.05,3.04,2.98,3.03,3.22,3.22,3.23,3.16,3.08,3.09,3.12,3.10,4.04,3.41,3.26,3.23,3.18,3.15,3.12,3.05,3.08,3.14,3.39,3.46,3.48,3.34,3.29,3.23,3.27,3.24,4.11,3.51,3.41,3.33,3.30,3.39,3.37,3.36,3.36,3.34,3.37,3.35,3.35,3.35,3.33,3.31,3.33,3.24,3.21,3.17,3.12,3.11,3.09,3.12,3.25,3.44,3.52,3.39,3.37,3.31,3.40,3.35,4.20,3.61,3.42,3.38,3.31,3.20,3.18,3.37,3.37,3.38,3.41,3.42},
6987    {1.71,1.85,2.63,2.24,2.12,1.99,1.93,1.92,1.92,2.35,2.99,2.66,2.50,2.41,2.33,2.34,2.32,2.35,3.32,2.72,2.53,2.47,2.45,2.42,2.42,2.41,2.35,2.40,2.59,2.59,2.60,2.53,2.45,2.46,2.49,2.47,3.41,2.78,2.63,2.60,2.55,2.52,2.49,2.42,2.45,2.51,2.76,2.83,2.85,2.71,2.66,2.60,2.64,2.61,3.48,2.88,2.78,2.70,2.67,2.76,2.74,2.73,2.73,2.71,2.74,2.72,2.72,2.72,2.70,2.68,2.70,2.61,2.58,2.54,2.49,2.48,2.46,2.49,2.62,2.81,2.89,2.76,2.74,2.68,2.77,2.72,3.57,2.98,2.79,2.75,2.68,2.57,2.55,2.74,2.74,2.75,2.78,2.79},
6988    {1.56,1.70,2.48,2.09,1.97,1.84,1.78,1.77,1.77,2.20,2.84,2.51,2.35,2.26,2.18,2.19,2.17,2.20,3.17,2.57,2.38,2.32,2.30,2.27,2.27,2.26,2.20,2.25,2.44,2.44,2.45,2.38,2.30,2.31,2.34,2.32,3.26,2.63,2.48,2.45,2.40,2.37,2.34,2.27,2.30,2.36,2.61,2.68,2.70,2.56,2.51,2.45,2.49,2.46,3.33,2.73,2.63,2.55,2.52,2.61,2.59,2.58,2.58,2.56,2.59,2.57,2.57,2.57,2.55,2.53,2.55,2.46,2.43,2.39,2.34,2.33,2.31,2.34,2.47,2.66,2.74,2.61,2.59,2.53,2.62,2.57,3.42,2.83,2.64,2.60,2.53,2.42,2.40,2.59,2.59,2.60,2.63,2.64},
6989    {1.53,1.67,2.45,2.06,1.94,1.81,1.75,1.74,1.74,2.17,2.81,2.48,2.32,2.23,2.15,2.16,2.14,2.17,3.14,2.54,2.35,2.29,2.27,2.24,2.24,2.23,2.17,2.22,2.41,2.41,2.42,2.35,2.27,2.28,2.31,2.29,3.23,2.60,2.45,2.42,2.37,2.34,2.31,2.24,2.27,2.33,2.58,2.65,2.67,2.53,2.48,2.42,2.46,2.43,3.30,2.70,2.60,2.52,2.49,2.58,2.56,2.55,2.55,2.53,2.56,2.54,2.54,2.54,2.52,2.50,2.52,2.43,2.40,2.36,2.31,2.30,2.28,2.31,2.44,2.63,2.71,2.58,2.56,2.50,2.59,2.54,3.39,2.80,2.61,2.57,2.50,2.39,2.37,2.56,2.56,2.57,2.60,2.61},
6990    {1.48,1.62,2.40,2.01,1.89,1.76,1.70,1.69,1.69,2.12,2.76,2.43,2.27,2.18,2.10,2.11,2.09,2.12,3.09,2.49,2.30,2.24,2.22,2.19,2.19,2.18,2.12,2.17,2.36,2.36,2.37,2.30,2.22,2.23,2.26,2.24,3.18,2.55,2.40,2.37,2.32,2.29,2.26,2.19,2.22,2.28,2.53,2.60,2.62,2.48,2.43,2.37,2.41,2.38,3.25,2.65,2.55,2.47,2.44,2.53,2.51,2.50,2.50,2.48,2.51,2.49,2.49,2.49,2.47,2.45,2.47,2.38,2.35,2.31,2.26,2.25,2.23,2.26,2.39,2.58,2.66,2.53,2.51,2.45,2.54,2.49,3.34,2.75,2.56,2.52,2.45,2.34,2.32,2.51,2.51,2.52,2.55,2.56},
6991    {1.45,1.59,2.37,1.98,1.86,1.73,1.67,1.66,1.66,2.09,2.73,2.40,2.24,2.15,2.07,2.08,2.06,2.09,3.06,2.46,2.27,2.21,2.19,2.16,2.16,2.15,2.09,2.14,2.33,2.33,2.34,2.27,2.19,2.20,2.23,2.21,3.15,2.52,2.37,2.34,2.29,2.26,2.23,2.16,2.19,2.25,2.50,2.57,2.59,2.45,2.40,2.34,2.38,2.35,3.22,2.62,2.52,2.44,2.41,2.50,2.48,2.47,2.47,2.45,2.48,2.46,2.46,2.46,2.44,2.42,2.44,2.35,2.32,2.28,2.23,2.22,2.20,2.23,2.36,2.55,2.63,2.50,2.48,2.42,2.51,2.46,3.31,2.72,2.53,2.49,2.42,2.31,2.29,2.48,2.48,2.49,2.52,2.53},
6992    {1.42,1.56,2.34,1.95,1.83,1.70,1.64,1.63,1.63,2.06,2.70,2.37,2.21,2.12,2.04,2.05,2.03,2.06,3.03,2.43,2.24,2.18,2.16,2.13,2.13,2.12,2.06,2.11,2.30,2.30,2.31,2.24,2.16,2.17,2.20,2.18,3.12,2.49,2.34,2.31,2.26,2.23,2.20,2.13,2.16,2.22,2.47,2.54,2.56,2.42,2.37,2.31,2.35,2.32,3.19,2.59,2.49,2.41,2.38,2.47,2.45,2.44,2.44,2.42,2.45,2.43,2.43,2.43,2.41,2.39,2.41,2.32,2.29,2.25,2.20,2.19,2.17,2.20,2.33,2.52,2.60,2.47,2.45,2.39,2.48,2.43,3.28,2.69,2.50,2.46,2.39,2.28,2.26,2.45,2.45,2.46,2.49,2.50},
6993    {1.35,1.49,2.27,1.88,1.76,1.63,1.57,1.56,1.56,1.99,2.63,2.30,2.14,2.05,1.97,1.98,1.96,1.99,2.96,2.36,2.17,2.11,2.09,2.06,2.06,2.05,1.99,2.04,2.23,2.23,2.24,2.17,2.09,2.10,2.13,2.11,3.05,2.42,2.27,2.24,2.19,2.16,2.13,2.06,2.09,2.15,2.40,2.47,2.49,2.35,2.30,2.24,2.28,2.25,3.12,2.52,2.42,2.34,2.31,2.40,2.38,2.37,2.37,2.35,2.38,2.36,2.36,2.36,2.34,2.32,2.34,2.25,2.22,2.18,2.13,2.12,2.10,2.13,2.26,2.45,2.53,2.40,2.38,2.32,2.41,2.36,3.21,2.62,2.43,2.39,2.32,2.21,2.19,2.38,2.38,2.39,2.42,2.43},
6994    {1.38,1.52,2.30,1.91,1.79,1.66,1.60,1.59,1.59,2.02,2.66,2.33,2.17,2.08,2.00,2.01,1.99,2.02,2.99,2.39,2.20,2.14,2.12,2.09,2.09,2.08,2.02,2.07,2.26,2.26,2.27,2.20,2.12,2.13,2.16,2.14,3.08,2.45,2.30,2.27,2.22,2.19,2.16,2.09,2.12,2.18,2.43,2.50,2.52,2.38,2.33,2.27,2.31,2.28,3.15,2.55,2.45,2.37,2.34,2.43,2.41,2.40,2.40,2.38,2.41,2.39,2.39,2.39,2.37,2.35,2.37,2.28,2.25,2.21,2.16,2.15,2.13,2.16,2.29,2.48,2.56,2.43,2.41,2.35,2.44,2.39,3.24,2.65,2.46,2.42,2.35,2.24,2.22,2.41,2.41,2.42,2.45,2.46},
6995    {1.44,1.58,2.36,1.97,1.85,1.72,1.66,1.65,1.65,2.08,2.72,2.39,2.23,2.14,2.06,2.07,2.05,2.08,3.05,2.45,2.26,2.20,2.18,2.15,2.15,2.14,2.08,2.13,2.32,2.32,2.33,2.26,2.18,2.19,2.22,2.20,3.14,2.51,2.36,2.33,2.28,2.25,2.22,2.15,2.18,2.24,2.49,2.56,2.58,2.44,2.39,2.33,2.37,2.34,3.21,2.61,2.51,2.43,2.40,2.49,2.47,2.46,2.46,2.44,2.47,2.45,2.45,2.45,2.43,2.41,2.43,2.34,2.31,2.27,2.22,2.21,2.19,2.22,2.35,2.54,2.62,2.49,2.47,2.41,2.50,2.45,3.30,2.71,2.52,2.48,2.41,2.30,2.28,2.47,2.47,2.48,2.51,2.52},
6996    {1.69,1.83,2.61,2.22,2.10,1.97,1.91,1.90,1.90,2.33,2.97,2.64,2.48,2.39,2.31,2.32,2.30,2.33,3.30,2.70,2.51,2.45,2.43,2.40,2.40,2.39,2.33,2.38,2.57,2.57,2.58,2.51,2.43,2.44,2.47,2.45,3.39,2.76,2.61,2.58,2.53,2.50,2.47,2.40,2.43,2.49,2.74,2.81,2.83,2.69,2.64,2.58,2.62,2.59,3.46,2.86,2.76,2.68,2.65,2.74,2.72,2.71,2.71,2.69,2.72,2.70,2.70,2.70,2.68,2.66,2.68,2.59,2.56,2.52,2.47,2.46,2.44,2.47,2.60,2.79,2.87,2.74,2.72,2.66,2.75,2.70,3.55,2.96,2.77,2.73,2.66,2.55,2.53,2.72,2.72,2.73,2.76,2.77},
6997    {1.76,1.90,2.68,2.29,2.17,2.04,1.98,1.97,1.97,2.40,3.04,2.71,2.55,2.46,2.38,2.39,2.37,2.40,3.37,2.77,2.58,2.52,2.50,2.47,2.47,2.46,2.40,2.45,2.64,2.64,2.65,2.58,2.50,2.51,2.54,2.52,3.46,2.83,2.68,2.65,2.60,2.57,2.54,2.47,2.50,2.56,2.81,2.88,2.90,2.76,2.71,2.65,2.69,2.66,3.53,2.93,2.83,2.75,2.72,2.81,2.79,2.78,2.78,2.76,2.79,2.77,2.77,2.77,2.75,2.73,2.75,2.66,2.63,2.59,2.54,2.53,2.51,2.54,2.67,2.86,2.94,2.81,2.79,2.73,2.82,2.77,3.62,3.03,2.84,2.80,2.73,2.62,2.60,2.79,2.79,2.80,2.83,2.84},
6998    {1.78,1.92,2.70,2.31,2.19,2.06,2.00,1.99,1.99,2.42,3.06,2.73,2.57,2.48,2.40,2.41,2.39,2.42,3.39,2.79,2.60,2.54,2.52,2.49,2.49,2.48,2.42,2.47,2.66,2.66,2.67,2.60,2.52,2.53,2.56,2.54,3.48,2.85,2.70,2.67,2.62,2.59,2.56,2.49,2.52,2.58,2.83,2.90,2.92,2.78,2.73,2.67,2.71,2.68,3.55,2.95,2.85,2.77,2.74,2.83,2.81,2.80,2.80,2.78,2.81,2.79,2.79,2.79,2.77,2.75,2.77,2.68,2.65,2.61,2.56,2.55,2.53,2.56,2.69,2.88,2.96,2.83,2.81,2.75,2.84,2.79,3.64,3.05,2.86,2.82,2.75,2.64,2.62,2.81,2.81,2.82,2.85,2.86},
6999    {1.64,1.78,2.56,2.17,2.05,1.92,1.86,1.85,1.85,2.28,2.92,2.59,2.43,2.34,2.26,2.27,2.25,2.28,3.25,2.65,2.46,2.40,2.38,2.35,2.35,2.34,2.28,2.33,2.52,2.52,2.53,2.46,2.38,2.39,2.42,2.40,3.34,2.71,2.56,2.53,2.48,2.45,2.42,2.35,2.38,2.44,2.69,2.76,2.78,2.64,2.59,2.53,2.57,2.54,3.41,2.81,2.71,2.63,2.60,2.69,2.67,2.66,2.66,2.64,2.67,2.65,2.65,2.65,2.63,2.61,2.63,2.54,2.51,2.47,2.42,2.41,2.39,2.42,2.55,2.74,2.82,2.69,2.67,2.61,2.70,2.65,3.50,2.91,2.72,2.68,2.61,2.50,2.48,2.67,2.67,2.68,2.71,2.72},
7000    {1.59,1.73,2.51,2.12,2.00,1.87,1.81,1.80,1.80,2.23,2.87,2.54,2.38,2.29,2.21,2.22,2.20,2.23,3.20,2.60,2.41,2.35,2.33,2.30,2.30,2.29,2.23,2.28,2.47,2.47,2.48,2.41,2.33,2.34,2.37,2.35,3.29,2.66,2.51,2.48,2.43,2.40,2.37,2.30,2.33,2.39,2.64,2.71,2.73,2.59,2.54,2.48,2.52,2.49,3.36,2.76,2.66,2.58,2.55,2.64,2.62,2.61,2.61,2.59,2.62,2.60,2.60,2.60,2.58,2.56,2.58,2.49,2.46,2.42,2.37,2.36,2.34,2.37,2.50,2.69,2.77,2.64,2.62,2.56,2.65,2.60,3.45,2.86,2.67,2.63,2.56,2.45,2.43,2.62,2.62,2.63,2.66,2.67},
7001    {1.53,1.67,2.45,2.06,1.94,1.81,1.75,1.74,1.74,2.17,2.81,2.48,2.32,2.23,2.15,2.16,2.14,2.17,3.14,2.54,2.35,2.29,2.27,2.24,2.24,2.23,2.17,2.22,2.41,2.41,2.42,2.35,2.27,2.28,2.31,2.29,3.23,2.60,2.45,2.42,2.37,2.34,2.31,2.24,2.27,2.33,2.58,2.65,2.67,2.53,2.48,2.42,2.46,2.43,3.30,2.70,2.60,2.52,2.49,2.58,2.56,2.55,2.55,2.53,2.56,2.54,2.54,2.54,2.52,2.50,2.52,2.43,2.40,2.36,2.31,2.30,2.28,2.31,2.44,2.63,2.71,2.58,2.56,2.50,2.59,2.54,3.39,2.80,2.61,2.57,2.50,2.39,2.37,2.56,2.56,2.57,2.60,2.61},
7002    {1.57,1.71,2.49,2.10,1.98,1.85,1.79,1.78,1.78,2.21,2.85,2.52,2.36,2.27,2.19,2.20,2.18,2.21,3.18,2.58,2.39,2.33,2.31,2.28,2.28,2.27,2.21,2.26,2.45,2.45,2.46,2.39,2.31,2.32,2.35,2.33,3.27,2.64,2.49,2.46,2.41,2.38,2.35,2.28,2.31,2.37,2.62,2.69,2.71,2.57,2.52,2.46,2.50,2.47,3.34,2.74,2.64,2.56,2.53,2.62,2.60,2.59,2.59,2.57,2.60,2.58,2.58,2.58,2.56,2.54,2.56,2.47,2.44,2.40,2.35,2.34,2.32,2.35,2.48,2.67,2.75,2.62,2.60,2.54,2.63,2.58,3.43,2.84,2.65,2.61,2.54,2.43,2.41,2.60,2.60,2.61,2.64,2.65},
7003    {1.54,1.68,2.46,2.07,1.95,1.82,1.76,1.75,1.75,2.18,2.82,2.49,2.33,2.24,2.16,2.17,2.15,2.18,3.15,2.55,2.36,2.30,2.28,2.25,2.25,2.24,2.18,2.23,2.42,2.42,2.43,2.36,2.28,2.29,2.32,2.30,3.24,2.61,2.46,2.43,2.38,2.35,2.32,2.25,2.28,2.34,2.59,2.66,2.68,2.54,2.49,2.43,2.47,2.44,3.31,2.71,2.61,2.53,2.50,2.59,2.57,2.56,2.56,2.54,2.57,2.55,2.55,2.55,2.53,2.51,2.53,2.44,2.41,2.37,2.32,2.31,2.29,2.32,2.45,2.64,2.72,2.59,2.57,2.51,2.60,2.55,3.40,2.81,2.62,2.58,2.51,2.40,2.38,2.57,2.57,2.58,2.61,2.62},
7004    {2.41,2.55,3.33,2.94,2.82,2.69,2.63,2.62,2.62,3.05,3.69,3.36,3.20,3.11,3.03,3.04,3.02,3.05,4.02,3.42,3.23,3.17,3.15,3.12,3.12,3.11,3.05,3.10,3.29,3.29,3.30,3.23,3.15,3.16,3.19,3.17,4.11,3.48,3.33,3.30,3.25,3.22,3.19,3.12,3.15,3.21,3.46,3.53,3.55,3.41,3.36,3.30,3.34,3.31,4.18,3.58,3.48,3.40,3.37,3.46,3.44,3.43,3.43,3.41,3.44,3.42,3.42,3.42,3.40,3.38,3.40,3.31,3.28,3.24,3.19,3.18,3.16,3.19,3.32,3.51,3.59,3.46,3.44,3.38,3.47,3.42,4.27,3.68,3.49,3.45,3.38,3.27,3.25,3.44,3.44,3.45,3.48,3.49},
7005    {1.81,1.95,2.73,2.34,2.22,2.09,2.03,2.02,2.02,2.45,3.09,2.76,2.60,2.51,2.43,2.44,2.42,2.45,3.42,2.82,2.63,2.57,2.55,2.52,2.52,2.51,2.45,2.50,2.69,2.69,2.70,2.63,2.55,2.56,2.59,2.57,3.51,2.88,2.73,2.70,2.65,2.62,2.59,2.52,2.55,2.61,2.86,2.93,2.95,2.81,2.76,2.70,2.74,2.71,3.58,2.98,2.88,2.80,2.77,2.86,2.84,2.83,2.83,2.81,2.84,2.82,2.82,2.82,2.80,2.78,2.80,2.71,2.68,2.64,2.59,2.58,2.56,2.59,2.72,2.91,2.99,2.86,2.84,2.78,2.87,2.82,3.67,3.08,2.89,2.85,2.78,2.67,2.65,2.84,2.84,2.85,2.88,2.89},
7006    {1.71,1.85,2.63,2.24,2.12,1.99,1.93,1.92,1.92,2.35,2.99,2.66,2.50,2.41,2.33,2.34,2.32,2.35,3.32,2.72,2.53,2.47,2.45,2.42,2.42,2.41,2.35,2.40,2.59,2.59,2.60,2.53,2.45,2.46,2.49,2.47,3.41,2.78,2.63,2.60,2.55,2.52,2.49,2.42,2.45,2.51,2.76,2.83,2.85,2.71,2.66,2.60,2.64,2.61,3.48,2.88,2.78,2.70,2.67,2.76,2.74,2.73,2.73,2.71,2.74,2.72,2.72,2.72,2.70,2.68,2.70,2.61,2.58,2.54,2.49,2.48,2.46,2.49,2.62,2.81,2.89,2.76,2.74,2.68,2.77,2.72,3.57,2.98,2.79,2.75,2.68,2.57,2.55,2.74,2.74,2.75,2.78,2.79},
7007    {1.63,1.77,2.55,2.16,2.04,1.91,1.85,1.84,1.84,2.27,2.91,2.58,2.42,2.33,2.25,2.26,2.24,2.27,3.24,2.64,2.45,2.39,2.37,2.34,2.34,2.33,2.27,2.32,2.51,2.51,2.52,2.45,2.37,2.38,2.41,2.39,3.33,2.70,2.55,2.52,2.47,2.44,2.41,2.34,2.37,2.43,2.68,2.75,2.77,2.63,2.58,2.52,2.56,2.53,3.40,2.80,2.70,2.62,2.59,2.68,2.66,2.65,2.65,2.63,2.66,2.64,2.64,2.64,2.62,2.60,2.62,2.53,2.50,2.46,2.41,2.40,2.38,2.41,2.54,2.73,2.81,2.68,2.66,2.60,2.69,2.64,3.49,2.90,2.71,2.67,2.60,2.49,2.47,2.66,2.66,2.67,2.70,2.71},
7008    {1.60,1.74,2.52,2.13,2.01,1.88,1.82,1.81,1.81,2.24,2.88,2.55,2.39,2.30,2.22,2.23,2.21,2.24,3.21,2.61,2.42,2.36,2.34,2.31,2.31,2.30,2.24,2.29,2.48,2.48,2.49,2.42,2.34,2.35,2.38,2.36,3.30,2.67,2.52,2.49,2.44,2.41,2.38,2.31,2.34,2.40,2.65,2.72,2.74,2.60,2.55,2.49,2.53,2.50,3.37,2.77,2.67,2.59,2.56,2.65,2.63,2.62,2.62,2.60,2.63,2.61,2.61,2.61,2.59,2.57,2.59,2.50,2.47,2.43,2.38,2.37,2.35,2.38,2.51,2.70,2.78,2.65,2.63,2.57,2.66,2.61,3.46,2.87,2.68,2.64,2.57,2.46,2.44,2.63,2.63,2.64,2.67,2.68},
7009    {1.69,1.83,2.61,2.22,2.10,1.97,1.91,1.90,1.90,2.33,2.97,2.64,2.48,2.39,2.31,2.32,2.30,2.33,3.30,2.70,2.51,2.45,2.43,2.40,2.40,2.39,2.33,2.38,2.57,2.57,2.58,2.51,2.43,2.44,2.47,2.45,3.39,2.76,2.61,2.58,2.53,2.50,2.47,2.40,2.43,2.49,2.74,2.81,2.83,2.69,2.64,2.58,2.62,2.59,3.46,2.86,2.76,2.68,2.65,2.74,2.72,2.71,2.71,2.69,2.72,2.70,2.70,2.70,2.68,2.66,2.68,2.59,2.56,2.52,2.47,2.46,2.44,2.47,2.60,2.79,2.87,2.74,2.72,2.66,2.75,2.70,3.55,2.96,2.77,2.73,2.66,2.55,2.53,2.72,2.72,2.73,2.76,2.77},
7010    {1.67,1.81,2.59,2.20,2.08,1.95,1.89,1.88,1.88,2.31,2.95,2.62,2.46,2.37,2.29,2.30,2.28,2.31,3.28,2.68,2.49,2.43,2.41,2.38,2.38,2.37,2.31,2.36,2.55,2.55,2.56,2.49,2.41,2.42,2.45,2.43,3.37,2.74,2.59,2.56,2.51,2.48,2.45,2.38,2.41,2.47,2.72,2.79,2.81,2.67,2.62,2.56,2.60,2.57,3.44,2.84,2.74,2.66,2.63,2.72,2.70,2.69,2.69,2.67,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.57,2.54,2.50,2.45,2.44,2.42,2.45,2.58,2.77,2.85,2.72,2.70,2.64,2.73,2.68,3.53,2.94,2.75,2.71,2.64,2.53,2.51,2.70,2.70,2.71,2.74,2.75},
7011    {1.66,1.80,2.58,2.19,2.07,1.94,1.88,1.87,1.87,2.30,2.94,2.61,2.45,2.36,2.28,2.29,2.27,2.30,3.27,2.67,2.48,2.42,2.40,2.37,2.37,2.36,2.30,2.35,2.54,2.54,2.55,2.48,2.40,2.41,2.44,2.42,3.36,2.73,2.58,2.55,2.50,2.47,2.44,2.37,2.40,2.46,2.71,2.78,2.80,2.66,2.61,2.55,2.59,2.56,3.43,2.83,2.73,2.65,2.62,2.71,2.69,2.68,2.68,2.66,2.69,2.67,2.67,2.67,2.65,2.63,2.65,2.56,2.53,2.49,2.44,2.43,2.41,2.44,2.57,2.76,2.84,2.71,2.69,2.63,2.72,2.67,3.52,2.93,2.74,2.70,2.63,2.52,2.50,2.69,2.69,2.70,2.73,2.74},
7012    {1.66,1.80,2.58,2.19,2.07,1.94,1.88,1.87,1.87,2.30,2.94,2.61,2.45,2.36,2.28,2.29,2.27,2.30,3.27,2.67,2.48,2.42,2.40,2.37,2.37,2.36,2.30,2.35,2.54,2.54,2.55,2.48,2.40,2.41,2.44,2.42,3.36,2.73,2.58,2.55,2.50,2.47,2.44,2.37,2.40,2.46,2.71,2.78,2.80,2.66,2.61,2.55,2.59,2.56,3.43,2.83,2.73,2.65,2.62,2.71,2.69,2.68,2.68,2.66,2.69,2.67,2.67,2.67,2.65,2.63,2.65,2.56,2.53,2.49,2.44,2.43,2.41,2.44,2.57,2.76,2.84,2.71,2.69,2.63,2.72,2.67,3.52,2.93,2.74,2.70,2.63,2.52,2.50,2.69,2.69,2.70,2.73,2.74},
7013    {1.64,1.78,2.56,2.17,2.05,1.92,1.86,1.85,1.85,2.28,2.92,2.59,2.43,2.34,2.26,2.27,2.25,2.28,3.25,2.65,2.46,2.40,2.38,2.35,2.35,2.34,2.28,2.33,2.52,2.52,2.53,2.46,2.38,2.39,2.42,2.40,3.34,2.71,2.56,2.53,2.48,2.45,2.42,2.35,2.38,2.44,2.69,2.76,2.78,2.64,2.59,2.53,2.57,2.54,3.41,2.81,2.71,2.63,2.60,2.69,2.67,2.66,2.66,2.64,2.67,2.65,2.65,2.65,2.63,2.61,2.63,2.54,2.51,2.47,2.42,2.41,2.39,2.42,2.55,2.74,2.82,2.69,2.67,2.61,2.70,2.65,3.50,2.91,2.72,2.68,2.61,2.50,2.48,2.67,2.67,2.68,2.71,2.72},
7014    {1.67,1.81,2.59,2.20,2.08,1.95,1.89,1.88,1.88,2.31,2.95,2.62,2.46,2.37,2.29,2.30,2.28,2.31,3.28,2.68,2.49,2.43,2.41,2.38,2.38,2.37,2.31,2.36,2.55,2.55,2.56,2.49,2.41,2.42,2.45,2.43,3.37,2.74,2.59,2.56,2.51,2.48,2.45,2.38,2.41,2.47,2.72,2.79,2.81,2.67,2.62,2.56,2.60,2.57,3.44,2.84,2.74,2.66,2.63,2.72,2.70,2.69,2.69,2.67,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.57,2.54,2.50,2.45,2.44,2.42,2.45,2.58,2.77,2.85,2.72,2.70,2.64,2.73,2.68,3.53,2.94,2.75,2.71,2.64,2.53,2.51,2.70,2.70,2.71,2.74,2.75},
7015    {1.65,1.79,2.57,2.18,2.06,1.93,1.87,1.86,1.86,2.29,2.93,2.60,2.44,2.35,2.27,2.28,2.26,2.29,3.26,2.66,2.47,2.41,2.39,2.36,2.36,2.35,2.29,2.34,2.53,2.53,2.54,2.47,2.39,2.40,2.43,2.41,3.35,2.72,2.57,2.54,2.49,2.46,2.43,2.36,2.39,2.45,2.70,2.77,2.79,2.65,2.60,2.54,2.58,2.55,3.42,2.82,2.72,2.64,2.61,2.70,2.68,2.67,2.67,2.65,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.55,2.52,2.48,2.43,2.42,2.40,2.43,2.56,2.75,2.83,2.70,2.68,2.62,2.71,2.66,3.51,2.92,2.73,2.69,2.62,2.51,2.49,2.68,2.68,2.69,2.72,2.73},
7016    {1.65,1.79,2.57,2.18,2.06,1.93,1.87,1.86,1.86,2.29,2.93,2.60,2.44,2.35,2.27,2.28,2.26,2.29,3.26,2.66,2.47,2.41,2.39,2.36,2.36,2.35,2.29,2.34,2.53,2.53,2.54,2.47,2.39,2.40,2.43,2.41,3.35,2.72,2.57,2.54,2.49,2.46,2.43,2.36,2.39,2.45,2.70,2.77,2.79,2.65,2.60,2.54,2.58,2.55,3.42,2.82,2.72,2.64,2.61,2.70,2.68,2.67,2.67,2.65,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.55,2.52,2.48,2.43,2.42,2.40,2.43,2.56,2.75,2.83,2.70,2.68,2.62,2.71,2.66,3.51,2.92,2.73,2.69,2.62,2.51,2.49,2.68,2.68,2.69,2.72,2.73},
7017    {1.65,1.79,2.57,2.18,2.06,1.93,1.87,1.86,1.86,2.29,2.93,2.60,2.44,2.35,2.27,2.28,2.26,2.29,3.26,2.66,2.47,2.41,2.39,2.36,2.36,2.35,2.29,2.34,2.53,2.53,2.54,2.47,2.39,2.40,2.43,2.41,3.35,2.72,2.57,2.54,2.49,2.46,2.43,2.36,2.39,2.45,2.70,2.77,2.79,2.65,2.60,2.54,2.58,2.55,3.42,2.82,2.72,2.64,2.61,2.70,2.68,2.67,2.67,2.65,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.55,2.52,2.48,2.43,2.42,2.40,2.43,2.56,2.75,2.83,2.70,2.68,2.62,2.71,2.66,3.51,2.92,2.73,2.69,2.62,2.51,2.49,2.68,2.68,2.69,2.72,2.73},
7018    {1.63,1.77,2.55,2.16,2.04,1.91,1.85,1.84,1.84,2.27,2.91,2.58,2.42,2.33,2.25,2.26,2.24,2.27,3.24,2.64,2.45,2.39,2.37,2.34,2.34,2.33,2.27,2.32,2.51,2.51,2.52,2.45,2.37,2.38,2.41,2.39,3.33,2.70,2.55,2.52,2.47,2.44,2.41,2.34,2.37,2.43,2.68,2.75,2.77,2.63,2.58,2.52,2.56,2.53,3.40,2.80,2.70,2.62,2.59,2.68,2.66,2.65,2.65,2.63,2.66,2.64,2.64,2.64,2.62,2.60,2.62,2.53,2.50,2.46,2.41,2.40,2.38,2.41,2.54,2.73,2.81,2.68,2.66,2.60,2.69,2.64,3.49,2.90,2.71,2.67,2.60,2.49,2.47,2.66,2.66,2.67,2.70,2.71},
7019    {1.61,1.75,2.53,2.14,2.02,1.89,1.83,1.82,1.82,2.25,2.89,2.56,2.40,2.31,2.23,2.24,2.22,2.25,3.22,2.62,2.43,2.37,2.35,2.32,2.32,2.31,2.25,2.30,2.49,2.49,2.50,2.43,2.35,2.36,2.39,2.37,3.31,2.68,2.53,2.50,2.45,2.42,2.39,2.32,2.35,2.41,2.66,2.73,2.75,2.61,2.56,2.50,2.54,2.51,3.38,2.78,2.68,2.60,2.57,2.66,2.64,2.63,2.63,2.61,2.64,2.62,2.62,2.62,2.60,2.58,2.60,2.51,2.48,2.44,2.39,2.38,2.36,2.39,2.52,2.71,2.79,2.66,2.64,2.58,2.67,2.62,3.47,2.88,2.69,2.65,2.58,2.47,2.45,2.64,2.64,2.65,2.68,2.69},
7020    {1.63,1.77,2.55,2.16,2.04,1.91,1.85,1.84,1.84,2.27,2.91,2.58,2.42,2.33,2.25,2.26,2.24,2.27,3.24,2.64,2.45,2.39,2.37,2.34,2.34,2.33,2.27,2.32,2.51,2.51,2.52,2.45,2.37,2.38,2.41,2.39,3.33,2.70,2.55,2.52,2.47,2.44,2.41,2.34,2.37,2.43,2.68,2.75,2.77,2.63,2.58,2.52,2.56,2.53,3.40,2.80,2.70,2.62,2.59,2.68,2.66,2.65,2.65,2.63,2.66,2.64,2.64,2.64,2.62,2.60,2.62,2.53,2.50,2.46,2.41,2.40,2.38,2.41,2.54,2.73,2.81,2.68,2.66,2.60,2.69,2.64,3.49,2.90,2.71,2.67,2.60,2.49,2.47,2.66,2.66,2.67,2.70,2.71},
7021    {1.54,1.68,2.46,2.07,1.95,1.82,1.76,1.75,1.75,2.18,2.82,2.49,2.33,2.24,2.16,2.17,2.15,2.18,3.15,2.55,2.36,2.30,2.28,2.25,2.25,2.24,2.18,2.23,2.42,2.42,2.43,2.36,2.28,2.29,2.32,2.30,3.24,2.61,2.46,2.43,2.38,2.35,2.32,2.25,2.28,2.34,2.59,2.66,2.68,2.54,2.49,2.43,2.47,2.44,3.31,2.71,2.61,2.53,2.50,2.59,2.57,2.56,2.56,2.54,2.57,2.55,2.55,2.55,2.53,2.51,2.53,2.44,2.41,2.37,2.32,2.31,2.29,2.32,2.45,2.64,2.72,2.59,2.57,2.51,2.60,2.55,3.40,2.81,2.62,2.58,2.51,2.40,2.38,2.57,2.57,2.58,2.61,2.62},
7022    {1.51,1.65,2.43,2.04,1.92,1.79,1.73,1.72,1.72,2.15,2.79,2.46,2.30,2.21,2.13,2.14,2.12,2.15,3.12,2.52,2.33,2.27,2.25,2.22,2.22,2.21,2.15,2.20,2.39,2.39,2.40,2.33,2.25,2.26,2.29,2.27,3.21,2.58,2.43,2.40,2.35,2.32,2.29,2.22,2.25,2.31,2.56,2.63,2.65,2.51,2.46,2.40,2.44,2.41,3.28,2.68,2.58,2.50,2.47,2.56,2.54,2.53,2.53,2.51,2.54,2.52,2.52,2.52,2.50,2.48,2.50,2.41,2.38,2.34,2.29,2.28,2.26,2.29,2.42,2.61,2.69,2.56,2.54,2.48,2.57,2.52,3.37,2.78,2.59,2.55,2.48,2.37,2.35,2.54,2.54,2.55,2.58,2.59},
7023    {1.47,1.61,2.39,2.00,1.88,1.75,1.69,1.68,1.68,2.11,2.75,2.42,2.26,2.17,2.09,2.10,2.08,2.11,3.08,2.48,2.29,2.23,2.21,2.18,2.18,2.17,2.11,2.16,2.35,2.35,2.36,2.29,2.21,2.22,2.25,2.23,3.17,2.54,2.39,2.36,2.31,2.28,2.25,2.18,2.21,2.27,2.52,2.59,2.61,2.47,2.42,2.36,2.40,2.37,3.24,2.64,2.54,2.46,2.43,2.52,2.50,2.49,2.49,2.47,2.50,2.48,2.48,2.48,2.46,2.44,2.46,2.37,2.34,2.30,2.25,2.24,2.22,2.25,2.38,2.57,2.65,2.52,2.50,2.44,2.53,2.48,3.33,2.74,2.55,2.51,2.44,2.33,2.31,2.50,2.50,2.51,2.54,2.55},
7024    {1.42,1.56,2.34,1.95,1.83,1.70,1.64,1.63,1.63,2.06,2.70,2.37,2.21,2.12,2.04,2.05,2.03,2.06,3.03,2.43,2.24,2.18,2.16,2.13,2.13,2.12,2.06,2.11,2.30,2.30,2.31,2.24,2.16,2.17,2.20,2.18,3.12,2.49,2.34,2.31,2.26,2.23,2.20,2.13,2.16,2.22,2.47,2.54,2.56,2.42,2.37,2.31,2.35,2.32,3.19,2.59,2.49,2.41,2.38,2.47,2.45,2.44,2.44,2.42,2.45,2.43,2.43,2.43,2.41,2.39,2.41,2.32,2.29,2.25,2.20,2.19,2.17,2.20,2.33,2.52,2.60,2.47,2.45,2.39,2.48,2.43,3.28,2.69,2.50,2.46,2.39,2.28,2.26,2.45,2.45,2.46,2.49,2.50},
7025    {1.41,1.55,2.33,1.94,1.82,1.69,1.63,1.62,1.62,2.05,2.69,2.36,2.20,2.11,2.03,2.04,2.02,2.05,3.02,2.42,2.23,2.17,2.15,2.12,2.12,2.11,2.05,2.10,2.29,2.29,2.30,2.23,2.15,2.16,2.19,2.17,3.11,2.48,2.33,2.30,2.25,2.22,2.19,2.12,2.15,2.21,2.46,2.53,2.55,2.41,2.36,2.30,2.34,2.31,3.18,2.58,2.48,2.40,2.37,2.46,2.44,2.43,2.43,2.41,2.44,2.42,2.42,2.42,2.40,2.38,2.40,2.31,2.28,2.24,2.19,2.18,2.16,2.19,2.32,2.51,2.59,2.46,2.44,2.38,2.47,2.42,3.27,2.68,2.49,2.45,2.38,2.27,2.25,2.44,2.44,2.45,2.48,2.49},
7026    {1.39,1.53,2.31,1.92,1.80,1.67,1.61,1.60,1.60,2.03,2.67,2.34,2.18,2.09,2.01,2.02,2.00,2.03,3.00,2.40,2.21,2.15,2.13,2.10,2.10,2.09,2.03,2.08,2.27,2.27,2.28,2.21,2.13,2.14,2.17,2.15,3.09,2.46,2.31,2.28,2.23,2.20,2.17,2.10,2.13,2.19,2.44,2.51,2.53,2.39,2.34,2.28,2.32,2.29,3.16,2.56,2.46,2.38,2.35,2.44,2.42,2.41,2.41,2.39,2.42,2.40,2.40,2.40,2.38,2.36,2.38,2.29,2.26,2.22,2.17,2.16,2.14,2.17,2.30,2.49,2.57,2.44,2.42,2.36,2.45,2.40,3.25,2.66,2.47,2.43,2.36,2.25,2.23,2.42,2.42,2.43,2.46,2.47},
7027    {1.42,1.56,2.34,1.95,1.83,1.70,1.64,1.63,1.63,2.06,2.70,2.37,2.21,2.12,2.04,2.05,2.03,2.06,3.03,2.43,2.24,2.18,2.16,2.13,2.13,2.12,2.06,2.11,2.30,2.30,2.31,2.24,2.16,2.17,2.20,2.18,3.12,2.49,2.34,2.31,2.26,2.23,2.20,2.13,2.16,2.22,2.47,2.54,2.56,2.42,2.37,2.31,2.35,2.32,3.19,2.59,2.49,2.41,2.38,2.47,2.45,2.44,2.44,2.42,2.45,2.43,2.43,2.43,2.41,2.39,2.41,2.32,2.29,2.25,2.20,2.19,2.17,2.20,2.33,2.52,2.60,2.47,2.45,2.39,2.48,2.43,3.28,2.69,2.50,2.46,2.39,2.28,2.26,2.45,2.45,2.46,2.49,2.50},
7028    {1.55,1.69,2.47,2.08,1.96,1.83,1.77,1.76,1.76,2.19,2.83,2.50,2.34,2.25,2.17,2.18,2.16,2.19,3.16,2.56,2.37,2.31,2.29,2.26,2.26,2.25,2.19,2.24,2.43,2.43,2.44,2.37,2.29,2.30,2.33,2.31,3.25,2.62,2.47,2.44,2.39,2.36,2.33,2.26,2.29,2.35,2.60,2.67,2.69,2.55,2.50,2.44,2.48,2.45,3.32,2.72,2.62,2.54,2.51,2.60,2.58,2.57,2.57,2.55,2.58,2.56,2.56,2.56,2.54,2.52,2.54,2.45,2.42,2.38,2.33,2.32,2.30,2.33,2.46,2.65,2.73,2.60,2.58,2.52,2.61,2.56,3.41,2.82,2.63,2.59,2.52,2.41,2.39,2.58,2.58,2.59,2.62,2.63},
7029    {1.74,1.88,2.66,2.27,2.15,2.02,1.96,1.95,1.95,2.38,3.02,2.69,2.53,2.44,2.36,2.37,2.35,2.38,3.35,2.75,2.56,2.50,2.48,2.45,2.45,2.44,2.38,2.43,2.62,2.62,2.63,2.56,2.48,2.49,2.52,2.50,3.44,2.81,2.66,2.63,2.58,2.55,2.52,2.45,2.48,2.54,2.79,2.86,2.88,2.74,2.69,2.63,2.67,2.64,3.51,2.91,2.81,2.73,2.70,2.79,2.77,2.76,2.76,2.74,2.77,2.75,2.75,2.75,2.73,2.71,2.73,2.64,2.61,2.57,2.52,2.51,2.49,2.52,2.65,2.84,2.92,2.79,2.77,2.71,2.80,2.75,3.60,3.01,2.82,2.78,2.71,2.60,2.58,2.77,2.77,2.78,2.81,2.82},
7030    {1.82,1.96,2.74,2.35,2.23,2.10,2.04,2.03,2.03,2.46,3.10,2.77,2.61,2.52,2.44,2.45,2.43,2.46,3.43,2.83,2.64,2.58,2.56,2.53,2.53,2.52,2.46,2.51,2.70,2.70,2.71,2.64,2.56,2.57,2.60,2.58,3.52,2.89,2.74,2.71,2.66,2.63,2.60,2.53,2.56,2.62,2.87,2.94,2.96,2.82,2.77,2.71,2.75,2.72,3.59,2.99,2.89,2.81,2.78,2.87,2.85,2.84,2.84,2.82,2.85,2.83,2.83,2.83,2.81,2.79,2.81,2.72,2.69,2.65,2.60,2.59,2.57,2.60,2.73,2.92,3.00,2.87,2.85,2.79,2.88,2.83,3.68,3.09,2.90,2.86,2.79,2.68,2.66,2.85,2.85,2.86,2.89,2.90},
7031    {1.69,1.83,2.61,2.22,2.10,1.97,1.91,1.90,1.90,2.33,2.97,2.64,2.48,2.39,2.31,2.32,2.30,2.33,3.30,2.70,2.51,2.45,2.43,2.40,2.40,2.39,2.33,2.38,2.57,2.57,2.58,2.51,2.43,2.44,2.47,2.45,3.39,2.76,2.61,2.58,2.53,2.50,2.47,2.40,2.43,2.49,2.74,2.81,2.83,2.69,2.64,2.58,2.62,2.59,3.46,2.86,2.76,2.68,2.65,2.74,2.72,2.71,2.71,2.69,2.72,2.70,2.70,2.70,2.68,2.66,2.68,2.59,2.56,2.52,2.47,2.46,2.44,2.47,2.60,2.79,2.87,2.74,2.72,2.66,2.75,2.70,3.55,2.96,2.77,2.73,2.66,2.55,2.53,2.72,2.72,2.73,2.76,2.77},
7032    {1.67,1.81,2.59,2.20,2.08,1.95,1.89,1.88,1.88,2.31,2.95,2.62,2.46,2.37,2.29,2.30,2.28,2.31,3.28,2.68,2.49,2.43,2.41,2.38,2.38,2.37,2.31,2.36,2.55,2.55,2.56,2.49,2.41,2.42,2.45,2.43,3.37,2.74,2.59,2.56,2.51,2.48,2.45,2.38,2.41,2.47,2.72,2.79,2.81,2.67,2.62,2.56,2.60,2.57,3.44,2.84,2.74,2.66,2.63,2.72,2.70,2.69,2.69,2.67,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.57,2.54,2.50,2.45,2.44,2.42,2.45,2.58,2.77,2.85,2.72,2.70,2.64,2.73,2.68,3.53,2.94,2.75,2.71,2.64,2.53,2.51,2.70,2.70,2.71,2.74,2.75},
7033    {1.61,1.75,2.53,2.14,2.02,1.89,1.83,1.82,1.82,2.25,2.89,2.56,2.40,2.31,2.23,2.24,2.22,2.25,3.22,2.62,2.43,2.37,2.35,2.32,2.32,2.31,2.25,2.30,2.49,2.49,2.50,2.43,2.35,2.36,2.39,2.37,3.31,2.68,2.53,2.50,2.45,2.42,2.39,2.32,2.35,2.41,2.66,2.73,2.75,2.61,2.56,2.50,2.54,2.51,3.38,2.78,2.68,2.60,2.57,2.66,2.64,2.63,2.63,2.61,2.64,2.62,2.62,2.62,2.60,2.58,2.60,2.51,2.48,2.44,2.39,2.38,2.36,2.39,2.52,2.71,2.79,2.66,2.64,2.58,2.67,2.62,3.47,2.88,2.69,2.65,2.58,2.47,2.45,2.64,2.64,2.65,2.68,2.69},
7034    {1.70,1.84,2.62,2.23,2.11,1.98,1.92,1.91,1.91,2.34,2.98,2.65,2.49,2.40,2.32,2.33,2.31,2.34,3.31,2.71,2.52,2.46,2.44,2.41,2.41,2.40,2.34,2.39,2.58,2.58,2.59,2.52,2.44,2.45,2.48,2.46,3.40,2.77,2.62,2.59,2.54,2.51,2.48,2.41,2.44,2.50,2.75,2.82,2.84,2.70,2.65,2.59,2.63,2.60,3.47,2.87,2.77,2.69,2.66,2.75,2.73,2.72,2.72,2.70,2.73,2.71,2.71,2.71,2.69,2.67,2.69,2.60,2.57,2.53,2.48,2.47,2.45,2.48,2.61,2.80,2.88,2.75,2.73,2.67,2.76,2.71,3.56,2.97,2.78,2.74,2.67,2.56,2.54,2.73,2.73,2.74,2.77,2.78},
7035    {1.65,1.79,2.57,2.18,2.06,1.93,1.87,1.86,1.86,2.29,2.93,2.60,2.44,2.35,2.27,2.28,2.26,2.29,3.26,2.66,2.47,2.41,2.39,2.36,2.36,2.35,2.29,2.34,2.53,2.53,2.54,2.47,2.39,2.40,2.43,2.41,3.35,2.72,2.57,2.54,2.49,2.46,2.43,2.36,2.39,2.45,2.70,2.77,2.79,2.65,2.60,2.54,2.58,2.55,3.42,2.82,2.72,2.64,2.61,2.70,2.68,2.67,2.67,2.65,2.68,2.66,2.66,2.66,2.64,2.62,2.64,2.55,2.52,2.48,2.43,2.42,2.40,2.43,2.56,2.75,2.83,2.70,2.68,2.62,2.71,2.66,3.51,2.92,2.73,2.69,2.62,2.51,2.49,2.68,2.68,2.69,2.72,2.73},
7036    {2.50,2.64,3.42,3.03,2.91,2.78,2.72,2.71,2.71,3.14,3.78,3.45,3.29,3.20,3.12,3.13,3.11,3.14,4.11,3.51,3.32,3.26,3.24,3.21,3.21,3.20,3.14,3.19,3.38,3.38,3.39,3.32,3.24,3.25,3.28,3.26,4.20,3.57,3.42,3.39,3.34,3.31,3.28,3.21,3.24,3.30,3.55,3.62,3.64,3.50,3.45,3.39,3.43,3.40,4.27,3.67,3.57,3.49,3.46,3.55,3.53,3.52,3.52,3.50,3.53,3.51,3.51,3.51,3.49,3.47,3.49,3.40,3.37,3.33,3.28,3.27,3.25,3.28,3.41,3.60,3.68,3.55,3.53,3.47,3.56,3.51,4.36,3.77,3.58,3.54,3.47,3.36,3.34,3.53,3.53,3.54,3.57,3.58},
7037    {1.91,2.05,2.83,2.44,2.32,2.19,2.13,2.12,2.12,2.55,3.19,2.86,2.70,2.61,2.53,2.54,2.52,2.55,3.52,2.92,2.73,2.67,2.65,2.62,2.62,2.61,2.55,2.60,2.79,2.79,2.80,2.73,2.65,2.66,2.69,2.67,3.61,2.98,2.83,2.80,2.75,2.72,2.69,2.62,2.65,2.71,2.96,3.03,3.05,2.91,2.86,2.80,2.84,2.81,3.68,3.08,2.98,2.90,2.87,2.96,2.94,2.93,2.93,2.91,2.94,2.92,2.92,2.92,2.90,2.88,2.90,2.81,2.78,2.74,2.69,2.68,2.66,2.69,2.82,3.01,3.09,2.96,2.94,2.88,2.97,2.92,3.77,3.18,2.99,2.95,2.88,2.77,2.75,2.94,2.94,2.95,2.98,2.99},
7038    {1.72,1.86,2.64,2.25,2.13,2.00,1.94,1.93,1.93,2.36,3.00,2.67,2.51,2.42,2.34,2.35,2.33,2.36,3.33,2.73,2.54,2.48,2.46,2.43,2.43,2.42,2.36,2.41,2.60,2.60,2.61,2.54,2.46,2.47,2.50,2.48,3.42,2.79,2.64,2.61,2.56,2.53,2.50,2.43,2.46,2.52,2.77,2.84,2.86,2.72,2.67,2.61,2.65,2.62,3.49,2.89,2.79,2.71,2.68,2.77,2.75,2.74,2.74,2.72,2.75,2.73,2.73,2.73,2.71,2.69,2.71,2.62,2.59,2.55,2.50,2.49,2.47,2.50,2.63,2.82,2.90,2.77,2.75,2.69,2.78,2.73,3.58,2.99,2.80,2.76,2.69,2.58,2.56,2.75,2.75,2.76,2.79,2.80},
7039    {1.68,1.82,2.60,2.21,2.09,1.96,1.90,1.89,1.89,2.32,2.96,2.63,2.47,2.38,2.30,2.31,2.29,2.32,3.29,2.69,2.50,2.44,2.42,2.39,2.39,2.38,2.32,2.37,2.56,2.56,2.57,2.50,2.42,2.43,2.46,2.44,3.38,2.75,2.60,2.57,2.52,2.49,2.46,2.39,2.42,2.48,2.73,2.80,2.82,2.68,2.63,2.57,2.61,2.58,3.45,2.85,2.75,2.67,2.64,2.73,2.71,2.70,2.70,2.68,2.71,2.69,2.69,2.69,2.67,2.65,2.67,2.58,2.55,2.51,2.46,2.45,2.43,2.46,2.59,2.78,2.86,2.73,2.71,2.65,2.74,2.69,3.54,2.95,2.76,2.72,2.65,2.54,2.52,2.71,2.71,2.72,2.75,2.76},
7040    {1.61,1.75,2.53,2.14,2.02,1.89,1.83,1.82,1.82,2.25,2.89,2.56,2.40,2.31,2.23,2.24,2.22,2.25,3.22,2.62,2.43,2.37,2.35,2.32,2.32,2.31,2.25,2.30,2.49,2.49,2.50,2.43,2.35,2.36,2.39,2.37,3.31,2.68,2.53,2.50,2.45,2.42,2.39,2.32,2.35,2.41,2.66,2.73,2.75,2.61,2.56,2.50,2.54,2.51,3.38,2.78,2.68,2.60,2.57,2.66,2.64,2.63,2.63,2.61,2.64,2.62,2.62,2.62,2.60,2.58,2.60,2.51,2.48,2.44,2.39,2.38,2.36,2.39,2.52,2.71,2.79,2.66,2.64,2.58,2.67,2.62,3.47,2.88,2.69,2.65,2.58,2.47,2.45,2.64,2.64,2.65,2.68,2.69},
7041    {1.50,1.64,2.42,2.03,1.91,1.78,1.72,1.71,1.71,2.14,2.78,2.45,2.29,2.20,2.12,2.13,2.11,2.14,3.11,2.51,2.32,2.26,2.24,2.21,2.21,2.20,2.14,2.19,2.38,2.38,2.39,2.32,2.24,2.25,2.28,2.26,3.20,2.57,2.42,2.39,2.34,2.31,2.28,2.21,2.24,2.30,2.55,2.62,2.64,2.50,2.45,2.39,2.43,2.40,3.27,2.67,2.57,2.49,2.46,2.55,2.53,2.52,2.52,2.50,2.53,2.51,2.51,2.51,2.49,2.47,2.49,2.40,2.37,2.33,2.28,2.27,2.25,2.28,2.41,2.60,2.68,2.55,2.53,2.47,2.56,2.51,3.36,2.77,2.58,2.54,2.47,2.36,2.34,2.53,2.53,2.54,2.57,2.58},
7042    {1.48,1.62,2.40,2.01,1.89,1.76,1.70,1.69,1.69,2.12,2.76,2.43,2.27,2.18,2.10,2.11,2.09,2.12,3.09,2.49,2.30,2.24,2.22,2.19,2.19,2.18,2.12,2.17,2.36,2.36,2.37,2.30,2.22,2.23,2.26,2.24,3.18,2.55,2.40,2.37,2.32,2.29,2.26,2.19,2.22,2.28,2.53,2.60,2.62,2.48,2.43,2.37,2.41,2.38,3.25,2.65,2.55,2.47,2.44,2.53,2.51,2.50,2.50,2.48,2.51,2.49,2.49,2.49,2.47,2.45,2.47,2.38,2.35,2.31,2.26,2.25,2.23,2.26,2.39,2.58,2.66,2.53,2.51,2.45,2.54,2.49,3.34,2.75,2.56,2.52,2.45,2.34,2.32,2.51,2.51,2.52,2.55,2.56},
7043    {1.67,1.81,2.59,2.20,2.08,1.95,1.89,1.88,1.88,2.31,2.95,2.62,2.46,2.37,2.29,2.30,2.28,2.31,3.28,2.68,2.49,2.43,2.41,2.38,2.38,2.37,2.31,2.36,2.55,2.55,2.56,2.49,2.41,2.42,2.45,2.43,3.37,2.74,2.59,2.56,2.51,2.48,2.45,2.38,2.41,2.47,2.72,2.79,2.81,2.67,2.62,2.56,2.60,2.57,3.44,2.84,2.74,2.66,2.63,2.72,2.70,2.69,2.69,2.67,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.57,2.54,2.50,2.45,2.44,2.42,2.45,2.58,2.77,2.85,2.72,2.70,2.64,2.73,2.68,3.53,2.94,2.75,2.71,2.64,2.53,2.51,2.70,2.70,2.71,2.74,2.75},
7044    {1.67,1.81,2.59,2.20,2.08,1.95,1.89,1.88,1.88,2.31,2.95,2.62,2.46,2.37,2.29,2.30,2.28,2.31,3.28,2.68,2.49,2.43,2.41,2.38,2.38,2.37,2.31,2.36,2.55,2.55,2.56,2.49,2.41,2.42,2.45,2.43,3.37,2.74,2.59,2.56,2.51,2.48,2.45,2.38,2.41,2.47,2.72,2.79,2.81,2.67,2.62,2.56,2.60,2.57,3.44,2.84,2.74,2.66,2.63,2.72,2.70,2.69,2.69,2.67,2.70,2.68,2.68,2.68,2.66,2.64,2.66,2.57,2.54,2.50,2.45,2.44,2.42,2.45,2.58,2.77,2.85,2.72,2.70,2.64,2.73,2.68,3.53,2.94,2.75,2.71,2.64,2.53,2.51,2.70,2.70,2.71,2.74,2.75},
7045    {1.68,1.82,2.60,2.21,2.09,1.96,1.90,1.89,1.89,2.32,2.96,2.63,2.47,2.38,2.30,2.31,2.29,2.32,3.29,2.69,2.50,2.44,2.42,2.39,2.39,2.38,2.32,2.37,2.56,2.56,2.57,2.50,2.42,2.43,2.46,2.44,3.38,2.75,2.60,2.57,2.52,2.49,2.46,2.39,2.42,2.48,2.73,2.80,2.82,2.68,2.63,2.57,2.61,2.58,3.45,2.85,2.75,2.67,2.64,2.73,2.71,2.70,2.70,2.68,2.71,2.69,2.69,2.69,2.67,2.65,2.67,2.58,2.55,2.51,2.46,2.45,2.43,2.46,2.59,2.78,2.86,2.73,2.71,2.65,2.74,2.69,3.54,2.95,2.76,2.72,2.65,2.54,2.52,2.71,2.71,2.72,2.75,2.76},
7046    {1.71,1.85,2.63,2.24,2.12,1.99,1.93,1.92,1.92,2.35,2.99,2.66,2.50,2.41,2.33,2.34,2.32,2.35,3.32,2.72,2.53,2.47,2.45,2.42,2.42,2.41,2.35,2.40,2.59,2.59,2.60,2.53,2.45,2.46,2.49,2.47,3.41,2.78,2.63,2.60,2.55,2.52,2.49,2.42,2.45,2.51,2.76,2.83,2.85,2.71,2.66,2.60,2.64,2.61,3.48,2.88,2.78,2.70,2.67,2.76,2.74,2.73,2.73,2.71,2.74,2.72,2.72,2.72,2.70,2.68,2.70,2.61,2.58,2.54,2.49,2.48,2.46,2.49,2.62,2.81,2.89,2.76,2.74,2.68,2.77,2.72,3.57,2.98,2.79,2.75,2.68,2.57,2.55,2.74,2.74,2.75,2.78,2.79},
7047    {1.72,1.86,2.64,2.25,2.13,2.00,1.94,1.93,1.93,2.36,3.00,2.67,2.51,2.42,2.34,2.35,2.33,2.36,3.33,2.73,2.54,2.48,2.46,2.43,2.43,2.42,2.36,2.41,2.60,2.60,2.61,2.54,2.46,2.47,2.50,2.48,3.42,2.79,2.64,2.61,2.56,2.53,2.50,2.43,2.46,2.52,2.77,2.84,2.86,2.72,2.67,2.61,2.65,2.62,3.49,2.89,2.79,2.71,2.68,2.77,2.75,2.74,2.74,2.72,2.75,2.73,2.73,2.73,2.71,2.69,2.71,2.62,2.59,2.55,2.50,2.49,2.47,2.50,2.63,2.82,2.90,2.77,2.75,2.69,2.78,2.73,3.58,2.99,2.80,2.76,2.69,2.58,2.56,2.75,2.75,2.76,2.79,2.80}
7048 	};
7049 
7050 static char *elements[] = {
7051 	"Bq","H","He","Li","Be","B","C","N","O","F","Ne",
7052 	"Na","Mg","Al","Si","P","S","Cl","Ar",
7053 	"K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu",
7054 	"Zn","Ga","Ge","As","Se","Br","Kr",
7055 	"Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag",
7056 	"Cd","In","Sn","Sb","Te","I","Xe",
7057 	"Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy",
7058 	"Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt",
7059 	"Au","Hg","Tl","Pb","Bi","Po","At","Rn",
7060 	"Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","X"};
7061 
7062 static char *elemts[] = { " H","He",
7063       "Li","Be"," B"," C"," N"," O"," F","Ne",
7064       "Na","Mg","Al","Si"," P"," S","Cl","Ar",
7065       " K","Ca","Sc","Ti"," V","Cr","Mn","Fe","Co","Ni","Cu",
7066       "Zn","Ga","Ge","As","Se","Br","Kr",
7067       "Rb","Sr"," Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag",
7068       "Cd","In","Sn","Sb","Te"," I","Xe",
7069       "Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy",
7070       "Ho","Er","Tm","Yb","Lu","Hf","Ta"," W","Re","Os","Ir","Pt",
7071       "Au","Hg","Tl","Pb","Bi","Po","At","Rn",
7072       "Fr","Ra","Ac","Th","Pa"," U","Np","Pu","Am","Cm","Bk","Cf",
7073       "XX","  "};
7074 
7075 static char *ATYPE[] = {
7076 	"    ",".1  ",".2  ",".3  ",".4  ",".ar ",".cat",
7077 	".am ",".pl3",".co2",".spc",".t3p",".O  ",".O2 "};
7078 
7079 static int IHBT[] = {
7080 	3     ,  1   ,  2   ,  3   ,  3   ,  4   ,  4   ,
7081 	3     ,  3   ,  2   ,  3   ,  3   ,  2   ,  2 };
7082 
7083 #define ZC_DEF 1
7084 #define ZC_CONN 0
7085 #define ZC_AT1 3
7086 #define ZC_AT2 4
7087 #define ZC_MARK -7
7088 #define ZC_VAR  ZC_DEF
7089 #define ZC_CONST -4
7090 #define ZC_LINK -13
7091 
7092 #define MAXFRPNT 3000
7093 typedef struct { Window win;
7094 		 double *fpts;
7095                  int *x;
7096                  int *y;
7097                  int *index;
7098                  int npts;
7099 		 int current;
7100 		 int yelev;
7101 		 int color;
7102 		 int wide;
7103 		 int high;
7104                 } FRSTRU;
7105 
7106 void drwgra(FRSTRU *tabptr,int yelev,Window gwin,int wide,int high,int *isav,double *fpts,int jbeg,int jend,int nents,double fmax,double fmin,double flim,int icol,int ifr,char *xstr,char *ystr,char *labstr,int isdash,int init,int notsav,int ityp);
7107 void parse_motion(FRSTRU *tabptr);
7108 static char *frsym[MAXFRQ];
7109 static int nfr = 0;
7110 
7111 static FRSTRU scfEfirst = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7112 static FRSTRU scfElast = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7113 
7114 static FRSTRU geoFmax = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7115 static FRSTRU geoFrms = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7116 static FRSTRU geoSmax = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7117 static FRSTRU geoSrms = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7118 static FRSTRU geoE = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7119 
7120 static FRSTRU spect = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7121 static FRSTRU docksco = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7122 
7123 static FRSTRU RamaStru = { 0, NULL, NULL, NULL, NULL,-1,0,0,0,0,0};
7124 
7125 static int *npmfs;
7126 static double *ewin = NULL;
7127 
7128 /* Spectrum variables */
7129 #define SPBHIGH  90
7130 static int SPECWIDE = 600;
7131 static int SPECHIGH = 300;
7132 #define NSBUTTS 7
7133 static int nsbutts = 6;
7134 static BSTRU spbut[NSBUTTS];
7135 static char *pktyp[] = {"Gaussian", "Lorentzian"};
7136 static char *sptyp[] = {"Infra Red", "Raman"};
7137 static char *nmrsptyp[] = {"1H", "13C"};
7138 static char *uvsptyp[] = {"UV spectrum"};
7139 static double *spint;
7140 static float *spfrq;
7141 static int *spnfrq;
7142 static int nspqbox = 5;
7143 static double *out_spec = NULL;
7144 static char *splab = NULL;
7145 static char *forlab = "Frequency";
7146 static char *uvlab = "Excitation Energy (nm)";
7147 static char *nmrlab = "Shift (ppm)";
7148 static float NMRbas = 100.0;
7149 static int NMRnuc = 1;
7150 static int specsize = 0;
7151 static int lorentzian = 1;
7152 static int spmode = 0;
7153 static double hwhm = 20.0;
7154 static double spec_mx;
7155 static double spec_mn;
7156 static double freq_step = 1.0;
7157 static double freq_scale = 1.0;
7158 static int min_freq = 0;
7159 static int max_freq = 4000;
7160 static int n_freqs = 2;
7161 static int specps = 0;
7162 static FILE *spout;
7163 
7164 #define mxcpl 5
7165 #define mxpeak 2*2*2*2*2
7166 static float *peaks  = NULL;
7167 static double *inten  = NULL;
7168 static int npks = 0;
7169 static float jcut  = 1.0;
7170 static float nmr1Href  = 32.78;
7171 static float nmr13Cref  = 194.47;
7172 static float nmr1Hstep = 0.001;
7173 static float nmr13Cstep = 0.01;
7174 static float *nmrref  = &nmr1Href;
7175 static int NMRup = 0;
7176 void FRQextr();
7177 void INTextr();
7178 
7179 void updcallb(char *str);
7180 void disp_map(char *str);
7181 void srfprop();
7182 void deletebox();
7183 
7184 /* pmf score variables */
7185 #define NSCBUTTS 6
7186 static BSTRU scbut[NSCBUTTS];
7187 
7188 #define NPBUTTS 1
7189 static BSTRU pbut[NPBUTTS];
7190 
7191 static double *pmfmn;
7192 static double *pmfmx;
7193 static double *pmflga;
7194 static int *ipmfmn;
7195 static int *ipmfmx;
7196 static int *npmfmx;
7197 static int *ialtyp = NULL;
7198 static int *iscst;
7199 static int *iocnt;
7200 static int *ipmfm;
7201 static int *ipmfh;
7202 static int *levcol;
7203 
7204 static int *logo;
7205 static int *nscnd;
7206 static int *dolabs;
7207 static int *forces_yes_no;
7208 static int *ifogl;
7209 static int *ifdogl;
7210 static int *fullgl;
7211 static int *icst;
7212 static int *ibox;
7213 static int *igfmap;
7214 static int *iresrd;
7215 static int srfsep;
7216 static int srftyp;
7217 static int *doesp;
7218 static int *doshad;
7219 static int *ihasex;
7220 static int *noshad;
7221 static int *ionoff;
7222 static int *icommf;
7223 
7224 #define AVG(a,b) (((a) + (b))/2)
7225 #define MIDDLEX(f,x,str) ((x)-XTextWidth(f,str,strlen(str))/2)
7226 #define MIDDLEY(f,y) ((y)-((f->ascent+f->descent)/2)+f->ascent)
7227 #define VIERKANT(x,y,rx,ry,rw,rh) \
7228            ((x)>=(rx) && (y)>=(ry) && (x)<=(rx)+(rw) && (y)<=(ry)+(rh))
7229 #define SPACING 3
7230 #define ASCENT   (mfinfo->ascent)
7231 #define DESCENT  (mfinfo->descent)
7232 #define CHIGH    (ASCENT + DESCENT)
7233 #define LINEHIGH (CHIGH + SPACING)
7234 #define WINCWIDE  260
7235 #define WINCHIGH  435
7236 #define DEFWINCGEOM "-130+80"
7237 
7238 #define CNTCOL -15
7239 #ifdef DOGL
7240 #define NBUTTS   35
7241 #else
7242 #define NBUTTS   34
7243 #endif
7244 
7245 #define BPSI     0
7246 #define BHOMO    1
7247 #define BLUMO    2
7248 #define BNDEN    3
7249 #define BBONDS   4
7250 #define BATOM    5
7251 #define BOVRLP   6
7252 #define BPOST    7
7253 #define BMOLMOD  8
7254 #define BQUIT    9
7255 #define BEUCL    10
7256 #define B3D      11
7257 #define BINCRS   12
7258 #define BDECRS   13
7259 #define BCONT    14
7260 #define BMOL     15
7261 #define BCOMM    16
7262 #define BORI     17
7263 #define BSTEP    18
7264 #define BCUT     19
7265 #define BWRBAS   20
7266 #define BRDBAS   21
7267 #define B3DX     22
7268 #define BSPACE   23
7269 #define BFILL    24
7270 #define BELPOT   25
7271 #define BMAXMIN  26
7272 #define BVRML2   27
7273 #define BLAPL    28
7274 #define BSRF2    29
7275 #define BCUBE    30
7276 #define BGIF2    31
7277 #define BLOCAL   32
7278 #define BELF     33
7279 #define BOGL     34
7280 
7281 #define NBUTTS2  47
7282 
7283 #define BFIRST   0
7284 #define BNEXT    1
7285 #define BSOLID   2
7286 #define BPOSTT   3
7287 #define BDENMOD  4
7288 #define BQUITT   5
7289 #define BFORC    6
7290 #define BINCRF   7
7291 #define BDECRF   8
7292 #define BUNSC    9
7293 #define BDIST    10
7294 #define BANGLE   11
7295 #define BDIHED   12
7296 #define BAUTH    13
7297 #define BLABEL   14
7298 #define BCONV    15
7299 #define BGEOM    16
7300 #define BZOOMIN  17
7301 #define BZOOMOUT 18
7302 #define BSHADE   19
7303 #define BBACKB   20
7304 #define BATCOL   21
7305 #define BPERSP   22
7306 #define BLEFT    23
7307 #define BRIGHT   24
7308 #define BUP      25
7309 #define BDOWN    26
7310 #define BMOVIE   27
7311 #define BZMAT    28
7312 #define BREADF   29
7313 #define BHBOND   30
7314 #define BPACE    31
7315 #define BGIF     32
7316 #define BPAL     33
7317 #define BCELL    34
7318 #define BORIG    35
7319 #define BSURF    36
7320 #define BVRML    37
7321 #define BHYD     38
7322 #define BWRITF   39
7323 #define BALIGN   40
7324 #define BBALL    41
7325 #define BHOUR    42
7326 #define BMOLF    43
7327 #define BPREV    44
7328 #define BJCPL    45
7329 #define BMOV     46
7330 
7331 #define NBUTTR   6
7332 
7333 #define BDIR      0
7334 #define BCAN      1
7335 #define BREP      2
7336 #define BADD      3
7337 #define BPDB      4
7338 #define BSPDB     5
7339 
7340 
7341 #define NQBOX   95
7342 
7343 #define QORB     0
7344 #define QCOMM    1
7345 #define QPOST    2
7346 #define QSPAC    3
7347 #define QSTEP    4
7348 #define QCUT     5
7349 #define QPOSTT   6
7350 #define QRESI    7
7351 #define QHBOND   8
7352 #define QREADF   9
7353 #define QBZMAT  10
7354 #define QFRAG   11
7355 #define QVRML   12
7356 #define QCSPACE 13
7357 #define QMXYZ   14
7358 #define QGLIN1  15
7359 #define QGLIN2  16
7360 #define QGTITL  17
7361 #define QJNAME  18
7362 #define QQNAME  19
7363 #define QENAME  20
7364 #define QTIME   21
7365 #define QRADI   22
7366 #define QCPA    23
7367 #define QCPB    24
7368 #define QCPC    25
7369 #define QCPAL   26
7370 #define QCPBE   27
7371 #define QCPGA   28
7372 #define QCPSPGN 29
7373 #define QCPSPGS 30
7374 #define QSRFW   31
7375 #define QSRFR   32
7376 #define QEDGE   33
7377 #define QVALC1  34
7378 #define QVALC2  35
7379 #define QVALC3  36
7380 #define QNPTS   37
7381 #define QCHARG  38
7382 #define QRSD    39
7383 #define QATOM   40
7384 #define QPHI    41
7385 #define QPSI    42
7386 #define QPROT   43
7387 #define QGRD    44
7388 #define QARCH   45
7389 #define QTNKJN  46
7390 #define QMAXIT  47
7391 #define QCUBE   48
7392 #define QCTA    49
7393 #define QCTB    50
7394 #define QCTC    51
7395 #define QNSCAL  52
7396 #define QVFILE  53
7397 #define QMFILE  54
7398 #define QCNTVAL 55
7399 #define QCOLVAL1 56
7400 #define QCOLVAL2 57
7401 #define QCOLVAL3 58
7402 #define QCOLVAL4 59
7403 #define QCOLVAL5 60
7404 #define QPOLVAL1 61
7405 #define QPOLVAL2 62
7406 #define QSVFILE  63
7407 #define QSCNT    64
7408 #define QHW      65
7409 #define QMINF    66
7410 #define QMAXF    67
7411 #define QSSCAL   68
7412 #define QIMAX    69
7413 #define QTMS     70
7414 #define QFREQ    71
7415 #define QSFIL    72
7416 #define QDEL     73
7417 #define QCNT     74
7418 #define QHBMIN   75
7419 #define QHBMAX   76
7420 #define QHAMIN   77
7421 #define QHAMAX   78
7422 #define QPDB     79
7423 #define QCNT2    80
7424 #define QSUBSTR  81
7425 #define QMOV     82
7426 #define QSRCH    83
7427 #define QCHRG2   84
7428 #define QRESF    85
7429 #define QQUERY   86
7430 #define QNRES    87
7431 #define QPHRMT   88
7432 #define QPHRMR   89
7433 #define QSCSDF   90
7434 #define QCRIND   91
7435 #define QDCKFI   92
7436 #define QDCKSL   93
7437 #define QDCKOUT  94
7438 
7439 #define NBUTSS  16
7440 
7441 #define SMETH   0
7442 #define SCLOS   1
7443 #define SSUBM   2
7444 #define STASK   3
7445 #define SBASS   4
7446 #define SCHAR   5
7447 #define SSPIN   6
7448 #define SMOLD   7
7449 #define SDIRE   8
7450 #define SBATC   9
7451 #define SHESS  10
7452 #define SREST  11
7453 #define SQUEU  12
7454 #define SZMAT  13
7455 #define SWXYZ  14
7456 #define SONI   15
7457 
7458 #define NBUTCP  2
7459 #define NBUTCT  4
7460 #define BCPAPP  0
7461 #define BCPCAN  1
7462 
7463 #define NCLBUT  5
7464 #define BMONI   0
7465 #define BCLR    1
7466 #define BCLOSE  2
7467 #define BCNTCT  3
7468 #define BCONN   4
7469 
7470 static BSTRU dbut[NBUTTS];
7471 static BSTRU cbut[NBUTTS2];
7472 static BSTRU rbut[NBUTTR];
7473 static BSTRU clbut[NCLBUT];
7474 static BSTRU obut[2];
7475 static BSTRU sbut[NBUTSS];
7476 static BSTRU cpbut[NBUTCP];
7477 static BSTRU ctbut[NBUTCT];
7478 static FSELSTRU fsel;
7479 static FSELSTRU gsel;
7480 static FSELSTRU dsel;
7481 static LISTSTRU flist;
7482 static LISTSTRU dirlist;
7483 static LISTSTRU frlist;
7484 static LISTSTRU elist;
7485 static LISTSTRU fftlist;
7486 static LISTSTRU srchlist;
7487 static LISTSTRU pmflistmx;
7488 static LISTSTRU pmflistmn;
7489 static LISTSTRU flxlist;
7490 static LISTSTRU strlist;
7491 static LISTSTRU str2list;
7492 static LISTSTRU strclist;
7493 static QBOXSTRU qboxes[NQBOX];
7494 
7495 static int *Sinct;
7496 static int *Sincp;
7497 
7498 #define MAXFILELEN 1024
7499 #define NFLS 13
7500 static int    lpnt = 0;
7501 static int    selfil = 0;
7502 static int    firstreadf = 1;
7503 static int    nfilesstart = 0;
7504 static char   firstfile[MAXFILELEN];
7505 static char   *pdbcode = NULL;
7506 static char   *pdbcbck = NULL;
7507 #define DIRX 35
7508 #define DIRY 40
7509 #define DIRW 255
7510 #define DIRH 200
7511 
7512 #define NDRS 4
7513 static int    seldir = 0;
7514 #define DDIRX 35
7515 #define DDIRY 250
7516 #define DDIRW 255
7517 #define DDIRH 76
7518 static int Fwinopt = BREP;
7519 
7520 #define BOFFX 14
7521 
7522 #define PLOFFX 0
7523 #define PLOFFY 0
7524 #define MSOFFX 0
7525 #define MSOFFY 219
7526 #define SPOFFX 0
7527 #define SPOFFY 342
7528 #define PMOFFX 139
7529 #define PMOFFY 0
7530 #define D3OFFX 139
7531 #define D3OFFY 94
7532 #define CNOFFX 139
7533 #define CNOFFY 219
7534 #define BSOFFX 139
7535 #define BSOFFY 293
7536 #define QOFFX 139
7537 #define QOFFY 367
7538 #define S2OFFX 5
7539 #define S2OFFY 403
7540 
7541 #define POFFX 0
7542 #define POFFY 0
7543 #define MOFFX 0
7544 #define MOFFY 100
7545 #define DMOFFX 0
7546 #define DMOFFY 224
7547 
7548 #define MIOFFX 107
7549 #define MIOFFY 0
7550 #define MICONY 5
7551 #define SOFFX 5
7552 #define SOFFY 412
7553 
7554 #define FOFFX 141
7555 #define FOFFY 0
7556 #define CLOFFX 141
7557 #define CLOFFY 145
7558 #define CVOFFX 141
7559 #define CVOFFY 240
7560 #define XOFFX 107
7561 #define XOFFY 314
7562 
7563 #define WINMCWIDE  248
7564 #define WINMCHIGH  445
7565 #define DEFWINMCGEOM "-130+80"
7566 static int DowinC = 1;
7567 static int DowinMC = 1;
7568 static int DoactC = 1;
7569 static int DoactMC = 1;
7570 static Bool DEBUG = 0;
7571 
7572 #define BUTTW   60
7573 #define BUTTH   19
7574 #define BUTTN   24
7575 #define TOGGWH  19
7576 
7577 static int dogif = 0;
7578 static int picnum = 0;
7579 static int *picmax;
7580 static char *GifFile = "mol";
7581 
7582 static Pixmap grayStip;
7583 static unsigned int  dispDEEP;
7584 
7585 float rama_area1[16][2] = {
7586 	{-177.5f,-180.0f},
7587 	{-177.5f,-177.5f},
7588 	{-172.5f,-177.5f},
7589 	{-172.5f,-172.5f},
7590 	{-167.5f,-172.5f},
7591 	{-167.5f,-167.5f},
7592 	{-127.5f,-167.5f},
7593 	{-127.5f,-172.5f},
7594 	{-97.5f,-172.5f},
7595 	{-97.5f,-167.5f},
7596 	{-77.5f,-167.5f},
7597 	{-77.5f,-172.5f},
7598 	{-72.5f,-172.5f},
7599 	{-72.5f,-177.5f},
7600 	{-67.5f,-177.5f},
7601 	{-67.5f,-180.0f},
7602 };
7603 
7604 float rama_area2[25][2] = {
7605 	{57.5f,67.5f},
7606 	{57.5f,62.5f},
7607 	{62.5f,62.5f},
7608 	{62.5f,57.5f},
7609 	{67.5f,57.5f},
7610 	{67.5f,47.5f},
7611 	{72.5f,47.5f},
7612 	{72.5f,32.5f},
7613 	{77.5f,32.5f},
7614 	{77.5f,2.5f},
7615 	{62.5f,2.5f},
7616 	{62.5f,7.5f},
7617 	{57.5f,7.5f},
7618 	{57.5f,12.5f},
7619 	{52.5f,12.5f},
7620 	{52.5f,22.5f},
7621 	{47.5f,22.5f},
7622 	{47.5f,27.5f},
7623 	{42.5f,27.5f},
7624 	{42.5f,37.5f},
7625 	{37.5f,37.5f},
7626 	{37.5f,62.5f},
7627 	{42.5f,62.5f},
7628 	{42.5f,67.5f},
7629 	{57.5f,67.5f}
7630 };
7631 
7632 float rama_area3[108][2] = {
7633 	{-62.5f,180.0f},
7634 	{-62.5f,172.5f},
7635 	{-57.5f,172.5f},
7636 	{-57.5f,167.5f},
7637 	{-52.5f,167.5f},
7638 	{-52.5f,157.5f},
7639 	{-47.5f,157.5f},
7640 	{-47.5f,147.5f},
7641 	{-42.5f,147.5f},
7642 	{-42.5f,137.5f},
7643 	{-37.5f,137.5f},
7644 	{-37.5f,122.5f},
7645 	{-42.5f,122.5f},
7646 	{-42.5f,117.5f},
7647 	{-47.5f,117.5f},
7648 	{-47.5f,112.5f},
7649 	{-57.5f,112.5f},
7650 	{-57.5f,107.5f},
7651 	{-62.5f,107.5f},
7652 	{-62.5f,102.5f},
7653 	{-67.5f,102.5f},
7654 	{-67.5f,97.5f},
7655 	{-72.5f,97.5f},
7656 	{-72.5f,62.5f},
7657 	{-77.5f,62.5f},
7658 	{-77.5f,52.5f},
7659 	{-87.5f,52.5f},
7660 	{-87.5f,47.5f},
7661 	{-92.5f,47.5f},
7662 	{-92.5f,52.5f},
7663 	{-97.5f,52.5f},
7664 	{-97.5f,67.5f},
7665 	{-102.5f,67.5f},
7666 	{-102.5f,77.5f},
7667 	{-107.5f,77.5f},
7668 	{-107.5f,82.5f},
7669 	{-112.5f,82.5f},
7670 	{-112.5f,72.5f},
7671 	{-117.5f,72.5f},
7672 	{-117.5f,62.5f},
7673 	{-122.5f,62.5f},
7674 	{-122.5f,52.5f},
7675 	{-127.5f,52.5f},
7676 	{-127.5f,47.5f},
7677 	{-112.5f,47.5f},
7678 	{-112.5f,42.5f},
7679 	{-102.5f,42.5f},
7680 	{-102.5f,37.5f},
7681 	{-92.5f,37.5f},
7682 	{-92.5f,32.5f},
7683 	{-87.5f,32.5f},
7684 	{-87.5f,22.5f},
7685 	{-82.5f,22.5f},
7686 	{-82.5f,17.5f},
7687 	{-77.5f,17.5f},
7688 	{-77.5f,12.5f},
7689 	{-67.5f,12.5f},
7690 	{-67.5f,7.5f},
7691 	{-62.5f,7.5f},
7692 	{-62.5f,2.5f},
7693 	{-57.5f,2.5f},
7694 	{-57.5f,-7.5f},
7695 	{-52.5f,-7.5f},
7696 	{-52.5f,-12.5f},
7697 	{-47.5f,-12.5f},
7698 	{-47.5f,-22.5f},
7699 	{-42.5f,-22.5f},
7700 	{-42.5f,-32.5f},
7701 	{-37.5f,-32.5f},
7702 	{-37.5f,-62.5f},
7703 	{-42.5f,-62.5f},
7704 	{-42.5f,-67.5f},
7705 	{-77.5f,-67.5f},
7706 	{-77.5f,-62.5f},
7707 	{-117.5f,-62.5f},
7708 	{-117.5f,-57.5f},
7709 	{-122.5f,-57.5f},
7710 	{-122.5f,-47.5f},
7711 	{-127.5f,-47.5f},
7712 	{-127.5f,-37.5f},
7713 	{-132.5f,-37.5f},
7714 	{-132.5f,-17.5f},
7715 	{-137.5f,-17.5f},
7716 	{-137.5f,2.5f},
7717 	{-142.5f,2.5f},
7718 	{-142.5f,32.5f},
7719 	{-137.5f,32.5f},
7720 	{-137.5f,52.5f},
7721 	{-142.5f,52.5f},
7722 	{-142.5f,57.5f},
7723 	{-147.5f,57.5f},
7724 	{-147.5f,67.5f},
7725 	{-152.5f,67.5f},
7726 	{-152.5f,77.5f},
7727 	{-147.5f,77.5f},
7728 	{-147.5f,87.5f},
7729 	{-152.5f,87.5f},
7730 	{-152.5f,97.5f},
7731 	{-157.5f,97.5f},
7732 	{-157.5f,112.5f},
7733 	{-162.5f,112.5f},
7734 	{-162.5f,122.5f},
7735 	{-167.5f,122.5f},
7736 	{-167.5f,132.5f},
7737 	{-172.5f,132.5f},
7738 	{-172.5f,142.5f},
7739 	{-180.0f,142.5f},
7740 	{-180.0f,180.0f}
7741 };
7742 
7743 float rama_area4[108][2] = {
7744 	{-42.5f,180.0f},
7745 	{-42.5f,172.5f},
7746 	{-42.5f,172.5f},
7747 	{-37.5f,172.5f},
7748 	{-37.5f,167.5f},
7749 	{-32.5f,167.5f},
7750 	{-32.5f,157.5f},
7751 	{-27.5f,157.5f},
7752 	{-27.5f,147.5f},
7753 	{-22.5f,147.5f},
7754 	{-22.5f,127.5f},
7755 	{-17.5f,127.5f},
7756 	{-17.5f,112.5f},
7757 	{-22.5f,112.5f},
7758 	{-22.5f,107.5f},
7759 	{-27.5f,107.5f},
7760 	{-27.5f,102.5f},
7761 	{-32.5f,102.5f},
7762 	{-32.5f,97.5f},
7763 	{-47.5f,97.5f},
7764 	{-47.5f,92.5f},
7765 	{-52.5f,92.5f},
7766 	{-52.5f,72.5f},
7767 	{-57.5f,72.5f},
7768 	{-57.5f,42.5f},
7769 	{-62.5f,42.5f},
7770 	{-62.5f,27.5f},
7771 	{-57.5f,27.5f},
7772 	{-57.5f,22.5f},
7773 	{-52.5f,22.5f},
7774 	{-52.5f,12.5f},
7775 	{-47.5f,12.5f},
7776 	{-47.5f,7.5f},
7777 	{-42.5f,7.5f},
7778 	{-42.5f,2.5f},
7779 	{-37.5f,2.5f},
7780 	{-37.5f,-7.5f},
7781 	{-32.5f,-7.5f},
7782 	{-32.5f,-12.5f},
7783 	{-27.5f,-12.5f},
7784 	{-27.5f,-27.5f},
7785 	{-22.5f,-27.5f},
7786 	{-22.5f,-47.5f},
7787 	{-17.5f,-47.5f},
7788 	{-17.5f,-67.5f},
7789 	{-22.5f,-67.5f},
7790 	{-22.5f,-77.5f},
7791 	{-27.5f,-77.5f},
7792 	{-27.5f,-82.5f},
7793 	{-47.5f,-82.5f},
7794 	{-47.5f,-87.5f},
7795 	{-77.5f,-87.5f},
7796 	{-77.5f,-92.5f},
7797 	{-87.5f,-92.5f},
7798 	{-87.5f,-112.5f},
7799 	{-92.5f,-112.5f},
7800 	{-92.5f,-122.5f},
7801 	{-97.5f,-122.5f},
7802 	{-97.5f,-137.5f},
7803 	{-92.5f,-137.5f},
7804 	{-92.5f,-142.5f},
7805 	{-82.5f,-142.5f},
7806 	{-82.5f,-147.5f},
7807 	{-72.5f,-147.5f},
7808 	{-72.5f,-152.5f},
7809 	{-67.5f,-152.5f},
7810 	{-67.5f,-157.5f},
7811 	{-62.5f,-157.5f},
7812 	{-62.5f,-162.5f},
7813 	{-57.5f,-162.5f},
7814 	{-57.5f,-167.5f},
7815 	{-52.5f,-167.5f},
7816 	{-52.5f,-172.5f},
7817 	{-47.5f,-172.5f},
7818 	{-47.5f,-177.5f},
7819 	{-42.5f,-177.5f},
7820 	{-42.5f,-180.0f},
7821 	{-180.0f,-180.0f},
7822 	{-180.0f,-147.5f},
7823 	{-177.5f,-147.5f},
7824 	{-167.5f,-147.5f},
7825 	{-167.5f,-142.5f},
7826 	{-157.5f,-142.5f},
7827 	{-157.5f,-137.5f},
7828 	{-147.5f,-137.5f},
7829 	{-147.5f,-132.5f},
7830 	{-142.5f,-132.5f},
7831 	{-142.5f,-127.5f},
7832 	{-147.5f,-127.5f},
7833 	{-147.5f,-97.5f},
7834 	{-152.5f,-97.5f},
7835 	{-152.5f,-92.5f},
7836 	{-157.5f,-92.5f},
7837 	{-157.5f,-82.5f},
7838 	{-162.5f,-82.5f},
7839 	{-162.5f,-52.5f},
7840 	{-157.5f,-52.5f},
7841 	{-157.5f,-37.5f},
7842 	{-162.5f,-37.5f},
7843 	{-162.5f,-7.5f},
7844 	{-167.5f,-7.5f},
7845 	{-167.5f,32.5f},
7846 	{-172.5f,32.5f},
7847 	{-172.5f,52.5f},
7848 	{-177.5f,52.5f},
7849 	{-177.5f,77.5f},
7850 	{-180.0f,77.5f},
7851 	{-180.0f,180.0f}
7852 };
7853 
7854 float rama_area5[67][2] = {
7855 	{82.5f,57.5f},
7856 	{87.5f,57.5f},
7857 	{87.5f,42.5f},
7858 	{92.5f,42.5f},
7859 	{92.5f,22.5f},
7860 	{97.5f,22.5f},
7861 	{97.5f,-17.5f},
7862 	{92.5f,-17.5f},
7863 	{92.5f,-22.5f},
7864 	{87.5f,-22.5f},
7865 	{87.5f,-27.5f},
7866 	{82.5f,-27.5f},
7867 	{82.5f,-37.5f},
7868 	{87.5f,-37.5f},
7869 	{87.5f,-47.5f},
7870 	{92.5f,-47.5f},
7871 	{92.5f,-57.5f},
7872 	{87.5f,-57.5f},
7873 	{87.5f,-67.5f},
7874 	{82.5f,-67.5f},
7875 	{82.5f,-72.5f},
7876 	{77.5f,-72.5f},
7877 	{77.5f,-77.5f},
7878 	{62.5f,-77.5f},
7879 	{62.5f,-72.5f},
7880 	{57.5f,-72.5f},
7881 	{57.5f,-67.5f},
7882 	{52.5f,-67.5f},
7883 	{52.5f,-37.5f},
7884 	{57.5f,-37.5f},
7885 	{57.5f,-27.5f},
7886 	{62.5f,-27.5f},
7887 	{62.5f,-22.5f},
7888 	{57.5f,-22.5f},
7889 	{57.5f,-12.5f},
7890 	{52.5f,-12.5f},
7891 	{52.5f,-7.5f},
7892 	{47.5f,-7.5f},
7893 	{47.5f,-2.5f},
7894 	{42.5f,-2.5f},
7895 	{42.5f,2.5f},
7896 	{37.5f,2.5f},
7897 	{37.5f,12.5f},
7898 	{32.5f,12.5f},
7899 	{32.5f,22.5f},
7900 	{27.5f,22.5f},
7901 	{27.5f,32.5f},
7902 	{22.5f,32.5f},
7903 	{22.5f,47.5f},
7904 	{17.5f,47.5f},
7905 	{17.5f,67.5f},
7906 	{22.5f,67.5f},
7907 	{22.5f,77.5f},
7908 	{27.5f,77.5f},
7909 	{27.5f,82.5f},
7910 	{32.5f,82.5f},
7911 	{32.5f,87.5f},
7912 	{47.5f,87.5f},
7913 	{47.5f,92.5f},
7914 	{67.5f,92.5f},
7915 	{67.5f,87.5f},
7916 	{72.5f,87.5f},
7917 	{72.5f,82.5f},
7918 	{77.5f,82.5f},
7919 	{77.5f,77.5f},
7920 	{82.5f,77.5f},
7921 	{82.5f,57.5f},
7922 };
7923 
7924 float rama_area6[10][2] = {
7925 	{77.5f,180.0f},
7926 	{77.5f,162.5f},
7927 	{82.5f,162.5f},
7928 	{82.5f,147.5f},
7929 	{72.5f,147.5f},
7930 	{72.5f,157.5f},
7931 	{67.5f,157.5f},
7932 	{67.5f,167.5f},
7933 	{62.5f,167.5f},
7934 	{62.5f,180.0f}
7935 };
7936 
7937 float rama_area7[28][2] = {
7938 	{57.5f,-180.0f},
7939 	{57.5f,-167.5f},
7940 	{52.5f,-167.5f},
7941 	{52.5f,-162.5f},
7942 	{47.5f,-162.5f},
7943 	{47.5f,-157.5f},
7944 	{42.5f,-157.5f},
7945 	{42.5f,-152.5f},
7946 	{37.5f,-152.5f},
7947 	{37.5f,-142.5f},
7948 	{32.5f,-142.5f},
7949 	{32.5f,-107.5f},
7950 	{37.5f,-107.5f},
7951 	{37.5f,-102.5f},
7952 	{42.5f,-102.5f},
7953 	{42.5f,-97.5f},
7954 	{52.5f,-97.5f},
7955 	{52.5f,-92.5f},
7956 	{62.5f,-92.5f},
7957 	{62.5f,-97.5f},
7958 	{67.5f,-97.5f},
7959 	{67.5f,-102.5f},
7960 	{72.5f,-102.5f},
7961 	{72.5f,-112.5f},
7962 	{77.5f,-112.5f},
7963 	{77.5f,-157.5f},
7964 	{72.5f,-157.5f},
7965 	{72.5f,-180.0f}
7966 };
7967 
7968 float rama_area8[10][2] = {
7969 	{162.5f,180.0f},
7970 	{162.5f,147.5f},
7971 	{167.5f,147.5f},
7972 	{167.5f,132.5f},
7973 	{172.5f,132.5f},
7974 	{172.5f,117.5f},
7975 	{177.5f,117.5f},
7976 	{177.5f,77.5f},
7977 	{180.0f,77.5f},
7978 	{180.0f,180.0f}
7979 };
7980 
7981 float rama_area9[10][2] = {
7982 	{162.5f,-180.0f},
7983 	{162.5f,-177.5f},
7984 	{167.5f,-177.5f},
7985 	{167.5f,-167.5f},
7986 	{172.5f,-167.5f},
7987 	{172.5f,-157.5f},
7988 	{177.5f,-157.5f},
7989 	{177.5f,-147.5f},
7990 	{180.0f,-147.5f},
7991 	{180.0f,-180.0f}
7992 };
7993 
7994 static Atom atom_DELWIN = 0;
7995 static Atom atom_PROTOCOLS = 0;
7996 
StoreDeleteWindowProp(win)7997 void StoreDeleteWindowProp (win)
7998      Window win;
7999 {
8000   if (! atom_DELWIN)
8001     atom_DELWIN = XInternAtom (display, "WM_DELETE_WINDOW", False);
8002 
8003   if (! atom_PROTOCOLS)
8004     atom_PROTOCOLS = XInternAtom (display, "WM_PROTOCOLS", False);
8005 
8006   if (atom_PROTOCOLS == None) return;
8007 
8008   XChangeProperty(display, win, atom_PROTOCOLS, XA_ATOM, 32,
8009                   PropModeReplace, (unsigned char *) &atom_DELWIN, 1);
8010 }
8011 
X_Error_Message_CB(Display * display,XErrorEvent * err)8012 int X_Error_Message_CB (Display *display, XErrorEvent *err)
8013 {
8014    char msg[80];
8015    XGetErrorText(display, err->error_code, msg, 80);
8016    printf("X error code %s\n", msg);
8017 
8018 
8019 /*
8020    Timer(10000000,0);
8021 */
8022 
8023 
8024 
8025 /* you can Control-C here in the debugger, when the time is activated */
8026    return 0;
8027 }
8028 
CreateWindow(xname,geom,w,h,fg,bg,Parwin)8029 Window CreateWindow(xname,geom,w,h,fg,bg,Parwin)
8030 char         *xname, *geom;
8031 unsigned int  w,h;
8032 unsigned long fg, bg;
8033 Window Parwin;
8034 {
8035   Window               hwin;
8036   XSetWindowAttributes hxswa;
8037   unsigned int         xswamask;
8038   XWMHints             xwmh;
8039   XSizeHints           hints;
8040   int                  i,x,y;
8041 
8042   if (DEBUG) fprintf(stderr,"CreateWindow in\n");
8043 
8044   if (Parwin) {
8045 	xswamask = CWBackPixel | CWBorderPixel | CWBackingStore | CWBackingPlanes;
8046 	hxswa.background_pixel = bg;
8047 	hxswa.border_pixel     = fg;
8048 	hxswa.save_under       = False;
8049 	hxswa.backing_store    = NotUseful;
8050 	hxswa.backing_planes   = 0;
8051 
8052 	x = 0; y = 0;
8053 
8054 	if (has_opengl) {
8055 	   hwin = XCreateWindow(display, Parwin, x, y, w, h,
8056 			2, vi->depth, InputOutput,
8057 			vi->visual, xswamask, &hxswa);
8058 	} else {
8059 	   hwin = XCreateWindow(display, Parwin, x, y, w, h,
8060 			2, CopyFromParent, InputOutput,
8061 			CopyFromParent, xswamask, &hxswa);
8062 	}
8063 	if (!hwin) return(hwin);   /* leave immediately if couldn't create */
8064 
8065 	XSelectInput(display, hwin, ExposureMask | VisibilityChangeMask | EnterWindowMask);
8066 	XSetTransientForHint(display, hwin, Parwin);
8067   }
8068   else {
8069   /* note that only x,y are gotten from geom spec.  w,h are fixed */
8070 	x = y = 1;
8071 	i = XParseGeometry(geom,&x,&y,&w,&h);
8072 
8073 	if (i&XValue || i&YValue) hints.flags = USPosition;
8074                        else hints.flags = PPosition;
8075 
8076 	hints.flags |= USSize;
8077 
8078 	if (i&XValue && i&XNegative)
8079 	  x = DisplayWidth(display,screen) - w - abs(x);
8080 	if (i&YValue && i&YNegative)
8081 	  y = DisplayHeight(display,screen) - h - abs(y);
8082 
8083 	hints.x = x;                  hints.y = y;
8084 	hints.width = w;              hints.height = h;
8085 	hints.min_width  = w;         hints.min_height = h;
8086 	hints.max_width  = w;         hints.max_height = h;
8087 	hints.flags |= PMaxSize | PMinSize;
8088 	xswa.background_pixel = bg;
8089 	xswa.border_pixel     = fg;
8090 	hxswa.background_pixel = bg;
8091 	hxswa.border_pixel     = fg;
8092 	hxswa.backing_store    = NotUseful;
8093 	hxswa.backing_planes   = 0;
8094 
8095 	if (has_opengl) {
8096 	    hwin = XCreateWindow(display, RootWindow(display,vi->screen),
8097 			x, y, w, h, 2, vi->depth, InputOutput,
8098 			vi->visual,
8099 			(CWBorderPixel | CWBackPixel | CWColormap | CWEventMask | CWBackingStore | CWBackingPlanes), &xswa);
8100 	} else {
8101 	    hwin = XCreateWindow(display, RootWindow(display,screen),
8102 			x, y, w, h, 2, CopyFromParent, CopyFromParent,
8103 			CopyFromParent,
8104 			(CWBorderPixel | CWBackPixel | CWBackingStore | CWBackingPlanes), &hxswa);
8105 	}
8106 	if (!hwin) return(hwin);   /* leave immediately if couldn't create */
8107 
8108 	XSetStandardProperties(display, hwin, xname, xname, None, NULL, 0, &hints);
8109 
8110 	xwmh.input = True;
8111 	xwmh.flags = InputHint;
8112 	XSetWMHints(display, hwin, &xwmh);
8113 
8114 	StoreDeleteWindowProp(hwin);
8115 
8116   }
8117 
8118   if (setcmap) XSetWindowColormap(display,hwin,cmap);
8119 
8120   if (DEBUG) fprintf(stderr,"CreateWindow out\n");
8121   return(hwin);
8122 }
8123 
8124 #define PI   3.14159265358979323846
8125 
lorentz(double rel_offset)8126 double lorentz(double rel_offset) {
8127   return 1.0 / (1.0 + rel_offset * rel_offset);
8128 }
8129 
gauss(double rel_offset)8130 double gauss(double rel_offset) {
8131   const double nln2 = -log(2.0);
8132   return exp(nln2 * rel_offset * rel_offset);
8133 }
8134 
8135 static double Tsin[361],Tcos[361];
8136 
SetupTable()8137 void SetupTable()
8138 {
8139   int alpha;
8140 
8141   for ( alpha=0; alpha < 361; alpha++ ) {
8142 	Tsin[alpha] = sin((PI*alpha)/180.0);
8143 	Tcos[alpha] = cos((PI*alpha)/180.0);
8144   }
8145 }
8146 
Get_Tsin(int dg,double * sina,double * cosa)8147 void Get_Tsin(int dg, double *sina, double *cosa)
8148 {
8149    int deg;
8150 
8151    if (dg >= 0) {
8152 	*sina = Tsin[dg]; *cosa = Tcos[dg];
8153    } else {
8154         deg = dg + 360;
8155 	*sina = Tsin[deg]; *cosa = Tcos[deg];
8156    }
8157 }
8158 
Get_FTsin(int dg,float * sina,float * cosa)8159 void Get_FTsin(int dg, float *sina, float *cosa)
8160 {
8161    int deg;
8162 
8163    if (dg >= 0) {
8164 	*sina = (float) Tsin[dg]; *cosa = (float) Tcos[dg];
8165    } else {
8166         deg = dg + 360;
8167 	*sina = (float) Tsin[deg]; *cosa = (float) Tcos[deg];
8168    }
8169 }
8170 
rotat(currx,curry)8171 void rotat(currx,curry)
8172 int currx;
8173 int curry;
8174 {
8175     float tangy,rsqx,rsqy;
8176 
8177     hold = 1;
8178     holdt = 0;
8179     holdp = 0;
8180     rsqx = (int) (width / 2 - currx);
8181     rsqy = (int) (height / 2 - curry);
8182     if (rsqx*rsqx+rsqy*rsqy < 3000) {
8183 	holdt = -1; holdp = 1;
8184 	if ((event.xbutton.state & ControlMask) ||
8185 	    (event.xbutton.state & ShiftMask)) holdp = -1;
8186 	return;
8187     }
8188     if (rsqx == 0 && rsqy == 0){ hold = 0; return;}
8189     if (rsqx == 0) {
8190 	holdt = -2;
8191 	if (rsqy > 0) holdp = -1;
8192 	if (rsqy < 0) holdp =  1;
8193 	return;
8194     }
8195     if (rsqy == 0) {
8196 	holdt = -3;
8197 	if (rsqx > 0) holdp =  1;
8198 	if (rsqx < 0) holdp = -1;
8199 	return;
8200      }
8201      tangy = rsqy / rsqx;
8202      if (rsqx > 0) {
8203 	if (tangy <= 1 && tangy >= -1) {
8204 	    holdt = -3; holdp = -1;
8205 	}
8206 	else if (tangy > 1) {
8207 	    holdt = -2; holdp = 1;
8208 	}
8209 	else {
8210 	    holdt = -2; holdp = -1;
8211 	}
8212      } else if (rsqx < 0) {
8213 	if (tangy <= 1 && tangy >= -1) {
8214 	    holdt = -3; holdp = 1;
8215 	}
8216 	else if (tangy > 1) {
8217 	    holdt = -2; holdp = -1;
8218 	}
8219 	else {
8220 	    holdt = -2; holdp = 1;
8221 	}
8222      }
8223 }
8224 
DOSpath(UNIXpath)8225 char *DOSpath(UNIXpath)
8226 char *UNIXpath;
8227 {
8228   char dospath[MAXDIRLEN] = "";
8229   char *pathptr;
8230   int i,n;
8231 
8232   if (strstr(UNIXpath,"/cygdrive/")) {
8233 	pathptr = strstr(UNIXpath,"/cygdrive/");
8234 	strcpy(dospath,"");
8235 	strncpy(dospath,pathptr+10,1);
8236 	strcat(dospath,":");
8237 	strcat(dospath,pathptr+11);
8238 	n = strlen(dospath);
8239 	for (i=0; i<n; i++)
8240 	   if (dospath[i] == '/') dospath[i] = '\\';
8241 	strcpy(UNIXpath,dospath);
8242 /*        fprintf(stderr,"DOSPath %s\n",dospath);*/
8243   }
8244   return UNIXpath;
8245 }
8246 
IsBinary(strname)8247 int IsBinary(strname)
8248 char *strname;
8249 {
8250    char line[MAXCMD];
8251    int i,j,il,ret,jmin,jmax,nbin,ncr;
8252    FILE *f;
8253    struct stat st_record;
8254 
8255    stat(strname, &st_record);
8256    if (st_record.st_size <= 1) {
8257 	fprintf(stderr,"Empty file !\n");
8258 	return(0);
8259    }
8260 
8261    f = fopen(strname,"r");
8262    fgets(line,MAXCMD,f);
8263    il = strlen(line);
8264    if (il > 0) line[il-1] = '\0';
8265    fclose(f);
8266 
8267    ret = 0;
8268    jmax = 0;
8269    jmin = 256;
8270    nbin = 0;
8271    ncr = 0;
8272 
8273    for (i = 0; i < strlen(line); i++) {
8274 	j = (int) line[i];
8275 	if (j > jmax && j != 9 && j != 27) jmax = j;
8276 	if (j < jmin && j != 9 && j != 27) jmin = j;
8277 	if (j > 126 || j < 32) nbin++;
8278 	if (j == 13) ncr++;
8279    }
8280 
8281    if ( jmax > 126 || jmin < 32) {
8282 	if (ncr != nbin) ret = 1;
8283    }
8284 
8285    return(ret);
8286 }
8287 
lViewer(ogfil)8288 void lViewer(ogfil)
8289 char *ogfil;
8290 {
8291     int pid;
8292 
8293 #ifdef DARWIN
8294     pid = fork();
8295 #else
8296     pid = vfork();
8297 #endif
8298     switch(pid) {
8299     case -1:
8300           fprintf(stderr,"Couldnt Fork\n");
8301           break;
8302     case 0:       /*child */
8303 #ifdef __CYGWIN__
8304 	  if (access("./mogl",F_OK) == 0) {
8305              execlp("./mogl","mogl",DOSpath(ogfil),NULL);
8306 	  } else {
8307 	     sprintf(cmdstr,"mogl \"%s\"",DOSpath(ogfil));
8308 	     system(cmdstr);
8309 	  }
8310 #else
8311           execlp("moldenogl","moldenogl",ogfil,NULL);
8312 #endif
8313 	  _exit(0);
8314           break;
8315     default:      /*parent*/
8316           break;
8317     }
8318 }
8319 
excmd(str,spid)8320 void excmd(str,spid)
8321 char *str;
8322 int *spid;
8323 {
8324     int pid;
8325 
8326 #ifdef DARWIN
8327     *spid = fork();
8328 #else
8329     *spid = vfork();
8330 #endif
8331 
8332     switch(*spid) {
8333     case -1:
8334           fprintf(stderr,"Couldnt Fork\n");
8335           break;
8336     case 0:       /*child */
8337 	  system(str);
8338 	  _exit(0);
8339           break;
8340     default:      /*parent*/
8341           break;
8342     }
8343 }
8344 
8345 #ifdef GCC_FORTRAN_H
8346 
8347 extern int _gfortran_iargc(void);
8348 
8349 #if defined(VMS) || defined(UNDERSC)
iargc()8350 int iargc()
8351 #else
8352 #ifdef CRAY
8353 int IARGC()
8354 #else
8355 int iargc_()
8356 #endif
8357 #endif
8358 {
8359    return _gfortran_iargc();
8360 }
8361 
8362 #endif
8363 
8364 #if defined(VMS) || defined(UNDERSC)
tounx()8365 void tounx()
8366 #else
8367 #ifdef CRAY
8368 void TOUNX()
8369 #else
8370 void tounx_()
8371 #endif
8372 #endif
8373 {
8374    if (xison) {
8375     if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
8376 	"Molden cant handle DOS files very well.\n Convert file to Unix format ?",1)) {
8377 	dos2u(strname);
8378     }
8379    } else {
8380 	dos2u(strname);
8381    }
8382 }
8383 
izz(i,j)8384 int izz(i,j)
8385 int i;
8386 int j;
8387 {
8388  int result;
8389 
8390  result = *(zmptrp->iz + (i*4) + j);
8391 
8392  return(result);
8393 
8394 }
8395 
pizz(i,j)8396 int *pizz(i,j)
8397 int i;
8398 int j;
8399 {
8400  int *result;
8401 
8402  result = (zmptrp->iz + (i*4) + j);
8403 
8404  return(result);
8405 
8406 }
8407 
fndchr(line,chr)8408 int fndchr(line,chr)
8409 char *line;
8410 char chr;
8411 {
8412    int n,i;
8413 
8414    n = strlen(line);
8415    for (i=0; i<n; i++)
8416 	if (line[i] == chr) return(i);
8417 
8418    return(0);
8419 }
8420 
8421 /* shadow C routines for Fortran routines to pass Z-matrix pointers */
8422 
8423 #if defined(VMS) || defined(UNDERSC)
plinzz(isel,istat)8424 void plinzz(isel,istat)
8425 #else
8426 #ifdef CRAY
8427 void PLINZZ(isel,istat)
8428 #else
8429 void plinzz_(isel,istat)
8430 #endif
8431 #endif
8432 int *isel;
8433 int *istat;
8434 {
8435 
8436 #if defined(VMS) || defined(UNDERSC)
8437    plinz(isel,istat,
8438 #else
8439 #ifdef CRAY
8440    PLINZ(isel,istat,
8441 #else
8442    plinz_(isel,istat,
8443 #endif
8444 #endif
8445 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8446 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8447 	xyzp->lwrit,xyzp->ianz);
8448 
8449 }
8450 
8451 #if defined(VMS) || defined(UNDERSC)
dumlin(isel,blv,alphv,betv)8452 void dumlin(isel,blv,alphv,betv)
8453 #else
8454 #ifdef CRAY
8455 void DUMLIN(isel,blv,alphv,betv)
8456 #else
8457 void dumlin_(isel,blv,alphv,betv)
8458 #endif
8459 #endif
8460 int *isel;
8461 double *blv;
8462 double *alphv;
8463 double *betv;
8464 {
8465 
8466 #if defined(VMS) || defined(UNDERSC)
8467 	dumliz(isel,blv,alphv,betv,
8468 #else
8469 #ifdef CRAY
8470 	DUMLIZ(isel,blv,alphv,betv,
8471 #else
8472 	dumliz_(isel,blv,alphv,betv,
8473 #endif
8474 #endif
8475 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8476 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8477 	xyzp->lwrit,xyzp->ianz);
8478 
8479 }
8480 
8481 #if defined(VMS) || defined(UNDERSC)
wline(iun,iopt,igamb)8482 void wline(iun,iopt,igamb)
8483 #else
8484 #ifdef CRAY
8485 void WLINE(iun,iopt,igamb)
8486 #else
8487 void wline_(iun,iopt,igamb)
8488 #endif
8489 #endif
8490 int *iun;
8491 int *iopt;
8492 int *igamb;
8493 {
8494 
8495 #if defined(VMS) || defined(UNDERSC)
8496 	wlinz(iun,iopt,igamb,
8497 #else
8498 #ifdef CRAY
8499 	WLINZ(iun,iopt,igamb,
8500 #else
8501 	wlinz_(iun,iopt,igamb,
8502 #endif
8503 #endif
8504 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8505 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8506 	xyzp->iconn,xyzp->ianz,xyzp->ityp,xyzp->qat);
8507 
8508 }
8509 
8510 #if defined(VMS) || defined(UNDERSC)
wrzmat(iun,iopt)8511 void wrzmat(iun,iopt)
8512 #else
8513 #ifdef CRAY
8514 void WRZMAT(iun,iopt)
8515 #else
8516 void wrzmat_(iun,iopt)
8517 #endif
8518 #endif
8519 int *iun;
8520 int *iopt;
8521 {
8522 
8523 #if defined(VMS) || defined(UNDERSC)
8524 	wrzmaz(iun,iopt,
8525 #else
8526 #ifdef CRAY
8527 	WRZMAZ(iun,iopt,
8528 #else
8529 	wrzmaz_(iun,iopt,
8530 #endif
8531 #endif
8532 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8533 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8534 	geop->epoints,xyzp->ianz);
8535 
8536 }
8537 
8538 #if defined(VMS) || defined(UNDERSC)
mapxzz(iun,imod,iff,izmtmp,istat)8539 void mapxzz(iun,imod,iff,izmtmp,istat)
8540 #else
8541 #ifdef CRAY
8542 void MAPXZZ(iun,imod,iff,izmtmp,istat)
8543 #else
8544 void mapxzz_(iun,imod,iff,izmtmp,istat)
8545 #endif
8546 #endif
8547 int *iun;
8548 int *imod;
8549 int *iff;
8550 int *izmtmp;
8551 int *istat;
8552 {
8553 
8554 #if defined(VMS) || defined(UNDERSC)
8555 	mapzzz(iun,imod,iff,izmtmp,istat,
8556 #else
8557 #ifdef CRAY
8558 	MAPZZZ(iun,imod,iff,izmtmp,istat,
8559 #else
8560 	mapzzz_(iun,imod,iff,izmtmp,istat,
8561 #endif
8562 #endif
8563 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8564 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,xyzp->ianz);
8565 
8566 }
8567 
8568 #if defined(VMS) || defined(UNDERSC)
fndmaz(ixyz,istat)8569 void fndmaz(ixyz,istat)
8570 #else
8571 #ifdef CRAY
8572 void FNDMAZ(ixyz,istat)
8573 #else
8574 void fndmaz_(ixyz,istat)
8575 #endif
8576 #endif
8577 int *ixyz;
8578 int *istat;
8579 {
8580 
8581 #if defined(VMS) || defined(UNDERSC)
8582 	fndmzz(ixyz,istat,zmptrp->imap);
8583 #else
8584 #ifdef CRAY
8585 	FNDMZZ(ixyz,istat,zmptrp->imap);
8586 #else
8587 	fndmzz_(ixyz,istat,zmptrp->imap);
8588 #endif
8589 #endif
8590 
8591 }
8592 
8593 #if defined(VMS) || defined(UNDERSC)
chkmaz(istat)8594 void chkmaz(istat)
8595 #else
8596 #ifdef CRAY
8597 void CHKMAZ(istat)
8598 #else
8599 void chkmaz_(istat)
8600 #endif
8601 #endif
8602 int *istat;
8603 {
8604 
8605 #if defined(VMS) || defined(UNDERSC)
8606 	chkmzz(istat,
8607 #else
8608 #ifdef CRAY
8609 	CHKMZZ(istat,
8610 #else
8611 	chkmzz_(istat,
8612 #endif
8613 #endif
8614 	xyzp->qat,xyzp->rzp,zmptrp->ianz,zmptrp->imap,
8615 	xyzp->ianz,xyzp->lring,xyzp->ityp,xyzp->ipdbt);
8616 
8617 }
8618 
8619 #if defined(VMS) || defined(UNDERSC)
prtzm()8620 void prtzm()
8621 #else
8622 #ifdef CRAY
8623 void PRTZM()
8624 #else
8625 void prtzm_()
8626 #endif
8627 #endif
8628 {
8629 
8630 #if defined(VMS) || defined(UNDERSC)
8631 	prtzz(
8632 #else
8633 #ifdef CRAY
8634 	PRTZZ(
8635 #else
8636 	prtzz_(
8637 #endif
8638 #endif
8639 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8640 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz);
8641 
8642 }
8643 
8644 #if defined(VMS) || defined(UNDERSC)
getzmz(istat)8645 void getzmz(istat)
8646 #else
8647 #ifdef CRAY
8648 void GETZMZ(istat)
8649 #else
8650 void getzmz_(istat)
8651 #endif
8652 #endif
8653 int *istat;
8654 {
8655 
8656 #if defined(VMS) || defined(UNDERSC)
8657 	getzzz(istat,
8658 #else
8659 #ifdef CRAY
8660 	GETZZZ(istat,
8661 #else
8662 	getzzz_(istat,
8663 #endif
8664 #endif
8665 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8666 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz);
8667 
8668 }
8669 
8670 #if defined(VMS) || defined(UNDERSC)
dumzm(cc,ianc,nnatoms)8671 void dumzm(cc,ianc,nnatoms)
8672 #else
8673 #ifdef CRAY
8674 void DUMZM(cc,ianc,nnatoms)
8675 #else
8676 void dumzm_(cc,ianc,nnatoms)
8677 #endif
8678 #endif
8679 double *cc;
8680 int *ianc;
8681 int *nnatoms;
8682 {
8683 	int part;
8684 
8685 	part = zmpart->ipart;
8686 
8687 #if defined(VMS) || defined(UNDERSC)
8688 	dumzz(cc,ianc,nnatoms,
8689 #else
8690 #ifdef CRAY
8691 	DUMZZ(cc,ianc,nnatoms,
8692 #else
8693 	dumzz_(cc,ianc,nnatoms,
8694 #endif
8695 #endif
8696 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8697 	zmptrp->ibet, zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8698 	stocp->cstoc,stocp->czstoc,stocp->astoc,stocp->bstoc,stocp->ianstc,
8699 	xyzp->coo,xyzp->iresid,&calfptr->issdon);
8700 
8701 }
8702 
8703 #if defined(VMS) || defined(UNDERSC)
convzmat(cc,ianc,nnatoms,igo,ico,ido)8704 void convzmat(cc,ianc,nnatoms,igo,ico,ido)
8705 #else
8706 #ifdef CRAY
8707 void CONVZMAT(cc,ianc,nnatoms,igo,ico,ido)
8708 #else
8709 void convzmat_(cc,ianc,nnatoms,igo,ico,ido)
8710 #endif
8711 #endif
8712 double *cc;
8713 int *ianc;
8714 int *nnatoms;
8715 int *igo;
8716 int *ico;
8717 int *ido;
8718 {
8719 
8720 #if defined(VMS) || defined(UNDERSC)
8721 	convzmzz(cc,ianc,nnatoms,igo,ico,ido,
8722 #else
8723 #ifdef CRAY
8724 	CONVZMZZ(cc,ianc,nnatoms,igo,ico,ido,
8725 #else
8726 	convzmzz_(cc,ianc,nnatoms,igo,ico,ido,
8727 #endif
8728 #endif
8729 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8730 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8731 	stocp->cstoc,stocp->czstoc,stocp->astoc,stocp->bstoc,stocp->ianstc);
8732 
8733 }
8734 
8735 #if defined(VMS) || defined(UNDERSC)
getmop(nnatoms,heat,igo,ico,istat)8736 void getmop(nnatoms,heat,igo,ico,istat)
8737 #else
8738 #ifdef CRAY
8739 void GETMOP(nnatoms,heat,igo,ico,istat)
8740 #else
8741 void getmop_(nnatoms,heat,igo,ico,istat)
8742 #endif
8743 #endif
8744 int *nnatoms;
8745 int *igo;
8746 int *ico;
8747 double *heat;
8748 int *istat;
8749 {
8750 
8751 #if defined(VMS) || defined(UNDERSC)
8752 	getmdp(nnatoms,heat,igo,ico,istat,
8753 #else
8754 #ifdef CRAY
8755 	GETMDP(nnatoms,heat,igo,ico,istat,
8756 #else
8757 	getmdp_(nnatoms,heat,igo,ico,istat,
8758 #endif
8759 #endif
8760         xyzp->coo,xyzp->ianz,
8761 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8762 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8763 	stocp->cstoc,stocp->czstoc,stocp->astoc,stocp->bstoc,stocp->ianstc);
8764 
8765 }
8766 
8767 #if defined(VMS) || defined(UNDERSC)
getzm(nnatoms,igo,ico,istat)8768 void getzm(nnatoms,igo,ico,istat)
8769 #else
8770 #ifdef CRAY
8771 void GETZM(nnatoms,igo,ico,istat)
8772 #else
8773 void getzm_(nnatoms,igo,ico,istat)
8774 #endif
8775 #endif
8776 int *nnatoms;
8777 int *igo;
8778 int *ico;
8779 int *istat;
8780 {
8781 
8782 #if defined(VMS) || defined(UNDERSC)
8783 	getzd(nnatoms,igo,ico,istat,
8784 #else
8785 #ifdef CRAY
8786 	GETZD(nnatoms,igo,ico,istat,
8787 #else
8788 	getzd_(nnatoms,igo,ico,istat,
8789 #endif
8790 #endif
8791 	xyzp->coo,xyzp->ianz,
8792 	zmptrp->bl,zmptrp->alph,zmptrp->bet,zmptrp->ibl,zmptrp->ialph,
8793 	zmptrp->ibet,zmptrp->imap,zmptrp->ianz,zmptrp->iz,
8794 	stocp->cstoc,stocp->czstoc,stocp->astoc,stocp->bstoc,stocp->ianstc);
8795 
8796 }
8797 
8798 /* END shadow C routines for Fortran routines to pass Z-matrix pointers */
8799 
8800 /* shadow C routines for Fortran routines to pass orbital pointers */
8801 
8802 #if defined(VMS) || defined(UNDERSC)
adffun(x,y,z,psi)8803 void adffun(x,y,z,psi)
8804 #else
8805 #ifdef CRAY
8806 void ADFFUN(x,y,z,psi)
8807 #else
8808 void adffun_(x,y,z,psi)
8809 #endif
8810 #endif
8811 double *x;
8812 double *y;
8813 double *z;
8814 double *psi;
8815 {
8816 
8817 #if defined(VMS) || defined(UNDERSC)
8818 	adffud(x,y,z,psi,
8819 #else
8820 #ifdef CRAY
8821 	ADFFUD(x,y,z,psi,
8822 #else
8823 	adffud_(x,y,z,psi,
8824 #endif
8825 #endif
8826 	dorbp->stoalfa,dorbp->stobnorm,dorbp->istos,dorbp->naorbs);
8827 
8828 }
8829 
8830 #if defined(VMS) || defined(UNDERSC)
atdd(imo,ipsi,iao)8831 void atdd(imo,ipsi,iao)
8832 #else
8833 #ifdef CRAY
8834 void ATDD(imo,ipsi,iao)
8835 #else
8836 void atdd_(imo,ipsi,iao)
8837 #endif
8838 #endif
8839 int *imo;
8840 int *ipsi;
8841 int *iao;
8842 {
8843 
8844 #if defined(VMS) || defined(UNDERSC)
8845 	addd(imo,ipsi,iao,
8846 #else
8847 #ifdef CRAY
8848 	ADDD(imo,ipsi,iao,
8849 #else
8850 	addd_(imo,ipsi,iao,
8851 #endif
8852 #endif
8853 	dorbp->p,dorbp->paa,orbp->pd);
8854 
8855 }
8856 
8857 #if defined(VMS) || defined(UNDERSC)
denmad(ido)8858 void denmad(ido)
8859 #else
8860 #ifdef CRAY
8861 void DENMAD(ido)
8862 #else
8863 void denmad_(ido)
8864 #endif
8865 #endif
8866 int *ido;
8867 {
8868 
8869 #if defined(VMS) || defined(UNDERSC)
8870 	denmdd(ido,
8871 #else
8872 #ifdef CRAY
8873 	DENMDD(ido,
8874 #else
8875 	denmdd_(ido,
8876 #endif
8877 #endif
8878 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->p,dorbp->paa,
8879 	dorbp->averag,orbp->qd);
8880 
8881 }
8882 
8883 #if defined(VMS) || defined(UNDERSC)
densmat(ido)8884 void densmat(ido)
8885 #else
8886 #ifdef CRAY
8887 void DENSMAT(ido)
8888 #else
8889 void densmat_(ido)
8890 #endif
8891 #endif
8892 int *ido;
8893 {
8894 
8895 #if defined(VMS) || defined(UNDERSC)
8896 	densmad(ido,
8897 #else
8898 #ifdef CRAY
8899 	DENSMAD(ido,
8900 #else
8901 	densmad_(ido,
8902 #endif
8903 #endif
8904 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->p,dorbp->nocc);
8905 
8906 }
8907 
8908 #if defined(VMS) || defined(UNDERSC)
densmto(ido)8909 void densmto(ido)
8910 #else
8911 #ifdef CRAY
8912 void DENSMTO(ido)
8913 #else
8914 void densmto_(ido)
8915 #endif
8916 #endif
8917 int *ido;
8918 {
8919 
8920 #if defined(VMS) || defined(UNDERSC)
8921 	densmtd(ido,
8922 #else
8923 #ifdef CRAY
8924 	DENSMTD(ido,
8925 #else
8926 	densmtd_(ido,
8927 #endif
8928 #endif
8929 	dorbp->vectrs,dorbp->focc,dorbp->p,dorbp->nocc);
8930 
8931 }
8932 
8933 #if defined(VMS) || defined(UNDERSC)
espot(x,y,z,epot,idebug)8934 void espot(x,y,z,epot,idebug)
8935 #else
8936 #ifdef CRAY
8937 void ESPOT(x,y,z,epot,idebug)
8938 #else
8939 void espot_(x,y,z,epot,idebug)
8940 #endif
8941 #endif
8942 double *x;
8943 double *y;
8944 double *z;
8945 double *epot;
8946 int *idebug;
8947 {
8948 
8949 #if defined(VMS) || defined(UNDERSC)
8950 	espod(x,y,z,epot,idebug,
8951 #else
8952 #ifdef CRAY
8953 	ESPOD(x,y,z,epot,idebug,
8954 #else
8955 	espod_(x,y,z,epot,idebug,
8956 #endif
8957 #endif
8958 	dorbp->p);
8959 
8960 }
8961 
8962 #if defined(VMS) || defined(UNDERSC)
espgrd(npts1,npts2,npts3,idebug)8963 void espgrd(npts1,npts2,npts3,idebug)
8964 #else
8965 #ifdef CRAY
8966 void ESPGRD(npts1,npts2,npts3,idebug)
8967 #else
8968 void espgrd_(npts1,npts2,npts3,idebug)
8969 #endif
8970 #endif
8971 int *npts1;
8972 int *npts2;
8973 int *npts3;
8974 int *idebug;
8975 {
8976    int ZSize,memstat;
8977    double d;
8978 
8979    ZSize = *sgrd.mx3d;
8980    memstat = 1;
8981 
8982    if (fsgrd.xden == NULL) {
8983        if ((fsgrd.xden = (double *) malloc((sizeof d)*ZSize*ZSize*ZSize))
8984 		== NULL) {
8985 		memstat = 0;
8986        }
8987        if ((fsgrd.yden = (double *) malloc((sizeof d)*ZSize*ZSize*ZSize))
8988 		== NULL) {
8989 		memstat = 0;
8990        }
8991        if ((fsgrd.zden = (double *) malloc((sizeof d)*ZSize*ZSize*ZSize))
8992 		== NULL) {
8993 		memstat = 0;
8994        }
8995    }
8996 
8997 #if defined(VMS) || defined(UNDERSC)
8998 	espgrdd(npts1,npts2,npts3,idebug,
8999 #else
9000 #ifdef CRAY
9001 	ESPGRDD(npts1,npts2,npts3,idebug,
9002 #else
9003 	espgrdd_(npts1,npts2,npts3,idebug,
9004 #endif
9005 #endif
9006 	sgrd.denn,dorbp->p,fsgrd.xden,fsgrd.yden,fsgrd.zden);
9007 
9008 }
9009 
9010 #if defined(VMS) || defined(UNDERSC)
newdenmak()9011 void newdenmak()
9012 #else
9013 #ifdef CRAY
9014 void NEWDENMAK()
9015 #else
9016 void newdenmak_()
9017 #endif
9018 #endif
9019 {
9020 
9021 #if defined(VMS) || defined(UNDERSC)
9022 	newdenmad(dorbp->p,orbp->qd);
9023 #else
9024 #ifdef CRAY
9025 	NEWDENMAD(dorbp->p,orbp->qd);
9026 #else
9027 	newdenmad_(dorbp->p,orbp->qd);
9028 #endif
9029 #endif
9030 
9031 }
9032 
9033 #if defined(VMS) || defined(UNDERSC)
calhes(psi,grd,hess,den,g,hes)9034 void calhes(psi,grd,hess,den,g,hes)
9035 #else
9036 #ifdef CRAY
9037 void CALHES(psi,grd,hess,den,g,hes)
9038 #else
9039 void calhes_(psi,grd,hess,den,g,hes)
9040 #endif
9041 #endif
9042 double *psi;
9043 double *grd;
9044 double *hess;
9045 double *den;
9046 double *g;
9047 double *hes;
9048 {
9049 
9050 #if defined(VMS) || defined(UNDERSC)
9051 	calhed(psi,grd,hess,den,g,hes,
9052 #else
9053 #ifdef CRAY
9054 	CALHED(psi,grd,hess,den,g,hes,
9055 #else
9056 	calhed_(psi,grd,hess,den,g,hes,
9057 #endif
9058 #endif
9059 	dorbp->p);
9060 
9061 }
9062 
9063 #if defined(VMS) || defined(UNDERSC)
grdcal(dens,npts1,npts2,iprnt,space)9064 void grdcal(dens,npts1,npts2,iprnt,space)
9065 #else
9066 #ifdef CRAY
9067 void GRDCAL(dens,npts1,npts2,iprnt,space)
9068 #else
9069 void grdcal_(dens,npts1,npts2,iprnt,space)
9070 #endif
9071 #endif
9072 double *dens;
9073 int *npts1;
9074 int *npts2;
9075 int *iprnt;
9076 int *space;
9077 {
9078 
9079 #if defined(VMS) || defined(UNDERSC)
9080 	grdcad(dens,npts1,npts2,iprnt,space,
9081 #else
9082 #ifdef CRAY
9083 	GRDCAD(dens,npts1,npts2,iprnt,space,
9084 #else
9085 	grdcad_(dens,npts1,npts2,iprnt,space,
9086 #endif
9087 #endif
9088 	dorbp->p,dorbp->paa,orbp->pd,orbp->gd,orbp->hd,
9089 	dorbp->phi,dorbp->dphi,dorbp->dxpsi,dorbp->dypsi,dorbp->dzpsi,
9090 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb);
9091 
9092 }
9093 
9094 #if defined(VMS) || defined(UNDERSC)
prtvec()9095 void prtvec()
9096 #else
9097 #ifdef CRAY
9098 void PRTVEC()
9099 #else
9100 void prtvec_()
9101 #endif
9102 #endif
9103 {
9104 
9105 #if defined(VMS) || defined(UNDERSC)
9106 	prtved(
9107 #else
9108 #ifdef CRAY
9109 	PRTVED(
9110 #else
9111 	prtved_(
9112 #endif
9113 #endif
9114 	dorbp->vectrs,dorbp->vectrb,dorbp->eiga,dorbp->eigb,
9115 	dorbp->ncols,dorbp->ncolb);
9116 
9117 }
9118 
9119 #if defined(VMS) || defined(UNDERSC)
stint()9120 void stint()
9121 #else
9122 #ifdef CRAY
9123 void STINT()
9124 #else
9125 void stint_()
9126 #endif
9127 #endif
9128 {
9129 
9130 #if defined(VMS) || defined(UNDERSC)
9131 	stind(dorbp->p,xyzp->qat);
9132 #else
9133 #ifdef CRAY
9134 	STIND(dorbp->p,xyzp->qat);
9135 #else
9136 	stind_(dorbp->p,xyzp->qat);
9137 #endif
9138 #endif
9139 
9140 }
9141 
9142 #if defined(VMS) || defined(UNDERSC)
muldmd(vdwr,moddma,idm,idd)9143 void muldmd(vdwr,moddma,idm,idd)
9144 #else
9145 #ifdef CRAY
9146 void MULDMD(vdwr,moddma,idm,idd)
9147 #else
9148 void muldmd_(vdwr,moddma,idm,idd)
9149 #endif
9150 #endif
9151 double *vdwr;
9152 int *moddma;
9153 int *idm;
9154 int *idd;
9155 {
9156 
9157 #if defined(VMS) || defined(UNDERSC)
9158 	mulddd(vdwr,moddma,idm,idd,
9159 #else
9160 #ifdef CRAY
9161 	MULDDD(vdwr,moddma,idm,idd,
9162 #else
9163 	mulddd_(vdwr,moddma,idm,idd,
9164 #endif
9165 #endif
9166 	dorbp->p,xyzp->qat,xyzp->iconn);
9167 
9168 }
9169 
9170 #if defined(VMS) || defined(UNDERSC)
dipole()9171 void dipole()
9172 #else
9173 #ifdef CRAY
9174 void DIPOLE()
9175 #else
9176 void dipole_()
9177 #endif
9178 #endif
9179 {
9180    int ZSize,ntt,i;
9181    double d;
9182 
9183    ZSize = *dorbp->mxorb;
9184    if ((dmao = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
9185 	fprintf(stderr,"Out of memory\n");
9186    }
9187    if ((nor = (int *) malloc((sizeof i)*ZSize*ZSize)) == NULL) {
9188 	fprintf(stderr,"Out of memory\n");
9189    }
9190 
9191    ntt = NAT->norbs*(NAT->norbs+1)/2;
9192 
9193 
9194 #if defined(VMS) || defined(UNDERSC)
9195 	dipold(
9196 #else
9197 #ifdef CRAY
9198 	DIPOLD(
9199 #else
9200 	dipold_(
9201 #endif
9202 #endif
9203 	&ntt,nor,dmao,dorbp->focc,dorbp->focb,dorbp->vectrs,dorbp->vectrb,dorbp->p);
9204 
9205 }
9206 
9207 #if defined(VMS) || defined(UNDERSC)
boys(norb,nor,dmao,vecs)9208 void boys(norb,nor,dmao,vecs)
9209 #else
9210 #ifdef CRAY
9211 void BOYS(norb,nor,dmao,vecs)
9212 #else
9213 void boys_(norb,nor,dmao,vecs)
9214 #endif
9215 #endif
9216 int *norb;
9217 int *nor;
9218 double *dmao;
9219 double *vecs;
9220 {
9221    int i,ZSize,ntt,memstat,nbasis;
9222    double d;
9223    double *cl,*rij,*qpix,*qpjx;
9224    int *iord,*iir;
9225 
9226    memstat = 1;
9227    nbasis = NAT->norbs;
9228    ntt = nbasis*(nbasis+1)/2;
9229 
9230    boy.dmao = dmao;
9231    boy.nor = nor;
9232 
9233    if ((cl = (double *) malloc((sizeof d)*nbasis*nbasis)) == NULL) {
9234         memstat = 0;
9235 	fprintf(stderr,"cl Out of memory\n");
9236    }
9237    boy.cl = cl;
9238 
9239    if ((rij = (double *) malloc((sizeof d)*ntt*3)) == NULL) {
9240         memstat = 0;
9241 	fprintf(stderr,"rij Out of memory\n");
9242    }
9243    boy.rij = rij;
9244 
9245    if ((qpix = (double *) malloc((sizeof d)*nbasis)) == NULL) {
9246         memstat = 0;
9247 	fprintf(stderr,"qpix Out of memory\n");
9248    }
9249    boy.qpix = qpix;
9250 
9251    if ((qpjx = (double *) malloc((sizeof d)*nbasis)) == NULL) {
9252         memstat = 0;
9253 	fprintf(stderr,"qpjx Out of memory\n");
9254    }
9255    boy.qpjx = qpjx;
9256 
9257    if ((iord = (int *) malloc((sizeof i)*nbasis)) == NULL) {
9258         memstat = 0;
9259 	fprintf(stderr,"iord Out of memory\n");
9260    }
9261    boy.iord = iord;
9262 
9263    if ((iir = (int *) malloc((sizeof i)*nbasis)) == NULL) {
9264         memstat = 0;
9265 	fprintf(stderr,"irr Out of memory\n");
9266    }
9267    boy.iir = iir;
9268 
9269 #if defined(VMS) || defined(UNDERSC)
9270 	boyd(norb,nor,dmao,vecs,
9271 #else
9272 #ifdef CRAY
9273 	BOYS(norb,nor,dmao,vecs,
9274 #else
9275 	boyd_(norb,nor,dmao,vecs,
9276 #endif
9277 #endif
9278 	&nbasis,&ntt,cl,iord,iir,rij,qpix,qpjx);
9279 
9280 }
9281 
9282 #if defined(VMS) || defined(UNDERSC)
mseed()9283 int mseed()
9284 #else
9285 #ifdef CRAY
9286 int MSEED()
9287 #else
9288 int mseed_()
9289 #endif
9290 #endif
9291 {
9292   return (int)(((long)time(NULL)+(long)getpid()) % (long)1000000);
9293 }
9294 
9295 #if defined(VMS) || defined(UNDERSC)
mopin(istat,ibin,impas)9296 void mopin(istat,ibin,impas)
9297 #else
9298 #ifdef CRAY
9299 void MOPIN(istat,ibin,impas)
9300 #else
9301 void mopin_(istat,ibin,impas)
9302 #endif
9303 #endif
9304 int *istat;
9305 int *ibin;
9306 int *impas;
9307 {
9308 
9309 #if defined(VMS) || defined(UNDERSC)
9310 	mopdd(istat,ibin,impas,
9311 #else
9312 #ifdef CRAY
9313 	MOPDD(istat,ibin,impas,
9314 #else
9315 	mopdd_(istat,ibin,impas,
9316 #endif
9317 #endif
9318 	dorbp->vectrs,dorbp->averag,dorbp->p,dorbp->focc,dorbp->eiga,
9319 	orbp->qd,orbp->pd,dorbp->nocc,dorbp->ncols);
9320 
9321 }
9322 
9323 
9324 #if defined(VMS) || defined(UNDERSC)
rdgad(idebug,ibefo,istatio,ioxyz,irtype,istats)9325 void rdgad(idebug,ibefo,istatio,ioxyz,irtype,istats)
9326 #else
9327 #ifdef CRAY
9328 void RDGAD(idebug,ibefo,istatio,ioxyz,irtype,istats)
9329 #else
9330 void rdgad_(idebug,ibefo,istatio,ioxyz,irtype,istats)
9331 #endif
9332 #endif
9333 int *idebug;
9334 int *ibefo;
9335 int *istatio;
9336 int *ioxyz;
9337 int *irtype;
9338 int *istats;
9339 {
9340 
9341 #if defined(VMS) || defined(UNDERSC)
9342 	rdgdd(idebug,ibefo,istatio,ioxyz,irtype,istats,
9343 #else
9344 #ifdef CRAY
9345 	RDGDD(idebug,ibefo,istatio,ioxyz,irtype,istats,
9346 #else
9347 	rdgdd_(idebug,ibefo,istatio,ioxyz,irtype,istats,
9348 #endif
9349 #endif
9350 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->eiga,
9351 	dorbp->eigb,dorbp->nocc,dorbp->nocb,dorbp->ncols,dorbp->ncolb,
9352 	xyzp->coo,xyzp->ianz);
9353 
9354 }
9355 
9356 #if defined(VMS) || defined(UNDERSC)
rdgamd(idebug,ibefo,istatio,irtype,ihsend,istats)9357 void rdgamd(idebug,ibefo,istatio,irtype,ihsend,istats)
9358 #else
9359 #ifdef CRAY
9360 void RDGAMD(idebug,ibefo,istatio,irtype,ihsend,istats)
9361 #else
9362 void rdgamd_(idebug,ibefo,istatio,irtype,ihsend,istats)
9363 #endif
9364 #endif
9365 int *idebug;
9366 int *ibefo;
9367 int *istatio;
9368 int *irtype;
9369 int *ihsend;
9370 int *istats;
9371 {
9372 
9373 #if defined(VMS) || defined(UNDERSC)
9374 	rdgadd(idebug,ibefo,istatio,irtype,ihsend,istats,
9375 #else
9376 #ifdef CRAY
9377 	RDGADD(idebug,ibefo,istatio,irtype,ihsend,istats,
9378 #else
9379 	rdgadd_(idebug,ibefo,istatio,irtype,ihsend,istats,
9380 #endif
9381 #endif
9382 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->eiga,
9383 	dorbp->eigb,dorbp->nocc,dorbp->nocb,dorbp->ncols,dorbp->ncolb);
9384 
9385 }
9386 
9387 #if defined(VMS) || defined(UNDERSC)
rdgaud(idebug,ibefo,istatio,irtype,istats)9388 void rdgaud(idebug,ibefo,istatio,irtype,istats)
9389 #else
9390 #ifdef CRAY
9391 void RDGAUD(idebug,ibefo,istatio,irtype,istats)
9392 #else
9393 void rdgaud_(idebug,ibefo,istatio,irtype,istats)
9394 #endif
9395 #endif
9396 int *idebug;
9397 int *ibefo;
9398 int *istatio;
9399 int *irtype;
9400 int *istats;
9401 {
9402 
9403 #if defined(VMS) || defined(UNDERSC)
9404 	rdgdud(idebug,ibefo,istatio,irtype,istats,
9405 #else
9406 #ifdef CRAY
9407 	RDGDUD(idebug,ibefo,istatio,irtype,istats,
9408 #else
9409 	rdgdud_(idebug,ibefo,istatio,irtype,istats,
9410 #endif
9411 #endif
9412 	dorbp->focc,dorbp->focb,dorbp->nocc,dorbp->nocb,dorbp->ncols,
9413 	dorbp->ncolb,xyzp->coo,xyzp->ianz);
9414 
9415 }
9416 
9417 #if defined(VMS) || defined(UNDERSC)
rdqchm(idebug,irtype,istats)9418 void rdqchm(idebug,irtype,istats)
9419 #else
9420 #ifdef CRAY
9421 void RDQCHM(idebug,irtype,istats)
9422 #else
9423 void rdqchm_(idebug,irtype,istats)
9424 #endif
9425 #endif
9426 int *idebug;
9427 int *irtype;
9428 int *istats;
9429 {
9430 
9431 #if defined(VMS) || defined(UNDERSC)
9432 	rdqchd(idebug,irtype,istats,
9433 #else
9434 #ifdef CRAY
9435 	RDQCHD(idebug,irtype,istats,
9436 #else
9437 	rdqchd_(idebug,irtype,istats,
9438 #endif
9439 #endif
9440 	dorbp->focc,dorbp->focb,dorbp->nocc,dorbp->nocb,
9441 	dorbp->ncols,dorbp->ncolb);
9442 
9443 }
9444 
9445 #if defined(VMS) || defined(UNDERSC)
rdorca(idebug,irtype,istats)9446 void rdorca(idebug,irtype,istats)
9447 #else
9448 #ifdef CRAY
9449 void RDORCA(idebug,irtype,istats)
9450 #else
9451 void rdorca_(idebug,irtype,istats)
9452 #endif
9453 #endif
9454 int *idebug;
9455 int *irtype;
9456 int *istats;
9457 {
9458 
9459 #if defined(VMS) || defined(UNDERSC)
9460 	rdorcd(idebug,irtype,istats,
9461 #else
9462 #ifdef CRAY
9463 	RDORCD(idebug,irtype,istats,
9464 #else
9465 	rdorcd_(idebug,irtype,istats,
9466 #endif
9467 #endif
9468 	xyzp->ianz,xyzp->iatoms,
9469 	dorbp->focc,dorbp->focb,dorbp->nocc,dorbp->nocb,
9470 	dorbp->ncols,dorbp->ncolb);
9471 
9472 }
9473 
9474 #if defined(VMS) || defined(UNDERSC)
rdnwch(idebug,irtype,istats)9475 void rdnwch(idebug,irtype,istats)
9476 #else
9477 #ifdef CRAY
9478 void RDNWCH(idebug,irtype,istats)
9479 #else
9480 void rdnwch_(idebug,irtype,istats)
9481 #endif
9482 #endif
9483 int *idebug;
9484 int *irtype;
9485 int *istats;
9486 {
9487 
9488 #if defined(VMS) || defined(UNDERSC)
9489 	rdnwcd(idebug,irtype,istats,
9490 #else
9491 #ifdef CRAY
9492 	RDNWCD(idebug,irtype,istats,
9493 #else
9494 	rdnwcd_(idebug,irtype,istats,
9495 #endif
9496 #endif
9497 	xyzp->ianz,xyzp->iatoms,
9498 	dorbp->focc,dorbp->focb,dorbp->nocc,dorbp->nocb,
9499 	dorbp->ncols,dorbp->ncolb,xyzp->coo);
9500 
9501 }
9502 
9503 #if defined(VMS) || defined(UNDERSC)
rdmaud(idebug,istatio,istats)9504 void rdmaud(idebug,istatio,istats)
9505 #else
9506 #ifdef CRAY
9507 void RDMAUD(idebug,istatio,istats)
9508 #else
9509 void rdmaud_(idebug,istatio,istats)
9510 #endif
9511 #endif
9512 int *idebug;
9513 int *istatio;
9514 int *istats;
9515 {
9516 
9517 #if defined(VMS) || defined(UNDERSC)
9518 	rdmadd(idebug,istatio,istats,
9519 #else
9520 #ifdef CRAY
9521 	RDMADD(idebug,istatio,istats,
9522 #else
9523 	rdmadd_(idebug,istatio,istats,
9524 #endif
9525 #endif
9526 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->eiga,
9527 	dorbp->eigb,dorbp->averag,dorbp->p,orbp->qd,orbp->pd,
9528 	dorbp->nocc,dorbp->nocb,dorbp->ncols,dorbp->ncolb,
9529 	geop->formax,geop->forrms,geop->dismax,geop->disrms,
9530 	geop->epoints,geop->isav,xyzp->qat);
9531 
9532 }
9533 
9534 #if defined(VMS) || defined(UNDERSC)
rdmold(idebug,istatio,irtype,iesp,istats)9535 void rdmold(idebug,istatio,irtype,iesp,istats)
9536 #else
9537 #ifdef CRAY
9538 void RDMOLD(idebug,istatio,irtype,iesp,istats)
9539 #else
9540 void rdmold_(idebug,istatio,irtype,iesp,istats)
9541 #endif
9542 #endif
9543 int *idebug;
9544 int *istatio;
9545 int *irtype;
9546 int *iesp;
9547 int *istats;
9548 {
9549 
9550 #if defined(VMS) || defined(UNDERSC)
9551 	rdmodd(idebug,istatio,irtype,iesp,istats,
9552 #else
9553 #ifdef CRAY
9554 	RDMODD(idebug,istatio,irtype,iesp,istats,
9555 #else
9556 	rdmodd_(idebug,istatio,irtype,iesp,istats,
9557 #endif
9558 #endif
9559 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->eiga,
9560 	dorbp->eigb,dorbp->nocc,dorbp->nocb,dorbp->ncols,dorbp->ncolb,
9561 	dorbp->stoalfa,dorbp->stobnorm,dorbp->istos,dorbp->naorbs,
9562 	geop->formax,geop->forrms,geop->dismax,geop->disrms,
9563 	geop->epoints,geop->isav);
9564 
9565 }
9566 
9567 #if defined(VMS) || defined(UNDERSC)
prtmolf(iun,ihaszm,ipoints)9568 void prtmolf(iun,ihaszm,ipoints)
9569 #else
9570 #ifdef CRAY
9571 void PRTMOLF(iun,ihaszm,ipoints)
9572 #else
9573 void prtmolf_(iun,ihaszm,ipoints)
9574 #endif
9575 #endif
9576 int *iun;
9577 int *ihaszm;
9578 int *ipoints;
9579 {
9580 
9581 #if defined(VMS) || defined(UNDERSC)
9582 	prtmold(iun,ihaszm,ipoints,
9583 #else
9584 #ifdef CRAY
9585 	PRTMOLD(iun,ihaszm,ipoints,
9586 #else
9587 	prtmold_(iun,ihaszm,ipoints,
9588 #endif
9589 #endif
9590 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->eiga,
9591 	dorbp->eigb,dorbp->nocc,dorbp->nocb,dorbp->ncols,dorbp->ncolb,
9592 	dorbp->stoalfa,dorbp->stobnorm,dorbp->istos,dorbp->naorbs,
9593 	geop->formax,geop->forrms,geop->dismax,geop->disrms,
9594 	geop->epoints,geop->isav,xyzp->ianz);
9595 
9596 }
9597 
9598 #if defined(VMS) || defined(UNDERSC)
rdvct(idebug,istats)9599 void rdvct(idebug,istats)
9600 #else
9601 #ifdef CRAY
9602 void RDVCT(idebug,istats)
9603 #else
9604 void rdvct_(idebug,istats)
9605 #endif
9606 #endif
9607 int *idebug;
9608 int *istats;
9609 {
9610 
9611 #if defined(VMS) || defined(UNDERSC)
9612 	rdvcd(idebug,istats,
9613 #else
9614 #ifdef CRAY
9615 	RDVCD(idebug,istats,
9616 #else
9617 	rdvcd_(idebug,istats,
9618 #endif
9619 #endif
9620 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->eiga,dorbp->eigb,
9621 	dorbp->ncols,dorbp->ncolb);
9622 
9623 }
9624 
9625 #if defined(VMS) || defined(UNDERSC)
rdvect(idebug,ig94,istats)9626 void rdvect(idebug,ig94,istats)
9627 #else
9628 #ifdef CRAY
9629 void RDVECT(idebug,ig94,istats)
9630 #else
9631 void rdvect_(idebug,ig94,istats)
9632 #endif
9633 #endif
9634 int *idebug;
9635 int *ig94;
9636 int *istats;
9637 {
9638 
9639 #if defined(VMS) || defined(UNDERSC)
9640 	rdvecd(idebug,ig94,istats,
9641 #else
9642 #ifdef CRAY
9643 	RDVECD(idebug,ig94,istats,
9644 #else
9645 	rdvecd_(idebug,ig94,istats,
9646 #endif
9647 #endif
9648 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->eiga,dorbp->eigb,
9649 	dorbp->ncols,dorbp->ncolb);
9650 
9651 }
9652 
9653 #if defined(VMS) || defined(UNDERSC)
exxtop(npr,norbs)9654 void exxtop(npr,norbs)
9655 #else
9656 #ifdef CRAY
9657 void EXXTOP(npr,norbs)
9658 #else
9659 void exxtop_(npr,norbs)
9660 #endif
9661 #endif
9662 int *npr;
9663 int *norbs;
9664 {
9665 
9666 #if defined(VMS) || defined(UNDERSC)
9667 	exxtod(npr,norbs,
9668 #else
9669 #ifdef CRAY
9670 	EXXTOD(npr,norbs,
9671 #else
9672 	exxtod_(npr,norbs,
9673 #endif
9674 #endif
9675 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,
9676 	dorbp->eiga,dorbp->eigb);
9677 
9678 }
9679 
9680 #if defined(VMS) || defined(UNDERSC)
rdqvec(idebug,istats)9681 void rdqvec(idebug,istats)
9682 #else
9683 #ifdef CRAY
9684 void RDQVEC(idebug,istats)
9685 #else
9686 void rdqvec_(idebug,istats)
9687 #endif
9688 #endif
9689 int *idebug;
9690 int *istats;
9691 {
9692 
9693 #if defined(VMS) || defined(UNDERSC)
9694 	rdqvcd(idebug,istats,
9695 #else
9696 #ifdef CRAY
9697 	RDQVCD(idebug,istats,
9698 #else
9699 	rdqvcd_(idebug,istats,
9700 #endif
9701 #endif
9702 	dorbp->vectrs,dorbp->vectrb,dorbp->eiga,dorbp->eigb,
9703 	dorbp->ncols,dorbp->ncolb);
9704 
9705 }
9706 
9707 #if defined(VMS) || defined(UNDERSC)
denfst(summ,psi)9708 void denfst(summ,psi)
9709 #else
9710 #ifdef CRAY
9711 void DENFST(summ,psi)
9712 #else
9713 void denfst_(summ,psi)
9714 #endif
9715 #endif
9716 double *summ;
9717 double *psi;
9718 {
9719 
9720 #if defined(VMS) || defined(UNDERSC)
9721 	denfsd(summ,psi,
9722 #else
9723 #ifdef CRAY
9724 	DENFSD(summ,psi,
9725 #else
9726 	denfsd_(summ,psi,
9727 #endif
9728 #endif
9729 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb);
9730 
9731 }
9732 
9733 #if defined(VMS) || defined(UNDERSC)
datin(npts1,npts2,npts3)9734 void datin(npts1,npts2,npts3)
9735 #else
9736 #ifdef CRAY
9737 void DATIN(npts1,npts2,npts3)
9738 #else
9739 void datin_(npts1,npts2,npts3)
9740 #endif
9741 #endif
9742 int *npts1;
9743 int *npts2;
9744 int *npts3;
9745 {
9746 
9747 #if defined(VMS) || defined(UNDERSC)
9748 	datid(npts1,npts2,npts3,
9749 #else
9750 #ifdef CRAY
9751 	DATID(npts1,npts2,npts3,
9752 #else
9753 	datid_(npts1,npts2,npts3,
9754 #endif
9755 #endif
9756 	dorbp->ncols,dorbp->ncolb,dorbp->focc,dorbp->focb,dorbp->eiga,dorbp->eigb);
9757 
9758 }
9759 
9760 #if defined(VMS) || defined(UNDERSC)
homo(ipsi)9761 void homo(ipsi)
9762 #else
9763 #ifdef CRAY
9764 void HOMO(ipsi)
9765 #else
9766 void homo_(ipsi)
9767 #endif
9768 #endif
9769 int *ipsi;
9770 {
9771 
9772 #if defined(VMS) || defined(UNDERSC)
9773 	homod(ipsi,
9774 #else
9775 #ifdef CRAY
9776 	HOMOD(ipsi,
9777 #else
9778 	homod_(ipsi,
9779 #endif
9780 #endif
9781 	dorbp->focc,dorbp->focb,dorbp->eiga,dorbp->eigb);
9782 
9783 }
9784 
9785 #if defined(VMS) || defined(UNDERSC)
lumo(ipsi)9786 void lumo(ipsi)
9787 #else
9788 #ifdef CRAY
9789 void LUMO(ipsi)
9790 #else
9791 void lumo_(ipsi)
9792 #endif
9793 #endif
9794 int *ipsi;
9795 {
9796 
9797 #if defined(VMS) || defined(UNDERSC)
9798 	lumod(ipsi,
9799 #else
9800 #ifdef CRAY
9801 	LUMOD(ipsi,
9802 #else
9803 	lumod_(ipsi,
9804 #endif
9805 #endif
9806 	dorbp->focc,dorbp->focb,dorbp->eiga,dorbp->eigb);
9807 
9808 }
9809 
9810 #if defined(VMS) || defined(UNDERSC)
occup(istat)9811 void occup(istat)
9812 #else
9813 #ifdef CRAY
9814 void OCCUP(istat)
9815 #else
9816 void occup_(istat)
9817 #endif
9818 #endif
9819 int *istat;
9820 {
9821 
9822 #if defined(VMS) || defined(UNDERSC)
9823 	occupd(istat,
9824 #else
9825 #ifdef CRAY
9826 	OCCUPD(istat,
9827 #else
9828 	occupd_(istat,
9829 #endif
9830 #endif
9831 	dorbp->focc,dorbp->focb);
9832 
9833 }
9834 
9835 /* END shadow C routines for Fortran routines to pass orbital pointers */
9836 
9837 /* shadow C routines for Fortran routines to pass grid pointers */
9838 
9839 #if defined(VMS) || defined(UNDERSC)
asurf(idomap,idocal)9840 void asurf(idomap,idocal)
9841 #else
9842 #ifdef CRAY
9843 void ASURF(idomap,idocal)
9844 #else
9845 void asurf_(idomap,idocal)
9846 #endif
9847 #endif
9848 int *idomap;
9849 int *idocal;
9850 {
9851        int mapit,idum;
9852 
9853        mapit = 1;
9854 
9855 #if defined(VMS) || defined(UNDERSC)
9856        if (*idomap) almgrd();
9857        if (*idocal) srfcal(idomap,sgrd.denn,mgrd.fmap,xyzp->coo,
9858 			xyzp->lwrit,xyzp->ityp,xyzp->icont,xyzp->ncont);
9859        else mapsrf(sgrd.denn,mgrd.fmap,&mapit);
9860 #else
9861 #ifdef CRAY
9862        if (*idomap) ALMGRD();
9863        if (*idocal) SRFCAL(idomap,sgrd.denn,mgrd.fmap,xyzp->coo,
9864 			xyzp->lwrit,xyzp->ityp,xyzp->icont,xyzp->ncont);
9865        else MAPSRF(sgrd.denn,mgrd.fmap,&mapit);
9866 #else
9867        if (*idomap) almgrd_();
9868        if (*idocal) srfcal_(idomap,sgrd.denn,mgrd.fmap,xyzp->coo,
9869 			xyzp->lwrit,xyzp->ityp,xyzp->icont,xyzp->ncont);
9870        else mapsrf_(sgrd.denn,mgrd.fmap,&mapit);
9871 #endif
9872 #endif
9873 }
9874 
9875 #if defined(VMS) || defined(UNDERSC)
cntour(a,mdim,imax,jmax,pz,value,r11,id)9876 void cntour(a,mdim,imax,jmax,pz,value,r11,id)
9877 #else
9878 #ifdef CRAY
9879 void CNTOUR(a,mdim,imax,jmax,pz,value,r11,id)
9880 #else
9881 void cntour_(a,mdim,imax,jmax,pz,value,r11,id)
9882 #endif
9883 #endif
9884 double *a;
9885 int *mdim;
9886 int *imax;
9887 int *jmax;
9888 double *pz;
9889 double *value;
9890 double *r11;
9891 int *id;
9892 {
9893 
9894 #if defined(VMS) || defined(UNDERSC)
9895 	cntoud(a,mdim,imax,jmax,pz,value,r11,id,
9896 #else
9897 #ifdef CRAY
9898 	CNTOUD(a,mdim,imax,jmax,pz,value,r11,id,
9899 #else
9900 	cntoud_(a,mdim,imax,jmax,pz,value,r11,id,
9901 #endif
9902 #endif
9903 	sgrd.ix);
9904 
9905 }
9906 
9907 #if defined(VMS) || defined(UNDERSC)
den3d(npts1,npts2,scale)9908 void den3d(npts1,npts2,scale)
9909 #else
9910 #ifdef CRAY
9911 void DEN3D(npts1,npts2,scale)
9912 #else
9913 void den3d_(npts1,npts2,scale)
9914 #endif
9915 #endif
9916 int *npts1;
9917 int *npts2;
9918 double *scale;
9919 {
9920 
9921 #if defined(VMS) || defined(UNDERSC)
9922 	dendd(npts1,npts2,scale,
9923 #else
9924 #ifdef CRAY
9925 	DENDD(npts1,npts2,scale,
9926 #else
9927 	dendd_(npts1,npts2,scale,
9928 #endif
9929 #endif
9930 	sgrd.dens,sgrd.edx,sgrd.edy,sgrd.iedlog);
9931 
9932 }
9933 
9934 #if defined(VMS) || defined(UNDERSC)
dencnt(npts1,npts2,fcnt)9935 void dencnt(npts1,npts2,fcnt)
9936 #else
9937 #ifdef CRAY
9938 void DENCNT(npts1,npts2,fcnt)
9939 #else
9940 void dencnt_(npts1,npts2,fcnt)
9941 #endif
9942 #endif
9943 int *npts1;
9944 int *npts2;
9945 double *fcnt;
9946 {
9947 
9948 #if defined(VMS) || defined(UNDERSC)
9949 	dencnd(npts1,npts2,fcnt,
9950 #else
9951 #ifdef CRAY
9952 	DENCND(npts1,npts2,fcnt,
9953 #else
9954 	dencnd_(npts1,npts2,fcnt,
9955 #endif
9956 #endif
9957 	sgrd.dens,sgrd.iedlog);
9958 
9959 }
9960 
9961 #if defined(VMS) || defined(UNDERSC)
grdcl(npts1,npts2,iprnt,space)9962 void grdcl(npts1,npts2,iprnt,space)
9963 #else
9964 #ifdef CRAY
9965 void GRDCL(npts1,npts2,iprnt,space)
9966 #else
9967 void grdcl_(npts1,npts2,iprnt,space)
9968 #endif
9969 #endif
9970 int *npts1;
9971 int *npts2;
9972 int *iprnt;
9973 double *space;
9974 {
9975 
9976 #if defined(VMS) || defined(UNDERSC)
9977 	grdcd(npts1,npts2,iprnt,space,
9978 #else
9979 #ifdef CRAY
9980 	GRDCD(npts1,npts2,iprnt,space,
9981 #else
9982 	grdcd_(npts1,npts2,iprnt,space,
9983 #endif
9984 #endif
9985 	sgrd.dens);
9986 }
9987 
9988 #if defined(VMS) || defined(UNDERSC)
resedl()9989 void resedl()
9990 #else
9991 #ifdef CRAY
9992 void RESEDL()
9993 #else
9994 void resedl_()
9995 #endif
9996 #endif
9997 {
9998 
9999 #if defined(VMS) || defined(UNDERSC)
10000 	resedd(sgrd.iedlog);
10001 #else
10002 #ifdef CRAY
10003 	RESEDD(sgrd.iedlog);
10004 #else
10005 	resedd_(sgrd.iedlog);
10006 #endif
10007 #endif
10008 
10009 }
10010 
10011 typedef struct {
10012 	int init;
10013 	int nhetz[MXHETA];
10014 	int istz[MXHETA]; } HETTMPSTRU;
10015 static HETTMPSTRU HetTmp = {.init = 0};
10016 
iniHetTmp()10017 void iniHetTmp()
10018 {
10019    int i,j;
10020 
10021 	for (j=0; j<hetptr.NHetAtm; j++) {
10022 	    HetTmp.nhetz[j] = 0;
10023 	    HetTmp.istz[j] = -1;
10024 	}
10025 
10026         for (i=0; i<*xyzp->iatoms; i++) {
10027 	   for (j=4; j<hetptr.NHetAtm; j++) {
10028 		if (xyzp->iresid[i] == -j) {
10029 		   if (HetTmp.istz[j] == -1) HetTmp.istz[j] = i;
10030 		   HetTmp.nhetz[j]++;
10031 		}
10032 	   }
10033 	}
10034 	HetTmp.init = 1;
10035 }
10036 
ChkHetCoo(opt)10037 void ChkHetCoo(opt)
10038 int opt;
10039 {
10040    int i,j,k,l;
10041    double x,y,z,tol,tol2;
10042    int confl[MXHETA];
10043 
10044    tol = 0.1;
10045    tol2 = tol*tol;
10046 
10047    for (i=0; i<MXHETA; i++) confl[i] = 0;
10048 
10049    for (i=HetTmp.istz[opt]; i<HetTmp.istz[opt]+HetTmp.nhetz[opt]; i++) {
10050 	for (j=4; j<hetptr.NHetAtm; j++) {
10051 	   if (j != opt) {
10052 		for (k=HetTmp.istz[j]; k<HetTmp.istz[j]+HetTmp.nhetz[j]; k++) {
10053 		   x = xyzp->coo[k*3  ] - xyzp->coo[i*3  ];
10054 		   y = xyzp->coo[k*3+1] - xyzp->coo[i*3+1];
10055 		   z = xyzp->coo[k*3+2] - xyzp->coo[i*3+2];
10056 		   if (x*x + y*y + z*z < tol2) {
10057 			fprintf(stderr,"Residue %s, atom %d: Distance to atom %d  of residue %s is nearly zero!\n",hetptr.HetAtm[opt],i,k,hetptr.HetAtm[j]);
10058 			confl[j] = 1;
10059 		   }
10060 		}
10061 	   }
10062 	}
10063    }
10064 
10065    for (i=4; i<MXHETA; i++)  {
10066 	if (confl[i]) {
10067 	    sprintf(cmdstr,
10068 	"Conflict Ligand %s and ligand %s\nAtoms overlap: Remove ligand %s from pdb file,\nif you want Molden to correctly add hydrogens",
10069 		hetptr.HetAtm[opt],hetptr.HetAtm[i],hetptr.HetAtm[i]);
10070 	    if (DoCan(event.xbutton.x_root,event.xbutton.y_root,cmdstr,
10071 		0)) {}
10072 
10073 	}
10074    }
10075 }
10076 
10077 #if defined(VMS) || defined(UNDERSC)
maxmin(npts1,npts2,scale)10078 void maxmin(npts1,npts2,scale)
10079 #else
10080 #ifdef CRAY
10081 void MAXMIN(npts1,npts2,scale)
10082 #else
10083 void maxmin_(npts1,npts2,scale)
10084 #endif
10085 #endif
10086 int *npts1;
10087 int *npts2;
10088 double *scale;
10089 {
10090 
10091 #if defined(VMS) || defined(UNDERSC)
10092 	maxmid(npts1,npts2,scale,
10093 #else
10094 #ifdef CRAY
10095 	MAXMID(npts1,npts2,scale,
10096 #else
10097 	maxmid_(npts1,npts2,scale,
10098 #endif
10099 #endif
10100 	sgrd.dens);
10101 }
10102 
10103 #if defined(VMS) || defined(UNDERSC)
plden(ndim1,ndim2,scale,icells,adjus,idisml)10104 void plden(ndim1,ndim2,scale,icells,adjus,idisml)
10105 #else
10106 #ifdef CRAY
10107 void PLDEN(ndim1,ndim2,scale,icells,adjus,idisml)
10108 #else
10109 void plden_(ndim1,ndim2,scale,icells,adjus,idisml)
10110 #endif
10111 #endif
10112 int *ndim1;
10113 int *ndim2;
10114 double *scale;
10115 int *icells;
10116 double *adjus;
10117 int *idisml;
10118 {
10119 
10120 #if defined(VMS) || defined(UNDERSC)
10121 	plded(ndim1,ndim2,scale,icells,adjus,idisml,
10122 #else
10123 #ifdef CRAY
10124 	PLDED(ndim1,ndim2,scale,icells,adjus,idisml,
10125 #else
10126 	plded_(ndim1,ndim2,scale,icells,adjus,idisml,
10127 #endif
10128 #endif
10129 	sgrd.dens,sgrd.ix,sgrd.iy,sgrd.rz);
10130 }
10131 
10132 #if defined(VMS) || defined(UNDERSC)
p3dv(iun,scale,ndimx,ndimz,adjus)10133 void p3dv(iun,scale,ndimx,ndimz,adjus)
10134 #else
10135 #ifdef CRAY
10136 void P3DV(iun,scale,ndimx,ndimz,adjus)
10137 #else
10138 void p3dv_(iun,scale,ndimx,ndimz,adjus)
10139 #endif
10140 #endif
10141 int *iun;
10142 double *scale;
10143 int *ndimx;
10144 int *ndimz;
10145 double *adjus;
10146 {
10147 
10148 #if defined(VMS) || defined(UNDERSC)
10149 	p3dd(iun,scale,ndimx,ndimz,adjus,
10150 #else
10151 #ifdef CRAY
10152 	P3DD(iun,scale,ndimx,ndimz,adjus,
10153 #else
10154 	p3dd_(iun,scale,ndimx,ndimz,adjus,
10155 #endif
10156 #endif
10157 	sgrd.dens);
10158 }
10159 
10160 #if defined(VMS) || defined(UNDERSC)
rdcube(npts1,npts2,npts3,iposng,ipsi,istat,iun,idebug)10161 void rdcube(npts1,npts2,npts3,iposng,ipsi,istat,iun,idebug)
10162 #else
10163 #ifdef CRAY
10164 void RDCUBE(npts1,npts2,npts3,iposng,ipsi,istat,iun,idebug)
10165 #else
10166 void rdcube_(npts1,npts2,npts3,iposng,ipsi,istat,iun,idebug)
10167 #endif
10168 #endif
10169 int *npts1;
10170 int *npts2;
10171 int *npts3;
10172 int *iposng;
10173 int *ipsi;
10174 int *istat;
10175 int *iun;
10176 int *idebug;
10177 {
10178 
10179 #if defined(VMS) || defined(UNDERSC)
10180 	rdcubd(npts1,npts2,npts3,iposng,ipsi,istat,iun,idebug,
10181 #else
10182 #ifdef CRAY
10183 	RDCUBD(npts1,npts2,npts3,iposng,ipsi,istat,iun,idebug,
10184 #else
10185 	rdcubd_(npts1,npts2,npts3,iposng,ipsi,istat,iun,idebug,
10186 #endif
10187 #endif
10188 	sgrd.denn,sgrd.pmnn);
10189 
10190 }
10191 
10192 #if defined(VMS) || defined(UNDERSC)
wrcube(npts1,npts2,npts3,ipsi)10193 void wrcube(npts1,npts2,npts3,ipsi)
10194 #else
10195 #ifdef CRAY
10196 void WRCUBE(npts1,npts2,npts3,ipsi)
10197 #else
10198 void wrcube_(npts1,npts2,npts3,ipsi)
10199 #endif
10200 #endif
10201 int *npts1;
10202 int *npts2;
10203 int *npts3;
10204 int *ipsi;
10205 {
10206 
10207 #if defined(VMS) || defined(UNDERSC)
10208 	wrcubd(npts1,npts2,npts3,ipsi,
10209 #else
10210 #ifdef CRAY
10211 	WRCUBD(npts1,npts2,npts3,ipsi,
10212 #else
10213 	wrcubd_(npts1,npts2,npts3,ipsi,
10214 #endif
10215 #endif
10216 	sgrd.denn);
10217 
10218 }
10219 
10220 #if defined(VMS) || defined(UNDERSC)
rdgrd(npts1,npts2,npts3,iun,istat)10221 void rdgrd(npts1,npts2,npts3,iun,istat)
10222 #else
10223 #ifdef CRAY
10224 void RDGRD(npts1,npts2,npts3,iun,istat)
10225 #else
10226 void rdgrd_(npts1,npts2,npts3,iun,istat)
10227 #endif
10228 #endif
10229 int *npts1;
10230 int *npts2;
10231 int *npts3;
10232 int *istat;
10233 int *iun;
10234 {
10235 
10236 #if defined(VMS) || defined(UNDERSC)
10237 	rdgrdd(npts1,npts2,npts3,iun,istat,
10238 #else
10239 #ifdef CRAY
10240 	RDGRDD(npts1,npts2,npts3,iun,istat,
10241 #else
10242 	rdgrdd_(npts1,npts2,npts3,iun,istat,
10243 #endif
10244 #endif
10245 	sgrd.denn,sgrd.dens,sgrd.pmnn,sgrd.denst,&cell->ichx);
10246 
10247 }
10248 
10249 #if defined(VMS) || defined(UNDERSC)
rdomap(npts1,npts2,npts3,iun,istat)10250 void rdomap(npts1,npts2,npts3,iun,istat)
10251 #else
10252 #ifdef CRAY
10253 void RDOMAP(npts1,npts2,npts3,iun,istat)
10254 #else
10255 void rdomap_(npts1,npts2,npts3,iun,istat)
10256 #endif
10257 #endif
10258 int *npts1;
10259 int *npts2;
10260 int *npts3;
10261 int *istat;
10262 int *iun;
10263 {
10264 
10265 #if defined(VMS) || defined(UNDERSC)
10266 	rdomad(npts1,npts2,npts3,iun,istat,
10267 #else
10268 #ifdef CRAY
10269 	RDOMAD(npts1,npts2,npts3,iun,istat,
10270 #else
10271 	rdomad_(npts1,npts2,npts3,iun,istat,
10272 #endif
10273 #endif
10274 	sgrd.denn,sgrd.dens,sgrd.pmnn,&cell->ichx);
10275 
10276 }
10277 
10278 #if defined(VMS) || defined(UNDERSC)
rdccp4(npts1,npts2,npts3,iun,istat)10279 void rdccp4(npts1,npts2,npts3,iun,istat)
10280 #else
10281 #ifdef CRAY
10282 void RDCCP4(npts1,npts2,npts3,iun,istat)
10283 #else
10284 void rdccp4_(npts1,npts2,npts3,iun,istat)
10285 #endif
10286 #endif
10287 int *npts1;
10288 int *npts2;
10289 int *npts3;
10290 int *istat;
10291 int *iun;
10292 {
10293 
10294 #if defined(VMS) || defined(UNDERSC)
10295 	rdccpd(npts1,npts2,npts3,iun,istat,
10296 #else
10297 #ifdef CRAY
10298 	RDCCPD(npts1,npts2,npts3,iun,istat,
10299 #else
10300 	rdccpd_(npts1,npts2,npts3,iun,istat,
10301 #endif
10302 #endif
10303 	sgrd.denn,sgrd.dens,sgrd.pmnn,&cell->ichx,
10304 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2]);
10305 
10306 }
10307 
10308 static XColor extdef[256];
10309 
GetExact()10310 void GetExact()
10311 {
10312     int i,r,g,b,ret;
10313 
10314     for (i=0; i<256; i++) {
10315 	extdef[i].pixel = colors[i];
10316 	XQueryColor(display,cmap,&extdef[i]);
10317     }
10318 }
10319 
ApproxCol(r0,g0,b0)10320 int ApproxCol(r0,g0,b0)
10321 int r0;
10322 int b0;
10323 int g0;
10324 {
10325     int i,r,g,b,ret;
10326     int dr,dg,db,dx;
10327     XColor exact_def;
10328 
10329     dx = 1000;
10330     ret = 0;
10331 
10332     for (i=0; i<256; i++) {
10333         r = (int) extdef[i].red>>8;
10334         g = (int) extdef[i].green>>8;
10335         b = (int) extdef[i].blue>>8;
10336 	dr = ABS(r0-r); dg = ABS(g0-g); db = ABS(b0-b);
10337 	if (dr+dg+db < dx) {
10338 	   dx = dr+dg+db;
10339 	   ret = i;
10340 	}
10341     }
10342     return(ret);
10343 }
10344 
mkext(str,ext)10345 char * mkext(str,ext)
10346 char *str;
10347 char *ext;
10348 {
10349    char *xstr1;
10350    char *last1;
10351    char *dot1;
10352    int l,n1=0;
10353 
10354    if (str != NULL) {
10355 	last1 = str;
10356 	l = strlen(last1);
10357 	xstr1 = (char *) malloc(sizeof(char)*(l+6));
10358 	if (xstr1 == NULL) return(NULL);
10359 	if (last1 != NULL) {
10360 	   dot1 = strrchr(last1,'.');
10361 	   if (dot1 != NULL) {
10362 		n1 = (int) (dot1 - last1);
10363 		strncpy(xstr1,last1,n1);
10364 		xstr1[n1] = '\0';
10365 		strcat(xstr1,ext);
10366 	   } else {
10367 		return(NULL);
10368 	   }
10369 	} else {
10370 	   return(NULL);
10371 	}
10372    } else {
10373 	return(NULL);
10374    }
10375 
10376    return(xstr1);
10377 }
10378 
Cvt2SVG()10379 void Cvt2SVG()
10380 {
10381   char str[500];
10382   int n,i,pid;
10383 
10384   if (getob()) {
10385 	if (OBloc) {
10386 	   sprintf(str,
10387 	   "%sobabel -imol /tmp/tmpje.mol --gen2D -d -osvg -xC -xd -O /tmp/b.svg &> /dev/null &",
10388 	   exepath[0]);
10389 
10390 	} else {
10391 	   sprintf(str,
10392 	   "/usr/local/bin/obabel -imol /tmp/tmpje.mol --gen2D -d -osvg -xC -xd -O /tmp/b.svg &> /dev/null &");
10393 	}
10394 
10395 	n = strlen(str);
10396 	system(str);
10397 
10398  	DCKsvg = (SVGFSTRUC *) malloc(sizeof(SVGFSTRUC));
10399 
10400 	GetExact();
10401 	rdsvg(DCKsvg,"/tmp/b.svg");
10402 /*
10403 	rdsvg(DCKsvg,"c.svg");
10404 */
10405 
10406 	DrawSVG(10, 10, 50 , 50,*DCKsvg,windock);
10407 	DCKSVG = 1;
10408   }
10409 
10410 }
10411 
rdsvgs()10412 int rdsvgs()
10413 {
10414    int i,j,n,ntits,ncmd,itmp;
10415    int fd;
10416    char *xstr1;
10417 
10418    xstr1 = mkext(COO[istruct]->fname,".svgs");
10419 
10420    fd = open(xstr1,O_RDONLY,0644);
10421 
10422    if (fd < 0) {
10423 	fprintf(stderr,"rdsvgs: Error opening file %s\n",xstr1);
10424  	return(1);
10425    }
10426 
10427    read(fd,&ntits,sizeof(int));
10428 
10429    if (COO[istruct]->ntits != ntits) {
10430 	fprintf(stderr,"ntits read %d not equal ntits in memory %d\n",
10431 		ntits,COO[istruct]->ntits);
10432 	return(1);
10433    }
10434 
10435    COO[istruct]->svgs =
10436 	(SVGFSTRUC *) malloc(sizeof(SVGFSTRUC)*(ntits));
10437 
10438    for (i = 0; i < COO[istruct]->ntits; i++) {
10439 	read(fd,&COO[istruct]->svgs[i],sizeof(SVGFSTRUC));
10440 	ncmd = COO[istruct]->svgs[i].ncmd;
10441 	if (ncmd == 0) {
10442 	   if (i > 0) bcksvg.CurSVG = i - 1;
10443 	   close(fd);
10444 	   return(1);
10445 	}
10446 	COO[istruct]->svgs[i].array =
10447 		(SVGSTRUC *) malloc(sizeof(SVGSTRUC)*(ncmd));
10448 	for (j = 0; j < ncmd; j++) {
10449 	   read(fd,&COO[istruct]->svgs[i].array[j],sizeof(SVGSTRUC));
10450 	}
10451 	for (j = 0; j < ncmd; j++) {
10452 	   if (COO[istruct]->svgs[i].array[j].type != 1) {
10453 		COO[istruct]->svgs[i].array[j].str = NULL;
10454 		read(fd,&itmp,sizeof(int));
10455 	   } else {
10456 		read(fd,&n,sizeof(int));
10457 		COO[istruct]->svgs[i].array[j].str =
10458 			(char *) malloc(sizeof(char)*(n+1));
10459 		read(fd,COO[istruct]->svgs[i].array[j].str,sizeof(char)*n);
10460 		COO[istruct]->svgs[i].array[j].str[n] = '\0';
10461 	   }
10462 	}
10463    }
10464 
10465    close(fd);
10466    COO[istruct]->svgdone = 1;
10467    return(0);
10468 
10469 }
10470 
wrsvgs()10471 int wrsvgs()
10472 {
10473    SVGSTRUC rec;
10474    int i,j,n;
10475    int fd;
10476    char xstr1[MAXCMD];
10477    char *last1;
10478    char *dot1;
10479    int n1=0;
10480 
10481    if (COO[bcksvg.istruct]->svgs == NULL) return(1);
10482 
10483    last1 = COO[bcksvg.istruct]->fname;
10484    if (last1 != NULL) {
10485 	dot1 = strrchr(last1,'.');
10486 	if (dot1 != NULL) {
10487 	   n1 = (int) (dot1 - last1);
10488 	   strncpy(xstr1,last1,n1);
10489 	   xstr1[n1] = '\0';
10490 	   strcat(xstr1,".svgs");
10491 	} else {
10492 	   return(1);
10493 	}
10494    } else {
10495 	return(1);
10496    }
10497 
10498 
10499    fd = open(xstr1,O_WRONLY|O_CREAT,0644);
10500 
10501    if (fd < 0) {
10502 	fprintf(stderr,"wrsvgs: Error opening file %s\n",xstr1);
10503  	return(1);
10504    }
10505 
10506    write(fd,&COO[bcksvg.istruct]->ntits,sizeof(int));
10507 
10508    for (i = 0; i < COO[bcksvg.istruct]->ntits; i++) {
10509 	write(fd,&COO[bcksvg.istruct]->svgs[i],sizeof(SVGFSTRUC));
10510 	for (j = 0; j < COO[bcksvg.istruct]->svgs[i].ncmd; j++) {
10511 	   write(fd,&COO[bcksvg.istruct]->svgs[i].array[j],sizeof(SVGSTRUC));
10512 	}
10513 	for (j = 0; j < COO[bcksvg.istruct]->svgs[i].ncmd; j++) {
10514 	   if (COO[bcksvg.istruct]->svgs[i].array[j].type != 1) {
10515 		write(fd,&MONE,sizeof(int));
10516 	   } else {
10517 		n = strlen(COO[bcksvg.istruct]->svgs[i].array[j].str);
10518 		write(fd,&n,sizeof(int));
10519 		write(fd,COO[bcksvg.istruct]->svgs[i].array[j].str,sizeof(char)*n);
10520 	   }
10521 	}
10522    }
10523 
10524    close(fd);
10525    return(0);
10526 }
10527 
rdsvg(svgfile,str)10528 int rdsvg(svgfile,str)
10529 SVGFSTRUC *svgfile;
10530 char *str;
10531 {
10532    FILE *f;
10533    SVGSTRUC rec;
10534    char strmax[1000];
10535    char *strp;
10536    char *strpe;
10537    int ncmd = 0;
10538    int icmd,i,j;
10539    int type = 0;
10540    int n,r,g,b;
10541 
10542    f = fopen(str,"r");
10543 
10544    if (f == NULL) {
10545 	fprintf(stderr,"Error opening file %s\n",str);
10546  	return(0);
10547    }
10548 
10549    ncmd = 0;
10550    svgfile->w = 0.0;
10551    svgfile->h = 0.0;
10552    while(1) {
10553 	if (fgets(strmax,1000,f) == NULL) break;
10554 	if (strstr(strmax,"xmlns")) {
10555 	   strp = strstr(strmax,"width=");
10556 	   if (strp != NULL) {
10557 		strp++;strp++;strp++;strp++;
10558 		strp++;strp++;strp++;
10559 		sscanf(strp,"%f",&svgfile->w);
10560 	   }
10561 	   strp = strstr(strmax,"height=");
10562 	   if (strp != NULL) {
10563 		strp++;strp++;strp++;strp++;
10564 		strp++;strp++;strp++;strp++;
10565 		sscanf(strp,"%f",&svgfile->h);
10566 	   }
10567 	}
10568 	if (strstr(strmax,"<line") || strstr(strmax,"<text") ||
10569 	    strstr(strmax,"<polygon")) ncmd++;
10570    }
10571    rewind(f);
10572 
10573    svgfile->ncmd = ncmd;
10574    svgfile->array = (SVGSTRUC *) malloc(sizeof(SVGSTRUC)*(ncmd));
10575 
10576    i = -1;
10577    while(1) {
10578 	if (fgets(strmax,1000,f) == NULL) break;
10579 	if (strstr(strmax,"<line") || strstr(strmax,"<text") ||
10580 	    strstr(strmax,"<polyg")) {
10581 	   i++;
10582 	   if (strstr(strmax,"<line")) {
10583 		rec.type = 0;
10584 		rec.col = 0;
10585 
10586 		rec.x1 = 0.0;
10587 		strp = strstr(strmax,"x1=");
10588 		if (strp != NULL) {
10589 		   strp++;strp++;strp++;strp++;
10590 		   sscanf(strp,"%f",&rec.x1);
10591 		}
10592 
10593 		rec.y1 = 0.0;
10594 		strp = strstr(strmax,"y1=");
10595 		if (strp != NULL) {
10596 		   strp++;strp++;strp++;strp++;
10597 		   sscanf(strp,"%f",&rec.y1);
10598 		}
10599 
10600 		rec.x2 = 0.0;
10601 		strp = strstr(strmax,"x2=");
10602 		if (strp != NULL) {
10603 		   strp++;strp++;strp++;strp++;
10604 		   sscanf(strp,"%f",&rec.x2);
10605 		}
10606 
10607 		rec.y2 = 0.0;
10608 		strp = strstr(strmax,"y2=");
10609 		if (strp != NULL) {
10610 		   strp++;strp++;strp++;strp++;
10611 		   sscanf(strp,"%f",&rec.y2);
10612 		}
10613 	   } else if (strstr(strmax,"<text")) {
10614 		rec.type = 1;
10615 		rec.col = 0;
10616 
10617 		rec.x1 = 0.0;
10618 		strp = strstr(strmax,"x=");
10619 		if (strp != NULL) {
10620 		   strp++;strp++;strp++;
10621 		   sscanf(strp,"%f",&rec.x1);
10622 		}
10623 
10624 		rec.y1 = 0.0;
10625 		strp = strstr(strmax,"y=");
10626 		if (strp != NULL) {
10627 		   strp++;strp++;strp++;
10628 		   sscanf(strp,"%f",&rec.y1);
10629 		}
10630 
10631 		rec.str = NULL;
10632 		if (rec.type == 1) {
10633 		   strp = strstr(strmax,">");
10634 		   if (strp != NULL) {
10635 			strp++;
10636 			strpe = strstr(strp,"<");
10637 			if (strpe != NULL) {
10638 			   n = strpe - strp;
10639 			   rec.str = (char *) malloc(sizeof(char)*(n+1));
10640 			   strncpy(rec.str, strp,n);
10641 			   rec.str[n] = '\0';
10642 			}
10643 		   }
10644 		}
10645 
10646 		r = 0; g = 0; b = 0;
10647 		strp = strstr(strmax,"rgb(");
10648 		if (strp != NULL) {
10649 		   strp++;strp++;strp++;strp++;
10650 		   sscanf(strp,"%d",&r);
10651 		   strp = strstr(strp,",");
10652 		   if (strp != NULL) {
10653 			strp++;
10654 			sscanf(strp,"%d",&g);
10655 			strp = strstr(strp,",");
10656 			if (strp != NULL) {
10657 			   strp++;
10658 			   sscanf(strp,"%d",&b);
10659 			}
10660 		   }
10661 		   rec.col = ApproxCol(r,g,b);
10662   		}
10663 
10664 	   } else {
10665 		rec.type = 2;
10666 		rec.col = 0;
10667 
10668 		strp = strstr(strmax,"points=");
10669 		if (strp != NULL) {
10670 		   strp++;strp++;strp++;strp++;
10671 		   strp++;strp++;strp++;strp++;
10672 		   sscanf(strp,"%f",&rec.poly[0]);
10673 		   strp = strstr(strp," ");
10674 		   if (strp != NULL) {
10675 			strp++;
10676 			sscanf(strp,"%f",&rec.poly[1]);
10677 		        strp = strstr(strp," ");
10678 		        if (strp != NULL) {
10679 			   strp++;
10680 			   sscanf(strp,"%f",&rec.poly[2]);
10681 		           strp = strstr(strp," ");
10682 			   if (strp != NULL) {
10683 				strp++;
10684 				sscanf(strp,"%f",&rec.poly[3]);
10685 		        	strp = strstr(strp," ");
10686 				if (strp != NULL) {
10687 				   strp++;
10688 				   sscanf(strp,"%f",&rec.poly[4]);
10689 		        	   strp = strstr(strp," ");
10690 				   if (strp != NULL) {
10691 					strp++;
10692 					sscanf(strp,"%f",&rec.poly[5]);
10693 				   }
10694 				}
10695 			   }
10696 			}
10697 		   }
10698 		}
10699 
10700 	   }
10701 	   svgfile->array[i] = rec;
10702 	}
10703    }
10704 
10705    fclose(f);
10706    return(1);
10707 }
10708 
DrawSVG(x,y,w0,h0,svgfile,win)10709 void DrawSVG(x,y,w0,h0,svgfile,win)
10710 int x;
10711 int y;
10712 int w0;
10713 int h0;
10714 SVGFSTRUC svgfile;
10715 Window win;
10716 {
10717    int i,j,n;
10718    float w,h,wr,hr;
10719    XPoint poly[3];
10720 
10721    w = svgfile.w;
10722    h = svgfile.h;
10723 
10724    wr = (float) w0 / w;
10725    hr = (float) h0 / h;
10726    wr = hr;
10727 
10728    XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
10729 
10730    if (svgfile.ncmd == 0 || svgfile.array == NULL) return;
10731 
10732    for (i = 0; i < svgfile.ncmd; i++) {
10733 	if (svgfile.array[i].type == 1) {
10734 	   if (svgfile.array[i].str != NULL) {
10735            XSetForeground(display, gc1, colors[svgfile.array[i].col]);
10736 	   XDrawString(display,win,gc1,
10737 		x + (int) svgfile.array[i].x1*wr,
10738 		y + (int) svgfile.array[i].y1*hr,
10739 		svgfile.array[i].str,strlen(svgfile.array[i].str));
10740 	   }
10741 	} else if (svgfile.array[i].type == 2) {
10742 	   for (j = 0; j < 3; j++) {
10743 		poly[j].x = x + (int) svgfile.array[i].poly[j*2]*wr;
10744 		poly[j].y = y + (int) svgfile.array[i].poly[j*2+1]*hr;
10745 	   }
10746            XSetForeground(display, gc, colors[svgfile.array[i].col]);
10747 	   XFillPolygon(display,win,gc,poly,3,Convex,CoordModeOrigin);
10748 	} else {
10749            XSetForeground(display, gc, colors[0]);
10750 	   XDrawLine(display,win,gc,
10751 		x + (int) svgfile.array[i].x1*wr,
10752 		y + (int) svgfile.array[i].y1*hr,
10753 		x + (int) svgfile.array[i].x2*wr,
10754 		y + (int) svgfile.array[i].y2*hr);
10755 	}
10756    }
10757    XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
10758 }
10759 
disp_map(char * str)10760 void disp_map(char *str)
10761 {
10762 	int i,idopn,srft;
10763 
10764 	srft = NSurf[istruct];
10765 	NSurf[istruct] = omapsrf;
10766 	*vlcnt = omapcnt1;
10767 	idopn = 0;
10768 	if (omapPandN && !(*rng1 >= 0.0) ) {
10769 	   idopn = 1;
10770 	   *vlcnt2 = omapcnt2;
10771 	} else {
10772 	   *vlcnt2 = -omapcnt1;
10773 	}
10774 #if defined(VMS) || defined(UNDERSC)
10775 	dpomap(&idopn);
10776 #else
10777 #ifdef CRAY
10778 	DPOMAP(&idopn);
10779 #else
10780 	dpomap_(&idopn);
10781 #endif
10782 #endif
10783 #ifdef DOGL
10784 	srfprop();
10785 	if (srft > omapsrf) NSurf[istruct] = srft;
10786 
10787 	ogbox();
10788 #endif
10789 	update_struct();
10790 }
10791 
10792 #if defined(VMS) || defined(UNDERSC)
dpomap(iopt)10793 void dpomap(iopt)
10794 #else
10795 #ifdef CRAY
10796 void DPOMAP(iopt)
10797 #else
10798 void dpomap_(iopt)
10799 #endif
10800 #endif
10801 int *iopt;
10802 {
10803 
10804 #if defined(VMS) || defined(UNDERSC)
10805 	dpomad(iopt,
10806 #else
10807 #ifdef CRAY
10808 	DPOMAD(iopt,
10809 #else
10810 	dpomad_(iopt,
10811 #endif
10812 #endif
10813 	sgrd.denn);
10814 
10815 }
10816 
change_iso(int iop)10817 void change_iso(int iop)
10818 {
10819 
10820   if (!has_box) return;
10821 
10822   if (iop) {
10823 	omapcnt1 = omapcnt1 + 0.05;
10824 	if (omapcnt1 > *rng2) omapcnt1 = *rng2;
10825   } else {
10826 	omapcnt1 = omapcnt1 - 0.05;
10827 	if (omapcnt1 < 0.0) omapcnt1 = 0.0;
10828   }
10829   sprintf(qboxes[QCNT].str,"%5.2f", omapcnt1);
10830   PromptBox(&qboxes[QCNT]);
10831   disp_map(NULL);
10832   XSync(display, True);
10833 }
10834 
getcval()10835 void getcval()
10836 {
10837 	omapcnt1 = (*rng2 / 10.0);
10838 	sprintf(stemp,"%5.2f",omapcnt1);
10839 	qboxstr(&qboxes[QCNT],&OMAPwin,1,0,-1,20,180,
10840 	   50,QBOXHIGH, 0,NULL,stemp,
10841 	   0,3,2000,-1,disp_map);
10842 	qboxes[QCNT].dflt = &omapcnt1;
10843 
10844 
10845 	if (omapPandN && !(*rng1 >= 0.0) ) {
10846 	   omapcnt2 = *rng1 / 2.0;
10847 	   sprintf(stemp,"%5.2f",omapcnt2);
10848 	   qboxstr(&qboxes[QCNT2],&OMAPwin,0,0,-1,20,210,
10849 	   50,QBOXHIGH, 0,NULL,stemp,
10850 	   0,3,2000,-1,disp_map);
10851 	   qboxes[QCNT2].dflt = &omapcnt2;
10852 	}
10853 	has_box = 1;
10854 }
10855 
omap()10856 int omap()
10857 {
10858     if (!*ipdbon) {
10859 	DoCan(event.xbutton.x_root, event.xbutton.y_root,
10860 	"Electron density maps are only available for PDB files.",0);
10861 	return(1);
10862     } else {
10863 	if (pdbcode == NULL) {
10864 	     qboxstr(&qboxes[QSRFW],NULL,1,0,-1,
10865 			DEFQX,DEFQY,QBOXWIDE,QBOXHIGH,0,
10866 			"CCP4 Filename ? ",NULL,0,0,
10867 			585,1,dummyproc);
10868 			return(1);
10869 	} else {
10870 	     if (omapr == 1) {
10871 		 if (!OMAPup) InitOmap(0);
10872 	     } else {
10873 		 if (OMAPup) DeleteOMAP();
10874 		 if (!CheckWGET())
10875 		      if (!GetOMAPWWW(pdbcode,strname)) return(1);
10876 	     }
10877 	}
10878    }
10879    return(0);
10880 }
10881 
calcab(double vx[3],double vy[3],double vz[3],double vn[3],double fr[3])10882 void calcab(double vx[3], double vy[3], double vz[3], double vn[3], double fr[3])
10883 {
10884    double nz[3],vyn[3],vyx[3],vxn[3],vxy[3],nzvyn,nzvyx,nzvxn,nzvxy;
10885    double vnp[3],vnpl[3];
10886 
10887    crossprd(vx,vy,nz);
10888    CROSS(vn,nz,vnpl);
10889    CROSS(vnpl,nz,vnp);
10890    dimprod(vn,vz,&fr[2]);
10891 
10892    CROSS(vy,vnp,vyn);
10893    improduct(nz,vyn,&nzvyn);
10894    CROSS(vy,vx,vyx);
10895    improduct(nz,vyx,&nzvyx);
10896    fr[0] = ABS(nzvyn/nzvyx);
10897 
10898    CROSS(vx,vnp,vxn);
10899    improduct(nz,vxn,&nzvxn);
10900    CROSS(vx,vy,vxy);
10901    improduct(nz,vxy,&nzvxy);
10902    fr[1] = ABS(nzvxn/nzvxy);
10903 
10904 }
10905 
res_dens(int Ca,int opt)10906 void res_dens(int Ca,int opt)
10907 {
10908    int i,l;
10909    double ca[3],t[3];
10910    double slice[3];
10911    double fr[3];
10912    double tmpo[3];
10913    double devx[3],devy[3],devz[3];
10914 
10915    for (i = 0; i < 3; i++) tmpo[i] = comsrfptr->vo[i];
10916 
10917    if (opt) {
10918 	l = calfptr->icalf[Ca][0]-1;
10919 	omapCa = l;
10920    } else {
10921 	l = Ca;
10922    }
10923 
10924    for (i = 0; i < 3; i++) {
10925 	ca[i] = xyzp->coo[l*3+i] - tmpo[i];
10926 	devx[i] = comsrfptr->v1[i]*comsrfptr->r[0];
10927 	devy[i] = comsrfptr->v2[i]*comsrfptr->r[1];
10928 	devz[i] = comsrfptr->v3[i]*comsrfptr->r[2];
10929    }
10930 
10931    calcab(devx,devy,devz,ca,fr);
10932    fr[2] = ca[2]/comsrfptr->r[2];
10933 
10934 // This currently setup for alpha,beta,gamma = 90 AND
10935 // alpha,beta = 90 and gamma != 90
10936 // PDBCODE 1mep does not work
10937 
10938 // Y direction
10939 
10940    slice[2] = comsrfptr->r[2]/10.0;
10941    EQ[0] = vox[2] + extnt[2]*fr[2];
10942    omaprat[0] = (float) (fr[2] + 0.1);
10943    EQ[0] = EQ[0] + slice[2];
10944    if (omaprat[0] > 1.0) omaprat[0] = 1.0;
10945    if (omaprat[0] < 0.0) omaprat[0] = 0.0;
10946 
10947    omaprat[1] =  (float) 2.0*slice[2]/extnt[2];
10948    if (omaprat[1] < 0.0) omaprat[1] = 0.0;
10949    if (omaprat[1] > 1.0) omaprat[1] = 1.0;
10950    slab[0] = 2.0*slice[2];
10951 
10952 // X direction
10953 
10954    slice[0] = comsrfptr->r[0]/10.0;
10955    EQ[1] = vox[0] + extnt[0]*fr[0];
10956    omaprat[2] = (float) (fr[0] + 0.1);
10957    EQ[1] = EQ[1] + slice[0];
10958    if (omaprat[2] > 1.0) omaprat[2] = 1.0;
10959    if (omaprat[2] < 0.0) omaprat[2] = 0.0;
10960 
10961    omaprat[3] = (float) 2.0*slice[0]/extnt[0];
10962    if (omaprat[3] < 0.0) omaprat[3] = 0.0;
10963    if (omaprat[3] > 1.0) omaprat[3] = 1.0;
10964    slab[1] = 2.0*slice[0];
10965 
10966 // Z direction
10967 
10968    slice[1] = comsrfptr->r[1]/10.0;
10969    EQ[2] = vox[1] + extnt[1]*fr[1];
10970    omaprat[4] = (float) (fr[1] + 0.1);
10971    EQ[2] = EQ[2] + slice[1];
10972    if (omaprat[4] > 1.0) omaprat[4] = 1.0;
10973    if (omaprat[4] < 0.0) omaprat[4] = 0.0;
10974 
10975    omaprat[5] = 2.0*slice[1]/extnt[1];
10976    if (omaprat[5] < 0.0) omaprat[5] = 0.0;
10977    if (omaprat[5] > 1.0) omaprat[5] = 1.0;
10978    slab[2] = 2.0*slice[1];
10979 
10980    omapwpos[0] = (int) ((float) omapwn[0]*omaprat[0]);
10981    omapwpos[2] = (int) ((float) omapwn[2]*omaprat[2]);
10982    omapwpos[4] = (int) ((float) omapwn[4]*omaprat[4]);
10983 
10984    RedrawSlide(&omapscr[0]);
10985    RedrawSlide(&omapscr[2]);
10986    RedrawSlide(&omapscr[4]);
10987 
10988    omapwpos[1] = (int) ((float) omapwn[1]*omaprat[1]);
10989    omapwpos[3] = (int) ((float) omapwn[3]*omaprat[3]);
10990    omapwpos[5] = (int) ((float) omapwn[5]*omaprat[5]);
10991 
10992    RedrawSlide(&omapscr[1]);
10993    RedrawSlide(&omapscr[3]);
10994    RedrawSlide(&omapscr[5]);
10995 
10996    update_struct();
10997 }
10998 
UpdateOMAP1()10999 void UpdateOMAP1()
11000 {
11001 
11002    EQ[0] = vox[2] + extnt[2]*omaprat[0];
11003 
11004    update_struct();
11005 
11006 }
11007 
UpdateSLAB1()11008 void UpdateSLAB1()
11009 {
11010 
11011    slab[0] = extnt[2]*omaprat[1];
11012 
11013    update_struct();
11014 
11015 }
11016 
UpdateOMAP2()11017 void UpdateOMAP2()
11018 {
11019 
11020 
11021    EQ[1] = vox[0] + extnt[0]*omaprat[2];
11022 
11023    update_struct();
11024 
11025 }
11026 
UpdateSLAB2()11027 void UpdateSLAB2()
11028 {
11029 
11030    slab[1] = extnt[0]*omaprat[3];
11031 
11032    update_struct();
11033 
11034 }
11035 
UpdateOMAP3()11036 void UpdateOMAP3()
11037 {
11038 
11039    EQ[2] = vox[1] + extnt[1]*omaprat[4];
11040 
11041    update_struct();
11042 
11043 }
11044 
UpdateSLAB3()11045 void UpdateSLAB3()
11046 {
11047 
11048    slab[2] = extnt[1]*omaprat[5];
11049 
11050    update_struct();
11051 
11052 }
11053 
RedrawOMAP()11054 void RedrawOMAP()
11055 {
11056    int i;
11057 
11058    if (!OMAPup) return;
11059 
11060    butje(OMAPwin,0,0,230,300,4,0,-15,1,None,0,0,0);
11061    ULineString(OMAPwin,"Clip Planes:",20,20);
11062    LineString(OMAPwin,"Position",20,35);
11063    LineString(OMAPwin,"Separation",140,35);
11064 
11065    LineString(OMAPwin,"Z",25,48);
11066    LineString(OMAPwin,"X",55,48);
11067    LineString(OMAPwin,"Y",85,48);
11068 
11069    LineString(OMAPwin,"Z",145,48);
11070    LineString(OMAPwin,"X",175,48);
11071    LineString(OMAPwin,"Y",205,48);
11072 
11073    sprintf(atemp,"Contour Value [ 0.0 - %5.2f]:",*rng2);
11074    ULineString(OMAPwin,atemp,20,170);
11075 
11076    LineString(OMAPwin,"Residue",180,195);
11077    LineString(OMAPwin,"Follow",180,205);
11078 
11079    LineString(OMAPwin,"Use Shift Scroll Wheel",20,225);
11080    LineString(OMAPwin,"Transparent/Lined surface",40,253);
11081 
11082    for (i=0; i<6; i++) RedrawSlide(&omapscr[i]);
11083 
11084    PromptBox(&qboxes[QCNT]);
11085    if (omapPandN) PromptBox(&qboxes[QCNT2]);
11086 
11087    for (i=0; i<4; i++) DrwBut(&butomap[i]);
11088 
11089 }
11090 
11091 #ifdef DOGL
11092 static GLdouble theEQ1[4] = {  0.0,  0.0, -1.0, 0.0};
11093 static GLdouble theEQ2[4] = {  0.0,  0.0,  1.0, 0.0};
11094 static GLdouble theEQ3[4] = { -1.0,  0.0,  0.0, 0.0};
11095 static GLdouble theEQ4[4] = {  1.0,  0.0,  0.0, 0.0};
11096 static GLdouble theEQ5[4] = {  0.0, -1.0,  0.0, 0.0};
11097 static GLdouble theEQ6[4] = {  0.0,  1.0,  0.0, 0.0};
11098 #else
11099 static double theEQ1[4] = {  0.0,  0.0, -1.0, 0.0};
11100 static double theEQ2[4] = {  0.0,  0.0,  1.0, 0.0};
11101 static double theEQ3[4] = { -1.0,  0.0,  0.0, 0.0};
11102 static double theEQ4[4] = {  1.0,  0.0,  0.0, 0.0};
11103 static double theEQ5[4] = {  0.0, -1.0,  0.0, 0.0};
11104 static double theEQ6[4] = {  0.0,  1.0,  0.0, 0.0};
11105 #endif
11106 
InitOmap(iopt)11107 void InitOmap(iopt)
11108 int iopt;
11109 {
11110    int i;
11111 #ifdef DOGL
11112    GLdouble d[3];
11113 #else
11114    double d[3];
11115 #endif
11116 
11117    OMAPup = 1;
11118    OMAPtype = 0;
11119 
11120    omapPandN = iopt;
11121 
11122    OMAPwin = CreateWindow("CCP4 display","-30+30",230,300,
11123 	 		 infobg,infofg,(Window)0);
11124 
11125    subOMAP = CreateWindow("Subwindow","",10,10,
11126                             colors[0],colors[15],OMAPwin);
11127    XSelectInput(display, OMAPwin,
11128 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask
11129 		| ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
11130    XMapWindow(display,OMAPwin);
11131 
11132    WinObj[24].win = &OMAPwin;
11133    WinObj[24].subwin = &subOMAP;
11134    WinObj[24].butarr = butomap;
11135    WinObj[24].numbut = 4;
11136    WinObj[24].winup = &OMAPup;
11137    WinObj[24].init = InitOmap;
11138    WinObj[24].redraw = RedrawOMAP;
11139 
11140    getcval();
11141 
11142    DefBut(&butomap[0], OMAPwin, 100, 265, 50, 23,
11143 	"Close", infobg, -15);
11144 
11145    DefBut(&butomap[2], OMAPwin, 75, 180, 50, 23,
11146 	"Apply", infobg, -15);
11147 
11148    DefBut(&butomap[1], OMAPwin, 155, 185, 15, 15,
11149 	"", infobg, -15);
11150 
11151    DefBut(&butomap[3], OMAPwin, 20, 240, 15, 15,
11152 	"", infobg, -15);
11153 
11154    omapwn[0] = 100; omapwpos[0] = 100;
11155    DefSlide(&omapscr[0],OMAPwin,20,50,20,100,10,&omapwn[0],&omapwpos[0],
11156 	&omaprat[0], UpdateOMAP1);
11157 
11158    omapwn[1] = 100; omapwpos[1] = 100;
11159    DefSlide(&omapscr[1],OMAPwin,140,50,20,100,10,
11160 	&omapwn[1],&omapwpos[1],
11161 	&omaprat[1], UpdateSLAB1);
11162 
11163    omapwn[2] = 100; omapwpos[2] = 100;
11164    DefSlide(&omapscr[2],OMAPwin,50,50,20,100,10,
11165 	&omapwn[2],&omapwpos[2],
11166 	&omaprat[2], UpdateOMAP2);
11167 
11168    omapwn[3] = 100; omapwpos[3] = 100;
11169    DefSlide(&omapscr[3],OMAPwin,170,50,20,100,10,&omapwn[3],&omapwpos[3],
11170 	&omaprat[3], UpdateSLAB2);
11171 
11172    omapwn[4] = 100; omapwpos[4] = 100;
11173    DefSlide(&omapscr[4],OMAPwin,80,50,20,100,10,
11174 	&omapwn[4],&omapwpos[4],
11175 	&omaprat[4], UpdateOMAP3);
11176 
11177    omapwn[5] = 100; omapwpos[5] = 100;
11178    DefSlide(&omapscr[5],OMAPwin,200,50,20,100,10,
11179 	&omapwn[5],&omapwpos[5],
11180 	&omaprat[5], UpdateSLAB3);
11181 
11182 //
11183 
11184    crossprd(comsrfptr->v2,comsrfptr->v1,d);
11185 #ifdef DOGL
11186    improduct(d,comsrfptr->vo,&vox[2]);
11187 #endif
11188    for (i=0; i<3; i++) {
11189 	theEQ1[i] = -d[i];
11190 	theEQ2[i] =  d[i];
11191    }
11192 
11193 //
11194 
11195    crossprd(comsrfptr->v1,comsrfptr->v3,d);
11196 #ifdef DOGL
11197    improduct(d,comsrfptr->vo,&vox[1]);
11198 #endif
11199    for (i=0; i<3; i++) {
11200 	theEQ5[i] = -d[i];
11201 	theEQ6[i] =  d[i];
11202    }
11203 
11204 //
11205 
11206    crossprd(comsrfptr->v3,comsrfptr->v2,d);
11207 #ifdef DOGL
11208    improduct(d,comsrfptr->vo,&vox[0]);
11209 #endif
11210 
11211    for (i=0; i<3; i++) {
11212 	theEQ3[i] = -d[i];
11213 	theEQ4[i] =  d[i];
11214    }
11215 
11216    extnt[0] = comsrfptr->r[0];
11217    extnt[1] = comsrfptr->r[1];
11218    extnt[2] = comsrfptr->r[2];
11219 
11220    slab[0] = extnt[2];
11221    EQ[0] = vox[2] + slab[0];
11222 
11223    slab[1] = extnt[0];
11224    EQ[1] = vox[0] + slab[1];
11225 
11226    slab[2] = extnt[1];
11227    EQ[2] = vox[1] + slab[2];
11228 
11229    omapsrf = NSurf[istruct];
11230    NSurf[istruct]++;
11231    if (omapPandN && !(*rng1 >= 0.0) ) NSurf[istruct]++;
11232 
11233    omapcnt1 = atof(qboxes[QCNT].str);
11234    disp_map(NULL);
11235 
11236 }
11237 
DeleteOMAP()11238 void DeleteOMAP()
11239 {
11240    int i;
11241 
11242    XSync(display, False);
11243    XDestroyWindow(display,OMAPwin);
11244    XSync(display, False);
11245    omapfol = 0;
11246    omapCa = -1;
11247    if (omaplck) {
11248   	for (i=0; i<3; i++) rotptr->t[i] = omapt[i];
11249 	omaplck = 0;
11250    }
11251    OMAPup = 0;
11252 #ifdef DOGL
11253    DeleteSurface(omapsrf);
11254    deletebox();
11255 #endif
11256    update_struct();
11257 }
11258 
11259 
11260 static COMSRFSTRU clpsrf;
11261 
UpdOMAP1()11262 void UpdOMAP1()
11263 {
11264 
11265 /*
11266    EQ[0] is set here but it is not actually used anymore
11267    same goes for updOMAP1, just the equation in dispsf is used
11268 */
11269    EQ[0] = rotptr->t[2] + 2.0*scalptr->scali*omaprat[0];
11270 
11271    update_struct();
11272 
11273 }
11274 
RedrwOMAP()11275 void RedrwOMAP()
11276 {
11277    int i;
11278 
11279    if (!OMAPup) return;
11280 
11281    butje(OMAPwin,0,0,230,280,4,0,-15,1,None,0,0,0);
11282    ULineString(OMAPwin,"Clip Planes:",20,20);
11283 
11284    LineString(OMAPwin,"Near",23,45);
11285 
11286    LineString(OMAPwin,"Far",143,45);
11287 
11288    RedrawSlide(&omapscr[0]);
11289    RedrawSlide(&omapscr[1]);
11290 
11291    DrwBut(&butomap[0]);
11292 
11293 }
11294 
IniOmap()11295 void IniOmap()
11296 {
11297    int i;
11298    double tmp2[3];
11299 
11300    OMAPup = 1;
11301    OMAPtype = 1;
11302    omapsrf = -1;
11303 
11304    OMAPwin = CreateWindow("OMAP display","-30+30",230,280,
11305 	 		 infobg,infofg,(Window)0);
11306 
11307    subOMAP = CreateWindow("Subwindow","",10,10,
11308                             colors[0],colors[15],OMAPwin);
11309    XSelectInput(display, OMAPwin,
11310 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask
11311 		| ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
11312    XMapWindow(display,OMAPwin);
11313 
11314    WinObj[24].win = &OMAPwin;
11315    WinObj[24].subwin = &subOMAP;
11316    WinObj[24].butarr = butomap;
11317    WinObj[24].numbut = 1;
11318    WinObj[24].winup = &OMAPup;
11319    WinObj[24].init = IniOmap;
11320    WinObj[24].redraw = RedrwOMAP;
11321 
11322    DefBut(&butomap[0], OMAPwin, 100, 245, 50, 23,
11323 	"Close", infobg, -15);
11324 
11325    omapwn[1] = 100; omapwpos[1] = 100;
11326    DefSlide(&omapscr[1],OMAPwin,20,50,20,100,10,&omapwn[1],&omapwpos[1],
11327 	&omaprat[1], UpdateSLAB1);
11328 
11329    omapwn[0] = 100; omapwpos[0] = 0;
11330    DefSlide(&omapscr[0],OMAPwin,140,50,20,100,10,&omapwn[0],&omapwpos[0],
11331 	&omaprat[0], UpdOMAP1);
11332 
11333    theEQ1[2] = -1.0*theEQ1[2];
11334    theEQ2[2] = -1.0*theEQ2[2];
11335 
11336 
11337    extnt[2] = 2.0*scalptr->scali;
11338    slab[0] = extnt[2];
11339    EQ[0] = rotptr->t[2] + 2.0*scalptr->scali;
11340 
11341 /*
11342    EQ[0] is set here but it is not actually used anymore
11343    same goes for updOMAP1
11344 */
11345 
11346    if (denmode) {
11347      slab[1] = 2.0*scalptr->scali;
11348      EQ[1] = rotptr->t[0] - scalptr->scali + slab[1];
11349    } else {
11350      slab[1] = 2.0*scl[istruct];
11351      EQ[1] = rotptr->t[0] - scl[istruct] + slab[1];
11352    }
11353 
11354    if (denmode) {
11355      slab[2] = 2.0*scalptr->scali;
11356      EQ[2] = rotptr->t[1] - scalptr->scali + slab[2];
11357    } else {
11358      slab[2] = 2.0*scl[istruct];
11359      EQ[2] = rotptr->t[1] - scl[istruct] + slab[2];
11360    }
11361 
11362 
11363    for (i=0; i<NSurf[istruct]; i++) {
11364 	if (SSon[istruct][i]) clp[istruct][i] = 1;
11365    }
11366 
11367 }
11368 
11369 
11370 #if defined(VMS) || defined(UNDERSC)
rdvasp(npts1,npts2,npts3,iposng,istat,lenf,idocub,idebug)11371 void rdvasp(npts1,npts2,npts3,iposng,istat,lenf,idocub,idebug)
11372 #else
11373 #ifdef CRAY
11374 void RDVASP(npts1,npts2,npts3,iposng,istat,lenf,idocub,idebug)
11375 #else
11376 void rdvasp_(npts1,npts2,npts3,iposng,istat,lenf,idocub,idebug)
11377 #endif
11378 #endif
11379 int *npts1;
11380 int *npts2;
11381 int *npts3;
11382 int *iposng;
11383 int *istat;
11384 int *lenf;
11385 int *idocub;
11386 int *idebug;
11387 {
11388 
11389 #if defined(VMS) || defined(UNDERSC)
11390 	rdvasd(npts1,npts2,npts3,iposng,istat,lenf,idocub,idebug,
11391 #else
11392 #ifdef CRAY
11393 	RDVASD(npts1,npts2,npts3,iposng,istat,lenf,idocub,idebug,
11394 #else
11395 	rdvasd_(npts1,npts2,npts3,iposng,istat,lenf,idocub,idebug,
11396 #endif
11397 #endif
11398 	sgrd.denn,sgrd.pmnn,sgrd.bucket,
11399 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
11400 	&cell->natc,&cell->norg,&cell->icent,&cell->inorm,
11401 	&cell->ncon,&cell->nspg,&cell->ichx,
11402 	&cell->nopr,cell->ir,cell->it,
11403 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
11404 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
11405 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
11406 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
11407 
11408 }
11409 
11410 #if defined(VMS) || defined(UNDERSC)
rdinfo(npts1,npts2,isubtr,istat)11411 void rdinfo(npts1,npts2,isubtr,istat)
11412 #else
11413 #ifdef CRAY
11414 void RDINFO(npts1,npts2,isubtr,istat)
11415 #else
11416 void rdinfo_(npts1,npts2,isubtr,istat)
11417 #endif
11418 #endif
11419 int *npts1;
11420 int *npts2;
11421 int *isubtr;
11422 int *istat;
11423 {
11424 
11425 #if defined(VMS) || defined(UNDERSC)
11426 	rdinfd(npts1,npts2,isubtr,istat,
11427 #else
11428 #ifdef CRAY
11429 	RDINFD(npts1,npts2,isubtr,istat,
11430 #else
11431 	rdinfd_(npts1,npts2,isubtr,istat,
11432 #endif
11433 #endif
11434 	sgrd.dens,sgrd.denst);
11435 }
11436 
11437 #if defined(VMS) || defined(UNDERSC)
rd3inf(npts1,npts2,npts3,isubtr,adjus,istat)11438 void rd3inf(npts1,npts2,npts3,isubtr,adjus,istat)
11439 #else
11440 #ifdef CRAY
11441 void RD3INF(npts1,npts2,npts3,isubtr,adjus,istat)
11442 #else
11443 void rd3inf_(npts1,npts2,npts3,isubtr,adjus,istat)
11444 #endif
11445 #endif
11446 int *npts1;
11447 int *npts2;
11448 int *npts3;
11449 int *isubtr;
11450 double *adjus;
11451 int *istat;
11452 {
11453 
11454 #if defined(VMS) || defined(UNDERSC)
11455 	rd3ind(npts1,npts2,npts3,isubtr,adjus,istat,
11456 #else
11457 #ifdef CRAY
11458 	RD3IND(npts1,npts2,npts3,isubtr,adjus,istat,
11459 #else
11460 	rd3ind_(npts1,npts2,npts3,isubtr,adjus,istat,
11461 #endif
11462 #endif
11463 	sgrd.denn,sgrd.pmnn,sgrd.denst);
11464 }
11465 
11466 #if defined(VMS) || defined(UNDERSC)
rd3chk(npts1,npts2,npts3,igauss,impas,istat)11467 void rd3chk(npts1,npts2,npts3,igauss,impas,istat)
11468 #else
11469 #ifdef CRAY
11470 void RD3CHK(npts1,npts2,npts3,igauss,impas,istat)
11471 #else
11472 void rd3chk_(npts1,npts2,npts3,igauss,impas,istat)
11473 #endif
11474 #endif
11475 int *npts1;
11476 int *npts2;
11477 int *npts3;
11478 int *igauss;
11479 int *impas;
11480 int *istat;
11481 {
11482 
11483 #if defined(VMS) || defined(UNDERSC)
11484 	rd3chd(npts1,npts2,npts3,igauss,impas,istat,
11485 #else
11486 #ifdef CRAY
11487 	RD3CHD(npts1,npts2,npts3,igauss,impas,istat,
11488 #else
11489 	rd3chd_(npts1,npts2,npts3,igauss,impas,istat,
11490 #endif
11491 #endif
11492 	mgrd.fmap);
11493 }
11494 
11495 #if defined(VMS) || defined(UNDERSC)
11496 void oginid(double *r, double *adjus, int *natoms, int *nat, int *icol,
11497 #else
11498 #ifdef CRAY
11499 void OGINID(double *r, double *adjus, int *natoms, int *nat, int *icol,
11500 #else
11501 void oginid_(double *r, double *adjus, int *natoms, int *nat, int *icol,
11502 #endif
11503 #endif
11504        double *xsym, double *ysym, double *zsym, double *vdwr,
11505        double *cnst, int *nnpts1, int *nnpts2, int *iorb, double *dens);
11506 
11507 #if defined(VMS) || defined(UNDERSC)
oginit(r,adjus,natoms,nat,icol,xsym,ysym,zsym,vdwr,cnst,npts1,npts2,iorb)11508 void oginit(r,adjus,natoms,nat,icol,xsym,ysym,zsym,vdwr,cnst,npts1,npts2,iorb)
11509 #else
11510 #ifdef CRAY
11511 void OGINIT(r,adjus,natoms,nat,icol,xsym,ysym,zsym,vdwr,cnst,npts1,npts2,iorb)
11512 #else
11513 void oginit_(r,adjus,natoms,nat,icol,xsym,ysym,zsym,vdwr,cnst,npts1,npts2,iorb)
11514 #endif
11515 #endif
11516 double *r, *adjus;
11517 int *natoms, *nat, *icol;
11518 double *xsym, *ysym, *zsym;
11519 double *vdwr;
11520 double *cnst;
11521 int *npts1;
11522 int *npts2;
11523 int *iorb;
11524 {
11525 
11526 #if defined(VMS) || defined(UNDERSC)
11527         oginid(r,adjus,natoms,nat,icol,xsym,ysym,zsym,vdwr,cnst,npts1,
11528 		npts2,iorb,sgrd.dens);
11529 #else
11530 #ifdef CRAY
11531         OGINID(r,adjus,natoms,nat,icol,xsym,ysym,zsym,vdwr,cnst,npts1,
11532 		npts2,iorb,sgrd.dens);
11533 #else
11534         oginid_(r,adjus,natoms,nat,icol,xsym,ysym,zsym,vdwr,cnst,npts1,
11535 		npts2,iorb,sgrd.dens);
11536 #endif
11537 #endif
11538 
11539 }
11540 
11541 #if defined(VMS) || defined(UNDERSC)
wrinfo(npts1,npts2)11542 void wrinfo(npts1,npts2)
11543 #else
11544 #ifdef CRAY
11545 void WRINFO(npts1,npts2)
11546 #else
11547 void wrinfo_(npts1,npts2)
11548 #endif
11549 #endif
11550 int *npts1;
11551 int *npts2;
11552 {
11553 
11554 #if defined(VMS) || defined(UNDERSC)
11555 	wrinfd(npts1,npts2,
11556 #else
11557 #ifdef CRAY
11558 	WRINFD(npts1,npts2,
11559 #else
11560 	wrinfd_(npts1,npts2,
11561 #endif
11562 #endif
11563 	sgrd.dens);
11564 }
11565 
11566 #if defined(VMS) || defined(UNDERSC)
wr3inf(npts1,npts2,npts3,adjus)11567 void wr3inf(npts1,npts2,npts3,adjus)
11568 #else
11569 #ifdef CRAY
11570 void WR3INF(npts1,npts2,npts3,adjus)
11571 #else
11572 void wr3inf_(npts1,npts2,npts3,adjus)
11573 #endif
11574 #endif
11575 int *npts1;
11576 int *npts2;
11577 int *npts3;
11578 double *adjus;
11579 {
11580 
11581 #if defined(VMS) || defined(UNDERSC)
11582 	wr3ind(npts1,npts2,npts3,adjus,
11583 #else
11584 #ifdef CRAY
11585 	WR3IND(npts1,npts2,npts3,adjus,
11586 #else
11587 	wr3ind_(npts1,npts2,npts3,adjus,
11588 #endif
11589 #endif
11590 	sgrd.denn);
11591 }
11592 
11593 #if defined(VMS) || defined(UNDERSC)
spaced(npts1,npts2,npts3,valcnt,idofil,adjus,ipsprt,idisml,idvrml,mapit)11594 void spaced(npts1,npts2,npts3,valcnt,idofil,adjus,ipsprt,idisml,idvrml,mapit)
11595 #else
11596 #ifdef CRAY
11597 void SPACED(npts1,npts2,npts3,valcnt,idofil,adjus,ipsprt,idisml,idvrml,mapit)
11598 #else
11599 void spaced_(npts1,npts2,npts3,valcnt,idofil,adjus,ipsprt,idisml,idvrml,mapit)
11600 #endif
11601 #endif
11602 int *npts1;
11603 int *npts2;
11604 int *npts3;
11605 double *valcnt;
11606 int *idofil;
11607 double *adjus;
11608 int *ipsprt;
11609 int *idisml;
11610 int *idvrml;
11611 int *mapit;
11612 {
11613 
11614 #if defined(VMS) || defined(UNDERSC)
11615    spacdd(npts1,npts2,npts3,valcnt,idofil,adjus,ipsprt,idisml,idvrml,mapit,
11616 #else
11617 #ifdef CRAY
11618    SPACDD(npts1,npts2,npts3,valcnt,idofil,adjus,ipsprt,idisml,idvrml,mapit,
11619 #else
11620    spacdd_(npts1,npts2,npts3,valcnt,idofil,adjus,ipsprt,idisml,idvrml,mapit,
11621 #endif
11622 #endif
11623 	sgrd.denn,sgrd.pmnn,sgrd.iedlog,mgrd.fmap);
11624 }
11625 
11626 #if defined(VMS) || defined(UNDERSC)
spasrf(npts1,npts2,npts3,valcnt)11627 void spasrf(npts1,npts2,npts3,valcnt)
11628 #else
11629 #ifdef CRAY
11630 void SPASRF(npts1,npts2,npts3,valcnt)
11631 #else
11632 void spasrf_(npts1,npts2,npts3,valcnt)
11633 #endif
11634 #endif
11635 int *npts1;
11636 int *npts2;
11637 int *npts3;
11638 double *valcnt;
11639 {
11640 
11641 #if defined(VMS) || defined(UNDERSC)
11642 	spasrd(npts1,npts2,npts3,valcnt,
11643 #else
11644 #ifdef CRAY
11645 	SPASRD(npts1,npts2,npts3,valcnt,
11646 #else
11647 	spasrd_(npts1,npts2,npts3,valcnt,
11648 #endif
11649 #endif
11650 	sgrd.denn,sgrd.pmnn,sgrd.dens,sgrd.iedlog);
11651 }
11652 
11653 #if defined(VMS) || defined(UNDERSC)
isoden(valc,nvalc,scincr,nespt,iwhere)11654 void isoden(valc,nvalc,scincr,nespt,iwhere)
11655 #else
11656 #ifdef CRAY
11657 void ISODEN(valc,nvalc,scincr,nespt,iwhere)
11658 #else
11659 void isoden_(valc,nvalc,scincr,nespt,iwhere)
11660 #endif
11661 #endif
11662 double *valc;
11663 int *nvalc;
11664 double *scincr;
11665 int *nespt;
11666 int *iwhere;
11667 {
11668 
11669 #if defined(VMS) || defined(UNDERSC)
11670 	isoded(valc,nvalc,scincr,nespt,iwhere,
11671 #else
11672 #ifdef CRAY
11673 	ISODED(valc,nvalc,scincr,nespt,iwhere,
11674 #else
11675 	isoded_(valc,nvalc,scincr,nespt,iwhere,
11676 #endif
11677 #endif
11678 	sgrd.dens,sgrd.iedlog);
11679 }
11680 
11681 #if defined(VMS) || defined(UNDERSC)
rdcpmdd(idebug,ibefo,istatio,ioxyz,irtype,ihsend,istats)11682 void rdcpmdd(idebug,ibefo,istatio,ioxyz,irtype,ihsend,istats)
11683 #else
11684 #ifdef CRAY
11685 void RDCPMDD(idebug,ibefo,istatio,ioxyz,irtype,ihsend,istats)
11686 #else
11687 void rdcpmdd_(idebug,ibefo,istatio,ioxyz,irtype,ihsend,istats)
11688 #endif
11689 #endif
11690 int *idebug;
11691 int *ibefo;
11692 int *istatio;
11693 int *ioxyz;
11694 int *irtype;
11695 int *ihsend;
11696 int *istats;
11697 {
11698 
11699 #if defined(VMS) || defined(UNDERSC)
11700 	rdcpmddd(idebug,ibefo,istatio,ioxyz,irtype,ihsend,istats,
11701 #else
11702 #ifdef CRAY
11703 	RDCPMDDD(idebug,ibefo,istatio,ioxyz,irtype,ihsend,istats,
11704 #else
11705 	rdcpmddd_(idebug,ibefo,istatio,ioxyz,irtype,ihsend,istats,
11706 #endif
11707 #endif
11708 	dorbp->vectrs,dorbp->vectrb,dorbp->focc,dorbp->focb,dorbp->eiga,
11709 	dorbp->eigb,dorbp->nocc,dorbp->nocb,dorbp->ncols,dorbp->ncolb);
11710 
11711 }
11712 
11713 /* END shadow C routines for Fortran routines to pass grid pointers */
11714 
11715 /* shadow C routines for Fortran routines to pass coordinate pointers */
11716 
anim()11717 void anim()
11718 {
11719 #if defined(VMS) || defined(UNDERSC)
11720 	anid(xyzp->coo,xyzp->ianz);
11721 #else
11722 #ifdef CRAY
11723 	ANID(xyzp->coo,xyzp->ianz);
11724 #else
11725 	anid_(xyzp->coo,xyzp->ianz);
11726 #endif
11727 #endif
11728 }
11729 
11730 #if defined(VMS) || defined(UNDERSC)
actami(inum,ikleur,iopt,idosrf)11731 void actami(inum,ikleur,iopt,idosrf)
11732 #else
11733 #ifdef CRAY
11734 void ACTAMI(inum,ikleur,iopt,idosrf)
11735 #else
11736 void actami_(inum,ikleur,iopt,idosrf)
11737 #endif
11738 #endif
11739 int *inum;
11740 int *ikleur;
11741 int *iopt;
11742 int *idosrf;
11743 {
11744 
11745 #if defined(VMS) || defined(UNDERSC)
11746 	actamd(inum,ikleur,iopt,idosrf,
11747 #else
11748 #ifdef CRAY
11749 	ACTAMD(inum,ikleur,iopt,idosrf,
11750 #else
11751 	actamd_(inum,ikleur,iopt,idosrf,
11752 #endif
11753 #endif
11754 	xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->isurf,
11755 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
11756 	&calfptr->nchain,calfptr->iamino,
11757 	calfptr->ihet,calfptr->iclhet,calfptr->reson,calfptr->iams,
11758 	calfptr->isal,&calfptr->ishoh,&calfptr->ision);
11759 
11760 }
11761 
11762 #if defined(VMS) || defined(UNDERSC)
actexp(que,lque,ikleur,idosrf)11763 void actexp(que,lque,ikleur,idosrf)
11764 #else
11765 #ifdef CRAY
11766 void ACTEXP(que,lque,ikleur,idosrf)
11767 #else
11768 void actexp_(que,lque,ikleur,idosrf)
11769 #endif
11770 #endif
11771 int *que;
11772 int *lque;
11773 int *ikleur;
11774 int *idosrf;
11775 {
11776 
11777 #if defined(VMS) || defined(UNDERSC)
11778 	actexd(que,lque,ikleur,idosrf,
11779 #else
11780 #ifdef CRAY
11781 	ACTEXD(que,lque,ikleur,idosrf,
11782 #else
11783 	actexd_(que,lque,ikleur,idosrf,
11784 #endif
11785 #endif
11786 	&calfptr->ncalf,calfptr->iamino);
11787 
11788 }
11789 
11790 #if defined(VMS) || defined(UNDERSC)
caldip()11791 void caldip()
11792 #else
11793 #ifdef CRAY
11794 void CALDIP()
11795 #else
11796 void caldip_()
11797 #endif
11798 #endif
11799 {
11800 #if defined(VMS) || defined(UNDERSC)
11801 	caldid(
11802 #else
11803 #ifdef CRAY
11804 	CALDID(
11805 #else
11806 	caldid_(
11807 #endif
11808 #endif
11809 	xyzp->qat,xyzp->coo);
11810 }
11811 
11812 #if defined(VMS) || defined(UNDERSC)
aacom(vrad,ires,str,nstr,istsrf)11813 void aacom(vrad,ires,str,nstr,istsrf)
11814 #else
11815 #ifdef CRAY
11816 void AACOM(vrad,ires,str,nstr,istsrf)
11817 #else
11818 void aacom_(vrad,ires,str,nstr,istsrf)
11819 #endif
11820 #endif
11821 double *vrad;
11822 int *ires;
11823 int *nstr;
11824 int *istsrf;
11825 char *str;
11826 {
11827 
11828 #if defined(VMS) || defined(UNDERSC)
11829 	aacod(vrad,ires,str,nstr,istsrf,
11830 #else
11831 #ifdef CRAY
11832 	AACOD(vrad,ires,str,nstr,istsrf,
11833 #else
11834 	aacod_(vrad,ires,str,nstr,istsrf,
11835 #endif
11836 #endif
11837 	xyzp->iresid,xyzp->isurf,
11838         &calfptr->ncalf,calfptr->ianf,calfptr->islu,
11839         &calfptr->nchain,calfptr->iamino,calfptr->ihet,calfptr->reson,
11840 	calfptr->isal,calfptr->irsnr,calfptr->achain);
11841 
11842 }
11843 
11844 #if defined(VMS) || defined(UNDERSC)
actcal(iopt)11845 void actcal(iopt)
11846 #else
11847 #ifdef CRAY
11848 void ACTCAL(iopt)
11849 #else
11850 void actcal_(iopt)
11851 #endif
11852 #endif
11853 int *iopt;
11854 {
11855 
11856 #if defined(VMS) || defined(UNDERSC)
11857 	actcad(iopt,
11858 #else
11859 #ifdef CRAY
11860 	ACTCAD(iopt,
11861 #else
11862 	actcad_(iopt,
11863 #endif
11864 #endif
11865 	xyzp->iaton,xyzp->iatclr,xyzp->iresid,
11866 	calfptr->icalf,calfptr->ianf,calfptr->islu,&calfptr->nchain,
11867 	calfptr->iamino,calfptr->ibck);
11868 
11869 }
11870 
11871 #if defined(VMS) || defined(UNDERSC)
acthel(iopt,iscnd,jcolsp,inclbb)11872 void acthel(iopt,iscnd,jcolsp,inclbb)
11873 #else
11874 #ifdef CRAY
11875 void ACTHEL(iopt,iscnd,jcolsp,inclbb)
11876 #else
11877 void acthel_(iopt,iscnd,jcolsp,inclbb)
11878 #endif
11879 #endif
11880 int *iopt;
11881 int *iscnd;
11882 int *jcolsp;
11883 int *inclbb;
11884 {
11885 
11886 #if defined(VMS) || defined(UNDERSC)
11887 	acthed(iopt,iscnd,jcolsp,inclbb,
11888 #else
11889 #ifdef CRAY
11890 	ACTHED(iopt,iscnd,jcolsp,inclbb,
11891 #else
11892 	acthed_(iopt,iscnd,jcolsp,inclbb,
11893 #endif
11894 #endif
11895 	xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
11896 	calfptr->icalf,calfptr->ianf,calfptr->islu,
11897 	&calfptr->nchain,calfptr->iamino,calfptr->ihet,calfptr->reson,
11898 	calfptr->isal,calfptr->ibck);
11899 
11900 }
11901 
11902 #if defined(VMS) || defined(UNDERSC)
actss(iopt)11903 void actss(iopt)
11904 #else
11905 #ifdef CRAY
11906 void ACTSS(iopt)
11907 #else
11908 void actss_(iopt)
11909 #endif
11910 #endif
11911 int *iopt;
11912 {
11913 
11914 #if defined(VMS) || defined(UNDERSC)
11915 	actsd(iopt,
11916 #else
11917 #ifdef CRAY
11918 	ACTSD(iopt,
11919 #else
11920 	actsd_(iopt,
11921 #endif
11922 #endif
11923 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn);
11924 
11925 }
11926 
11927 #if defined(VMS) || defined(UNDERSC)
pmfass(iopt,dochg)11928 void pmfass(iopt,dochg)
11929 #else
11930 #ifdef CRAY
11931 void PMFASS(iopt,dochg)
11932 #else
11933 void pmfass_(iopt,dochg)
11934 #endif
11935 #endif
11936 int *iopt;
11937 int *dochg;
11938 {
11939 
11940 #if defined(VMS) || defined(UNDERSC)
11941 	pmfasd(iopt,dochg,
11942 #else
11943 #ifdef CRAY
11944 	PMFASD(iopt,dochg,
11945 #else
11946 	pmfasd_(iopt,dochg,
11947 #endif
11948 #endif
11949 	xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->ityp,
11950 	&calfptr->ncalf,calfptr->iamino);
11951 
11952 }
11953 
11954 #if defined(VMS) || defined(UNDERSC)
dfiass()11955 void dfiass()
11956 #else
11957 #ifdef CRAY
11958 void DFIASS()
11959 #else
11960 void dfiass_()
11961 #endif
11962 #endif
11963 {
11964 
11965 #if defined(VMS) || defined(UNDERSC)
11966 	dfiasd(
11967 #else
11968 #ifdef CRAY
11969 	DFIASD(
11970 #else
11971 	dfiasd_(
11972 #endif
11973 #endif
11974 	xyzp->ityp,
11975 	&calfptr->ncalf,calfptr->iamino);
11976 
11977 }
11978 
11979 #if defined(VMS) || defined(UNDERSC)
updres()11980 void updres()
11981 #else
11982 #ifdef CRAY
11983 void UPDRES()
11984 #else
11985 void updres_()
11986 #endif
11987 #endif
11988 {
11989 
11990 #if defined(VMS) || defined(UNDERSC)
11991 	updred(
11992 #else
11993 #ifdef CRAY
11994 	UPDRED(
11995 #else
11996 	updred_(
11997 #endif
11998 #endif
11999 	xyzp->coo,
12000 	&calfptr->ncalf,calfptr->icalf);
12001 
12002 }
12003 
12004 #if defined(VMS) || defined(UNDERSC)
dfires()12005 void dfires()
12006 #else
12007 #ifdef CRAY
12008 void DFIRES()
12009 #else
12010 void dfires_()
12011 #endif
12012 #endif
12013 {
12014 
12015 #if defined(VMS) || defined(UNDERSC)
12016 	dfired(
12017 #else
12018 #ifdef CRAY
12019 	DFIRED(
12020 #else
12021 	dfired_(
12022 #endif
12023 #endif
12024 	xyzp->coo,
12025 	calfptr->icalf,&calfptr->ncalf,calfptr->iamino);
12026 
12027 }
12028 
12029 #if defined(VMS) || defined(UNDERSC)
twodfi(tdfi,ires1,ires2)12030 void twodfi(tdfi,ires1,ires2)
12031 #else
12032 #ifdef CRAY
12033 void TWODFI(tdfi,ires1,ires2)
12034 #else
12035 void twodfi_(tdfi,ires1,ires2)
12036 #endif
12037 #endif
12038 double *tdfi;
12039 int *ires1;
12040 int *ires2;
12041 {
12042 
12043 #if defined(VMS) || defined(UNDERSC)
12044 	twodfd(tdfi,ires1,ires2,
12045 #else
12046 #ifdef CRAY
12047 	TWODFD(tdfi,ires1,ires2,
12048 #else
12049 	twodfd_(tdfi,ires1,ires2,
12050 #endif
12051 #endif
12052 	xyzp->coo,xyzp->ityp);
12053 
12054 }
12055 
12056 #if defined(VMS) || defined(UNDERSC)
twodfib(tdfi,ires1,ires2)12057 void twodfib(tdfi,ires1,ires2)
12058 #else
12059 #ifdef CRAY
12060 void TWODFIB(tdfi,ires1,ires2)
12061 #else
12062 void twodfib_(tdfi,ires1,ires2)
12063 #endif
12064 #endif
12065 double *tdfi;
12066 int *ires1;
12067 int *ires2;
12068 {
12069 
12070 #if defined(VMS) || defined(UNDERSC)
12071 	twodfid(tdfi,ires1,ires2,
12072 #else
12073 #ifdef CRAY
12074 	TWODFID(tdfi,ires1,ires2,
12075 #else
12076 	twodfid_(tdfi,ires1,ires2,
12077 #endif
12078 #endif
12079 	xyzp->coo,xyzp->ityp);
12080 
12081 }
12082 
12083 #if defined(VMS) || defined(UNDERSC)
onedfi(tdfi,ires1)12084 void onedfi(tdfi,ires1)
12085 #else
12086 #ifdef CRAY
12087 void ONEDFI(tdfi,ires1)
12088 #else
12089 void onedfi_(tdfi,ires1)
12090 #endif
12091 #endif
12092 double *tdfi;
12093 int *ires1;
12094 {
12095 
12096 #if defined(VMS) || defined(UNDERSC)
12097 	onedfd(tdfi,ires1,
12098 #else
12099 #ifdef CRAY
12100 	ONEDFD(tdfi,ires1,
12101 #else
12102 	onedfd_(tdfi,ires1,
12103 #endif
12104 #endif
12105 	xyzp->coo,xyzp->ityp);
12106 
12107 }
12108 
12109 #if defined(VMS) || defined(UNDERSC)
totpmf(totpmf)12110 void totpmf(totpmf)
12111 #else
12112 #ifdef CRAY
12113 void TOTPMF(totpmf)
12114 #else
12115 void totpmf_(totpmf)
12116 #endif
12117 #endif
12118 double *totpmf;
12119 {
12120 
12121 #if defined(VMS) || defined(UNDERSC)
12122 	totpmd(totpmf,
12123 #else
12124 #ifdef CRAY
12125 	TOTPMD(totpmf,
12126 #else
12127 	totpmd_(totpmf,
12128 #endif
12129 #endif
12130 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->ityp);
12131 
12132 }
12133 
12134 #if defined(VMS) || defined(UNDERSC)
pmfinf(iatm)12135 void pmfinf(iatm)
12136 #else
12137 #ifdef CRAY
12138 void PMFINF(iatm)
12139 #else
12140 void pmfinf_(iatm)
12141 #endif
12142 #endif
12143 int *iatm;
12144 {
12145 
12146 #if defined(VMS) || defined(UNDERSC)
12147 	pmfind(iatm,
12148 #else
12149 #ifdef CRAY
12150 	PMFIND(iatm,
12151 #else
12152 	pmfind_(iatm,
12153 #endif
12154 #endif
12155 	xyzp->coo,xyzp->ianz,xyzp->ityp);
12156 
12157 }
12158 
12159 #if defined(VMS) || defined(UNDERSC)
ipmtyp(iptm,iat,ian,idochg)12160 void ipmtyp(iptm,iat,ian,idochg)
12161 #else
12162 #ifdef CRAY
12163 void IPMTYP(iptm,iat,ian,idochg)
12164 #else
12165 void ipmtyp_(iptm,iat,ian,idochg)
12166 #endif
12167 #endif
12168 int *iptm;
12169 int *iat;
12170 int *ian;
12171 int *idochg;
12172 {
12173 
12174 #if defined(VMS) || defined(UNDERSC)
12175 	ipmtyd(iptm,iat,ian,idochg,
12176 #else
12177 #ifdef CRAY
12178 	IPMTYD(iptm,iat,ian,idochg,
12179 #else
12180 	ipmtyd_(iptm,iat,ian,idochg,
12181 #endif
12182 #endif
12183 	xyzp->ianz,xyzp->iconn,xyzp->qat);
12184 
12185 }
12186 
12187 #if defined(VMS) || defined(UNDERSC)
clmon(car,pot)12188 void clmon(car,pot)
12189 #else
12190 #ifdef CRAY
12191 void CLMON(car,pot)
12192 #else
12193 void clmon_(car,pot)
12194 #endif
12195 #endif
12196 double *car;
12197 double *pot;
12198 {
12199 
12200 #if defined(VMS) || defined(UNDERSC)
12201 	clmod(car,pot,
12202 #else
12203 #ifdef CRAY
12204 	CLMOD(car,pot,
12205 #else
12206 	clmod_(car,pot,
12207 #endif
12208 #endif
12209 	xyzp->coo,xyzp->qat);
12210 
12211 }
12212 
12213 #if defined(VMS) || defined(UNDERSC)
clmons(car,pot,idoloc)12214 void clmons(car,pot,idoloc)
12215 #else
12216 #ifdef CRAY
12217 void CLMONS(car,pot,idoloc)
12218 #else
12219 void clmons_(car,pot,idoloc)
12220 #endif
12221 #endif
12222 double *car;
12223 double *pot;
12224 int *idoloc;
12225 {
12226 
12227 #if defined(VMS) || defined(UNDERSC)
12228 	clmond(car,pot,idoloc,
12229 #else
12230 #ifdef CRAY
12231 	CLMOND(car,pot,idoloc,
12232 #else
12233 	clmond_(car,pot,idoloc,
12234 #endif
12235 #endif
12236 	xyzp->coo,xyzp->qat,xyzp->icont,xyzp->ncont);
12237 }
12238 
12239 #if defined(VMS) || defined(UNDERSC)
calfa(istat,istpdb,iaddh,ioatms,nstrt,ioadd)12240 void calfa(istat,istpdb,iaddh,ioatms,nstrt,ioadd)
12241 #else
12242 #ifdef CRAY
12243 void CALFA(istat,istpdb,iaddh,ioatms,nstrt,ioadd)
12244 #else
12245 void calfa_(istat,istpdb,iaddh,ioatms,nstrt,ioadd)
12246 #endif
12247 #endif
12248 int *istat;
12249 int *istpdb;
12250 int *iaddh;
12251 int *ioatms;
12252 int *nstrt;
12253 int *ioadd;
12254 {
12255 
12256 #if defined(VMS) || defined(UNDERSC)
12257 	calfd(istat,istpdb,iaddh,ioatms,nstrt,ioadd,
12258 #else
12259 #ifdef CRAY
12260 	CALFD(istat,istpdb,iaddh,ioatms,nstrt,ioadd,
12261 #else
12262 	calfd_(istat,istpdb,iaddh,ioatms,nstrt,ioadd,
12263 #endif
12264 #endif
12265 	xyzp->ianz,xyzp->iconn,xyzp->ityp,
12266         calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
12267 	&calfptr->nchain,calfptr->iamino,
12268 	calfptr->isal,calfptr->irsnr,&calfptr->ihashb,
12269 	calfptr->rphi,calfptr->rpsi);
12270 
12271 }
12272 
12273 #if defined(VMS) || defined(UNDERSC)
docct()12274 void docct()
12275 #else
12276 #ifdef CRAY
12277 void DOCCT()
12278 #else
12279 void docct_()
12280 #endif
12281 #endif
12282 {
12283 
12284 #if defined(VMS) || defined(UNDERSC)
12285 	doccd(
12286 #else
12287 #ifdef CRAY
12288 	DOCCD(
12289 #else
12290 	doccd_(
12291 #endif
12292 #endif
12293 	xyzp->coo,xyzp->ianz);
12294 
12295 }
12296 
12297 #if defined(VMS) || defined(UNDERSC)
docent()12298 void docent()
12299 #else
12300 #ifdef CRAY
12301 void DOCENT()
12302 #else
12303 void docent_()
12304 #endif
12305 #endif
12306 {
12307 
12308 #if defined(VMS) || defined(UNDERSC)
12309 	docend(
12310 #else
12311 #ifdef CRAY
12312 	DOCEND(
12313 #else
12314 	docend_(
12315 #endif
12316 #endif
12317 	rotptr->t,xyzp->coo,xyzp->ianz);
12318 
12319 }
12320 
12321 #if defined(VMS) || defined(UNDERSC)
valdis(var,ipntr,numat,iop,iasel,istat)12322 void valdis(var,ipntr,numat,iop,iasel,istat)
12323 #else
12324 #ifdef CRAY
12325 void VALDIS(var,ipntr,numat,iop,iasel,istat)
12326 #else
12327 void valdis_(var,ipntr,numat,iop,iasel,istat)
12328 #endif
12329 #endif
12330 double *var;
12331 int *ipntr;
12332 int *numat;
12333 int *iop;
12334 int *iasel;
12335 int *istat;
12336 {
12337 
12338 #if defined(VMS) || defined(UNDERSC)
12339 	valdid(var,ipntr,numat,iop,iasel,istat,
12340 #else
12341 #ifdef CRAY
12342 	VALDID(var,ipntr,numat,iop,iasel,istat,
12343 #else
12344 	valdid_(var,ipntr,numat,iop,iasel,istat,
12345 #endif
12346 #endif
12347 	xyzp->ianz,xyzp->iresid,xyzp->qat);
12348 
12349 }
12350 
12351 #if defined(VMS) || defined(UNDERSC)
eemcalc(var,ipntr,numat)12352 void eemcalc(var,ipntr,numat)
12353 #else
12354 #ifdef CRAY
12355 void EEMCALC(var,ipntr,numat)
12356 #else
12357 void eemcalc_(var,ipntr,numat)
12358 #endif
12359 #endif
12360 double *var;
12361 int *numat;
12362 int *ipntr;
12363 {
12364 
12365 #if defined(VMS) || defined(UNDERSC)
12366 	eemcald(var,ipntr,numat,
12367 #else
12368 #ifdef CRAY
12369 	EEMCALD(var,ipntr,numat,
12370 #else
12371 	eemcald_(var,ipntr,numat,
12372 #endif
12373 #endif
12374 	xyzp->ianz,xyzp->coo,xyzp->qat);
12375 
12376 }
12377 
12378 #if defined(VMS) || defined(UNDERSC)
distchk()12379 void distchk()
12380 #else
12381 #ifdef CRAY
12382 void DISTCHK()
12383 #else
12384 void distchk_()
12385 #endif
12386 #endif
12387 {
12388 
12389 #if defined(VMS) || defined(UNDERSC)
12390 	distchd(
12391 #else
12392 #ifdef CRAY
12393 	DISTCHD(
12394 #else
12395 	distchd_(
12396 #endif
12397 #endif
12398 	xyzp->coo);
12399 
12400 }
12401 
12402 #if defined(VMS) || defined(UNDERSC)
calgas(iasel,istat)12403 void calgas(iasel,istat)
12404 #else
12405 #ifdef CRAY
12406 void CALGAS(iasel,istat)
12407 #else
12408 void calgas_(iasel,istat)
12409 #endif
12410 #endif
12411 int *iasel;
12412 int *istat;
12413 {
12414    int memstat,i,ff;
12415    short int j;
12416    short int *ityp;
12417 
12418    memstat = 1;
12419 
12420    ff = *fftyp;
12421 
12422    if ((ityp = (short int *) malloc((sizeof j)*(*xyzp->iatoms))) == NULL) {
12423 	memstat = 0;
12424    } else {
12425 	for (i = 0; i < *xyzp->iatoms; i++) ityp[i] = xyzp->ityp[i];
12426    }
12427 
12428 #if defined(VMS) || defined(UNDERSC)
12429 	calgad(iasel,istat,
12430 #else
12431 #ifdef CRAY
12432 	CALGAD(iasel,istat,
12433 #else
12434 	calgad_(iasel,istat,
12435 #endif
12436 #endif
12437 	xyzp->qat,xyzp->ianz,xyzp->iconn,xyzp->iresid,xyzp->ityp);
12438 
12439    if (memstat) {
12440 	for (i = 0; i < *xyzp->iatoms; i++) xyzp->ityp[i] = ityp[i];
12441 	free(ityp);
12442 	*fftyp = ff;
12443    }
12444 }
12445 
12446 #if defined(VMS) || defined(UNDERSC)
mkscon(c,rad,grdw,iptr,npts)12447 void mkscon(c,rad,grdw,iptr,npts)
12448 #else
12449 #ifdef CRAY
12450 void MKSCON(c,rad,grdw,iptr,npts)
12451 #else
12452 void mkscon_(c,rad,grdw,iptr,npts)
12453 #endif
12454 #endif
12455 double *c;
12456 double *rad;
12457 double *grdw;
12458 int *iptr;
12459 int *npts;
12460 {
12461 
12462 #if defined(VMS) || defined(UNDERSC)
12463 	mkscod(c,rad,grdw,iptr,npts,
12464 #else
12465 #ifdef CRAY
12466 	MKSCOD(c,rad,grdw,iptr,npts,
12467 #else
12468 	mkscod_(c,rad,grdw,iptr,npts,
12469 #endif
12470 #endif
12471 	xyzp->coo,xyzp->iconn);
12472 
12473 }
12474 
12475 #if defined(VMS) || defined(UNDERSC)
connlp(dens,idomap,isp)12476 void connlp(dens,idomap,isp)
12477 #else
12478 #ifdef CRAY
12479 void CONNLP(dens,idomap,isp)
12480 #else
12481 void connlp_(dens,idomap,isp)
12482 #endif
12483 #endif
12484 int *dens;
12485 int *idomap;
12486 int *isp;
12487 {
12488 
12489 #if defined(VMS) || defined(UNDERSC)
12490 	connld(dens,idomap,isp,
12491 #else
12492 #ifdef CRAY
12493 	CONNLD(dens,idomap,isp,
12494 #else
12495 	connld_(dens,idomap,isp,
12496 #endif
12497 #endif
12498 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,xyzp->isurf);
12499 
12500 }
12501 
12502 
12503 #if defined(VMS) || defined(UNDERSC)
allsrf(docol,idomap,idocal,isp)12504 void allsrf(docol,idomap,idocal,isp)
12505 #else
12506 #ifdef CRAY
12507 void ALLSRF(docol,idomap,idocal,isp)
12508 #else
12509 void allsrf_(docol,idomap,idocal,isp)
12510 #endif
12511 #endif
12512 int *docol;
12513 int *idomap;
12514 int *idocal;
12515 int *isp;
12516 {
12517 
12518 #if defined(VMS) || defined(UNDERSC)
12519 	allsrd(docol,idomap,idocal,isp,
12520 #else
12521 #ifdef CRAY
12522 	ALLSRD(docol,idomap,idocal,isp,
12523 #else
12524 	allsrd_(docol,idomap,idocal,isp,
12525 #endif
12526 #endif
12527 	xyzp->isurf,xyzp->iaton,xyzp->ianz,xyzp->iatclr);
12528 
12529 }
12530 
12531 #if defined(VMS) || defined(UNDERSC)
alasrf()12532 void alasrf()
12533 #else
12534 #ifdef CRAY
12535 void ALASRF()
12536 #else
12537 void alasrf_()
12538 #endif
12539 #endif
12540 {
12541 
12542 #if defined(VMS) || defined(UNDERSC)
12543 	alasrd(
12544 #else
12545 #ifdef CRAY
12546 	ALASRD(
12547 #else
12548 	alasrd_(
12549 #endif
12550 #endif
12551 	xyzp->iresid,xyzp->isurf,calfptr->iams,calfptr->ihets);
12552 
12553 }
12554 
12555 #if defined(VMS) || defined(UNDERSC)
clrsrf()12556 void clrsrf()
12557 #else
12558 #ifdef CRAY
12559 void CLRSRF()
12560 #else
12561 void clrsrf_()
12562 #endif
12563 #endif
12564 {
12565 
12566 #if defined(VMS) || defined(UNDERSC)
12567 	clrsrd(
12568 #else
12569 #ifdef CRAY
12570 	CLRSRD(
12571 #else
12572 	clrsrd_(
12573 #endif
12574 #endif
12575 	xyzp->isurf);
12576 
12577 }
12578 
12579 #if defined(VMS) || defined(UNDERSC)
propnt(qx,qy,qz,ipen)12580 void propnt(qx,qy,qz,ipen)
12581 #else
12582 #ifdef CRAY
12583 void PROPNT(qx,qy,qz,ipen)
12584 #else
12585 void propnt_(qx,qy,qz,ipen)
12586 #endif
12587 #endif
12588 double *qx;
12589 double *qy;
12590 double *qz;
12591 int *ipen;
12592 {
12593 
12594 
12595 #if defined(VMS) || defined(UNDERSC)
12596 	propnd(qx,qy,qz,ipen,
12597 #else
12598 #ifdef CRAY
12599 	PROPND(qx,qy,qz,ipen,
12600 #else
12601 	propnd_(qx,qy,qz,ipen,
12602 #endif
12603 #endif
12604 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn);
12605 
12606 }
12607 
12608 #if defined(VMS) || defined(UNDERSC)
getfr(istat)12609 void getfr(istat)
12610 #else
12611 #ifdef CRAY
12612 void GETFR(istat)
12613 #else
12614 void getfr_(istat)
12615 #endif
12616 #endif
12617 int *istat;
12618 {
12619 
12620 #if defined(VMS) || defined(UNDERSC)
12621 	getfd(istat,
12622 #else
12623 #ifdef CRAY
12624 	GETFD(istat,
12625 #else
12626 	getfd_(istat,
12627 #endif
12628 #endif
12629 	xyzp->coo);
12630 
12631 }
12632 
12633 #if defined(VMS) || defined(UNDERSC)
ggetfr(istat)12634 void ggetfr(istat)
12635 #else
12636 #ifdef CRAY
12637 void GGETFR(istat)
12638 #else
12639 void ggetfr_(istat)
12640 #endif
12641 #endif
12642 int *istat;
12643 {
12644 
12645 #if defined(VMS) || defined(UNDERSC)
12646 	ggetfd(istat,
12647 #else
12648 #ifdef CRAY
12649 	GGETFD(istat,
12650 #else
12651 	ggetfd_(istat,
12652 #endif
12653 #endif
12654 	xyzp->coo);
12655 
12656 }
12657 
12658 #if defined(VMS) || defined(UNDERSC)
getfrm(istat)12659 void getfrm(istat)
12660 #else
12661 #ifdef CRAY
12662 void GETFRM(istat)
12663 #else
12664 void getfrm_(istat)
12665 #endif
12666 #endif
12667 int *istat;
12668 {
12669 
12670 #if defined(VMS) || defined(UNDERSC)
12671 	getfrd(istat,
12672 #else
12673 #ifdef CRAY
12674 	GETFRD(istat,
12675 #else
12676 	getfrd_(istat,
12677 #endif
12678 #endif
12679 	xyzp->coo,xyzp->ianz);
12680 
12681 }
12682 
12683 #if defined(VMS) || defined(UNDERSC)
getfra(istat)12684 void getfra(istat)
12685 #else
12686 #ifdef CRAY
12687 void GETFRA(istat)
12688 #else
12689 void getfra_(istat)
12690 #endif
12691 #endif
12692 int *istat;
12693 {
12694 
12695 #if defined(VMS) || defined(UNDERSC)
12696 	getfrad(istat,
12697 #else
12698 #ifdef CRAY
12699 	GETFRAD(istat,
12700 #else
12701 	getfrad_(istat,
12702 #endif
12703 #endif
12704 	xyzp->ianz);
12705 
12706 }
12707 
12708 #if defined(VMS) || defined(UNDERSC)
nxtpnt(iopt,fancy,atcol,dolabs,backb,wpnt)12709 void nxtpnt(iopt,fancy,atcol,dolabs,backb,wpnt)
12710 #else
12711 #ifdef CRAY
12712 void NXTPNT(iopt,fancy,atcol,dolabs,backb,wpnt)
12713 #else
12714 void nxtpnt_(iopt,fancy,atcol,dolabs,backb,wpnt)
12715 #endif
12716 #endif
12717 int *iopt;
12718 int *fancy;
12719 int *atcol;
12720 int *dolabs;
12721 int *backb;
12722 int *wpnt;
12723 {
12724 
12725 #if defined(VMS) || defined(UNDERSC)
12726 	nxtpnd(iopt,fancy,atcol,dolabs,backb,wpnt,
12727 #else
12728 #ifdef CRAY
12729 	NXTPND(iopt,fancy,atcol,dolabs,backb,wpnt,
12730 #else
12731 	nxtpnd_(iopt,fancy,atcol,dolabs,backb,wpnt,
12732 #endif
12733 #endif
12734 	xyzp->coo);
12735 
12736 }
12737 
12738 #if defined(VMS) || defined(UNDERSC)
scalfr(iopt,fancy,atcol,dolabs,backb,wpnt)12739 void scalfr(iopt,fancy,atcol,dolabs,backb,wpnt)
12740 #else
12741 #ifdef CRAY
12742 void SCALFR(iopt,fancy,atcol,dolabs,backb,wpnt)
12743 #else
12744 void scalfr_(iopt,fancy,atcol,dolabs,backb,wpnt)
12745 #endif
12746 #endif
12747 int *iopt;
12748 int *fancy;
12749 int *atcol;
12750 int *dolabs;
12751 int *backb;
12752 int *wpnt;
12753 {
12754 
12755 #if defined(VMS) || defined(UNDERSC)
12756 	scalfd(iopt,fancy,atcol,dolabs,backb,wpnt,
12757 #else
12758 #ifdef CRAY
12759 	SCALFD(iopt,fancy,atcol,dolabs,backb,wpnt,
12760 #else
12761 	scalfd_(iopt,fancy,atcol,dolabs,backb,wpnt,
12762 #endif
12763 #endif
12764 	rotptr->t,xyzp->coo,
12765 	&scalptr->scal,&scalptr->scali,&scalptr->smag);
12766 
12767 }
12768 
12769 #if defined(VMS) || defined(UNDERSC)
resfr()12770 void resfr()
12771 #else
12772 #ifdef CRAY
12773 void RESFR()
12774 #else
12775 void resfr_()
12776 #endif
12777 #endif
12778 {
12779 
12780 #if defined(VMS) || defined(UNDERSC)
12781 	resfd(
12782 #else
12783 #ifdef CRAY
12784 	RESFD(
12785 #else
12786 	resfd_(
12787 #endif
12788 #endif
12789 	xyzp->coo);
12790 
12791 }
12792 
12793 #if defined(VMS) || defined(UNDERSC)
tofcoo()12794 void tofcoo()
12795 #else
12796 #ifdef CRAY
12797 void TOFCOO()
12798 #else
12799 void tofcoo_()
12800 #endif
12801 #endif
12802 {
12803 
12804 #if defined(VMS) || defined(UNDERSC)
12805 	tofcod(
12806 #else
12807 #ifdef CRAY
12808 	TOFCOD(
12809 #else
12810 	tofcod_(
12811 #endif
12812 #endif
12813 	xyzp->coo);
12814 
12815 }
12816 
12817 #if defined(VMS) || defined(UNDERSC)
iatnox(iatnx)12818 void iatnox(iatnx)
12819 #else
12820 #ifdef CRAY
12821 void IATNOX(iatnx)
12822 #else
12823 void iatnox_(iatnx)
12824 #endif
12825 #endif
12826 int *iatnx;
12827 {
12828 
12829 #if defined(VMS) || defined(UNDERSC)
12830 	iatnod(iatnx,
12831 #else
12832 #ifdef CRAY
12833 	IATNOD(iatnx,
12834 #else
12835 	iatnod_(iatnx,
12836 #endif
12837 #endif
12838 	xyzp->ianz);
12839 
12840 }
12841 
12842 #if defined(VMS) || defined(UNDERSC)
gampoi(ipoint,istat,ioxyz)12843 void gampoi(ipoint,istat,ioxyz)
12844 #else
12845 #ifdef CRAY
12846 void GAMPOI(ipoint,istat,ioxyz)
12847 #else
12848 void gampoi_(ipoint,istat,ioxyz)
12849 #endif
12850 #endif
12851 int *ipoint;
12852 int *istat;
12853 int *ioxyz;
12854 {
12855 
12856 #if defined(VMS) || defined(UNDERSC)
12857 	gampod(ipoint,istat,ioxyz,
12858 #else
12859 #ifdef CRAY
12860 	GAMPOD(ipoint,istat,ioxyz,
12861 #else
12862 	gampod_(ipoint,istat,ioxyz,
12863 #endif
12864 #endif
12865 	xyzp->coo,xyzp->ianz);
12866 
12867 }
12868 
12869 #if defined(VMS) || defined(UNDERSC)
gaupoi(istat)12870 void gaupoi(istat)
12871 #else
12872 #ifdef CRAY
12873 void GAUPOI(istat)
12874 #else
12875 void gaupoi_(istat)
12876 #endif
12877 #endif
12878 int *istat;
12879 {
12880 
12881 #if defined(VMS) || defined(UNDERSC)
12882 	gaupod(istat,
12883 #else
12884 #ifdef CRAY
12885 	GAUPOD(istat,
12886 #else
12887 	gaupod_(istat,
12888 #endif
12889 #endif
12890 	xyzp->coo,xyzp->ianz);
12891 
12892 }
12893 
12894 #if defined(VMS) || defined(UNDERSC)
getpoi(icomm,ifd,iff,doscl,ioatms,ioadd)12895 void getpoi(icomm,ifd,iff,doscl,ioatms,ioadd)
12896 #else
12897 #ifdef CRAY
12898 void GETPOI(icomm,ifd,iff,doscl,ioatms,ioadd)
12899 #else
12900 void getpoi_(icomm,ifd,iff,doscl,ioatms,ioadd)
12901 #endif
12902 #endif
12903 int *icomm;
12904 int *ifd;
12905 int *iff;
12906 int *doscl;
12907 int *ioatms;
12908 int *ioadd;
12909 {
12910 
12911 #if defined(VMS) || defined(UNDERSC)
12912 	getpod(icomm,ifd,iff,doscl,ioatms,ioadd,
12913 #else
12914 #ifdef CRAY
12915 	GETPOD(icomm,ifd,iff,doscl,ioatms,ioadd,
12916 #else
12917 	getpod_(icomm,ifd,iff,doscl,ioatms,ioadd,
12918 #endif
12919 #endif
12920 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iconn,
12921 	&scalptr->scal,&scalptr->scali,&scalptr->smag,
12922 	&cell->natc,&cell->ichx,&cell->icrtp);
12923 
12924 }
12925 
12926 #if defined(VMS) || defined(UNDERSC)
doconn()12927 void doconn()
12928 #else
12929 #ifdef CRAY
12930 void DOCONN()
12931 #else
12932 void doconn_()
12933 #endif
12934 #endif
12935 {
12936 
12937 #if defined(VMS) || defined(UNDERSC)
12938 	docond(
12939 #else
12940 #ifdef CRAY
12941 	DOCOND(
12942 #else
12943 	docond_(
12944 #endif
12945 #endif
12946 	xyzp->coo,xyzp->iconn,xyzp->ianz);
12947 
12948 }
12949 
12950 #if defined(VMS) || defined(UNDERSC)
dohcon(ihflag)12951 void dohcon(ihflag)
12952 #else
12953 #ifdef CRAY
12954 void DOHCON(ihflag)
12955 #else
12956 void dohcon_(ihflag)
12957 #endif
12958 #endif
12959 int *ihflag;
12960 {
12961 
12962 #if defined(VMS) || defined(UNDERSC)
12963 	dohcod(ihflag,
12964 #else
12965 #ifdef CRAY
12966 	DOHCOD(ihflag,
12967 #else
12968 	dohcod_(ihflag,
12969 #endif
12970 #endif
12971 	xyzp->coo,xyzp->ianz,xyzp->iconn,xyzp->isurf);
12972 
12973 }
12974 
12975 #if defined(VMS) || defined(UNDERSC)
nohcon()12976 void nohcon()
12977 #else
12978 #ifdef CRAY
12979 void NOHCON()
12980 #else
12981 void nohcon_()
12982 #endif
12983 #endif
12984 {
12985 
12986 #if defined(VMS) || defined(UNDERSC)
12987 	nohcod(
12988 #else
12989 #ifdef CRAY
12990 	NOHCOD(
12991 #else
12992 	nohcod_(
12993 #endif
12994 #endif
12995 	xyzp->iconn);
12996 
12997 }
12998 
12999 #if defined(VMS) || defined(UNDERSC)
doscal()13000 void doscal()
13001 #else
13002 #ifdef CRAY
13003 void DOSCAL()
13004 #else
13005 void doscal_()
13006 #endif
13007 #endif
13008 {
13009 
13010 #if defined(VMS) || defined(UNDERSC)
13011 	doscad(
13012 #else
13013 #ifdef CRAY
13014 	DOSCAD(
13015 #else
13016 	doscad_(
13017 #endif
13018 #endif
13019 	rotptr->t,xyzp->coo,&posptr->zv,&posptr->pincr,
13020 	&scalptr->scal,&scalptr->scali,&scalptr->smag,&scalptr->iscupd);
13021 
13022 }
13023 
13024 #if defined(VMS) || defined(UNDERSC)
redcon()13025 void redcon()
13026 #else
13027 #ifdef CRAY
13028 void REDCON()
13029 #else
13030 void redcon_()
13031 #endif
13032 #endif
13033 {
13034 
13035 #if defined(VMS) || defined(UNDERSC)
13036 	redcod(
13037 #else
13038 #ifdef CRAY
13039 	REDCOD(
13040 #else
13041 	redcod_(
13042 #endif
13043 #endif
13044 	xyzp->iconn);
13045 
13046 }
13047 
13048 #if defined(VMS) || defined(UNDERSC)
domcon(ipt,idoall)13049 void domcon(ipt,idoall)
13050 #else
13051 #ifdef CRAY
13052 void DOMCON(ipt,idoall)
13053 #else
13054 void domcon_(ipt,idoall)
13055 #endif
13056 #endif
13057 int *ipt;
13058 int *idoall;
13059 {
13060 
13061 #if defined(VMS) || defined(UNDERSC)
13062 	domcod(ipt,idoall,&monmode,
13063 #else
13064 #ifdef CRAY
13065 	DOMCOD(ipt,idoall,&monmode,
13066 #else
13067 	domcod_(ipt,idoall,&monmode,
13068 #endif
13069 #endif
13070 	xyzp->iconn);
13071 
13072 }
13073 
13074 #if defined(VMS) || defined(UNDERSC)
getxyz(igetxy,heat,iaddprv)13075 void getxyz(igetxy,heat,iaddprv)
13076 #else
13077 #ifdef CRAY
13078 void GETXYZ(igetxy,heat,iaddprv)
13079 #else
13080 void getxyz_(igetxy,heat,iaddprv)
13081 #endif
13082 #endif
13083 int *igetxy;
13084 double *heat;
13085 int *iaddprv;
13086 {
13087 
13088 #if defined(VMS) || defined(UNDERSC)
13089 	getxyd(igetxy,heat,iaddprv,
13090 #else
13091 #ifdef CRAY
13092 	GETXYD(igetxy,heat,iaddprv,
13093 #else
13094 	getxyd_(igetxy,heat,iaddprv,
13095 #endif
13096 #endif
13097 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iconn,xyzp->qat,
13098 	&cell->natc,&cell->norg,&cell->icent,&cell->nspg,
13099 	&cell->ichx,&cell->nopr,cell->ir,cell->it,
13100 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
13101 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
13102 
13103 
13104 	if (*igetxy == -1) {
13105 
13106 #if defined(VMS) || defined(UNDERSC)
13107 	   allcoo(&addat,&ZERO);
13108 	   getxyd(igetxy,heat,iaddprv,
13109 #else
13110 #ifdef CRAY
13111 	   ALLCOO(&addat,&ZERO);
13112 	   GETXYD(igetxy,heat,iaddprv,
13113 #else
13114 	   allcoo_(&addat,&ZERO);
13115 	   getxyd_(igetxy,heat,iaddprv,
13116 #endif
13117 #endif
13118 	   xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iconn,xyzp->qat,
13119 	   &cell->natc,&cell->norg,&cell->icent,&cell->nspg,
13120 	   &cell->ichx,&cell->nopr,cell->ir,cell->it,
13121 	   &cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
13122 	   &cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
13123 
13124         }
13125 }
13126 
13127 #if defined(VMS) || defined(UNDERSC)
aln2ml(iopt,istat)13128 void aln2ml(iopt,istat)
13129 #else
13130 #ifdef CRAY
13131 void ALN2ML(iopt,istat)
13132 #else
13133 void aln2ml_(iopt,istat)
13134 #endif
13135 #endif
13136 int *iopt;
13137 int *istat;
13138 {
13139 
13140 #if defined(VMS) || defined(UNDERSC)
13141 	aln2md(iopt,istat,
13142 #else
13143 #ifdef CRAY
13144 	ALN2MD(iopt,istat,
13145 #else
13146 	aln2md_(iopt,istat,
13147 #endif
13148 #endif
13149 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid);
13150 
13151 }
13152 
13153 #if defined(VMS) || defined(UNDERSC)
alnrot(vec,irot)13154 void alnrot(vec,irot)
13155 #else
13156 #ifdef CRAY
13157 void ALNROT(vec,irot)
13158 #else
13159 void alnrot_(vec,irot)
13160 #endif
13161 #endif
13162 double *vec;
13163 int *irot;
13164 {
13165 
13166 #if defined(VMS) || defined(UNDERSC)
13167 	alnrod(vec,irot,
13168 #else
13169 #ifdef CRAY
13170 	ALNROD(vec,irot,
13171 #else
13172 	alnrod_(vec,irot,
13173 #endif
13174 #endif
13175 	xyzp->coo);
13176 
13177 }
13178 
13179 #if defined(VMS) || defined(UNDERSC)
pckrot(istat,iatsel)13180 void pckrot(istat,iatsel)
13181 #else
13182 #ifdef CRAY
13183 void PCKROT(istat,iatsel)
13184 #else
13185 void pckrot_(istat,iatsel)
13186 #endif
13187 #endif
13188 int *iatsel;
13189 int *istat;
13190 {
13191 
13192 #if defined(VMS) || defined(UNDERSC)
13193 	pckrod(istat,iatsel,
13194 #else
13195 #ifdef CRAY
13196 	PCKROD(istat,iatsel,
13197 #else
13198 	pckrod_(istat,iatsel,
13199 #endif
13200 #endif
13201 	xyzp->iresid,xyzp->iconn,
13202 	calfptr->ianf,calfptr->islu,
13203 	&calfptr->nchain);
13204 
13205 }
13206 
13207 #if defined(VMS) || defined(UNDERSC)
alnwrt()13208 void alnwrt()
13209 #else
13210 #ifdef CRAY
13211 void ALNWRT()
13212 #else
13213 void alnwrt_()
13214 #endif
13215 #endif
13216 {
13217 
13218 #if defined(VMS) || defined(UNDERSC)
13219 	alnwrd(
13220 #else
13221 #ifdef CRAY
13222 	ALNWRD(
13223 #else
13224 	alnwrd_(
13225 #endif
13226 #endif
13227 	xyzp->coo,xyzp->ianz);
13228 
13229 }
13230 
13231 #if defined(VMS) || defined(UNDERSC)
alnsel(isel)13232 void alnsel(isel)
13233 #else
13234 #ifdef CRAY
13235 void ALNSEL(isel)
13236 #else
13237 void alnsel_(isel)
13238 #endif
13239 #endif
13240 int *isel;
13241 {
13242 
13243 #if defined(VMS) || defined(UNDERSC)
13244 	alnsed(isel,
13245 #else
13246 #ifdef CRAY
13247 	ALNSED(isel,
13248 #else
13249 	alnsed_(isel,
13250 #endif
13251 #endif
13252 	xyzp->coo);
13253 
13254 }
13255 
13256 #if defined(VMS) || defined(UNDERSC)
getchr(igetca)13257 void getchr(igetca)
13258 #else
13259 #ifdef CRAY
13260 void GETCHR(igetca)
13261 #else
13262 void getchr_(igetca)
13263 #endif
13264 #endif
13265 int *igetca;
13266 {
13267 
13268 #if defined(VMS) || defined(UNDERSC)
13269 	getchd(igetca,
13270 #else
13271 #ifdef CRAY
13272 	GETCHD(igetca,
13273 #else
13274 	getchd_(igetca,
13275 #endif
13276 #endif
13277 	xyzp->qat);
13278 
13279 }
13280 
13281 #if defined(VMS) || defined(UNDERSC)
mopxyz(iun)13282 void mopxyz(iun)
13283 #else
13284 #ifdef CRAY
13285 void MOPXYZ(iun)
13286 #else
13287 void mopxyz_(iun)
13288 #endif
13289 #endif
13290 int *iun;
13291 {
13292 
13293 #if defined(VMS) || defined(UNDERSC)
13294 	mopxyd(iun,
13295 #else
13296 #ifdef CRAY
13297 	MOPXYD(iun,
13298 #else
13299 	mopxyd_(iun,
13300 #endif
13301 #endif
13302 	xyzp->coo,xyzp->ianz,xyzp->iconn);
13303 
13304 }
13305 
13306 #if defined(VMS) || defined(UNDERSC)
getmol(igetmo,iadd)13307 void getmol(igetmo,iadd)
13308 #else
13309 #ifdef CRAY
13310 void GETMOl(igetmo,iadd)
13311 #else
13312 void getmol_(igetmo,iadd)
13313 #endif
13314 #endif
13315 int *igetmo;
13316 int *iadd;
13317 {
13318 
13319 #if defined(VMS) || defined(UNDERSC)
13320 	getmod(igetmo,iadd,
13321 #else
13322 #ifdef CRAY
13323 	GETMOD(igetmo,iadd,
13324 #else
13325 	getmod_(igetmo,iadd,
13326 #endif
13327 #endif
13328 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iaton,xyzp->iconn,xyzp->iresid);
13329 
13330 }
13331 
13332 #if defined(VMS) || defined(UNDERSC)
outmol(iun)13333 void outmol(iun)
13334 #else
13335 #ifdef CRAY
13336 void OUTMOl(iun)
13337 #else
13338 void outmol_(iun)
13339 #endif
13340 #endif
13341 int *iun;
13342 {
13343 
13344 #if defined(VMS) || defined(UNDERSC)
13345 	outmod(iun,
13346 #else
13347 #ifdef CRAY
13348 	OUTMOD(iun,
13349 #else
13350 	outmod_(iun,
13351 #endif
13352 #endif
13353 	xyzp->coo,xyzp->ianz,xyzp->iconn);
13354 
13355 }
13356 
13357 #if defined(VMS) || defined(UNDERSC)
mopaco(istats,mopopt,irtype)13358 void mopaco(istats,mopopt,irtype)
13359 #else
13360 #ifdef CRAY
13361 void MOPACO(istats,mopopt,irtype)
13362 #else
13363 void mopaco_(istats,mopopt,irtype)
13364 #endif
13365 #endif
13366 int *istats;
13367 int *mopopt;
13368 int *irtype;
13369 {
13370 
13371 #if defined(VMS) || defined(UNDERSC)
13372 	mopacd(istats,mopopt,irtype,
13373 #else
13374 #ifdef CRAY
13375 	MOPACD(istats,mopopt,irtype,
13376 #else
13377 	mopacd_(istats,mopopt,irtype,
13378 #endif
13379 #endif
13380 	xyzp->ianz,xyzp->iatclr,xyzp->iconn,xyzp->coo,xyzp->qat,
13381 	&cell->natc,&cell->icent,&cell->nspg,
13382 	&cell->ichx,&cell->nopr,cell->ir,cell->it,
13383 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
13384 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
13385 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
13386 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
13387 
13388 }
13389 
13390 #if defined(VMS) || defined(UNDERSC)
parfc()13391 void parfc()
13392 #else
13393 #ifdef CRAY
13394 void PARFC()
13395 #else
13396 void parfc_()
13397 #endif
13398 #endif
13399 {
13400 
13401 #if defined(VMS) || defined(UNDERSC)
13402 	parfd(
13403 #else
13404 #ifdef CRAY
13405 	PARFD(
13406 #else
13407 	parfd_(
13408 #endif
13409 #endif
13410 	xyzp->coo,&scalptr->fscal);
13411 
13412 }
13413 
13414 #if defined(VMS) || defined(UNDERSC)
plmol()13415 void plmol()
13416 #else
13417 #ifdef CRAY
13418 void PLMOL()
13419 #else
13420 void plmol_()
13421 #endif
13422 #endif
13423 {
13424 
13425 #if defined(VMS) || defined(UNDERSC)
13426 	plmod(
13427 #else
13428 #ifdef CRAY
13429 	PLMOD(
13430 #else
13431 	plmod_(
13432 #endif
13433 #endif
13434 	xyzp->coo,xyzp->qat,xyzp->rzp,xyzp->ixp,xyzp->iyp,xyzp->iconn,
13435 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->inat,
13436 	calfptr->lab,clfstrptr->labhet,
13437 	&posptr->xv,&posptr->yv,calfptr->icalf,&calfptr->ncalf,
13438 	calfptr->icxp,calfptr->icyp,&scalptr->scal,&scalptr->scali);
13439 
13440 }
13441 
13442 #if defined(VMS) || defined(UNDERSC)
plmolp()13443 void plmolp()
13444 #else
13445 #ifdef CRAY
13446 void PLMOLP()
13447 #else
13448 void plmolp_()
13449 #endif
13450 #endif
13451 {
13452 
13453 #if defined(VMS) || defined(UNDERSC)
13454 	plmold(
13455 #else
13456 #ifdef CRAY
13457 	PLMOLD(
13458 #else
13459 	plmold_(
13460 #endif
13461 #endif
13462 	xyzp->coo,xyzp->qat,xyzp->rzp,xyzp->ixp,xyzp->iyp,xyzp->iconn,xyzp->ianz,
13463 	xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->inat,
13464 	calfptr->lab,clfstrptr->labhet,
13465 	&posptr->xv,&posptr->yv,&posptr->zv,&posptr->c0,
13466 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
13467 	&calfptr->nchain,calfptr->iamino,calfptr->reson,
13468 	calfptr->icxp,calfptr->icyp,calfptr->irsnr,calfptr->achain,
13469 	&scalptr->scali);
13470 
13471 }
13472 
13473 #if defined(VMS) || defined(UNDERSC)
plfc(shade,ixx,k,ihigh,colsc,icltan,zvect)13474 void plfc(shade,ixx,k,ihigh,colsc,icltan,zvect)
13475 #else
13476 #ifdef CRAY
13477 void PLFC(shade,ixx,k,ihigh,colsc,icltan,zvect)
13478 #else
13479 void plfc_(shade,ixx,k,ihigh,colsc,icltan,zvect)
13480 #endif
13481 #endif
13482 int *shade;
13483 int *ixx;
13484 int *k;
13485 int *ihigh;
13486 double *colsc;
13487 int *icltan;
13488 double *zvect;
13489 {
13490 
13491 #if defined(VMS) || defined(UNDERSC)
13492 	plfd(shade,ixx,k,ihigh,colsc,icltan,zvect,
13493 #else
13494 #ifdef CRAY
13495 	PLFD(shade,ixx,k,ihigh,colsc,icltan,zvect,
13496 #else
13497 	plfd_(shade,ixx,k,ihigh,colsc,icltan,zvect,
13498 #endif
13499 #endif
13500 	xyzp->coo,xyzp->rzp,xyzp->ixp,xyzp->iyp,
13501 	&posptr->xv,&posptr->yv,&scalptr->scal,&scalptr->scali);
13502 
13503 }
13504 
13505 #if defined(VMS) || defined(UNDERSC)
plfcp(shade,ixx,k,ihigh,colsc,icltan,zvect,scalp)13506 void plfcp(shade,ixx,k,ihigh,colsc,icltan,zvect,scalp)
13507 #else
13508 #ifdef CRAY
13509 void PLFCP(shade,ixx,k,ihigh,colsc,icltan,zvect,scalp)
13510 #else
13511 void plfcp_(shade,ixx,k,ihigh,colsc,icltan,zvect,scalp)
13512 #endif
13513 #endif
13514 int *shade;
13515 int *ixx;
13516 int *k;
13517 int *ihigh;
13518 double *colsc;
13519 int *icltan;
13520 double *zvect;
13521 double *scalp;
13522 {
13523 
13524 #if defined(VMS) || defined(UNDERSC)
13525 	plfcd(shade,ixx,k,ihigh,colsc,icltan,zvect,scalp,
13526 #else
13527 #ifdef CRAY
13528 	PLFCD(shade,ixx,k,ihigh,colsc,icltan,zvect,scalp,
13529 #else
13530 	plfcd_(shade,ixx,k,ihigh,colsc,icltan,zvect,scalp,
13531 #endif
13532 #endif
13533 	xyzp->coo,xyzp->rzp,xyzp->ixp,xyzp->iyp,
13534 	&posptr->xv,&posptr->yv,&posptr->zv,&posptr->c0,
13535 	&scalptr->scali);
13536 
13537 }
13538 
13539 #if defined(VMS) || defined(UNDERSC)
mstick(zvect,colsc,icltan,m,k,shade,idash)13540 void mstick(zvect,colsc,icltan,m,k,shade,idash)
13541 #else
13542 #ifdef CRAY
13543 void MSTICK(zvect,colsc,icltan,m,k,shade,idash)
13544 #else
13545 void mstick_(zvect,colsc,icltan,m,k,shade,idash)
13546 #endif
13547 #endif
13548 double *zvect;
13549 double *colsc;
13550 int *icltan;
13551 int *m;
13552 int *k;
13553 int *shade;
13554 int *idash;
13555 {
13556 
13557 #if defined(VMS) || defined(UNDERSC)
13558 	msticd(zvect,colsc,icltan,m,k,shade,idash,
13559 #else
13560 #ifdef CRAY
13561 	MSTICD(zvect,colsc,icltan,m,k,shade,idash,
13562 #else
13563 	msticd_(zvect,colsc,icltan,m,k,shade,idash,
13564 #endif
13565 #endif
13566 	xyzp->coo,xyzp->rzp,xyzp->ixp,xyzp->iyp,xyzp->iatclr,
13567 	&scalptr->scali);
13568 
13569 }
13570 
13571 #if defined(VMS) || defined(UNDERSC)
mstck(zvect,colsc,icltan,m,k,shade,idash)13572 void mstck(zvect,colsc,icltan,m,k,shade,idash)
13573 #else
13574 #ifdef CRAY
13575 void MSTCK(zvect,colsc,icltan,m,k,shade,idash)
13576 #else
13577 void mstck_(zvect,colsc,icltan,m,k,shade,idash)
13578 #endif
13579 #endif
13580 double *zvect;
13581 double *colsc;
13582 int *icltan;
13583 int *m;
13584 int *k;
13585 int *shade;
13586 int *idash;
13587 {
13588 
13589 #if defined(VMS) || defined(UNDERSC)
13590 	mstcd(zvect,colsc,icltan,m,k,shade,idash,
13591 #else
13592 #ifdef CRAY
13593 	MSTCD(zvect,colsc,icltan,m,k,shade,idash,
13594 #else
13595 	mstcd_(zvect,colsc,icltan,m,k,shade,idash,
13596 #endif
13597 #endif
13598 	xyzp->coo,xyzp->rzp,xyzp->ixp,xyzp->iyp,xyzp->iatclr,
13599 	&posptr->zv,&scalptr->scali);
13600 
13601 }
13602 
13603 #if defined(VMS) || defined(UNDERSC)
sstick()13604 void sstick()
13605 #else
13606 #ifdef CRAY
13607 void SSTICK()
13608 #else
13609 void sstick_()
13610 #endif
13611 #endif
13612 {
13613 
13614 #if defined(VMS) || defined(UNDERSC)
13615 	ssticd(
13616 #else
13617 #ifdef CRAY
13618 	SSTICD(
13619 #else
13620 	ssticd_(
13621 #endif
13622 #endif
13623 	xyzp->coo,xyzp->ixp,xyzp->iyp,xyzp->iaton,xyzp->iconn,
13624 	&posptr->xv,&posptr->yv,&scalptr->scal);
13625 
13626 }
13627 
13628 #if defined(VMS) || defined(UNDERSC)
astick(zvect,colsc,icltan,m,k,ihigh,shade,idash,imon)13629 void astick(zvect,colsc,icltan,m,k,ihigh,shade,idash,imon)
13630 #else
13631 #ifdef CRAY
13632 void ASTICK(zvect,colsc,icltan,m,k,ihigh,shade,idash,imon)
13633 #else
13634 void astick_(zvect,colsc,icltan,m,k,ihigh,shade,idash,imon)
13635 #endif
13636 #endif
13637 double *zvect;
13638 double *colsc;
13639 int *icltan;
13640 int *m;
13641 int *k;
13642 int *ihigh;
13643 int *shade;
13644 int *idash;
13645 int *imon;
13646 {
13647 
13648 #if defined(VMS) || defined(UNDERSC)
13649 	asticd(zvect,colsc,icltan,m,k,ihigh,shade,idash,imon,
13650 #else
13651 #ifdef CRAY
13652 	ASTICD(zvect,colsc,icltan,m,k,ihigh,shade,idash,imon,
13653 #else
13654 	asticd_(zvect,colsc,icltan,m,k,ihigh,shade,idash,imon,
13655 #endif
13656 #endif
13657 	xyzp->coo,xyzp->rzp,xyzp->ixp,xyzp->iyp,xyzp->ianz,xyzp->iatclr,
13658 	&posptr->xv,&posptr->yv,&scalptr->scal,&scalptr->scali);
13659 
13660 }
13661 
13662 #if defined(VMS) || defined(UNDERSC)
astck(zvect,colsc,scalp,icltan,m,k,ihigh,shade,idash,imon)13663 void astck(zvect,colsc,scalp,icltan,m,k,ihigh,shade,idash,imon)
13664 #else
13665 #ifdef CRAY
13666 void ASTCK(zvect,colsc,scalp,icltan,m,k,ihigh,shade,idash,imon)
13667 #else
13668 void astck_(zvect,colsc,scalp,icltan,m,k,ihigh,shade,idash,imon)
13669 #endif
13670 #endif
13671 double *zvect;
13672 double *colsc;
13673 double *scalp;
13674 int *icltan;
13675 int *m;
13676 int *k;
13677 int *ihigh;
13678 int *shade;
13679 int *idash;
13680 int *imon;
13681 {
13682 
13683 #if defined(VMS) || defined(UNDERSC)
13684 	astcd(zvect,colsc,scalp,icltan,m,k,ihigh,shade,idash,imon,
13685 #else
13686 #ifdef CRAY
13687 	ASTCD(zvect,colsc,scalp,icltan,m,k,ihigh,shade,idash,imon,
13688 #else
13689 	astcd_(zvect,colsc,scalp,icltan,m,k,ihigh,shade,idash,imon,
13690 #endif
13691 #endif
13692 	xyzp->coo,xyzp->rzp,xyzp->ixp,xyzp->iyp,xyzp->ianz,xyzp->iatclr,
13693 	&posptr->xv,&posptr->yv,&posptr->zv,&posptr->c0,&scalptr->scali);
13694 
13695 }
13696 
13697 #if defined(VMS) || defined(UNDERSC)
snglat(zvect,scalp,colsc,icltan,k,ihigh,shade,atcol,ipersp,ipost,icolps)13698 void snglat(zvect,scalp,colsc,icltan,k,ihigh,shade,atcol,ipersp,ipost,icolps)
13699 #else
13700 #ifdef CRAY
13701 void SNGLAT(zvect,scalp,colsc,icltan,k,ihigh,shade,atcol,ipersp,ipost,icolps)
13702 #else
13703 void snglat_(zvect,scalp,colsc,icltan,k,ihigh,shade,atcol,ipersp,ipost,icolps)
13704 #endif
13705 #endif
13706 double *zvect;
13707 double *scalp;
13708 double *colsc;
13709 int *icltan;
13710 int *k;
13711 int *ihigh;
13712 int *shade;
13713 int *atcol;
13714 int *ipersp;
13715 int *ipost;
13716 int *icolps;
13717 {
13718 
13719 #if defined(VMS) || defined(UNDERSC)
13720 	snglad(zvect,scalp,colsc,icltan,k,ihigh,shade,atcol,ipersp,ipost,icolps,
13721 #else
13722 #ifdef CRAY
13723 	SNGLAD(zvect,scalp,colsc,icltan,k,ihigh,shade,atcol,ipersp,ipost,icolps,
13724 #else
13725 	snglad_(zvect,scalp,colsc,icltan,k,ihigh,shade,atcol,ipersp,ipost,icolps,
13726 #endif
13727 #endif
13728 	xyzp->coo,xyzp->rzp,xyzp->ixp,xyzp->iyp,xyzp->ianz,xyzp->iatclr,
13729 	&posptr->xv,&posptr->yv,&posptr->zv,&posptr->c0,
13730 	&scalptr->scal,&scalptr->scali);
13731 
13732 }
13733 
13734 #if defined(VMS) || defined(UNDERSC)
fstick(roddef,rfac,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)13735 void fstick(roddef,rfac,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)
13736 #else
13737 #ifdef CRAY
13738 void FSTICK(roddef,rfac,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)
13739 #else
13740 void fstick_(roddef,rfac,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)
13741 #endif
13742 #endif
13743 double *roddef;
13744 double *rfac;
13745 double *zvect;
13746 double *colsc;
13747 int *icltan;
13748 int *m;
13749 int *k;
13750 int *ihigh;
13751 int *shade;
13752 int *atcol;
13753 int *scnd;
13754 {
13755 
13756 #if defined(VMS) || defined(UNDERSC)
13757 	fsticd(roddef,rfac,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd,
13758 #else
13759 #ifdef CRAY
13760 	FSTICD(roddef,rfac,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd,
13761 #else
13762 	fsticd_(roddef,rfac,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd,
13763 #endif
13764 #endif
13765 	xyzp->coo,xyzp->rzp,xyzp->ianz,xyzp->iatclr,
13766 	&posptr->xv,&posptr->yv,&scalptr->scal,&scalptr->scali);
13767 
13768 }
13769 
13770 #if defined(VMS) || defined(UNDERSC)
fstck(roddef,rfac,scalp,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)13771 void fstck(roddef,rfac,scalp,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)
13772 #else
13773 #ifdef CRAY
13774 void FSTCK(roddef,rfac,scalp,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)
13775 #else
13776 void fstck_(roddef,rfac,scalp,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd)
13777 #endif
13778 #endif
13779 double *roddef;
13780 double *rfac;
13781 double *scalp;
13782 double *zvect;
13783 double *colsc;
13784 int *icltan;
13785 int *m;
13786 int *k;
13787 int *ihigh;
13788 int *shade;
13789 int *atcol;
13790 int *scnd;
13791 {
13792 
13793 #if defined(VMS) || defined(UNDERSC)
13794 	fstcd(roddef,rfac,scalp,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd,
13795 #else
13796 #ifdef CRAY
13797 	FSTCD(roddef,rfac,scalp,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd,
13798 #else
13799 	fstcd_(roddef,rfac,scalp,zvect,colsc,icltan,m,k,ihigh,shade,atcol,scnd,
13800 #endif
13801 #endif
13802 	xyzp->coo,xyzp->rzp,xyzp->ianz,xyzp->iatclr,
13803 	&posptr->xv,&posptr->yv,&posptr->zv,&posptr->c0,&scalptr->scali);
13804 
13805 }
13806 
13807 #if defined(VMS) || defined(UNDERSC)
pldstg()13808 void pldstg()
13809 #else
13810 #ifdef CRAY
13811 void PLDSTG()
13812 #else
13813 void pldstg_()
13814 #endif
13815 #endif
13816 {
13817 
13818 #if defined(VMS) || defined(UNDERSC)
13819 	pldstd(
13820 #else
13821 #ifdef CRAY
13822 	PLDSTD(
13823 #else
13824 	pldstd_(
13825 #endif
13826 #endif
13827 	xyzp->ixp,xyzp->iyp);
13828 
13829 }
13830 
13831 #if defined(VMS) || defined(UNDERSC)
plalab(iqon)13832 void plalab(iqon)
13833 #else
13834 #ifdef CRAY
13835 void PLALAB(iqon)
13836 #else
13837 void plalab_(iqon)
13838 #endif
13839 #endif
13840 int *iqon;
13841 {
13842 
13843 #if defined(VMS) || defined(UNDERSC)
13844 	plalad(iqon,
13845 #else
13846 #ifdef CRAY
13847 	PLALAD(iqon,
13848 #else
13849 	plalad_(iqon,
13850 #endif
13851 #endif
13852 	xyzp->rzp,xyzp->ixp,xyzp->iyp,
13853 	calfptr->icalf,calfptr->ianf,calfptr->islu,&calfptr->nchain,
13854 	calfptr->iamino,calfptr->reson,calfptr->irsnr,calfptr->achain,
13855 	&scalptr->scali);
13856 
13857 }
13858 
13859 #if defined(VMS) || defined(UNDERSC)
reslab()13860 void reslab()
13861 #else
13862 #ifdef CRAY
13863 void RESLAB()
13864 #else
13865 void reslab_()
13866 #endif
13867 #endif
13868 {
13869 
13870 #if defined(VMS) || defined(UNDERSC)
13871 	reslad(
13872 #else
13873 #ifdef CRAY
13874 	RESLAD(
13875 #else
13876 	reslad_(
13877 #endif
13878 #endif
13879 	xyzp->rzp,xyzp->ixp,xyzp->iyp,
13880 	calfptr->icalf,&calfptr->nchain,
13881 	calfptr->iamino,calfptr->reson,calfptr->irsnr,calfptr->lab,
13882 	calfptr->ihet,
13883 	calfptr->achain,&calfptr->ncalf,&scalptr->scali);
13884 
13885 }
13886 
13887 #if defined(VMS) || defined(UNDERSC)
plalb(iami)13888 void plalb(iami)
13889 #else
13890 #ifdef CRAY
13891 void PLALB(iami)
13892 #else
13893 void plalb_(iami)
13894 #endif
13895 #endif
13896 int *iami;
13897 {
13898 
13899 #if defined(VMS) || defined(UNDERSC)
13900 	plald(iami,
13901 #else
13902 #ifdef CRAY
13903 	PLALD(iami,
13904 #else
13905 	plald_(iami,
13906 #endif
13907 #endif
13908 	xyzp->ixp,xyzp->iyp,
13909 	calfptr->icalf,calfptr->iamino,calfptr->irsnr);
13910 
13911 }
13912 
13913 #if defined(VMS) || defined(UNDERSC)
pllab(ixp,iyp,ianz,k,qat,inr,iqon,ires,ipost)13914 void pllab(ixp,iyp,ianz,k,qat,inr,iqon,ires,ipost)
13915 #else
13916 #ifdef CRAY
13917 void PLLAB(ixp,iyp,ianz,k,qat,inr,iqon,ires,ipost)
13918 #else
13919 void pllab_(ixp,iyp,ianz,k,qat,inr,iqon,ires,ipost)
13920 #endif
13921 #endif
13922 int *ixp;
13923 int *iyp;
13924 int *ianz;
13925 int *k;
13926 double *qat;
13927 int *inr;
13928 int *iqon;
13929 int *ires;
13930 int *ipost;
13931 {
13932 
13933 #if defined(VMS) || defined(UNDERSC)
13934 	pllad(ixp,iyp,ianz,k,qat,inr,iqon,ires,ipost,
13935 #else
13936 #ifdef CRAY
13937 	PLLAD(ixp,iyp,ianz,k,qat,inr,iqon,ires,ipost,
13938 #else
13939 	pllad_(ixp,iyp,ianz,k,qat,inr,iqon,ires,ipost,
13940 #endif
13941 #endif
13942 	xyzp->ityp,xyzp->ipdbt,
13943 	calfptr->iamino,calfptr->reson);
13944 
13945 }
13946 
13947 #if defined(VMS) || defined(UNDERSC)
plpost(backb,dolabs,icolps,fancy,atcol,persp,shade,idelx)13948 void plpost(backb,dolabs,icolps,fancy,atcol,persp,shade,idelx)
13949 #else
13950 #ifdef CRAY
13951 void PLPOST(backb,dolabs,icolps,fancy,atcol,persp,shade,idelx)
13952 #else
13953 void plpost_(backb,dolabs,icolps,fancy,atcol,persp,shade,idelx)
13954 #endif
13955 #endif
13956 int *backb;
13957 int *dolabs;
13958 int *icolps;
13959 int *fancy;
13960 int *atcol;
13961 int *persp;
13962 int *shade;
13963 int *idelx;
13964 {
13965 
13966 #if defined(VMS) || defined(UNDERSC)
13967 	plposd(backb,dolabs,icolps,fancy,atcol,persp,shade,idelx,
13968 #else
13969 #ifdef CRAY
13970 	PLPOSD(backb,dolabs,icolps,fancy,atcol,persp,shade,idelx,
13971 #else
13972 	plposd_(backb,dolabs,icolps,fancy,atcol,persp,shade,idelx,
13973 #endif
13974 #endif
13975 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iatclr,xyzp->iconn,
13976 	xyzp->ixp,xyzp->iyp,xyzp->rzp,xyzp->inat,xyzp->qat,
13977 	&posptr->xv,&posptr->yv,&posptr->zv,
13978 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
13979 	&calfptr->nchain,calfptr->iamino,calfptr->reson,&scalptr->scal);
13980 
13981 }
13982 
13983 #if defined(VMS) || defined(UNDERSC)
plvrml(iun,fancy,atcol,dolabs,ihnd,backb,dohead)13984 void plvrml(iun,fancy,atcol,dolabs,ihnd,backb,dohead)
13985 #else
13986 #ifdef CRAY
13987 void PLVRML(iun,fancy,atcol,dolabs,ihnd,backb,dohead)
13988 #else
13989 void plvrml_(iun,fancy,atcol,dolabs,ihnd,backb,dohead)
13990 #endif
13991 #endif
13992 int *iun;
13993 int *fancy;
13994 int *atcol;
13995 int *dolabs;
13996 int *ihnd;
13997 int *backb;
13998 int *dohead;
13999 {
14000 
14001 #if defined(VMS) || defined(UNDERSC)
14002 	plvrmd(iun,fancy,atcol,dolabs,ihnd,backb,dohead,
14003 #else
14004 #ifdef CRAY
14005 	PLVRMD(iun,fancy,atcol,dolabs,ihnd,backb,dohead,
14006 #else
14007 	plvrmd_(iun,fancy,atcol,dolabs,ihnd,backb,dohead,
14008 #endif
14009 #endif
14010 	rotptr->rz,rotptr->t,
14011 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
14012 	calfptr->icalf,calfptr->ianf,calfptr->islu,&calfptr->nchain,
14013 	calfptr->iamino,calfptr->reson,&scalptr->scal,&scalptr->scali);
14014 
14015 }
14016 
14017 #if defined(VMS) || defined(UNDERSC)
plvst(iun,jcol,k,atcol,hndexl)14018 void plvst(iun,jcol,k,atcol,hndexl)
14019 #else
14020 #ifdef CRAY
14021 void PLVST(iun,jcol,k,atcol,hndexl)
14022 #else
14023 void plvst_(iun,jcol,k,atcol,hndexl)
14024 #endif
14025 #endif
14026 int *iun;
14027 int *jcol;
14028 int *k;
14029 int *atcol;
14030 int *hndexl;
14031 {
14032 
14033 #if defined(VMS) || defined(UNDERSC)
14034 	plvsd(iun,jcol,k,atcol,hndexl,
14035 #else
14036 #ifdef CRAY
14037 	PLVSD(iun,jcol,k,atcol,hndexl,
14038 #else
14039 	plvsd_(iun,jcol,k,atcol,hndexl,
14040 #endif
14041 #endif
14042 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iconn);
14043 
14044 }
14045 
14046 #if defined(VMS) || defined(UNDERSC)
hcoord(ioatms,nstrt,iaddh)14047 void hcoord(ioatms,nstrt,iaddh)
14048 #else
14049 #ifdef CRAY
14050 void HCOORD(ioatms,nstrt,iaddh)
14051 #else
14052 void hcoord_(ioatms,nstrt,iaddh)
14053 #endif
14054 #endif
14055 int *ioatms;
14056 int *nstrt;
14057 int *iaddh;
14058 {
14059   int istat;
14060 
14061 #if defined(VMS) || defined(UNDERSC)
14062 	hcoodd(&istat,ioatms,nstrt,iaddh,
14063 #else
14064 #ifdef CRAY
14065 	HCOODD(&istat,ioatms,nstrt,iaddh,
14066 #else
14067 	hcoodd_(&istat,ioatms,nstrt,iaddh,
14068 #endif
14069 #endif
14070 	xyzp->ipdbt,xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn,
14071 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14072 	&calfptr->nchain,calfptr->iamino);
14073 
14074 
14075 	if (!istat) {
14076 #if defined(VMS) || defined(UNDERSC)
14077 	   allcoo(&addat,&ZERO);
14078 	   hcoodd(&istat,ioatms,nstrt,iaddh,
14079 #else
14080 #ifdef CRAY
14081 	   ALLCOO(&addat,&ZERO);
14082 	   HCOODD(&istat,ioatms,nstrt,iaddh,
14083 #else
14084 	   allcoo_(&addat,&ZERO);
14085 	   hcoodd_(&istat,ioatms,nstrt,iaddh,
14086 #endif
14087 #endif
14088 	   xyzp->ipdbt,xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iresid,
14089 	   xyzp->iconn,
14090 	   calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14091 	   &calfptr->nchain,calfptr->iamino);
14092         }
14093 }
14094 
14095 #if defined(VMS) || defined(UNDERSC)
hang(idx1,idx2,hang)14096 void hang(idx1,idx2,hang)
14097 #else
14098 #ifdef CRAY
14099 void HANG(idx1,idx2,hang)
14100 #else
14101 void hang_(idx1,idx2,hang)
14102 #endif
14103 #endif
14104 int *idx1;
14105 int *idx2;
14106 double *hang;
14107 {
14108 
14109 #if defined(VMS) || defined(UNDERSC)
14110 	hand(idx1,idx2,hang,
14111 #else
14112 #ifdef CRAY
14113 	HAND(idx1,idx2,hang,
14114 #else
14115 	hand_(idx1,idx2,hang,
14116 #endif
14117 #endif
14118 	xyzp->coo,xyzp->ianz,xyzp->iconn,
14119 	calfptr->icalf);
14120 
14121 }
14122 
14123 #if defined(VMS) || defined(UNDERSC)
hbond(ioatms,nstrt)14124 void hbond(ioatms,nstrt)
14125 #else
14126 #ifdef CRAY
14127 void HBOND(ioatms,nstrt)
14128 #else
14129 void hbond_(ioatms,nstrt)
14130 #endif
14131 #endif
14132 int *ioatms;
14133 int *nstrt;
14134 {
14135 
14136 #if defined(VMS) || defined(UNDERSC)
14137 	hbodd(ioatms,nstrt,
14138 #else
14139 #ifdef CRAY
14140 	HBODD(ioatms,nstrt,
14141 #else
14142 	hbodd_(ioatms,nstrt,
14143 #endif
14144 #endif
14145 	xyzp->coo,xyzp->ianz,xyzp->iconn,
14146 	calfptr->icalf,&calfptr->ncalf,calfptr->iamino);
14147 
14148 }
14149 
14150 #if defined(VMS) || defined(UNDERSC)
acthb(iopt,hbfilt)14151 void acthb(iopt,hbfilt)
14152 #else
14153 #ifdef CRAY
14154 void ACTHB(iopt,hbfilt)
14155 #else
14156 void acthb_(iopt,hbfilt)
14157 #endif
14158 #endif
14159 int *iopt;
14160 double *hbfilt;
14161 {
14162 
14163 #if defined(VMS) || defined(UNDERSC)
14164 	acthd(iopt,hbfilt,
14165 #else
14166 #ifdef CRAY
14167 	ACTHD(iopt,hbfilt,
14168 #else
14169 	acthd_(iopt,hbfilt,
14170 #endif
14171 #endif
14172 	xyzp->coo,xyzp->iconn,xyzp->ianz,
14173 	calfptr->icalf,&calfptr->ncalf);
14174 
14175 }
14176 
14177 #if defined(VMS) || defined(UNDERSC)
disabh(iopt)14178 void disabh(iopt)
14179 #else
14180 #ifdef CRAY
14181 void DISABH(iopt)
14182 #else
14183 void disabh_(iopt)
14184 #endif
14185 #endif
14186 int *iopt;
14187 {
14188 
14189 #if defined(VMS) || defined(UNDERSC)
14190 	disabd(iopt,
14191 #else
14192 #ifdef CRAY
14193 	DISABD(iopt,
14194 #else
14195 	disabd_(iopt,
14196 #endif
14197 #endif
14198 	xyzp->ianz,xyzp->iaton,xyzp->iconn);
14199 
14200 }
14201 
14202 #if defined(VMS) || defined(UNDERSC)
hbconn(iopt,iat1,iat2)14203 void hbconn(iopt,iat1,iat2)
14204 #else
14205 #ifdef CRAY
14206 void HBCONN(iopt,iat1,iat2)
14207 #else
14208 void hbconn_(iopt,iat1,iat2)
14209 #endif
14210 #endif
14211 int *iopt;
14212 int *iat1;
14213 int *iat2;
14214 {
14215 
14216 #if defined(VMS) || defined(UNDERSC)
14217 	hbcond(iopt,iat1,iat2,
14218 #else
14219 #ifdef CRAY
14220 	HBCOND(iopt,iat1,iat2,
14221 #else
14222 	hbcond_(iopt,iat1,iat2,
14223 #endif
14224 #endif
14225 	xyzp->ianz,xyzp->iatclr,xyzp->iaton,xyzp->iconn);
14226 
14227 }
14228 
14229 #if defined(VMS) || defined(UNDERSC)
getchn(ires,ichain)14230 void getchn(ires,ichain)
14231 #else
14232 #ifdef CRAY
14233 void GETCHN(ires,ichain)
14234 #else
14235 void getchn_(ires,ichain)
14236 #endif
14237 #endif
14238 int *ires;
14239 int *ichain;
14240 {
14241 #if defined(VMS) || defined(UNDERSC)
14242 	getcdh(ires,ichain,
14243 #else
14244 #ifdef CRAY
14245 	GETCDH(ires,ichain,
14246 #else
14247 	getcdh_(ires,ichain,
14248 #endif
14249 #endif
14250 	calfptr->ianf,calfptr->islu,&calfptr->nchain);
14251 }
14252 
14253 #if defined(VMS) || defined(UNDERSC)
ribbs()14254 void ribbs()
14255 #else
14256 #ifdef CRAY
14257 void RIBBS()
14258 #else
14259 void ribbs_()
14260 #endif
14261 #endif
14262 {
14263 #if defined(VMS) || defined(UNDERSC)
14264 	ribbd(
14265 #else
14266 #ifdef CRAY
14267 	RIBBD(
14268 #else
14269 	ribbd_(
14270 #endif
14271 #endif
14272 	&calfptr->issdon);
14273 }
14274 
14275 #if defined(VMS) || defined(UNDERSC)
ribbon(iscnd,dogl,nr,iungl,ipart,ist,ichain)14276 void ribbon(iscnd,dogl,nr,iungl,ipart,ist,ichain)
14277 #else
14278 #ifdef CRAY
14279 void RIBBON(iscnd,dogl,nr,iungl,ipart,ist,ichain)
14280 #else
14281 void ribbon_(iscnd,dogl,nr,iungl,ipart,ist,ichain)
14282 #endif
14283 #endif
14284 int *iscnd;
14285 int *dogl;
14286 int *nr;
14287 int *iungl;
14288 int *ipart;
14289 int *ist;
14290 int *ichain;
14291 {
14292  int istat;
14293 
14294 #if defined(VMS) || defined(UNDERSC)
14295 	ribbod(&istat,iscnd,dogl,nr,iungl,ipart,ist,ichain,rotptr->t,
14296 #else
14297 #ifdef CRAY
14298 	RIBBOD(&istat,iscnd,dogl,nr,iungl,ipart,ist,ichain,rotptr->t,
14299 #else
14300 	ribbod_(&istat,iscnd,dogl,nr,iungl,ipart,ist,ichain,rotptr->t,
14301 #endif
14302 #endif
14303 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,
14304 	xyzp->iconn,
14305 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14306 	&calfptr->nchain,calfptr->iamino,calfptr->isal,&calfptr->ihashb);
14307 
14308 	if (!istat) {
14309 #if defined(VMS) || defined(UNDERSC)
14310 	   allcoo(&addat,&ZERO);
14311 	   ribbod(&istat,iscnd,dogl,nr,iungl,ipart,ist,ichain,rotptr->t,
14312 #else
14313 #ifdef CRAY
14314 	   ALLCOO(&addat,&ZERO);
14315 	   RIBBOD(&istat,iscnd,dogl,nr,iungl,ipart,ist,ichain,rotptr->t,
14316 #else
14317 	   allcoo_(&addat,&ZERO);
14318 	   ribbod_(&istat,iscnd,dogl,nr,iungl,ipart,ist,ichain,rotptr->t,
14319 #endif
14320 #endif
14321 	   xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,
14322 	   xyzp->iconn,
14323 	   calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14324 	   &calfptr->nchain,calfptr->iamino,calfptr->isal,&calfptr->ihashb);
14325         }
14326 }
14327 
14328 #if defined(VMS) || defined(UNDERSC)
prnts()14329 void prnts()
14330 #else
14331 #ifdef CRAY
14332 void PRNTS()
14333 #else
14334 void prnts_()
14335 #endif
14336 #endif
14337 {
14338 
14339 #if defined(VMS) || defined(UNDERSC)
14340 	prntd(
14341 #else
14342 #ifdef CRAY
14343 	PRNTD(
14344 #else
14345 	prntd_(
14346 #endif
14347 #endif
14348 	xyzp->iaton);
14349 
14350 }
14351 #if defined(VMS) || defined(UNDERSC)
proxim(itarg,thresh,ikleur,idosrf)14352 void proxim(itarg,thresh,ikleur,idosrf)
14353 #else
14354 #ifdef CRAY
14355 void PROXIM(itarg,thresh,ikleur,idosrf)
14356 #else
14357 void proxim_(itarg,thresh,ikleur,idosrf)
14358 #endif
14359 #endif
14360 int *itarg;
14361 double *thresh;
14362 int *ikleur;
14363 int *idosrf;
14364 {
14365 
14366 #if defined(VMS) || defined(UNDERSC)
14367 	proxid(itarg,thresh,ikleur,idosrf,
14368 #else
14369 #ifdef CRAY
14370 	PROXID(itarg,thresh,ikleur,idosrf,
14371 #else
14372 	proxid_(itarg,thresh,ikleur,idosrf,
14373 #endif
14374 #endif
14375 	xyzp->coo,xyzp->iresid,&calfptr->ishoh);
14376 
14377 }
14378 
14379 #if defined(VMS) || defined(UNDERSC)
proxic(itarg,backb,adds,idocom,thresh)14380 void proxic(itarg,backb,adds,idocom,thresh)
14381 #else
14382 #ifdef CRAY
14383 void PROXIC(itarg,backb,adds,idocom,thresh)
14384 #else
14385 void proxic_(itarg,backb,adds,idocom,thresh)
14386 #endif
14387 #endif
14388 int *itarg;
14389 int *backb;
14390 int *adds;
14391 int *idocom;
14392 double *thresh;
14393 {
14394 
14395 #if defined(VMS) || defined(UNDERSC)
14396 	proxd(itarg,backb,adds,idocom,thresh,
14397 #else
14398 #ifdef CRAY
14399 	PROXD(itarg,backb,adds,idocom,thresh,
14400 #else
14401 	proxd_(itarg,backb,adds,idocom,thresh,
14402 #endif
14403 #endif
14404 	xyzp->coo,xyzp->iresid,xyzp->iaton,xyzp->iconn,
14405 	calfptr->iams,&calfptr->ishoh);
14406 
14407 }
14408 
14409 #if defined(VMS) || defined(UNDERSC)
setchn(iopt)14410 void setchn(iopt)
14411 #else
14412 #ifdef CRAY
14413 void SETCHN(iopt)
14414 #else
14415 void setchn_(iopt)
14416 #endif
14417 #endif
14418 int *iopt;
14419 {
14420 
14421 #if defined(VMS) || defined(UNDERSC)
14422 	setcdd(iopt,
14423 #else
14424 #ifdef CRAY
14425 	SETCDD(iopt,
14426 #else
14427 	setcdd_(iopt,
14428 #endif
14429 #endif
14430 	&calfptr->nchain,calfptr->ianf,calfptr->islu,calfptr->irsnr,
14431 	calfptr->achain);
14432 
14433 }
14434 
14435 #if defined(VMS) || defined(UNDERSC)
rdchx(idebug,iop,istdbd,useab,moddma,istat,icssr)14436 void rdchx(idebug,iop,istdbd,useab,moddma,istat,icssr)
14437 #else
14438 #ifdef CRAY
14439 void RDCHX(idebug,iop,istdbd,useab,moddma,istat,icssr)
14440 #else
14441 void rdchx_(idebug,iop,istdbd,useab,moddma,istat,icssr)
14442 #endif
14443 #endif
14444 int *idebug;
14445 int *iop;
14446 int *istdbd;
14447 int *useab;
14448 int *moddma;
14449 int *istat;
14450 int *icssr;
14451 {
14452 
14453 #if defined(VMS) || defined(UNDERSC)
14454 	rdchd(idebug,iop,istdbd,useab,moddma,istat,icssr,
14455 #else
14456 #ifdef CRAY
14457 	RDCHD(idebug,iop,istdbd,useab,moddma,istat,icssr,
14458 #else
14459 	rdchd_(idebug,iop,istdbd,useab,moddma,istat,icssr,
14460 #endif
14461 #endif
14462 	xyzp->coo,xyzp->iconn,xyzp->ianz,xyzp->iatclr,xyzp->ityp,xyzp->qat,
14463 	&cell->natc,&cell->icent,&cell->inorm,&cell->ncon,&cell->nspg,
14464 	&cell->kz,&cell->ichx,&cell->icrtp,&cell->nopr,cell->ir,cell->it,
14465 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
14466 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
14467 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14468 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14469 
14470 }
14471 
14472 #if defined(VMS) || defined(UNDERSC)
rfbio(idebug,ifrst,istat)14473 void rfbio(idebug,ifrst,istat)
14474 #else
14475 #ifdef CRAY
14476 void RFBIO(idebug,ifrst,istat)
14477 #else
14478 void rfbio_(idebug,ifrst,istat)
14479 #endif
14480 #endif
14481 int *idebug;
14482 int *ifrst;
14483 int *istat;
14484 {
14485 
14486 #if defined(VMS) || defined(UNDERSC)
14487 	rfbid(idebug,ifrst,istat,
14488 #else
14489 #ifdef CRAY
14490 	RFBID(idebug,ifrst,istat,
14491 #else
14492 	rfbid_(idebug,ifrst,istat,
14493 #endif
14494 #endif
14495 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
14496 	&cell->natc,&cell->norg,&cell->icent,&cell->inorm,&cell->ncon,
14497 	&cell->nspg,&cell->kz,&cell->nopr,cell->ir,cell->it,
14498 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
14499 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
14500 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14501 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14502 
14503 }
14504 
14505 #if defined(VMS) || defined(UNDERSC)
getxdt(ipnt,nat,istat)14506 void getxdt(ipnt,nat,istat)
14507 #else
14508 #ifdef CRAY
14509 void GETXDT(ipnt,nat,istat)
14510 #else
14511 void getxdt_(ipnt,nat,istat)
14512 #endif
14513 #endif
14514 int *ipnt;
14515 int *nat;
14516 int *istat;
14517 {
14518 
14519 #if defined(VMS) || defined(UNDERSC)
14520 	getxdd(ipnt,nat,istat,
14521 #else
14522 #ifdef CRAY
14523 	GETXDD(ipnt,nat,istat,
14524 #else
14525 	getxdd_(ipnt,nat,istat,
14526 #endif
14527 #endif
14528 	xyzp->coo);
14529 
14530 }
14531 
14532 #if defined(VMS) || defined(UNDERSC)
rfdat(idebug,istat,refcod)14533 void rfdat(idebug,istat,refcod)
14534 #else
14535 #ifdef CRAY
14536 void RFDAT(idebug,istat,refcod)
14537 #else
14538 void rfdat_(idebug,istat,refcod)
14539 #endif
14540 #endif
14541 int *idebug;
14542 int *istat;
14543 int *refcod;
14544 {
14545 
14546 #if defined(VMS) || defined(UNDERSC)
14547 	rfdad(idebug,istat,refcod,
14548 #else
14549 #ifdef CRAY
14550 	RFDAD(idebug,istat,refcod,
14551 #else
14552 	rfdad_(idebug,istat,refcod,
14553 #endif
14554 #endif
14555 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
14556 	&cell->natc,&cell->norg,&cell->icent,&cell->inorm,
14557 	&cell->ncon,&cell->nspg,&cell->kz,
14558 	&cell->nopr,cell->ir,cell->it,
14559 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
14560 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
14561 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14562 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14563 
14564 }
14565 
14566 #if defined(VMS) || defined(UNDERSC)
fdat(iop,ifrst,istdbd,useab,moddma,idebug)14567 void fdat(iop,ifrst,istdbd,useab,moddma,idebug)
14568 #else
14569 #ifdef CRAY
14570 void FDAT(iop,ifrst,istdbd,useab,moddma,idebug)
14571 #else
14572 void fdat_(iop,ifrst,istdbd,useab,moddma,idebug)
14573 #endif
14574 #endif
14575 int *iop;
14576 int *ifrst;
14577 int *istdbd;
14578 int *useab;
14579 int *moddma;
14580 int *idebug;
14581 {
14582 
14583 #if defined(VMS) || defined(UNDERSC)
14584 	fdad(iop,ifrst,istdbd,useab,moddma,idebug,
14585 #else
14586 #ifdef CRAY
14587 	FDAD(iop,ifrst,istdbd,useab,moddma,idebug,
14588 #else
14589 	fdad_(iop,ifrst,istdbd,useab,moddma,idebug,
14590 #endif
14591 #endif
14592 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,
14593 	xyzp->iconn,xyzp->lwrit,xyzp->lring,xyzp->ityp,
14594 	&scalptr->scal,&scalptr->scali,&scalptr->smag,
14595 	&cell->natc,&cell->norg,&cell->icent,&cell->inorm,
14596 	&cell->ncon,&cell->nspg,
14597 	&cell->nopr,cell->ir,cell->it,
14598 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
14599 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
14600 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2]);
14601 
14602 }
14603 
14604 #if defined(VMS) || defined(UNDERSC)
delat(iat,iacn,iorg,mxdma)14605 void delat(iat,iacn,iorg,mxdma)
14606 #else
14607 #ifdef CRAY
14608 void DELAT(iat,iacn,iorg,mxdma)
14609 #else
14610 void delat_(iat,iacn,iorg,mxdma)
14611 #endif
14612 #endif
14613 int *iat;
14614 int *iacn;
14615 int *iorg;
14616 int *mxdma;
14617 {
14618 
14619 #if defined(VMS) || defined(UNDERSC)
14620 	delad(iat,iacn,iorg,mxdma,
14621 #else
14622 #ifdef CRAY
14623 	DELAD(iat,iacn,iorg,mxdma,
14624 #else
14625 	delad_(iat,iacn,iorg,mxdma,
14626 #endif
14627 #endif
14628 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->qat,xyzp->ityp);
14629 
14630 }
14631 
14632 #if defined(VMS) || defined(UNDERSC)
polh(nat,ipolh,iatom)14633 void polh(nat,ipolh,iatom)
14634 #else
14635 #ifdef CRAY
14636 void POLH(nat,ipolh,iatom)
14637 #else
14638 void polh_(nat,ipolh,iatom)
14639 #endif
14640 #endif
14641 int *ipolh;
14642 int *iatom;
14643 int *nat;
14644 {
14645 
14646 #if defined(VMS) || defined(UNDERSC)
14647 	pold(nat,ipolh,iatom,
14648 #else
14649 #ifdef CRAY
14650 	POLD(nat,ipolh,iatom,
14651 #else
14652 	pold_(nat,ipolh,iatom,
14653 #endif
14654 #endif
14655 	xyzp->ianz,xyzp->iconn);
14656 
14657 }
14658 
14659 #if defined(VMS) || defined(UNDERSC)
ifnn(ifnn,noff,ia1,ia2)14660 void ifnn(ifnn,noff,ia1,ia2)
14661 #else
14662 #ifdef CRAY
14663 void IFNN(ifnn,noff,ia1,ia2)
14664 #else
14665 void ifnn_(ifnn,noff,ia1,ia2)
14666 #endif
14667 #endif
14668 int *ifnn;
14669 int *noff;
14670 int *ia1;
14671 int *ia2;
14672 {
14673 
14674 #if defined(VMS) || defined(UNDERSC)
14675 	ifnd(ifnn,noff,ia1,ia2,
14676 #else
14677 #ifdef CRAY
14678 	IFND(ifnn,noff,ia1,ia2,
14679 #else
14680 	ifnd_(ifnn,noff,ia1,ia2,
14681 #endif
14682 #endif
14683 	xyzp->iconn);
14684 
14685 }
14686 
14687 #if defined(VMS) || defined(UNDERSC)
rdgro(idebug,istat)14688 void rdgro(idebug,istat)
14689 #else
14690 #ifdef CRAY
14691 void RDGRO(idebug,istat)
14692 #else
14693 void rdgro_(idebug,istat)
14694 #endif
14695 #endif
14696 int *idebug;
14697 int *istat;
14698 {
14699 
14700 #if defined(VMS) || defined(UNDERSC)
14701 	rdgrod(idebug,istat,
14702 #else
14703 #ifdef CRAY
14704 	RDGROD(idebug,istat,
14705 #else
14706 	rdgrod_(idebug,istat,
14707 #endif
14708 #endif
14709 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
14710 	xyzp->ityp,xyzp->ipdbt,
14711 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14712 	&calfptr->nchain,calfptr->iamino,calfptr->reson,
14713 	calfptr->isal,calfptr->irsnr,&calfptr->ishoh);
14714 
14715 	if (*istat == -1) {
14716            hetptr.NHetAtm = 0;
14717 #if defined(VMS) || defined(UNDERSC)
14718 	   allcoo(&addat,&ZERO);
14719 	   rdgrod(idebug,istat,
14720 #else
14721 #ifdef CRAY
14722 	   ALLCOO(&addat,&ZERO);
14723 	   RDGROD(idebug,istat,
14724 #else
14725 	   allcoo_(&addat,&ZERO);
14726 	   rdgrod_(idebug,istat,
14727 #endif
14728 #endif
14729 	   xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
14730 	   xyzp->ityp,xyzp->ipdbt,
14731 	   calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14732 	   &calfptr->nchain,calfptr->iamino,calfptr->reson,
14733 	   calfptr->isal,calfptr->irsnr,&calfptr->ishoh);
14734         }
14735 }
14736 
14737 #if defined(VMS) || defined(UNDERSC)
addbox(v1,v2,v3)14738 void addbox(v1,v2,v3)
14739 #else
14740 #ifdef CRAY
14741 void ADDBOX(v1,v2,v3)
14742 #else
14743 void addbox_(v1,v2,v3)
14744 #endif
14745 #endif
14746 double *v1;
14747 double *v2;
14748 double *v3;
14749 {
14750 
14751 #if defined(VMS) || defined(UNDERSC)
14752 	addbod(v1,v2,v3,
14753 #else
14754 #ifdef CRAY
14755 	ADDBOD(v1,v2,v3,
14756 #else
14757 	addbod_(v1,v2,v3,
14758 #endif
14759 #endif
14760 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn);
14761 
14762 }
14763 
14764 #if defined(VMS) || defined(UNDERSC)
addtbx(v1,v2,v3)14765 void addtbx(v1,v2,v3)
14766 #else
14767 #ifdef CRAY
14768 void ADDTBX(v1,v2,v3)
14769 #else
14770 void addtbx_(v1,v2,v3)
14771 #endif
14772 #endif
14773 double *v1;
14774 double *v2;
14775 double *v3;
14776 {
14777 
14778 #if defined(VMS) || defined(UNDERSC)
14779 	addtbd(v1,v2,v3,
14780 #else
14781 #ifdef CRAY
14782 	ADDTBD(v1,v2,v3,
14783 #else
14784 	addtbd_(v1,v2,v3,
14785 #endif
14786 #endif
14787 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,xyzp->iaton,xyzp->iresid);
14788 
14789 }
14790 
14791 #if defined(VMS) || defined(UNDERSC)
gropt(ipnt)14792 void gropt(ipnt)
14793 #else
14794 #ifdef CRAY
14795 void GROPT(ipnt)
14796 #else
14797 void gropt_(ipnt)
14798 #endif
14799 #endif
14800 int *ipnt;
14801 {
14802 
14803 #if defined(VMS) || defined(UNDERSC)
14804 	gropd(ipnt,
14805 #else
14806 #ifdef CRAY
14807 	GROPD(ipnt,
14808 #else
14809 	gropd_(ipnt,
14810 #endif
14811 #endif
14812 	xyzp->coo);
14813 
14814 }
14815 
14816 #if defined(VMS) || defined(UNDERSC)
rdmol(idebug,ipdbon,ioadd,istat)14817 void rdmol(idebug,ipdbon,ioadd,istat)
14818 #else
14819 #ifdef CRAY
14820 void RDMOL(idebug,ipdbon,ioadd,istat)
14821 #else
14822 void rdmol_(idebug,ipdbon,ioadd,istat)
14823 #endif
14824 #endif
14825 int *idebug;
14826 int *ipdbon;
14827 int *ioadd;
14828 int *istat;
14829 {
14830 
14831 #if defined(VMS) || defined(UNDERSC)
14832 	rdmod(idebug,ipdbon,ioadd,istat,
14833 #else
14834 #ifdef CRAY
14835 	RDMOD(idebug,ipdbon,ioadd,istat,
14836 #else
14837 	rdmod_(idebug,ipdbon,ioadd,istat,
14838 #endif
14839 #endif
14840 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
14841 	xyzp->ityp,xyzp->ipdbt,
14842 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14843 	&calfptr->nchain,calfptr->iamino,calfptr->reson,
14844 	calfptr->isal,&calfptr->ishoh,&calfptr->ihashb,
14845 	&cell->natc,&cell->norg,&cell->icent,&cell->ncon,&cell->nspg,
14846 	&cell->kz,&cell->ichx,&cell->nopr,cell->ir,cell->it,
14847 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
14848 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
14849 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14850 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14851 
14852 	if (*istat == -1) {
14853 #if defined(VMS) || defined(UNDERSC)
14854 	   allcoo(&addat,&ZERO);
14855 	   rdmod(idebug,ipdbon,ioadd,istat,
14856 #else
14857 #ifdef CRAY
14858 	   ALLCOO(&addat,&ZERO);
14859 	   RDMOD(idebug,ipdbon,ioadd,istat,
14860 #else
14861 	   allcoo_(&addat,&ZERO);
14862 	   rdmod_(idebug,ipdbon,ioadd,istat,
14863 #endif
14864 #endif
14865 	   xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
14866    	   xyzp->ityp,xyzp->ipdbt,
14867 	   calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
14868    	   &calfptr->nchain,calfptr->iamino,calfptr->reson,
14869 	   calfptr->isal,&calfptr->ishoh,&calfptr->ihashb,
14870 	   &cell->natc,&cell->norg,&cell->icent,&cell->ncon,&cell->nspg,
14871 	   &cell->kz,&cell->ichx,&cell->nopr,cell->ir,cell->it,
14872 	   &cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
14873 	   &cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
14874 	   &cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14875 	   &cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14876         }
14877 }
14878 
14879 #if defined(VMS) || defined(UNDERSC)
wrmol(iun)14880 void wrmol(iun)
14881 #else
14882 #ifdef CRAY
14883 void WRMOL(iun)
14884 #else
14885 void wrmol_(iun)
14886 #endif
14887 #endif
14888 int *iun;
14889 {
14890 
14891 #if defined(VMS) || defined(UNDERSC)
14892 	wrmod(iun,
14893 #else
14894 #ifdef CRAY
14895 	WRMOD(iun,
14896 #else
14897 	wrmod_(iun,
14898 #endif
14899 #endif
14900 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iconn,
14901 	xyzp->iresid,xyzp->lring,xyzp->inat,xyzp->ityp,xyzp->ipdbt,
14902 	calfptr->icalf,&calfptr->ncalf,calfptr->iamino,&calfptr->ishoh,
14903 	&cell->natc,&cell->nspg,&cell->ichx,
14904 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14905 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14906 
14907 }
14908 
14909 #if defined(VMS) || defined(UNDERSC)
ispn(ispn,iat,irng,idochg,ifive)14910 void ispn(ispn,iat,irng,idochg,ifive)
14911 #else
14912 #ifdef CRAY
14913 void ISPN(ispn,iat,irng,idochg,ifive)
14914 #else
14915 void ispn_(ispn,iat,irng,idochg,ifive)
14916 #endif
14917 #endif
14918 int *ispn;
14919 int *iat;
14920 int *irng;
14921 int *idochg;
14922 int *ifive;
14923 {
14924 
14925 #if defined(VMS) || defined(UNDERSC)
14926 	ispnd(ispn,iat,irng,idochg,ifive,
14927 #else
14928 #ifdef CRAY
14929 	ISPND(ispn,iat,irng,idochg,ifive,
14930 #else
14931 	ispnd_(ispn,iat,irng,idochg,ifive,
14932 #endif
14933 #endif
14934 	xyzp->qat,xyzp->ianz,xyzp->iaton,xyzp->iconn,xyzp->lwrit,xyzp->lring);
14935 
14936 }
14937 
14938 #if defined(VMS) || defined(UNDERSC)
wrcrys(iun)14939 void wrcrys(iun)
14940 #else
14941 #ifdef CRAY
14942 void WRCRYS(iun)
14943 #else
14944 void wrcrys_(iun)
14945 #endif
14946 #endif
14947 int *iun;
14948 {
14949 
14950 #if defined(VMS) || defined(UNDERSC)
14951 	wrcryd(iun,
14952 #else
14953 #ifdef CRAY
14954 	WRCRYD(iun,
14955 #else
14956 	wrcryd_(iun,
14957 #endif
14958 #endif
14959 	xyzp->ianz,xyzp->coo,
14960 	&cell->natc,&cell->nspg,&cell->ichx,
14961 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14962 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14963 
14964 }
14965 
14966 #if defined(VMS) || defined(UNDERSC)
rdshlx(idebug,istat)14967 void rdshlx(idebug,istat)
14968 #else
14969 #ifdef CRAY
14970 void RDSHLX(idebug,istat)
14971 #else
14972 void rdshlx_(idebug,istat)
14973 #endif
14974 #endif
14975 int *idebug;
14976 int *istat;
14977 {
14978 
14979 #if defined(VMS) || defined(UNDERSC)
14980 	rdshld(idebug,istat,
14981 #else
14982 #ifdef CRAY
14983 	RDSHLD(idebug,istat,
14984 #else
14985 	rdshld_(idebug,istat,
14986 #endif
14987 #endif
14988 	xyzp->coo,xyzp->ianz,xyzp->iconn,xyzp->iatclr,
14989 	&cell->natc,&cell->icent,&cell->ncon,&cell->nspg,
14990 	&cell->kz,&cell->nopr,cell->ir,cell->it,
14991 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
14992 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
14993 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
14994 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
14995 
14996 }
14997 
14998 #if defined(VMS) || defined(UNDERSC)
rdcif(idebug,istat)14999 void rdcif(idebug,istat)
15000 #else
15001 #ifdef CRAY
15002 void RDCIF(idebug,istat)
15003 #else
15004 void rdcif_(idebug,istat)
15005 #endif
15006 #endif
15007 int *idebug;
15008 int *istat;
15009 {
15010 
15011 #if defined(VMS) || defined(UNDERSC)
15012 	rdcifd(idebug,istat,
15013 #else
15014 #ifdef CRAY
15015 	RDCIFD(idebug,istat,
15016 #else
15017 	rdcifd_(idebug,istat,
15018 #endif
15019 #endif
15020 	xyzp->coo,xyzp->ianz,xyzp->iconn,xyzp->iatclr,
15021 	&cell->natc,&cell->icent,&cell->ncon,&cell->nspg,
15022 	&cell->nopr,cell->ir,cell->it,
15023 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15024 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
15025 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15026 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15027 
15028 }
15029 
15030 #if defined(VMS) || defined(UNDERSC)
wrshlx(iun,idospf)15031 void wrshlx(iun,idospf)
15032 #else
15033 #ifdef CRAY
15034 void WRSHLX(iun,idospf)
15035 #else
15036 void wrshlx_(iun,idospf)
15037 #endif
15038 #endif
15039 int *iun;
15040 int *idospf;
15041 {
15042 
15043 #if defined(VMS) || defined(UNDERSC)
15044 	wrshld(iun,idospf,
15045 #else
15046 #ifdef CRAY
15047 	WRSHLD(iun,idospf,
15048 #else
15049 	wrshld_(iun,idospf,
15050 #endif
15051 #endif
15052 	xyzp->coo,xyzp->ianz,
15053 	&cell->natc,&cell->icent,&cell->nspg,
15054 	&cell->kz,&cell->ichx,&cell->nopr,cell->ir,cell->it,
15055 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15056 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15057 
15058 }
15059 
15060 #if defined(VMS) || defined(UNDERSC)
wrcif(iun)15061 void wrcif(iun)
15062 #else
15063 #ifdef CRAY
15064 void WRCIF(iun)
15065 #else
15066 void wrcif_(iun)
15067 #endif
15068 #endif
15069 int *iun;
15070 {
15071 
15072 #if defined(VMS) || defined(UNDERSC)
15073 	wrcifd(iun,
15074 #else
15075 #ifdef CRAY
15076 	WRCIFD(iun,
15077 #else
15078 	wrcifd_(iun,
15079 #endif
15080 #endif
15081 	xyzp->coo,xyzp->ianz,
15082 	&cell->natc,&cell->nspg,&cell->ichx,
15083 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15084 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15085 
15086 }
15087 
15088 #if defined(VMS) || defined(UNDERSC)
cllrot(vec,irot,ifd)15089 void cllrot(vec,irot,ifd)
15090 #else
15091 #ifdef CRAY
15092 void CLLROT(vec,irot,ifd)
15093 #else
15094 void cllrot_(vec,irot,ifd)
15095 #endif
15096 #endif
15097 double *vec;
15098 int *irot;
15099 int *ifd;
15100 {
15101 
15102 #if defined(VMS) || defined(UNDERSC)
15103 	cllrod(vec,irot,ifd,
15104 #else
15105 #ifdef CRAY
15106 	CLLROD(vec,irot,ifd,
15107 #else
15108 	cllrod_(vec,irot,ifd,
15109 #endif
15110 #endif
15111 	xyzp->coo,xyzp->ianz,
15112 	&cell->natc,
15113 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15114 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5]);
15115 
15116 }
15117 
15118 #if defined(VMS) || defined(UNDERSC)
zm2fr(cm,ctmp,imkeep)15119 void zm2fr(cm,ctmp,imkeep)
15120 #else
15121 #ifdef CRAY
15122 void ZM2FR(cm,ctmp,imkeep)
15123 #else
15124 void zm2fr_(cm,ctmp,imkeep)
15125 #endif
15126 #endif
15127 double *cm;
15128 double *ctmp;
15129 int *imkeep;
15130 {
15131 
15132 #if defined(VMS) || defined(UNDERSC)
15133 	zm2fd(cm,ctmp,imkeep,
15134 #else
15135 #ifdef CRAY
15136 	ZM2FD(cm,ctmp,imkeep,
15137 #else
15138 	zm2fd_(cm,ctmp,imkeep,
15139 #endif
15140 #endif
15141 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
15142 	&cell->natc,&cell->ichx,
15143 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15144 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5]);
15145 
15146 }
15147 
15148 #if defined(VMS) || defined(UNDERSC)
wrchx(iun)15149 void wrchx(iun)
15150 #else
15151 #ifdef CRAY
15152 void WRCHX(iun)
15153 #else
15154 void wrchx_(iun)
15155 #endif
15156 #endif
15157 int *iun;
15158 {
15159 
15160 #if defined(VMS) || defined(UNDERSC)
15161 	wrchd(iun,
15162 #else
15163 #ifdef CRAY
15164 	WRCHD(iun,
15165 #else
15166 	wrchd_(iun,
15167 #endif
15168 #endif
15169 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,xyzp->qat,xyzp->ityp,
15170 	&cell->natc,&cell->inorm,&cell->nspg,&cell->ichx,
15171 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15172 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15173 
15174 }
15175 
15176 #if defined(VMS) || defined(UNDERSC)
rdmsi(idebug,istat)15177 void rdmsi(idebug,istat)
15178 #else
15179 #ifdef CRAY
15180 void RDMSI(idebug,istat)
15181 #else
15182 void rdmsi_(idebug,istat)
15183 #endif
15184 #endif
15185 int *idebug;
15186 int *istat;
15187 {
15188 
15189 #if defined(VMS) || defined(UNDERSC)
15190 	rdmsd(idebug,istat,
15191 #else
15192 #ifdef CRAY
15193 	RDMSD(idebug,istat,
15194 #else
15195 	rdmsd_(idebug,istat,
15196 #endif
15197 #endif
15198 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,xyzp->qat,
15199 	&cell->natc,&cell->icent,&cell->ncon,&cell->nspg,
15200 	&cell->ichx,&cell->nopr,cell->ir,cell->it,
15201 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15202 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
15203 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15204 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15205 
15206 }
15207 
15208 #if defined(VMS) || defined(UNDERSC)
wrmsi(iun)15209 void wrmsi(iun)
15210 #else
15211 #ifdef CRAY
15212 void WRMSI(iun)
15213 #else
15214 void wrmsi_(iun)
15215 #endif
15216 #endif
15217 int *iun;
15218 {
15219 
15220 #if defined(VMS) || defined(UNDERSC)
15221 	wrmsd(iun,
15222 #else
15223 #ifdef CRAY
15224 	WRMSD(iun,
15225 #else
15226 	wrmsd_(iun,
15227 #endif
15228 #endif
15229 	xyzp->coo,xyzp->ianz,xyzp->iconn,xyzp->qat,
15230 	&cell->natc,&cell->nspg,&cell->ichx,
15231 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15232 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5]);
15233 
15234 }
15235 
15236 #if defined(VMS) || defined(UNDERSC)
rdcpmolu(istats)15237 void rdcpmolu(istats)
15238 #else
15239 #ifdef CRAY
15240 void RDCPMOLU(istats)
15241 #else
15242 void rdcpmolu_(istats)
15243 #endif
15244 #endif
15245 int *istats;
15246 {
15247 
15248 #if defined(VMS) || defined(UNDERSC)
15249 	rdcpmold(istats,
15250 #else
15251 #ifdef CRAY
15252 	RDCPMOLD(istats,
15253 #else
15254 	rdcpmold_(istats,
15255 #endif
15256 #endif
15257 	xyzp->coo,xyzp->ianz);
15258 
15259 }
15260 
15261 #if defined(VMS) || defined(UNDERSC)
cpmdpt(ipnt,istat)15262 void cpmdpt(ipnt,istat)
15263 #else
15264 #ifdef CRAY
15265 void CPMDPT(ipnt,istat)
15266 #else
15267 void cpmdpt_(ipnt,istat)
15268 #endif
15269 #endif
15270 int *ipnt;
15271 int *istat;
15272 {
15273 
15274 #if defined(VMS) || defined(UNDERSC)
15275 	cpmdpd(ipnt,istat,
15276 #else
15277 #ifdef CRAY
15278 	CPMDPD(ipnt,istat,
15279 #else
15280 	cpmdpd_(ipnt,istat,
15281 #endif
15282 #endif
15283 	xyzp->coo,xyzp->ianz);
15284 
15285 }
15286 
15287 #if defined(VMS) || defined(UNDERSC)
cpmdgetfr(istat)15288 void cpmdgetfr(istat)
15289 #else
15290 #ifdef CRAY
15291 void CPMDGETFR(istat)
15292 #else
15293 void cpmdgetfr_(istat)
15294 #endif
15295 #endif
15296 int *istat;
15297 {
15298 
15299 #if defined(VMS) || defined(UNDERSC)
15300 	cpmdgetfd(istat,
15301 #else
15302 #ifdef CRAY
15303 	CPMDGETFD(istat,
15304 #else
15305 	cpmdgetfd_(istat,
15306 #endif
15307 #endif
15308 	xyzp->coo);
15309 
15310 }
15311 
15312 #if defined(VMS) || defined(UNDERSC)
cpmdptdyn(ipnt,istat)15313 void cpmdptdyn(ipnt,istat)
15314 #else
15315 #ifdef CRAY
15316 void CPMDPTDYN(ipnt,istat)
15317 #else
15318 void cpmdptdyn_(ipnt,istat)
15319 #endif
15320 #endif
15321 int *ipnt;
15322 int *istat;
15323 {
15324 
15325 #if defined(VMS) || defined(UNDERSC)
15326 	cpmdptdyd(ipnt,istat,
15327 #else
15328 #ifdef CRAY
15329 	CPMDPTDYD(ipnt,istat,
15330 #else
15331 	cpmdptdyd_(ipnt,istat,
15332 #endif
15333 #endif
15334 	xyzp->coo);
15335 
15336 }
15337 
15338 #if defined(VMS) || defined(UNDERSC)
wrcpmd(iun)15339 void wrcpmd(iun)
15340 #else
15341 #ifdef CRAY
15342 void WRCPMD(iun)
15343 #else
15344 void wrcpmd_(iun)
15345 #endif
15346 #endif
15347 int *iun;
15348 {
15349 
15350 #if defined(VMS) || defined(UNDERSC)
15351 	wrcpdd(iun,
15352 #else
15353 #ifdef CRAY
15354 	WRCPDD(iun,
15355 #else
15356 	wrcpdd_(iun,
15357 #endif
15358 #endif
15359 	xyzp->ianz,xyzp->coo,&cell->natc,&cell->ichx,
15360         &cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15361         &cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15362 
15363 }
15364 
15365 #if defined(VMS) || defined(UNDERSC)
cpmdcell()15366 void cpmdcell()
15367 #else
15368 #ifdef CRAY
15369 void CPMDCELL()
15370 #else
15371 void cpmdcell_()
15372 #endif
15373 #endif
15374 {
15375 
15376 #if defined(VMS) || defined(UNDERSC)
15377 	cpmdceld(
15378 #else
15379 #ifdef CRAY
15380 	CPMDCELD(
15381 #else
15382 	cpmdceld_(
15383 #endif
15384 #endif
15385 	&cell->nspg,
15386 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15387 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
15388 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15389 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15390 
15391 }
15392 
15393 #if defined(VMS) || defined(UNDERSC)
rdmolu(sline,iemlin,idocoo,idobohr,istats)15394 void rdmolu(sline,iemlin,idocoo,idobohr,istats)
15395 #else
15396 #ifdef CRAY
15397 void RDMOLU(sline,iemlin,idocoo,idobohr,istats)
15398 #else
15399 void rdmolu_(sline,iemlin,idocoo,idobohr,istats)
15400 #endif
15401 #endif
15402 int *sline;
15403 int *iemlin;
15404 int *idocoo;
15405 int *idobohr;
15406 int *istats;
15407 {
15408 
15409 #if defined(VMS) || defined(UNDERSC)
15410 	rdmodu(sline,iemlin,idocoo,idobohr,istats,
15411 #else
15412 #ifdef CRAY
15413 	RDMODU(sline,iemlin,idocoo,idobohr,istats,
15414 #else
15415 	rdmodu_(sline,iemlin,idocoo,idobohr,istats,
15416 #endif
15417 #endif
15418 	xyzp->coo,xyzp->ianz);
15419 
15420 }
15421 
15422 #if defined(VMS) || defined(UNDERSC)
gamupt(ipnt,istat)15423 void gamupt(ipnt,istat)
15424 #else
15425 #ifdef CRAY
15426 void GAMUPT(ipnt,istat)
15427 #else
15428 void gamupt_(ipnt,istat)
15429 #endif
15430 #endif
15431 int *ipnt;
15432 int *istat;
15433 {
15434 
15435 #if defined(VMS) || defined(UNDERSC)
15436 	gamupd(ipnt,istat,
15437 #else
15438 #ifdef CRAY
15439 	GAMUPD(ipnt,istat,
15440 #else
15441 	gamupd_(ipnt,istat,
15442 #endif
15443 #endif
15444 	xyzp->coo,xyzp->ianz);
15445 
15446 }
15447 
15448 #if defined(VMS) || defined(UNDERSC)
ugetfr(istat)15449 void ugetfr(istat)
15450 #else
15451 #ifdef CRAY
15452 void UGETFR(istat)
15453 #else
15454 void ugetfr_(istat)
15455 #endif
15456 #endif
15457 int *istat;
15458 {
15459 
15460 #if defined(VMS) || defined(UNDERSC)
15461 	ugetfd(istat,
15462 #else
15463 #ifdef CRAY
15464 	ugetfd(istat,
15465 #else
15466 	ugetfd_(istat,
15467 #endif
15468 #endif
15469 	xyzp->coo);
15470 
15471 }
15472 
15473 #if defined(VMS) || defined(UNDERSC)
wrvasp(iun)15474 void wrvasp(iun)
15475 #else
15476 #ifdef CRAY
15477 void WRVASP(iun)
15478 #else
15479 void wrvasp_(iun)
15480 #endif
15481 #endif
15482 int *iun;
15483 {
15484 
15485 #if defined(VMS) || defined(UNDERSC)
15486 	wrvasd(iun,
15487 #else
15488 #ifdef CRAY
15489 	WRVASD(iun,
15490 #else
15491 	wrvasd_(iun,
15492 #endif
15493 #endif
15494 	xyzp->coo,xyzp->ianz,
15495 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15496 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
15497 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15498 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15499 
15500 }
15501 
15502 #if defined(VMS) || defined(UNDERSC)
wrmopa(iun)15503 void wrmopa(iun)
15504 #else
15505 #ifdef CRAY
15506 void WRMOPA(iun)
15507 #else
15508 void wrmopa_(iun)
15509 #endif
15510 #endif
15511 int *iun;
15512 {
15513 
15514 #if defined(VMS) || defined(UNDERSC)
15515 	wrmopd(iun,
15516 #else
15517 #ifdef CRAY
15518 	WRMOPD(iun,
15519 #else
15520 	wrmopd_(iun,
15521 #endif
15522 #endif
15523 	xyzp->coo,xyzp->ianz,
15524 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15525 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5]);
15526 
15527 }
15528 
15529 #if defined(VMS) || defined(UNDERSC)
wrfc(iun3)15530 void wrfc(iun3)
15531 #else
15532 #ifdef CRAY
15533 void WRFC(iun3)
15534 #else
15535 void wrfc_(iun3)
15536 #endif
15537 #endif
15538 int *iun3;
15539 {
15540 
15541 #if defined(VMS) || defined(UNDERSC)
15542 	wrfd(iun3,
15543 #else
15544 #ifdef CRAY
15545 	WRFD(iun3,
15546 #else
15547 	wrfd_(iun3,
15548 #endif
15549 #endif
15550 	xyzp->coo);
15551 
15552 }
15553 
15554 #if defined(VMS) || defined(UNDERSC)
rdfc(ipnt,istats)15555 void rdfc(ipnt,istats)
15556 #else
15557 #ifdef CRAY
15558 void RDFC(ipnt,istats)
15559 #else
15560 void rdfc_(ipnt,istats)
15561 #endif
15562 #endif
15563 int *ipnt;
15564 int *istats;
15565 {
15566 
15567 #if defined(VMS) || defined(UNDERSC)
15568 	rdfd(ipnt,istats,
15569 #else
15570 #ifdef CRAY
15571 	RDFD(ipnt,istats,
15572 #else
15573 	rdfd_(ipnt,istats,
15574 #endif
15575 #endif
15576 	xyzp->coo);
15577 
15578 }
15579 
15580 #if defined(VMS) || defined(UNDERSC)
rdmsf(idebug,istat)15581 void rdmsf(idebug,istat)
15582 #else
15583 #ifdef CRAY
15584 void RDMSF(idebug,istat)
15585 #else
15586 void rdmsf_(idebug,istat)
15587 #endif
15588 #endif
15589 int *idebug;
15590 int *istat;
15591 {
15592 
15593 #if defined(VMS) || defined(UNDERSC)
15594 	rdmdf(idebug,istat,
15595 #else
15596 #ifdef CRAY
15597 	RDMDF(idebug,istat,
15598 #else
15599 	rdmdf_(idebug,istat,
15600 #endif
15601 #endif
15602 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,xyzp->qat,xyzp->ityp,
15603 	&cell->natc,&cell->norg,&cell->icent,&cell->inorm,
15604 	&cell->ncon,&cell->nspg,&cell->kz,&cell->ichx,
15605 	&cell->nopr,cell->ir,cell->it,
15606 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
15607 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
15608 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
15609 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
15610 
15611 }
15612 
15613 #if defined(VMS) || defined(UNDERSC)
rdpdb(istat)15614 void rdpdb(istat)
15615 #else
15616 #ifdef CRAY
15617 void RDPDB(istat)
15618 #else
15619 void rdpdb_(istat)
15620 #endif
15621 #endif
15622 int *istat;
15623 {
15624 
15625 #if defined(VMS) || defined(UNDERSC)
15626 	rdpdd(istat,
15627 #else
15628 #ifdef CRAY
15629 	RDPDD(istat,
15630 #else
15631 	rdpdd_(istat,
15632 #endif
15633 #endif
15634 	xyzp->coo,xyzp->ianz,&calfptr->ihashb);
15635 
15636 }
15637 
15638 #if defined(VMS) || defined(UNDERSC)
quwat(nwat)15639 void quwat(nwat)
15640 #else
15641 #ifdef CRAY
15642 void QUWAT(nwat)
15643 #else
15644 void quwat_(nwat)
15645 #endif
15646 #endif
15647 int *nwat;
15648 {
15649 
15650 #if defined(VMS) || defined(UNDERSC)
15651 	quwad(nwat,
15652 #else
15653 #ifdef CRAY
15654 	QUWAD(nwat,
15655 #else
15656 	quwad_(nwat,
15657 #endif
15658 #endif
15659 	xyzp->iresid,xyzp->iconn,xyzp->ianz);
15660 
15661 }
15662 
15663 #if defined(VMS) || defined(UNDERSC)
evwat()15664 void evwat()
15665 #else
15666 #ifdef CRAY
15667 void EVWAT()
15668 #else
15669 void evwat_()
15670 #endif
15671 #endif
15672 {
15673 	int nwat;
15674 
15675 #if defined(VMS) || defined(UNDERSC)
15676 	quwat(&nwat);
15677 	nwat = nwat*3;
15678 	if (nwat + *xyzp->iatoms > *xyzp->mxnat) allcoo(&nwat,&ZERO);
15679 	evwad(
15680 #else
15681 #ifdef CRAY
15682 	QUWAT(&nwat);
15683 	nwat = nwat*3;
15684 	if (nwat + *xyzp->iatoms > *xyzp->mxnat) ALLCOO(&nwat,&ZERO);
15685 	EVWAD(
15686 #else
15687 	quwat_(&nwat);
15688 	nwat = nwat*3;
15689 	if (nwat + *xyzp->iatoms > *xyzp->mxnat) allcoo_(&nwat,&ZERO);
15690 	evwad_(
15691 #endif
15692 #endif
15693 
15694 	xyzp->coo,xyzp->qat,xyzp->iresid,calfptr->irsnr,xyzp->iatclr,
15695 	xyzp->iaton,xyzp->iconn,xyzp->ianz,&calfptr->ncalf,calfptr->icalf,
15696 	xyzp->ityp,xyzp->ipdbt,&calfptr->ishoh);
15697 
15698 }
15699 
15700 #if defined(VMS) || defined(UNDERSC)
fndoh(itar,ang,ires,copt,istat)15701 void fndoh(itar,ang,ires,copt,istat)
15702 #else
15703 #ifdef CRAY
15704 void FNDOH(itar,ang,ires,copt,istat)
15705 #else
15706 void fndoh_(itar,ang,ires,copt,istat)
15707 #endif
15708 #endif
15709 int *itar;
15710 double *ang;
15711 int *ires;
15712 double *copt;
15713 int *istat;
15714 {
15715 
15716 #if defined(VMS) || defined(UNDERSC)
15717 	fndod(itar,ang,ires,copt,istat,
15718 #else
15719 #ifdef CRAY
15720 	FNDOD(itar,ang,ires,copt,istat,
15721 #else
15722 	fndod_(itar,ang,ires,copt,istat,
15723 #endif
15724 #endif
15725 	xyzp->coo,xyzp->qat,xyzp->iconn,xyzp->ityp,xyzp->iresid,
15726 	calfptr->irsnr,&calfptr->ncalf,calfptr->icalf);
15727 
15728 }
15729 
FreeWat(sel)15730 void FreeWat(sel)
15731 int sel;
15732 {
15733    if (watres[sel] != NULL) free(watres[sel]);
15734    if (watanz[sel] != NULL) free(watanz[sel]);
15735    if (watcoo[sel] != NULL) free(watcoo[sel]);
15736    if (watcon[sel] != NULL) free(watcon[sel]);
15737    if (watmap[sel] != NULL) free(watmap[sel]);
15738    if (watqat[sel] != NULL) free(watqat[sel]);
15739    if (wattyp[sel] != NULL) free(wattyp[sel]);
15740 
15741    watres[sel] = NULL;
15742    watanz[sel] = NULL;
15743    watcoo[sel] = NULL;
15744    watcon[sel] = NULL;
15745    watmap[sel] = NULL;
15746    watqat[sel] = NULL;
15747    wattyp[sel] = NULL;
15748 }
15749 
RestComplete()15750 void RestComplete()
15751 {
15752   int i,j,k,ires,irsnrt,nw,ido;
15753 
15754 #if defined(VMS) || defined(UNDERSC)
15755   curs(&ONE);
15756 #else
15757 #ifdef CRAY
15758   CURS(&ONE);
15759 #else
15760   curs_(&ONE);
15761 #endif
15762 #endif
15763 
15764   if (!incompl->nincmp) return;
15765 
15766   for (j=0;j<3;j++) {
15767      for (i = 0; i < incompl->nincmp; i++) {
15768 	ires = ABS(incompl->incomp[i]);
15769 
15770 	ido = 1;
15771 	for (k = 0; k < 3; k++) {
15772 	    if (!calfptr->icalf[ires-1][k]) ido = 0;
15773 	}
15774 
15775 	if (!calfptr->icalf[ires][0]) ido = 0;
15776 
15777 	if (ido) {
15778 	   if (j == 2) {
15779 		onerot(ires,1);
15780 	   } else {
15781 		onerot(ires,0);
15782 	   }
15783 
15784 	} else {
15785 	   if (j == 2) {
15786 		fprintf(stderr,"%s %d: incomplete residue skipped: missing backbone atoms !!\n",AminoAcids[calfptr->iamino[ires-1]-1],calfptr->irsnr[ires-1]);
15787 	   }
15788 	}
15789      }
15790   }
15791 
15792 
15793 #ifdef DOGL
15794   update_model = 0;
15795 #else
15796   update_model = 1;
15797 #endif
15798 
15799 #if defined(VMS) || defined(UNDERSC)
15800   qupd();
15801   curs(&ZERO);
15802 #else
15803 #ifdef CRAY
15804   QUPD();
15805   CURS(&ZERO);
15806 #else
15807   qupd_();
15808   curs_(&ZERO);
15809 #endif
15810 #endif
15811 
15812 }
15813 
15814 #if defined(VMS) || defined(UNDERSC)
opthyd()15815 void opthyd()
15816 #else
15817 #ifdef CRAY
15818 void OPTHYD()
15819 #else
15820 void opthyd_()
15821 #endif
15822 #endif
15823 {
15824 	int i;
15825 
15826 	if (HLIG) LigandHydroQ(1,1,1,0);
15827 
15828 	if (HINC) RestComplete();
15829 
15830         update_model=0;
15831 	if (*fftyp != 7) typit(7,1);
15832 
15833 #if defined(VMS) || defined(UNDERSC)
15834 	opthdd(&HFLP,&HHIS,&HRES,&HWAT,
15835 #else
15836 #ifdef CRAY
15837 	OPTHDD(&HFLP,&HHIS,&HRES,&HWAT,
15838 #else
15839 	opthdd_(&HFLP,&HHIS,&HRES,&HWAT,
15840 #endif
15841 #endif
15842 	iupres,&nupres,calfptr->irsnr,&calfptr->ncalf, calfptr->icalf,xyzp->coo,
15843 	xyzp->qat,xyzp->iconn,xyzp->ianz,xyzp->iresid,calfptr->iamino,
15844 	xyzp->ityp,xyzp->ipdbt);
15845 
15846 #ifdef DOGL
15847 	for (i=0; i < nupres; i++ ) {
15848 	   ogres(iupres[i],0,0);
15849 	}
15850 	if (*fancy) {
15851 	   oghet(0);
15852 	} else {
15853 	   oglines();
15854 	}
15855 	update_model = 0;
15856 #endif
15857 	update_struct();
15858 
15859 }
15860 
15861 #if defined(VMS) || defined(UNDERSC)
appchg()15862 void appchg()
15863 #else
15864 #ifdef CRAY
15865 void APPCHG()
15866 #else
15867 void appchg_()
15868 #endif
15869 #endif
15870 {
15871   if (! *icommf) return;
15872   if (calfptr->ncalf > 0) {
15873      if (!qdpptr->ihasq) {
15874 	HINC = HRES = HLIG = HFLP = HHIS = HWAT = 1;
15875 #if defined(VMS) || defined(UNDERSC)
15876 	opthyd();
15877 #else
15878 #ifdef CRAY
15879 	OPTHYD();
15880 #else
15881 	opthyd_();
15882 #endif
15883 #endif
15884      }
15885   } else {
15886      if (!qdpptr->ihasq) {
15887 #if defined(VMS) || defined(UNDERSC)
15888 	addchg();
15889 #else
15890 #ifdef CRAY
15891 	ADDCHG();
15892 #else
15893 	addchg_();
15894 #endif
15895 #endif
15896      }
15897   }
15898 }
15899 
15900 #if defined(VMS) || defined(UNDERSC)
nmrcpl(idebug)15901 void nmrcpl(idebug)
15902 #else
15903 #ifdef CRAY
15904 void NMRCPL(idebug)
15905 #else
15906 void nmrcpl_(idebug)
15907 #endif
15908 #endif
15909 int *idebug;
15910 {
15911    double d;
15912    int size;
15913 
15914    size = NAT->natoms;
15915 
15916    if ((jcoupl = (double *) malloc((sizeof d)*size*size)) != NULL) {
15917 #if defined(VMS) || defined(UNDERSC)
15918 	nmrcpd(idebug,
15919 #else
15920 #ifdef CRAY
15921 	NMRCPD(idebug,
15922 #else
15923 	nmrcpd_(idebug,
15924 #endif
15925 #endif
15926 	jcoupl);
15927    } else {
15928 	fprintf(stderr,"Failed to allocate memory for J-coupling !\n");
15929 	nmrptr->ihsnmr = 1;
15930    }
15931 }
15932 
15933 #if defined(VMS) || defined(UNDERSC)
nmcshl()15934 void nmcshl()
15935 #else
15936 #ifdef CRAY
15937 void NMCSHL()
15938 #else
15939 void nmcshl_()
15940 #endif
15941 #endif
15942 {
15943    double d;
15944    int size;
15945 
15946    size = NAT->natoms;
15947 
15948    if ((jcoupl = (double *) malloc((sizeof d)*size*size)) != NULL) {
15949 #if defined(VMS) || defined(UNDERSC)
15950 	nmcshd(
15951 #else
15952 #ifdef CRAY
15953 	NMCSHD(
15954 #else
15955 	nmcshd_(
15956 #endif
15957 #endif
15958 	jcoupl);
15959    } else {
15960 	fprintf(stderr,"Failed to allocate memory for J-coupling !\n");
15961 	nmrptr->ihsnmr = 1;
15962    }
15963 }
15964 
15965 #if defined(VMS) || defined(UNDERSC)
pdbstd(istat,doscnd,ioadd)15966 void pdbstd(istat,doscnd,ioadd)
15967 #else
15968 #ifdef CRAY
15969 void PDBSTD(istat,doscnd,ioadd)
15970 #else
15971 void pdbstd_(istat,doscnd,ioadd)
15972 #endif
15973 #endif
15974 int *istat;
15975 int *doscnd;
15976 int *ioadd;
15977 {
15978   int iszhnt;
15979 
15980 #if defined(VMS) || defined(UNDERSC)
15981 	pdbsiz(&iszhnt);
15982 	if (*ioadd) {
15983 	   if (iszhnt + *xyzp->iatoms > *xyzp->mxnat) allcoo(&iszhnt,&ZERO);
15984 	} else {
15985 	   if (iszhnt > *xyzp->mxnat) allcoo(&iszhnt,&ZERO);
15986            setid(&FOUR,&ZERO,xyzp->isurf,xyzp->iresid,xyzp->ipdbt);
15987 	}
15988 	pdbsdd(istat,doscnd,ioadd,
15989 #else
15990 #ifdef CRAY
15991 	PDBSIZ(&iszhnt);
15992 	if (*ioadd) {
15993 	   if (iszhnt + *xyzp->iatoms > *xyzp->mxnat) ALLCOO(&iszhnt,&ZERO);
15994 	} else {
15995 	   if (iszhnt > *xyzp->mxnat) ALLCOO(&iszhnt,&ZERO);
15996            SETID(&FOUR,&ZERO,xyzp->isurf,xyzp->iresid,xyzp->ipdbt);
15997 	}
15998 	PDBSDD(istat,doscnd,ioadd,
15999 #else
16000 	pdbsiz_(&iszhnt);
16001 	if (*ioadd) {
16002 	   if (iszhnt + *xyzp->iatoms > *xyzp->mxnat) allcoo_(&iszhnt,&ZERO);
16003 	} else {
16004 	   if (iszhnt > *xyzp->mxnat) allcoo_(&iszhnt,&ZERO);
16005            setid_(&FOUR,&ZERO,xyzp->isurf,xyzp->iresid,xyzp->ipdbt);
16006 	}
16007 	pdbsdd_(istat,doscnd,ioadd,
16008 #endif
16009 #endif
16010 	xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn,xyzp->ityp,
16011         &calfptr->ncalf,calfptr->ianf,calfptr->islu,
16012         &calfptr->nchain,calfptr->iamino,calfptr->ihet,
16013         calfptr->isal,calfptr->irsnr,calfptr->achain,
16014 	&calfptr->ihashb,&calfptr->ishoh);
16015 
16016 
16017 	if (*istat == -1) {
16018 	   hetptr.NHetAtm = 0;
16019 #if defined(VMS) || defined(UNDERSC)
16020 	   allcoo(&addat,&ZERO);
16021 	   pdbsdd(istat,doscnd,ioadd,
16022 #else
16023 #ifdef CRAY
16024 	   ALLCOO(&addat,&ZERO);
16025 	   PDBSDD(istat,doscnd,ioadd,
16026 #else
16027 	   allcoo_(&addat,&ZERO);
16028 	   pdbsdd_(istat,doscnd,ioadd,
16029 #endif
16030 #endif
16031 	   xyzp->coo,xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn,
16032 	   xyzp->ityp,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
16033            &calfptr->nchain,calfptr->iamino,calfptr->ihet,
16034            calfptr->isal,calfptr->irsnr,calfptr->achain,
16035 	   &calfptr->ihashb,&calfptr->ishoh);
16036         }
16037 }
16038 
16039 #if defined(VMS) || defined(UNDERSC)
conpdb()16040 void conpdb()
16041 #else
16042 #ifdef CRAY
16043 void CONPDB()
16044 #else
16045 void conpdb_()
16046 #endif
16047 #endif
16048 {
16049 
16050 #if defined(VMS) || defined(UNDERSC)
16051 	conpdd(
16052 #else
16053 #ifdef CRAY
16054 	CONPDD(
16055 #else
16056 	conpdd_(
16057 #endif
16058 #endif
16059 	xyzp->ianz,xyzp->iconn,xyzp->iresid,
16060 	&calfptr->ncalf,calfptr->iamino);
16061 
16062 }
16063 
16064 #if defined(VMS) || defined(UNDERSC)
convpdb()16065 void convpdb()
16066 #else
16067 #ifdef CRAY
16068 void CONVPDB()
16069 #else
16070 void convpdb_()
16071 #endif
16072 #endif
16073 {
16074 
16075 #if defined(VMS) || defined(UNDERSC)
16076 	convpdd(
16077 #else
16078 #ifdef CRAY
16079 	CONVPDD(
16080 #else
16081 	convpdd_(
16082 #endif
16083 #endif
16084 	xyzp->ianz,xyzp->iconn,xyzp->iresid,
16085 	&calfptr->ncalf,calfptr->iamino);
16086 
16087 }
16088 
16089 #if defined(VMS) || defined(UNDERSC)
conslv()16090 void conslv()
16091 #else
16092 #ifdef CRAY
16093 void CONSLV()
16094 #else
16095 void conslv_()
16096 #endif
16097 #endif
16098 {
16099 
16100 #if defined(VMS) || defined(UNDERSC)
16101 	consld(
16102 #else
16103 #ifdef CRAY
16104 	CONSLD(
16105 #else
16106 	consld_(
16107 #endif
16108 #endif
16109 	xyzp->iconn,xyzp->iresid);
16110 
16111 }
16112 
16113 #if defined(VMS) || defined(UNDERSC)
connij(idcon,i,j,idoconv)16114 void connij(idcon,i,j,idoconv)
16115 #else
16116 #ifdef CRAY
16117 void CONNIJ(idcon,i,j,idoconv)
16118 #else
16119 void connij_(idcon,i,j,idoconv)
16120 #endif
16121 #endif
16122 int *idcon;
16123 int *i;
16124 int *j;
16125 int *idoconv;
16126 {
16127 
16128 #if defined(VMS) || defined(UNDERSC)
16129 	connid(idcon,i,j,idoconv,
16130 #else
16131 #ifdef CRAY
16132 	CONNID(idcon,i,j,idoconv,
16133 #else
16134 	connid_(idcon,i,j,idoconv,
16135 #endif
16136 #endif
16137 	xyzp->iconn,xyzp->ianz,xyzp->coo);
16138 
16139 }
16140 
16141 #if defined(VMS) || defined(UNDERSC)
setchg(iat,iopt)16142 void setchg(iat,iopt)
16143 #else
16144 #ifdef CRAY
16145 void SETCHG(iat,iopt)
16146 #else
16147 void setchg_(iat,iopt)
16148 #endif
16149 #endif
16150 int *iat;
16151 int *iopt;
16152 {
16153 
16154 #if defined(VMS) || defined(UNDERSC)
16155 	setchd(iat,iopt,
16156 #else
16157 #ifdef CRAY
16158 	SETCHD(iat,iopt,
16159 #else
16160 	setchd_(iat,iopt,
16161 #endif
16162 #endif
16163 	xyzp->qat,xyzp->ityp);
16164 
16165 }
16166 
16167 #if defined(VMS) || defined(UNDERSC)
flagh(ihpdb,iat)16168 void flagh(ihpdb,iat)
16169 #else
16170 #ifdef CRAY
16171 void FLAGH(ihpdb,iat)
16172 #else
16173 void flagh_(ihpdb,iat)
16174 #endif
16175 #endif
16176 int *ihpdb;
16177 int *iat;
16178 {
16179 
16180 #if defined(VMS) || defined(UNDERSC)
16181 	flagd(ihpdb,iat,
16182 #else
16183 #ifdef CRAY
16184 	FLAGD(ihpdb,iat,
16185 #else
16186 	flagd_(ihpdb,iat,
16187 #endif
16188 #endif
16189 	xyzp->isurf);
16190 
16191 }
16192 
16193 #if defined(VMS) || defined(UNDERSC)
conat(ipdb,iat1,iat2,iop)16194 void conat(ipdb,iat1,iat2,iop)
16195 #else
16196 #ifdef CRAY
16197 void CONAT(ipdb,iat1,iat2,iop)
16198 #else
16199 void conat_(ipdb,iat1,iat2,iop)
16200 #endif
16201 #endif
16202 int *ipdb;
16203 int *iat1;
16204 int *iat2;
16205 int *iop;
16206 {
16207 
16208 #if defined(VMS) || defined(UNDERSC)
16209 	conad(ipdb,iat1,iat2,iop,
16210 #else
16211 #ifdef CRAY
16212 	CONAD(ipdb,iat1,iat2,iop,
16213 #else
16214 	conad_(ipdb,iat1,iat2,iop,
16215 #endif
16216 #endif
16217 	xyzp->iconn);
16218 
16219 }
16220 
16221 #if defined(VMS) || defined(UNDERSC)
conath(ipdb,ihpdb,iat1,iat2)16222 void conath(ipdb,ihpdb,iat1,iat2)
16223 #else
16224 #ifdef CRAY
16225 void CONATH(ipdb,ihpdb,iat1,iat2)
16226 #else
16227 void conath_(ipdb,ihpdb,iat1,iat2)
16228 #endif
16229 #endif
16230 int *ipdb;
16231 int *ihpdb;
16232 int *iat1;
16233 int *iat2;
16234 {
16235 
16236 #if defined(VMS) || defined(UNDERSC)
16237 	conatd(ipdb,ihpdb,iat1,iat2,
16238 #else
16239 #ifdef CRAY
16240 	CONATD(ipdb,ihpdb,iat1,iat2,
16241 #else
16242 	conatd_(ipdb,ihpdb,iat1,iat2,
16243 #endif
16244 #endif
16245 	xyzp->iconn);
16246 
16247 }
16248 
16249 #if defined(VMS) || defined(UNDERSC)
pdbtyp(ipdb,ihpdb,jres,ihashy)16250 void pdbtyp(ipdb,ihpdb,jres,ihashy)
16251 #else
16252 #ifdef CRAY
16253 void PDBTYP(ipdb,ihpdb,jres,ihashy)
16254 #else
16255 void pdbtyp_(ipdb,ihpdb,jres,ihashy)
16256 #endif
16257 #endif
16258 int *ipdb;
16259 int *ihpdb;
16260 int *jres;
16261 int *ihashy;
16262 {
16263 
16264 #if defined(VMS) || defined(UNDERSC)
16265 	pdbtyd(ipdb,ihpdb,jres,ihashy,
16266 #else
16267 #ifdef CRAY
16268 	PDBTYD(ipdb,ihpdb,jres,ihashy,
16269 #else
16270 	pdbtyd_(ipdb,ihpdb,jres,ihashy,
16271 #endif
16272 #endif
16273 	xyzp->ipdbt);
16274 
16275 }
16276 
16277 #if defined(VMS) || defined(UNDERSC)
typeit(ipdb,jres,ihpdb,ihashy)16278 void typeit(ipdb,jres,ihpdb,ihashy)
16279 #else
16280 #ifdef CRAY
16281 void TYPEIT(ipdb,jres,ihpdb,ihashy)
16282 #else
16283 void typeit_(ipdb,jres,ihpdb,ihashy)
16284 #endif
16285 #endif
16286 int *ipdb;
16287 int *ihpdb;
16288 int *jres;
16289 int *ihashy;
16290 {
16291 
16292 #if defined(VMS) || defined(UNDERSC)
16293 	typeid(ipdb,jres,ihpdb,ihashy,
16294 #else
16295 #ifdef CRAY
16296 	TYPEID(ipdb,jres,ihpdb,ihashy,
16297 #else
16298 	typeid_(ipdb,jres,ihpdb,ihashy,
16299 #endif
16300 #endif
16301 	xyzp->ianz,xyzp->iconn,xyzp->ityp);
16302 
16303 }
16304 
16305 #if defined(VMS) || defined(UNDERSC)
typamb(ipdb,jres,ihpdb,ihashy)16306 void typamb(ipdb,jres,ihpdb,ihashy)
16307 #else
16308 #ifdef CRAY
16309 void TYPAMB(ipdb,jres,ihpdb,ihashy)
16310 #else
16311 void typamb_(ipdb,jres,ihpdb,ihashy)
16312 #endif
16313 #endif
16314 int *ipdb;
16315 int *ihpdb;
16316 int *jres;
16317 int *ihashy;
16318 {
16319 
16320 #if defined(VMS) || defined(UNDERSC)
16321 	typamd(ipdb,jres,ihpdb,ihashy,
16322 #else
16323 #ifdef CRAY
16324 	TYPAMD(ipdb,jres,ihpdb,ihashy,
16325 #else
16326 	typamd_(ipdb,jres,ihpdb,ihashy,
16327 #endif
16328 #endif
16329 	xyzp->ianz,xyzp->iconn,xyzp->ityp);
16330 
16331 }
16332 
16333 #if defined(VMS) || defined(UNDERSC)
typamo(ipdb,jres,ihpdb,ihashy)16334 void typamo(ipdb,jres,ihpdb,ihashy)
16335 #else
16336 #ifdef CRAY
16337 void TYPAMO(ipdb,jres,ihpdb,ihashy)
16338 #else
16339 void typamo_(ipdb,jres,ihpdb,ihashy)
16340 #endif
16341 #endif
16342 int *ipdb;
16343 int *ihpdb;
16344 int *jres;
16345 int *ihashy;
16346 {
16347 
16348 #if defined(VMS) || defined(UNDERSC)
16349 	typado(ipdb,jres,ihpdb,ihashy,
16350 #else
16351 #ifdef CRAY
16352 	TYPADO(ipdb,jres,ihpdb,ihashy,
16353 #else
16354 	typado_(ipdb,jres,ihpdb,ihashy,
16355 #endif
16356 #endif
16357 	xyzp->ianz,xyzp->iconn,xyzp->ityp);
16358 
16359 }
16360 
16361 
16362 #if defined(VMS) || defined(UNDERSC)
mkback(ipdb,ihpdb,jres,icres,ihashy,idoconv)16363 void mkback(ipdb,ihpdb,jres,icres,ihashy,idoconv)
16364 #else
16365 #ifdef CRAY
16366 void MKBACK(ipdb,ihpdb,jres,icres,ihashy,idoconv)
16367 #else
16368 void mkback_(ipdb,ihpdb,jres,icres,ihashy,idoconv)
16369 #endif
16370 #endif
16371 int *ipdb;
16372 int *ihpdb;
16373 int *jres;
16374 int *icres;
16375 int *ihashy;
16376 int *idoconv;
16377 {
16378 
16379 /*
16380  The variable NW_MKBACK switches betwwen the old (NW_MKBACK=0)
16381  and the new (NW_MKBACK=0) form of mkback. The old version depended
16382  on the next call (residue nr. one higher) to complete the connections of
16383  Coo. Hence if called on its own the Coo connections would not be complete.
16384  However since the icalf variables of the next residue have NOT been set
16385  at the time when it is first called, we still need this one !!!
16386 
16387  The new form of mkback can be called on its own and have all connections
16388  complete. Depend on icalf variables already been set for all residues.
16389 */
16390 
16391     if (NW_MKBACK) {
16392 #if defined(VMS) || defined(UNDERSC)
16393 	mkbadd(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16394 #else
16395 #ifdef CRAY
16396 	MKBADD(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16397 #else
16398 	mkbadd_(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16399 #endif
16400 #endif
16401 	xyzp->iconn,xyzp->coo,
16402         calfptr->icalf,calfptr->ianf,calfptr->islu,
16403         &calfptr->nchain,calfptr->iamino);
16404     } else {
16405 #if defined(VMS) || defined(UNDERSC)
16406 	mkbacd(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16407 #else
16408 #ifdef CRAY
16409 	MKBACD(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16410 #else
16411 	mkbacd_(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16412 #endif
16413 #endif
16414 	xyzp->iconn,xyzp->coo,
16415         calfptr->icalf,calfptr->ianf,calfptr->islu,
16416         &calfptr->nchain,calfptr->iamino);
16417     }
16418 
16419 }
16420 
16421 #if defined(VMS) || defined(UNDERSC)
mknbck(ipdb,ihpdb,jres,icres,ihashy,idoconv)16422 void mknbck(ipdb,ihpdb,jres,icres,ihashy,idoconv)
16423 #else
16424 #ifdef CRAY
16425 void MKNBCK(ipdb,ihpdb,jres,icres,ihashy,idoconv)
16426 #else
16427 void mknbck_(ipdb,ihpdb,jres,icres,ihashy,idoconv)
16428 #endif
16429 #endif
16430 int *ipdb;
16431 int *ihpdb;
16432 int *jres;
16433 int *icres;
16434 int *ihashy;
16435 int *idoconv;
16436 {
16437 
16438 #if defined(VMS) || defined(UNDERSC)
16439 	mknbcd(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16440 #else
16441 #ifdef CRAY
16442 	MKNBCD(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16443 #else
16444 	mknbcd_(ipdb,ihpdb,jres,icres,ihashy,idoconv,
16445 #endif
16446 #endif
16447 	xyzp->iconn,xyzp->coo,
16448         calfptr->icalf,calfptr->ianf,calfptr->islu,
16449         &calfptr->nchain,calfptr->iamino);
16450 
16451 }
16452 
16453 #if defined(VMS) || defined(UNDERSC)
tautom()16454 void tautom()
16455 #else
16456 #ifdef CRAY
16457 void TAUTOM()
16458 #else
16459 void tautom_()
16460 #endif
16461 #endif
16462 {
16463 
16464 #if defined(VMS) || defined(UNDERSC)
16465 	tautd(
16466 #else
16467 #ifdef CRAY
16468 	TAUTD(
16469 #else
16470 	tautd_(
16471 #endif
16472 #endif
16473 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
16474 	xyzp->ipdbt,xyzp->ityp,&calfptr->ncalf,calfptr->icalf,
16475 	xyzp->coo);
16476 
16477 }
16478 
16479 #if defined(VMS) || defined(UNDERSC)
addhs(ires,jres,ipdb,ihpdb,nterm)16480 void addhs(ires,jres,ipdb,ihpdb,nterm)
16481 #else
16482 #ifdef CRAY
16483 void ADDHS(ires,jres,ipdb,ihpdb,nterm)
16484 #else
16485 void addhs_(ires,jres,ipdb,ihpdb,nterm)
16486 #endif
16487 #endif
16488 int *ires;
16489 int *jres;
16490 int *ipdb;
16491 int *ihpdb;
16492 int *nterm;
16493 {
16494 
16495 #if defined(VMS) || defined(UNDERSC)
16496 	addhd(ires,jres,ipdb,ihpdb,nterm,
16497 #else
16498 #ifdef CRAY
16499 	ADDHD(ires,jres,ipdb,ihpdb,nterm,
16500 #else
16501 	addhd_(ires,jres,ipdb,ihpdb,nterm,
16502 #endif
16503 #endif
16504 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
16505 	xyzp->isurf,xyzp->ipdbt,xyzp->ityp,&calfptr->ncalf,calfptr->icalf,
16506 	xyzp->coo);
16507 
16508 }
16509 
16510 #if defined(VMS) || defined(UNDERSC)
numhet(num)16511 void numhet(num)
16512 #else
16513 #ifdef CRAY
16514 void NUMHET(num)
16515 #else
16516 void numhet_(num)
16517 #endif
16518 #endif
16519 int *num;
16520 {
16521 
16522 #if defined(VMS) || defined(UNDERSC)
16523 	numhed(num,
16524 #else
16525 #ifdef CRAY
16526 	NUMHED(num,
16527 #else
16528 	numhed_(num,
16529 #endif
16530 #endif
16531 	xyzp->iresid);
16532 
16533 }
16534 
16535 #if defined(VMS) || defined(UNDERSC)
qcxyz(idebug,nuclear,ipnt,istat)16536 void qcxyz(idebug,nuclear,ipnt,istat)
16537 #else
16538 #ifdef CRAY
16539 void QCXYZ(idebug,nuclear,ipnt,istat)
16540 #else
16541 void qcxyz_(idebug,nuclear,ipnt,istat)
16542 #endif
16543 #endif
16544 int *idebug;
16545 int *nuclear;
16546 int *ipnt;
16547 int *istat;
16548 {
16549 
16550 #if defined(VMS) || defined(UNDERSC)
16551 	qcxyd(idebug,nuclear,ipnt,istat,
16552 #else
16553 #ifdef CRAY
16554 	QCXYD(idebug,nuclear,ipnt,istat,
16555 #else
16556 	qcxyd_(idebug,nuclear,ipnt,istat,
16557 #endif
16558 #endif
16559 	xyzp->ianz,xyzp->coo);
16560 
16561 }
16562 
16563 #if defined(VMS) || defined(UNDERSC)
orcxyz(idebug,ipnt,istat)16564 void orcxyz(idebug,ipnt,istat)
16565 #else
16566 #ifdef CRAY
16567 void ORCXYZ(idebug,ipnt,istat)
16568 #else
16569 void orcxyz_(idebug,ipnt,istat)
16570 #endif
16571 #endif
16572 int *idebug;
16573 int *ipnt;
16574 int *istat;
16575 {
16576 
16577 #if defined(VMS) || defined(UNDERSC)
16578 	orcxyd(idebug,ipnt,istat,
16579 #else
16580 #ifdef CRAY
16581 	ORCXYD(idebug,ipnt,istat,
16582 #else
16583 	orcxyd_(idebug,ipnt,istat,
16584 #endif
16585 #endif
16586 	xyzp->ianz,xyzp->coo);
16587 
16588 }
16589 
16590 #if defined(VMS) || defined(UNDERSC)
entag(idebug,istat)16591 void entag(idebug,istat)
16592 #else
16593 #ifdef CRAY
16594 void ENTAG(idebug,istat)
16595 #else
16596 void entag_(idebug,istat)
16597 #endif
16598 #endif
16599 int *idebug;
16600 int *istat;
16601 {
16602 
16603 #if defined(VMS) || defined(UNDERSC)
16604 	entad(idebug,istat,
16605 #else
16606 #ifdef CRAY
16607 	ENTAD(idebug,istat,
16608 #else
16609 	entad_(idebug,istat,
16610 #endif
16611 #endif
16612 	xyzp->ianz);
16613 
16614 }
16615 
16616 #if defined(VMS) || defined(UNDERSC)
enmull(idebug,istat)16617 void enmull(idebug,istat)
16618 #else
16619 #ifdef CRAY
16620 void ENMULL(idebug,istat)
16621 #else
16622 void enmull_(idebug,istat)
16623 #endif
16624 #endif
16625 int *idebug;
16626 int *istat;
16627 {
16628 
16629 #if defined(VMS) || defined(UNDERSC)
16630 	enmuld(idebug,istat,
16631 #else
16632 #ifdef CRAY
16633 	ENMULD(idebug,istat,
16634 #else
16635 	enmuld_(idebug,istat,
16636 #endif
16637 #endif
16638 	xyzp->qat);
16639 
16640 }
16641 
16642 #if defined(VMS) || defined(UNDERSC)
nwxyz(idebug,ipnt,istat)16643 void nwxyz(idebug,ipnt,istat)
16644 #else
16645 #ifdef CRAY
16646 void NWXYZ(idebug,ipnt,istat)
16647 #else
16648 void nwxyz_(idebug,ipnt,istat)
16649 #endif
16650 #endif
16651 int *idebug;
16652 int *ipnt;
16653 int *istat;
16654 {
16655 
16656 #if defined(VMS) || defined(UNDERSC)
16657 	nwxyd(idebug,ipnt,istat,
16658 #else
16659 #ifdef CRAY
16660 	NWXYD(idebug,ipnt,istat,
16661 #else
16662 	nwxyd_(idebug,ipnt,istat,
16663 #endif
16664 #endif
16665 	xyzp->ianz,xyzp->coo);
16666 
16667 }
16668 
16669 #if defined(VMS) || defined(UNDERSC)
enwxyz(idebug,ipnt,istat)16670 void enwxyz(idebug,ipnt,istat)
16671 #else
16672 #ifdef CRAY
16673 void ENWXYZ(idebug,ipnt,istat)
16674 #else
16675 void enwxyz_(idebug,ipnt,istat)
16676 #endif
16677 #endif
16678 int *idebug;
16679 int *ipnt;
16680 int *istat;
16681 {
16682 
16683 #if defined(VMS) || defined(UNDERSC)
16684 	enwxyd(idebug,ipnt,istat,
16685 #else
16686 #ifdef CRAY
16687 	ENWXYD(idebug,ipnt,istat,
16688 #else
16689 	enwxyd_(idebug,ipnt,istat,
16690 #endif
16691 #endif
16692 	xyzp->ianz,xyzp->coo);
16693 
16694 }
16695 
16696 #if defined(VMS) || defined(UNDERSC)
fnwxyz(idebug,istat)16697 void fnwxyz(idebug,istat)
16698 #else
16699 #ifdef CRAY
16700 void FNWXYZ(idebug,istat)
16701 #else
16702 void fnwxyz_(idebug,istat)
16703 #endif
16704 #endif
16705 int *idebug;
16706 int *istat;
16707 {
16708 
16709 #if defined(VMS) || defined(UNDERSC)
16710 	fnwxyd(idebug,istat,
16711 #else
16712 #ifdef CRAY
16713 	FNWXYD(idebug,istat,
16714 #else
16715 	fnwxyd_(idebug,istat,
16716 #endif
16717 #endif
16718 	xyzp->ianz,xyzp->coo);
16719 
16720 }
16721 
16722 #if defined(VMS) || defined(UNDERSC)
getqfr(istat)16723 void getqfr(istat)
16724 #else
16725 #ifdef CRAY
16726 void GETQFR(istat)
16727 #else
16728 void getqfr_(istat)
16729 #endif
16730 #endif
16731 int *istat;
16732 {
16733 
16734 #if defined(VMS) || defined(UNDERSC)
16735 	getqfd(istat,
16736 #else
16737 #ifdef CRAY
16738 	GETQFD(istat,
16739 #else
16740 	getqfd_(istat,
16741 #endif
16742 #endif
16743 	xyzp->coo);
16744 
16745 }
16746 
16747 #if defined(VMS) || defined(UNDERSC)
getofr(istat)16748 void getofr(istat)
16749 #else
16750 #ifdef CRAY
16751 void GETOFR(istat)
16752 #else
16753 void getofr_(istat)
16754 #endif
16755 #endif
16756 int *istat;
16757 {
16758 
16759 #if defined(VMS) || defined(UNDERSC)
16760 	getofd(istat,
16761 #else
16762 #ifdef CRAY
16763 	GETOFD(istat,
16764 #else
16765 	getofd_(istat,
16766 #endif
16767 #endif
16768 	xyzp->coo);
16769 
16770 }
16771 
16772 #if defined(VMS) || defined(UNDERSC)
getnfr(istat)16773 void getnfr(istat)
16774 #else
16775 #ifdef CRAY
16776 void GETNFR(istat)
16777 #else
16778 void getnfr_(istat)
16779 #endif
16780 #endif
16781 int *istat;
16782 {
16783 
16784 #if defined(VMS) || defined(UNDERSC)
16785 	getnfd(istat,
16786 #else
16787 #ifdef CRAY
16788 	GETNFD(istat,
16789 #else
16790 	getnfd_(istat,
16791 #endif
16792 #endif
16793 	xyzp->coo);
16794 
16795 }
16796 
16797 #if defined(VMS) || defined(UNDERSC)
egtnfr(istat)16798 void egtnfr(istat)
16799 #else
16800 #ifdef CRAY
16801 void EGTNFR(istat)
16802 #else
16803 void egtnfr_(istat)
16804 #endif
16805 #endif
16806 int *istat;
16807 {
16808 
16809 #if defined(VMS) || defined(UNDERSC)
16810 	egtnfd(istat,
16811 #else
16812 #ifdef CRAY
16813 	EGTNFD(istat,
16814 #else
16815 	egtnfd_(istat,
16816 #endif
16817 #endif
16818 	xyzp->coo);
16819 
16820 }
16821 
16822 #if defined(VMS) || defined(UNDERSC)
rotcor(b)16823 void rotcor(b)
16824 #else
16825 #ifdef CRAY
16826 void ROTCOR(b)
16827 #else
16828 void rotcor_(b)
16829 #endif
16830 #endif
16831 double *b;
16832 {
16833 
16834 #if defined(VMS) || defined(UNDERSC)
16835 	rotcod(b,
16836 #else
16837 #ifdef CRAY
16838 	ROTCOD(b,
16839 #else
16840 	rotcod_(b,
16841 #endif
16842 #endif
16843 	xyzp->coo);
16844 
16845 }
16846 
16847 #if defined(VMS) || defined(UNDERSC)
rotmom(ipoint,ifav)16848 void rotmom(ipoint,ifav)
16849 #else
16850 #ifdef CRAY
16851 void ROTMOM(ipoint,ifav)
16852 #else
16853 void rotmom_(ipoint,ifav)
16854 #endif
16855 #endif
16856 int *ipoint;
16857 int *ifav;
16858 {
16859 
16860 #if defined(VMS) || defined(UNDERSC)
16861 	rotmod(ipoint,ifav,
16862 #else
16863 #ifdef CRAY
16864 	ROTMOD(ipoint,ifav,
16865 #else
16866 	rotmod_(ipoint,ifav,
16867 #endif
16868 #endif
16869 	xyzp->coo);
16870 
16871 }
16872 
16873 #if defined(VMS) || defined(UNDERSC)
rotfir(ioxyz)16874 void rotfir(ioxyz)
16875 #else
16876 #ifdef CRAY
16877 void ROTFIR(ioxyz)
16878 #else
16879 void rotfir_(ioxyz)
16880 #endif
16881 #endif
16882 int *ioxyz;
16883 {
16884 
16885 #if defined(VMS) || defined(UNDERSC)
16886 	rotfid(ioxyz,
16887 #else
16888 #ifdef CRAY
16889 	ROTFID(ioxyz,
16890 #else
16891 	rotfid_(ioxyz,
16892 #endif
16893 #endif
16894 	xyzp->ianz,xyzp->coo);
16895 
16896 }
16897 
16898 #if defined(VMS) || defined(UNDERSC)
setorg(iatom)16899 void setorg(iatom)
16900 #else
16901 #ifdef CRAY
16902 void SETORG(iatom)
16903 #else
16904 void setorg_(iatom)
16905 #endif
16906 #endif
16907 int *iatom;
16908 {
16909 
16910 #if defined(VMS) || defined(UNDERSC)
16911 	setord(iatom,
16912 #else
16913 #ifdef CRAY
16914 	SETORD(iatom,
16915 #else
16916 	setord_(iatom,
16917 #endif
16918 #endif
16919 	rotptr->t,xyzp->coo);
16920 
16921 }
16922 
16923 #if defined(VMS) || defined(UNDERSC)
samino(istat)16924 void samino(istat)
16925 #else
16926 #ifdef CRAY
16927 void SAMINO(istat)
16928 #else
16929 void samino_(istat)
16930 #endif
16931 #endif
16932 int *istat;
16933 {
16934 
16935 #if defined(VMS) || defined(UNDERSC)
16936 	samind(istat,
16937 #else
16938 #ifdef CRAY
16939 	SAMIND(istat,
16940 #else
16941 	samind_(istat,
16942 #endif
16943 #endif
16944 	xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->ipdbt,
16945 	calfptr->icalf,&calfptr->ncalf,calfptr->iamino);
16946 
16947 }
16948 
16949 #if defined(VMS) || defined(UNDERSC)
getpdb(ires,ipdb,ihpdb)16950 void getpdb(ires,ipdb,ihpdb)
16951 #else
16952 #ifdef CRAY
16953 void GETPDB(ires,ipdb,ihpdb)
16954 #else
16955 void getpdb_(ires,ipdb,ihpdb)
16956 #endif
16957 #endif
16958 int *ires;
16959 int *ipdb;
16960 int *ihpdb;
16961 {
16962 
16963 #if defined(VMS) || defined(UNDERSC)
16964 	getpdd(ires,ipdb,ihpdb,
16965 #else
16966 #ifdef CRAY
16967 	GETPDD(ires,ipdb,ihpdb,
16968 #else
16969 	getpdd_(ires,ipdb,ihpdb,
16970 #endif
16971 #endif
16972 	xyzp->ianz,xyzp->iresid,xyzp->ipdbt);
16973 
16974 }
16975 
16976 #if defined(VMS) || defined(UNDERSC)
bckok(ibckok,ires,iop)16977 void bckok(ibckok,ires,iop)
16978 #else
16979 #ifdef CRAY
16980 void BCKOK(ibckok,ires,iop)
16981 #else
16982 void bckok_(ibckok,ires,iop)
16983 #endif
16984 #endif
16985 int *ibckok;
16986 int *ires;
16987 int *iop;
16988 {
16989 
16990 #if defined(VMS) || defined(UNDERSC)
16991 	bckod(ibckok,ires,iop,
16992 #else
16993 #ifdef CRAY
16994 	BCKOD(ibckok,ires,iop,
16995 #else
16996 	bckod_(ibckok,ires,iop,
16997 #endif
16998 #endif
16999 	xyzp->ianz,xyzp->iresid,xyzp->ipdbt,
17000 	calfptr->iamino);
17001 
17002 }
17003 
17004 #if defined(VMS) || defined(UNDERSC)
wrsrf(iun,nesp,iesp)17005 void wrsrf(iun,nesp,iesp)
17006 #else
17007 #ifdef CRAY
17008 void WRSRF(iun,nesp,iesp)
17009 #else
17010 void wrsrf_(iun,nesp,iesp)
17011 #endif
17012 #endif
17013 int *iun;
17014 int *nesp;
17015 int *iesp;
17016 {
17017 
17018 #if defined(VMS) || defined(UNDERSC)
17019 	wrsrd(iun,nesp,iesp,
17020 #else
17021 #ifdef CRAY
17022 	WRSRD(iun,nesp,iesp,
17023 #else
17024 	wrsrd_(iun,nesp,iesp,
17025 #endif
17026 #endif
17027 	xyzp->ianz,xyzp->iatclr,xyzp->iconn,xyzp->coo);
17028 
17029 }
17030 
17031 #if defined(VMS) || defined(UNDERSC)
rdsrf(iun,istats,iesp,iaddprv,idebug)17032 void rdsrf(iun,istats,iesp,iaddprv,idebug)
17033 #else
17034 #ifdef CRAY
17035 void RDSRF(iun,istats,iesp,iaddprv,idebug)
17036 #else
17037 void rdsrf_(iun,istats,iesp,iaddprv,idebug)
17038 #endif
17039 #endif
17040 int *iun;
17041 int *istats;
17042 int *iesp;
17043 int *iaddprv;
17044 int *idebug;
17045 {
17046 
17047 #if defined(VMS) || defined(UNDERSC)
17048 	rdsrd(iun,istats,iesp,iaddprv,idebug,
17049 #else
17050 #ifdef CRAY
17051 	RDSRD(iun,istats,iesp,iaddprv,idebug,
17052 #else
17053 	rdsrd_(iun,istats,iesp,iaddprv,idebug,
17054 #endif
17055 #endif
17056 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,xyzp->coo);
17057 
17058 }
17059 
17060 #if defined(VMS) || defined(UNDERSC)
srfden(x,y,z,f)17061 void srfden(x,y,z,f)
17062 #else
17063 #ifdef CRAY
17064 void SRFDEN(x,y,z,f)
17065 #else
17066 void srfden_(x,y,z,f)
17067 #endif
17068 #endif
17069 double *x;
17070 double *y;
17071 double *z;
17072 double *f;
17073 {
17074 
17075 #if defined(VMS) || defined(UNDERSC)
17076 	srfded(x,y,z,f,
17077 #else
17078 #ifdef CRAY
17079 	SRFDED(x,y,z,f,
17080 #else
17081 	srfded_(x,y,z,f,
17082 #endif
17083 #endif
17084 	xyzp->ianz,xyzp->isurf,xyzp->coo,xyzp->icont,xyzp->ncont);
17085 
17086 }
17087 
17088 #if defined(VMS) || defined(UNDERSC)
defsrf()17089 void defsrf()
17090 #else
17091 #ifdef CRAY
17092 void DEFSRF()
17093 #else
17094 void defsrf_()
17095 #endif
17096 #endif
17097 {
17098 
17099 #if defined(VMS) || defined(UNDERSC)
17100 	defsrd(
17101 #else
17102 #ifdef CRAY
17103 	DEFSRD(
17104 #else
17105 	defsrd_(
17106 #endif
17107 #endif
17108 	xyzp->isurf,xyzp->ianz,xyzp->coo);
17109 
17110 }
17111 
17112 #if defined(VMS) || defined(UNDERSC)
clrmon()17113 void clrmon()
17114 #else
17115 #ifdef CRAY
17116 void CLRMON()
17117 #else
17118 void clrmon_()
17119 #endif
17120 #endif
17121 {
17122 
17123 #if defined(VMS) || defined(UNDERSC)
17124 	clrmod(
17125 #else
17126 #ifdef CRAY
17127 	CLRMOD(
17128 #else
17129 	clrmod_(
17130 #endif
17131 #endif
17132 	xyzp->iconn);
17133 
17134 }
17135 
17136 #if defined(VMS) || defined(UNDERSC)
intcor(intc,rout,isel,inum)17137 void intcor(intc,rout,isel,inum)
17138 #else
17139 #ifdef CRAY
17140 void INTCOR(intc,rout,isel,inum)
17141 #else
17142 void intcor_(intc,rout,isel,inum)
17143 #endif
17144 #endif
17145 int *intc;
17146 short int *rout;
17147 int *isel;
17148 int *inum;
17149 {
17150 
17151 #if defined(VMS) || defined(UNDERSC)
17152 	intcod(intc,rout,isel,inum,
17153 #else
17154 #ifdef CRAY
17155 	INTCOD(intc,rout,isel,inum,
17156 #else
17157 	intcod_(intc,rout,isel,inum,
17158 #endif
17159 #endif
17160 	xyzp->coo);
17161 
17162 }
17163 
17164 #if defined(VMS) || defined(UNDERSC)
xyzcoo(idocopy,idoconv,ioadd)17165 void xyzcoo(idocopy,idoconv,ioadd)
17166 #else
17167 #ifdef CRAY
17168 void XYZCOO(idocopy,idoconv,ioadd)
17169 #else
17170 void xyzcoo_(idocopy,idoconv,ioadd)
17171 #endif
17172 #endif
17173 int *idocopy;
17174 int *idoconv;
17175 int *ioadd;
17176 {
17177 
17178 #if defined(VMS) || defined(UNDERSC)
17179 	xyzcod(idocopy,idoconv,ioadd,
17180 #else
17181 #ifdef CRAY
17182 	XYZCOD(idocopy,idoconv,ioadd,
17183 #else
17184 	xyzcod_(idocopy,idoconv,ioadd,
17185 #endif
17186 #endif
17187 	xyzp->ianz,xyzp->coo);
17188 
17189 }
17190 
17191 #if defined(VMS) || defined(UNDERSC)
wrmsf(iun)17192 void wrmsf(iun)
17193 #else
17194 #ifdef CRAY
17195 void WRMSF(iun)
17196 #else
17197 void wrmsf_(iun)
17198 #endif
17199 #endif
17200 int *iun;
17201 {
17202 
17203 #if defined(VMS) || defined(UNDERSC)
17204 	wrmsfd(iun,
17205 #else
17206 #ifdef CRAY
17207 	WRMSFD(iun,
17208 #else
17209 	wrmsfd_(iun,
17210 #endif
17211 #endif
17212 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,
17213 	xyzp->iconn,xyzp->lring,xyzp->ityp,&cell->natc,&cell->nspg,&cell->ichx,
17214 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17215 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17216 
17217 
17218 }
17219 
17220 #if defined(VMS) || defined(UNDERSC)
wrtnk(iun)17221 void wrtnk(iun)
17222 #else
17223 #ifdef CRAY
17224 void WRTNK(iun)
17225 #else
17226 void wrtnk_(iun)
17227 #endif
17228 #endif
17229 int *iun;
17230 {
17231 
17232 #if defined(VMS) || defined(UNDERSC)
17233 	wrtnd(iun,
17234 #else
17235 #ifdef CRAY
17236 	WRTND(iun,
17237 #else
17238 	wrtnd_(iun,
17239 #endif
17240 #endif
17241 	xyzp->ianz,xyzp->iaton,xyzp->iconn,xyzp->lring,xyzp->ityp,xyzp->coo);
17242 
17243 }
17244 
17245 #if defined(VMS) || defined(UNDERSC)
wrgff(iun)17246 void wrgff(iun)
17247 #else
17248 #ifdef CRAY
17249 void WRGFF(iun)
17250 #else
17251 void wrgff_(iun)
17252 #endif
17253 #endif
17254 int *iun;
17255 {
17256 
17257 #if defined(VMS) || defined(UNDERSC)
17258 	wrgfd(iun,
17259 #else
17260 #ifdef CRAY
17261 	WRGFD(iun,
17262 #else
17263 	wrgfd_(iun,
17264 #endif
17265 #endif
17266 	xyzp->ianz,xyzp->iaton,xyzp->iconn,xyzp->isurf,xyzp->lring,
17267 	xyzp->lwrit,&calfptr->ncalf,&calfptr->ishoh,
17268 	xyzp->iresid,xyzp->ityp,xyzp->coo,xyzp->qat,
17269 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
17270 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
17271 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17272 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17273 
17274 }
17275 
17276 #if defined(VMS) || defined(UNDERSC)
wrogl(iun)17277 void wrogl(iun)
17278 #else
17279 #ifdef CRAY
17280 void WROGL(iun)
17281 #else
17282 void wrogl_(iun)
17283 #endif
17284 #endif
17285 int *iun;
17286 {
17287 
17288 #if defined(VMS) || defined(UNDERSC)
17289 	wrogd(iun,
17290 #else
17291 #ifdef CRAY
17292 	WROGD(iun,
17293 #else
17294 	wrogd_(iun,
17295 #endif
17296 #endif
17297 	rotptr->rx,rotptr->ry,rotptr->rz,
17298 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,
17299 	xyzp->lring,xyzp->coo,xyzp->rzp,calfptr->reson,
17300 	calfptr->ianf,&calfptr->nchain,&calfptr->ncalf);
17301 
17302 }
17303 
17304 #if defined(VMS) || defined(UNDERSC)
getnat(natoms)17305 void getnat(natoms)
17306 #else
17307 #ifdef CRAY
17308 void GETNAT(natoms)
17309 #else
17310 void getnat_(natoms)
17311 #endif
17312 #endif
17313 int *natoms;
17314 {
17315    int i;
17316 
17317 /*
17318    *natoms = 0;
17319    for (i=0; i < *xyzp->iatoms; i++ )
17320 	if (xyzp->ianz[i] < 100 && xyzp->ianz[i] > 0) (*natoms)++;
17321 */
17322 
17323    *natoms = *xyzp->iatoms;
17324    for (i=*xyzp->iatoms-1; i >= 0; i-- )
17325 	if (xyzp->ianz[i] < 100 && xyzp->ianz[i] > 0) {
17326 	    *natoms = i;
17327             (*natoms)++;
17328 	    break;
17329 	}
17330 }
17331 
17332 #if defined(VMS) || defined(UNDERSC)
allon(ntota,nwat,nion,nsign,newat,nresi)17333 void allon(ntota,nwat,nion,nsign,newat,nresi)
17334 #else
17335 #ifdef CRAY
17336 void ALLON(ntota,nwat,nion,nsign,newat,nresi)
17337 #else
17338 void allon_(ntota,nwat,nion,nsign,newat,nresi)
17339 #endif
17340 #endif
17341 int *ntota;
17342 int *nwat;
17343 int *nion;
17344 int *nsign;
17345 int *newat;
17346 int *nresi;
17347 {
17348    int i,j,iwat,nwater,iall,nions,ires;
17349 
17350    if ( *nion == -1) {
17351 	nions = 0;
17352 	nwater = (*newat - *nwat);
17353    } else {
17354 	nions = (*newat - *nion + 1);
17355 	nwater = (*nion - *nwat);
17356    }
17357    iall = nwater + nions + 8;
17358    nwater = nwater/3;
17359 
17360    if (*newat > *xyzp->mxnat)  {
17361 #if defined(VMS) || defined(UNDERSC)
17362 	allcoo(&iall,&ZERO);
17363 #else
17364 #ifdef CRAY
17365 	ALLCOO(&iall,&ZERO);
17366 #else
17367 	allcoo_(&iall,&ZERO);
17368 #endif
17369 #endif
17370    }
17371 
17372 
17373    *xyzp->iatoms = *newat;
17374 
17375    if (hetptr.NHetAtm == 0) {
17376 	hetptr.Allocated[0] = 1;
17377 	hetptr.HetAtm[0] = (char *) malloc(6);
17378 	strcpy(hetptr.HetAtm[0],"Helix");
17379 	hetptr.Allocated[1] = 1;
17380 	hetptr.HetAtm[1] = (char *) malloc(5);
17381 	strcpy(hetptr.HetAtm[1],"Beta");
17382 	hetptr.Allocated[2] = 1;
17383 	hetptr.HetAtm[2] = (char *) malloc(8);
17384 	strcpy(hetptr.HetAtm[2],"RNA/DNA");
17385 	hetptr.Allocated[3] = 1;
17386 	hetptr.HetAtm[3] = (char *) malloc(5);
17387 	strcpy(hetptr.HetAtm[3],"coil");
17388 	hetptr.NHetAtm = 4;
17389    }
17390 /*   if (hetptr.NHetAtm < 4) hetptr.NHetAtm = 4;*/
17391 
17392    cellpnt->iclon = 1;
17393 
17394    ires = *nresi -1;
17395    if (ires > 0) ires = -4;
17396 
17397    hetptr.Allocated[hetptr.NHetAtm] = 1;
17398    hetptr.HetAtm[hetptr.NHetAtm] = (char *) malloc(4);
17399    strcpy(hetptr.HetAtm[hetptr.NHetAtm],"HOH");
17400    hetptr.NHetAtm++;
17401 
17402    if (calfptr->ishoh == 0) calfptr->ishoh = abs(ires);
17403 
17404    for (i=0; i < nwater; i++ ) {
17405         iwat = *ntota + 3*i;
17406 
17407 	xyzp->ianz[iwat] = 8;
17408 	xyzp->ityp[iwat] = 649;
17409 	xyzp->qat[iwat] = -0.834;
17410 	xyzp->iaton[iwat] = 1;
17411 	xyzp->iatclr[iwat] = 1;
17412 	xyzp->iresid[iwat] = ires;
17413 	xyzp->iconn[iwat*(MXCON+1)] = 2;
17414 	xyzp->iconn[iwat*(MXCON+1)+1] = (iwat+1)+1;
17415 	xyzp->iconn[iwat*(MXCON+1)+2] = (iwat+2)+1;
17416 
17417 	xyzp->ianz[iwat+1] = 1;
17418 	xyzp->ityp[iwat+1] = 650;
17419 	xyzp->qat[iwat+1] = 0.471;
17420 	xyzp->iaton[iwat+1] = 1;
17421 	xyzp->iatclr[iwat+1] = 1;
17422 	xyzp->iresid[iwat+1] = ires;
17423 	xyzp->iconn[(iwat+1)*(MXCON+1)] = 1;
17424 	xyzp->iconn[(iwat+1)*(MXCON+1)+1] = (iwat)+1;
17425 
17426 	xyzp->ianz[iwat+2] = 1;
17427 	xyzp->ityp[iwat+2] = 650;
17428 	xyzp->qat[iwat+2] = 0.471;
17429 	xyzp->iaton[iwat+2] = 1;
17430 	xyzp->iatclr[iwat+2] = 1;
17431 	xyzp->iresid[iwat+2] = ires;
17432 	xyzp->iconn[(iwat+2)*(MXCON+1)] = 1;
17433 	xyzp->iconn[(iwat+2)*(MXCON+1)+1] = (iwat)+1;
17434 
17435 	ires--;
17436 
17437    }
17438 
17439    if (nions > 0) {
17440 	calfptr->ision = ires;
17441 	hetptr.Allocated[hetptr.NHetAtm] = 1;
17442 	hetptr.HetAtm[hetptr.NHetAtm] = (char *) malloc(5);
17443 	strcpy(hetptr.HetAtm[hetptr.NHetAtm],"ions");
17444 	hetptr.NHetAtm++;
17445    } else calfptr->ision = 10000;
17446 
17447    for (i=0; i < nions; i++ ) {
17448         iwat = *ntota + nwater*3 + i;
17449 
17450 	if (*nsign) {
17451 	   xyzp->ianz[iwat] = 17;
17452 	   xyzp->ityp[iwat] = 659;
17453 	   xyzp->qat[iwat] =  -1.0;
17454 	} else {
17455 	   xyzp->ianz[iwat] = 11;
17456 	   xyzp->ityp[iwat] = 652;
17457 	   xyzp->qat[iwat] =  1.0;
17458 	}
17459 	xyzp->iaton[iwat] = 1;
17460 	xyzp->iatclr[iwat] = 1;
17461 	xyzp->iresid[iwat] = ires;
17462 	xyzp->iconn[iwat*(MXCON+1)] = 0;
17463 
17464 	ires--;
17465 
17466    }
17467 
17468  /*  hetptr.NHetAtm++;*/
17469 
17470    *xyzp->iatoms = *ntota + iall;
17471    for (i=0; i < 8; i++ ) {
17472         iwat = *ntota + nwater*3 + nions + i;
17473 	xyzp->iaton[iwat] = 1;
17474 	xyzp->ianz[iwat] = 100;
17475 	xyzp->iresid[iwat] = 0;
17476 	xyzp->lwrit[iwat] = 1;
17477 
17478    }
17479 
17480 
17481 }
17482 
17483 #if defined(VMS) || defined(UNDERSC)
upajob()17484 void upajob()
17485 #else
17486 #ifdef CRAY
17487 void UPAJOB()
17488 #else
17489 void upajob_()
17490 #endif
17491 #endif
17492 {
17493    if (ATMup) RedrawATM();
17494    if (TNKup) RedrawTNK();
17495    RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
17496 }
17497 
17498 #if defined(VMS) || defined(UNDERSC)
rdbin(iun,heat)17499 void rdbin(iun,heat)
17500 #else
17501 #ifdef CRAY
17502 void RDBIN(iun,heat)
17503 #else
17504 void rdbin_(iun,heat)
17505 #endif
17506 #endif
17507 int *iun;
17508 double *heat;
17509 {
17510 #if defined(VMS) || defined(UNDERSC)
17511 	rdbid(iun,heat,
17512 #else
17513 #ifdef CRAY
17514 	RDBID(iun,heat,
17515 #else
17516 	rdbid_(iun,heat,
17517 #endif
17518 #endif
17519 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
17520 	xyzp->lring, &cell->natc,&cell->norg,
17521 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
17522 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
17523 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17524 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17525 }
17526 
17527 #if defined(VMS) || defined(UNDERSC)
gettyp(ires,iat1,iat2)17528 void gettyp(ires,iat1,iat2)
17529 #else
17530 #ifdef CRAY
17531 void GETTYP(ires,iat1,iat2)
17532 #else
17533 void gettyp_(ires,iat1,iat2)
17534 #endif
17535 #endif
17536 int *ires;
17537 int *iat1;
17538 int *iat2;
17539 {
17540 #if defined(VMS) || defined(UNDERSC)
17541 	gettyd(ires,iat1,iat2,
17542 #else
17543 #ifdef CRAY
17544 	GETTYD(ires,iat1,iat2,
17545 #else
17546 	gettyd_(ires,iat1,iat2,
17547 #endif
17548 #endif
17549 	xyzp->ityp,xyzp->ipdbt,xyzp->ianz,xyzp->iresid,
17550 	calfptr->iamino,calfptr->icalf,&calfptr->ncalf);
17551 }
17552 
17553 #if defined(VMS) || defined(UNDERSC)
chkbrk()17554 void chkbrk()
17555 #else
17556 #ifdef CRAY
17557 void CHKBRK()
17558 #else
17559 void chkbrk_()
17560 #endif
17561 #endif
17562 {
17563 #if defined(VMS) || defined(UNDERSC)
17564 	chkbrd(
17565 #else
17566 #ifdef CRAY
17567 	CHKBRD(
17568 #else
17569 	chkbrd_(
17570 #endif
17571 #endif
17572 	xyzp->iconn,calfptr->icalf,calfptr->ianf,calfptr->islu,
17573 	calfptr->iamino,calfptr->isal,calfptr->reson,
17574 	&calfptr->ncalf,&calfptr->nchain);
17575 }
17576 
17577 #if defined(VMS) || defined(UNDERSC)
gettnk(igttnk,idebug,ipdbon,iffset,iheat,heat)17578 void gettnk(igttnk,idebug,ipdbon,iffset,iheat,heat)
17579 #else
17580 #ifdef CRAY
17581 void GETTNK(igttnk,idebug,ipdbon,iffset,iheat,heat)
17582 #else
17583 void gettnk_(igttnk,idebug,ipdbon,iffset,iheat,heat)
17584 #endif
17585 #endif
17586 int *igttnk;
17587 int *idebug;
17588 int *ipdbon;
17589 int *iffset;
17590 int *iheat;
17591 double *heat;
17592 {
17593 
17594 	int i;
17595 
17596 #if defined(VMS) || defined(UNDERSC)
17597 	gettnd(igttnk,idebug,ipdbon,iffset,iheat,heat,
17598 #else
17599 #ifdef CRAY
17600 	GETTND(igttnk,idebug,ipdbon,iffset,iheat,heat,
17601 #else
17602 	gettnd_(igttnk,idebug,ipdbon,iffset,iheat,heat,
17603 #endif
17604 #endif
17605 	xyzp->ianz,xyzp->iconn,xyzp->iatclr,xyzp->ityp,xyzp->coo,xyzp->qat,
17606 	xyzp->isurf,&calfptr->issdon,&cellpnt->iclon,&cell->ichx,
17607 	&calfptr->ishoh,&calfptr->ision,&cell->nspg,&cell->natc,&cell->norg,
17608 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
17609 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
17610 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17611 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17612 
17613 	if (*igttnk == -1) {
17614 #if defined(VMS) || defined(UNDERSC)
17615 	   allcoo(&addat,&ZERO);
17616 	   gettnd(igttnk,idebug,ipdbon,iffset,iheat,heat,
17617 #else
17618 #ifdef CRAY
17619 	   ALLCOO(&addat,&ZERO);
17620 	   GETTND(igttnk,idebug,ipdbon,iffset,iheat,heat,
17621 #else
17622 	   allcoo_(&addat,&ZERO);
17623 	   gettnd_(igttnk,idebug,ipdbon,iffset,iheat,heat,
17624 #endif
17625 #endif
17626 	   xyzp->ianz,xyzp->iconn,xyzp->iatclr,xyzp->ityp,xyzp->coo,xyzp->qat,
17627 	   xyzp->isurf,&calfptr->issdon,&cellpnt->iclon,&cell->ichx,
17628 	   &calfptr->ishoh,&calfptr->ision,&cell->nspg,&cell->natc,&cell->norg,
17629 	   &cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
17630 	   &cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
17631 	   &cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17632 	   &cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17633         }
17634 	COO[istruct]->icst = *icst;
17635 	for (i=0; i<*xyzp->iatoms; i++) {
17636 	   if (xyzp->isurf[i] != 1) *icst = 1;
17637 	}
17638 }
17639 
17640 #if defined(VMS) || defined(UNDERSC)
tnkfst(igttnk,idebug,ialloc)17641 void tnkfst(igttnk,idebug,ialloc)
17642 #else
17643 #ifdef CRAY
17644 void TNKFST(igttnk,idebug,ialloc)
17645 #else
17646 void tnkfst_(igttnk,idebug,ialloc)
17647 #endif
17648 #endif
17649 int *igttnk;
17650 int *idebug;
17651 int *ialloc;
17652 {
17653 
17654 
17655 #if defined(VMS) || defined(UNDERSC)
17656 	tnkfsd(igttnk,idebug,ialloc,
17657 #else
17658 #ifdef CRAY
17659 	TNKFSD(igttnk,idebug,ialloc,
17660 #else
17661 	tnkfsd_(igttnk,idebug,ialloc,
17662 #endif
17663 #endif
17664 	xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
17665 	xyzp->lring,&cell->ichx,
17666 	&cell->natc,&cell->norg,
17667 	&cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
17668 	&cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
17669 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17670 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17671 
17672 	if (*igttnk == -1) {
17673 #if defined(VMS) || defined(UNDERSC)
17674 	   allcoo(&addat,&ZERO);
17675 	   tnkfsd(igttnk,idebug,ialloc,
17676 #else
17677 #ifdef CRAY
17678 	   ALLCOO(&addat,&ZERO);
17679 	   TNKFSD(igttnk,idebug,ialloc,
17680 #else
17681 	   allcoo_(&addat,&ZERO);
17682 	   tnkfsd_(igttnk,idebug,ialloc,
17683 #endif
17684 #endif
17685 	   xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
17686 	   xyzp->lring,&cell->ichx,
17687 	   &cell->natc,&cell->norg,
17688 	   &cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
17689 	   &cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
17690 	   &cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17691 	   &cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17692         }
17693 }
17694 
17695 #if defined(VMS) || defined(UNDERSC)
dotyp(icel)17696 void dotyp(icel)
17697 #else
17698 #ifdef CRAY
17699 void DOTYP(icel)
17700 #else
17701 void dotyp_(icel)
17702 #endif
17703 #endif
17704 int *icel;
17705 {
17706 
17707 #if defined(VMS) || defined(UNDERSC)
17708 	dotyd(icel,
17709 #else
17710 #ifdef CRAY
17711 	DOTYD(icel,
17712 #else
17713 	dotyd_(icel,
17714 #endif
17715 #endif
17716 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iconn,xyzp->iresid,
17717 	xyzp->lwrit,xyzp->lring,xyzp->ityp,xyzp->coo,xyzp->qat,xyzp->icont,
17718 	calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
17719 	&calfptr->nchain,calfptr->iamino,&calfptr->ishoh,
17720 	&cell->natc,
17721 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
17722 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
17723 
17724 }
17725 
17726 #if defined(VMS) || defined(UNDERSC)
chkcoo(kcoo,kcooh)17727 void chkcoo(kcoo,kcooh)
17728 #else
17729 #ifdef CRAY
17730 void CHKCOO(kcoo,kcooh)
17731 #else
17732 void chkcoo_(kcoo,kcooh)
17733 #endif
17734 #endif
17735 int *kcoo;
17736 int *kcooh;
17737 {
17738 
17739 #if defined(VMS) || defined(UNDERSC)
17740 	chkcod(kcoo,kcooh,
17741 #else
17742 #ifdef CRAY
17743 	CHKCOD(kcoo,kcooh,
17744 #else
17745 	chkcod_(kcoo,kcooh,
17746 #endif
17747 #endif
17748 	xyzp->ianz,xyzp->iconn);
17749 }
17750 
17751 #if defined(VMS) || defined(UNDERSC)
espfit(idip,nesp,esp,connl,dx,dy,dz,iz,dmachg,ichadd)17752 void espfit(idip,nesp,esp,connl,dx,dy,dz,iz,dmachg,ichadd)
17753 #else
17754 #ifdef CRAY
17755 void ESPFIT(idip,nesp,esp,connl,dx,dy,dz,iz,dmachg,ichadd)
17756 #else
17757 void espfit_(idip,nesp,esp,connl,dx,dy,dz,iz,dmachg,ichadd)
17758 #endif
17759 #endif
17760 int *idip;
17761 int *nesp;
17762 double *esp;
17763 double *connl;
17764 double *dx;
17765 double *dy;
17766 double *dz;
17767 int *iz;
17768 int *dmachg;
17769 int *ichadd;
17770 {
17771 
17772 #if defined(VMS) || defined(UNDERSC)
17773 	espfid(idip,nesp,esp,connl,dx,dy,dz,iz,dmachg,ichadd,
17774 #else
17775 #ifdef CRAY
17776 	ESPFID(idip,nesp,esp,connl,dx,dy,dz,iz,dmachg,ichadd,
17777 #else
17778 	espfid_(idip,nesp,esp,connl,dx,dy,dz,iz,dmachg,ichadd,
17779 #endif
17780 #endif
17781 	xyzp->qat);
17782 
17783 }
17784 
17785 #if defined(VMS) || defined(UNDERSC)
allzmt(ipdbon)17786 void allzmt(ipdbon)
17787 #else
17788 #ifdef CRAY
17789 void ALLZMT(ipdbon)
17790 #else
17791 void allzmt_(ipdbon)
17792 #endif
17793 #endif
17794 int *ipdbon;
17795 {
17796 
17797 #if defined(VMS) || defined(UNDERSC)
17798 	allzmd(ipdbon,
17799 #else
17800 #ifdef CRAY
17801 	ALLZMD(ipdbon,
17802 #else
17803 	allzmd_(ipdbon,
17804 #endif
17805 #endif
17806 	xyzp->ianz,xyzp->iaton,xyzp->coo);
17807 
17808 }
17809 
17810 #if defined(VMS) || defined(UNDERSC)
ligzmt()17811 void ligzmt()
17812 #else
17813 #ifdef CRAY
17814 void LIGZMT()
17815 #else
17816 void ligzmt_()
17817 #endif
17818 #endif
17819 {
17820 
17821 #if defined(VMS) || defined(UNDERSC)
17822 	ligzmd(
17823 #else
17824 #ifdef CRAY
17825 	LIGZMD(
17826 #else
17827 	ligzmd_(
17828 #endif
17829 #endif
17830 	xyzp->ianz,xyzp->iaton);
17831 
17832 }
17833 
17834 #if defined(VMS) || defined(UNDERSC)
pdbzmt()17835 void pdbzmt()
17836 #else
17837 #ifdef CRAY
17838 void PDBZMT()
17839 #else
17840 void pdbzmt_()
17841 #endif
17842 #endif
17843 {
17844 
17845 #if defined(VMS) || defined(UNDERSC)
17846 	pdbzmd(
17847 #else
17848 #ifdef CRAY
17849 	PDBZMD(
17850 #else
17851 	pdbzmd_(
17852 #endif
17853 #endif
17854 	xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn,
17855 	&calfptr->ishoh);
17856 	clfstrptr->ihashz = 0;
17857 
17858 }
17859 
17860 #if defined(VMS) || defined(UNDERSC)
haswat(ino)17861 void haswat(ino)
17862 #else
17863 #ifdef CRAY
17864 void HASWAT(ino)
17865 #else
17866 void haswat_(ino)
17867 #endif
17868 #endif
17869 int *ino;
17870 {
17871 
17872 #if defined(VMS) || defined(UNDERSC)
17873 	haswad(ino,
17874 #else
17875 #ifdef CRAY
17876 	HASWAD(ino,
17877 #else
17878 	haswad_(ino,
17879 #endif
17880 #endif
17881 	xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn);
17882 
17883 }
17884 
17885 #if defined(VMS) || defined(UNDERSC)
intzmt(ispdb)17886 void intzmt(ispdb)
17887 #else
17888 #ifdef CRAY
17889 void INTZMT(ispdb)
17890 #else
17891 void intzmt_(ispdb)
17892 #endif
17893 #endif
17894 int *ispdb;
17895 {
17896 
17897 #if defined(VMS) || defined(UNDERSC)
17898 	intzmd(ispdb,
17899 #else
17900 #ifdef CRAY
17901 	INTZMD(ispdb,
17902 #else
17903 	intzmd_(ispdb,
17904 #endif
17905 #endif
17906 	xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn,
17907 	xyzp->lwrit,xyzp->lring,
17908 	calfptr->icalf,calfptr->ianf,calfptr->islu,
17909 	&calfptr->nchain,calfptr->iamino);
17910 
17911 }
17912 
17913 #if defined(VMS) || defined(UNDERSC)
icrcon(icrcon,isel,idisc,ndisc,nanz,ispdb)17914 void icrcon(icrcon,isel,idisc,ndisc,nanz,ispdb)
17915 #else
17916 #ifdef CRAY
17917 void ICRCON(icrcon,isel,idisc,ndisc,nanz,ispdb)
17918 #else
17919 void icrcon_(icrcon,isel,idisc,ndisc,nanz,ispdb)
17920 #endif
17921 #endif
17922 int *icrcon;
17923 int *isel;
17924 int *idisc;
17925 int *ndisc;
17926 int *nanz;
17927 int *ispdb;
17928 {
17929 
17930 #if defined(VMS) || defined(UNDERSC)
17931 	icrcod(icrcon,isel,idisc,ndisc,nanz,ispdb,
17932 #else
17933 #ifdef CRAY
17934 	ICRCOD(icrcon,isel,idisc,ndisc,nanz,ispdb,
17935 #else
17936 	icrcod_(icrcon,isel,idisc,ndisc,nanz,ispdb,
17937 #endif
17938 #endif
17939 	xyzp->ianz,xyzp->iaton,xyzp->iconn,xyzp->lwrit,xyzp->coo,
17940 	calfptr->icalf,&calfptr->ncalf);
17941 
17942 }
17943 
17944 #if defined(VMS) || defined(UNDERSC)
calcx(ical,isel,nx)17945 void calcx(ical,isel,nx)
17946 #else
17947 #ifdef CRAY
17948 void CALCX(ical,isel,nx)
17949 #else
17950 void calcx_(ical,isel,nx)
17951 #endif
17952 #endif
17953 int *ical;
17954 int *isel;
17955 int *nx;
17956 {
17957 
17958 #if defined(VMS) || defined(UNDERSC)
17959 	calcd(ical,isel,nx,
17960 #else
17961 #ifdef CRAY
17962 	CALCD(ical,isel,nx,
17963 #else
17964 	calcd_(ical,isel,nx,
17965 #endif
17966 #endif
17967 	xyzp->ianz,xyzp->iaton,xyzp->iconn,xyzp->coo);
17968 
17969 }
17970 
17971 #if defined(VMS) || defined(UNDERSC)
prelea(iprel,ilead,isel,ispdb,ithree)17972 void prelea(iprel,ilead,isel,ispdb,ithree)
17973 #else
17974 #ifdef CRAY
17975 void PRELEA(iprel,ilead,isel,ispdb,ithree)
17976 #else
17977 void prelea_(iprel,ilead,isel,ispdb,ithree)
17978 #endif
17979 #endif
17980 int *iprel;
17981 int *ilead;
17982 int *isel;
17983 int *ispdb;
17984 int *ithree;
17985 {
17986 
17987 #if defined(VMS) || defined(UNDERSC)
17988 	prelead(iprel,ilead,isel,ispdb,ithree,
17989 #else
17990 #ifdef CRAY
17991 	PRELEAD(iprel,ilead,isel,ispdb,ithree,
17992 #else
17993 	prelead_(iprel,ilead,isel,ispdb,ithree,
17994 #endif
17995 #endif
17996 	xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn,xyzp->lwrit);
17997 
17998 }
17999 
18000 #if defined(VMS) || defined(UNDERSC)
preleh(iprel,ilead,isel,ispdb,ithree)18001 void preleh(iprel,ilead,isel,ispdb,ithree)
18002 #else
18003 #ifdef CRAY
18004 void PRELEH(iprel,ilead,isel,ispdb,ithree)
18005 #else
18006 void preleh_(iprel,ilead,isel,ispdb,ithree)
18007 #endif
18008 #endif
18009 int *iprel;
18010 int *ilead;
18011 int *isel;
18012 int *ispdb;
18013 int *ithree;
18014 {
18015 
18016 #if defined(VMS) || defined(UNDERSC)
18017 	prelehd(iprel,ilead,isel,ispdb,ithree,
18018 #else
18019 #ifdef CRAY
18020 	PRELEHD(iprel,ilead,isel,ispdb,ithree,
18021 #else
18022 	prelehd_(iprel,ilead,isel,ispdb,ithree,
18023 #endif
18024 #endif
18025 	xyzp->ianz,xyzp->iaton,xyzp->iresid,xyzp->iconn,xyzp->lwrit);
18026 
18027 }
18028 
18029 #if defined(VMS) || defined(UNDERSC)
rdbas(idebug,dfree,istats)18030 void rdbas(idebug,dfree,istats)
18031 #else
18032 #ifdef CRAY
18033 void RDBAS(idebug,dfree,istats)
18034 #else
18035 void rdbas_(idebug,dfree,istats)
18036 #endif
18037 #endif
18038 int *idebug;
18039 int *dfree;
18040 int *istats;
18041 {
18042 
18043 #if defined(VMS) || defined(UNDERSC)
18044 	rdbad(idebug,dfree,istats,
18045 #else
18046 #ifdef CRAY
18047 	RDBAD(idebug,dfree,istats,
18048 #else
18049 	rdbad_(idebug,dfree,istats,
18050 #endif
18051 #endif
18052 	xyzp->ityp);
18053 
18054 }
18055 
18056 #if defined(VMS) || defined(UNDERSC)
setis(nset,istart)18057 void setis(nset,istart)
18058 #else
18059 #ifdef CRAY
18060 void SETIS(nset,istart)
18061 #else
18062 void setis_(nset,istart)
18063 #endif
18064 #endif
18065 int *nset;
18066 int *istart;
18067 {
18068 
18069 #if defined(VMS) || defined(UNDERSC)
18070 	setid(nset,istart,
18071 #else
18072 #ifdef CRAY
18073 	SETID(nset,istart,
18074 #else
18075 	setid_(nset,istart,
18076 #endif
18077 #endif
18078 	xyzp->isurf,xyzp->iresid,xyzp->ipdbt);
18079 
18080 }
18081 
18082 #if defined(VMS) || defined(UNDERSC)
clkbck(istsurf,incp,ifogl)18083 void clkbck(istsurf,incp,ifogl)
18084 #else
18085 #ifdef CRAY
18086 void CLKBCK(istsurf,incp,ifogl)
18087 #else
18088 void clkbck_(istsurf,incp,ifogl)
18089 #endif
18090 #endif
18091 int *istsurf;
18092 int *incp;
18093 int *ifogl;
18094 {
18095 
18096 #if defined(VMS) || defined(UNDERSC)
18097 	clkbcd(istsurf,incp,ifogl,
18098 #else
18099 #ifdef CRAY
18100 	CLKBCD(istsurf,incp,ifogl,
18101 #else
18102 	clkbcd_(istsurf,incp,ifogl,
18103 #endif
18104 #endif
18105 	xyzp->iresid,xyzp->coo,
18106 	calfptr->icalf,&calfptr->ncalf,calfptr->reson);
18107 
18108 }
18109 
18110 #if defined(VMS) || defined(UNDERSC)
newfil(idebug,istat,inc,ioadd,ioatms,nstrt,namols,nxtmf,ipdbon,namls,iof)18111 void newfil(idebug,istat,inc,ioadd,ioatms,nstrt,namols,nxtmf,ipdbon,namls,iof)
18112 #else
18113 #ifdef CRAY
18114 void NEWFIL(idebug,istat,inc,ioadd,ioatms,nstrt,namols,nxtmf,ipdbon,namls,iof)
18115 #else
18116 void newfil_(idebug,istat,inc,ioadd,ioatms,nstrt,namols,nxtmf,ipdbon,namls,iof)
18117 #endif
18118 #endif
18119 int *idebug;
18120 int *istat;
18121 int *inc;
18122 int *ioadd;
18123 int *ioatms;
18124 int *nstrt;
18125 int *namols;
18126 int *nxtmf;
18127 int *ipdbon;
18128 int *namls;
18129 int *iof;
18130 {
18131 
18132 #if defined(VMS) || defined(UNDERSC)
18133 	newfid(idebug,istat,inc,ioadd,ioatms,nstrt,namols,nxtmf,ipdbon,namls,iof,
18134 #else
18135 #ifdef CRAY
18136 	NEWFID(idebug,istat,inc,ioadd,ioatms,nstrt,namols,nxtmf,ipdbon,namls,iof,
18137 #else
18138 	newfid_(idebug,istat,inc,ioadd,ioatms,nstrt,namols,nxtmf,ipdbon,namls,iof,
18139 #endif
18140 #endif
18141 	xyzp->iaton,xyzp->iatclr,xyzp->iresid,
18142 	&calfptr->ncalf);
18143 
18144 }
18145 
18146 #if defined(VMS) || defined(UNDERSC)
acthlp(iop1,iop2,iop3)18147 void acthlp(iop1,iop2,iop3)
18148 #else
18149 #ifdef CRAY
18150 void ACTHLP(iop1,iop2,iop3)
18151 #else
18152 void acthlp_(iop1,iop2,iop3)
18153 #endif
18154 #endif
18155 int *iop1;
18156 int *iop2;
18157 int *iop3;
18158 {
18159 
18160 #if defined(VMS) || defined(UNDERSC)
18161 	acthld(iop1,iop2,iop3,
18162 #else
18163 #ifdef CRAY
18164 	ACTHLD(iop1,iop2,iop3,
18165 #else
18166 	acthld_(iop1,iop2,iop3,
18167 #endif
18168 #endif
18169 	calfptr->ihet);
18170 
18171 }
18172 
18173 #if defined(VMS) || defined(UNDERSC)
acttog(iop1,iop2,iop3)18174 void acttog(iop1,iop2,iop3)
18175 #else
18176 #ifdef CRAY
18177 void ACTTOG(iop1,iop2,iop3)
18178 #else
18179 void acttog_(iop1,iop2,iop3)
18180 #endif
18181 #endif
18182 int *iop1;
18183 int *iop2;
18184 int *iop3;
18185 {
18186 
18187 #if defined(VMS) || defined(UNDERSC)
18188 	acttod(iop1,iop2,iop3,
18189 #else
18190 #ifdef CRAY
18191 	ACTTOD(iop1,iop2,iop3,
18192 #else
18193 	acttod_(iop1,iop2,iop3,
18194 #endif
18195 #endif
18196 	calfptr->ihet);
18197 
18198 }
18199 
18200 #if defined(VMS) || defined(UNDERSC)
acttag(iop1,iop2,iop3)18201 void acttag(iop1,iop2,iop3)
18202 #else
18203 #ifdef CRAY
18204 void ACTTAG(iop1,iop2,iop3)
18205 #else
18206 void acttag_(iop1,iop2,iop3)
18207 #endif
18208 #endif
18209 int *iop1;
18210 int *iop2;
18211 int *iop3;
18212 {
18213 
18214 #if defined(VMS) || defined(UNDERSC)
18215 	acttad(iop1,iop2,iop3,
18216 #else
18217 #ifdef CRAY
18218 	ACTTAD(iop1,iop2,iop3,
18219 #else
18220 	acttad_(iop1,iop2,iop3,
18221 #endif
18222 #endif
18223 	calfptr->ihet,&calfptr->ision);
18224 
18225 }
18226 
18227 #if defined(VMS) || defined(UNDERSC)
setarr(iop,iopval,ioatms)18228 void setarr(iop,iopval,ioatms)
18229 #else
18230 #ifdef CRAY
18231 void SETARR(iop,iopval,ioatms)
18232 #else
18233 void setarr_(iop,iopval,ioatms)
18234 #endif
18235 #endif
18236 int *iop;
18237 int *iopval;
18238 int *ioatms;
18239 {
18240 
18241 #if defined(VMS) || defined(UNDERSC)
18242 	setard(iop,iopval,ioatms,
18243 #else
18244 #ifdef CRAY
18245 	SETARD(iop,iopval,ioatms,
18246 #else
18247 	setard_(iop,iopval,ioatms,
18248 #endif
18249 #endif
18250 	xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iresid,xyzp->iconn,xyzp->qat,
18251 	calfptr->ihet,calfptr->iclhet,calfptr->reson,calfptr->lab,
18252 	clfstrptr->labhet,&clfstrptr->ilcset,clfstrptr->ligcat,calfptr->iams,
18253 	calfptr->ihets,calfptr->irsnr,&calfptr->ncalf,&calfptr->issdon,
18254 	&scalptr->scal,&scalptr->scali,&scalptr->fscal,&scalptr->smag,
18255 	&posptr->xv,&posptr->yv,&posptr->zv,&posptr->pincr,
18256 	&cell->natc,&cell->ichx,&cell->icrtp,
18257 	&pnt->ipoints,&geo1ptr->ngeoms);
18258 
18259 }
18260 
18261 #if defined(VMS) || defined(UNDERSC)
epvrml(vdwr,moddma,natoms,norbs,idops)18262 void epvrml(vdwr,moddma,natoms,norbs,idops)
18263 #else
18264 #ifdef CRAY
18265 void EPVRML(vdwr,moddma,natoms,norbs,idops)
18266 #else
18267 void epvrml_(vdwr,moddma,natoms,norbs,idops)
18268 #endif
18269 #endif
18270 double *vdwr;
18271 int *moddma;
18272 int *natoms;
18273 int *norbs;
18274 int *idops;
18275 {
18276 
18277 #if defined(VMS) || defined(UNDERSC)
18278 	epvrmd(vdwr,moddma,natoms,norbs,idops,
18279 #else
18280 #ifdef CRAY
18281 	EPVRMD(vdwr,moddma,natoms,norbs,idops,
18282 #else
18283 	epvrmd_(vdwr,moddma,natoms,norbs,idops,
18284 #endif
18285 #endif
18286 	xyzp->iaton);
18287 
18288 }
18289 
18290 #if defined(VMS) || defined(UNDERSC)
clrcod(natorg,natoms,idebug)18291 void clrcod(natorg,natoms,idebug)
18292 #else
18293 #ifdef CRAY
18294 void CLRCOD(natorg,natoms,idebug)
18295 #else
18296 void clrcod_(natorg,natoms,idebug)
18297 #endif
18298 #endif
18299 int *natorg;
18300 int *natoms;
18301 int *idebug;
18302 {
18303 
18304 #if defined(VMS) || defined(UNDERSC)
18305 	clrcdd(natorg,natoms,idebug,
18306 #else
18307 #ifdef CRAY
18308 	CLRCDD(natorg,natoms,idebug,
18309 #else
18310 	clrcdd_(natorg,natoms,idebug,
18311 #endif
18312 #endif
18313 	xyzp->iatclr);
18314 
18315 }
18316 
18317 #if defined(VMS) || defined(UNDERSC)
wrxyz(jmod)18318 void wrxyz(jmod)
18319 #else
18320 #ifdef CRAY
18321 void WRXYZ(jmod)
18322 #else
18323 void wrxyz_(jmod)
18324 #endif
18325 #endif
18326 int *jmod;
18327 {
18328 
18329 #if defined(VMS) || defined(UNDERSC)
18330 	wrxyd(jmod,
18331 #else
18332 #ifdef CRAY
18333 	WRXYD(jmod,
18334 #else
18335 	wrxyd_(jmod,
18336 #endif
18337 #endif
18338 	xyzp->qat);
18339 
18340 }
18341 
18342 #if defined(VMS) || defined(UNDERSC)
progeo(ipoints,iff,istat)18343 void progeo(ipoints,iff,istat)
18344 #else
18345 #ifdef CRAY
18346 void PROGEO(ipoints,iff,istat)
18347 #else
18348 void progeo_(ipoints,iff,istat)
18349 #endif
18350 #endif
18351 int *ipoints;
18352 int *iff;
18353 int *istat;
18354 {
18355 
18356 #if defined(VMS) || defined(UNDERSC)
18357 	proged(ipoints,iff,istat,
18358 #else
18359 #ifdef CRAY
18360 	PROGED(ipoints,iff,istat,
18361 #else
18362 	proged_(ipoints,iff,istat,
18363 #endif
18364 #endif
18365 	geop->formax,geop->forrms,geop->dismax,geop->disrms,
18366 	geop->epoints,geop->isav,xyzp->coo,xyzp->ianz,
18367 	&cell->icrtp);
18368 
18369 }
18370 
18371 #if defined(VMS) || defined(UNDERSC)
wrcart(iun,dopdb,idogau,ipdbwh)18372 void wrcart(iun,dopdb,idogau,ipdbwh)
18373 #else
18374 #ifdef CRAY
18375 void WRCART(iun,dopdb,idogau,ipdbwh)
18376 #else
18377 void wrcart_(iun,dopdb,idogau,ipdbwh)
18378 #endif
18379 #endif
18380 int *iun;
18381 int *dopdb;
18382 int *idogau;
18383 int *ipdbwh;
18384 {
18385 
18386 #if defined(VMS) || defined(UNDERSC)
18387 	wrcard(iun,dopdb,idogau,ipdbwh,
18388 #else
18389 #ifdef CRAY
18390 	WRCARD(iun,dopdb,idogau,ipdbwh,
18391 #else
18392 	wrcard_(iun,dopdb,idogau,ipdbwh,
18393 #endif
18394 #endif
18395 	geop->epoints,
18396 	xyzp->coo,xyzp->qat,xyzp->ianz,xyzp->iaton,xyzp->iresid,
18397 	xyzp->iconn,xyzp->ityp,
18398 	&calfptr->ncalf,calfptr->ianf,calfptr->islu,&calfptr->nchain,
18399 	calfptr->iamino,calfptr->reson,calfptr->irsnr,calfptr->achain,
18400 	&calfptr->ishoh);
18401 
18402 }
18403 
18404 #if defined(VMS) || defined(UNDERSC)
dyncpmd(ipoints)18405 void dyncpmd(ipoints)
18406 #else
18407 #ifdef CRAY
18408 void DYNCPMD(ipoints)
18409 #else
18410 void dyncpmd_(ipoints)
18411 #endif
18412 #endif
18413 int *ipoints;
18414 {
18415 
18416 #if defined(VMS) || defined(UNDERSC)
18417 	dyncpdd(ipoints,
18418 #else
18419 #ifdef CRAY
18420 	DYNCPDD(ipoints,
18421 #else
18422 	dyncpdd_(ipoints,
18423 #endif
18424 #endif
18425 	geop->isav,geop->epoints);
18426 
18427 }
18428 
18429 #if defined(VMS) || defined(UNDERSC)
plvend(iun,loop)18430 void plvend(iun,loop)
18431 #else
18432 #ifdef CRAY
18433 void PLVEND(iun,loop)
18434 #else
18435 void plvend_(iun,loop)
18436 #endif
18437 #endif
18438 int *iun;
18439 int *loop;
18440 {
18441 
18442 #if defined(VMS) || defined(UNDERSC)
18443 	plvedd(iun,loop,
18444 #else
18445 #ifdef CRAY
18446 	PLVEDD(iun,loop,
18447 #else
18448 	plvedd_(iun,loop,
18449 #endif
18450 #endif
18451 	geop->epoints,&scalptr->scal);
18452 
18453 }
18454 
18455 /* END shadow C routines for Fortran routines to pass coordinate pointers */
18456 
18457 /* shadow C routines for Fortran routines to rotation pointers */
18458 
18459 #if defined(VMS) || defined(UNDERSC)
xyzrot(inct,theang)18460 void xyzrot(inct,theang)
18461 #else
18462 #ifdef CRAY
18463 void XYZROT(inct,theang)
18464 #else
18465 void xyzrot_(inct,theang)
18466 #endif
18467 #endif
18468 int *inct;
18469 double *theang;
18470 {
18471 #if defined(VMS) || defined(UNDERSC)
18472 	xyzrod(inct,theang,
18473 #else
18474 #ifdef CRAY
18475 	XYZROD(inct,theang,
18476 #else
18477 	xyzrod_(inct,theang,
18478 #endif
18479 #endif
18480 	rotptr->rx,rotptr->ry,rotptr->rz);
18481 }
18482 
18483 #if defined(VMS) || defined(UNDERSC)
rotts(x,y,z,xc,yc,zc,itran)18484 void rotts(x,y,z,xc,yc,zc,itran)
18485 #else
18486 #ifdef CRAY
18487 void ROTTS(x,y,z,xc,yc,zc,itran)
18488 #else
18489 void rotts_(x,y,z,xc,yc,zc,itran)
18490 #endif
18491 #endif
18492 float *x;
18493 float *y;
18494 float *z;
18495 double *xc;
18496 double *yc;
18497 double *zc;
18498 int *itran;
18499 {
18500 #if defined(VMS) || defined(UNDERSC)
18501 	rottd(x,y,z,xc,yc,zc,itran,
18502 #else
18503 #ifdef CRAY
18504 	ROTTD(x,y,z,xc,yc,zc,itran,
18505 #else
18506 	rottd_(x,y,z,xc,yc,zc,itran,
18507 #endif
18508 #endif
18509 	rotptr->rx,rotptr->ry,rotptr->rz,rotptr->t);
18510 }
18511 
18512 #if defined(VMS) || defined(UNDERSC)
rott(x,y,z,xc,yc,zc,itran)18513 void rott(x,y,z,xc,yc,zc,itran)
18514 #else
18515 #ifdef CRAY
18516 void ROTT(x,y,z,xc,yc,zc,itran)
18517 #else
18518 void rott_(x,y,z,xc,yc,zc,itran)
18519 #endif
18520 #endif
18521 double *x;
18522 double *y;
18523 double *z;
18524 double *xc;
18525 double *yc;
18526 double *zc;
18527 int *itran;
18528 {
18529 #if defined(VMS) || defined(UNDERSC)
18530 	rotd(x,y,z,xc,yc,zc,itran,
18531 #else
18532 #ifdef CRAY
18533 	ROTD(x,y,z,xc,yc,zc,itran,
18534 #else
18535 	rotd_(x,y,z,xc,yc,zc,itran,
18536 #endif
18537 #endif
18538 	rotptr->rx,rotptr->ry,rotptr->rz,rotptr->t);
18539 }
18540 
18541 #if defined(VMS) || defined(UNDERSC)
inirot()18542 void inirot()
18543 #else
18544 #ifdef CRAY
18545 void INIROT()
18546 #else
18547 void inirot_()
18548 #endif
18549 #endif
18550 {
18551 #if defined(VMS) || defined(UNDERSC)
18552 	inirod(
18553 #else
18554 #ifdef CRAY
18555 	INIROD(
18556 #else
18557 	inirod_(
18558 #endif
18559 #endif
18560 	rotptr->rx,rotptr->ry,rotptr->rz,rotptr->t);
18561 }
18562 
18563 #if defined(VMS) || defined(UNDERSC)
mtinv3()18564 void mtinv3()
18565 #else
18566 #ifdef CRAY
18567 void MTINV3()
18568 #else
18569 void mtinv3_()
18570 #endif
18571 #endif
18572 {
18573 #if defined(VMS) || defined(UNDERSC)
18574 	mtind3(
18575 #else
18576 #ifdef CRAY
18577 	MTIND3(
18578 #else
18579 	mtind3_(
18580 #endif
18581 #endif
18582 	rotptr->rx,rotptr->ry,rotptr->rz);
18583 }
18584 
18585 #if defined(VMS) || defined(UNDERSC)
mktrn(inct,incp)18586 void mktrn(inct,incp)
18587 #else
18588 #ifdef CRAY
18589 void MKTRN(inct,incp)
18590 #else
18591 void mktrn_(inct,incp)
18592 #endif
18593 #endif
18594 int *inct;
18595 int *incp;
18596 {
18597 #if defined(VMS) || defined(UNDERSC)
18598 	mktrd(inct,incp,
18599 #else
18600 #ifdef CRAY
18601 	MKTRD(inct,incp,
18602 #else
18603 	mktrd_(inct,incp,
18604 #endif
18605 #endif
18606 	&posptr->xv,&posptr->yv,&posptr->zv,
18607 	&posptr->pincr,&scalptr->scal,&scalptr->scali,&scalptr->smag);
18608 }
18609 
18610 #if defined(VMS) || defined(UNDERSC)
setxyv()18611 void setxyv()
18612 #else
18613 #ifdef CRAY
18614 void SETXYV()
18615 #else
18616 void setxyv_()
18617 #endif
18618 #endif
18619 {
18620 #if defined(VMS) || defined(UNDERSC)
18621 	setxyd(
18622 #else
18623 #ifdef CRAY
18624 	SETXYD(
18625 #else
18626 	setxyd_(
18627 #endif
18628 #endif
18629 	&posptr->xv,&posptr->yv);
18630 }
18631 
18632 #if defined(VMS) || defined(UNDERSC)
chkbck(upogl)18633 void chkbck(upogl)
18634 #else
18635 #ifdef CRAY
18636 void CHKBCK(upogl)
18637 #else
18638 void chkbck_(upogl)
18639 #endif
18640 #endif
18641 int *upogl;
18642 {
18643 	if (*upogl) SSdone[istruct] = 0;
18644 #if defined(VMS) || defined(UNDERSC)
18645 	chkbcd(
18646 #else
18647 #ifdef CRAY
18648 	CHKBCD(
18649 #else
18650 	chkbcd_(
18651 #endif
18652 #endif
18653 	&calfptr->ncalf,calfptr->ihet,calfptr->reson,xyzp->iaton,xyzp->iatclr,&calfptr->ision);
18654 }
18655 
18656 /* END shadow C routines for Fortran routines to rotation pointers */
18657 
18658 #if defined(VMS) || defined(UNDERSC)
qupd()18659 void qupd()
18660 {
18661     int oglon;
18662 
18663     rsold = RESUND;
18664     oglon = (*fancy || *fullgl);
18665     if (denmode) oglon = *ifdogl;
18666 #ifdef DOGL
18667     if (oglon && has_opengl) {
18668 	if (update_res > 0) {
18669 	   ogres(update_res,1,1);
18670         } else {
18671            if (update_model || *irtcel) ogind();
18672 	   else dispsf();
18673 	}
18674         if (dogif) {
18675            picnum++;
18676            if (picnum < *picmax) {
18677 		glXWaitGL();
18678 		switch (*igffrm) {
18679 		case 1:
18680 			sprintf(stemp, "%s%03d.gif",GifFile,picnum);
18681 			WOGLGIF(stemp);
18682 			break;
18683 		case 2:
18684 			sprintf(stemp, "%s%03d.rgb",GifFile,picnum);
18685 			save_rgb(stemp);
18686 			break;
18687 		case 3:
18688 			sprintf(stemp, "%s%03d.bmp",GifFile,picnum);
18689 			save_bmp(stemp);
18690 			break;
18691 		}
18692 		glXSwapBuffers(display, win);
18693 	   }
18694 	}
18695     } else {
18696 #endif
18697       if (!denmode) {
18698 	doclr();
18699 	if (*persp) {
18700 	   plmolp();
18701 	} else {
18702 	   plmol();
18703 	}
18704       } else {
18705 	RedrawWin();
18706       }
18707       if (*logo) dlogo();
18708       doexp();
18709 #ifdef DOGL
18710     }
18711 #endif
18712 
18713 }
18714 #else
18715 #ifdef CRAY
QUPD()18716 void QUPD()
18717 {
18718     int oglon;
18719 
18720     oglon = (*fancy || *fullgl);
18721     if (denmode) oglon = *ifdogl;
18722 #ifdef DOGL
18723     if (oglon && has_opengl) {
18724 	if (update_res > 0) {
18725 	   ogres(update_res,1,1);
18726         } else {
18727            if (update_model || *irtcel) ogind();
18728 	   else dispsf();
18729 	}
18730         if (dogif) {
18731            picnum++;
18732            if (picnum < *picmax) {
18733 		glXWaitGL();
18734 		switch (*igffrm) {
18735 		case 1:
18736 			sprintf(stemp, "%s%03d.gif",GifFile,picnum);
18737 			WOGLGIF(stemp);
18738 			break;
18739 		case 2:
18740 			sprintf(stemp, "%s%03d.rgb",GifFile,picnum);
18741 			save_rgb(stemp);
18742 			break;
18743 		case 3:
18744 			sprintf(stemp, "%s%03d.bmp",GifFile,picnum);
18745 			save_bmp(stemp);
18746 			break;
18747 		}
18748 		glXSwapBuffers(display, win);
18749 	   }
18750 	}
18751     } else {
18752 #endif
18753       if (!denmode) {
18754 	doclr();
18755 	if (*persp) {
18756 	   PLMOLP();
18757 	} else {
18758 	   PLMOL();
18759 	}
18760       } else {
18761 	RedrawWin();
18762       }
18763       if (*logo) DLOGO();
18764       DOEXP();
18765 #ifdef DOGL
18766     }
18767 #endif
18768 }
18769 
18770 #else
qupd_()18771 void qupd_()
18772 {
18773     int oglon;
18774     oglon = (*fancy || *fullgl);
18775     if (denmode) oglon = *ifdogl;
18776 #ifdef DOGL
18777     if (oglon && has_opengl) {
18778 	if (update_res > 0) {
18779 	   ogres(update_res,1,1);
18780         } else {
18781            if (update_model || *irtcel) ogind();
18782 	   else dispsf();
18783 	}
18784         if (dogif) {
18785            picnum++;
18786            if (picnum < *picmax) {
18787 		glXWaitGL();
18788 		switch (*igffrm) {
18789 		case 1:
18790 			sprintf(stemp, "%s%03d.gif",GifFile,picnum);
18791 			WOGLGIF(stemp);
18792 			break;
18793 		case 2:
18794 			sprintf(stemp, "%s%03d.rgb",GifFile,picnum);
18795 			save_rgb(stemp);
18796 			break;
18797 		case 3:
18798 			sprintf(stemp, "%s%03d.bmp",GifFile,picnum);
18799 			save_bmp(stemp);
18800 			break;
18801 		}
18802 		glXSwapBuffers(display, win);
18803 	   }
18804 	}
18805     } else {
18806 #endif
18807       if (!denmode) {
18808 	doclr();
18809 	if (*persp) {
18810 	   plmolp_();
18811 	} else {
18812 	   plmol_();
18813 	}
18814       } else {
18815 	RedrawWin();
18816       }
18817       if (!*fullgl) {
18818 	if (*logo) dlogo_();
18819 	doexp_();
18820       }
18821 #ifdef DOGL
18822     }
18823 #endif
18824 }
18825 #endif
18826 #endif
18827 
update_struct()18828 void update_struct()
18829 {
18830 #if defined(VMS) || defined(UNDERSC)
18831    qupd();
18832 #else
18833 #ifdef CRAY
18834    QUPD();
18835 #else
18836    qupd_();
18837 #endif
18838 #endif
18839 }
18840 
SetSurfColor(is,j)18841 void SetSurfColor(is,j)
18842 int is;
18843 int j;
18844 {
18845    int i;
18846 
18847    if (is >= MAXSURF || j >= MAX_COLORS) return;
18848 
18849 #ifdef DOGL
18850    diffuseColor[istruct][is][0] = ((GLfloat) colorr[j]) / 65535.0 ;
18851    diffuseColor[istruct][is][1] = ((GLfloat) colorg[j]) / 65535.0 ;
18852    diffuseColor[istruct][is][2] = ((GLfloat) colorb[j]) / 65535.0 ;
18853    diffuseColor[istruct][is][3] = 1.0;
18854    for (i=0; i<3; i++) {
18855 	specularColor[is][i] = specColor[i];
18856    }
18857 #endif
18858 }
18859 
CopySurfColor(is1,is2)18860 void CopySurfColor(is1,is2)
18861 int is1;
18862 int is2;
18863 {
18864    int i;
18865 
18866    if (is2 >= MAXSURF) return;
18867 
18868    fprintf(stderr,"copysurfcolor is1 %d is2 %d\n",is1,is2);
18869 #ifdef DOGL
18870    diffuseColor[istruct][is2][0] = diffuseColor[istruct][is1][0];
18871    diffuseColor[istruct][is2][1] = diffuseColor[istruct][is1][1];
18872    diffuseColor[istruct][is2][2] = diffuseColor[istruct][is1][2];
18873    for (i=0; i<3; i++) {
18874 	specularColor[is2][i] = specularColor[is1][i];
18875    }
18876 #endif
18877 }
18878 
sizz(i,j,iset)18879 void sizz(i,j,iset)
18880 int i;
18881 int j;
18882 int iset;
18883 {
18884 
18885  *(zmptrp->iz + (i*4) + j) = iset;
18886 
18887 }
18888 
18889 
18890 static int *Snstr;
18891 #ifdef VMS
18892 static struct dsc$descriptor_s *Sstr;
18893 #else
18894 #ifdef CRAY
18895 static _fcd Sstr;
18896 #else
18897 static char *Sstr;
18898 #endif
18899 #endif
18900 
18901 
ColorByStruct()18902 void ColorByStruct()
18903 {
18904     int i,k,ilow;
18905 
18906     for (k=0; k < alnptr->nalign; k++) {
18907 	if (k == 0) {
18908 	   ilow = 0;
18909         } else {
18910 	   ilow = alnptr->istch[k-1];
18911 	}
18912 	for (i=ilow; i < alnptr->istch[k]; i++)
18913 	   chncol(i,alnptr->istcol[k],0);
18914     }
18915 }
18916 
18917 
18918 #if defined(VMS) || defined(UNDERSC)
setion()18919 void setion()
18920 #else
18921 #ifdef CRAY
18922 void SETION()
18923 #else
18924 void setion_()
18925 #endif
18926 #endif
18927 {
18928     calfptr->ision = 100000;
18929 }
18930 
presetp()18931 void presetp()
18932 {
18933         int iop,i,j;
18934 
18935 	if (hetptr.NHetAtm) {
18936 
18937 	    if (!calfptr->issdon) {
18938 #if defined(VMS) || defined(UNDERSC)
18939 		ribbs();
18940 #else
18941 #ifdef CRAY
18942 		RIBBS();
18943 #else
18944 		ribbs_();
18945 #endif
18946 #endif
18947 	    }
18948 
18949             for (iop=0;iop<4;iop++) {
18950 		if (calfptr->ihet[iop]) {
18951 #if defined(VMS) || defined(UNDERSC)
18952                 acthel(&ONE,&iop,&clfhptr->isndcl[iop],&ZERO);
18953 #else
18954 #ifdef CRAY
18955                 ACTHEL(&ONE,&iop,&clfhptr->isndcl[iop],&ZERO);
18956 #else
18957                 acthel_(&ONE,&iop,&clfhptr->isndcl[iop],&ZERO);
18958 #endif
18959 #endif
18960 		}
18961 	    }
18962             for (i=0;i < calfptr->ncalf;i++) {
18963 		if (calfptr->reson[i] > 0) {
18964 		   if (calfptr->iamino[i] > 23) {
18965             	   	for (j=0;j<6;j++)
18966 			   xyzp->iaton[calfptr->icalf[i][j] - 1] = 1;
18967 		   } else {
18968             		for (j=0;j<4;j++)
18969 			   if (calfptr->icalf[i][j] >= 1 &&
18970 				calfptr->icalf[i][j] < 50000) {
18971 				xyzp->iaton[calfptr->icalf[i][j] - 1] = 1;
18972 			   }
18973 		   }
18974 		}
18975 	    }
18976 	}
18977 }
18978 
sndon(iop,set,color)18979 void sndon(iop,set,color)
18980 int iop;
18981 int set;
18982 int color;
18983 {
18984    int i;
18985 
18986    if (iop > 3) return;
18987 
18988    if (*ipdbon && SSdone[istruct] == -1) {
18989        if (!OMAPup) NSurf[istruct] = 0;
18990 #if defined(VMS) || defined(UNDERSC)
18991        ribgl(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
18992 #else
18993 #ifdef CRAY
18994        RIBGL(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
18995 #else
18996        ribgl_(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
18997 #endif
18998 #endif
18999        SSdone[istruct] = 1;
19000    }
19001 
19002    for (i=RIBindex[istruct].start[iop];
19003 	i <= RIBindex[istruct].end[iop]; i++) {
19004 	if (i == -1) break;
19005 	SSon[istruct][i] = 1;
19006 	if (set) {
19007 	   SetSurfColor(i,color);
19008 	} else {
19009 	   SetSurfColor(i,clfhptr->isndcl[iop]);
19010 	}
19011    }
19012 
19013    RedrawSTRC();
19014 }
19015 
sndoff(iop)19016 void sndoff(iop)
19017 int iop;
19018 {
19019    int i;
19020 
19021    if (iop > 3) return;
19022 
19023    for (i=RIBindex[istruct].start[iop];
19024 	i <= RIBindex[istruct].end[iop]; i++) {
19025 	if (i == -1) break;
19026 	SSon[istruct][i] = 0;
19027    }
19028 
19029    RedrawSTRC();
19030 }
19031 
preset(int iset)19032 void preset(int iset)
19033 {
19034     int i,iop;
19035     int cell_up, cell_low;
19036 
19037 
19038     cell_low = cell_up = 0;
19039     if (cellpnt->iclon) {
19040 	cell_low = cellpnt->iclpnt[0]-1;
19041 	cell_up = cell_low + 7;
19042     }
19043 
19044     if (hetptr.NHetAtm) {
19045 
19046 	    if (!calfptr->issdon) {
19047 #if defined(VMS) || defined(UNDERSC)
19048 		ribbs();
19049 #else
19050 #ifdef CRAY
19051 		RIBBS();
19052 #else
19053 		ribbs_();
19054 #endif
19055 #endif
19056          	for (i=0;i<4;i++) calfptr->ihet[i] = 0;
19057 	    }
19058 
19059 /* red 1, orange 2, green 3 (helix), ... purple 9 (beta), grey 8 (coil) */
19060 	    if (iset) {
19061 #if defined(VMS) || defined(UNDERSC)
19062 	        actcal(&ZERO);
19063 #else
19064 #ifdef CRAY
19065 	        ACTCAL(&ZERO);
19066 #else
19067 	        actcal_(&ZERO);
19068 #endif
19069 #endif
19070 		for (i=0; i < calfptr->ncalf; i++) calfptr->reson[i] = 0;
19071 		for (i=0; i < *xyzp->iatoms; i++ ) {
19072 		   if (! (i >= cell_low && i <= cell_up) ) xyzp->iaton[i] = 0;
19073 		}
19074 		update_sel = 1;
19075 
19076 		for (i=0; i < MXHETA; i++) calfptr->ihet[i] = 0;
19077 	    }
19078 
19079             for (iop=0;iop<4;iop++) {
19080 		calfptr->ihet[iop] = 1;
19081 #if defined(VMS) || defined(UNDERSC)
19082                 acthel(&ONE,&iop,&clfhptr->isndcl[iop],&ZERO);
19083 #else
19084 #ifdef CRAY
19085                 ACTHEL(&ONE,&iop,&clfhptr->isndcl[iop],&ZERO);
19086 #else
19087                 acthel_(&ONE,&iop,&clfhptr->isndcl[iop],&ZERO);
19088 #endif
19089 #endif
19090 		sndon(iop,0,0);
19091 	    }
19092 	    if (alnptr->nalign) ColorByStruct();
19093     }
19094 }
19095 
str2qbox(qp,str,len)19096 void str2qbox(qp,str,len)
19097 QBOXSTRU	*qp;
19098 char *str;
19099 int len;
19100 {
19101    if (len == -1) {
19102 	strcpy(qp->str,str);
19103    } else {
19104 	strncpy(qp->str,str,MINI(len,qp->strmax));
19105    }
19106    qp->wnd_start = 0;
19107    qp->curpos = strlen(qp->str);
19108 }
19109 
DebugStructure()19110 void DebugStructure()
19111 {
19112    int i;
19113 
19114    for (i=0; i<nstruct; i++) {
19115 	   fprintf(stderr,"str %d file %s\n",i,COO[i]->fname);
19116 	   fprintf(stderr," iatoms %d\n",COO[i]->iatoms);
19117 	   fprintf(stderr," natoms %d\n",COO[i]->NAT.natoms);
19118 	   fprintf(stderr," ipoints %d\n",COO[i]->ipoints);
19119 	   fprintf(stderr," iftyp %d\n",COO[i]->iftyp);
19120 	   fprintf(stderr," iconv %d\n",COO[i]->poi.iconv);
19121 	   fprintf(stderr," mxzorg %d\n",COO[i]->zmt.mxzorg);
19122    }
19123 }
19124 
SaveFirstStruct()19125 void SaveFirstStruct()
19126 {
19127     int j;
19128     char* p;
19129 
19130     COO[0]->coo   = *xyzp;
19131     COO[0]->geop  = *geop;
19132     COO[0]->zmt   = *zmptrp;
19133     COO[0]->stoc  = *stocp;
19134     COO[0]->dorb  = *dorbp;
19135     COO[0]->orb   = *orbp;
19136 
19137     COO[0]->fname = (char *) malloc(strlen(firstfile) + 3);
19138     strcpy(COO[0]->fname, firstfile);
19139 
19140     if ((p = strrchr(firstfile, '/'))) p++;
19141     strfiles[0] = (char *) malloc(strlen(p) + 3);
19142     strcpy(strfiles[0], p);
19143 
19144     for (j=0; j<hetptr.NHetAtm; j++) {
19145        COO[0]->hetatm.Allocated[j] = hetptr.Allocated[j];
19146        COO[0]->hetatm.HetAtm[j] = hetptr.HetAtm[j];
19147     }
19148     COO[0]->hetatm.NHetAtm = hetptr.NHetAtm;
19149 
19150     if (pdbcode == NULL) {
19151 	if (COO[0]->pdbcode != NULL) free(COO[0]->pdbcode);
19152 	COO[0]->pdbcode = NULL;
19153     } else {
19154 	COO[0]->pdbcode = (char *) malloc(5);
19155 	strncpy(COO[0]->pdbcode, pdbcode,4);
19156 	COO[0]->pdbcode[4] = '\0';
19157     }
19158 
19159 }
19160 
SaveActiveStruct()19161 void SaveActiveStruct()
19162 {
19163     int j;
19164     char* p;
19165 
19166 /*
19167    These are the data with general pointers that are copied to the
19168    COO structures when a new structure becomes active
19169 
19170    For Data structures that use dynamic memory allocation, we only
19171    keep a pointer in the COO structure. The pointer is assigned in
19172    the memory allocation rotines (allcoo, allgeo) when a new file
19173    is read.
19174 */
19175 
19176     COO[istruct]->geop  = *geop;
19177     COO[istruct]->zmt   = *zmptrp;
19178     COO[istruct]->stoc  = *stocp;
19179     COO[istruct]->dorb  = *dorbp;
19180     COO[istruct]->orb   = *orbp;
19181 
19182     COO[istruct]->IANZbox = IANZbox;
19183     COO[istruct]->BLbox   = BLbox;
19184     COO[istruct]->ALPHbox = ALPHbox;
19185     COO[istruct]->BETbox  = BETbox;
19186     COO[istruct]->IZbox   = IZbox;
19187 
19188     COO[istruct]->iatoms = *xyzp->iatoms;
19189     COO[istruct]->mxnat = *xyzp->mxnat;
19190     COO[istruct]->natorg = *natorg;
19191     COO[istruct]->pdb = *ipdbon;
19192     COO[istruct]->backb = *backb;
19193     COO[istruct]->iftyp = *iftyp;
19194     COO[istruct]->rot = *rotptr;
19195     COO[istruct]->pos = *posptr;
19196     COO[istruct]->scal = *scalptr;
19197     COO[istruct]->cell = *cell;
19198     COO[istruct]->cellpnt = *cellpnt;
19199     COO[istruct]->geo = *geo1ptr;
19200     COO[istruct]->cnv = *cnvptr;
19201     COO[istruct]->poi = poi;
19202     COO[istruct]->ipoints = pnt->ipoints;
19203     COO[istruct]->calf = *calfptr;
19204     COO[istruct]->strx = strx;
19205     COO[istruct]->XYZ = *XYZ;
19206     COO[istruct]->NAT = *NAT;
19207     COO[istruct]->bas = *BAS;
19208     COO[istruct]->gau = *slagau;
19209     COO[istruct]->mop = *MOP;
19210     COO[istruct]->frq = *FRQ;
19211     COO[istruct]->pseud = *PSEUD;
19212     COO[istruct]->plane = *plane;
19213     COO[istruct]->eul = *eul;
19214     COO[istruct]->proj = *proj;
19215     COO[istruct]->mfdata = *mfdata;
19216     COO[istruct]->potcom = *potcom;
19217     COO[istruct]->zmpart = *zmpart;
19218     COO[istruct]->jobcom = *jobcom;
19219     COO[istruct]->qdpptr = *qdpptr;
19220     COO[istruct]->hlpsrf = *hlpsrf;
19221     COO[istruct]->hetlab = hetlab;
19222     COO[istruct]->nmr = *nmrptr;
19223     COO[istruct]->jcoupl = jcoupl;
19224     COO[istruct]->nz = *zmptrp->nz;
19225     COO[istruct]->ihaszm = *zmptrp->ihaszm;
19226     COO[istruct]->mxzat = *zmptrp->mxzat;
19227     COO[istruct]->ncols = *dorbp->ncols;
19228     COO[istruct]->ncolb = *dorbp->ncolb;
19229     COO[istruct]->nocc = *dorbp->nocc;
19230     COO[istruct]->nocb = *dorbp->nocb;
19231     COO[istruct]->naorbs = *dorbp->naorbs;
19232     COO[istruct]->mxorb = *dorbp->mxorb;
19233     COO[istruct]->uhf = *iuhf;
19234     COO[istruct]->spd = *ispd;
19235     COO[istruct]->ipsi = *ipsi;
19236     COO[istruct]->inact = inactMC;
19237     COO[istruct]->inaf = inafMC;
19238     COO[istruct]->uscl = *uscl;
19239     COO[istruct]->adjus = *adjuss;
19240     COO[istruct]->atcol = *atcol;
19241     COO[istruct]->ZMEAA = ZMEAA;
19242     COO[istruct]->doesp = *doesp;
19243     COO[istruct]->fftyp = *fftyp;
19244     COO[istruct]->irtcel = *irtcel;
19245     COO[istruct]->normc = *normc;
19246     COO[istruct]->icst = *icst;
19247     COO[istruct]->ibox = *ibox;
19248     COO[istruct]->igfmap = *igfmap;
19249     COO[istruct]->iresrd = *iresrd;
19250     COO[istruct]->clfstr = *clfstrptr;
19251     COO[istruct]->fancy = *fancy;
19252     COO[istruct]->alnstr = *alnptr;
19253     COO[istruct]->ihasex = *ihasex;
19254     COO[istruct]->bcksvg = bcksvg;
19255 
19256     wrsvgs();
19257 
19258     for (j=0; j<FRQ->nfreq; j++)
19259        COO[istruct]->frsym[j] = frsym[j];
19260 
19261     for (j=0; j<hetptr.NHetAtm; j++) {
19262        COO[istruct]->hetatm.Allocated[j] = hetptr.Allocated[j];
19263        COO[istruct]->hetatm.HetAtm[j] = hetptr.HetAtm[j];
19264     }
19265     COO[istruct]->hetatm.NHetAtm = hetptr.NHetAtm;
19266 
19267     for (j=0; j<MXHETA; j++) hetptr.Allocated[j] = 0;
19268     hetptr.NHetAtm = 0;
19269 
19270     COO[istruct]->mlftit = mlftit;
19271     COO[istruct]->ntits = ntits;
19272     COO[istruct]->mxtits = mxtits;
19273 
19274     if (pdbcode == NULL) {
19275 	if (COO[istruct]->pdbcode != NULL) free(COO[istruct]->pdbcode);
19276 	COO[istruct]->pdbcode = NULL;
19277     } else {
19278 	if (COO[istruct]->pdbcode == NULL) {
19279 	   COO[istruct]->pdbcode = (char *) malloc(5);
19280 	   strncpy(COO[istruct]->pdbcode, pdbcode,4);
19281 	   COO[istruct]->pdbcode[4] = '\0';
19282 	}
19283     }
19284 }
19285 
AllocateStructure(newstr)19286 void AllocateStructure(newstr)
19287 STRUSTRU **newstr;
19288 {
19289   *newstr = (STRUSTRU *) malloc((sizeof **newstr)*1);
19290   (*newstr)->memfil.str = NULL;
19291 }
19292 
AllocateSubStructures(file,naat)19293 void AllocateSubStructures(file,naat)
19294 char *file;
19295 int naat;
19296 {
19297 	int *allc,*frst;
19298 
19299 	hetptr.NHetAtm = 0;
19300 	COO[nstruct]->pdbcode = NULL;
19301 	Ngrostr = 0;
19302 	omapr = 0;
19303 
19304 	xyzp   = &COO[nstruct]->coo;
19305 	geop   = &COO[nstruct]->geop;
19306 	zmptrp = &COO[nstruct]->zmt;
19307 	stocp  = &COO[nstruct]->stoc;
19308 	dorbp  = &COO[nstruct]->dorb;
19309 	orbp   = &COO[nstruct]->orb;
19310 
19311 	strfiles[nstruct] = (char *) malloc(strlen(file) + 3);
19312 	COO[nstruct]->fname = (char *) malloc(strlen(strname) + 3);
19313 	strcpy(strfiles[nstruct], file);
19314 	strcpy(COO[nstruct]->fname, strname);
19315 	mfdata->mollin = (int *) malloc(sizeof(int)*MXMFMOL);
19316 	mfdata->mollin[0] = 0;
19317 	mfdata->maxmol = MXMFMOL;
19318 	mlftit = (char **) malloc(sizeof(char *)*MXMFMOL);
19319 	mxtits = MXMFMOL;
19320 	COO[nstruct]->svgs = NULL;
19321 	COO[nstruct]->svgdone = 0;
19322 
19323 	fileop.str = NULL;
19324 	fileop.line_index = NULL;
19325 	fileop.size = 0;
19326 	fileop.nlines = 0;
19327 	fileop.nfiles = 0;
19328 	fileop.currl = 0;
19329 
19330 	bcksvg.UpSVG = 0;
19331 	bcksvg.CurSVG = 0;
19332 	bcksvg.ReadSVG = 0;
19333 	bcksvg.istruct = nstruct;
19334 
19335 	if (strx.fpos != NULL) strx.fpos = NULL;
19336 	if (strx.fptr) strx.fptr = NULL;
19337 
19338 	nstruct++;
19339 	istruct = nstruct - 1;
19340 
19341 	allc = &addat; frst = &ONE;
19342 	if (naat > 0) {
19343 	   allc = &naat;
19344 	   frst = &MONE;
19345 	}
19346 
19347 #if defined(VMS) || defined(UNDERSC)
19348 	allcoo(allc,frst);
19349 	allgeo(&addat,&ONE);
19350 	allorb(&addat,&ONE);
19351 #else
19352 #ifdef CRAY
19353 	ALLCOO(allc,frst);
19354 	ALLGEO(&addat,&ONE);
19355 	ALLORB(&addat,&ONE);
19356 #else
19357 	allcoo_(allc,frst);
19358 	allgeo_(&addat,&ONE);
19359 	allorb_(&addat,&ONE);
19360 #endif
19361 #endif
19362 
19363 	*xyzp->iatoms = 0;
19364 
19365 	AllocZMat(*xyzp->mxnat,ONE);
19366 
19367 
19368 	strlist.select = istruct;
19369 	if (!STRup) inistr();
19370 	else RedrawSTR();
19371 }
19372 
NewActiveStruct()19373 void NewActiveStruct()
19374 {
19375     int i,j,j1,nstr, HasZMtmp;
19376 #ifdef VMS
19377     struct dsc$descriptor_s ztr;
19378 #else
19379 #ifdef CRAY
19380     _fcd ztr;
19381 #else
19382     char ztr[4];
19383 #endif
19384 #endif
19385 
19386     xyzp   = &COO[istruct]->coo;
19387     geop   = &COO[istruct]->geop;
19388     zmptrp = &COO[istruct]->zmt;
19389     stocp  = &COO[istruct]->stoc;
19390     dorbp  = &COO[istruct]->dorb;
19391     orbp   = &COO[istruct]->orb;
19392 
19393     IANZbox = COO[istruct]->IANZbox;
19394     BLbox   = COO[istruct]->BLbox;
19395     ALPHbox = COO[istruct]->ALPHbox;
19396     BETbox  = COO[istruct]->BETbox;
19397     IZbox   = COO[istruct]->IZbox;
19398 
19399     *xyzp->iatoms   = COO[istruct]->iatoms;
19400     *xyzp->mxnat    = COO[istruct]->mxnat;
19401     *natorg         = COO[istruct]->natorg;
19402     *ipdbon         = COO[istruct]->pdb;
19403     *iftyp          = COO[istruct]->iftyp;
19404     *rotptr         = COO[istruct]->rot;
19405     *posptr         = COO[istruct]->pos;
19406     *scalptr        = COO[istruct]->scal;
19407     *cell           = COO[istruct]->cell;
19408     *cellpnt        = COO[istruct]->cellpnt;
19409     *geo1ptr        = COO[istruct]->geo;
19410     *cnvptr         = COO[istruct]->cnv;
19411     bckpoi(istruct);
19412     pnt->ipoints    = COO[istruct]->ipoints;
19413     *calfptr        = COO[istruct]->calf;
19414     strx            = COO[istruct]->strx;
19415     *XYZ            = COO[istruct]->XYZ;
19416     *NAT            = COO[istruct]->NAT;
19417     *BAS            = COO[istruct]->bas;
19418     *slagau         = COO[istruct]->gau;
19419     *MOP            = COO[istruct]->mop;
19420     *FRQ            = COO[istruct]->frq;
19421     *PSEUD          = COO[istruct]->pseud;
19422     *plane          = COO[istruct]->plane;
19423     *eul            = COO[istruct]->eul;
19424     *proj           = COO[istruct]->proj;
19425     *mfdata         = COO[istruct]->mfdata;
19426     *potcom         = COO[istruct]->potcom;
19427     *zmpart         = COO[istruct]->zmpart;
19428     *jobcom         = COO[istruct]->jobcom;
19429     *qdpptr         = COO[istruct]->qdpptr;
19430     *hlpsrf         = COO[istruct]->hlpsrf;
19431     hetlab          = COO[istruct]->hetlab;
19432     *nmrptr         = COO[istruct]->nmr;
19433     jcoupl          = COO[istruct]->jcoupl;
19434     *zmptrp->nz     = COO[istruct]->nz;
19435     *zmptrp->ihaszm = COO[istruct]->ihaszm;
19436     *zmptrp->mxzat  = COO[istruct]->mxzat;
19437     *dorbp->ncols   = COO[istruct]->ncols;
19438     *dorbp->ncolb   = COO[istruct]->ncolb;
19439     *dorbp->nocc    = COO[istruct]->nocc;
19440     *dorbp->nocb    = COO[istruct]->nocb;
19441     *dorbp->naorbs  = COO[istruct]->naorbs;
19442     *dorbp->mxorb   = COO[istruct]->mxorb;
19443     *iuhf           = COO[istruct]->uhf;
19444     *ispd           = COO[istruct]->spd;
19445     *ipsi           = COO[istruct]->ipsi;
19446     *uscl           = COO[istruct]->uscl;
19447     *adjuss         = COO[istruct]->adjus;
19448     *atcol          = COO[istruct]->atcol;
19449     *doesp          = COO[istruct]->doesp;
19450     *fftyp          = COO[istruct]->fftyp;
19451     *irtcel         = COO[istruct]->irtcel;
19452     *normc          = COO[istruct]->normc;
19453     *icst           = COO[istruct]->icst;
19454     *ibox           = COO[istruct]->ibox;
19455     *igfmap         = COO[istruct]->igfmap;
19456     *iresrd         = COO[istruct]->iresrd;
19457     *clfstrptr      = COO[istruct]->clfstr;
19458     *fancy          = COO[istruct]->fancy;
19459     *alnptr         = COO[istruct]->alnstr;
19460     *ihasex         = COO[istruct]->ihasex;
19461     bcksvg	    = COO[istruct]->bcksvg;
19462 
19463     if (pdbcode != NULL) {
19464 	if (pdbcode == pdbcbck) {
19465 	   free(pdbcode); pdbcode = NULL;
19466 	}
19467     }
19468 
19469     pdbcode	    = COO[istruct]->pdbcode;
19470 
19471     hetptr.NHetAtm         = COO[istruct]->hetatm.NHetAtm;
19472     for (j=0; j<hetptr.NHetAtm; j++) {
19473 	hetptr.Allocated[j] = COO[istruct]->hetatm.Allocated[j];
19474 	hetptr.HetAtm[j] = COO[istruct]->hetatm.HetAtm[j];
19475     }
19476 
19477     for (j=0; j<hetptr.NHetAtm; j++) {
19478 	j1 = j + 1;
19479 #if defined(VMS) || defined(UNDERSC)
19480 /*
19481 	for (i=0; i<strlen(hetptr.HetAtm[j]); i++)
19482 	    ztr.dsc$a_pointer[i] = hetptr.HetAtm[j][i];
19483 	parhet(&j1,&ztr);
19484 */
19485 	clfstrptr->ihashz = 0;
19486 #else
19487 #ifdef CRAY
19488 /*
19489 	strncpy(_fcdtocp(ztr),hetptr.HetAtm[j],strlen(hetptr.HetAtm[j]));
19490 	PARHET(&j1,ztr);
19491 */
19492 	clfstrptr->ihashz = 0;
19493 #else
19494 	if (hetptr.HetAtm[j] != NULL) {
19495 	   strncpy(ztr,hetptr.HetAtm[j],3);
19496 	   parhet_(&j1,ztr);
19497 	}
19498 #endif
19499 #endif
19500     }
19501 
19502     ntits         = COO[istruct]->ntits;
19503     mxtits        = COO[istruct]->mxtits;
19504     mlftit        = COO[istruct]->mlftit;
19505 /*    svgarr        = COO[istruct]->svgs;*/
19506 
19507     for (j=0; j<FRQ->nfreq; j++)
19508         frsym[j]  = COO[istruct]->frsym[j];
19509 
19510     pnt->ipnt = 1;
19511 
19512     HasZMtmp = *zmptrp->ihaszm;
19513 
19514     actde(COO[istruct]->inact,COO[istruct]->inaf,0);
19515 
19516     *backb           = COO[istruct]->backb;
19517     if (*backb) {
19518 	TogDown(&cbut[BBACKB]);
19519 	ActBut(&cbut[BFORC],1);
19520 	ActBut(&cbut[BINCRF],1);
19521 	ActBut(&cbut[BHBOND],1);
19522 	ActBut(&cbut[BDECRF],1);
19523 	ActBut(&cbut[BUNSC],1);
19524     } else {
19525 	TogUp(&cbut[BBACKB]);
19526     }
19527 
19528     if (*fancy) {
19529 	TogDown(&cbut[BSOLID]);
19530     } else {
19531 	TogUp(&cbut[BSOLID]);
19532     }
19533 
19534     if (*atcol) {
19535 	TogDown(&cbut[BATCOL]);
19536     } else {
19537 	TogUp(&cbut[BATCOL]);
19538     }
19539 
19540     if (HasZMtmp) {
19541 	ZMEAA           = COO[istruct]->ZMEAA;
19542 	if (ZMEAA) EXPbox[0].fake = 0;
19543 	else EXPbox[0].fake = 1;
19544     }
19545 
19546 /* Now update open windows */
19547 
19548     if (ZMEup) {
19549 
19550 	if (pdb && !*zmptrp->ihaszm) {
19551 	   if (DoPDB(1)) i = 1;
19552 	} else {
19553 #if defined(VMS) || defined(UNDERSC)
19554 	   upzme();
19555 #else
19556 #ifdef CRAY
19557 	   UPZME();
19558 #else
19559 	   upzme_();
19560 #endif
19561 #endif
19562 	}
19563 	RedrawZME();
19564     }
19565 
19566     if (cnvup) {
19567 	drwcnv();
19568     }
19569 
19570     if (specup) {
19571 	createspec(0);
19572 	drwspec();
19573     }
19574 
19575     if (FRup) {
19576 	createfr(0);
19577 	RedrawList(&frlist);
19578     }
19579 
19580     if (OMAPup) EndOMAP();
19581 
19582     if (geoup) {
19583 	XClearWindow(display,wingeo);
19584 
19585 #if defined(VMS) || defined(UNDERSC)
19586 	drwgeo();
19587 #else
19588 #ifdef CRAY
19589 	DRWGEO();
19590 #else
19591 	drwgeo_();
19592 #endif
19593 #endif
19594     }
19595 
19596 /* close old iun2 unit and open file associated with new active structure */
19597 
19598     nstr = strlen(COO[istruct]->fname);
19599 
19600 #ifdef VMS
19601     for (i=0; i<strlen(COO[istruct]->fname); i++)
19602 	{Sstr->dsc$a_pointer[i] = COO[istruct]->fname[i];}
19603     nwfil(Sstr,&nstr);
19604 #else
19605 #ifdef CRAY
19606     strncpy(_fcdtocp(Sstr),COO[istruct]->fname,
19607 	strlen(COO[istruct]->fname));
19608     NWFIL(Sstr,&nstr);
19609 #else
19610     strcpy(Sstr,COO[istruct]->fname);
19611 #if defined(UNDERSC)
19612     nwfil(Sstr,&nstr);
19613 #else
19614     nwfil_(Sstr,&nstr);
19615 #endif
19616 #endif
19617 #endif
19618 
19619     WinName(win,COO[istruct]->fname);
19620     omapr = 0;
19621 
19622 }
19623 
GetFirstFile()19624 void GetFirstFile()
19625 {
19626 char* p;
19627 char* q;
19628 
19629 	nfilesstart = fsel.nfiles;
19630 	firstreadf = 0;
19631 	if (nfilesstart) {
19632 	   strcpy(firstfile,fsel.files[0]);
19633 	   if (firstfile[0] != '/') {
19634 		if (getcwd(firstfile,MAXFILELEN) == NULL)
19635 		   strcpy(firstfile,"./");
19636 		if (firstfile[strlen(firstfile)-1] == '/')
19637 		   firstfile[strlen(firstfile)-1] = '\0';
19638 
19639 		p = fsel.files[0];
19640 		while (p[0] == '.' && p[1] == '.') {
19641 		   q = firstfile;
19642 		   if ((q = strrchr(firstfile, '/'))) q[0] = '\0';
19643 		   p++; p++; p++;
19644 		}
19645 		if (p[0] == '.') p++;
19646 		if (p[0] == '/') p++;
19647 		if (firstfile[strlen(firstfile)-1] != '/')
19648 		   strcat(firstfile,"/");
19649 		strcat(firstfile,p);
19650 	   }
19651 	}
19652 }
19653 
NewDir(fs)19654 void NewDir(fs)
19655 FSELSTRU *fs;
19656 {
19657 char* p;
19658 char  tmpdir[MAXDIRLEN];
19659 
19660 	seldir = fs->dirlist.select;
19661 	if (seldir > fs->ndirs - 1) seldir = fs->ndirs - 1;
19662 
19663 	if (strcmp(fs->dirs[seldir],"..") == 0) {
19664 	    strcpy(tmpdir,fs->lastdir);
19665 	    if (fs->lastdir[0] != '/') {
19666 
19667 		if (getcwd(fs->lastdir,MAXDIRLEN) == NULL)
19668 		   strcpy(fs->lastdir,"./");
19669 		if (fs->lastdir[strlen(fs->lastdir)-1] != '/')
19670 		   strcat(fs->lastdir,"/");
19671 
19672 		p = tmpdir;
19673 		if (p[0] == '.') p++;
19674 		if (p[0] == '/') p++;
19675 		strcat(fs->lastdir,p);
19676 	    }
19677 
19678 	    if (fs->lastdir[strlen(fs->lastdir)-1] == '/')
19679 		fs->lastdir[strlen(fs->lastdir)-1] = '\0';
19680 
19681 	    if ((p = strrchr(fs->lastdir, '/'))) {
19682 		p++; *p = '\0';
19683 	    }
19684 
19685 	} else {
19686 	    if (strcmp(fs->dirs[seldir],".") != 0) {
19687 		strcat(fs->lastdir,fs->dirs[seldir]);
19688 		strcat(fs->lastdir,"/");
19689 	    }
19690 	}
19691 }
19692 
19693 #if defined(VMS) || defined(UNDERSC)
19694 void parsfn(char *str, int *nstr, int *iopt);
19695 #else
19696 #ifdef CRAY
19697 void PARSFN(char *str, int *nstr, int *iopt);
19698 #else
19699 void parsfn_(char *str, int *nstr, int *iopt);
19700 #endif
19701 #endif
19702 
palette()19703 int palette()
19704 {
19705     int iii, clopt, ich, doret;
19706     LSSTRU List;
19707 
19708 #ifdef DOGL
19709     GLint loc;
19710     List.list = palopt; List.nents = 9;
19711 #ifdef GL_COLOR_ATTACHMENT0_EXT
19712     if (has_shader && has_fbo) List.nents = 12;
19713 #endif
19714 #else
19715     List.list = palopt; List.nents = 7;
19716 #endif
19717 
19718     doret = 1;
19719 
19720     if (DoPopUp(winMC, cbut[BPAL].x+1,cbut[BPAL].y+BUTTH,
19721 	&List,&clopt,0) == -1) {
19722    	update_model = 0;
19723 	return(0);
19724     }
19725 
19726     RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
19727 
19728     switch (clopt) {
19729 	case 0:
19730 		List.list = bgopt; List.nents = 2;
19731 		if (DoPopUp(winMC,cbut[BPAL].x+1,cbut[BPAL].y+BUTTH,
19732 			    &List,&BGmode,0) == -1) return(0);
19733 #if defined(VMS) || defined(UNDERSC)
19734 		wrtres();
19735 #else
19736 #ifdef CRAY
19737 		WRTRES();
19738 #else
19739 		wrtres_();
19740 #endif
19741 #endif
19742 		break;
19743 
19744 	case 1:
19745 	case 2:
19746 		if (!monoscr) {
19747 		    int colt;
19748 
19749 		    update_model = 0;
19750 
19751 		    if (clopt == 1) {
19752 			if (DoPopUp(winMC,cbut[BPAL].x-8,cbut[BPAL].y+BUTTH,
19753 				    NULL,&iii,0) == -1) return(0);
19754 			colt = iii;
19755 		    } else {
19756 			if (has_opengl && (*fancy || *fullgl)) {
19757 				colt = 13; BGmode = 1;
19758 			} else colt = 0;
19759 		    }
19760 
19761 		    if (has_opengl && (*fancy || *fullgl) ) {
19762 			OBGcolor = colt;
19763 		    } else {
19764 			IBGcolor = colt;
19765 		    }
19766 
19767 		    XSetBackground(display, gc, colors[IBGcolor]);
19768 
19769 #ifdef DOGL
19770 		    if (has_opengl) setobg();
19771 #endif
19772 #if defined(VMS) || defined(UNDERSC)
19773 		    wrtres();
19774 #else
19775 #ifdef CRAY
19776 		    WRTRES();
19777 #else
19778 		    wrtres_();
19779 #endif
19780 #endif
19781 		}
19782 		break;
19783 
19784 	case 3:
19785 		doret = 0;
19786 		update_model = 0;
19787 		if (!COLup) InitCOL();
19788 		else XMapRaised(display,COLwin);
19789 		break;
19790 
19791 	case 4:
19792 		doret = 0;
19793 		if (!monoscr) {
19794 			if (DoPopUp(winMC,cbut[BPAL].x-8,cbut[BPAL].y+BUTTH,
19795 				    NULL,&iii,0) == -1) return(0);
19796 			if (iii) {
19797 			   activecolor = iii;
19798 			   update_model = 0;
19799 			   if (!ECOLup) EditCOL();
19800 			   else XMapRaised(display,ECOLwin);
19801 			}
19802 		}
19803 		break;
19804 
19805 	case 5:
19806 		ResetColors();
19807 		break;
19808 
19809 	case 6:
19810 		doret = 0;
19811 		update_model = 0;
19812 		if (!DPTup) InitDPT();
19813 		else XMapRaised(display,DPTwin);
19814 		break;
19815 
19816 	case 7:
19817 		doret = 0;
19818 		update_model = 0;
19819 		if (!STRCup) inistrc();
19820 		break;
19821 
19822 	case 8:
19823 		List.list = Chains;
19824 		List.nents = calfptr->nchain;
19825 
19826 		doret = 0;
19827 
19828 		if (DoPopUp(winMC,cbut[BPAL].x-8,cbut[BPAL].y+8*BUTTH,
19829 			     &List,&ich,0) == -1) return(0);
19830 
19831 		RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
19832 
19833 		if (DoPopUp(winMC,cbut[BPAL].x-8,cbut[BPAL].y+8*BUTTH,
19834 			     NULL,&iii,0) == -1) return(0);
19835 
19836 		RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
19837 		chncol(ich,iii-1,1);
19838 		break;
19839 	case 9:
19840 		DoSSAO = 0;
19841 		DoShad = 0;
19842 		DoShadow = 0;
19843 		if (DoBlur) {
19844 		   DoBlur = 0;
19845 		} else {
19846 		   DoBlur = 1;
19847 		}
19848 		break;
19849 	case 10:
19850 		List.list = occlopt; List.nents = 2;
19851 
19852 		DoBlur = 0;
19853 		DoShad = 0;
19854 		DoShadow = 0;
19855 		if (DoSSAO) {
19856 		   DoSSAO = 0;
19857 		} else {
19858 		   if (DoPopUp(winMC,cbut[BPAL].x+1,cbut[BPAL].y+10*BUTTH,
19859 			    &List,&SSAO_type,0) == -1) return(0);
19860 		   RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
19861 		   DoSSAO = 1;
19862 		}
19863 #ifdef DOGL
19864 #ifdef GL_ARB_shader_objects
19865 		glUseProgramObjectARB(program[1]);
19866 		loc    = glGetUniformLocationARB(program[1], "ssaotyp");
19867 		glUniform1iARB(loc, SSAO_type);
19868 #endif
19869 #endif
19870 		break;
19871 	case 11:
19872 		if (DoShad) DoShad = 0;
19873 		else {
19874 		   DoShad = 1;
19875 		   DoShadow = 1;
19876 		   DoSSAO = 0;
19877 		   DoBlur = 0;
19878 		}
19879 		break;
19880        }
19881 
19882        return(doret);
19883 }
19884 
ScrollWheel(inct,incp,iop)19885 void ScrollWheel(inct,incp,iop)
19886 int *inct;
19887 int *incp;
19888 int iop;
19889 {
19890         update_model = 0;
19891 	*inct = 417;
19892 
19893 	*incp = 5;
19894 	if (iop) *incp = -5;
19895 
19896 #if defined(VMS) || defined(UNDERSC)
19897 	mktrn(inct,incp);
19898 	qupd();
19899 #else
19900 #ifdef CRAY
19901  	MKTRN(inct,incp);
19902 	QUPD();
19903 #else
19904        	mktrn_(inct,incp);
19905 	qupd_();
19906 #endif
19907 #endif
19908 
19909 }
19910 
setgif(iopt)19911 void setgif(iopt)
19912 int iopt;
19913 {
19914 
19915   if (dogif) {
19916 	dogif = 0;
19917 	if (iopt) {
19918 	   TogBut(&cbut[BGIF]);
19919 	} else {
19920 	   TogBut(&dbut[BGIF2]);
19921 	}
19922   } else {
19923 	if (DisplayCells(display, screen) > 256) {;
19924 	   strcpy(molwstr,"GIF file only for 8-bits screen");
19925 	   StatusStr(0,1);
19926 	} else {
19927 	   dogif = 1;
19928 	   if (iopt) {
19929 #ifdef DOGL
19930 	     if (has_opengl && (*fancy || *fullgl)) {
19931 		strcpy(molwstr,"a Gif file per screen update");
19932 		StatusStr(0,1);
19933 		if (dogif) {
19934 		    picnum++;
19935 		    if (picnum < *picmax) {
19936 		  	glXWaitGL();
19937 			sprintf(stemp, "%s%03d.gif",GifFile,picnum);
19938 			WOGLGIF(stemp);
19939 			glXSwapBuffers(display, win);
19940 		    }
19941 		}
19942 	     } else {
19943 #endif
19944 	 	strcpy(molwstr,"a GIF file per screen update");
19945 		StatusStr(0,1);
19946 #if defined(VMS) || defined(UNDERSC)
19947 		doexp();
19948 #else
19949 #ifdef CRAY
19950 		DOEXP();
19951 #else
19952 		doexp_();
19953 #endif
19954 #endif
19955 #ifdef DOGL
19956 	     }
19957 #endif
19958 	     TogBut(&cbut[BGIF]);
19959 	   } else {
19960 	     TogBut(&dbut[BGIF2]);
19961 	   }
19962 	}
19963   }
19964   update_model = 0;
19965 }
19966 
RedrawFwin(fs)19967 void RedrawFwin(fs)
19968 FSELSTRU *fs;
19969 {
19970   int i;
19971 
19972   XSetForeground(display, gc, infobg);
19973   if (fs->parse) {
19974 	str2qbox(&qboxes[QREADF],fs->lastdir,MAXPATHLEN);
19975   } else {
19976 	str2qbox(&qboxes[QREADF],fs->pntr,MAXPATHLEN);
19977   }
19978   PromptBox(&qboxes[QREADF]);
19979 
19980   RedrawList(&fs->flist);
19981   RedrawList(&fs->dirlist);
19982 
19983   if (fs->parse) {
19984 	for (i=0; i<NBUTTR; i++) DrwBut(&fs->rbut[i]);
19985 	PromptBox(&qboxes[QPDB]);
19986 	PromptBox(&qboxes[QSUBSTR]);
19987   } else {
19988 	for (i=0; i<2; i++) DrwBut(&fs->rbut[i]);
19989   }
19990 
19991   ULineString(fs->win, "Files", 325, 55);
19992   ULineString(fs->win, "Directories", 325, 265);
19993   if (fs->parse) {
19994 	LineString(fs->win, "Filter:", 322, 145);
19995 	LineString(fs->win, "Replace", 350, 85);
19996 	LineString(fs->win, "Add", 350, 110);
19997   }
19998 
19999 }
20000 
EndOMAP()20001 void EndOMAP()
20002 {
20003   int j;
20004 
20005   if (!OMAPup) return;
20006 
20007   XSync(display, False);
20008   XDestroyWindow(display,OMAPwin);
20009   XSync(display, False);
20010   omapfol = 0;
20011   omapCa = -1;
20012   OMAPtype = 0;
20013   if (omaplck) {
20014  	for (j=0; j<3; j++) rotptr->t[j] = omapt[j];
20015 	omaplck = 0;
20016   }
20017   OMAPup = 0;
20018 #ifdef DOGL
20019   for (j=0; j<NSurf[istruct]; j++) {
20020 	if (SSon[istruct][j]) clp[istruct][j] = 0;
20021   }
20022 
20023   DeleteSurface(omapsrf);
20024 
20025   deletebox();
20026 #endif
20027   update_struct();
20028 }
20029 
ClickOMAP(int i)20030 void ClickOMAP(int i)
20031 {
20032    int j,i2;
20033 
20034    if (i>=0) {
20035 
20036      switch (i) {
20037 	case 0:
20038 	   if (OMAPup) EndOMAP();
20039 	   break;
20040 
20041 	case 1:
20042 	   TogBut(&butomap[1]);
20043 	   if (omapfol) {
20044 		omapfol = 0;
20045    		for (j=0; j<3; j++) {
20046 			rotptr->t[j] = omapt[j];
20047 			omaprat[j] = 1.0;
20048 		}
20049    		for (j=0; j<6; j++) {
20050 			omaprat[j] = 1.0;
20051 			RedrawSlide(&omapscr[j]);
20052 		}
20053 		UpdateOMAP1();
20054 		UpdateSLAB1();
20055 		UpdateOMAP2();
20056 		UpdateSLAB2();
20057 		UpdateOMAP3();
20058 		UpdateSLAB3();
20059 		disp_map(NULL);
20060 		update_struct();
20061 	   } else {
20062 		if (!omaphlp) {
20063 	           if (DoCan(event.xbutton.x_root,
20064 			event.xbutton.y_root,
20065 			"Use space bar to lock/unlock\nDensity volume",0)) {}
20066 		   omaphlp = 1;
20067 		   RedrawOMAP();
20068 		}
20069 		omapfol = 1;
20070 	   	for (j=0; j<3; j++) {
20071 			int i2;
20072 			omapt[j] = rotptr->t[j];
20073 			i2 = 1 + 2*j;
20074 			omaprat[i2] = 25.0/(float) comsrfptr->r[j];
20075 			omapwpos[i2] =
20076 				(int) ((float) omapwn[i2]*omaprat[i2]);
20077 			RedrawSlide(&omapscr[i2]);
20078 		}
20079 	   }
20080 	   UpdateSLAB1();
20081 	   UpdateSLAB2();
20082 	   UpdateSLAB3();
20083 	   update_struct();
20084 	   break;
20085 
20086 	case 2:
20087 	   omapcnt1 = atof(qboxes[QCNT].str);
20088 	   if (omapPandN) omapcnt2 = atof(qboxes[QCNT2].str);
20089 	   disp_map(NULL);
20090 	   break;
20091 
20092 	case 3:
20093 	   if (!TogBut(&butomap[3])) {
20094 		DoLines = 1;
20095 		for (j=0; j<NSurf[istruct]; j++) {
20096 		   if (SSon[istruct][j]) {
20097 			trns[istruct][j] = 0;
20098 		   }
20099 		}
20100 	   } else {
20101 		DoLines = 0;
20102 		for (j=0; j<NSurf[istruct]; j++) {
20103 		   if (SSon[istruct][j] && Schain[istruct][i] == -1) {
20104 			trns[istruct][j] = 1;
20105 		   }
20106 		}
20107 	   }
20108 	   disp_map(NULL);
20109 	   break;
20110 
20111      }
20112 
20113    } else {
20114 
20115 	if (ClickBox(&qboxes[QCNT],1, event.xbutton.x,event.xbutton.y) >= 0) {
20116 		qboxes[QCNT].active = 1;
20117 		qboxes[QCNT2].active = 0;
20118 		RedrawOMAP();
20119 	}
20120 	if (ClickBox(&qboxes[QCNT2],1, event.xbutton.x,event.xbutton.y) >= 0) {
20121 		qboxes[QCNT2].active = 1;
20122 		qboxes[QCNT].active = 0;
20123 		RedrawOMAP();
20124 	}
20125    }
20126 
20127    for (j=0; j<6; j++) {
20128 	if (SlideScroll(&omapscr[j],event.xbutton.x,event.xbutton.y)) { }
20129    }
20130 
20131 }
20132 
FileSelectBP(fs)20133 int FileSelectBP(fs)
20134 FSELSTRU *fs;
20135 {
20136     int i;
20137 
20138 #ifndef VMS
20139 
20140     if (PressList(&fs->dirlist,event.xbutton.x, event.xbutton.y)) {
20141 	 if (fs->ndirs > 0) {
20142 	     NewDir(fs);
20143 	     getfiles(fs,fs->lastdir);
20144 	     RedrawFwin(fs);
20145 	     update_model = 0;
20146 	 }
20147     }
20148 
20149 #endif
20150 
20151     if (PressList(&fs->flist,event.xbutton.x, event.xbutton.y)) {
20152 
20153 	 selfil = fs->flist.select;
20154 	 if (selfil > fs->nfiles - 1) selfil = fs->nfiles - 1;
20155 	 lpnt = fs->flist.lpnt;
20156          XFlush(display);
20157          XSync(display, True);
20158          RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
20159          XSync(display, True);
20160 
20161 	 if (fs->parse) {
20162 
20163 	    if (fs->files[selfil][0] != '/') {
20164 		strcpy(strname,fs->lastdir);
20165 #ifndef VMS
20166 		if (strname[strlen(strname)-1] != '/') strcat(strname,"/");
20167 #endif
20168 		strcat(strname,fs->files[selfil]);
20169 	    } else strcpy(strname,fs->files[selfil]);
20170 
20171 	    if (strstr(strname,".ogl")) {
20172 		if (!has_opengl) {
20173 		   lViewer(strname);
20174 		   return(1);
20175 		}
20176 	    }
20177 
20178 	    XFlush(display);
20179 	    if (ParseFile(strname,fs->files[selfil])) return(1);
20180 
20181 	 } else {
20182 	    str2qbox(&qboxes[QREADF],fs->files[selfil],-1);
20183 	    PromptBox(&qboxes[QREADF]);
20184 	    if (fs->subopt == 1) {
20185 		str2qbox(&qboxes[QMFILE],fs->files[selfil],-1);
20186 	        PromptBox(&qboxes[QMFILE]);
20187 	    }
20188 	 }
20189     } else {
20190 
20191 	update_model = 0;
20192 
20193 	i = ClickBox(&qboxes[QREADF],1,event.xbutton.x,event.xbutton.y);
20194 	if (i>=0) {
20195 	    qboxes[QREADF].active = 1;
20196 	    qboxes[QPDB].active = 0;
20197 	    qboxes[QSUBSTR].active = 0;
20198 	}
20199 	PromptBox(&qboxes[QREADF]);
20200 
20201 
20202 	if (fs->parse) {
20203 	   i = ClickBox(&qboxes[QSUBSTR],1,event.xbutton.x,event.xbutton.y);
20204 	   if (i>=0) {
20205 	       qboxes[QSUBSTR].active = 1;
20206 	       qboxes[QREADF].active = 0;
20207 	       qboxes[QPDB].active = 0;
20208 	   }
20209 	   i = ClickBox(&qboxes[QPDB],1,event.xbutton.x,event.xbutton.y);
20210 	   if (i>=0) {
20211 	       qboxes[QPDB].active = 1;
20212 	       qboxes[QSUBSTR].active = 0;
20213 	       qboxes[QREADF].active = 0;
20214 	   }
20215 	   PromptBox(&qboxes[QREADF]);
20216 	   PromptBox(&qboxes[QSUBSTR]);
20217 	   PromptBox(&qboxes[QPDB]);
20218 	   i=Clickwin(fs->rbut,NBUTTR,event.xbutton.x, event.xbutton.y,1);
20219 	} else {
20220 	   i=Clickwin(fs->rbut,2,event.xbutton.x, event.xbutton.y,1);
20221 	}
20222 
20223 	if (i>=0) {
20224         	switch (i) {
20225                     case BDIR : if (fs->parse) {
20226 				   getfiles(fs,qboxes[QREADF].str);
20227 				} else {
20228 				   getfiles(fs,fs->lastdir);
20229 				}
20230 				RedrawFwin(fs);
20231 				break;
20232                     case BCAN : XUnmapWindow(display,fs->win);
20233 				TogUp(&cbut[BREADF]);
20234                                 fs->qbrfile = 0;
20235 				if (!fs->parse && !fs->subopt) {
20236 				   cpstr(qboxes[QREADF].str,gfile,SUBLEN1);
20237 	    			   *Sinct = fs->inct;
20238 	    			   return(1);
20239 				}
20240                                 break;
20241                     case BREP : TogBut(&fs->rbut[Fwinopt]);
20242 				ActBut(&fs->rbut[Fwinopt],1);
20243 				Fwinopt = BREP;
20244 				TogBut(&fs->rbut[Fwinopt]);
20245 				ActBut(&fs->rbut[Fwinopt],-1);
20246 				addfile = 0;
20247 				break;
20248                     case BADD : TogBut(&fs->rbut[Fwinopt]);
20249 				ActBut(&fs->rbut[Fwinopt],1);
20250 				Fwinopt = BADD;
20251 				TogBut(&fs->rbut[Fwinopt]);
20252 				ActBut(&fs->rbut[Fwinopt],-1);
20253 				addfile = 1;
20254 				if (DoCan(event.xbutton.x_root,
20255 					event.xbutton.y_root,
20256 				"The ADD file is only functional for file types:\n  - Mol2, PDB, sdf and XYZ files",0)) {}
20257 				break;
20258                     case BPDB :
20259 				if (!CheckWGET()) {
20260 				    strcpy(strname,"");
20261 				    GetPDBWWW(qboxes[QPDB].str,strname);
20262 				    if (ParseFile(strname,qboxes[QPDB].str)) return(1);
20263 				}
20264 				break;
20265                     case BSPDB :
20266 				InitSRCH(event.xbutton.x_root,
20267 					event.xbutton.y_root);
20268 				break;
20269 		}
20270 	}
20271 
20272     }
20273 }
20274 
FileSelect(fs)20275 void FileSelect(fs)
20276 FSELSTRU *fs;
20277 {
20278 
20279     fs->win = CreateWindow("Molden File Select","-80-80",QBOXWIDE,QBOXRFD,
20280                             infobg,infofg,(Window)0);
20281     XSelectInput(display, fs->win, ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
20282 
20283     DefBut(&fs->rbut[BDIR],  fs->win, 325, 275            , 110, BUTTH,
20284         	   "Update Directory", infobg, CNTCOL);
20285 
20286     if (fs->parse) {
20287 	DefBut(&fs->rbut[BCAN],  fs->win, 325, 275+BUTTN      , 50, BUTTH,
20288         	   "Close", infobg, CNTCOL);
20289 
20290 	DefBut(&fs->rbut[BREP],  fs->win, 325, 75            , 15, 15,
20291         	   " ", infobg, CNTCOL);
20292 	DefBut(&fs->rbut[BADD],  fs->win, 325, 100            ,15, 15,
20293         	   " ", infobg, CNTCOL);
20294 	DefBut(&fs->rbut[BPDB],  fs->win, 380, 216            ,65, BUTTH,
20295         	   "<-Get PDB", infobg, CNTCOL);
20296 	DefBut(&fs->rbut[BSPDB],  fs->win, 325, 190           ,70, BUTTH,
20297         	   "Search PDB", infobg, CNTCOL);
20298 	ActBut(&fs->rbut[Fwinopt],-1);
20299 	TogDown(&fs->rbut[Fwinopt]);
20300     } else {
20301 	DefBut(&fs->rbut[BCAN],  fs->win, 325, 275+BUTTN      , 50, BUTTH,
20302         	   "OK", infobg, CNTCOL);
20303     }
20304 
20305 
20306     if (fs->nfiles == 0) {
20307 	  getfiles(fs,fs->lastdir);
20308     } else {
20309 	if (fs->parse) {
20310 	  if (firstreadf) GetFirstFile();
20311 	}
20312     }
20313 
20314     WinObj[9].win = &fs->win;
20315     WinObj[9].subwin = NULL;
20316     WinObj[9].butarr = fs->rbut;
20317     WinObj[9].numbut = 5;
20318     WinObj[9].winup = NULL;
20319     WinObj[9].init = FileSelect;
20320     WinObj[9].redraw = NULL;
20321 }
20322 
FileSelectList(fs)20323 void FileSelectList(fs)
20324 FSELSTRU *fs;
20325 {
20326    DefList(&fs->flist,fs->win,DIRX,DIRY,DIRW,DIRH,NULL,
20327 		NFLS,fs->files,NULL,NULL,NULL,&fs->nfiles,NULL);
20328    fs->flist.select = selfil;
20329    fs->flist.lpnt = lpnt;
20330    DefList(&fs->dirlist,fs->win,DDIRX,DDIRY,DDIRW,
20331 		DDIRH,NULL,NDRS,fs->dirs,NULL,NULL,NULL,&fs->ndirs,NULL);
20332    fs->dirlist.select = seldir;
20333    fs->dirlist.lpnt = 0;
20334    XMapWindow(display,fs->win);
20335 
20336    if (fs->parse) {
20337    	qboxstr(&qboxes[QREADF],&fs->win,1,0,-1,DEFQX,
20338 		DEFQY,QBOXWIDE,QBOXHIGH,0,
20339 		"Directory: ",fs->lastdir,0,
20340 		0,fs->inct,1,fwincall);
20341 
20342    	qboxstr(&qboxes[QSUBSTR],&fs->win,0,0,190,322,
20343 		155,60,35,0,
20344 		"","",0,0,fs->inct,-1,substrcall);
20345 
20346 	qboxstr(&qboxes[QPDB],&fs->win,0,0,190,322,
20347 		215,60,35,0,
20348 		"","",4,0,fs->inct,-1,getpdbcall);
20349    } else {
20350    	qboxstr(&qboxes[QREADF],&fs->win,1,0,-1,DEFQX,
20351 		DEFQY,QBOXWIDE,QBOXHIGH,0,
20352 		fs->label,fs->pntr,0,
20353 		0,fs->inct,-1,filecall);
20354 
20355    }
20356 }
20357 
UpdPHRM()20358 void UpdPHRM()
20359 {
20360     FeatSel = pharm.index[PHRMlist.select];
20361     if (FeatSel > -1 && FeatSel < pharm.NSelFeat) {
20362 	PHRMbut[6].str = FeatStr[pharm.array[FeatSel].type];
20363 	sprintf(qboxes[QPHRMR].str,"%f",pharm.array[FeatSel].rad*0.52917706);
20364     }
20365 
20366     if (PHRMup) {
20367 	ogfeatures();
20368 	dispsf();
20369 	XMapRaised(display,PHRMwin);
20370 	RedrawPHRM();
20371     }
20372 }
20373 
PHRMrad(char * str)20374 void PHRMrad(char *str)
20375 {
20376 	pharm.array[pharm.index[PHRMlist.select]].rad  =
20377 		atof(qboxes[QPHRMR].str) / 0.52917706;
20378 	UpdPHRM();
20379 }
20380 
Prt_CooD(double coo[3],int ianz)20381 void Prt_CooD(double coo[3],int ianz)
20382 {
20383 
20384     fprintf(stderr,"%d %#9.3f,%#9.3f,%#9.3f\n",ianz,
20385 		coo[0]*toangs, coo[1]*toangs, coo[2]*toangs);
20386 }
20387 
Prt_Coo(float coo[3],int ianz)20388 void Prt_Coo(float coo[3],int ianz)
20389 {
20390 
20391     fprintf(stderr,"%d %#9.3f,%#9.3f,%#9.3f\n",ianz,
20392 		coo[0]*toangs, coo[1]*toangs, coo[2]*toangs);
20393 }
20394 
PrtCoo(COOSTRU * coop,double * coo,int ATMsel)20395 void PrtCoo(COOSTRU *coop, double *coo,int ATMsel)
20396 {
20397     int k;
20398 
20399     fprintf(stderr,"Coordinates (Ang) %#9.3f,%#9.3f,%#9.3f\n",
20400 		coo[0]*toangs, coo[1]*toangs, coo[2]*toangs);
20401     fprintf(stderr,"ianz %d\n",coop->ianz[ATMsel]);
20402     fprintf(stderr,"num conn %d\n",coop->iconn[(ATMsel)*(MXCON+1)]);
20403 
20404     for (k=0; k < coop->iconn[(ATMsel)*(MXCON+1)]; k++)
20405 
20406     fprintf(stderr,"%d ",coop->iconn[(ATMsel)*(MXCON+1)+1+k]);
20407     fprintf(stderr,"\n");
20408     fprintf(stderr,"iresid %d\n",coop->iresid[ATMsel]);
20409 }
20410 
20411 #if defined(VMS) || defined(UNDERSC)
xwin(x,y,icomm,str,nstr,inct,incp)20412 void xwin(x, y, icomm, str, nstr, inct, incp)
20413 #else
20414 #ifdef CRAY
20415 void XWIN(x, y, icomm, str, nstr, inct, incp)
20416 #else
20417 void xwin_(x, y, icomm, str, nstr, inct, incp)
20418 #endif
20419 #endif
20420 
20421 float *x;
20422 float *y;
20423 int *icomm;
20424 #ifdef VMS
20425 struct dsc$descriptor_s *str;
20426 #else
20427 #ifdef CRAY
20428 _fcd str;
20429 #else
20430 char *str;
20431 #endif
20432 #endif
20433 int *nstr;
20434 int *inct;
20435 int *incp;
20436 
20437 
20438 {
20439 
20440   int done;
20441   int i,j;
20442 
20443   float Arg1;
20444   float Arg2;
20445   int Command;
20446 
20447   if (COO[0] == NULL) {
20448 	AllocateStructure(&COO[0]);
20449 	COO[0]->svgdone = 0;
20450 	COO[0]->fname = NULL;
20451   }
20452 
20453   if (*icomm == 15 || *icomm == 0) update_model = 1;
20454 
20455   Arg1 = *x;
20456   Arg2 = *y;
20457   Command = *icomm;
20458   if (Command == DenWindow || Command == MolWindow || Command == OpenWindow) {
20459      Sstr = str; Snstr = nstr; Sinct = inct; Sincp = incp;
20460   }
20461 
20462 
20463   switch(Command) {
20464   case DenWindow :
20465   {
20466 
20467 
20468 
20469     while(XCheckTypedWindowEvent(display,win,Expose,&report));
20470 
20471     if ( DowinC ) {
20472        DirBox(winC,1);
20473        DowinC = 0;
20474        ZoomEnable = True;
20475        ZoomSelection = False;
20476        xoff = 0.0;
20477        yoff = 0.0;
20478        scale = 1.0;
20479        XFlush(display);
20480     }
20481     if ( DoactC ) {actde(*inct,*incp,1);DoactC = 0;}
20482 
20483     done = 0;
20484     *inct = 0;
20485     *incp = 0;
20486     if (hold) {
20487        XSync(display, False);
20488        if (XPending(display)>0){
20489           if (XCheckMaskEvent(display,ButtonReleaseMask,&event))
20490                         { hold = 0; goto XXLOOP;}
20491        }
20492        if (!*ifdogl) {
20493 	   gl2DEnd();
20494 	   *inct = holdt;
20495 	   *incp = holdp;
20496 	   clrsave();
20497 	   gl2DInit();
20498 	   return;
20499        } else {
20500 #if defined(VMS) || defined(UNDERSC)
20501            mktrn(&holdt,&holdp);
20502 #else
20503 #ifdef CRAY
20504            MKTRN(&holdt,&holdp);
20505 #else
20506            mktrn_(&holdt,&holdp);
20507 #endif
20508 #endif
20509 	   if (update_model) ogind();
20510 	   else dispsf();
20511        }
20512     }
20513 XXLOOP:
20514 
20515     gl2DEnd();
20516 
20517     while (!done) {
20518 
20519 
20520 	XNextEvent(display, &event);
20521 
20522         switch (event.type) {
20523 
20524            case KeyPress:    {
20525               XKeyEvent *key_event = (XKeyEvent *) &event;
20526               char buf[1];  XComposeStatus status;  int stlen;
20527 
20528               stlen = XLookupString(key_event,buf,1,&ks,&status);
20529 	      /*if (!stlen) break;*/
20530 
20531 /* the following statement is only there to stop the compiler
20532    from optimising away ks */
20533 
20534 	      sprintf(stemp,"%d",(int) ks);
20535 
20536               for (i=0; i<NQBOX; i++)
20537 		if (key_event->window == qboxes[i].win && qboxes[i].active)
20538 		   if (KeyChk(&qboxes[i],buf[0],ks)) {
20539 		       if (key_event->window != fsel.win) {
20540 				if (*Sinct != 150) clrsave();
20541 				return;
20542 			}
20543 		   }
20544 
20545               /* do non-character processing (arrow-keys, that is) */
20546               if (key_event->window == win || key_event->window == winMC) {
20547                  if      (ks==XK_Left  || ks==XK_KP_4)
20548                    { *inct = 1; }
20549                  else if (ks==XK_Right || ks==XK_KP_6)
20550                    { *inct = -1; }
20551                  else if (ks==XK_Up    || ks==XK_KP_8)
20552                    { *incp = -1; }
20553                  else if (ks==XK_Down  || ks==XK_KP_2)
20554                    { *incp = 1; }
20555                  else if (buf[0]=='i')
20556                    { *inct = 30;
20557                      *incp = 1; }
20558                  else if (buf[0]=='d')
20559                    { *inct = 30;
20560                      *incp = -1; }
20561                  else if (buf[0]=='m')
20562                    { *inct = 45; }
20563                  else if (buf[0]=='c')
20564                    { *inct = 80; }
20565                  else if (buf[0]=='e')
20566                    { *inct = 85; }
20567 /*
20568                  else if (buf[0]=='3')
20569                    { *inct = 90; }
20570                  else if (buf[0]=='t') {
20571                    { sprintf(stemp,"Orbital number (1-%d)? ",NAT->norbs);
20572 		     qboxstr(&qboxes[QORB],NULL,1,0,-1,DEFQX,DEFQY,
20573 		     QBOXWIDE,QBOXHIGH, 0,stemp,NULL,0,1,160,dummyproc);
20574 		    }
20575 		 }
20576 */
20577                  else if (buf[0]=='n')
20578                    { *inct = 170; }
20579                  else if (buf[0]=='b')
20580                    { *inct = 180; }
20581                  else if (buf[0]=='a')
20582                    { *inct = 190; }
20583                  else if (buf[0]=='o')
20584                    { *inct = 200; }
20585                  else if (buf[0]=='r')
20586                    { *inct = 210; }
20587                  else if (buf[0]=='u')
20588 		   { OnTop(); }
20589                  if ((*ifdogl && has_opengl) && key_event->window == win) 				{Key(buf[0]);}
20590                  cnt = 0;
20591 		 clrsave();
20592                  if (!(*ifdogl && has_opengl)) return;
20593               }
20594            }
20595            break;
20596 
20597            case ButtonPress: {
20598 
20599               if(DEBUG)fprintf(stderr,"ButtonPress\n");
20600 
20601               if(event.xbutton.window == win && event.xbutton.button == 2
20602                  && ZoomEnable && !do3dx && !*ifdogl) {
20603 
20604                  ZoomEnable = False;
20605                  ZoomSelection = True;
20606                  MotionCount = 0;
20607 
20608                  XDefineCursor(display, win, ZoomCursor);
20609                  XSetFunction(display, gc, GXxor);
20610                  XSetForeground(display, gc, colors[11]);
20611                  ZoomX1 = event.xbutton.x;
20612                  ZoomY1 = event.xbutton.y;
20613                  ZoomW = 1;
20614                  ZoomH = 1;
20615                  XDrawRectangle(display, win, gc,
20616                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
20617 
20618               } else if(event.xbutton.window == win && event.xbutton.button == 2
20619                       && !ZoomEnable && !ZoomSelection && !*ifdogl) {
20620 
20621                  ZoomEnable = True;
20622                  scale = 1.0;
20623                  xoff = 0.0;
20624                  yoff = 0.0;
20625 
20626                  RedrawWin();
20627               } else if(event.xbutton.window == win &&
20628                       event.xbutton.button == 3) {
20629 
20630                  DirBox(winC,1);
20631                  if (qbcomm) DirBox(COMMwin,1);
20632                  if (DoEig) DirBox(EBox,1);
20633                  for (i=0; i<NQBOX; i++)
20634    		   if (qboxes[i].pop && qboxes[i].active)
20635 			XMapRaised(display,qboxes[i].win);
20636 
20637               }
20638 
20639               if (event.xbutton.window == EBox) {
20640 	       if (PressList(&elist,event.xbutton.x, event.xbutton.y)) {
20641 		 update_model = 1;
20642 		 *ivtwo = -1;
20643 		 clrsave();
20644                  *inct = 160;
20645 		 if (*iuhf && ibeta) {
20646 			*incp = -1*(elist.select+1);
20647 		 } else {
20648 			*incp = elist.select+1;
20649 		 }
20650 		 gl2DInit();
20651                  return;
20652 	       }
20653 	      } else if(event.xbutton.window == win &&
20654                       event.xbutton.button == 1 ) {
20655 
20656                  int curtx = event.xbutton.x;
20657                  int curty = event.xbutton.y;
20658                  float dangy,tsqx,tsqy;
20659 
20660                  if (!ZoomEnable && *dospa  && !*ifdogl) {
20661                     ZoomEnable = True;
20662                     scale = 1.0;
20663                     xoff = 0.0;
20664                     yoff = 0.0;
20665                     return;
20666                  }
20667 
20668 		 if (*ifdogl) {
20669 		    moving = 1;
20670 		    startx = event.xbutton.x;
20671 		    starty = event.xbutton.y;
20672 		    btype = 0;
20673 		    if (event.xbutton.state & ShiftMask) btype = 1;
20674 		    if (event.xbutton.state & ControlMask) btype = 2;
20675 		    if ((event.xbutton.state & ControlMask)
20676 			  && (event.xbutton.state & ShiftMask)) btype = 3;
20677 		    if (has_opengl)
20678 			  moused(event.xbutton.button,event.xbutton.state,
20679 					  event.xbutton.x, event.xbutton.y);
20680 		    break;
20681 
20682                  } else {
20683 		   hold = 1;
20684 		   holdt = 0;
20685 		   holdp = 0;
20686                    tsqx = (int) (width / 2 - curtx);
20687                    tsqy = (int) (height / 2 - curty);
20688                    cnt = 0;
20689 		   clrsave();
20690 		   gl2DInit();
20691                    if (tsqx == 0 && tsqy == 0) return;
20692                    if (tsqx == 0 && tsqy > 0) { *incp = -1; holdp = *incp; return;}
20693                    if (tsqx == 0 && tsqy < 0) { *incp =  1; holdp = *incp; return;}
20694                    if (tsqy == 0 && tsqx > 0) { *inct = -1; holdt = *inct; return;}
20695                    if (tsqy == 0 && tsqx < 0) { *inct =  1; holdt = *inct; return;}
20696                    dangy = tsqy / tsqx;
20697                    if (tsqx > 0) {
20698                     if (dangy <= 1 && dangy >= -1) {
20699                         *inct = 1; holdt = *inct; return;}
20700                     else if (dangy > 1) {
20701                         *incp = 1; holdp = *incp; return;}
20702                     else { *incp = -1; holdp = *incp; return;}
20703                    }
20704                    if (tsqx < 0) {
20705                     if (dangy <= 1 && dangy >= -1) {
20706                         *inct = -1; holdt = *inct; return;}
20707                     else if (dangy > 1) {
20708                         *incp = -1; holdp = *incp; return;}
20709                     else { *incp = 1; holdp = *incp; return;}
20710                    }
20711                  }
20712               }
20713 
20714               if (event.xbutton.window == win && event.xbutton.button == 4)
20715 			ScrollWheel(inct,incp,1);
20716 
20717 
20718               if (event.xbutton.window == win && event.xbutton.button == 5)
20719 		 	ScrollWheel(inct,incp,0);
20720 
20721 
20722               if (event.xbutton.window == QBox && qboxup)  {
20723 		for (j=0; j<NQBOX; j++)
20724 		    if (qboxes[j].win == QBox && qboxes[j].active) break;
20725 		i = Clickwin(qboxclose,2,event.xbutton.x,event.xbutton.y,1);
20726 		if (i == 0) {
20727 		   if (KeyChk(&qboxes[j],'\012',(KeySym) 0)) return;
20728 		} else if (i == 1) {
20729 		   XDestroyWindow(display,QBox);
20730 		   XSync(display, False);
20731 		   qboxup = 0;
20732 		}
20733 	      }
20734 
20735 	      if (event.xbutton.button  == 3)
20736 			QBoxPaste(event.xbutton.window,qboxes,NQBOX);
20737 
20738               if (event.xbutton.window == MAPwin) {
20739 		 i = Clickwin(mapbut,NBUTSM,event.xbutton.x, event.xbutton.y,1);
20740 		 if (i>=0) {
20741 			if (ButtonsMAP(i)) return;
20742 		 } else {
20743 			i = ClickBox(&qboxes[QVFILE],10,
20744 				event.xbutton.x,event.xbutton.y);
20745 			if (i>=0) {
20746 				for (j=0; j<10; j++) qboxes[QVFILE+j].active = 0;
20747 				qboxes[QVFILE+i].active = 1;
20748 				RedrawMAP();
20749 			}
20750 		 }
20751 	      }
20752 
20753 	      if (event.xbutton.window == OMAPwin && OMAPup) {
20754 		    update_model = 0;
20755 		    i = Clickwin(butomap,3,event.xbutton.x, event.xbutton.y,1);
20756 		    ClickOMAP(i);
20757 	      }
20758 
20759               if (event.xbutton.window == VIRwin) {
20760 		 i = Clickwin(virbut,2,event.xbutton.x, event.xbutton.y,1);
20761 		 if (i>=0) {
20762 			if (ButtonsVIR(i)) return;
20763 		 } else {
20764 			i = ClickBox(&qboxes[QSVFILE],2,
20765 				event.xbutton.x,event.xbutton.y);
20766 			if (i>=0) {
20767 				for (j=0; j<2; j++)
20768 					qboxes[QSVFILE+j].active = 0;
20769 				qboxes[QSVFILE+i].active = 1;
20770 				RedrawVIR();
20771 			}
20772 		 }
20773 	      }
20774 
20775               if (event.xbutton.window == STRCwin) {
20776 	         update_model = 0;
20777 		 i = Clickwin(strcbut,STRCBN,event.xbutton.x, event.xbutton.y,1);
20778 		 if (i>=0) {
20779 			if (ButtonsSTRC(i)) return;
20780 		 } else {
20781 			if (PressList(&strclist,
20782 				event.xbutton.x, event.xbutton.y)) {
20783 
20784 				dispsf();
20785 			}
20786 		 }
20787 	      }
20788 
20789               if (event.xbutton.window == gsel.win ) {
20790 
20791 		if (FileSelectBP(&gsel) == 1) return;
20792 
20793               }
20794 
20795               if (event.xbutton.window == dsel.win ) {
20796 
20797 		if (FileSelectBP(&dsel) == 1) return;
20798 
20799               }
20800               if (event.xbutton.window == winC) {
20801 		 int doret = 1;
20802 		 *ivtwo = -1;
20803                  i=Clickwin(dbut,NBUTTS,event.xbutton.x, event.xbutton.y,1);
20804 
20805 		 update_model = 1;
20806 		 gl2DInit();
20807 
20808                  if (i>=0) {
20809                  switch (i) {
20810                  case BPSI:
20811 			update_model = 0;
20812 			doret = 0;
20813 			if (TogBut(&dbut[BPSI])) {
20814 			   XDestroyWindow(display,EBox);
20815 			   *inct = 160; *incp = 0;
20816 			   DoEig = 0;
20817 			}
20818 			else {
20819 			   LSSTRU List;
20820 			   List.list = alphbet; List.nents = 2;
20821 			   if (*iuhf) {
20822 				if (DoPopUp(winC,dbut[BPSI].x+1,
20823 					dbut[BPSI].y+BUTTH,&List,&ibeta,0) == -1) break;
20824 			   }
20825 			   EBox = CreateWindow("Molden Orbital Select",
20826 				"-80-80",QBOXWIDE,QBOXRF,infobg,infofg,
20827 				(Window)0);
20828 
20829 			   XSelectInput(display, EBox, ExposureMask |
20830 				KeyPressMask | ButtonPressMask |
20831 				ButtonReleaseMask | ButtonMotionMask |
20832 				LeaveWindowMask | EnterWindowMask);
20833 
20834 			   WinObj[18].win = &EBox;
20835 			   WinObj[18].subwin = NULL;
20836 			   WinObj[18].butarr = NULL;
20837 			   WinObj[18].numbut = -1;
20838 			   WinObj[18].winup = &DoEig;
20839 			   WinObj[18].init = NULL;
20840 			   WinObj[18].redraw = NULL;
20841 
20842 			   if ((*iuhf && !ibeta) || !*iuhf)
20843       				DefList(&elist,EBox,DIRX,DIRY,DIRW,DIRH,
20844 				" Nr.        Eigenvalue   Occupation",
20845 				NFLS,NULL,dorbp->eiga,dorbp->focc,
20846 				NULL,dorbp->ncols,NULL);
20847 
20848 			   if (*iuhf && ibeta)
20849       				DefList(&elist,EBox,DIRX,DIRY,DIRW,DIRH,
20850 				" Nr.        Eigenvalue   Occupation",
20851 				NFLS,NULL,dorbp->eigb,dorbp->focb,NULL,
20852 				dorbp->ncolb,NULL);
20853 
20854 			   XMapWindow(display,EBox);
20855 			   DoEig = 1;
20856 			}
20857 			break;
20858                  case BHOMO: *inct = 230; break;
20859                  case BLUMO: *inct = 240; break;
20860                  case BNDEN: if (*iuhf)
20861 				{LSSTRU List;
20862 				 List.list = spdopt; List.nents = 2;
20863 				 if (DoPopUp(winC,dbut[BNDEN].x+1,
20864 					dbut[BNDEN].y+BUTTH,&List,ispd,0) == -1) break;
20865 				}
20866 			     *inct = 170;
20867 			     break;
20868                  case BLAPL: *inct = 171; break;
20869                  case BELF:  *inct = 172; *valcnt = 0.8; break;
20870                  case BBONDS: *inct = 180; break;
20871                  case BATOM: *inct = 190; break;
20872                  case BOVRLP: *inct = 200; break;
20873                  case BELPOT: {
20874 				int itmp;
20875 				LSSTRU List;
20876 				List.list = pots2; List.nents = 3;
20877 				if (DoPopUp(winC,dbut[BELPOT].x+1,
20878 					dbut[BELPOT].y+BUTTH,&List,&itmp,0) == -1) break;
20879 				*inct = 350+itmp;
20880 				break;}
20881                  case BMAXMIN: *inct = 360; break;
20882                  case BPOST:   {
20883 				LSSTRU List;
20884 				if (do3dx) {
20885 			           if (DoCan(event.xbutton.x_root,
20886 					event.xbutton.y_root,
20887 				"Postscript is not supported for this drawing mode",0)) {}
20888 				   break;
20889 				}
20890 				List.list = postopt; List.nents = 2;
20891 				if (DoPopUp(winC,dbut[BPOST].x+1,
20892 					dbut[BPOST].y+BUTTH,&List,icolps,0) == -1) break;
20893 				qboxstr(&qboxes[QPOST],NULL,1,0,-1,DEFQX,DEFQY,
20894 					QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
20895 					0,0,150,0,dummyproc);
20896 				}
20897 				break;
20898                  case BMOLMOD: *inct = 75; DirBox(winC,0);
20899                                 DowinMC =1;DoactMC = 1;
20900 				denmode = 0;
20901 		 		empty_model(istruct,1);
20902 				update_model = 1;
20903 				ZoomEnable = True;
20904 				ZoomSelection = False;
20905 				xoff = 0.0;
20906 				yoff = 0.0;
20907 				scale = 1.0;
20908 				if (qbcomm) {
20909 			   	   TogUp(&dbut[BCOMM]);
20910 			   	   qbcomm = 0;
20911 			   	   XUnmapWindow(display,COMMwin);
20912 				}
20913 		 		if (DoEig) {
20914 				    TogUp(&dbut[BPSI]);
20915 				    XDestroyWindow(display,EBox);
20916 				    DoEig = 0;
20917 				}
20918 		 		if (STRCup) {
20919 				    XDestroyWindow(display,STRCwin);
20920 				    STRCup = 0;
20921 				}
20922                                 break;
20923                  case BEUCL: *inct = 85; do3dx = 0; *do3d = 0;*dospa = 0;
20924                              ActBut(&dbut[BCONT],1);
20925                              ActBut(&dbut[BINCRS],1);
20926                              ActBut(&dbut[BDECRS],1);
20927                              ActBut(&dbut[BSTEP],1);
20928                              ActBut(&dbut[BCUT],1);
20929                              ActBut(&dbut[BFILL],0);
20930                              DrwBut(&dbut[BCONT]);
20931                              DrwBut(&dbut[BFILL]);
20932                              DrwBut(&dbut[BSTEP]);
20933                              DrwBut(&dbut[BCUT]);
20934                              DrwBut(&dbut[BINCRS]);
20935                              DrwBut(&dbut[BDECRS]);
20936 #ifdef DOGL
20937 			     if (*ifdogl) {
20938 				*ifdogl = 0;
20939 				TogUp(&dbut[BOGL]);
20940 			     }
20941 #endif
20942                              break;
20943                  case B3D:
20944 			     *inct = 90; do3dx = 0; *do3d = 1; *dospa = 0;
20945                              ActBut(&dbut[BCONT],1);
20946                              ActBut(&dbut[BINCRS],1);
20947                              ActBut(&dbut[BDECRS],1);
20948                              ActBut(&dbut[BSTEP],1);
20949                              ActBut(&dbut[BCUT],1);
20950                              ActBut(&dbut[BFILL],0);
20951                              DrwBut(&dbut[BCONT]);
20952                              DrwBut(&dbut[BFILL]);
20953                              DrwBut(&dbut[BSTEP]);
20954                              DrwBut(&dbut[BCUT]);
20955                              DrwBut(&dbut[BINCRS]);
20956                              DrwBut(&dbut[BDECRS]);
20957 #if defined(VMS) || defined(UNDERSC)
20958 			     bldlst();
20959 #else
20960 #ifdef CRAY
20961 			     BLDLST();
20962 #else
20963 			     bldlst_();
20964 #endif
20965 #endif
20966 			     if (*ifdogl) doret = 0;
20967                              break;
20968                  case B3DX:
20969 			     *inct = 91; do3dx = 1; *do3d = 0; *dospa = 0;
20970                              ActBut(&dbut[BINCRS],1);
20971                              ActBut(&dbut[BDECRS],1);
20972                              ActBut(&dbut[BCONT],0);
20973                              ActBut(&dbut[BFILL],0);
20974                              ActBut(&dbut[BSTEP],0);
20975                              ActBut(&dbut[BCUT],0);
20976                              DrwBut(&dbut[BCONT]);
20977                              DrwBut(&dbut[BFILL]);
20978                              DrwBut(&dbut[BSTEP]);
20979                              DrwBut(&dbut[BCUT]);
20980                              DrwBut(&dbut[BINCRS]);
20981                              DrwBut(&dbut[BDECRS]);
20982 #if defined(VMS) || defined(UNDERSC)
20983 			     bldlst();
20984 #else
20985 #ifdef CRAY
20986 			     BLDLST();
20987 #else
20988 			     bldlst_();
20989 #endif
20990 #endif
20991 			     if (*ifdogl) doret = 0;
20992                              break;
20993                  case BSRF2:
20994 			     if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
20995 				"Go to Mol. Mode to view this\nUse the Surface icon to save the surface",0)) {
20996 				}
20997 			     linmax = 2;
20998                  case BVRML2:
20999 			     if ((do3dx || *do3d) && i == BVRML2 && ! *dospa) {
21000 				int optie;
21001 				LSSTRU List;
21002 				List.list = vrml2dopt; List.nents = 2;
21003 
21004 				if (DoPopUp(winC,dbut[BVRML2].x+1,
21005 					dbut[BVRML2].y+BUTTH,&List,&optie,0) == -1) break;
21006 				if (optie) {
21007 				   *inct = 651;
21008 				} else {
21009 				   qboxstr(&qboxes[QVRML],NULL,1,0,-1,
21010 				   DEFQX,DEFQY, QBOXWIDE,QBOXHIGH,0,
21011 				   "VRML Filename ? ",NULL,0,0,
21012 				   650,0,dummyproc);
21013 				}
21014 				break;
21015 			     }
21016                  case BSPACE:
21017 			     *ivtwo = -1;
21018 /* check */
21019 			     if (i == BVRML2) {
21020 				LSSTRU List; LSSTRU MList;
21021 				if (!*ipsi) {
21022 				   MList.list = denopt; MList.nents = 2;
21023 				   if (DoPopUp(winC,dbut[BVRML2].x-25,
21024 					dbut[BVRML2].y+BUTTH,&MList,mapit,0) == -1) break;
21025 				}
21026 				if (! *mapit) {
21027 				   List.list = vrmlopt; List.nents = 4;
21028 				   if (DoPopUp(winC,dbut[BVRML2].x+1,
21029 					dbut[BVRML2].y+BUTTH,&List,ivtwo,0) == -1) break;
21030 				}
21031 			      }
21032 			     do3dx = 0; *do3d = 0;
21033                              ActBut(&dbut[BCONT],0);
21034                              ActBut(&dbut[BINCRS],0);
21035                              ActBut(&dbut[BDECRS],0);
21036                              ActBut(&dbut[BSTEP],0);
21037                              ActBut(&dbut[BCUT],0);
21038                              ActBut(&dbut[BFILL],1);
21039                              DrwBut(&dbut[BCONT]);
21040                              DrwBut(&dbut[BFILL]);
21041                              DrwBut(&dbut[BSTEP]);
21042                              DrwBut(&dbut[BCUT]);
21043                              DrwBut(&dbut[BINCRS]);
21044                              DrwBut(&dbut[BDECRS]);
21045 			     if (*mapit) {
21046 				doret = 0;
21047 				InitMAP();
21048 			     } else {
21049 				if (i == BVRML2)
21050 				   InitVIR();
21051 				else if (i == BSPACE &&
21052 				(NAT->natoms || (*cubetyp == 2 || *cubetyp == 3))) {
21053 				   qboxes[QSPAC].dflt = valcnt;
21054 	   			   sprintf(stemp,"%5.2f",*valcnt);
21055 		    		   qboxstr(&qboxes[QSPAC],NULL,1,0,-1,DEFQX,DEFQY,
21056 				   QBOXWIDE,QBOXHIGH, 0,"Contour Value ? ",stemp,
21057 				   0,3,92,-1,dummyproc);
21058 				   doret = 0;
21059 				}
21060 				else if (i == BSPACE) *inct = 92;
21061 				else if (i == BSRF2) *inct = 94;
21062 			     }
21063                              break;
21064                  case BFILL : *inct = 93;TogBut(&dbut[BFILL]);break;
21065                  case BINCRS: *inct = 30;*incp = 1;break;
21066                  case BDECRS: *inct = 30;*incp = -1;break;
21067                  case BCONT:  *inct = 80;TogBut(&dbut[BCONT]); break;
21068                  case BMOL:   *inct = 45;TogBut(&dbut[BMOL]); break;
21069                  case BCOMM:
21070 			*ivtwo = -1;
21071 			if (qbcomm) {
21072 			   TogUp(&dbut[BCOMM]);
21073 			   qbcomm = 0;
21074 			   XUnmapWindow(display,COMMwin);
21075 			}
21076 			else {
21077 			   TogDown(&dbut[BCOMM]);
21078 			   XMapWindow(display,COMMwin); qbcomm = 1;
21079 			   qboxstr(&qboxes[QCOMM],&COMMwin,1,0,-1,DEFQX,DEFQY,
21080 				QBOXWIDE,QBOXHIGH,0,"Command Line ? ",NULL,
21081 				0,0,220,-1,dummyproc);
21082 			}
21083 			if (*ifdogl) doret = 0;
21084 			break;
21085                  case BQUIT: {
21086 			if (!DoCan(event.xbutton.x_root,
21087 					event.xbutton.y_root,
21088 					" Are you sure to quit?  ",1)) {
21089 		          FreeAll(1);
21090                           XFreeGC(display, gc);
21091                           XCloseDisplay(display);
21092                           *inct = 15;
21093 			} }
21094 			break;
21095                  case BCUBE:
21096 			{int irwopt; LSSTRU List;
21097 			 List.list = rwopt; List.nents = 2;
21098 			 if (DoPopUp(winC,dbut[BCUBE].x+1,
21099 				dbut[BCUBE].y+BUTTH-30,&List,&irwopt,0) == -1) break;
21100 			 if (irwopt) {
21101 			    qboxstr(&qboxes[QCUBE],NULL,1,0,-1,DEFQX,DEFQY,
21102 				QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
21103 				0,0,282,0,dummyproc);
21104 			 } else {
21105 			    List.list = cubeopt; List.nents = 3;
21106 			    if (DoPopUp(winC,dbut[BCUBE].x+1,
21107 				dbut[BCUBE].y+BUTTH-30,&List,cubetyp,0) == -1) break;
21108 			    *do3d = 0; do3dx = 0;
21109 			    qboxstr(&qboxes[QCUBE],NULL,1,0,-1,DEFQX,DEFQY,
21110 				QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
21111 				0,0,281,0,dummyproc);
21112 			 }
21113         		 XSync(display, False);
21114 			}
21115 			break;
21116                  case BGIF2:
21117 			setgif(0);
21118 			doret = 0;
21119 			break;
21120                  case BLOCAL:
21121 #if defined(VMS) || defined(UNDERSC)
21122 			dipole();
21123 #else
21124 #ifdef CRAY
21125 			DIPOLE();
21126 #else
21127 			dipole_();
21128 #endif
21129 #endif
21130 			doret = 0;
21131 			break;
21132                  case BOGL:
21133 #ifdef DOGL
21134 			if (*ifdogl) {
21135 			   *ifdogl = 0;
21136 			   TogUp(&dbut[BOGL]);
21137 			   gl2DInit();
21138 			} else {
21139 			   if (has_opengl) {
21140 			      *ifdogl = 1;
21141 			      TogDown(&dbut[BOGL]);
21142 			      if (!do3dx && !*do3d && !*dospa) *do3d = 1;
21143 			      dispsf();
21144 			      inistrc();
21145 			   }
21146 			}
21147 			doret = 1;
21148 #endif
21149 			break;
21150                  case BORI: *inct = 210; TogBut(&dbut[BORI]); break;
21151                  case BSTEP: {
21152 		      qboxstr(&qboxes[QSTEP],NULL,1,0,-1,DEFQX,DEFQY,
21153 			QBOXWIDE,QBOXHIGH,0,"Step ? ",NULL,0,3,250,-1,
21154 				dummyproc);
21155 		      break;}
21156                  case BCUT: {
21157 		      qboxstr(&qboxes[QCUT],NULL,1,0,-1,DEFQX,DEFQY,
21158 			QBOXWIDE,QBOXHIGH,0,"Cut (0.0 > cut <= 1.0) ? ",NULL,
21159 			0,3,260,-1,dummyproc);
21160 		      break;}
21161                  case BWRBAS: *inct = 270; break;
21162                  case BRDBAS:
21163 /*				if (*dospa) {*/
21164 				{
21165 				 LSSTRU List;
21166 				 List.list = readgrd; List.nents = 2;
21167 				 if (DoPopUp(winC,dbut[BRDBAS].x+1,
21168 					dbut[BRDBAS].y+BUTTH,&List,incp,0) == -1) break;
21169 /*				}*/
21170 				gsel.qbrfile = 1;
21171 				gsel.subopt = 0;
21172 				FileSelectList(&gsel);
21173 				doret = 0;
21174 				*inct = 280;
21175 				}
21176 				break;
21177                  }
21178                  cnt = 0;
21179 		 clrsave();
21180                  if (doret) return;
21181                  }
21182               }
21183 
21184            }
21185            break;
21186 
21187 
21188            case MotionNotify: {
21189 
21190 
21191               if(DEBUG)fprintf(stderr,"MotionNotify\n");
21192 
21193 	      if (!bcksvg.UpSVG) SetExplButton(event.xmotion.window,
21194 				event.xmotion.x,event.xmotion.y);
21195 
21196               if(event.xmotion.window == win && ZoomSelection) {
21197                  int NewX, NewY;
21198 
21199 
21200                  while(XCheckTypedWindowEvent(display, win, MotionNotify,
21201                                         &event));
21202 
21203                  MotionCount++;
21204 
21205 #ifdef DOGL
21206 		 rubber(0);
21207 #else
21208                  XDrawRectangle(display, win, gc,
21209                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
21210 #endif
21211 
21212                  /* get the location of the pointer */
21213 
21214                  NewX = event.xmotion.x;
21215                  NewY = event.xmotion.y;
21216 
21217                  ZoomX2 = MAXI(ZoomX1, NewX);
21218                  ZoomY2 = MAXI(ZoomY1, NewY);
21219                  ZoomW = MAXI(ABS(ZoomX2 - ZoomX1),1);
21220                  ZoomH = MAXI(ABS(ZoomY2 - ZoomY1),1);
21221 
21222 #ifdef DOGL
21223 		 rubber(0);
21224 #else
21225                  XDrawRectangle(display, win, gc,
21226                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
21227 #endif
21228 
21229               } /* end ZoomSelection */
21230               if (event.xmotion.window == win && *ifdogl && (moving || gmoving)) {
21231 	        /*update_model = 0;*/
21232 		if (XCheckMaskEvent(display,ButtonReleaseMask,&event)) {
21233 		   if (has_opengl) motion(event.xmotion.x, event.xmotion.y, 1);
21234 		   moving = 0;
21235 		} else {
21236 		   while (XCheckMaskEvent(display,ButtonMotionMask,&event));
21237 		   *incp = (event.xmotion.x - startx);
21238 		   if (btype == 0) {
21239 			*inct = 421;
21240 		   } else if (btype == 1) {
21241 			*inct = 415;
21242 		   } else if (btype == 2) {
21243 			*inct = 417;
21244 		   } else if (btype == 3) {
21245 			*inct = 422;
21246 		   }
21247 #if defined(VMS) || defined(UNDERSC)
21248 		   mktrn(inct,incp);
21249 #else
21250 #ifdef CRAY
21251         	   MKTRN(inct,incp);
21252 #else
21253         	   mktrn_(inct,incp);
21254 #endif
21255 #endif
21256 		   *incp = (event.xmotion.y - starty);
21257 		   if (btype == 0) {
21258 			*inct = -421;
21259 		   } else if (btype == 1) {
21260 			*inct = 416;
21261 		   }
21262 
21263 #if defined(VMS) || defined(UNDERSC)
21264 		   mktrn(inct,incp);
21265                    if (*ifdogl) motion(event.xmotion.x, event.xmotion.y, 0);
21266 		   else qupd();
21267 #else
21268 #ifdef CRAY
21269         	   MKTRN(inct,incp);
21270                    if (*ifdogl) motion(event.xmotion.x, event.xmotion.y, 0);
21271 		   else QUPD();
21272 #else
21273         	   mktrn_(inct,incp);
21274                    if (*ifdogl) motion(event.xmotion.x, event.xmotion.y, 0);
21275 		   else qupd_();
21276 #endif
21277 #endif
21278 		   startx = event.xmotion.x;
21279 		   starty = event.xmotion.y;
21280 		   *inct = 0;
21281 		   XFlush(display);
21282 		   XSync(display, False);
21283                 }
21284 	      }
21285            } /* end MotionNotify */
21286            break;
21287 
21288 
21289            case ButtonRelease: {
21290 
21291 
21292               if(DEBUG)fprintf(stderr,"ButtonRelease\n");
21293 
21294               if (!*ifdogl && event.xbutton.window == win) {
21295 		 moving = 0;
21296 		 gmoving = 0;
21297 	      }
21298 
21299               if (event.xbutton.window == win &&
21300 		  (event.xbutton.button == 1 || event.xbutton.button == 2) &&
21301                   !ZoomSelection ) moving = 0;
21302 
21303               if(event.xbutton.window == win && event.xbutton.button == 2
21304                  && ZoomSelection ) {
21305 
21306                  ZoomSelection = False;
21307                  XDrawRectangle(display, win, gc,
21308                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
21309                  XSetFunction(display, gc, GXcopy);
21310                  XUndefineCursor(display, win);
21311 
21312 
21313                  ZoomX2 = event.xbutton.x;
21314                  ZoomY2 = event.xbutton.y;
21315 
21316                  if (MotionCount >=3 ) {
21317 
21318                     scale   = height*1.0 /MAXI(ABS(ZoomY2 - ZoomY1),1);
21319                     xoff = ZoomX1*1.0 / height;
21320 		    yoff = ZoomY1*1.0 / height;
21321 		    if (*fullgl && !*ifdogl) {
21322 			yoff = 1.0 - yoff - 1.0/scale;
21323 		    }
21324 
21325                     RedrawWin();
21326                  }
21327                  else
21328                  {ZoomEnable = True;}
21329 
21330 
21331 
21332               } /* end zoom */
21333 
21334               if (*ifdogl && event.xbutton.window == win) {
21335 		 mouseu(event.xbutton.button,event.xbutton.state,
21336 			event.xbutton.x, event.xbutton.y);
21337                  dispsf();
21338 		 break;
21339 	      }
21340 
21341            } /* end ButtonRelease */
21342            break;
21343 
21344 
21345 	   case ClientMessage: {
21346 		Atom proto, delwin;
21347 		XClientMessageEvent *client_event =
21348 			(XClientMessageEvent *) &event;
21349 
21350 		proto = XInternAtom(display, "WM_PROTOCOLS", False);
21351 		delwin = XInternAtom(display, "WM_DELETE_WINDOW", False);
21352 
21353 		if (client_event->message_type == proto &&
21354 		    client_event->data.l[0] == delwin) {
21355 		    if (client_event->window == COMMwin) {
21356 			if (qbcomm) {
21357 			   TogUp(&dbut[BCOMM]);
21358 			   qbcomm = 0;
21359 			   XUnmapWindow(display,COMMwin);
21360 			}
21361 		    } else if (client_event->window == EBox) {
21362 			if (DoEig) {
21363 			   TogUp(&dbut[BPSI]);
21364 			   DoEig = 0;
21365 			   XUnmapWindow(display,EBox);
21366 			}
21367 		    } else if (client_event->window == QBox) {
21368 			XDestroyWindow(display,QBox);
21369 			XSync(display, False);
21370 		        qboxup = 0;
21371 		    }
21372 		}
21373 	   }
21374 	   break;
21375 
21376            case Expose: {
21377 
21378 
21379               if(DEBUG)fprintf(stderr,"Expose\n");
21380 
21381         /* if the window doesn't do intelligent redraw, drop all-1 exposes */
21382 
21383 	      if (event.xexpose.count>0 && event.xexpose.window != win) break;
21384 
21385 	      while(XCheckTypedWindowEvent(display,win,Expose,&report)) {
21386 	           if (event.xexpose.count == 0) break;
21387 	      }
21388 
21389               if (event.xexpose.window == win && !ZoomSelection && !*ifdogl) {
21390                    if (!CheckForConfig()) {
21391                        if (!*fullgl && molback == molcur) {
21392                           XCopyArea(display,molcur,win,gc,0,0,width,height,0,0);
21393                        }
21394                        else {
21395                           RedrawWin();
21396                        }
21397                    }
21398               } else {
21399                    if (event.xexpose.window == winC) {
21400 			while(XCheckTypedWindowEvent(display,win,
21401 				Expose,&report)) {
21402 			}
21403                    	RedrawwinC(0,0,WINCWIDE,WINCHIGH);
21404 		   }
21405               }
21406 
21407               if (*ifdogl && event.xexpose.window == win) {
21408                  dispsf();
21409               }
21410 
21411               for (i=0; i<NQBOX; i++)
21412 		if (event.xexpose.window == qboxes[i].win)
21413 			PromptBox(&qboxes[i]);
21414 
21415               for (i=0; i<NOBJS; i++) {
21416 	         if (WinObj[i].win != NULL && WinObj[i].winup != NULL) {
21417 	            if (event.xexpose.window == *WinObj[i].win
21418 			&& WinObj[i].redraw != NULL && *(WinObj[i].winup))
21419 			WinObj[i].redraw();
21420 		 }
21421 	      }
21422 	      if (event.xexpose.window == EBox) RedrawList(&elist);
21423 	      if (event.xexpose.window == gsel.win) RedrawFwin(&gsel);
21424 	      if (event.xexpose.window == dsel.win) RedrawFwin(&dsel);
21425            }
21426            break;
21427 
21428 	   case MapNotify: {
21429 	      if (event.xmap.window == expldat.win &&
21430 		event.xmap.send_event == True) DoExpl();
21431            }
21432            break;
21433 
21434 	   case EnterNotify: {
21435 		if (!bcksvg.UpSVG) {
21436 		   expldat.win = -1;
21437 		   signal(SIGALRM,SIG_IGN);
21438 		}
21439            }
21440            break;
21441 
21442 	   case LeaveNotify: {
21443 		if (!bcksvg.UpSVG) {
21444 		   expldat.win = -1;
21445 		   signal(SIGALRM,SIG_IGN);
21446 		}
21447            }
21448            break;
21449 
21450            case ConfigureNotify: {
21451 
21452               if(DEBUG)fprintf(stderr,"ConfigureNotify\n");
21453 
21454               /* you want to increase or decrease the size of the window*/
21455               /* get the new width and height*/
21456 
21457               if (event.xconfigure.window == win) {
21458 
21459 		   while(XCheckTypedWindowEvent(display, win,
21460 			ConfigureNotify,&event)) {
21461 		   }
21462 
21463                    if (event.xconfigure.width == width &&
21464                        event.xconfigure.height == height) {
21465 			if (has_opengl && *ifdogl) {
21466 #ifdef DOGL
21467 			    glXSwapBuffers(display, win);
21468 #endif
21469 			} else {
21470 			    if ( !*fullgl && molback == molcur) {
21471 				XCopyArea(display,molcur,win,gc,
21472 					0,0,width,height,0,0);
21473 			    } else {
21474 				RedrawWin();
21475 			    }
21476                         }
21477 			break;
21478 		   }
21479 
21480                    width  = event.xconfigure.width;
21481                    height = event.xconfigure.height;
21482 
21483                    /* now resize the Graphics window, this will generate an
21484                       expose event*/
21485 
21486                    if (!CheckForConfig()) {
21487                       XEvent xev;
21488                       xwa.width = width;
21489                       xwa.height = height;
21490                       XResizeWindow(display,
21491                                     win,
21492                                     width,
21493                                     height);
21494 
21495                    while (XCheckTypedWindowEvent(display, win, Expose, &xev)) {
21496                       XExposeEvent *exp = (XExposeEvent *) &xev;}
21497 
21498 		   Aspect = (float) width / (float) height;
21499 		   if (has_opengl && *ifdogl) Reshape(1);
21500 		   else {
21501                       if (do3dx || *dospa) return;
21502                       else RedrawWin();
21503 		   }
21504 
21505                    }
21506               }
21507            }
21508            break;
21509 
21510            case UnmapNotify:         break;
21511 
21512            default: break;		/* ignore unexpected events */
21513 
21514         }  /* end switch event type*/
21515 
21516     }/* end while */
21517 
21518     XFreeGC(display, gc);
21519     XCloseDisplay(display);
21520     *inct = 15;
21521     return;
21522 
21523   } /* end DenWindow */
21524   break;
21525 
21526   case MolWindow :
21527   {
21528 
21529 
21530     if ( DowinMC ) {
21531        DirBox(winMC,1);
21532        DowinMC = 0;
21533        ZoomEnable = False;
21534        ZoomSelection = False;
21535     }
21536 
21537     if (DoactMC) {
21538 #if defined(VMS) || defined(UNDERSC)
21539 	curs(&ZERO);
21540 #else
21541 #ifdef CRAY
21542 	CURS(&ZERO);
21543 #else
21544 	curs_(&ZERO);
21545 #endif
21546 #endif
21547 	actde(*inct,*incp,0);
21548 	DoactMC = 0;
21549 	if (ntits > 1)  {
21550 	   if (!MLTup)  initMLT();
21551 	   else RedrawMLT();
21552  	}
21553 
21554     }
21555 
21556     done = 0;
21557     *inct = 0;
21558     *incp = 0;
21559 
21560 
21561     if (hold) {
21562        update_model = 0;
21563        while (1){
21564         XSync(display, False);
21565         if (XCheckMaskEvent(display,ButtonReleaseMask,&event))
21566           		{ hold = 0; goto XLOOP;}
21567 	doclr();
21568 #if defined(VMS) || defined(UNDERSC)
21569         mktrn(&holdt,&holdp);
21570 	qupd();
21571 #else
21572 #ifdef CRAY
21573         MKTRN(&holdt,&holdp);
21574 	QUPD();
21575 #else
21576         mktrn_(&holdt,&holdp);
21577 	qupd_();
21578 #endif
21579 #endif
21580        }
21581     }
21582 XLOOP:
21583 
21584     if (animptr.on) {
21585        int donext=0;
21586 
21587        while (1){
21588 	int i;
21589 	double vartmp;
21590 
21591         XSync(display, False);
21592 	if (update_res == -1) update_model = 1;
21593 	doclr();
21594 /*        if (XCheckTypedWindowEvent(display,ANIMwin,Expose,&event)) {*/
21595 	   if (ANIMup) RedrawANIM();
21596 /*	}*/
21597         if (XCheckMaskEvent(display,ButtonPressMask,&event)) {
21598 	   if (event.xbutton.window == win) {
21599 		hold = 0;
21600 		XSendEvent(display, win, False, NoEventMask, &event);
21601 		goto ALOOP;
21602 	   } else if (event.xbutton.window == ANIMwin) {
21603 		if (ANIMup) {
21604 		   RedrawANIM();
21605 		   i = Clickwin(butANIM,ANIMBN,
21606 			event.xbutton.x, event.xbutton.y,1);
21607 		   if (i>=0) {
21608 			if (ButtonsANIM(i)) {
21609 			   SwitchOffAnim();
21610 			   goto ALOOP;
21611 			} else {
21612 			   donext = 1;
21613 			}
21614 		   }
21615 		}
21616 	   }
21617         }
21618 	if (donext) {
21619 	   i = 0;
21620 	   animptr.frame = animptr.frame + animptr.vdirection;
21621 	   if (animptr.frame >= animptr.nframe ||
21622 	    animptr.frame <= -animptr.nframe) {
21623 		animptr.vdirection = -1*animptr.vdirection;
21624 		i = 1;
21625 	   }
21626 	   vartmp = animptr.varinit +
21627 		animptr.frame * animptr.varincr[animptr.vartype];
21628 	   if (animptr.vartype == 0 && vartmp <= 0.0) {
21629 		vartmp = *animptr.variable;
21630 		animptr.vdirection = -1*animptr.vdirection;
21631    	   }
21632 	   if (animptr.vartype == 1 && (vartmp <= 0.0 || vartmp >= 180.0)) {
21633 		vartmp = *animptr.variable;
21634 		if (!i) animptr.vdirection = -1*animptr.vdirection;
21635 	   }
21636 	   *animptr.variable = vartmp;
21637 	   AnimLinks(vartmp);
21638 	   if (animptr.part) zmpart->ipart = animptr.part;
21639 	   if (!animptr.ssdone) SSdone[istruct] = 0;
21640 	   anim();
21641 	}
21642 	if (!ANIMNXT) donext = 0;
21643        }
21644      }
21645 ALOOP:
21646 
21647     while (!done) {
21648 
21649 	XFlush(display);
21650 	if (XPending(display) == 0  && DoFreq ) {
21651 		XSync(display,False); return;
21652 	}
21653 	if (aflag && !cflag && !dflag) {
21654 	   if (! ((*fancy || *fullgl) && has_opengl) ) {
21655               XSetForeground(display, gc, colors[2]);
21656               for (i = 0; i <acnt-1; i++) {
21657 		   XDrawLine(display,win,gc,
21658 			xyzp->iyp[asel[i]-1],xyzp->ixp[asel[i]-1],
21659 			xyzp->iyp[asel[i+1]-1],xyzp->ixp[asel[i+1]-1]);
21660               }
21661            }
21662         }
21663 
21664 	if (DoSVGExpose) SvgExpose();
21665 	DoSvgfile();
21666         XNextEvent(display, &event);
21667         switch (event.type) {
21668 
21669            case KeyPress:    {
21670               XKeyEvent *key_event = (XKeyEvent *) &event;
21671               char buf[10];  XComposeStatus status;  int stlen,istat;
21672 
21673               if(DEBUG)fprintf(stderr,"KeyPress\n");
21674 
21675               stlen = XLookupString(key_event,buf,1,&ks,&status);
21676 	      /*if (!stlen) break;*/
21677 
21678 /* the following statement is only there to stop the compiler
21679    from optimising away ks */
21680 
21681 	      sprintf(stemp,"%d",(int) ks);
21682 
21683               for (i=0; i<NQBOX; i++) {
21684 		if (key_event->window == qboxes[i].win && qboxes[i].active) {
21685 		   if (KeyChk(&qboxes[i],buf[0],ks)) {
21686 		       if (key_event->window == ATMwin && i == QATOM) {
21687 				if (ATMselp <= *xyzp->iatoms ||
21688 				    ChkLig(ATMselp) || ChkProt(ATMselp) ) {
21689 	    			    update_sel = 1;
21690 	    			    update_model = 0;
21691 				    if (xyzp->iaton[ATMsel] == 2)
21692 					xyzp->iaton[ATMsel] = 1;
21693 				    ATMsel = ATMselp - 1;
21694 				    xyzp->iaton[ATMsel] = 2;
21695 				    UpdateATM();
21696 				    RedrawATM();
21697 				    if (DCKLIGPROC) ogLigSurf();
21698 				    else if (DCKPROTPROC == 1) ogIntSurf();
21699 				    update_struct();
21700 				} else {
21701 				    if (DoCan(width/2, height/2,
21702 					"Number greater than total number of atoms",0)) {
21703 				    }
21704 				}
21705 			}
21706 		       if (!(key_event->window == fsel.win &&
21707 			     (i == QREADF || i == QSUBSTR))) {
21708 				return;
21709 			}
21710 		   }
21711 		}
21712 	      }
21713 
21714               if (key_event->window == ZMEwin) {
21715 		int isl;
21716 
21717 		istat = 0; isl = 0;
21718 		for (i=0; i<*zmptrp->nz; i++) {
21719 			if (IANZbox[i].active) {
21720 			   istat = KeyChk(&IANZbox[i],buf[0],ks);
21721 			   isl = i;
21722 			}
21723 			if (BLbox[i].active) {
21724 			   istat = KeyChk(&BLbox[i],buf[0],ks);
21725 			   isl = i;
21726 			}
21727 			if (ALPHbox[i].active) {
21728 			   istat = KeyChk(&ALPHbox[i],buf[0],ks);
21729 			   isl = i;
21730 			}
21731 			if (BETbox[i].active) {
21732 			   istat = KeyChk(&BETbox[i],buf[0],ks);
21733 			   isl = i;
21734 			}
21735 			for (j=0; j<4; j++) {
21736 				if (IZbox[i*4+j].active) {
21737 				   istat = KeyChk(&IZbox[i*4+j],buf[0],ks);
21738 			   	   isl = i;
21739 				}
21740 			}
21741 		}
21742           	if (istat && !Selecting && !ZMEsel) {
21743 		    if (!mapchk()) map_prop();
21744 		    DeActZME(); GetQZME(); UpdateZME();
21745 		    if (IsPhiPsi(isl)) {
21746 			FindZRangeFromBox(isl);
21747 	   		if (zmpart->ipart) {
21748 			   zmpart->imx = *zmptrp->nz;
21749 			   update_res = -1;
21750 			   SSdone[istruct] = 0;
21751 	   		}
21752 		    } else FindZRangeFromBox(isl);
21753 		    update_model = 1;
21754 		    *Sinct = 530; return;
21755 		}
21756 		if (EXPbox[0].active)
21757 			if (KeyChk(&EXPbox[0],buf[0],ks))
21758 				aaexp(EXPbox[0].str,strlen(EXPbox[0].str));
21759 	      }
21760 
21761               if (key_event->window == win || key_event->window == winMC) {
21762 		 update_model = 0;
21763                  if      (ks==XK_Left)
21764                    { *inct = -3; *incp = 1; }
21765                  else if (ks==XK_Right)
21766                    { *inct = -3; *incp = -1; }
21767                  else if (ks==XK_Up)
21768                    { *inct = -2; *incp = 1;}
21769                  else if (ks==XK_Down)
21770                    { *inct = -2; *incp = -1;}
21771                  else if (ks==XK_KP_7)
21772                    { *inct = -1; *incp = 1;}
21773                  else if (ks==XK_KP_9)
21774                    { *inct = -1; *incp = -1;}
21775                  else if (ks==XK_KP_1)
21776                    { *inct = 290; *incp = -1;}
21777                  else if (ks==XK_KP_3)
21778                    { *inct = 290; *incp = 1;}
21779                  else if (ks==XK_KP_4)
21780                    { *inct = 420; }
21781                  else if (ks==XK_KP_6)
21782                    { *inct = 430; }
21783                  else if (ks==XK_KP_8)
21784                    { *inct = 440;}
21785                  else if (ks==XK_KP_2)
21786                    { *inct = 450;}
21787                  else if (ks==XK_space)
21788                    { if (omaplck) omaplck = 0;
21789 		     else {
21790 			omaplck = 1;
21791 			for (i=0; i<3; i++)
21792 			   rotptr->t[i] = xyzp->coo[omapCa*3+i];
21793 			update_struct();
21794 		     }
21795 		   }
21796                  else if (buf[0]=='a' || buf[0]=='A')
21797 		   {
21798 			if (!gijsup) {
21799 			   createauthor();gijsup = 1;
21800 			} else {
21801 			   XFreePixmap(display,gijs);
21802 			   XDestroyWindow(display,winau);gijsup = 0;
21803 			}
21804 		   }
21805                  else if (buf[0]=='s')
21806                    { *inct = 75; DowinC = 1;DoactC = 1; }
21807                  else if (buf[0]=='f')
21808                    { update_model = 1; *inct = 100; }
21809                  else if (buf[0]=='n')
21810                    { update_model = 1; *inct = 110; }
21811                  else if (buf[0]=='l')
21812                    { *inct = 120; }
21813                  else if (buf[0]=='k')
21814                    { *inct = 130; }
21815                  else if (buf[0]=='b')
21816                    { *ball = 1; hold = 0;}
21817                  else if (buf[0]=='x')
21818                    { *inct = 610; }
21819                  else if (buf[0]=='m')
21820                    {update_model = 1;
21821 		     qboxstr(&qboxes[QMXYZ],NULL,1,0,-1,DEFQX,DEFQY,QBOXWIDE,
21822 			QBOXHIGH, 0,"XYZ file ? ",NULL,0,0,151,0,dummyproc);
21823 		   }
21824                  else if (buf[0]=='h')
21825                    {update_model = 1;
21826 		     qboxstr(&qboxes[QMXYZ],NULL,1,0,-1,DEFQX,DEFQY,QBOXWIDE,
21827 			QBOXHIGH, 0,"XYZ file ? ",NULL,0,0,152,0,dummyproc);
21828 		   }
21829                  else if (buf[0]=='u')
21830 		   { OnTop(); }
21831                  else if (buf[0]=='c')
21832 		   { *igtfil = 1;update_model = 1;
21833 		     DeActZME(); GetQZME(); UpdateZME();
21834 		     *Sinct = 530; return;
21835 		   }
21836                  else if (buf[0]==' ')
21837                    {
21838 			*inct = 155;
21839 		   }
21840                  else if (ks==XK_Escape) {
21841 		   if (DoDockCenter) {
21842 			DoDockCenter = 0;
21843 			DCKPROTPROC = 0;
21844 			if (!DCKBYPASS) {
21845 #ifndef DOGL
21846 			   DCKRadius = 8.0/((double) toangs);
21847 #endif
21848 			   createDock();dockup=1;
21849 			} else {
21850 			   ogIntSurf();
21851 			}
21852 		   }
21853                    if (dflag) {
21854 			dflag = 0;aflag = 0;
21855 			Selecting = 0; ZMEsel = 0;
21856 /*
21857 			for ( i = 0; i < *xyzp->iatoms; i++ ) {
21858 				if (xyzp->iaton[i] >= 2) xyzp->iaton[i] = 1;
21859 			}
21860 	    		update_sel = 1;
21861 			XUndefineCursor(display,win);
21862 			RedrawZME();
21863 */
21864 			XUndefineCursor(display,win);
21865 			if (*ialtyp == 1) {
21866                            for (i=0; i<*iscst; i++) xyzp->iaton[i] = 1;
21867                            for (i=*iscst; i<(*iscst)+(*nscnd); i++)
21868 				xyzp->iaton[i] = 2;
21869 			} else {
21870                            for (i=0; i<*xyzp->iatoms; i++) xyzp->iaton[i] = 2;
21871 			}
21872 	    		update_sel = 1;
21873                         *isimpl = 4;
21874                         ApplSel(0);
21875 		        update_model = 1;
21876                         return;
21877 		     } else {
21878 			if (update_casel)  exit_casel();
21879 			if (*irtcel) {
21880 		           update_model = 1;
21881 			   i = *irtcel; *irtcel = 0;
21882 			   ogmoll(0);
21883 			   *irtcel = i;
21884 			}
21885 			DoFreq = 0;
21886 		        update_model = 0;
21887 			*inct = 153;
21888                         return;
21889 		     }
21890 		   }
21891                  else if (ks==XK_Tab)
21892 		   { if (!Selecting && !cflag && !dflag) {
21893 			acnt = 0;
21894 			if (doalign) {
21895 			   cflag = 1;aflag = 6;anum = 6;
21896 			} else {
21897 			   cflag = 2;
21898 			   aflag = 2;anum = 2;
21899 			   if (event.xbutton.state & ShiftMask)
21900 				aflag = 4;anum = 4;
21901 			}
21902 		        XDefineCursor(display,win,AtomCursor);
21903 		     }
21904 		   }
21905                    if (((*fancy || *fullgl) && has_opengl)
21906 			&& key_event->window == win)
21907 			{Key(buf[0]);}
21908                  return;
21909               }
21910            }
21911            break;
21912 
21913            case ButtonPress: {
21914 	      int doret = 1;
21915 
21916               if(DEBUG)fprintf(stderr,"ButtonPress\n");
21917 
21918 	      if (!bcksvg.UpSVG) {
21919 	         expldat.win = -1;
21920 	         signal(SIGALRM,SIG_IGN);
21921 	      }
21922 
21923 	      update_model = 1;
21924 
21925               if(event.xbutton.window == win && !ZoomEnable &&
21926                 (event.xbutton.button == 1 || event.xbutton.button == 2)) {
21927                  int curx = event.xbutton.x;
21928                  int cury = event.xbutton.y;
21929 
21930 /* blag set: single atom selection */
21931 
21932                  if (bflag) {
21933                     XUndefineCursor(display,win);
21934                     bflag = 0;
21935                     *inct = bretval;
21936 		    if (bretval == 320) {
21937 			if (ScreenPDB(curx,cury)) {
21938 			   int ires=-1;
21939 			   ires = CurAmino + 1;
21940 #if defined(VMS) || defined(UNDERSC)
21941 			   actami(&ires,&ZERO,&ONE,&ZERO);
21942 #else
21943 #ifdef CRAY
21944 			   ACTAMI(&ires,&ZERO,&ONE,&ZERO);
21945 #else
21946 			   actami_(&ires,&ZERO,&ONE,&ZERO);
21947 #endif
21948 #endif
21949 			   *inct = 0;
21950 			   rsold = RESUND;
21951 #ifdef DOGL
21952 			   ogres(ires,ONE,1);
21953 #else
21954 			   return;
21955 #endif
21956 			}
21957 		    }
21958 		    *incp = 1 + FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
21959 					*xyzp->iatoms,curx,cury,MINDIFF);
21960 
21961 		    if (bretval == 321) {
21962 			*inct = 530;
21963 			idum1 = DelAmino(xyzp->iresid[*incp-1]);
21964 		    }
21965 
21966 		    if (bretval == 563) {
21967 		        j = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
21968 			    *xyzp->iatoms,curx,cury,MINDIFF);
21969 			if (j != -1) {
21970                            for (i=0; i<3; i++) {
21971 				CNTDCK[i] = (float) xyzp->coo[j*3+i];
21972 			   }
21973 			}
21974 			DoDockCenter = 1;
21975 		    }
21976 
21977 		    if (bretval == 322) {
21978 			*inct = 530;
21979 			InsertAmino = xyzp->iresid[*incp-1];
21980 			if (SEQup) {
21981 			   XMapRaised(display,SEQwin);
21982 			   RedrawSEQ();
21983 			} else {
21984 			   InitSEQ(event.xbutton.x_root,
21985 				event.xbutton.y_root);
21986 			}
21987 		    }
21988 
21989 		    if (bretval == 561) {
21990 			for ( i = 0; i < *xyzp->iatoms; i++ ) xyzp->iaton[i] = 1;
21991 			xyzp->iaton[*incp-1] = 2;
21992 	    		update_sel = 1;
21993 		    }
21994 		    if (bretval == 565) {
21995 			int ir;
21996 
21997 			ir = xyzp->iresid[*incp-1];
21998 			for (i=0; i < *xyzp->iatoms; i++ ) {
21999 			   if (xyzp->iresid[i] == ir) xyzp->iaton[i] = 2;
22000 			}
22001 	    		update_sel = 1;
22002 		    }
22003 
22004 		    if (bretval == 566) {
22005 
22006 #if defined(VMS) || defined(UNDERSC)
22007 			proxic(incp,backb,&ONE,&ZERO,&THRESH);
22008 #else
22009 #ifdef CRAY
22010 			PROXIC(incp,backb,&ONE,&ZERO,&THRESH);
22011 #else
22012 			proxic_(incp,backb,&ONE,&ZERO,&THRESH);
22013 #endif
22014 #endif
22015 			ressel();
22016 	    		update_sel = 1;
22017 		    }
22018 		    return;
22019                  }
22020 
22021 /* aflag set: select multiple atoms */
22022 
22023                  if (aflag && ! bflag && !(event.xbutton.state & ControlMask)) {
22024                     int ia,ib,floke,low,up;
22025 
22026 		    up = *xyzp->iatoms;
22027 		    low = 0;
22028 
22029 		    if (cflag) {
22030 			if (acnt == 0 || acnt == 2 || acnt == 4) {
22031 			   low = 0; up = *iscst;
22032 			} else {
22033 			   low = *iscst; up = *xyzp->iatoms;
22034 			}
22035 		    }
22036 
22037 
22038 		    ib = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,low,up,
22039 				curx,cury,MINDIFF);
22040 
22041 		    if (ib < 0) ib = -2;
22042                     floke = 1;
22043 
22044                     for (ia = 0; ia <acnt; ia++) {
22045 			if (dflag) {
22046 			   if (ia < *xyzp->mxnat)
22047 				if (jring[ia] == ib+1 ) floke = 0;
22048 			} else {
22049                            if (asel[ia] == ib+1 ) floke = 0;
22050 			}
22051 		    }
22052 
22053 /*
22054 		    if (cflag) {
22055 			if (acnt == 0 || acnt == 2 || acnt == 4) {
22056 			   if (ib >= *iscst) floke = 0;
22057 			} else {
22058 			   if (ib < *iscst) floke = 0;
22059 			}
22060 		    }
22061 */
22062 
22063                     if (floke && ib >= 0) {
22064 
22065 		       if (dflag) {
22066 			  if (acnt < *xyzp->mxnat) jring[acnt] = ib+1;
22067 		       } else {
22068 			  asel[acnt] = ib+1;
22069 		       }
22070 
22071 		       if (aflag && (*fancy || *fullgl) && has_opengl) {
22072 			  xyzp->iaton[ib] = 3;
22073 		          update_model = 0;
22074 	    		  update_sel = 1;
22075 #ifdef DOGL
22076 			  dispsf();
22077 #endif
22078 		       }
22079 
22080                        aflag--;
22081                        acnt++;
22082 
22083                        if (*ibell) XBell(display,0);
22084 
22085 		       if (cflag) {
22086 			xyzp->iaton[ib] = 3 + (acnt-1)/2;
22087 	    		update_sel = 1;
22088 #ifdef DOGL
22089 			ogsel();
22090 #endif
22091 			if (aflag) return;
22092 		       }
22093 
22094 		       if (dflag) {
22095 			xyzp->iaton[ib] = 3;
22096 			sprintf(stemp,"%d Atoms to go",aflag);
22097 			strcpy(ZMEerr,stemp);
22098 			RedrawStatus();
22099 	    		update_sel = 1;
22100 			if (aflag) {
22101 		           update_model = 0;
22102 			   return;
22103 			}
22104 		       }
22105                     }
22106 
22107 		    if (!cflag && !dflag) {
22108 			if (! ((*fancy || *fullgl) && has_opengl) ) {
22109 			   XSetForeground(display, gc, colors[2]);
22110 			   for (i = 0; i <acnt-1; i++) {
22111 				XDrawLine(display,win,gc,
22112 				xyzp->iyp[asel[i]-1]  ,xyzp->ixp[asel[i]-1],
22113 				xyzp->iyp[asel[i+1]-1],xyzp->ixp[asel[i+1]-1]);
22114 			   }
22115 			}
22116 		    }
22117 
22118                     if (!aflag) {
22119 
22120 /* done multiple atom selecting, now parse selection */
22121 
22122 	               update_model = 1;
22123                        XUndefineCursor(display,win);
22124 
22125 		       if (cflag) {
22126 			  for (i=0; i<*xyzp->iatoms; i++) xyzp->iaton[i] = 1;
22127 	    		  update_sel = 1;
22128 			  if (cflag == 1) {
22129 
22130 /* align two molecules, 3 atoms of each molecule selected */
22131 
22132 #if defined(VMS) || defined(UNDERSC)
22133 				alnsel(asel);
22134 #else
22135 #ifdef CRAY
22136 				ALNSEL(asel);
22137 #else
22138 				alnsel_(asel);
22139 #endif
22140 #endif
22141 			  } else {
22142 #if defined(VMS) || defined(UNDERSC)
22143 				cllvec(asel,&anum,xyzp->coo);
22144 #else
22145 #ifdef CRAY
22146 				CLLVEC(asel,&anum,xyzp->coo);
22147 #else
22148 				cllvec_(asel,&anum,xyzp->coo);
22149 #endif
22150 #endif
22151 			  }
22152 			  cflag = 0;
22153 			  return;
22154 
22155 		       } else if (dflag) {
22156 /* reorder zmatrix */
22157 			  dflag = 0; Selecting = 0; ZMEsel = 0;
22158 			  for (i=0; i<*xyzp->iatoms; i++) xyzp->iaton[i] = 2;
22159 	    		  update_sel = 1;
22160 			  *isimpl = 4;
22161 			  ApplSel(0);
22162 			  return;
22163 
22164 		       } else if (SelZME(asel)) {
22165 
22166 /* add zmat line, parse new structure */
22167 
22168 			  return;
22169 
22170 		       } else {
22171 
22172 /* calculate distance, angle, or dihedral */
22173 
22174 #ifdef DOGL
22175 			  if ((*fancy || *fullgl) && has_opengl) {
22176 			      ogunsel();
22177 			  }
22178 #endif
22179 
22180 			  if (eflag) {
22181 			     if (asel[1] > asel[0]) {
22182 				eflag = asel[0];
22183 				asel[0] = asel[1];
22184 				asel[1] = eflag;
22185 			     }
22186 			     eflag = 0;
22187 			     aret = jcoupl[(asel[0]-1)*NAT->natoms + asel[1]-1];
22188 			     anum = 6;
22189 			  } else {
22190 #if defined(VMS) || defined(UNDERSC)
22191 			     tomold(&aret,asel,&anum);
22192 #else
22193 #ifdef CRAY
22194 			     TOMOLD(&aret,asel,&anum);
22195 #else
22196 			     tomold_(&aret,asel,&anum);
22197 #endif
22198 #endif
22199 			  }
22200 			  MkDistWin(asel,anum,aret);
22201 	                  update_model = 0;
22202 		       }
22203                     }
22204                  }
22205 		 else {
22206 
22207 		 int k;
22208 
22209 		 if (!Selecting && !animptr.on) {
22210 		    if (ScreenZME(event.xbutton.x,event.xbutton.y)
22211 			&& ZMEup && *zmptrp->ihaszm) {
22212 			if (event.xbutton.button == 2) {
22213 			     int iret;
22214 
22215 			     if (ZMEAA) {
22216 				if (AmiCom(1,event.xbutton.x,event.xbutton.y))
22217 					return;
22218 			     } else {
22219 	 			iret = GetFrag(1,event.xbutton.x,event.xbutton.y);
22220 				if (iret != -1) return;
22221 			     }
22222 			}
22223 	                update_model = 0;
22224 			return;
22225 		    }
22226 
22227 		    if (ScreenPDB(event.xbutton.x,event.xbutton.y) &&
22228 			!((event.xbutton.state & ShiftMask) ||
22229 			  (event.xbutton.state & ControlMask)) &&
22230 			event.xbutton.button == 2) {
22231 			moving = 0; gmoving = 0;
22232 			if (AmiCom(1,event.xbutton.x,event.xbutton.y)) {
22233 				    while(XCheckTypedWindowEvent(display, win,
22234 					ButtonRelease,&event));
22235 				    return;
22236 			}
22237 			while(XCheckTypedWindowEvent(display, win,
22238 				ButtonRelease,&event)) {
22239 			}
22240 	                update_model = 0;
22241 			break;
22242 			/*return;*/
22243 		    }
22244 		 }
22245 
22246 		 if (!Selecting && !animptr.on) {
22247 		    if (hlpsrf->itsrf) {
22248 			if (has_opengl && (*fancy || *fullgl)) {
22249 			   if (ChangeLevel(event.xbutton.button,
22250 				event.xbutton.x,event.xbutton.y)) return;
22251 			}
22252 		    } else {
22253 			if (FindEsp(event.xbutton.button,
22254 				event.xbutton.x,event.xbutton.y)) return;
22255 		    }
22256 		 }
22257 
22258 		if (event.xbutton.button == 1 && PHRMup && !ZMEup &&
22259 			!((event.xbutton.state & ShiftMask) ||
22260 			  (event.xbutton.state & ControlMask)) ) {
22261 		    k = FindSel(NULL,pharm.iyp,pharm.ixp,0,pharm.nfeat,
22262 			event.xbutton.x,event.xbutton.y,MINDIFF);
22263 		    if (k != -1) {
22264 			FeatSel = k;
22265 			if (PHRMup) {
22266 			   XMapRaised(display,PHRMwin);
22267 			   RedrawPHRM();
22268 			}
22269 		    }
22270  		}
22271 
22272 		if (event.xbutton.button == 1 && ATMup && !ZMEup &&
22273 			!((event.xbutton.state & ShiftMask) ||
22274 			  (event.xbutton.state & ControlMask)) ) {
22275 
22276 		    k = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
22277 			*xyzp->iatoms,curx,cury,MINDIFF);
22278 
22279 		    if (k != -1) {
22280 			if (xyzp->iaton[ATMsel] == 2) xyzp->iaton[ATMsel] = 1;
22281 	    		update_sel = 1;
22282 			ATMsel = k;
22283 			ATMselp = ATMsel + 1;
22284 			xyzp->iaton[ATMsel] = 2;
22285 			PrtCoo(xyzp,&xyzp->coo[ATMsel*3],ATMsel);
22286 			if (ATMup) {
22287 			   UpdateATM();
22288 			   XMapRaised(display,ATMwin);
22289 			   RedrawATM();
22290 			} else {
22291 			   InitATM(event.xbutton.x_root,event.xbutton.y_root);
22292 			   qdpptr->iqon = 2;
22293 			   if (cbut[BLABEL].toggle) {
22294 			      TogDown(&cbut[BLABEL]);
22295 			      *Sinct = 180;
22296 			   }
22297 			}
22298 	                update_model = 0;
22299 			return;
22300 		    }
22301 		 }
22302 
22303 		 if (*ball && !dflag) {
22304 		    moving = 1;
22305 		    startx = event.xbutton.x;
22306 		    starty = event.xbutton.y;
22307 		    btype = 0;
22308 		    if (event.xbutton.state & ShiftMask) btype = 1;
22309 		    if (event.xbutton.state & ControlMask) btype = 2;
22310 		    if ((event.xbutton.state & ControlMask)
22311 			  && (event.xbutton.state & ShiftMask)) btype = 3;
22312 		    if ((*fancy || *fullgl) && has_opengl)
22313 			  moused(event.xbutton.button,event.xbutton.state,
22314 					  event.xbutton.x, event.xbutton.y);
22315 		    break;
22316 		 } else {
22317 		    rotat(event.xbutton.x,event.xbutton.y);
22318 		    *inct = holdt; *incp = holdp;
22319 		    return;
22320 		 }
22321 
22322                  }
22323               }
22324               else if(event.xbutton.window == win && (event.xbutton.button == 1
22325                   || event.xbutton.button == 2) && ZoomEnable ) {
22326 
22327 		 moving = 0;
22328                  ZoomEnable = False;
22329                  ZoomSelection = True;
22330                  MotionCount = 0;
22331 
22332                  XDefineCursor(display, win, ZoomCursor);
22333 		 if (! (has_opengl && (*fancy || *fullgl)) ) {
22334                     XSetFunction(display, gc, GXxor);
22335                     XSetForeground(display, gc, colors[11]);
22336 		 }
22337 
22338                  ZoomX1 = event.xbutton.x;
22339                  ZoomY1 = event.xbutton.y;
22340                  ZoomW = 1;
22341                  ZoomH = 1;
22342 
22343 		 if (has_opengl && (*fancy || *fullgl)) {
22344 #ifdef DOGL
22345 		    rubber(1);
22346 #endif
22347 		 } else {
22348                     XDrawRectangle(display, win, gc,
22349                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
22350 		 }
22351 
22352               }
22353 
22354               if (event.xbutton.window == win && event.xbutton.button == 3)  {
22355 	        update_model = 0;
22356 		OnTop();
22357 	      }
22358 
22359               if (event.xbutton.window == win && event.xbutton.button == 4)  {
22360 		if (event.xbutton.state & ShiftMask) {
22361 			change_iso(1);
22362 		} else {
22363 			update_model = 0;
22364 			if (DoDockCenter) {
22365 			   DCKRadius = DCKRadius + 1.0;
22366 			   if (DCKRadius < 1.) DCKRadius = 1.0;
22367 			   if (DCKRadius*((double) toangs) > 8.0)
22368 				DCKRadius = 8.0/((double) toangs);
22369 			   dispsf();
22370 			} else {
22371 			   *inct = 417; *incp = -5;
22372 #if defined(VMS) || defined(UNDERSC)
22373 			   mktrn(inct,incp);
22374 			   qupd();
22375 #else
22376 #ifdef CRAY
22377  			   MKTRN(inct,incp);
22378 			   QUPD();
22379 #else
22380        			   mktrn_(inct,incp);
22381 			   qupd_();
22382 #endif
22383 #endif
22384 			}
22385 		}
22386 	      }
22387 
22388               if (event.xbutton.window == win && event.xbutton.button == 5)  {
22389 		if (event.xbutton.state & ShiftMask) {
22390 			change_iso(0);
22391 		} else {
22392 			update_model = 0;
22393 			if (DoDockCenter) {
22394 			   DCKRadius = DCKRadius - 1.0;
22395 			   if (DCKRadius < 1.) DCKRadius = 1.0;
22396 			   dispsf();
22397 			} else {
22398 			   *inct = 417; *incp = 5;
22399 #if defined(VMS) || defined(UNDERSC)
22400 			   mktrn(inct,incp);
22401 		   	   qupd();
22402 #else
22403 #ifdef CRAY
22404  		   	   MKTRN(inct,incp);
22405 		   	   QUPD();
22406 #else
22407        		   	   mktrn_(inct,incp);
22408 		   	   qupd_();
22409 #endif
22410 #endif
22411 			}
22412 		}
22413 	      }
22414 
22415               if (event.xbutton.window == QBox)  {
22416 		for (j=0; j<NQBOX; j++)
22417 		    if (qboxes[j].win == QBox && qboxes[j].active) break;
22418 		i = Clickwin(qboxclose,2,event.xbutton.x,event.xbutton.y,1);
22419 		if (i == 0) {
22420 		   if (KeyChk(&qboxes[j],'\012',(KeySym) 0)) return;
22421 		} else if (i == 1) {
22422 		   XDestroyWindow(display,QBox);
22423 		   XSync(display, False);
22424 		   qboxup = 0;
22425 		}
22426 	      }
22427 
22428 	      if (event.xbutton.button  == 3) {
22429 	         update_model = 0;
22430 		 QBoxPaste(event.xbutton.window,qboxes,NQBOX);
22431 	      }
22432 
22433               if (event.xbutton.window == winau) {
22434 	         update_model = 0;
22435                  XFreePixmap(display,gijs);
22436                  XDestroyWindow(display,winau);gijsup = 0;}
22437 
22438               if (event.xbutton.window == wincnv) {
22439 	         update_model = 0;
22440                  XDestroyWindow(display,wincnv);cnvup = 0;}
22441 
22442               if (event.xbutton.window == winsco) {
22443 	         update_model = 0;
22444 		 i = Clickwin(scbut,NSCBUTTS,event.xbutton.x, event.xbutton.y,1);
22445 		 if (i>=0) {
22446 			if (ButtonsSCO(i)) return;
22447 		 }
22448 	      }
22449 
22450               if (event.xbutton.window == winpmf) {
22451 	         update_model = 0;
22452 		 i = Clickwin(pbut,NPBUTTS,event.xbutton.x, event.xbutton.y,1);
22453 		 if (i>=0) {
22454 			if (ButtonsPMF(i)) return;
22455 		 }
22456 	      }
22457 
22458 
22459               if (event.xbutton.window == winspec && specup) {
22460 		 if (event.xbutton.button == 1 || event.xbutton.button == 2) {
22461 			*inct = 510; *incp = 0;
22462 			if (spect.current != -1) {
22463 				*incp = 1 + spect.index[spect.current];
22464 				frlist.select = spect.index[spect.current];
22465 				if (DoFreq && FRQ->ihasi) RedrawList(&frlist);
22466 			}
22467 			if (*incp) {
22468 			   if (FRQ->ihasi) {
22469 				drwspec();
22470 				return;
22471 			   } else if (nmrptr->ihsnmr) {
22472 				click_nmr_spec(spect.current);
22473 			   }
22474 			} else {
22475 			   /* dummy inct */
22476 			   *inct = 1000;
22477 			}
22478 		 }
22479 	      }
22480 
22481               if (event.xbutton.window == wingeo && geoup) {
22482 		 if (event.xbutton.button == 1 || event.xbutton.button == 2) {
22483 			*inct = 117; *incp = 0;
22484 			if (geo1ptr->ifmxav && geoFmax.current != -1) {
22485 				*incp = 1 + geoFmax.index[geoFmax.current];
22486 			}
22487 			if (geo1ptr->ifrmav && geoFrms.current != -1) {
22488 				*incp = 1 + geoFrms.index[geoFrms.current];
22489 			}
22490 			if (geo1ptr->idmxav && geoSmax.current != -1) {
22491 				*incp = 1 + geoSmax.index[geoSmax.current];
22492 			}
22493 			if (geo1ptr->idrmav && geoSrms.current != -1) {
22494 				*incp = 1 + geoSrms.index[geoSrms.current];
22495 			}
22496 			if (geo1ptr->ieav && geoE.current != -1) {
22497 				*incp = 1 + geoE.index[geoE.current];
22498 			}
22499 			if (*incp) {
22500 			   pnt->ipnt = *incp;
22501 #if defined(VMS) || defined(UNDERSC)
22502 			   drwgeo();
22503 #else
22504 #ifdef CRAY
22505 			   DRWGEO();
22506 #else
22507 			   drwgeo_();
22508 #endif
22509 #endif
22510 			   return;
22511 			}
22512 		 }
22513 		 else if(event.xbutton.button == 3) {
22514 	                update_model = 0;
22515 			XDestroyWindow(display,wingeo);geoup = 0;
22516 			TogUp(&cbut[BGEOM]);
22517 		 }
22518 	      }
22519 
22520               if (event.xbutton.window == winrama && ramaup) {
22521 		 if (event.xbutton.button == 1 || event.xbutton.button == 2) {
22522 		    int i,j,itmp,ftmp,rtmp;
22523 		    i = FindSel(NULL,RamaStru.x,RamaStru.y,0,RamaStru.npts,
22524 			event.xbutton.x,event.xbutton.y,GLTOL);
22525 		    if (i >= 0 && i < calfptr->ncalf) {
22526 			j = (calfptr->iamino[i])-1;
22527 			if (j >= 0 && j < MXRES) {
22528 			   sprintf(pchgtmp,"%s %d",
22529 				AminoAcids[j],calfptr->irsnr[i]);
22530 			   XSetBackground(display, gc, colors[15]);
22531 			   XSetForeground(display, gc, colors[0]);
22532 			   XDrawImageString(display, winrama, gc,
22533 				rwi-100, rhi-10, pchgtmp, strlen(pchgtmp));
22534 
22535 			   itmp = *ivdwpl;
22536 			   ftmp = *fancy;
22537 			   *ivdwpl = 1;
22538 			   *fancy = 1;
22539 			   calfptr->reson[i] = 1;
22540 			   rtmp = i+1;
22541 			   if (*backb) actami_(&rtmp,&ZERO,&ONE,&ZERO);
22542 #ifdef DOGL
22543 			   ogres(i+1,1,0);
22544 #endif
22545 			   *ivdwpl = itmp;
22546 			   *fancy = ftmp;
22547 			   if (RamaStru.current != -1) {
22548 				j = RamaStru.current;
22549 				rtmp = j+1;
22550 				if (*backb) {
22551 					calfptr->reson[j] = 0;
22552 					actami_(&rtmp,&ZERO,&ZERO,&ZERO);
22553 				}
22554 #ifdef DOGL
22555 				ogres(j+1,1,0);
22556 #endif
22557 				if (calfptr->iamino[j] == 1) {
22558 				   DrawTriangle(0.0,0.0,
22559 				   RamaStru.x[j],RamaStru.y[j],
22560 				   6,3,1,0);
22561 				} else if (calfptr->iamino[j] == 15) {
22562 				   DrawTriangle(0.0,0.0,
22563 				   RamaStru.x[j],RamaStru.y[j],
22564 				   6,4,1,0);
22565 				} else {
22566 				   DrawBox(0.0,0.0,
22567 				   RamaStru.x[j],RamaStru.y[j],
22568 				   6,3,1,0);
22569 				}
22570 			   }
22571 			   dispsf();
22572 			   if (calfptr->iamino[i] == 1) {
22573 				DrawTriangle(0.0,0.0,
22574 				RamaStru.x[i],RamaStru.y[i],
22575 				6,0,0,0);
22576 			   } else if (calfptr->iamino[i] == 15) {
22577 				DrawTriangle(0.0,0.0,
22578 				RamaStru.x[i],RamaStru.y[i],
22579 				6,0,0,0);
22580 			   } else {
22581 				DrawBox(0.0,0.0,
22582 				RamaStru.x[i],RamaStru.y[i],
22583 				6,0,0,0);
22584 			   }
22585 			   RamaStru.current = i;
22586 			}
22587 #ifndef DOGL
22588 			return;
22589 #endif
22590 		    }
22591 		 }
22592 	      }
22593 
22594               if (event.xbutton.window == FrBox) {
22595 	       if (PressList(&frlist,event.xbutton.x, event.xbutton.y)) {
22596                  *inct = 510; *incp = frlist.select+1;
22597                  return;
22598 	       }
22599 	      }
22600 
22601               if (event.xbutton.window == FLXwin) {
22602 	       if (PressList(&flxlist,event.xbutton.x, event.xbutton.y)) {
22603 		   showresrot(flxlist.select);
22604 	       }
22605 	      }
22606 
22607               if (event.xbutton.window == ZMEwin) {
22608 		if (PressZME(event.xbutton.button, event.xbutton.x, event.xbutton.y)) return;
22609 	      }
22610 
22611               if (event.xbutton.window == ATMwin ) {
22612 		if (PressList(&fftlist,event.xbutton.x, event.xbutton.y)) {
22613 		 if (fftlist.list.ilst == NULL) {
22614 		    if (ffatnr[*fftyp] ==  NULL) {
22615 			xyzp->ityp[ATMsel] = ffsgn[*fftyp]*(fftlist.select + 1);
22616 		    } else {
22617 			if (xyzp->ianz[ATMsel] ==
22618 				ffatnr[*fftyp][fftlist.select]) {
22619 			   xyzp->ityp[ATMsel] = ffsgn[*fftyp]*(fftlist.select + 1);
22620 			} else {
22621 		  	   if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
22622 				"Wrong type for this atom",0)) fftlist.select = -1;
22623 				fftlist.select = -1;
22624 				RedrawList(&fftlist);
22625 
22626 			}
22627 		    }
22628 		 } else {
22629 			if (xyzp->ianz[ATMsel] ==
22630 				ffatnr[*fftyp][fftlist.select]) {
22631 			   xyzp->ityp[ATMsel] =  ffsgn[*fftyp]*
22632 				(fftlist.list.ilst[fftlist.select] + 1);
22633 			} else {
22634 		  	   if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
22635 				"Wrong type for this atom",0)) fftlist.select = -1;
22636 				fftlist.select = -1;
22637 				RedrawList(&fftlist);
22638 
22639 			}
22640 		 }
22641 		 return;
22642 		}
22643 	      }
22644 
22645               if (event.xbutton.window == winpmf) {
22646 	       if (PressList(&pmflistmn,event.xbutton.x, event.xbutton.y)) {
22647 		 int pmfat1;
22648 
22649 		 pmfat1 = ipmfmn[pmflistmn.select]-1;
22650                  if (xyzp->iaton[pmfat1] == 1) xyzp->iaton[pmfat1] = 3;
22651 		 else xyzp->iaton[pmfat1] = 1;
22652 	    	 update_sel = 1;
22653                  return;
22654 	       }
22655 	       if (PressList(&pmflistmx,event.xbutton.x, event.xbutton.y)) {
22656 		 int pmfat2;
22657 
22658 		 pmfat2 = ipmfmx[pmflistmx.select]-1;
22659                  if (xyzp->iaton[pmfat2] == 1) xyzp->iaton[pmfat2] = 4;
22660 		 else xyzp->iaton[pmfat2] = 1;
22661 	    	 update_sel = 1;
22662                  return;
22663 	       }
22664 	      }
22665 
22666               if (event.xbutton.window == MLTwin ) {
22667 
22668 	       if (PressList(&mltlist,event.xbutton.x, event.xbutton.y)) {
22669 		 if (mltlist.select > ntits - 1 ) mltlist.select = ntits - 1;
22670 		 mfdata->imol = mltlist.select + 1;
22671 		 if (mfdata->imol > ntits) mfdata->imol = ntits;
22672 		 WinName(win,mlftit[mltlist.select]);
22673 		 DowinC = 1; DoactC = 1; DoactMC = 1;
22674 #if defined(VMS) || defined(UNDERSC)
22675 		 curs(&ONE);
22676 #else
22677 #ifdef CRAY
22678 	 	 CURS(&ONE);
22679 #else
22680 		 curs_(&ONE);
22681 #endif
22682 #endif
22683 		 *inct = 481;
22684 		 *incp = addfile;
22685 		 if (addfile && *ipdbon) {
22686 			int nl;
22687 
22688 			nl = strlen(mlftit[mltlist.select]);
22689 #if defined(VMS) || defined(UNDERSC)
22690 			parsfn(mlftit[mltlist.select], &nl, &ONE);
22691 #else
22692 #ifdef CRAY
22693 			PARSFN(mlftit[mltlist.select], &nl, &ONE);
22694 #else
22695 			parsfn_(mlftit[mltlist.select], &nl, &ONE);
22696 #endif
22697 #endif
22698 		 }
22699                  return;
22700 
22701 	       }
22702 
22703 	      }
22704 
22705               if (event.xbutton.window == SRCHwin) {
22706 	       if (PressList(&srchlist,event.xbutton.x, event.xbutton.y)) {
22707 		   PDBentry(pdbres[srchlist.select]);
22708 	       }
22709 	      }
22710 
22711               if (event.xbutton.window == fsel.win ) {
22712 
22713 		if (FileSelectBP(&fsel) == 1) return;
22714 
22715               }
22716 
22717               if (event.xbutton.window == gsel.win ) {
22718 
22719 		if (FileSelectBP(&gsel) == 1) {
22720 		   if (gsel.Callwin == PHRMwin) {
22721 			sprintf(qboxes[QPHRMT].str,"%s%s",gsel.lastdir,gfile);
22722 			GetJsonU(qboxes[QPHRMT].str);
22723 			if (PHRMup) {
22724 			   ogfeatures();
22725 			   dispsf();
22726 			   XMapRaised(display,PHRMwin);
22727 			   RedrawPHRM();
22728 			}
22729 		   }
22730 		   if (gsel.Callwin == PSRCHwin) {
22731 			if (PSRCHup) {
22732 			   sprintf(qboxes[QSCSDF].str,"%s%s",gsel.lastdir,gfile);
22733 			   XMapRaised(display,PSRCHwin);
22734 			   RedrawPSRCH();
22735 			}
22736 		   }
22737 		}
22738 
22739               }
22740 
22741               if (event.xbutton.window == dsel.win ) {
22742 
22743 	        update_model = 0; doret = 0;
22744 		if (FileSelectBP(&dsel) == 1) {
22745 		   if (dsel.Callwin == windock) {
22746 			if (dockup) {
22747 			   sprintf(qboxes[QDCKFI].str,"%s%s",dsel.lastdir,gfile);
22748 			   XMapRaised(display,windock);
22749 			   strcpy(dcklig,qboxes[QDCKFI].str);
22750 			   if (access(dcklig,F_OK) != 0) {
22751 				DoCan(event.xbutton.x_root,
22752 					event.xbutton.y_root,
22753 					"Non existent ambfor .xyz file !\n",0);
22754 				break;
22755 			   }
22756 			   if (!IntSurfDone) {
22757 				if (*ipdbon) {
22758 				    ogIntSurf();
22759 	   			}
22760 			   }
22761 			   Write_Mol("/tmp/tmpje.mol");
22762 			   Cvt2SVG();
22763 			   drwdock();
22764 			   break;
22765 			}
22766 		   }
22767 		}
22768 
22769               }
22770 
22771 	      if (event.xbutton.window == DISTwin) {
22772 	         update_model = 0;
22773 		 i = Clickwin(clbut,NCLBUT,event.xbutton.x, event.xbutton.y,1);
22774 
22775 		 if (i>=0) {
22776 		     if (ButtonsDIST(i)) return;
22777 		 }
22778 	      }
22779 
22780 	      if (event.xbutton.window == COLwin) {
22781 		 i = Clickwin(colbut,NBUTSC,event.xbutton.x, event.xbutton.y,1);
22782                  if (i>=0) {
22783 			RButtonsCOL(i);
22784 		 } else {
22785 			i = Clickwin(AtmBut,TABBUTN,
22786 				event.xbutton.x,event.xbutton.y,1);
22787 			if (i>=0) {
22788 			    ButtonsCOL(i);
22789 			    return;
22790 			}
22791 		 }
22792 	      }
22793 
22794 
22795 	      if (event.xbutton.window == SEQwin) {
22796 		 i = Clickwin(butSEQ,NBUTSEQ,event.xbutton.x, event.xbutton.y,1);
22797                  if (i>=0) {
22798 			if (ButtonsSEQ(i)) return;
22799 		 } else {
22800 			i = ClickBox(&qboxes[QPHI],2,
22801 				event.xbutton.x,event.xbutton.y);
22802                  	if (i>=0) {
22803 				qboxes[QPHI].active = 0;
22804 				qboxes[QPSI].active = 0;
22805 				qboxes[QPHI+i].active = 1;
22806 				RedrawSEQ();
22807 			}
22808 		 }
22809 	      }
22810 
22811 	      if (event.xbutton.window == TNKwin) {
22812 	         update_model = 0;
22813 		 i = Clickwin(butTNK,ntnkb,event.xbutton.x, event.xbutton.y,1);
22814                  if (i>=0) {
22815 			if (ButtonsTNK(i)) return;
22816 		 } else {
22817 			i = ClickBox(&qboxes[QGRD],4,
22818 				event.xbutton.x,event.xbutton.y);
22819                  	if (i>=0) {
22820 				qboxes[QGRD].active = 0;
22821 				qboxes[QARCH].active = 0;
22822 				qboxes[QTNKJN].active = 0;
22823 				qboxes[QMAXIT].active = 0;
22824 				qboxes[QGRD+i].active = 1;
22825 				RedrawTNK();
22826 			}
22827 		 }
22828 	      }
22829 
22830 	      if (event.xbutton.window == CPwin) {
22831 		  if (ButtonsCP(event.xbutton.x, event.xbutton.y)) {
22832 			*Sinct = 154; return;
22833 		  }
22834 	      }
22835 
22836 	      if (event.xbutton.window == CTwin) {
22837 		  int CTtmp;
22838 		  CTtmp = ButtonsCT(event.xbutton.x, event.xbutton.y);
22839 		  if (CTtmp) {
22840 			*Sinct = 550;
22841 			if (CTtmp == 2) *Sincp = 17;
22842 			else *Sincp = 2;
22843 			return;
22844 		  }
22845 	      }
22846 
22847 	      if (event.xbutton.window == ISOwin) {
22848 		 i = Clickwin(isobut,NBUTISO,event.xbutton.x, event.xbutton.y,1);
22849                  if (i>=0) {
22850 			if (ButtonsISO(i)) {
22851 				return;
22852 			}
22853 		 } else {
22854 			i = ClickBox(&qboxes[QEDGE],5,
22855 				event.xbutton.x,event.xbutton.y);
22856                  	if (i>=0) {
22857 				qboxes[QEDGE].active = 0;
22858 				qboxes[QVALC1].active = 0;
22859 				qboxes[QVALC2].active = 0;
22860 				qboxes[QVALC3].active = 0;
22861 				qboxes[QNPTS].active = 0;
22862 				qboxes[QEDGE+i].active = 1;
22863 				RedrawISO();
22864 			}
22865 		 }
22866 	      }
22867 
22868 	      if (event.xbutton.window == ATMwin) {
22869 		 i = Clickwin(butATM,NBUTATM,event.xbutton.x, event.xbutton.y,1);
22870                  if (i>=0) {
22871 			if (ButtonsATM(i)) {
22872 				return;
22873 			}
22874                  } else {
22875                         i = ClickBox(&qboxes[QCHARG],3,
22876                                 event.xbutton.x,event.xbutton.y);
22877                         if (i>=0) {
22878 			    if ( i == 1 && (event.xbutton.state & ShiftMask) ) {
22879 			        if (DoCan(event.xbutton.x_root,
22880 					event.xbutton.y_root,selstr,0)) {
22881 				}
22882 				Selecting = 1; ZoomEnable = True;Select = True;
22883 				SelRes = *qboxes[QRSD].iflt;
22884 			    } else {
22885                                 qboxes[QCHARG].active = 0;
22886                                 qboxes[QRSD].active = 0;
22887                                 qboxes[QATOM].active = 0;
22888                                 qboxes[QCHARG+i].active = 1;
22889                                 RedrawATM();
22890 			    }
22891                         }
22892 		 }
22893 	      }
22894 
22895 	      if (event.xbutton.window == winspec) {
22896 		 i = Clickwin(spbut,nsbutts,event.xbutton.x, event.xbutton.y,1);
22897                  if (i>=0) {
22898 			if (ButtonsSPC(i)) {
22899 				*Sinct = 1000; return;
22900 		 	}
22901                  } else {
22902                         i = ClickBox(&qboxes[QHW],nspqbox,
22903                                 event.xbutton.x,event.xbutton.y);
22904                         if (i>=0) {
22905 			    int j;
22906 			    for (j=0; j<nspqbox; j++) qboxes[QHW+j].active = 0;
22907 			    qboxes[QHW+i].active = 1;
22908 			    drwspec();
22909                         }
22910 		 }
22911 	      }
22912 
22913 	      if (event.xbutton.window == ONIwin) {
22914 		 i = Clickwin(onbut,NBUTSO,event.xbutton.x, event.xbutton.y,1);
22915                  if (i>=0) {
22916 			if (ButtonsONI(i)) {
22917 				*Sinct = 1000; return;
22918 			}
22919 		 }
22920 	      }
22921 
22922 	      if (event.xbutton.window == windock && dockup) {
22923 		 i = Clickwin(dockbut,NBUTDCK,event.xbutton.x, event.xbutton.y,1);
22924                  if (i>=0) {
22925 			if (ButtonsDCK(i)) return;
22926 		 } else {
22927 			i = ClickBox(&qboxes[QDCKFI],3,
22928 				event.xbutton.x,event.xbutton.y);
22929                  	if (i>=0) {
22930 				qboxes[QDCKFI].active = 0;
22931 				qboxes[QDCKSL].active = 0;
22932 				qboxes[QDCKOUT].active = 0;
22933 				qboxes[QDCKFI+i].active = 1;
22934 				drwdock();
22935 			}
22936 		 }
22937 	      }
22938 
22939 	      if (event.xbutton.window == FLRwin) {
22940 		 i = Clickwin(flrbut,NBUTSF,event.xbutton.x, event.xbutton.y,1);
22941                  if (i>=0) {
22942 			if (ButtonsFLR(i)) {
22943 				*Sinct = 1000; return;
22944 			}
22945 		 }
22946 	      }
22947 
22948 	      if (event.xbutton.window == SUBwin) {
22949 	         update_model = 0;
22950 		 i = Clickwin(sbut,NBUTSS,event.xbutton.x, event.xbutton.y,1);
22951                  if (i>=0) {
22952 			if (ButtonsSUB(i)) {
22953 				*Sinct = 151; *iixyz = 7+jmode;
22954 				if (jmode == 3) *iixyz = 12;
22955 				return;
22956 			}
22957 		 } else {
22958 			i = ClickBox(&qboxes[QGLIN1],7,
22959 				event.xbutton.x,event.xbutton.y);
22960                  	if (i>=0) {
22961 				qboxes[QGLIN1].active = 0;
22962 				qboxes[QGLIN2].active = 0;
22963 				qboxes[QGTITL].active = 0;
22964 				qboxes[QJNAME].active = 0;
22965 #ifndef DOQUEUE
22966 				qboxes[QQNAME].active = 0;
22967 				qboxes[QTIME].active = 0;
22968 #endif
22969 				qboxes[QENAME].active = 0;
22970 				qboxes[QGLIN1+i].active = 1;
22971 				RedrawSUB();
22972 			}
22973 
22974 		 }
22975 	      }
22976 
22977 	      if (event.xbutton.window == DPTwin) {
22978 		    update_model = 0;
22979 		    i = Clickwin(butdpt,2,event.xbutton.x, event.xbutton.y,1);
22980 		    if (i>=0) {
22981                         switch (i) {
22982 			case 0:
22983 			   XSync(display, False);
22984 			   XDestroyWindow(display,DPTwin);
22985 			   XSync(display, False);
22986 			   DPTup = 0;
22987 			   break;
22988 			case 1: { LSSTRU List;
22989 			   List.list = ChainLength; List.nents = 10;
22990 			   if (DoPopUp(DPTwin,butdpt[1].x+1,
22991 				   butdpt[1].y,&List,&linmax,0) == -1) break;
22992 			   linmax++;
22993 			   }
22994 			   break;
22995 			}
22996 		    }
22997 		    if (ScrollPage(NULL,&dptscr[0],event.xbutton.x,
22998 			event.xbutton.y)) {
22999 		    }
23000 	      }
23001 
23002 	      if (event.xbutton.window == OMAPwin) {
23003 		    update_model = 0;
23004 		    i = Clickwin(butomap,4,event.xbutton.x, event.xbutton.y,1);
23005 		    ClickOMAP(i);
23006 	      }
23007 
23008 	      if (event.xbutton.window == ECOLwin) {
23009 		    if (Clickwin(butecol,1,event.xbutton.x, event.xbutton.y,1) != -1) {
23010 			SetPalCol(1);
23011 			XSync(display, False);
23012 			XDestroyWindow(display,ECOLwin);
23013 			XSync(display, False);
23014 			ECOLup = 0;
23015 			return;
23016 		    }
23017 		    if (ScrollPage(NULL,&ecolscr[0],event.xbutton.x,event.xbutton.y)) {
23018 			SetPalCol(0);
23019 		    }
23020 		    if (ScrollPage(NULL,&ecolscr[1],event.xbutton.x,event.xbutton.y)) {
23021 			SetPalCol(0);
23022 		    }
23023 		    if (ScrollPage(NULL,&ecolscr[2],event.xbutton.x,event.xbutton.y)) {
23024 			SetPalCol(0);
23025 		    }
23026 	      }
23027 
23028               if (event.xbutton.window == DELAYwin) {
23029 	         update_model = 0;
23030 		 i = Clickwin(delbut,3,event.xbutton.x, event.xbutton.y,1);
23031 		 if (i>=0) {
23032 			if (ButtonsDEL(i)) idum1 = 0;
23033 		 }
23034 	      }
23035 
23036               if (event.xbutton.window == MOVwin) {
23037 		 i = Clickwin(movbut,5,event.xbutton.x, event.xbutton.y,1);
23038 		 if (i>=0) {
23039 			if (ButtonsMOV(i)) idum1 = 0;
23040 		 } else {
23041 			j = ClickBox(&qboxes[QMOV],1,
23042 				event.xbutton.x, event.xbutton.y);
23043 			if (j>=0) {
23044 			   qboxes[QMOV].active = 1;
23045 			   RedrawMOV();
23046 			}
23047 		 }
23048 	      }
23049 
23050               if (event.xbutton.window == SRFwin) {
23051 	         update_model = 0;
23052 		 i = Clickwin(srfbut,6,event.xbutton.x, event.xbutton.y,1);
23053 		 if (i>=0) {
23054 			if (ButtonsSRF(i)) idum1 = 0;
23055 		 }
23056 	      }
23057 
23058               if (event.xbutton.window == MLTwin) {
23059 	         update_model = 0;
23060 		 i = Clickwin(mltbut,Nmltb,event.xbutton.x, event.xbutton.y,1);
23061 		 if (i>=0) {
23062 			if (ButtonsMLT(i)) idum1 = 0;
23063 		 } else {
23064 			i = ClickBox(&qboxes[QRESF],3,
23065 				event.xbutton.x,event.xbutton.y);
23066                  	if (i>=0) {
23067 				qboxes[QRESF].active = 0;
23068 				qboxes[QQUERY].active = 0;
23069 				qboxes[QNRES].active = 0;
23070 				qboxes[QRESF+i].active = 1;
23071 				RedrawMLT();
23072 			}
23073 		 }
23074 	      }
23075 
23076               if (event.xbutton.window == PHRMwin) {
23077 	         update_model = 0;
23078 		 i = Clickwin(PHRMbut,PHRMBUT,event.xbutton.x, event.xbutton.y,1);
23079 		 if (i>=0) {
23080 			if (ButtonsPHRM(i)) idum1 = 0;
23081 		 } else {
23082 			if (PressList(&PHRMlist,
23083 				event.xbutton.x, event.xbutton.y)) {
23084 
23085 			   UpdPHRM();
23086 
23087 			} else {
23088 			   i = ClickBox(&qboxes[QPHRMT],2,
23089 				event.xbutton.x,event.xbutton.y);
23090                  	   if (i>=0) {
23091 				qboxes[QPHRMT].active = 0;
23092 				qboxes[QPHRMR].active = 0;
23093 				qboxes[QPHRMT+i].active = 1;
23094 				RedrawPHRM();
23095 			   }
23096 			}
23097 		 }
23098 	      }
23099 
23100               if (event.xbutton.window == PSRCHwin) {
23101 	         update_model = 0;
23102 		 i = Clickwin(PSRCHbut,PSRCHBUT,event.xbutton.x, event.xbutton.y,1);
23103 		 if (i>=0) {
23104 			if (ButtonsPSRCH(i)) idum1 = 0;
23105 		 } else {
23106 			i = ClickBox(&qboxes[QSCSDF],2,
23107 				event.xbutton.x,event.xbutton.y);
23108                  	if (i>=0) {
23109 				qboxes[QSCSDF].active = 0;
23110 				qboxes[QCRIND].active = 0;
23111 				qboxes[QSCSDF+i].active = 1;
23112 				RedrawPSRCH();
23113 			}
23114 		 }
23115 	      }
23116 
23117               if (event.xbutton.window == FLXwin) {
23118 	         update_model = 0;
23119 		 i = Clickwin(flxbut,9,event.xbutton.x, event.xbutton.y,1);
23120 		 if (i>=0) {
23121 			if (ButtonsFLX(i)) idum1 = 0;
23122 		 }
23123 	      }
23124 
23125               if (event.xbutton.window == CHGwin) {
23126 	         update_model = 0;
23127 		 i = Clickwin(chgbut,3,event.xbutton.x, event.xbutton.y,1);
23128 		 if (i>=0) {
23129 			if (ButtonsCHG(i)) return;
23130 		 } else {
23131                         ClickBox(&qboxes[QCHRG2],1,
23132                                 event.xbutton.x,event.xbutton.y);
23133 		 }
23134 	      }
23135 
23136               if (event.xbutton.window == STRwin) {
23137 	         update_model = 0;
23138 		 i = Clickwin(strbut,5,event.xbutton.x, event.xbutton.y,1);
23139 		 if (i>=0) {
23140 			if (ButtonsSTR(i)) return;
23141 		 } else {
23142 			if (PressList(&strlist,
23143 				event.xbutton.x, event.xbutton.y)) {
23144 
23145 			    if (istruct > -1) SaveActiveStruct();
23146 
23147 			    uping = 0;
23148 /*
23149 			    bcksvg.UpSVG = 0; bcksvg.ReadSVG = 0;
23150 			    bcksvg.CurSVG = 0;
23151 */
23152 
23153 			    if (strlist.select < nstruct) {
23154 				istruct = strlist.select;
23155 				NewActiveStruct();
23156 
23157 				/*DebugStructure();*/
23158 
23159   				update_sel = 1;
23160 				doclr();
23161 				if (NMols[istruct] == -1) update_model = 1;
23162 				update_struct();
23163 				if (ntits > 1) {
23164 				   initMLT();
23165 				} else {
23166 				   if (MLTup) {
23167 		    			XDestroyWindow(display,MLTwin);
23168 					MLTup = 0;
23169 				   }
23170 				}
23171 			    }
23172 			}
23173 			if (PressList(&str2list,
23174 				event.xbutton.x, event.xbutton.y)) {
23175 
23176 			    if (str2list.select < nstruct) {
23177 				sstruct = str2list.select;
23178 			    }
23179 			}
23180 		 }
23181 	      }
23182 
23183               if (event.xbutton.window == STRCwin) {
23184 	         update_model = 0;
23185 		 i = Clickwin(strcbut,STRCBN,event.xbutton.x, event.xbutton.y,1);
23186 		 if (i>=0) {
23187 			if (ButtonsSTRC(i)) return;
23188 		 } else {
23189 			if (PressList(&strclist,
23190 				event.xbutton.x, event.xbutton.y)) {
23191 
23192 				dispsf();
23193 			}
23194 		 }
23195 	      }
23196 
23197               if (event.xbutton.window == SELHwin) {
23198 	         update_model = 0;
23199 		 i = Clickwin(selhbut,SELHBN,event.xbutton.x, event.xbutton.y,1);
23200 		 if (i>=0) {
23201 			if (ButtonsSELH(i)) return;
23202 		 }
23203 	      }
23204 
23205               if (event.xbutton.window == SRCHwin) {
23206 	         update_model = 0;
23207 		 i = Clickwin(butSRCH,SRCHBN,event.xbutton.x, event.xbutton.y,1);
23208 		 if (i>=0) {
23209 			if (ButtonsSRCH(i)) return;
23210 		 }
23211 	      }
23212 
23213               if (event.xbutton.window == PARwin) {
23214 	         update_model = 0;
23215 		 i = Clickwin(parbut,3,event.xbutton.x, event.xbutton.y,1);
23216 		 if (i>=0) {
23217 			if (ButtonsPAR(i)) return;
23218 		 } else {
23219 			i = ClickBox(&qboxes[QHBMIN],4,
23220 				event.xbutton.x,event.xbutton.y);
23221                  	if (i>=0) {
23222 				qboxes[QHBMIN].active = 0;
23223 				qboxes[QHBMAX].active = 0;
23224 				qboxes[QHAMIN].active = 0;
23225 				qboxes[QHAMAX].active = 0;
23226 				qboxes[QHBMIN+i].active = 1;
23227 				RedrawPAR();
23228 			}
23229 		 }
23230 	      }
23231 
23232               if (event.xbutton.window == winMC &&  !ZoomEnable &&
23233 		  !ZoomSelection && !animptr.on) {
23234 
23235                  i=Clickwin(cbut,NBUTTS2,event.xbutton.x, event.xbutton.y,1);
23236 
23237                  if (i>=0) {
23238                  switch (i) {
23239 
23240                  case BFIRST: *inct = 100; break;
23241                  case BPREV:  *inct = 109; break;
23242                  case BNEXT:  *inct = 110; break;
23243                  case BMOVIE: *inct = 115; DoFreq = 1; break;
23244                  case BHOUR:  update_model = 0; InitDelay(); break;
23245                  case BMOLF:
23246 /*
23247 				{LSSTRU List;
23248 				 List.list = mlftit; List.nents = ntits;
23249 				 if (DoPopUp(winMC,cbut[BMOLF].x+1,
23250 					cbut[BMOLF].y+BUTTH-10,&List,
23251 					&mfdata->imol,0) == -1) break;
23252 				 WinName(win,mlftit[mfdata->imol]);
23253 				 mfdata->imol++;
23254 				 if (geoup) {
23255 				    TogUp(&cbut[BGEOM]);
23256 				    XDestroyWindow(display,wingeo);
23257 				    geoup = 0;
23258 				 }
23259 				 if (cnvup) {
23260 				    XDestroyWindow(display,wincnv);
23261 				    cnvup = 0;
23262 		 		 }
23263 				 DowinC = 1; DoactC = 1; DoactMC = 1;
23264 				 *inct = 700;
23265 				}
23266 */
23267 				if (ntits > 1)  {
23268 				   if (!MLTup)  initMLT();
23269 				   else RedrawMLT();
23270  				}
23271 				break;
23272                  case BSOLID:
23273 			      update_sel = 1;
23274 			      if (!TogBut(&cbut[BSOLID])){
23275 				LSSTRU List;
23276 				List.list = vdwstr ;
23277 				if (has_opengl) {
23278 				   List.nents = 3;
23279 				} else {
23280 				   List.nents = 2;
23281 				}
23282 				if (DoPopUp(winMC,
23283 				    cbut[BSOLID].x+1,cbut[BSOLID].y+BUTTH,
23284 					&List,ivdwpl,0) == -1) {
23285 				   TogBut(&cbut[BSOLID]);
23286 				   break;
23287 				}
23288 				*incp = 0;
23289 				if (has_opengl) {
23290 				   int ndmtmp;
23291 				   *ifogl = 1;
23292 				   *fancy = 1;
23293 				   ndmtmp = monptr->ndm;
23294 				   if (*fancy || *fullgl) {
23295 #if defined(VMS) || defined(UNDERSC)
23296 					ogmon();
23297 #else
23298 #ifdef CRAY
23299 					OGMON();
23300 #else
23301 					ogmon_();
23302 #endif
23303 #endif
23304 #ifdef DOGL
23305 					ogbox();
23306 #endif
23307 				   }
23308 /*
23309  clrmon clears created connections, and sets ndm zero
23310  it DOES NOT clear the monitor array
23311 */
23312 
23313 #if defined(VMS) || defined(UNDERSC)
23314 					clrmon();
23315 #else
23316 #ifdef CRAY
23317 					CLRMON();
23318 #else
23319 					clrmon_();
23320 #endif
23321 #endif
23322 				   monptr->ndm = ndmtmp;
23323 				   ResetRes();
23324 				}
23325 			      } else {
23326 				*incp = 1;
23327 				*ivdwpl = 0;
23328 				if (has_opengl) {
23329 				   if (*fullgl) {
23330 					*ifogl = 1;
23331 				   } else {
23332 					*ifogl = 0;
23333 				   }
23334 				} else {
23335 				   *ifogl = 0;
23336 				}
23337 				*fancy = 0;
23338 				if (has_opengl) {
23339 				   if (*fullgl) {
23340 #if defined(VMS) || defined(UNDERSC)
23341 				      ogmon();
23342 #else
23343 #ifdef CRAY
23344 				      OGMON();
23345 #else
23346 				      ogmon_();
23347 #endif
23348 #endif
23349 #ifdef DOGL
23350 				      ogbox();
23351 #endif
23352 				   } else {
23353 /*
23354  domcon creates connections for ifogl!=1 and calls ogmon
23355 */
23356 
23357 #if defined(VMS) || defined(UNDERSC)
23358 				      domcon(&ONE,&ONE);
23359 #else
23360 #ifdef CRAY
23361 				      DOMCON(&ONE,&ONE);
23362 #else
23363 				      domcon_(&ONE,&ONE);
23364 #endif
23365 #endif
23366 				   }
23367 				   ResetRes();
23368 				}
23369 			      }
23370 			      *inct = 140;
23371                               break;
23372                  case BZOOMIN:   hold = 1; holdt = 290; holdp = -1;
23373 				 *inct = 290;*incp = -1; break;
23374                  case BZOOMOUT:  hold = 1; holdt = 290; holdp = 1;
23375 				 *inct = 290;*incp = 1; break;
23376                  case BPOSTT: {
23377 				int idums;
23378 				LSSTRU List;
23379 				update_model = 0;
23380 				List.list = postopt; List.nents = 2;
23381 				if (DoPopUp(winMC,
23382 					cbut[BPOSTT].x+1,cbut[BPOSTT].y+BUTTH,
23383 					&List,icolps,0) == -1) break;
23384 		/* check for dummies */
23385 				idums = 0;
23386 				for (i=0; i<*xyzp->iatoms; i++)
23387 				   if (xyzp->ianz[i] == 99)  idums = 1;
23388 				if (idums) {
23389 				   List.list = dumopt; List.nents = 2;
23390 				   if (DoPopUp(winMC,
23391 					cbut[BPOSTT].x+1,cbut[BPOSTT].y+BUTTH,
23392 					&List,idelx,0) == -1) break;
23393 				}
23394 				qboxstr(&qboxes[QPOSTT],NULL,1,0,-1,DEFQX,DEFQY,
23395 					QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
23396 					0,0,150,0,dummyproc);
23397 				break;}
23398 
23399                  case BDENMOD:  *inct = 75; DirBox(winMC,0);
23400                                 DowinC =1; DoactC = 1;
23401 				denmode = 1;
23402 				*shade  = 0;
23403 				*ifdogl = 0;
23404 				*ivdwpl = 0;
23405 #ifdef DOGL
23406 				TogUp(&dbut[BOGL]);
23407 #endif
23408 				cursrfcol[0][0] = 0.0 ;
23409 				cursrfcol[0][1] = 0.0 ;
23410 				cursrfcol[0][2] = 1.0 ;
23411 		                empty_model(istruct,1);
23412 				if (fsel.qbrfile) {
23413 				   TogUp(&cbut[BREADF]);
23414 				   fsel.qbrfile = 0;
23415 				   XUnmapWindow(display,fsel.win);
23416 				}
23417 				if (ZMEup) UnMapZME();
23418 				if (frfor && FRup) {
23419 				   TogUp(&cbut[BFORC]);
23420 				   XDestroyWindow(display,FrBox);
23421 				   DoFreq = 0;
23422 				   FRup = 0;
23423 				   NMRup = 0;
23424 				}
23425 				if (frfor && specup) {
23426 				   XDestroyWindow(display,winspec);
23427 				   specup = 0;
23428 				}
23429 				if (distup) {
23430 				   distup = 0;
23431 				   XUnmapWindow(display,DISTwin);
23432 				}
23433 		 		if (STRCup) {
23434 				    XDestroyWindow(display,STRCwin);
23435 				    STRCup = 0;
23436 				}
23437 		 		if (OMAPup) {
23438 				    XDestroyWindow(display,OMAPwin);
23439 				    OMAPup = 0;
23440 				    omapr = 0;
23441 #ifdef DOGL
23442 				    deletebox();
23443 #endif
23444 				}
23445 				gl2DInit();
23446 				break;
23447 
23448                  case BQUITT:
23449 				update_model = 0;
23450 				if (!DoCan(event.xbutton.x_root,
23451 					event.xbutton.y_root,
23452 					" Are you sure to quit?  ",1)) {
23453 				   FreeAll(1);
23454 #ifdef DOGL
23455 #ifdef GL_ARB_shader_objects
23456 				   if (has_shader) del_shader();
23457 #endif
23458 #ifdef GL_COLOR_ATTACHMENT0_EXT
23459 				   if (has_fbo) del_fbo(&fbo);
23460 #endif
23461 #endif
23462 				   XFreeGC(display, gc);
23463 				   XCloseDisplay(display);
23464 				   exit(0);
23465 				   *inct = 15;
23466 				}
23467 				break;
23468 
23469                  case BSURF: {
23470 				int itmp;
23471 				LSSTRU List;
23472 				if (ISOup) break;
23473 #ifdef MPFIT
23474 				List.list = pots; List.nents = 20;
23475 #else
23476 				List.list = pots; List.nents = 19;
23477 #endif
23478 				if (DoPopUp(winMC,
23479 				   cbut[BSURF].x+1,cbut[BSURF].y-40,
23480 				   &List,&itmp,0) == -1) break;
23481 				RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
23482 				if (itmp == 7) {
23483 				   if (DoCan(event.xbutton.x_root,
23484 					event.xbutton.y_root,
23485 					"This will take a while",1)) {
23486 					break;
23487 				   }
23488 				}
23489 				if (itmp == 0 || itmp == 1 || itmp == 7 || itmp == 8) {
23490 				   List.list = surftyp; List.nents = 2;
23491 		   		   if (itmp == 1) List.nents = 3;
23492 				   if (DoPopUp(winMC,
23493 					cbut[BSURF].x+1,cbut[BSURF].y+BUTTH,
23494 					&List,&surface->istyp,0) == -1) break;
23495 				   if (surface->istyp == 1) {
23496                              		if (itmp == 0 || itmp == 1) {
23497 						surface->nvalc = 1;
23498 					}
23499                              		if (itmp == 7 || itmp == 8) {
23500 						surface->nvalc = 3;
23501 					}
23502 					if (!ISOup) {
23503 					   InitISO(event.xbutton.x_root,
23504 						event.xbutton.y_root);
23505 					   ISOt = 570+itmp;
23506                              		   if (itmp == 0 || itmp ==1) {
23507 						 ActBut(&isobut[0],0);
23508 					   }
23509 					   break;
23510 					} else {
23511                              		   if (itmp == 0 || itmp ==1) {
23512 						isobut[0].str =
23513 						   ChainLength[surface->nvalc];
23514 						ActBut(&isobut[0],0);
23515 						RedrawISO();
23516 					   }
23517 					}
23518 				   }
23519 		   		   if (surface->istyp == 2) {
23520 				   	   int kcoo,kcooh;
23521 #if defined(VMS) || defined(UNDERSC)
23522 					   chkcoo(&kcoo,&kcooh);
23523 #else
23524 #ifdef CRAY
23525 					   CHKCOO(&kcoo,&kcooh);
23526 #else
23527 					   chkcoo_(&kcoo,&kcooh);
23528 #endif
23529 #endif
23530 					   *pol  =  0.085;
23531 					   *pol2 = -0.07;
23532 					   *ipsa = 1;
23533 
23534 					   if (kcooh) {
23535 #if defined (_WIN32) || defined(_WIN64)
23536 			   		   if (DoCan(XX,YY,
23537 #else
23538 			   		   if (DoCan(event.xbutton.x_root,
23539 						   	event.xbutton.y_root,
23540 #endif
23541 				"Molecule contains -COOH group !\nThis should be deprotonated",0)) {}
23542 					   }
23543 		   		   }
23544 				   RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
23545 				}
23546 				if (itmp == 3) {
23547 				    double tsa,psa;
23548 
23549 #if defined(VMS) || defined(UNDERSC)
23550 				    tpsa();
23551 #else
23552 #ifdef CRAY
23553 				    TPSA();
23554 #else
23555 				    tpsa_();
23556 #endif
23557 #endif
23558 				    doret = 0;
23559 				    break;
23560 				}
23561 				if (itmp == 4) {
23562 				   qboxstr(&qboxes[QSRFW],NULL,1,0,-1,
23563 				    DEFQX,DEFQY,QBOXWIDE,QBOXHIGH,0,
23564 				    "Surface Filename ? ",NULL,0,0,
23565 				    574,0,dummyproc);
23566 				    break;
23567 				}
23568 				if (itmp == 5) {
23569 				   qboxstr(&qboxes[QSRFW],NULL,1,0,-1,
23570 				    DEFQX,DEFQY,QBOXWIDE,QBOXHIGH,0,
23571 				    "Surface Filename ? ",NULL,0,0,
23572 				    575,0,dummyproc);
23573 				    break;
23574 				}
23575 				if (itmp == 11) {
23576 				   List.list = eems; List.nents = 4;
23577 				   if (DoPopUp(winMC,
23578 					cbut[BSURF].x+50,
23579 					cbut[BSURF].y+11*LINEHIGH,
23580 					&List,&ieemopt,0) == -1) break;
23581 				   RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
23582 				   inichg(1);
23583 				   break;
23584 				}
23585 				if (itmp == 12) {
23586 #if defined(VMS) || defined(UNDERSC)
23587 				   clqgas(&calfptr->ishoh);
23588 #else
23589 #ifdef CRAY
23590 				   CLQGAS(&calfptr->ishoh);
23591 #else
23592 				   clqgas_(&calfptr->ishoh);
23593 #endif
23594 #endif
23595 				   break;
23596 				}
23597 				if (itmp == 14) {
23598 				    List.list = srfopt; List.nents = 2; int iii;
23599 				    if (DoPopUp(winMC,cbut[BSURF].x-8,
23600 					cbut[BSURF].y+14*LINEHIGH,&List,&iii,0) == -1) break;
23601 				    if (iii) {
23602 					molsrf(iii,0,1);
23603 				    } else {
23604 					if (DoPopUp(winMC,
23605 					      cbut[BSURF].x-8,cbut[BSURF].y+BUTTH,
23606 					      NULL,&iii,0) == -1) break;
23607 					molsrf(iii,0,0);
23608 				    }
23609 				    break;
23610 				}
23611 				if (itmp == 15) {
23612 				    if (omap()) break;
23613 				    break;
23614 				}
23615 
23616 				if (itmp == 16) {
23617 				    OpenPHRME();
23618 				    break;
23619 				}
23620 
23621 				if (itmp == 17) {
23622 				   if (OMAPup) DeleteOMAP();
23623 				   qboxstr(&qboxes[QSRFW],NULL,1,0,-1,
23624 					DEFQX,DEFQY,QBOXWIDE,QBOXHIGH,0,
23625 					"GRID kont Filename ? ",NULL,0,0,
23626 					586,0,dummyproc);
23627 				    break;
23628 				}
23629 				if (itmp == 18) {
23630 			   	   createRama();ramaup=1;
23631 				}
23632 #ifdef DOGL
23633 				*incp = 0;
23634 				if (itmp == 6) {
23635 #if defined(VMS) || defined(UNDERSC)
23636 				   srfclr();
23637 #else
23638 
23639 #ifdef CRAY
23640 				   SRFCLR();
23641 #else
23642 				   srfclr_();
23643 #endif
23644 
23645 #endif
23646 				   dispsf();
23647 				}
23648 #endif
23649 				if (itmp == 13) {
23650 				   if (qdpptr->ihsdp) {
23651 					if (qdpptr->idipon) {
23652 					   qdpptr->idipon = 0;
23653 					} else {
23654 					   qdpptr->idipon = 1;
23655 #if defined(VMS) || defined(UNDERSC)
23656 					   putxyz();
23657 #else
23658 
23659 #ifdef CRAY
23660 					   PUTXYZ();
23661 #else
23662 					   putxyz_();
23663 #endif
23664 
23665 #endif
23666 					}
23667 				   } else {
23668 #if defined(VMS) || defined(UNDERSC)
23669 					calelt();
23670 #else
23671 
23672 #ifdef CRAY
23673 					CALELT();
23674 #else
23675 					calelt_();
23676 #endif
23677 
23678 #endif
23679 				   	if (qdpptr->ihsdp) qdpptr->idipon = 1;
23680 				   }
23681 #ifdef DOGL
23682 				   if (qdpptr->idipon) ogdipole();
23683 #endif
23684 				   if (qdpptr->idipon)
23685 #if defined(VMS) || defined(UNDERSC)
23686 					   prtdip();
23687 #else
23688 
23689 #ifdef CRAY
23690 					   PRTDIP();
23691 #else
23692 					   prtdip_();
23693 #endif
23694 
23695 #endif
23696 				   update_struct();
23697 				}
23698 #ifdef MPFIT
23699 				if (itmp == 19) {
23700 				    List.nents = 2;
23701 				    if (DoPopUp(winMC,
23702 					cbut[BSURF].x+1,cbut[BSURF].y+BUTTH,
23703 					&List,incp,0) == -1) *incp = 0;
23704 				}
23705 #endif
23706 				*inct = 570+itmp;
23707 			      break;}
23708 
23709                  case BHYD: {
23710 				   if (!cbut[BHYD].toggle) {
23711 					TogUp(&cbut[BHYD]);
23712 					*inct = 620;
23713 				   } else {
23714 					int itmp;
23715 					LSSTRU List;
23716 					List.list = hyds; List.nents = 5;
23717 					if (DoPopUp(winMC,
23718 					     cbut[BHYD].x+1,cbut[BHYD].y+BUTTH,
23719 					     &List,&itmp,0) == -1) break;
23720 					if (itmp != 2 && itmp != 3 &&
23721 					    itmp != 4) TogDown(&cbut[BHYD]);
23722 
23723 					if (itmp == 3) InitPar();
23724 					else if (itmp == 4) {
23725 					   if (!SELHup) iniselh();
23726 					   doret = 0;
23727 					}
23728 					else *inct = 621+itmp;
23729 				   }
23730 			      break;}
23731 
23732                  case BVRML: {
23733 				LSSTRU List;
23734 				List.list = vrmlopt; List.nents = 4;
23735 				if (DoPopUp(winMC,
23736 					cbut[BVRML].x+1,cbut[BVRML].y+BUTTH,
23737 					&List,ivtwo,0) == -1) break;
23738 				update_model = 0;
23739 				if (*ivtwo == 3 ||
23740 				   (*ivtwo == 2 && *ipdbon && *backb)) {
23741 				   *inct = 116;
23742 				} else {
23743 				   qboxstr(&qboxes[QVRML],NULL,1,0,-1,DEFQX,
23744 					DEFQY, QBOXWIDE,QBOXHIGH,0,
23745 					"VRML Filename ? ",NULL,0,0,
23746 					589,0,dummyproc);
23747 				}
23748 			      }
23749 			      break;
23750 
23751                  case BMOV: { int iret = -1;
23752 			      strcpy(stemp,"which avconv > /dev/null 2>&1");
23753 			      iret = system(stemp);
23754 			      if (iret == 0) {
23755 			         if (!Movup) InitMovie(event.xbutton.x_root,
23756 						    event.xbutton.y_root);
23757 			      } else {
23758 				if (DoCan(event.xbutton.x_root,
23759 					event.xbutton.y_root,
23760 				"The movie functionality depends on package avconv\nOn linux to install:\nsudo apt-get install libav-tools",0)) {}
23761 			      }
23762 			      }
23763 			      break;
23764                  case BALIGN: {
23765 				LSSTRU List; int ial;
23766 				List.list = alnopt; List.nents = 3;
23767 				if (DoPopUp(winMC,
23768 					cbut[BALIGN].x+1,cbut[BALIGN].y+BUTTH,
23769 					&List,&ial,0) == -1) break;
23770 				RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
23771 			if (ial == 0) {
23772 				if (!DoCan(event.xbutton.x_root,
23773 					event.xbutton.y_root,ogXYZStr,1)) {
23774 				 qboxstr(&qboxes[QMXYZ],NULL,1,0,-1,DEFQX,DEFQY,
23775 				   QBOXWIDE,QBOXHIGH, 0,"XYZ file ? ",NULL,0,0,
23776 				   152,0,dummyproc);
23777 				}
23778 			} else if (ial == 1) {
23779 			    LSSTRU List; int ibl;
23780 			    List.list = dckopt; List.nents = 2;
23781 			    if (DoPopUp(winMC,
23782 				cbut[BALIGN].x+1,cbut[BALIGN].y+BUTTH,
23783 				&List,&ibl,0) == -1) break;
23784 			    if (ibl == 0) {
23785 				*iocnt = 0;
23786 				if (!DoCan(event.xbutton.x_root,
23787 					event.xbutton.y_root,
23788 	"To you want to overlay the centers of the two molecules ? \n\
23789 Click Cancel if you want to keep the original coordinates",1)) {
23790 				   *iocnt = 1;
23791 				}
23792 				if (!DoCan(event.xbutton.x_root,
23793 					event.xbutton.y_root,ogOVRLStr,1)) {
23794 				 qboxstr(&qboxes[QMXYZ],NULL,1,0,-1,DEFQX,DEFQY,
23795 				   QBOXWIDE,QBOXHIGH, 0,"PDB file ? ",NULL,0,0,
23796 				   1520,0,dummyproc);
23797 				 }
23798 			    } else {
23799 				if (!DoCan(event.xbutton.x_root,
23800 					event.xbutton.y_root,ogLigStr,1)) {
23801 				   *iocnt = 0;
23802 				   bflag = 1; doret = 1; bretval = 562;
23803 			           XDefineCursor(display,win,AtomCursor);
23804 				 }
23805 			    }
23806 			} else {
23807 				doret = 1;
23808 				if (!DoCan(event.xbutton.x_root,
23809 					   event.xbutton.y_root,
23810 					   ogDockStr,1)) {
23811 			           XDefineCursor(display,win,AtomCursor);
23812 				   bflag = 1; bretval = 563;
23813 
23814 				}
23815 
23816 			      	break;
23817 			}
23818 				 doalign = 1;
23819 			      }
23820 			      break;
23821 
23822                  case BORIG: {bflag = 1; doret = 0; bretval = 560;
23823 			      strcpy(molwstr,"Click on atom to set Origin !");
23824 			      StatusStr(0,1);
23825 			      XDefineCursor(display,win,AtomCursor);
23826 			      break;}
23827 
23828                  case BCELL: { int icell; int iwcell; LSSTRU List;
23829 				List.list = cellopts; List.nents = ncell;
23830 				if (DoPopUp(winMC,
23831 					cbut[BCELL].x-8,cbut[BCELL].y-BUTTH,
23832 					&List,&icell,0) == -1) break;
23833 				RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
23834                                 if (! cell->ichx) {
23835 #if defined(VMS) || defined(UNDERSC)
23836 					mkcell(xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
23837 #else
23838 #ifdef CRAY
23839 					MKCELL(xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
23840 #else
23841 					mkcell_(xyzp->coo,xyzp->ianz,xyzp->iatclr,xyzp->iconn,
23842 #endif
23843 #endif
23844 				   &cell->natc,&cell->icent,&cell->inorm,&cell->nspg,
23845 				   &cell->nopr,cell->ir,cell->it,
23846 				   &cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
23847 				   &cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
23848 				   &cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
23849 				   &cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
23850 					cell->ichx = 1;
23851 				}
23852 				*incp = icell + 1;
23853 				if (icell == 19) {
23854 				   List.list = cellwopts; List.nents = nwcell;
23855 				   RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
23856 				   XFlush(display); XSync(display,False);
23857 				   if (DoPopUp(winMC,
23858 					cbut[BCELL].x-8,cbut[BCELL].y+7*BUTTH,
23859 					&List,&iwcell,0) == -1) break;
23860 				   *incp = 20 + iwcell;
23861 				}
23862                                 *inct = 550;
23863 		 		TogUp(&cbut[BHYD]);
23864 				if (icell == 13) {
23865 				   if (DoCan(event.xbutton.x_root,
23866 					event.xbutton.y_root,
23867 	" - Use the standard rotation, translation and zoom in/out.\n\
23868  - Use the Esc to switch between rotation of part or the whole structure",1)) {
23869 					*inct = 0;
23870 				   } else {
23871 					doalign = 0;
23872 				   }
23873 				}
23874 				if (icell == 14) {
23875 				   CreateCellPar();
23876 				   doret = 0;
23877 				   *inct = 0;
23878 				}
23879 				if (icell == 18) {
23880 				   RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
23881 				   List.list = xtinkopts; List.nents = 2;
23882 				   if (DoPopUp(winMC,
23883 					cbut[BCELL].x-8,cbut[BCELL].y+BUTTH,
23884 					&List,iqopt,0) == -1) break;
23885 				}
23886 				if (icell == 15 || icell == 16) {
23887 				   InitCellDelTrans(0);
23888 				   *incp = 2;
23889 				   if (icell == 15) InitCellDelTrans(1);
23890 				   else InitCellDelTrans(0);
23891 				}
23892 			   }
23893 			   break;
23894 
23895                  case BFORC:  if (pdb) {
23896 				 if (qbres) {
23897 				    TogUp(&cbut[BFORC]);
23898 				    qbres = 0;
23899 				    XUnmapWindow(display,RESwin);
23900 				 } else {
23901 				    XMapWindow(display,RESwin); qbres = 1;
23902 				    TogDown(&cbut[BFORC]);
23903 		                    qboxstr(&qboxes[QRESI],&RESwin,1,0,-1,DEFQX,DEFQY,
23904 				    QBOXWIDE,QBOXHIGH,0,"Display residue(s) ? ",
23905 				    NULL,0,0,460,-1,dummyproc);
23906 				 }
23907 				update_model = 0;
23908 		              } else {
23909 				update_model = 0;
23910 				if (frfor) {
23911 				   if (FRup) {
23912                                            XDestroyWindow(display,FrBox);
23913 					   if (specup) {
23914 					      XDestroyWindow(display,winspec);
23915 					      specup = 0;
23916 					   }
23917 					   *inct = 520;
23918 					   DoFreq = 0;
23919 					   FRup = 0;
23920 				           TogUp(&cbut[BFORC]);
23921 				   } else {
23922 					   if (FRQ->nfreq) createfr(1);
23923 					   createspec(1);
23924 					   DoFreq = 1;
23925 					   if (FRQ->nfreq) FRup = 1;
23926 				           TogDown(&cbut[BFORC]);
23927 				   }
23928 				} else {
23929 				   *incp = TogBut(&cbut[BFORC]);
23930 				   *inct = 130;
23931 				   if (*fancy || *fullgl) ogforces();
23932 				   update_struct();
23933 				}
23934 			      }
23935                               break;
23936 
23937                  case BINCRF: if (pdb) {
23938 				bflag = 1; doret = 0; bretval = 320;
23939 				strcpy(molwstr,"Click on the backbone to activate !");
23940 				StatusStr(0,1);
23941 				XDefineCursor(display,win,AtomCursor);}
23942                               else {
23943 				doret = 0;
23944 				scalptr->fscal = scalptr->fscal*1.5;
23945 				scalptr->fscal = MAXI(scalptr->fscal,0.01);
23946 #if defined(VMS) || defined(UNDERSC)
23947 				parfc();
23948 #else
23949 #ifdef CRAY
23950 				PARFC();
23951 #else
23952 				parfc_();
23953 #endif
23954 #endif
23955 				update_model = 0;
23956 				if (*fancy || *fullgl) ogforces();
23957 				update_struct();
23958 			      }
23959                               break;
23960                  case BDECRF: if (pdb) {
23961 				int doit;
23962 
23963 				if (hetptr.NHetAtm) {
23964 				 LSSTRU List; int iop;
23965 				 if (!calfptr->issdon) {
23966 #if defined(VMS) || defined(UNDERSC)
23967 					ribbs();
23968 #else
23969 #ifdef CRAY
23970 					RIBBS();
23971 #else
23972 					ribbs_();
23973 #endif
23974 #endif
23975 					calfptr->ihet[0] = 0;
23976 					calfptr->ihet[1] = 0;
23977 					calfptr->ihet[2] = 0;
23978 					calfptr->ihet[3] = 0;
23979 				 }
23980 
23981 				 List.list = hetptr.HetAtm; List.nents = hetptr.NHetAtm;
23982 				 if (DoPopUp(winMC,
23983 					cbut[BDECRF].x+1,cbut[BDECRF].y+BUTTH,
23984 					&List,&iop,0) == -1) break;
23985 				 *incp = -1*iop;
23986 				 doit =  calfptr->ihet[iop];
23987 
23988 				 if (hetptr.HetAtm[iop] != NULL) {
23989 				    if (strncmp(hetptr.HetAtm[iop],"ion",3) == 0) {
23990 					*incp = calfptr->ision;
23991 					doit = !(*ionoff);
23992 				    }
23993 				 }
23994 
23995                 		 if (!monoscr && doit == 0) {
23996 
23997 /* switch ON helix/strand/.. or hetatm */
23998 
23999 					if (DoPopUp(winMC,
24000 					  cbut[BDECRF].x-8,cbut[BDECRF].y+BUTTH,
24001 					  NULL,Snstr,0) == -1) break;
24002 
24003 					sndon(iop,1,*Snstr);
24004 
24005 				 } else {
24006 
24007 /* switch OFF helix/strand/.. or hetatm */
24008 
24009 					*Snstr = 1;
24010 					sndoff(iop);
24011 #ifdef DOGL
24012 					ogbck(iop);
24013 #endif
24014 				 }
24015 				 *inct = 330;
24016 				}
24017 			      }
24018                               else {
24019 				doret = 0;
24020 				scalptr->fscal = scalptr->fscal/1.5;
24021 				scalptr->fscal = MAXI(scalptr->fscal,0.01);
24022 #if defined(VMS) || defined(UNDERSC)
24023 				parfc();
24024 #else
24025 #ifdef CRAY
24026 				PARFC();
24027 #else
24028 				parfc_();
24029 #endif
24030 #endif
24031 				update_model = 0;
24032 				if (*fancy || *fullgl) ogforces();
24033 				update_struct();
24034 			      }
24035 			      break;
24036 
24037                  case BUNSC:  if (pdb) {*inct = 340;
24038 					TogBut(&cbut[BUNSC]);}
24039                               else {
24040 				doret = 0;
24041 				scalptr->fscal = 1.0;
24042 #if defined(VMS) || defined(UNDERSC)
24043 				parfc();
24044 #else
24045 #ifdef CRAY
24046 				PARFC();
24047 #else
24048 				parfc_();
24049 #endif
24050 #endif
24051 				update_model = 0;
24052 				if (*fancy || *fullgl) ogforces();
24053 				update_struct();
24054 			      }
24055                               break;
24056 
24057                  case BHBOND: if (pdb) {
24058                                 int ict;
24059 
24060 			        TogBut(&cbut[BHBOND]);
24061 				if (!hbon) {
24062 				   hbon = 1;
24063 				   ict = 490;
24064 				   if (*ipdbon && *zmptrp->ihaszm) ict = 626;
24065 				   qboxstr(&qboxes[QHBOND],NULL,1,0,-1,
24066 					DEFQX, DEFQY, QBOXWIDE,QBOXHIGH, 0,
24067 					"Maximum H-bond distance (Angs.) ? ",
24068 					NULL, 0,2,ict,-1,dummyproc);
24069 				} else {
24070 				   hbon = 0;
24071 				   if (*ipdbon && *zmptrp->ihaszm) {
24072 					*inct = 624;
24073 				   } else {
24074 					*inct = 490;*incp = -1;
24075 				   }
24076 				}
24077                               }
24078                               break;
24079 
24080                  case BWRITF: { LSSTRU List;
24081 			      List.list = wropt; List.nents = 16;
24082 			      if (DoPopUp(winMC,
24083 					cbut[BWRITF].x+1,cbut[BWRITF].y+BUTTH,
24084 					&List,iwropt,0) == -1) break;
24085 			      if (*iwropt == 8) {
24086 				List.list = pdbwh; List.nents = 3;
24087 		   		RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
24088 				if (DoPopUp(winMC,
24089 					cbut[BWRITF].x+1,cbut[BWRITF].y+BUTTH,
24090 					&List,ipdbwh,0) == -1) break;
24091 			      }
24092 			      if (*iwropt == 14 && cell->ichx) {
24093 				   List.list = ambwopts; List.nents = 2;
24094 				   if (DoPopUp(winMC,
24095 					cbut[BWRITF].x+1,cbut[BWRITF].y+BUTTH,
24096 					&List,&pbc->icell,0) == -1) break;
24097 				   if (pbc->icell == 1) {
24098 #if defined(VMS) || defined(UNDERSC)
24099 				fdat(&EIGHTEEN,&ZERO,&ZERO,&ZERO,&ZERO,&ZERO);
24100 #else
24101 #ifdef CRAY
24102 				FDAT(&EIGHTEEN,&ZERO,&ZERO,&ZERO,&ZERO,&ZERO);
24103 #else
24104 				fdat_(&EIGHTEEN,&ZERO,&ZERO,&ZERO,&ZERO,&ZERO);
24105 #endif
24106 #endif
24107 		   		   }
24108 			      }
24109 			      if (*iwropt == 13) {
24110 				   WriteCML();
24111 				   strcpy(molwstr,"Wrote file molecule.cml");
24112 				   StatusStr(0,1);
24113 				   break;
24114 			      }
24115 			      if (*iwropt == 15) {
24116 #if defined(VMS) || defined(UNDERSC)
24117 				   wrtwfn();
24118 #else
24119 #ifdef CRAY
24120 				   WRTWFN();
24121 #else
24122 				   wrtwfn_();
24123 #endif
24124 #endif
24125 
24126 				   strcpy(molwstr,"Wrote file molden.wfn");
24127 				   StatusStr(0,1);
24128 				   break;
24129 			      }
24130 			      if (*iwropt >= 3) *ixyz = *iwropt - 3;
24131 			      *iwropt = *iwropt + 1;
24132 			      if (*iwropt > 4) *iwropt = 4;
24133 			      qboxstr(&qboxes[QPOST],NULL,1,0,-1,DEFQX,DEFQY,
24134 					QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
24135 					0,0,470,0,dummyproc);
24136 			      update_model = 0;
24137 			      }
24138                               break;
24139 
24140                  case BREADF:
24141 				doret = 0;
24142 				if (fsel.qbrfile) {
24143 				   TogUp(&cbut[BREADF]);
24144 				   fsel.qbrfile = 0;
24145 				   XUnmapWindow(display,fsel.win);
24146 				}
24147 				else {
24148 				   TogDown(&cbut[BREADF]);
24149 				   fsel.qbrfile = 1;
24150 				   FileSelectList(&fsel);
24151 
24152 				   TogDown(&dbut[BMOL]);
24153 				   TogDown(&dbut[BCONT]);
24154 				   TogUp(&dbut[BFILL]);
24155 				   TogUp(&dbut[BORI]);
24156 				}
24157 			        update_model = 0;
24158 				break;
24159 
24160                  case BZMAT:    if (ZMEup) {
24161 				   UnMapZME();
24162 				}
24163 				else {
24164 				   if (pdb && !*zmptrp->ihaszm) {
24165 					if (!DoPDB(1)) break;
24166 				   }
24167 #if defined(VMS) || defined(UNDERSC)
24168 				   clrmon();
24169 #else
24170 #ifdef CRAY
24171 				   CLRMON();
24172 #else
24173 				   clrmon_();
24174 #endif
24175 #endif
24176 				   TogDown(&cbut[BZMAT]);
24177         			   if (denm) ActBut(&cbut[BDENMOD],0);
24178 				   if (pdb) {
24179 				      if (ialtyp == NULL) ZMEAA = 1;
24180 				      else if (*ialtyp == 1) ZMEAA = 0;
24181 				      else ZMEAA = 1;
24182 				   }
24183 				   InitZME();
24184 				   if (pdb) {
24185 				      if (ialtyp == NULL) ZMEAA = 1;
24186 				      else if (*ialtyp == 1) ZMEAA = 0;
24187 				      else if (calfptr->ncalf <= 0) ZMEAA = 0;
24188 				      else ZMEAA = 1;
24189 				   }
24190 				}
24191 				*inct = 630;
24192 			        update_model = 0;
24193 				break;
24194 
24195                  case BDIST:
24196 			        update_model = 0;
24197                                 if (!Selecting && !cflag && !dflag) {
24198 				   *inct = 170;*incp = 1;
24199 				   aflag = 2;anum = 2;acnt = 0;
24200 				   XDefineCursor(display,win,AtomCursor);
24201 				}
24202                                 break;
24203 
24204                  case BANGLE:
24205 			        update_model = 0;
24206                                 if (!Selecting && !cflag && !dflag) {
24207 				   *inct = 170;*incp = 2;
24208 				   aflag = 3;anum = 3;acnt = 0;
24209 				   XDefineCursor(display,win,AtomCursor);
24210 				}
24211                                 break;
24212 
24213                  case BDIHED:
24214 			        update_model = 0;
24215                                 if (!Selecting && !cflag && !dflag) {
24216 				   *inct = 170;*incp = 3;
24217 				   aflag = 4;anum = 4;acnt = 0;
24218 				   XDefineCursor(display,win,AtomCursor);
24219 				}
24220 				break;
24221 
24222                  case BAUTH:
24223 				if (!ATMup) InitATM(event.xbutton.x_root,
24224 						    event.xbutton.y_root);
24225 			        update_model = 0;
24226 				break;
24227 
24228                  case BPAL:
24229 				doret = palette();
24230 				break;
24231 
24232                  case BGIF:
24233                               { setgif(1);
24234 				doret = 0;
24235 				break;}
24236                  case BLABEL:
24237 				if (cbut[BLABEL].toggle) {
24238 				   LSSTRU List;
24239 				   List.list = labels;
24240 				   List.nents = 6;
24241 				   if (nmrptr->ihsnmr) {
24242 					List.nents = 7;
24243 					if (DoPopUp(winMC,
24244 					cbut[BLABEL].x+1,cbut[BLABEL].y-20,
24245 					&List,&qdpptr->iqon,0) == -1) break;
24246 				   } else {
24247 
24248 					if (DoPopUp(winMC,
24249 					cbut[BLABEL].x+1,cbut[BLABEL].y,
24250 					&List,&qdpptr->iqon,0) == -1) break;
24251 				   }
24252 				   if (qdpptr->iqon == 3 && !qdpptr->ihasq) {
24253 					strcpy(molwstr,
24254 					     "Click on atom to set Origin !");
24255 					StatusStr(0,1);
24256 				   }
24257 				}
24258 				*inct = 180;*incp = 0;
24259 				update_model = 0;
24260 				TogBut(&cbut[BLABEL]);
24261 				break;
24262                  case BSHADE:
24263 				if (*shade) {
24264 				   *shade = 0;
24265 				   TogUp(&cbut[BSHADE]);
24266 				   if (DPTup) XUnmapWindow(display,DPTwin);
24267 				} else {
24268 				   if (colcells >= 256) *shade = 1;
24269 				   if (*shade) TogDown(&cbut[BSHADE]);
24270 				   if (!DPTup) InitDPT();
24271 				   else XMapRaised(display,DPTwin);
24272 				}
24273 #ifdef DOGL
24274 			        EnableFog();
24275 #endif
24276 			        update_model = 0;
24277 				break;
24278 
24279                  case BBACKB:  *inct = 310;*incp = 0;
24280 				DoBackbone();
24281                                break;
24282                  case BATCOL:  *inct = 400;*incp = 0;
24283 				TogBut(&cbut[BATCOL]); break;
24284                  case BPERSP:  *inct = 410;*incp = 0;
24285 			       update_model = 0;
24286 				TogBut(&cbut[BPERSP]); break;
24287                  case BLEFT:    hold = 1; holdt = 420; holdp = 0;
24288 			       update_model = 0;
24289 				*inct = 420;*incp = 0; break;
24290                  case BRIGHT:   hold = 1; holdt = 430; holdp = 0;
24291 			       update_model = 0;
24292 				*inct = 430;*incp = 0; break;
24293                  case BUP:      hold = 1; holdt = 440; holdp = 0;
24294 			       update_model = 0;
24295 				*inct = 440;*incp = 0; break;
24296                  case BDOWN:    hold = 1; holdt = 450; holdp = 0;
24297 			       update_model = 0;
24298 				*inct = 450;*incp = 0; break;
24299 		 case BBALL:
24300 				if (*ball) {
24301 				   *ball = 0;
24302 				   strcpy(molwstr,"Old Style rotation");
24303 				   StatusStr(0,1);
24304 				} else {
24305 				   *ball = 1;
24306 				   strcpy(molwstr,"Sticky Pointer rotation");
24307 				   StatusStr(0,1);
24308 				}
24309 #if defined(VMS) || defined(UNDERSC)
24310 				wrtres();
24311 #else
24312 #ifdef CRAY
24313 				WRTRES();
24314 #else
24315 				wrtres_();
24316 #endif
24317 #endif
24318 				TogBut(&cbut[BBALL]);
24319 				hold = 0;
24320 			        update_model = 0;
24321 				break;
24322                  case BPACE:   {
24323                                 *inct = 500;
24324 			       update_model = 0;
24325                                if (coarse == 2) {
24326                                   coarse = 0;
24327                                   cbut[BPACE].pix = slowPix;
24328                                }
24329                                else if(coarse == 1) {
24330                                   coarse = 2;
24331                                   cbut[BPACE].pix = blastPix;
24332                                }
24333                                else {
24334                                   coarse = 1;
24335                                   cbut[BPACE].pix = fastPix;
24336                                }
24337                                DrwBut(&cbut[BPACE]);
24338                                *incp = coarse; break;
24339                                }
24340                  case BCONV:
24341                               {
24342 			       update_model = 0;
24343                                if (!cnvup)
24344                                     {createconv();cnvup = 1;}
24345                                else {
24346                                     XDestroyWindow(display,wincnv);cnvup = 0;}
24347                                break;}
24348                  case BGEOM:
24349                               {
24350 			       update_model = 0;
24351                                if (!geoup) {
24352                                     if (geo1ptr->gcvav) {
24353 				        TogDown(&cbut[BGEOM]);
24354 					creategeom();
24355 					geoup = 1;
24356 				    }
24357 			       }
24358                                else {
24359 				    TogUp(&cbut[BGEOM]);
24360                                     XDestroyWindow(display,wingeo);geoup = 0;}
24361                                break;}
24362                  case BJCPL:
24363 			        update_model = 0;
24364                                 if (!Selecting && !cflag && !dflag) {
24365 				   *inct = 170;*incp = 1;
24366 				   aflag = 2;anum = 2;acnt = 0; eflag = 1;
24367 				   XDefineCursor(display,win,AtomCursor);
24368 				}
24369                                 break;
24370 
24371 
24372                  }/*end switch*/
24373                  if (doret) return;
24374                  }
24375               }/* end if*/
24376 
24377 
24378            }/*end buttonpress*/
24379            break;
24380 
24381 
24382            case MotionNotify: {
24383 
24384 
24385               if(DEBUG)fprintf(stderr,"MotionNotify\n");
24386 
24387 	      motion_screen(inct,incp);
24388 
24389 	      if (!bcksvg.UpSVG) SetExplButton(event.xmotion.window,
24390 				event.xmotion.x,event.xmotion.y);
24391 
24392               if(event.xmotion.window == wincnv) {
24393 		if (cnvptr->icvav1)
24394 			parse_motion(&scfEfirst);
24395 		if (cnvptr->icvav2)
24396 			parse_motion(&scfElast);
24397 	      }
24398 
24399               if (event.xmotion.window == winspec) {
24400 			parse_motion(&spect);
24401 	      }
24402 
24403               if (event.xmotion.window == winsco && scoup) {
24404 			parse_motion(&docksco);
24405 	      }
24406 
24407               if(event.xmotion.window == wingeo) {
24408 		if (geo1ptr->gcvav) {
24409 			if (geo1ptr->ifmxav) parse_motion(&geoFmax);
24410       			if (geo1ptr->ifrmav) parse_motion(&geoFrms);
24411 			if (geo1ptr->idmxav) parse_motion(&geoSmax);
24412 			if (geo1ptr->idrmav) parse_motion(&geoSrms);
24413 			if (geo1ptr->ieav) parse_motion(&geoE);
24414 		}
24415 	      }
24416 
24417               if(event.xmotion.window == win && ZoomSelection) {
24418 
24419 
24420                  while(XCheckTypedWindowEvent(display, win, MotionNotify,
24421                                         &event));
24422 		 if ( !(has_opengl && (*fancy || *fullgl))) {
24423                     XDrawRectangle(display, win, gc,
24424                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
24425 		 }
24426 
24427                  MotionCount++;
24428 
24429                  /* get the location of the pointer */
24430 
24431                  ZoomX2 = MAXI(ZoomX1, event.xmotion.x);
24432                  ZoomY2 = MAXI(ZoomY1, event.xmotion.y);
24433                  ZoomW = MAXI(ABS(ZoomX2 - ZoomX1),1);
24434                  ZoomH = MAXI(ABS(ZoomY2 - ZoomY1),1);
24435 		 if (has_opengl && (*fancy || *fullgl)) {
24436 #ifdef DOGL
24437 		    rubber(1);
24438 #endif
24439 		 } else {
24440                     XDrawRectangle(display, win, gc,
24441                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
24442 		 }
24443 
24444               } /* end ZoomSelection */
24445 
24446 
24447            } /* end MotionNotify */
24448            break;
24449 
24450 
24451            case ButtonRelease: {
24452 
24453               if (!((*fancy || *fullgl) && has_opengl) && event.xbutton.window == win) {
24454 		 moving = 0;
24455 		 gmoving = 0;
24456 	      }
24457 
24458               if (event.xbutton.window == win &&
24459 		  (event.xbutton.button == 1 || event.xbutton.button == 2) &&
24460                   !ZoomSelection ) moving = 0;
24461 
24462               if (event.xbutton.window == win && (event.xbutton.button == 1 ||
24463                  event.xbutton.button == 2) && ZoomSelection ) {
24464 
24465                  ZoomSelection = False;
24466 
24467 		 if (has_opengl && (*fancy || *fullgl)) {
24468 		    dispsf();
24469 		 } else {
24470                     XDrawRectangle(display, win, gc,
24471                                 ZoomX1, ZoomY1, ZoomW, ZoomH);
24472                     XSetFunction(display, gc, GXcopy);
24473 		 }
24474                  XUndefineCursor(display, win);
24475 
24476                  if (MotionCount >=3 ) {
24477                     for ( i = 0; i < *xyzp->iatoms; i++ ) {
24478                       if (xyzp->iaton[i] >= 1 &&
24479                       VIERKANT(xyzp->iyp[i], xyzp->ixp[i],
24480 				ZoomX1, ZoomY1, ZoomW, ZoomH)) {
24481                          if (Select && xyzp->ianz[i] != 100) xyzp->iaton[i] = 2;
24482                          else xyzp->iaton[i] = 1;
24483                       }
24484                     }
24485 		    if (SelRes != -3) {
24486 			for ( i = 0; i < *xyzp->iatoms; i++ ) {
24487 			   if (xyzp->iaton[i] > 1) {
24488 				xyzp->iresid[i] = SelRes;
24489 	   			xyzp->iatclr[i] = xyzp->iatclr[ATMsel];
24490 				xyzp->iaton[i] = 1;
24491 			   }
24492 			}
24493 			SelRes = -3;
24494 		    }
24495 	    	    update_model = 0;
24496 	    	    update_sel = 1;
24497                     return;
24498                  }
24499 
24500               } /* end zoom */
24501 
24502               if (( (*fancy || *fullgl) && has_opengl)
24503 			&& event.xbutton.window == win) {
24504 		 mouseu(event.xbutton.button,event.xbutton.state,
24505 			event.xbutton.x, event.xbutton.y);
24506                  dispsf();
24507 		 if (animptr.on) {
24508 		    hold = 0;
24509 		    return;
24510 		 }
24511 		 break;
24512 	      }
24513 
24514            } /* end ButtonRelease */
24515            break;
24516 
24517 
24518            case Expose: {
24519 
24520 
24521 	      update_model = 0;
24522               if (DEBUG) fprintf(stderr,"Expose\n");
24523 
24524 	      while (XCheckWindowEvent(display, event.xexpose.window,
24525 			ExposureMask, &event)) {
24526 	      }
24527 
24528               if ( !((*fancy || *fullgl) && has_opengl)
24529 			&& event.xexpose.window == win) {
24530                  if ( molback == molcur ) {
24531                     XCopyArea(display,molcur,win,gc,0,0,width,height,0,0);
24532                  }
24533               }
24534 
24535               if (((*fancy || *fullgl)  && has_opengl)
24536 			&& event.xexpose.window == win) {
24537                 dispsf();
24538 		break;
24539               }
24540 
24541               for (i=0; i<NQBOX; i++) {
24542 		if (event.xexpose.window == qboxes[i].win)
24543 			PromptBox(&qboxes[i]);
24544 	      }
24545 
24546               for (i=0; i<NOBJS; i++) {
24547 	         if (WinObj[i].win != NULL && WinObj[i].winup != NULL) {
24548 	            if (event.xexpose.window == *WinObj[i].win
24549 			&& WinObj[i].redraw != NULL && *(WinObj[i].winup)) {
24550 			WinObj[i].redraw();
24551 		    }
24552 		 }
24553 	      }
24554 	      if (event.xexpose.window == fsel.win) RedrawFwin(&fsel);
24555 
24556 	      if (event.xexpose.window == gsel.win) RedrawFwin(&gsel);
24557 
24558 	      if (event.xexpose.window == dsel.win) RedrawFwin(&dsel);
24559 
24560 	      if (event.xexpose.window == FrBox) RedrawList(&frlist);
24561 	      if (event.xexpose.window == MLTwin &&
24562 			event.xexpose.send_event == True) DoSvgfile();
24563 	      if (event.xexpose.window == MLTwin) RedrawMLT();
24564               if (event.xexpose.window == winMC) {
24565                    RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);}
24566 
24567 
24568               if (event.xexpose.window == winau && gijsup) {
24569                    XSetForeground(display, gc, infobg);
24570                    XSetBackground(display, gc, infofg);
24571                    XCopyPlane(display, gijs, winau, gc, 0, 0, gijsface_width,
24572                    gijsface_height, 0, 0, (unsigned long)1);}
24573 
24574               if (event.xexpose.window == FLXwin && FLXup)
24575 	           RedrawList(&flxlist);
24576 
24577               if (event.xexpose.window == winrama && ramaup) {
24578 		   if ( rwiold != rwi || rhiold != rwi) {
24579 	              if (event.xexpose.count == 0) {
24580 			  XResizeWindow(display, winrama, rwi, rwi);
24581 			  rwiold = rwi; rhiold = rhi;
24582 		      }
24583 		   }
24584 		   DrawRama();
24585 	      }
24586 
24587               if (event.xexpose.window == wingeo && geoup) {
24588 
24589 		   while(XCheckTypedWindowEvent(display,wingeo,
24590 				Expose,&report));
24591 		   XClearWindow(display,wingeo);
24592 
24593 #if defined(VMS) || defined(UNDERSC)
24594                    drwgeo();
24595 #else
24596 #ifdef CRAY
24597                    DRWGEO();
24598 #else
24599                    drwgeo_();
24600 #endif
24601 #endif
24602 	      }
24603 
24604               if (event.xexpose.window == windock && dockup) {
24605 
24606                    drwdock();
24607 	      }
24608            }
24609            break;
24610 
24611 	   case MapNotify: {
24612 	      if (event.xmap.window == expldat.win &&
24613 		event.xmap.send_event == True) DoExpl();
24614            }
24615            break;
24616 
24617 	   case EnterNotify: {
24618 		if (!bcksvg.UpSVG) {
24619 		   expldat.win = -1;
24620 		   signal(SIGALRM,SIG_IGN);
24621 		}
24622            }
24623            break;
24624 
24625 	   case ClientMessage: {
24626 		Atom proto, delwin;
24627 		XClientMessageEvent *client_event =
24628 			(XClientMessageEvent *) &event;
24629 
24630 		proto = XInternAtom(display, "WM_PROTOCOLS", False);
24631 		delwin = XInternAtom(display, "WM_DELETE_WINDOW", False);
24632 
24633 		if (client_event->message_type == proto &&
24634 		    client_event->data.l[0] == delwin) {
24635 		    if (client_event->window == ZMEwin) {
24636 			UnMapZME();
24637 		    } else if (client_event->window == RESwin) {
24638 			if (qbres) {
24639 			    TogUp(&cbut[BFORC]);
24640 			    qbres = 0;
24641 			    XUnmapWindow(display,RESwin);
24642 			}
24643 		    } else if (client_event->window == fsel.win) {
24644 			if (fsel.qbrfile) {
24645 			    TogUp(&cbut[BREADF]);
24646 			    fsel.qbrfile = 0;
24647 			    XUnmapWindow(display,fsel.win);
24648 			}
24649 		    } else if (client_event->window == DISTwin) {
24650 			if (distup) {
24651 			    distup = 0;
24652 			    XUnmapWindow(display,DISTwin);
24653 			}
24654 		    } else if (client_event->window == FrBox) {
24655 			if (frfor && FRup) {
24656 			    TogUp(&cbut[BFORC]);
24657 			    XDestroyWindow(display,FrBox);
24658 			    DoFreq = 0;
24659 			    FRup = 0;
24660 #if defined(VMS) || defined(UNDERSC)
24661 			    resfr();
24662 			    doconn();
24663 #else
24664 #ifdef CRAY
24665 			    RESFR();
24666 			    DOCONN();
24667 #else
24668 			    resfr_();
24669 			    doconn_();
24670 #endif
24671 #endif
24672        		      	    *normc = 0;
24673 			}
24674 		    } else if (client_event->window == winspec) {
24675 			if (frfor && specup) {
24676 			    XDestroyWindow(display,winspec);
24677 			    specup = 0;
24678 			}
24679 		    } else if (client_event->window == wingeo) {
24680 			if (geoup) {
24681 			    TogUp(&cbut[BGEOM]);
24682 			    XDestroyWindow(display,wingeo);
24683 			    geoup = 0;
24684 			}
24685 		    } else if (client_event->window == wincnv) {
24686 			if (cnvup) {
24687 			    XDestroyWindow(display,wincnv);
24688 			    cnvup = 0;
24689 			}
24690 		    } else if (client_event->window == winsco) {
24691 			if (scoup) {
24692 			    XDestroyWindow(display,winsco);
24693 			    scoup = 0;
24694 			}
24695 		    } else if (client_event->window == winrama) {
24696 			if (ramaup) {
24697 			    XDestroyWindow(display,winrama);
24698 			    ramaup = 0;
24699 			}
24700 		    } else if (client_event->window == winpmf) {
24701 			if (pmfup) {
24702 			    XDestroyWindow(display,winpmf);
24703 			    pmfup = 0;
24704 			}
24705 		    } else if (client_event->window == winspec) {
24706 			if (specup) {
24707 			    XDestroyWindow(display,winspec);
24708 			    specup = 0;
24709 			}
24710 		    } else if (client_event->window == windock) {
24711 			if (dockup) {
24712 			    XDestroyWindow(display,windock);
24713 			    dockup = 0;
24714 			}
24715 		    } else if (client_event->window == CPwin) {
24716 			if (CPup) {
24717 			    XDestroyWindow(display,CPwin);
24718 			    CPup = 0;
24719 			}
24720 		    } else if (client_event->window == ATMwin) {
24721 			if (ATMup) {
24722 #ifdef DOGL
24723 			    if ((*fancy || *fullgl) && has_opengl) ogunsel();
24724 #endif
24725 			    XDestroyWindow(display,ATMwin);
24726 			    ATMup = 0;
24727 			}
24728 		    } else if (client_event->window == COLwin) {
24729 			if (COLup) {
24730 			    XDestroyWindow(display,COLwin);
24731 			    COLup = 0;
24732 			}
24733 		    } else if (client_event->window == ECOLwin) {
24734 			if (ECOLup) {
24735 			    XDestroyWindow(display,ECOLwin);
24736 			    ECOLup = 0;
24737 			}
24738 		    } else if (client_event->window == CHGwin) {
24739 			if (CHGup) {
24740 			    XDestroyWindow(display,CHGwin);
24741 			    CHGup = 0;
24742 			}
24743 		    } else if (client_event->window == CTwin) {
24744 			if (CTup) {
24745 			    XDestroyWindow(display,CTwin);
24746 			    CTup = 0;
24747 			}
24748 		    } else if (client_event->window == DPTwin) {
24749 			if (DPTup) {
24750 			    XDestroyWindow(display,DPTwin);
24751 			    DPTup = 0;
24752 			}
24753 		    } else if (client_event->window == SUBwin) {
24754 			if (SUBup) {
24755 			    XDestroyWindow(display,SUBwin);
24756 			    SUBup = 0;
24757 			}
24758 		    } else if (client_event->window == SEQwin) {
24759 			if (SEQup) {
24760 			    XDestroyWindow(display,SEQwin);
24761 			    SEQup = 0;
24762 			}
24763 		    } else if (client_event->window == TNKwin) {
24764 			if (TNKup) {
24765 			    XDestroyWindow(display,TNKwin);
24766 			    TNKup = 0;
24767 			}
24768 		    } else if (client_event->window == SRFwin) {
24769 			if (SRFup) {
24770 			    XDestroyWindow(display,SRFwin);
24771 			    SRFup = 0;
24772 			}
24773 		    } else if (client_event->window == SELHwin) {
24774 			if (SELHup) {
24775 			    XDestroyWindow(display,SELHwin);
24776 			    SELHup = 0;
24777 			}
24778 		    } else if (client_event->window == SRCHwin) {
24779 			if (SRCHup) {
24780 			    XDestroyWindow(display,SRCHwin);
24781 			    SRCHup = 0;
24782 			}
24783 		    } else if (client_event->window == MLTwin) {
24784 			if (MLTup) {
24785 			    XDestroyWindow(display,MLTwin);
24786 			    MLTup = 0;
24787 			}
24788 		    } else if (client_event->window == winau) {
24789 			if (gijsup) {
24790 			    XFreePixmap(display,gijs);
24791 			    XDestroyWindow(display,winau);
24792 			    gijsup = 0;
24793 			}
24794 		    } else if (client_event->window == MOVwin) {
24795 			if (Movup) {
24796 			    XDestroyWindow(display,MOVwin);
24797 			    Movup = 0;
24798 			}
24799 		    } else if (client_event->window == STRwin) {
24800 			if (DoCan(width/2, height/2,
24801 				"This window is essential",0)) {}
24802 		    } else if (client_event->window == QBox) {
24803 			XDestroyWindow(display,QBox);
24804 			XSync(display, False);
24805 		        qboxup = 0;
24806 		    } else if (client_event->window == winMC ||
24807 				client_event->window == win) {
24808 			if (DoCan(width/2, height/2,
24809 				"Use the Skull Icon to quit Molden",0)) {}
24810 		    }
24811 		}
24812 	   }
24813 	   break;
24814 
24815            case ConfigureNotify: {
24816 
24817               if(DEBUG)fprintf(stderr,"ConfigureNotify\n");
24818 
24819               /* you want to increase or decrease the size of the window*/
24820               /* get the new width and height*/
24821 
24822 	      while(XCheckTypedWindowEvent(display,
24823 		event.xconfigure.window, ConfigureNotify,&event)) {
24824 	      }
24825 
24826               if (event.xconfigure.window == win) {
24827 
24828 		   /* check for real resize */
24829 
24830                    if (event.xconfigure.width == width &&
24831                        event.xconfigure.height == height) {
24832 			if (has_opengl && (*fancy || *fullgl)) {
24833 #ifdef DOGL
24834 			    /*glXSwapBuffers(display, win);*/
24835 dispsf();
24836 #endif
24837 			    break;
24838 			} else return;
24839 		   }
24840 
24841                    width  = event.xconfigure.width;
24842                    height = event.xconfigure.height;
24843 
24844                    /* now resize the Graphics window, this will generate an
24845                       expose event*/
24846 
24847                    size_hints.flags  = USSize;
24848                    size_hints.width  =  width;
24849                    size_hints.height  =  height;
24850                    XSetNormalHints(display, win, &size_hints);
24851 		   if (has_opengl && (*fancy || *fullgl)) Reshape(1);
24852                    return;
24853               }
24854 
24855               if (event.xconfigure.window == winspec) {
24856 		   int i, spold,spoldw;
24857 
24858 		   spold = SPECHIGH;
24859 		   spoldw = SPECWIDE;
24860 		   SPECWIDE = event.xconfigure.width;
24861 		   SPECHIGH = event.xconfigure.height - SPBHIGH;
24862 		   if (SPECHIGH < 0) SPECHIGH = 0;
24863 
24864                    /* now resize the Graphics window, this will generate an
24865                       expose event*/
24866 
24867                    size_hints.flags  = USSize;
24868                    size_hints.width  =  SPECWIDE;
24869 		   if (event.xconfigure.height < SPBHIGH) {
24870 			size_hints.height  =  SPBHIGH;
24871 		   } else {
24872 			size_hints.height  =  event.xconfigure.height;
24873 		   }
24874                    XSetNormalHints(display, winspec, &size_hints);
24875 		   for (i=0; i<nsbutts; i++) {
24876 			spbut[i].y = SPECHIGH + (spbut[i].y - spold);
24877 			if (i >= 2)
24878 			    spbut[i].x = SPECWIDE + (spbut[i].x - spoldw);
24879 		   }
24880 		   for (i=0; i<nspqbox; i++)
24881 			qboxes[QHW+i].y = SPECHIGH + (qboxes[QHW+i].y - spold);
24882 		   drwspec();
24883               }
24884 
24885               if (event.xconfigure.window == wingeo) {
24886 
24887 		   nhframes = 1;
24888 		   if (geo1ptr->ifmxav || geo1ptr->ifrmav) nhframes = 2;
24889 		   nwframes = 1;
24890 		   if (geo1ptr->idmxav || geo1ptr->idrmav) nwframes = 2;
24891 
24892 		   gwi = event.xconfigure.width;
24893 		   ghi = event.xconfigure.height;
24894 
24895 		   if (nwframes == 2) {
24896 			CNVWIDE = gwi / 2;
24897 		   } else {
24898 			CNVWIDE = gwi;
24899 		   }
24900 		   if (nhframes == 2) {
24901 			CNVHIGH = ghi / 2;
24902 		   } else {
24903 			CNVHIGH = ghi;
24904 		   }
24905 
24906                    /* now resize the Graphics window, this will generate an
24907                       expose event*/
24908 
24909                    size_hints.flags  = USSize;
24910                    size_hints.width  =  gwi;
24911                    size_hints.height  =  ghi;
24912                    XSetNormalHints(display, wingeo, &size_hints);
24913 		   XClearWindow(display,wingeo);
24914 #if defined(VMS) || defined(UNDERSC)
24915 		   drwgeo();
24916 #else
24917 #ifdef CRAY
24918 		   DRWGEO();
24919 #else
24920 		   drwgeo_();
24921 #endif
24922 #endif
24923                    return;
24924               }
24925 
24926               if (event.xconfigure.window == winrama) {
24927 
24928 		   rwi = event.xconfigure.width;
24929 		   rhi = event.xconfigure.height;
24930 
24931 		   if (rwi < rhi) {
24932 			rhi = rwi;
24933 		   } else {
24934 			rwi = rhi;
24935 		   }
24936 
24937 		   if (rwi > DisplayWidth(display,screen) ||
24938 		       rhi > DisplayHeight(display,screen)) {
24939 			if (DisplayWidth(display,screen) >
24940 			    DisplayHeight(display,screen)) {
24941 				rwi = rhi = DisplayHeight(display,screen);
24942 			} else {
24943 				rwi = rhi = DisplayWidth(display,screen);
24944 			}
24945 		   }
24946 
24947                    size_hints.flags  = PSize;
24948                    size_hints.width  =  rwi;
24949                    size_hints.height  =  rwi;
24950                    XSetNormalHints(display, winrama, &size_hints);
24951               }
24952            }
24953            break;
24954 
24955            case UnmapNotify:         break;
24956 
24957            default: break;		/* ignore unexpected events */
24958 
24959         }  /* end switch event type*/
24960 
24961 
24962     }/* end while */
24963 
24964 #ifdef DOGL
24965     if ((has_opengl && (
24966 	(!(*fancy || *fullgl) && !moving ) ||
24967 	( (*fancy || *fullgl) && !gmoving)
24968 	))
24969 		|| !has_opengl) {
24970 	    return;
24971     } else dispsf();
24972 #else
24973     return;
24974 #endif
24975 
24976   } /* end MolWindow */
24977   break;
24978 
24979   case OpenWindow :
24980   {
24981     int ig;
24982 #ifdef DOGL
24983     int dummy;
24984 #endif
24985 
24986     SetupTable();
24987 
24988 #ifdef __CYGWIN__
24989 /*
24990     if (getenv("DISPLAY") == NULL) putenv("DISPLAY=localhost:0.0");
24991 */
24992     if (getenv("DISPLAY") == NULL) putenv("DISPLAY=127.0.0.1:0.0");
24993 #endif
24994     if (( display = XOpenDisplay(NULL)) == NULL )
24995     {
24996       fprintf( stderr, "Molden: cannot connect to X server %s\n",
24997                XDisplayName(display_name));
24998       exit(-1);
24999     }
25000 
25001     if (strstr(ServerVendor(display),"StarNet")) {
25002 	if (*istaro) {
25003 	   StarNetOld = 1;
25004 	} else {
25005 	   StarNet = 1;
25006 	   fprintf(stderr,"\nWith older versions of StarNet X-Win32\n");
25007 	   fprintf(stderr,"(6.1 and older) use the -Q commandline flag\n\n");
25008 	}
25009     }
25010 
25011     xison = 1;
25012 
25013     if (DEBUG) XSynchronize(display,1);
25014 
25015     XSetErrorHandler (X_Error_Message_CB);
25016 
25017     width  = 800;
25018     height = 800;
25019 
25020     screen         = DefaultScreen(display);
25021     Mwidth  = DisplayWidth(display, screen);
25022     Mheight = DisplayHeight(display, screen);
25023 
25024     if (GEOMset) {
25025 	ig = XParseGeometry(GEOMstr,&wx,&wy,&width,&height);
25026     }
25027 
25028     xswa.background_pixel = BlackPixel(display,screen);
25029     xswa.border_pixel     = WhitePixel(display,screen);
25030     xswa.backing_store    = NotUseful;
25031     xswa.backing_planes   = 0;
25032     xswa.save_under       = False;
25033     IBGcolor = 0;
25034 
25035     rootW = RootWindow(display,screen);
25036     dispDEEP  = DisplayPlanes(display,screen);
25037 
25038 #ifdef DOGL
25039     if (glXQueryExtension(display, &dummy, &dummy)) has_opengl = 1;
25040 
25041     if (has_opengl) {
25042 	if ((vi = glXChooseVisual(display, DefaultScreen(display),attributeList))) {
25043 	    screen = vi->screen;
25044 
25045 	    if (vi->class != TrueColor) fprintf(stderr,"TRuecolor required\n");
25046             if (!(cx = glXCreateContext(display, vi, 0, GL_TRUE))) fprintf(stderr,"no context\n");
25047             cmap = XCreateColormap(display,RootWindow(display,vi->screen),vi->visual,AllocNone);
25048             xswa.colormap = cmap;
25049         } else {
25050 	    has_opengl = 0;
25051         }
25052     }
25053 
25054 #endif
25055 
25056     Aspect = (float) width / (float) height;
25057 
25058     if (has_opengl) {
25059        win = XCreateWindow(display,
25060                         RootWindow(display,screen),
25061                         wx,
25062                         wy,
25063                         width,
25064                         height,
25065                         0,
25066                         vi->depth,
25067                         InputOutput,
25068                         vi->visual,
25069                         (CWBorderPixel | CWColormap | CWEventMask | CWBackingStore | CWBackingPlanes | CWSaveUnder),
25070                         &xswa);
25071     } else {
25072        win = XCreateWindow(display,
25073                         RootWindow(display,screen),
25074                         wx,
25075                         wy,
25076                         width,
25077                         height,
25078                         border_width,
25079                         CopyFromParent,
25080                         InputOutput,
25081                         CopyFromParent,
25082                         (CWBackPixel | CWBorderPixel | CWBackingStore | CWBackingPlanes),
25083                         &xswa);
25084     }
25085 
25086 
25087     StoreDeleteWindowProp(win);
25088 
25089     icon_pixmap = XCreateBitmapFromData(display,
25090                                         win,
25091                                         icon_bitmap_bits,
25092                                         icon_bitmap_width,
25093                                         icon_bitmap_height);
25094 
25095 
25096     size_hints.flags 	  = PPosition | PSize | PMinSize;
25097     size_hints.x 	  = wx;
25098     size_hints.y 	  = wy;
25099     size_hints.width 	  = width;
25100     size_hints.height 	  = height;
25101     size_hints.min_width  = 0;
25102     size_hints.min_height = 0;
25103 
25104     XSetStandardProperties(display,
25105                            win,
25106                            window_name,
25107                            icon_name,
25108                            icon_pixmap,
25109                            0, 0,
25110                            &size_hints);
25111 
25112     XSelectInput(display,
25113                  win,
25114                  (StructureNotifyMask|ExposureMask|ButtonPressMask
25115                  |ButtonReleaseMask|ButtonMotionMask|KeyPressMask
25116 		 |KeyReleaseMask|PointerMotionMask|EnterWindowMask));
25117 
25118     region = XCreateRegion();
25119 
25120     values.foreground = WhitePixel(display,screen);
25121     values.background = BlackPixel(display,screen);
25122 
25123     gc = XCreateGC(display,
25124                    win,
25125                    (GCForeground|GCBackground|GCArcMode),
25126                    &values);
25127     XSetArcMode(display,gc,ArcPieSlice);
25128     gc1 = XCreateGC(display,
25129                    win,
25130                    (GCForeground|GCBackground|GCArcMode),
25131                    &values);
25132 
25133     if ( (mfinfo = XLoadQueryFont(display,FONT))== NULL) {
25134        mfinfo = XQueryFont(display,XGContextFromGC(gc));}
25135     else {
25136 
25137        XSetFont(display,gc,mfinfo->fid);
25138     }
25139 
25140     labinfo = XLoadQueryFont(display,LFONT);
25141     slabinfo = XLoadQueryFont(display,SFONT);
25142     if (slabinfo == NULL) {
25143 	gc1 = gc;
25144     } else {
25145 	XSetFont(display,gc1,slabinfo->fid);
25146     }
25147 
25148 
25149     if (Arg1 >= 0.0) coloff = Arg1;
25150 
25151     def_colors();			/* define colors	*/
25152 
25153     *inct = colcells;
25154 
25155     stipple = XCreateBitmapFromData(display, win, stipple_bits, stipple_width,
25156                                         stipple_height);
25157 
25158     qwgrey = XCreateBitmapFromData(display, win, qwgrey_bits, qwgrey_width,
25159                                         qwgrey_height);
25160     tqwgrey = XCreateBitmapFromData(display, win, tqwgrey_bits, tqwgrey_width,
25161                                         tqwgrey_height);
25162 
25163     grayStip = XCreatePixmapFromBitmapData(display, win, gray50_bits,
25164              gray50_width, gray50_height, 1, 0, 1);
25165 
25166     molPix     = XCreateBitmapFromData(display, win,
25167                 mol_bits, mol_width, mol_height);
25168     upPix      = XCreateBitmapFromData(display, win,
25169                 up_bits, up_width, up_height);
25170     downPix    = XCreateBitmapFromData(display, win,
25171                 down_bits, down_width, down_height);
25172     lPix       = XCreateBitmapFromData(display, win,
25173                 l_bits, l_width, l_height);
25174     rPix       = XCreateBitmapFromData(display, win,
25175                 r_bits, r_width, r_height);
25176     ballPix    = XCreateBitmapFromData(display, win,
25177                 ball_bits, ball_width, ball_height);
25178     HourPix    = XCreateBitmapFromData(display, win,
25179                 hourglass_bits, hourglass_width, hourglass_height);
25180     gPix       = XCreateBitmapFromData(display, win,
25181                 g_bits, g_width, g_height);
25182     SkullPix   = XCreateBitmapFromData(display, win,
25183                 skull_bits, skull_width, skull_height);
25184     FFPix      = XCreateBitmapFromData(display, win,
25185                 ff_bits, ff_width, ff_height);
25186     MLFPix     = XCreateBitmapFromData(display, win,
25187                 mlf_bits, mlf_width, mlf_height);
25188     HPix       = XCreateBitmapFromData(display, win,
25189                 hbit_bits, hbit_width, hbit_height);
25190     VRMLPix    = XCreateBitmapFromData(display, win,
25191                 vrml_bits, vrml_width, vrml_height);
25192     AlignPix   = XCreateBitmapFromData(display, win,
25193                 align_bits, align_width, align_height);
25194     OrigPix    = XCreateBitmapFromData(display, win,
25195                 orig_bits, orig_width, orig_height);
25196     CellPix    = XCreateBitmapFromData(display, win,
25197                 cell_bits, cell_width, cell_height);
25198     SurfPix    = XCreateBitmapFromData(display, win,
25199                 surf_bits, surf_width, surf_height);
25200     FotoPix    = XCreateBitmapFromData(display, win,
25201                 foto_bits, foto_width, foto_height);
25202     movPix    = XCreateBitmapFromData(display, win,
25203                 film_bits, film_width, film_height);
25204     ColPix     = XCreateBitmapFromData(display, win,
25205                 palette_bits, palette_width, palette_height);
25206     slowPix    = XCreateBitmapFromData(display, win,
25207                 slow_bits, pace_width, pace_height);
25208     fastPix    = XCreateBitmapFromData(display, win,
25209                 fast_bits, pace_width, pace_height);
25210     blastPix   = XCreateBitmapFromData(display, win,
25211                 blast_bits, pace_width, pace_height);
25212     BigPix     = XCreateBitmapFromData(display, win,
25213                 bigsmall_bits, bigsmall_width, bigsmall_height);
25214     OGLPix     = XCreateBitmapFromData(display, win,
25215                 ogl_bits, ogl_width, ogl_height);
25216     stopPix     = XCreateBitmapFromData(display, win,
25217                 stop_bits, stop_width, stop_height);
25218     mapPix    = XCreateBitmapFromData(display, win,
25219                 map_bits, map_width, map_height);
25220 
25221 #ifdef DOBACK
25222 #ifdef VMS
25223     molback = XCreatePixmap(display, win,Mwidth,Mheight,
25224         DefaultDepth(display,screen));
25225 #else
25226     if (has_opengl) {
25227         if (( molback = XCreatePixmap(display, win,Mwidth,Mheight,
25228             vi->depth)) == (Pixmap) NULL )
25229         {
25230             fprintf( stderr, "Molden: cannot create pixmap \n");
25231         }
25232         if (( bckwin = XCreatePixmap(display, win,BckW,BckH,
25233             vi->depth)) == (Pixmap) NULL )
25234         {
25235             fprintf( stderr, "Molden: cannot create pixmap \n");
25236         }
25237         if (( colmap = XCreatePixmap(display, win,256,1,
25238             vi->depth)) == (Pixmap) NULL )
25239         {
25240             fprintf( stderr, "Molden: cannot create pixmap \n");
25241         }
25242     } else {
25243 	if (( molback = XCreatePixmap(display, win,Mwidth,Mheight,
25244 	    DefaultDepth(display,screen))) == (Pixmap) NULL )
25245         {
25246             fprintf( stderr, "Molden: cannot create pixmap \n");
25247         }
25248         if (( bckwin = XCreatePixmap(display, win,BckW,BckH,
25249 	    DefaultDepth(display,screen))) == (Pixmap) NULL )
25250         {
25251             fprintf( stderr, "Molden: cannot create pixmap \n");
25252         }
25253         if (( colmap = XCreatePixmap(display, win,256,1,
25254 	    DefaultDepth(display,screen))) == (Pixmap) NULL )
25255         {
25256             fprintf( stderr, "Molden: cannot create pixmap \n");
25257         }
25258     }
25259     FakeCMap();
25260 #endif
25261 #else
25262     molback = NULL;
25263 #endif
25264 
25265 
25266     if ( molback ) {
25267         molcur = molback;
25268     }
25269     else {
25270         molcur = win;
25271     }
25272 
25273     XSetStipple(display,gc,stipple);
25274 
25275 
25276     ZoomCursor = XCreateFontCursor(display, 120);
25277     AtomCursor = XCreateFontCursor(display, 40);
25278     WaitCursor = XCreateFontCursor(display, XC_watch);
25279 
25280     for (i=0; i<MAXAT; i++) {
25281 	IANZboxes[i].win = (Window) NULL;
25282 	BLboxes[i].win = (Window) NULL;
25283 	ALPHboxes[i].win = (Window) NULL;
25284 	BETboxes[i].win = (Window) NULL;
25285         for (j=0; j<4; j++)
25286 	   IZboxes[i][j].win = (Window) NULL;
25287     }
25288 
25289     XMapWindow(display, win);
25290 
25291 /* use event to display window! since event loop is in the FORTRAN code
25292    we have to fudge the X to do anything */
25293 
25294     XCheckTypedWindowEvent(display,
25295                            win,
25296                            ExposureMask,
25297                            &report) ;
25298 
25299 
25300     done = 0;
25301 
25302     while (!done) {
25303 
25304         XNextEvent(display, &event);
25305         switch (event.type) {
25306               case MapNotify: {
25307                                  done = 1;
25308               }
25309         break;
25310 
25311         default: break;
25312         }
25313     }
25314 
25315     XGetWindowAttributes(display, win, &xwa);
25316 
25317     if ( (xwa.width  != width ) || (xwa.height != height) )
25318        {
25319             width  = xwa.width;
25320             height = xwa.height;
25321        }
25322 
25323     XCheckTypedWindowEvent(display,
25324                            win,
25325                            ExposureMask,
25326                            &report) ;
25327 
25328     initnthe();
25329 
25330 #ifdef DOGL
25331     if (has_opengl) {
25332        if (strstr(ServerVendor(display),"StarNet") && !(*istaro))
25333 	   *fullgl = 1;
25334        if (*fullgl) *ifogl = 1;
25335        glXMakeCurrent(display,win,cx);
25336        Reshape(0);
25337        const GLubyte *glExtensions =
25338 		(const GLubyte *) glGetString(GL_EXTENSIONS);
25339        if (strstr(((const char *) glGetString(GL_VENDOR)),"Tungsten"))
25340 		DoMIPMAP = 0;
25341        if (strstr(((const char *) glGetString(GL_VENDOR)),"Intel"))
25342 		DoIntel = 1;
25343 
25344 #ifdef GL_ARB_shader_objects
25345        if (! *noshad) {
25346 	if (*doshad) has_shader = check_shader((const char *) glExtensions);
25347        }
25348 #endif
25349 #ifdef GL_COLOR_ATTACHMENT0_EXT
25350        if (! *noshad) {
25351 	   has_fbo = init_fbo(&fbo,fbo_type,(const char *) glExtensions);
25352 	   if (!has_fbo) {
25353 	      fbo_type = 4;
25354 	      has_fbo = init_fbo(&fbo,fbo_type,(const char *) glExtensions);
25355 	   }
25356        }
25357 #endif
25358        glClear(GL_COLOR_BUFFER_BIT);
25359        makeRasterFont(display);
25360        initOpengl();
25361        initthe();
25362        ogelem();
25363     }
25364 #else
25365     *fullgl = 0;
25366 #endif
25367 
25368     CreatewinC(DEFWINCGEOM);
25369     XSelectInput(display, winC,
25370 		SubstructureNotifyMask | ExposureMask |
25371 		ButtonPressMask | KeyPressMask | PointerMotionMask |
25372 		PointerMotionMask | EnterWindowMask | LeaveWindowMask |
25373 		EnterWindowMask);
25374     CreatewinMC(DEFWINMCGEOM);
25375     XSelectInput(display, winMC,
25376 		StructureNotifyMask | SubstructureNotifyMask |ExposureMask |
25377                 ButtonPressMask | ButtonReleaseMask |
25378 		KeyPressMask | PointerMotionMask |
25379 		EnterWindowMask | LeaveWindowMask | EnterWindowMask);
25380     DowinC = 1;
25381     DowinMC = 1;
25382     DoactC = 1;
25383     DoactMC = 1;
25384 
25385 
25386     RESwin  = CreateWindow("Molden Query Box","-10-10",QBOXWIDE,QBOXTX+20,
25387                             infobg,infofg,(Window)0);
25388     XSelectInput(display, RESwin, ExposureMask | KeyPressMask | EnterWindowMask);
25389 
25390     WinObj[10].win = &RESwin;
25391     WinObj[10].subwin = NULL;
25392     WinObj[10].butarr = NULL;
25393     WinObj[10].numbut = -1;
25394     WinObj[10].winup = &qbres;
25395     WinObj[10].init = NULL;
25396     WinObj[10].redraw = RedrawRESwin;
25397 
25398     COMMwin = CreateWindow("Molden Query Box",DEFQBOXGEOM,QBOXWIDE,QBOXTX,
25399                             infobg,infofg,(Window)0);
25400     XSelectInput(display, COMMwin, ExposureMask | KeyPressMask | EnterWindowMask);
25401 
25402     WinObj[11].win = &COMMwin;
25403     WinObj[11].subwin = NULL;
25404     WinObj[11].butarr = NULL;
25405     WinObj[11].numbut = -1;
25406     WinObj[11].winup = &qbcomm;
25407     WinObj[11].init = NULL;
25408     WinObj[11].redraw = RedrawCOMMwin;
25409 
25410     gsel.parse = 0;
25411     gsel.inct = 280;
25412 #ifdef VMS
25413     strcpy(gsel.lastdir,"[]");
25414 #else
25415     strcpy(gsel.lastdir,"./");
25416 #endif
25417     strcpy(gsel.label,"Grid file:");
25418     gsel.pntr = gfile;
25419 
25420     FileSelect(&gsel);
25421 
25422     dsel.parse = 0;
25423     dsel.inct = 280;
25424 #ifdef VMS
25425     strcpy(dsel.lastdir,"[]");
25426 #else
25427     strcpy(dsel.lastdir,"./");
25428 #endif
25429     strcpy(dsel.label,"XYZ file:");
25430     dsel.pntr = gfile;
25431 
25432     FileSelect(&dsel);
25433 
25434     fsel.parse = 1;
25435     fsel.inct = 480;
25436 #ifdef VMS
25437     strcpy(fsel.lastdir,"[]");
25438 #else
25439     strcpy(fsel.lastdir,"./");
25440 #endif
25441 
25442     FileSelect(&fsel);
25443 
25444     ZMEwin = CreateWindow("Zmatrix Editor","-0+0",ZMEWINW,ZMEWINH,infobg,infofg,(Window)0);
25445     XSelectInput(display, ZMEwin,
25446 		SubstructureNotifyMask | ExposureMask | KeyPressMask |
25447 		ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
25448 		LeaveWindowMask | PointerMotionMask | EnterWindowMask);
25449     subZM = CreateWindow("Subwindow","",10,10,
25450                             colors[0],colors[15],ZMEwin);
25451 
25452     WinObj[16].win = &ZMEwin;
25453     WinObj[16].subwin = &subZM;
25454     WinObj[16].butarr = ZMEbut;
25455     WinObj[16].numbut = ZMEBUTTS;
25456     WinObj[16].winup = &ZMEup;
25457     WinObj[16].init = InitZME;
25458     WinObj[16].redraw = RedrawZME;
25459 
25460     DISTwin = CreateWindow("Molden Calculate","-20-80",
25461 	DBWIDE,DBHIGH+2*BUTTH, infobg,infofg,(Window)0);
25462 
25463     subDIST = CreateWindow("Subwindow","",10,10,
25464                             colors[0],colors[15],DISTwin);
25465 
25466     WinObj[12].win = &DISTwin;
25467     WinObj[12].subwin = &subDIST;
25468     WinObj[12].butarr = clbut;
25469     WinObj[12].numbut = NCLBUT;
25470     WinObj[12].winup = &distup;
25471     WinObj[12].init = NULL;
25472     WinObj[12].redraw = RedrawDIST;
25473 
25474     if (has_opengl) {
25475         if (( distpix = XCreatePixmap(display, DISTwin,DBWIDE,DBHIGH,
25476             vi->depth)) == (Pixmap) NULL )
25477         {
25478             fprintf( stderr, "Molden: cannot create pixmap \n");
25479         }
25480     } else {
25481 	if (( distpix = XCreatePixmap(display, DISTwin,DBWIDE,DBHIGH,
25482 	    DefaultDepth(display,screen))) == (Pixmap) NULL )
25483         {
25484             fprintf( stderr, "Molden: cannot create pixmap \n");
25485         }
25486     }
25487 
25488     XSelectInput(display, DISTwin, ExposureMask | ButtonPressMask
25489 	| SubstructureNotifyMask | PointerMotionMask
25490 	| EnterWindowMask | LeaveWindowMask | EnterWindowMask);
25491 
25492     DefBut(&clbut[BMONI], DISTwin, 0, DBHIGH , DBWIDE/4, BUTTH,
25493         	   "Monitor", infobg, 0);
25494     clbut[BMONI].explstr = "Update distance on screen\nwith each new structure";
25495 
25496     DefBut(&clbut[BCLR],  DISTwin, DBWIDE/4, DBHIGH , DBWIDE/2, BUTTH,
25497         	   "Clear Mon/Cont", infobg, 0);
25498     clbut[BCLR].explstr = "clear distance monitors,\nclosest contacts";
25499 
25500     DefBut(&clbut[BCNTCT],DISTwin, (3*DBWIDE)/4, DBHIGH , DBWIDE/4, BUTTH,
25501         	   "Contact", infobg, 0);
25502     clbut[BCNTCT].explstr = "show closest contacts\nof selected atom";
25503 
25504     DefBut(&clbut[BCLOSE],DISTwin, (3*DBWIDE)/4, DBHIGH+BUTTH , DBWIDE/4, BUTTH,
25505         	   "Close", infobg, 0);
25506     clbut[BCLOSE].explstr = "close the window";
25507 
25508     DefBut(&clbut[BCONN],DISTwin, 0, DBHIGH+BUTTH , (3*DBWIDE)/4, BUTTH,
25509         	   "Connect/DISconnect", infobg, 0);
25510     clbut[BCONN].explstr = "(dis)connect atoms measured distance";
25511 
25512     return;
25513   } /* end OpenWindow */
25514   break;
25515 
25516   case MovePen :			/* move pen to x,y	*/
25517   {
25518     if ( count < MAXSAVE-1 ) {
25519        count++;
25520        savecom[count].evtype = Command;
25521        savecom[count].xxval = Arg1;
25522        savecom[count].yyval = Arg2;
25523     }
25524     movexy(Arg1,Arg2);
25525     return;
25526   } /* end MovePen */
25527   break;
25528 
25529   case DrawLine :
25530   {
25531     if ( count < MAXSAVE-1 ) {
25532        count++;
25533        savecom[count].evtype = Command;
25534        savecom[count].xxval = Arg1;
25535        savecom[count].yyval = Arg2;
25536     }
25537     drawxy(Arg1,Arg2);
25538     return;
25539   } /* end DrawLine */
25540   break;
25541 
25542   case DrawString :
25543   {
25544     if ( count < MAXSAVE-1 ) {
25545        count++;
25546        savecom[count].evtype = Command;
25547        savecom[count].xxval = Arg1;
25548        savecom[count].yyval = Arg2;
25549     }
25550     if ( scount < MXSAVESTR-1 ) {
25551        int ns;
25552        scount++;
25553        ns = *nstr;
25554        if (*nstr > 254 ) ns = 254;
25555        strcp(str,savestr[scount],ns);
25556        savestr[scount][ns] = '\0';
25557        nsavestr[scount] = ns;
25558     }
25559     drawstring(Arg1,Arg2,&savestr[scount][0],nsavestr[scount]);
25560     return;
25561   } /* end DrawString */
25562   break;
25563 
25564   case 5 :			/* do nothing		*/
25565   {
25566     return;
25567   }
25568   break;
25569 
25570   case ClearScreen :
25571   {
25572     doclr();
25573     return;
25574   } /* end ClearScreen */
25575   break;
25576 
25577   case SolidLine :
25578   {
25579     if ( count < MAXSAVE-1 ) {
25580        count++;
25581        savecom[count].evtype = Command;
25582     }
25583 #if defined(VMS) || defined(UNDERSC)
25584     sollin();
25585 #else
25586 #ifdef CRAY
25587     SOLLIN();
25588 #else
25589     sollin_();
25590 #endif
25591 #endif
25592     return;
25593   } /* end SolidLine */
25594   break;
25595 
25596   case DashedLine :
25597   {
25598     if ( count < MAXSAVE-1 ) {
25599        count++;
25600        savecom[count].evtype = Command;
25601     }
25602     dashline();
25603     return;
25604   } /* end DashedLine */
25605   break;
25606 
25607   case LineWidth :
25608   {
25609     if ( count < MAXSAVE-1 ) {
25610        count++;
25611        savecom[count].evtype = Command;
25612        savecom[count].xxval = Arg1;
25613     }
25614 #if defined(VMS) || defined(UNDERSC)
25615     cwidth(&Arg1);
25616 #else
25617 #ifdef CRAY
25618     CWIDTH(&Arg1);
25619 #else
25620     cwidth_(&Arg1);
25621 #endif
25622 #endif
25623 
25624     return;
25625   } /* end LineWidth */
25626   break;
25627 
25628   case ParseNorbs:
25629   {
25630     norbs = *inct;
25631     return;
25632   }
25633   break;
25634 
25635   case ChangeColor :
25636   {
25637     if ( count < MAXSAVE-1 ) {
25638        count++;
25639        savecom[count].evtype = Command;
25640        savecom[count].xxval = Arg1;
25641     }
25642     changepen(Arg1);
25643     return;
25644   } /* end ChangeColor */
25645   break;
25646 
25647   default:
25648   {
25649     fprintf(stderr,"ERROR in Command= %d", Command);
25650     return;
25651   }
25652   break;
25653 
25654  } /* end main command switch */
25655     exit(-1);
25656 
25657 }
25658 
25659 static char *name[] =				/* colors here	*/
25660 	{"Black", "#FF1010", "goldenrod1", "Green", "Aquamarine", "#80FFFF", "Gold",
25661          "LightBlue", "Grey", "Magenta", "Lime Green", "Wheat",
25662          "Orange", "#0000E0", "Chocolate", "White"};
25663 
25664 static char *nameback[] =				/* colors here	*/
25665 	{"#000000","#FF1010","#FF9F09","#00FF00","#7FFFD4","#80FFFF",
25666 	 "#FFBF00","#84C1D6","#9B9B9B","#FF00FF","#10B010","#EFCA8C",
25667          "#FF7A00","#0000E0","#B83806","#FFFFFF"};
25668 
25669 
ParseBasicColor(activecolor,docmap)25670 void ParseBasicColor(activecolor,docmap)
25671 int activecolor;
25672 int docmap;
25673 {
25674   XColor exact_def;
25675   float rslice,gslice,bslice;
25676   int i;
25677 
25678    rslice = colorr[activecolor]*(1.0-coloff) / 10.0;
25679    gslice = colorg[activecolor]*(1.0-coloff) / 10.0;
25680    bslice = colorb[activecolor]*(1.0-coloff) / 10.0;
25681 
25682    if (!docmap) XFreeColors(display, cmap,&colors[16+(activecolor-1)*10],10,0);
25683 
25684    for (i = 1; i < 11; i++ ) {
25685 	exact_def.red = colorr[activecolor]*coloff + i * rslice;
25686 	exact_def.green = colorg[activecolor]*coloff + i * gslice;
25687 	exact_def.blue = colorb[activecolor]*coloff + i * bslice;
25688 
25689 	if ( !XAllocColor(display, cmap, &exact_def) ) {
25690 	   if (docmap) {
25691              cmap =  XCopyColormapAndFree(display,cmap);
25692              XSetWindowColormap(display,win,cmap);
25693              setcmap = 1;
25694 	     i--;
25695 	   }
25696 	} else {
25697 	   colors[15+(activecolor-1)*10+i] = exact_def.pixel;
25698 	}
25699 
25700    }
25701 }
25702 
ParseMapColors(docmap)25703 void ParseMapColors(docmap)
25704 int docmap;
25705 {
25706   XColor exact_def;
25707   int i;
25708 
25709    if (!docmap) XFreeColors(display, cmap,mappedcols,5,0);
25710 
25711    for (i = 0; i < 5; i++ ) {
25712 	exact_def.red   = (int )(mapcol[i].r)*65535;
25713 	exact_def.green = (int )(mapcol[i].g)*65535;
25714 	exact_def.blue  = (int )(mapcol[i].b)*65535;
25715 
25716 	if ( !XAllocColor(display, cmap, &exact_def) ) {
25717 	   if (docmap) {
25718              cmap =  XCopyColormapAndFree(display,cmap);
25719              XSetWindowColormap(display,win,cmap);
25720              setcmap = 1;
25721 	     i--;
25722 	   }
25723 	} else {
25724 	   mappedcols[i] = exact_def.pixel;
25725 	}
25726 
25727    }
25728 }
25729 
def_col16(colnam)25730 void def_col16(colnam)
25731 char **colnam;
25732 {
25733   int i;
25734   XColor exact_def;
25735 
25736     for (i = 0; i < 16; i++ ) {
25737 
25738       if ( !XParseColor(display, cmap, colnam[i], &exact_def) ) {
25739 	if ( !XParseColor(display, cmap, nameback[i], &exact_def) ) {
25740            fprintf( stderr, "Xwin: color %s not in database\n", nameback[i]);
25741            exit(-1);
25742 	}
25743       }
25744 
25745       if ( !XAllocColor(display, cmap, &exact_def) ) {
25746        cmap = XCopyColormapAndFree(display,cmap);
25747        XSetWindowColormap(display,win,cmap);
25748        setcmap = 1;
25749        i--;
25750       } else {
25751 	colors[i] = exact_def.pixel;
25752 	colorr[i] = exact_def.red;
25753 	colorg[i] = exact_def.green;
25754 	colorb[i] = exact_def.blue;
25755       }
25756 
25757     }
25758 }
25759 
ResetColors()25760 void ResetColors()
25761 {
25762    int j;
25763 
25764    XFreeColors(display, cmap,&colors[0],16,0);
25765    def_col16(name);
25766    for (j = 1; j < 16; j++ ) ParseBasicColor(j,0);
25767 #if defined(VMS) || defined(UNDERSC)
25768    wrtres();
25769 #else
25770 #ifdef CRAY
25771    WRTRES();
25772 #else
25773    wrtres_();
25774 #endif
25775 #endif
25776 }
25777 
def_colors()25778 void def_colors()
25779 {
25780   int depth;
25781   int ncells;
25782   XColor exact_def;
25783   int i,j;
25784   static char **colnam;
25785 
25786 /* #80ffff used to be Cyan */
25787 
25788 
25789   static char *shcol[SHCOLNUM][3] =
25790 	{{"#729FFF","#C4D7FF","#3E578C"},
25791 	 {"#A59F80","#DAD7CA","#5B5746"},
25792 	 {"#FFC494","#CC9D76","#8C6C51"},
25793 	 {"#F74F41","#FCB0AA","#802921"},
25794 	 {"#FFBF00","#FFE69C","#916D00"},
25795 	 {"#5F985F","#B6D0B6","#314F31"},
25796 	 {"#56B2F7","#B8DFFC","#2F6288"}
25797   };
25798 /*         medium   light    dark */
25799 
25800   if (NColNam == 16) colnam = ColNam;
25801   else colnam = name;
25802 
25803   depth  = DisplayPlanes(display, screen);
25804   ncells = DisplayCells(display, screen);
25805 
25806   if (depth >= 8) ncells = 256;
25807 
25808   if (!has_opengl) cmap   = DefaultColormap(display, screen);
25809 
25810   if ( ncells <= 2 )		/* mono screen	*/
25811   {
25812     colcells = 2;
25813     monoscr = 1;
25814     colors[0] = BlackPixel(display, screen);
25815     for ( i = 1; i < MAX_COLORS; i++ )
25816     {
25817        colors[i] = WhitePixel(display, screen);
25818     }
25819   }
25820 
25821   else
25822   {
25823     def_col16(colnam);
25824 
25825     if ( ncells >= 256 )
25826     {
25827        colcells = 256;
25828        for (j = 1; j < 16; j++ ) ParseBasicColor(j,1);
25829        for (j = 0; j < SHCOLNUM; j++ )
25830        for (i = 0; i < 3; i++ ) {
25831 		XParseColor(display, cmap, shcol[j][i], &exact_def);
25832 		if ( !XAllocColor(display, cmap, &exact_def) ) {
25833 		  cmap =  XCopyColormapAndFree(display,cmap);
25834 		  XSetWindowColormap(display,win,cmap);
25835 		  setcmap = 1;
25836 		  XAllocColor(display, cmap, &exact_def);
25837 		}
25838 		colors[190+3*j+i] = exact_def.pixel;
25839        }
25840 #ifdef DOGL
25841        ParseMapColors(1);
25842 #endif
25843     }
25844     else if ( ncells >= 32 )
25845     {
25846        colcells = 32;
25847        for (i = 1; i < 11; i++ )
25848        {
25849          exact_def.red = i * 6553;
25850          exact_def.green = i * 4250;
25851          exact_def.blue = 0;
25852 
25853          if ( !XAllocColor(display, cmap, &exact_def) )
25854          {
25855            cmap = XCopyColormapAndFree(display,cmap);
25856            XSetWindowColormap(display,win,cmap);
25857            setcmap = 1;
25858 /*           fprintf(stderr,"Xwin: all colorcells allocated, read/write\n");
25859            exit(-1);*/
25860          }
25861 
25862          colors[125+i] = exact_def.pixel;
25863        }
25864     }
25865 
25866   }
25867 
25868 
25869   if (monoscr || colcells <= 32) {
25870      infofg = WhitePixel(display,screen);
25871      infobg = BlackPixel(display,screen);
25872      White = WhitePixel(display,screen);
25873      Black = BlackPixel(display,screen); }
25874   else {
25875      infofg = colors[15];
25876      infobg = colors[0];
25877      White = WhitePixel(display,screen);
25878      Black = BlackPixel(display,screen);
25879   }
25880   if (*ibgcol) IBGcolor = *ibgcol;
25881   if (*ibgclo) OBGcolor = *ibgclo;
25882   if (*ibgmod) BGmode = *ibgmod;
25883 }
25884 
FakeCMap()25885 void FakeCMap()
25886 {
25887    int i;
25888    unsigned long pixl;
25889    XImage *img;
25890 
25891    for (i=0; i<256; i++) {
25892 	XSetForeground(display,gc,colors[i]);
25893 	XDrawPoint(display,colmap,gc,i,0);
25894    }
25895    img = XGetImage(display,colmap,0,0,256,1,AllPlanes,ZPixmap);
25896    for (i=0; i<256; i++) {
25897 	pixl = XGetPixel(img,i,0);
25898 	colors[i] = pixl;
25899    }
25900    XDestroyImage(img);
25901 }
25902 
25903 static int isdraw = 0;
25904 
movexy(float xval,float yval)25905 void movexy(float xval,float yval)
25906 {
25907 #ifdef DOGL
25908   gstart_xlx = (xval-xoff)*scale*2.0 - 1.0;
25909   gstart_yly = (yval-yoff)*scale*2.0 - 1.0;
25910 
25911   if (*fullgl && !*ifdogl) {
25912 	if (isdraw) glEnd();
25913 	isdraw = 1;
25914 	glBegin(GL_LINES);
25915   }
25916 #endif
25917 
25918   start_xlx = (xval-xoff) * height * scale;
25919   start_yly = (1.0- yval -yoff) * height * scale;
25920 }
25921 
drawxy(float xval,float yval)25922 void drawxy(float xval,float yval)
25923 {
25924   xlx = (xval-xoff) * height * scale;
25925   yly = (1.0 - yval - yoff) * height * scale;
25926 
25927 #ifdef DOGL
25928 
25929   gxlx = (xval-xoff)*scale*2.0 - 1.0;
25930   gyly = (yval-yoff)*scale*2.0 - 1.0;
25931 
25932   if (*fullgl && !*ifdogl) {
25933 	if (isdraw) {
25934 	   glVertex2f(gstart_xlx, gstart_yly);
25935 	   glVertex2f(gxlx,gyly);
25936 /*
25937 fprintf(stderr,"gstart_xlx %f gstart_yly %f\n",gstart_xlx,gstart_yly);
25938 fprintf(stderr,"gxlx %f gyly %f\n",gxlx,gyly);
25939 */
25940 	}
25941 	gstart_xlx = gxlx;
25942 	gstart_yly = gyly;
25943   } else {
25944 #endif
25945 	XDrawLine(display, molcur, gc, xlx, yly, start_xlx, start_yly);
25946 #ifdef DOGL
25947   }
25948 #endif
25949 
25950   start_xlx = xlx;
25951   start_yly = yly;
25952 
25953 }
25954 
drawstring(float xval,float yval,char * strval,int nval)25955 void drawstring(float xval,float yval,char *strval,int nval)
25956 {
25957   xlx = (xval-xoff) * height * scale;
25958   yly = (1.0 - yval -yoff) * height * scale;
25959 #ifdef DOGL
25960 /*
25961   if (*fullgl && !*ifdogl) {
25962 	gxlx = (xval-xoff)*scale*2.0 -1.0;
25963 	gyly = (yval-yoff)*scale*2.0 -1.0;
25964 	if (isdraw) {
25965 	   glEnd();
25966 	   isdraw = 0;
25967         }
25968 #if defined(VMS) || defined(UNDERSC)
25969 	drwstr(&gxlx,&gyly,strval,&nval,&MONE);
25970 #else
25971 #ifdef CRAY
25972 	DRWSTR(&gxlx,&gyly,strval,&nval,&MONE);
25973 #else
25974 	drwstr_(&gxlx,&gyly,strval,&nval,&MONE);
25975 #endif
25976 #endif
25977   } else {
25978 */
25979 #endif
25980 	XDrawString(display, molcur, gc, xlx, yly, strval, nval);
25981 #ifdef DOGL
25982 /*
25983   }
25984 */
25985 #endif
25986 
25987 }
25988 
25989 #if defined(VMS) || defined(UNDERSC)
sollin()25990 void sollin()
25991 #else
25992 #ifdef CRAY
25993 void SOLLIN()
25994 #else
25995 void sollin_()
25996 #endif
25997 #endif
25998 
25999 {
26000    if (!xison) return;
26001 
26002    isdash = 0;
26003    XSetLineAttributes(display, gc, linwid, LineSolid, CapButt, JoinMiter);
26004 
26005 }
26006 
dashline()26007 void dashline()
26008 {
26009    isdash = 1;
26010    if ( monoscr ) {
26011         XSetBackground(display, gc, BlackPixel(display,screen));
26012         XSetLineAttributes(display, gc, linwid, LineDoubleDash,
26013                                       CapButt, JoinMiter);
26014    }
26015 }
26016 
26017 #if defined(VMS) || defined(UNDERSC)
dash(on)26018 void dash(on)
26019 #else
26020 #ifdef CRAY
26021 void DASH(on)
26022 #else
26023 void dash_(on)
26024 #endif
26025 #endif
26026 int *on;
26027 {
26028    if (!xison) return;
26029    if (*on) XSetLineAttributes(display, gc, linwid, LineOnOffDash,
26030                                CapButt, JoinMiter);
26031    else XSetLineAttributes(display, gc, linwid, LineSolid,
26032                                CapButt, JoinMiter);
26033 }
26034 
26035 #if defined(VMS) || defined(UNDERSC)
cwidth(linpass)26036 void cwidth(linpass)
26037 #else
26038 #ifdef CRAY
26039 void CWIDTH(linpass)
26040 #else
26041 void cwidth_(linpass)
26042 #endif
26043 #endif
26044 
26045 float *linpass;
26046 {
26047   linwid = (int) *linpass;
26048   if (linwid > linmax) linwid = linmax;
26049 #ifdef DOGL
26050   if (*fullgl && !*ifdogl) {
26051 	if (isdraw) {
26052 	   glEnd();
26053 	   isdraw = 0;
26054         }
26055 	glLineWidth(*linpass);
26056    }
26057 #endif
26058 }
26059 
changepen(float pen)26060 void changepen(float pen)
26061 {
26062   foreground_pixel = colors[(int)pen];
26063 
26064 #ifdef DOGL
26065   if (*fullgl && !*ifdogl) {
26066 	if (isdraw) {
26067 	   glEnd();
26068 	   isdraw = 0;
26069         }
26070 	glColor3f(((GLfloat) colorr[(int) pen]) / 65535.0,
26071 		  ((GLfloat) colorg[(int) pen]) / 65535.0,
26072 		  ((GLfloat) colorb[(int) pen]) / 65535.0);
26073   } else {
26074 #endif
26075 	XSetForeground(display, gc, foreground_pixel);
26076 #ifdef DOGL
26077   }
26078 #endif
26079 
26080 }
26081 
26082 #if defined(VMS) || defined(UNDERSC)
setcol(pen)26083 void setcol(pen)
26084 #else
26085 #ifdef CRAY
26086 void SETCOL(pen)
26087 #else
26088 void setcol_(pen)
26089 #endif
26090 #endif
26091 int *pen;
26092 {
26093 unsigned long f_pixel;
26094 
26095   if (!xison) return;
26096 
26097   if (*pen < MAX_COLORS && *pen >= 0) {
26098 	f_pixel = colors[*pen];
26099 	XSetForeground(display, gc, f_pixel);
26100   }
26101 
26102 }
26103 
CheckForConfig()26104 static int CheckForConfig()
26105 {
26106   XEvent ev;
26107   char   foo;
26108 
26109   /* returns true if there's a config event in which mainW changes size
26110      in the event queue */
26111 
26112   foo = 0;
26113   XCheckIfEvent(display, &ev, IsConfig, &foo);
26114   return foo;
26115 }
26116 
IsConfig(dpy,ev,arg)26117 static Bool IsConfig(dpy, ev, arg)
26118 Display *dpy;
26119 XEvent  *ev;
26120 char    *arg;
26121 {
26122   XConfigureEvent *cev;
26123 
26124   if (ev->type == ConfigureNotify) {
26125     cev = (XConfigureEvent *) ev;
26126     if (cev->window == win && (cev->width != width || cev->height != height))
26127       *arg = 1;
26128   }
26129   return False;
26130 }
26131 
26132 static int v2d;
26133 
gl2DInit()26134 void gl2DInit()
26135 {
26136 
26137 #ifdef DOGL
26138     if (*fullgl && !*ifdogl && !isgl2D) {
26139 	v2d = width;
26140 	if (v2d > height) v2d = height;
26141 	glViewport(0,0,v2d,v2d);
26142         glXMakeCurrent(display,win,cx);
26143 	glClearColor(0.0,0.0,0.0,1.0);
26144 	glDisable(GL_LIGHTING);
26145 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
26146 	glLineWidth(1.0);
26147 	glMatrixMode (GL_MODELVIEW);
26148 	glLoadIdentity ();
26149 	glMatrixMode (GL_PROJECTION);
26150 	glLoadIdentity ();
26151 	gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
26152         glEnable(GL_COLOR_MATERIAL);
26153 	glRasterPos2f(-1.0,-1.0);
26154 	isdraw = 0;
26155 	isgl2D = 1;
26156 	if (StarNet) {
26157 	   if (!glIsList(theDens)) {
26158 		theDens = glGenLists(1);
26159 		glNewList(theDens, GL_COMPILE_AND_EXECUTE);
26160 	   }
26161 	}
26162     }
26163 #endif
26164 }
26165 
gl2DEnd()26166 void gl2DEnd()
26167 {
26168 #ifdef DOGL
26169     if (*fullgl && !*ifdogl && isgl2D) {
26170 	glEnd();
26171         glXSwapBuffers(display, win);
26172 	if (StarNet) glDeleteLists(theDens,1);
26173         glDisable(GL_COLOR_MATERIAL);
26174         if (dogif && count > 0) {
26175            picnum++;
26176            if (picnum < *picmax) {
26177 		glXWaitGL();
26178 		sprintf(stemp, "%s%03d.gif",GifFile,picnum);
26179 		WOGLGIF(stemp);
26180 	   }
26181 	}
26182 	isgl2D = 0;
26183     }
26184 #endif
26185 }
26186 
RedrawWin()26187 void RedrawWin()
26188 {
26189      int cnt = 0;
26190      int i;
26191 
26192      if (count <= 0) return;
26193 
26194 #ifdef DOGL
26195      if (*fullgl) {
26196 	gl2DInit();
26197      } else {
26198 #endif
26199 	if ( molback ==  molcur ) {
26200 	  if (denmode) XSetForeground(display, gc, colors[0]);
26201 	  else XSetForeground(display, gc, colors[IBGcolor]);
26202           XFillRectangle(display,molcur,gc,0,0,width,height);
26203           XSetForeground(display, gc, WhitePixel(display,screen));
26204 	} else {
26205           XClearWindow(display,win);
26206 	}
26207 #ifdef DOGL
26208      }
26209 #endif
26210 
26211      for (i=1; i<=count; i++)
26212      {
26213        switch(savecom[i].evtype){
26214 
26215        case MovePen : {
26216           movexy(savecom[i].xxval,savecom[i].yyval);
26217           }
26218        break;
26219 
26220        case DrawLine : {
26221           drawxy(savecom[i].xxval,savecom[i].yyval);
26222           }
26223        break;
26224 
26225 
26226        case DrawString : {
26227           cnt++;
26228           drawstring(savecom[i].xxval,savecom[i].yyval,
26229                      &savestr[cnt][0],nsavestr[cnt]);
26230           }
26231        break;
26232 
26233 
26234        case SolidLine : {
26235 #if defined(VMS) || defined(UNDERSC)
26236           sollin();
26237 #else
26238 #ifdef CRAY
26239 	  SOLLIN();
26240 #else
26241 	  sollin_();
26242 #endif
26243 #endif
26244           }
26245        break;
26246 
26247        case DashedLine : {
26248           dashline();
26249           }
26250        break;
26251 
26252        case LineWidth : {
26253 #if defined(VMS) || defined(UNDERSC)
26254           cwidth(&savecom[i].xxval);
26255 #else
26256 #ifdef CRAY
26257           CWIDTH(&savecom[i].xxval);
26258 #else
26259           cwidth_(&savecom[i].xxval);
26260 #endif
26261 #endif
26262 
26263           }
26264        break;
26265 
26266        case ChangeColor : {
26267           changepen(savecom[i].xxval);
26268           }
26269        break;
26270 
26271        case FillPoly : {
26272 	  poldrw(savecom[i].points,&savecom[i].npoints,
26273 		&savecom[i].icol,&savecom[i].icon,&savecom[i].isgrey);
26274           }
26275        break;
26276        default: break;
26277        } /* end command switch */
26278      } /*end for */
26279 
26280 #ifdef DOGL
26281      if (*fullgl) {
26282 	gl2DEnd();
26283      } else {
26284 #endif
26285         if ( molback == molcur )
26286 		XCopyArea(display,molcur,win,gc,0,0,width,height,0,0);
26287 #ifdef DOGL
26288      }
26289 #endif
26290 
26291 } /* end ReDraw */
26292 
26293 #if defined(VMS) || defined(UNDERSC)
gethei(hei)26294 void gethei(hei)
26295 #else
26296 #ifdef CRAY
26297 void GETHEI(hei)
26298 #else
26299 void gethei_(hei)
26300 #endif
26301 #endif
26302 int *hei;
26303 {
26304   *hei = height;
26305   return;
26306 }
26307 
26308 #if defined(VMS) || defined(UNDERSC)
drawseg(segments,npoints,iinv)26309 void drawseg(segments,npoints,iinv)
26310 #else
26311 #ifdef CRAY
26312 void DRAWSEG(segments,npoints,iinv)
26313 #else
26314 void drawseg_(segments,npoints,iinv)
26315 #endif
26316 #endif
26317 
26318 XSegment *segments;
26319 int *npoints;
26320 int *iinv;
26321 {
26322   int con1,con2;
26323 
26324   if (!xison) return;
26325 
26326   if (*npoints == 1) {
26327      con1 = ((segments[0].x1 >= 0 && segments[0].y1 >= 0)  &&
26328              (segments[0].x1 <= (int) width && segments[0].y1 <= (int) height));
26329      con2 = ((segments[0].x2 >= 0 && segments[0].y2 >= 0)  &&
26330              (segments[0].x2 <= (int) width && segments[0].y2 <= (int) height));
26331      if (con1 || con2) {
26332 	if (monoscr && *iinv) XSetFunction(display,gc,GXxor);
26333 	XDrawSegments(display, molcur, gc, segments, *npoints);
26334 	if (monoscr && *iinv) XSetFunction(display,gc,GXcopy);
26335      }
26336      return;
26337   }
26338   if (monoscr && *iinv) XSetFunction(display,gc,GXxor);
26339   XDrawSegments(display, molcur, gc, segments, *npoints);
26340   if (monoscr && *iinv) XSetFunction(display,gc,GXcopy);
26341 
26342 }
26343 
26344 #if defined(VMS) || defined(UNDERSC)
drwseg(segments,npoints,iinv)26345 void drwseg(segments,npoints,iinv)
26346 #else
26347 #ifdef CRAY
26348 void DRWSEG(segments,npoints,iinv)
26349 #else
26350 void drwseg_(segments,npoints,iinv)
26351 #endif
26352 #endif
26353 
26354 XSegment *segments;
26355 int *npoints;
26356 int *iinv;
26357 {
26358   XDrawSegments(display, win, gc, segments, *npoints);
26359 
26360 }
26361 
26362 #if defined(VMS) || defined(UNDERSC)
drwpol(points,npoints,icol,icon,isgrey,rec)26363 void drwpol(points,npoints,icol,icon,isgrey,rec)
26364 #else
26365 #ifdef CRAY
26366 void DRWPOL(points,npoints,icol,icon,isgrey,rec)
26367 #else
26368 void drwpol_(points,npoints,icol,icon,isgrey,rec)
26369 #endif
26370 #endif
26371 
26372 XPoint *points;
26373 int *npoints;
26374 int *icol;
26375 int *icon;
26376 int *isgrey;
26377 int *rec;
26378 {
26379 /*  XPoint *tempp;*/
26380   int i;
26381 
26382   if (!xison) return;
26383 
26384   if (*rec) {
26385      if ( count < MAXSAVE-1 ) {
26386        count++;
26387        savecom[count].evtype = FillPoly;
26388        savecom[count].points = (XPoint *) malloc(sizeof(XPoint)*(*npoints));
26389 	for (i=0; i<*npoints; i++)  savecom[count].points[i] = points[i];
26390        savecom[count].npoints = *npoints;
26391        savecom[count].icol = *icol;
26392        savecom[count].icon = *icon;
26393        savecom[count].isgrey = *isgrey;
26394      }
26395   }
26396   XSetForeground(display, gc, colors[*icol]);
26397   if (*icon == 1) XFillPolygon(display,molcur,gc,points,*npoints,Convex,CoordModeOrigin);
26398   else {
26399 #if defined(VMS) || defined(UNDERSC)
26400         if (*isgrey == 1) ststip();
26401 #else
26402 #ifdef CRAY
26403         if (*isgrey == 1) STSTIP();
26404 #else
26405         if (*isgrey == 1) ststip_();
26406 #endif
26407 #endif
26408        XFillPolygon(display,molcur,gc,points,*npoints,Nonconvex,CoordModeOrigin);
26409 #if defined(VMS) || defined(UNDERSC)
26410         if (*isgrey == 1) unstip();
26411 #else
26412 #ifdef CRAY
26413         if (*isgrey == 1) UNSTIP();
26414 #else
26415         if (*isgrey == 1) unstip_();
26416 #endif
26417 #endif
26418   }
26419   if (colcells < 256 || (*icon == 0 && colcells >= 256) ) {
26420      if (monoscr) {
26421          XSetForeground(display, gc, colors[0]);
26422          if (isdash) XSetLineAttributes(display, gc, linwid, LineSolid, CapButt, JoinMiter);
26423      }
26424      else XSetForeground(display, gc, colors[2]);
26425      if (*icon == 0 && *isgrey == 1 && !monoscr) XSetForeground(display, gc, colors[1]);
26426      XDrawLines(display,molcur,gc,points,*npoints,CoordModeOrigin);
26427      if (monoscr && isdash) dashline();
26428 /*     tempp = points;
26429      XDrawSegments(display, molcur, gc, tempp, 1);
26430      tempp++;
26431      XDrawSegments(display, molcur, gc, tempp, 1);
26432      tempp++;
26433      XDrawSegments(display, molcur, gc, tempp, 1);*/
26434   }
26435 
26436 }
26437 
glpoly(points,npoints,icol)26438 void glpoly(points,npoints,icol)
26439 XPoint *points;
26440 int npoints;
26441 int icol;
26442 {
26443   int i;
26444 
26445 #ifdef DOGL
26446   GLfloat g0x, g0y, g1x, g1y, g2x, g2y;
26447 
26448      glDisable(GL_DEPTH_TEST);
26449      glDisable(GL_COLOR_MATERIAL);
26450 
26451      glColor3f(((GLfloat) colorr[icol]) / 65535.0,
26452 	  ((GLfloat) colorg[icol]) / 65535.0,
26453 	  ((GLfloat) colorb[icol]) / 65535.0);
26454 
26455      g0x = (((GLfloat) points[0].x/height) - xoff)*scale*2.0 - 1.0;
26456      g0y = (1.0 - ((GLfloat) points[0].y/height) - yoff)*scale*2.0 - 1.0;
26457 
26458      glBegin(GL_POLYGON);
26459 
26460      for (i=1; i<npoints-1; i++) {
26461 	g1x = (((GLfloat) points[i].x/height) - xoff)*scale*2.0 - 1.0;
26462 	g1y = (1.0 - ((GLfloat) points[i].y/height) - yoff)*scale*2.0 - 1.0;
26463 	g2x = (((GLfloat) points[i+1].x/height) - xoff)*scale*2.0 - 1.0;
26464 	g2y = (1.0 - ((GLfloat) points[i+1].y/height) - yoff)*scale*2.0 - 1.0;
26465 
26466 	glVertex2f(g0x,g0y);
26467 	glVertex2f(g1x,g1y);
26468 	glVertex2f(g2x,g2y);
26469      }
26470 
26471      glEnd();
26472 
26473 #endif
26474 
26475 }
26476 
poldrw(points,npoints,icol,icon,isgrey)26477 void poldrw(points,npoints,icol,icon,isgrey)
26478 XPoint *points;
26479 int *npoints;
26480 int *icol;
26481 int *icon;
26482 int *isgrey;
26483 {
26484   XPoint *tmppnts;
26485   int i;
26486 #ifdef DOGL
26487   GLfloat g0x, g0y, g1x, g1y, g2x, g2y;
26488 #endif
26489 
26490   if (!xison) return;
26491 
26492 #ifdef DOGL
26493 
26494   if (*fullgl && !*ifdogl) {
26495 
26496      if (isdraw) {
26497 	glEnd();
26498 	isdraw = 0;
26499      }
26500 
26501      glpoly(points,*npoints,*icol);
26502 
26503      glColor3f(((GLfloat) colorr[2]) / 65535.0,
26504 	  ((GLfloat) colorg[2]) / 65535.0,
26505 	  ((GLfloat) colorb[2]) / 65535.0);
26506 
26507      if (*icon == 0 && *isgrey == 1) {
26508         glColor3f(((GLfloat) colorr[1]) / 65535.0,
26509 	  ((GLfloat) colorg[1]) / 65535.0,
26510 	  ((GLfloat) colorb[1]) / 65535.0);
26511      }
26512 
26513      glBegin(GL_LINES);
26514      glLineWidth(3.0);
26515      for (i=0; i<*npoints; i++) {
26516 	g0x = (((GLfloat) points[i].x/height) - xoff)*scale*2.0 - 1.0;
26517 	g0y = (1.0 - ((GLfloat) points[i].y/height) - yoff)*scale*2.0 - 1.0;
26518 	glVertex2f(g0x,g0y);
26519      }
26520      glEnd();
26521   }
26522 
26523 
26524 
26525 #else
26526   tmppnts = (XPoint *) malloc(sizeof(XPoint)*(*npoints));
26527   for (i=0; i<*npoints; i++) {
26528       tmppnts[i].x = (short) (((float) points[i].x - xoff)*scale);
26529       tmppnts[i].y = (short) (((float) points[i].y - yoff)*scale);
26530   }
26531 
26532   XSetForeground(display, gc, colors[*icol]);
26533 
26534   if (*icon == 1)
26535 	XFillPolygon(display,molcur,gc,
26536 	tmppnts,*npoints,Convex,CoordModeOrigin);
26537   else {
26538 
26539 #if defined(VMS) || defined(UNDERSC)
26540         if (*isgrey == 1) ststip();
26541 #else
26542 #ifdef CRAY
26543         if (*isgrey == 1) STSTIP();
26544 #else
26545         if (*isgrey == 1) ststip_();
26546 #endif
26547 #endif
26548        XFillPolygon(display,molcur,gc,
26549 	tmppnts,*npoints,Nonconvex,CoordModeOrigin);
26550 
26551 #if defined(VMS) || defined(UNDERSC)
26552         if (*isgrey == 1) unstip();
26553 #else
26554 #ifdef CRAY
26555         if (*isgrey == 1) UNSTIP();
26556 #else
26557         if (*isgrey == 1) unstip_();
26558 #endif
26559 #endif
26560   }
26561 
26562   if (colcells < 256 || (*icon == 0 && colcells >= 256) ) {
26563      if (monoscr) {
26564          XSetForeground(display, gc, colors[0]);
26565          if (isdash) XSetLineAttributes(display, gc, linwid, LineSolid, CapButt, JoinMiter);
26566      }
26567      else XSetForeground(display, gc, colors[2]);
26568      if (*icon == 0 && *isgrey == 1 && !monoscr) XSetForeground(display, gc, colors[1]);
26569      XDrawLines(display,molcur,gc,tmppnts,*npoints,CoordModeOrigin);
26570      if (monoscr && isdash) dashline();
26571   }
26572 #endif
26573 
26574 }
26575 
26576 #if defined(VMS) || defined(UNDERSC)
plsph(xori,yori,fwidth,ia)26577 void plsph(xori,yori,fwidth,ia)
26578 #else
26579 #ifdef CRAY
26580 void PLSPH(xori,yori,fwidth,ia)
26581 #else
26582 void plsph_(xori,yori,fwidth,ia)
26583 #endif
26584 #endif
26585 
26586 int *xori;
26587 int *yori;
26588 int *fwidth;
26589 int *ia;
26590 {
26591   int xc,yc,xce,yce;
26592   unsigned int wi,hi,wi1;
26593 
26594   wi = (unsigned int) *fwidth;
26595   hi = wi;
26596 
26597   xc = *xori - wi/2;
26598   yc = *yori - hi/2;
26599   xce = *xori + wi/2;
26600   yce = *yori + hi/2;
26601 
26602   if (xce < 0 && yce < 0) return;
26603   if (xc > (int) width && yc > (int) height) return;
26604 
26605   XFillArc(display, molcur, gc, xc,yc, wi, hi, 0,360*64);
26606 
26607   XSetBackground(display, gc, BlackPixel(display,screen));
26608   XSetFillStyle(display,gc,FillOpaqueStippled);
26609   XSetStipple(display,gc,stipple);
26610   XFillArc(display, molcur, gc, xc,yc, wi, hi, 90*64,180*64);
26611 
26612   XSetFillStyle(display,gc,FillSolid);
26613   wi1 =  wi*0.50;
26614   XFillArc(display, molcur, gc, *xori - wi1/2,yc, wi1, hi, 0,360*64);
26615   if (*ia >= 2 && (ZMEup || cflag || ATMup || SelDel || ONIup || scoup)) {
26616      XSetForeground(display, gc, colors[rimcols[*ia]]);
26617      XDrawArc(display, molcur, gc, xc,yc, wi, hi, 0,360*64);
26618   }
26619 
26620 }
26621 
26622 #if defined(VMS) || defined(UNDERSC)
plsel(xori,yori,ia)26623 void plsel(xori,yori,ia)
26624 #else
26625 #ifdef CRAY
26626 void PLSEL(xori,yori,ia)
26627 #else
26628 void plsel_(xori,yori,ia)
26629 #endif
26630 #endif
26631 
26632 int *xori;
26633 int *yori;
26634 int *ia;
26635 {
26636   int xc,yc;
26637   unsigned int wi;
26638 
26639   wi = 20;
26640 
26641   xc = *xori - wi/2;
26642   yc = *yori - wi/2;
26643 
26644   if (*ia >= 2 && (ZMEup || cflag || ATMup || SelDel || ONIup || scoup)) {
26645      XSetForeground(display, gc, colors[rimcols[*ia]]);
26646      XFillArc(display, molcur, gc, xc,yc, wi, wi, 0,360*64);
26647   }
26648 
26649 }
26650 
26651 
26652 #if defined(VMS) || defined(UNDERSC)
ststip()26653 void ststip()
26654 #else
26655 #ifdef CRAY
26656 void STSTIP()
26657 #else
26658 void ststip_()
26659 #endif
26660 #endif
26661 {
26662   if (monoscr) {
26663      XSetFillStyle(display,gc,FillOpaqueStippled);
26664      XSetStipple(display,gc,stipple);
26665   }
26666 }
26667 
26668 
26669 #if defined(VMS) || defined(UNDERSC)
unstip()26670 void unstip()
26671 #else
26672 #ifdef CRAY
26673 void UNSTIP()
26674 #else
26675 void unstip_()
26676 #endif
26677 #endif
26678 {
26679   if (monoscr) {
26680      XSetFillStyle(display,gc,FillSolid);
26681   }
26682 }
26683 
26684 #if defined(VMS) || defined(UNDERSC)
doexp()26685 void doexp()
26686 #else
26687 #ifdef CRAY
26688 void DOEXP()
26689 #else
26690 void doexp_()
26691 #endif
26692 #endif
26693 {
26694      if (*doesp && !denmode) PlotColIndex();
26695 
26696      if ( molback == molcur ) {
26697           XCopyArea(display,molcur,win,gc,0,0,width,height,0,0);
26698      }
26699      if (dogif) {
26700         picnum++;
26701 	if (picnum < *picmax) {
26702 /*
26703 	    sprintf(stemp, "convert X:MOLDEN gif87:%s%d.gif",GifFile,picnum);
26704 	    system(stemp);
26705 */
26706 	   sprintf(stemp, "%s%03d.gif",GifFile,picnum);
26707 	   ToGIF(molcur,stemp);
26708 	}
26709      }
26710 }
26711 
doclr()26712 void doclr()
26713 {
26714 
26715     if (denmode && *ifdogl) return;
26716     if (!xison) return;
26717 
26718     if ( molback ==  molcur ) {
26719 
26720        if (denmode) XSetForeground(display, gc, colors[0]);
26721        else XSetForeground(display, gc, colors[IBGcolor]);
26722        XFillRectangle(display,molcur,gc,0,0,width,height);
26723        XSetForeground(display, gc, WhitePixel(display,screen));
26724 
26725     }
26726     else {
26727        XGetWindowAttributes(display, win, &xwa);
26728 
26729        if ( (xwa.width  != width ) || (xwa.height != height) )
26730        {
26731             width  = xwa.width;
26732             height = xwa.height;
26733        }
26734 
26735        XClearArea(display, win, 0,0,0,0,0);
26736     }
26737 }
26738 
26739 #if defined(VMS) || defined(UNDERSC)
dlogo()26740 void dlogo()
26741 #else
26742 #ifdef CRAY
26743 void DLOGO()
26744 #else
26745 void dlogo_()
26746 #endif
26747 #endif
26748 {
26749      XSetBackground(display, gc, infobg);
26750      XSetForeground(display, gc, infofg);
26751      XCopyPlane(display,molPix,molcur,gc,0,0,mol_width,mol_height,15,15,(unsigned long)1);
26752 }
26753 
26754 #define QPOSINT  1
26755 #define QPOSREAL 2
26756 #define QREAL    3
26757 #define QSTRING  0
26758 
TrmStr(qp)26759 void TrmStr(qp)
26760 QBOXSTRU        *qp;
26761 {
26762   int len,i,j;
26763 
26764   len = strlen(qp->str);
26765 
26766   j = len;
26767   for (i=len-1; i >= 0; i--) {
26768 	if (qp->str[i] != ' ') {
26769 	   j = i+1;
26770 	   break;
26771 	}
26772   }
26773 
26774   len = j;
26775   qp->str[len] = '\0';
26776 }
26777 
molcopy(obj,cop,len)26778 void molcopy(obj, cop, len)
26779      const char *obj;
26780      char *cop;
26781      int len;
26782 {
26783 
26784   if (obj == cop || len <= 0) return;
26785 
26786   if (obj < cop && obj+len > cop) {
26787 
26788     obj = obj + len - 1;
26789     cop = cop + len - 1;
26790     for ( ; len>0; len--, obj--, cop--) *cop = *obj;
26791 
26792   } else {
26793 
26794     for ( ; len>0; len--, obj++, cop++) *cop = *obj;
26795 
26796   }
26797 }
26798 
DirKey(qp,c,ks)26799 int DirKey(qp,c,ks)
26800 QBOXSTRU	*qp;
26801 int c;
26802 KeySym ks;
26803 {
26804   int len, retval;
26805 
26806   if(DEBUG)fprintf(stderr,"DirKey in\n");
26807 
26808   if (qp->fake) return(-1);
26809 
26810   retval = -1;
26811   len = strlen(qp->str);
26812   if (qp->curpos < 0) qp->curpos = 0;
26813 
26814   if (qp->qbopt > QSTRING ) {
26815     if ((c>='\060' && c<='\071') || (c=='+' && qp->qbopt == QREAL)
26816     || (c=='-' && qp->qbopt == QREAL) || (c=='.' && qp->qbopt >= QPOSREAL)) {
26817             if (len >= qp->strmax) {
26818 		if (*ibell) XBell(display,0);
26819 		return(-1);
26820 	    }
26821 	    molcopy(&qp->str[qp->wnd_start+qp->curpos],
26822 		    &qp->str[qp->wnd_start+qp->curpos+1],
26823 		    (len-(qp->wnd_start+qp->curpos)+1));
26824             qp->str[qp->wnd_start+qp->curpos]=c; retval = 0;
26825 	    qp->curpos++;
26826     }
26827   }
26828   else
26829   {
26830    if (c>=' ' && c<'\177') {
26831     if (len >= qp->strmax) {
26832 	if (*ibell) XBell(display,0);
26833 	return(-1);
26834     }
26835     molcopy(&qp->str[qp->wnd_start+qp->curpos],
26836 	    &qp->str[qp->wnd_start+qp->curpos+1],
26837 	    (len-(qp->wnd_start+qp->curpos)+1));
26838     qp->str[qp->wnd_start+qp->curpos]=c; retval = 0;
26839     qp->curpos++;
26840    }
26841   }
26842 
26843   if (ks==XK_Left) {
26844         if (qp->curpos > 0) {
26845 	   qp->curpos--; retval = 0;
26846 	} else {
26847 	   if (qp->wnd_start > 0) {
26848 		qp->wnd_start--; retval = 0;
26849 	   }
26850 	}
26851   }
26852 
26853   if (ks==XK_Right) {
26854         if (qp->curpos == qp->wlen) {
26855 	   if (qp->wnd_start < (qp->strmax - qp->wlen)) {
26856 	      if (strlen(qp->str) > qp->wlen) {
26857 	      if (qp->wnd_start < (strlen(qp->str) - qp->wlen)) {
26858 		if (qp->wnd_start < strlen(qp->str)) {
26859 		   qp->wnd_start++; retval = 0;
26860 		}
26861 	      }
26862 	      }
26863 	   }
26864 	} else if (qp->curpos <= qp->wlen && qp->curpos < strlen(qp->str)) {
26865 	   qp->curpos++; retval = 0;
26866 	}
26867   }
26868 
26869   if (retval) {
26870      if (c=='\010' && qp->curpos > 0) {
26871         if (len==0) {
26872 	   if (*ibell) XBell(display,0);
26873 	   return(-1);
26874 	}
26875 	molcopy(&qp->str[qp->wnd_start+qp->curpos],
26876 		&qp->str[qp->wnd_start+qp->curpos-1],
26877 		(len-(qp->wnd_start+qp->curpos)+1));
26878 	qp->curpos--;
26879      }
26880 
26881      else if (c=='\004' || c=='\177') {
26882         if (len==0) {
26883 	   if (*ibell) XBell(display,0);
26884 	   return(-1);
26885 	}
26886 	molcopy(&qp->str[qp->wnd_start+qp->curpos+1],
26887 		&qp->str[qp->wnd_start+qp->curpos],
26888 		(len-(qp->wnd_start+qp->curpos)));
26889      }
26890 
26891      else if (c=='\025' || c=='\013') {
26892        qp->str[0] = '\0';
26893      }
26894 
26895      else if (c=='\012' || c=='\015') {
26896        return(-2);
26897      }
26898 
26899      else {
26900 	if (*ibell) XBell(display,0);
26901 	return(-1);
26902      }
26903 
26904   }
26905 
26906   PromptBox(qp);
26907   return(0);
26908 }
26909 
ChkKey(qp,c)26910 int ChkKey(qp,c)
26911 QBOXSTRU	*qp;
26912 int c;
26913 {
26914   int retval;
26915 
26916   if (qp->fake) return(-1);
26917 
26918   retval = -1;
26919 
26920   if (qp->qbopt > QSTRING ) {
26921     if ((c>='\060' && c<='\071') || (c=='+' && qp->qbopt == QREAL)
26922     || (c=='-' && qp->qbopt == QREAL) || (c=='.' && qp->qbopt >= QPOSREAL))
26923              retval = 0;
26924   } else if (c>=' ' && c<'\177') retval = 0;
26925 
26926   return(retval);
26927 }
26928 
KeyChk(qp,c,ks)26929 int KeyChk(qp,c,ks)
26930 QBOXSTRU	*qp;
26931 int c;
26932 KeySym ks;
26933 {
26934      int retval;
26935 
26936      if (DEBUG) fprintf(stderr,"KeyChk in\n");
26937 
26938      if (qp->fake) return(0);
26939 
26940      qp->changed = 1;
26941 
26942      retval = 0;
26943 
26944      if (DirKey(qp,c,ks) == -2) {
26945 
26946           retval = 1;
26947           if (qp->pop) {
26948 		XDestroyWindow(display,qp->win);
26949 		XSync(display, False);
26950 		qp->active = 0;
26951 		if (qp->win == QBox) qboxup = 0;
26952 	  }
26953 
26954           *Sinct = qp->qbinct;
26955           if (qp->qbopt == 1) *Sincp = atoi(qp->str);
26956           else {
26957 		cpstr(qp->str,Sstr,strlen(qp->str));
26958                 *Snstr = strlen(qp->str);
26959           }
26960 	  if (qp->iflt != NULL) *qp->iflt = atoi(qp->str);
26961 	  if (qp->i2flt != NULL) *qp->i2flt = atoi(qp->str);
26962 	  if (qp->qflt != NULL) *qp->qflt = atof(qp->str);
26963 	  if (qp->dflt != NULL) *qp->dflt = atof(qp->str);
26964 
26965           if (qp->win == ZMEwin) {
26966              if (*backb) {ActBut(&cbut[BDECRF],1); ActBut(&cbut[BUNSC],1);}
26967              ActBut(&cbut[BDIST],1);
26968              ActBut(&cbut[BANGLE],1);
26969              ActBut(&cbut[BDIHED],1);
26970              ActBut(&cbut[BREADF],1);
26971              if (denm) ActBut(&cbut[BDENMOD],1);
26972              *iwropt = ZMEopt-ZMEGAM + 1;
26973 	     if (*iwropt == 5) *iwropt = 7;
26974           }
26975 
26976           if (qp->win == ATMwin && qp->qbopt == QREAL) qdpptr->ihasq = 1;
26977 
26978           qp->callback(qp->str);
26979 
26980           if (qp->win == COMMwin ) {
26981 	     update_model = 1;
26982 	  }
26983 
26984           if (qp->win == RESwin ) {
26985              if (strstr(qp->str,"neigh")) {
26986 		bflag = 1; retval = 0; bretval = 460;
26987 		strcpy(molwstr,"Click on residu/hetatm to activate !");
26988 		StatusStr(0,1);
26989 		XDefineCursor(display,win,AtomCursor);
26990              } else if (strstr(qp->str,"col")) {
26991                 if (!monoscr) {
26992 		    if (DoPopUp(RESwin,0,0,NULL,Sincp,0) == -1) *Sincp = 0;
26993 		}
26994                 else *Sincp = 0;
26995 	     }
26996              else *Sincp = 0;
26997 	     strcpy(qp->str,DEFSTRNAME);
26998 	     qp->curpos = 0;
26999 	     PromptBox(qp);
27000 	     update_model = 1;
27001           }
27002      }
27003 
27004      return(retval);
27005 }
27006 
PFake(win,x,y,w,h,bgcol)27007 void PFake(win,x,y,w,h,bgcol)
27008 Window win;
27009 int x;
27010 int y;
27011 int w;
27012 int h;
27013 int bgcol;
27014 {
27015    XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinMiter);
27016    if (bgcol == -1) XSetForeground(display, gc, White);
27017    else XSetForeground(display, gc, colors[bgcol]);
27018    XDrawRectangle(display, win, gc, x, y, w-QBOXFR, h-14);
27019    XFillRectangle(display, win, gc, x, y, w-QBOXFR, h-14);
27020    XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
27021    XSetForeground(display, gc, Black);
27022 }
27023 
PromptBox(qp)27024 void PromptBox(qp)
27025 QBOXSTRU	*qp;
27026 {
27027   int qlen,tpos,cpos;
27028   int xpos,ypos;
27029   int RectThick,wlen;
27030 
27031   if (DEBUG) fprintf(stderr,"PromptBox in\n");
27032 
27033   if (qp->fake) {
27034 	PFake(qp->win,qp->x,qp->y,qp->w,qp->h,qp->bgcol);
27035 	return;
27036   }
27037 
27038   if (qp->prompt != NULL) {
27039 	qlen = XTextWidth(mfinfo,qp->prompt, strlen(qp->prompt));
27040 	qlen = qlen + 5;
27041   }
27042   else qlen = 0;
27043 
27044   RectThick = 2;
27045   if (!qp->active) RectThick = -1*RectThick;
27046   tpos = (qp->h-14-10)/2; tpos = 10 + tpos;
27047   if (tpos < 0) tpos = 0;
27048   butje(qp->win,qp->x+qlen,qp->y,qp->w-qlen-QBOXFR,qp->h-14,QBOXFR,qp->bgcol,qp->col,0,None,0,0,RectThick);
27049   if (qp->prompt != NULL) XDrawString(display, qp->win, gc, qp->x, qp->y+tpos, qp->prompt, strlen(qp->prompt));
27050 
27051   xpos = qp->x+qlen+QBOXFR+QBOXBORD;
27052   ypos = qp->y+tpos;
27053 
27054   wlen = qp->wlen;
27055   if (qp->strmax < wlen) wlen = qp->strmax;
27056   if (qp->str != NULL) {
27057      if (strlen(qp->str) < wlen) wlen = strlen(qp->str);
27058 
27059      XDrawString(display, qp->win, gc, xpos, ypos,
27060 	&qp->str[qp->wnd_start], wlen);
27061   }
27062 
27063   if (qp->active) {
27064 	ypos = ypos - ASCENT;
27065 	cpos = XTextWidth(mfinfo, &qp->str[0], qp->curpos);
27066 	XDrawLine(display, qp->win, gc, xpos+cpos, ypos-1,
27067 					xpos+cpos, ypos+CHIGH);
27068 	XDrawLine(display, qp->win, gc, xpos+cpos, ypos+CHIGH,
27069 					xpos+3+cpos, ypos+CHIGH+3);
27070 	XDrawLine(display, qp->win, gc, xpos+cpos, ypos+CHIGH,
27071 					xpos-2+cpos, ypos+CHIGH+2);
27072   }
27073 
27074   if (qp->win == QBox && qp->active) {
27075 	DrwBut(&qboxclose[0]);
27076 	DrwBut(&qboxclose[1]);
27077   }
27078   XFlush(display);
27079 
27080   if (DEBUG) fprintf(stderr,"PromptBox out\n");
27081 }
27082 
ClickBox(qbox,num,x,y)27083 int ClickBox(qbox,num,x,y)
27084 QBOXSTRU	*qbox;
27085 int x,y,num;
27086 {
27087   int qlen;
27088   int bnum;
27089   int slen;
27090   double rtmp;
27091   QBOXSTRU *qp;
27092 
27093   bnum = -1;
27094 
27095   for (bnum=0; bnum<num; bnum++) {
27096     qp = &qbox[bnum];
27097     if (!qp->fake) {
27098 	if (qp->prompt != NULL) {
27099 	    qlen = XTextWidth(mfinfo,qp->prompt, strlen(qp->prompt));
27100 	    qlen = qlen + 5;
27101 	}
27102 	else qlen = 0;
27103 
27104 	if (VIERKANT(x, y, qp->x+qlen, qp->y, qp->w-qlen-QBOXFR, 27)) {
27105 	  if (qp->str != NULL) {
27106 	    slen = XTextWidth(mfinfo,qp->str, strlen(qp->str));
27107 	    rtmp = (double)  (x - (qp->x+qlen+QBOXFR+QBOXBORD))/slen;
27108 	    if (rtmp > 1.0)  rtmp = 1.0;
27109 	    if (rtmp < 0.0)  rtmp = 0.0;
27110 	    qp->curpos = (int) (rtmp*((double) (strlen(qp->str))));
27111 	    break;
27112 	  }
27113 	}
27114     }
27115   }
27116 
27117   if (bnum<num && bnum != -1)  return (bnum);
27118 
27119   return -1;
27120 
27121 }
27122 
CheckBox(qbox,num,win,x,y)27123 int CheckBox(qbox,num,win,x,y)
27124 QBOXSTRU	*qbox;
27125 Window win;
27126 int x,y,num;
27127 {
27128   int qlen;
27129   int bnum;
27130   QBOXSTRU *qp;
27131 
27132   bnum = -1;
27133 
27134   for (bnum=0; bnum<num; bnum++) {
27135     qp = &qbox[bnum];
27136     if (!qp->fake && win == qp->win && !qp->active) {
27137 	if (qp->prompt != NULL) {
27138 	    qlen = XTextWidth(mfinfo,qp->prompt, strlen(qp->prompt));
27139 	    qlen = qlen + 5;
27140 	}
27141 	else qlen = 0;
27142 
27143 	if (VIERKANT(x, y, qp->x+qlen, qp->y, qp->w-qlen-QBOXFR, 27)) break;
27144     }
27145   }
27146 
27147   if (bnum<num && bnum != -1)  return (bnum);
27148 
27149   return -1;
27150 
27151 }
27152 
qboxstr(qp,win,active,fake,bgcol,x,y,w,h,col,prompt,defstr,strmax,iopt,qinct,mxstr,callback)27153 void qboxstr(qp,win,active,fake,bgcol,x,y,w,h,col,prompt,defstr,strmax,iopt,qinct,mxstr,callback)
27154 QBOXSTRU	*qp;
27155 Window		*win;
27156 int		active;
27157 int		fake;
27158 int		bgcol;
27159 int		x,y,w,h;
27160 int		col;
27161 char		*prompt;
27162 char		*defstr;
27163 int		strmax;
27164 int		iopt;
27165 int		qinct;
27166 int		mxstr;
27167 ptr_void_proc	callback;
27168 {
27169   int lchr,qlen,mx;
27170 
27171   qp->active = active;
27172   qp->fake = fake;
27173   qp->bgcol = bgcol;
27174   qp->x = x;  qp->y = y;  qp->w = w;  qp->h = h;
27175   qp->col = col;
27176   qp->iflt = NULL;
27177   qp->i2flt = NULL;
27178   qp->qflt = NULL;
27179   qp->dflt = NULL;
27180   qp->changed = 0;
27181 
27182   if (win == NULL) {
27183        if (qboxup) {
27184 	   XDestroyWindow(display,QBox);
27185 	   XSync(display, False);
27186        }
27187        QBox = CreateWindow("Molden Query Box",DEFQBOXGEOM,QBOXWIDE,QBOXHIGH+30,
27188                             infobg,infofg,(Window)0);
27189        qboxup = 1;
27190        qp->win = QBox;
27191        qp->pop = 1;
27192        XSelectInput(display, QBox,
27193 	ExposureMask | KeyPressMask | ButtonPressMask | EnterWindowMask);
27194        XMapWindow(display,QBox);
27195   }
27196   else {qp->win = *win; qp->pop = 0;}
27197 
27198   if (mxstr != -1) {
27199      qp->str = (char *) malloc(sizeof(char)*(MAXPATHLEN+1));
27200      mx = MAXPATHLEN;
27201   } else {
27202      qp->str = (char *) malloc(sizeof(char)*(MAXSTRLEN+1));
27203      mx = MAXSTRLEN;
27204   }
27205 
27206   memset(qp->str,'\0',sizeof(*qp->str));
27207   memset(qp->str,'\0',mx+1);
27208   if (defstr == NULL) strcpy(qp->str,DEFSTRNAME);
27209   else strcpy(qp->str,defstr);
27210   if (strmax) {
27211 	qp->strmax = strmax;
27212 	if (strmax > mx)
27213 	  fprintf(stderr,"qboxstr: strmax longer than allowed\n");
27214   } else qp->strmax = mx;
27215 
27216   qp->wnd_start = 0;
27217   qp->curpos = strlen(qp->str);
27218   qp->prompt = prompt;
27219 
27220   qp->qbopt = iopt;
27221   qp->qbinct = qinct;
27222   qp->callback = callback;
27223 
27224   lchr = XTextWidth(mfinfo," ",1);
27225   if (qp->prompt != NULL) {
27226 	qlen = XTextWidth(mfinfo,qp->prompt, strlen(qp->prompt));
27227 	qlen = qlen + 5;
27228   } else {
27229 	qlen = 0;
27230   }
27231 
27232   qp->wlen = (qp->w - qlen - 2*QBOXFR - 2*QBOXBORD) / lchr;
27233 
27234   if (qp->win == QBox) {
27235 	DefBut(&qboxclose[0], QBox, 10, QBOXHIGH, 50, 23,
27236 	"Apply", infobg, -15);
27237 	DefBut(&qboxclose[1], QBox, 70, QBOXHIGH, 50, 23,
27238 	"Cancel", infobg, -15);
27239   }
27240 
27241 
27242 }
27243 
dummyproc()27244 void dummyproc()
27245 {
27246  int i;
27247 
27248  i = 1;
27249 /*
27250  fprintf(stderr,"I am a dummy\n");
27251 */
27252 }
27253 
27254 
QBoxPaste(ParWin,qp,nboxes)27255 int QBoxPaste(ParWin,qp,nboxes)
27256 Window ParWin;
27257 QBOXSTRU *qp;
27258 int nboxes;
27259 {
27260 int i, j, ret_val, is_ok,format,done;
27261 unsigned long len,bytes_left;
27262 Atom type, XA_CLIPBOARD;
27263 
27264    done = 0;
27265    ret_val = 0;
27266    for (i=0; i<nboxes; i++) {
27267 	if (ParWin == qp[i].win && qp[i].active) {
27268 		ret_val = 1;
27269 		nbytes_select = 0;
27270 		if (XGetSelectionOwner(display,XA_PRIMARY)) {
27271 		   XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_PRIMARY,
27272 					qp[i].win,CurrentTime);
27273 		   XFlush(display);
27274 		   while (!done) {
27275 			XNextEvent(display, &event);
27276 			switch (event.type) {
27277 			case SelectionNotify:
27278 			   if (XGetWindowProperty(display,qp[i].win,
27279 					XA_PRIMARY, 0,10000000L,True,XA_STRING,
27280 					&type,&format,&len,&bytes_left,
27281 				(unsigned char**) &select_pointer) == Success) {
27282 				if (type == XA_STRING)
27283 					nbytes_select = (int) len;
27284 			   }
27285 			   done = 1;
27286 			   break;
27287 			case SelectionClear:
27288 			   done = 1;
27289 			   break;
27290 			}
27291 		   }
27292 
27293 		}
27294 		if (nbytes_select == 0) {
27295 		   select_pointer = XFetchBytes(display, &nbytes_select);
27296 		}
27297 		if (nbytes_select >= MAXPATHLEN)
27298 			nbytes_select = MAXPATHLEN-1;
27299 		if (nbytes_select >= qp[i].strmax)
27300 			nbytes_select = qp[i].strmax;
27301 		if (select_pointer != NULL) {
27302 			is_ok = 1;
27303 			for (j=0; j<nbytes_select; j++)
27304 			   if (ChkKey(&qp[i],select_pointer[j])) is_ok = 0;
27305 			if (is_ok) {
27306 			   int len,na,nb;
27307 			   len = strlen(qp[i].str);
27308 			   nb = qp[i].strmax - (len + nbytes_select);
27309 			   na = qp[i].strmax - (qp[i].curpos + nbytes_select);
27310 			   if (na > 0) na = 0;
27311 
27312 			   if (qp[i].curpos + nbytes_select <= qp[i].strmax)
27313 				molcopy(&qp[i].str[qp[i].curpos],
27314 				   &qp[i].str[qp[i].curpos+nbytes_select],
27315 				   (len-qp[i].curpos+1+nb));
27316 			   molcopy(select_pointer,
27317 				   &qp[i].str[qp[i].curpos],nbytes_select+na);
27318 			   if (na < 0) qp[i].str[qp[i].strmax] = '\0';
27319 			   PromptBox(&qp[i]);
27320 			} else if (*ibell)  XBell(display,0);
27321 		}
27322 	}
27323    }
27324    return (ret_val);
27325 }
27326 
27327 #define BARR1	0
27328 #define BARR2	1
27329 #define BARRW	23
27330 #define BARRH	23
27331 
RedrawList(lp)27332 void RedrawList(lp)
27333 LISTSTRU *lp;
27334 {
27335  int itm;
27336 
27337  itm  = QBOXWIDE;
27338  if (lp->wwin) itm = lp->wwin;
27339 
27340 /* Label Box */
27341 
27342       XSetForeground(display, gc, infobg);
27343       if (lp->label != NULL) {
27344 	  butje(lp->win,0,0,itm,lp->y-4,4,0,0,1,None,0,0,0);
27345 	  LineString(lp->win,lp->label,lp->x+5,lp->y-15);
27346       }
27347 
27348 /* List Box 3d BackGround */
27349 
27350       if (monoscr) {
27351           XSetFillStyle(display, gc, FillStippled);
27352           XSetStipple(display, gc, hlfgrey);
27353           XSetForeground(display, gc, infobg);
27354           XFillRectangle(display, lp->win, gc, 0, lp->y, itm, lp->h+1);
27355           XSetFillStyle(display,gc,FillSolid);}
27356       else butje(lp->win,0,lp->y-5,itm,lp->h+10,4,0,0,1,None,0,0,0);
27357 
27358 /* the central ListBox */
27359 
27360       RedrawLBox(lp);
27361 
27362 /* The scrollbar */
27363 
27364       RedrawScroll(&lp->scrbar);
27365 
27366       DrwBut(&lp->arrbut[0]);
27367       DrwBut(&lp->arrbut[1]);
27368       XFlush(display);
27369       XSync(display, False);
27370 }
27371 
ParseLGAM()27372 void ParseLGAM()
27373 {
27374    if (jobcom->ibatch) {
27375       if (iresopt) {
27376 	sprintf(rungam,"$GAMESS_ROOT/utilities/rungamess %s -n %s %s",
27377 		reskey[iresopt],qboxes[QENAME].str,qboxes[QJNAME].str);
27378       } else {
27379 	sprintf(rungam,"$GAMESS_ROOT/utilities/rungamess %s",
27380 		qboxes[QJNAME].str);
27381       }
27382    } else {
27383       if (iresopt) {
27384 	sprintf(rungam,
27385 	   "$GAMESS_ROOT/utilities/rungamess %s -n %s %s -nqs -q %s",
27386 	   reskey[iresopt],qboxes[QENAME].str,qboxes[QJNAME].str,
27387 #ifdef DOQUEUE
27388 	   ques[qopt]);
27389 #else
27390 	   qboxes[QQNAME].str);
27391 #endif
27392       } else {
27393 	sprintf(rungam,"$GAMESS_ROOT/utilities/rungamess %s -nqs -q %s",
27394 		qboxes[QJNAME].str,
27395 #ifdef DOQUEUE
27396 		ques[qopt]);
27397 #else
27398 		qboxes[QQNAME].str);
27399 #endif
27400       }
27401    }
27402 }
27403 
CheckChargeMult()27404 int CheckChargeMult()
27405 {
27406    int i,ne,ionil;
27407 
27408    ne = 0;
27409 
27410    ionil = 0;
27411 
27412    if (ioniom) {
27413      ionil = 3 - (lnkat / 10000);
27414      lnkat -= (lnkat / 10000) * 10000;
27415    } else {
27416      lnkat = 0;
27417    }
27418 
27419    if (*zmptrp->ihaszm) {
27420 	for (i=0; i<*zmptrp->nz; i++) {
27421 	   if (ioniom && (xyzp->ityp[i]/10000 >= ionil)) continue;
27422 	   if (zmptrp->ianz[i] >= 0 && zmptrp->ianz[i] < 99) {
27423 		ne = ne + zmptrp->ianz[i];
27424 	   }
27425 	}
27426    } else {
27427       if (jobcom->iwxyz) {
27428 	for (i=0; i<*xyzp->iatoms; i++) {
27429 	   if (ioniom && (xyzp->ityp[i]/10000 >= ionil)) continue;
27430 	   if (xyzp->ianz[i] >= 0 && xyzp->ianz[i] < 99) {
27431 		ne = ne + xyzp->ianz[i];
27432 	   }
27433 	}
27434       } else {
27435 	return(0);
27436       }
27437    }
27438 /*
27439    fprintf(stderr,"ionil %d ne %d itotc %d lnkat %d mult %d\n",
27440                    ionil,ne,jobcom->itotc,lnkat,jobcom->imult);
27441 */
27442    ne = ne - jobcom->itotc + lnkat;
27443    if (ne % 2 == jobcom->imult % 2) return(1);
27444    return(0);
27445 }
27446 
ParseLine()27447 void ParseLine()
27448 {
27449    char *scfd;
27450    char *mopo;
27451    int i, isl, ism;
27452 
27453    if (jmode == 3) return;
27454 
27455    if (jmode == 1 && ONIup) {
27456 
27457 	ism = isl = 0;
27458 	for (i=0;i<*xyzp->iatoms;i++) {
27459 	   if (xyzp->ityp[i] >= 20000) isl = 1;
27460 	   if (xyzp->ityp[i] >= 10000 && xyzp->ityp[i] < 20000) ism = 1;
27461 	}
27462 	ioniom = 0;
27463 	if (isl && ism) ioniom = 2;
27464 	if ( (isl && ! ism) || (ism && ! isl) ) ioniom = 1;
27465 
27466 	if (strcmp(mkey[imopth],"AM1") == 0 ||
27467 	    strcmp(mkey[imopth],"dreiding") == 0 ||
27468 	    strcmp(mkey[imopth],"Amber") == 0) {
27469    	   sprintf(*olev,"%s",mkey[imopth]);
27470 	} else {
27471    	   sprintf(*olev,"%s/%s",mkey[imopth],bkey[ibopth]);
27472 	}
27473 	if (strcmp(mkey[imoptm],"AM1") == 0 ||
27474 	    strcmp(mkey[imoptm],"dreiding") == 0 ||
27475 	    strcmp(mkey[imoptm],"Amber") == 0) {
27476    	   sprintf(*(olev+1),"%s",mkey[imoptm]);
27477 	} else {
27478    	   sprintf(*(olev+1),"%s/%s",mkey[imoptm],bkey[iboptm]);
27479 	}
27480 	if (strcmp(mkey[imoptl],"AM1") == 0 ||
27481 	    strcmp(mkey[imoptl],"dreiding") == 0 ||
27482 	    strcmp(mkey[imoptl],"Amber") == 0) {
27483    	   sprintf(*(olev+2),"%s",mkey[imoptl]);
27484 	} else {
27485    	   sprintf(*(olev+2),"%s/%s",mkey[imoptl],bkey[iboptl]);
27486 	}
27487 /*
27488 	if (ioniom == 0) DeActOButs();
27489 	if (ioniom >= 1) ActOButs();
27490 */
27491    }
27492 
27493    if (imolopt[jmode] && jmode != 2) {
27494 
27495 	if (ioniom == 0) {
27496 	   sprintf(qboxes[QGLIN1].str,"#P %s/%s %s",
27497 		mkey[imopt[jmode]],bkey[ibopt[jmode]],tkey[itopt[jmode]]);
27498 	} else if(ioniom == 1) {
27499 	   sprintf(qboxes[QGLIN1].str,"#P ONIOM(%s:%s) %s",
27500 	      olev[0],olev[2],tkey[itopt[jmode]]);
27501 	} else {
27502 	   sprintf(qboxes[QGLIN1].str,"#P ONIOM(%s:%s:%s) %s",
27503 	      olev[0],olev[1],olev[2],tkey[itopt[jmode]]);
27504 	}
27505    } else {
27506 	if (jmode == 2) {
27507 
27508 	   mopo = tkey[itopt[2]];
27509 	   if (!imolopt[2] && itopt[2] == 1) mopo = nullstr;
27510 
27511            if (ispopt) {
27512 	      if (icopt != 3) {
27513 	        sprintf(qboxes[QGLIN1].str,"%s %s %s CHARGE=%s T=24.0H NOINTER +",
27514 		mkey[imopt[jmode]],mopo,spopt[ispopt],copt[icopt]);
27515 	      } else {
27516 	        sprintf(qboxes[QGLIN1].str,"%s %s %s T=24.0H NOINTER +",
27517 		mkey[imopt[jmode]],mopo,spopt[ispopt]);
27518 	      }
27519 	   } else {
27520 	      if (icopt != 3) {
27521 	        sprintf(qboxes[QGLIN1].str,"%s %s CHARGE=%s T=24.0H NOINTER +",
27522 		mkey[imopt[jmode]],mopo,copt[icopt]);
27523 	      } else {
27524 	        sprintf(qboxes[QGLIN1].str,"%s %s T=24.0H NOINTER +",
27525 		mkey[imopt[jmode]],mopo);
27526 	      }
27527 	   }
27528 	} else {
27529 	   if (ioniom == 0) {
27530 	      sprintf(qboxes[QGLIN1].str,"# %s/%s %s",
27531 		   mkey[imopt[jmode]],bkey[ibopt[jmode]],tkey[itopt[jmode]]);
27532 	   } else if(ioniom == 1) {
27533 	      sprintf(qboxes[QGLIN1].str,"# ONIOM(%s:%s) %s",
27534 	         olev[0],olev[2],tkey[itopt[jmode]]);
27535 	   } else {
27536 	      sprintf(qboxes[QGLIN1].str,"# ONIOM(%s:%s:%s) %s",
27537 	         olev[0],olev[1],olev[2],tkey[itopt[jmode]]);
27538 	   }
27539  	}
27540    }
27541    qboxes[QGLIN1].wnd_start = 0;
27542    qboxes[QGLIN1].curpos = strlen(qboxes[QGLIN1].str);
27543 
27544    if (iscfd) {
27545 	scfd = nullstr;
27546    } else {
27547 	scfd = scfdir;
27548    }
27549 
27550    if (imolopt[jmode]) {
27551      if (jmode == 1) {
27552 	if (imolopt[jmode] == 1) {
27553 	   sprintf(qboxes[QGLIN2].str,"# GFINPUT IOP(6/7=3) 6D 10F %s",scfd);
27554 	} else {
27555 	   sprintf(qboxes[QGLIN2].str,"# GFINPUT IOP(6/7=1) 6D 10F %s",scfd);
27556 	}
27557      } else if (jmode == 2) {
27558 	if (imolopt[jmode] == 1) {
27559 	   sprintf(qboxes[QGLIN2].str,"GRAPH AUX PRNT=2 COMPFG");
27560 	}
27561      }
27562    } else {
27563 	if (jmode == 2) {
27564 	   sprintf(qboxes[QGLIN2].str," ");
27565 	} else {
27566 	   sprintf(qboxes[QGLIN2].str,"# %s",scfd);
27567 	}
27568    }
27569    qboxes[QGLIN2].wnd_start = 0;
27570    qboxes[QGLIN2].curpos = strlen(qboxes[QGLIN2].str);
27571 
27572 }
27573 
CreateSUB(imd)27574 int CreateSUB(imd)
27575 int imd;
27576 {
27577   jmode = imd;
27578   if (jmode > 3) {
27579 	if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
27580 	"Not Implemented",0)) {
27581 	}
27582 	return(0);
27583   }
27584 
27585   SUBup = 1;
27586   topt = toph[jmode];
27587   tkey = tkeyh[jmode];
27588   toptn = topn[jmode];
27589 
27590   mopt = moph[jmode];
27591   mkey = mkeyh[jmode];
27592   moptn = mopn[jmode];
27593 
27594   bopt = boph[jmode];
27595   bkey = bkeyh[jmode];
27596   boptn = bopn[jmode];
27597 
27598   if (jmode == 2) {
27599      molopt = molopt2;
27600   } else if (jmode == 3) {
27601      molopt = molopt3;
27602   } else {
27603      molopt = molopt1;
27604   }
27605 
27606   SUBwin = CreateWindow(subwname[jmode],"-80-80",
27607 			 SBOXWIDE,SBOXHIGH,infobg,infofg,(Window)0);
27608   XSelectInput(display, SUBwin,
27609 	ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask |
27610 	EnterWindowMask);
27611 
27612   XMapWindow(display,SUBwin);
27613 
27614   WinObj[13].win = &SUBwin;
27615   WinObj[13].subwin = NULL;
27616   WinObj[13].butarr = sbut;
27617   WinObj[13].numbut = NBUTSS;
27618   WinObj[13].winup = &SUBup;
27619   WinObj[13].init = NULL;
27620   WinObj[13].redraw = RedrawSUB;
27621 
27622   DefBut(&sbut[STASK], SUBwin, SBOXOFFX, 20, SBOXBLEN, 23,
27623 	"Task", infobg, -15);
27624   DefBut(&sbut[SMETH], SUBwin, SBOXOFFX, 20+BUTTN, SBOXBLEN, 23,
27625 	"Method", infobg, -15);
27626   DefBut(&sbut[SBASS], SUBwin, SBOXOFFX, 20+2*BUTTN, SBOXBLEN, 23,
27627 	"Basis Set", infobg, -15);
27628   if (jmode == 2) ActBut(&sbut[SBASS],2);
27629   DefBut(&sbut[SCHAR], SUBwin, SBOXOFFX, 20+4*BUTTN, SBOXBLEN, 23,
27630 	"Charge", infobg, -15);
27631   DefBut(&sbut[SSPIN], SUBwin, SBOXOFFX, 20+5*BUTTN, SBOXBLEN, 23,
27632 	"Spin", infobg, -15);
27633   DefBut(&sbut[SMOLD], SUBwin, SBOXOFFL+100, 20+BUTTN, 110, 23,
27634 	"Molden", infobg, -15);
27635   if (!jmode) ActBut(&sbut[SMOLD],2);
27636   DefBut(&sbut[SREST], SUBwin, SBOXOFFL+100, 20+BUTTN, 110, 23,
27637 	"Restart", infobg, -15);
27638   if (jmode) ActBut(&sbut[SREST],2);
27639   DefBut(&sbut[SDIRE], SUBwin, SBOXOFFL+100, 24+2*BUTTN, 15, 15,
27640 	" ", infobg, -15);
27641   DefBut(&sbut[SZMAT], SUBwin, SBOXOFFL+200, 24+2*BUTTN, 15, 15,
27642 	" ", infobg, -15);
27643   DefBut(&sbut[SWXYZ], SUBwin, SBOXOFFL+230, 24+3*BUTTN, 15, 15,
27644 	" ", infobg, -15);
27645   DefBut(&sbut[SHESS], SUBwin, SBOXOFFL+100, 24+2*BUTTN, 15, 15,
27646 	" ", infobg, -15);
27647   if (jmode != 1) ActBut(&sbut[SDIRE],2);
27648   if (jmode != 1) ActBut(&sbut[SZMAT],2);
27649   if (jmode != 1 && jmode != 3) ActBut(&sbut[SWXYZ],2);
27650   if (jmode) ActBut(&sbut[SHESS],2);
27651 
27652   DefBut(&sbut[SBATC], SUBwin, SBOXOFFL+100, 24+3*BUTTN, 15, 15,
27653 	" ", infobg, -15);
27654   DefBut(&sbut[SONI], SUBwin, SBOXOFFL+165, 24+3*BUTTN, 15, 15,
27655 	" ", infobg, -15);
27656   if (jmode != 1) ActBut(&sbut[SONI],2);
27657   DefBut(&sbut[SQUEU], SUBwin, SBOXOFFL+173, 15+6*BUTTN, 110,23,
27658 	"short", infobg, -15);
27659 #ifndef DOQUEUE
27660   ActBut(&sbut[SQUEU],2);
27661 #endif
27662   DefBut(&sbut[SSUBM], SUBwin, SBOXOFFX, 30+12*BUTTN, 110, 23,
27663 	"Submit", infobg, -4);
27664   DefBut(&sbut[SCLOS], SUBwin, SBOXOFFX+120, 30+12*BUTTN, 110, 23,
27665 	"Close", infobg, -4);
27666   if (jmode && jmode != 3) {
27667 	qboxstr(&qboxes[QGLIN1],&SUBwin,1,0,190,10,20+7*BUTTN,
27668 		SBOXWIDE-20,QBOXHIGH,2,"Keywrd",NULL,SUBLEN1,0,2000,-1,
27669 		dummyproc);
27670 	qboxstr(&qboxes[QGLIN2],&SUBwin,0,0,190,10,25+8*BUTTN,
27671 		SBOXWIDE-20,QBOXHIGH,2,"      ",NULL,SUBLEN1,0,2000,-1,
27672 		dummyproc);
27673   }
27674   qboxstr(&qboxes[QGTITL],&SUBwin,0,0,190,10,30+10*BUTTN,
27675 	SBOXWIDE-20,QBOXHIGH,2,"Title ","title",SUBLEN1,0,2000,-1,
27676 	dummyproc);
27677   qboxstr(&qboxes[QJNAME],&SUBwin,0,0,190,SBOXOFFL+100,24+4*BUTTN,
27678 	230,QBOXHIGH,2,"Job Name   ","test",SUBLEN2,0,2000,-1,
27679 	dummyproc);
27680 
27681 #ifndef DOQUEUE
27682   qboxstr(&qboxes[QQNAME],&SUBwin,0,0,190,SBOXOFFL+100,30+5*BUTTN,
27683 	230,QBOXHIGH,2,"Queue Name ","short",SUBLEN2,0,2000,-1,
27684 	dummyproc);
27685 #endif
27686 
27687   if (!jmode) {
27688 #ifndef DOQUEUE
27689 	qboxstr(&qboxes[QTIME],&SUBwin,0,0,190,SBOXOFFL+100,36+6*BUTTN,
27690 		230,QBOXHIGH,2,"Job Time   ","10",SUBLEN2,1,2000,-1,
27691 		dummyproc);
27692 #endif
27693 	qboxstr(&qboxes[QENAME],&SUBwin,0,0,190,SBOXOFFL+100,42+7*BUTTN,
27694 		230,QBOXHIGH,2,"ED Name    ","edtest",SUBLEN2,0,2000,-1,
27695 		dummyproc);
27696   }
27697 
27698   sbut[STASK].str = topt[itopt[jmode]];
27699   sbut[SMETH].str = mopt[imopt[jmode]];
27700   if (jmode != 2) sbut[SBASS].str = bopt[ibopt[jmode]];
27701   sbut[SSPIN].str = spopt[ispopt];
27702   sbut[SCHAR].str = copt[icopt];
27703   if (jmode) sbut[SMOLD].str = molopt[imolopt[jmode]];
27704   if (!jmode) sbut[SREST].str = resopt[iresopt];
27705   if (jmode == 1) {
27706      if (iscfd) {
27707 	TogUp(&sbut[SDIRE]);
27708      } else {
27709 	TogDown(&sbut[SDIRE]);
27710      }
27711      if (izmat) {
27712 	TogUp(&sbut[SZMAT]);
27713 	tkey = tkey2;
27714      } else {
27715 	TogDown(&sbut[SZMAT]);
27716 	tkey = tkey2b;
27717      }
27718      if (ionon == 0) {
27719 	TogUp(&sbut[SONI]);
27720      } else {
27721 	TogDown(&sbut[SONI]);
27722      }
27723   }
27724   if (!jmode) {
27725      if (ihess) {
27726 	TogUp(&sbut[SHESS]);
27727      } else {
27728 	TogDown(&sbut[SHESS]);
27729      }
27730   }
27731   if (jobcom->ibatch) {
27732 	TogUp(&sbut[SBATC]);
27733   } else {
27734 	TogDown(&sbut[SBATC]);
27735   }
27736 
27737   if (jobcom->iwxyz) {
27738 	TogDown(&sbut[SWXYZ]);
27739   } else {
27740 	TogUp(&sbut[SWXYZ]);
27741   }
27742 
27743 #ifdef DOQUEUE
27744   sbut[SQUEU].str = ques[qopt];
27745 #endif
27746 
27747   if (jmode && jmode != 3) ParseLine();
27748 
27749   return(1);
27750 }
27751 
RedrawSUB()27752 void RedrawSUB()
27753 {
27754   int i;
27755 
27756   butje(SUBwin,0,0,SBOXWIDE,SBOXHIGH,4,0,0,1,None,0,0,0);
27757   for (i=0; i<NBUTSS; i++) DrwBut(&sbut[i]);
27758   LineString(SUBwin, "Task", SBOXOFFL, 35);
27759   if (jmode) ULineString(SUBwin, "Extra print keys for Molden",SBOXOFFL+100, 35);
27760   else ULineString(SUBwin, "Dumpfile Control",SBOXOFFL+100, 35);
27761   if (jmode == 1) LineString(SUBwin, "Direct Mode", SBOXOFFL+125, 35+2*BUTTN);
27762   if (jmode == 1) LineString(SUBwin, "Opt. Z-matrix", SBOXOFFL+225, 35+2*BUTTN);
27763   if (jmode == 1 || jmode == 3) LineString(SUBwin, "Write XYZ", SBOXOFFL+250, 35+3*BUTTN);
27764   if (jmode == 0) LineString(SUBwin, "PickUp Hessian", SBOXOFFL+125, 35+2*BUTTN);
27765   if (jmode == 1) LineString(SUBwin, "ONIOM", SBOXOFFL+185, 35+3*BUTTN);
27766   LineString(SUBwin, "Batch", SBOXOFFL+125, 35+3*BUTTN);
27767 #ifdef DOQUEUE
27768   LineString(SUBwin, "Queue Name", SBOXOFFL+100, 30+6*BUTTN);
27769 #endif
27770   LineString(SUBwin, "Method", SBOXOFFL, 35+BUTTN);
27771   if (jmode != 2) LineString(SUBwin, "Basis Set", SBOXOFFL, 35+2*BUTTN);
27772   LineString(SUBwin, "Charge", SBOXOFFL, 35+4*BUTTN);
27773   LineString(SUBwin, "Spin", SBOXOFFL, 35+5*BUTTN);
27774   if (jmode) {
27775      PromptBox(&qboxes[QGLIN1]);
27776      PromptBox(&qboxes[QGLIN2]);
27777   }
27778   PromptBox(&qboxes[QGTITL]);
27779   PromptBox(&qboxes[QJNAME]);
27780 #ifndef DOQUEUE
27781   PromptBox(&qboxes[QQNAME]);
27782 #endif
27783   if (!jmode) {
27784 #ifndef DOQUEUE
27785      PromptBox(&qboxes[QTIME]);
27786 #endif
27787      PromptBox(&qboxes[QENAME]);
27788   }
27789 
27790   if (jmode == 3) {
27791 	if (system("which nwchem > /dev/null 2>&1")) {
27792 	   if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
27793 		"nwchem: command NOT found !",1)) {
27794 		   XDestroyWindow(display,SUBwin);
27795 		   SUBup = 0;
27796 	   }
27797 	}
27798   }
27799 
27800 }
27801 
ButtonsSUB(i)27802 int ButtonsSUB(i)
27803 int i;
27804 {
27805   LSSTRU List;
27806   int redraw=0;
27807   int j,k,ionij,nconn;
27808 
27809   switch (i) {
27810   case STASK:
27811 		List.list = topt; List.nents = toptn;
27812 		if (DoPopUp(SUBwin,
27813 			sbut[STASK].x+SBOXBLEN/2,sbut[STASK].y+BUTTH,
27814 			&List,&itopt[jmode],1) == -1) break;
27815 		sbut[STASK].str = topt[itopt[jmode]];
27816 		if (!jmode && itopt[jmode] == 12) {
27817 		   iresopt = 1;
27818 		   sbut[SREST].str = resopt[iresopt];
27819 		   DrwBut(&sbut[SREST]);
27820 		}
27821 		redraw = 1;
27822 		break;
27823   case SMETH:
27824 		List.list = mopt; List.nents = moptn;
27825 		if (DoPopUp(SUBwin,
27826 			sbut[SMETH].x+SBOXBLEN/2,sbut[SMETH].y+BUTTH,
27827 			&List,&imopt[jmode],1) == -1) break;
27828 		sbut[SMETH].str = mopt[imopt[jmode]];
27829 		redraw = 1;
27830 		break;
27831   case SBASS:
27832 		List.list = bopt; List.nents = boptn;
27833 		if (DoPopUp(SUBwin,
27834 			sbut[SBASS].x+SBOXBLEN/2,sbut[SBASS].y+BUTTH,
27835 			&List,&ibopt[jmode],1) == -1) break;
27836 		sbut[SBASS].str = bopt[ibopt[jmode]];
27837 		redraw = 1;
27838 		break;
27839 #ifdef DOQUEUE
27840   case SQUEU:
27841 		List.list = ques; List.nents = nques;
27842 		if (DoPopUp(SUBwin,
27843 			sbut[SQUEU].x+110/2,sbut[SQUEU].y+BUTTH,
27844 			&List,&qopt,1) == -1) break;
27845 		sbut[SQUEU].str = ques[qopt];
27846 		redraw = 1;
27847 		break;
27848 #endif
27849   case SCHAR:
27850 		List.list = copt; List.nents = 7;
27851 		if (DoPopUp(SUBwin,
27852 			sbut[SCHAR].x+SBOXBLEN/2,sbut[SCHAR].y+BUTTH,
27853 			&List,&icopt,1) == -1) break;
27854 		sbut[SCHAR].str = copt[icopt];
27855 		redraw = 1;
27856 		break;
27857   case SSPIN:
27858 		List.list = spopt; List.nents = 8;
27859 		if (DoPopUp(SUBwin,
27860 			sbut[SSPIN].x+SBOXBLEN/2,sbut[SSPIN].y+BUTTH,
27861 			&List,&ispopt,1) == -1) break;
27862 		sbut[SSPIN].str = spopt[ispopt];
27863 		redraw = 1;
27864 		break;
27865   case SMOLD:
27866 		List.list = molopt;
27867 		if (jmode == 2 || jmode == 3) {
27868 		   List.nents = 2;
27869 		} else {
27870 		   List.nents = 3;
27871 		}
27872 		if (DoPopUp(SUBwin,
27873 			sbut[SMOLD].x+110/2,sbut[SMOLD].y+BUTTH,
27874 			&List,&imolopt[jmode],1) == -1) break;
27875 		sbut[SMOLD].str = molopt[imolopt[jmode]];
27876 		redraw = 1;
27877 		jobcom->iextopt = imolopt[jmode];
27878 		break;
27879   case SREST:
27880 		List.list = resopt;
27881 		List.nents = 10;
27882 		if (DoPopUp(SUBwin,
27883 			sbut[SREST].x+110/2,sbut[SREST].y+BUTTH,
27884 			&List,&iresopt,1) == -1) break;
27885 		sbut[SREST].str = resopt[iresopt];
27886 		redraw = 1;
27887 		break;
27888   case SDIRE:
27889 		iscfd = TogBut(&sbut[SDIRE]);
27890 		redraw = 1;
27891 		break;
27892   case SHESS:
27893 		ihess = TogBut(&sbut[SHESS]);
27894 		if (ihess) {
27895 		   iresopt = 0;
27896 		} else {
27897 		   iresopt = 1;
27898 		}
27899 		sbut[SREST].str = resopt[iresopt];
27900 		DrwBut(&sbut[SREST]);
27901 		redraw = 1;
27902 		break;
27903   case SBATC:
27904 		jobcom->ibatch = TogBut(&sbut[SBATC]);
27905 		break;
27906   case SSUBM:
27907 
27908 		/* If ONIOM, should check the charge/mult for levels H, H+M
27909 		   and eventually H+M+L */
27910 
27911 		if (ioniom == 1) {
27912 		  int ism, isl;
27913 
27914 		  lnkat = 0;
27915 
27916 		  /* Counting the number of Link atoms between H and lower
27917 		     levels*/
27918 
27919 		  ism = isl = 0;
27920 		  for (j=0;j<*xyzp->iatoms;j++) {
27921 	   	     if (xyzp->ityp[j] >= 20000) isl = 1;
27922 	   	     if (xyzp->ityp[j] >= 10000 && xyzp->ityp[j] < 20000) ism = 1;
27923 		     ionij = xyzp->ityp[j] / 10000;
27924 		     if (ionij != 0) continue;
27925 		     nconn = xyzp->iconn[j*(MXCON+1)];
27926 		     for (k=1;k<=nconn;k++) {
27927 		       if (xyzp->ityp[xyzp->iconn[j*(MXCON+1)+k]-1]/10000 > 0) lnkat++;
27928 		     }
27929 		  }
27930 		  lnkat += 20000;
27931 		  jobcom->itotc = jobcom->icopth;
27932 		  jobcom->imult = jobcom->ispopth;
27933 		  if (CheckChargeMult()) {
27934 	           if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
27935 		       "WARNING: inconsistent multiplicity and charge for H level",0)) {
27936 		       i = 0;
27937 	           }
27938 /*
27939 	           break;
27940 */
27941 		  }
27942 		  icopt = jobcom->icoptm+3;
27943 		  ispopt = jobcom->ispoptm-1;
27944 		  if (ism == 0 && isl == 1) {
27945 		     icopt = jobcom->icoptl+3;
27946 		     ispopt = jobcom->ispoptl-1;
27947 		  }
27948 
27949 		}  else if (ioniom == 2) {
27950 
27951 	          lnkat = 0;
27952 
27953 		  /* Counting the number of Link atoms between H and
27954 		       lower levels*/
27955 
27956 		 for (j=0;j<*xyzp->iatoms;j++) {
27957 		         ionij = xyzp->ityp[j] / 10000;
27958 			 if(ionij != 0) continue;
27959 		         nconn = xyzp->iconn[j*(MXCON+1)];
27960 		         for (k=1;k<=nconn;k++) {
27961 		           if (xyzp->ityp[xyzp->iconn[j*(MXCON+1)+k]-1]/10000 > 0) lnkat++;
27962 		         }
27963 		  }
27964 		  lnkat += 20000;
27965 		  jobcom->itotc = jobcom->icopth;
27966 		  jobcom->imult = jobcom->ispopth;
27967 		  if (CheckChargeMult()) {
27968 	               if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
27969 			"WARNING: inconsistent multiplicity and charge for H level",0)) {
27970 		           i = 0;
27971 	               }
27972 /*
27973 	               break;
27974 */
27975 		  }
27976 	          lnkat = 0;
27977 
27978 		  /* Counting the number of Link atoms between H+M and
27979 		     lower levels*/
27980 
27981 		  for (j=0;j<*xyzp->iatoms;j++) {
27982 			ionij = xyzp->ityp[j] / 10000;
27983 			if (ionij == 2) continue;
27984 			nconn = xyzp->iconn[j*(MXCON+1)];
27985 			for (k=1;k<=nconn;k++) {
27986 			   if (xyzp->ityp[xyzp->iconn[j*(MXCON+1)+k]-1]/10000 == 2) lnkat++;
27987 			}
27988 		  }
27989 		  lnkat += 20000;
27990 		  jobcom->itotc = jobcom->icoptm;
27991 		  jobcom->imult = jobcom->ispoptm;
27992 		  if (CheckChargeMult()) {
27993 		     if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
27994 			"WARNING: inconsistent multiplicity and charge for M level",0)) {
27995 		           i = 0;
27996 		     }
27997 /*
27998 		     break;
27999 */
28000 		  }
28001 		  icopt = jobcom->icoptl+3;
28002 		  ispopt = jobcom->ispoptl-1;
28003 		}
28004 		lnkat = 0;
28005 		jobcom->itotc = icopt - 3;
28006 		jobcom->imult = ispopt + 1;
28007 		jobcom->ito = itopt[jmode] + 1;
28008 		jobcom->imo = imopt[jmode] + 1;
28009 		jobcom->ibo = ibopt[jmode] + 1;
28010 		jobcom->ihs = ihess;
28011 #ifdef DOQUEUE
28012 		jobcom->itm = quetims[qopt];
28013 #else
28014 		if (jmode != 3) {
28015 		   jobcom->itm = atoi(qboxes[QTIME].str);
28016 		}
28017 #endif
28018 
28019 		if (CheckChargeMult()) {
28020 		   if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
28021 			"WARNING: inconsistent multiplicity and charge",0)) {
28022 			i = 0;
28023 		   }
28024 /*
28025 		   break;
28026 */
28027 		}
28028 
28029 		if (!jmode) ParseLGAM();
28030 
28031 		if (jmode && jmode != 3) {
28032 		   cpstr(qboxes[QGLIN1].str,glin1,SUBLEN1);
28033 		   cpstr(qboxes[QGLIN2].str,glin2,SUBLEN1);
28034 		}
28035 		cpstr(qboxes[QGTITL].str,gtitl,SUBLEN1);
28036 		cpstr(qboxes[QJNAME].str,jname,SUBLEN2);
28037 #ifdef DOQUEUE
28038 		cpstr(ques[qopt],qname,SUBLEN2);
28039 #else
28040 		cpstr(qboxes[QQNAME].str,qname,SUBLEN2);
28041 #endif
28042 		if (!jmode) cpstr(rungam,ename,SUBLEN1);
28043 		if (TogBut(&ZMEbut[ZMESUB])) {
28044 		   XDestroyWindow(display,SUBwin);
28045 		   SUBup = 0;
28046 		}
28047 		return(1);
28048 		break;
28049   case SZMAT:
28050 		izmat = TogBut(&sbut[SZMAT]);
28051 		if (izmat) {
28052 		   tkey = tkey2;
28053 		} else {
28054 		   tkey = tkey2b;
28055 		}
28056 		redraw = 1;
28057 		break;
28058   case SWXYZ:
28059 		jobcom->iwxyz = 1 - TogBut(&sbut[SWXYZ]);
28060 		break;
28061   case SONI:
28062 		ionon = 1 - TogBut(&sbut[SONI]);
28063 
28064 		if (ionon == 0) {
28065 	           if (ONIup) {
28066 			XDestroyWindow(display,ONIwin);
28067 			ONIup = 0;
28068 		   }
28069 		} else {
28070 		   if (!ONIup) {
28071 			CreateONI();
28072 			*Sinct = 401; return(0);
28073 		   }
28074 		}
28075 		redraw = 1;
28076 		break;
28077    case SCLOS:
28078 		if (TogBut(&ZMEbut[ZMESUB])) {
28079 		   XDestroyWindow(display,SUBwin);
28080 		   SUBup = 0;
28081 		}
28082 		break;
28083   default: break;
28084   }
28085 
28086   if (redraw && jmode) {
28087   	RedrawSUB();
28088 	ParseLine();
28089 	PromptBox(&qboxes[QGLIN1]);
28090 	PromptBox(&qboxes[QGLIN2]);
28091   }
28092   if (redraw && !jmode) ParseLGAM();
28093 
28094   return(0);
28095 
28096 }
28097 
RedrawLBox(lp)28098 void RedrawLBox(lp)
28099 LISTSTRU *lp;
28100 {
28101       int i,nen,isel;
28102       char drawstrc[44];
28103 
28104       drawstrc[43] = '\0';
28105 
28106       XSetForeground(display, gc, infofg);
28107       XFillRectangle(display, lp->win, gc, lp->x+1, lp->y+1, lp->w-1, lp->h-1);
28108 
28109       XSetForeground(display, gc, infobg);
28110       XDrawRectangle(display, lp->win, gc, lp->x, lp->y, lp->w, lp->h);
28111 
28112       nen = MINI(lp->mxents,*lp->list.nents);
28113       if (lp->lpnt > *lp->list.nents - lp->mxents) {
28114 	 lp->lpnt = *lp->list.nents - lp->mxents;
28115 	 if (lp->lpnt < 0) lp->lpnt = 0;
28116       }
28117 
28118       for (i=0; i<nen; i++) {
28119 	 isel = 0;
28120 	 if (lp->list.slst != NULL) {
28121 	   if (lp->list.slst[i+lp->lpnt]) isel = 1;
28122 	 } else {
28123 	   if (i+lp->lpnt == lp->select) isel = 1;
28124 	 }
28125          if (isel) {
28126 	      if (lp->list.svgs != NULL) {
28127 		  XSetLineAttributes(display, gc, 3, LineSolid, CapButt,
28128 			JoinMiter);
28129 		  XSetForeground(display, gc, infobg);
28130 		  XDrawRectangle(display, lp->win, gc,
28131 		    lp->x, lp->y+i*lp->h/lp->mxents, lp->w, lp->h/lp->mxents);
28132 		  XSetForeground(display, gc, infofg);
28133 		  if (lp->list.svgs[lp->lpnt+i].array != NULL) {
28134 		  	DrawSVG(lp->x, lp->y+i*lp->h/lp->mxents,
28135 			lp->w, lp->h/lp->mxents,lp->list.svgs[lp->lpnt+i],MLTwin);
28136 		  } else if (lp->list.list != NULL) {
28137 			strncpy(drawstrc,lp->list.list[lp->lpnt+i],42);
28138 			XSetForeground(display, gc, infobg);
28139                   	LineString(lp->win,drawstrc,lp->x+5,
28140 			lp->y+12+i*lp->h/lp->mxents);
28141 		  }
28142 	      } else if (lp->list.list == NULL) {
28143 		  XSetForeground(display, gc, infobg);
28144 		  XFillRectangle(display, lp->win, gc,
28145 		    lp->x, lp->y+i*lp->h/lp->mxents, lp->w, lp->h/lp->mxents);
28146 		  XSetForeground(display, gc, infofg);
28147 		  if (lp->list.flst == NULL)
28148 			sprintf(drawstrc,"%4d      %11.6f",lp->lpnt+i+1,
28149 			lp->list.rlst[lp->lpnt+i]);
28150 		  else if (lp->list.rlst == NULL)
28151 		  	sprintf(drawstrc,"%4d      %3.2f",lp->lpnt+i+1,
28152 			lp->list.flst[lp->lpnt+i]);
28153 		  else
28154 		  	sprintf(drawstrc,"%4d      %11.6f      %3.2f",lp->lpnt+i+1,
28155 			lp->list.rlst[lp->lpnt+i],lp->list.flst[lp->lpnt+i]);
28156                   LineString(lp->win,drawstrc,lp->x+5,
28157 			lp->y+12+i*lp->h/lp->mxents);
28158 	      } else {
28159 		  XSetForeground(display, gc, infobg);
28160 		  XFillRectangle(display, lp->win, gc,
28161 		    lp->x, lp->y+i*lp->h/lp->mxents, lp->w, lp->h/lp->mxents);
28162 		  XSetForeground(display, gc, infofg);
28163 		  if (lp->list.ilst == NULL) {
28164 		  	if (lp->list.rlst != NULL && lp->list.flst == NULL)
28165 		  	   sprintf(drawstrc,"%4d      %11.6f      %s",
28166 				lp->lpnt+i+1,lp->list.rlst[lp->lpnt+i],
28167 				lp->list.list[lp->lpnt+i]);
28168 		  	if (lp->list.rlst != NULL && lp->list.flst != NULL)
28169 		  	   sprintf(drawstrc,"%4d   %11.3f        %6.2f   %s",
28170 				lp->lpnt+i+1,lp->list.rlst[lp->lpnt+i],
28171 				lp->list.flst[lp->lpnt+i],
28172 				lp->list.list[lp->lpnt+i]);
28173 			else if (lp->list.rlst == NULL &&
28174 				 lp->list.flst == NULL) {
28175 			   if (lp->list.list[lp->lpnt+i] != NULL)
28176 			   strncpy(drawstrc,lp->list.list[lp->lpnt+i],42);
28177 			}
28178 		  } else {
28179 			XDrawRectangle(display, lp->win, gc,
28180 		    lp->x, lp->y+i*lp->h/lp->mxents, lp->w, lp->h/lp->mxents);
28181 			XFillRectangle(display, lp->win, gc,
28182 		    lp->x, lp->y+i*lp->h/lp->mxents, lp->w, lp->h/lp->mxents);
28183 			XSetForeground(display, gc, infofg);
28184 			strncpy(drawstrc,lp->list.list[lp->list.ilst[lp->lpnt+i]],42);
28185 		  }
28186                   LineString(lp->win,drawstrc,lp->x+5,
28187 			lp->y+12+i*lp->h/lp->mxents);
28188 	      }
28189               XSetForeground(display, gc, infobg);
28190          } else {
28191 	      if (lp->list.svgs != NULL) {
28192 		  XSetLineAttributes(display, gc, 1, LineSolid, CapButt,
28193 			JoinMiter);
28194 		  XSetForeground(display, gc, infobg);
28195 		  XDrawRectangle(display, lp->win, gc,
28196 		    lp->x, lp->y+i*lp->h/lp->mxents, lp->w, lp->h/lp->mxents);
28197 		  XSetForeground(display, gc, infofg);
28198 		  if (lp->list.svgs[lp->lpnt+i].array != NULL) {
28199 		  	DrawSVG(lp->x, lp->y+i*lp->h/lp->mxents,
28200 			lp->w, lp->h/lp->mxents,lp->list.svgs[lp->lpnt+i],MLTwin);
28201 		  } else if (lp->list.list != NULL) {
28202 			strncpy(drawstrc,lp->list.list[lp->lpnt+i],42);
28203 			XSetForeground(display, gc, infobg);
28204                   	LineString(lp->win,drawstrc,lp->x+5,
28205 			lp->y+12+i*lp->h/lp->mxents);
28206 		  }
28207 	      } else if (lp->list.list == NULL) {
28208 		  if (lp->list.flst == NULL) {
28209 		  	sprintf(drawstrc,"%4d      %11.6f",lp->lpnt+i+1,
28210 			lp->list.rlst[lp->lpnt+i]);
28211 		  }
28212 		  else if (lp->list.rlst == NULL) {
28213 		  	sprintf(drawstrc,"%4d      %3.2f",lp->lpnt+i+1,
28214 			lp->list.flst[lp->lpnt+i]);
28215 		  }
28216 		  else {
28217 		  	sprintf(drawstrc,"%4d      %11.6f      %3.2f",lp->lpnt+i+1,
28218 			lp->list.rlst[lp->lpnt+i],lp->list.flst[lp->lpnt+i]);
28219 		  }
28220 	          LineString(lp->win,drawstrc,lp->x+5,
28221 			lp->y+12+i*lp->h/lp->mxents);
28222 	      } else {
28223 		  if (lp->list.ilst == NULL) {
28224 		  	if (lp->list.rlst != NULL && lp->list.flst == NULL)
28225 		  	   sprintf(drawstrc,"%4d      %11.6f      %s",
28226 				lp->lpnt+i+1,lp->list.rlst[lp->lpnt+i],
28227 				lp->list.list[lp->lpnt+i]);
28228 		  	if (lp->list.rlst != NULL && lp->list.flst != NULL)
28229 		  	   sprintf(drawstrc,"%4d   %11.3f        %6.2f   %s",
28230 				lp->lpnt+i+1,lp->list.rlst[lp->lpnt+i],
28231 				lp->list.flst[lp->lpnt+i],
28232 				lp->list.list[lp->lpnt+i]);
28233 			else if (lp->list.rlst == NULL &&
28234 				 lp->list.flst == NULL) {
28235 			   if (lp->list.list[lp->lpnt+i] != NULL)
28236 			   strncpy(drawstrc,lp->list.list[lp->lpnt+i],42);
28237 			}
28238 		  } else {
28239 			strncpy(drawstrc,lp->list.list[lp->list.ilst[lp->lpnt+i]],42);
28240 		  }
28241 	          LineString(lp->win,drawstrc,lp->x+5,
28242 			lp->y+12+i*lp->h/lp->mxents);
28243 	      }
28244 	  }
28245       }
28246       XFlush(display);
28247 }
28248 
DefList(lp,win,x,y,w,h,label,mx,lstr,rlist,flst,slist,nentries,svgs)28249 void DefList(lp,win,x,y,w,h,label,mx,lstr,rlist,flst,slist,nentries,svgs)
28250 LISTSTRU	*lp;
28251 Window		win;
28252 int		x,y;
28253 unsigned int	w,h;
28254 char		*label;
28255 int		mx;
28256 char		**lstr;
28257 float		*rlist;
28258 double		*flst;
28259 int		*slist;
28260 int		*nentries;
28261 SVGFSTRUC	*svgs;
28262 {
28263   int ggx, ggy;
28264   unsigned int ggw, ggh, ggb, ggd;
28265   Window rt;
28266 
28267   lp->win = win;
28268   lp->x = x;  lp->y = y;  lp->w = w;  lp->h = h;
28269   lp->mxents = mx;
28270   lp->list.list = lstr;
28271   lp->list.rlst = rlist;
28272   lp->list.flst = flst;
28273   lp->list.ilst = NULL;
28274   lp->list.slst = slist;
28275   lp->list.svgs = svgs;
28276   lp->list.nents = nentries;
28277   lp->lpnt = 0;
28278   lp->select = 0;
28279   lp->label = label;
28280 
28281   lp->wwin = 0;
28282   if (XGetGeometry(display,lp->win,&rt,
28283 	&ggx, &ggy, &ggw, &ggh, &ggb, &ggd) == True ) lp->wwin = ggw;
28284 
28285   DefScroll(&lp->scrbar,lp->win,lp->x+lp->w,lp->y+BARRH,BARRW,
28286              lp->h-2*BARRH,lp->list.nents,&lp->lpnt,lp->mxents,NULL);
28287 
28288   DefBut(&lp->arrbut[0], lp->win, lp->x+lp->w, lp->y            ,
28289 	BARRW, BARRH, " ", infobg, 0);
28290   DefBut(&lp->arrbut[1], lp->win, lp->x+lp->w, lp->y+lp->h-BARRH+1,
28291 	BARRW, BARRH, " ", infobg, 0);
28292 
28293   lp->arrbut[0].pix = upPix;
28294   lp->arrbut[0].pw  = up_width;
28295   lp->arrbut[0].ph  = up_height;
28296 
28297   lp->arrbut[1].pix = downPix;
28298   lp->arrbut[1].pw  = down_width;
28299   lp->arrbut[1].ph  = down_height;
28300 }
28301 
PressList(lp,x,y)28302 int PressList(lp,x,y)
28303 LISTSTRU	*lp;
28304 int		x;
28305 int		y;
28306 {
28307       int i;
28308 
28309   if (VIERKANT(x, y,lp->x,lp->y,lp->w,lp->h)){
28310 
28311       lp->select = lp->lpnt + lp->mxents*(y - lp->y) / lp->h;
28312       if (lp->list.slst != NULL) {
28313 	   if (lp->list.slst[lp->select]) {
28314 		lp->list.slst[lp->select] = 0;
28315 	   } else {
28316 		lp->list.slst[lp->select] = 1;
28317 	   }
28318       }
28319       RedrawList(lp);
28320       return 1;
28321 
28322   } else {
28323 
28324       i=Clickwin(lp->arrbut,2,x,y,1);
28325 
28326       if (i>=0) {
28327 
28328 	  switch (i) {
28329 
28330           case BARR1:
28331 
28332 		if (*lp->list.nents > lp->mxents)
28333 		    if (lp->lpnt) {
28334 			lp->lpnt--;RedrawLBox(lp); RedrawScroll(&lp->scrbar);
28335 		    }
28336 #ifdef HASTIMER
28337 		Timer(100,0);
28338 		while (!XCheckWindowEvent(display, lp->win,
28339 			ButtonReleaseMask, &event)) {
28340 
28341 			if (*lp->list.nents > lp->mxents)
28342 			   if (lp->lpnt) {
28343 				lp->lpnt--;
28344 				RedrawLBox(lp); RedrawScroll(&lp->scrbar);
28345 				Timer(50,0);
28346 			   }
28347 		}
28348 #endif
28349 		break;
28350 
28351           case BARR2:
28352 		if (*lp->list.nents > lp->mxents) {
28353 			lp->lpnt++;
28354 			if (lp->lpnt > *lp->list.nents-lp->mxents)
28355 				lp->lpnt = *lp->list.nents-lp->mxents;
28356 			RedrawLBox(lp); RedrawScroll(&lp->scrbar);
28357 		}
28358 #ifdef HASTIMER
28359 		Timer(100,0);
28360 		while (!XCheckWindowEvent(display, lp->win,
28361 			ButtonReleaseMask, &event)) {
28362 
28363 			if (*lp->list.nents > lp->mxents) {
28364 				lp->lpnt++;
28365 				if (lp->lpnt > *lp->list.nents-lp->mxents) {
28366 					lp->lpnt = *lp->list.nents-lp->mxents;
28367                                	} else {
28368 					RedrawLBox(lp);
28369 					RedrawScroll(&lp->scrbar);
28370 				}
28371 				Timer(50,0);
28372                         }
28373 		}
28374 #endif
28375 		break;
28376           }
28377       }
28378       ScrollPage(lp,&lp->scrbar,x,y);
28379       return 0;
28380   }
28381 
28382 }
28383 
28384 /**********************************************/
DefBut(bp,win,x,y,w,h,str,bg,fg)28385 void DefBut(bp,win,x,y,w,h,str,bg,fg)
28386 BSTRU         *bp;
28387 Window        win;
28388 int           x,y,w,h;
28389 char         *str;
28390 unsigned long bg;
28391 int fg;
28392 {
28393   bp->win = win;
28394   bp->x = x;  bp->y = y;  bp->w = w;  bp->h = h;
28395   if (!w) {
28396 	bp->w = XTextWidth(mfinfo,str,strlen(str)) + 2*SPACING;
28397   } else {
28398 	bp->w = w;
28399   }
28400   bp->str = str;
28401   if (monoscr || colcells <= 32) {bp->fg = infobg; bp->bg = infofg;}
28402   else {bp->fg = fg;  bp->bg = bg;}
28403   bp->lit = 0;
28404   bp->active = 1;
28405   bp->toggle = 1;
28406   bp->pix = None;
28407   bp->style = 0;
28408   bp->fwidth = 3;
28409   bp->lastused = 0;
28410   bp->explstr = NULL;
28411 
28412   if (!hlfgrey) {
28413     hlfgrey = XCreatePixmapFromBitmapData(display, win, hlfgrey_bits,
28414 		       hlfgrey_width, hlfgrey_height, 1, 0, 1);
28415     if (!hlfgrey) fprintf(stderr,"Unable to create hlfgrey bitmap\n");
28416   }
28417 }
28418 
28419 
28420 
ActBut(bp,act)28421 void ActBut(bp,act)
28422 BSTRU *bp;
28423 int           act;
28424 {
28425   if (bp->active != act) {
28426     bp->active = act;
28427     DrwBut(bp);
28428   }
28429 }
28430 
TogBut(bp)28431 int TogBut(bp)
28432 BSTRU *bp;
28433 {
28434   if (bp->toggle) bp->toggle = 0;
28435   else bp->toggle = 1;
28436   DrwBut(bp);
28437   return (bp->toggle);
28438 }
28439 
28440 
TogDown(bp)28441 void TogDown(bp)
28442 BSTRU *bp;
28443 {
28444   bp->toggle = 0;
28445   DrwBut(bp);
28446 }
28447 
TogUp(bp)28448 void TogUp(bp)
28449 BSTRU *bp;
28450 {
28451   bp->toggle = 1;
28452   DrwBut(bp);
28453 }
28454 
28455 /**********************************************/
DrwBut(bp)28456 void DrwBut(bp)
28457 BSTRU *bp;
28458 {
28459   int x,y,w,h,r,x1,y1;
28460 
28461   if (bp->active == 2) return;
28462 
28463   x = bp->x;  y=bp->y;  w=bp->w;  h=bp->h;  r=bp->fwidth;
28464 
28465   if (bp->active < 1) bp->lit = 0;
28466   if (bp->lit) {
28467     r -= 1;
28468     if (r<0) r = 0;
28469   }
28470 
28471   if (bp->lastused == 1) {
28472 	butje(bp->win,x,y,w,h,r,0,bp->fg,bp->toggle,bp->pix,bp->pw,bp->ph,2);
28473   } else if (bp->lastused == -1) {
28474 	butje(bp->win,x,y,w,h,r,bp->bg,bp->fg,bp->toggle,bp->pix,bp->pw,bp->ph,-2);
28475   } else butje(bp->win,x,y,w,h,r,0,bp->fg,bp->toggle,bp->pix,bp->pw,bp->ph,0);
28476 
28477   if (bp->lit) {
28478       if (monoscr || colcells <= 32) {
28479            XDrawRectangle(display, bp->win, gc, x+2, y+2, w-4, h-4);
28480            XDrawRectangle(display, bp->win, gc, x+1, y+1, w-2, h-2);
28481       }
28482       else XDrawRectangle(display, bp->win, gc, x+1, y+1, w-2, h-2);
28483   }
28484 
28485   if (bp->pix == None) {
28486     x1 = MIDDLEX(mfinfo, x + w/2, bp->str);
28487     y1 = MIDDLEY(mfinfo, y + h/2);
28488 
28489     if (bp->active == 1) {
28490       XDrawString(display, bp->win, gc, x1,y1, bp->str, strlen(bp->str));
28491     }
28492     else {
28493       XSetFillStyle(display, gc, FillStippled);
28494       XSetStipple(display, gc, grayStip);
28495       XDrawString(display, bp->win, gc, x1,y1, bp->str, strlen(bp->str));
28496       XSetFillStyle(display,gc,FillSolid);
28497     }
28498   }
28499 
28500 }
28501 
28502 
SelBut(bp)28503 void SelBut(bp)
28504 BSTRU *bp;
28505 {
28506 
28507   XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinMiter);
28508   XSetForeground(display, gc, Black);
28509   XDrawRectangle(display, bp->win, gc, bp->x-2, bp->y-2, bp->w+4, bp->h+4);
28510   XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
28511 
28512 }
28513 
28514 /***************************************************/
Clickwin(but,num,x,y,check)28515 int Clickwin(but,num,x,y,check)
28516 BSTRU  *but;
28517 int x,y,num,check;
28518 {
28519   BSTRU  *bp;
28520   int    bnum;
28521 
28522   for (bnum=0; bnum<num; bnum++) {
28523     bp = &but[bnum];
28524     if (bp->active != 2) if (VIERKANT(x, y, bp->x, bp->y, bp->w, bp->h)) break;
28525   }
28526 
28527   if (bnum<num) {   /* found one */
28528     if (check) {
28529 	if (ChkBut(bp)) return (bnum);
28530     } else {
28531 	return (bnum);
28532     }
28533   }
28534 
28535   return -1;
28536 }
28537 
28538 /**********************************************/
ChkBut(bp)28539 int ChkBut(bp)
28540 BSTRU *bp;
28541 {
28542 
28543   int          rval, inval;
28544 #ifndef HASTIMER
28545   Window       rW, cW;
28546   int          x, y, rx, ry;
28547   unsigned int mask;
28548 #endif
28549 
28550   if (bp->active != 1) return 0;
28551 
28552   inval = bp->lit;
28553   bp->lit = !bp->lit;
28554 
28555   DrwBut(bp);  XFlush(display);
28556 #ifdef HASTIMER
28557   Timer(120,0);  /* long enough for turn on to be visible */
28558 
28559 #else
28560   while (XQueryPointer(display,bp->win,&rW,&cW,&rx,&ry,&x,&y,&mask)) {
28561     if (!(mask & Button1Mask)) break;    /* button released */
28562 
28563     if (bp->lit==inval && VIERKANT(x, y, bp->x, bp->y, bp->w, bp->h)) {
28564       bp->lit = !inval;  DrwBut(bp);  XFlush(display);
28565     }
28566 
28567     if (bp->lit!=inval && !VIERKANT(x, y, bp->x, bp->y, bp->w, bp->h)) {
28568       bp->lit = inval;  DrwBut(bp);  XFlush(display);
28569     }
28570   }
28571 #endif
28572 
28573   rval = (bp->lit != inval);
28574 
28575   if (bp->lit )
28576     { bp->lit = 0;  DrwBut(bp);  XFlush(display); }
28577 
28578   return(rval);
28579 }
28580 
28581 #define EXPLSPACE 5
DoExpl()28582 void DoExpl()
28583 {
28584   Window win;
28585   int x,y,xt,yt;
28586   int wit,hit,bw,xp,retval,nlines,wittmp,ql;
28587   char *p, *q;
28588   BSTRU *bp;
28589   QBOXSTRU *qp;
28590 
28591   if ((!expldat.borq && expldat.barr == NULL) ||
28592       (expldat.borq && expldat.qarr == NULL)) return;
28593 
28594   if (expldat.winup != NULL) if (! *expldat.winup) return;
28595   if (animptr.on || *movie) return;
28596 
28597   expldat.active = 1;
28598   signal(SIGALRM,SIG_IGN);
28599 
28600   if (expldat.borq) {
28601 	qp = &expldat.qarr[expldat.button];
28602 	win = qp->win;
28603 	x = qp->x; y = qp->y;
28604 	p = qp->explstr;
28605 	q = qp->explstr;
28606   } else {
28607 	bp = &expldat.barr[expldat.button];
28608 	win = bp->win;
28609 	x = bp->x; y = bp->y;
28610 	p = bp->explstr;
28611 	q = bp->explstr;
28612   }
28613 
28614   XGetWindowAttributes(display, win, &xwa);
28615 
28616   nlines = 0;
28617   wit = 0;
28618 
28619   while ((p = strchr(q, '\n'))) {
28620      ql = (int) (p-q);
28621      wittmp = XTextWidth(mfinfo,q,ql) + 2*EXPLSPACE;
28622      if (wittmp > wit) wit = wittmp;
28623      p++;
28624      q = p;
28625      nlines++;
28626   }
28627   ql = strlen(q);
28628   wittmp = XTextWidth(mfinfo,q,ql) + 2*EXPLSPACE;
28629   if (wittmp > wit) wit = wittmp;
28630   nlines++;
28631 
28632   hit = EXPLSPACE + LINEHIGH*nlines + EXPLSPACE;
28633   xt = x-wit/2; yt = y-hit/2;
28634   if (x+wit > xwa.width) xt = xwa.width-wit;
28635   if (xt < 0) xt = 0;
28636   if (yt < 0) yt = 0;
28637 
28638   XSelectInput(display, expldat.win,
28639   ( ExposureMask | PointerMotionMask | VisibilityChangeMask ));
28640 
28641   XMoveResizeWindow(display, expldat.win, xt, yt, wit, hit);
28642 
28643   XMapRaised(display,expldat.win);
28644 
28645   XSync(display, False);
28646 
28647   XNextEvent(display, &event);
28648 
28649   XSetForeground(display, gc, colors[0]);
28650 
28651   nlines = 0;
28652   if (expldat.borq) {
28653 	p = qp->explstr;
28654 	q = qp->explstr;
28655   } else {
28656 	p = bp->explstr;
28657 	q = bp->explstr;
28658   }
28659 
28660   while ((p = strchr(q, '\n'))) {
28661 		ql = (int) (p-q);
28662 	        XDrawString(display, expldat.win, gc,
28663 			EXPLSPACE, CHIGH+nlines*LINEHIGH+EXPLSPACE, q, ql);
28664 		p++;
28665 		q = p;
28666 		nlines++;
28667   }
28668   ql = strlen(q);
28669   XDrawString(display, expldat.win, gc,
28670 		EXPLSPACE, CHIGH+nlines*LINEHIGH+EXPLSPACE, q, ql);
28671 
28672   XFlush(display);
28673 
28674   XMaskEvent(display, PointerMotionMask | ButtonPressMask, &event);
28675 
28676 
28677   XUnmapWindow(display,expldat.win);
28678   XSync(display, False);
28679   expldat.active = 0;
28680   expldat.barr = NULL;
28681   expldat.qarr = NULL;
28682   expldat.win = -1;
28683 }
28684 
StringWidth(str)28685 int StringWidth(str)
28686 char *str;
28687 {
28688   return(XTextWidth(mfinfo, str, strlen(str)));
28689 }
28690 
butje(bwin,x,y,w,h,r,bgcol,sh_ind,iopt,pix,pw,ph,rec)28691 void butje(bwin,x,y,w,h,r,bgcol,sh_ind,iopt,pix,pw,ph,rec)
28692 Window bwin;
28693 int x,y,w,h,r,bgcol,sh_ind,iopt;
28694 Pixmap pix;
28695 int pw,ph,rec;
28696 {
28697   int i,x1,y1;
28698   int dark,light,medium;
28699   XPoint butb[10], butc[10], buta[5];
28700 
28701   if (DEBUG) fprintf(stderr,"butje in\n");
28702 
28703   if (bwin == (Window) NULL) return;
28704 
28705   buta[0].x = x+r;        buta[0].y = y+r;
28706   buta[1].x = x+r;        buta[1].y = y+h-r;
28707   buta[2].x = x+w-r;      buta[2].y = y+h-r;
28708   buta[3].x = x+w-r;      buta[3].y = y+r;
28709   buta[4].x = buta[0].x;  buta[4].y = buta[0].y;
28710 
28711 
28712   butb[0].x = x;            butb[0].y = y+h;
28713   butb[1].x = buta[1].x;    butb[1].y = buta[1].y;
28714   butb[2].x = buta[2].x;    butb[2].y = buta[2].y;
28715   butb[3].x = buta[3].x;    butb[3].y = buta[3].y;
28716   butb[4].x = x+w;          butb[4].y = y;
28717   butb[5].x = x+w;          butb[5].y = y+h;
28718   butb[6].x = x;            butb[6].y = y+h;
28719 
28720   butc[0].x = x;            butc[0].y = y+h;
28721   butc[1].x = buta[1].x;    butc[1].y = buta[1].y;
28722   butc[2].x = buta[0].x;    butc[2].y = buta[0].y;
28723   butc[3].x = buta[3].x;    butc[3].y = buta[3].y;
28724   butc[4].x = x+w;          butc[4].y = y;
28725   butc[5].x = x;            butc[5].y = y;
28726   butc[6].x = x;            butc[6].y = y+h;
28727 
28728 
28729   if (monoscr || colcells <= 32) {
28730 
28731     XSetForeground(display, gc, White);
28732     XFillRectangle(display, bwin, gc, x, y, w, h);
28733     XSetForeground(display, gc, Black);
28734     XDrawRectangle(display, bwin, gc, x, y, w, h);
28735 
28736     XSetForeground(display, gc, Black);
28737     XSetFillStyle(display, gc, FillStippled);
28738     XSetStipple(display, gc, hlfgrey);
28739     XFillPolygon(display, bwin, gc, butc, 7, Nonconvex, CoordModeOrigin);
28740     XSetFillStyle(display,gc,FillSolid);
28741 
28742     XSetForeground(display, gc, Black);
28743     XDrawLines(display, bwin, gc, buta, 5, CoordModeOrigin);
28744 
28745     XDrawLine(display, bwin, gc, x+1,   y+1,  buta[0].x,buta[0].y);
28746     XDrawLine(display, bwin, gc, x+1,   y+h-1,buta[1].x,buta[1].y);
28747     XDrawLine(display, bwin, gc, x+w-1, y+h-1,buta[2].x,buta[2].y);
28748     XDrawLine(display, bwin, gc, x+w-1, y+1,  buta[3].x,buta[3].y);
28749 
28750   } else {
28751 
28752     if (sh_ind >= 0) {
28753 	dark   = shcolors[sh_ind]+DARK;
28754 	light  = shcolors[sh_ind]+LIGHT;
28755 	medium = shcolors[sh_ind]+MEDIUM;
28756     }
28757     else {
28758 	dark   = 15-(sh_ind+1)*10+3;
28759 	light  = 15-(sh_ind+1)*10+10;
28760 	medium = 15-(sh_ind+1)*10+7;
28761     }
28762 
28763     XSetForeground(display, gc, colors[medium] );
28764     XFillRectangle(display, bwin, gc, x+1, y+1, w-1, h-1);
28765 
28766     if (!iopt) XSetForeground(display, gc, colors[dark]);
28767     else XSetForeground(display, gc, colors[light]);
28768 
28769     if (DoIntel) {
28770        for (i=0; i<=r; i++) {
28771          XDrawLine(display, bwin, gc, x+i, y+i, x+w, y+i);
28772          XDrawLine(display, bwin, gc, x+i, y+i, x+i, y+h);
28773        }
28774     } else {
28775        for (i=1; i<=r; i++) {
28776          XDrawLine(display, bwin, gc, x+i, y+i, x+w, y+i);
28777          XDrawLine(display, bwin, gc, x+i, y+i, x+i, y+h);
28778        }
28779     }
28780 
28781     if (!iopt) XSetForeground(display, gc, colors[light]);
28782     else XSetForeground(display, gc, colors[dark]);
28783 
28784     if (DoIntel) {
28785        for (i=0; i<=r; i++) {
28786          XDrawLine(display, bwin, gc, x+i, y+h-i, x+w, y+h-i);
28787          XDrawLine(display, bwin, gc, x+w-i, y+h, x+w-i, y+i);
28788        }
28789     } else {
28790        for (i=1; i<=r; i++) {
28791          XDrawLine(display, bwin, gc, x+i, y+h-i, x+w, y+h-i);
28792          XDrawLine(display, bwin, gc, x+w-i, y+h, x+w-i, y+i);
28793        }
28794     }
28795 
28796     if (rec) {
28797 
28798         XSetLineAttributes(display, gc, ABS(rec),
28799 				LineSolid, CapButt, JoinMiter);
28800 	if (rec > 0) {
28801 	    XSetForeground(display, gc, Black);
28802 	} else {
28803 	    if (bgcol == -1) XSetForeground(display, gc, White);
28804 	    else XSetForeground(display, gc, colors[bgcol]);
28805 	}
28806 	XDrawRectangle(display, bwin, gc, x, y, w, h);
28807         XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
28808     }
28809 
28810   }
28811 
28812 
28813   XSetForeground(display, gc, Black);
28814 
28815   if (pix != None) {
28816     x1 = x+(1+w-pw)/2;
28817     y1 = y+(1+h-ph)/2;
28818 
28819     if (monoscr || colcells <= 32) XSetBackground(display, gc, White);
28820     else XSetBackground(display, gc, colors[medium]);
28821     XCopyPlane(display, pix, bwin, gc, 0,0,pw,ph, x1,y1, 1);
28822     XSetBackground(display, gc, White);
28823   }
28824 
28825   if (DEBUG) fprintf(stderr,"butje out\n");
28826 
28827 }
28828 
28829 /***************************************************/
CreatewinC(geom)28830 void CreatewinC(geom)
28831 char *geom;
28832 {
28833 
28834 
28835   if (DEBUG) fprintf(stderr,"CreatewinC in\n");
28836 
28837   winC = CreateWindow("Molden Control",geom,WINCWIDE, WINCHIGH, infobg, infofg,(Window)0);
28838 
28839   subC = CreateWindow("Subwindow","",10,10,
28840                             colors[0],colors[15],winC);
28841 
28842   DefBut(&dbut[BPSI],   winC, PLOFFX+BOFFX, PLOFFY+24            , 60, BUTTH,
28843 	   "Orbital", infobg, CNTCOL);
28844   dbut[BPSI].explstr = "Select orbital to display\nFor open shell:\nselect alpha or beta orbitals";
28845   DefBut(&dbut[BHOMO],  winC, PLOFFX+BOFFX, PLOFFY+24+BUTTN  , 60, BUTTH,
28846 	   "Homo", infobg, CNTCOL);
28847   dbut[BHOMO].explstr = "Highest Occupied Molecular Orbital\nis displayed";
28848   DefBut(&dbut[BLUMO],  winC, PLOFFX+BOFFX+65, PLOFFY+24+BUTTN, 60, BUTTH,
28849 	   "Lumo", infobg, CNTCOL);
28850   dbut[BLUMO].explstr = "Lowest Unoccupied Molecular Orbital\nis displayed";
28851   DefBut(&dbut[BNDEN],  winC, PLOFFX+BOFFX, PLOFFY+24+BUTTN*2, 60, BUTTH,
28852 	   "Density", infobg, CNTCOL);
28853   dbut[BNDEN].explstr = "Display electron density";
28854   DefBut(&dbut[BLAPL],  winC, PLOFFX+BOFFX+65, PLOFFY+24+BUTTN*2, 60, BUTTH,
28855 	   "Laplac.", infobg, CNTCOL);
28856   dbut[BLAPL].explstr = "Display Laplacian of\nelectron density";
28857   DefBut(&dbut[BELF],  winC, PLOFFX+BOFFX+65, PLOFFY+24+BUTTN*3, 60, BUTTH,
28858 	   "ELF", infobg, CNTCOL);
28859   dbut[BELF].explstr = "Display Electron Localization Funtion";
28860   DefBut(&dbut[BBONDS], winC, PLOFFX+BOFFX, PLOFFY+24+BUTTN*4, 60, BUTTH,
28861 	   "Bonds", infobg, CNTCOL);
28862   dbut[BBONDS].explstr = "Display Difference Density:\nMolecular minus Atomic";
28863   DefBut(&dbut[BORI],   winC, PLOFFX+BOFFX+65,PLOFFY+36+BUTTN*4,TOGGWH, TOGGWH,
28864 	   " ", infobg, CNTCOL);
28865   dbut[BORI].explstr = "Use oriented atomic density in\ncalculation of Difference Density:\nMolecular minus Atomic";
28866   DefBut(&dbut[BATOM],  winC, PLOFFX+BOFFX, PLOFFY+24+BUTTN*5, 60, BUTTH,
28867 	   "Atomic", infobg, CNTCOL);
28868   dbut[BATOM].explstr = "Display Difference Density:\nMolecular minus Atomic\nOnly contributions where \nAO1,AO2 are on the same atom";
28869   DefBut(&dbut[BOVRLP], winC, PLOFFX+BOFFX, PLOFFY+24+BUTTN*6, 60, BUTTH,
28870 	   "Overlap", infobg, CNTCOL);
28871   dbut[BOVRLP].explstr = "Display Difference Density:\nMolecular minus Atomic\nOnly overlap contributions only:\nAO1,AO2 not on the same atom";
28872   DefBut(&dbut[BELPOT], winC, PLOFFX+BOFFX, PLOFFY+24+BUTTN*7, 60, BUTTH,
28873 	   "Elec. Pot", infobg, CNTCOL);
28874   dbut[BELPOT].explstr = "Calculate Electrostatic Potential";
28875 
28876   DefBut(&dbut[BCOMM],  winC, MSOFFX+BOFFX, MSOFFY+24+BUTTN*0, 70, BUTTH,
28877 	   "PlotPlane", infobg, CNTCOL);
28878   dbut[BCOMM].explstr = "commands that define the plotplane\nfor euclid plots\nand the grid size\n(also for space plots)";
28879   DefBut(&dbut[BMAXMIN],winC, MSOFFX+BOFFX, MSOFFY+24+BUTTN*1, 70, BUTTH,
28880 	   "Maxi/Mini", infobg, CNTCOL);
28881   dbut[BMAXMIN].explstr = "show the maxima and minima\nfor euclid plots";
28882   DefBut(&dbut[BPOST],  winC, MSOFFX+BOFFX, MSOFFY+24+BUTTN*2, 70, BUTTH,
28883 	   "Postscript", infobg, CNTCOL);
28884   dbut[BPOST].explstr = "write a postscript file\nof current plot";
28885   DefBut(&dbut[BMOLMOD],winC, MSOFFX+BOFFX, MSOFFY+24+BUTTN*3, 70, BUTTH,
28886 	   "Mol. Mode", infobg, CNTCOL);
28887   dbut[BMOLMOD].explstr = "switch back to the molecular mode";
28888 
28889   DefBut(&dbut[BEUCL],  winC, PMOFFX+30, PMOFFY+26, 60, BUTTH-2,
28890 	   "Euclid", infobg, CNTCOL);
28891   dbut[BEUCL].explstr = "2D contour plot of orbital/density\nin a plane";
28892   DefBut(&dbut[B3D],    winC, PMOFFX+15, PMOFFY+26+(BUTTH+2)*1, 40, BUTTH-2,
28893 	   "3D", infobg, CNTCOL);
28894   dbut[B3D].explstr = "3D plot of orbital/density\nin a plane";
28895   DefBut(&dbut[B3DX],   winC, PMOFFX+65, PMOFFY+26+(BUTTH+2)*1, 40, BUTTH-2,
28896 	   "3D-X", infobg, CNTCOL);
28897   dbut[B3DX].explstr = "3D plot of orbital/density\nin a plane:\nXwindows rendering";
28898   DefBut(&dbut[BSPACE], winC, PMOFFX+5, PMOFFY+26+(BUTTH+2)*2, 50, BUTTH-2,
28899 	   "Space", infobg, CNTCOL);
28900   dbut[BSPACE].explstr = "iso-surface of orbital/density\ncalculated in a 3D grid";
28901   DefBut(&dbut[BVRML2], winC, PMOFFX+63, PMOFFY+26+(BUTTH+2)*2, 24, 24,
28902 	   "VRML", infobg, CNTCOL);
28903   dbut[BVRML2].explstr = "write a Virtual Reality Modeling Language\nrepresentation of the current plot";
28904   DefBut(&dbut[BSRF2],  winC, PMOFFX+93, PMOFFY+26+(BUTTH+2)*2, 24, 24,
28905 	   "SRF", infobg, CNTCOL);
28906   dbut[BSRF2].explstr = "convert space plot so it can be\ndisplayed in molecular mode";
28907 
28908   DefBut(&dbut[BINCRS], winC, D3OFFX+BOFFX, D3OFFY+24+BUTTN*0, 80, BUTTH,
28909 	   "Incr. Scale", infobg, CNTCOL);
28910   dbut[BINCRS].explstr = "increase the heigth of the 3D plot.";
28911   DefBut(&dbut[BDECRS], winC, D3OFFX+BOFFX, D3OFFY+24+BUTTN*1, 80, BUTTH,
28912 	   "Decr. Scale", infobg, CNTCOL);
28913   dbut[BDECRS].explstr = "decrease the heigth of the 3D plot.";
28914   DefBut(&dbut[BCONT],  winC, D3OFFX+BOFFX, D3OFFY+24+BUTTN*2, TOGGWH, TOGGWH,
28915 	   " ", infobg, CNTCOL);
28916   dbut[BCONT].explstr = "toggle contours on/off in the 3D plot.";
28917   DefBut(&dbut[BMOL],   winC, D3OFFX+BOFFX, D3OFFY+24+BUTTN*3, TOGGWH, TOGGWH,
28918 	   " ", infobg, CNTCOL);
28919   dbut[BMOL].explstr = "toggle molecule on/off in the 3D plot.";
28920 
28921   DefBut(&dbut[BSTEP],  winC, CNOFFX+BOFFX, CNOFFY+24+BUTTN*0, 60, BUTTH,
28922 	   "Step", infobg, CNTCOL);
28923   dbut[BSTEP].explstr = "function value increment between\nconsequtive contour lines ";
28924   DefBut(&dbut[BCUT],   winC, CNOFFX+BOFFX, CNOFFY+24+BUTTN*1, 60, BUTTH,
28925 	   "Cut", infobg, CNTCOL);
28926   dbut[BCUT].explstr = "contours above cutoff are not shown";
28927 
28928   DefBut(&dbut[BFILL],  winC, SPOFFX+BOFFX, SPOFFY+24, TOGGWH, TOGGWH,
28929 	   " ", infobg, CNTCOL);
28930 
28931   DefBut(&dbut[BWRBAS], winC, BSOFFX+BOFFX, BSOFFY+24+BUTTN*0, 70, BUTTH,
28932 	   "Write Grid", infobg, CNTCOL);
28933   dbut[BWRBAS].explstr = "write 2D/3D grid as\ngridfile/3dgrifile";
28934   DefBut(&dbut[BRDBAS], winC, BSOFFX+BOFFX, BSOFFY+24+BUTTN*1, 70, BUTTH,
28935 	   "Read Grid", infobg, CNTCOL);
28936   dbut[BRDBAS].explstr = "read 2D/3D grid as\ngridfile/3dgrifile";
28937 
28938   DefBut(&dbut[BCUBE],  winC, QOFFX+BOFFX, QOFFY+3, 70, BUTTH,
28939 	   "Rd/Wr Cube", infobg, CNTCOL);
28940   dbut[BCUBE].explstr = "read/write Gaussian cube file (3D grid)";
28941 
28942   DefBut(&dbut[BQUIT],  winC, QOFFX+BOFFX+80, QOFFY+1, 22, 22,
28943 	   "Quit", infobg, CNTCOL);
28944   dbut[BQUIT].explstr = "exit molden";
28945 
28946   DefBut(&dbut[BGIF2],  winC, MSOFFX+BOFFX+90, MSOFFY+24+BUTTN*2, 22, 22,
28947 	   "Quit", infobg, CNTCOL);
28948   dbut[BGIF2].explstr = "Make a gif file of each screen update.";
28949 
28950   DefBut(&dbut[BLOCAL], winC, PLOFFX+BOFFX+65, PLOFFY+24, 60, BUTTH,
28951 	   "Local", infobg, CNTCOL);
28952   dbut[BLOCAL].explstr = "Boys localization of orbitals";
28953 
28954 #ifdef DOGL
28955   DefBut(&dbut[BOGL],  winC, PMOFFX+93, PMOFFY+21, 24, 24,
28956 	   "Ogl", infobg, CNTCOL);
28957   dbut[BOGL].explstr = "switch between Xwindows (primitive)\nand OpenGL (quality) rendering";
28958 #endif
28959 
28960   dbut[BVRML2].pix = VRMLPix;
28961   dbut[BVRML2].pw  = vrml_width;
28962   dbut[BVRML2].ph  = vrml_height;
28963 
28964   dbut[BSRF2].pix = SurfPix;
28965   dbut[BSRF2].pw  = surf_width;
28966   dbut[BSRF2].ph  = surf_height;
28967 
28968   dbut[BQUIT].pix = SkullPix;
28969   dbut[BQUIT].pw  = skull_width;
28970   dbut[BQUIT].ph  = skull_height;
28971 
28972   dbut[BGIF2].pix = FotoPix;
28973   dbut[BGIF2].pw  = foto_width;
28974   dbut[BGIF2].ph  = foto_height;
28975 
28976 #ifdef DOGL
28977   dbut[BOGL].pix = OGLPix;
28978   dbut[BOGL].pw  = ogl_width;
28979   dbut[BOGL].ph  = ogl_height;
28980 
28981   if (*ifdogl) TogDown(&dbut[BOGL]);
28982   else TogUp(&dbut[BOGL]);
28983 #endif
28984 
28985   WinObj[1].win = &winC;
28986   WinObj[1].subwin = &subC;
28987   WinObj[1].butarr = dbut;
28988   WinObj[1].numbut = NBUTTS;
28989   WinObj[1].winup = NULL;
28990   WinObj[1].redraw = NULL;
28991 
28992   if (DEBUG) fprintf(stderr,"CreatewinC out\n");
28993 }
28994 
28995 
CreatewinMC(geom)28996 void CreatewinMC(geom)
28997 char *geom;
28998 {
28999 
29000 
29001   if (DEBUG) fprintf(stderr,"CreatewinMC in\n");
29002 
29003   winMC = CreateWindow("Molden Control",geom,WINMCWIDE, WINMCHIGH, infobg, infofg,(Window)0);
29004 
29005   subMC = CreateWindow("Subwindow","",10,10,
29006                             colors[0],colors[15],winMC);
29007 
29008   DefBut(&cbut[BFIRST], winMC, POFFX+BOFFX , POFFY+24         , 60, BUTTH,
29009 	   "First", infobg, CNTCOL);
29010   cbut[BFIRST].explstr = "When multiple structures available:\nMD trajectory, Geometry optimisation etc.\nGo to the first structure";
29011 
29012   DefBut(&cbut[BNEXT] , winMC, POFFX+BOFFX-5 , POFFY+24+BUTTN   , 35, BUTTH,
29013 	   "Next", infobg, CNTCOL);
29014   cbut[BNEXT].explstr = "When multiple structures available:\nMD trajectory, Geometry optimisation etc.\nGo to the next structure";
29015 
29016   DefBut(&cbut[BPREV] , winMC, POFFX+BOFFX+33 , POFFY+24+BUTTN   , 33, BUTTH,
29017 	   "Prev", infobg, CNTCOL);
29018   cbut[BPREV].explstr = "When multiple structures available:\nMD trajectory, Geometry optimisation etc.\nGo to the previous structure";
29019 
29020   DefBut(&cbut[BMOVIE], winMC, POFFX+BOFFX , POFFY+24+BUTTN*2 , 60, BUTTH,
29021 	   "Movie", infobg, CNTCOL);
29022   cbut[BMOVIE].explstr = "When multiple structures available:\nMD trajectory, Geometry optimisation etc.\nDisplay all structures as a movie";
29023 
29024   DefBut(&cbut[BMOLF], winMC,  POFFX+BOFFX+63,  POFFY+22, 24, 24,
29025 	   " ", infobg, CNTCOL);
29026   cbut[BMOLF].explstr = "Multiple outputs available in\nMolden format file\nClick two select output";
29027 
29028   DefBut(&cbut[BHOUR], winMC,  POFFX+BOFFX+70 , POFFY+24+BUTTN , 20, 25,
29029 	   " ", infobg, CNTCOL);
29030   cbut[BHOUR].explstr = "Set Minimum time\nbetween Movie frames";
29031 
29032 
29033   DefBut(&cbut[BSOLID], winMC, DMOFFX+BOFFX, DMOFFY+24        , TOGGWH, TOGGWH,
29034 	   " ", infobg, CNTCOL);
29035   cbut[BSOLID].explstr = "Toggle between stick and\nSolid drawing modes";
29036 
29037   DefBut(&cbut[BATCOL], winMC, DMOFFX+BOFFX, DMOFFY+24+BUTTN  , TOGGWH, TOGGWH,
29038 	   " ", infobg, CNTCOL);
29039   TogDown(&cbut[BATCOL]);
29040   cbut[BATCOL].explstr = "Color by Atom or\nSubstructure (residue)";
29041 
29042   DefBut(&cbut[BSHADE], winMC, DMOFFX+BOFFX, DMOFFY+24+BUTTN*2, TOGGWH, TOGGWH,
29043 	   " ", infobg, CNTCOL);
29044   cbut[BSHADE].explstr = "Apply depth shading";
29045 
29046   DefBut(&cbut[BPERSP], winMC, DMOFFX+BOFFX, DMOFFY+24+BUTTN*3, TOGGWH, TOGGWH,
29047 	   " ", infobg, CNTCOL);
29048   cbut[BPERSP].explstr = "Toggle Perspective or\nOrthographic projection";
29049 
29050   DefBut(&cbut[BLABEL], winMC, DMOFFX+BOFFX, DMOFFY+24+BUTTN*4, TOGGWH, TOGGWH,
29051 	   " ", infobg, CNTCOL);
29052   DefBut(&cbut[BBACKB], winMC, DMOFFX+BOFFX, DMOFFY+24+BUTTN*5, TOGGWH, TOGGWH,
29053 	   "", infobg, CNTCOL);
29054   cbut[BBACKB].explstr = "Switch All Atom vs Backbone Atoms Only\nOnly for Protein Structures\nIn Solid mode,\nbackbone is drawn in cartoon style";
29055 
29056   DefBut(&cbut[BZOOMIN],  winMC, XOFFX+10, XOFFY+20+9, 30, 23,
29057 	   "In", infobg, CNTCOL);
29058   cbut[BZOOMIN].explstr = "Translate structure\nalong Z-axis. Alternative:\nCtrl+left mouse button+drag";
29059 
29060   DefBut(&cbut[BZOOMOUT], winMC, XOFFX+10, XOFFY+20+9+BUTTN, 30, 23,
29061 	   "Out", infobg, CNTCOL);
29062   cbut[BZOOMOUT].explstr = "Translate structure\nalong Z-axis. Alternative:\nCtrl+left mouse button+drag";
29063 
29064   DefBut(&cbut[BDENMOD], winMC, MOFFX+BOFFX, MOFFY+24     , 80, BUTTH,
29065 	   "Dens. Mode", infobg, CNTCOL);
29066   cbut[BDENMOD].explstr = "Switch to Density/Orbital mode";
29067 
29068   DefBut(&cbut[BREADF],  winMC, MOFFX+BOFFX-5, MOFFY+24+BUTTN*1, 40, BUTTH,
29069 	   "Read", infobg, CNTCOL);
29070   cbut[BREADF].explstr = "Read new structure from file";
29071 
29072   DefBut(&cbut[BWRITF],  winMC, MOFFX+BOFFX+45, MOFFY+24+BUTTN*1, 45, BUTTH,
29073 	   "Write", infobg, CNTCOL);
29074   cbut[BWRITF].explstr = "Write current structure to file";
29075 
29076   DefBut(&cbut[BZMAT],   winMC, MOFFX+BOFFX, MOFFY+24+BUTTN*2, 80, BUTTH,
29077 	   "ZMAT Editor", infobg, CNTCOL);
29078   cbut[BZMAT].explstr = "Edit internal coordinates of structure\nEdit Phi,Psi,Chi (Proteins Only)\nAnimate internal coordinates\nSubmit Gaussian/Gamess/Mopac jobs";
29079   DefBut(&cbut[BPOSTT],  winMC, MOFFX+BOFFX, MOFFY+24+BUTTN*3, 80, BUTTH,
29080 	   "PostScript", infobg, CNTCOL);
29081 
29082   DefBut(&cbut[BAUTH],   winMC, MIOFFX+6, MIOFFY+MICONY, 24, 24,
29083 	   "Auth", infobg, CNTCOL);
29084   cbut[BAUTH].explstr = "Apply force field\nOptimise with Amber/GAFF/Tinker\nSet atom properties:\nStickColor, Residue, Charge";
29085 
29086   DefBut(&cbut[BGIF],    winMC, MIOFFX+6, MIOFFY+MICONY+4+BUTTN, 24, 24,
29087 	   "Foto", infobg, CNTCOL);
29088   cbut[BGIF].explstr = "picture of each screen update.\nstick mode: GIF";
29089 
29090   DefBut(&cbut[BMOV],    winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*2, 24, 24,
29091 	   "Movie", infobg, CNTCOL);
29092   cbut[BMOV].explstr = "Create movie of screen updates.\n";
29093 
29094   DefBut(&cbut[BPAL],    winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*3, 24, 24,
29095 	   "Palette", infobg, CNTCOL);
29096   cbut[BPAL].explstr = "Change/Set Colors\nElement Properties\nSet Depth Shading";
29097 
29098   DefBut(&cbut[BCELL],   winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*4, 24, 24,
29099 	   "Cell", infobg, CNTCOL);
29100   cbut[BCELL].explstr = "Display/Create/Edit\nCrystal Structures";
29101 
29102   DefBut(&cbut[BORIG],   winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*5, 24, 24,
29103 	   "Origin", infobg, CNTCOL);
29104   cbut[BORIG].explstr = "Click on an atom\nto set new origin";
29105 
29106   DefBut(&cbut[BSURF],   winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*6, 24, 24,
29107 	   "Surface", infobg, CNTCOL);
29108   cbut[BSURF].explstr = "Create Surfaces,\nCalculate Charges,\nMultipoles,Dipole";
29109 
29110   DefBut(&cbut[BVRML],   winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*7, 24, 24,
29111 	   "VRML", infobg, CNTCOL);
29112   cbut[BVRML].explstr = "Virtual Reality Modeling Language,\nPovray, OpenGl helper program";
29113 
29114   DefBut(&cbut[BHYD],    winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*8, 24, 24,
29115 	   "Quit", infobg, CNTCOL);
29116   cbut[BHYD].explstr = "(Re)Calculate Hydrogen Bonds,\nSet Parameters Hydrogen Bonds,\n(Un)Display Hydrogens";
29117 
29118   DefBut(&cbut[BALIGN],  winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*9, 24, 24,
29119 	   "Align", infobg, CNTCOL);
29120   cbut[BALIGN].explstr = "Align two molecules,\nInteractive Docking";
29121 
29122   DefBut(&cbut[BQUITT],  winMC, MIOFFX+6, MIOFFY+MICONY+(4+BUTTN)*10, 24, 24,
29123 	   "Quit", infobg, CNTCOL);
29124   cbut[BQUITT].explstr = "Exit Molden";
29125 
29126 
29127   DefBut(&cbut[BDIST],  winMC, CLOFFX+BOFFX, CLOFFY+24        , 80, BUTTH,
29128 	   "Distance", infobg, CNTCOL);
29129   cbut[BDIST].explstr = "Calculate interatomic distance\nClick on two atoms";
29130 
29131   DefBut(&cbut[BANGLE], winMC, CLOFFX+BOFFX, CLOFFY+24+BUTTN*1, 80, BUTTH,
29132 	   "Angle", infobg, CNTCOL);
29133   cbut[BANGLE].explstr = "Calculate angle\nClick on three atoms";
29134 
29135   DefBut(&cbut[BDIHED], winMC, CLOFFX+BOFFX, CLOFFY+24+BUTTN*2, 80, BUTTH,
29136 	   "Dihedral", infobg, CNTCOL);
29137   cbut[BDIHED].explstr = "Calculate dihedral angle\nClick on four atoms";
29138 
29139   DefBut(&cbut[BCONV],  winMC, CVOFFX+BOFFX, CVOFFY+24        , 80, BUTTH,
29140 	   "SCF conv.", infobg, CNTCOL);
29141   cbut[BCONV].explstr = "Self Consistent Field convergence\nGamess/Gaussian/Molf Only";
29142 
29143   DefBut(&cbut[BGEOM],  winMC, CVOFFX+BOFFX, CVOFFY+24+BUTTN*1, 80, BUTTH,
29144 	   "Geom. conv.", infobg, CNTCOL);
29145   cbut[BGEOM].explstr = "Geometry convergence, for\nmultiple structures combined\nwith Energy/Step/Force info";
29146 
29147   DefBut(&cbut[BLEFT],  winMC, XOFFX+50   , XOFFY+5+BUTTN*1, 23, 23,
29148 	   "<", infobg, CNTCOL);
29149   cbut[BLEFT].explstr = "Translate structure\nalong X-axis. Alternative:\nShift+left mouse button+drag";
29150 
29151   DefBut(&cbut[BRIGHT], winMC, XOFFX+50+50, XOFFY+5+BUTTN*1, 23, 23,
29152 	   ">", infobg, CNTCOL);
29153   cbut[BRIGHT].explstr = "Translate structure\nalong X-axis. Alternative:\nShift+left mouse button+drag";
29154 
29155   DefBut(&cbut[BUP],    winMC, XOFFX+50+25, XOFFY+5        , 23, 23,
29156 	   "^", infobg, CNTCOL);
29157   cbut[BUP].explstr = "Translate structure\nalong Y-axis. Alternative:\nShift+left mouse button+drag";
29158 
29159   DefBut(&cbut[BDOWN],  winMC, XOFFX+50+25, XOFFY+5+BUTTN*2, 23, 23,
29160 	   "v", infobg, CNTCOL);
29161   cbut[BDOWN].explstr = "Translate structure\nalong Y-axis. Alternative:\nShift+left mouse button+drag";
29162 
29163   DefBut(&cbut[BPACE],  winMC, XOFFX+50+25, XOFFY+5+BUTTN*1, 23, 23,
29164 	   " ", infobg, CNTCOL);
29165   cbut[BPACE].explstr = "In old style rotation\nSet rotation increment:\nSmall,Medium or Large";
29166 
29167   DefBut(&cbut[BBALL],  winMC, XOFFX+50+65, XOFFY+5+BUTTN*2+7, 15, 15,
29168 	   " ", infobg, CNTCOL);
29169   cbut[BBALL].explstr = "Toggle: default rotation style/\nold style rotation";
29170 
29171   DefBut(&cbut[BJCPL],  winMC, CLOFFX+BOFFX+70, CLOFFY+5, 15, 15,
29172 	   "J", infobg, CNTCOL);
29173   cbut[BJCPL].explstr = "Calculate J coupling two atoms";
29174 
29175   if ( colcells < 16 ) ActBut(&cbut[BSHADE],0);
29176   if (monoscr) ActBut(&cbut[BATCOL],0);
29177 
29178   cbut[BUP].pix = upPix;
29179   cbut[BUP].pw  = up_width;
29180   cbut[BUP].ph  = up_height;
29181 
29182   cbut[BDOWN].pix = downPix;
29183   cbut[BDOWN].pw  = down_width;
29184   cbut[BDOWN].ph  = down_height;
29185 
29186   cbut[BLEFT].pix = lPix;
29187   cbut[BLEFT].pw  = l_width;
29188   cbut[BLEFT].ph  = l_height;
29189 
29190   cbut[BRIGHT].pix = rPix;
29191   cbut[BRIGHT].pw  = r_width;
29192   cbut[BRIGHT].ph  = r_height;
29193 
29194   cbut[BBALL].pix = ballPix;
29195   cbut[BBALL].pw  = ball_width;
29196   cbut[BBALL].ph  = ball_height;
29197 
29198   cbut[BAUTH].pix = FFPix;
29199   cbut[BAUTH].pw  = ff_width;
29200   cbut[BAUTH].ph  = ff_height;
29201 
29202   cbut[BMOLF].pix = MLFPix;
29203   cbut[BMOLF].pw  = mlf_width;
29204   cbut[BMOLF].ph  = mlf_height;
29205 
29206 /* Old, sigh
29207   cbut[BAUTH].pix = gPix;
29208   cbut[BAUTH].pw  = g_width;
29209   cbut[BAUTH].ph  = g_height;
29210 */
29211 
29212   cbut[BQUITT].pix = SkullPix;
29213   cbut[BQUITT].pw  = skull_width;
29214   cbut[BQUITT].ph  = skull_height;
29215 
29216   cbut[BHYD].pix = HPix;
29217   cbut[BHYD].pw  = hbit_width;
29218   cbut[BHYD].ph  = hbit_height;
29219 
29220   cbut[BORIG].pix = OrigPix;
29221   cbut[BORIG].pw  = orig_width;
29222   cbut[BORIG].ph  = orig_height;
29223 
29224   cbut[BSURF].pix = SurfPix;
29225   cbut[BSURF].pw  = surf_width;
29226   cbut[BSURF].ph  = surf_height;
29227 
29228   cbut[BVRML].pix = VRMLPix;
29229   cbut[BVRML].pw  = vrml_width;
29230   cbut[BVRML].ph  = vrml_height;
29231 
29232   cbut[BALIGN].pix = AlignPix;
29233   cbut[BALIGN].pw  = align_width;
29234   cbut[BALIGN].ph  = align_height;
29235 
29236   cbut[BCELL].pix = CellPix;
29237   cbut[BCELL].pw  = cell_width;
29238   cbut[BCELL].ph  = cell_height;
29239 
29240   cbut[BGIF].pix = FotoPix;
29241   cbut[BGIF].pw  = foto_width;
29242   cbut[BGIF].ph  = foto_height;
29243 
29244   cbut[BPAL].pix = ColPix;
29245   cbut[BPAL].pw  = palette_width;
29246   cbut[BPAL].ph  = palette_height;
29247 
29248   cbut[BHOUR].pix = HourPix;
29249   cbut[BHOUR].pw  = hourglass_width;
29250   cbut[BHOUR].ph  = hourglass_height;
29251 
29252   cbut[BMOV].pix = movPix;
29253   cbut[BMOV].pw  = film_width;
29254   cbut[BMOV].ph  = film_height;
29255 
29256   cbut[BPACE].pw  = pace_width;
29257   cbut[BPACE].ph  = pace_height;
29258   if (coarse==2) cbut[BPACE].pix = blastPix;
29259   else if(coarse==1) cbut[BPACE].pix = fastPix;
29260   else cbut[BPACE].pix = slowPix;
29261   if (*ball) TogDown(&cbut[BBALL]);
29262   else TogUp(&cbut[BBALL]);
29263   if (*shade) TogDown(&cbut[BSHADE]);
29264   else TogUp(&cbut[BSHADE]);
29265 
29266   WinObj[0].win = &winMC;
29267   WinObj[0].subwin = &subMC;
29268   WinObj[0].butarr = cbut;
29269   WinObj[0].numbut = NBUTTS2;
29270   WinObj[0].winup = NULL;
29271   WinObj[0].redraw = NULL;
29272 
29273   if (DEBUG) fprintf(stderr,"CreatewinMC out\n");
29274 }
29275 
29276 /***************************************************/
DirBox(hwin,vis)29277 void DirBox(hwin,vis)
29278 Window  hwin;
29279 int vis;
29280 {
29281   if (vis) XMapRaised(display, hwin);
29282   else     XUnmapWindow(display, hwin);
29283 
29284 }
29285 
29286 
29287 /***************************************************/
RedrawwinC(x,y,w,h)29288 void RedrawwinC(x,y,w,h)
29289 int x,y,w,h;
29290 {
29291   int  i;
29292   XRectangle xr;
29293 
29294   if (DEBUG) fprintf(stderr,"RedrawwinC in\n");
29295   xr.x = x;  xr.y = y;  xr.width = w;  xr.height = h;
29296   XSetClipRectangles(display, gc, 0,0, &xr, 1, Unsorted);
29297 
29298   if (monoscr) {
29299 	XSetFillStyle(display, gc, FillStippled);
29300 	XSetStipple(display, gc, grayStip);
29301 	XSetForeground(display, gc, infobg);
29302 	XFillRectangle(display, winC, gc, PLOFFX, PLOFFY+22,120 ,198);
29303 	XFillRectangle(display, winC, gc, MSOFFX, MSOFFY+22,120 ,102);
29304 	XFillRectangle(display, winC, gc, PMOFFX, PMOFFY+22,120 ,73);
29305 	XFillRectangle(display, winC, gc, D3OFFX, D3OFFY+22,120 ,52);
29306 	XFillRectangle(display, winC, gc, CNOFFX, CNOFFY+22,120 ,50);
29307 	XFillRectangle(display, winC, gc, BSOFFX, BSOFFY+22,120 ,50);
29308 	XSetForeground(display, gc, infofg);
29309 	XSetFillStyle(display, gc, FillSolid);}
29310   else {
29311 	butje(winC,PLOFFX,PLOFFY,140,220,1,0,0,1,None,0,0,0);
29312 	butje(winC,MSOFFX,MSOFFY,140,124,1,0,0,1,None,0,0,0);
29313 	butje(winC,SPOFFX,SPOFFY,140,50,1,0,0,1,None,0,0,0);
29314 	butje(winC,PMOFFX,PMOFFY,120,95,1,0,0,1,None,0,0,0);
29315 	butje(winC,D3OFFX,D3OFFY,120,126,1,0,0,1,None,0,0,0);
29316 	butje(winC,CNOFFX,CNOFFY,120,75,1,0,0,1,None,0,0,0);
29317 	butje(winC,BSOFFX,BSOFFY,120,75,1,0,0,1,None,0,0,0);
29318 	butje(winC,QOFFX,QOFFY,120,25,1,0,0,1,None,0,0,0);
29319   }
29320 
29321 
29322   for (i=0; i<NBUTTS; i++)
29323 	DrwBut(&dbut[i]);
29324 
29325   ULineString(winC, "Plot Function:"  , PLOFFX+BOFFX, PLOFFY+15);
29326   ULineString(winC, "Miscellaneous:"  , MSOFFX+BOFFX, MSOFFY+15);
29327   ULineString(winC, "Plot Mode:"      , PMOFFX+30   , PMOFFY+15);
29328   ULineString(winC, "3D subcommands:" , D3OFFX+BOFFX, D3OFFY+15);
29329   ULineString(winC, "Contour subcomm.", CNOFFX+BOFFX, CNOFFY+15);
29330   ULineString(winC, "Space subcomm."  , SPOFFX+BOFFX, SPOFFY+15);
29331   ULineString(winC, "Basisset Differ.", BSOFFX+BOFFX, BSOFFY+15);
29332   ULineString(winC, "Status line:"    , S2OFFX+5 , S2OFFY);
29333 
29334   LineString(winC, "Orient"  , PLOFFX+BOFFX+88,PLOFFY+50+BUTTN*4);
29335   LineString(winC, "Fill"    , SPOFFX+BOFFX+28, SPOFFY+38);
29336   LineString(winC, "Contours", D3OFFX+BOFFX+28, D3OFFY+38+BUTTN*2);
29337   LineString(winC, "Molecule", D3OFFX+BOFFX+28, D3OFFY+38+BUTTN*3);
29338 
29339   XDrawRectangle(display, winC, gc, S2OFFX, S2OFFY+7,240 ,20);
29340   XDrawString(display,winC,gc,S2OFFX+5,S2OFFY+20,densstr,MINI(MAXSTRLMW,strlen(densstr)));
29341 
29342   XSetClipMask(display, gc, None);
29343   if (DEBUG) fprintf(stderr,"RedrawwinC out\n");
29344 }
29345 
29346 
29347 /***************************************************/
RedrawwinMC(x,y,w,h)29348 void RedrawwinMC(x,y,w,h)
29349 int x,y,w,h;
29350 {
29351   int  i,r;
29352 
29353   if (DEBUG) fprintf(stderr,"RedrawwinMC in\n");
29354 
29355   if (monoscr) {
29356 	XSetForeground(display, gc, infobg);
29357 	XSetBackground(display, gc, infofg);
29358 	XSetFillStyle(display, gc, FillOpaqueStippled);
29359 	XSetStipple(display, gc, grayStip);
29360 	XFillRectangle(display, winMC, gc, POFFX+5, POFFY+22 ,98 ,80);
29361 	XFillRectangle(display, winMC, gc, MOFFX+5, MOFFY+22 ,98 ,95);
29362 	if (!pdb) XFillRectangle(display, winMC, gc, FOFFX, 48,100 ,95);
29363 	XFillRectangle(display, winMC, gc, CLOFFX, CLOFFY+22,100 ,72);
29364 	XFillRectangle(display, winMC, gc, CVOFFX, CVOFFY+22,100 ,52);
29365 	XSetFillStyle(display, gc, FillSolid);
29366 	XSetForeground(display, gc, infofg);
29367 	if (pdb) XFillRectangle(display, winMC, gc, FOFFX, FOFFY,100 ,146);
29368 	else XFillRectangle(display, winMC, gc, FOFFX, FOFFY,110 ,44);
29369   }
29370   else {
29371 	r = 1;
29372 	if (DoIntel) r = 2;
29373 	butje(winMC,POFFX,POFFY,108,101,r,0,0,1,None,0,0,0);
29374 	butje(winMC,MOFFX,MOFFY,108,125,r,0,0,1,None,0,0,0);
29375 	butje(winMC,DMOFFX,DMOFFY,108,176,r,0,0,1,None,0,0,0);
29376 
29377 	butje(winMC,MIOFFX,MIOFFY,35,315,r,0,0,1,None,0,0,0);
29378 
29379 	butje(winMC,FOFFX,FOFFY,107,146,r,0,0,1,None,0,0,0);
29380 	butje(winMC,CLOFFX,CLOFFY,107,96,r,0,0,1,None,0,0,0);
29381 	butje(winMC,CVOFFX,CVOFFY,107,75,r,0,0,1,None,0,0,0);
29382 
29383 	butje(winMC,XOFFX,XOFFY,141,86,r,0,0,1,None,0,0,0);
29384   }
29385 
29386 
29387 
29388   for (i=0; i<NBUTTS2; i++) {
29389 	if (! ( (i == BMOLF && ntits <= 1) ||
29390 	        (i == BJCPL && nmrptr->ihsnmr != 2) ) )
29391 	   DrwBut(&cbut[i]);
29392   }
29393 
29394   ULineString(winMC, "Select Point:", POFFX+BOFFX , POFFY+15);
29395   ULineString(winMC, "Draw Mode:"   , DMOFFX+BOFFX , DMOFFY+15);
29396   ULineString(winMC, "Zoom:"        , XOFFX+10 , XOFFY+20);
29397   if (pdb) {
29398 	ULineString(winMC, "Add to BackBone:", FOFFX+BOFFX, FOFFY+15);
29399 	LineString(winMC, "SulfurBridge",      FOFFX+BOFFX+20, FOFFY+38+BUTTN*3);
29400 	LineString(winMC, "H-bonds",           FOFFX+BOFFX+20, FOFFY+38+BUTTN*4);
29401   } else {
29402 	if (frfor) {
29403 	   if (nmrptr->ihsnmr) {
29404 		ULineString(winMC, "Spectrum:", FOFFX+BOFFX , FOFFY+15);
29405 		LineString(winMC, "NMR Spectr."         ,
29406 			FOFFX+BOFFX+20 , FOFFY+38);
29407 	   } else if (*ihasex) {
29408 		ULineString(winMC, "Spectrum:", FOFFX+BOFFX , FOFFY+15);
29409 		LineString(winMC, "UV spectrum"         ,
29410 			FOFFX+BOFFX+20 , FOFFY+38);
29411 	   } else {
29412 		ULineString(winMC, "Frequecies:", FOFFX+BOFFX , FOFFY+15);
29413 		LineString(winMC, "Norm. Mode"         ,
29414 			FOFFX+BOFFX+20 , FOFFY+38);
29415 	   }
29416 	} else {
29417 	   ULineString(winMC, "Render Forces:", FOFFX+BOFFX , FOFFY+15);
29418 	   LineString(winMC, "Forces"         , FOFFX+BOFFX+28 , FOFFY+38);
29419 	}
29420   }
29421 
29422   ULineString(winMC, "Calculate :"   , CLOFFX+BOFFX, CLOFFY+15);
29423   ULineString(winMC, "Miscellaneous:", MOFFX+BOFFX , MOFFY+15);
29424   ULineString(winMC, "Status line:"  , SOFFX+5  , SOFFY);
29425   ULineString(winMC, "Convergence:"  , CVOFFX+BOFFX, CVOFFY+15);
29426 
29427   LineString(winMC, "Solid",      DMOFFX+BOFFX+28, DMOFFY+38);
29428   LineString(winMC, "StickColor", DMOFFX+BOFFX+28, DMOFFY+38+BUTTN);
29429   LineString(winMC, "Shade",      DMOFFX+BOFFX+28, DMOFFY+38+BUTTN*2);
29430   LineString(winMC, "Perspect.",     DMOFFX+BOFFX+28, DMOFFY+38+BUTTN*3);
29431   LineString(winMC, "Label",      DMOFFX+BOFFX+28, DMOFFY+38+BUTTN*4);
29432   LineString(winMC, "BackBone",   DMOFFX+BOFFX+28, DMOFFY+38+BUTTN*5);
29433 
29434   XDrawRectangle(display, winMC, gc, SOFFX, SOFFY+7,240 ,20);
29435   XDrawString(display,winMC,gc,SOFFX+5,SOFFY+20,molwstr,MINI(MAXSTRLMW,strlen(molwstr)));
29436 
29437   if (DEBUG) fprintf(stderr,"RedrawwinMC out\n");
29438 }
29439 
RedrawCOMMwin()29440 void RedrawCOMMwin()
29441 {
29442   int xboff,yboff,boff;
29443 
29444   xboff = 10; boff = 20; yboff = boff+30;
29445   XSetForeground(display, gc, infobg);
29446   PromptBox(&qboxes[QCOMM]);
29447 
29448   butje(COMMwin,0,yboff-boff,QBOXWIDE,QBOXTX-boff-10,4,0,0,1,None,0,0,0);
29449   XDrawString(display,COMMwin,gc,xboff,yboff ,
29450   "The following commands are available:",37);
29451   XDrawString(display,COMMwin,gc,xboff,yboff+20 ,
29452   "Plane  = (atom1,atom2,atom3)  3 atoms define the plotplane             ",71);
29453   XDrawString(display,COMMwin,gc,xboff,yboff+30 ,
29454   "Rot    = (atom1,atom2,nnn.nn) rotate this plane  n.nn degrees around   ",71);
29455   XDrawString(display,COMMwin,gc,xboff,yboff+40 ,
29456   "                              the axis from atom1 and atom2, which must",71);
29457   XDrawString(display,COMMwin,gc,xboff,yboff+50 ,
29458   "                              be one of the atoms used with plane      ",71);
29459   XDrawString(display,COMMwin,gc,xboff,yboff+60 ,
29460   "Center = atom1                coordinates of atom1 define plane center ",71);
29461   XDrawString(display,COMMwin,gc,xboff,yboff+70,
29462   "Center = (n.nn,n.nn,n.nn)     specify coordinates for plane center     ",71);
29463   XDrawString(display,COMMwin,gc,xboff,yboff+80,
29464   "Line   = atom1                vector; plane center - atom1 taken as    ",71);
29465   XDrawString(display,COMMwin,gc,xboff,yboff+90,
29466   "                              the outvector of the plotplane           ",71);
29467   XDrawString(display,COMMwin,gc,xboff,yboff+100,
29468   "Line   = (n.nn,n.nn,n.nn)     specify the outvector of the plotplane   ",71);
29469   XDrawString(display,COMMwin,gc,xboff,yboff+110,
29470   "Edge   = n.nn                 specify the size of the plotplane        ",71);
29471   XDrawString(display,COMMwin,gc,xboff,yboff+120,
29472   "Lift   = n.nn                 translate the center of the plotplane    ",71);
29473   XDrawString(display,COMMwin,gc,xboff,yboff+130,
29474   "                              along the outvector of the plane         ",71);
29475   XDrawString(display,COMMwin,gc,xboff,yboff+150,
29476   "Where atom[1-n] is an integer indicating the atoms number in the list  ",71);
29477   XDrawString(display,COMMwin,gc,xboff,yboff+170,
29478   "align                         center graph = center molecule           ",71);
29479   XDrawString(display,COMMwin,gc,xboff,yboff+180,
29480   "phase                         toggle the phase (sign) of the plot      ",71);
29481   XDrawString(display,COMMwin,gc,xboff,yboff+200,
29482   "nptsx  = n                    number of points in the x-direction      ",71);
29483   XDrawString(display,COMMwin,gc,xboff,yboff+210,
29484   "nptsy  = n                    number of points in the y-direction      ",71);
29485   XDrawString(display,COMMwin,gc,xboff,yboff+220,
29486   "nptsz  = n                    number of points in the z-direction      ",71);
29487   XDrawString(display,COMMwin,gc,xboff,yboff+230,
29488   "edx    = n.nn                 size of the plotplane in the x-direction ",71);
29489   XDrawString(display,COMMwin,gc,xboff,yboff+240,
29490   "edy    = n.nn                 size of the plotplane in the y-direction ",71);
29491   XDrawString(display,COMMwin,gc,xboff,yboff+250,
29492   "edz    = n.nn                 size of the plotplane in the z-direction ",71);
29493 }
29494 
RedrawRESwin()29495 void RedrawRESwin()
29496 {
29497   int i;
29498   int xboff,yboff,boff;
29499 
29500   xboff = 10; boff = 20; yboff = boff+30;
29501   XSetForeground(display, gc, infobg);
29502   PromptBox(&qboxes[QRESI]);
29503 
29504   butje(RESwin,0,yboff-boff,QBOXWIDE,QBOXTX-boff-10,4,0,0,1,None,0,0,0);
29505   XDrawString(display,RESwin,gc,xboff,yboff ,
29506   "The following commands are available:",37);
29507   XDrawString(display,RESwin,gc,xboff,yboff+20 ,
29508   "all [amino|nucl] [col] [surf] display all residues                     ",71);
29509   XDrawString(display,RESwin,gc,xboff,yboff+30 ,
29510   "clear [surf]                  clear all displayed residues             ",71);
29511   XDrawString(display,RESwin,gc,xboff,yboff+40 ,
29512   "ala [col] [surf]              display all alanines                     ",71);
29513   XDrawString(display,RESwin,gc,xboff,yboff+50 ,
29514   "                              Valid strings are:                       ",71);
29515   XDrawString(display,RESwin,gc,xboff,yboff+60 ,
29516   "                              gly ala ser cys thr ile val met asp asn  ",71);
29517   XDrawString(display,RESwin,gc,xboff,yboff+70,
29518   "                              leu lys glu gln pro arg his phe tyr trp  ",71);
29519   XDrawString(display,RESwin,gc,xboff,yboff+80,
29520   "pos [col] [surf]              positively charged residues: lys arg his ",71);
29521   XDrawString(display,RESwin,gc,xboff,yboff+90,
29522   "neg [col] [surf]              negatively charged residues: asp glu     ",71);
29523   XDrawString(display,RESwin,gc,xboff,yboff+100,
29524   "cha [col] [surf]              charged residues: pos + neg              ",71);
29525   XDrawString(display,RESwin,gc,xboff,yboff+110,
29526   "pol [col] [surf]              polar residues: cha + ser thr asn gln    ",71);
29527   XDrawString(display,RESwin,gc,xboff,yboff+120,
29528   "aro [col] [surf]              aromatic aminoacids: phe + tyr + trp     ",71);
29529   XDrawString(display,RESwin,gc,xboff,yboff+130,
29530   "ali [col] [surf]              display all aliphatic aminoacids:        ",71);
29531   XDrawString(display,RESwin,gc,xboff,yboff+140,
29532   "                              gly + ala + val + leu + ile + pro        ",71);
29533   XDrawString(display,RESwin,gc,xboff,yboff+150,
29534   "(aikknx) [col] [surf]         display all aminoacids specified by one  ",71);
29535   XDrawString(display,RESwin,gc,xboff,yboff+160,
29536   "                              letter code pattern (max. 20 residues)   ",71);
29537   XDrawString(display,RESwin,gc,xboff,yboff+170,
29538   "hel [rod | ball] [incl] [col] helix      [display type] [+backbone]    ",71);
29539   XDrawString(display,RESwin,gc,xboff,yboff+180,
29540   "bet [rod | ball] [incl] [col] beta sheet [display type] [+backbone]    ",71);
29541   XDrawString(display,RESwin,gc,xboff,yboff+200,
29542   "All previous symbols can be combined, and negated by the use of: not   ",71);
29543   XDrawString(display,RESwin,gc,xboff,yboff+220,
29544   "20-30[:ChainNr] [col] [surf]  display residues number 20 through 31    ",71);
29545   XDrawString(display,RESwin,gc,xboff,yboff+230,
29546   "20-30[:ChainNr] [hel|bet|rnd] set secondary structure of res. 20 to 30 ",71);
29547   XDrawString(display,RESwin,gc,xboff,yboff+240,
29548   "neigh[=r] [surf]              display all neighbours at distance r Angs",71);
29549   XDrawString(display,RESwin,gc,xboff,yboff+250,
29550   "suron [mapped [local|global]] surface drawing mode ON, [map potential] ",71);
29551   XDrawString(display,RESwin,gc,xboff,yboff+260,
29552   "suroff                        switches off surface drawing mode        ",71);
29553   XDrawString(display,RESwin,gc,xboff,yboff+270,
29554   "all surf                      all currently displayed atoms as surface ",71);
29555   XDrawString(display,RESwin,gc,xboff,yboff+280,
29556   "[col]                         color select,if omitted def. per amin.a  ",71);
29557 }
29558 
filecall(char * str)29559 void filecall(char *str)
29560 {
29561 	cpstr(str,gfile,SUBLEN1);
29562 }
29563 
fwincall(char * str)29564 void fwincall(char *str)
29565 {
29566 	getfiles(&fsel,str);
29567 	RedrawFwin(&fsel);
29568 }
29569 
substrcall(char * str)29570 void substrcall(char *str)
29571 {
29572 	getfiles(&fsel,fsel.lastdir);
29573 	RedrawFwin(&fsel);
29574 }
29575 
getpdbcall(char * str)29576 void getpdbcall(char *str)
29577 {
29578 	if (!CheckWGET()) {
29579 	    GetPDBWWW(qboxes[QPDB].str,strname);
29580 	    if (ParseFile(strname,qboxes[QPDB].str)) return;
29581 	}
29582 }
29583 
29584 
29585 
PDBFile(strname)29586 int PDBFile(strname)
29587 char *strname;
29588 {
29589    int naat;
29590    struct stat st_record;
29591 
29592    stat(strname, &st_record);
29593    if (st_record.st_size <= 1) {
29594 	fprintf(stderr,"Empty file !\n");
29595 	return(0);
29596    }
29597 
29598    naat = 0;
29599 
29600    if (!IsBinary(strname)) {
29601 	int ispdb,i;
29602 	FILE *f;
29603 	char cmdfil[MAXCMD];
29604 
29605 	ispdb = 0;
29606 	f = fopen(strname,"r");
29607 
29608 	for (i = 0; i < 10; i++) {
29609 	   fgets(cmdfil,MAXCMD,f);
29610            if (strstr(cmdfil,"HEADER")) ispdb = 1;
29611 
29612 	}
29613 
29614 	if (ispdb) {
29615 	   rewind(f);
29616 	   while (1) {
29617 		if (fgets(cmdfil,MAXCMD,f) == NULL) break;
29618 		if (strstr(cmdfil,"ATOM") || strstr(cmdfil,"HETATM")) naat++;
29619 	   }
29620 	   naat = naat * 3;
29621 	}
29622 	fclose(f);
29623    }
29624    return(naat);
29625 }
29626 
NAtMax(strname)29627 int NAtMax(strname)
29628 char *strname;
29629 {
29630    int mx;
29631 
29632    mx = 0;
29633 
29634    if (!IsBinary(strname)) {
29635 	int i,mxh;
29636 	FILE *f;
29637 	char cmdfil[MAXCMD];
29638 
29639 	f = fopen(strname,"r");
29640 
29641 	rewind(f);
29642 	mx = 0;
29643 	while (1) {
29644 		if (fgets(cmdfil,MAXCMD,f) == NULL) break;
29645 		if (strstr(cmdfil,"V2000")) {
29646 		    sscanf(cmdfil,"%d",&mxh);
29647 		    if (mxh > mx) mx = mxh;
29648 		}
29649 	}
29650 	fclose(f);
29651    }
29652    return(mx);
29653 }
29654 
29655 #define MXSTRFOR 137
29656 
29657 #if defined(VMS) || defined(UNDERSC)
nxtlin(str,istat)29658 void nxtlin(str,istat)
29659 #else
29660 #ifdef CRAY
29661 void NXTLIN(str,istat)
29662 #else
29663 void nxtlin_(str,istat)
29664 #endif
29665 #endif
29666 #ifdef VMS
29667 struct dsc$descriptor_s *str;
29668 #else
29669 #ifdef CRAY
29670 _fcd str;
29671 #else
29672 char *str;
29673 #endif
29674 #endif
29675 int *istat;
29676 {
29677    int i1,i2;
29678    int i,n;
29679    char *t;
29680 
29681    if (COO[istruct] == NULL || nomemf) {
29682 #if defined(VMS) || defined(UNDERSC)
29683 	nxline(str,istat);
29684 #else
29685 #ifdef CRAY
29686 	NXLINE(str,istat);
29687 #else
29688 	nxline_(str,istat);
29689 #endif
29690 #endif
29691 	return;
29692    }
29693 
29694    if (COO[istruct]->memfil.str != NULL) {
29695 
29696 	*istat = 0;
29697 	i1 = COO[istruct]->memfil.line_index[COO[istruct]->memfil.currl];
29698 	COO[istruct]->memfil.currl++;
29699 
29700 	if (COO[istruct]->memfil.currl < COO[istruct]->memfil.nlines) {
29701 	   i2 = COO[istruct]->memfil.line_index[COO[istruct]->memfil.currl];
29702 	   n = i2 - i1 - 1;
29703 	} else {
29704 	   if (COO[istruct]->memfil.currl == COO[istruct]->memfil.nlines) {
29705 		n = COO[istruct]->memfil.size - i1 - 1;
29706 	   } else {
29707 		COO[istruct]->memfil.currl = COO[istruct]->memfil.nlines - 1;
29708 		*istat = 1;
29709 		return;
29710 	   }
29711 	}
29712 
29713 	if (n > MXSTRFOR) n = MXSTRFOR;
29714 
29715 #ifdef VMS
29716    for (i=0; i<n; i++)
29717        {str->dsc$a_pointer[i] = COO[istruct]->memfil.str[i1+i];}
29718 #else
29719 #ifdef CRAY
29720    strncpy(_fcdtocp(str),&COO[istruct]->memfil.str[i1],n);
29721 #else
29722    strncpy(str,&COO[istruct]->memfil.str[i1],(size_t) n);
29723    str[n] = '\0';
29724    for (i=n; i<137; i++) str[i] = ' ';
29725 #endif
29726 #endif
29727 
29728    } else {
29729 
29730 #if defined(VMS) || defined(UNDERSC)
29731    nxline(str,istat);
29732 #else
29733 #ifdef CRAY
29734    NXLINE(str,istat);
29735 #else
29736    nxline_(str,istat);
29737 #endif
29738 #endif
29739 
29740    }
29741 
29742 }
29743 
29744 
29745 #if defined(VMS) || defined(UNDERSC)
redel(str,n)29746 void redel(str,n)
29747 #else
29748 #ifdef CRAY
29749 void REDEL(str,n)
29750 #else
29751 void redel_(str,n)
29752 #endif
29753 #endif
29754 #ifdef VMS
29755 struct dsc$descriptor_s *str;
29756 #else
29757 #ifdef CRAY
29758 _fcd str;
29759 #else
29760 char *str;
29761 #endif
29762 #endif
29763 int *n;
29764 {
29765     int i;
29766     int istat;
29767 
29768    if (COO[istruct] == NULL || nomemf) {
29769 #if defined(VMS) || defined(UNDERSC)
29770     readel(str,n);
29771 #else
29772 #ifdef CRAY
29773     READEL(str,n);
29774 #else
29775     readel_(str,n);
29776 #endif
29777 #endif
29778     return;
29779    }
29780 
29781    if (COO[istruct]->memfil.str != NULL) {
29782     for (i=0; i<*n; i++) {
29783 #if defined(VMS) || defined(UNDERSC)
29784 	nxtlin(str,&istat);
29785 #else
29786 #ifdef CRAY
29787 	NXTLIN(str,&istat);
29788 #else
29789 	nxtlin_(str,&istat);
29790 #endif
29791 #endif
29792     }
29793    } else {
29794 
29795 #if defined(VMS) || defined(UNDERSC)
29796     readel(str,n);
29797 #else
29798 #ifdef CRAY
29799     READEL(str,n);
29800 #else
29801     readel_(str,n);
29802 #endif
29803 #endif
29804 
29805    }
29806 }
29807 
29808 #if defined(VMS) || defined(UNDERSC)
rewmf()29809 void rewmf()
29810 #else
29811 #ifdef CRAY
29812 void REWMF()
29813 #else
29814 void rewmf_()
29815 #endif
29816 #endif
29817 {
29818 #if defined(VMS) || defined(UNDERSC)
29819     rewmd(mfdata->mollin);
29820 #else
29821 #ifdef CRAY
29822     REWMD(mfdata->mollin);
29823 #else
29824     rewmd_(mfdata->mollin);
29825 #endif
29826 #endif
29827 }
29828 
29829 #if defined(VMS) || defined(UNDERSC)
prsqmf()29830 void prsqmf()
29831 #else
29832 #ifdef CRAY
29833 void PRSQMF()
29834 #else
29835 void prsqmf_()
29836 #endif
29837 #endif
29838 {
29839 
29840 #if defined(VMS) || defined(UNDERSC)
29841     prsqmd(mfdata->mollin);
29842 #else
29843 #ifdef CRAY
29844     PRSQMD(mfdata->mollin);
29845 #else
29846     prsqmd_(mfdata->mollin);
29847 #endif
29848 #endif
29849 }
29850 
29851 #if defined(VMS) || defined(UNDERSC)
prsomf()29852 void prsomf()
29853 #else
29854 #ifdef CRAY
29855 void PRSOMF()
29856 #else
29857 void prsomf_()
29858 #endif
29859 #endif
29860 {
29861 
29862 #if defined(VMS) || defined(UNDERSC)
29863     prsomd(mfdata->mollin);
29864 #else
29865 #ifdef CRAY
29866     PRSOMD(mfdata->mollin);
29867 #else
29868     prsomd_(mfdata->mollin);
29869 #endif
29870 #endif
29871 }
29872 
29873 #if defined(VMS) || defined(UNDERSC)
prsgmf(iopt)29874 void prsgmf(iopt)
29875 #else
29876 #ifdef CRAY
29877 void PRSGMF(iopt)
29878 #else
29879 void prsgmf_(iopt)
29880 #endif
29881 #endif
29882 int *iopt;
29883 {
29884 
29885 #if defined(VMS) || defined(UNDERSC)
29886     prsgmd(iopt,mfdata->mollin);
29887 #else
29888 #ifdef CRAY
29889     PRSGMD(iopt,mfdata->mollin);
29890 #else
29891     prsgmd_(iopt,mfdata->mollin);
29892 #endif
29893 #endif
29894 }
29895 
29896 #if defined(VMS) || defined(UNDERSC)
parsmf()29897 void parsmf()
29898 #else
29899 #ifdef CRAY
29900 void PARSMF()
29901 #else
29902 void parsmf_()
29903 #endif
29904 #endif
29905 {
29906 
29907 #if defined(VMS) || defined(UNDERSC)
29908     parsmd(mfdata->mollin);
29909 #else
29910 #ifdef CRAY
29911     PARSMD(mfdata->mollin);
29912 #else
29913     parsmd_(mfdata->mollin);
29914 #endif
29915 #endif
29916 }
29917 
29918 #if defined(VMS) || defined(UNDERSC)
rewfil()29919 void rewfil()
29920 #else
29921 #ifdef CRAY
29922 void REWFIL()
29923 #else
29924 void rewfil_()
29925 #endif
29926 #endif
29927 {
29928 
29929  if (COO[istruct] == NULL || nomemf) {
29930 #if defined(VMS) || defined(UNDERSC)
29931     rwfile();
29932 #else
29933 #ifdef CRAY
29934     RWFILE();
29935 #else
29936     rwfile_();
29937 #endif
29938 #endif
29939     return;
29940  }
29941 
29942  if (COO[istruct]->memfil.str != NULL) {
29943    COO[istruct]->memfil.currl = 0;
29944  } else {
29945 
29946 #if defined(VMS) || defined(UNDERSC)
29947     rwfile();
29948 #else
29949 #ifdef CRAY
29950     RWFILE();
29951 #else
29952     rwfile_();
29953 #endif
29954 #endif
29955 
29956  }
29957 }
29958 
29959 #if defined(VMS) || defined(UNDERSC)
bckfil()29960 void bckfil()
29961 #else
29962 #ifdef CRAY
29963 void BCKFIL()
29964 #else
29965 void bckfil_()
29966 #endif
29967 #endif
29968 {
29969 
29970  if (COO[istruct] == NULL || nomemf) {
29971 #if defined(VMS) || defined(UNDERSC)
29972     bcfile();
29973 #else
29974 #ifdef CRAY
29975     BCFILE();
29976 #else
29977     bcfile_();
29978 #endif
29979 #endif
29980     return;
29981  }
29982 
29983  if (COO[istruct]->memfil.str != NULL) {
29984    COO[istruct]->memfil.currl--;
29985    if (COO[istruct]->memfil.currl < 0) COO[istruct]->memfil.currl = 0;
29986  } else {
29987 
29988 #if defined(VMS) || defined(UNDERSC)
29989     bcfile();
29990 #else
29991 #ifdef CRAY
29992     BCFILE();
29993 #else
29994     bcfile_();
29995 #endif
29996 #endif
29997 
29998  }
29999 }
30000 
30001 
filmem(iopt,strn)30002 void filmem(iopt,strn)
30003 int iopt;
30004 char *strn;
30005 {
30006    FILE *f;
30007    struct stat buf;
30008    int i,n,fd,size,nlines,nfiles,ilin;
30009    int *linidx;
30010    char *string, *tstr, *tstrb;
30011    char maxlin[MAXCMD] = " ";
30012 
30013    f = fopen(strn, "r");
30014 
30015    fd = fileno(f);
30016    fstat(fd, &buf);
30017    size = buf.st_size;
30018 
30019    string = malloc(sizeof(char)*size+1);
30020    size_t nl = fread(string, sizeof(char), size, f);
30021    if (nl == 0) {
30022 	fprintf(stderr,"Error reading file: %s\n", strn);
30023    } else {
30024 	string[size] = 0;
30025    }
30026    fclose(f);
30027 
30028    fileop.str = string;
30029    fileop.size = nl;
30030 
30031    COO[istruct]->ihasmf = 1;
30032 
30033    tstr = string;
30034 
30035    nlines = 0;
30036    while (*tstr != '\0') {
30037 	if (*tstr == '\n')  nlines++;
30038 	tstr++;
30039    }
30040    fileop.nlines = nlines;
30041 
30042    if (iopt) {
30043 
30044 	tstr = string;
30045 	tstrb = tstr;
30046 	nfiles = 0;
30047 
30048 	while (*tstr != '\0') {
30049 	   if (*tstr == '\n') {
30050         	n = (int) (tstr - tstrb);
30051 		strncpy(maxlin,tstrb,n);
30052 		tstrb = tstr;
30053 		tstr++;
30054 		if (strstr(maxlin,"$$$$") != NULL) nfiles++;
30055 		if (strstr(maxlin,"<TRIPOS>MOLECULE") != NULL) nfiles++;
30056 	   } else {
30057 		tstr++;
30058 	   }
30059 	}
30060 	fileop.nfiles = nfiles;
30061 
30062 	if (nfiles > mfdata->maxmol) {
30063 	   if (mfdata->mollin != NULL) free(mfdata->mollin);
30064 	   mfdata->mollin = (int *) malloc(sizeof(int)*nfiles);
30065 	   mfdata->mollin[0] = 0;
30066 	   mfdata->maxmol = nfiles;
30067 	   if (mlftit != NULL) free(mlftit);
30068 	   mlftit = (char **) malloc(sizeof(char *)*nfiles);
30069 	   mxtits = nfiles;
30070 	}
30071    }
30072 
30073    linidx = malloc(sizeof(int)*(nlines+1));
30074    fileop.line_index = linidx;
30075 
30076    ilin = 1;
30077    tstr = string;
30078    linidx[0] = 0;
30079    while (*tstr != '\0') {
30080 	if (*tstr == '\n') {
30081 	   linidx[ilin] = (int) (tstr - string + 1);
30082 	   ilin++;
30083 	}
30084 	tstr++;
30085    }
30086 
30087    COO[istruct]->memfil = fileop;
30088 }
30089 
30090 #if defined(VMS) || defined(UNDERSC)
prsogl()30091 void prsogl()
30092 #else
30093 #ifdef CRAY
30094 void PRSOGL()
30095 #else
30096 void prsogl_()
30097 #endif
30098 #endif
30099 {
30100     selfil = 0;
30101 
30102     if (fsel.files[selfil][0] != '/') {
30103 	strcpy(strname,fsel.lastdir);
30104 #ifndef VMS
30105 	if (strname[strlen(strname)-1] != '/') strcat(strname,"/");
30106 #endif
30107 	strcat(strname,fsel.files[selfil]);
30108     } else strcpy(strname,fsel.files[selfil]);
30109 
30110     ParseFile(strname,fsel.files[selfil]);
30111 }
30112 
ParseFile(strname,shortname)30113 int ParseFile(strname,shortname)
30114 char *strname;
30115 char *shortname;
30116 {
30117    int i,naat;
30118 
30119 #ifdef VMS
30120    for (i=0; i<strlen(strname); i++)
30121 	Sstr->dsc$a_pointer[i] = strname[i];
30122 #else
30123 #ifdef CRAY
30124    strncpy(_fcdtocp(Sstr),strname,strlen(strname));
30125 #else
30126    if (Sstr != NULL) strcpy(Sstr,strname);
30127 #endif
30128 #endif
30129 
30130    *Snstr = strlen(strname);
30131    *Sinct = qboxes[QREADF].qbinct;
30132    *Sincp = addfile;
30133 /*   if (addfile) *Sinct = 481;*/
30134 
30135    doalign = 0;
30136    *irtcel = 0;
30137    if (!addfile) poszset = 0;
30138    *zmptrp->ihaszm = 0;
30139    WinName(win,shortname);
30140 
30141    if (qbres) {
30142 	TogUp(&cbut[BFORC]);
30143 	qbres = 0;
30144 	XUnmapWindow(display,RESwin);
30145    }
30146 
30147    if (frfor && FRup) {
30148 	TogUp(&cbut[BFORC]);
30149 	XDestroyWindow(display,FrBox);
30150 	DoFreq = 0;
30151 	FRup = 0;
30152         *normc = 0;
30153    }
30154 
30155    if (frfor && specup) {
30156 	XDestroyWindow(display,winspec);
30157 	specup = 0;
30158    }
30159 
30160    if (geoup) {
30161 	TogUp(&cbut[BGEOM]);
30162 	XDestroyWindow(display,wingeo);
30163 	geoup = 0;
30164    }
30165 
30166    if (cnvup) {
30167 	XDestroyWindow(display,wincnv);
30168 	cnvup = 0;
30169    }
30170 
30171    if (specup) {
30172 	XDestroyWindow(display,winspec);
30173 	specup = 0;
30174    }
30175 
30176    if (scoup) {
30177 	XDestroyWindow(display,winsco);
30178 	scoup = 0;
30179    }
30180 
30181    if (pmfup) {
30182 	XDestroyWindow(display,winpmf);
30183 	pmfup = 0;
30184    }
30185 
30186    if (MLTup) {
30187 	XDestroyWindow(display,MLTwin);
30188 	MLTup = 0;
30189    }
30190 
30191    ZMEswitch[0].toggle = 1; ZMEAA = 0; EXPbox[0].fake = 1;
30192    RedrawZME(); XSync(display,False);
30193    pdb = 0; oqlen = 0; oqpos = 0;
30194 
30195    DowinC = 1; DoactC = 1; DoactMC = 1;
30196    TogUp(&cbut[BHYD]);
30197    XFlush(display);
30198    aflag = 0; bflag = 0; cflag = 0; dflag = 0;
30199    LastAmino = -1;
30200    CurAmino = -1;
30201    do3dx = 0; *do3d = 1;
30202    FRQ->ihasi = 0;
30203    HETLABSTRU hetlab = {.NHetLab = 0};
30204 
30205    if (!addfile && *multstruct) {
30206 
30207 	if (nstruct == MAXSTRUCT) {
30208 
30209 	    if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
30210 		"Reached maximum number supported structures",0)) {}
30211 
30212 	} else {
30213 
30214 	    if (nstruct == 0 && nfilesstart != 0) {
30215 		SaveFirstStruct();
30216 		nstruct++;
30217 	    }
30218 
30219 	    AllocateStructure(&COO[nstruct]);
30220 
30221 	    if (nstruct != 0) SaveActiveStruct();
30222 
30223 	    if (COO[nstruct] == NULL) {
30224 		   if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
30225 			     "Failed to allocate memory for structure",0)) {}
30226 	    } else {
30227 		   naat = PDBFile(strname);
30228 		   if (naat > 0) {
30229 			AllocateSubStructures(shortname,naat);
30230 			*ipdbon = 1;
30231 			filmem(0,strname);
30232 		   } else {
30233 			AllocateSubStructures(shortname,0);
30234 		   }
30235 		   if (strstr(strname,".sdf")) {
30236 			if (bcksvg.UpSVG) {
30237 			   killob();
30238 			   bcksvg.UpSVG = 0;
30239 			}
30240 			*iftyp = 13;
30241 			filmem(1,strname);
30242 		   }
30243 		   if (strstr(strname,".mol2")) {
30244 			*iftyp = 16;
30245 			ntits = 0;
30246 			filmem(1,strname);
30247 		   }
30248 		   if (strstr(strname,".arc")) {
30249 			FILE *f;
30250 			char cmdfil[MAXCMD];
30251 
30252 			f = fopen(strname,"r");
30253 			fgets(cmdfil,MAXCMD,f);
30254 			fclose(f);
30255 		        if (strstr(cmdfil,"[AMBFOR]")) {
30256 			   *iftyp = 12;
30257 			   filmem(0,strname);
30258 			}
30259 		   }
30260 	    }
30261 	}
30262 
30263         ntits = 0;
30264 
30265    } else {
30266 
30267 /* The addfile == 1 part */
30268 
30269 	if (nstruct == MAXSTRUCT) {
30270 
30271 	    if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
30272 		"Reached maximum number supported structures",0)) {}
30273 
30274 	} else {
30275 
30276 	    if (nstruct == 0 && nfilesstart != 0) {
30277 		SaveFirstStruct();
30278 	    }
30279 	    if (strstr(strname,".sdf")) {
30280 	    	if (*ipdbon == 1) {
30281                     int nato1,mx;
30282 
30283 		    mx = NAtMax(strname);
30284 /*
30285    determine how much atoms have to be moved
30286 */
30287 		    mvhlpat(mx,&nato1);
30288 		    *xyzp->iatoms = *xyzp->iatoms + mx;
30289 		    *iscst = nato1;
30290 	    	}
30291 		*iftyp = 13;
30292 		filmem(1,strname);
30293 	    }
30294 	    if (strstr(strname,".mol2")) {
30295 		ntits = 0;
30296 		*iftyp = 16;
30297 		filmem(0,strname);
30298 	    }
30299 	}
30300    }
30301 
30302 
30303    if (!addfile) {
30304 	*backb = 0;
30305 	empty_model(istruct,1);
30306    }
30307 
30308 #if defined(VMS) || defined(UNDERSC)
30309    curs(&ONE);
30310 #else
30311 #ifdef CRAY
30312    CURS(&ONE);
30313 #else
30314    curs_(&ONE);
30315 #endif
30316 #endif
30317 
30318    if (strstr(strname,".ogl")) {
30319 	if (has_opengl) {
30320 	   if (rdoglfile(strname)) return(0);
30321 	}
30322 #if defined(VMS) || defined(UNDERSC)
30323 	curs(&ZERO);
30324 #else
30325 #ifdef CRAY
30326 	CURS(&ZERO);
30327 #else
30328 	curs_(&ZERO);
30329 #endif
30330 #endif
30331 	*Sinct = 0;
30332         return(0);
30333 
30334    } else {
30335 
30336   	update_sel = 1;
30337   	update_model = 1;
30338 	RedrawFwin(&fsel);
30339         return(1);
30340    }
30341 
30342 }
30343 
ULineString(hwin,str,x,y)30344 void ULineString(hwin,str,x,y)
30345 Window hwin;
30346 char *str;
30347 int x,y;
30348 {
30349   if (str != NULL) {
30350      XDrawString(display, hwin, gc, x, y, str, strlen(str));
30351      XDrawLine(display, hwin, gc, x, y+DESCENT-1,
30352             x+StringWidth(str), y+DESCENT-1);
30353   }
30354 }
30355 
LineString(hwin,str,x,y)30356 void LineString(hwin,str,x,y)
30357 Window hwin;
30358 char *str;
30359 int x,y;
30360 {
30361   if (str != NULL) {
30362 	XDrawString(display, hwin, gc, x, y, str, strlen(str));
30363   }
30364 }
30365 
30366 
createauthor()30367 void createauthor()
30368 {
30369       winau = CreateWindow("Author",DEFAUTHGEOM,
30370               gijsface_width,gijsface_height, infofg, infobg,(Window)0);
30371       XSelectInput(display, winau, ExposureMask |
30372               ButtonPressMask | KeyPressMask);
30373       gijs  = XCreateBitmapFromData(display, winau,
30374               gijsface_bits, gijsface_width, gijsface_height);
30375       XMapWindow(display, winau);
30376 
30377       WinObj[2].win = &winau;
30378       WinObj[2].subwin = NULL;
30379       WinObj[2].butarr = NULL;
30380       WinObj[2].numbut = -1;
30381       WinObj[2].winup = &gijsup;
30382       WinObj[2].redraw = NULL;
30383 }
30384 
DrawTriangle(x,y,xt,yt,r,icol,ifill,iconv)30385 void DrawTriangle(x,y,xt,yt,r,icol,ifill,iconv)
30386 double x;
30387 double y;
30388 int xt;
30389 int yt;
30390 int r;
30391 int icol;
30392 int ifill;
30393 int iconv;
30394 {
30395    int r2,r3,r6;
30396    XPoint box_Xpoint[5];
30397 
30398    r2 = 0.5 * r;
30399    r6 = 0.25*sqrt(6.0)*r;
30400    r3 = sqrt(3.0)*r/3.0;
30401 
30402    if (iconv) {
30403 	glpnt(rwi,rhi,x,y,&xt,&yt,0);
30404    }
30405 
30406    box_Xpoint[0].x = xt;
30407    box_Xpoint[0].y = yt+r3;
30408 
30409    box_Xpoint[1].x = xt+r2;
30410    box_Xpoint[1].y = yt-r6;
30411 
30412    box_Xpoint[2].x = xt-r2;
30413    box_Xpoint[2].y = yt-r6;
30414 
30415    box_Xpoint[3].x = box_Xpoint[0].x;
30416    box_Xpoint[3].y = box_Xpoint[0].y;
30417 
30418    XSetForeground(display, gc, colors[icol]);
30419    if (ifill) {
30420 	XFillPolygon(display,winrama,gc,box_Xpoint,3,
30421 		Nonconvex,CoordModeOrigin);
30422    } else {
30423 	XDrawLines(display,winrama,gc,box_Xpoint,4,CoordModeOrigin);
30424    }
30425 }
30426 
DrawBox(x,y,xt,yt,r,icol,ifill,iconv)30427 void DrawBox(x,y,xt,yt,r,icol,ifill,iconv)
30428 double x;
30429 double y;
30430 int xt;
30431 int yt;
30432 int r;
30433 int icol;
30434 int ifill;
30435 int iconv;
30436 {
30437    int r2;
30438    XPoint box_Xpoint[5];
30439 
30440    r2 = 0.5 * r;
30441 
30442    if (iconv) glpnt(rwi,rhi,x,y,&xt,&yt,0);
30443 
30444    box_Xpoint[0].x = xt-r2;
30445    box_Xpoint[0].y = yt-r2;
30446 
30447    box_Xpoint[1].x = xt-r2;
30448    box_Xpoint[1].y = yt+r2;
30449 
30450    box_Xpoint[2].x = xt+r2;
30451    box_Xpoint[2].y = yt+r2;
30452 
30453    box_Xpoint[3].x = xt+r2;
30454    box_Xpoint[3].y = yt-r2;
30455 
30456    box_Xpoint[4].x = box_Xpoint[0].x;
30457    box_Xpoint[4].y = box_Xpoint[0].y;
30458 
30459    XSetForeground(display, gc, colors[icol]);
30460    if (ifill) {
30461 	XFillPolygon(display,winrama,gc,box_Xpoint,5,
30462 		Nonconvex,CoordModeOrigin);
30463    } else {
30464 	XDrawLines(display,winrama,gc,box_Xpoint,5,CoordModeOrigin);
30465    }
30466 }
30467 
createDock()30468 void createDock()
30469 {
30470       if (!*ipdbon) {
30471 	DoCan(event.xbutton.x_root, event.xbutton.y_root,
30472 	"You can only dock info a PDB file !",0);
30473 	return;
30474       }
30475 
30476       DCKINVOKE = 1;
30477       rwi = 500; rhi = 450;
30478       windock = CreateWindow("Docking Start",DEFCNV2GEOM,
30479               rwi,rhi, infobg, infofg,(Window)0);
30480       XSelectInput(display, windock, ExposureMask | EnterWindowMask |
30481               ButtonPressMask | PointerMotionMask | StructureNotifyMask |
30482  	      KeyPressMask);
30483       XMapWindow(display, windock);
30484 
30485       qboxstr(&qboxes[QDCKFI],&windock,0,0,190,35,40,400,40,2,
30486           "Ambfor XYZ File name: ",NULL,MAXPATHLEN,QSTRING,2000,0,dummyproc);
30487       strcpy(qboxes[QDCKFI].str,"dock.xyz");
30488 
30489       qboxstr(&qboxes[QDCKOUT],&windock,0,0,190,35,70,400,40,2,
30490           "MOL2 output file    : ",NULL,MAXPATHLEN,QSTRING,2000,0,dummyproc);
30491       strcpy(qboxes[QDCKOUT].str,"dock.mol2");
30492 
30493       qboxstr(&qboxes[QDCKSL],&windock,0,0,190,35,100,200,40,2,
30494           "Number of solutions : ",NULL,2,QPOSINT,2000,0,dummyproc);
30495       strcpy(qboxes[QDCKSL].str,"20");
30496 
30497       DefBut(&dockbut[0], windock, 35, 395, 60, 30,
30498 	"Dock !", infobg, -15);
30499 
30500       DefBut(&dockbut[1], windock, 440, 38, 32, 25,
30501 	"File !", infobg, -15);
30502 
30503       DefBut(&dockbut[2], windock, 375, 395, 60, 30,
30504 	"Close", infobg, -15);
30505 
30506       DefBut(&dockbut[3], windock, 35, 140, 15, 15,
30507 	"", infobg, -15);
30508 
30509       dockbut[1].pix = mapPix;
30510       dockbut[1].pw  = map_width;
30511       dockbut[1].ph  = map_height;
30512 
30513       if (debugdck) {
30514 	TogDown(&dockbut[3]);
30515       } else {
30516 	TogUp(&dockbut[3]);
30517       }
30518       DrwBut(&dockbut[3]);
30519 
30520       WinObj[45].win = &windock;
30521       WinObj[45].subwin = NULL;
30522       WinObj[45].butarr = NULL;
30523       WinObj[45].numbut = -1;
30524       WinObj[45].winup = &dockup;
30525       WinObj[45].redraw = NULL;
30526 }
30527 
drwdock()30528 void drwdock()
30529 {
30530   int i;
30531 
30532   rwi = 600; rhi = 450;
30533 
30534   butje(windock,0,0,rwi,rhi,4,0,0,1,None,0,0,0);
30535 
30536   for (i=0; i<NBUTDCK; i++) DrwBut(&dockbut[i]);
30537 
30538   PromptBox(&qboxes[QDCKFI]);
30539   PromptBox(&qboxes[QDCKSL]);
30540   PromptBox(&qboxes[QDCKOUT]);
30541 
30542   if (DCKSVG) {
30543  	XSetForeground(display, gc, infofg);
30544         XFillRectangle(display, windock, gc, 35, 165, 400, 200);
30545 
30546 	DrawSVG(35, 165, 400 , 200,*DCKsvg,windock);
30547   }
30548 
30549   ULineString(windock, ": Add debug information", 60, 150);
30550 }
30551 
ButtonsDCK(k)30552 int ButtonsDCK(k)
30553 int k;
30554 {
30555   int ret=0;
30556   int i,j;
30557 
30558   switch (k) {
30559   case 0:
30560 	   strcpy(dcklig,qboxes[QDCKFI].str);
30561 	   strcpy(dckout,qboxes[QDCKOUT].str);
30562 	   dcksol = atoi(qboxes[QDCKSL].str);
30563 	   if (access(dcklig,F_OK) != 0) {
30564 	      DoCan(event.xbutton.x_root, event.xbutton.y_root,
30565 			"Non existent ambfor .xyz file !\n",0);
30566 	   } else {
30567 	      XDestroyWindow(display,windock);
30568 #ifdef DOGL
30569 	      ProcLig(1);
30570 #else
30571 	      IntSurfGetlig();
30572 	      ProcLig(1);
30573 #endif
30574 	      dockup = 0;
30575 	   }
30576            break;
30577   case 1:
30578 	   dsel.qbrfile = 1;
30579 	   dsel.subopt = 0;
30580 	   dsel.parse = 0;
30581 	   dsel.flist.select = -1;
30582 	   dsel.Callwin = windock;
30583 	   strcpy(dsel.pntr," ");
30584 	   strcpy(dsel.substr,"xyz");
30585 	   getfiles(&dsel,dsel.lastdir);
30586 	   FileSelectList(&dsel);
30587            break;
30588   case 2:
30589 	   XDestroyWindow(display,windock);
30590 	   dockup = 0;
30591            break;
30592   case 3:
30593 	   if (TogBut(&dockbut[3])) {
30594 		debugdck = 0;
30595 	   } else {
30596 		debugdck = 1;
30597 	   }
30598            break;
30599   default: break;
30600   }
30601 
30602 
30603 }
30604 
createRama()30605 void createRama()
30606 {
30607       rwi = 600; rhi = 600;
30608       winrama = CreateWindow("Ramachandran Plot",DEFCNV2GEOM,
30609               rwi,rhi, infobg, infofg,(Window)0);
30610       XSelectInput(display, winrama, ExposureMask | EnterWindowMask |
30611               ButtonPressMask | PointerMotionMask | StructureNotifyMask);
30612       XMapWindow(display, winrama);
30613       RamaStru.current = -1;
30614 
30615       WinObj[8].win = &winrama;
30616       WinObj[8].subwin = NULL;
30617       WinObj[8].butarr = NULL;
30618       WinObj[8].numbut = -1;
30619       WinObj[8].winup = &ramaup;
30620       WinObj[8].redraw = NULL;
30621 }
30622 
DrawRama()30623 void DrawRama()
30624 {
30625       char *tmpptr;
30626       int xt,yt,qlen;
30627       int dum0,i,n,x1t,y1t,ioff;
30628       double scx,scy,x1,y1,x2,y2;
30629       XPoint rama_Xpoint1[150];
30630 
30631       n = calfptr->ncalf;
30632 
30633       if (RamaStru.npts < n && RamaStru.x != NULL) {
30634 	free(RamaStru.x);
30635 	free(RamaStru.y);
30636 	free(RamaStru.index);
30637       }
30638 
30639       if (RamaStru.x == NULL || RamaStru.npts < n) {
30640 	RamaStru.x = (int *) malloc((sizeof i)*n);
30641 	RamaStru.y = (int *) malloc((sizeof i)*n);
30642 	RamaStru.index =  (int *) malloc((sizeof i)*n);
30643       }
30644       RamaStru.npts = n;
30645 
30646 	 butje(winrama,0,0, rwi,rhi,3,0,0,0,None,0,0,0);
30647 
30648          XSetForeground(display, gc, BlackPixel(display,screen));
30649 
30650 
30651          XDrawString(display,winrama,gc,rwi/2-13,rhi-10,
30652 		"PHI (degrees)",13);
30653 
30654          XDrawString(display,winrama,gc,10,rhi/2,   "P",1);
30655          XDrawString(display,winrama,gc,10,rhi/2+10,"S",1);
30656          XDrawString(display,winrama,gc,10,rhi/2+20,"I",1);
30657 
30658 	 glpnt(rwi,rhi,0.0,0.0,&xt,&yt,0);
30659 	 rama_Xpoint1[0].x = xt;
30660 	 rama_Xpoint1[0].y = yt;
30661 	 glpnt(rwi,rhi,0.0,1.0,&xt,&yt,0);
30662 	 rama_Xpoint1[1].x = xt;
30663 	 rama_Xpoint1[1].y = yt;
30664 	 glpnt(rwi,rhi,1.0,1.0,&xt,&yt,0);
30665 	 rama_Xpoint1[2].x = xt;
30666 	 rama_Xpoint1[2].y = yt;
30667 	 glpnt(rwi,rhi,1.0,0.0,&xt,&yt,0);
30668 	 rama_Xpoint1[3].x = xt;
30669 	 rama_Xpoint1[3].y = yt;
30670 	 glpnt(rwi,rhi,0.0,0.0,&xt,&yt,0);
30671 	 rama_Xpoint1[4].x = xt;
30672 	 rama_Xpoint1[4].y = yt;
30673 
30674 	 XSetForeground(display, gc, colors[15]);
30675 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,5,
30676 		Nonconvex,CoordModeOrigin);
30677 
30678 	 for (i=0; i<108; i++) {
30679 		x1 = (rama_area4[i][0]/360.0 + 0.5);
30680 		y1 = (rama_area4[i][1]/360.0 + 0.5);
30681 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30682 		rama_Xpoint1[i].x = x1t;
30683 		rama_Xpoint1[i].y = y1t;
30684 	 }
30685 	 rama_Xpoint1[108].x = rama_Xpoint1[0].x;
30686 	 rama_Xpoint1[108].y = rama_Xpoint1[0].y;
30687 
30688 	 XSetForeground(display, gc, colors[2]);
30689 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,108,
30690 		Nonconvex,CoordModeOrigin);
30691 
30692 	 for (i=0; i<67; i++) {
30693 		x1 = (rama_area5[i][0]/360.0 + 0.5);
30694 		y1 = (rama_area5[i][1]/360.0 + 0.5);
30695 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30696 		rama_Xpoint1[i].x = x1t;
30697 		rama_Xpoint1[i].y = y1t;
30698 	 }
30699 
30700 	 rama_Xpoint1[67].x = rama_Xpoint1[0].x;
30701 	 rama_Xpoint1[67].y = rama_Xpoint1[0].y;
30702 
30703 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,67,
30704 		Nonconvex,CoordModeOrigin);
30705 
30706 	 for (i=0; i<10; i++) {
30707 		x1 = (rama_area6[i][0]/360.0 + 0.5);
30708 		y1 = (rama_area6[i][1]/360.0 + 0.5);
30709 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30710 		rama_Xpoint1[i].x = x1t;
30711 		rama_Xpoint1[i].y = y1t;
30712 	 }
30713 
30714 	 rama_Xpoint1[10].x = rama_Xpoint1[0].x;
30715 	 rama_Xpoint1[10].y = rama_Xpoint1[0].y;
30716 
30717 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,10,
30718 		Nonconvex,CoordModeOrigin);
30719 
30720 	 for (i=0; i<28; i++) {
30721 		x1 = (rama_area7[i][0]/360.0 + 0.5);
30722 		y1 = (rama_area7[i][1]/360.0 + 0.5);
30723 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30724 		rama_Xpoint1[i].x = x1t;
30725 		rama_Xpoint1[i].y = y1t;
30726 	 }
30727 
30728 	 rama_Xpoint1[28].x = rama_Xpoint1[0].x;
30729 	 rama_Xpoint1[28].y = rama_Xpoint1[0].y;
30730 
30731 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,28,
30732 		Nonconvex,CoordModeOrigin);
30733 
30734 	 for (i=0; i<10; i++) {
30735 		x1 = (rama_area8[i][0]/360.0 + 0.5);
30736 		y1 = (rama_area8[i][1]/360.0 + 0.5);
30737 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30738 		rama_Xpoint1[i].x = x1t;
30739 		rama_Xpoint1[i].y = y1t;
30740 	 }
30741 
30742 	 rama_Xpoint1[10].x = rama_Xpoint1[0].x;
30743 	 rama_Xpoint1[10].y = rama_Xpoint1[0].y;
30744 
30745 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,10,
30746 		Nonconvex,CoordModeOrigin);
30747 
30748 	 for (i=0; i<10; i++) {
30749 		x1 = (rama_area9[i][0]/360.0 + 0.5);
30750 		y1 = (rama_area9[i][1]/360.0 + 0.5);
30751 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30752 		rama_Xpoint1[i].x = x1t;
30753 		rama_Xpoint1[i].y = y1t;
30754 	 }
30755 
30756 	 rama_Xpoint1[10].x = rama_Xpoint1[0].x;
30757 	 rama_Xpoint1[10].y = rama_Xpoint1[0].y;
30758 
30759 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,10,
30760 		Nonconvex,CoordModeOrigin);
30761 
30762 	 for (i=0; i<16; i++) {
30763 		x1 = (rama_area1[i][0]/360.0 + 0.5);
30764 		y1 = (rama_area1[i][1]/360.0 + 0.5);
30765 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30766 		rama_Xpoint1[i].x = x1t;
30767 		rama_Xpoint1[i].y = y1t;
30768 	 }
30769 	 rama_Xpoint1[16].x = rama_Xpoint1[0].x;
30770 	 rama_Xpoint1[16].y = rama_Xpoint1[0].y;
30771 
30772 	 XSetForeground(display, gc, colors[1]);
30773 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,17,
30774 		Nonconvex,CoordModeOrigin);
30775 
30776 	 for (i=0; i<25; i++) {
30777 		x1 = (rama_area2[i][0]/360.0 + 0.5);
30778 		y1 = (rama_area2[i][1]/360.0 + 0.5);
30779 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30780 		rama_Xpoint1[i].x = x1t;
30781 		rama_Xpoint1[i].y = y1t;
30782 	 }
30783 	 rama_Xpoint1[25].x = rama_Xpoint1[0].x;
30784 	 rama_Xpoint1[25].y = rama_Xpoint1[0].y;
30785 
30786 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,25,
30787 		Nonconvex,CoordModeOrigin);
30788 
30789 	 for (i=0; i<108; i++) {
30790 		x1 = (rama_area3[i][0]/360.0 + 0.5);
30791 		y1 = (rama_area3[i][1]/360.0 + 0.5);
30792 		glpnt(rwi,rhi,x1,y1,&x1t,&y1t,0);
30793 		rama_Xpoint1[i].x = x1t;
30794 		rama_Xpoint1[i].y = y1t;
30795 	 }
30796 	 rama_Xpoint1[108].x = rama_Xpoint1[0].x;
30797 	 rama_Xpoint1[108].y = rama_Xpoint1[0].y;
30798 
30799 	 XFillPolygon(display,winrama,gc,rama_Xpoint1,108,
30800 		Nonconvex,CoordModeOrigin);
30801 
30802          XSetForeground(display, gc, BlackPixel(display,screen));
30803 	 dum0 = 0;
30804          drwgl(winrama,rwi,rhi,0.0,0.0,1.0,0.0,dum0,dum0,0,0);
30805          drwgl(winrama,rwi,rhi,0.0,0.0,0.0,1.0,dum0,dum0,0,0);
30806          drwgl(winrama,rwi,rhi,0.0,1.0,1.0,1.0,dum0,dum0,0,0);
30807          drwgl(winrama,rwi,rhi,1.0,1.0,1.0,0.0,dum0,dum0,0,0);
30808          drwgl(winrama,rwi,rhi,0.0,0.5,1.0,0.5,dum0,dum0,0,0);
30809          drwgl(winrama,rwi,rhi,0.5,0.0,0.5,1.0,dum0,dum0,0,0);
30810 
30811 	 scx = 12.0;
30812 	 for (i=0; i<13; i++) {
30813 		  x1 = ((double) i)/scx;
30814 		  y1 = 0.0;
30815 		  y2 = -0.02;
30816 		  drwgl(winrama,rwi,rhi,x1,y1,x1,y2,dum0,dum0,0,0);
30817 		  drwgl(winrama,rwi,rhi,y1,x1,y2,x1,dum0,dum0,0,0);
30818 	 }
30819 
30820 	 ioff = CHIGH/2;
30821 
30822 	 glpnt(rwi,rhi,0.0,-0.04,&xt,&yt,0);
30823 	 sprintf(stemp,"%d",-180);
30824 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30825 	 XDrawString(display,winrama,gc,xt-qlen/2,yt,stemp,strlen(stemp));
30826 
30827 	 glpnt(rwi,rhi,0.25,-0.04,&xt,&yt,0);
30828 	 sprintf(stemp,"%d",-90);
30829 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30830 	 XDrawString(display,winrama,gc,xt-qlen/2,yt,stemp,strlen(stemp));
30831 
30832 	 glpnt(rwi,rhi,0.5,-0.04,&xt,&yt,0);
30833 	 sprintf(stemp,"%d",0);
30834 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30835 	 XDrawString(display,winrama,gc,xt-qlen/2,yt,stemp,strlen(stemp));
30836 
30837 	 glpnt(rwi,rhi,0.75,-0.04,&xt,&yt,0);
30838 	 sprintf(stemp,"%d",90);
30839 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30840 	 XDrawString(display,winrama,gc,xt-qlen/2,yt,stemp,strlen(stemp));
30841 
30842 	 glpnt(rwi,rhi,1.0,-0.04,&xt,&yt,0);
30843 	 sprintf(stemp,"%d",180);
30844 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30845 	 XDrawString(display,winrama,gc,xt-qlen/2,yt,stemp,strlen(stemp));
30846 
30847 	 glpnt(rwi,rhi,-0.04,0.0,&xt,&yt,0);
30848 	 sprintf(stemp,"%d",-180);
30849 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30850 	 XDrawString(display,winrama,gc,xt-qlen/2,yt+ioff,stemp,strlen(stemp));
30851 
30852 	 glpnt(rwi,rhi,-0.04,0.25,&xt,&yt,0);
30853 	 sprintf(stemp,"%d",-90);
30854 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30855 	 XDrawString(display,winrama,gc,xt-qlen/2,yt+ioff,stemp,strlen(stemp));
30856 
30857 	 glpnt(rwi,rhi,-0.04,0.5,&xt,&yt,0);
30858 	 sprintf(stemp,"%d",0);
30859 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30860 	 XDrawString(display,winrama,gc,xt-qlen/2,yt+ioff,stemp,strlen(stemp));
30861 
30862 	 glpnt(rwi,rhi,-0.04,0.75,&xt,&yt,0);
30863 	 sprintf(stemp,"%d",90);
30864 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30865 	 XDrawString(display,winrama,gc,xt-qlen/2,yt+ioff,stemp,strlen(stemp));
30866 
30867 	 glpnt(rwi,rhi,-0.04,1.0,&xt,&yt,0);
30868 	 sprintf(stemp,"%d",180);
30869 	 qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
30870 	 XDrawString(display,winrama,gc,xt-qlen/2,yt+ioff,stemp,strlen(stemp));
30871 
30872 	 for (i=0; i<calfptr->ncalf; i++) {
30873 	   x1 = calfptr->rphi[i]/360.0 + 0.5;
30874 	   y1 = calfptr->rpsi[i]/360.0 + 0.5;
30875            if (calfptr->iamino[i] == 1) {
30876 		DrawTriangle(x1,y1,0,0,6,3,1,1);
30877 	   } else if (calfptr->iamino[i] == 15) {
30878 		DrawTriangle(x1,y1,0,0,6,4,1,1);
30879 	   } else {
30880 		DrawBox(x1,y1,0,0,6,3,1,1);
30881 	   }
30882 	   glpnt(rwi,rhi,x1,y1,&xt,&yt,0);
30883 	   RamaStru.x[i] = xt;
30884 	   RamaStru.y[i] = yt;
30885 	   RamaStru.index[i] = i;
30886 	 }
30887 
30888 	 if (RamaStru.current != -1) {
30889 	   i = RamaStru.current;
30890 	   if (calfptr->iamino[i] == 1) {
30891 		DrawTriangle(0.0,0.0,
30892 			RamaStru.x[i],RamaStru.y[i],
30893 			6,0,0,0);
30894 	   } else if (calfptr->iamino[i] == 15) {
30895 		DrawTriangle(0.0,0.0,
30896 			RamaStru.x[i],RamaStru.y[i],
30897 			6,0,0,0);
30898 	   } else {
30899 		DrawBox(0.0,0.0,
30900 			RamaStru.x[i],RamaStru.y[i],
30901 			6,0,0,0);
30902 	   }
30903 	 }
30904 }
30905 
createconv()30906 void createconv()
30907 {
30908       wincnv = CreateWindow("SCF Convergence",DEFCNVGEOM,
30909               CNVWIDE,CNVHIGH, infobg, infofg,(Window)0);
30910       XSelectInput(display, wincnv, ExposureMask | EnterWindowMask |
30911               ButtonPressMask | PointerMotionMask);
30912       XMapWindow(display, wincnv);
30913 
30914       WinObj[3].win = &wincnv;
30915       WinObj[3].subwin = NULL;
30916       WinObj[3].butarr = NULL;
30917       WinObj[3].numbut = -1;
30918       WinObj[3].winup = &cnvup;
30919       WinObj[3].redraw = drwcnv;
30920 }
30921 
createfr(dowin)30922 void createfr(dowin)
30923 int dowin;
30924 {
30925 
30926    if (dowin) {
30927 	FrBox = CreateWindow("Molden Frequency Select","-80-80",QBOXWIDE,310,
30928 	   infobg,infofg,(Window)0);
30929 	XSelectInput(display, FrBox, ExposureMask | KeyPressMask |
30930 	   ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
30931 	   LeaveWindowMask | EnterWindowMask);
30932    }
30933 
30934    WinObj[17].win = &FrBox;
30935    WinObj[17].subwin = NULL;
30936    WinObj[17].butarr = NULL;
30937    WinObj[17].numbut = -1;
30938    WinObj[17].winup = &FRup;
30939    WinObj[17].redraw = NULL;
30940 
30941    if (FRQ->ihasi < 0) {
30942 	if (*ihasex) {
30943 	   DefList(&frlist,FrBox,DIRX,DIRY,DIRW,DIRH,
30944 	   "  Nr.     Excitation (nm)   Int.  Mult-Irrep.",
30945 	   NFLS,frsym,FRQ->freq,FRQ->frint,NULL,&FRQ->nfreq,NULL);
30946 	} else {
30947 	   DefList(&frlist,FrBox,DIRX,DIRY,DIRW,DIRH,
30948 	   "  Nr.     Frequency (cm-1)  Int.  Irrep.",
30949 	   NFLS,frsym,FRQ->freq,FRQ->frint,NULL,&FRQ->nfreq,NULL);
30950 	}
30951    } else {
30952       	DefList(&frlist,FrBox,DIRX,DIRY,DIRW,DIRH,"  Nr.     Frequency    (cm-1)",
30953 	NFLS,NULL,FRQ->freq,NULL,NULL,&FRQ->nfreq,NULL);
30954    }
30955 
30956    qboxstr(&qboxes[QNSCAL],&FrBox,1,0,-1,DEFQX,270, 170,QBOXHIGH,0,
30957 	"Scale Factor ? ","1.0", 0,3, 2000,-1,dummyproc);
30958 
30959    qboxes[QNSCAL].qflt = frmul;
30960    sprintf(qboxes[QNSCAL].str,"%f", *frmul);
30961    qboxes[QNSCAL].curpos = strlen(qboxes[QNSCAL].str);
30962    qboxes[QNSCAL].explstr = "Scale amplitude atomic movements";
30963    if (dowin) XMapWindow(display,FrBox);
30964 }
30965 
INTextr()30966 void INTextr() {
30967       int i;
30968 
30969       spec_mx = spec_mn = out_spec[0];
30970       for (i=1; i < n_freqs; i++) {
30971         if (out_spec[i] > spec_mx) {
30972     	   spec_mx = out_spec[i];
30973         }
30974         if (out_spec[i] < spec_mn) {
30975     	   spec_mn = out_spec[i];
30976         }
30977       }
30978 }
30979 
init_spec()30980 void init_spec()
30981 {
30982   int i,frtmp;
30983       if (FRQ->ihasi) {
30984 
30985 	spint = FRQ->frint;
30986 	spfrq = FRQ->freq;
30987 	spnfrq = &FRQ->nfreq;
30988 	min_freq = 0;
30989 	max_freq = 0;
30990 	for (i=0; i < FRQ->nfreq; i++) {
30991 	   frtmp = (int) (spfrq[i]*freq_scale);
30992 	   if (frtmp > max_freq) max_freq = frtmp;
30993 	}
30994 	i = max_freq / 500;
30995 	max_freq = (i+1)*500;
30996 	freq_step = 1.0;
30997 	hwhm = 20.0;
30998 	if (*ihasex) {
30999 	   splab = uvlab;
31000         } else {
31001 	   splab = forlab;
31002 	}
31003 	nspqbox = 5;
31004 	nsbutts = 5;
31005 
31006       } else if (nmrptr->ihsnmr) {
31007 
31008 	prep_nmr();
31009 	spint = inten;
31010 	spfrq = peaks;
31011 	spnfrq = &npks;
31012 	FRQextr();
31013 	if (spmode) {
31014 	   freq_step = nmr13Cstep;
31015 	} else {
31016 	   freq_step = nmr1Hstep;
31017 	}
31018 	hwhm = 0.01;
31019 	splab = nmrlab;
31020 	nspqbox = 7;
31021 	nsbutts = 7;
31022       }
31023 }
31024 
31025 #if defined(VMS) || defined(UNDERSC)
gtfcor(int * ifrq,int * x1,int * y1,int * x2,int * y2)31026 void gtfcor(int *ifrq,int *x1,int *y1,int *x2,int *y2)
31027 #else
31028 #ifdef CRAY
31029 void GTFCOR(int *ifrq,int *x1,int *y1,int *x2,int *y2)
31030 #else
31031 void gtfcor_(int *ifrq,int *x1,int *y1,int *x2,int *y2)
31032 #endif
31033 #endif
31034 {
31035   int lb,rb,frqrng,iw,x,imagx,imagy;
31036   double p;
31037 
31038   lb = 34; rb = 57; iw = 4;
31039   imagx = 1000; imagy = 500;
31040 
31041   frqrng = (max_freq - min_freq);
31042 
31043   p = (double) (imagx-lb-rb) / (double) frqrng;
31044 
31045   x =  lb + (int) (p*FRQ->freq[*ifrq-1]);
31046   *x1 = x - iw; *x2 = x + iw;
31047   *y1 = 0; *y2 = imagy;
31048 
31049 }
31050 
31051 #if defined(VMS) || defined(UNDERSC)
pltspec(int * opt)31052 void pltspec(int *opt)
31053 #else
31054 #ifdef CRAY
31055 void PLTSPEC(int *opt)
31056 #else
31057 void pltspec_(int *opt)
31058 #endif
31059 #endif
31060 {
31061    init_spec();
31062    if (nmrptr->ihsnmr) {
31063 	avch3();
31064 	prep_nmr();
31065    }
31066    calc_spectrum(0);
31067    write_spectrum("spec.ps",0,*opt);
31068 
31069 }
31070 
createspec(dowin)31071 void createspec(dowin)
31072 int dowin;
31073 {
31074       int i;
31075 
31076       if (!FRQ->ihasi && !nmrptr->ihsnmr) return;
31077 
31078       if (dowin) {
31079 	winspec = CreateWindow("Spectrum",DEFCNVGEOM,
31080               SPECWIDE,SPECHIGH+SPBHIGH, infobg, infofg,(Window)0);
31081 	XSelectInput(display, winspec, SubstructureNotifyMask | ExposureMask |
31082 		ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
31083 		StructureNotifyMask | KeyPressMask |
31084 		EnterWindowMask | LeaveWindowMask);
31085 	subSPEC = CreateWindow("Subwindow","",10,10,
31086                             colors[0],colors[15],winspec);
31087 	XMapWindow(display, winspec);
31088       }
31089 
31090       init_spec();
31091 
31092       calc_spectrum(0);
31093 
31094       DefBut(&spbut[0], winspec, 80, SPECHIGH + BUTTN, 100, 23, "Lorentzian",
31095 	infobg, ZMBCOL);
31096       spbut[0].str = pktyp[lorentzian];
31097       spbut[0].explstr = "Peak enveloppe: Lorentzian, Gaussian";
31098 
31099       DefBut(&spbut[1], winspec, 80, SPECHIGH, 100, 23, "Infra Red",
31100 	infobg, ZMBCOL);
31101       if (FRQ->ihasi) {
31102 	  if (*ihasex) {
31103              spbut[1].str = *uvsptyp;
31104 	     spbut[1].explstr = "UV spectrum";
31105 	  } else {
31106              spbut[1].str = sptyp[spmode];
31107 	     spbut[1].explstr = "Type of spectrum: Infrared, Raman\nSome QM programs calculate both intensities";
31108 	  }
31109       } else if (nmrptr->ihsnmr) {
31110           spbut[1].str = nmrsptyp[spmode];
31111 	  spbut[1].explstr = "Type of NMR spectrum: 1H, 13C";
31112 	  if (spmode) {
31113 		nmrref  = &nmr13Cref;
31114 	  } else {
31115 		nmrref  = &nmr1Href;
31116 	  }
31117       }
31118 
31119 
31120       DefBut(&spbut[2], winspec, SPECWIDE-85, SPECHIGH+15 + 2*BUTTN, 75, 23,
31121 	"Close", infobg, ZMBCOL);
31122       spbut[2].explstr = "Close window";
31123 
31124       DefBut(&spbut[3], winspec, SPECWIDE-85, SPECHIGH+15, 75, 23,
31125 	"Postscript", infobg, ZMBCOL);
31126       spbut[3].explstr = "Export spectrum as Postscript file";
31127 
31128       DefBut(&spbut[4], winspec, SPECWIDE-85, SPECHIGH+15 + BUTTN,35, 23,
31129 	"Xmgr", infobg, ZMBCOL);
31130       spbut[4].explstr = "Export spectrum as input file for Xmgr";
31131 
31132       DefBut(&spbut[5], winspec, SPECWIDE-40, SPECHIGH+15 + BUTTN,30, 23,
31133         "jdx", infobg, ZMBCOL);
31134       spbut[5].explstr = "Export spectrum as jdx file";
31135 
31136       DefBut(&spbut[6], winspec, SPECWIDE-85, SPECHIGH+15 - BUTTN,75, 23,
31137 	"Aver. CH3", infobg, ZMBCOL);
31138       spbut[6].explstr = "Average shielding and J-coupling\nof rotational equivalent Hydrogens on CH3";
31139 
31140       qboxstr(&qboxes[QHW],&winspec,1,0,190,200,SPECHIGH,
31141 	150,QBOXHIGH-5,2,"Half-Width"," ",10,QREAL,2000,-1,updcallb);
31142       if (FRQ->ihasi) {
31143 	sprintf(qboxes[QHW].str,"%-4.1f",hwhm);
31144       } else if (nmrptr->ihsnmr) {
31145 	sprintf(qboxes[QHW].str,"%-8.4f",hwhm);
31146       }
31147       qboxes[QHW].curpos = strlen(qboxes[QHW].str);
31148       qboxes[QHW].dflt = &hwhm;
31149       qboxes[QHW].explstr = "Half-Width of peak\nInfluences peak width";
31150 
31151       qboxstr(&qboxes[QSSCAL],&winspec,0,0,190,200,SPECHIGH+10+BUTTN,
31152 	150,QBOXHIGH-5,2,"Scale Fac."," ",10,QREAL,2000,-1,updcallb);
31153       sprintf(qboxes[QSSCAL].str,"%-4.2f",freq_scale);
31154       qboxes[QSSCAL].curpos = strlen(qboxes[QSSCAL].str);
31155       qboxes[QSSCAL].dflt = &freq_scale;
31156       qboxes[QSSCAL].explstr = "Apply frequency scale factor";
31157 
31158       qboxstr(&qboxes[QMINF],&winspec,0,0,190,350,SPECHIGH,
31159 	150,QBOXHIGH-5,2,"Min. Freq."," ",10,QREAL,2000,-1,updcallb);
31160       sprintf(qboxes[QMINF].str,"%d",min_freq);
31161       qboxes[QMINF].curpos = strlen(qboxes[QMINF].str);
31162       qboxes[QMINF].iflt = &min_freq;
31163       qboxes[QMINF].explstr = "Lowest frequency displayed\nSpecify displayed frequency range";
31164 
31165       qboxstr(&qboxes[QMAXF],&winspec,0,0,190,350,SPECHIGH+10+BUTTN,
31166 	150,QBOXHIGH-5,2,"Max. Freq."," ",10,QREAL,2000,-1,updcallb);
31167       sprintf(qboxes[QMAXF].str,"%d",max_freq);
31168       qboxes[QMAXF].curpos = strlen(qboxes[QMAXF].str);
31169       qboxes[QMAXF].iflt = &max_freq;
31170       qboxes[QMAXF].explstr = "Highest frequency displayed\nSpecify displayed frequency range";
31171 
31172       qboxstr(&qboxes[QIMAX],&winspec,0,0,190,350,SPECHIGH+15+2*BUTTN,
31173 	150,QBOXHIGH-5,2,"Max. Ints."," ",10,QREAL,2000,-1,updcallb);
31174       sprintf(qboxes[QIMAX].str,"%-4.2f",spec_mx);
31175       qboxes[QIMAX].curpos = strlen(qboxes[QIMAX].str);
31176       qboxes[QIMAX].dflt = &spec_mx;
31177       qboxes[QIMAX].explstr = "Apply intensity scale factor\nInstrumental in comparing spectra";
31178 
31179       if (nmrptr->ihsnmr) {
31180 
31181 	qboxstr(&qboxes[QTMS],&winspec,0,0,190,200,SPECHIGH+15+2*BUTTN,
31182 	150,QBOXHIGH-5,2,"TMS ref.  "," ",10,QREAL,2000,-1,updcallb);
31183 	sprintf(qboxes[QTMS].str,"%6.2f",*nmrref);
31184         qboxes[QTMS].curpos = strlen(qboxes[QTMS].str);
31185 	qboxes[QTMS].qflt = nmrref;
31186 	qboxes[QTMS].explstr = "The TMS reference.\nIsotropic Magnetic shielding (ppm)";
31187 
31188 	qboxstr(&qboxes[QFREQ],&winspec,0,0,190,10,SPECHIGH+15+2*BUTTN,
31189 	170,QBOXHIGH-5,2,"Carrier Freq. (MHz)"," ",10,QREAL,2000,-1,updcallb);
31190 	sprintf(qboxes[QFREQ].str,"%5.1f",NMRbas);
31191         qboxes[QFREQ].curpos = strlen(qboxes[QFREQ].str);
31192 	qboxes[QFREQ].qflt = &NMRbas;
31193 	qboxes[QFREQ].explstr = "Carrier frequency\nInfluences the size of the peak splitting";
31194       }
31195 
31196       specup = 1;
31197 
31198       WinObj[5].win = &winspec;
31199       WinObj[5].subwin = &subSPEC;
31200       WinObj[5].butarr = spbut;
31201       WinObj[5].numbut = NSBUTTS;
31202       WinObj[5].winup = &specup;
31203       WinObj[5].redraw = drwspec;
31204 }
31205 
creategeom()31206 void creategeom()
31207 {
31208 
31209       gwi = CNVWIDE*2; ghi = CNVHIGH*2;
31210       if (!geo1ptr->idmxav && !geo1ptr->idrmav) gwi = CNVWIDE;
31211       if (!geo1ptr->ifmxav && !geo1ptr->ifrmav) ghi = CNVHIGH;
31212 
31213       wingeo = CreateWindow("Geom. Convergence",DEFCNV2GEOM,
31214               gwi,ghi, infobg, infofg,(Window)0);
31215       XSelectInput(display, wingeo, ExposureMask | EnterWindowMask |
31216               ButtonPressMask | PointerMotionMask | StructureNotifyMask);
31217       XMapWindow(display, wingeo);
31218 
31219       WinObj[4].win = &wingeo;
31220       WinObj[4].subwin = NULL;
31221       WinObj[4].butarr = NULL;
31222       WinObj[4].numbut = -1;
31223       WinObj[4].winup = &geoup;
31224       WinObj[4].redraw = NULL;
31225 }
31226 
createscore()31227 void createscore()
31228 {
31229       winsco = CreateWindow("Docking Score",DEFCNVGEOM,
31230               CNVWIDE,CNVHIGH+140, infobg, infofg,(Window)0);
31231       XSelectInput(display, winsco, ExposureMask | EnterWindowMask |
31232               ButtonPressMask | PointerMotionMask);
31233       XMapWindow(display, winsco);
31234       scoup = 1;
31235 
31236       DefBut(&scbut[0], winsco, 10, CNVHIGH + 10, 75, 23,
31237 	"Save Pose", infobg, ZMBCOL);
31238 
31239       DefBut(&scbut[1], winsco, 90, CNVHIGH + 10, 75, 23,
31240 	"Write Poses", infobg, ZMBCOL);
31241 
31242       DefBut(&scbut[2], winsco, 170, CNVHIGH + 10, 50, 23,
31243 	"AtomInf", infobg, ZMBCOL);
31244 
31245       DefBut(&scbut[3], winsco, CNVWIDE-60, CNVHIGH + 10, 50, 23,
31246 	"Close", infobg, ZMBCOL);
31247 
31248       DefBut(&scbut[4], winsco, 10, CNVHIGH + 40, 15, 15,
31249 	" ", infobg, ZMBCOL);
31250 
31251       DefBut(&scbut[5], winsco, 10, CNVHIGH + 60, 15, 15,
31252 	" ", infobg, ZMBCOL);
31253 
31254       if (*ipmfm) {
31255 	  TogDown(&scbut[4]);
31256       } else {
31257 	  TogUp(&scbut[4]);
31258       }
31259 
31260       if (*ipmfh) {
31261 	  TogDown(&scbut[5]);
31262       } else {
31263 	  TogUp(&scbut[5]);
31264       }
31265 
31266       WinObj[6].win = &winsco;
31267       WinObj[6].subwin = NULL;
31268       WinObj[6].butarr = scbut;
31269       WinObj[6].numbut = NSCBUTTS;
31270       WinObj[6].winup = &scoup;
31271       WinObj[6].redraw = drwsco;
31272 }
31273 
createpmf()31274 void createpmf()
31275 {
31276       winpmf = CreateWindow("PMF Score",DEFPMFGEOM,
31277               325,CNVHIGH+40, infobg, infofg,(Window)0);
31278       XSelectInput(display, winpmf, ExposureMask | EnterWindowMask |
31279               ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
31280 		LeaveWindowMask);
31281       XMapWindow(display, winpmf);
31282       pmfup = 1;
31283 
31284       DefBut(&pbut[0], winpmf, 10, CNVHIGH + 10, 75, 23,
31285 	"Close", infobg, ZMBCOL);
31286 /*
31287       DefList(&pmflistmn,winpmf,DIRX,DIRY,DIRW,80,
31288 	"Top Negative Interactions",5,NULL,NULL,NULL,pmfmn,npmfmx,NULL);
31289 
31290       DefList(&pmflistmx,winpmf,DIRX,160,DIRW,80,
31291 	"Top Positive Interactions",5,NULL,NULL,NULL,pmfmx,npmfmx,NULL);
31292 */
31293       DefList(&pmflistmn,winpmf,DIRX,DIRY,DIRW,80,
31294 	NULL,5,NULL,NULL,pmfmn,NULL,npmfmx,NULL);
31295 
31296       DefList(&pmflistmx,winpmf,DIRX,160,DIRW,80,
31297 	NULL,5,NULL,NULL,pmfmx,NULL,npmfmx,NULL);
31298 
31299       WinObj[7].win = &winpmf;
31300       WinObj[7].subwin = NULL;
31301       WinObj[7].butarr = pbut;
31302       WinObj[7].numbut = NPBUTTS;
31303       WinObj[7].winup = &pmfup;
31304       WinObj[7].redraw = drwpmf;
31305 }
31306 
31307 #if defined(VMS) || defined(UNDERSC)
crsco()31308 void crsco()
31309 #else
31310 #ifdef CRAY
31311 void CRSCO()
31312 #else
31313 void crsco_()
31314 #endif
31315 #endif
31316 {
31317    if (!scoup) createscore();
31318    if (ZMEup) UnMapZME();
31319 }
31320 
31321 #if defined(VMS) || defined(UNDERSC)
cpmf()31322 void cpmf()
31323 #else
31324 #ifdef CRAY
31325 void CPMF()
31326 #else
31327 void cpmf_()
31328 #endif
31329 #endif
31330 {
31331    if (pmfup) drwpmf();
31332    else createpmf();
31333 }
31334 
31335 #if defined(VMS) || defined(UNDERSC)
upsco()31336 void upsco()
31337 #else
31338 #ifdef CRAY
31339 void UPSCO()
31340 #else
31341 void upsco_()
31342 #endif
31343 #endif
31344 {
31345 
31346    if (scoup) {
31347 	drwsco();
31348    } else {
31349 	createscore();
31350    }
31351 
31352 }
31353 
31354 #if defined(VMS) || defined(UNDERSC)
molstr(str,nstr,iwin)31355 void molstr(str, nstr, iwin)
31356 #else
31357 #ifdef CRAY
31358 void MOLSTR(str, nstr, iwin)
31359 #else
31360 void molstr_(str, nstr, iwin)
31361 #endif
31362 #endif
31363 
31364 #ifdef VMS
31365 struct dsc$descriptor_s *str;
31366 #else
31367 #ifdef CRAY
31368 _fcd str;
31369 #else
31370 char *str;
31371 #endif
31372 #endif
31373 int *nstr;
31374 int *iwin;
31375 {
31376 int i;
31377 int ns;
31378 int dobell;
31379 
31380        if(DEBUG)fprintf(stderr,"molstr in%d\n",*iwin);
31381 
31382        dobell = 0;
31383 
31384        ns = *nstr;
31385        if (*nstr > MAXSTRLMW ) ns = MAXSTRLMW;
31386        for (i=0; i<MAXSTRLMW; i++)
31387             {if (! *iwin) molwstr[i] = ' ';
31388              else densstr[i] = ' ';}
31389        if (! *iwin) strcp(str,molwstr,ns);
31390        else strcp(str,densstr,ns);
31391 
31392        if(DEBUG && *iwin)fprintf(stderr,"molstr in %d %s\n",*iwin,densstr);
31393        if(DEBUG && !*iwin)fprintf(stderr,"molstr in %d %s\n",*iwin,molwstr);
31394        for (i=0; i<ns; i++)
31395        {
31396            if (! *iwin && molwstr[i] == '!') dobell = 1;
31397            if ( *iwin && densstr[i] == '!') dobell = 1;
31398        }
31399 
31400        StatusStr(*iwin,dobell);
31401 
31402        if(DEBUG)fprintf(stderr,"molstr out\n");
31403 }
31404 
StatusStr(iwin,dobell)31405 void StatusStr(iwin,dobell)
31406 int iwin;
31407 int dobell;
31408 {
31409 
31410        if (dobell && *ibell) XBell(display,0);
31411 
31412        if (! iwin && !DowinMC) {
31413           XSetForeground(display, gc, infofg);
31414           XFillRectangle(display, winMC, gc, SOFFX, SOFFY+7,240 ,20);
31415           XSetForeground(display, gc, infobg);
31416           XDrawRectangle(display, winMC, gc, SOFFX, SOFFY+7,240 ,20);
31417           XDrawString(display,winMC,gc,SOFFX+5,SOFFY+20,molwstr,MINI(MAXSTRLMW,strlen(molwstr)));
31418        }
31419 
31420        if ( iwin && !DowinC) {
31421           XSetForeground(display, gc, infofg);
31422           XFillRectangle(display, winC, gc, S2OFFX, S2OFFY+7,240 ,20);
31423           XSetForeground(display, gc, infobg);
31424           XDrawRectangle(display, winC, gc, S2OFFX, S2OFFY+7,240 ,20);
31425           XDrawString(display,winC,gc,S2OFFX+5,S2OFFY+20,densstr,MINI(MAXSTRLMW,strlen(densstr)));
31426        }
31427        XFlush(display);
31428 }
31429 
31430 #if defined(VMS) || defined(UNDERSC)
errzme(str,nstr,icard,ivar)31431 void errzme(str, nstr, icard, ivar)
31432 #else
31433 #ifdef CRAY
31434 void ERRZME(str, nstr, icard, ivar)
31435 #else
31436 void errzme_(str, nstr, icard, ivar)
31437 #endif
31438 #endif
31439 
31440 #ifdef VMS
31441 struct dsc$descriptor_s *str;
31442 #else
31443 #ifdef CRAY
31444 _fcd str;
31445 #else
31446 char *str;
31447 #endif
31448 #endif
31449 int *nstr;
31450 int *icard;
31451 int *ivar;
31452 {
31453 int i;
31454 int ns;
31455 
31456 	if (DEBUG) fprintf(stderr,"errzme in\n");
31457 
31458 	if (!ZMEup) return;
31459 
31460 	ns = *nstr;
31461 	if (*nstr > MAXZMEERR ) ns = MAXZMEERR;
31462 	for (i=0; i<MAXZMEERR; i++) ZMEerr[i] = ' ';
31463 	strcp(str,ZMEerr,ns);
31464 
31465 	for (i=0; i<ns; i++) if (ZMEerr[i] == '!')
31466 	   if (*ibell) XBell(display,0);
31467 
31468 	XFlush(display);
31469 	for (i=0; i<*xyzp->iatoms; i++) xyzp->iaton[i] = 1;
31470 	DeActZME();
31471 	xyzp->iaton[zmptrp->imap[*icard-1]-1] = 3;
31472 	update_sel = 1;
31473 	if (ABS(*ivar) > 0) {
31474 		if (*ivar < 0) ActOnErr(*icard-1,4+ABS(*ivar)-1,ZMEerr);
31475 		else ActOnErr(*icard-1,*ivar,ZMEerr);
31476 	}
31477 	else ActOnErr(*icard-1,0,ZMEerr);
31478 
31479 	if (DEBUG) fprintf(stderr,"errzme out\n");
31480 
31481 	return;
31482 
31483 }
31484 
31485 #if defined(VMS) || defined(UNDERSC)
drwstr(xvl,yvl,strvl,sl,ind)31486 void drwstr(xvl,yvl,strvl,sl,ind)
31487 #else
31488 #ifdef CRAY
31489 void DRWSTR(xvl,yvl,strvl,sl,ind)
31490 #else
31491 void drwstr_(xvl,yvl,strvl,sl,ind)
31492 #endif
31493 #endif
31494 
31495 int *xvl;
31496 int *yvl;
31497 int *sl;
31498 int *ind;
31499 #ifdef VMS
31500 struct dsc$descriptor_s *strvl;
31501 #else
31502 #ifdef CRAY
31503 _fcd strvl;
31504 #else
31505 char *strvl;
31506 #endif
31507 #endif
31508 {
31509   if (monoscr) XSetBackground(display, gc, BlackPixel(display,screen));
31510 #ifdef VMS
31511   if (monoscr) XDrawImageString(display, molcur, gc, *yvl, *xvl, strvl->dsc$a_pointer, *sl);
31512   else {
31513 #ifdef DOGL
31514      if (has_opengl && (*fancy || *fullgl)) {
31515 	if (StarNetOld) {
31516 	   XDrawString(display, win, gc, *yvl, *xvl, strvl->dsc$a_pointer, *sl);
31517 	} else {
31518 	   if (strvl[*sl]  != '\0') strvl[*sl] = '\0';
31519 	   printString(*yvl,*xvl,0,strvl->dsc$a_pointer);
31520 	}
31521      } else
31522 #endif
31523         XDrawString(display, molcur, gc, *yvl, *xvl, strvl->dsc$a_pointer, *sl);
31524   }
31525 #else
31526 #ifdef CRAY
31527   if (monoscr) XDrawImageString(display, molcur, gc, *yvl, *xvl, _fcdtocp(strvl), *sl);
31528   else {
31529 #ifdef DOGL
31530      if (has_opengl && (*fancy || *fullgl)) {
31531 	if (StarNetOld) {
31532 	   XDrawString(display, win, gc, *yvl, *xvl, _fcdtocp(strvl), *sl);
31533 	} else {
31534 	   if (strvl[*sl]  != '\0') strvl[*sl] = '\0';
31535 	   printString(*yvl,*xvl,0,_fcdtocp(strvl));
31536 	}
31537      } else
31538 #endif
31539 	XDrawString(display, molcur, gc, *yvl, *xvl, _fcdtocp(strvl), *sl);
31540   }
31541 #else
31542   if (monoscr) XDrawImageString(display, molcur, gc, *yvl, *xvl, strvl, *sl);
31543   else {
31544 #ifdef DOGL
31545      if (has_opengl && (*fancy || *fullgl) ) {
31546 	if (StarNetOld) {
31547 	   XDrawString(display, win, gc, *yvl, *xvl, strvl, *sl);
31548 	} else {
31549 	   if (strvl[*sl]  != '\0') strvl[*sl] = '\0';
31550 	   printString(*yvl,*xvl,0,strvl);
31551 	}
31552      } else
31553 #endif
31554 	XDrawString(display, molcur, gc, *yvl, *xvl, strvl, *sl);
31555   }
31556 #endif
31557 #endif
31558 
31559 }
31560 
31561 
31562 #if defined(VMS) || defined(UNDERSC)
drwqstr(xvl,yvl,ian,q,ind)31563 void drwqstr(xvl,yvl,ian,q,ind)
31564 #else
31565 #ifdef CRAY
31566 void DRWQSTR(xvl,yvl,ian,q,ind)
31567 #else
31568 void drwqstr_(xvl,yvl,ian,q,ind)
31569 #endif
31570 #endif
31571 
31572 int *xvl;
31573 int *yvl;
31574 int *ian;
31575 double *q;
31576 int *ind;
31577 {
31578   sprintf(pchgtmp,"%s %7.4f  ",elements[*ian],*q);
31579   if (monoscr) XSetBackground(display, gc, BlackPixel(display,screen));
31580   if (monoscr) XDrawImageString(display, molcur, gc, *yvl, *xvl, pchgtmp, 10);
31581   else {
31582 #ifdef DOGL
31583      if (has_opengl && (*fancy || *fullgl)) {
31584 	if (StarNetOld) {
31585 	   XDrawString(display, win, gc, *yvl, *xvl, pchgtmp, 10);
31586 	} else {
31587 	   pchgtmp[10] = '\0';
31588 	   printString(*yvl,*xvl,0,pchgtmp);
31589 	}
31590      } else
31591 #endif
31592 	XDrawString(display, molcur, gc, *yvl, *xvl, pchgtmp, 10);
31593   }
31594 
31595 }
31596 
31597 #ifndef VMS
31598 #include <sys/types.h>
31599 #include <sys/param.h>
31600 #include <sys/stat.h>
31601 #include <dirent.h>
31602 #else
31603 #include <stat.h>
31604 #include <ctype.h>
31605 #include <errno.h>
31606 #include <rmsdef.h>
31607 
31608 struct dirent {
31609     char	d_name[100];		/* File name		*/
31610     int         d_namlen;
31611     int		vms_verscount;		/* Number of versions	*/
31612     int		vms_versions[20];	/* Version numbers	*/
31613 };
31614 
31615 typedef struct _dirdesc {
31616     long			context;
31617     int				vms_wantversions;
31618     char			*pattern;
31619     struct dirent		entry;
31620     struct dsc$descriptor_s	pat;
31621 } DIR;
31622 
31623 
31624 extern DIR		*opendir();
31625 extern struct dirent	*readdir();
31626 extern void             closedir();
31627 #endif
31628 
31629 
31630 #if defined(__convex__) && defined (__STDC__)
31631 #define S_IFMT  _S_IFMT
31632 #define S_IFDIR _S_IFDIR
31633 #endif
31634 
31635 
31636 
dosort(s1,s2)31637 static int dosort(s1,s2)
31638 char **s1, **s2;
31639 {
31640     return (strcmp((*s1), (*s2)));
31641 }
31642 
dsort(f1,f2)31643 static int dsort(f1,f2)
31644 float f1, f2;
31645 {
31646     int iret;
31647 
31648     iret = -1;
31649     if (f1 == f2) iret = 0;
31650     if (f1 > f2) iret = 1;
31651     return (iret);
31652 }
31653 
isdir(dirname)31654 int isdir(dirname)
31655 char* dirname;
31656 {
31657   struct stat st;
31658   int i,j, ftype;
31659 
31660   st.st_mode = 0;
31661   stat(dirname, &st);
31662   ftype = st.st_mode & S_IFMT;
31663   if ((st.st_mode & S_IFMT) == S_IFDIR) {
31664      return(1);
31665   } else {
31666      return(0);
31667   }
31668 }
31669 
getfiles(fs,dirname)31670 void getfiles(fs,dirname)
31671 FSELSTRU *fs;
31672 char* dirname;
31673 {
31674   DIR           *dir;
31675   int            i,j, ftype;
31676   int            idstat,ifstat;
31677   struct stat    st;
31678   struct dirent *dp;
31679   char tmpfname[MAXFILELEN];
31680 
31681   if (dirname[strlen(dirname)-1] != '/') strcat(dirname,"/");
31682   if (fs->lastdir != dirname) strcpy(fs->lastdir,dirname);
31683   if (qboxes[QSUBSTR].str != NULL)
31684 	strcpy(fs->substr,qboxes[QSUBSTR].str);
31685 
31686   for (i=0; i<fs->nfiles; i++) free(fs->files[i]);
31687   fs->nfiles = 0;
31688   lpnt = 0;
31689 
31690   for (i=0; i<fs->ndirs; i++) free(fs->dirs[i]);
31691   fs->ndirs = 0;
31692 
31693   dir = opendir(dirname);
31694   if (!dir) {
31695     fs->ndirs = 1;
31696     fs->dirs[0] = (char *) malloc(6);
31697     strcpy(fs->dirs[0], "..");
31698     return;
31699   }
31700 
31701   idstat=0; ifstat=0;
31702   i=0; j=0;
31703   while ( (dp = readdir(dir)) != NULL) {
31704 
31705 	strcpy(tmpfname,dirname);
31706 	strcat(tmpfname,dp->d_name);
31707         st.st_mode = 0;
31708         stat(tmpfname, &st);
31709 	ftype = st.st_mode & S_IFMT;
31710         if (ftype == S_IFDIR) {
31711 	   if (j >= MAXDIRS) {
31712 		idstat = 1;
31713 	   } else {
31714 		fs->dirs[j] = (char *) malloc(strlen(dp->d_name) + 3);
31715 		if (!fs->dirs[j]) fprintf(stderr,"getfiles: malloc error\n");
31716 		strcpy(fs->dirs[j], dp->d_name); j++;
31717 	   }
31718 	} else {
31719 	   if (i >= MAXNAMES) {
31720 		ifstat = 1;
31721 	   } else {
31722 		if (strstr(dp->d_name,fs->substr)) {
31723 		fs->files[i] = (char *) malloc(strlen(dp->d_name) + 3);
31724 		if (!fs->files[i]) fprintf(stderr,"getfiles: malloc error\n");
31725 		strcpy(fs->files[i], dp->d_name); i++;
31726 		}
31727 	   }
31728 	}
31729 
31730   }
31731 
31732   closedir(dir);
31733 
31734   if (idstat) {
31735       fprintf(stderr,
31736 	"too many directories in directory only showing first %d.\n",MAXDIRS);
31737   }
31738 
31739   if (ifstat) {
31740       fprintf(stderr,
31741 	"too many files in directory only showing first %d.\n",MAXNAMES);
31742   }
31743 
31744   fs->nfiles = i;
31745   fs->flist.lpnt = 0;
31746   fs->flist.select = 0;
31747 
31748   qsort((char *) fs->files, fs->nfiles, sizeof(char *), dosort);
31749 
31750   fs->ndirs = j;
31751   fs->dirlist.lpnt = 0;
31752   fs->dirlist.select = 0;
31753 
31754   if (fs->ndirs == 0) {
31755     fs->ndirs = 1;
31756     fs->dirs[j] = (char *) malloc(6);
31757     strcpy(fs->dirs[j], "..");
31758   } else {
31759     qsort((char *) fs->dirs, fs->ndirs, sizeof(char *), dosort);
31760   }
31761 
31762 }
31763 
31764 
31765 #ifdef VMS
31766 
31767 
31768 DIR *
opendir(name)31769 opendir(name)
31770     char	*name;
31771 {
31772     DIR		*dd;
31773 
31774     /* Get memory for the handle, and the pattern. */
31775     if ((dd = (DIR *)malloc(sizeof *dd)) == NULL) {
31776 	errno = ENOMEM;
31777 	return NULL;
31778     }
31779 
31780     if (strcmp(".",name) == 0) name = "";
31781 
31782     dd->pattern = malloc((unsigned int)(strlen(name) + sizeof "*.*" + 1));
31783     if (dd->pattern == NULL) {
31784 	free((char *)dd);
31785 	errno = ENOMEM;
31786 	return NULL;
31787     }
31788 
31789     /* Fill in the fields; mainly playing with the descriptor. */
31790     (void)sprintf(dd->pattern, "%s*.*", name);
31791     dd->context = 0;
31792     dd->vms_wantversions = 0;
31793     dd->pat.dsc$a_pointer = dd->pattern;
31794     dd->pat.dsc$w_length = strlen(dd->pattern);
31795     dd->pat.dsc$b_dtype = DSC$K_DTYPE_T;
31796     dd->pat.dsc$b_class = DSC$K_CLASS_S;
31797 
31798     return dd;
31799 }
31800 
31801 
31802 struct dirent *
readdir(dd)31803 readdir(dd)
31804     DIR				*dd;
31805 {
31806     struct dsc$descriptor_s	res;
31807     char			*p;
31808     char			buff[sizeof dd->entry.d_name];
31809     int				i;
31810 
31811     /* Set up result descriptor, and get next file. */
31812     res.dsc$a_pointer = buff;
31813     res.dsc$w_length = sizeof buff - 2;
31814     res.dsc$b_dtype = DSC$K_DTYPE_T;
31815     res.dsc$b_class = DSC$K_CLASS_S;
31816     if (lib$find_file(&dd->pat, &res, &dd->context) == RMS$_NMF
31817      || dd->context == 0L)
31818 	/* None left... */
31819 	return NULL;
31820 
31821     /* Force the buffer to end with a NUL. */
31822     buff[sizeof buff - 1] = '\0';
31823     for (p = buff; !isspace(*p); p++)
31824 	;
31825     *p = '\0';
31826 
31827     /* Skip any directory component and just copy the name. */
31828     if (p = strchr(buff, ']'))
31829 	(void)strcpy(dd->entry.d_name, p + 1);
31830     else
31831 	(void)strcpy(dd->entry.d_name, buff);
31832 
31833     /* Clobber the version. */
31834     if (p = strchr(dd->entry.d_name, ';'))
31835 	*p = '\0';
31836 
31837     dd->entry.d_namlen = strlen(dd->entry.d_name);
31838 
31839     dd->entry.vms_verscount = 0;
31840     return &dd->entry;
31841 }
31842 
31843 void
closedir(dd)31844 closedir(dd)
31845     DIR         *dd;
31846 {
31847     free(dd->pattern);
31848     free((char *)dd);
31849 }
31850 #endif /* end VMS */
31851 
actde(inactid,inactf,iwin)31852 void actde(inactid,inactf,iwin)
31853 
31854 int iwin;
31855 int inactid;
31856 int inactf;
31857 {
31858      int i;
31859      int inact;
31860      int inaf;
31861 
31862      if (DEBUG) fprintf(stderr,"actde in\n");
31863 
31864 
31865      inact = inactid;
31866      inaf  = inactf;
31867 
31868      if ( iwin == 1 ) {
31869 	 denmode = 1;
31870          for ( i = 0; i < NBUTTS; i++ ) ActBut(&dbut[i],1);
31871          if ( inact == 1 ) {
31872                ActBut(&dbut[BELPOT],0);
31873                ActBut(&dbut[BORI],0);
31874                ActBut(&dbut[BATOM],0);
31875                ActBut(&dbut[BOVRLP],0);
31876          }
31877 
31878      }
31879      else {
31880 	 inactMC = inact; inafMC = inaf;
31881 	 denmode = 0;
31882          pdb = 0;
31883 	 frfor = 0;
31884 	 ZMEAA = 0;
31885          if (inaf >= 10) {pdb = 1;inaf = inaf - 10;linmax = 3;}
31886 	 if (inaf == 2) {
31887 	    frfor = 1;
31888 	    if (FRup) RedrawList(&frlist);
31889             if (FRQ->ihasi) {
31890 	        if (specup) drwspec();
31891 	    } else {
31892 	        if (specup) {
31893 		   XDestroyWindow(display,winspec);
31894 		   specup = 0;
31895 		}
31896 	    }
31897 	    if (FRQ->ihasi && specup) drwspec();
31898 	 } else {
31899 	    if (FRup) {
31900 		RedrawList(&frlist);
31901 		XDestroyWindow(display,FrBox);
31902 		FRup = 0;
31903 	    }
31904 	    if (specup) {
31905 		XDestroyWindow(display,winspec);
31906 		specup = 0;
31907 	    }
31908 	 }
31909          if (pdb == 1) {
31910             if (!addfile) {
31911 		*backb = 0;
31912                 hbon = 0;
31913 	    }
31914             DefBut(&cbut[BFORC],  winMC, FOFFX+10, FOFFY+24, 80, BUTTH,
31915                      "Res.Comm.", infobg, CNTCOL);
31916 	    cbut[BFORC].explstr = "Residue command window (protein only)\nIn combination with backbone display\nSwitch on/off residues";
31917 
31918             DefBut(&cbut[BINCRF], winMC, FOFFX+10, FOFFY+24+BUTTN*1, 80, BUTTH,
31919                      "Residue", infobg, CNTCOL);
31920 	    cbut[BINCRF].explstr = "Switch on/off residues, by\nclicking on the backbone";
31921 
31922             DefBut(&cbut[BDECRF], winMC, FOFFX+10, FOFFY+24+BUTTN*2, 80, BUTTH,
31923                      "HetAtm", infobg, CNTCOL);
31924 	    cbut[BDECRF].explstr = "Switch on/off NON amino acids:\nHETATM records in the PDB\nSwitch on/off secundary structure\ncartoons";
31925 
31926             DefBut(&cbut[BUNSC],  winMC, FOFFX+10, FOFFY+24+BUTTN*3,
31927 		TOGGWH, TOGGWH, " ", infobg, CNTCOL);
31928 	    cbut[BUNSC].explstr = "Toggle display cysteine bridges";
31929 
31930             DefBut(&cbut[BHBOND], winMC, FOFFX+10, FOFFY+24+BUTTN*4, TOGGWH, TOGGWH,
31931                      " ", infobg, CNTCOL);
31932 	    cbut[BHBOND].explstr = "Toggle display hydrogen bonds\n of secundary structure";
31933 
31934             if (!addfile) {
31935 		TogUp(&cbut[BBACKB]);
31936 		TogUp(&cbut[BATCOL]);
31937 		TogUp(&cbut[BFORC]);
31938 		TogUp(&cbut[BUNSC]);
31939 		TogUp(&cbut[BHBOND]);
31940 	    }
31941          }
31942          else {
31943 	    DefBut(&cbut[BFORC],  winMC, FOFFX+10, FOFFY+24,
31944 			TOGGWH, TOGGWH, " ", infobg, CNTCOL);
31945 	    cbut[BFORC].explstr = "Switch on/off display of forces\nGaussian/Games/Molf only";
31946 	    if (frfor) cbut[BFORC].explstr =
31947 		"Normal Mode/Frequency analysis";
31948 
31949             DefBut(&cbut[BINCRF], winMC, FOFFX+10, FOFFY+24+BUTTN*1, 80, BUTTH,
31950                      "Incr. Scale", infobg, CNTCOL);
31951 	    cbut[BINCRF].explstr = "Increase scale of forces";
31952 
31953             DefBut(&cbut[BDECRF], winMC, FOFFX+10, FOFFY+24+BUTTN*2, 80, BUTTH,
31954                      "Decr. Scale", infobg, CNTCOL);
31955 	    cbut[BDECRF].explstr = "Decrease scale of forces";
31956 
31957             DefBut(&cbut[BUNSC],  winMC, FOFFX+10, FOFFY+24+BUTTN*3, 80, BUTTH,
31958                      "Unscale", infobg, CNTCOL);
31959 	    cbut[BUNSC].explstr = "no scaling of forces";
31960 
31961             DefBut(&cbut[BHBOND], winMC, FOFFX+10, FOFFY+24+BUTTN*4, 80, BUTTH,
31962                      "", infobg, CNTCOL);
31963          }
31964          for ( i = 0; i < NBUTTS2; i++ ) ActBut(&cbut[i],1);
31965 
31966 
31967          if (pdb) {
31968             if (!addfile) {
31969 		ActBut(&cbut[BFORC],0);
31970 		ActBut(&cbut[BINCRF],0);
31971 		ActBut(&cbut[BDECRF],0);
31972 		ActBut(&cbut[BUNSC],0);
31973 		ActBut(&cbut[BHBOND],0);
31974 	    }
31975          }
31976          if ( inact >= 4 ) {
31977             ActBut(&cbut[BDENMOD],0);
31978             denm = 0;
31979             inact = inact - 4;
31980          }
31981          else denm = 1;
31982 
31983          if ( inact >= 2 ) {
31984             ActBut(&cbut[BCONV],0);
31985             inact = inact - 2;
31986          }
31987          if ( inact == 1 ) {
31988             ActBut(&cbut[BFIRST],0);
31989             ActBut(&cbut[BNEXT],0);
31990             ActBut(&cbut[BPREV],0);
31991             ActBut(&cbut[BMOVIE],0);
31992             ActBut(&cbut[BGEOM],0);
31993          }
31994          if ( inaf >= 1 && !pdb ) {
31995             ActBut(&cbut[BFORC],0);
31996             ActBut(&cbut[BINCRF],0);
31997             ActBut(&cbut[BDECRF],0);
31998             ActBut(&cbut[BUNSC],0);
31999             ActBut(&cbut[BHBOND],0);
32000          }
32001          if ( inaf == 2 && !pdb ) {
32002 		ActBut(&cbut[BFORC],1);
32003 		TogUp(&cbut[BFORC]);
32004 	 }
32005          if (!pdb) ActBut(&cbut[BBACKB],0);
32006          if (!mfdata->imol) {
32007             ActBut(&cbut[BMOLF],-1);
32008 	 } else {
32009             ActBut(&cbut[BMOLF],1);
32010 	 }
32011 
32012 	 if (*fullgl) {
32013 	    *persp = 1;
32014 	    TogDown(&cbut[BPERSP]);
32015 	 }
32016 
32017      }
32018 
32019      if (iwin) RedrawwinC(0,0,WINCWIDE,WINCHIGH);
32020      else      RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
32021      ATMsel = 0;
32022      ATMselp = ATMsel + 1;
32023      if (ATMup) {
32024 	UpdateATM();
32025 	RedrawATM();
32026      }
32027      if (CPup) {
32028 	UpdateCP();
32029 	RedrawCP();
32030      }
32031      if (CTup) {
32032 	RedrawCT();
32033      }
32034      if (STRCup) {
32035 	UpdateSTRC();
32036 	RedrawSTRC();
32037      }
32038 
32039 
32040      if (pdb && ZMEup) {
32041 	if (DoPDB(1)) i = 1;
32042      }
32043      if (DEBUG) fprintf(stderr,"actde out\n");
32044 }
32045 
CentLig()32046 void CentLig()
32047 {
32048       int i,l,m;
32049       double CoorLig[3][MXHETA]= {0.0};
32050       double dmn[MXHETA]= {0.0};
32051       double d2,dx;
32052       int NligAt[MXHETA] = {0};
32053 
32054       if (*ipdbon && !clfstrptr->ilcset) {
32055 
32056 	for (l=0; l < *xyzp->iatoms; l++) {
32057 
32058 	  if (xyzp->iresid[l] < -3) {
32059 
32060 	   m = ABS(xyzp->iresid[l]);
32061 
32062 	   if (m < MXHETA) {
32063 		for (i=0; i<3; i++)
32064 		   CoorLig[i][m] = CoorLig[i][m] + xyzp->coo[l*3+i];
32065 		NligAt[m]++;
32066 	   }
32067 
32068 	  }
32069 	}
32070 
32071 	for (l=0; l < MXHETA; l++) {
32072 	   if (NligAt[l] > 0) {
32073 		for (i=0; i<3; i++)
32074 			CoorLig[i][l] = CoorLig[i][l] / (NligAt[l]);
32075 	   }
32076 	   dmn[l] = 1.0e08;
32077 	}
32078 
32079 	for (l=0; l < *xyzp->iatoms; l++) {
32080 
32081 	  if (xyzp->iresid[l] < -3) {
32082 
32083 	   m = ABS(xyzp->iresid[l]);
32084 
32085 
32086 	   if (m < MXHETA) {
32087 	      d2 = 0.0;
32088 	      for (i = 0; i < 3; i++) {
32089 		dx = CoorLig[i][m] - xyzp->coo[l*3+i];
32090 		d2 = d2 + dx*dx;
32091 	      }
32092 
32093 	      if (d2 < dmn[m])  {
32094 		dmn[m] = d2;
32095 		clfstrptr->ligcat[m] = l;
32096 	      }
32097 	   }
32098 
32099 	  }
32100 	}
32101 	clfstrptr->ilcset = 1;
32102 
32103       }
32104 
32105 
32106 }
32107 
32108 
32109 #if defined(VMS) || defined(UNDERSC)
hetnum(idum)32110 void hetnum(idum)
32111 #else
32112 #ifdef CRAY
32113 void HETNUM(idum)
32114 #else
32115 void hetnum_(idum)
32116 #endif
32117 #endif
32118 int *idum;
32119 {
32120    *idum =  hetptr.NHetAtm;
32121 }
32122 
32123 #if defined(VMS) || defined(UNDERSC)
chkmol2(iok)32124 void chkmol2(iok)
32125 #else
32126 #ifdef CRAY
32127 void CHKMOL2(iok)
32128 #else
32129 void chkmol2_(iok)
32130 #endif
32131 #endif
32132 int *iok;
32133 {
32134 #if defined(VMS) || defined(UNDERSC)
32135    chkmld(iok,
32136 #else
32137 #ifdef CRAY
32138    CHKMLD(iok,
32139 #else
32140    chkmld_(iok,
32141 #endif
32142 #endif
32143 	xyzp->ianz,xyzp->ityp);
32144 
32145 }
32146 
32147 #if defined(VMS) || defined(UNDERSC)
prslab(str,nstr,iopt)32148 void prslab(str, nstr, iopt)
32149 #else
32150 #ifdef CRAY
32151 void PRSLAB(str, nstr, iopt)
32152 #else
32153 void prslab_(str, nstr, iopt)
32154 #endif
32155 #endif
32156 
32157 #ifdef VMS
32158 struct dsc$descriptor_s *str;
32159 #else
32160 #ifdef CRAY
32161 _fcd str;
32162 #else
32163 char *str;
32164 #endif
32165 #endif
32166 int *nstr;
32167 int *iopt;
32168 {
32169 
32170        if (hetlab.NHetLab >= MXHETLAB) return;
32171 
32172        hetlab.iat[hetlab.NHetLab]    = *iopt;
32173 
32174        hetlab.HetLab[hetlab.NHetLab] = (char *) malloc(*nstr+1);
32175        if (!hetlab.HetLab[hetlab.NHetLab])
32176 		fprintf(stderr,"prslab: malloc error\n");
32177 
32178        strcp(str,hetlab.HetLab[hetlab.NHetLab],*nstr);
32179 
32180 #ifndef CRAY
32181        hetlab.HetLab[hetlab.NHetLab][*nstr] = '\0';
32182 #endif
32183        hetlab.NHetLab++;
32184 
32185 }
32186 
32187 #if defined(VMS) || defined(UNDERSC)
sftlab(iopt)32188 void sftlab(iopt)
32189 #else
32190 #ifdef CRAY
32191 void SFTLAB(iopt)
32192 #else
32193 void sftlab_(iopt)
32194 #endif
32195 #endif
32196 int *iopt;
32197 {
32198    int i;
32199 
32200    for (i=0; i<hetlab.NHetLab; i++)
32201 	if (hetlab.iat[i] == *iopt) hetlab.iat[i] = *iopt + 1;
32202 }
32203 
32204 #if defined(VMS) || defined(UNDERSC)
parsfn(str,nstr,iopt)32205 void parsfn(str, nstr, iopt)
32206 #else
32207 #ifdef CRAY
32208 void PARSFN(str, nstr, iopt)
32209 #else
32210 void parsfn_(str, nstr, iopt)
32211 #endif
32212 #endif
32213 
32214 #ifdef VMS
32215 struct dsc$descriptor_s *str;
32216 #else
32217 #ifdef CRAY
32218 _fcd str;
32219 #else
32220 char *str;
32221 #endif
32222 #endif
32223 int *nstr;
32224 int *iopt;
32225 {
32226        int j;
32227        char **strarr;
32228        int *nstrings;
32229        int room;
32230 
32231        switch(*iopt) {
32232        case 0:
32233 	  strarr = fsel.files;
32234 	  nstrings = &fsel.nfiles;
32235 	  room = *nstr + 3;
32236 	  break;
32237        case 1:
32238 	  strarr = hetptr.HetAtm;
32239 	  nstrings = &hetptr.NHetAtm;
32240 	  if (hetptr.NHetAtm >= MXHETA) return;
32241 	  hetptr.Allocated[*nstrings] = 1;
32242 	  room = *nstr + 1;
32243 	  break;
32244        case 2:
32245 	  strarr = &VRMLFname;
32246           j = 0;
32247 	  nstrings = &j;
32248 	  room = *nstr + 1;
32249 	  break;
32250        case 3:
32251 	  strarr = ColNam;
32252 	  nstrings = &NColNam;
32253 	  room = *nstr + 1;
32254 	  break;
32255        case 4:
32256 	  strarr = mm3;
32257 	  nstrings = &Nmm3;
32258 	  room = *nstr + 1;
32259 	  break;
32260        case 5:
32261 	  strarr = chmtnk;
32262 	  nstrings = &Nchmtnk;
32263 	  room = *nstr + 1;
32264 	  break;
32265        case 6:
32266 	  strarr = mol2;
32267 	  nstrings = &Nmol2;
32268 	  room = *nstr + 1;
32269 	  break;
32270        case 7:
32271 	  strarr = chmsf;
32272 	  nstrings = &Nchmsf;
32273 	  room = *nstr + 1;
32274 	  break;
32275        case 8:
32276 	  strarr = ambstr;
32277 	  nstrings = &Nambstr;
32278 	  room = *nstr + 1;
32279 	  break;
32280        case 9:
32281 	  strarr = &GEOMstr;
32282           j = 0;
32283 	  nstrings = &j;
32284 	  room = *nstr + 1;
32285 	  GEOMset = 1;
32286 	  break;
32287        case 10:
32288 	  strarr = spacegr;
32289 	  nstrings = &Nspgr;
32290 	  room = *nstr + 1;
32291 	  break;
32292        case 11:
32293 	  strarr = achain;
32294 	  nstrings = &ncal;
32295 	  room = *nstr + 1;
32296 	  break;
32297        case 12:
32298 	  strarr = frsym;
32299 	  nstrings = &nfr;
32300 	  room = *nstr + 1;
32301 	  break;
32302        case 13:
32303 	  strarr = mlftit;
32304 	  nstrings = &ntits;
32305 	  room = *nstr + 1;
32306 	  if (ntits >= mxtits) return;
32307 	  break;
32308        case 14:
32309 	  strarr = gmx;
32310 	  nstrings = &Ngmx;
32311 	  room = *nstr + 1;
32312 	  break;
32313        case 15:
32314 	  strarr = gmx2;
32315 	  nstrings = &Ngmx2;
32316 	  room = *nstr + 1;
32317 	  break;
32318        case 16:
32319 	  strarr = g43;
32320 	  nstrings = &Ng43;
32321 	  room = *nstr + 1;
32322 	  break;
32323        case 17:
32324 	  strarr = amostr;
32325 	  nstrings = &Namostr;
32326 	  room = *nstr + 1;
32327 	  break;
32328        case 18:
32329 	  strarr = grostr;
32330 	  nstrings = &Ngrostr;
32331 	  room = *nstr + 1;
32332 	  break;
32333        case 19:
32334 	  strarr = gffext;
32335 	  nstrings = &Ngffext;
32336 	  room = *nstr + 1;
32337 	  break;
32338        case 20:
32339 	  strarr = exepath;
32340 	  nstrings = &Nexepath;
32341 	  room = *nstr + 1;
32342 	  break;
32343        }
32344 
32345        strarr[*nstrings] = (char *) malloc(room);
32346        if (!strarr[*nstrings]) fprintf(stderr,"getfiles: malloc error\n");
32347        strcp(str,strarr[*nstrings],*nstr);
32348 #ifndef CRAY
32349        strarr[*nstrings][*nstr] = '\0';
32350 #endif
32351        (*nstrings)++;
32352 
32353 /* postprocess some strings */
32354 
32355        if (*iopt == 20) {
32356 	  char *p;
32357 
32358 	  if ((p = strrchr(exepath[0], '/'))) {
32359 		p++; *p = '\0';
32360 	  } else {
32361 		p = exepath[0];
32362 		*p = '\0';
32363 	  }
32364        }
32365 }
32366 
32367 #if defined(VMS) || defined(UNDERSC)
parstr(str,iopt)32368 void parstr(str, iopt)
32369 #else
32370 #ifdef CRAY
32371 void PARSTR(str, iopt)
32372 #else
32373 void parstr_(str, iopt)
32374 #endif
32375 #endif
32376 
32377 #ifdef VMS
32378 struct dsc$descriptor_s *str;
32379 #else
32380 #ifdef CRAY
32381 _fcd str;
32382 #else
32383 char *str;
32384 #endif
32385 #endif
32386 int *iopt;
32387 {
32388        int n;
32389 
32390        switch(*iopt) {
32391        case 0:
32392 	  glin1 = str;
32393 	  break;
32394        case 1:
32395 	  glin2 = str;
32396 	  break;
32397        case 2:
32398 	  gtitl = str;
32399 	  break;
32400        case 3:
32401 	  jname = str;
32402 	  break;
32403        case 4:
32404 	  qname = str;
32405 	  break;
32406        case 5:
32407 	  ename = str;
32408 	  break;
32409        case 6:
32410 	  tnkjn = str;
32411 	  break;
32412        case 7:
32413 	  vfile = str;
32414 	  break;
32415        case 8:
32416 	  mfile = str;
32417 	  break;
32418        case 9:
32419 	  oglfile = str;
32420 	  break;
32421        case 10:
32422 	  povfile = str;
32423 	  break;
32424        case 11:
32425 	  n = strlen(str);
32426 	  if (pdbcode != NULL && pdbcode == pdbcbck) free(pdbcode);
32427 	  pdbcode = (char *) malloc(n+1);
32428 	  pdbcbck = pdbcode;
32429 	  strncpy(pdbcode,str,n);
32430 	  pdbcode[4] = '\0';
32431 	  break;
32432        case 12:
32433 	  gfile = str;
32434 	  break;
32435        case 13:
32436 	  tmpfil = str;
32437 	  break;
32438        }
32439 }
32440 
cpstr(ostr,str,nlen)32441 void cpstr(ostr,str,nlen)
32442 char *ostr;
32443 #ifdef VMS
32444 struct dsc$descriptor_s *str;
32445 #else
32446 #ifdef CRAY
32447 _fcd str;
32448 #else
32449 char *str;
32450 #endif
32451 #endif
32452 int nlen;
32453 {
32454 /* ostr (C) -> str (Fortran) */
32455   int i;
32456   int n;
32457 
32458   if (nlen) {
32459 	n = MINI(strlen(ostr),nlen);
32460   } else {
32461 	n = strlen(ostr);
32462   }
32463 
32464 #ifdef VMS
32465                 for (i=0; i<n; i++)
32466                       {str->dsc$a_pointer[i] = ostr[i];}
32467 #else
32468 #ifdef CRAY
32469                 strncpy(_fcdtocp(str),ostr,n);
32470 #else
32471                 for (i=0; i<nlen; i++) str[i] = '\0';
32472                 strncpy(str,ostr,n);
32473 #endif
32474 #endif
32475 }
32476 
strcp(str,ostr,nlen)32477 void strcp(str,ostr,nlen)
32478 #ifdef VMS
32479 struct dsc$descriptor_s *str;
32480 #else
32481 #ifdef CRAY
32482 _fcd str;
32483 #else
32484 char *str;
32485 #endif
32486 #endif
32487 char *ostr;
32488 int nlen;
32489 {
32490 /* str (fortran) -> ostr (C) */
32491   int i;
32492 
32493 #ifdef VMS
32494                 for (i=0; i<nlen; i++)
32495                       ostr[i] = str->dsc$a_pointer[i];
32496 #else
32497 #ifdef CRAY
32498                 strncpy(ostr,_fcdtocp(str),nlen);
32499 #else
32500                 for (i=0; i<nlen; i++) ostr[i] = '\0';
32501                 strncpy(ostr,str,nlen);
32502 #endif
32503 #endif
32504 }
32505 
32506 #if defined(VMS) || defined(UNDERSC)
gtht(charr,ires)32507 void gtht(charr,ires)
32508 #else
32509 #ifdef CRAY
32510 void GTHT(charr,ires)
32511 #else
32512 void gtht_(charr,ires)
32513 #endif
32514 #endif
32515 int *charr;
32516 int *ires;
32517 {
32518    int i;
32519 
32520    if (*ires-1 < hetptr.NHetAtm) {
32521 	if (hetptr.HetAtm[*ires-1] == NULL) {
32522 	   charr[0] = 'R';
32523 	   charr[1] = 'E';
32524 	   charr[2] = 'S';
32525 	} else {
32526 	   for(i=0; i<3; i++) {
32527 		charr[i] = hetptr.HetAtm[*ires-1][i];
32528 	   }
32529 	}
32530    } else {
32531 	charr[0] = 'H';
32532 	charr[1] = 'O';
32533 	charr[2] = 'H';
32534    }
32535 }
32536 
send_expose()32537 void send_expose()
32538 {
32539    XExposeEvent expe;
32540 
32541    expe.type = Expose;
32542    expe.send_event = True;
32543    expe.display = display;
32544    expe.window = win;
32545    expe.x = 0;
32546    expe.y = 0;
32547    expe.count = 0;
32548    expe.width = width; expe.height = height;
32549    XSendEvent(display, win, True, ExposureMask, (XEvent *) &expe);
32550    XFlush(display);
32551 }
32552 
32553 #if defined(VMS) || defined(UNDERSC)
parfns(str,nstr)32554 void parfns(str, nstr)
32555 #else
32556 #ifdef CRAY
32557 void PARFNS(str, nstr)
32558 #else
32559 void parfns_(str, nstr)
32560 #endif
32561 #endif
32562 
32563 #ifdef VMS
32564 struct dsc$descriptor_s *str;
32565 #else
32566 #ifdef CRAY
32567 _fcd str;
32568 #else
32569 char *str;
32570 #endif
32571 #endif
32572 int *nstr;
32573 {
32574 
32575    if (*nstr < MAXSTRLEN) {
32576        strcp(str,strname,*nstr);
32577 #ifndef CRAY
32578        strname[*nstr] = '\0';
32579 #endif
32580    }
32581 
32582 }
32583 
32584 volatile sig_atomic_t pdone;
32585 
handle_child()32586 static void handle_child()
32587 {
32588 /*  fprintf(stderr,"handle_child %d\n",tnkpid);*/
32589   sigprocmask(SIG_BLOCK,&base_mask,NULL);
32590   pdone = 1;
32591   fndfile = 1;
32592   tnkupf = 1;
32593   if (tnkloop) send_expose();
32594   sigprocmask(SIG_UNBLOCK,&base_mask,NULL);
32595 }
32596 
32597 static int tdone;
32598 
handle_alarm()32599 static void handle_alarm()
32600 {
32601   tdone = 1;
32602 }
32603 
handle_explalarm()32604 static void handle_explalarm()
32605 {
32606    XMapEvent expe;
32607    Window win;
32608 
32609    expe.type = MapNotify;
32610    expe.display = display;
32611    if (expldat.borq) {
32612 	win = expldat.qarr[expldat.button].win;
32613    } else {
32614 	win = expldat.barr[expldat.button].win;
32615    }
32616    expe.window = expldat.win;
32617    if (expldat.winup != NULL) if (! *expldat.winup) return;
32618 
32619    if (!expldat.active && !animptr.on && !*movie) {
32620 	XFlush(display);
32621 	XSendEvent(display, win,
32622 		False, SubstructureNotifyMask, (XEvent *) &expe);
32623 	XFlush(display);
32624    }
32625 }
32626 
DoSvgfile()32627 static void DoSvgfile()
32628 {
32629    Window win;
32630    char str[500];
32631    char str1[500];
32632    int i;
32633 
32634 /*
32635 fprintf(stderr,"DoSvgfile CurSVG %d uping %d\n",bcksvg.CurSVG,uping);
32636 */
32637    if (!bcksvg.UpSVG) return;
32638 
32639    if (uping) {
32640 #ifdef HASTIMER
32641 	Timer(100,3);
32642 #else
32643 	signal(SIGALRM,handle_svgfile);
32644 	alarm(2);
32645 #endif
32646 	return;
32647    }
32648 
32649    uping = 1;
32650    signal(SIGALRM,SIG_IGN);
32651 
32652    if (!expldat.active && !animptr.on && !*movie && bcksvg.UpSVG) {
32653      for (i = 0; i < CHUNK; i++) {
32654 	sprintf(str,"/tmp/b%d.svg",bcksvg.CurSVG+1);
32655 	sprintf(str1,"/tmp/b%d.svg",bcksvg.CurSVG+2);
32656 	if (access(str1,F_OK) == 0 || bcksvg.CurSVG+1 == bcksvg.NUpSVG) {
32657 	   bcksvg.ReadSVG = 1;
32658 	   rdsvg(&COO[bcksvg.istruct]->svgs[bcksvg.CurSVG],str);
32659 	   bcksvg.CurSVG++;
32660 	   if (bcksvg.CurSVG >= bcksvg.NUpSVG) {
32661 		bcksvg.UpSVG = 0;
32662 		bcksvg.NUpSVG = 0;
32663 		bcksvg.CurSVG = 0;
32664 	   	handle = 0;
32665 	   	bcksvg.ReadSVG = 0;
32666 		COO[bcksvg.istruct]->svgdone = 1;
32667 		wrsvgs();
32668 		uping = 0;
32669 		return;
32670 	   }
32671 	}
32672     }
32673 #ifdef HASTIMER
32674 	Timer(100,3);
32675 #else
32676 	signal(SIGALRM,handle_svgfile);
32677 	alarm(2);
32678 #endif
32679    }
32680    uping = 0;
32681 }
32682 
SvgExpose()32683 static void SvgExpose()
32684 {
32685    XExposeEvent expe;
32686 
32687    expe.type = Expose;
32688    expe.send_event = True;
32689    expe.display = display;
32690    expe.window = MLTwin;
32691 /*   expe.count = 0;*/
32692 
32693    if (!expldat.active && !animptr.on && !*movie && bcksvg.UpSVG && !uping) {
32694 	if (*WinObj[30].winup) {
32695 	   XFlush(display);
32696 	   XSendEvent(display, MLTwin,
32697 		False, ExposureMask, (XEvent *) &expe);
32698 	   XFlush(display);
32699 	} else {
32700 	   initMLT();
32701 	}
32702 
32703    }
32704    DoSVGExpose = 0;
32705 }
32706 
handle_svgfile()32707 static void handle_svgfile()
32708 {
32709    if (uping)  return;
32710 
32711    sigprocmask(SIG_BLOCK,&base_mask,NULL);
32712    DoSVGExpose = 1;
32713    if (!expldat.active && !animptr.on && !*movie && bcksvg.UpSVG && !uping) {
32714 	DoSVGExpose = 1;
32715    }
32716    sigprocmask(SIG_UNBLOCK,&base_mask,NULL);
32717 }
32718 
32719 static int escopt = 0;
32720 
handle_tnk()32721 static void handle_tnk()
32722 {
32723    sigprocmask(SIG_BLOCK,&base_mask,NULL);
32724    tnkupf = 1;
32725    sigprocmask(SIG_UNBLOCK,&base_mask,NULL);
32726 }
32727 
update_tnk()32728 static void update_tnk()
32729 {
32730    int phlp,iret,i;
32731    char cmdcyc[MAXCMD];
32732    struct stat st;
32733    struct timeval tv,tvn;
32734    long tvs,tvu, tottv;
32735 
32736    if (uping) return;
32737 
32738    uping = 1;
32739    nomemf = 1;
32740    if (opttim) gettimeofday(&tv,NULL);
32741 
32742    phlp = pdone;
32743    sprintf(cmdcyc,"%s.%03d",cmdstr,cycle);
32744 /*fprintf(stderr,"TNKPNT %s\n",cmdcyc);*/
32745    fndfile = 1;
32746    st.st_mode = 0;
32747    if (!stat(cmdcyc, &st)) {
32748 /*fprintf(stderr,"Found file %s\n",cmdcyc);*/
32749 	signal(SIGALRM,SIG_IGN);
32750 #if defined(VMS) || defined(UNDERSC)
32751        	tnkpnt(&cycle,&iret);
32752 #else
32753 #ifdef CRAY
32754        	TNKPNT(&cycle,&iret);
32755 #else
32756        	tnkpnt_(&cycle,&iret);
32757 #endif
32758 #endif
32759 	if (iret) {
32760 	   tnkupd = 1;
32761 	   if (tnkloop) send_expose();
32762            if (delcyclefile) unlink(cmdcyc);
32763 	   cycle++;
32764 	} else {
32765 	   fprintf(stderr,"found file ERROR\n");
32766 	}
32767 
32768    } else {
32769 /*fprintf(stderr,"NOT Found file %s\n",cmdcyc);*/
32770 	if (phlp == pdone) {
32771 	   fndfile = 0;
32772 	   if (tnkloop) send_expose();
32773 	}
32774    }
32775 
32776    if (opttim) {
32777 	gettimeofday(&tvn,NULL);
32778 	tvs = tvn.tv_sec - tv.tv_sec;
32779 	tvu = (tvn.tv_usec - tv.tv_usec) / 1000L;
32780 	timo[icyco] = tvu;
32781 	icyco++;
32782 	if (icyco >= NCYCO) {
32783 	   tottv = 0L;
32784 	   for (i=0; i<NCYCO; i++)  {
32785 		tottv = tottv + timo[i];
32786 	   }
32787 	   TIMi = 2*((int) tottv) / NCYCO;
32788 	   if (TIMi < 5) TIMi = 5;
32789 	   opttim = 0;
32790 	}
32791    }
32792 
32793    uping = 0;
32794    nomemf = 0;
32795 }
32796 
handle_tnkesc()32797 static void handle_tnkesc()
32798 {
32799    tnkesc = 1;
32800 }
32801 
esctnk()32802 static void esctnk()
32803 {
32804    int ist,phlp,iret,cyclo;
32805    char cmdcyc[MAXCMD];
32806    char cmdtmp[MAXCMD];
32807    struct stat st;
32808 
32809    sprintf(cmdcyc,"%s.%03d",cmdstr,cycle);
32810    sprintf(cmdtmp,"%s.tmp",cmdstr);
32811    phlp = pdone;
32812    fndfile = 1;
32813    st.st_mode = 0;
32814    cyclo = cycle;
32815    while (!stat(cmdcyc, &st)) {
32816 	/*fprintf(stderr,"esc Found file %s\n",cmdcyc);*/
32817 	cyclo = cycle;
32818 	if (delcyclefile) {
32819 	   ist = rename(cmdcyc,cmdtmp);
32820 	   if (rename(cmdcyc,cmdtmp)) {
32821 	      unlink(cmdcyc);
32822 	   }
32823 	} else {
32824 	   strcpy(cmdtmp,cmdcyc);
32825 	}
32826 	cycle++;
32827         sprintf(cmdcyc,"%s.%03d",cmdstr,cycle);
32828    }
32829 
32830    if ( (access(cmdtmp,F_OK) == 0 && !isdir(cmdtmp)) ) {
32831 
32832 	if (delcyclefile) cyclo = -1;
32833 #if defined(VMS) || defined(UNDERSC)
32834 	tnkpnt(&cyclo,&iret);
32835 #else
32836 #ifdef CRAY
32837 	TNKPNT(&cyclo,&iret);
32838 #else
32839 	tnkpnt_(&cyclo,&iret);
32840 #endif
32841 #endif
32842         if (delcyclefile) unlink(cmdtmp);
32843 
32844 	if (iret) {
32845 	   tnkupd = 1;
32846 	   if (tnkloop) send_expose();
32847 	}
32848 
32849    } else {
32850 
32851 	if (phlp == pdone) {
32852 	   fndfile = 0;
32853 	   if (tnkloop) send_expose();
32854 	}
32855    }
32856 
32857    escopt = 0;
32858 
32859 #ifdef HASTIMER
32860    Timer(100,1);
32861 #endif
32862 
32863 }
32864 
escox()32865 int escox()
32866 {
32867    char cmdtmp[MAXCMD];
32868    struct stat st;
32869 
32870    sprintf(cmdtmp,"%s_opt.xyz",cmdstr);
32871    st.st_mode = 0;
32872    if (!stat(cmdtmp, &st)) {
32873 	if (st.st_size) return(1);
32874    }
32875    return(0);
32876 }
32877 
spaesc(fname)32878 void spaesc(fname)
32879 char *fname;
32880 {
32881    char tmpf[MAXCMD], *p, *q;
32882 
32883    strcpy(tmpf,fname);
32884 
32885    while ((p = strchr(fname,' '))) {
32886       q = strchr(tmpf,' ');
32887       p[0] = '\\';
32888       p[1] = '\0';
32889       strcat(fname,q);
32890       p[1] = '\n';
32891       strcpy(tmpf,fname);
32892    }
32893 
32894    while ((p = strchr(fname,'\n'))) p[0] = ' ';
32895 }
32896 
setlck(i)32897 void setlck(i)
32898 int *i;
32899 {
32900         FILE *out;
32901         char lckfile[80];
32902 	struct stat st;
32903 
32904         sprintf(lckfile,"%d.ambforw",*i);
32905 
32906 	st.st_mode = 0;
32907 	if (stat(lckfile, &st)) {
32908            out = fopen(lckfile,"w");
32909            fprintf(out,"lock\n");
32910            fclose(out);
32911 	}
32912 }
32913 
32914 #if defined(VMS) || defined(UNDERSC)
islck(i)32915 int islck(i)
32916 #else
32917 #ifdef CRAY
32918 int ISLCK(i)
32919 #else
32920 int islck_(i)
32921 #endif
32922 #endif
32923 int *i;
32924 {
32925         FILE *out;
32926         char lckfile[80];
32927 	struct stat st;
32928 
32929         sprintf(lckfile,"%d.ambforw",*i);
32930 
32931 	st.st_mode = 0;
32932 
32933 	if (!stat(lckfile, &st)) {
32934 	   return 1;
32935 	} else {
32936 	   return 0;
32937 	}
32938 }
32939 
getexe(iprg,mpi,cmdfil)32940 int getexe(iprg,mpi,cmdfil)
32941 int iprg;
32942 int mpi;
32943 char *cmdfil;
32944 {
32945 
32946 #ifdef __CYGWIN__
32947    sprintf(cmdfil,"%s%s.exe",exepath[0],AmbProgs[iprg]);
32948 #else
32949    if (mpi) {
32950 	sprintf(cmdfil,"%s%s.mpi",exepath[0],AmbProgs[iprg]);
32951    } else {
32952 	sprintf(cmdfil,"%s%s",exepath[0],AmbProgs[iprg]);
32953    }
32954 #endif
32955 
32956    if (! (access(cmdfil,F_OK) == 0 && !isdir(cmdfil))) {
32957 #ifdef __CYGWIN__
32958 	sprintf(cmdfil,"%sambfor/%s.exe",exepath[0],AmbProgs[iprg]);
32959 #else
32960 	if (mpi) {
32961 	   sprintf(cmdfil,"%sambfor/%s.mpi",exepath[0],AmbProgs[iprg]);
32962 	} else {
32963 	   sprintf(cmdfil,"%sambfor/%s",exepath[0],AmbProgs[iprg]);
32964 	}
32965 #endif
32966 	if (! (access(cmdfil,F_OK) == 0)) {
32967 	   if (mpi) {
32968 		sprintf(cmdfil,"%s.mpi",AmbProgs[iprg]);
32969 	   } else {
32970 		sprintf(cmdfil,"%s",AmbProgs[iprg]);
32971 	   }
32972 	} else {
32973 	   return(1);
32974 	}
32975    } else {
32976 	return(1);
32977    }
32978    return(0);
32979 }
32980 
doamb(jobstr)32981 void doamb(jobstr)
32982 char *jobstr;
32983 {
32984    char cmdfil[MAXCMD];
32985    char cmdopt[MAXCMD];
32986    char cmdtmp[MAXCMD] = "ambfor ";
32987    char **argv;
32988    char *p;
32989    char *ambfor = "ambfor";
32990    char *spntr;
32991    char gtolstr[20];
32992    char iterstr[20];
32993    int iprg;
32994    FILE *out;
32995 
32996    if (hasmpi && usempi) {
32997 	domamb(jobstr);
32998 	return;
32999    }
33000 
33001    iprg = *tnkprg;
33002    if (iprg == 2) iprg = 0;
33003 
33004    strcpy(cmdtmp,DOSpath(jobstr));
33005    strcat(cmdtmp,"_opt.xyz");
33006    if ( (access(cmdtmp,F_OK) == 0 && !isdir(cmdtmp)) ) {
33007 	strcpy(cmdopt,cmdtmp);
33008 	strcat(cmdopt,".old");
33009 	if (rename(cmdtmp,cmdopt)) {
33010 	   fprintf(stderr,"error renaming existing file %s\n",cmdopt);
33011 	}
33012    }
33013 
33014    strcpy(cmdtmp,DOSpath(jobstr));
33015    strcat(cmdtmp,".tmp");
33016    if ( (access(cmdtmp,F_OK) == 0 && !isdir(cmdtmp)) ) {
33017 	unlink(cmdtmp);
33018    }
33019 
33020    sprintf(gtolstr,"%f",*currgrd);
33021    sprintf(iterstr,"%d",*tnkit);
33022 
33023    getexe(iprg,0,cmdfil);
33024 
33025    strcpy(cmdtmp,cmdfil);
33026 #ifdef __CYGWIN__
33027    spaesc(cmdtmp);
33028    if (p = strstr(cmdfil,".exe")) p[0] = '\0';
33029 #endif
33030    strcat(cmdtmp," ");
33031 
33032    if (tnk_single) {
33033 	strcat(cmdtmp,"-n -s ");
33034    } else {
33035 	if (*tnkbg) {
33036 	   strcat(cmdtmp,"-n ");
33037 	} else {
33038 	   strcat(cmdtmp,"-M ");
33039 	}
33040 
33041 	if (*arch) {
33042 	   strcat(cmdtmp," -a ");
33043 	}
33044 
33045 	if (Box) {
33046 	   strcat(cmdtmp," -b ");
33047 	}
33048 
33049 	if (Cutoff) {
33050 	   strcat(cmdtmp," -N ");
33051 	}
33052 
33053 	strcat(cmdtmp,grdFlags[iprg]);
33054 	strcat(cmdtmp," ");
33055 	strcat(cmdtmp,gtolstr);
33056 
33057 	strcat(cmdtmp," ");
33058 	strcat(cmdtmp,iterFlags[iprg]);
33059 	strcat(cmdtmp," ");
33060 	strcat(cmdtmp,iterstr);
33061 
33062 	strcat(cmdtmp," ");
33063    }
33064 
33065    strcat(cmdtmp,DOSpath(jobstr));
33066 
33067    if (tnk_single) {
33068 	system(cmdtmp);
33069 	strcpy(cmdtmp,DOSpath(jobstr));
33070 	strcat(cmdtmp,".log");
33071 	out = fopen(cmdtmp,"r");
33072 	if (out != NULL) {
33073 	   while (fgets(cmdfil,MAXCMD,out) != NULL) {
33074 		if (strstr(cmdfil,"Estat") != NULL) {
33075 		   spntr = cmdfil + 6;
33076 		   sscanf(spntr,"%lf",&newen);
33077 /*
33078 		   fprintf(stderr,"newen %f\n",newen);
33079 */
33080 		}
33081 	   }
33082 	   fclose(out);
33083 	}
33084    } else {
33085      if (*tnkbg) {
33086 	if (*arch) {
33087 	   if (Box) {
33088 	      if (Cutoff) {
33089 		if (execlp(cmdfil,AmbProgs[iprg],"-n","-a","-b","-N",
33090 		    grdFlags[iprg],gtolstr,
33091 		    iterFlags[iprg],iterstr,
33092 		    DOSpath(jobstr),NULL) == -1) {
33093 		    system(cmdtmp);
33094 		}
33095 	      } else {
33096 		if (execlp(cmdfil,AmbProgs[iprg],"-n","-a","-b",
33097 		    grdFlags[iprg],gtolstr,
33098 		    iterFlags[iprg],iterstr,
33099 		    DOSpath(jobstr),NULL) == -1) {
33100 		    system(cmdtmp);
33101 		}
33102 	      }
33103 	   } else {
33104 	      if (Cutoff) {
33105 		if (execlp(cmdfil,AmbProgs[iprg],"-n","-a","-N",
33106 		    grdFlags[iprg],gtolstr,
33107 		    iterFlags[iprg],iterstr,
33108 		    DOSpath(jobstr),NULL) == -1) {
33109 		    system(cmdtmp);
33110 		}
33111 	      } else {
33112 		if (execlp(cmdfil,AmbProgs[iprg],"-n","-a",
33113 		    grdFlags[iprg],gtolstr,
33114 		    iterFlags[iprg],iterstr,
33115 		    DOSpath(jobstr),NULL) == -1) {
33116 		    system(cmdtmp);
33117 		}
33118 	      }
33119 	   }
33120 	} else {
33121 
33122 	   if (Box) {
33123 	      if (Cutoff) {
33124 		if (execlp(cmdfil,AmbProgs[iprg],"-n","-b","-N",
33125 		    grdFlags[iprg],gtolstr,
33126 		    iterFlags[iprg],iterstr,
33127 		    DOSpath(jobstr),NULL) == -1) {
33128 		    system(cmdtmp);
33129 		}
33130 	      } else {
33131 		if (execlp(cmdfil,AmbProgs[iprg],"-n","-b",
33132 		    grdFlags[iprg],gtolstr,
33133 		    iterFlags[iprg],iterstr,
33134 		    DOSpath(jobstr),NULL) == -1) {
33135 		    system(cmdtmp);
33136 		}
33137 	      }
33138 	   } else {
33139 	      if (Cutoff) {
33140 		if (execlp(cmdfil,AmbProgs[iprg],"-n","-N",
33141 		    grdFlags[iprg],gtolstr,
33142 		    iterFlags[iprg],iterstr,
33143 		    DOSpath(jobstr),NULL) == -1) {
33144 		    system(cmdtmp);
33145 		}
33146 	      } else {
33147 		if (execlp(cmdfil,AmbProgs[iprg],"-n",
33148 		    grdFlags[iprg],gtolstr,
33149 		    iterFlags[iprg],iterstr,
33150 		    DOSpath(jobstr),NULL) == -1) {
33151 		    system(cmdtmp);
33152 		}
33153 	      }
33154 	   }
33155 
33156 	}
33157      } else {
33158 	if (*arch) {
33159 	   if (Box) {
33160 	      if (Cutoff) {
33161 		if (execlp(cmdfil,AmbProgs[iprg],"-M","-a","-b","-N",
33162 		    grdFlags[iprg],gtolstr,
33163 		    iterFlags[iprg],iterstr,
33164 		    DOSpath(jobstr),NULL) == -1) {
33165 		    system(cmdtmp);
33166 		}
33167 	      } else {
33168 		if (execlp(cmdfil,AmbProgs[iprg],"-M","-a","-b",
33169 		    grdFlags[iprg],gtolstr,
33170 		    iterFlags[iprg],iterstr,
33171 		    DOSpath(jobstr),NULL) == -1) {
33172 		    system(cmdtmp);
33173 		}
33174 	      }
33175 	   } else {
33176 	      if (Cutoff) {
33177 		if (execlp(cmdfil,AmbProgs[iprg],"-M","-a","-N",
33178 		    grdFlags[iprg],gtolstr,
33179 		    iterFlags[iprg],iterstr,
33180 		    DOSpath(jobstr),NULL) == -1) {
33181 		    system(cmdtmp);
33182 		}
33183 	      } else {
33184 		if (execlp(cmdfil,AmbProgs[iprg],"-M","-a",
33185 		    grdFlags[iprg],gtolstr,
33186 		    iterFlags[iprg],iterstr,
33187 		    DOSpath(jobstr),NULL) == -1) {
33188 		    system(cmdtmp);
33189 		}
33190 	      }
33191 	   }
33192 	} else {
33193 	   if (Box) {
33194 	      if (Cutoff) {
33195 		if (execlp(cmdfil,AmbProgs[iprg],"-M","-b","-N",
33196 		    grdFlags[iprg],gtolstr,
33197 		    iterFlags[iprg],iterstr,
33198 		    DOSpath(jobstr),NULL) == -1) {
33199 		    system(cmdtmp);
33200 		}
33201 	      } else {
33202 		if (execlp(cmdfil,AmbProgs[iprg],"-M","-b",
33203 		    grdFlags[iprg],gtolstr,
33204 		    iterFlags[iprg],iterstr,
33205 		    DOSpath(jobstr),NULL) == -1) {
33206 		    system(cmdtmp);
33207 		}
33208 	      }
33209 	   } else {
33210 	      if (Cutoff) {
33211 		if (execlp(cmdfil,AmbProgs[iprg],"-M","-N",
33212 		    grdFlags[iprg],gtolstr,
33213 		    iterFlags[iprg],iterstr,
33214 		    DOSpath(jobstr),NULL) == -1) {
33215 		    system(cmdtmp);
33216 		}
33217 	      } else {
33218 		if (execlp(cmdfil,AmbProgs[iprg],"-M",
33219 		    grdFlags[iprg],gtolstr,
33220 		    iterFlags[iprg],iterstr,
33221 		    DOSpath(jobstr),NULL) == -1) {
33222 		    system(cmdtmp);
33223 		}
33224 	      }
33225 	   }
33226 	}
33227      }
33228    }
33229 }
33230 
domamb(jobstr)33231 void domamb(jobstr)
33232 char *jobstr;
33233 {
33234    char cmdfil[MAXCMD];
33235    char cmdopt[MAXCMD];
33236    char cmdtmp[MAXCMD] = "ambfor ";
33237    char **argv;
33238    char *p;
33239    char *ambfor = "ambfor";
33240    char *spntr;
33241    char gtolstr[20];
33242    char iterstr[20];
33243    char procstr[20];
33244    int iprg;
33245    FILE *out;
33246 
33247    iprg = *tnkprg;
33248    if (iprg == 2) iprg = 0;
33249 
33250    strcpy(cmdtmp,DOSpath(jobstr));
33251    strcat(cmdtmp,"_opt.xyz");
33252    if ( (access(cmdtmp,F_OK) == 0 && !isdir(cmdtmp)) ) {
33253 	strcpy(cmdopt,cmdtmp);
33254 	strcat(cmdopt,".old");
33255 	if (rename(cmdtmp,cmdopt)) {
33256 	   fprintf(stderr,"error renaming existing file %s\n",cmdopt);
33257 	}
33258    }
33259 
33260    strcpy(cmdtmp,DOSpath(jobstr));
33261    strcat(cmdtmp,".tmp");
33262    if ( (access(cmdtmp,F_OK) == 0 && !isdir(cmdtmp)) ) {
33263 	unlink(cmdtmp);
33264    }
33265 
33266    sprintf(gtolstr,"%f",*currgrd);
33267    sprintf(iterstr,"%d",*tnkit);
33268    sprintf(procstr,"%d",useproc);
33269 
33270    getexe(iprg,1,cmdfil);
33271 
33272    strcpy(cmdtmp,mpicmd);
33273    strcat(cmdtmp," -np ");
33274    strcat(cmdtmp,procstr);
33275    strcat(cmdtmp," ");
33276    strcat(cmdtmp,cmdfil);
33277 
33278 #ifdef __CYGWIN__
33279    spaesc(cmdtmp);
33280    if (p = strstr(cmdfil,".exe")) p[0] = '\0';
33281 #endif
33282 
33283    strcat(cmdtmp," ");
33284 
33285    if (tnk_single) {
33286 	strcat(cmdtmp,"-n -s ");
33287    } else {
33288 	if (*tnkbg) {
33289 	   strcat(cmdtmp,"-n ");
33290 	} else {
33291 	   strcat(cmdtmp,"-M ");
33292 	}
33293 
33294 	if (*arch) {
33295 	   strcat(cmdtmp," -a ");
33296 	}
33297 
33298 	if (Box) {
33299 	   strcat(cmdtmp," -b ");
33300 	}
33301 
33302 	if (Cutoff) {
33303 	   strcat(cmdtmp," -N ");
33304 	}
33305 
33306 	strcat(cmdtmp,grdFlags[iprg]);
33307 	strcat(cmdtmp," ");
33308 	strcat(cmdtmp,gtolstr);
33309 
33310 	strcat(cmdtmp," ");
33311 	strcat(cmdtmp,iterFlags[iprg]);
33312 	strcat(cmdtmp," ");
33313 	strcat(cmdtmp,iterstr);
33314 
33315 	strcat(cmdtmp," ");
33316    }
33317 
33318    strcat(cmdtmp,DOSpath(jobstr));
33319 
33320    if (tnk_single) {
33321 	system(cmdtmp);
33322 	strcpy(cmdtmp,DOSpath(jobstr));
33323 	strcat(cmdtmp,".log");
33324 	out = fopen(cmdtmp,"r");
33325 	if (out != NULL) {
33326 	   while (fgets(cmdfil,MAXCMD,out) != NULL) {
33327 		if (strstr(cmdfil,"Estat") != NULL) {
33328 		   spntr = cmdfil + 6;
33329 		   sscanf(spntr,"%lf",&newen);
33330 /*
33331 		   fprintf(stderr,"newen %f\n",newen);
33332 */
33333 		}
33334 	   }
33335 	   fclose(out);
33336 	}
33337    } else {
33338      if (*tnkbg) {
33339 	if (*arch) {
33340 	   if (Box) {
33341 	      if (Cutoff) {
33342 		if (execlp(mpicmd,"mpirun",
33343 		    "-np",procstr,
33344 		    cmdfil,"-n","-a","-b","-N",
33345 		    grdFlags[iprg],gtolstr,
33346 		    iterFlags[iprg],iterstr,
33347 		    DOSpath(jobstr),NULL) == -1) {
33348 		    system(cmdtmp);
33349 		}
33350 	      } else {
33351 		if (execlp(mpicmd,"mpirun",
33352 		    "-np",procstr,
33353 		    cmdfil,"-n","-a","-b",
33354 		    grdFlags[iprg],gtolstr,
33355 		    iterFlags[iprg],iterstr,
33356 		    DOSpath(jobstr),NULL) == -1) {
33357 		    system(cmdtmp);
33358 		}
33359 	      }
33360 	   } else {
33361 	      if (Cutoff) {
33362 		if (execlp(mpicmd,"mpirun",
33363 		    "-np",procstr,
33364 		    cmdfil,"-n","-a","-N",
33365 		    grdFlags[iprg],gtolstr,
33366 		    iterFlags[iprg],iterstr,
33367 		    DOSpath(jobstr),NULL) == -1) {
33368 		    system(cmdtmp);
33369 		}
33370 	      } else {
33371 		if (execlp(mpicmd,"mpirun",
33372 		    "-np",procstr,
33373 		    cmdfil,"-n","-a",
33374 		    grdFlags[iprg],gtolstr,
33375 		    iterFlags[iprg],iterstr,
33376 		    DOSpath(jobstr),NULL) == -1) {
33377 		    system(cmdtmp);
33378 		}
33379 	      }
33380 	   }
33381 	} else {
33382 
33383 	   if (Box) {
33384 	      if (Cutoff) {
33385 		if (execlp(mpicmd,"mpirun",
33386 		    "-np",procstr,
33387 		    cmdfil,"-n","-b","-N",
33388 		    grdFlags[iprg],gtolstr,
33389 		    iterFlags[iprg],iterstr,
33390 		    DOSpath(jobstr),NULL) == -1) {
33391 		    system(cmdtmp);
33392 		}
33393 	      } else {
33394 		if (execlp(mpicmd,"mpirun",
33395 		    "-np",procstr,
33396 		    cmdfil,"-n","-b",
33397 		    grdFlags[iprg],gtolstr,
33398 		    iterFlags[iprg],iterstr,
33399 		    DOSpath(jobstr),NULL) == -1) {
33400 		    system(cmdtmp);
33401 		}
33402 	      }
33403 	   } else {
33404 	      if (Cutoff) {
33405 		if (execlp(mpicmd,"mpirun",
33406 		    "-np",procstr,
33407 		    cmdfil,"-n","-N",
33408 		    grdFlags[iprg],gtolstr,
33409 		    iterFlags[iprg],iterstr,
33410 		    DOSpath(jobstr),NULL) == -1) {
33411 		    system(cmdtmp);
33412 		}
33413 	      } else {
33414 		if (execlp(mpicmd,"mpirun",
33415 		    "-np",procstr,
33416 		    cmdfil,"-n",
33417 		    grdFlags[iprg],gtolstr,
33418 		    iterFlags[iprg],iterstr,
33419 		    DOSpath(jobstr),NULL) == -1) {
33420 		    system(cmdtmp);
33421 		}
33422 	      }
33423 	   }
33424 
33425 	}
33426      } else {
33427 	if (*arch) {
33428 	   if (Box) {
33429 	      if (Cutoff) {
33430 		if (execlp(mpicmd,"mpirun",
33431 		    "-np",procstr,
33432 		    cmdfil,"-M","-a","-b","-N",
33433 		    grdFlags[iprg],gtolstr,
33434 		    iterFlags[iprg],iterstr,
33435 		    DOSpath(jobstr),NULL) == -1) {
33436 		    system(cmdtmp);
33437 		}
33438 	      } else {
33439 		if (execlp(mpicmd,"mpirun",
33440 		    "-np",procstr,
33441 		    cmdfil,"-M","-a","-b",
33442 		    grdFlags[iprg],gtolstr,
33443 		    iterFlags[iprg],iterstr,
33444 		    DOSpath(jobstr),NULL) == -1) {
33445 		    system(cmdtmp);
33446 		}
33447 	      }
33448 	   } else {
33449 	      if (Cutoff) {
33450 		if (execlp(mpicmd,"mpirun",
33451 		    "-np",procstr,
33452 		    cmdfil,"-M","-a","-N",
33453 		    grdFlags[iprg],gtolstr,
33454 		    iterFlags[iprg],iterstr,
33455 		    DOSpath(jobstr),NULL) == -1) {
33456 		    system(cmdtmp);
33457 		}
33458 	      } else {
33459 		if (execlp(mpicmd,"mpirun",
33460 		    "-np",procstr,
33461 		    cmdfil,"-M","-a",
33462 		    grdFlags[iprg],gtolstr,
33463 		    iterFlags[iprg],iterstr,
33464 		    DOSpath(jobstr),NULL) == -1) {
33465 		    system(cmdtmp);
33466 		}
33467 	      }
33468 	   }
33469 	} else {
33470 	   if (Box) {
33471 	      if (Cutoff) {
33472 		if (execlp(mpicmd,"mpirun",
33473 		    "-np",procstr,
33474 		    cmdfil,"-M","-b","-N",
33475 		    grdFlags[iprg],gtolstr,
33476 		    iterFlags[iprg],iterstr,
33477 		    DOSpath(jobstr),NULL) == -1) {
33478 		    system(cmdtmp);
33479 		}
33480 	      } else {
33481 		if (execlp(mpicmd,"mpirun",
33482 		    "-np",procstr,
33483 		    cmdfil,"-M","-b",
33484 		    grdFlags[iprg],gtolstr,
33485 		    iterFlags[iprg],iterstr,
33486 		    DOSpath(jobstr),NULL) == -1) {
33487 		    system(cmdtmp);
33488 		}
33489 	      }
33490 	   } else {
33491 	      if (Cutoff) {
33492 		if (execlp(mpicmd,"mpirun",
33493 		    "-np",procstr,
33494 		    cmdfil,"-M","-N",
33495 		    grdFlags[iprg],gtolstr,
33496 		    iterFlags[iprg],iterstr,
33497 		    DOSpath(jobstr),NULL) == -1) {
33498 		    system(cmdtmp);
33499 		}
33500 	      } else {
33501 /*yoyyoyo*/
33502 		if (execlp(mpicmd,"mpirun",
33503 		    "-np",procstr,
33504 		    cmdfil,"-M",
33505 		    grdFlags[iprg],gtolstr,
33506 		    iterFlags[iprg],iterstr,
33507 		    DOSpath(jobstr),NULL) == -1) {
33508 		    system(cmdtmp);
33509 		}
33510 	      }
33511 	   }
33512 	}
33513      }
33514    }
33515 }
33516 
mloop(iopt)33517 void mloop(iopt)
33518 int *iopt;
33519 {
33520    int i;
33521    int ptmp,ctmp;
33522 
33523    sigprocmask(SIG_BLOCK,&base_mask,NULL);
33524    XFlush(display);
33525 
33526    tnkloop = 1;
33527 
33528    if (XPending(display)>0) {
33529 
33530 	if (XCheckTypedWindowEvent(display, winMC, ButtonPress,&event)) {
33531 	   event.xbutton.window = winMC;
33532 	} else {
33533 	   if (XCheckTypedWindowEvent(display, win, ButtonPress,&event)) {
33534 		event.xbutton.window = win;
33535 	   } else {
33536 		XNextEvent(display, &event);
33537 	   }
33538 	}
33539 	tnkloop = 0;
33540 
33541 	switch (event.type) {
33542 	case KeyPress:
33543 	{
33544 	   XKeyEvent *key_event = (XKeyEvent *) &event;
33545 	   char buf[10]; XComposeStatus status;
33546 	   int stlen,istat;
33547 
33548 	   stlen = XLookupString(key_event,buf,10,&ks,&status);
33549 	   if (key_event->window == win || key_event->window == winMC) {
33550 		if (ks==XK_Escape) {
33551 		  if (!pdone) kill(-tnkpid,SIGINT);
33552 		  escopt = 1; pdone = 1;
33553 		  if (!escox()) *iopt = -1;
33554  		  Timer(TIMi,1);
33555 		  /*fndfile = 0;*/
33556 		  break;
33557 		}
33558 	   }
33559 
33560 	}
33561 	break;
33562 	case ButtonPress:
33563 		if (event.xbutton.window == win) {
33564 		   if (event.xbutton.button == 3) OnTop();
33565 		   else if (event.xbutton.button == 4)
33566 			ScrollWheel(&ctmp,&ptmp,1);
33567 		   else if (event.xbutton.button == 5)
33568 			ScrollWheel(&ctmp,&ptmp,0);
33569 		   else {
33570 		      if (*ball) {
33571 			gmoving = 1;
33572 			moving = 1;
33573 			tnkupd = 1;
33574 			hold = 0;
33575 			startx = event.xbutton.x;
33576 			starty = event.xbutton.y;
33577 			btype = 0;
33578 			if (event.xbutton.state & ShiftMask) btype = 1;
33579 			if (event.xbutton.state & ControlMask) btype = 2;
33580 			if ((event.xbutton.state & ControlMask)
33581 					 && (event.xbutton.state & ShiftMask))
33582 						btype = 3;
33583 			if ((*fancy || *fullgl) && has_opengl)
33584 			    moused(event.xbutton.button,
33585 					   event.xbutton.state,
33586 					   event.xbutton.x,
33587 					   event.xbutton.y);
33588 		      } else {
33589 			    rotat(event.xbutton.x,event.xbutton.y);
33590 		      }
33591 		   }
33592 
33593 		} else if (event.xbutton.window == winMC) {
33594 
33595 		   i = Clickwin(cbut,NBUTTS2,event.xbutton.x,event.xbutton.y,1);
33596 
33597 		   switch (i) {
33598 			case BQUITT:
33599 				kill(-tnkpid,SIGINT);
33600 				/*fndfile = 0;*/
33601 				pdone = 1;
33602 				escopt = 1;
33603 				if (!escox()) *iopt = -1;
33604  		  		Timer(TIMi,1);
33605 				break;
33606 
33607 			case BZOOMIN:
33608 				hold = 1;
33609 				holdt = 290; holdp = -1;
33610 				break;
33611 
33612 			case BZOOMOUT:
33613 				hold = 1;
33614 				holdt = 290; holdp = 1;
33615 				break;
33616 
33617 			case BLEFT:
33618 				hold = 1;
33619 				holdt = 420; holdp = 0;
33620 				break;
33621 
33622 			case BRIGHT:
33623 				hold = 1;
33624 				holdt = 430; holdp = 0;
33625 				break;
33626 
33627 			case BUP:
33628 				hold = 1;
33629 				holdt = 440; holdp = 0;
33630 				break;
33631 
33632 			case BDOWN:
33633 				hold = 1;
33634 				holdt = 450; holdp = 0;
33635 				break;
33636 
33637 			case BSOLID:
33638 				tnkupd = 1;
33639 				TogBut(&cbut[BSOLID]);
33640 				if (*fancy) {
33641 				    *fancy = 0;
33642 				    if (has_opengl) {
33643 					if (*fullgl) {
33644 					   *ifogl = 1;
33645 					} else {
33646 					   *ifogl = 0;
33647 					}
33648 				    } else {
33649 					*ifogl = 0;
33650 				    }
33651 				} else {
33652 				    *fancy = 1;
33653 				    if (has_opengl) {
33654 					*ifogl = 1;
33655 				    } else {
33656 					*ifogl = 0;
33657 				    }
33658 				}
33659 				break;
33660 
33661 			case BATCOL:
33662 				tnkupd = 1;
33663 				TogBut(&cbut[BATCOL]);
33664 				if (*atcol) *atcol = 0;
33665 				else *atcol = 1;
33666 				break;
33667 
33668 			case BSHADE:
33669 				tnkupd = 1;
33670 				TogBut(&cbut[BSHADE]);
33671 				if (*shade) *shade = 0;
33672 				else if (colcells >= 256) *shade = 1;
33673 				break;
33674 
33675 			case BPERSP:
33676 				tnkupd = 1;
33677 				TogBut(&cbut[BPERSP]);
33678 				if (*persp) *persp = 0;
33679 				else *persp = 1;
33680 				break;
33681 			default:
33682 				break;
33683 		   }
33684 		}
33685 		break;
33686 
33687 	case ButtonRelease:
33688 		if (!((*fancy || *fullgl) && has_opengl)
33689 					&& event.xbutton.window == win) {
33690 		   moving = 0;
33691 		   gmoving = 0;
33692 		   hold = 0;
33693 		   holdt = 0; holdp = 0;
33694 		}
33695 
33696 		if (event.xbutton.window == win &&
33697 			   (event.xbutton.button == 1 ||
33698 			    event.xbutton.button == 2) && !ZoomSelection )
33699 		   moving = 0;
33700 
33701 		if (((*fancy || *fullgl) && has_opengl) &&
33702 				event.xbutton.window == win) {
33703 		   gmoving = 0;
33704 		   moving = 0;
33705 		   hold = 0;
33706 		   holdt = 0; holdp = 0;
33707 		   dispsf();
33708 		}
33709 		break;
33710 
33711 	case MotionNotify:
33712 		event.xmotion.window = win;
33713 		motion_screen(&ctmp,&ptmp);
33714 		break;
33715 
33716 	case ConfigureNotify:
33717 		if (event.xconfigure.window == win) {
33718 		    width = event.xconfigure.width;
33719 		    height = event.xconfigure.height;
33720 		    if ((*fancy || *fullgl) && has_opengl) {
33721 		    Reshape(0);
33722 		    dispsf();
33723 		    }
33724 		}
33725 		break;
33726 
33727 	case Expose:
33728 		if (event.xexpose.window == win) {
33729 		   if ((*fancy || *fullgl) && has_opengl) {
33730 			dispsf();
33731 		   } else {
33732 			if (molback == molcur)
33733 			   XCopyArea(display,molcur,win,gc,
33734 					0,0,width,height,0,0);
33735 		   }
33736 		}
33737 		if (event.xexpose.window == ZMEwin) RedrawZME();
33738 		if (event.xexpose.window == SEQwin) RedrawSEQ();
33739               	if (event.xexpose.window == ATMwin) RedrawATM();
33740               	if (event.xexpose.window == MLTwin) RedrawList(&mltlist);
33741 		if (event.xexpose.window == winMC)
33742 				RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
33743 		break;
33744 
33745 	default: break;
33746 	}
33747    }
33748 
33749    sigprocmask(SIG_UNBLOCK,&base_mask,NULL);
33750 }
33751 
33752 #if defined(VMS) || defined(UNDERSC)
sysstr(str,nstr)33753 void sysstr(str,nstr)
33754 #else
33755 #ifdef CRAY
33756 void SYSSTR(str,nstr)
33757 #else
33758 void sysstr_(str,nstr)
33759 #endif
33760 #endif
33761 
33762 #ifdef VMS
33763 struct dsc$descriptor_s *str;
33764 #else
33765 #ifdef CRAY
33766 _fcd str;
33767 #else
33768 char *str;
33769 #endif
33770 #endif
33771 int *nstr;
33772 
33773 {
33774 	int i,ns;
33775 	char cmdfil[MAXCMD];
33776 
33777         ns = *nstr;
33778         if (*nstr > MAXCMD ) ns = MAXCMD;
33779         for (i=0; i<MAXCMD; i++) cmdstr[i] = ' ';
33780 	strcp(str,cmdstr,ns);
33781 	cmdstr[ns] = '\0';
33782 
33783 	system(cmdstr);
33784 }
33785 
33786 #if defined(VMS) || defined(UNDERSC)
exstr(str,nstr,iopt)33787 void exstr(str,nstr,iopt)
33788 #else
33789 #ifdef CRAY
33790 void EXSTR(str,nstr,iopt)
33791 #else
33792 void exstr_(str,nstr,iopt)
33793 #endif
33794 #endif
33795 
33796 #ifdef VMS
33797 struct dsc$descriptor_s *str;
33798 #else
33799 #ifdef CRAY
33800 _fcd str;
33801 #else
33802 char *str;
33803 #endif
33804 #endif
33805 int *nstr;
33806 int *iopt;
33807 
33808 {
33809 	int pid,i,ns;
33810         int ptmp,ctmp;
33811 	char cmdfil[MAXCMD];
33812 	char cmdfilh[MAXCMD];
33813 
33814 	delcyclefile = 0;
33815         ns = *nstr;
33816         if (*nstr > MAXCMD ) ns = MAXCMD;
33817         for (i=0; i<MAXCMD; i++) cmdstr[i] = ' ';
33818 	strcp(str,cmdstr,ns);
33819 	cmdstr[ns] = '\0';
33820 
33821 	switch(*iopt) {
33822 	case 0:
33823 	  system(cmdstr);
33824 	  break;
33825 	case 4:
33826 	case 1:
33827 #ifdef DARWIN
33828 	  pid = fork();
33829 #else
33830 	  pid = vfork();
33831 #endif
33832 	  switch(pid) {
33833 	  case -1:
33834 		fprintf(stderr,"Couldnt Fork\n");
33835 		break;
33836 	  case 0:	/*child */
33837 /* iopt is always 1 since this is case 1: so it will nver do doamb here ?*/
33838                 if (*iopt == 1) {
33839 		   execlp(cmdstr," ",(char *)0);
33840 		} else {
33841 		   doamb(cmdstr);
33842 		}
33843 		_exit(0);
33844 		break;
33845 	  default:	/*parent*/
33846 		return;
33847 		break;
33848 	  }
33849 	  break;
33850 
33851 	case 5:
33852 	case 3:
33853 	case 2:
33854 
33855 	  if (*iopt == 3 && ! *tnkbg) setlck(&ONE);
33856 
33857 	  signal(SIGCHLD,handle_child);
33858 #ifdef DARWIN
33859 	  tnkpid = fork();
33860 #else
33861 	  tnkpid = vfork();
33862 #endif
33863 	  tnkfrk = 1;
33864 
33865 	  switch(tnkpid) {
33866 	  case -1:
33867 		fprintf(stderr,"Couldnt Fork\n");
33868 		break;
33869 	  case 0:	/*child */
33870 		tnkpid = getpid();
33871 #ifndef VMS
33872 		setpgid(tnkpid,tnkpid);
33873 #endif
33874 	  	signal(SIGCHLD,SIG_DFL);
33875 	  	signal(SIGALRM,SIG_DFL);
33876 
33877                 if (*iopt == 2) {
33878 
33879 		   sprintf(cmdfil,"./%s.run",cmdstr);
33880 		   sprintf(cmdfilh,"%s.run",cmdstr);
33881 		   execlp(cmdfil,cmdfilh,(char *) NULL);
33882 
33883 		} else if (*iopt == 3) {
33884 
33885 		   setenv("LD_LIBRARY_PATH",npth,1);
33886 		   doamb(cmdstr);
33887 
33888 		} else if (*iopt == 5) {
33889 		   system(cmdstr);
33890 		}
33891 		_exit(0);
33892 		break;
33893 	  default:	/*parent*/
33894 	  	pdone = 0;
33895 	  	cycle = 1;
33896 		fndfile = 1;
33897 		escopt = 0;
33898 		tnkesc = 0;
33899 #ifdef HASTIMER
33900 		hold = 0;
33901 		holdt = 0; holdp = 0;
33902 		update_model = 0;
33903 
33904 		if (*iopt == 3) delcyclefile = 1;
33905 
33906 		opttim = 1;
33907 		icyco = 0;
33908 	  	signal(SIGCHLD,handle_child);
33909 		sigemptyset(&base_mask);
33910 		sigaddset(&base_mask,SIGALRM);
33911 		sigaddset(&base_mask,SIGCHLD);
33912    		Timer(TIMi,1);
33913 	/*	delayt();*/
33914 #endif
33915 
33916 /*
33917 pdone = 1 means child is done or killed by users
33918 fndfile = 1 means there is still a cycle file wich need to be read in
33919           and updated
33920 The follwing while loop ends if pdone = 1 and fndfile = 0
33921 */
33922 
33923 		while (!(pdone && !fndfile)) {
33924 #ifdef HASTIMER
33925 /* update the on screen structure  (just once)
33926    and the loop for holding a move direction
33927 */
33928 
33929 		   if (hold || tnkupf || tnkupd || tnkesc) {
33930 			 while (1){
33931 			   XSync(display, False);
33932 			   if (XCheckMaskEvent(display,
33933 				ButtonReleaseMask, &event)) {
33934 				hold = 0;
33935 				holdt = 0; holdp = 0;
33936 				moving = 0;
33937 				gmoving = 0;
33938 				break;
33939 			   }
33940 
33941 			   if (tnkesc) {
33942 				esctnk();
33943 			   } else {
33944 				sigprocmask(SIG_BLOCK,&base_mask,NULL);
33945 		   		if (tnkupf) {
33946 				   update_tnk();
33947 	/* set new alarm */
33948 				   Timer(TIMi,1);
33949 				   tnkupf = 0;
33950 				   if ((*fancy || *fullgl) && has_opengl)
33951 					update_model = 1;
33952 				}
33953 				sigprocmask(SIG_UNBLOCK,&base_mask,NULL);
33954 			   }
33955 
33956 		   	   if (tnkupd || tnkesc) {
33957 				if ((*fancy || *fullgl) && has_opengl)
33958 				update_model = 1;
33959 				tnkupd = 0;
33960 			   }
33961 
33962 			   doclr();
33963 
33964 #if defined(VMS) || defined(UNDERSC)
33965 			   mktrn(&holdt,&holdp);
33966 			   qupd();
33967 #else
33968 #ifdef CRAY
33969 			   MKTRN(&holdt,&holdp);
33970 			   QUPD();
33971 #else
33972 			   mktrn_(&holdt,&holdp);
33973 			   qupd_();
33974 #endif
33975 #endif
33976 			   update_model = 0;
33977 
33978 			   if (!hold) break;
33979 
33980 			   if (tnkesc) break;
33981 
33982 			 }
33983 		   }
33984 
33985 		   if (tnkesc) break;
33986 
33987 		   mloop(iopt);
33988 #else
33989 /* not hastimer */
33990                    handle_tnk();
33991 #endif
33992 		   if (tnkupd) {
33993 		        update_model = 1;
33994 			doclr();
33995 #if defined(VMS) || defined(UNDERSC)
33996 			mktrn(&holdt,&holdp);
33997 			qupd();
33998 #else
33999 #ifdef CRAY
34000 			MKTRN(&holdt,&holdp);
34001 			QUPD();
34002 #else
34003 			mktrn_(&holdt,&holdp);
34004 			qupd_();
34005 #endif
34006 #endif
34007 		   }
34008 
34009 		}
34010 		/*fprintf(stderr,"End of process %d\n",tnkpid);*/
34011 	  	signal(SIGCHLD,SIG_IGN);
34012 	  	signal(SIGALRM,SIG_IGN);
34013 		break;
34014 	  }
34015 	  break;
34016 	}
34017 
34018 	signal(SIGCHLD,SIG_DFL);
34019 	signal(SIGALRM,SIG_IGN);
34020 
34021 	esctnk();
34022 	update_model = 1;
34023 	doclr();
34024 
34025 #if defined(VMS) || defined(UNDERSC)
34026 	qupd();
34027 #else
34028 #ifdef CRAY
34029 	QUPD();
34030 #else
34031 	qupd_();
34032 #endif
34033 #endif
34034 
34035 	handle = 0;
34036 	tnkfrk = 0;
34037 }
34038 
34039 #if defined(VMS) || defined(UNDERSC)
tomap(imap,iambfor)34040 void tomap(imap,iambfor)
34041 #else
34042 #ifdef CRAY
34043 void TOMAP(imap,iambfor)
34044 #else
34045 void tomap_(imap,iambfor)
34046 #endif
34047 #endif
34048 int *imap;
34049 int *iambfor;
34050 {
34051   *imap = 1;
34052   *iambfor = 0;
34053   if (Progs == AmbProgs && *tnkprg == 1) *imap = 0;
34054   if (Progs == AmbProgs) *iambfor = 1;
34055 }
34056 
typchk(silent)34057 int typchk(silent)
34058 int silent;
34059 {
34060    int i,j;
34061 
34062    j = 0;
34063    for ( i = 0; i < *xyzp->iatoms; i++ ) {
34064 	   if (xyzp->ianz[i] < 99 &&  xyzp->ityp[i] == 0) {
34065 		if (!silent) {
34066 		   if (xyzp->iresid[i] > 0) {
34067 			fprintf(stderr,"AtomNr. %d %s %s untyped\n",i+1,
34068 			elements[xyzp->ianz[i]],
34069 			AminoAcids[calfptr->iamino[xyzp->iresid[i]-1]-1]);
34070 			fprintf(stderr,"Coordinates (Ang) %#9.3f,%#9.3f,%#9.3f\n",
34071 			   xyzp->coo[i*3]*toangs,
34072 			   xyzp->coo[i*3+1]*toangs,
34073 			   xyzp->coo[i*3+2]*toangs);
34074 		   } else if (xyzp->iresid[i] < -3) {
34075 			fprintf(stderr,"AtomNr. %d %s %s untyped\n",i+1,
34076 			elements[xyzp->ianz[i]],
34077 			hetptr.HetAtm[ABS(xyzp->iresid[i])]);
34078 			fprintf(stderr,"Coordinates (Ang) %#9.3f,%#9.3f,%#9.3f\n",
34079 			   xyzp->coo[i*3]*toangs,
34080 			   xyzp->coo[i*3+1]*toangs,
34081 			   xyzp->coo[i*3+2]*toangs);
34082 		   }
34083 		}
34084 		j++;
34085 	   }
34086 
34087    }
34088    return(j);
34089 
34090 }
34091 
typit(ff,silent)34092 int typit(ff,silent)
34093 int ff;
34094 int silent;
34095 {
34096    int iretval,retype;
34097    char mess[64];
34098 
34099    iretval = 0;
34100    retype = 0;
34101 
34102    if (*fftyp != ff) {
34103 	*fftyp = ff;
34104 	retype = 1;
34105    } else {
34106 	if (typchk(silent)) retype = 1;
34107    }
34108 
34109    if (retype) {
34110 #if defined(VMS) || defined(UNDERSC)
34111 	dotyp(&cell->ichx);
34112 #else
34113 #ifdef CRAY
34114 	DOTYP(&cell->ichx);
34115 #else
34116 	dotyp_(&cell->ichx);
34117 #endif
34118 #endif
34119 	iretval = typchk(silent);
34120 
34121 	if (ATMup) {
34122 	   UpdateATM();
34123 	   XMapRaised(display,ATMwin);
34124 	   RedrawATM();
34125 	}
34126 	if (!silent) {
34127 	   sprintf(mess,"(Re)typing %s",ForceFields[*fftyp]);
34128 	   if (DoCan(event.xbutton.x_root,event.xbutton.y_root,mess,0)) {}
34129 	}
34130    }
34131    return(iretval);
34132 }
34133 
34134 static int json = 0;
34135 
WriteJSON(str)34136 int WriteJSON(str)
34137 char *str;
34138 {
34139   FILE *f;
34140   int i;
34141 
34142   f = fopen(str,"w");
34143 
34144   if (f == NULL) {
34145 	fprintf(stderr,"Error opening file %s\n",str);
34146  	return(0);
34147   }
34148 
34149   fprintf(f,"{\n");
34150   fprintf(f,"\t\"points\" :\n");
34151   fprintf(f,"\t[\n");
34152 
34153   for (i=0; i<pharm.NSelFeat; i++) {
34154 	fprintf(f,"\t\t{\n");
34155 	fprintf(f,"\t\t\t\"name\" : \"%s\",\n",
34156 		FeatStr[pharm.array[pharm.index[i]].type]);
34157 	fprintf(f,"\t\t\t\"radius\" : %f,\n",
34158 		pharm.array[pharm.index[i]].rad*0.52917706);
34159 	fprintf(f,"\t\t\t\"requirement\" : \"required\",\n");
34160 	fprintf(f,"\t\t\t\"size\" : %d,\n",
34161 		pharm.array[pharm.index[i]].size);
34162 	fprintf(f,"\t\t\t\"vector\" :\n");
34163 	fprintf(f,"\t\t\t[\n");
34164 	if (pharm.array[pharm.index[i]].type <= 2) {
34165 	   fprintf(f,"\t\t\t\t{\n");
34166 	   fprintf(f,"\t\t\t\t\t\"x\" : %f,\n",
34167 		pharm.array[pharm.index[i]].vec1[0]*0.52917706);
34168 	   fprintf(f,"\t\t\t\t\t\"y\" : %f,\n",
34169 		pharm.array[pharm.index[i]].vec1[1]*0.52917706);
34170 	   fprintf(f,"\t\t\t\t\t\"z\" : %f\n",
34171 		pharm.array[pharm.index[i]].vec1[2]*0.52917706);
34172 	   fprintf(f,"\t\t\t\t}");
34173 	   if (pharm.array[pharm.index[i]].type == 0) {
34174 		fprintf(f,",\n");
34175 	   } else {
34176 		fprintf(f,"\n");
34177 	   }
34178 
34179 	   if (pharm.array[pharm.index[i]].type == 0) {
34180 		fprintf(f,"\t\t\t\t{\n");
34181 		fprintf(f,"\t\t\t\t\t\"x\" : %f,\n",
34182 		pharm.array[pharm.index[i]].vec2[0]*0.52917706);
34183 		fprintf(f,"\t\t\t\t\t\"y\" : %f,\n",
34184 		pharm.array[pharm.index[i]].vec2[1]*0.52917706);
34185 		fprintf(f,"\t\t\t\t\t\"z\" : %f\n",
34186 		pharm.array[pharm.index[i]].vec2[2]*0.52917706);
34187 		fprintf(f,"\t\t\t\t}\n");
34188 	   }
34189         }
34190 	fprintf(f,"\t\t\t],\n");
34191 	fprintf(f,"\t\t\t\"x\" : %f,\n",
34192 		pharm.array[pharm.index[i]].cor[0]*0.52917706);
34193 	fprintf(f,"\t\t\t\"y\" : %f,\n",
34194 		pharm.array[pharm.index[i]].cor[1]*0.52917706);
34195 	fprintf(f,"\t\t\t\"z\" : %f\n",
34196 		pharm.array[pharm.index[i]].cor[2]*0.52917706);
34197 	if (i == pharm.NSelFeat -1)  {
34198 	   fprintf(f,"\t\t}\n");
34199 	} else {
34200 	   fprintf(f,"\t\t},\n");
34201 	}
34202   }
34203 
34204   fprintf(f,"\t]\n");
34205   fprintf(f,"}\n");
34206 
34207   fclose(f);
34208 }
34209 
GetJson(str)34210 int GetJson(str)
34211 char *str;
34212 {
34213   FILE *f;
34214   char strmax[1000];
34215   char *strtmp;
34216   int feat,i,next,isvec;
34217 
34218   if (json) return(0);
34219 
34220   json = 1;
34221 
34222   f = fopen(str,"r");
34223 
34224   if (f == NULL) {
34225 	fprintf(stderr,"Error opening file %s\n",str);
34226  	return(0);
34227   }
34228 
34229   pharm.nfeat = 0;
34230   while (1) {
34231      if (fgets(strmax,1000,f) == NULL) break;
34232      if (strstr(strmax,"\"name\""))  pharm.nfeat++;
34233   }
34234 
34235   rewind(f);
34236 
34237   pharm.array = (PHARMSTRUC *) malloc(sizeof(PHARMSTRUC)*(pharm.nfeat));
34238   pharm.ixp   = (int *) malloc(sizeof(int)*(pharm.nfeat));
34239   pharm.iyp   = (int *) malloc(sizeof(int)*(pharm.nfeat));
34240   pharm.rzp   = (double *) malloc(sizeof(double)*(pharm.nfeat));
34241   pharm.index = (int *) malloc(sizeof(int)*(pharm.nfeat));
34242   pharm.str   = (char **) malloc(sizeof(char *)*(pharm.nfeat));
34243   pharm.NSelFeat = 0;
34244 
34245   feat = -1;
34246 
34247   while (1) {
34248      if (fgets(strmax,1000,f) == NULL) break;
34249      if (strstr(strmax,"\"name\"")) {
34250 	feat++;
34251 
34252 	pharm.array[feat].incl = 0;
34253 
34254 	for (i = 0; i < 6; i++) {
34255 	   if (strstr(strmax,FeatStr[i])) {
34256 		pharm.array[feat].type = i;
34257 		break;
34258 	   }
34259 	}
34260 
34261         if (fgets(strmax,1000,f) == NULL) break;
34262         if (strstr(strmax,"\"radius\"")) {
34263 	   strtmp = strchr(strmax,':');
34264 	   strtmp++;
34265 	   sscanf(strtmp,"%f",&pharm.array[feat].rad);
34266 	   pharm.array[feat].rad = pharm.array[feat].rad / 0.52917706;
34267 	}
34268 
34269         if (fgets(strmax,1000,f) == NULL) break;
34270         if (fgets(strmax,1000,f) == NULL) break;
34271         if (strstr(strmax,"\"size\"")) {
34272 	   strtmp = strchr(strmax,':');
34273 	   strtmp++;
34274 	   sscanf(strtmp,"%d",&pharm.array[feat].size);
34275 	}
34276 
34277         next = 1;
34278 
34279         if (fgets(strmax,1000,f) == NULL) break;
34280         if (strstr(strmax,"\"vector\"")) {
34281 	   isvec  = -1;
34282 	   while (fgets(strmax,1000,f) != NULL) {
34283 		if (strchr(strmax,']'))  break;
34284         	if (strstr(strmax,"\"x\"")) {
34285 		   isvec++;
34286 	   	   strtmp = strchr(strmax,':');
34287 		   strtmp++;
34288 		   if (isvec == 0) {
34289 			sscanf(strtmp,"%f",&pharm.array[feat].vec1[0]);
34290 			pharm.array[feat].vec1[0] =
34291 				pharm.array[feat].vec1[0] / 0.52917706;
34292 		   } else {
34293 			sscanf(strtmp,"%f",&pharm.array[feat].vec2[0]);
34294 			pharm.array[feat].vec2[0] =
34295 				pharm.array[feat].vec2[0] / 0.52917706;
34296 		   }
34297 		}
34298 
34299         	if (strstr(strmax,"\"y\"")) {
34300 	   	   strtmp = strchr(strmax,':');
34301 		   strtmp++;
34302 		   if (isvec == 0) {
34303 			sscanf(strtmp,"%f",&pharm.array[feat].vec1[1]);
34304 			pharm.array[feat].vec1[1] =
34305 				pharm.array[feat].vec1[1] / 0.52917706;
34306 		   } else {
34307 			sscanf(strtmp,"%f",&pharm.array[feat].vec2[1]);
34308 			pharm.array[feat].vec2[1] =
34309 				pharm.array[feat].vec2[1] / 0.52917706;
34310 		   }
34311 		}
34312 
34313         	if (strstr(strmax,"\"z\"")) {
34314 	   	   strtmp = strchr(strmax,':');
34315 		   strtmp++;
34316 		   if (isvec == 0) {
34317 			sscanf(strtmp,"%f",&pharm.array[feat].vec1[2]);
34318 			pharm.array[feat].vec1[2] =
34319 				pharm.array[feat].vec1[2] / 0.52917706;
34320 		   } else {
34321 			sscanf(strtmp,"%f",&pharm.array[feat].vec2[2]);
34322 			pharm.array[feat].vec2[2] =
34323 				pharm.array[feat].vec2[2] / 0.52917706;
34324 		   }
34325 		}
34326 	   }
34327 	} else {
34328 	   next = 0;
34329 	}
34330 
34331         if (next ) {
34332 	   if (fgets(strmax,1000,f) == NULL) break;
34333 	}
34334 
34335         if (strstr(strmax,"\"x\"")) {
34336 	   strtmp = strchr(strmax,':');
34337 	   strtmp++;
34338 	   sscanf(strtmp,"%f",&pharm.array[feat].cor[0]);
34339 	   pharm.array[feat].cor[0] = pharm.array[feat].cor[0] / 0.52917706 ;
34340 	}
34341 
34342         if (fgets(strmax,1000,f) == NULL) break;
34343         if (strstr(strmax,"\"y\"")) {
34344 	   strtmp = strchr(strmax,':');
34345 	   strtmp++;
34346 	   sscanf(strtmp,"%f",&pharm.array[feat].cor[1]);
34347 	   pharm.array[feat].cor[1] = pharm.array[feat].cor[1] / 0.52917706 ;
34348 	}
34349 
34350         if (fgets(strmax,1000,f) == NULL) break;
34351         if (strstr(strmax,"\"z\"")) {
34352 	   strtmp = strchr(strmax,':');
34353 	   strtmp++;
34354 	   sscanf(strtmp,"%f",&pharm.array[feat].cor[2]);
34355 	   pharm.array[feat].cor[2] = pharm.array[feat].cor[2] / 0.52917706 ;
34356 	}
34357      }
34358   }
34359 
34360   fclose(f);
34361 
34362 }
34363 
GetJsonU(str)34364 int GetJsonU(str)
34365 char *str;
34366 {
34367   FILE *f;
34368   char strmax[1000];
34369   char *strtmp;
34370   int feat,i,next,type;
34371   float x,y,z,rad,dx,dy,dz,tol;
34372 
34373   tol = 0.01;
34374 
34375   f = fopen(str,"r");
34376 
34377   if (f == NULL) {
34378 	fprintf(stderr,"Error opening file %s\n",str);
34379  	return(0);
34380   }
34381 
34382   rewind(f);
34383 
34384   pharm.NSelFeat = 0;
34385 
34386   while (1) {
34387      if (fgets(strmax,1000,f) == NULL) break;
34388      if (strstr(strmax,"\"name\"")) {
34389 
34390 
34391 	for (i = 0; i < 6; i++) {
34392 	   if (strstr(strmax,FeatStr[i])) {
34393 		type = i;
34394 		break;
34395 	   }
34396 	}
34397 
34398         if (fgets(strmax,1000,f) == NULL) break;
34399         if (strstr(strmax,"\"radius\"")) {
34400 	   strtmp = strchr(strmax,':');
34401 	   strtmp++;
34402 	   sscanf(strtmp,"%f",&rad);
34403 	   rad = rad / 0.52917706;
34404 	}
34405 
34406         if (fgets(strmax,1000,f) == NULL) break;
34407         if (fgets(strmax,1000,f) == NULL) break;
34408         if (strstr(strmax,"\"size\"")) {
34409 	}
34410 
34411         next = 1;
34412 
34413         if (fgets(strmax,1000,f) == NULL) break;
34414         if (strstr(strmax,"\"vector\"")) {
34415 	   while (fgets(strmax,1000,f) != NULL) {
34416 		if (strchr(strmax,']'))  break;
34417 	   }
34418 	} else {
34419 	   next = 0;
34420 	}
34421 
34422         if (next ) {
34423 	   if (fgets(strmax,1000,f) == NULL) break;
34424 	}
34425 
34426         if (strstr(strmax,"\"x\"")) {
34427 	   strtmp = strchr(strmax,':');
34428 	   strtmp++;
34429 	   sscanf(strtmp,"%f",&x);
34430 	   x = x / 0.52917706;
34431 	}
34432 
34433         if (fgets(strmax,1000,f) == NULL) break;
34434         if (strstr(strmax,"\"y\"")) {
34435 	   strtmp = strchr(strmax,':');
34436 	   strtmp++;
34437 	   sscanf(strtmp,"%f",&y);
34438 	   y = y / 0.52917706;
34439 	}
34440 
34441         if (fgets(strmax,1000,f) == NULL) break;
34442         if (strstr(strmax,"\"z\"")) {
34443 	   strtmp = strchr(strmax,':');
34444 	   strtmp++;
34445 	   sscanf(strtmp,"%f",&z);
34446 	   z = z / 0.52917706;
34447 	}
34448 
34449 	for (feat = 0; feat < pharm.nfeat; feat++) {
34450 	   dx = fabsf(x-pharm.array[feat].cor[0]);
34451 	   dy = fabsf(y-pharm.array[feat].cor[1]);
34452 	   dz = fabsf(z-pharm.array[feat].cor[2]);
34453 	   if (dx < tol && dy < tol && dz < tol &&
34454 	       pharm.array[feat].type == type) {
34455 
34456 		pharm.NSelFeat++;
34457 		pharm.index[pharm.NSelFeat-1] = feat;
34458 		pharm.array[feat].incl = 1;
34459 	        pharm.array[feat].rad = rad;
34460 
34461 	        pharm.str[pharm.NSelFeat-1] = (char *) malloc(sizeof(char)*17);
34462 	        strcpy(pharm.str[pharm.NSelFeat-1],FeatStr[type]);
34463 	   }
34464 	}
34465 
34466      }
34467   }
34468 
34469   fclose(f);
34470 
34471 }
34472 
getPharmer()34473 int getPharmer()
34474 {
34475   char cmdfil[MAXSTRLEN];
34476 
34477   getob();
34478 
34479   strcpy(cmdfil,"/usr/local/bin/pharmer");
34480   if (access(cmdfil,X_OK) == 0 && !isdir(cmdfil)) {
34481 	PHRMloc = 0;
34482 	return(1);
34483   }
34484 
34485   sprintf(cmdfil,"%spharmer",exepath[0]);
34486   if (access(cmdfil,X_OK) == 0 && !isdir(cmdfil)) {
34487 	return(1);
34488 	PHRMloc = 1;
34489   }
34490 
34491   return(0);
34492 }
34493 
mkjson()34494 char * mkjson()
34495 {
34496   int n1,l;
34497   char *xstr1;
34498   char *last1;
34499   char *dot1;
34500 
34501   last1 = COO[istruct]->fname;
34502   l = strlen(last1);
34503   if (l > 512) return(NULL);
34504   xstr1 = (char *) malloc(sizeof(char)*(l+5));
34505   if (xstr1 == NULL) return(NULL);
34506   if (last1 != NULL) {
34507      dot1 = strrchr(last1,'.');
34508      if (dot1 != NULL) {
34509 	n1 = (int) (dot1 - last1);
34510 	strncpy(xstr1,last1,n1);
34511 	xstr1[n1] = '\0';
34512 	strcat(xstr1,".json");
34513      } else {
34514 	return(NULL);
34515      }
34516   } else {
34517      return(NULL);
34518   }
34519 
34520   return(xstr1);
34521 }
34522 
mkdb()34523 char * mkdb()
34524 {
34525   int n1,l;
34526   char *xstr1;
34527   char *last1;
34528   char *dot1;
34529 
34530   l = strlen(qboxes[QSCSDF].str);
34531   if (l > 512) return(NULL);
34532   xstr1 = (char *) malloc(sizeof(char)*(l+5));
34533   if (xstr1 == NULL) return(NULL);
34534   strcpy(xstr1,qboxes[QSCSDF].str);
34535   last1 = xstr1;
34536   if (last1 != NULL) {
34537      dot1 = strrchr(last1,'.');
34538      if (dot1 != NULL) {
34539 	n1 = (int) (dot1 - last1);
34540 	xstr1[n1] = '\0';
34541 	strcat(xstr1,".db");
34542      } else {
34543 	return(NULL);
34544      }
34545   } else {
34546      return(NULL);
34547   }
34548 
34549   return(xstr1);
34550 }
34551 
FeatEditor()34552 int FeatEditor()
34553 {
34554   int n,n1,stat;
34555   char cmdfil[512];
34556   char xstr1[512];
34557   char fn[] = "/tmp/fileXXXXXX";
34558   char *last1;
34559   char *dot1;
34560 
34561   if (!has_opengl) {
34562 	DoCan(event.xbutton.x_root, event.xbutton.y_root,
34563 	"The pharmacophore editor is only available with gmolden.",0);
34564 	return(0);
34565   }
34566 
34567   if (COO[istruct]->fname == NULL) {
34568 	DoCan(event.xbutton.x_root, event.xbutton.y_root,
34569 	"The pharmacophore editor is NOT available with \n files read from the commandline.",0);
34570 	return(0);
34571   }
34572 
34573   if (getPharmer()) {
34574 	strcpy(cmdfil,"/usr/local/lib/openbabel");
34575 	if (!isdir(cmdfil)) {
34576 	     if (getenv("BABEL_LIBDIR") == NULL) {
34577 #if !defined(DARWIN)
34578 		sprintf(cmdfil,"%s",exepath[0]);
34579 		setenv("LD_LIBRARY_PATH",cmdfil,1);
34580 		setenv("BABEL_LIBDIR",cmdfil,1);
34581 		setenv("BABEL_DATADIR",cmdfil,1);
34582 #else
34583 		sprintf(cmdfil,"%s/data",exepath[0]);
34584 		setenv("BABEL_DATADIR",cmdfil,1);
34585 		sprintf(cmdfil,"%s/lib",exepath[0]);
34586 		setenv("BABEL_LIBDIR",cmdfil,1);
34587 #endif
34588 	     }
34589 	}
34590 
34591 
34592 	stat = 1;
34593 	last1 = rindex(COO[istruct]->fname,'/');
34594 	sprintf(xstr1,"%s.json",mktemp(fn));
34595 
34596 	if (stat) {
34597 	   if (PHRMloc) {
34598 		sprintf(cmdfil,
34599 		"%spharmer -cmd pharma -in %s -out %s",exepath[0],
34600 		COO[istruct]->fname,xstr1);
34601 	   } else {
34602 		sprintf(cmdfil,
34603 		"/usr/local/bin/pharmer -cmd pharma -in %s -out %s",
34604 		COO[istruct]->fname,xstr1);
34605 	   }
34606 	   n = strlen(cmdfil);
34607 #if defined(VMS) || defined(UNDERSC)
34608 	   exstr(cmdfil,&n,&ZERO);
34609 #else
34610 #ifdef CRAY
34611 	   EXSTR(cmdfil,&n,&ZERO);
34612 #else
34613 	   exstr_(cmdfil,&n,&ZERO);
34614 #endif
34615 #endif
34616 	   GetJson(xstr1);
34617 	   return(1);
34618 
34619 	} else {
34620 
34621 	   return(0);
34622 	}
34623 
34624   } else {
34625 	DoCan(event.xbutton.x_root, event.xbutton.y_root,
34626 	"Could NOT locate Pharmer.",0);
34627 	return(0);
34628   }
34629 
34630 }
34631 
OpenPHRME()34632 void OpenPHRME()
34633 {
34634     if (FeatEditor()) initPHRM();
34635 }
34636 
getob()34637 int getob()
34638 {
34639   char cmdfil[MAXSTRLEN];
34640 
34641   strcpy(cmdfil,"/usr/local/lib/openbabel");
34642   if (!isdir(cmdfil)) {
34643      if (getenv("BABEL_LIBDIR") == NULL) {
34644 #if !defined(DARWIN)
34645 	sprintf(cmdfil,"%s",exepath[0]);
34646 	setenv("BABEL_LIBDIR",cmdfil,1);
34647 	setenv("BABEL_DATADIR",cmdfil,1);
34648 #else
34649 	sprintf(cmdfil,"%s/data",exepath[0]);
34650 	setenv("BABEL_DATADIR",cmdfil,1);
34651 	sprintf(cmdfil,"%s/lib",exepath[0]);
34652 	setenv("BABEL_LIBDIR",cmdfil,1);
34653 #endif
34654      }
34655   }
34656 
34657   sprintf(cmdfil,"%sobabel",exepath[0]);
34658   if (access(cmdfil,X_OK) == 0 && !isdir(cmdfil)) {
34659 	OBloc = 1;
34660 	return(1);
34661   }
34662 
34663   strcpy(cmdfil,"/usr/local/bin/obabel");
34664   if (access(cmdfil,X_OK) == 0 && !isdir(cmdfil)) {
34665 	OBloc = 0;
34666 	return(1);
34667   }
34668 
34669   return(0);
34670 }
34671 
killob()34672 void killob()
34673 {
34674   int n;
34675   char cmdfil[MAXSTRLEN];
34676 
34677   sprintf(cmdfil,"killall obabel");
34678   n = strlen(cmdfil);
34679   excmd(cmdfil,&n);
34680 }
34681 
obsrch(char * str)34682 void obsrch(char *str)
34683 {
34684   int n,nres;
34685   float tani;
34686   char cmdfil[MAXSTRLEN];
34687   char xstr1[MAXCMD];
34688   char *last1;
34689   char *dot1;
34690   int n1,stat;
34691 
34692   getob();
34693 
34694   tani = atof(qboxes[QNRES].str);
34695 
34696   stat = 1;
34697   last1 = COO[istruct]->fname;
34698   if (last1 != NULL) {
34699      dot1 = strrchr(last1,'.');
34700      if (dot1 != NULL) {
34701 	n1 = (int) (dot1 - last1);
34702 	strncpy(xstr1,last1,n1);
34703 	xstr1[n1] = '\0';
34704 	strcat(xstr1,".fs");
34705      } else {
34706 	stat = 0;
34707      }
34708   } else {
34709      stat = 0;
34710   }
34711 
34712 
34713   if (stat) {
34714 	if (OBloc) {
34715 	    sprintf(cmdfil,
34716 		"%sobabel %s -O %s -s %s -at %f -xfFP3",exepath[0],
34717 		xstr1,qboxes[QRESF].str,qboxes[QQUERY].str,tani);
34718 	} else {
34719 	    sprintf(cmdfil,
34720 		"/usr/local/bin/obabel %s -O %s -s %s -at %f -xfFP3",
34721 		xstr1,qboxes[QRESF].str,qboxes[QQUERY].str,tani);
34722 	}
34723 	n = strlen(cmdfil);
34724 /*
34725 fprintf(stderr,"obsrch: cmdfil %s\n",cmdfil);
34726 */
34727 #if defined(VMS) || defined(UNDERSC)
34728 	exstr(cmdfil,&n,&ZERO);
34729 #else
34730 #ifdef CRAY
34731 	EXSTR(cmdfil,&n,&ZERO);
34732 #else
34733 	exstr_(cmdfil,&n,&ZERO);
34734 #endif
34735 #endif
34736   }
34737   return;
34738 }
34739 
obfp()34740 int obfp()
34741 {
34742   int n;
34743   char cmdfil[MAXSTRLEN];
34744 
34745   getob();
34746   if (OBloc) {
34747      sprintf(cmdfil,
34748 	"%sobabel %s -ofs -xfFP3",exepath[0],COO[istruct]->fname);
34749   } else {
34750      sprintf(cmdfil,
34751 	"/usr/local/bin/obabel %s -ofs -xfFP3",COO[istruct]->fname);
34752   }
34753   n = strlen(cmdfil);
34754 #if defined(VMS) || defined(UNDERSC)
34755   exstr(cmdfil,&n,&ZERO);
34756 #else
34757 #ifdef CRAY
34758   EXSTR(cmdfil,&n,&ZERO);
34759 #else
34760   exstr_(cmdfil,&n,&ZERO);
34761 #endif
34762 #endif
34763   return(0);
34764 }
34765 
34766 #define NUMCOL 16
34767 
34768 static int PopUpNum, PopUpEntryH, PopUpHeight, PopUpWidth, PopUpChunk, PopUpCLow;
34769 static int PopUpMaxNum = 20;
34770 
DoPopUp(ParentWin,x,y,List,iopt,icent)34771 int DoPopUp(ParentWin,x,y,List,iopt,icent)
34772 Window ParentWin;
34773 int *iopt;
34774 LSSTRU *List;
34775 int x,y,icent;
34776 {
34777   int done, inew, iold, ifrst, i, wit, wi, xt, ioptt;
34778 
34779   ioptt = *iopt;
34780 
34781   if (List == NULL) {
34782 	PopUpNum = NUMCOL;
34783 	PopUpEntryH = 14;
34784 	PopUpWidth = 100;
34785 	PopUpChunk = -1;
34786   } else {
34787 	PopUpChunk = -1;
34788 	PopUpNum = List->nents;
34789 	if (PopUpNum > PopUpMaxNum) {
34790 	   PopUpChunk = 0;
34791 	   PopUpCLow = PopUpChunk*PopUpMaxNum;
34792 	   PopUpNum = PopUpMaxNum;
34793 	   if ((PopUpChunk+1)*PopUpMaxNum > List->nents)
34794 		PopUpNum = List->nents - PopUpCLow;
34795 	} else {
34796 	   PopUpCLow = 0;
34797 	}
34798 	PopUpEntryH = LINEHIGH;
34799 	wi = 0;
34800 	for (i=0; i<PopUpNum; i++) {
34801 	    if (List->list[i] != NULL) {
34802 		wit = XTextWidth(mfinfo,List->list[i],strlen(List->list[i]));
34803 	    } else {
34804 		wit  = 0;
34805 	    }
34806 	    if (wit > wi) wi = wit;
34807 	}
34808 	PopUpWidth = wi + 2*SPACING;
34809   }
34810 
34811   PopUpHeight = PopUpNum*PopUpEntryH;
34812   if (PopUpChunk != -1) PopUpHeight = (PopUpNum+1)*PopUpEntryH;
34813 
34814   if (!PopUpHeight || !PopUpWidth) return 0;
34815 
34816   PopUp = CreateWindow("Molden Color Box",DEFQBOXGEOM,PopUpWidth,PopUpHeight,
34817                             colors[0],colors[190],ParentWin);
34818 
34819   XSelectInput(display, PopUp,
34820   ( ExposureMask | ButtonPressMask | PointerMotionMask | VisibilityChangeMask));
34821 
34822   xt = x;
34823   if (icent) {
34824 	xt = x - PopUpWidth/2;
34825 	if (xt < 0) xt = 0;
34826   }
34827   XMoveResizeWindow(display, PopUp, xt, y, PopUpWidth, PopUpHeight);
34828 
34829   XSetFunction(display, gc, GXcopy);
34830   XSetPlaneMask(display, gc, colors[0] ^ colors[190]);
34831   XSetForeground(display, gc, colors[0]);
34832   XSetBackground(display, gc, colors[190]);
34833 
34834 #ifdef DOGL
34835   if ( (*fancy || *fullgl) && has_opengl && !StarNetOld) {
34836 	dispsf();
34837 	glXWaitGL();
34838   }
34839 #endif
34840 
34841   XMapRaised(display,PopUp);
34842 
34843   XWindowEvent(display, PopUp, VisibilityChangeMask, &event);
34844 
34845   XFlush(display);
34846 
34847   iold = -1;
34848   ifrst = 1;
34849   done = 0;
34850   while (!done) {
34851 
34852     if (XPending(display)>0) {
34853       XNextEvent(display, &event);
34854 
34855       switch (event.type) {
34856       case Expose: {
34857 
34858 	if (event.xexpose.window == PopUp) {
34859             RedrawPopUp(List);
34860 	}
34861       }
34862       break;
34863 
34864       case ButtonPress: {
34865         if (event.xbutton.window == PopUp) {
34866            *iopt = (event.xbutton.y*PopUpNum) / PopUpHeight;
34867 	   if (PopUpChunk != -1) {
34868 		*iopt = event.xbutton.y / PopUpEntryH;
34869 		if (*iopt >= PopUpNum) {
34870 		    PopUpChunk = PopUpChunk + 1;
34871 		    if (PopUpChunk*PopUpMaxNum > List->nents) PopUpChunk = 0;
34872 		    PopUpCLow = PopUpChunk*PopUpMaxNum;
34873 		    PopUpNum = PopUpMaxNum;
34874 		    if ((PopUpChunk+1)*PopUpMaxNum > List->nents)
34875 			PopUpNum = List->nents - PopUpCLow;
34876 		    iold = -1;
34877 		    RedrawPopUp(List);
34878 		} else {
34879 		    *iopt = *iopt + PopUpChunk*PopUpMaxNum;
34880 		    if (List != NULL) if (*iopt >= List->nents)
34881 			*iopt = List->nents - 1;
34882 		    done = 1;
34883 		}
34884 	   } else {
34885 		done = 1;
34886 	   }
34887         } else {
34888            done = 1;
34889            *iopt = ioptt;
34890 	   XSetFunction(display, gc, GXcopy);
34891 	   XSetPlaneMask(display, gc, (unsigned long) ~0L);
34892 	   XDestroyWindow(display,PopUp);
34893 
34894 	   return -1;
34895 	}
34896       }
34897       break;
34898 
34899       case MotionNotify: {
34900         if (event.xmotion.window == PopUp) {
34901            inew = (event.xmotion.y*PopUpNum) / PopUpHeight;
34902 	   if (PopUpChunk != -1) inew =
34903 		(event.xmotion.y*(PopUpNum+1)) / ((PopUpNum+1)*PopUpEntryH);
34904            if (inew != iold) {
34905 		if (List == NULL) {
34906 		    XSetForeground(display, gc, colors[1+iold]);
34907 		    XDrawRectangle(display, PopUp, gc, 0,
34908 		     (iold * PopUpHeight)/PopUpNum, PopUpWidth,PopUpEntryH);
34909 		    XSetForeground(display, gc, colors[0]);
34910 		    XDrawRectangle(display, PopUp, gc, 0,
34911 		    (inew * PopUpHeight)/PopUpNum, PopUpWidth,PopUpEntryH);
34912 		} else {
34913 		    XSetFunction(display, gc, GXinvert);
34914 		    XSetPlaneMask(display, gc, colors[190] ^ colors[0]);
34915 		    if (!ifrst) {
34916 		        XFillRectangle(display, PopUp, gc, 0,
34917 		         iold * PopUpEntryH, PopUpWidth,PopUpEntryH);
34918 		    } else ifrst = 0;
34919 		    XFillRectangle(display, PopUp, gc, 0,
34920 		     inew * PopUpEntryH, PopUpWidth,PopUpEntryH);
34921 		    XSetFunction(display, gc, GXcopy);
34922 		    XSetPlaneMask(display, gc, (unsigned long) ~0L);
34923 		}
34924 		iold = inew;
34925            }
34926         }
34927       }
34928       break;
34929 
34930       default: break;
34931 
34932       } /* end switch */
34933      }/* end if XPending*/
34934    } /*end while */
34935 
34936    XSetFunction(display, gc, GXcopy);
34937    XSetPlaneMask(display, gc, (unsigned long) ~0L);
34938    XDestroyWindow(display,PopUp);
34939 
34940 #ifdef DOGL
34941    if ( (*fancy || *fullgl) && has_opengl && !StarNetOld) {
34942 	dispsf();
34943 	glXWaitGL();
34944    }
34945 #endif
34946 
34947    return 0;
34948 }
34949 
RedrawPopUp(List)34950 void RedrawPopUp(List)
34951 LSSTRU *List;
34952 {
34953       int i;
34954 
34955   if (List == NULL) {
34956       XSetFunction(display, gc, GXcopy);
34957       XSetPlaneMask(display, gc, (unsigned long) ~0L);
34958       for (i=0; i < PopUpNum; i++) {
34959           XSetForeground(display, gc, colors[i]);
34960           XFillRectangle(display, PopUp, gc, 0,
34961                (i * PopUpHeight)/PopUpNum, PopUpWidth,PopUpEntryH);
34962       }
34963   }
34964   else {
34965       XSetForeground(display, gc, colors[190]);
34966       XFillRectangle(display, PopUp, gc, 0,0,
34967 		          PopUpWidth,PopUpHeight);
34968       XSetFunction(display, gc, GXcopy);
34969       XSetPlaneMask(display, gc, colors[0] ^ colors[190]);
34970       for (i=0; i < PopUpNum; i++) {
34971           XSetForeground(display, gc, colors[190]);
34972           XFillRectangle(display, PopUp, gc, 0,
34973 		         i * PopUpEntryH, PopUpWidth,PopUpEntryH);
34974           XSetForeground(display, gc, colors[0]);
34975 	  LineString(PopUp,List->list[i+PopUpCLow],SPACING,ASCENT + i*PopUpEntryH);
34976       }
34977       if (PopUpChunk != -1) {
34978           XSetForeground(display, gc, colors[190]);
34979           XFillRectangle(display, PopUp, gc, 0,
34980 		         PopUpNum * PopUpEntryH, PopUpWidth,PopUpEntryH);
34981           XSetForeground(display, gc, colors[0]);
34982 	  if (PopUpCLow+PopUpNum == List->nents)
34983 	    LineString(PopUp,"<- To top",SPACING,ASCENT + PopUpNum*PopUpEntryH);
34984 	  else
34985 	    LineString(PopUp,"More ...",SPACING,ASCENT + PopUpNum*PopUpEntryH);
34986       }
34987   }
34988 }
34989 
34990 #define POPSPACE 8
DoCan(x,y,strval,docan)34991 int DoCan(x,y,strval,docan)
34992 int x,y;
34993 char *strval;
34994 int docan;
34995 {
34996   int done,wit,hit,bw,xp,retval,nb,nlines,wittmp,ql;
34997   char wgeom[64];
34998   char *p, *q;
34999 
35000   retval = 0;
35001   nb = 1;
35002   if (docan) nb = 2;
35003 
35004   nlines = 0;
35005   p = strval;
35006   q = strval;
35007   wit = 0;
35008   while ((p = strchr(q, '\n'))) {
35009      ql = (int) (p-q);
35010      wittmp = XTextWidth(mfinfo,q,ql) + 2*POPSPACE;
35011      if (wittmp > wit) wit = wittmp;
35012      p++;
35013      q = p;
35014      nlines++;
35015   }
35016   ql = strlen(q);
35017   wittmp = XTextWidth(mfinfo,q,ql) + 2*POPSPACE;
35018   if (wittmp > wit) wit = wittmp;
35019   nlines++;
35020 
35021   hit = POPSPACE + LINEHIGH*nlines + POPSPACE + BUTTH + POPSPACE;
35022 
35023 
35024   sprintf(wgeom,"+%d+%d",x-wit/2,y-hit/2);
35025 
35026   PopOk = CreateWindow("Molden OK Box",wgeom,wit,hit,
35027                             infobg,colors[190],(Window)0);
35028 
35029   XSelectInput(display, PopOk,
35030   ( ExposureMask | ButtonPressMask | VisibilityChangeMask ));
35031 
35032   XMoveResizeWindow(display, PopOk, x-wit/2, y-hit/2, wit, hit);
35033 
35034   XMapRaised(display,PopOk);
35035 
35036   XWindowEvent(display, PopOk, VisibilityChangeMask, &event);
35037 
35038   XFlush(display);
35039 
35040   if (docan) {
35041 	bw = (wit - 4*POPSPACE) / 2;
35042 	DefBut(&obut[0],  PopOk, POPSPACE, nlines*LINEHIGH + 2*POPSPACE,
35043 		bw, BUTTH, "OK", infobg, 0);
35044 	DefBut(&obut[1],  PopOk, bw + 3*POPSPACE, nlines*LINEHIGH + 2*POPSPACE,
35045 		bw, BUTTH, "Cancel", infobg, 0);
35046   } else {
35047 	bw = 40;
35048 	xp = wit / 2 - bw / 2;
35049 	DefBut(&obut[0],  PopOk, xp, nlines*LINEHIGH + 2*POPSPACE,
35050 		bw, BUTTH, "OK", infobg, 0);
35051   }
35052 
35053   done = 0;
35054   while (!done) {
35055 
35056     if (XPending(display)>0) {
35057       XNextEvent(display, &event);
35058 
35059       switch (event.type) {
35060       case Expose: {
35061 
35062 	if (event.xexpose.window == PopOk) {
35063 	   nlines = 0;
35064 	   p = strval;
35065 	   q = strval;
35066 	   while ((p = strchr(q, '\n'))) {
35067 		ql = (int) (p-q);
35068 	        XDrawString(display, PopOk, gc,
35069 			POPSPACE, CHIGH+nlines*LINEHIGH+POPSPACE, q, ql);
35070 		p++;
35071 		q = p;
35072 		nlines++;
35073 	   }
35074 	   ql = strlen(q);
35075 	   XDrawString(display, PopOk, gc,
35076 			POPSPACE, CHIGH+nlines*LINEHIGH+POPSPACE, q, ql);
35077 	   DrwBut(&obut[0]);
35078 	   if (docan) DrwBut(&obut[1]);
35079 	}
35080 	if (event.xexpose.window == win) {
35081 #ifndef DOGL
35082 	   if (molback == molcur)
35083                     XCopyArea(display,molcur,win,gc,0,0,width,height,0,0);
35084 #endif
35085 	}
35086       }
35087       break;
35088 
35089       case ButtonPress: {
35090         if (event.xbutton.window == PopOk) {
35091 	   if (Clickwin(obut,nb,event.xbutton.x, event.xbutton.y,1) == 1)
35092 		retval = 1;
35093            done = 1;
35094 	} else {
35095 	   DirBox(PopOk,1);
35096         }
35097       }
35098       break;
35099 
35100       default: break;
35101 
35102       } /* end switch */
35103      }/* end if XPending*/
35104    } /*end while */
35105 
35106    XDestroyWindow(display,PopOk);
35107    XSync(display, False);
35108    return(retval);
35109 }
35110 
35111 #if defined(VMS) || defined(UNDERSC)
confrm(iop,istat)35112 void confrm(iop,istat)
35113 #else
35114 #ifdef CRAY
35115 void CONFRM(iop,istat)
35116 #else
35117 void confrm_(iop,istat)
35118 #endif
35119 #endif
35120 
35121 int *iop;
35122 int *istat;
35123 {
35124    char statstr[200];
35125 
35126    if (!xison) return;
35127 
35128    switch (*iop) {
35129 	case 0:
35130 		strcpy(statstr,"Setup completed, click OK to optimise. \n\n Hit esc to abort calculation.");
35131 		break;
35132 	case 1:
35133 		strcpy(statstr,"Found mutiple structure XDATCAR file, \n click OK to use this in conjuction with POSCAR/CONTCAR file");
35134 		break;
35135    }
35136 
35137    *istat = 1;
35138    if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
35139 	statstr,1)) {
35140 	*istat = 0;
35141    }
35142    if (*iop == 0) RedrawZME();
35143 }
35144 
35145 #if defined(VMS) || defined(UNDERSC)
plsph3(xori,yori,diameter,ia,ioffs,icfac)35146 void plsph3(xori,yori,diameter,ia,ioffs,icfac)
35147 #else
35148 #ifdef CRAY
35149 void PLSPH3(xori,yori,diameter,ia,ioffs,icfac)
35150 #else
35151 void plsph3_(xori,yori,diameter,ia,ioffs,icfac)
35152 #endif
35153 #endif
35154 
35155 int *xori;
35156 int *yori;
35157 int *diameter;
35158 int *ia;
35159 int *ioffs;
35160 int *icfac;
35161 {
35162   int xc,yc,xce,yce;
35163   int thetad,coli,oldcol;
35164   double tcos,tsin;
35165   unsigned int wi,hi,wold,wtmp,whlf;
35166 
35167 /*
35168    xori,yori = x,y of center of sphere
35169    diameter  = diameter of sphere
35170    ia        = flag for green circle around sphere (z-mat)
35171    ioffs     = offset in color array for atom color
35172    icfac     = range of shades possible
35173 */
35174 
35175   xc = *xori - *diameter/2;
35176   yc = *yori - *diameter/2;
35177   xce = *xori + *diameter/2;
35178   yce = *yori + *diameter/2;
35179 
35180   if (xce < 0 && yce < 0) return;
35181   if (xc > (int) width && yc > (int) height) return;
35182 
35183   oldcol = -1; wold = 30000;
35184   for ( thetad=90; thetad > 0; thetad-- ) {
35185      tcos = Tcos[thetad];  tsin = Tsin[thetad];
35186      wi = (unsigned int) (*diameter * tsin + 0.5);
35187      coli = (int)( *ioffs + tcos * (*icfac) + 0.5);
35188      if (coli != oldcol) {
35189 
35190         if (wold < 30000) {
35191            whlf = (wold + wi) / 2;
35192            XSetForeground(display, gc, colors[coli]);
35193            XSetBackground(display, gc, colors[oldcol]);
35194            XSetFillStyle(display,gc,FillOpaqueStippled);
35195 
35196            wtmp = (wold + whlf) / 2;
35197            xc = *xori - wtmp / 2;
35198            yc = *yori - wtmp / 2;
35199            XSetStipple(display,gc,qwgrey);
35200            XFillArc(display, molcur, gc, xc,yc, wtmp, wtmp, 0,360*64);
35201 
35202            xc = *xori - whlf / 2;
35203            yc = *yori - whlf / 2;
35204            XSetStipple(display,gc,stipple);
35205            XFillArc(display, molcur, gc, xc,yc, whlf, whlf, 0,360*64);
35206 
35207            wtmp = (wi + whlf) / 2;
35208            xc = *xori - wtmp / 2;
35209            yc = *yori - wtmp / 2;
35210            XSetStipple(display,gc,tqwgrey);
35211            XFillArc(display, molcur, gc, xc,yc, wtmp, wtmp, 0,360*64);
35212 
35213            XSetFillStyle(display,gc,FillSolid);
35214         }
35215 
35216         xc = *xori - wi / 2;
35217         yc = *yori - wi / 2;
35218         XSetBackground(display, gc, BlackPixel(display,screen));
35219         XSetForeground(display, gc, colors[coli]);
35220         XFillArc(display, molcur, gc, xc,yc, wi, wi, 0,360*64);
35221 
35222         oldcol = coli; wold = wi;
35223      }
35224   }
35225 
35226 /* if atoms select for Z-matrix, draw green circle around it */
35227 
35228   xc = *xori - *diameter / 2;
35229   yc = *yori - *diameter / 2;
35230 
35231   if (*ia >= 2 && (ZMEup || ATMup) ) {
35232      wi = (unsigned int) *diameter;
35233      hi = wi;
35234      XSetForeground(display, gc, colors[rimcols[*ia]]);
35235      XDrawArc(display, molcur, gc, xc,yc, wi, hi, 0,360*64);
35236   }
35237 }
35238 
35239 void plrod(int xori,int yori,int rada,int radb,int radc,int rodl,float cosa,float sina);
35240 
35241 #if defined(VMS) || defined(UNDERSC)
plrod3(xori,yori,diameter1,diameter2,diameter3,rodlen,ioffs,icfac,cosa,sina)35242 void plrod3(xori,yori,diameter1,diameter2,diameter3,rodlen,ioffs,icfac,cosa,sina)
35243 #else
35244 #ifdef CRAY
35245 void PLROD3(xori,yori,diameter1,diameter2,diameter3,rodlen,ioffs,icfac,cosa,sina)
35246 #else
35247 void plrod3_(xori,yori,diameter1,diameter2,diameter3,rodlen,ioffs,icfac,cosa,sina)
35248 #endif
35249 #endif
35250 
35251 int *xori;
35252 int *yori;
35253 int *diameter1;
35254 int *diameter2;
35255 int *diameter3;
35256 int *rodlen;
35257 int *icfac;
35258 int *ioffs;
35259 float *cosa;
35260 float *sina;
35261 {
35262   int xc,yc;
35263   int thetad,coli,oldcol;
35264   double x,y,x1,y1,x2,y2,x3,y3;
35265   double tcos,tsin;
35266   unsigned int wi1,wi2,wi3,wold1,wtmp1,whlf1,wold3,wtmp3,whlf3;
35267   float Cosa,Sina;
35268   int rodl;
35269   int is;
35270 
35271 /*
35272    xori,yori = x,y of center of sphere
35273    diameter  = diameter of sphere
35274    ia        = flag for green circle around sphere (z-mat)
35275    ioffs     = offset in color array for atom color
35276    icfac     = range of shades possible
35277 */
35278 
35279   is = 0;
35280   x1 = (double) *xori; y1 = (double) *yori;
35281   x = (double) 0; y = (double) -*rodlen;
35282   x2 = *xori + (*cosa*x - *sina*y);
35283   y2 = *yori + (*sina*x + *cosa*y);
35284   x3 = (x1 + x2) / 2.0;
35285   y3 = (y1 + y2) / 2.0;
35286 
35287   if ((x1 >= 0 && x1 <= (double) width) &&
35288 	(y1 >= 0 && y1 <= (double) height)) is++;
35289   if ((x2 >= 0 && x2 <= (double) width) &&
35290 	(y2 >= 0 && y2 <= (double) height)) is++;
35291   if ((x3 >= 0 && x3 <= (double) width) &&
35292 	(y3 >= 0 && y3 <= (double) height)) is++;
35293 
35294   if (!is) return;
35295 
35296   Cosa = *cosa; Sina = *sina ; rodl = *rodlen;
35297   xc = *xori; yc = *yori;
35298   oldcol = -1; wold1 = 30000;
35299   for ( thetad=90; thetad > 0; thetad-- ) {
35300      tcos = Tcos[thetad];  tsin = Tsin[thetad];
35301      wi1 = (unsigned int) (*diameter1 * tsin + 0.5);
35302      wi2 = (unsigned int) (*diameter2 + 0.5);
35303      wi3 = (unsigned int) (*diameter3 * tsin + 0.5);
35304      coli = (int)( *ioffs + tcos * (*icfac) + 0.5);
35305      if (coli != oldcol) {
35306 
35307         if (wold1 < 30000) {
35308            whlf1 = (wold1 + wi1) / 2;
35309            whlf3 = (wold3 + wi3) / 2;
35310            XSetForeground(display, gc, colors[coli]);
35311            XSetBackground(display, gc, colors[oldcol]);
35312            XSetFillStyle(display,gc,FillOpaqueStippled);
35313 
35314            wtmp1 = (wold1 + whlf1) / 2;
35315            wtmp3 = (wold3 + whlf3) / 2;
35316            XSetStipple(display,gc,qwgrey);
35317 	   plrod(xc,yc,wtmp1,wi2,wtmp3,rodl,Cosa,Sina);
35318 
35319            XSetStipple(display,gc,stipple);
35320 	   plrod(xc,yc,whlf1,wi2,whlf3,rodl,Cosa,Sina);
35321 
35322            wtmp1 = (wi1 + whlf1) / 2;
35323            wtmp3 = (wi3 + whlf3) / 2;
35324            XSetStipple(display,gc,tqwgrey);
35325 	   plrod(xc,yc,wtmp1,wi2,wtmp3,rodl,Cosa,Sina);
35326 
35327            XSetFillStyle(display,gc,FillSolid);
35328         }
35329 
35330         XSetBackground(display, gc, BlackPixel(display,screen));
35331         XSetForeground(display, gc, colors[coli]);
35332 	plrod(xc,yc,wi1,wi2,wi3,rodl,Cosa,Sina);
35333 
35334         oldcol = coli; wold1 = wi1; wold3 = wi3;
35335      }
35336   }
35337 }
35338 
35339 
plellps(xori,yori,rada,radb,alpha)35340 void plellps(xori,yori,rada,radb,alpha)
35341 int xori;
35342 int yori;
35343 int rada;
35344 int radb;
35345 float alpha;
35346 {
35347 	int beta;
35348 	double x,y;
35349 	XPoint points[400];
35350 	int npoints;
35351 	double C,S;
35352 /*
35353    xori,yori = x,y of center of ellips
35354    rada      = first axis radius
35355    radb      = second axis radius
35356    alpha     = rotation angle of ellips
35357 
35358    Let beta run from 0 to 360 degrees:
35359 
35360    x = rada*cos(beta)
35361    y = radb*sin(beta)
35362 
35363    Then rotation over alpha degrees and translation
35364 
35365    X = xori + (cos(alpha)*x - sin(alpha)*y)
35366    Y = yori + (sin(alpha)*x + cos(alpha)*y)
35367 */
35368 	C = cos(alpha);
35369 	S = sin(alpha);
35370 	for (beta=0; beta <= 360; beta++)
35371 	{
35372 		x = rada*Tcos[beta];
35373 		y = radb*Tsin[beta];
35374 		points[beta].x = xori + (C*x - S*y);
35375 		points[beta].y = yori + (S*x + C*y);
35376 	}
35377 	npoints = 361;
35378 	XFillPolygon(display,molcur,gc,points,npoints,Convex,CoordModeOrigin);
35379 }
35380 
plrod(int xori,int yori,int rada,int radb,int radc,int rodl,float cosa,float sina)35381 void plrod(int xori,int yori,int rada,int radb,int radc,int rodl,
35382 		float cosa,float sina)
35383 {
35384 	int beta;
35385 	double x,y;
35386 	XPoint points[400];
35387 	int npoints;
35388 	int binc;
35389 /*
35390    xori,yori = x,y of center of ellips on top of rod
35391    rada      = first axis radius
35392    radb      = second axis up radius
35393    radc      = second axis down radius
35394    rodl      = rod length
35395    alpha     = rotation angle of rod
35396 
35397    Let beta run from 0 to 360 degrees:
35398 
35399    x = rada*cos(beta)
35400    y = radb*sin(beta)
35401 
35402    Then rotation over alpha degrees and translation
35403 
35404    X = xori + (cos(alpha)*x - sin(alpha)*y)
35405    Y = yori + (sin(alpha)*x + cos(alpha)*y)
35406 */
35407 	npoints = 0;
35408 
35409 	if (rada) {
35410 		binc = 180/rada; if (!binc) binc = 1;
35411 	}
35412 	else binc = 1;
35413 	x = radc; y = -rodl;
35414 	points[0].x = xori + (cosa*x - sina*y);
35415 	points[0].y = yori + (sina*x + cosa*y);
35416 	for (beta=0; beta <= 180; beta = beta + binc)
35417 	{
35418 		npoints++;
35419 		x = rada*Tcos[beta];
35420 		y = radb*Tsin[beta];
35421 		points[npoints].x = xori + (cosa*x - sina*y);
35422 		points[npoints].y = yori + (sina*x + cosa*y);
35423 	}
35424 	npoints++;
35425 	x = -radc; y = -rodl;
35426 	points[npoints].x = xori + (cosa*x - sina*y);
35427 	points[npoints].y = yori + (sina*x + cosa*y);
35428 	npoints++;
35429 	XFillPolygon(display,molcur,gc,points,npoints,Convex,CoordModeOrigin);
35430 }
35431 
35432 #if defined(VMS) || defined(UNDERSC)
plrodx(xori,yori,rada,radb,radc,rodlen,ioffs,cosa,sina)35433 void plrodx(xori,yori,rada,radb,radc,rodlen,ioffs,cosa,sina)
35434 #else
35435 #ifdef CRAY
35436 void PLRODX(xori,yori,rada,radb,radc,rodlen,ioffs,cosa,sina)
35437 #else
35438 void plrodx_(xori,yori,rada,radb,radc,rodlen,ioffs,cosa,sina)
35439 #endif
35440 #endif
35441 
35442 int *xori;
35443 int *yori;
35444 int *rada;
35445 int *radb;
35446 int *radc;
35447 int *rodlen;
35448 int *ioffs;
35449 float *cosa;
35450 float *sina;
35451 {
35452   int rodl;
35453   int beta;
35454   int is;
35455   double x,y,x1,y1,x2,y2,x3,y3;
35456   XPoint points[400];
35457   int npoints;
35458   int binc;
35459 
35460 /*
35461    xori,yori = x,y of center of sphere
35462    diameter  = diameter of sphere
35463    ia        = flag for green circle around sphere (z-mat)
35464    ioffs     = offset in color array for atom color
35465 */
35466 
35467   rodl = *rodlen;
35468 
35469   XSetForeground(display, gc, colors[*ioffs]);
35470 
35471   npoints = 0;
35472 
35473   if (*rada) {
35474 	binc = 180/(*rada); if (!binc) binc = 1;
35475   }
35476   else binc = 1;
35477 
35478   is = 0;
35479   x1 = (double) *xori; y1 = (double) *yori;
35480   x = (double) 0; y = (double) -rodl;
35481   x2 = *xori + (*cosa*x - *sina*y);
35482   y2 = *yori + (*sina*x + *cosa*y);
35483   x3 = (x1 + x2) / 2.0;
35484   y3 = (y1 + y2) / 2.0;
35485 
35486   if ((x1 >= 0 && x1 <= (double) width) &&
35487 	(y1 >= 0 && y1 <= (double) height)) is++;
35488   if ((x2 >= 0 && x2 <= (double) width) &&
35489 	(y2 >= 0 && y2 <= (double) height)) is++;
35490   if ((x3 >= 0 && x3 <= (double) width) &&
35491 	(y3 >= 0 && y3 <= (double) height)) is++;
35492 
35493   if (!is) return;
35494 
35495   x = *radc; y = -rodl;
35496   points[0].x = *xori + (*cosa*x - *sina*y);
35497   points[0].y = *yori + (*sina*x + *cosa*y);
35498   for (beta=0; beta <= 180; beta = beta + binc)
35499   {
35500 	npoints++;
35501 	x = *rada*Tcos[beta];
35502 	y = *radb*Tsin[beta];
35503 	points[npoints].x = *xori + (*cosa*x - *sina*y);
35504 	points[npoints].y = *yori + (*sina*x + *cosa*y);
35505   }
35506   npoints++;
35507   x = -(*radc); y = -rodl;
35508   points[npoints].x = *xori + (*cosa*x - *sina*y);
35509   points[npoints].y = *yori + (*sina*x + *cosa*y);
35510   npoints++;
35511   XFillPolygon(display,molcur,gc,points,npoints,Convex,CoordModeOrigin);
35512 
35513   XSetBackground(display, gc, BlackPixel(display,screen));
35514   XSetFillStyle(display,gc,FillOpaqueStippled);
35515   XSetStipple(display,gc,stipple);
35516 
35517   npoints = 0;
35518   if (*cosa < 0) {
35519     x = *radc; y = -rodl;
35520     points[0].x = *xori + (*cosa*x - *sina*y);
35521     points[0].y = *yori + (*sina*x + *cosa*y);
35522     for (beta=0; beta <= 90; beta = beta + binc)
35523     {
35524 	   npoints++;
35525 	   x = *rada*Tcos[beta];
35526 	   y = *radb*Tsin[beta];
35527 	   points[npoints].x = *xori + (*cosa*x - *sina*y);
35528 	   points[npoints].y = *yori + (*sina*x + *cosa*y);
35529     }
35530     npoints++;
35531     x = 0; y = -rodl;
35532     points[npoints].x = *xori + (*cosa*x - *sina*y);
35533     points[npoints].y = *yori + (*sina*x + *cosa*y);
35534     npoints++;
35535     XFillPolygon(display,molcur,gc,points,npoints,Convex,CoordModeOrigin);
35536   }
35537   else {
35538     x = -(*radc); y = -rodl;
35539     points[0].x = *xori + (*cosa*x - *sina*y);
35540     points[0].y = *yori + (*sina*x + *cosa*y);
35541     for (beta=180; beta >= 90; beta = beta - binc)
35542     {
35543 	   npoints++;
35544 	   x = *rada*Tcos[beta];
35545 	   y = *radb*Tsin[beta];
35546 	   points[npoints].x = *xori + (*cosa*x - *sina*y);
35547 	   points[npoints].y = *yori + (*sina*x + *cosa*y);
35548     }
35549     npoints++;
35550     x = 0; y = -rodl;
35551     points[npoints].x = *xori + (*cosa*x - *sina*y);
35552     points[npoints].y = *yori + (*sina*x + *cosa*y);
35553     npoints++;
35554     XFillPolygon(display,molcur,gc,points,npoints,Convex,CoordModeOrigin);
35555   }
35556   XSetFillStyle(display,gc,FillSolid);
35557 
35558   npoints = 0;
35559   x = (*radc)/2; y = -rodl;
35560   points[0].x = *xori + (*cosa*x - *sina*y);
35561   points[0].y = *yori + (*sina*x + *cosa*y);
35562   for (beta=0; beta <= 180; beta = beta + binc)
35563   {
35564 	npoints++;
35565 	x = (*rada)*Tcos[beta]/2;
35566 	y = *radb*Tsin[beta];
35567 	points[npoints].x = *xori + (*cosa*x - *sina*y);
35568 	points[npoints].y = *yori + (*sina*x + *cosa*y);
35569   }
35570   npoints++;
35571   x = -(*radc)/2; y = -rodl;
35572   points[npoints].x = *xori + (*cosa*x - *sina*y);
35573   points[npoints].y = *yori + (*sina*x + *cosa*y);
35574   npoints++;
35575   XFillPolygon(display,molcur,gc,points,npoints,Convex,CoordModeOrigin);
35576 }
35577 
35578 #ifdef HASTIMER
35579 
35580 
Timer(msec,timopt)35581 void Timer(msec,timopt)   /* waits for 'n' milliseconds */
35582  int  msec;
35583  int timopt;
35584 {
35585 #ifdef VMS
35586   float ftime;
35587   ftime = msec / 1000.0;
35588   lib$wait(&ftime);
35589 
35590 #else
35591 
35592   long usec;
35593 
35594   if (handle == 1 && (timopt == 0 || timopt == 2 || timopt == 3)) return;
35595   if (bcksvg.UpSVG && (timopt == 0 || timopt == 2)) return;
35596   if (msec <= 0) return;
35597   usec = (long) msec * 1000;
35598 
35599   it[timopt].it_value.tv_sec = 0L;
35600   it[timopt].it_value.tv_usec = 0L;
35601   it[timopt].it_interval.tv_sec = 0L;
35602   it[timopt].it_interval.tv_usec = 0L;
35603 
35604   if (usec>=1000000L) {
35605     it[timopt].it_value.tv_sec = usec / 1000000L;
35606     usec %= 1000000L;
35607   }
35608 
35609   it[timopt].it_value.tv_usec = usec;
35610   tdone = 0;
35611   handle = timopt;
35612   if (timopt == 3) {
35613      signal(SIGALRM,handle_svgfile);
35614   } else if (timopt == 2) {
35615      signal(SIGALRM,handle_explalarm);
35616   } else if (timopt == 1) {
35617      if (!escopt) {
35618 	signal(SIGALRM,handle_tnk);
35619      } else {
35620 	signal(SIGALRM,handle_tnkesc);
35621      }
35622   } else signal(SIGALRM,handle_alarm);
35623   setitimer(ITIMER_REAL, &it[timopt], NULL);
35624   if (!timopt) pause();
35625 #endif
35626 }
35627 #endif
35628 
35629 #if defined(VMS) || defined(UNDERSC)
parpoi(nzm,nso,nio,nzo,ioropt,ifor,ixyz98,iopr,isymm,irc,imp2,icntp,msucc,ioni,mopopt,isbin,irtype,ipdbgro,ifav,ioxyz,iconv,ircus,nscnd,iscst,ialtyp)35630 void parpoi(
35631 #else
35632 #ifdef CRAY
35633 void PARPOI(
35634 #else
35635 void parpoi_(
35636 #endif
35637 #endif
35638 	nzm,nso,nio,nzo,ioropt,ifor,ixyz98,iopr,isymm,irc,
35639 	imp2,icntp,msucc,ioni,mopopt,isbin,irtype,
35640 	ipdbgro,ifav,ioxyz,iconv,ircus,nscnd,iscst,ialtyp)
35641 
35642 int *nzm;
35643 int *nso;
35644 int *nio;
35645 int *nzo;
35646 int *ioropt;
35647 int *ifor;
35648 int *ixyz98;
35649 int *iopr;
35650 int *isymm;
35651 int *irc;
35652 int *imp2;
35653 int *icntp;
35654 int *msucc;
35655 int *ioni;
35656 int *mopopt;
35657 int *isbin;
35658 int *irtype;
35659 int *ipdbgro;
35660 int *ifav;
35661 int *ioxyz;
35662 int *iconv;
35663 int *ircus;
35664 int *nscnd;
35665 int *iscst;
35666 int *ialtyp;
35667 {
35668 
35669  poi.nzm = *nzm;
35670  poi.nso = *nso;
35671  poi.nio = *nio;
35672  poi.nzo = *nzo;
35673  poi.ioropt = *ioropt;
35674  poi.ifor = *ifor;
35675  poi.ixyz98 = *ixyz98;
35676  poi.iopr = *iopr;
35677  poi.isymm = *isymm;
35678  poi.irc = *irc;
35679  poi.imp2 = *imp2;
35680  poi.icntp = *icntp;
35681  poi.msucc = *msucc;
35682  poi.ioni = *ioni;
35683  poi.mopopt = *mopopt;
35684  poi.isbin = *isbin;
35685  poi.irtype = *irtype;
35686  poi.ipdbgro = *ipdbgro;
35687  poi.ifav = *ifav;
35688  poi.ioxyz = *ioxyz;
35689  poi.iconv = *iconv;
35690  poi.ircus = *ircus;
35691  poi.nscnd = *nscnd;
35692  poi.iscst = *iscst;
35693  poi.ialtyp = *ialtyp;
35694 
35695  ptrpoi.nzm = nzm;
35696  ptrpoi.nso = nso;
35697  ptrpoi.nio = nio;
35698  ptrpoi.nzo = nzo;
35699  ptrpoi.ioropt = ioropt;
35700  ptrpoi.ifor = ifor;
35701  ptrpoi.ixyz98 = ixyz98;
35702  ptrpoi.iopr = iopr;
35703  ptrpoi.isymm = isymm;
35704  ptrpoi.irc = irc;
35705  ptrpoi.imp2 = imp2;
35706  ptrpoi.icntp = icntp;
35707  ptrpoi.msucc = msucc;
35708  ptrpoi.ioni = ioni;
35709  ptrpoi.mopopt = mopopt;
35710  ptrpoi.isbin = isbin;
35711  ptrpoi.irtype = irtype;
35712  ptrpoi.ipdbgro = ipdbgro;
35713  ptrpoi.ifav = ifav;
35714  ptrpoi.ioxyz = ioxyz;
35715  ptrpoi.iconv = iconv;
35716  ptrpoi.ircus = ircus;
35717  ptrpoi.nscnd = nscnd;
35718  ptrpoi.iscst = iscst;
35719  ptrpoi.ialtyp = ialtyp;
35720 }
35721 
bckpoi(istruct)35722 void bckpoi(istruct)
35723 int istruct;
35724 {
35725 
35726  poi = COO[istruct]->poi;
35727 
35728  *ptrpoi.nzm     = poi.nzm;
35729  *ptrpoi.nso     = poi.nso;
35730  *ptrpoi.nio     = poi.nio;
35731  *ptrpoi.nzo     = poi.nzo;
35732  *ptrpoi.ioropt  = poi.ioropt;
35733  *ptrpoi.ifor    = poi.ifor;
35734  *ptrpoi.ixyz98  = poi.ixyz98;
35735  *ptrpoi.iopr    = poi.iopr;
35736  *ptrpoi.isymm   = poi.isymm;
35737  *ptrpoi.irc     = poi.irc;
35738  *ptrpoi.imp2    = poi.imp2;
35739  *ptrpoi.icntp   = poi.icntp;
35740  *ptrpoi.msucc   = poi.msucc;
35741  *ptrpoi.ioni    = poi.ioni;
35742  *ptrpoi.mopopt  = poi.mopopt;
35743  *ptrpoi.isbin   = poi.isbin;
35744  *ptrpoi.irtype  = poi.irtype;
35745  *ptrpoi.ipdbgro = poi.ipdbgro;
35746  *ptrpoi.ifav    = poi.ifav;
35747  *ptrpoi.ioxyz   = poi.ioxyz;
35748  *ptrpoi.iconv   = poi.iconv;
35749  *ptrpoi.ircus   = poi.ircus;
35750  *ptrpoi.nscnd   = poi.nscnd;
35751  *ptrpoi.iscst   = poi.iscst;
35752  *ptrpoi.ialtyp  = poi.ialtyp;
35753 
35754 }
35755 
35756 #if defined(VMS) || defined(UNDERSC)
parptr(nptr,fptr,ffptr,nitem)35757 void parptr(nptr, fptr, ffptr, nitem)
35758 #else
35759 #ifdef CRAY
35760 void PARPTR(nptr, fptr, ffptr, nitem)
35761 #else
35762 void parptr_(nptr, fptr, ffptr, nitem)
35763 #endif
35764 #endif
35765 
35766 int *nptr;
35767 float *fptr;
35768 float *ffptr;
35769 int *nitem;
35770 {
35771 
35772     switch(*nptr) {
35773     case 1: FRQ = (FRQSTRU *) fptr; break;
35774     case 2: dorb.eiga = fptr; dorb.focc = (double *) ffptr; dorb.ncols = nitem;
35775 	    dorb.mxorg = 0;
35776 	    break;
35777     case 3: geo1ptr = (GEO1STRU *) fptr;
35778 	    geopntr.mxorg = 0;
35779 	    break;
35780     case 151: geo2ptr = (GEO2STRU *) fptr;
35781 	    geopntr.formax = geo2ptr->formax;
35782 	    geopntr.forrms = geo2ptr->forrms;
35783 	    geopntr.dismax = geo2ptr->dismax;
35784 	    geopntr.disrms = geo2ptr->disrms;
35785 	    geopntr.epoints = geo2ptr->epoints;
35786 	    geopntr.isav = geo2ptr->isav;
35787 	    break;
35788     case 4: cnvptr = (CNVSTRU *) fptr; break;
35789     case 5: pnt = (PNTSTRU *) nitem; break;
35790     case 6: zmatptr = (ZMATSTRU *) fptr;
35791 	    zmptr.bl = zmatptr->bl;
35792 	    zmptr.ibl = zmatptr->ibl;
35793 	    zmptr.alph = zmatptr->alph;
35794 	    zmptr.ialph = zmatptr->ialph;
35795 	    zmptr.bet = zmatptr->bet;
35796 	    zmptr.ibet = zmatptr->ibet;
35797 	    zmptr.imap = zmatptr->imap;
35798 	    zmptr.ianz = zmatptr->ianz;
35799 	    zmptr.iz = (int *) zmatptr->iz;
35800 	    break;
35801     case 7: atomptr = (ATOMSTRU *) fptr;
35802 	    xyz.coo = (double *) atomptr->coo;
35803 	    xyz.rzp = (double *) atomptr->rzp;
35804 	    xyz.ianz = (int *) atomptr->ianz;
35805 	    xyz.iaton = (int *) atomptr->iaton;
35806 	    xyz.iatclr = (int *) atomptr->iatclr;
35807 	    xyz.iresid = (int *) atomptr->iresid;
35808 	    xyz.ixp = (int *) atomptr->ixp;
35809 	    xyz.iyp = (int *) atomptr->iyp;
35810 	    xyz.iconn = (int *) atomptr->iconn;
35811 	    break;
35812     case 8: elmptr = (ELMSTRU *) fptr; break;
35813     case 9: zmptr.nz = nitem;
35814 	    zmptr.mxzorg = 0;
35815 	    break;
35816     case 10: dorb.eigb = fptr; dorb.focb = (double *) ffptr; dorb.ncolb = nitem;
35817 	     break;
35818     case 11: iuhf = nitem; break;
35819     case 12: xyz.icont = nitem; break;
35820     case 13: xyz.ncont = nitem; break;
35821     case 14: igffrm = nitem; break;
35822     case 15: xyz.iatoms = nitem;
35823 	     xyz.mxorg = 0;
35824 	     break;
35825     case 16: DoFreq = 0; break;
35826     case 129: DoFreq = 1; break;
35827     case 17: iftyp = nitem; break;
35828     case 18: esp = (double *) fptr; break;
35829     case 19: doesp = nitem; break;
35830     case 20: potcom = (POTSTRU *) fptr; break;
35831     case 21: irtval = nitem; break;
35832     case 22: ifntcl = nitem; break;
35833     case 24: icolps = nitem; break;
35834     case 25: ivtwo = nitem; break;
35835     case 26: ixyz = nitem; break;
35836     case 27: iixyz = nitem; break;
35837     case 28: iwropt = nitem; break;
35838     case 29: jobcom = (JOBSTRU *) nitem; break;
35839     case 37: espvdw = (double *) fptr; break;
35840     case 38: ispd = nitem; break;
35841     case 39: ibgcol = nitem; break;
35842     case 40: cell= (CELLSTRU *) nitem; break;
35843     case 41: jring = nitem; break;
35844     case 42: isimpl = nitem; break;
35845     case 43: surface = (SRFSTRU *) fptr; break;
35846     case 44: ivdwpl = nitem;break;
35847     case 45: NAT = (NATSTRU *) nitem; break;
35848     case 46: dospa = nitem; break;
35849     case 47: xyz.qat = (double *) fptr;
35850 	     break;
35851     case 48: fftyp = nitem; break;
35852     case 49: xyz.ityp = (short int *) nitem;
35853 	     break;
35854     case 50: xyz.ipdbt = (short int *) nitem;
35855 	     break;
35856     case 51: calfptr = (CALFSTRU *) fptr; break;
35857     case 52: istaro = nitem; break;
35858     case 53: fancy = nitem; break;
35859     case 54: atcol = nitem; break;
35860     case 55: shade = nitem; break;
35861     case 56: persp = nitem; break;
35862     case 57: tnkprg = nitem; break;
35863     case 58: currgrd = (double *) fptr; break;
35864     case 59: tnkbg = nitem; break;
35865     case 60: arch = nitem; break;
35866     case 61: archfrq = nitem; break;
35867     case 62: tnkit = nitem; break;
35868     case 63: iqopt = nitem; break;
35869     case 64: icalc = nitem; break;
35870     case 65: ipdbon = nitem; break;
35871     case 66: cubetyp = nitem; break;
35872     case 67: normc = nitem; break;
35873     case 68: frmul = fptr; break;
35874     case 69: ibell = nitem; break;
35875     case 70: natorg = nitem; break;
35876     case 71: zmptr.ihaszm = nitem; break;
35877     case 72: zmptr.mxzat = nitem; break;
35878     case 73: tstoc = (TSTOCSTRU *) fptr;
35879 	     stoc.cstoc = (double *) tstoc->cstoc;
35880 	     stoc.czstoc = (double *) tstoc->czstoc;
35881 	     stoc.astoc = tstoc->astoc;
35882 	     stoc.bstoc = tstoc->bstoc;
35883 	     stoc.ianstc = tstoc->ianstc;
35884 	     break;
35885     case 74: torb = (TORBSTRU *) fptr;
35886 	     orb.qd = (double *) torb->qd;
35887 	     orb.pd = torb->pd;
35888 	     orb.gd = (double *) torb->gd;
35889 	     orb.hd = (double *) torb->hd;
35890 	     break;
35891     case 75: dorb.vectrs = (double *) fptr; dorb.vectrb = (double *) ffptr;
35892 	     break;
35893     case 76: dorb.nocc = nitem; break;
35894     case 77: dorb.nocb = nitem; break;
35895     case 78: dorb.p = (double *) fptr; dorb.paa = (double *) ffptr;
35896 	     break;
35897     case 79: dorb.istos = nitem; break;
35898     case 80: dorb.stoalfa = fptr; dorb.stobnorm = ffptr;
35899 	     dorb.naorbs = nitem; break;
35900     case 81: dorb.averag = (double *) fptr; break;
35901     case 82: dorb.mxorb = nitem; break;
35902     case 83: sgrd.denn = (double *) fptr;
35903 	     sgrd.pmnn = (double *) ffptr;
35904 	     sgrd.mx3d = nitem;
35905 	     break;
35906     case 84: sgrd.dens = (double *) fptr;
35907 	     sgrd.denst = (double *) ffptr;
35908 	     sgrd.mx3d2 = nitem;
35909 	     break;
35910     case 85: sgrd.edx = (double *) fptr;
35911 	     sgrd.edy = (double *) ffptr;
35912 	     sgrd.iedlog = nitem;
35913 	     break;
35914     case 86: sgrd.rz = (double *) fptr;
35915 	     sgrd.bucket = (double *) ffptr;
35916 	     sgrd.ix = nitem;
35917 	     break;
35918     case 87: sgrd.iy = nitem; break;
35919     case 88: sgrd.mx3d = nitem; sgrd.mxorg = 0; break;
35920     case 89: sgrd.mx3d2 = nitem; break;
35921     case 90: irtcel = nitem; break;
35922     case 91: idelx = nitem; break;
35923     case 92: uscl = (double *) fptr; break;
35924     case 93: ball = nitem; break;
35925     case 94: picmax = nitem; break;
35926     case 95: cellpnt = (CELLSTRUC *) nitem; break;
35927     case 96: igztyp = nitem; break;
35928     case 97: igtfil = nitem; break;
35929     case 98: mgrd.fmap = (double *) fptr;
35930 	     mgrd.mx3d = nitem; mgrd.mxorg = 0;
35931 	     break;
35932     case 99: mapit = nitem; break;
35933     case 100: ipsi = nitem; break;
35934     case 101: mapval = (double *) fptr; break;
35935     case 102: imapopt = nitem; break;
35936     case 110: ipdbwh = nitem; break;
35937     case 113: ideltm = nitem; break;
35938     case 115: ewin = (double *) fptr; break;
35939     case 116: npmfs = nitem; break;
35940     case 117: pmfmn = (double *) fptr; pmfmx = (double *) ffptr;
35941 		npmfmx = nitem; break;
35942     case 118: ipmfmn = nitem; break;
35943     case 119: ipmfmx = nitem; break;
35944     case 120: pmflga = (double *) fptr; break;
35945     case 121: ialtyp = nitem; break;
35946     case 122: iscst = nitem; break;
35947     case 123: ipmfm = nitem; break;
35948     case 124: levcol = nitem; break;
35949     case 125: ipmfh = nitem; break;
35950     case 126: zmpart = (ZMPARTSTRU *) nitem; break;
35951     case 130: rotptr = (ROTSTRU *) fptr; break;
35952     case 131: posptr = (POSSTRU *) fptr; break;
35953     case 132: logo = nitem; break;
35954     case 133: nscnd = nitem; break;
35955     case 134: dolabs = nitem; break;
35956     case 135: fcptr = (FCSTRU *) fptr; break;
35957     case 136: forces_yes_no = nitem; break;
35958     case 137: ifogl = nitem; break;
35959     case 138: hlpsrf = (HSRFSTRU *) nitem; break;
35960     case 139: backb = nitem; break;
35961     case 142: XYZ = (XYZSTRU *) fptr; break;
35962     case 143: BAS = (BASSTRU *) fptr;
35963 	      slagau = (GAUSTRU *) nitem;
35964 	      break;
35965     case 144: comsrfptr = (COMSRFSTRU *) fptr; break;
35966     case 145: scle = (double *) fptr; break;
35967     case 146: ipsa = nitem; break;
35968     case 148: ifdogl = nitem; break;
35969     case 149: xyz.isurf = nitem;
35970 	      break;
35971     case 150: mapcol = (RGB *) fptr; valcol = (double *) ffptr; break;
35972 /* already declared above
35973     case 151: (GEO2STRU *) fptr; break;
35974 */
35975     case 153: pmfrot = (PMFROTSTRU *) fptr; break;
35976     case 154: adjuss = (double *) fptr; break;
35977     case 156: iocnt = nitem; break;
35978     case 157: monptr = (MONSTRU *) fptr; break;
35979     case 158: xyz.mxnat = nitem; break;
35980     case 159: xyz.lwrit = nitem; break;
35981     case 160: xyz.lring = nitem; break;
35982     case 161: xyz.inat = nitem; break;
35983     case 162: ibgclo = nitem; break;
35984     case 163: qdpptr = (CHGDIP *) fptr; break;
35985     case 164: ibgmod = nitem; break;
35986     case 165: rng1 = (double *) fptr; rng2 = (double *) ffptr; break;
35987     case 166: vlcnt = (double *) fptr; vlcnt2 = (double *) ffptr; break;
35988     case 167: scalptr = (SCALSTRU *) fptr; break;
35989     case 168: clfhptr = (CLFHSTR *) nitem; break;
35990     case 170: idoh = nitem; break;
35991     case 171: hbpars = (HBSTRU *) fptr; break;
35992     case 172: itot = nitem; break;
35993     case 173: do3d = nitem; break;
35994     case 174: ambchg = nitem; break;
35995     case 175: MOP = (MOPSTRU *) nitem; break;
35996     case 176: PSEUD = (PSEUDSTRU *) nitem; break;
35997     case 177: plane = (PLANESTRU *) fptr; break;
35998     case 178: eul = (EULSTRU *) fptr; break;
35999     case 179: proj = (PROJSTRU *) fptr; break;
36000     case 180: multstruct = nitem; break;
36001     case 181: mfdata = (MFSTRU *) nitem;
36002 	      mfdata->mollin = (int *) malloc(sizeof(int)*MXMFMOL);
36003 	      mfdata->mollin[0] = 0;
36004 	      mfdata->maxmol = MXMFMOL;
36005 	      mlftit = (char **) malloc(sizeof(char *)*MXMFMOL);
36006 	      mxtits = MXMFMOL;
36007               break;
36008     case 182: pol = (double *) fptr; break;
36009     case 183: pol2 = (double *) fptr; break;
36010     case 184: icpsa = (int *) nitem; break;
36011     case 185: idtpsa = (int *) nitem; break;
36012     case 186: movie = (int *) nitem; break;
36013     case 187: fullgl = (int *) nitem; break;
36014     case 188: icst = (int *) nitem; break;
36015     case 189: ibox = (int *) nitem; break;
36016     case 190: igfmap = (int *) nitem; break;
36017     case 191: clfstrptr = (CLFSTRU *) nitem; break;
36018     case 192: nmrptr = (NMRSTRU *) fptr; break;
36019     case 193: iresrd = (int *) nitem; break;
36020     case 194: alnptr = (ALNSTRU *) nitem; break;
36021     case 195: pbc = (PBCSTRUC *) fptr; break;
36022     case 196: doshad = (int *) nitem; break;
36023     case 197: ihasex = (int *) nitem; break;
36024     case 198: noshad = (int *) nitem; break;
36025     case 199: dorb.phi = (double *) fptr; break;
36026     case 200: dorb.dxpsi = (double *) fptr; break;
36027     case 201: dorb.dypsi = (double *) fptr; break;
36028     case 202: dorb.dzpsi = (double *) fptr; break;
36029     case 203: dorb.dphi = (double *) fptr; break;
36030     case 204: valcnt = (double *) fptr; break;
36031     case 205: incompl = (INCOMPLSTRU *) nitem; break;
36032     case 206: ionoff = (int *) nitem; break;
36033     case 207: icommf = (int *) nitem; break;
36034     case 208: mets = (METSTRU *) fptr; break;
36035     case 209: eneptr = (ENERSTRU *) nitem; break;
36036     case 210: chgvdwptr = (CHGVDWSTRU *) fptr; break;
36037     }
36038 }
36039 
drwcnv()36040 void drwcnv()
36041 {
36042       int nents;
36043 
36044       if (cnvptr->icvav2)
36045 	  nents = MAXI(cnvptr->jend1,cnvptr->jend2);
36046       else nents = cnvptr->jend1;
36047 
36048       if (cnvptr->icvav1)
36049       drwgra(&scfEfirst,-5,wincnv,CNVWIDE,CNVHIGH,NULL,cnvptr->convg1,cnvptr->jstrt1,cnvptr->jend1,nents,cnvptr->cnvmax,cnvptr->cnvmin,0.0e0,5,1,"Iterations","Energy","First Point",0,1,0,0);
36050       if (cnvptr->icvav2)
36051       drwgra(&scfElast,10,wincnv,CNVWIDE,CNVHIGH,NULL,cnvptr->convg2,cnvptr->jstrt2,cnvptr->jend2,nents,cnvptr->cnvmax,cnvptr->cnvmin,0.0e0,6,1,"Iterations","Energy","Last Point",1,0,0,0);
36052       XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
36053 }
36054 
drwspec()36055 void drwspec()
36056 {
36057       int i,j,ifr;
36058       double intensity, frq, center, rel_offset;
36059       double (*lineshape)(double);
36060       double fminus,scx,scy,x1,y1;
36061 
36062 
36063       if (out_spec == NULL) return;
36064 
36065       drwgra(&spect,-5,winspec,SPECWIDE,SPECHIGH,NULL,out_spec,1,n_freqs,n_freqs,spec_mx,spec_mn,0.0e0,5,1,splab,"Intensity","",0,1,0,1);
36066 
36067       if (!specps) {
36068 	XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
36069       }
36070 
36071       if (lorentzian) {
36072 	lineshape = lorentz;
36073       } else {
36074 	lineshape = gauss;
36075       }
36076 
36077       spect.npts = 0;
36078       scx = 1.0*n_freqs;
36079       scy = spec_mx - spec_mn;
36080       fminus = spec_mn - 0.05*scy;
36081       scy = 1.05*scy;
36082       ifr = 1;
36083 
36084       for (i=0; i < *spnfrq; i++) {
36085 	intensity = 0.0;
36086 	frq = ((double) spfrq[i])*freq_scale;
36087 	for (j=0; j < *spnfrq; j++) {
36088 	   center = ((double) spfrq[j])*freq_scale ;
36089 	   rel_offset = (frq - center) / hwhm;
36090 	   intensity += spint[j] * lineshape(rel_offset);
36091 	}
36092 
36093 	x1 = ((((double) spfrq[i])*freq_scale - min_freq)/freq_step)/scx;
36094  	y1 = (intensity-fminus)/scy;
36095 	if (spect.npts < MAXFRPNT) {
36096 		glpnt(SPECWIDE,SPECHIGH,x1,y1,
36097 		&spect.x[spect.npts],&spect.y[spect.npts],ifr);
36098 		spect.index[spect.npts] = i;
36099 	}
36100 	spect.npts++;
36101 
36102       }
36103 
36104       spect.fpts = (double *) spfrq;
36105 
36106       if (!specps) {
36107 	for (i=0; i<nsbutts; i++) DrwBut(&spbut[i]);
36108 	for (i=0; i<nspqbox; i++) {
36109 	   PromptBox(&qboxes[QHW+i]);
36110 	}
36111 
36112 	ULineString(winspec,"Spectrum:",CNVBORD, SPECHIGH+15);
36113 	ULineString(winspec,"Lineshape:",CNVBORD, SPECHIGH+BUTTN+15);
36114       }
36115 
36116 }
36117 
drwsco()36118 void drwsco()
36119 {
36120    int i;
36121    int PEH,PH,PW,NE,MW,jx,jy;
36122 
36123    scomin = 1.e10;
36124    scomax = -1.e10;
36125 
36126    for (i=0; i<*npmfs; i++) {
36127 	if (ewin[i] > scomax) scomax = ewin[i];
36128 	if (ewin[i] < scomin) scomin = ewin[i];
36129    }
36130    scomax = 1.2e0*(scomax - scomin) + scomin;
36131 
36132    if (*npmfs && ! (scomax == scomin)) {
36133       drwgra(&docksco,-5,winsco,CNVWIDE,CNVHIGH,NULL,ewin,1,*npmfs,*npmfs,scomax,scomin,0.0e0,5,1,"Orientations","Score",NULL,0,1,0,0);
36134       XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
36135    }
36136    for (i=0; i<NSCBUTTS; i++) DrwBut(&scbut[i]);
36137 
36138    LineString(winsco, "Ligand Color Mode", 30, CNVHIGH+54);
36139    LineString(winsco, "Include Hydrogens", 30, CNVHIGH+74);
36140 
36141    NE = 4;
36142    PEH = 20;
36143    PW = 70;
36144    PH = NE*PEH;
36145    MW = 10;
36146 
36147    jx = CNVWIDE-PW-10;
36148    jy = CNVHIGH+45;
36149 
36150    if (! *ipmfm) {
36151 	XSetForeground(display, gc, White);
36152 	XFillRectangle(display, winsco, gc, jx-10,jy-10, PW+20,4*PEH+20);
36153 	XSetForeground(display, gc, Black);
36154 	return;
36155    }
36156 
36157    for (i=0; i < NE; i++) {
36158 	XSetForeground(display, gc, colors[levcol[i]]);
36159 	XFillRectangle(display, winsco, gc, jx,jy+(i * PH)/NE, PW,PEH);
36160    }
36161 
36162    XSetForeground(display, gc, Black);
36163 
36164    sprintf(stemp, "PMFmax");
36165    XDrawString(display,winsco,gc,jx+15,jy+4,
36166            stemp,strlen(stemp));
36167    sprintf(stemp, "PMFavg");
36168    XDrawString(display,winsco,gc,jx+15,jy+4+(2*PH)/NE,
36169            stemp,strlen(stemp));
36170    sprintf(stemp, "PMFmin");
36171    XDrawString(display,winsco,gc,jx+15,jy+4+(4*PH)/NE,
36172            stemp,strlen(stemp));
36173 
36174 }
36175 
ButtonsSCO(i)36176 int ButtonsSCO(i)
36177 int i;
36178 {
36179    double tpmf;
36180 
36181    switch(i) {
36182    case 0:
36183 #if defined(VMS) || defined(UNDERSC)
36184 	alnsav();
36185 #else
36186 #ifdef CRAY
36187 	ALNSAV();
36188 #else
36189 	alnsav_();
36190 #endif
36191 #endif
36192 	break;
36193    case 1:
36194 #if defined(VMS) || defined(UNDERSC)
36195 	alnwrt();
36196 #else
36197 #ifdef CRAY
36198 	ALNWRT();
36199 #else
36200 	alnwrt_();
36201 #endif
36202 #endif
36203 	break;
36204    case 2:
36205 	bflag = 1; bretval = 561;
36206 	strcpy(molwstr,"Click on atom to analyze score !");
36207 	StatusStr(0,1);
36208 	XDefineCursor(display,win,AtomCursor);
36209 	break;
36210    case 3:
36211 	XDestroyWindow(display,winsco);scoup = 0;
36212 	break;
36213    case 4:
36214 	if (*ipmfm) {
36215 	   *ipmfm = 0;
36216 	} else {
36217 	   *ipmfm = 1;
36218 	}
36219 	TogBut(&scbut[4]);
36220 #if defined(VMS) || defined(UNDERSC)
36221 	totpmf(&tpmf);
36222 	qupd();
36223 #else
36224 #ifdef CRAY
36225 	TOTPMF(&tpmf);
36226 	QUPD();
36227 #else
36228 	totpmf_(&tpmf);
36229 	qupd_();
36230 #endif
36231 #endif
36232 	drwsco();
36233 
36234 	break;
36235    case 5:
36236 	if (*ipmfh) {
36237 	   *ipmfh = 0;
36238 	} else {
36239 	   *ipmfh = 1;
36240 	}
36241 	TogBut(&scbut[5]);
36242 #if defined(VMS) || defined(UNDERSC)
36243 	totpmf(&tpmf);
36244 	qupd();
36245 #else
36246 #ifdef CRAY
36247 	TOTPMF(&tpmf);
36248 	QUPD();
36249 #else
36250 	totpmf_(&tpmf);
36251 	qupd_();
36252 #endif
36253 #endif
36254 	drwsco();
36255 
36256 	break;
36257    }
36258    return(0);
36259 }
36260 
drwpmf()36261 void drwpmf()
36262 {
36263    int i;
36264 
36265    butje(winpmf,0,0,325,CNVHIGH+40,2,0,2,1,None,0,0,0);
36266    for (i=0; i<NPBUTTS; i++) DrwBut(&pbut[i]);
36267    RedrawList(&pmflistmx);
36268    RedrawList(&pmflistmn);
36269    ULineString(winpmf, "Top Negative Interactions", SBOXOFFX, 25);
36270    ULineString(winpmf, "Top Positive Interactions", SBOXOFFX, 25+120);
36271    sprintf(stemp, "Total Score Atom  : %8.3f",*pmflga);
36272    LineString(winpmf, stemp, SBOXOFFX, 25+120+120);
36273    sprintf(stemp, "Total Score Ligand: %8.3f",ewin[*npmfs-1]);
36274    LineString(winpmf, stemp, SBOXOFFX, 25+120+140);
36275 
36276 }
36277 
ButtonsPMF(i)36278 int ButtonsPMF(i)
36279 int i;
36280 {
36281 
36282    switch(i) {
36283    case 0:
36284 	XDestroyWindow(display,winpmf);pmfup = 0;
36285 	break;
36286    }
36287    return(0);
36288 }
36289 
36290 #if defined(VMS) || defined(UNDERSC)
drwgeo()36291 void drwgeo()
36292 #else
36293 #ifdef CRAY
36294 void DRWGEO()
36295 #else
36296 void drwgeo_()
36297 #endif
36298 #endif
36299 {
36300       int nitems;
36301 
36302       if (!geo1ptr->gcvav || !geoup) return;
36303 
36304       nhframes = 1;
36305       if (geo1ptr->ifmxav || geo1ptr->ifrmav) nhframes = 2;
36306       nwframes = 1;
36307       if (geo1ptr->idmxav || geo1ptr->idrmav) nwframes = 2;
36308 
36309       if (geo1ptr->ieav) {
36310 	   nitems = geo1ptr->nepnts;
36311 	   if (nitems > geo1ptr->mxpnt) nitems = geo1ptr->mxpnt;
36312 	   drwgra(&geoE,-5,wingeo,CNVWIDE,CNVHIGH,geop->isav,
36313 	   geop->epoints,0,0,nitems,geo1ptr->enmax,geo1ptr->enmin,
36314 	   0.0e0,9,1,"Point","Energy",NULL,0,1,1,0);
36315       }
36316 
36317       nitems = geo1ptr->ngeoms;
36318       if (nitems > geo1ptr->mxpnt) nitems = geo1ptr->mxpnt;
36319 
36320       if (geo1ptr->ifmxav)
36321 	   drwgra(&geoFmax,-5,wingeo,CNVWIDE,CNVHIGH,geop->isav,
36322 	   geop->formax,0,0,nitems,geo1ptr->fgmax,geo1ptr->fgmin,
36323 	   geo1ptr->fmaxt,5,2,"Point","Force","Max. Force",0,1,0,0);
36324 
36325       if (geo1ptr->ifrmav)
36326 	   drwgra(&geoFrms,10,wingeo,CNVWIDE,CNVHIGH,geop->isav,
36327 	   geop->forrms,0,0,nitems,geo1ptr->fgmax,geo1ptr->fgmin,
36328 	   geo1ptr->frmst,6,2,"Point","Force","Aver. Force",1,0,0,0);
36329 
36330       if (geo1ptr->idmxav)
36331 	   drwgra(&geoSmax,-5,wingeo,CNVWIDE,CNVHIGH,geop->isav,
36332 	   geop->dismax,0,0,nitems,geo1ptr->dgmax,geo1ptr->dgmin,
36333 	   geo1ptr->dmaxt,1,3,"Point","Step","Max. Step",0,1,0,0);
36334 
36335       if (geo1ptr->idrmav)
36336 	   drwgra(&geoSrms,10,wingeo,CNVWIDE,CNVHIGH,geop->isav,
36337            geop->disrms,0,0,nitems,geo1ptr->dgmax,geo1ptr->dgmin,
36338 	   geo1ptr->drmst,11,3,"Point","Step","Aver. Step",1,0,0,0);
36339 
36340       XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
36341 
36342 
36343 }
36344 
drwgra(tabptr,yelev,gwin,wide,high,isav,fpts,jbeg,jend,nents,fmax,fmin,flim,icol,ifr,xstr,ystr,labstr,isdash,init,notsav,ityp)36345 void drwgra(tabptr,yelev,gwin,wide,high,isav,fpts,jbeg,jend,nents,fmax,fmin,flim,icol,ifr,xstr,ystr,labstr,isdash,init,notsav,ityp)
36346 FRSTRU *tabptr;
36347 int yelev;
36348 Window gwin;
36349 int wide,high;
36350 int *isav;
36351 double *fpts;
36352 int jbeg,jend;
36353 int nents;
36354 double fmax,fmin,flim;
36355 int icol;
36356 int ifr;
36357 char *xstr;
36358 char *ystr;
36359 char *labstr;
36360 int isdash;
36361 int init;
36362 int notsav;
36363 int ityp;
36364 {
36365       int i,j,xt,yt,qlen,xoff;
36366       int ifrx,ifry;
36367       int dum0,dum1,itel,tick;
36368       double frq,fminus,scx,scy,x1,y1,x2,y2;
36369       char *tmpptr;
36370 
36371       tabptr->current = -1;
36372       tabptr->win = gwin;
36373       tabptr->fpts = fpts;
36374       tabptr->npts = 0;
36375       tabptr->yelev = yelev;
36376       tabptr->color = icol;
36377       tabptr->wide = wide;
36378       tabptr->high = high;
36379 
36380       if (tabptr->npts < nents && tabptr->x != NULL) {
36381 	free(tabptr->x);
36382 	free(tabptr->y);
36383 	free(tabptr->index);
36384       }
36385 
36386       if (tabptr->x == NULL || tabptr->npts < nents) {
36387 	tabptr->x = (int *) malloc((sizeof i)*nents);
36388 	tabptr->y = (int *) malloc((sizeof i)*nents);
36389 	tabptr->index =  (int *) malloc((sizeof i)*nents);
36390       }
36391 
36392       dum0 = 0;
36393       dum1 = 1;
36394 
36395       tmpptr = ystr;
36396 
36397       ifrx = 0;
36398       ifry = 0;
36399       if (ifr == 3 || ifr == 4) ifrx = 1;
36400       if (ifr == 2 || ifr == 4) ifry = 1;
36401 
36402       scx = 1.0*nents;
36403       scy = fmax - fmin;
36404       fminus = fmin - 0.05*scy;
36405       scy = 1.05*scy;
36406 
36407       if (init) {
36408 
36409        if (!specps) {
36410          XSetLineAttributes(display,gc,2,LineSolid,CapButt,JoinMiter);
36411 	 butje(gwin,CNVBORD+tabptr->wide*ifrx,CNVBORD+tabptr->high*ifry,
36412 	   tabptr->wide-2*CNVBORD,tabptr->high-2*CNVBORD,3,0,0,0,None,0,0,0);
36413          XSetForeground(display, gc, BlackPixel(display,screen));
36414 	 xoff = strlen(xstr)*10;
36415          XDrawString(display,gwin,gc,(tabptr->wide-CNVBORD-xoff)+tabptr->wide*ifrx,(tabptr->high-CNVBORD-10)+tabptr->high*ifry,xstr,strlen(xstr));
36416          for (i=0; i < strlen(ystr); i++,tmpptr++)
36417              XDrawString(display,gwin,gc,CNVBORD+13+tabptr->wide*ifrx,CNVBORD+40+tabptr->high*ifry+i*10,tmpptr,1);
36418 
36419          XSetForeground(display, gc, BlackPixel(display,screen));
36420 
36421 	} else {
36422 	   glpnt(tabptr->wide,tabptr->high,0.85,-0.10,&xt,&yt,ifr);
36423 	   qlen = strlen(xstr);
36424 	   fprintf(spout,"%d %d m 4 0 (%s) ashow\n",
36425 		600*(xt-qlen/2)/SPECWIDE,-300*yt/SPECHIGH,xstr);
36426 	   qlen = strlen(ystr);
36427 	   for (i=0; i < strlen(ystr); i++,tmpptr++) {
36428 		glpnt(tabptr->wide,tabptr->high,-0.02,1.0-i*0.05,&xt,&yt,ifr);
36429 		fprintf(spout,"%d %d m 4 0 (%c) ashow\n",
36430 		600*(xt)/SPECWIDE,-300*yt/SPECHIGH,ystr[i]);
36431 	   }
36432         }
36433 
36434          x1 = 0.0;
36435          y1 = 0.0;
36436          x2 = 1.0;
36437          y2 = 0.0;
36438          drwgl(gwin,tabptr->wide,tabptr->high,x1,y1,x2,y2,dum0,dum0,ifr,isdash);
36439          x2 = 0.0;
36440          y2 = 1.0;
36441          drwgl(gwin,tabptr->wide,tabptr->high,x1,y1,x2,y2,dum0,dum0,ifr,isdash);
36442 
36443 	 if (freq_step == 1.0) {
36444 		tick = 5;
36445 		if (nents > 50) tick = 10;
36446 		if (nents > 500) tick = 100;
36447 		if (nents > 1000) tick = 500;
36448 		if (nents > 10000) tick = 1000;
36449 		if (nents > 100000) tick = 10000;
36450 	 } else if (freq_step == nmr1Hstep) {
36451 		tick = 1;
36452 	 } else if (freq_step == nmr13Cstep) {
36453 		tick = 10;
36454 	 }
36455 
36456 	 if (ityp) {
36457 	    i = min_freq / tick;
36458 	    if (i < 0) i = 0;
36459 	    for (frq=tick*i; frq <= max_freq; frq = frq + tick) {
36460                if (frq >= 0 && frq <= nents) {
36461 		  x1 = ((frq - min_freq)/freq_step)/scx;
36462 		  y1 = 0.0;
36463 		  x2 = x1;
36464 		  y2 = -0.02;
36465 		  drwgl(gwin,tabptr->wide,tabptr->high,x1,y1,x2,y2,dum0,dum0,
36466 		    ifr,isdash);
36467 		  glpnt(tabptr->wide,tabptr->high,x1,-0.05,&xt,&yt,ifr);
36468 		  sprintf(stemp,"%d",(int) frq);
36469 
36470 		  if (specps) {
36471 			qlen = strlen(stemp);
36472 			fprintf(spout,"%d %d m 4 0 (%s) ashow\n",
36473 			  600*(xt-qlen/2)/SPECWIDE,-300*yt/SPECHIGH,stemp);
36474 		  } else {
36475 			qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
36476 			XDrawString(display,gwin,gc,xt-qlen/2,yt,stemp,
36477 			  strlen(stemp));
36478 		  }
36479                }
36480 	    }
36481 	 } else {
36482 	    for (i=0; i<=nents; i = i + tick) {
36483                if (i >= 0 && i <= nents) {
36484 		  x1 = i/scx;
36485 		  y1 = 0.0;
36486 		  x2 = i/scx;
36487 		  y2 = -0.02;
36488 		  drwgl(gwin,tabptr->wide,tabptr->high,x1,y1,x2,y2,dum0,dum0,
36489 		    ifr,isdash);
36490 		  glpnt(tabptr->wide,tabptr->high,x1,-0.05,&xt,&yt,ifr);
36491 		  sprintf(stemp,"%d",i);
36492 		  qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
36493 		  XDrawString(display,gwin,gc,xt-qlen/2,yt,stemp,strlen(stemp));
36494                }
36495 	    }
36496 	 }
36497       }
36498 
36499       if (labstr != NULL) {
36500 	if (!specps) {
36501 
36502          if (! monoscr) XSetForeground(display, gc, colors[icol]);
36503          else {
36504              XSetForeground(display, gc, BlackPixel(display,screen));
36505              if (isdash)
36506                   XSetLineAttributes(display,gc,2,LineOnOffDash,CapButt,JoinMiter);
36507 	     else XSetLineAttributes(display,gc,2,LineSolid,CapButt,JoinMiter);
36508              XDrawLine(display,gwin,gc,(tabptr->wide-CNVBORD-250)+tabptr->wide*ifrx,CNVBORD+40+isdash*20+tabptr->high*ifry,(tabptr->wide-CNVBORD-250)+tabptr->wide*ifrx,CNVBORD+40+isdash*20+tabptr->high*ifry);
36509          }
36510 
36511          XSetLineAttributes(display,gc,2,LineSolid,CapButt,JoinMiter);
36512          XDrawString(display,gwin,gc,(tabptr->wide-CNVBORD-100)+tabptr->wide*ifrx,CNVBORD+40+isdash*20+tabptr->high*ifry,labstr,strlen(labstr));
36513 
36514 	} else {
36515 		qlen = strlen(labstr);
36516 		xt = 0; yt = 0;
36517 		fprintf(spout,"%d %d m 4 0 (%s) ashow\n",
36518 		600*(xt-qlen/2)/SPECWIDE,-300*yt/SPECHIGH,labstr);
36519 	}
36520       }
36521 
36522       if (scy == 0.0) return;
36523 
36524       if (isav != NULL) {
36525 	 itel = -1;
36526          for (i=1; i <= nents-1; i++) {
36527             if (isav[i-1] == 1 || notsav) {
36528 	       if (i == pnt->ipnt) itel = tabptr->npts;
36529                x1 = i/scx;
36530                y1 = (fpts[i-1]-fminus)/scy;
36531 	       tabptr->index[tabptr->npts] = i-1;
36532 	       glpnt(tabptr->wide,tabptr->high,x1,y1,
36533 		 &tabptr->x[tabptr->npts],&tabptr->y[tabptr->npts],ifr);
36534 	       tabptr->npts++;
36535                for (j=i+1; j <= nents; j++) {
36536                  if (isav[j-1] == 1 || notsav) {
36537                     x2 = j/scx;
36538                     y2 = (fpts[j-1]-fminus)/scy;
36539                     drwgl(gwin,tabptr->wide,tabptr->high,x1,y1,x2,y2,
36540 			icol,dum1,ifr,isdash);
36541 		    if (j == nents) {
36542 	       		if (j == pnt->ipnt) itel = tabptr->npts;
36543 			tabptr->index[tabptr->npts] = nents-1;
36544 			glpnt(tabptr->wide,tabptr->high,x2,y2,
36545 			 &tabptr->x[tabptr->npts],&tabptr->y[tabptr->npts],ifr);
36546 			tabptr->npts++;
36547 		    }
36548                     break;
36549                  }
36550                }
36551             }
36552          }
36553 	 if (itel >= 0 && !specps) {
36554 	    XSetForeground(display,gc,colors[15]);
36555 	    XDrawArc(display, gwin, gc, tabptr->x[itel]-10,tabptr->y[itel]-10, 20, 20, 0,360*64);
36556 	 }
36557       }
36558       else {
36559 /*
36560    Leave out first Energy point because the jump is to big, all detail
36561    of the rest of the curve would be lost
36562 */
36563 
36564          for (i=jbeg; i <= jend; i++) {
36565                x1 = (i)/scx;
36566                y1 = (fpts[i-1]-fminus)/scy;
36567                x2 = (i+1)/scx;
36568                y2 = (fpts[i]-fminus)/scy;
36569 	       if (ityp) {
36570 		  if (i <= jend-1) drwgl(gwin,tabptr->wide,tabptr->high,
36571 		                   x1,y1,x2,y2,icol,dum0,ifr,isdash);
36572 	       } else {
36573 		  if (i <= jend-1) drwgl(gwin,tabptr->wide,tabptr->high,
36574 		                   x1,y1,x2,y2,icol,dum1,ifr,isdash);
36575 	                           tabptr->index[tabptr->npts] = i-1;
36576 		  glpnt(tabptr->wide,tabptr->high,x1,y1,
36577 		    &tabptr->x[tabptr->npts],&tabptr->y[tabptr->npts],ifr);
36578 		  tabptr->npts++;
36579 	       }
36580          }
36581       }
36582 
36583       if (flim > 0.0) {
36584          x1 = 0.0;
36585          y1 = (flim-fminus)/scy;
36586          x2 = 0.2;
36587          y2 = y1;
36588          drwgl(gwin,tabptr->wide,tabptr->high,x1,y1,x2,y2,icol,dum0,ifr,isdash);
36589       }
36590 
36591 }
36592 
drwgl(gwin,wide,high,x1,y1,x2,y2,icol,icross,iframe,isdash)36593 void drwgl(gwin,wide,high,x1,y1,x2,y2,icol,icross,iframe,isdash)
36594 Window gwin;
36595 double x1;
36596 double y1;
36597 double x2;
36598 double y2;
36599 int wide,high;
36600 int icol;
36601 int icross;
36602 int iframe;
36603 int isdash;
36604 {
36605   int x1t,x2t,y1t,y2t;
36606 
36607   glpnt(wide,high,x1,y1,&x1t,&y1t,iframe);
36608   glpnt(wide,high,x2,y2,&x2t,&y2t,iframe);
36609 
36610   if (!specps) {
36611 	if (monoscr) XSetForeground(display, gc, colors[0]);
36612 	else XSetForeground(display,gc,colors[icol]);
36613 	if (monoscr && icol) {
36614 	    if (isdash) XSetLineAttributes(display, gc, 2, LineOnOffDash,
36615 			CapButt, JoinMiter);
36616 	}
36617 	XDrawLine(display,gwin,gc,x1t,y1t,x2t,y2t);
36618 
36619 	if (icross == 1) {
36620 	     XDrawLine(display,gwin,gc,x1t-2,y1t-2,x1t+2,y1t+2);
36621 	     XDrawLine(display,gwin,gc,x1t-2,y1t+2,x1t+2,y1t-2);
36622 	     XDrawLine(display,gwin,gc,x2t-2,y2t-2,x2t+2,y2t+2);
36623 	     XDrawLine(display,gwin,gc,x2t-2,y2t+2,x2t+2,y2t-2);
36624 	}
36625 	if (monoscr && icol) {
36626 	   XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinMiter);
36627 	}
36628   } else {
36629      fprintf(spout,"newpath\n");
36630      fprintf(spout,"%d %d m %d %d l\n",600*x1t/SPECWIDE,-300*y1t/SPECHIGH,
36631 	600*x2t/SPECWIDE,-300*y2t/SPECHIGH);
36632      fprintf(spout,"stroke\n");
36633   }
36634 }
36635 
glpnt(wide,high,x,y,xr,yr,iframe)36636 void glpnt(wide,high,x,y,xr,yr,iframe)
36637 int wide,high;
36638 double x;
36639 double y;
36640 int *xr;
36641 int *yr;
36642 int iframe;
36643 {
36644   int ifrx,ifry;
36645 
36646   ifrx = 0;
36647   ifry = 1;
36648   if (iframe == 3 || iframe == 4) ifrx = 1;
36649   if (iframe == 2 || iframe == 4) ifry = 2;
36650 
36651   *xr = x*(wide-2*CNVOFFX-2*CNVBORD) + CNVOFFX + CNVBORD + wide*ifrx;
36652   *yr = high*ifry - (y*(high-2*CNVOFFY-2*CNVBORD) + 1.4*CNVOFFY + CNVBORD);
36653 
36654 }
36655 
parse_motion(tabptr)36656 void parse_motion(tabptr)
36657 FRSTRU *tabptr;
36658 {
36659   int qlen,nopnt = 1;
36660 
36661   if (tabptr->npts <= 0) return;
36662 
36663   XSetLineAttributes(display, gc, 2, LineSolid, CapButt, JoinMiter);
36664   nopnt = FindSel(NULL,tabptr->x,tabptr->y,0,tabptr->npts,
36665 	event.xmotion.x,event.xmotion.y,GLTOL);
36666 
36667   if (tabptr->current != nopnt) {
36668      if (tabptr->current != -1) {
36669         XSetForeground(display, gc, colors[190]);
36670         XSetFunction(display, gc, GXxor);
36671 	if (tabptr->fpts == (double *) spfrq) {
36672 	   sprintf(stemp,"%f",freq_scale*spfrq[tabptr->index[tabptr->current]]);
36673 	} else {
36674 	   sprintf(stemp,"%f",tabptr->fpts[tabptr->index[tabptr->current]]);
36675 	}
36676         qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
36677         XDrawString(display,tabptr->win,gc,tabptr->x[tabptr->current]-qlen,
36678    	  tabptr->y[tabptr->current]+tabptr->yelev,stemp,strlen(stemp));
36679         XSetFunction(display, gc, GXcopy);
36680         XSetForeground(display, gc, colors[tabptr->color]);
36681         XDrawLine(display,tabptr->win,gc,tabptr->x[tabptr->current]-2,
36682    	  tabptr->y[tabptr->current]-2,tabptr->x[tabptr->current]+2,
36683    	  tabptr->y[tabptr->current]+2);
36684         XDrawLine(display,tabptr->win,gc,tabptr->x[tabptr->current]-2,
36685 	  tabptr->y[tabptr->current]+2,tabptr->x[tabptr->current]+2,
36686 	  tabptr->y[tabptr->current]-2);
36687      }
36688      if (nopnt != -1) {
36689         XSetForeground(display, gc, colors[190]);
36690         XSetFunction(display, gc, GXxor);
36691 	if (tabptr->fpts == (double *) spfrq) {
36692            sprintf(stemp,"%f",freq_scale*spfrq[tabptr->index[nopnt]]);
36693 	} else {
36694            sprintf(stemp,"%f",tabptr->fpts[tabptr->index[nopnt]]);
36695 	}
36696         qlen = XTextWidth(mfinfo,stemp, strlen(stemp));
36697         XDrawString(display,tabptr->win,gc,tabptr->x[nopnt]-qlen,
36698    	  tabptr->y[nopnt]+tabptr->yelev,stemp,strlen(stemp));
36699         XSetFunction(display, gc, GXcopy);
36700         XSetForeground(display, gc, BlackPixel(display, screen));
36701         XDrawLine(display,tabptr->win,gc,tabptr->x[nopnt]-2,tabptr->y[nopnt]-2,
36702    	  tabptr->x[nopnt]+2,tabptr->y[nopnt]+2);
36703         XDrawLine(display,tabptr->win,gc,tabptr->x[nopnt]-2,tabptr->y[nopnt]+2,
36704 	  tabptr->x[nopnt]+2,tabptr->y[nopnt]-2);
36705      }
36706   }
36707   tabptr->current = nopnt;
36708   XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinMiter);
36709 }
36710 
parse_label(Ca,l,ix,iy)36711 void parse_label(Ca,l,ix,iy)
36712 int Ca;
36713 int l;
36714 int *ix;
36715 int *iy;
36716 {
36717       int x,y;
36718 
36719 /* only visible atoms have non-zero ixp and iyp values */
36720 
36721       if ((Ca >= 0 && Ca != rsold) || (Ca <= -4 && Ca != rsold) ||
36722 		(Ca == RESUND && rsold != RESUND)) {
36723 
36724 	 if ( !((*fancy || *fullgl) && has_opengl && !StarNetOld) ) {
36725            if (rsold != RESUND)
36726 	       XCopyArea(display,bckwin,win,gc,0,0,BckW,BckH,bckx,bcky);
36727 	 }
36728 
36729 	 strcpy(atemp,"               ");
36730 
36731 	 if ( ( (Ca >= 0 && Ca != rsold) || (Ca <= -4 && Ca != rsold) )
36732 		&& Ca != RESUND) {
36733 
36734 
36735 	   if (Ca >= 0) l = calfptr->icalf[Ca][0]-1;
36736 	   x = iy[l];
36737 	   y = ix[l];
36738 	   lhoh = l;
36739 
36740 	   if (Ca >= 0) {
36741 		sprintf(atemp,"%3s %-6d ",AminoAcids[calfptr->iamino[Ca]-1],
36742 					 calfptr->irsnr[Ca]);
36743 		atemp[12] = '\0';
36744 	   } else {
36745 		int aca;
36746 
36747 		aca = abs(Ca+1);
36748 		if (calfptr->ishoh > 0 && Ca+1 < -1.0e0*calfptr->ishoh) {
36749 		   if (Ca+1 <= calfptr->ision && calfptr->ision < 0) {
36750 			sprintf(atemp,"ION     ");
36751 		   } else {
36752 			sprintf(atemp,"HOH     ");
36753 		   }
36754 		} else {
36755 		   if (aca < MXHETA && abs(Ca) < MXHETA) {
36756 			sprintf(atemp,"%3s     ",hetptr.HetAtm[abs(Ca)]);
36757 			sprintf(atemp,"%3s     ",hetptr.HetAtm[abs(Ca+1)]);
36758 		   }
36759 		}
36760 		atemp[9] = '\0';
36761 	   }
36762 
36763 	   if ((*fancy || *fullgl) && has_opengl && !StarNetOld) {
36764 #ifdef DOGL
36765 	      dispsf();
36766 	      printString(x,y,1,atemp);
36767 #endif
36768 	   } else {
36769 	      foreground_pixel = colors[15];
36770 	      XSetForeground(display, gc, foreground_pixel);
36771 	      XCopyArea(display,win,bckwin,gc,x,y-20,BckW,BckH,0,0);
36772 	      XDrawString(display, win, gc, x, y, atemp, 8);
36773 	   }
36774 
36775 
36776 	   bckx = x; bcky = y-20;
36777 	 } else if (Ca == RESUND && rsold != RESUND) {
36778 #ifdef DOGL
36779 	   if ((*fancy || *fullgl) && has_opengl && !StarNetOld) dispsf();
36780 #endif
36781 	 }
36782 	 rsold = Ca;
36783       }
36784 }
36785 
parse_labelp(Ca,l,ix,iy)36786 void parse_labelp(Ca,l,ix,iy)
36787 int Ca;
36788 int l;
36789 int *ix;
36790 int *iy;
36791 {
36792       int x,y;
36793 
36794       if ( (Ca >= 0 && Ca != rsold && !( (*fancy || *fullgl) && has_opengl))
36795 	|| (Ca <= -4 && Ca != rsold) ||
36796 	   (Ca == RESUND && rsold != RESUND)) {
36797 
36798 	 if ( !( (*fancy || *fullgl) && has_opengl && !StarNetOld) ) {
36799            if (rsold != RESUND)
36800 	       XCopyArea(display,bckwin,win,gc,0,0,BckW,BckH,bckx,bcky);
36801 	 }
36802 
36803 	 strcpy(atemp,"        ");
36804 	 if ( ( (Ca >= 0 && Ca != rsold) || (Ca <= -4 && Ca != rsold) )
36805 		&& Ca != RESUND) {
36806 
36807 	   if (Ca >= 0) {
36808             /*this gives a wrong position for res label */
36809 		x = calfptr->icyp[Ca];
36810 		y = calfptr->icxp[Ca];
36811 	   } else {
36812 		x = iy[l];
36813 		y = ix[l]-20;
36814 		lhoh = l;
36815 	   }
36816 
36817 	   if (Ca >= 0) {
36818 		sprintf(atemp,"%3s %3d ",AminoAcids[calfptr->iamino[Ca]-1],
36819 					 calfptr->irsnr[Ca]);
36820 	   } else {
36821 		int aca;
36822 
36823 		aca = abs(Ca+1);
36824 		if (calfptr->ishoh > 0 && Ca+1 < -1.0e0*calfptr->ishoh) {
36825 		   if (Ca+1 <= calfptr->ision && calfptr->ision < 0) {
36826 			sprintf(atemp,"ION     ");
36827 		   } else {
36828 			sprintf(atemp,"HOH     ");
36829 		   }
36830 		} else {
36831 		   if (aca < MXHETA && abs(Ca) < MXHETA) {
36832 			sprintf(atemp,"%3s     ",hetptr.HetAtm[abs(Ca)]);
36833 			sprintf(atemp,"%3s     ",hetptr.HetAtm[abs(Ca+1)]);
36834 		   }
36835 		}
36836 	   }
36837 
36838 	   if ( (*fancy || *fullgl) && has_opengl && !StarNetOld) {
36839 #ifdef DOGL
36840 	      dispsf();
36841 	      printString(x,y,1,atemp);
36842 #endif
36843 	   } else {
36844 	      foreground_pixel = colors[15];
36845 	      XSetForeground(display, gc, foreground_pixel);
36846 	      XCopyArea(display,win,bckwin,gc,x,y-20,BckW,BckH,0,0);
36847 	      XDrawString(display, win, gc, x, y, atemp, 8);
36848 	   }
36849 
36850 
36851 	   bckx = x; bcky = y-20;
36852 	 } else if (Ca == RESUND && rsold != RESUND) {
36853 #ifdef DOGL
36854 	   if ( (*fancy || *fullgl) && has_opengl && !StarNetOld) dispsf();
36855 #endif
36856 	 }
36857 	 rsold = Ca;
36858       }
36859 }
36860 
FindSel(onoff,x,y,ist,num_items,cursorx,cursory,mindiff)36861 int FindSel(onoff,x,y,ist,num_items,cursorx,cursory,mindiff)
36862 int *onoff;
36863 int *x;
36864 int *y;
36865 int ist;
36866 int num_items;
36867 int cursorx,cursory;
36868 int mindiff;
36869 {
36870     int i,irt,dx,dy,dsqr,dsq_min,found,oke;
36871 
36872     found = -1;
36873     dsq_min = mindiff*mindiff;
36874     for ( i = ist; i < ist+num_items; i++ ) {
36875       oke = 0;
36876       if (onoff == NULL) oke = 1;
36877       else if (onoff[i] >= 1) oke = 1;
36878       if (oke) {
36879 	  dx = ABS(cursorx - x[i]);
36880 	  dy = ABS(cursory - y[i]);
36881 	  dsqr = dx*dx + dy*dy;
36882           if (dx < mindiff && dy < mindiff && dsqr < dsq_min ) {
36883 		dsq_min = dsqr;
36884 		found = i;
36885           }
36886       }
36887     }
36888 /* below is to accomodate to find a Calfa, because when in the upper loop it
36889    find Calfa it is from the secondary structure visualsation because these
36890    always come last in the atom array, so actually not the real Calfa is found
36891    but the visualisation Calfa (ianz = 100)
36892 */
36893     if ((found == -1 || (found != -1 && xyzp->ianz[found] == 100 )) && *ipdbon && onoff != NULL) {
36894 	irt = FindCa(onoff,x,y,cursorx,cursory,mindiff);
36895 	if (irt != -1) irt = calfptr->icalf[irt][0]-1;
36896 	return(irt);
36897     } else return (found);
36898 }
36899 
FindCa(onoff,x,y,cursorx,cursory,mindiff)36900 int FindCa(onoff,x,y,cursorx,cursory,mindiff)
36901 int *onoff;
36902 int *x;
36903 int *y;
36904 int cursorx,cursory;
36905 int mindiff;
36906 {
36907     int i,j,l,dx,dy,dsqr,dsq_min,dsq_minz,found,oke;
36908     double dz, dzmin;
36909 
36910     found = -1;
36911     dsq_min = mindiff*mindiff;
36912     dsq_minz = mindiff*mindiff;
36913     if (has_opengl && (*fancy || *fullgl)) {
36914 	dzmin = 1000000;
36915     } else {
36916 	dzmin = -1000000;
36917     }
36918     for ( i = 0; i < calfptr->ncalf; i++ ) {
36919      for ( j = 0; j < 4; j++ ) {
36920       l = calfptr->icalf[i][j]-1;
36921       if (l < 0 || l > *xyzp->mxnat) continue;
36922       oke = 0;
36923       if (onoff == NULL) oke = 1;
36924       else if (onoff[l] >= 1) oke = 1;
36925       if (1) {
36926 	  dx = ABS(cursorx - x[l]);
36927 	  dy = ABS(cursory - y[l]);
36928 	  dz = xyzp->rzp[l];
36929 	  dsqr = dx*dx + dy*dy;
36930           if (dx < mindiff && dy < mindiff && dsqr < dsq_min) {
36931 	     if (has_opengl && (*fancy || *fullgl)) {
36932 		if (dz < dzmin) {
36933 	 	  dzmin = dz;
36934 		  found = i;
36935 		}
36936 	     } else {
36937 		if (dz > dzmin) {
36938 	 	  dzmin = dz;
36939 		  found = i;
36940 		}
36941 	     }
36942           }
36943       }
36944      }
36945     }
36946     return (found);
36947 }
36948 
FindCaP(cursorx,cursory,mindiff)36949 int FindCaP(cursorx,cursory,mindiff)
36950 int cursorx,cursory;
36951 int mindiff;
36952 {
36953     int i,dx,dy,dsqr,dsq_min,found;
36954 
36955     found = -1;
36956     dsq_min = mindiff*mindiff;
36957     for ( i = 0; i < calfptr->ncalf; i++ ) {
36958 	dx = ABS(cursorx - calfptr->icyp[i]);
36959 	dy = ABS(cursory - calfptr->icxp[i]);
36960 	dsqr = dx*dx + dy*dy;
36961         if (dx < mindiff && dy < mindiff && dsqr < dsq_min) {
36962 	  found = i;
36963         }
36964     }
36965     return (found);
36966 }
36967 
36968 #if defined(VMS) || defined(UNDERSC)
labnr(isup)36969 void labnr(isup)
36970 #else
36971 #ifdef CRAY
36972 void LABNR(isup)
36973 #else
36974 void labnr_(isup)
36975 #endif
36976 #endif
36977 
36978 int *isup;
36979 {
36980     if (ZMEup&&*zmptrp->ihaszm) *isup = 1;
36981     else *isup = 0;
36982 }
36983 
InitZME()36984 void InitZME()
36985 {
36986    int i;
36987 
36988    ZMEup = 1;
36989 
36990    ZME_window_pos = 0;
36991    ZMEmode = 0;
36992    ZMEsel = 0;
36993 
36994    ZMEanW  = XTextWidth(mfinfo,"  ",2)+3*QBOXFR+2*QBOXBORD;
36995    ZMEconW = XTextWidth(mfinfo,"   ",3)+3*QBOXFR+2*QBOXBORD;
36996    ZMEbutW = XTextWidth(mfinfo,"   ",3)+2*QBOXBORD+3;
36997    ZMEvarW = XTextWidth(mfinfo,"------------",11)+3*QBOXFR+2*QBOXBORD;
36998    ZMEvarWs = XTextWidth(mfinfo,"--------",8)+3*QBOXFR+2*QBOXBORD;
36999    ZMEiz4W = XTextWidth(mfinfo,"-",1)+3*QBOXFR+2*QBOXBORD;
37000    ZMEiz   = ZMEanW+ZMETab2+ZMEvarW+ZMETab3;
37001    ZMEizs  = ZMEvarWs;
37002    ZMEZWIDE = ZMEBord + ZMETab1 + 3*ZMEiz + ZMEiz4W + ZMEBord;
37003 
37004    XMapWindow(display,ZMEwin);
37005 
37006 
37007    DefBut(&ZMEbut[ZMECANC], ZMEwin, ZMEZOffx+ZMEZWIDE+ZMESCR-30, 5,
37008 	50, 23, "Close", infobg, ZMBCOL);
37009    ZMEbut[ZMECANC].explstr = "Close the Z-Matrix window";
37010 
37011    DefBut(&ZMEbut[ZMEARR1], ZMEwin, ZMEZOffx+ZMEZWIDE+ZMESCR, ZMEZOffy ,
37012 	23, 23, " ", infobg, 0);
37013    DefBut(&ZMEbut[ZMEARR2], ZMEwin, ZMEZOffx+ZMEZWIDE+ZMESCR,
37014 	ZMEZOffy+ZME_window_high*ZMEQHIGH+ZMEBord-22, 23, 23, " ", infobg, 0);
37015 
37016    DefBut(&ZMEbut[ZMEAPPL], ZMEwin, ZMEZOffx, ZMEButOffy,
37017 	ZMEBW2, 23, "Apply Changes to current Z-Mat", infobg, ZMBCOL);
37018    ZMEbut[ZMEAPPL].explstr = "Update on screen structure by applying the current Z-matrix\nHitting Enter/Return in the variable fields has the same effect";
37019 
37020    DefBut(&ZMEbut[ZMECAN1], ZMEwin, ZMEZOffx, ZMEButOffy+ZMEBWIDE,
37021 	ZMEBW2, 23, "Cancel Non-Applied Changes", infobg, ZMBCOL);
37022    ZMEbut[ZMECAN1].explstr = "Restore values of the Z-matrix the last time it was applied";
37023 
37024    DefBut(&ZMEbut[ZMEDEL], ZMEwin, ZMEZOffx, ZMEButOffy+2*ZMEBWIDE,
37025 	ZMEBW4, 23, "Delete Line", infobg, ZMBCOL);
37026    ZMEbut[ZMEDEL].explstr = "Delete a line from Z-matrix ==\nDelete an atom/dummy from the structure:\nLines can ONLY be removed when no other lines\nuse it as reference.\nIf there are references, remove those first";
37027 
37028    DefBut(&ZMEbut[ZMEADD], ZMEwin, 2*ZMEZOffx+ZMEBW4, ZMEButOffy+2*ZMEBWIDE,
37029 	ZMEBW4, 23, "Add Line", infobg, ZMBCOL);
37030    ZMEbut[ZMEADD].explstr = "Add line to Z-matrix ==\nAdd an atom/dummy to your structure";
37031 
37032    DefBut(&ZMEbut[ZMEFRG], ZMEwin, ZMEZOffx, ZMEButOffy+3*ZMEBWIDE,
37033 	ZMEBW2, 23, "Substitute atom by Fragment", infobg, ZMBCOL);
37034    ZMEbut[ZMEFRG].explstr = "Substitute active atom/line\nby the fragment you select";
37035 
37036    DefBut(&ZMEbut[ZMENEW], ZMEwin, ZMEZOffx, ZMEButOffy+4*ZMEBWIDE,
37037 	ZMEBW4, 23, "New Z-mat", infobg, ZMBCOL);
37038    ZMEbut[ZMENEW].explstr = "Clear Z-Matrix.\nSame as start with empty structure";
37039    DefBut(&ZMEbut[ZMEMAP], ZMEwin, 2*ZMEZOffx+ZMEBW4, ZMEButOffy+4*ZMEBWIDE,
37040 	ZMEBW4, 23, "MapXYZ/Optimise", infobg, ZMBCOL);
37041    ZMEbut[ZMEMAP].explstr = "Convert a structure from file to the current Z-matrix.\nUseful if the optimised structure is only available as XYZ.\nBut you need it as Z-matrix\nAlso interfaces to external optimisers are available";
37042 
37043    DefBut(&ZMEbut[ZMECVAR], ZMEwin, ZMEZOffx+ZMEWINW/2, ZMEButOffy,
37044 	ZMEBW2, 23, "Set Status All Variables", infobg, ZMBCOL);
37045    ZMEbut[ZMECVAR].explstr = "Treat all bond distances, bond angles and dihedral angles\neither as variable or constant.\nIndividual variables can be set by cicking\nwith the second mouse button in the variable field";
37046 
37047    DefBut(&ZMEbut[ZMEORD],  ZMEwin, ZMEZOffx+ZMEWINW/2, ZMEButOffy+2*ZMEBWIDE,
37048 	ZMEBW2, 23, "Reorder Z-matrix", infobg, ZMBCOL);
37049    ZMEbut[ZMEORD].explstr = "Reorder the Z-matrix by clicking on screen atoms\nin the order you want the Z-matrix to be\nYou can abort the specification after any number of clicked atoms\nMolden will supply the remaining ones";
37050 
37051    DefBut(&ZMEbut[ZMESEL], ZMEwin, ZMEZOffx+ZMEWINW/2, ZMEButOffy+3*ZMEBWIDE,
37052 	ZMEBW4, 23, "Select by pointer", infobg, ZMBCOL);
37053    ZMEbut[ZMESEL].explstr = "Select a substructure of on screen atoms of which a Z-matrix will be generated\nSelecting: click first mouse button,\ndrag while keeping the mouse button pressed.\nUse in combination with DeSelect and Apply Selection";
37054 
37055    DefBut(&ZMEbut[ZMEUSEL],ZMEwin, 2*ZMEZOffx+ZMEWINW/2+ZMEBW4,
37056 	ZMEButOffy+3*ZMEBWIDE, ZMEBW4, 23, "DeSelect", infobg,ZMBCOL);
37057    ZMEbut[ZMEUSEL].explstr = "Deselect on screen atoms of which a Z-matrix will be generated\nSelecting: click first mouse button,\ndrag while keeping the mouse button pressed.\nUse in combination with Select by pointer and Apply Selection";
37058 
37059    DefBut(&ZMEbut[ZMESELA],ZMEwin, ZMEZOffx+ZMEWINW/2, ZMEButOffy+4*ZMEBWIDE,
37060 	ZMEBW2, 23, "Apply Selection", infobg, ZMBCOL);
37061    ZMEbut[ZMESELA].explstr = "Generate Z-matrix of selected on screen atoms.\nUse in combination with Select by pointer and DeSelect";
37062 
37063    DefBut(&ZMEbut[ZMEGAM], ZMEwin, ZMEZOffx+75,ZMEWOffy+ZMEWBOFF , 23, 23,
37064         	   " ", infobg, ZMBCOL);
37065    ZMEbut[ZMEGAM].explstr = "In combination with the Write Z-Matrix button:\nWrite the Z-matrix in Gamess format.\nIn combination with the Submit Job button\nSubmit a Gamess job";
37066 
37067    DefBut(&ZMEbut[ZMEGAU], ZMEwin, ZMEZOffx+155,ZMEWOffy+ZMEWBOFF, 23, 23,
37068         	   " ", infobg, ZMBCOL);
37069    ZMEbut[ZMEGAU].explstr = "In combination with the Write Z-Matrix button:\nWrite the Z-matrix in Gaussian format.\nIn combination with the Submit Job button\nSubmit a Gaussian job";
37070 
37071    DefBut(&ZMEbut[ZMEMOP], ZMEwin, ZMEZOffx+245,ZMEWOffy+ZMEWBOFF, 23, 23,
37072         	   " ", infobg, ZMBCOL);
37073    ZMEbut[ZMEMOP].explstr = "In combination with the Write Z-Matrix button:\nWrite the Z-matrix in MOPAC format.\nIn combination with the Submit Job button\nSubmit a MOPAC job";
37074 
37075    DefBut(&ZMEbut[ZMENWC], ZMEwin, ZMEZOffx+315,ZMEWOffy+ZMEWBOFF, 23, 23,
37076         	   " ", infobg, ZMBCOL);
37077    ZMEbut[ZMENWC].explstr = "In combination with the Write Z-Matrix button:\nWrite the Z-matrix in NWCHEM format.\nIn combination with the Submit Job button\nSubmit a NWCHEM job";
37078 
37079    DefBut(&ZMEbut[ZMECAR], ZMEwin, ZMEZOffx+400,ZMEWOffy+ZMEWBOFF, 23, 23,
37080         	   " ", infobg, ZMBCOL);
37081    DefBut(&ZMEbut[ZMEWRT], ZMEwin, ZMEZOffx,ZMEWOffy+10, ZMEBW2, 23,
37082         	   "Write Z-Matrix", infobg, ZMBCOL);
37083    ZMEbut[ZMEWRT].explstr = "Write the current Z-Matrix\nIn combination with the format buttons";
37084 
37085    DefBut(&ZMEbut[ZMESUB], ZMEwin, ZMEZOffx+ZMEWINW/2,ZMEWOffy+10,
37086 		ZMEBW2, 23, "Submit Job", infobg, ZMBCOL);
37087    ZMEbut[ZMESUB].explstr = "Submit a Gaussian/Gamess/MOPAC job\nIn combination with the format buttons";
37088 
37089    DefBut(&ZMEBbut[ZMESIN], ZMEwin, ZMEZOffx+145,ZMEButOffy , 23, 23,
37090         	   " ", infobg, ZMBCOL);
37091    ZMEBbut[ZMESIN].explstr = "Select bond distance and bond angle for a single bond";
37092 
37093    DefBut(&ZMEBbut[ZMEDBL], ZMEwin, ZMEZOffx+145,ZMEButOffy+ZMEBWIDE, 23, 23,
37094         	   " ", infobg, ZMBCOL);
37095    ZMEBbut[ZMEDBL].explstr = "Select bond distance and bond angle for a double bond";
37096 
37097    DefBut(&ZMEBbut[ZMETRI], ZMEwin, ZMEZOffx+145,ZMEButOffy+2*ZMEBWIDE, 23, 23,
37098         	   " ", infobg, ZMBCOL);
37099    ZMEBbut[ZMETRI].explstr = "Select bond distance and bond angle for a triple bond";
37100 
37101    DefBut(&ZMEswitch[0], ZMEwin, ZMEZOffx+ZMEZWIDE+ZMESCR-110,
37102 	ZMEZOffy-ZMEFRBord+ZMEZHIGH-TOGGWH-1, TOGGWH, TOGGWH, " ", infobg, ZMBCOL);
37103 
37104    DefBut(&ZMEswitch[1], ZMEwin, ZMEZOffx+ZMEZWIDE+ZMESCR-55,
37105 	5, 23, 23, " ", infobg, ZMBCOL);
37106 
37107    ZMEswitch[1].pix = BigPix;
37108    ZMEswitch[1].pw  = bigsmall_width;
37109    ZMEswitch[1].ph  = bigsmall_height;
37110 
37111    DefBut(&ZMEbut[ZMEUS], ZMEwin, ZMEZOffx+105,ZMEWOffy+ZMEWBOFF+18 , 15, 15,
37112         	   " ", infobg, ZMBCOL);
37113    ZMEbut[ZMEUS].explstr = "Switch between Gamess-UK and Gamess-US format";
37114 
37115    ActBut(&ZMEbut[ZMEopt],-1);
37116    TogDown(&ZMEbut[ZMEopt]);
37117    ActBut(&ZMEBbut[ZMEmul],-1);
37118    TogDown(&ZMEBbut[ZMEmul]);
37119    if (ZMEAA) {
37120 	TogUp(&ZMEswitch[0]);
37121    } else {
37122 	TogDown(&ZMEswitch[0]);
37123    }
37124    if (ZMEbig) {
37125 	TogUp(&ZMEswitch[1]);
37126    } else {
37127 	TogDown(&ZMEswitch[1]);
37128    }
37129    if (SUBup) TogDown(&ZMEbut[ZMESUB]);
37130    ZMEbut[ZMEARR1].pix = upPix;
37131    ZMEbut[ZMEARR1].pw  = up_width;
37132    ZMEbut[ZMEARR1].ph  = up_height;
37133 
37134    ZMEbut[ZMEARR2].pix = downPix;
37135    ZMEbut[ZMEARR2].pw  = down_width;
37136    ZMEbut[ZMEARR2].ph  = down_height;
37137 
37138    qboxstr(&qboxes[QBZMAT],&ZMEwin,0,0,190,ZMEZOffx,ZMEWOffy+40,
37139       ZMEZWIDE,QBOXHIGH,2,"File name ? ",NULL,0,0,470,0,dummyproc);
37140 
37141    qboxstr(&EXPbox[0],&ZMEwin,0,0,190,ZMEZOffx+225,ZMEZOffy-ZMEFRBord+
37142 	   ZMEZHIGH-TOGGWH,130,QBOXHIGH-9,2,"Expr.",NULL,10,0,2000,-1,dummyproc);
37143    if (ZMEAA) EXPbox[0].fake = 0;
37144    else EXPbox[0].fake = 1;
37145 
37146    for (i=0; i < TABBUTN; i++) {
37147 	if (i==TABBUTN-1)
37148    	DefBut(&TabBut[i],ZMEwin, ZMEZOffx+ZMEBord+TabPos[i][1]*(ZMETABH+1), ZMEZOffy+ZMEBord+TabPos[i][0]*(ZMETABH+1), ZMETABH, ZMETABH,
37149         	   elements[99], infobg, -elmptr->icol[98]);
37150 	else
37151    	DefBut(&TabBut[i],ZMEwin, ZMEZOffx+ZMEBord+TabPos[i][1]*(ZMETABH+1), ZMEZOffy+ZMEBord+TabPos[i][0]*(ZMETABH+1), ZMETABH, ZMETABH,
37152         	   elements[i+1], infobg, -elmptr->icol[i]);
37153    }
37154 
37155    SetQZME();
37156 
37157    DefScroll(&zscroll,ZMEwin,ZMEZOffx+ZMEZWIDE+ZMESCR,ZMEZOffy+22,22,
37158              ZME_window_high*ZMEQHIGH+ZMEBord-2*22,zmptrp->nz,
37159 	    &ZME_window_pos,ZME_window_high,NULL);
37160 
37161    strcpy(ZMEerr,"Use Mouse Button 2 to change the status of a variable");
37162 
37163    if (ZMEAA) make_aa();
37164 }
37165 
UnMapZME()37166 void UnMapZME()
37167 {
37168 	int nw;
37169 
37170 	SwitchOffAnim();
37171 	TogUp(&cbut[BZMAT]);
37172 	ZMEup = 0;
37173 	XUnmapWindow(display,ZMEwin);
37174 	ZoomEnable = False; ZoomSelection = False;
37175 	DeActZME();
37176 	ActBut(&cbut[BDIST],1);
37177 	ActBut(&cbut[BANGLE],1);
37178 	ActBut(&cbut[BDIHED],1);
37179         if (*backb) {ActBut(&cbut[BDECRF],1); ActBut(&cbut[BUNSC],1);}
37180         ActBut(&cbut[BREADF],1);
37181         if (denm) ActBut(&cbut[BDENMOD],1);
37182 #ifdef DOGL
37183 	if ((*fancy || *fullgl) && has_opengl) ogunsel();
37184 #endif
37185 
37186 #if defined(VMS) || defined(UNDERSC)
37187         haswat(&nw);
37188 #else
37189 #ifdef CRAY
37190         HASWAT(&nw);
37191 #else
37192         haswat_(&nw);
37193 #endif
37194 #endif
37195 	if (nw != nwater[istruct])  {
37196 	   reswat();
37197 #ifdef DOGL
37198 	   if (*fancy) {
37199 	      oghet(0);
37200 	   } else {
37201 	      oglines();
37202 	   }
37203 #endif
37204 	}
37205 #ifdef DOGL
37206 	dispsf();
37207 #endif
37208 }
37209 
RedrawZME()37210 void RedrawZME()
37211 {
37212    int i,ZMEx,ZMEy;
37213 
37214    if (!ZMEup) return;
37215 
37216    ZMEy = 20;
37217    ZMEx = ZMEZOffx + ZMEBord + 5;
37218    XDrawString(display,ZMEwin,gc,ZMEx,ZMEy,"Atom",4);
37219    ZMEx = ZMEx + ZMETab1 + ZMEconW + ZMETab2;
37220 
37221    if (monoscr) {
37222        XSetFillStyle(display, gc, FillStippled);
37223        XSetStipple(display, gc, hlfgrey);
37224        XSetForeground(display, gc, infobg);
37225        XFillRectangle(display, ZMEwin, gc, 0, ZMEZOffy-ZMEFRBord, ZMEWINW, ZMEZHIGH+1);
37226        XSetFillStyle(display,gc,FillSolid);}
37227    else {
37228 	butje(ZMEwin,0,0,ZMEWINW-1,ZMEZOffy-ZMEFRBord+1,1,0,0,1,None,0,0,0);
37229         XSetForeground(display, gc, infobg);
37230 	butje(ZMEwin,0,ZMEZOffy-ZMEFRBord,ZMEWINW-1,ZMEZHIGH,1,0,0,1,None,0,0,0);
37231    }
37232    if (ZMEAA) {
37233 	XDrawString(display,ZMEwin,gc,ZMEZOffx+ZMETab1+15+0*ZMEizs,45,"Phi",3);
37234 	XDrawString(display,ZMEwin,gc,ZMEZOffx+ZMETab1+15+1*ZMEizs,45,"Psi",3);
37235 	XDrawString(display,ZMEwin,gc,ZMEZOffx+ZMETab1+15+2*ZMEizs,45,"Chi1",4);
37236 	XDrawString(display,ZMEwin,gc,ZMEZOffx+ZMETab1+15+3*ZMEizs,45,"Chi2",4);
37237 	XDrawString(display,ZMEwin,gc,ZMEZOffx+ZMETab1+15+4*ZMEizs,45,"Chi3",4);
37238 	XDrawString(display,ZMEwin,gc,ZMEZOffx+ZMETab1+15+5*ZMEizs,45,"Chi4",4);
37239    } else {
37240 	XDrawString(display,ZMEwin,gc,ZMEx,ZMEy,"BondLength",10);
37241 	XDrawString(display,ZMEwin,gc,ZMEx+ZMEiz,ZMEy,"BondAngle",9);
37242 	XDrawString(display,ZMEwin,gc,ZMEx+2*ZMEiz,ZMEy,"DiHedral",8);
37243    }
37244 
37245    butje(ZMEwin,0,ZMEZOffy-ZMEFRBord+ZMEZHIGH-1,ZMEWINW/2+1,ZMEBHIGH,1,0,0,1,None,0,0,0);
37246    butje(ZMEwin,ZMEWINW/2,ZMEZOffy-ZMEFRBord+ZMEZHIGH-1,ZMEWINW/2,ZMEBHIGH,1,0,0,1,None,0,0,0);
37247    RedrawStatus();
37248    butje(ZMEwin,0,ZMEWOffy-3,ZMEWINW-1,ZMEWHIGH,1,0,0,1,None,0,0,0);
37249 
37250    butje(ZMEwin, ZMEZOffx+1, ZMEZOffy, ZMEZWIDE-1, ZME_window_high*ZMEQHIGH+ZMEBord+1,2,0,2,0,None,0,0,0);
37251 
37252    UpdateZME();
37253 
37254    if (ZMEsel || ZMEmode) {
37255    	for (i=0; i<3; i++) DrwBut(&ZMEBbut[i]);
37256 	ULineString(ZMEwin, "Bond Length:", ZMEZOffx+3 ,ZMEButOffy+15);
37257 	LineString(ZMEwin, "Single", ZMEZOffx+190  ,ZMEButOffy+15);
37258 	LineString(ZMEwin, "Double", ZMEZOffx+190 ,ZMEButOffy+ZMEBWIDE+15);
37259 	LineString(ZMEwin, "Triple", ZMEZOffx+190 ,ZMEButOffy+2*ZMEBWIDE+15);
37260 	return;
37261    }
37262 
37263    if (pdb) LineString(ZMEwin, "Full Z-Mat", ZMEZOffx+ZMEZWIDE+ZMESCR-80,
37264 	ZMEZOffy-ZMEFRBord+ZMEZHIGH-ZMETABA+16);
37265 
37266    RedrawScroll(&zscroll);
37267    for (i=0; i<ZMEBUTTS; i++) DrwBut(&ZMEbut[i]);
37268    if (pdb && ! *ialtyp) DrwBut(&ZMEswitch[0]);
37269    DrwBut(&ZMEswitch[1]);
37270 
37271    PromptBox(&qboxes[QBZMAT]);
37272    ULineString(ZMEwin, "New Z-mat from screen coordinates:", ZMEZOffx+ZMEWINW/2+5 ,ZMEButOffy+15+ZMEBWIDE);
37273    ULineString(ZMEwin, "Format:", ZMEZOffx ,ZMEWOffy+ZMEWBOFF+15);
37274    LineString(ZMEwin, "Gamess"           , ZMEZOffx+75+30 ,ZMEWOffy+ZMEWBOFF+15);
37275    LineString(ZMEwin, "US", ZMEZOffx+125 ,ZMEWOffy+ZMEWBOFF+30);
37276    LineString(ZMEwin, "Gaussian"         , ZMEZOffx+155+30 ,ZMEWOffy+ZMEWBOFF+15);
37277    LineString(ZMEwin, "Mopac"            , ZMEZOffx+245+30 ,ZMEWOffy+ZMEWBOFF+15);
37278    LineString(ZMEwin, "NWchem"           , ZMEZOffx+315+30 ,ZMEWOffy+ZMEWBOFF+15);
37279    LineString(ZMEwin, "Cartesian"        , ZMEZOffx+400+30 ,ZMEWOffy+ZMEWBOFF+15);
37280 }
37281 
RedrawStatus()37282 void RedrawStatus()
37283 {
37284 
37285  if (!ZMEup) return;
37286 
37287  butje(ZMEwin,0,ZMEZOffy-ZMEFRBord+ZMEZHIGH+ZMEBHIGH-2,ZMEWINW-1,ZMESHIGH,1,0,0,1,None,0,0,0);
37288  butje(ZMEwin,ZMEZOffx,ZMEZOffy-ZMEFRBord+ZMEZHIGH+ZMEBHIGH+8,ZMEZWIDE,20,2,0,2,0,None,0,0,0);
37289  XSetForeground(display, gc, infobg);
37290  XDrawString(display,ZMEwin,gc,ZMEZOffx+5,ZMEZOffy-ZMEFRBord+ZMEZHIGH+ZMEBHIGH+22,ZMEerr,strlen(ZMEerr));
37291 }
37292 
UpdateZME()37293 void UpdateZME()
37294 {
37295    int i,j,k;
37296    int ZMEx,ZMEy,ZMESx,ZMESy;
37297    int isvis,isaa;
37298 
37299    if (DEBUG) fprintf(stderr,"UpdateZME in\n");
37300    if (!ZMEup) return;
37301 
37302    if (ZMEmode) {
37303 	strcpy(ZMEerr,"Select Atom");
37304 	RedrawStatus();
37305 	for (i=0; i<TABBUTN; i++) DrwBut(&TabBut[i]);
37306 	return;
37307    }
37308 
37309    if (ZMEAA) {
37310 
37311 	for (i=0; i<*zmptrp->nz; i++) {
37312 	   BETbox[i].x = 0;
37313 	   BETbox[i].y = 0;
37314 	}
37315 
37316 	zscroll.wn = &calfptr->ncalf;
37317 
37318 	if (ZME_window_pos > calfptr->ncalf-1-ZME_window_high) {
37319 	    if (calfptr->ncalf-1-ZME_window_high >= 0) {
37320 		ZME_window_pos = calfptr->ncalf-ZME_window_high;
37321             } else ZME_window_pos = 0;
37322 	}
37323 
37324 
37325         ZMESy = ZMEZOffy-ZMEFRBord+ZMEZHIGH-ZMETABA;
37326         j = 0;
37327 	for (i=0; i<calfptr->ncalf; i++) {
37328 
37329 	   isvis = (i >= ZME_window_pos && i < ZME_window_pos + ZME_window_high);
37330 	   if (isvis) {
37331 		ZMEx = ZMEZOffx + ZMEBord - 3;
37332 		ZMEy = ZMEZOffy + ZMEBord + (i - ZME_window_pos)*ZMEQHIGH;
37333 		ZMESx = ZMEZOffx + ZMETab1 + 5 + j*ZMETABA;
37334 	   } else {
37335 		ZMEx = 0;
37336 		ZMEy = 0;
37337 	   }
37338 
37339            isaa = (*aaptr[i].iamino <= 23);
37340 
37341            if (isvis) {
37342 		DefBut(&ZMEAAbut[j], ZMEwin, ZMEx, ZMEy, ZMEbutW, ZMETABH+2,
37343         	   AminoAcids[*aaptr[i].iamino-1], infobg,
37344 		   -clfhptr->iamicl[*aaptr[i].iamino-1]);
37345 		if (i == CurAmino) {
37346 			ZMEAAbut[j].lastused = 1;
37347 			ZMEAAbut[j].bg = 1;
37348 		} else {
37349 			ZMEAAbut[j].lastused = -1;
37350 			ZMEAAbut[j].bg = 196;
37351 		}
37352 		DefBut(&ZMEAASbut[j], ZMEwin, ZMESx, ZMESy, ZMETABA, ZMETABA,
37353         	   AAlet[*aaptr[i].iamino-1], infobg,
37354 		   -clfhptr->iamicl[*aaptr[i].iamino-1]);
37355 		ZMEx = ZMEZOffx + ZMETab1 + 5 ;
37356 		j++;
37357 	   }
37358 
37359 	   if (isaa) {
37360 		BETbox[aaptr[i].phi].x = ZMEx;
37361 		BETbox[aaptr[i].phi].y = ZMEy;
37362 		if (isvis) PromptBox(&BETbox[aaptr[i].phi]);
37363 
37364 		if (isvis) ZMEx = ZMEZOffx + ZMETab1 + 5 + 1*ZMEizs;
37365 		BETbox[aaptr[i].psi].x = ZMEx;
37366 		BETbox[aaptr[i].psi].y = ZMEy;
37367 		if (isvis) PromptBox(&BETbox[aaptr[i].psi]);
37368 
37369 		if (isvis) ZMEx = ZMEZOffx + ZMETab1 + 5 + 2*ZMEizs;
37370 		if (aaptr[i].chi1 > -1) {
37371 		   BETbox[aaptr[i].chi1].x = ZMEx;
37372 		   BETbox[aaptr[i].chi1].y = ZMEy;
37373 		   if (isvis) PromptBox(&BETbox[aaptr[i].chi1]);
37374 		} else {
37375 		   if (isvis) PFake(ZMEwin,ZMEx,ZMEy,ZMEvarWs,ZMEQHIGH,196);
37376 		}
37377 
37378 		if (isvis) ZMEx = ZMEZOffx + ZMETab1 + 5 + 3*ZMEizs;
37379 		if (aaptr[i].chi2 > -1) {
37380 		   BETbox[aaptr[i].chi2].x = ZMEx;
37381 		   BETbox[aaptr[i].chi2].y = ZMEy;
37382 		   if (isvis) PromptBox(&BETbox[aaptr[i].chi2]);
37383 		} else {
37384 		   if (isvis) PFake(ZMEwin,ZMEx,ZMEy,ZMEvarWs,ZMEQHIGH,196);
37385 		}
37386 
37387 		if (isvis) ZMEx = ZMEZOffx + ZMETab1 + 5 + 4*ZMEizs;
37388 		if (aaptr[i].chi3 > -1) {
37389 		   BETbox[aaptr[i].chi3].x = ZMEx;
37390 		   BETbox[aaptr[i].chi3].y = ZMEy;
37391 		   if (isvis) PromptBox(&BETbox[aaptr[i].chi3]);
37392 		} else {
37393 		   if (isvis) PFake(ZMEwin,ZMEx,ZMEy,ZMEvarWs,ZMEQHIGH,196);
37394 		}
37395 
37396 		if (isvis) ZMEx = ZMEZOffx + ZMETab1 + 5 + 5*ZMEizs;
37397 		if (aaptr[i].chi4 > -1) {
37398 		   BETbox[aaptr[i].chi4].x = ZMEx;
37399 		   BETbox[aaptr[i].chi4].y = ZMEy;
37400 		   if (isvis) PromptBox(&BETbox[aaptr[i].chi4]);
37401 		} else {
37402 		   if (isvis) PFake(ZMEwin,ZMEx,ZMEy,ZMEvarWs,ZMEQHIGH,196);
37403 		}
37404 
37405 	   } else {
37406 
37407 		if (isvis) {
37408 		   for (k=0; k<6; k++) {
37409 			ZMEx = ZMEZOffx + ZMETab1 + 5 + k*ZMEizs;
37410 			PFake(ZMEwin,ZMEx,ZMEy,ZMEvarWs,ZMEQHIGH,196);
37411 		   }
37412 		}
37413 	   }
37414 	}
37415 
37416         for (i=0; i<ZME_window_high; i++) {
37417 	   if (i<calfptr->ncalf) {
37418 		DrwBut(&ZMEAAbut[i]);
37419 		DrwBut(&ZMEAASbut[i]);
37420 	   }
37421 	}
37422 	ZMEx = ZMEZOffx + ZMEBord - 3;
37423         ZMESx = ZMEZOffx + ZMETab1;
37424         XSetForeground(display, gc, colors[190]);
37425 	XFillRectangle(display, ZMEwin, gc,
37426                                 ZMEx, ZMESy+3, 30, ZMETABA-4);
37427 	sprintf(ZMEups,"%-4d",ZME_window_pos+1);
37428         XSetForeground(display, gc, colors[0]);
37429 	XDrawString(display,ZMEwin,gc,ZMEx+5,ZMESy+17,ZMEups,4);
37430         EXPbox[0].fake = 0;
37431 	PromptBox(&EXPbox[0]);
37432 
37433 	return;
37434    }
37435 
37436    zscroll.wn = zmptrp->nz;
37437 
37438    if (ZME_window_pos > *zmptrp->nz-1-ZME_window_high) {
37439 	if (*zmptrp->nz-1-ZME_window_high >= 0) {
37440 	    ZME_window_pos = *zmptrp->nz-ZME_window_high;
37441         }
37442 	else ZME_window_pos = 0;
37443    }
37444 
37445    for (i=0; i<*zmptrp->nz; i++) {
37446 	isvis = (i >= ZME_window_pos && i < ZME_window_pos + ZME_window_high);
37447 	if (isvis) {
37448 	   ZMEx = ZMEZOffx + ZMEBord;
37449 	   ZMEy = ZMEZOffy + ZMEBord + (i - ZME_window_pos)*ZMEQHIGH;
37450 	}
37451 	else {
37452 	   ZMEx = 0;
37453 	   ZMEy = 0;
37454 	}
37455 	IANZbox[i].x = ZMEx;
37456 	IANZbox[i].y = ZMEy;
37457 	if (isvis) PromptBox(&IANZbox[i]);
37458 	for (j=0; j<3; j++) {
37459 		if (isvis) ZMEx = ZMEZOffx + ZMEBord + ZMETab1 + j*ZMEiz;
37460 	   	IZbox[i*4+j].x = ZMEx;
37461 	   	IZbox[i*4+j].y = ZMEy;
37462 		if (isvis) PromptBox(&IZbox[i*4+j]);
37463 		if (isvis) ZMEx = ZMEx + ZMEconW + ZMETab2;
37464 		if (j == 0) {
37465 	   	   BLbox[i].x = ZMEx;
37466 	   	   BLbox[i].y = ZMEy;
37467 		   if (isvis) PromptBox(&BLbox[i]);
37468 		}
37469 		else if (j == 1) {
37470 	   	   ALPHbox[i].x = ZMEx;
37471 	   	   ALPHbox[i].y = ZMEy;
37472 		   if (isvis) PromptBox(&ALPHbox[i]);
37473 		}
37474 		else if (j == 2) {
37475 	   	   BETbox[i].x = ZMEx;
37476 	   	   BETbox[i].y = ZMEy;
37477 		   if (isvis) PromptBox(&BETbox[i]);
37478 		}
37479 	}
37480 	if (isvis) ZMEx = ZMEZOffx + ZMEBord + ZMETab1 + 3*ZMEiz;
37481 	IZbox[i*4+3].x = ZMEx;
37482 	IZbox[i*4+3].y = ZMEy;
37483 	if (isvis) PromptBox(&IZbox[i*4+3]);
37484    }
37485    EXPbox[0].fake = 1;
37486    if (pdb) PFake(ZMEwin,ZMEZOffx+225,ZMEZOffy-ZMEFRBord+ZMEZHIGH-TOGGWH,130,
37487 	QBOXHIGH-9, EXPbox[0].bgcol);
37488    if (DEBUG) fprintf(stderr,"UpdateZME out\n");
37489 }
37490 
QPcol(qp,iop)37491 void QPcol(qp,iop)
37492 QBOXSTRU *qp;
37493 int iop;
37494 {
37495     int icol;
37496 
37497     switch (iop) {
37498 	case 0: icol = ZC_CONST; break;
37499 	case 1: icol = ZC_VAR; break;
37500 	default: icol = ZC_LINK;
37501     }
37502     qp->col = icol;
37503 }
37504 
SetConst(iop)37505 void SetConst(iop)
37506 int iop;
37507 {
37508  int i,icol;
37509 
37510     switch (iop) {
37511 	case 0: icol = ZC_CONST; break;
37512 	case 1: icol = ZC_VAR; break;
37513 	default: icol = ZC_LINK;
37514     }
37515     for (i=0; i<*zmptrp->nz; i++) {
37516 		zmptrp->ibl[i] = iop;
37517 		BLbox[i].col = icol;
37518 		BLbox[i].changed = 1;
37519 		zmptrp->ialph[i] = iop;
37520 		ALPHbox[i].col = icol;
37521 		ALPHbox[i].changed = 1;
37522 		zmptrp->ibet[i] = iop;
37523 		BETbox[i].col = icol;
37524 		BETbox[i].changed = 1;
37525     }
37526     UpdateZME();
37527 }
37528 
SetQZME()37529 void SetQZME()
37530 {
37531    int i,j;
37532    int nvar,fake,zvw,zvwn;
37533 
37534    if (DEBUG) fprintf(stderr,"SetQZME in\n");
37535 
37536 /*
37537    SetQZME updates on screen zmat information with the zmat-structure
37538 */
37539 
37540    if (!*zmptrp->ihaszm) return;
37541 
37542    strcpy(ZMEerr," ");
37543    for (i=0; i<*zmptrp->nz; i++) {
37544 	   if (zmptrp->ianz[i] >= 0 && zmptrp->ianz[i] < 100)
37545 		sprintf(stemp,"%s",elements[zmptrp->ianz[i]]);
37546 	   else sprintf(stemp,"%s","?");
37547 
37548 	   qboxstr(&IANZbox[i],&ZMEwin,0,0,196,0,0,ZMEanW,ZMEQHIGH,
37549 		    ZC_DEF,NULL,stemp,2,0,0,-1,dummyproc);
37550 	   IANZbox[i].explstr = IANZstr;
37551 	   nvar = 3; if (i <= 2) nvar = i;
37552 	   for (j=0; j<3; j++) {
37553 		fake = 1;
37554 		if (j<nvar) fake = 0;
37555 		sprintf(stemp,"%d",izz(i,j));
37556 		qboxstr(&IZbox[i*4+j],&ZMEwin,0,fake,196,0,0,ZMEconW,ZMEQHIGH,
37557 		     ZC_CONN,NULL,stemp,5,1,0,-1,dummyproc);
37558 		IZbox[i*4+j].explstr = IZstr;
37559 		if (j == 0) {
37560 	   	   sprintf(stemp,zmeblform[ZMEAA],zmptrp->bl[i]);
37561 	   	   qboxstr(&BLbox[i],&ZMEwin,0,fake,196,0,0,ZMEvarW,ZMEQHIGH,
37562 		     ZC_DEF,NULL,stemp,11,2,0,-1,dummyproc);
37563 		   QPcol(&BLbox[i],zmptrp->ibl[i]);
37564 		   BLbox[i].explstr = BLstr;
37565 		}
37566 		else if (j == 1) {
37567 	   	   sprintf(stemp,zmeform[ZMEAA],zmptrp->alph[i]);
37568 	   	   qboxstr(&ALPHbox[i],&ZMEwin,0,fake,196,0,0,ZMEvarW,ZMEQHIGH,
37569 		     ZC_DEF,NULL,stemp,11,2,0,-1,dummyproc);
37570 		   QPcol(&ALPHbox[i],zmptrp->ialph[i]);
37571 		   ALPHbox[i].explstr = ALPHstr;
37572 		}
37573 		else if (j == 2) {
37574 		   zvw = ZMEvarW; zvwn = 11;
37575                    if (ZMEAA) {
37576 			zvw = ZMEvarWs;
37577 			zvwn = 8;
37578 		   }
37579 	   	   sprintf(stemp,zmeform[ZMEAA],zmptrp->bet[i]);
37580 	   	   qboxstr(&BETbox[i],&ZMEwin,0,fake,196,0,0,zvw,ZMEQHIGH,
37581 		     ZC_DEF,NULL,stemp,zvwn,3,0,-1,dummyproc);
37582 		   QPcol(&BETbox[i],zmptrp->ibet[i]);
37583 		   BETbox[i].explstr = BETstr;
37584 		}
37585 	   }
37586 	   fake = 1;
37587 	   if (i > 2) fake = 0;
37588 	   sprintf(stemp,"%d",izz(i,3));
37589 	   qboxstr(&IZbox[i*4+3],&ZMEwin,0,fake,196,0,0,ZMEiz4W,ZMEQHIGH,
37590 	       ZC_CONN,NULL,stemp,1,1,0,-1,dummyproc);
37591    }
37592    if (DEBUG) fprintf(stderr,"SetQZME out\n");
37593 }
37594 
37595 
37596 #if defined(VMS) || defined(UNDERSC)
upzme()37597 void upzme()
37598 #else
37599 #ifdef CRAY
37600 void UPZME()
37601 #else
37602 void upzme_()
37603 #endif
37604 #endif
37605 {
37606 /* for the convenience of fortran */
37607 
37608 
37609   if (!xison) return;
37610 
37611 	SetQZME();
37612 	if (ZME_window_pos >= *zmptrp->nz) ZME_window_pos = 0;
37613 	if (*zmptrp->nz < ZME_window_high) RedrawZME();
37614 	else {
37615 	   UpdateZME();
37616 	   if (ZMEup) RedrawScroll(&zscroll);
37617 	}
37618 }
37619 
GetQZME()37620 void GetQZME()
37621 {
37622    int i,j;
37623    int nvar,found;
37624 
37625    if (DEBUG) fprintf(stderr,"GetQZME in\n");
37626 
37627 /*
37628 Textual zmat to numeric
37629 */
37630 
37631    for (i=0; i<*zmptrp->nz; i++) {
37632 
37633 	   found = 0;
37634 	   for (j=0; j<100; j++) {
37635 		if (strcasecmp(IANZbox[i].str,elements[j]) == 0) {
37636 		    found = 1;
37637 		    zmptrp->ianz[i] = j;
37638 		}
37639 	   }
37640 	   if (strcasecmp(IANZbox[i].str,"XX") == 0) {
37641 		found = 1;
37642 		zmptrp->ianz[i] = 99;
37643 	   }
37644 	   if (!found) {
37645 		ActOnErr(i,0,"ZMAT NOT parsed: Unrecognised Atom Name !");
37646 		return;
37647 	   }
37648 
37649 	   nvar = 3; if (i <= 2) nvar = i;
37650 	   for (j=0; j<nvar; j++) {
37651 
37652 		if (strlen(IZbox[i*4+j].str))
37653 		    sscanf(IZbox[i*4+j].str,"%d",pizz(i,j));
37654 		else {
37655 		    ActOnErr(i,4+j,"ZMAT NOT parsed: Empty string !");
37656 		    return;
37657 		}
37658 
37659 		switch (j) {
37660 		case 0:
37661 
37662 		    if (zmptrp->ibl[i] > 1) {
37663 			zmptrp->bl[i] = zmptrp->bl[zmptrp->ibl[i] - 1];
37664 			strcpy(BLbox[i].str,BLbox[zmptrp->ibl[i] - 1].str);
37665 		    } else {
37666 			if (BLbox[i].changed) {
37667 	   		    if (strlen(BLbox[i].str))
37668 				sscanf(BLbox[i].str,"%lf",&zmptrp->bl[i]);
37669 			    else {
37670 				ActOnErr(i,1,"ZMAT NOT parsed: Empty string !");
37671 				return;
37672 			    }
37673 			    BLbox[i].changed = 0;
37674 			}
37675 		    }
37676 		    break;
37677 		case 1:
37678 
37679 		    if (zmptrp->ialph[i] > 1) {
37680 			zmptrp->alph[i] = zmptrp->alph[zmptrp->ialph[i] - 1];
37681 			strcpy(ALPHbox[i].str,ALPHbox[zmptrp->ialph[i] - 1].str);
37682 		    } else {
37683 			if (ALPHbox[i].changed) {
37684 	   		    if (strlen(ALPHbox[i].str))
37685 				sscanf(ALPHbox[i].str,"%lf",&zmptrp->alph[i]);
37686 			    else {
37687 				ActOnErr(i,2,"ZMAT NOT parsed: Empty string !");
37688 				return;
37689 			    }
37690 			    ALPHbox[i].changed = 0;
37691 			}
37692 		    }
37693 		    break;
37694 		case 2:
37695 		    if (ABS(zmptrp->ibet[i]) > 1) {
37696 			if (zmptrp->ibet[i] > 0) {
37697 			    zmptrp->bet[i] = zmptrp->bet[zmptrp->ibet[i] - 1];
37698 			    strcpy(BETbox[i].str,BETbox[zmptrp->ibet[i] - 1].str);
37699 			} else {
37700 			    zmptrp->bet[i] = -zmptrp->bet[ABS(zmptrp->ibet[i]) - 1];
37701 			    sprintf(stemp,"%f",zmptrp->bet[i]);
37702 			    strcpy(BETbox[i].str,stemp);
37703 			}
37704 		    } else {
37705 			if (BETbox[i].changed) {
37706 	   		    if (strlen(BETbox[i].str))
37707 				sscanf(BETbox[i].str,"%lf",&zmptrp->bet[i]);
37708 			    else {
37709 				ActOnErr(i,3,"ZMAT NOT parsed: Empty string !");
37710 				return;
37711 			    }
37712 			    BETbox[i].changed = 0;
37713 			}
37714 		    }
37715 		    break;
37716 		}
37717 	   }
37718 	   if (i > 2) {
37719 		sscanf(IZbox[i*4+3].str,"%d",pizz(i,3));
37720 	   }
37721    }
37722    if (DEBUG) fprintf(stderr,"GetQZME out\n");
37723 }
37724 
ActOnErr(zline,boxnum,errstr)37725 void ActOnErr(zline,boxnum,errstr)
37726 int zline;
37727 int boxnum;
37728 char *errstr;
37729 {
37730     if (zline >= 0) {
37731 	ZME_window_pos = zline;
37732 	IANZbox[zline].col = ZC_AT1;
37733 	switch(boxnum) {
37734 	case 0: IANZbox[zline].active = 1; break;
37735 	case 1: BLbox[zline].active = 1; break;
37736 	case 2: ALPHbox[zline].active = 1; break;
37737 	case 3: BETbox[zline].active = 1; break;
37738 	case 4: IZbox[zline*4].active = 1; break;
37739 	case 5: IZbox[zline*4+1].active = 1; break;
37740 	case 6: IZbox[zline*4+2].active = 1; break;
37741 	case 7: IZbox[zline*4+3].active = 1; break;
37742 	}
37743 	UpdateZME();
37744 	RedrawScroll(&zscroll);
37745     }
37746 #if !defined(DARWIN)
37747     strcpy(ZMEerr,errstr);
37748 #endif
37749     RedrawStatus();
37750 }
37751 
MapAtom(jxyz)37752 int MapAtom(jxyz)
37753 int jxyz;
37754 {
37755 int j;
37756 
37757     for (j=0; j<*zmptrp->nz; j++) {
37758 	if (jxyz == zmptrp->imap[j]) {
37759 	    return j;
37760 	}
37761     }
37762     return (-1);
37763 
37764 }
37765 
CalcBL(mult,atomnr1,atomnr2)37766 float CalcBL(mult,atomnr1,atomnr2)
37767 int atomnr1;
37768 int atomnr2;
37769 int mult;
37770 {
37771   int iptr1,iptr2;
37772   float BL;
37773 
37774     iptr1 = FindInd(atomnr1,DisAtoms,NUMDIS);
37775     iptr2 = FindInd(atomnr2,DisAtoms,NUMDIS);
37776 
37777     if (iptr1 > -1 && iptr2 > -1) {
37778 	switch (mult) {
37779 	case 0: BL = SingleDis[iptr1][iptr2]; break;
37780 	case 1: BL = DoubleDis[iptr1][iptr2]; break;
37781 	case 2: BL = TripleDis[iptr1][iptr2]; break;
37782 	}
37783 	strcpy(ZMEerr,"Bondlength from literature");
37784     }
37785     else {
37786 	BL = (elmptr->vdwr[atomnr1-1] + elmptr->vdwr[atomnr2-1])*0.98;
37787 	strcpy(ZMEerr,"Bondlength estimated from Van der Waals Radii");
37788     }
37789     return BL;
37790 
37791 }
37792 
FirstLine()37793 void FirstLine()
37794 {
37795 
37796 	*zmptrp->nz = 1;
37797 	xyzp->ianz[0] = zmptrp->ianz[0];
37798 	zmptrp->imap[0] = 1;
37799 	*xyzp->iatoms = 1;
37800 	xyzp->coo[0] = 0.0;
37801 	xyzp->coo[1] = 0.0;
37802 	xyzp->coo[2] = 0.0;
37803 	xyzp->iconn[0] = 0;
37804 	xyzp->iaton[0] = 1;
37805 	scalptr->scali = 3.5;
37806 	scalptr->scal = 2.5*scalptr->scali;
37807 	ZME_window_pos = 0;
37808 #if defined(VMS) || defined(UNDERSC)
37809 	strot(rotptr->rx,rotptr->ry,rotptr->rz);
37810 #else
37811 #ifdef CRAY
37812 	STROT(rotptr->rx,rotptr->ry,rotptr->rz);
37813 #else
37814 	strot_(rotptr->rx,rotptr->ry,rotptr->rz);
37815 #endif
37816 #endif
37817 	update_sel = 1;
37818 }
37819 
GetRes(atomnr,iph,opt,Asel)37820 int GetRes(atomnr,iph,opt,Asel)
37821 int atomnr;
37822 short int *iph;
37823 int opt;
37824 int Asel;
37825 {
37826   int irt,irtt,n,i,ii,nt,nh[3];
37827   short int ipt;
37828 
37829   *iph = 0; irt = NHETRES;
37830 
37831   if (*ipdbon && !*ialtyp) {
37832 
37833 #if defined(VMS) || defined(UNDERSC)
37834 	numhed(&irt,xyzp->iresid);
37835 #else
37836 #ifdef CRAY
37837 	NUMHED(&irt,xyzp->iresid);
37838 #else
37839 	numhed_(&irt,xyzp->iresid);
37840 #endif
37841 #endif
37842 	if (irt != calfptr->ishoh) irt++;
37843 	irt++;
37844 /* one extra incr irt because NUMHED does not see waters in zmat editor
37845   after complte incomplte residues it does however */
37846 	irt = -irt;
37847 
37848 	irtt = xyzp->iresid[Asel];
37849 
37850 	if (irtt > 0) {
37851 
37852 /* attach to residue atom */
37853 
37854 		if (atomnr == 1) {
37855 
37856 		/* attach H to residue atom */
37857 
37858 		   ipt = xyzp->ipdbt[Asel];
37859 		   switch (calfptr->iamino[irtt-1]) {
37860 		   case 3:
37861 		   /* serine */
37862 			switch (ipt) {
37863 			case 1:
37864 			   *iph = 1;
37865 			   irt = irtt;
37866 			   break;
37867 			case 31:
37868 			   *iph = 10;
37869 			   irt = irtt;
37870 			   break;
37871 			}
37872 			break;
37873 		   case 5:
37874 		   /* threonine */
37875 			switch (ipt) {
37876 			case 1:
37877 			   *iph = 1;
37878 			   irt = irtt;
37879 			   break;
37880 			case 31:
37881 			   *iph = 10;
37882 			   irt = irtt;
37883 			   break;
37884 			case 32:
37885 			   *iph = 13;
37886 			   irt = irtt;
37887 			   break;
37888 			}
37889 			break;
37890 		   case 4:
37891 		   /* cysteine */
37892 			switch (ipt) {
37893 			case 1:
37894 			   *iph = 1;
37895 			   irt = irtt;
37896 			   break;
37897 			case 37:
37898 			   *iph = 10;
37899 			   irt = irtt;
37900 			   break;
37901 			}
37902 			break;
37903 		   case 9:
37904 		   /* asparate */
37905 			switch (ipt) {
37906 			case 1:
37907 			   *iph = 1;
37908 			   irt = irtt;
37909 			   break;
37910 			case 29:
37911 			   *iph = 22;
37912 			   irt = irtt;
37913 			   break;
37914 			case 30:
37915 			   *iph = 25;
37916 			   irt = irtt;
37917 			   break;
37918 			}
37919 			break;
37920 		   case 13:
37921 		   /* glutamate */
37922 			switch (ipt) {
37923 			case 1:
37924 			   *iph = 1;
37925 			   irt = irtt;
37926 			   break;
37927 			case 34:
37928 			   *iph = 31;
37929 			   irt = irtt;
37930 			   break;
37931 			case 35:
37932 			   *iph = 34;
37933 			   irt = irtt;
37934 			   break;
37935 			}
37936 			break;
37937 		   case 17:
37938 		   /* histidine */
37939 			switch (ipt) {
37940 			case 1:
37941 			   *iph = 1;
37942 			   irt = irtt;
37943 			   break;
37944 			case 20:
37945 			   *iph = 22;
37946 			   irt = irtt;
37947 			   break;
37948 			case 24:
37949 			   *iph = 34;
37950 			   irt = irtt;
37951 			   break;
37952 			}
37953 			break;
37954 		   case 19:
37955 		   /* tyrosine */
37956 			switch (ipt) {
37957 			case 33:
37958 			   *iph = 52;
37959 			   irt = irtt;
37960 			   break;
37961 			}
37962 			break;
37963 		   default:
37964 			switch (ipt) {
37965 			case 1:
37966 			   *iph = 1;
37967 			   irt = irtt;
37968 			   break;
37969 			}
37970 			break;
37971 		   }
37972 		}
37973 		if (*iph == 1) {
37974 		   for (i=0; i < 3; i++) nh[i] = 0;
37975 		   n = xyzp->iconn[Asel*(MXCON+1)];
37976 		   for (i=0; i < n; i++) {
37977 			ii = xyzp->iconn[Asel*(MXCON+1)+i+1];
37978 			if (ii > 0) {
37979 			    if (xyzp->ianz[ii-1] == 1) {
37980 				nt = (int) xyzp->ipdbt[ii-1];
37981 				if (nt >= 1 && nt <= 3) {
37982 				   nh[nt-1] = 1;
37983 				}
37984 			    }
37985 			}
37986 		   }
37987 		   for (i=0; i < 3; i++) {
37988 			if (nh[i] == 0) {
37989 			   *iph = i+1;
37990 			   break;
37991 			}
37992 		   }
37993 		}
37994 
37995 	} else {
37996 
37997 /* attach to NON residue atom */
37998 
37999 		irt = irtt;
38000 	}
38001 	if (opt) {
38002 	   if (irtt > 0 && irt != irtt) {
38003 
38004 	     if (hetptr.NHetAtm < MXHETA) {
38005 		calfptr->ihet[hetptr.NHetAtm] = 1;
38006 		hetptr.Allocated[hetptr.NHetAtm] = 1;
38007 		hetptr.HetAtm[hetptr.NHetAtm] = (char *) malloc(8);
38008 		sprintf(stemp,"%s.Mod",AAlet[calfptr->iamino[irtt-1]-1]);
38009 		strcpy(hetptr.HetAtm[hetptr.NHetAtm],stemp);
38010 		hetptr.NHetAtm++;
38011 	     }
38012 	   }
38013 	}
38014   }
38015 
38016   return(irt);
38017 }
38018 
AddLine(atomnr,activate,Asel,dist,covang,dihang,multip)38019 void AddLine(atomnr,activate,Asel,dist,covang,dihang,multip)
38020 int atomnr;
38021 int activate;
38022 int *Asel;
38023 float *dist;
38024 float *covang;
38025 float *dihang;
38026 int multip;
38027 {
38028   int i,j,fake,nvar,ioke,irt,irtt,row;
38029   int iptr1,iptr3,izptr;
38030   int hit,nhits;
38031   float angle[2],angtmp,dis,dihtmp;
38032   short int ipt,iph;
38033 
38034 /*
38035   AddLine receives an atom to be connected to 3 atoms defined by asel
38036   and parses new zmat
38037 */
38038 
38039   iph = 0;
38040   ioke =1;
38041   if (*zmptrp->nz >= *zmptrp->mxzat - 1) {
38042 	ioke = 0;
38043 	if (AllocZMat(*xyzp->mxnat,ZERO)) ioke = 1;
38044   }
38045   if (!ioke) return;
38046 
38047   if (!mapchk()) map_prop();
38048 
38049   izptr = *zmptrp->nz;
38050 
38051   if (Asel != NULL) {
38052 	irt = GetRes(atomnr,&iph,1,Asel[0]);
38053   } else {
38054 	irt = NHETRES;
38055   }
38056 
38057   if (iph) {
38058 	int imxt,imnt,ipartt;
38059 
38060 	imxt = zmpart->imx; imnt = zmpart->imn; ipartt = zmpart->ipart;
38061 	FindZRange(irt);
38062 	row = zmpart->imx;
38063 	zmpart->imx = imxt; zmpart->imn = imnt; zmpart->ipart = ipartt;
38064 	InsertEmptyLines(0,row,1,0,0,NULL);
38065 	izptr = row;
38066   }
38067 
38068   if (ZMEup) {
38069 
38070 	qboxstr(&IANZbox[izptr],&ZMEwin,0,0,196,0,0,ZMEanW,ZMEQHIGH,
38071 		    ZC_DEF,NULL,elements[atomnr],2,0,0,-1,dummyproc);
38072 	zmptrp->ianz[izptr] = atomnr;
38073 	if (activate) {
38074 	    IANZbox[izptr].col = ZC_AT1;
38075 	    IANZbox[izptr].active = 1;
38076 	}
38077 
38078 	nvar = 3; if (izptr <= 2) nvar = izptr;
38079 	for (j=0; j<3; j++) {
38080 	    fake = 1;
38081 	    if (j<nvar) fake = 0;
38082 	    qboxstr(&IZbox[izptr*4+j],&ZMEwin,0,fake,196,0,0,
38083 		ZMEconW,ZMEQHIGH,ZC_CONN,NULL,NULL,3,1,0,-1,dummyproc);
38084 	    switch (j) {
38085 	    case 0: qboxstr(&BLbox[izptr],&ZMEwin,0,fake,196,0,0,
38086 			ZMEvarW,ZMEQHIGH,ZC_DEF,NULL,NULL,11,2,0,-1,dummyproc);
38087 		    break;
38088 	    case 1: qboxstr(&ALPHbox[izptr],&ZMEwin,0,fake,196,0,0,
38089 			ZMEvarW,ZMEQHIGH,ZC_DEF,NULL,NULL,11,2,0,-1,dummyproc);
38090 		    break;
38091 	    case 2: qboxstr(&BETbox[izptr],&ZMEwin,0,fake,196,0,0,
38092 			ZMEvarW,ZMEQHIGH,ZC_DEF,NULL,NULL,11,3,0,-1,dummyproc);
38093 		    break;
38094 	    }
38095 	}
38096 	fake = 1;
38097 	if (izptr > 2) fake = 0;
38098 	qboxstr(&IZbox[izptr*4+3],&ZMEwin,0,fake,196,0,0,ZMEiz4W,ZMEQHIGH,
38099 	       ZC_CONN,NULL,"0",1,1,0,-1,dummyproc);
38100 
38101 	if (!nvar) {
38102 	    GetQZME();
38103 	    FirstLine();
38104 	    return;
38105 	}
38106 /*
38107 	connectivity
38108 */
38109 	for (i = 0; i <4; i++) {
38110 	    if (i == 3) {
38111 		sizz(izptr,3,0);
38112 	    } else {
38113 		if (Asel[i] != -1) sizz(izptr,i, Asel[i] + 1);
38114 	    }
38115 	    sprintf(stemp,"%d",izz(izptr,i));
38116 	    strcpy(IZbox[izptr*4+i].str,stemp);
38117 	    IZbox[izptr*4+i].changed = 1;
38118 	}
38119 
38120 /*
38121 	Bondlength
38122 */
38123 	if (dist == NULL) {
38124 	    dis = CalcBL(multip,zmptrp->ianz[izptr],zmptrp->ianz[Asel[0]]);
38125 	} else dis = *dist;
38126 
38127 	sprintf(BLbox[izptr].str,"%f",dis);
38128 	zmptrp->bl[izptr] = (double) dis;
38129 	BLbox[izptr].changed = 1;
38130 
38131 /*
38132 	BondAngle
38133 */
38134 	angtmp = 109.471;
38135 	if (covang == NULL) {
38136 	    if (izz(Asel[1],0)-1 == Asel[0] &&
38137 		izz(Asel[1],1)-1 == Asel[2] && izptr > 2) {
38138 		if (ABS(zmptrp->alph[Asel[1]]-120.0) <=
38139 		    ABS(zmptrp->alph[Asel[1]]-109.471)) angtmp = 120.0;
38140 	    } else {
38141 		for (i=0; i<izptr; i++) {
38142 		    if (izz(i,0)-1 == Asel[0] &&
38143 			izz(i,1)-1 == Asel[1] && izptr > 2) {
38144 			if (ABS(zmptrp->alph[i]-120.0) <=
38145 			   ABS(zmptrp->alph[i]-109.471)) angtmp = 120.0;
38146 		    }
38147 		}
38148 	    }
38149 	    switch (multip) {
38150 	    case 0: break;
38151 	    case 1: angtmp = 120.0; break;
38152 	    case 2: angtmp = 179.0; break;
38153 	    }
38154 	}
38155 	else angtmp = *covang;
38156 
38157 	sprintf(ALPHbox[izptr].str,"%f",angtmp);
38158 	zmptrp->alph[izptr] = (double) angtmp;
38159 	ALPHbox[izptr].changed = 1;
38160 
38161 /*
38162 	DihedralAngle
38163 */
38164 	if (dihang == NULL) {
38165 	    nhits = 0;
38166 	    for (j=0; j<izptr; j++) {
38167 		hit = 1;
38168 		for (i = 0; i <3; i++) {
38169 		    if (izz(izptr,i) != izz(j,i)) {
38170 			hit = 0;
38171 		    }
38172 		}
38173 		if (hit) {
38174 		    if (nhits < 2) angle[nhits] = zmptrp->bet[j];
38175 		    nhits++;
38176 		}
38177 	    }
38178 
38179 	    switch (nhits) {
38180 	    case 0: iptr3 = izz(izptr,2);
38181 		    if (izz(izptr,0) == izz(iptr3,0) &&
38182 			izz(izptr,1) == izz(iptr3,1)) {
38183 			if (angtmp == 120.0) dihtmp = 180.0;
38184 			else dihtmp = 120.0;
38185 		    } else dihtmp = 180.0;
38186 		    break;
38187 	    case 1: angtmp = angle[0]+120.0;
38188 		    if (angtmp >= 360.0) angtmp = angtmp - 360.0;
38189 		    dihtmp = angtmp;
38190 		    break;
38191 	    default:
38192 	    case 2: angtmp = (angle[0] + angle[1])/2 + 180.0;
38193 		    if (angtmp >= 360.0) angtmp = angtmp - 360.0;
38194 		    dihtmp = angtmp;
38195 		    break;
38196 	    }
38197 	}
38198 	else dihtmp = *dihang;
38199 
38200 	sprintf(BETbox[izptr].str,"%f",dihtmp);
38201 	zmptrp->bet[izptr] = (double) dihtmp;
38202 	BETbox[izptr].changed = 1;
38203 
38204         zmptrp->ibl[izptr] = 1;
38205         zmptrp->ialph[izptr] = 1;
38206         zmptrp->ibet[izptr] = 1;
38207         zmptrp->imap[izptr] = izptr+1;
38208 
38209         iptr1 = izptr;
38210 	if (*ialtyp) iptr1 = iptr1 + *iscst;
38211 
38212 	xyzp->ipdbt[iptr1] = iph;
38213 	xyzp->iresid[iptr1] = irt;
38214 	xyzp->ityp[iptr1] = 0;
38215 	xyzp->iaton[iptr1] = 1;
38216 	xyzp->iatclr[iptr1] = 1;
38217 
38218 	(*zmptrp->nz)++;
38219 	update_sel = 1;
38220 	SetQZME();
38221   }
38222 }
38223 
SelZME(asel)38224 int SelZME(asel)
38225 int *asel;
38226 {
38227   int selMap[3];
38228   int i;
38229   float b,a,d;
38230 
38231 /*
38232   SelZME receives an atom to be connected to 3 atoms defined by asel
38233   and parses new zmat
38234 */
38235 
38236   if (ZMEup && ZMEsel) {
38237 	for (i = 0; i <3; i++) {
38238 	    selMap[i] = MapAtom(asel[i]);
38239 	}
38240 
38241 	if (ZMEatom == 99) {
38242 	   b = 1.0; a = 90.0; d = 180.0;
38243 	   AddLine(ZMEatom,1,selMap,&b,&a,&d,ZMEmul);
38244 	} else {
38245 	   AddLine(ZMEatom,1,selMap,NULL,NULL,NULL,ZMEmul);
38246 	}
38247 
38248 	ActBut(&cbut[BDIST],1);
38249 	ActBut(&cbut[BANGLE],1);
38250 	ActBut(&cbut[BDIHED],1);
38251 	ZMEsel = 0;
38252 	ZME_window_pos = *zmptrp->nz-ZME_window_high;
38253 	if (ZME_window_pos < 0) ZME_window_pos = 0;
38254 	RedrawStatus();
38255 	RedrawZME();
38256 	*Sinct = 530;
38257 	return(1);
38258   }
38259   return(0);
38260 }
38261 
GetRow(update)38262 int GetRow(update)
38263 int update;
38264 {
38265     int type,row,column;
38266 
38267     activeZME(&type,&row,&column);
38268     if (type == -1 || row < 0) {
38269 	if (type == -1 && update) {
38270 	    strcpy(ZMEerr,"FRAGMENT NOT ADDED: no atom selected");
38271 	}
38272 	row = -1;
38273 	if (update) RedrawStatus();
38274     }
38275     return row;
38276 }
38277 
AddXH3(atnr,update)38278 void AddXH3(atnr,update)
38279 int atnr;
38280 int update;
38281 {
38282     int row,iptr1,irt,rest;
38283     int selMap[3];
38284     int isfirst;
38285     short int iph;
38286 
38287     isfirst = 0;
38288     if (!*zmptrp->nz) isfirst = 1;
38289 
38290     row = GetRow(1);
38291     if (row == -1) {
38292 	if (isfirst) {
38293            AddLine(1,0,selMap,NULL,NULL,NULL,0);
38294            *zmptrp->nz = 1;
38295 	   row = 0;
38296 	   zmptr.ianz[0] = atnr;
38297 	} else {
38298 	   return;
38299 	}
38300     }
38301 
38302     irt = NHETRES;
38303     rest = zmptrp->imap[row]-1;
38304     if (rest >= 0) irt = GetRes(atnr,&iph,1,rest);
38305 
38306     sizz(1,1,0);
38307     sizz(1,2,0);
38308     sizz(1,3,0);
38309     sizz(2,2,0);
38310     sizz(2,3,0);
38311     zmptrp->alph[1] = 0.0;
38312     zmptrp->bet[1] = 0.0;
38313     zmptrp->bet[2] = 0.0;
38314 
38315     *zmptrp->ihaszm = 1;
38316 
38317     switch(atnr) {
38318     case 6: strcpy(IANZbox[row].str,"C");break;
38319     case 7: strcpy(IANZbox[row].str,"N");break;
38320     }
38321     IANZbox[row].changed = 1;
38322 
38323     iptr1 = row;
38324     if (*ialtyp) iptr1 = iptr1 + *iscst;
38325 
38326     xyzp->ipdbt[iptr1] = 0;
38327     xyzp->ityp[iptr1] = 0;
38328     xyzp->iresid[iptr1] = irt;
38329     xyzp->iatclr[iptr1] = 1;
38330     xyzp->iaton[iptr1] = 1;
38331     update_sel = 1;
38332 
38333     if (*zmptrp->nz >1) {
38334 	sprintf(BLbox[row].str,"%f",
38335 	    CalcBL(0,atnr,zmptrp->ianz[izz(row,0)-1]));
38336 	BLbox[row].changed = 1;
38337     }
38338     if (!isfirst) {
38339 	GetQZME();
38340 	DeActZME();
38341     }
38342 
38343     selMap[0] = row;
38344     if (row == 0) {
38345 	selMap[1] = 1;
38346 	selMap[2] = 2;
38347     } else if (row == 1) {
38348 	selMap[1] = 0;
38349 	selMap[2] = 2;
38350     } else {
38351 	selMap[1] = izz(row,0)-1;
38352 	selMap[2] = izz(row,1)-1;
38353     }
38354     AddLine(1,0,selMap,NULL,NULL,NULL,0);
38355 
38356     selMap[2] = *zmptrp->nz-1;
38357 
38358     switch(atnr) {
38359     case 6:	AddLine(1,0,selMap,NULL,NULL,NULL,0);
38360 	        if (*zmptrp->nz == 3) selMap[2] = *zmptrp->nz-1;
38361     		AddLine(1,1,selMap,NULL,NULL,NULL,0);
38362 		break;
38363     case 7:	AddLine(1,1,selMap,NULL,NULL,NULL,0);
38364 		break;
38365     }
38366 
38367     if (update) {
38368 	ZME_window_pos = *zmptrp->nz-ZME_window_high;
38369 	if (ZME_window_pos < 0) ZME_window_pos = 0;
38370 
38371 	RedrawZME();
38372 	*Sinct = 530;
38373     }
38374 
38375 }
38376 
38377 #if defined(VMS) || defined(UNDERSC)
cnvfrg(fraglen)38378 void cnvfrg(fraglen)
38379 #else
38380 #ifdef CRAY
38381 void CNVFRG(fraglen)
38382 #else
38383 void cnvfrg_(fraglen)
38384 #endif
38385 #endif
38386 int *fraglen;
38387 {
38388     ZLINESTRU *frag;
38389     int frglen;
38390     int i,j,offset;
38391 
38392     frglen = *fraglen;
38393 
38394     frglen = *zmptrp->nz - frglen;
38395     *zmptrp->nz = *zmptrp->nz - frglen;
38396 
38397     if (!frglen) return;
38398 
38399     frag = (ZLINESTRU *) malloc((sizeof *frag)*frglen);
38400 
38401     for (i=0; i < frglen; i++) {
38402 	offset = *zmptrp->nz + i;
38403 	frag[i].ianz = zmptrp->ianz[offset];
38404 	for (j=0; j < 3; j++) {
38405             frag[i].iz[j] = izz(offset,j);
38406 	}
38407 	frag[i].iz[3] = izz(offset,3);
38408 	frag[i].bl = zmptrp->bl[offset];
38409 	frag[i].alph = zmptrp->alph[offset];
38410 	frag[i].bet = zmptrp->bet[offset];
38411     }
38412     AddFrag(frag,frglen,109.471,180.0,-1,1,1,1);
38413 }
38414 
scrfrg(ScrewNotTrans,nfrg)38415 void scrfrg(ScrewNotTrans,nfrg)
38416 int ScrewNotTrans;
38417 int nfrg;
38418 {
38419     ZLINESTRU *frag;
38420     int frglen;
38421     int i,j,offset,offhlp,xprev,xxprev;
38422     int scangle,iscangle;
38423     double *arr;
38424 
38425     if ((arr = (double *) malloc((sizeof *arr)*(*zmptrp->mxzat))) == NULL)
38426 	return;
38427 
38428     for (j=0; j<*zmptrp->nz; j++) {
38429 	if (zmptrp->imap[j] > 0) {
38430 	   arr[j] = xyzp->qat[zmptrp->imap[j]-1];
38431 	} else {
38432 	   arr[j] = 0.0;
38433 	}
38434     }
38435     for (j=0; j<*zmptrp->nz; j++) xyzp->qat[j] = arr[j];
38436 
38437     if (ScrewNotTrans) {
38438 	scangle = 180.0;
38439     } else {
38440 	scangle = 0.0;
38441     }
38442 
38443     frglen = *zmptrp->nz;
38444     *zmptrp->nz = 0;
38445 
38446     if (!frglen) return;
38447 
38448     frag = (ZLINESTRU *) malloc((sizeof *frag)*frglen);
38449 
38450 
38451     for (i=0; i < frglen; i++) {
38452 	offset = *zmptrp->nz + i;
38453 	frag[i].ianz = zmptrp->ianz[offset];
38454 	for (j=0; j < 3; j++) {
38455             frag[i].iz[j] = izz(offset,j);
38456 	}
38457 	frag[i].iz[3] = izz(offset,3);
38458 	frag[i].bl = zmptrp->bl[offset];
38459 	frag[i].alph = zmptrp->alph[offset];
38460 	frag[i].bet = zmptrp->bet[offset];
38461     }
38462     *zmptrp->nz = 0;
38463     CopyFrag(SCREW,2,-1);
38464     CopyFrag(frag,frglen,-1);
38465 
38466     sizz(2,0,2);
38467     sizz(2,1,1);
38468     sizz(2,2,0);
38469     zmptrp->bl[2] = 1.08;
38470     if (!ScrewNotTrans) zmptrp->ibl[2] = 0;
38471     zmptrp->alph[2] = 90.0;
38472     zmptrp->ialph[2] = 0;
38473     zmptrp->bet[2] = 0.0;
38474 
38475     sizz(3,1,2);
38476     sizz(3,2,1);
38477     zmptrp->alph[3] = 120.0;
38478     zmptrp->bet[3] = 120.0;
38479 
38480     sizz(4,2,2);
38481     zmptrp->bet[4] = 120.0;
38482 
38483     for (j=0; j < *zmptrp->nz; j++) xyzp->iatclr[j] = 12;
38484 
38485     xyzp->qat[0] = 0.0;
38486     xyzp->qat[1] = 0.0;
38487     for (j=frglen-1; j >= 0; j--) {
38488 	xyzp->iresid[j+2] = 1;
38489 	xyzp->qat[j+2] = xyzp->qat[j];
38490     }
38491 
38492     xxprev = 1;
38493     xprev = 2;
38494 
38495     for (i=0; i < nfrg; i++) {
38496 
38497 	offset = *zmptrp->nz;
38498 	offhlp = offset;
38499 	*zmptrp->nz = *zmptrp->nz + 1;
38500 	zmptrp->ianz[offset] = 99;
38501 	sizz(offset,0,xprev);
38502 	sizz(offset,1,xprev + 1);
38503 	sizz(offset,2,xxprev);
38504 	zmptrp->bl[offset] = zmptrp->bl[1];
38505 	zmptrp->ibl[offset] = 2;
38506 	zmptrp->alph[offset] = 90.0;
38507 	zmptrp->ialph[offset] = 0;
38508 	zmptrp->bet[offset] = 180.0;
38509 	zmptrp->ibet[offset] = 0;
38510         xyzp->qat[offset] = 0.0;
38511 
38512 	offset++;
38513 
38514 	CopyFrag(frag,frglen,3);
38515 
38516 	sizz(offset,0,offset);
38517 	sizz(offset,1,xprev);
38518 	sizz(offset,2,xprev + 1);
38519 	zmptrp->bl[offset] = zmptrp->bl[2];
38520 	zmptrp->ibl[offset] = 3;
38521 	zmptrp->alph[offset] = 90.0;
38522 	zmptrp->ialph[offset] = 0;
38523 	zmptrp->bet[offset] = scangle;
38524 	if (i == 0) {
38525 	   zmptrp->ibet[offset] = 0;
38526 	   iscangle = offset + 1;
38527 	} else {
38528 	   zmptrp->ibet[offset] = iscangle;
38529 	}
38530 
38531 	offset++;
38532 
38533 	sizz(offset,1,offset - 1);
38534 	sizz(offset,2,xprev);
38535 	zmptrp->alph[offset] = zmptrp->alph[3];
38536 	zmptrp->ialph[offset] = 4;
38537 	zmptrp->bet[offset] = zmptrp->bet[3];
38538 	zmptrp->ibet[offset] = 4;
38539 
38540 	offset++;
38541 	sizz(offset,2,offset - 2);
38542 	zmptrp->bet[offset] = zmptrp->bet[4];
38543 	zmptrp->ibet[offset] = 5;
38544 
38545 	xxprev = xprev;
38546 	xprev = 2 + (1+frglen)*(i+1);
38547 
38548 	for (j=offhlp; j < *zmptrp->nz; j++) xyzp->iatclr[j] = i + 1;
38549 
38550 	for (j=frglen-1; j >= 0 ; j--) {
38551 	   xyzp->iresid[j+offhlp+1] = i+1;
38552 	   xyzp->qat[j+offhlp+1] =arr[j];
38553 	}
38554     }
38555 
38556     for (j=0; j < *zmptrp->nz; j++) xyzp->iaton[j] = 1;
38557     update_sel = 1;
38558 
38559     DeActZME();
38560 
38561     *zmptrp->ihaszm = 1;
38562 
38563     SetQZME();
38564 
38565     ZME_window_pos = 0;
38566 
38567     if (*zmptrp->nz < ZME_window_high) RedrawZME();
38568     else UpdateZME();
38569 
38570 #if defined(VMS) || defined(UNDERSC)
38571     dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
38572     doconn();docent();doclr();qupd();
38573 #else
38574 #ifdef CRAY
38575     DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
38576     DOCONN();DOCENT();doclr();QUPD();
38577 #else
38578     dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
38579     doconn_();docent_();doclr();qupd_();
38580 #endif
38581 #endif
38582 
38583     free(arr);
38584 }
38585 
SetPDBArray(pdbt,frglen,value,offset)38586 void SetPDBArray(pdbt,frglen,value,offset)
38587 int *pdbt;
38588 int frglen;
38589 int value;
38590 int offset;
38591 {
38592     int i,j;
38593 
38594     for (i=0; i<frglen; i++) {
38595 	j = offset+i;
38596 	if (j < *xyzp->mxnat) pdbt[j] = value;
38597     }
38598 }
38599 
CopyPDBTyp(pdbt,fragpdb,frglen,offset)38600 void CopyPDBTyp(pdbt,fragpdb,frglen,offset)
38601 short int *pdbt;
38602 short int *fragpdb;
38603 int frglen;
38604 int offset;
38605 {
38606     int i,j;
38607 
38608     for (i=0; i<frglen; i++) {
38609 	j = offset+i;
38610 	if (j < *xyzp->mxnat) pdbt[j] = fragpdb[i];
38611     }
38612 }
38613 
AddAmino(iamin,addrow,aphi,apsi,omega,chi1,chi2,chi3,chi4,iconf,update,iadd)38614 int AddAmino(iamin,addrow,aphi,apsi,omega,chi1,chi2,chi3,chi4,iconf,update,iadd)
38615 int iamin;
38616 int *addrow;
38617 double aphi;
38618 double apsi;
38619 double *omega;
38620 double *chi1;
38621 double *chi2;
38622 double *chi3;
38623 double *chi4;
38624 int iconf;
38625 int update;
38626 int iadd;
38627 {
38628     int frglen;
38629     int i,isfirst,row,iret;
38630     int co,ca,nn,nz,amiami,sidechainstart;
38631 
38632     nz = *zmptrp->nz;
38633 
38634     iret = 1;
38635     if (nz > *zmptrp->mxzat-28) {
38636 	iret = 0;
38637 	if (AllocZMat(*xyzp->mxnat,ZERO)) iret = 1;
38638     }
38639     if (!iret) {
38640 	if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
38641 	     "No more room to add residues !",0)) { i = 0;}
38642 	return(iret);
38643     }
38644 
38645     amiami = 0;
38646     isfirst = 0;
38647     if (!*zmptrp->nz) isfirst = 1;
38648 
38649 /* Check if O is the right oxygen of the two connected to the C-terminus */
38650 
38651     co = ca = nn = -1;
38652 
38653     if (*addrow == -1) row = GetRow(0);
38654     else row = *addrow;
38655     if (!isfirst && row == -1) row = LastAmino;
38656 
38657     if (isfirst) {
38658 	FirstLine();
38659 	row = 0;
38660 	nz = 1;
38661     } else {
38662 	if (row == -1) {
38663 	    row = GetRow(1); return(iret);
38664 	} else {
38665 	    if (zmptrp->ianz[row] == 8) {
38666 		if (zmptrp->ianz[izz(row,0)-1] == 6) {
38667 		   co = izz(row,0)-1;
38668 		   if (izz(row,2) == row) {
38669 			if (zmptrp->ianz[row-1] == 8) {
38670 			    row--;
38671 			    if (update) {
38672 				DeActZME();
38673 				IANZbox[row].active = 1;
38674 			    }
38675 			}
38676 		   }
38677 		   nn = row;
38678 		   if (zmptrp->ianz[izz(co,0)-1] == 6)
38679 			ca = izz(co,0)-1;
38680 		}
38681 	    }
38682 	}
38683     }
38684     if (ca != -1 && co != -1 && nn != -1) amiami = 1;
38685 
38686     if (!pdb) {
38687 	calfptr->nchain = 1;
38688 	calfptr->ianf[0] = 1;
38689 	pdb = 1;
38690 	*ipdbon = 1;
38691 	hbon = 0;
38692 	ActBut(&cbut[BBACKB],1);
38693 	cbut[BFORC].str = "Res.Comm.";
38694 	cbut[BINCRF].str = "Residue";
38695 	cbut[BDECRF].str = "HetAtm";
38696 	cbut[BUNSC].str = " ";
38697 	cbut[BHBOND].str = " ";
38698 	cbut[BFORC].w = 80;
38699 	cbut[BINCRF].w = 80;
38700 	cbut[BDECRF].w = 80;
38701 	cbut[BUNSC].w = TOGGWH;
38702 	cbut[BHBOND].w = TOGGWH;
38703 	hetptr.NHetAtm = 4;
38704 	hetptr.Allocated[0] = 1;
38705 	hetptr.HetAtm[0] = (char *) malloc(6);
38706 	strcpy(hetptr.HetAtm[0],"Helix");
38707 	hetptr.Allocated[1] = 1;
38708 	hetptr.HetAtm[1] = (char *) malloc(5);
38709 	strcpy(hetptr.HetAtm[1],"Beta");
38710 	hetptr.Allocated[2] = 1;
38711 	hetptr.HetAtm[2] = (char *) malloc(8);
38712 	strcpy(hetptr.HetAtm[2],"RNA/DNA");
38713 	hetptr.Allocated[3] = 1;
38714 	hetptr.HetAtm[3] = (char *) malloc(4);
38715 	strcpy(hetptr.HetAtm[3],"HET");
38716     } else if (!amiami && iadd) {
38717 	calfptr->ianf[calfptr->nchain] = calfptr->ncalf+1;
38718 	calfptr->nchain++;
38719     }
38720     calfptr->issdon = 0;
38721 
38722     calfptr->reson[calfptr->ncalf] = 0;
38723     calfptr->iamino[calfptr->ncalf] = iamin + 1;
38724     calfptr->icalf[calfptr->ncalf][0] = nz+1;
38725     if (isfirst) calfptr->icalf[calfptr->ncalf][1] = 1;
38726     else calfptr->icalf[calfptr->ncalf][1] = nn+1;
38727     calfptr->icalf[calfptr->ncalf][2] = nz+2;
38728     calfptr->icalf[calfptr->ncalf][3] = nz+5;
38729     calfptr->isal[calfptr->ncalf] = iconf;
38730     calfptr->irsnr[calfptr->ncalf] = calfptr->ncalf+1;
38731     if (calfptr->ncalf-1 > 0)
38732 	strcpy(achain[calfptr->ncalf],achain[calfptr->ncalf-1]);
38733     calfptr->ncalf++;
38734     if (iadd) calfptr->islu[calfptr->nchain-1] = calfptr->ncalf;
38735 
38736     frglen = 6;
38737     if (iamin == 14) frglen = 5;
38738     MoveFrag(BACK,AMINO,frglen,0);
38739     CopyPDBTyp(xyzp->ipdbt,BACK_TYP,frglen-1,nz);
38740     if (isfirst) {
38741 	xyzp->ipdbt[0] = 1;
38742 	xyzp->iresid[0] = calfptr->ncalf;
38743 	xyzp->iatclr[0] = 12;
38744     } else {
38745 	xyzp->ipdbt[row] = 1;
38746 	xyzp->iresid[row] = calfptr->ncalf;
38747 	xyzp->iatclr[row] = 12;
38748     }
38749 
38750     MoveFrag(aminozmt[iamin].zmat,AMINO,aminozmt[iamin].zlines,frglen);
38751     CopyPDBTyp(xyzp->ipdbt,aminozmt[iamin].ipdbt,aminozmt[iamin].zlines,
38752 		nz+frglen-1);
38753     frglen = frglen + aminozmt[iamin].zlines;
38754 
38755     if (isfirst) {
38756 	MoveFrag(BACKHS,AMINO,2,frglen);
38757 	CopyPDBTyp(xyzp->ipdbt,BACKHS_TYP,2,nz+frglen-1);
38758 	frglen = frglen + 2;
38759     }
38760     AddFrag(AMINO,frglen,109.471,180.0,row,0,0,0);
38761     SetPDBArray(xyzp->iresid,frglen-1,calfptr->ncalf,nz);
38762     SetPDBArray(xyzp->iatclr,frglen-1,12,nz);
38763 
38764     if (isfirst) {
38765 	zmptrp->bet[nz+2] = apsi;
38766     } else if (amiami) {
38767 	if (iamin != 14) {
38768 	    sizz(nz+4,2,co + 1);
38769 	    zmptrp->bet[nz+4] = 180.0;
38770 	}
38771 	zmptrp->bl[nn] = 1.340;
38772 	zmptrp->alph[nn] = 112.7;
38773 	sizz(nz,1,co + 1);
38774 	sizz(nz,2,ca + 1);
38775 	zmptrp->alph[nz] = 121.0;
38776 	if (omega != NULL) zmptrp->bet[nz] = *omega;
38777 	else zmptrp->bet[nz] = 180.0;
38778 	sizz(nz+1,2,co + 1);
38779 	zmptrp->bet[nz+1] = aphi;
38780 	zmptrp->bet[nz+2] = apsi;
38781     }
38782 
38783     sidechainstart = nz+5;
38784     if (iamin == 14) sidechainstart = nz+4;
38785     if (chi1 != NULL && aminozmt[iamin].chis[0] != -1)
38786 	zmptrp->bet[sidechainstart-1+aminozmt[iamin].chis[0]] = *chi1;
38787     if (chi2 != NULL && aminozmt[iamin].chis[1] != -1)
38788 	zmptrp->bet[sidechainstart-1+aminozmt[iamin].chis[1]] = *chi2;
38789     if (chi3 != NULL && aminozmt[iamin].chis[2] != -1)
38790 	zmptrp->bet[sidechainstart-1+aminozmt[iamin].chis[2]] = *chi3;
38791     if (chi4 != NULL && aminozmt[iamin].chis[3] != -1)
38792 	zmptrp->bet[sidechainstart-1+aminozmt[iamin].chis[3]] = *chi4;
38793 
38794     if (update) {
38795 	SetQZME();
38796 	DeActZME();
38797 	if (isfirst) IANZbox[3].active = 1;
38798 	else IANZbox[nz+2].active = 1;
38799 	if (ZMEAA) {
38800 	   make_aa();
38801 	   ZME_window_pos = calfptr->ncalf-ZME_window_high;
38802 	   if (ZME_window_pos < 0) ZME_window_pos = 0;
38803 	} else {
38804 	   ZME_window_pos = *zmptrp->nz-ZME_window_high;
38805 	   if (ZME_window_pos < 0) ZME_window_pos = 0;
38806 	}
38807 	RedrawZME();
38808 	*Sinct = 530;
38809     }
38810 
38811     *addrow = nz+2;
38812     LastAmino = *addrow;
38813 
38814     return(iret);
38815 
38816 }
38817 
38818 #define ALPHA 0
38819 #define BETA 1
38820 #define TURN 2
38821 
AddSequence(sequence,seq_len,sec_struc)38822 void AddSequence(sequence,seq_len,sec_struc)
38823 int *sequence;
38824 int seq_len;
38825 int sec_struc;
38826 {
38827     int i;
38828     int addrow,update;
38829     double phit;
38830 
38831     addrow = -1;
38832 
38833     for (i=0; i < seq_len; i++) {
38834 	phit = phi_angle;
38835 	update = 0;
38836 	if (i == seq_len - 1) update = 1;
38837 	if (sequence[i] == 14) phit = -70.0;
38838 	if (!AddAmino(sequence[i],&addrow,
38839 	   phit,psi_angle,NULL,NULL,NULL,NULL,NULL,iconform,update,1)) break;
38840         calfptr->reson[calfptr->ncalf-1] = 1;
38841     }
38842 
38843 }
38844 
InsertEmptyLines(ires,row,nlines,seq_len,nprot,iprot)38845 void InsertEmptyLines(ires,row,nlines,seq_len,nprot,iprot)
38846 int ires;
38847 int row;
38848 int nlines;
38849 int seq_len;
38850 int nprot;
38851 int *iprot;
38852 {
38853 /*
38854 ires   = residue
38855 row    = zmat line from which lines will be added/inserted
38856 nlines = number of lines inserted
38857 seq_len = number of amino acids inserted
38858 */
38859 
38860   int i,j,k,l,kcon,prot,ab,noab;
38861 
38862     for (j=*zmptrp->nz-1; j >= row; j--) {
38863 	zmptrp->bl[j+nlines] = zmptrp->bl[j];
38864 	zmptrp->alph[j+nlines] = zmptrp->alph[j];
38865 	zmptrp->bet[j+nlines] = zmptrp->bet[j];
38866 	zmptrp->ianz[j+nlines] = zmptrp->ianz[j];
38867 	zmptrp->imap[j+nlines] = zmptrp->imap[j] + nlines;
38868 	for (k=0; k < 4; k++) {
38869 	   prot = 0;
38870 	   for (l=0; l < nprot; l++) {
38871 		if ((izz(j,k) == iprot[l]) && xyzp->iresid[j] <= 0) prot = 1;
38872 	   }
38873 	   if (izz(j,k) < row+1 || prot)
38874 		sizz(j+nlines,k,izz(j,k));
38875 	   else
38876 		sizz(j+nlines,k,izz(j,k) + nlines);
38877 	}
38878 	if (ABS(zmptrp->ibl[j]) < row+1)
38879 	   zmptrp->ibl[j+nlines] = zmptrp->ibl[j];
38880 	else zmptrp->ibl[j+nlines] = zmptrp->ibl[j]-SIGN(zmptrp->ibl[j]);
38881 
38882 	if (ABS(zmptrp->ialph[j]) < row+1)
38883 	   zmptrp->ialph[j+nlines] = zmptrp->ialph[j];
38884 	else zmptrp->ialph[j+nlines] = zmptrp->ialph[j]-SIGN(zmptrp->ialph[j]);
38885 
38886 	if (ABS(zmptrp->ibet[j]) < row+1)
38887 	   zmptrp->ibet[j+nlines] = zmptrp->ibet[j];
38888 	else zmptrp->ibet[j+nlines] = zmptrp->ibet[j]-SIGN(zmptrp->ibet[j]);
38889     }
38890 
38891     for (j=*xyzp->iatoms-1; j >= row; j--) {
38892 	xyzp->iatclr[j+nlines] = xyzp->iatclr[j];
38893 	if (xyzp->iresid[j] >= ires) {
38894 	   xyzp->iresid[j+nlines] = xyzp->iresid[j] + seq_len;
38895         } else {
38896 	   xyzp->iresid[j+nlines] = xyzp->iresid[j];
38897 	}
38898 	xyzp->iaton[j+nlines] = xyzp->iaton[j];
38899 	xyzp->ianz[j+nlines] = xyzp->ianz[j];
38900 	stocp->ianstc[j+nlines] = xyzp->ianz[j];
38901 	xyzp->ipdbt[j+nlines] = xyzp->ipdbt[j];
38902 	xyzp->ityp[j+nlines] = xyzp->ityp[j];
38903 	if (qdpptr->ihasq) xyzp->qat[j+nlines] = xyzp->qat[j];
38904 	for (k=0; k < 3; k++) {
38905 	   xyzp->coo[(j+nlines)*3+k] = xyzp->coo[j*3+k];
38906 	   stocp->cstoc[(j+nlines)*3+k] = xyzp->coo[j*3+k];
38907 	   stocp->czstoc[(j+nlines)*3+k] = xyzp->coo[j*3+k];
38908 	}
38909 	kcon = 0;
38910 	for (k=0; k < xyzp->iconn[j*(MXCON+1)]; k++) {
38911 	   noab = xyzp->iconn[j*(MXCON+1)+k+1];
38912 	   ab = ABS(noab);
38913 	   prot = 0;
38914 	   for (l=0; l < nprot; l++) {
38915 		if ((ab == iprot[l]) && xyzp->iresid[j] <= 0) prot = 1;
38916 	   }
38917 	   if (ab > row && !prot) {
38918 		if (noab > 0) {
38919 		   xyzp->iconn[(j+nlines)*(MXCON+1)+kcon+1] = noab + nlines;
38920 		} else {
38921 		   xyzp->iconn[(j+nlines)*(MXCON+1)+kcon+1] = noab - nlines;
38922 		}
38923 		kcon++;
38924 	   } else {
38925 		xyzp->iconn[(j+nlines)*(MXCON+1)+kcon+1] = noab;
38926 		kcon++;
38927 	   }
38928 	}
38929 	xyzp->iconn[(j+nlines)*(MXCON+1)] = kcon;
38930     }
38931 
38932 }
38933 
InsertSequence(sequence,seq_len,sec_struc,ires,nprot,iprot)38934 int InsertSequence(sequence,seq_len,sec_struc,ires,nprot,iprot)
38935 int *sequence;
38936 int seq_len;
38937 int sec_struc;
38938 int ires;
38939 int nprot;
38940 int *iprot;
38941 {
38942     int i,j,k,l, nzold, nlines,nlinesn,row,nc,nch,iaf,isl;
38943     int addrow,update;
38944     int ica,in,inn,icop,icap;
38945     double phit;
38946 
38947 
38948 /* ires schuift op, dus insertie voor ires */
38949 
38950     addrow = -1;
38951 
38952     nc = calfptr->ncalf;
38953     nch = 0; iaf = 1; isl = nc;
38954     for (i=0; i < calfptr->nchain; i++) {
38955         if (ires >= calfptr->ianf[i] && ires < calfptr->islu[i]) {
38956 	   nch = i;
38957 	   iaf = calfptr->ianf[i];
38958 	   isl = calfptr->islu[i];
38959 	}
38960     }
38961     if (ires >= calfptr->islu[calfptr->nchain - 1]) {
38962 	nch = calfptr->nchain - 1;
38963 	isl = calfptr->islu[nch];
38964     }
38965     nzold = *zmptrp->nz;
38966 
38967     nlines = 0;
38968     for (i=0; i < seq_len; i++) {
38969 	nlines = nlines + aminozmt[sequence[i]].zlines + 5;
38970 	if (sequence[i] == 14) nlines--;
38971     }
38972 
38973     if (ZMEup) DeActZME();
38974 
38975     if (ires <= nc ) {
38976 	row = calfptr->icalf[ires-1][0] - 1;
38977 	addrow = izz(row,0) - 1;
38978 	zmptrp->ianz[addrow] = 8;
38979     } else {
38980 	row = -1;
38981 	ica = calfptr->icalf[ires-2][0] - 1;
38982 	for (i=ica; i < *zmptrp->nz; i++) {
38983 	    if (xyzp->iresid[i] != ires-1) {
38984 		row = i; break;
38985 	    }
38986 	}
38987 	if (row == -1) row = *zmptrp->nz;
38988 	addrow = ica + 2;
38989     }
38990 
38991     InsertEmptyLines(ires,row,nlines,seq_len,nprot,iprot);
38992 
38993     for (j=calfptr->ncalf-1; j >= 0; j--) {
38994 	for (k=0; k < 4; k++) {
38995 	   if (calfptr->icalf[j][k]-1 >= row)
38996 		calfptr->icalf[j+seq_len][k] = calfptr->icalf[j][k] + nlines;
38997 	}
38998 	if (j >= ires-1) {
38999 	   calfptr->iamino[j+seq_len] = calfptr->iamino[j];
39000 	   calfptr->reson[j+seq_len] = calfptr->reson[j];
39001 	   calfptr->isal[j+seq_len] = calfptr->isal[j];
39002 	   calfptr->irsnr[j+seq_len] = calfptr->irsnr[j]+seq_len;
39003 	   strcpy(achain[j+seq_len],achain[j]);
39004 	}
39005     }
39006 
39007     *zmptrp->nz = row;
39008     calfptr->ncalf = ires - 1;
39009 
39010     update = 0;
39011     for (i=0; i < seq_len; i++) {
39012 	phit = phi_angle;
39013 	if (sequence[i] == 14) phit = -70.0;
39014 	if (!AddAmino(sequence[i],&addrow,
39015 	   phit,psi_angle,NULL,NULL,NULL,NULL,NULL,iconform,update,0)) break;
39016         calfptr->reson[calfptr->ncalf-1] = 1;
39017     }
39018 
39019 /* Connect last of inserted residue to next residue, except when this
39020    was actually an add, insert at last residue, for the benefit of
39021    replace last residue (=del+ins) */
39022 
39023     if (ires-1 != nc) {
39024 
39025 	ica = calfptr->icalf[ires-1+seq_len][0] - 1;
39026 	icap = calfptr->icalf[ires-2+seq_len][0];
39027 	icop = icap + 1;
39028 	in = icap + 2;
39029 	zmptrp->ianz[in-1] = 7;
39030 	xyzp->ipdbt[in-1] = 1;
39031 	xyzp->iresid[in-1] = ires+seq_len;
39032 	calfptr->icalf[ires-1+seq_len][1] = in;
39033 
39034 	inn = izz(ica,0);
39035 
39036 	sizz(ica,0,in);
39037 	sizz(ica,1,icop);
39038 	sizz(ica,2,icap);
39039 
39040 	sizz(ica+1,1,in);
39041 	sizz(ica+1,2,icop);
39042 
39043 	sizz(ica+2,2,in);
39044 
39045 /* The general situation, the forth atom after Calfa is H attached to N */
39046 
39047 	if (zmptrp->ianz[ica+4] == 1 && zmptrp->ianz[ica+3] == 8) {
39048 	   sizz(ica+4,0,in);
39049 	   sizz(ica+4,2,icop);
39050 	}
39051 
39052 /* When res after insert is the last res, the third atom after Calfa in not N but H */
39053 	if (zmptrp->ianz[ica+3] == 1) {
39054 	   sizz(ica+3,0,in);
39055 	   sizz(ica+3,2,icop);
39056 	}
39057 
39058 /* if res after insert is proline, this is not actually a check for proline,
39059    this should deal with the Cbeta, why isnt this picked up later with check for inn ? */
39060 
39061 	if (zmptrp->ianz[ica+3] == 8 && zmptrp->ianz[ica+4] == 6) {
39062 /* regular pro */
39063 	   sizz(ica+4,0,ica+1);
39064 	   sizz(ica+4,2,in);
39065 	} else if (zmptrp->ianz[ica+2] == 8 && zmptrp->ianz[ica+3] == 6) {
39066 /* end pro */
39067 	   sizz(ica+3,0,ica+1);
39068 	   sizz(ica+3,2,in);
39069 	}
39070 
39071 
39072 	xyzp->iatclr[in-1] = xyzp->iatclr[ica];
39073 
39074     }
39075     if (ires == 1) {
39076 	zmptrp->alph[ica] = 121.0;
39077 	zmptrp->bet[ica] = 180.0;
39078 	zmptrp->bet[ica+1] = phi_angle;
39079 	zmptrp->bet[ica+4] = 180.0;
39080     }
39081 
39082 /* search for more lines which where defines with respect to backbone
39083    N of residue ires+1; inn */
39084 
39085 /* and Beware oflast residue */
39086 
39087     if (ires-1 != nc) {
39088       nlinesn = aminozmt[calfptr->iamino[ires-1+seq_len]-1].zlines + 5;
39089       if (calfptr->iamino[ires-1+seq_len]-1 == 14) nlinesn--;
39090 	for (i=ica; i < nzold + nlines; i++) {
39091 	     for (k=0; k < 3; k++) {
39092 	        if (izz(i,k) == inn) sizz(i,k,in);
39093 	     }
39094 	}
39095     }
39096 
39097 
39098     *zmptrp->nz = nzold + nlines;
39099     calfptr->ncalf = nc + seq_len;
39100 
39101     for (i=0; i < calfptr->nchain; i++) {
39102         if (i == nch) {
39103 	   calfptr->islu[i] = isl + seq_len;
39104 	} else {
39105            if (ires <= calfptr->islu[i])
39106 		calfptr->islu[i] = calfptr->islu[i] + seq_len;
39107            if (ires < calfptr->ianf[i])
39108 		calfptr->ianf[i] = calfptr->ianf[i] + seq_len;
39109 	}
39110     }
39111 
39112     calfptr->issdon = 0;
39113     UpdHet2(nlines);
39114 
39115     if (ZMEup) {
39116 	SetQZME();
39117 	DeActZME();
39118 
39119 	if (ZMEAA) {
39120 	   if (ZME_window_pos > calfptr->ncalf-1-ZME_window_high) {
39121 		if (calfptr->ncalf-1-ZME_window_high >= 0) {
39122 		   ZME_window_pos = calfptr->ncalf-ZME_window_high;
39123         	} else ZME_window_pos = 0;
39124 	   }
39125 	} else {
39126 	   if (ZME_window_pos > *zmptrp->nz-1-ZME_window_high) {
39127 		if (*zmptrp->nz-1-ZME_window_high >= 0) {
39128 		   ZME_window_pos = *zmptrp->nz-ZME_window_high;
39129         	} else ZME_window_pos = 0;
39130 	   }
39131 	}
39132 	if (ZME_window_pos < 0) ZME_window_pos = 0;
39133 	if (ZMEAA) make_aa();
39134 	RedrawZME();
39135     }
39136     *Sinct = 530;
39137     update_sel = 1;
39138     return(nlines);
39139 
39140 }
39141 
39142 
39143 #define MXPROTHET 100
ReplaceSequence(sequence,seq_len,sec_struc,ires)39144 void ReplaceSequence(sequence,seq_len,sec_struc,ires)
39145 int *sequence;
39146 int seq_len;
39147 int sec_struc;
39148 int ires;
39149 {
39150    int ica0,ica,ica2,ict1,i,k,l,n,ilst1,ilst2,ilst2am,ilst2nl,ktyp;
39151    int ina, ico,icap;
39152    double ph,ps,omeg,ph2;
39153    int nprot;
39154    int iprot[3];
39155    double bl1[5],alph1[5],bet1[5];
39156    double bl2[3],alph2[3];
39157    double bl3[1],alph3[1];
39158    double refa1[3],refa2[3],refa3[3];
39159    int prothet[MXPROTHET][5],nprothet;
39160    int ndellin,ninslin,nefflin;
39161 
39162 /* ica2 blijkt vrij nutteloos te zijn doch helemaal weg kan hij niet */
39163 
39164    ica0 = calfptr->icalf[ires-1][1] - 1;
39165    ica = calfptr->icalf[ires-1][0] - 1;
39166    ica2 = -1;
39167 
39168    if (ires == 1) {
39169 	ina = calfptr->icalf[ires-1][1] - 1;
39170 	ico = calfptr->icalf[ires-1][2] - 1;
39171    	icap = calfptr->icalf[ires][0] - 1;
39172 	ph2 = zmptrp->bet[icap+1];
39173 	for (i=0; i < 3; i++) {
39174 	   refa1[i] = stocp->czstoc[ina*3+i];
39175 	   refa2[i] = stocp->czstoc[ica*3+i];
39176 	   refa3[i] = stocp->czstoc[ico*3+i];
39177 	}
39178    }
39179 
39180    if (ires >= calfptr->ncalf) {
39181 	for (i=ica; i < *zmptrp->nz; i++) {
39182 	    if (xyzp->iresid[i] != ires) {
39183 		ica2 = i; break;
39184 	    }
39185 	}
39186 	if (ica2 == -1) ica2 = *zmptrp->nz - 1;
39187 
39188    } else {
39189 	ica2 = calfptr->icalf[ires][0] - 1;
39190    }
39191    ilst2am = calfptr->iamino[ires] - 1;
39192    ilst2nl = aminozmt[ilst2am].zlines + 5;
39193    if (ilst2am == 14) ilst2nl--;
39194 
39195    ph = phi_angle;
39196    ps = psi_angle;
39197 
39198    if (seq_len == 1) {
39199 	phi_angle = zmptrp->bet[ica+1];
39200 
39201 /* if list2: psi_angle != zmptrp->bet[ica+2]; */
39202 	psi_angle = zmptrp->bet[ica+2];
39203 
39204 	omeg = zmptrp->bet[ica];
39205 	for (i=0; i < 4; i++) {
39206            bl1[i] = zmptrp->bl[ica+i];
39207            alph1[i] = zmptrp->alph[ica+i];
39208            bet1[i] = zmptrp->bet[ica+i];
39209 	}
39210 	if (zmptrp->ianz[ica+2] == 7) {
39211 	   ilst1 = 0;
39212 	} else if (zmptrp->ianz[ica+2] == 8) {
39213 	   ilst1 = 1;
39214 	}
39215 
39216 /*
39217    check for chain break after to be replaced residue:
39218    then the atom just before Calfa is an N
39219    (mind you zmatlines number 0 - nz-1, atom references in
39220    zmat run from 1 - iatoms, so:
39221 
39222    izz(ica2,0) == ica2 instead of izz(ica2,0) == ica2-1
39223 */
39224 
39225 	ilst2 = 0;
39226 	if (izz(ica2,0) == ica2) {
39227 	   ilst2 = 1;
39228 	   ica2 = ica2 - 1;
39229 	   psi_angle = zmptrp->bet[ica2];
39230 	}
39231 
39232 	for (i=0; i < 3; i++) {
39233            bl2[i] = zmptrp->bl[ica2+i];
39234            alph2[i] = zmptrp->alph[ica2+i];
39235 	}
39236 	bl3[0] = zmptrp->bl[ica0];
39237 	alph3[0] = zmptrp->alph[ica0];
39238    }
39239 
39240 
39241    ict1 = calfptr->icalf[ires-1][0];
39242 
39243    nprot = 3;
39244    iprot[0] = ica+1;
39245    iprot[1] = izz(ica,0);
39246    iprot[2] = ica+2;
39247 
39248    nprothet = 0; ndellin = 0; ninslin = 0;
39249    for (i=ica; i < *zmptrp->nz; i++) {
39250 	ktyp = 0;
39251 	if (xyzp->iresid[i] <= 0) ktyp = 1;
39252 	if ((xyzp->iresid[i] == ires) && (xyzp->ianz[i] == 1) &&
39253 	   (i > ica2) ) ktyp = 2;
39254 	if (ktyp) {
39255 	   for (k=0; k < 5; k++) prothet[nprothet][k] = -1;
39256 	   for (k=0; k < 3; k++) {
39257 		for (l=0; l < nprot; l++) {
39258 		   if (izz(i,k) == iprot[l] && nprothet < MXPROTHET) {
39259 			prothet[nprothet][k+1] = iprot[l];
39260 			prothet[nprothet][0] = i;
39261 			prothet[nprothet][4] = ktyp;
39262 		   }
39263 		}
39264 	   }
39265 	   if (prothet[nprothet][0] != -1) nprothet++;
39266 	}
39267    }
39268 
39269    ndellin = DelAmino(ires);
39270 
39271    if (ires-1 == calfptr->ncalf) {
39272 	calfptr->icalf[ires-1][0] = ict1;
39273    }
39274 
39275    ninslin = InsertSequence(sequence,seq_len,iconform,ires,0,NULL);
39276 
39277    if (seq_len == 1) {
39278 	if (sequence[0] == 14) zmptrp->bet[ica+1] = phi_angle;
39279 	if (ilst2) {
39280 	   zmptrp->bet[ica+2] = psi_angle;
39281 	   zmptrp->bet[ica+3] = bet1[2];
39282 	}
39283 	if (ires == 1) {
39284 	   icap = calfptr->icalf[1][0] - 1;
39285 	   zmptrp->bet[ica+2] = psi_angle;
39286 	   zmptrp->bet[icap+1] = ph2;
39287 	}
39288 	phi_angle = ph;
39289 	psi_angle = ps;
39290 
39291 	n = 4;
39292 
39293 /* if last res replaced (or actually last before chain break)
39294    if replaced by a a proline ica + 3 was H(-N) and then becomes a Cbeta */
39295 /* NOG DOEN: als een PRO vervangen wordt door een PRO dan eigenlijk wel
39296    weer n = 4 */
39297 
39298 	if (ilst1 && sequence[0] == 14) n = 3;
39299 
39300 	for (i=0; i < n; i++) {
39301            zmptrp->bl[ica+i] = bl1[i];
39302            zmptrp->alph[ica+i] = alph1[i];
39303 	}
39304 
39305 /* ilst2 = 1
39306    Als laatste RES voor chainbreak vervangen wordt dan veranderd de volgorde
39307    van:
39308 
39309    Calfa(res)    N    (res)    Coo  (res-1) Calfa(res-1)
39310    Coo  (res)    Calfa(res)    N    (res)   Coo  (res-1)
39311    Ooc  (res)    Coo  (res)    Calfa(res)   N    (res)
39312    .... H or Cbeta (ANY or PRO)
39313 
39314 -> N    (res+1)  Coo  (res)    Calfa(res)   N    (res)
39315    Calfa(res+1)  N    (res+1)  Coo  (res)   Calfa(res)
39316    Coo  (res+1)  Calfa(res+1)  N    (res+1) Coo  (res)
39317 
39318    Naar:
39319 
39320    Calfa(res)    N    (res)    Coo  (res-1) Calfa(res-1)
39321    Coo  (res)    Calfa(res)    N    (res)   Coo  (res-1)
39322 -> N    (res+1)  Coo  (res)    Calfa(res)   N    (res)
39323    Ooc  (res)    Coo  (res)    Calfa(res)   N    (res)
39324    .... H or Cbeta (ANY or PRO)
39325 
39326    Calfa(res+1)  N    (res+1)  Coo  (res)   Calfa(res)
39327    Coo  (res+1)  Calfa(res+1)  N    (res+1) Coo  (res)
39328 
39329 */
39330 
39331 	if (ilst2) {
39332            zmptrp->bl[ica+2] = bl2[0];
39333            zmptrp->alph[ica+2] = alph2[0];
39334            zmptrp->bl[ica+3] = bl1[3];
39335            zmptrp->alph[ica+3] = alph1[3];
39336 	}
39337 	zmptrp->bl[ica0] = bl3[0];
39338 	zmptrp->alph[ica0] = alph3[0];
39339 	zmptrp->bet[ica] = omeg;
39340    }
39341 
39342    nefflin = ninslin - ndellin;
39343 
39344    for (l=0; l < nprothet; l++) {
39345 	i = prothet[l][0];
39346 	for (k=0; k < 3; k++) {
39347 	   if (prothet[l][1+k] != -1) {
39348 		sizz(i+nefflin,k,prothet[l][1+k]);
39349 	   }
39350 	}
39351 	if (prothet[l][4] == 2) xyzp->iresid[i+nefflin] = ires;
39352    }
39353 
39354    if (ires == 1) {
39355 	for (i=0; i < 3; i++) {
39356 	   xyzp->coo[i]   = refa1[i];
39357 	   xyzp->coo[3+i] = refa2[i];
39358 	   xyzp->coo[6+i] = refa3[i];
39359 	}
39360    }
39361 
39362 
39363 }
39364 
prtzmt(ibeg)39365 void prtzmt(ibeg)
39366 int ibeg;
39367 {
39368    int i;
39369 
39370    fprintf(stderr,"Zmatrix\n");
39371    fprintf(stderr,"zmptrp->nz %d\n",*zmptrp->nz);
39372    for (i=ibeg; i < *zmptrp->nz; i++) {
39373 	fprintf(stderr,"zmt %d ianz %d iz0 %d iz1 %d iz2 %d\n",i,zmptrp->ianz[i],izz(i,0),izz(i,1),izz(i,2));
39374 	fprintf(stderr,"atm iresid %d ipdbt %d ityp %d iaton %d \n",xyzp->iresid[i],xyzp->ipdbt[i],xyzp->ityp[i],xyzp->iaton[i]);
39375    }
39376    fprintf(stderr,"Residues\n");
39377    for (i=0; i < calfptr->ncalf; i++) {
39378 	fprintf(stderr,"calf %d iamino %d reson %d isal %d irsnr %d\n",i,calfptr->iamino[i],calfptr->reson[i],calfptr->isal[i],calfptr->irsnr[i]);
39379    }
39380    fprintf(stderr,"Residues icalf\n");
39381    for (i=0; i < calfptr->ncalf; i++) {
39382 	fprintf(stderr,"calf %d icalf0 %d icalf1 %d icalf2 %d\n",i,calfptr->icalf[i][0],calfptr->icalf[i][1],calfptr->icalf[i][2]);
39383    }
39384    fprintf(stderr,"Chains %d\n",calfptr->nchain);
39385    for (i=0; i < calfptr->nchain; i++) {
39386 	fprintf(stderr,"ch ianf %d islu %d\n",calfptr->ianf[i],calfptr->islu[i]);
39387    }
39388 }
39389 
39390 #if defined(VMS) || defined(UNDERSC)
readsq(ami,angs,namin)39391 void readsq(ami,angs,namin)
39392 #else
39393 #ifdef CRAY
39394 void READSQ(ami,angs,namin)
39395 #else
39396 void readsq_(ami,angs,namin)
39397 #endif
39398 #endif
39399 int *ami;
39400 double angs[][7];
39401 int *namin;
39402 {
39403     int i,j;
39404     int addrow,update;
39405     double phit,psit;
39406     double *omchi[5];
39407 
39408 
39409     addrow = -1;
39410 
39411     for (i=0; i < *namin; i++) {
39412 
39413 	phit = -119.0;
39414 	if (ami[i] == 14) phit = -70.0;
39415 	psit = 113.0;
39416         if (angs[i][0] != -1) phit = angs[i][0];
39417         if (angs[i][1] != -1) psit = angs[i][1];
39418 
39419         for (j=0; j < 5; j++) {
39420 	   if (angs[i][2+j] != -1) omchi[j] = &angs[i][2+j];
39421 	   else omchi[j] = NULL;
39422 	}
39423 
39424 	update = 0;
39425 	if (i == (*namin)-1) update = 1;
39426 	if (!AddAmino(ami[i],&addrow,phit,psit,omchi[0],omchi[1],omchi[2],
39427 		omchi[3],omchi[4],iconform,update,1)) break;
39428     }
39429 
39430     NSeq = 0;
39431     UpdateSeqStat();
39432 }
39433 
CopyFrag(frag,frglen,linkoffset)39434 void CopyFrag(frag,frglen,linkoffset)
39435 ZLINESTRU *frag;
39436 int frglen;
39437 int linkoffset;
39438 {
39439     int i,j,offset,variablestatus;
39440 
39441     for (i=0; i < frglen; i++) {
39442 	offset = *zmptrp->nz + i;
39443 	if (linkoffset != -1) {
39444 	   variablestatus = linkoffset + i;
39445 	} else {
39446 	   variablestatus = 1;
39447 	}
39448 	zmptrp->ianz[offset] = frag[i].ianz;
39449 	for (j=0; j < 3; j++) {
39450 	    sizz(offset,j, frag[i].iz[j] + *zmptrp->nz);
39451 	}
39452 	sizz(offset,3,0);
39453 	zmptrp->bl[offset] = frag[i].bl;
39454 	zmptrp->ibl[offset] = variablestatus;
39455 	zmptrp->alph[offset] = frag[i].alph;
39456 	zmptrp->ialph[offset] = variablestatus;
39457 	zmptrp->bet[offset] = frag[i].bet;
39458 	zmptrp->ibet[offset] = variablestatus;
39459     }
39460     *zmptrp->nz = *zmptrp->nz + frglen;
39461 }
39462 
MoveFrag(frag,destiny,frglen,destoff)39463 void MoveFrag(frag,destiny,frglen,destoff)
39464 ZLINESTRU *frag;
39465 ZLINESTRU *destiny;
39466 int frglen;
39467 int destoff;
39468 {
39469     int i,j;
39470 
39471     for (i=0; i < frglen; i++) {
39472 	destiny[destoff+i].ianz = frag[i].ianz;
39473 	for (j=0; j < 3; j++) {
39474 	    destiny[destoff+i].iz[j] = frag[i].iz[j];
39475 	}
39476 	destiny[destoff+i].bl = frag[i].bl;
39477 	destiny[destoff+i].alph = frag[i].alph;
39478 	destiny[destoff+i].bet = frag[i].bet;
39479     }
39480 }
39481 
AddFrag(frag,fraglen,covang,dih,addrow,update,pdbt,doadd)39482 void AddFrag(frag,fraglen,covang,dih,addrow,update,pdbt,doadd)
39483 ZLINESTRU *frag;
39484 int fraglen;
39485 double covang,dih;
39486 int addrow;
39487 int update;
39488 int pdbt;
39489 int doadd;
39490 {
39491     int row,iptr1,irt,rest,atnr;
39492     int offset,i,j,isfirst;
39493     short int iph;
39494 
39495     isfirst = 0;
39496     if (!*zmptrp->nz) isfirst = 1;
39497 
39498     if (DEBUG) {
39499 	fprintf(stderr,"nz %d\n",*zmptrp->nz);
39500 	for (i=0; i < fraglen; i++) {
39501 	    fprintf(stderr,"ianz %d\n",frag[i].ianz);
39502 	    for (j=0; j < 4; j++) {
39503 		fprintf(stderr,"iz[%d] %d\n",j,frag[i].iz[j]);
39504 	    }
39505 	fprintf(stderr,"bl %f\n",frag[i].bl);
39506 	fprintf(stderr,"alph %f\n",frag[i].alph);
39507 	fprintf(stderr,"bet %f\n",frag[i].bet);
39508 	}
39509     }
39510 
39511 
39512     if (addrow == -1) {
39513         row = GetRow(1);
39514         if (row == -1) {
39515 	   if (isfirst) {
39516 		FirstLine();
39517 		row = 0;
39518 		*zmptrp->nz = 1;
39519 	   } else {
39520 		return;
39521 	   }
39522 	}
39523     } else row = addrow;
39524 
39525     atnr = 6;
39526     irt = NHETRES;
39527     rest = zmptrp->imap[row]-1;
39528     if (rest >= 0) irt = GetRes(atnr,&iph,doadd,rest);
39529 
39530     if (*zmptrp->nz >1) {
39531 	zmptrp->ianz[row] = frag[0].ianz;
39532 	zmptrp->bl[row] =
39533 		CalcBL(0,frag[0].ianz,zmptrp->ianz[izz(row,0)-1]);
39534 	if (pdbt) {
39535 
39536 	   iptr1 = row;
39537 	   if (*ialtyp) iptr1 = iptr1 + *iscst;
39538 
39539 	   xyzp->ipdbt[iptr1] = 0;
39540 	   xyzp->ityp[iptr1] = 0;
39541 	   xyzp->iresid[iptr1] = irt;
39542 	   xyzp->iatclr[iptr1] = 1;
39543 	   xyzp->iaton[iptr1] = 1;
39544 	}
39545     }
39546 
39547     if (*zmptrp->nz == 1) {
39548 	row = 0;
39549         zmptrp->ianz[0] = frag[0].ianz;
39550     }
39551 
39552     for (i=1; i < fraglen; i++) {
39553 	offset = *zmptrp->nz + i - 1;
39554 	zmptrp->ianz[offset] = frag[i].ianz;
39555 	for (j=0; j < 3; j++) {
39556 	    if (frag[i].iz[j] == 1) {
39557 		sizz(offset,j, row + 1);
39558 	    } else {
39559 		sizz(offset,j, frag[i].iz[j] + *zmptrp->nz - 1);
39560 	    }
39561 	}
39562 	sizz(offset,3, frag[i].iz[3]);
39563 	zmptrp->bl[offset] = frag[i].bl;
39564 	zmptrp->ibl[offset] = 1;
39565 	zmptrp->alph[offset] = frag[i].alph;
39566 	zmptrp->ialph[offset] = 1;
39567 	zmptrp->bet[offset] = frag[i].bet;
39568 	zmptrp->ibet[offset] = 1;
39569 	zmptrp->imap[offset] = offset+1;
39570 	xyzp->iatclr[offset] = 12;
39571 	if (pdbt) {
39572 
39573 	    iptr1 = offset;
39574 	    if (*ialtyp) iptr1 = iptr1 + *iscst;
39575 
39576 	    xyzp->ipdbt[iptr1] = 0;
39577 	    xyzp->iresid[iptr1] = irt;
39578 	    xyzp->iatclr[iptr1] = 1;
39579 	    xyzp->ityp[iptr1] = 0;
39580 	    xyzp->iaton[iptr1] = 1;
39581 	}
39582     }
39583 
39584 
39585     sizz(1,1,0);
39586     sizz(1,2,0);
39587     sizz(1,3,0);
39588     sizz(2,2,0);
39589     sizz(2,3,0);
39590     zmptrp->alph[1] = 0.0;
39591     zmptrp->bet[1] = 0.0;
39592     zmptrp->bet[2] = 0.0;
39593 
39594     if (*zmptrp->nz > 1) {
39595 	offset = *zmptrp->nz;
39596 	if (row == 0) {
39597 	    sizz(offset,1,2);
39598 	    sizz(offset,2,3);
39599 	} else if (row == 1) {
39600 	    sizz(offset,1,1);
39601 	    sizz(offset,2,3);
39602 	} else {
39603 	    sizz(offset,1,izz(row,0));
39604 	    sizz(offset,2,izz(row,1));
39605 	}
39606 	zmptrp->alph[offset] = covang;
39607 	zmptrp->bet[offset] = dih;
39608 	offset++;
39609 	if (row == 0) {
39610 	    sizz(offset,2,2);
39611 	} else if (row == 1) {
39612 	    sizz(offset,2,1);
39613 	} else {
39614 	    sizz(offset,2,izz(row,0));
39615 	}
39616 	if (frag == cyclopentane) {
39617 	   zmptrp->bet[offset] = 200.0;
39618 	} else {
39619 	   zmptrp->bet[offset] = 180.0;
39620 	}
39621     }
39622 
39623     update_sel = 1;
39624     if (update) DeActZME();
39625 
39626     *zmptrp->nz = *zmptrp->nz + fraglen - 1;
39627 
39628     *zmptrp->ihaszm = 1;
39629 
39630     if (update) {
39631 
39632 	SetQZME();
39633 
39634 	ZME_window_pos = *zmptrp->nz-ZME_window_high;
39635 	if (ZME_window_pos < 0) ZME_window_pos = 0;
39636 
39637 	if (*zmptrp->nz < ZME_window_high) RedrawZME();
39638 	else UpdateZME();
39639 
39640 	*Sinct = 530;
39641     }
39642 }
39643 
AddCycloHexane()39644 void AddCycloHexane() {
39645 
39646     AddXH3(6,0);
39647     (*zmptrp->nz)--;
39648     DeActZME();
39649     IANZbox[*zmptrp->nz-2].active = 1;
39650     AddXH3(6,0);
39651     DeActZME();
39652     IANZbox[*zmptrp->nz-3].active = 1;
39653     AddXH3(6,0);
39654     strcpy(BETbox[*zmptrp->nz-3].str,"60.0");
39655     BETbox[*zmptrp->nz-3].changed = 1;
39656     GetQZME();
39657     DeActZME();
39658     IANZbox[*zmptrp->nz-3].active = 1;
39659     AddXH3(6,0);
39660     strcpy(BETbox[*zmptrp->nz-3].str,"300.0");
39661     BETbox[*zmptrp->nz-3].changed = 1;
39662     DeActZME();
39663     GetQZME();
39664     IANZbox[*zmptrp->nz-3].active = 1;
39665     AddXH3(6,0);
39666     strcpy(BETbox[*zmptrp->nz-3].str,"60.0");
39667     BETbox[*zmptrp->nz-3].changed = 1;
39668     GetQZME();
39669     DeActZME();
39670     IANZbox[*zmptrp->nz-3].active = 1;
39671     AddXH3(6,0);
39672     strcpy(BETbox[*zmptrp->nz-3].str,"60.0");
39673     BETbox[*zmptrp->nz-3].changed = 1;
39674     DeActZME();
39675     GetQZME();
39676     (*zmptrp->nz)--;
39677 
39678     ZME_window_pos = *zmptrp->nz-ZME_window_high;
39679     if (ZME_window_pos < 0) ZME_window_pos = 0;
39680 
39681     RedrawZME();
39682     *Sinct = 530;
39683 
39684 }
39685 
ScreenZME(cursorx,cursory)39686 int ScreenZME(cursorx,cursory)
39687 int cursorx;
39688 int cursory;
39689 {
39690  int i,j,k,n,ires;
39691 
39692 /*
39693 
39694   ScreenZME light up atom closest to cursor, and light up corresponding
39695   atom in the zmatrix-editor
39696 
39697 */
39698 
39699 
39700  if (ZMEup) {
39701 
39702 	i = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,*xyzp->iatoms,
39703 			cursorx,cursory,MINDIFF);
39704 
39705 	if (i >= 0) {
39706     		update_sel = 1;
39707 		for (j=0; j<*zmptrp->nz; j++) {
39708 			if (i == zmptrp->imap[j]-1) {
39709 				for (k=0; k<*xyzp->iatoms; k++)
39710 				   if (xyzp->iaton[k] >= 1) xyzp->iaton[k] = 1;
39711 				DeActZME();
39712 				xyzp->iaton[i] = 3;
39713                                 if (ZMEAA) {
39714 				   ires = xyzp->iresid[i] - 1;
39715 				   CurAmino = ires;
39716 				   if (ires < 0) return(0);
39717 				   ZME_window_pos =  ires;
39718 				} else {
39719 				   n = j/ZME_window_high;
39720 				   ZME_window_pos =  n*ZME_window_high;
39721 				   IANZbox[j].col = ZC_AT1;
39722 				   IANZbox[j].active = 1;
39723 				}
39724 				UpdateZME();
39725 				sprintf(ZMEerr, "Line %d Atom %d",i+1,zmptrp->imap[i]);
39726 				RedrawStatus();
39727 				RedrawScroll(&zscroll);
39728 				return(1);
39729 			}
39730 		}
39731 	}
39732  }
39733  return(0);
39734 }
39735 
ScreenPDB(cursorx,cursory)39736 int ScreenPDB(cursorx,cursory)
39737 int cursorx;
39738 int cursory;
39739 {
39740  int iat,ires;
39741 
39742 /*
39743 
39744   ScreenPDB light up atom closest to cursor, set CurAmino for later use in AmiCom
39745 
39746 */
39747 
39748    iat = -1; ires = -1;
39749 
39750    if (has_opengl) {
39751 	if (*ipdbon) {
39752 	   if (*fancy || *fullgl) {
39753                 iat = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
39754 			*xyzp->iatoms,cursorx,cursory,MINDIFF);
39755 	   } else {
39756                 iat = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
39757 			*xyzp->iatoms,cursorx,cursory,MINDIFF);
39758                 if (iat < 0) ires = FindCaP(cursorx,cursory,MINDIFF);
39759 	   }
39760 	}
39761    } else {
39762 	if (*ipdbon) {
39763            iat = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
39764 			*xyzp->iatoms,cursorx,cursory,MINDIFF);
39765 	   if (iat < 0) ires = FindCaP(cursorx,cursory,MINDIFF);
39766 	}
39767    }
39768 
39769    if ((iat >= 0 || ires >= 0) && *ipdbon) {
39770 	if (iat >= 0) {
39771 	   CurAmino = xyzp->iresid[iat] - 1;
39772 	} else if (ires >= 0) {
39773 	   CurAmino = ires;
39774 	}
39775 	return(1);
39776    }
39777 
39778    return(0);
39779 }
39780 
map_prop()39781 void map_prop()
39782 {
39783   int j,k;
39784   int *iarr;
39785   int *imarr;
39786 
39787 
39788 /*
39789  Dont do property mapping when doing interactive docking
39790 */
39791   if (*ialtyp == 1) return;
39792   if (!*zmptrp->ihaszm) return;
39793 
39794   if (qdpptr->ihasq) maparr(NULL,xyzp->qat,NULL,NULL,1);
39795   maparr(NULL,NULL,NULL,xyzp->ityp,3);
39796   maparr(NULL,NULL,NULL,xyzp->ipdbt,3);
39797   maparr(NULL,NULL,xyzp->iatclr,NULL,2);
39798   maparr(NULL,NULL,xyzp->iresid,NULL,2);
39799 
39800   if ((iarr = (int *) malloc((sizeof j)*(*zmptrp->mxzat))) != NULL) {
39801     if ((imarr = (int *) malloc((sizeof j)*(*zmptrp->mxzat))) != NULL) {
39802 	rearrz(iarr);
39803 	for (k=0; k<6; k++) {
39804 	   for (j=0; j<calfptr->ncalf; j++)
39805 		imarr[j] = calfptr->icalf[j][k];
39806 
39807 	   for (j=0; j<calfptr->ncalf; j++) {
39808 		if (imarr[j]-1 >= 0)
39809 		   calfptr->icalf[j][k] = iarr[imarr[j]-1]+1;
39810 	   }
39811 	}
39812 	free(imarr);
39813 
39814      }
39815      free(iarr);
39816   }
39817 }
39818 
DelLine(row,nlines,nprot,iprot)39819 void DelLine(row,nlines,nprot,iprot)
39820 int row;
39821 int nlines;
39822 int nprot;
39823 int *iprot;
39824 {
39825   int j,k,l,rowmap,prot,kcon,noab,ab;
39826 
39827    if (ZMEup) DeActZME();
39828    rowmap = zmptrp->imap[row];
39829 
39830    map_prop();
39831 
39832    for (j=row; j < *zmptrp->nz-nlines; j++) {
39833 	zmptrp->bl[j] = zmptrp->bl[j+nlines];
39834 	zmptrp->alph[j] = zmptrp->alph[j+nlines];
39835 	zmptrp->bet[j] = zmptrp->bet[j+nlines];
39836 	zmptrp->ianz[j] = zmptrp->ianz[j+nlines];
39837 	for (k=0; k < 4; k++) {
39838 	   prot = 0;
39839 	   for (l=0; l < nprot; l++) {
39840 		if ((izz(j+nlines,k) == iprot[l]) && xyzp->iresid[j+nlines] <= 0) prot = 1;
39841 	   }
39842 	   if ((izz(j+nlines,k) < row+1) || prot)
39843 		sizz(j,k,izz(j+nlines,k));
39844 	   else sizz(j,k,izz(j+nlines,k)-nlines);
39845 	}
39846 	if (ABS(zmptrp->ibl[j+nlines]) < row+1)
39847 	   zmptrp->ibl[j] = zmptrp->ibl[j+nlines];
39848 	else zmptrp->ibl[j] = zmptrp->ibl[j+nlines]-SIGN(zmptrp->ibl[j+nlines]);
39849 
39850 	if (ABS(zmptrp->ialph[j+nlines]) < row+1)
39851 	   zmptrp->ialph[j] = zmptrp->ialph[j+nlines];
39852 	else zmptrp->ialph[j] = zmptrp->ialph[j+nlines]-SIGN(zmptrp->ialph[j+nlines]);
39853 
39854 	if (ABS(zmptrp->ibet[j+nlines]) < row+1)
39855 	   zmptrp->ibet[j] = zmptrp->ibet[j+nlines];
39856 	else zmptrp->ibet[j] = zmptrp->ibet[j+nlines]-SIGN(zmptrp->ibet[j+nlines]);
39857 
39858 	xyzp->iatclr[j]  = xyzp->iatclr[j+nlines];
39859 	xyzp->iresid[j]  = xyzp->iresid[j+nlines];
39860 	xyzp->iaton[j]   = xyzp->iaton[j+nlines];
39861 	xyzp->ianz[j]    = xyzp->ianz[j+nlines];
39862 	stocp->ianstc[j] = xyzp->ianz[j+nlines];
39863 	xyzp->ipdbt[j]   = xyzp->ipdbt[j+nlines];
39864 	xyzp->ityp[j]    = xyzp->ityp[j+nlines];
39865 	if (qdpptr->ihasq) xyzp->qat[j] = xyzp->qat[j+nlines];
39866 	for (k=0; k < 3; k++) {
39867 	   xyzp->coo[j*3+k] = xyzp->coo[(j+nlines)*3+k];
39868 	   stocp->cstoc[j*3+k] = xyzp->coo[(j+nlines)*3+k];
39869 	   stocp->czstoc[j*3+k] = xyzp->coo[(j+nlines)*3+k];
39870 	}
39871 	kcon = 0;
39872 	for (k=0; k < xyzp->iconn[(j+nlines)*(MXCON+1)]; k++) {
39873 	   noab = xyzp->iconn[(j+nlines)*(MXCON+1)+k+1];
39874 	   ab = ABS(noab);
39875 	   prot = 0;
39876 	   for (l=0; l < nprot; l++) {
39877 		if ((ab == iprot[l]) && xyzp->iresid[j+nlines] <= 0) prot = 1;
39878 	   }
39879 	   if (ab > row && !prot) {
39880 		if (noab > 0) {
39881 		   xyzp->iconn[j*(MXCON+1)+kcon+1] = noab - nlines;
39882 		} else {
39883 		   xyzp->iconn[j*(MXCON+1)+kcon+1] = noab + nlines;
39884 		}
39885 		kcon++;
39886 	   } else {
39887 		xyzp->iconn[j*(MXCON+1)+kcon+1] = noab;
39888 		kcon++;
39889 	   }
39890 	}
39891 	xyzp->iconn[j*(MXCON+1)] = kcon;
39892 
39893    }
39894 
39895    for (j=0; j < *zmptrp->nz; j++) {
39896 	zmptrp->imap[j] = j + 1;
39897    }
39898 
39899 
39900    for (j=0; j < calfptr->ncalf; j++) {
39901 	for (k=0; k < 4; k++)
39902 	   if (calfptr->icalf[j][k] >= row)
39903 		calfptr->icalf[j][k] = calfptr->icalf[j][k] - nlines;
39904    }
39905 
39906    *zmptrp->nz = *zmptrp->nz - nlines;
39907    update_sel = 1;
39908 }
39909 
CheckCOO(ires)39910 int CheckCOO(ires)
39911 int ires;
39912 {
39913    int i,ica,icnt,iresult;
39914 
39915    ica = calfptr->icalf[ires-1][0] - 1;
39916    icnt = 0; iresult = 0;
39917 
39918 /* Coo is always the next line after Calfa */
39919 
39920    for (i=0; i < xyzp->iconn[(ica+1)*(MXCON+1)]; i++)
39921 	if (xyzp->ianz[xyzp->iconn[(ica+1)*(MXCON+1)+1+i]-1] == 8) icnt++;
39922    if (icnt == 2) iresult = 1;
39923 
39924    return(iresult);
39925 
39926 }
39927 
CheckNH3(ires,icnn1,icnn2)39928 int CheckNH3(ires,icnn1,icnn2)
39929 int ires;
39930 int *icnn1;
39931 int *icnn2;
39932 {
39933    int i,k,ica,in,icnt,iatje;
39934 
39935    ica = calfptr->icalf[ires-1][0] - 1;
39936    in = izz(ica,0) - 1;
39937    icnt = 0;
39938    for (i=0; i < xyzp->iconn[in*(MXCON+1)]; i++)
39939 	iatje = xyzp->iconn[in*(MXCON+1)+1+i]-1;
39940 	if (xyzp->ianz[iatje] == 1) {
39941 	   icnt++;
39942 	   if (icnt == 2) {
39943 		icnn1[0] = iatje;
39944 		for (k=0; k<3; k++) {
39945 		   icnn1[k+1] = izz(iatje,k);
39946 		}
39947 	   }
39948 	   if (icnt == 3) {
39949 		icnn2[0] = iatje;
39950 		for (k=0; k<3; k++) {
39951 		   icnn2[k+1] = izz(iatje,k);
39952 		}
39953 	   }
39954 	}
39955    icnt--;
39956 
39957    return(icnt);
39958 
39959 }
39960 
DelAmino(ires)39961 int DelAmino(ires)
39962 int ires;
39963 {
39964    int i,j,k,n,ica,ican,nlines,in,inn,icap,icop,iaminn,nlinesn;
39965    int iend,ibeg,nprot,isrend,isnh3;
39966    int iprot[3];
39967    int icnn1[4],icnn2[4];
39968 
39969    ica = calfptr->icalf[ires-1][0] - 1;
39970 
39971    iend = 0; ibeg = 0;
39972 
39973    for (i=0; i < calfptr->nchain; i++) {
39974 	if (ires == calfptr->islu[i]) iend = i + 1;
39975 	if (ires == calfptr->ianf[i]) ibeg = i + 1;
39976    }
39977 
39978    isrend = CheckCOO(ires);
39979    isnh3 = CheckNH3(ires,icnn1,icnn2);
39980 
39981    if (iend && isrend) {
39982 	iaminn = calfptr->iamino[ires-1] - 1;
39983 	nlines = aminozmt[iaminn].zlines + 5;
39984 	if (iaminn == 14) nlines--;
39985 	nlinesn = 0;
39986    } else {
39987 	if (iend == calfptr->nchain) {
39988 	   nlines = *zmptrp->nz - ica;
39989 	   for (i=ica; i < *zmptrp->nz; i++) {
39990 		if (xyzp->iresid[i] != ires) {
39991 		   nlines = i - ica; break;
39992 		}
39993 	   }
39994 	   nlinesn = 0;
39995 	} else {
39996 	   ican = calfptr->icalf[ires][0] - 1;
39997 	   nlines = ican - ica;
39998 	   iaminn = calfptr->iamino[ires] - 1;
39999 	   nlinesn = aminozmt[iaminn].zlines + 5;
40000 	   if (iaminn == 14) nlinesn--;
40001 	}
40002    }
40003 
40004 
40005    in = izz(ica,0);
40006    icop = izz(ica,1);
40007    icap = izz(ica,2);
40008 
40009    nprot = 3;
40010    iprot[0] = ica+1;
40011    iprot[1] = izz(ica,0);
40012    iprot[2] = ica+2;
40013    nprot = 0;
40014 
40015    DelLine(ica,nlines,0,NULL);
40016 
40017    inn = izz(ica,0);
40018    n = 0;
40019 
40020    if (! (iend && (isrend || iend == calfptr->nchain)) ) {
40021 	sizz(ica,0,in);
40022 	sizz(ica,1,icop);
40023 	sizz(ica,2,icap);
40024 
40025 	sizz(ica+1,1,in);
40026 	sizz(ica+1,2,icop);
40027 
40028 	n = 5;
40029 
40030 	if (zmptrp->ianz[ica+2] == 7) {
40031 
40032 	   sizz(ica+2,2,in);
40033 	   sizz(ica+4,0,in);
40034 	   sizz(ica+4,2,icop);
40035 
40036 	} else {
40037 
40038 	   if (zmptrp->ianz[ica+2] == 8) {
40039 
40040 		if (zmptrp->ianz[ica+3] == 1) {
40041 		   sizz(ica+3,0,in);
40042 		   sizz(ica+3,2,icop);
40043 		   n = 4;
40044 		}
40045 		if (zmptrp->ianz[ica+3] == 8) {
40046 		   sizz(ica+2,2,in);
40047 		   sizz(ica+4,0,in);
40048 		   sizz(ica+4,2,icop);
40049 		   n = 5;
40050 		}
40051 
40052 	   }
40053 	}
40054    }
40055 
40056    if (ibeg) sizz(ica+4,2,ica + 2);
40057 
40058    if (iend && (isrend || iend == calfptr->nchain) ) {
40059 
40060 /*
40061    if this was the last residue, change the N to OXT
40062    BUT what if it was the last of this chain, and it goes on
40063    with an other chain. Then you have lost the N which belonged to
40064    the next residue !!!. You now have the first residue of a new chain
40065    WITHOUT an N
40066 */
40067 	zmptrp->ianz[in-1] = 8;
40068 	xyzp->iresid[in-1] = xyzp->iresid[in-1] - 1;
40069 	xyzp->ipdbt[in-1] = 38;
40070    } else {
40071 	xyzp->iatclr[in-1] = xyzp->iatclr[ica];
40072    }
40073 
40074 /* search for more lines which where defines with respect to backbone
40075    N of residue ires+1; inn */
40076 
40077    if (! (iend && (isrend || iend == calfptr->nchain)) ) {
40078 	for (i=ica+n; i < *zmptrp->nz; i++) {
40079 	   for (k=0; k < 3; k++)
40080 		if (izz(i,k) == inn) sizz(i,k,in);
40081 	}
40082 /*
40083    In case of res after the deleted one is after a chain break, the N has
40084    three H's attached to it. Two of them are not located in the amino part of
40085    the zmatrix, but rather much further down. The have to be connected to
40086    the right atom again.
40087    DUBBEL OP zie boven !!!, alleen als grenzen i=ica; i < ica+nlinesn
40088    voegt dit iets toe
40089 */
40090 	for (i=ica+nlinesn; i < *zmptrp->nz; i++) {
40091 	   if (izz(i,0) == inn) sizz(i,0,in);
40092 	}
40093    }
40094 
40095    for (i=0; i < *zmptrp->nz; i++) {
40096 	if (xyzp->iresid[i] > ires)
40097 	   xyzp->iresid[i] = xyzp->iresid[i] - 1;
40098    }
40099 
40100    for (j=ires-1; j < calfptr->ncalf; j++) {
40101 	for (k=0; k < 4; k++)
40102 		calfptr->icalf[j][k] = calfptr->icalf[j+1][k];
40103 	calfptr->iamino[j] = calfptr->iamino[j+1];
40104 	calfptr->reson[j] = calfptr->reson[j+1];
40105 	calfptr->irsnr[j] = calfptr->irsnr[j+1] - 1;
40106 	calfptr->isal[j] = calfptr->isal[j+1];
40107 	strcpy(achain[j],achain[j+1]);
40108    }
40109 
40110    calfptr->ncalf = calfptr->ncalf - 1;
40111    calfptr->issdon = 0;
40112 
40113    for (i=0; i < calfptr->nchain; i++) {
40114 	if (ires <= calfptr->islu[i]) calfptr->islu[i] = calfptr->islu[i] - 1;
40115 	if (ires < calfptr->ianf[i]) calfptr->ianf[i] = calfptr->ianf[i] - 1;
40116    }
40117 
40118    UpdHet2(-nlines);
40119    if (ZMEup) {
40120       if (ZME_window_pos >= *zmptrp->nz-1) ZME_window_pos = 0;
40121       SetQZME(); RedrawZME();
40122    }
40123 
40124    return(nlines);
40125 }
40126 
FindZRange(ires)40127 void FindZRange(ires)
40128 int ires;
40129 {
40130    int ica,ica2,i;
40131 
40132    ica = calfptr->icalf[ires-1][0] - 1;
40133    ica2 = calfptr->icalf[ires][0] - 1;
40134 
40135    zmpart->imx = -1;
40136    for (i=ica; i < *zmptrp->nz; i++) {
40137         if (xyzp->iresid[i] != ires) {
40138             zmpart->imx = i; break;
40139         }
40140    }
40141    zmpart->imn = ica + 1;
40142    /*
40143    zmpart->imn = ica;
40144    */
40145    if (zmpart->imx == -1) zmpart->imx = *zmptrp->nz;
40146    else zmpart->imx++;
40147 
40148    if (ires <= calfptr->ncalf-1) zmpart->imx = ica2;
40149 
40150    if (zmpart->imx > zmpart->imn) zmpart->ipart = 2;
40151 }
40152 
FindZRangeFromBox(isel)40153 void FindZRangeFromBox(isel)
40154 int isel;
40155 {
40156    int ica,ires,iamino,sidechainstart,i;
40157 
40158    if (!*ipdbon || *ialtyp) return;
40159 /*
40160  Dont do partial zmatrix update when doing interactive docking
40161 */
40162 
40163    ires = xyzp->iresid[isel];
40164 
40165    if (ires < 0) {
40166 	zmpart->imn = isel + 1;
40167 	zmpart->imx = *zmptrp->nz;
40168 
40169 	if (zmpart->imx > zmpart->imn) zmpart->ipart = 1;
40170 	return;
40171    }
40172 
40173    iamino = calfptr->iamino[ires-1];
40174 
40175    if (!(iamino > 0 && iamino <= 23)) return;
40176 
40177    ica = calfptr->icalf[ires-1][0] - 1;
40178 
40179    sidechainstart = ica+5;
40180 
40181    if (iamino == 15) {
40182 	sidechainstart = ica+4;
40183 	if (zmptrp->ianz[ica+2] == 8) {
40184 		sidechainstart--;
40185 	}
40186    } else {
40187 /* if start residue there might be an N missing at nz+2 */
40188 
40189 	if (zmptrp->ianz[ica+4] != 1 && zmptrp->ianz[ica+3] == 1)
40190 		sidechainstart--;
40191    }
40192 
40193 /*
40194    if (isel < sidechainstart) return;
40195 */
40196    if (isel < sidechainstart) sidechainstart = isel;
40197 
40198    for (i=sidechainstart; i < *zmptrp->nz; i++) {
40199         if (xyzp->iresid[i] != ires) {
40200             zmpart->imx = i; break;
40201         }
40202    }
40203    zmpart->imn = sidechainstart + 1;
40204    zmpart->imx = zmpart->imx + 1;
40205 
40206    if (zmpart->imx > zmpart->imn) zmpart->ipart = 1;
40207 }
40208 
IsPhiPsi(isel)40209 int IsPhiPsi(isel)
40210 int isel;
40211 {
40212    int i;
40213 
40214    for (i=0; i<calfptr->ncalf; i++) {
40215 	if (aaptr[i].phi == isel || aaptr[i].psi == isel)
40216 		return(1);
40217    }
40218    return(0);
40219 }
40220 
AmiCom(iopt,x,y)40221 int AmiCom(iopt,x,y)
40222 int iopt;
40223 int x;
40224 int y;
40225 {
40226 
40227   if (ZMEAA || (!(ZMEup && *zmptrp->ihaszm) && *ipdbon) ) {
40228         int ires,i,iflp,ihis;
40229 
40230 	iflp = 0;
40231 	ires = -1;
40232 
40233 	if (iopt) {
40234 	   ires = CurAmino + 1;
40235 	   if (ires <= -4) {
40236 		if (HetCom(x,y)) return(1);
40237 	   }
40238 	} else {
40239 	   i = Clickwin(ZMEAAbut,ZME_window_high,x,y,1);
40240 	   if (i>=0) {
40241 		ires = ZME_window_pos+i+1;
40242 		CurAmino = ires-1;
40243 	   }
40244 	}
40245 	moving = gmoving = 0;
40246 	if (ires > 0) {
40247 	   LSSTRU List; int iamin, aminotyp;
40248 
40249 	   aminotyp = calfptr->iamino[ires-1]-1;
40250 
40251 	if (has_opengl && (*fancy || *fullgl)) {
40252 
40253            if (calfptr->iamino[ires-1] > 23) {
40254 		List.list = AmiBOpt; List.nents = 7;
40255 	   } else {
40256 		if (ZMEup && *zmptrp->ihaszm && *ipdbon) {
40257 		   if (aminotyp == 9 || aminotyp == 13) {
40258 			List.list = AmiNQOpt; List.nents = 17;
40259 	   	   } else if (aminotyp == 16) {
40260 			List.list = AmiHOpt; List.nents = 17;
40261 	   	   } else {
40262 			List.list = AmiBOpt; List.nents = 16;
40263 	   	   }
40264 		   if (ires == calfptr->ncalf) List.nents++;
40265 		} else {
40266 		   if (aminotyp == 9 || aminotyp == 13) {
40267 			List.list = AmiNQOpt; List.nents = 13;
40268 		   } else if (aminotyp == 16) {
40269 			List.list = AmiHOpt; List.nents = 13;
40270 		   } else {
40271 			List.list = AmiBOpt; List.nents = 12;
40272 		   }
40273 		}
40274 	   }
40275 	} else if (!has_opengl || (has_opengl && !(*fancy || *fullgl) )) {
40276 
40277 
40278            if (calfptr->iamino[ires-1] > 23) {
40279 		List.list = AmiBOptS; List.nents = 5;
40280 	   } else {
40281 		if (ZMEup && *zmptrp->ihaszm && *ipdbon) {
40282 		   if (aminotyp == 9 || aminotyp == 13) {
40283 			List.list = AmiNQOptS; List.nents = 15;
40284 		   } else if (aminotyp == 16) {
40285 			List.list = AmiHOptS; List.nents = 15;
40286 		   } else {
40287 			List.list = AmiBOptS; List.nents = 14;
40288 	   	   }
40289 		   if (ires == calfptr->ncalf) List.nents++;
40290 		} else {
40291 		   if (aminotyp == 9 || aminotyp == 13) {
40292 			List.list = AmiNQOptS; List.nents = 11;
40293 		   } else if (aminotyp == 16) {
40294 			List.list = AmiHOptS; List.nents = 11;
40295 		   } else {
40296 			List.list = AmiBOptS; List.nents = 10;
40297 	   	   }
40298 		}
40299 	   }
40300 	}
40301 
40302 	   if (iopt) {
40303 		if (DoPopUp(win,x,y,&List,&iamin,0) == -1) return 0;
40304 	   } else {
40305 		if (DoPopUp(ZMEwin,
40306 			ZMEAAbut[i].x+5,ZMEAAbut[i].y+5,
40307 			&List,&iamin,0) == -1) return 0;
40308 		RedrawZME();
40309 	   }
40310 
40311 	   if (aminotyp == 9 || aminotyp == 13) {
40312 		if (iamin == 5) iflp = 1;
40313 		if (iflp) {
40314 #if defined(VMS) || defined(UNDERSC)
40315 		    sngflp(&ires,
40316 #else
40317 #ifdef CRAY
40318 		    SNGFLP(&ires,
40319 #else
40320 		    sngflp_(&ires,
40321 #endif
40322 #endif
40323 			calfptr->iamino,xyzp->coo);
40324 #ifdef DOGL
40325 		    ogres(ires,1,1);
40326 		    update_model = 0;
40327 #endif
40328 		    update_struct();
40329 		    return(0);
40330 		} else {
40331 	   	    if (iamin > 5) iamin--;
40332 		}
40333 	   }
40334 
40335 	   if (aminotyp == 16) {
40336 		if (iamin == 5) iflp = 1;
40337 		if (iflp) {
40338 	           List.list = HisOpt; List.nents = 3;
40339 
40340 	   	   if (iopt) {
40341 			if (DoPopUp(win,x,y,&List,&ihis,0) == -1) return 0;
40342 	   	   } else {
40343 			if (DoPopUp(ZMEwin,
40344 			   ZMEAAbut[i].x+5,ZMEAAbut[i].y+5,
40345 			   &List,&ihis,0) == -1) return 0;
40346 	   	   }
40347 
40348 		   ihis++;
40349 #if defined(VMS) || defined(UNDERSC)
40350 		   sethis(&ires,&ihis,
40351 #else
40352 #ifdef CRAY
40353 		   SETHIS(&ires,&ihis,
40354 #else
40355 		   sethis_(&ires,&ihis,
40356 #endif
40357 #endif
40358 			xyzp->coo,xyzp->qat,xyzp->iresid,xyzp->iatclr,
40359 			xyzp->iaton,xyzp->iconn,xyzp->ianz,&calfptr->ncalf,
40360 			calfptr->icalf,xyzp->ityp,xyzp->ipdbt);
40361 #ifdef DOGL
40362 		   ogres(ires,1,1);
40363 		   update_model = 0;
40364 #endif
40365 		   update_struct();
40366 		   return(0);
40367 
40368 		} else {
40369 	   	    if (iamin > 5) iamin--;
40370 		}
40371 	   }
40372 
40373 	if (!has_opengl || (has_opengl && !(*fancy || *fullgl) )) {
40374 	   if (iamin >= 5) {
40375 		iamin++;
40376 		iamin++;
40377 	   }
40378 	}
40379 
40380 	   switch (iamin) {
40381 	   case 0:
40382 		   if (calfptr->reson[ires-1] == 0) {
40383 #if defined(VMS) || defined(UNDERSC)
40384 			actami(&ires,&ZERO,&ONE,&ZERO);
40385 #else
40386 #ifdef CRAY
40387 			ACTAMI(&ires,&ZERO,&ONE,&ZERO);
40388 #else
40389 			actami_(&ires,&ZERO,&ONE,&ZERO);
40390 #endif
40391 #endif
40392 			rsold = RESUND;
40393 #ifdef DOGL
40394 			ogres(ires,ONE,1);
40395 #else
40396 			return(1);
40397 #endif
40398 		  } else {
40399 #if defined(VMS) || defined(UNDERSC)
40400 			actami(&ires,&ZERO,&ZERO,&ZERO);
40401 #else
40402 #ifdef CRAY
40403 			ACTAMI(&ires,&ZERO,&ZERO,&ZERO);
40404 #else
40405 			actami_(&ires,&ZERO,&ZERO,&ZERO);
40406 #endif
40407 #endif
40408 			rsold = RESUND;
40409 #ifdef DOGL
40410 			ogres(ires,ONE,1);
40411 			update_model = 0;
40412 			return(1);
40413 #else
40414 			update_model = 1;
40415 			return(1);
40416 #endif
40417 		  }
40418 			break;
40419 	   case 1:
40420 			strcpy(molwstr,"Entering Amino Acid range select");
40421 			StatusStr(0,1);
40422 
40423 			if (DisHlp) {
40424 			   DoCan(event.xbutton.x_root, event.xbutton.y_root,
40425 	"Residue range selection: Follow the point of the read arrow\nwhen it appears. To end selection hit the escape key.",0);
40426 			   DisHlp = 0;
40427 			}
40428 
40429 			DisAmino = ires;
40430 #if defined(VMS) || defined(UNDERSC)
40431 			actami(&DisAmino,&ZERO,&ONE,&ZERO);
40432 #else
40433 #ifdef CRAY
40434 			ACTAMI(&DisAmino,&ZERO,&ONE,&ZERO);
40435 #else
40436 			actami_(&DisAmino,&ZERO,&ONE,&ZERO);
40437 #endif
40438 #endif
40439 			update_casel = 1;
40440 #ifdef DOGL
40441 			ogres(DisAmino,ONE,1);
40442 #else
40443 			return(1);
40444 #endif
40445 			break;
40446 	   case 2:	{
40447 			LSSTRU List;
40448 			List.list = labels;
40449 			List.nents = 6;
40450 			if (calfptr->lab[ires-1] == 0) {
40451 			   if (DoPopUp(win,x,y,&List,
40452 				&calfptr->lab[ires-1],0) == -1) return(0);
40453 			   calfptr->lab[ires-1]++;
40454 			   calfptr->lab[ires-1]++;
40455 			} else {
40456 			   calfptr->lab[ires-1] = 0;
40457 			}
40458 #ifdef DOGL
40459 			update_model = 0;
40460 #else
40461 			update_model = 1;
40462 			return(1);
40463 #endif
40464 			}
40465 			break;
40466 	   case 3:
40467 #if defined(VMS) || defined(UNDERSC)
40468 			setorg(&calfptr->icalf[ires-1][0]);
40469 #else
40470 #ifdef CRAY
40471 			SETORG(&calfptr->icalf[ires-1][0]);
40472 #else
40473 			setorg_(&calfptr->icalf[ires-1][0]);
40474 #endif
40475 #endif
40476 			return(1);
40477 			break;
40478 	   case 4:
40479 #if defined(VMS) || defined(UNDERSC)
40480 			proxic(&calfptr->icalf[ires-1][0],backb,&ZERO,&ONE,&THRESH);
40481 #else
40482 #ifdef CRAY
40483 			PROXIC(&calfptr->icalf[ires-1][0],backb,&ZERO,&ONE,&THRESH);
40484 #else
40485 			proxic_(&calfptr->icalf[ires-1][0],backb,&ZERO,&ONE,&THRESH);
40486 #endif
40487 #endif
40488 			XMapRaised(display,DISTwin);
40489 			distup = 1;
40490 			RedrawDIST();
40491 			return(1);
40492 			break;
40493 	   case 5:
40494 #if defined(VMS) || defined(UNDERSC)
40495 			proxic(&calfptr->icalf[ires-1][0],backb,&ONE,&ONE,&THRESH);
40496 			initsrf();
40497 #else
40498 #ifdef CRAY
40499 			PROXIC(&calfptr->icalf[ires-1][0],backb,&ONE,&ONE,&THRESH);
40500 	 		INITSRF();
40501 #else
40502 			proxic_(&calfptr->icalf[ires-1][0],backb,&ONE,&ONE,&THRESH);
40503 			initsrf_();
40504 #endif
40505 #endif
40506 			XMapRaised(display,DISTwin);
40507 			distup = 1;
40508 			RedrawDIST();
40509 			return(1);
40510 			break;
40511 	   case 6:
40512 			calfptr->iams[ires-1] = 1;
40513 #if defined(VMS) || defined(UNDERSC)
40514 			initsrf();
40515 #else
40516 #ifdef CRAY
40517 	 		INITSRF();
40518 #else
40519 			initsrf_();
40520 #endif
40521 #endif
40522 		/*	return(1);*/
40523 			break;
40524 	   case 7:	{
40525 			LSSTRU List; int inrs;
40526 			List.list = Rotamers;
40527 			List.nents = aminozmt[aminotyp].nrots;
40528 
40529 			inrs = 0;
40530 			if (iopt) {
40531 			   if (DoPopUp(win,x,y,&List,&inrs,0) == -1) return 0;
40532 			} else {
40533 			   if (DoPopUp(ZMEwin,
40534 				ZMEAAbut[i].x+5,ZMEAAbut[i].y+5,
40535 				&List,&inrs,0) == -1) return 0;
40536 			}
40537 			if (!ZMEup) {
40538 #if defined(VMS) || defined(UNDERSC)
40539 			   dfiass();
40540 #else
40541 #ifdef CRAY
40542 			   DFIASS();
40543 #else
40544 			   dfiass_();
40545 #endif
40546 #endif
40547 
40548 			   pmfrot->ndrs = 1;
40549 			   pmfrot->idrs[0] = ires;
40550 			   AllocRot();
40551 			   rotset(ires,inrs);
40552 			   DeAllocRot();
40553 #ifdef DOGL
40554 			   ogres(ires,ONE,1);
40555 #endif
40556 			   return(1);
40557 			} else {
40558 			   if (aminozmt[aminotyp].chis[0] != -1)
40559 				zmptrp->bet[aaptr[ires-1].chi1] =
40560 					aminozmt[aminotyp].rots[inrs].rots[0];
40561 			   if (aminozmt[aminotyp].chis[1] != -1)
40562 				zmptrp->bet[aaptr[ires-1].chi2] =
40563 					aminozmt[aminotyp].rots[inrs].rots[1];
40564 			   if (aminozmt[aminotyp].chis[2] != -1)
40565 				zmptrp->bet[aaptr[ires-1].chi3] =
40566 					aminozmt[aminotyp].rots[inrs].rots[2];
40567 			   if (aminozmt[aminotyp].chis[3] != -1)
40568 				zmptrp->bet[aaptr[ires-1].chi4] =
40569 					aminozmt[aminotyp].rots[inrs].rots[3];
40570 #if defined(VMS) || defined(UNDERSC)
40571 			   curs(&ONE);
40572 #else
40573 #ifdef CRAY
40574 	 		   CURS(&ONE);
40575 #else
40576 			   curs_(&ONE);
40577 #endif
40578 #endif
40579 			   SetQZME();
40580 			   if (ZME_window_pos >= calfptr->ncalf) ZME_window_pos = 0;
40581 			   if (calfptr->ncalf < ZME_window_high) RedrawZME();
40582 			   else UpdateZME();
40583 			   RedrawScroll(&zscroll);
40584 			   FindZRange(ires);
40585    			   zmt2cor(ires,0);
40586 			}
40587 			}
40588 			break;
40589 	   case 8:	{
40590 			void scanrot(int,int);
40591 
40592 			scanrot(ires,aminotyp);
40593 
40594 			}
40595 			return(1);
40596 			break;
40597 	   case 9:	{
40598 			void onerot(int ires,int print);
40599 
40600 			onerot(ires,1);
40601 
40602 			}
40603 			return(1);
40604 			break;
40605 	   case 10:
40606 			{int ikeus;
40607 	   		List.list = RotLib; List.nents = 2;
40608 			if (DoPopUp(win,x,y,&List,&ikeus,0) == -1) return 0;
40609 			if (ZMEup) {
40610 			   if (ikeus) aminozmt = aminozmtd;
40611 			   else aminozmt = aminozmtr;
40612 			} else {
40613 			   if (ikeus) RDrots = aminorots;
40614 			   else RDrots = raminorots;
40615 			}
40616 			}
40617 			break;
40618 	   case 11:
40619 			initflx();
40620 			for (i=0; i < *xyzp->iatoms; i++) {
40621 			   if (xyzp->iresid[i] == ires) {
40622 				xyzp->iatclr[i] = 15;
40623 			   }
40624 			}
40625 			pmfrot->idrs[pmfrot->ndrs] = ires;
40626 			resrot[0].idrs[pmfrot->ndrs] = ires;
40627 			pmfrot->ndrs++;
40628 			resrot[0].ndrs = pmfrot->ndrs;
40629 #ifdef DOGL
40630 			ogres(ires,1,1);
40631 #endif
40632 			update_model = 0;
40633 			break;
40634 	   case 12:
40635 #if defined(VMS) || defined(UNDERSC)
40636 			curs(&ONE);
40637 #else
40638 #ifdef CRAY
40639 	 		CURS(&ONE);
40640 #else
40641 			curs_(&ONE);
40642 #endif
40643 #endif
40644 			idum1 = DelAmino(ires);
40645 			make_aa();
40646 			if (ZME_window_pos >= calfptr->ncalf) ZME_window_pos = 0;
40647 			if (calfptr->ncalf < ZME_window_high) RedrawZME();
40648 			else UpdateZME();
40649 			RedrawScroll(&zscroll);
40650 			*Sinct = 530;
40651 			update_model = 1;
40652 			return(1);
40653 			break;
40654 	   case 13:
40655 			InsertAmino = ires;
40656 			ReplaceAmino = 0;
40657 			if (SEQup) {
40658 			   XMapRaised(display,SEQwin);
40659 			   RedrawSEQ();
40660 			} else {
40661 			   InitSEQ(event.xbutton.x_root,event.xbutton.y_root);
40662 			}
40663 			update_model = 1;
40664 			break;
40665 	   case 14:	{
40666 			LSSTRU List; int inrs; int irsnrt;
40667 			List.list = AminoAcids; List.nents = 20;
40668 
40669 			if (!calfptr->icalf[ires][0]) {
40670 			   DoCan(event.xbutton.x_root, event.xbutton.y_root,
40671 			"Amino acid can not be replaced: \nMissing C alpha next residue.",0);
40672 			   break;
40673 			}
40674 
40675 			if (iopt) {
40676 			   if (DoPopUp(win,x,y,&List,&inrs,0) == -1) return 0;
40677 			} else {
40678 			   if (DoPopUp(ZMEwin,
40679 				ZMEAAbut[i].x+5,ZMEAAbut[i].y+5,
40680 				&List,&inrs,0) == -1) return 0;
40681 			}
40682 #if defined(VMS) || defined(UNDERSC)
40683 			curs(&ONE);
40684 #else
40685 #ifdef CRAY
40686 	 		CURS(&ONE);
40687 #else
40688 			curs_(&ONE);
40689 #endif
40690 #endif
40691 			Sequence[0] = inrs;
40692 
40693     			irsnrt = calfptr->irsnr[ires-1];
40694 			ReplaceSequence(Sequence,1,0,ires);
40695     			calfptr->irsnr[ires-1] = irsnrt;
40696 			make_aa();
40697 			SetQZME();
40698 			if (ZME_window_pos >= calfptr->ncalf) ZME_window_pos = 0;
40699 			if (calfptr->ncalf < ZME_window_high) RedrawZME();
40700 			else UpdateZME();
40701 			RedrawScroll(&zscroll);
40702 			FindZRange(ires);
40703 			if (ires <= calfptr->ncalf-1)
40704 				xyzp->iaton[calfptr->icalf[ires][1]-1] = 1;
40705 
40706 #if defined(VMS) || defined(UNDERSC)
40707 			actami(&ires,&ZERO,&ONE,&ZERO);
40708 #else
40709 #ifdef CRAY
40710 			ACTAMI(&ires,&ZERO,&ONE,&ZERO);
40711 #else
40712 			actami_(&ires,&ZERO,&ONE,&ZERO);
40713 #endif
40714 #endif
40715    			zmt2cor(ires,1);
40716 			if (*fftyp == 7) {
40717 			   cell->ichx = 0;
40718 
40719 #if defined(VMS) || defined(UNDERSC)
40720 			   dotyp(&cell->ichx);
40721 #else
40722 #ifdef CRAY
40723 			   DOTYP(&cell->ichx);
40724 #else
40725 			   dotyp_(&cell->ichx);
40726 #endif
40727 #endif
40728 			}
40729 
40730 			}
40731 			break;
40732 	   case 15:
40733 			if (!AddCap(ires)) return(0);
40734 			if (ZMEup) {
40735 #ifdef DOGL
40736 #if defined(VMS) || defined(UNDERSC)
40737 			   dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
40738 			   doconn();docent();doclr();qupd();
40739 #else
40740 #ifdef CRAY
40741 			   DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
40742 			   DOCONN();DOCENT();doclr();QUPD();
40743 #else
40744 			   dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
40745 			   doconn_();docent_();doclr();qupd_();
40746 #endif
40747 #endif
40748 #endif
40749 			   return(1);
40750 			}
40751 			break;
40752 	   case 16:
40753 #if defined(VMS) || defined(UNDERSC)
40754 			curs(&ONE);
40755 #else
40756 #ifdef CRAY
40757 	 		CURS(&ONE);
40758 #else
40759 			curs_(&ONE);
40760 #endif
40761 #endif
40762 			InsertAmino = -1;
40763 			ReplaceAmino = 0;
40764 			LastAmino = calfptr->icalf[ires-1][2];
40765 			if (SEQup) {
40766 			   XMapRaised(display,SEQwin);
40767 			   RedrawSEQ();
40768 			} else {
40769 			   InitSEQ(event.xbutton.x_root,event.xbutton.y_root);
40770 			}
40771 			break;
40772 	   }
40773 	}
40774   }
40775   return(0);
40776 }
40777 
HetCom(x,y)40778 int HetCom(x,y)
40779 int x;
40780 int y;
40781 {
40782 
40783   if (ZMEAA || (!(ZMEup && *zmptrp->ihaszm) && *ipdbon) ) {
40784         int ires,i;
40785 	double rdist;
40786 
40787         rdist = 5.0;
40788 
40789 
40790 	ires = CurAmino + 1;
40791 
40792 	moving = gmoving = 0;
40793 
40794 	if (ires < 0) {
40795 	   LSSTRU List; int iamin, aminotyp;
40796 
40797 #ifdef DOGL
40798 	   List.list = HetOpt; List.nents = 10;
40799 
40800 #else
40801 	   List.list = HetOpt; List.nents = 9;
40802 
40803 #endif
40804 
40805 	   if (DoPopUp(win,x,y,&List,&iamin,0) == -1) return 0;
40806 
40807 	   switch (iamin) {
40808 	   case 0:
40809 			i = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
40810 					*xyzp->iatoms,x,y,MINDIFF);
40811 			if (i != -1) {
40812 			   i++;
40813 #if defined(VMS) || defined(UNDERSC)
40814 			setorg(&i);
40815 #else
40816 #ifdef CRAY
40817 			SETORG(&i);
40818 #else
40819 			setorg_(&i);
40820 #endif
40821 #endif
40822 			return(1);
40823 			}
40824 			break;
40825 	   case 1:	{
40826 			LSSTRU List;
40827 			List.list = labhet;
40828 			List.nents = 5;
40829 			if (clfstrptr->labhet[ABS(ires)] == 0) {
40830 			   if (DoPopUp(win,x,y,&List,
40831 				&clfstrptr->labhet[ABS(ires)],0) == -1) return(0);
40832 			   clfstrptr->labhet[ABS(ires)]++;
40833 			   clfstrptr->labhet[ABS(ires)]++;
40834 			} else {
40835 			   clfstrptr->labhet[ABS(ires)] = 0;
40836 			}
40837 			CentLig();
40838 #ifdef DOGL
40839 			update_model = 0;
40840 #else
40841 			update_model = 1;
40842 			return(1);
40843 #endif
40844 			}
40845 			break;
40846 	   case 2:
40847 			i = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
40848 					*xyzp->iatoms,x,y,MINDIFF);
40849 			i++;
40850 #if defined(VMS) || defined(UNDERSC)
40851 			proxic(&i,backb,&ZERO,&ONE,&THRESH);
40852 #else
40853 #ifdef CRAY
40854 			PROXIC(&i,backb,&ZERO,&ONE,&THRESH);
40855 #else
40856 			proxic_(&i,backb,&ZERO,&ONE,&THRESH);
40857 #endif
40858 #endif
40859 			XMapRaised(display,DISTwin);
40860 			distup = 1;
40861 			RedrawDIST();
40862 			return(1);
40863 			break;
40864 	   case 3:
40865 			i = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
40866 					*xyzp->iatoms,x,y,MINDIFF);
40867 			i++;
40868 #if defined(VMS) || defined(UNDERSC)
40869 			proxic(&i,backb,&ONE,&ONE,&THRESH);
40870 			initsrf();
40871 #else
40872 #ifdef CRAY
40873 			PROXIC(&i,backb,&ONE,&ONE,&THRESH);
40874 	 		INITSRF();
40875 #else
40876 			proxic_(&i,backb,&ONE,&ONE,&THRESH);
40877 			initsrf_();
40878 #endif
40879 #endif
40880 			XMapRaised(display,DISTwin);
40881 			distup = 1;
40882 			RedrawDIST();
40883 			return(1);
40884 			break;
40885 	   case 4:
40886 			inichg(ires);
40887 			break;
40888 	   case 5:
40889 			DelHet(ires);
40890 			return(1);
40891 			break;
40892 	   case 6:
40893 			LigandStruct(ires);
40894 			break;
40895 	   case 7:
40896 			if (CheckWGET()) {
40897 			   LigandHydro(ires);
40898 			} else {
40899 			   if (CheckHydro(ires)) {
40900 				if (!DoCan(event.xbutton.x_root,
40901 				           event.xbutton.y_root,
40902 				   "Hydrogens already present !!\nAdding Hydrogens will render the\n stored formal charge as incorrect\nContinue ?",1)) {
40903 				LigandHydroPBE(ires);
40904 				}
40905 			   } else {
40906 				LigandHydroPBE(ires);
40907 			   }
40908 			}
40909 
40910 #ifdef DOGL
40911 			if (*fancy) {
40912 			    oghet(0);
40913 			} else {
40914 			    oglines();
40915 			}
40916 			update_model = 0;
40917 #endif
40918 			update_struct();
40919 			break;
40920 	   case 8:
40921 			if (ires < 0) {
40922 			   int aires;
40923 
40924 			   aires = ABS(ires);
40925 
40926 			   if (aires < MXHETA)
40927 				calfptr->ihet[aires] = 0;
40928 
40929 			   if (DoPopUp(win, x,y,
40930 				  NULL,Snstr,0) == -1) break;
40931 			   *Sinct = 330;
40932 			   *Sincp = ires;
40933 
40934 			   sndon(ires,1,*Snstr);
40935 			   return(1);
40936 			}
40937 			break;
40938 	   case 9:
40939 			if (ires < 0) {
40940 			   int aires;
40941 
40942 			   aires = ABS(ires);
40943 
40944 			   if (aires < MXHETA)
40945 				calfptr->ihets[aires] = 1;
40946 
40947 #if defined(VMS) || defined(UNDERSC)
40948 			   initsrf();
40949 #else
40950 #ifdef CRAY
40951 	 		   INITSRF();
40952 #else
40953 			   initsrf_();
40954 #endif
40955 #endif
40956 			}
40957 		/*	return(1);*/
40958 			break;
40959 	   }
40960 	}
40961   }
40962   return(0);
40963 }
40964 
PressZME(butnr,x,y)40965 int PressZME(butnr,x,y)
40966 int butnr;
40967 int x;
40968 int y;
40969 {
40970   int i,j,k,iptr;
40971   int nat,nattmp,nprev,nvar;
40972   int type,row,column,deloke;
40973   LSSTRU List;
40974 
40975   if (DEBUG) fprintf(stderr,"PressZME in\n");
40976 
40977 if (ZMEmode) {
40978   i = Clickwin(TabBut,TABBUTN,x,y,1);
40979       if (i>=0) {
40980 	DeActZME();
40981         if (i==TABBUTN-1) ZMEatom = 99;
40982 	else ZMEatom = i+1;
40983 	nvar = 3; if (*zmptrp->nz <= 2) nvar = *zmptrp->nz;
40984 	ZMEmode = 0;
40985 	if (nvar > 0) {
40986 	    ZMEsel = 1;
40987 	    aflag = nvar;anum = nvar;acnt = 0;
40988 	    sprintf(stemp,
40989 		"Select %d Atoms to define the connectivety of this Center"
40990 		,nvar);
40991 	    strcpy(ZMEerr,stemp);
40992 	    XDefineCursor(display,win,AtomCursor);
40993 	    ActBut(&cbut[BDIST],0);
40994 	    ActBut(&cbut[BANGLE],0);
40995 	    ActBut(&cbut[BDIHED],0);
40996 	}
40997 	else AddLine(ZMEatom,1,NULL,NULL,NULL,NULL,ZMEmul);
40998 	RedrawZME();
40999 	return(1);
41000       }
41001       i = Clickwin(&ZMEBbut[ZMESIN],3,x,y,1);
41002 
41003       if (i>=0) {
41004 	  switch (i) {
41005 	  case ZMESIN:	TogBut(&ZMEBbut[ZMEmul]);ActBut(&ZMEBbut[ZMEmul],1);
41006 			ZMEmul = ZMESIN;
41007 			TogBut(&ZMEBbut[ZMEmul]);ActBut(&ZMEBbut[ZMEmul],-1);
41008 			break;
41009 	  case ZMEDBL:	TogBut(&ZMEBbut[ZMEmul]);ActBut(&ZMEBbut[ZMEmul],1);
41010 			ZMEmul = ZMEDBL;
41011 			TogBut(&ZMEBbut[ZMEmul]);ActBut(&ZMEBbut[ZMEmul],-1);
41012 			break;
41013 	  case ZMETRI:	TogBut(&ZMEBbut[ZMEmul]);ActBut(&ZMEBbut[ZMEmul],1);
41014 			ZMEmul = ZMETRI;
41015 			TogBut(&ZMEBbut[ZMEmul]);ActBut(&ZMEBbut[ZMEmul],-1);
41016 			break;
41017 	  }
41018       }
41019       return(0);
41020 }
41021 else if (!Selecting && !ZMEsel) {
41022 
41023   if (butnr == 3) {
41024 	k = 0;
41025 	if (QBoxPaste(ZMEwin,IANZbox,*zmptrp->nz)) k = 1;;
41026 	if (QBoxPaste(ZMEwin,BLbox,*zmptrp->nz)) k = 1;;
41027 	if (QBoxPaste(ZMEwin,ALPHbox,*zmptrp->nz)) k = 1;;
41028 	if (QBoxPaste(ZMEwin,BETbox,*zmptrp->nz)) k = 1;;
41029 	if (!k) OnTop();
41030 	return(0);
41031   } else {
41032 
41033      if (!ZMEAA) {
41034         i = ClickBox(IANZbox,*zmptrp->nz,x,y);
41035         if (i>=0) {
41036    	   DeActZME();
41037 	   IANZbox[i].col = ZC_AT1;
41038 	   IANZbox[i].active = 1; UpdateZME();
41039 	   if (zmptrp->imap[i]-1 >= 0) xyzp->iaton[zmptrp->imap[i]-1] = 3;
41040 	   sprintf(ZMEerr, "Line %d Atom %d",i+1,zmptrp->imap[i]);
41041 	   RedrawStatus();
41042 	   update_model = 0;
41043 	   update_sel = 1;
41044 	   return(1);
41045         }
41046         i = ClickBox(BLbox,*zmptrp->nz,x,y);
41047         if (i>=0) {
41048 	   ActVar(i,0,butnr);
41049 	   return(1);
41050         }
41051         i = ClickBox(ALPHbox,*zmptrp->nz,x,y);
41052         if (i>=0) {
41053 	   ActVar(i,1,butnr);
41054 	   return(1);
41055         }
41056      }
41057      i = ClickBox(BETbox,*zmptrp->nz,x,y);
41058      if (i>=0) {
41059 	ActVar(i,2,butnr);
41060 	return(1);
41061      }
41062      for (i=0; i<*zmptrp->nz; i++) {
41063 	j = ClickBox(&IZbox[i*4],4,x,y);
41064 	if (j>=0) {
41065 		update_model = 0;
41066 		DeActZME();
41067 		iptr = izz(i,j)-1;
41068 		if (iptr < *zmptrp->nz && iptr >= 0) {
41069 			IANZbox[iptr].col = ZC_AT2+j;
41070 			xyzp->iaton[zmptrp->imap[iptr]-1] = 4+j;
41071 		}
41072 		IANZbox[i].col = ZC_AT1;
41073 		IZbox[i*4+j].active = 1;
41074 		UpdateZME();
41075 		if (zmptrp->imap[i]-1 >= 0) xyzp->iaton[zmptrp->imap[i]-1] = 3;
41076 		update_sel = 1;
41077 		return(1);
41078 	}
41079      }
41080    }
41081 }
41082 
41083 if (ZMEsel) return(0);
41084 
41085   i = ClickBox(&qboxes[QBZMAT],1,x,y);
41086   if (i>=0) {
41087 		DeActZME();
41088 		UpdateZME();
41089 		qboxes[QBZMAT].active = 1;
41090 		EXPbox[0].active = 0;
41091 		PromptBox(&qboxes[QBZMAT]);
41092 		PromptBox(&EXPbox[0]);
41093   }
41094 
41095   i = ClickBox(&EXPbox[0],1,x,y);
41096   if (i>=0) {
41097 		DeActZME();
41098 		UpdateZME();
41099 		EXPbox[0].active = 1;
41100 		qboxes[QBZMAT].active = 0;
41101 		PromptBox(&EXPbox[0]);
41102 		PromptBox(&qboxes[QBZMAT]);
41103   }
41104 
41105   i = Clickwin(ZMEswitch,2,x,y,1);
41106   if (i>=0) {
41107      switch (i) {
41108      case 0:
41109 	if (pdb && ! *ialtyp) {
41110 	   if (ZMEAA) {
41111 		ZMEAA = 0;
41112 		TogDown(&ZMEswitch[0]);
41113 		EXPbox[0].fake = 1;
41114 	   } else {
41115 		ZMEAA = 1;
41116 		make_aa();
41117 		TogUp(&ZMEswitch[0]);
41118 		EXPbox[0].fake = 0;
41119 	   }
41120 	   DeActZME();
41121 	   SetQZME();
41122 	   RedrawZME();
41123 	}
41124 	break;
41125      case 1:
41126 	size_hints.flags =  USSize;
41127 	size_hints.width = ZMEWINW;
41128 	if (!ZMEbig) {
41129 	   size_hints.height = ZMEWINH;
41130 	   ZMEbig = 1;
41131 	} else {
41132 	   size_hints.height = ZMEZOffy-ZMEFRBord+ZMEZHIGH+1;
41133 	   ZMEbig = 0;
41134 	}
41135 	XSetNormalHints(display, ZMEwin, &size_hints);
41136 	XResizeWindow(display, ZMEwin, ZMEWINW,size_hints.height);
41137 	TogBut(&ZMEswitch[1]);
41138 	DrwBut(&ZMEswitch[1]);
41139 	break;
41140      }
41141   }
41142 
41143   if (AmiCom(0,x,y) == 1) {
41144 	update_model = 0;
41145 	return(1);
41146   }
41147 
41148   i = Clickwin(ZMEbut,ZMEBUTTS,x,y,1);
41149 
41150       if (i>=0) {
41151 	  strcpy(ZMEerr," ");
41152 	  RedrawStatus();
41153 	  switch (i) {
41154 	  case ZMEARR1: ScrollBut(i); break;
41155 	  case ZMEARR2: ScrollBut(i); break;
41156           case ZMEAPPL:	if (!Selecting && !ZMEsel) {
41157 			    DeActZME(); GetQZME(); UpdateZME();
41158 		  	    map_prop();
41159 			    for (j=0; j<MAXSURF; j++) SSon[istruct][j] = 0;
41160 			    SSdone[istruct] = 0;
41161 			    RedrawSTRC();
41162 			    *Sinct = 530; return(1);
41163 			}
41164 			break;
41165           case ZMECAN1:	if (!Selecting && !ZMEsel) {
41166 			    DeActZME(); SetQZME(); UpdateZME(); return(1);
41167 			}
41168 			break;
41169           case ZMEFRG:
41170 			{int iret;
41171 			   iret = GetFrag(0,0,0);
41172 			   if (iret != -1) return(iret);
41173 			}
41174 			break;
41175 	  case ZMEADD:	if (!Selecting && !ZMEsel) {
41176 			    ZMEmode = 1; RedrawZME(); return(0);
41177 			    calfptr->issdon = 0;
41178 			}
41179 			break;
41180 	  case ZMEDEL:	if (Selecting || ZMEsel) break;
41181 			activeZME(&type,&row,&column);
41182 			deloke = 1;
41183 			calfptr->issdon = 0;
41184 			if (row < *zmptrp->nz && row >= 0) {
41185 				for (j=row+1; j < *zmptrp->nz; j++) {
41186 					for (k=0; k < 4; k++)
41187 						if (izz(j,k) == row+1)
41188 							deloke = 0;
41189 					if (deloke) {
41190 					if (ABS(zmptrp->ibl[j]) == row+1)
41191 						deloke = -1;
41192 					if (ABS(zmptrp->ialph[j]) == row+1)
41193 						deloke = -1;
41194 					if (ABS(zmptrp->ibet[j]) == row+1)
41195 						deloke = -1;
41196 					}
41197 				}
41198 			} else {
41199 				deloke = -2;
41200 			}
41201 			if (deloke == 1) {
41202 				DelLine(row,1,0,NULL);
41203 				if (ZME_window_pos >= *zmptrp->nz-1) ZME_window_pos = 0;
41204 				SetQZME(); RedrawZME(); *Sinct = 530; return(1);
41205 			}
41206 			else {
41207 				if (deloke == -1) strcpy(ZMEerr,
41208 					"LINE NOT DELETED: first remove all links to this line");
41209 				else if (deloke == -2) strcpy(ZMEerr,
41210 					"LINE NOT DELETED: no atom selected");
41211 				else strcpy(ZMEerr,
41212 					"LINE NOT DELETED: first remove all atoms connected to this line");
41213 				if (*ibell) XBell(display,0);
41214 				RedrawStatus();
41215 			}
41216 			break;
41217 	  case ZMENEW:	if (!Selecting && !ZMEsel) {
41218 			   *irtcel = 0;
41219 			   *fftyp = 0;
41220 			   pdb = 0;
41221 			   *ipdbon = 0;
41222 			   *icalc = 0;
41223 			   cell->ichx = 0;
41224 			   *natorg = 0;
41225 			   DeActZME();
41226 			   *xyzp->iatoms = 0;
41227 			   for (j=0; j < 3; j++)
41228 			      for (k=0; k < 3; k++)
41229 				xyzp->coo[j*3+k] = 0.0;
41230 			   *zmptrp->nz = 0;
41231 			   ZME_window_pos = 0;
41232 			   *zmptrp->ihaszm = 1;
41233 			   geo1ptr->ieav = 0;
41234 			   calfptr->ncalf = 0;
41235 			   *backb = 0;
41236 			   calfptr->nchain = 0;
41237 			   LastAmino = -1;
41238 			   calfptr->issdon = 0;
41239 			   ZMEAA = 0;
41240           		   SetQZME(); RedrawZME();
41241 			   nwater[istruct] = 0;
41242 			   if (ATMup) {
41243 				UpdateATM();
41244 				XMapRaised(display,ATMwin);
41245 				RedrawATM();
41246 			   }
41247 			   send_expose();
41248 			   empty_model(istruct,1);
41249 			   return(1);
41250 			}
41251 			break;
41252 	  case ZMEMAP:	if (!Selecting && !ZMEsel) {
41253 			   int ff; List.list = mapopt; List.nents = 7;
41254 			   if (DoPopUp(ZMEwin,
41255 				ZMEbut[ZMEMAP].x+1,ZMEbut[ZMEMAP].y-BUTTH,
41256 				&List,iixyz,0) == -1) break;
41257 			   if (*iixyz >= 4) {
41258 				switch(*iixyz) {
41259 				case 4:
41260 					ff = 5;
41261 					break;
41262 				case 5:
41263 					ff = 6;
41264 					break;
41265 				case 6:
41266 					if (! (*fftyp >= 1 && *fftyp <= 4) ) {
41267 					   ff = 1;
41268 					   if (pdb) ff = 2;
41269 					} else {
41270 					   ff = *fftyp;
41271 					}
41272 					break;
41273 				default:
41274 					break;
41275 				}
41276 				if (typit(ff,0)) {
41277 				   if (DoCan(event.xbutton.x_root,
41278 					event.xbutton.y_root,
41279 					"Found UnTyped Atoms !",0)) {}
41280 				} else {
41281 				   if (*iixyz == 6) {
41282 					if (TNKup) {
41283 					   XMapRaised(display,TNKwin);
41284 					   RedrawTNK();
41285 					} else {
41286 					   InitTNK(event.xbutton.x_root,
41287 						event.xbutton.y_root);
41288 					}
41289 				   } else {
41290 					*Sinct = 151; return(1);
41291 				   }
41292 				}
41293 			   } else {
41294 			      qboxstr(&qboxes[QMXYZ],NULL,1,0,-1,DEFQX,DEFQY,
41295 				   QBOXWIDE,QBOXHIGH, 0,"XYZ file ? ",NULL,
41296 				   0,0,151,0,dummyproc);
41297 			   }
41298 			}
41299 			break;
41300 	  case ZMECANC:
41301 			UnMapZME();
41302 			RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);
41303 			break;
41304 	  case ZMECVAR:	 { int iop;
41305 			   List.list = zmevarclr; List.nents = 2;
41306 			   if (DoPopUp(ZMEwin,
41307 				ZMEbut[ZMECVAR].x+1,ZMEbut[ZMECVAR].y+BUTTH,
41308 				&List,&iop,0) == -1) break;
41309 			   SetConst(iop);
41310 			}
41311 			break;
41312 	  case ZMEGAM:	TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],1);
41313 			ZMEopt = ZMEGAM;
41314 			TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],-1);
41315 			break;
41316 	  case ZMEUS:
41317 			if (*igztyp) {
41318 			   TogBut(&ZMEbut[ZMEUS]);
41319 			   *igztyp = 0;
41320 			   strcpy(ZMEerr,"Switching to Gamess-UK style of Z-Matrix writing");
41321 			} else {
41322 			   TogDown(&ZMEbut[ZMEUS]);
41323 			   *igztyp = 1;
41324 			   strcpy(ZMEerr,"Switching to Gamess-US style of Z-Matrix writing");
41325 			}
41326 			RedrawStatus();
41327 			break;
41328 	  case ZMEGAU:	TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],1);
41329 			ZMEopt = ZMEGAU;
41330 			TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],-1);
41331 			break;
41332 	  case ZMEMOP:	TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],1);
41333 			ZMEopt = ZMEMOP;
41334 			TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],-1);
41335 			break;
41336 	  case ZMENWC:	TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],1);
41337 			ZMEopt = ZMENWC;
41338 			TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],-1);
41339 			break;
41340 	  case ZMECAR:	{LSSTRU List;
41341 			TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],1);
41342 			ZMEopt = ZMECAR;
41343 			TogBut(&ZMEbut[ZMEopt]);ActBut(&ZMEbut[ZMEopt],-1);
41344 			List.list = xyzopt; List.nents = 5; /* List.nents = 4; */
41345 			DoPopUp(ZMEwin,ZMEbut[ZMECAR].x+1,
41346 					ZMEbut[ZMECAR].y-3*BUTTH,&List,ixyz,0);
41347 			/* DoPopUp(ZMEwin,ZMEbut[ZMECAR].x+1,
41348 					ZMEbut[ZMECAR].y-2*BUTTH,&List,ixyz,0); */
41349 			}
41350 			break;
41351 	  case ZMESUB:
41352 			if (TogBut(&ZMEbut[ZMESUB])) {
41353 			   XDestroyWindow(display,SUBwin);
41354 		   	   SUBup = 0;
41355 			} else {
41356 			   if ((ZMEopt == ZMEGAM) && *igztyp) {
41357 		  	 	if (DoCan(event.xbutton.x_root,
41358 					event.xbutton.y_root,
41359 					"Submit Gamess-US not available",0)) {
41360 				}
41361 				TogBut(&ZMEbut[ZMESUB]);
41362 			   } else {
41363 				int jmode;
41364 
41365 				jmode = ZMEopt-ZMEGAM;
41366 				if (jmode == 4) jmode = 3;
41367 				if (!CreateSUB(jmode))
41368 					TogBut(&ZMEbut[ZMESUB]);
41369 			   }
41370 			}
41371 			break;
41372 	  case ZMEWRT:
41373 			*Sinct = qboxes[QBZMAT].qbinct;
41374 			*iwropt = ZMEopt-ZMEGAM + 1;
41375 	 		if (*iwropt == 5) *iwropt = 7;
41376 			cpstr(qboxes[QBZMAT].str,Sstr,
41377 				strlen(qboxes[QBZMAT].str));
41378 			*Snstr = strlen(qboxes[QBZMAT].str);
41379 			return(1);
41380 			break;
41381 	  case ZMEORD:
41382 			if (!Selecting && !dflag && !cflag) {
41383 			   if (!DoCan(event.xbutton.x_root,
41384 				event.xbutton.y_root,
41385 				"Use ESC to cancel\nUse CNTL to rotate",1)) {
41386 				for (i = 0; i <*xyzp->iatoms; i++)
41387 				   if (i < *xyzp->mxnat) jring[i] = 0;
41388 				Selecting = 1; ZMEsel = 1;
41389 				dflag = 1;
41390 				aflag = *xyzp->iatoms;
41391 				anum = *xyzp->iatoms; acnt = 0;
41392 				XDefineCursor(display,win,AtomCursor);
41393 				strcpy(ZMEerr,"Select Atoms in the order you want the Z-matrix created");
41394 				RedrawStatus();
41395 				DeActZME();
41396 			   }
41397 			}
41398 			break;
41399 	  case ZMESEL:
41400 			strcpy(ZMEerr,selstr);
41401 			RedrawStatus();
41402 			DeActZME();
41403 			Selecting = 1;
41404 			ZoomEnable = True;Select = True;
41405 			break;
41406 	  case ZMEUSEL:
41407 			strcpy(ZMEerr,dselstr);
41408 			ZoomEnable = True;Select = False;
41409 			break;
41410 	  case ZMESELA:
41411 			Selecting = 0;
41412 			nat = 0;
41413 			for ( i = 0; i < *xyzp->iatoms; i++ )
41414 				if (xyzp->iaton[i] > 1) nat++;
41415 			if (!nat) {
41416 				strcpy(ZMEerr,"Invalid Selection: No atoms selected");
41417 				if (*ibell) XBell(display,0);
41418 				RedrawStatus();
41419 				return(0);
41420 			}
41421 			if (nat > *zmptrp->mxzat) {
41422 			   strcpy(ZMEerr,"Invalid Selection: Too many atoms selected");
41423 			   if (*ibell) XBell(display,0);
41424 			   RedrawStatus();
41425 			   for ( i = 0; i < *xyzp->iatoms; i++ )
41426 				if (xyzp->iaton[i] >= 2) xyzp->iaton[i] = 1;
41427 			   update_sel = 1;
41428 		  	   return(1);
41429 			}
41430 			else {
41431 			   AGLAB:
41432 			   nprev = -1;
41433 			   nattmp = 0;
41434 			   for ( i = 0; i < *xyzp->iatoms; i++ ) {
41435 				if (xyzp->iaton[i] >= 2) {
41436 			  	    nattmp++;
41437 				    if (i != nprev+1) {
41438 					for ( j = 0; j < *xyzp->iatoms-i; j++ ) {
41439 					    for (k=0; k < 3; k++)
41440 						xyzp->coo[(nprev+1+j)*3+k] =
41441 						   xyzp->coo[(i+j)*3+k];
41442 					    xyzp->ianz[nprev+1+j] = xyzp->ianz[i+j];
41443 					    xyzp->iaton[nprev+1+j] = xyzp->iaton[i+j];
41444 					    xyzp->iatclr[nprev+1+j] = xyzp->iatclr[i+j];
41445 					    xyzp->iresid[nprev+1+j] = xyzp->iresid[i+j];
41446 					    xyzp->qat[nprev+1+j] = xyzp->qat[i+j];
41447 					    xyzp->ipdbt[nprev+1+j] = xyzp->ipdbt[i+j];
41448 					    xyzp->ityp[nprev+1+j] = xyzp->ityp[i+j];
41449 					}
41450 					if (nattmp < nat) goto AGLAB;
41451 				    }
41452 				    nprev = i;
41453 				}
41454 			   }
41455 		 	   *xyzp->iatoms = nat;
41456 			   cell->ichx = 0; cellpnt->iclon = 0;
41457 			   *ipdbon = 0;
41458 			   ZMEAA = 0;
41459 			   ApplSel(1);
41460 			   empty_model(istruct,1);
41461 			   *Sinct = 530;
41462 			   update_sel = 1;
41463 			   return(1);
41464 			}
41465 			break;
41466           }
41467       }
41468   ScrollPage(NULL,&zscroll,x,y);
41469 
41470   if (DEBUG) fprintf(stderr,"PressZME out\n");
41471   return (0);
41472 }
41473 
ApplSel(iop)41474 void ApplSel(iop)
41475 int iop;
41476 {
41477 int i,j;
41478 
41479    ZME_window_pos = 0;
41480    *doesp = 0;
41481 
41482    if (iop) {
41483 #if defined(VMS) || defined(UNDERSC)
41484 	docent();doconn();doscal();setxyv();
41485 #else
41486 #ifdef CRAY
41487 	DOCENT();DOCONN();DOSCAL();SETXYV();
41488 #else
41489 	docent_();doconn_();doscal_();setxyv_();
41490 #endif
41491 #endif
41492    }
41493 
41494 
41495 
41496 #if defined(VMS) || defined(UNDERSC)
41497    intzmt(&ZERO);
41498 #else
41499 #ifdef CRAY
41500    INTZMT(&ZERO);
41501 #else
41502    intzmt_(&ZERO);
41503 #endif
41504 #endif
41505 
41506    if (qdpptr->ihasq) maparr(NULL,xyzp->qat,NULL,xyzp->ityp,1);
41507    maparr(NULL,NULL,NULL,xyzp->ityp,3);
41508    maparr(NULL,NULL,NULL,xyzp->ipdbt,3);
41509    maparr(NULL,NULL,xyzp->iatclr,NULL,2);
41510    maparr(NULL,NULL,xyzp->iresid,NULL,2);
41511 
41512    for ( i = 0; i < *xyzp->iatoms; i++ ) {
41513 	if (xyzp->iaton[i] >= 2) xyzp->iaton[i] = 1;
41514    }
41515    update_sel = 1;
41516    SetQZME();
41517    RedrawZME();
41518 }
41519 
maparr(flarr,dblarr,intarr,shintarr,iopt)41520 void maparr(flarr,dblarr,intarr,shintarr,iopt)
41521 float *flarr;
41522 double *dblarr;
41523 int *intarr;
41524 short int *shintarr;
41525 int iopt;
41526 {
41527    float *flarrt;
41528    double *dblarrt;
41529    int *intarrt;
41530    short int *shintarrt;
41531    int j;
41532 
41533    switch(iopt) {
41534    case 0:
41535 	if ((flarrt = (float *) malloc((sizeof *flarrt)*(*zmptrp->mxzat)))
41536 	   != NULL) {
41537 
41538 	   for (j=0; j<*zmptrp->nz; j++) {
41539 	      if (zmptrp->imap[j] > 0) {
41540 		flarrt[j] = flarr[zmptrp->imap[j]-1];
41541 	      } else {
41542 		flarrt[j] = 0.0;
41543 	      }
41544 	   }
41545 	   for (j=0; j<*zmptrp->nz; j++) flarr[j] = flarrt[j];
41546 	   free(flarrt);
41547 	}
41548 	break;
41549    case 1:
41550 	if ((dblarrt = (double *) malloc((sizeof *dblarrt)*(*zmptrp->mxzat)))
41551 	   != NULL) {
41552 
41553 	   for (j=0; j<*zmptrp->nz; j++) {
41554 	      if (zmptrp->imap[j] > 0) {
41555 		dblarrt[j] = dblarr[zmptrp->imap[j]-1];
41556 	      } else {
41557 		dblarrt[j] = 0.0;
41558 	      }
41559 	   }
41560 	   for (j=0; j<*zmptrp->nz; j++) dblarr[j] = dblarrt[j];
41561 	   free(dblarrt);
41562 	}
41563 	break;
41564    case 2:
41565 	if ((intarrt = (int *) malloc((sizeof *intarrt)*(*zmptrp->mxzat)))
41566 	   != NULL) {
41567 
41568 	   for (j=0; j<*zmptrp->nz; j++) {
41569 	      if (zmptrp->imap[j] > 0) {
41570 		intarrt[j] = intarr[zmptrp->imap[j]-1];
41571 	      } else {
41572 		intarrt[j] = 0;
41573 	      }
41574 	   }
41575 	   for (j=0; j<*zmptrp->nz; j++) intarr[j] = intarrt[j];
41576 	   free(intarrt);
41577 	}
41578 	break;
41579    case 3:
41580 	if ((shintarrt = (short int *) malloc((sizeof *shintarrt)*(*zmptrp->mxzat)))
41581 	   != NULL) {
41582 
41583 	   for (j=0; j<*zmptrp->nz; j++) {
41584 	      if (zmptrp->imap[j] > 0) {
41585 		shintarrt[j] = shintarr[zmptrp->imap[j]-1];
41586 	      } else {
41587 		shintarrt[j] = 0;
41588 	      }
41589 	   }
41590 	   for (j=0; j<*zmptrp->nz; j++) shintarr[j] = shintarrt[j];
41591 	   free(shintarrt);
41592 	}
41593 	break;
41594    default:
41595 	break;
41596    }
41597 
41598 }
41599 
ScrollBut(i)41600 void ScrollBut(i)
41601 int i;
41602 {
41603 
41604     switch (i) {
41605     case ZMEARR1:
41606 #ifdef HASTIMER
41607         XSync(display, False);
41608 	do {
41609 		if (*zscroll.wn > ZME_window_high)
41610 		   if (ZME_window_pos) {
41611 			ZME_window_pos--;
41612 			RedrawScroll(&zscroll);
41613 			UpdateZME();
41614 			Timer(50,0);
41615 		   }
41616 		}
41617 	while (!XCheckWindowEvent(display, ZMEwin, ButtonReleaseMask, &event));
41618 #else
41619 	if (*zscroll.wn > ZME_window_high) {
41620 	   if (ZME_window_pos) {
41621 		ZME_window_pos--;UpdateZME();
41622 		RedrawScroll(&zscroll);
41623 	   }
41624 	}
41625 #endif
41626 	break;
41627     case ZMEARR2:
41628 #ifdef HASTIMER
41629         XSync(display, False);
41630         do {
41631        		if (*zscroll.wn > ZME_window_high) {
41632            		ZME_window_pos++;
41633                		if (ZME_window_pos > *zscroll.wn-ZME_window_high)
41634 				ZME_window_pos = *zscroll.wn-ZME_window_high;
41635                		else {RedrawScroll(&zscroll); UpdateZME(); }
41636 			Timer(50,0);
41637               	}
41638 	 } while (!XCheckWindowEvent(display, ZMEwin, ButtonReleaseMask, &event));
41639 #else
41640 	if (*zscroll.wn > ZME_window_high) {
41641 		ZME_window_pos++;
41642 		if (ZME_window_pos > *zscroll.wn-ZME_window_high)
41643 			ZME_window_pos = *zscroll.wn-ZME_window_high;
41644 		UpdateZME();
41645 		RedrawScroll(&zscroll);
41646 	}
41647 #endif
41648 	break;
41649     }
41650 }
41651 
41652 
ScrollPage(lp,sc,x,y)41653 int ScrollPage(lp,sc,x,y)
41654 SCRSTRU *sc;
41655 LISTSTRU *lp;
41656 int x;
41657 int y;
41658 {
41659   int i,slidey,slideh,fnd,wposold;
41660   float ZMEScrRatio;
41661   XEvent xev;
41662 
41663   fnd = 0;
41664 
41665 /*
41666    divide number of elements in scroll window (wh)
41667    by total number of elements (wn). Height of slider (slideh)
41668    with respect to height scroll bar (sc->h) has the same ratio
41669    wh : slideh = wn : sc->h
41670    or
41671    wh : wn = slideh : sc->h
41672 */
41673 
41674   if (*sc->wn > 0) ZMEScrRatio = (sc->wh*1.0) / (*sc->wn);
41675   else ZMEScrRatio = 1.0;
41676   if (ZMEScrRatio > 1.0) ZMEScrRatio = 1.0;
41677 
41678   slideh = sc->h * ZMEScrRatio;
41679   if (slideh < SCRMIN) slideh = SCRMIN;
41680 
41681 /* sc->wpos position of first element visible listbox in the element array.
41682   Height per elemnt =  h/wn , Hwpos = wpos*(h/wn)
41683 */
41684 
41685   if (*sc->wn > 0) ZMEScrRatio = (sc->h-slideh)*1.0 / (*sc->wn - sc->wh);
41686   else ZMEScrRatio = 0.0;
41687   slidey = *sc->wpos * ZMEScrRatio;
41688 
41689   if (VIERKANT(x, y, sc->x, sc->y, sc->w, sc->h)) {
41690 	fnd = 2;
41691 /*      clicked on slider */
41692   }
41693   if (VIERKANT(x, y, sc->x, sc->y, sc->w, slidey)) {
41694 	*sc->wpos = *sc->wpos - sc->wh;
41695 	fnd = 1;
41696 /*      clicked above slider */
41697   }
41698   if (VIERKANT(x, y, sc->x, sc->y+slidey+slideh, sc->w,
41699                sc->h-slideh-slidey)) {
41700 	*sc->wpos = *sc->wpos + sc->wh;
41701 	fnd = 1;
41702 /*      clicked below slider */
41703   }
41704   if (VIERKANT(x, y, sc->x, slidey, sc->w,
41705                slideh)) {
41706 	fnd = 2;
41707 /*      clicked below slider */
41708   }
41709 
41710 
41711   wposold = -1;
41712   while (fnd) {
41713 	if (*sc->wpos > (*sc->wn) - 1 - sc->wh) {
41714 	   if ((*sc->wn) - 1 - sc->wh >= 0) {
41715 		*sc->wpos = (*sc->wn) - sc->wh;
41716 	   }
41717 	   else *sc->wpos = 0;
41718 	}
41719 	if (*sc->wpos < 0) *sc->wpos = 0;
41720 
41721         if (*sc->wpos != wposold) {
41722 	   if (sc->win == ZMEwin) {
41723 		UpdateZME();
41724 		RedrawScroll(sc);
41725 	   } else if (sc->win == DPTwin) {
41726 		RedrawScroll(&dptscr[0]);
41727 		UpdateDPT();
41728 	   } else if (lp != NULL) {
41729 		RedrawLBox(lp); RedrawScroll(&lp->scrbar);
41730 	   } else {
41731 		RedrawScroll(sc);
41732 	   }
41733 	   XSync(display,True);
41734 	}
41735 	wposold = *sc->wpos;
41736 
41737 	if (fnd == 1) {
41738 	   return(1);
41739 	} else {
41740 	   XNextEvent(display, &xev);
41741 	   switch (xev.type) {
41742 		case ButtonRelease:
41743 		case LeaveNotify:
41744 		   return(1);
41745 		   break;
41746 		case MotionNotify:
41747 		   if (xev.xmotion.window == sc->win)  {
41748 			*sc->wpos = *sc->wn * ((int) xev.xmotion.y - sc->y)
41749 				/ (int) (sc->h);
41750 		   }
41751 		   break;
41752 	   }
41753 	}
41754   }
41755 
41756   return(0);
41757 
41758 }
41759 
ActVar(isel,itype,butnr)41760 void ActVar(isel,itype,butnr)
41761 int isel;
41762 int itype;
41763 int butnr;
41764 {
41765    int i,j,iptr,ierr;
41766    int *ii;
41767 
41768    i = isel;
41769 
41770    ierr = 0;
41771 
41772    if (butnr == 2) ierr = QBselect(i,itype);
41773 
41774    switch (itype) {
41775 	case 0: ii = &zmptrp->ibl[isel] ; break;
41776 	case 1: ii = &zmptrp->ialph[isel]; break;
41777 	case 2: ii = &zmptrp->ibet[isel]; break;
41778    }
41779 
41780    switch (ABS(*ii)) {
41781 	case 0: strcpy(ZMEerr,"Constant"); break;
41782 	case 1: strcpy(ZMEerr,"Variable"); break;
41783 	default: i = ABS(*ii) - 1;
41784 		 if (*ii < 0) {
41785 			strcpy(ZMEerr,"Negative Linked Variable");
41786 		 } else {
41787 			strcpy(ZMEerr,"Linked Variable");
41788 		 }
41789    }
41790    if (!ierr) RedrawStatus();
41791 
41792    DeActZME();
41793    for (j=0; j<itype+1; j++) {
41794 	iptr = izz(i,j)-1;
41795 	if (iptr < *zmptrp->nz && iptr >= 0) {
41796 		IANZbox[iptr].col = ZC_AT2+j;
41797 		xyzp->iaton[zmptrp->imap[iptr]-1] = 4+j;
41798 	}
41799    }
41800    IANZbox[i].col = ZC_AT1;
41801 
41802    switch (itype) {
41803    case 0:	BLbox[i].active = 1; break;
41804    case 1:	ALPHbox[i].active = 1; break;
41805    case 2:	BETbox[i].active = 1; break;
41806    }
41807 
41808 
41809    if (ZMEAA) {
41810 	CurAmino = -1;
41811 	for (j=0; j<ZME_window_high; j++) {
41812 	   ZMEAAbut[j].lastused = -1;
41813 	   ZMEAAbut[j].bg = 196;
41814 	}
41815    }
41816 
41817    update_model = 0;
41818    update_sel = 1;
41819    UpdateZME();
41820    if (zmptrp->imap[i]-1 >= 0) xyzp->iaton[zmptrp->imap[i]-1] = 3;
41821 
41822 }
41823 
QBselect(isel,itype)41824 int QBselect(isel,itype)
41825 int isel;
41826 int itype;
41827 {
41828     XEvent xev;
41829     int x,y,doit,ierr,ilnkerr,i,icol;
41830     LSSTRU List; int iop; int ltype;
41831 
41832     switch (itype) {
41833 	case 0: x = BLbox[isel].x; y = BLbox[isel].y; break;
41834 	case 1: x = ALPHbox[isel].x; y = ALPHbox[isel].y; break;
41835 	case 2: x = BETbox[isel].x; y = BETbox[isel].y; break;
41836     }
41837 
41838     if (*ipdbon)
41839 	if (xyzp->iresid[isel] > 0) update_res = xyzp->iresid[isel];
41840 
41841     ierr = 0; ilnkerr = 0;
41842     List.list = zmevaropt; List.nents = 6;
41843     if (itype == 2) List.nents = 7;
41844     if (DoPopUp(ZMEwin,x+1,y+BUTTH,&List,&iop,0) == -1) return 0;
41845 
41846     if (iop == 4) {
41847 	animptr.isel = isel;
41848 	animptr.vdirection = 1;
41849 	animptr.frame = 0;
41850 	switch (itype) {
41851 	    case 0:
41852 		animptr.variable = &zmptrp->bl[isel];
41853 		if (zmptrp->ibl[isel] > 1) {
41854 		   animptr.variable = &zmptrp->bl[zmptrp->ibl[isel] - 1];
41855 		   animptr.isel = zmptrp->ibl[isel] - 1;
41856 		}
41857 		break;
41858 	    case 1:
41859 		animptr.variable = &zmptrp->alph[isel];
41860 		if (zmptrp->ialph[isel] > 1) {
41861 		   animptr.variable = &zmptrp->alph[zmptrp->ialph[isel] - 1];
41862 		   animptr.isel = zmptrp->ialph[isel] - 1;
41863 		}
41864 		break;
41865 	    case 2:
41866 		animptr.variable = &zmptrp->bet[isel];
41867 		if (ABS(zmptrp->ibet[isel]) > 1) {
41868 		   animptr.variable = &zmptrp->bet[ABS(zmptrp->ibet[isel])-1];
41869 		   animptr.isel = ABS(zmptrp->ibet[isel])-1;
41870 		}
41871 		break;
41872 	}
41873 	animptr.varinit = *animptr.variable;
41874 	animptr.vartype = itype;
41875 	if (IsPhiPsi(isel)) {
41876 	   FindZRangeFromBox(isel);
41877 	   if (zmpart->ipart) {
41878 		animptr.part = zmpart->ipart;
41879 		zmpart->imx = *zmptrp->nz;
41880 		update_res = -1;
41881 		animptr.ssdone = 0;
41882 	   }
41883 	} else {
41884 	   FindZRangeFromBox(isel);
41885 	   if (zmpart->ipart) animptr.part = zmpart->ipart;
41886 	}
41887 	*Sinct = 530;
41888 	InitANIM(event.xbutton.x_root,event.xbutton.y_root);
41889 	RedrawZME();
41890 	animptr.on = 1;
41891         return(0);
41892     }
41893     if (iop > 4) iop--;
41894 
41895     if (iop == 2 || iop == 3) {
41896 	if (iop == 2) icol = ZC_MARK;
41897 	if (iop == 3) {
41898 	    switch (itype) {
41899 	    case 0: iop = zmptrp->ibl[isel]; break;
41900 	    case 1: iop = zmptrp->ialph[isel]; break;
41901 	    case 2: iop = zmptrp->ibet[isel]; break;
41902 	    }
41903 	    switch (iop) {
41904 		case 0: icol = ZC_CONST; break;
41905 		case 1: icol = ZC_VAR; break;
41906 		default: icol = ZC_LINK;
41907 	    }
41908 	}
41909 	switch (itype) {
41910 	case 0: BLbox[isel].col = icol; break;
41911 	case 1: ALPHbox[isel].col = icol; break;
41912 	case 2: BETbox[isel].col = icol; break;
41913 	}
41914 	return(0);
41915     }
41916 
41917     if (iop > 3) {
41918       switch (itype) {
41919 	case 0: strcpy(ZMEerr,"Click on a Z-matrix Bondlength"); break;
41920 	case 1: strcpy(ZMEerr,"Click on a Z-matrix BondAngle"); break;
41921 	case 2: strcpy(ZMEerr,"Click on a Z-matrix Dihedral"); break;
41922       }
41923       if (*ibell) XBell(display,0);
41924       RedrawStatus();
41925       ltype = 1;
41926       if (iop == 5) ltype = -1;
41927       doit = 1;
41928       while (doit) {
41929         XNextEvent(display, &xev);
41930         if (xev.xexpose.window == ZMEwin) {
41931 	    switch (xev.type) {
41932 
41933 		case Expose:	RedrawZME(); break;
41934 		case ButtonPress:
41935 		    i = Clickwin(ZMEbut,ZMEBUTTS,xev.xbutton.x,xev.xbutton.y,1);
41936 
41937 		    if (i>=0) {
41938 			switch (i) {
41939 			    case ZMEARR1: ScrollBut(i); break;
41940 			    case ZMEARR2: ScrollBut(i); break;
41941 			}
41942 			break;
41943 		    }
41944 		    if (ScrollPage(NULL,&zscroll,xev.xbutton.x,xev.xbutton.y))
41945 			break;
41946                     iop = 1;
41947 		    switch (itype) {
41948 			case 0: iop = 1+ClickBox(BLbox,*zmptrp->nz,
41949 						xev.xbutton.x,xev.xbutton.y);
41950 				if (ABS(zmptrp->ibl[iop-1]) > 1) ilnkerr = 1;
41951 				break;
41952 			case 1: iop = 1+ClickBox(ALPHbox,*zmptrp->nz,
41953 						xev.xbutton.x,xev.xbutton.y);
41954 				if (ABS(zmptrp->ialph[iop-1]) > 1) ilnkerr = 1;
41955 				break;
41956 			case 2: iop = 1+ClickBox(BETbox,*zmptrp->nz,
41957 						xev.xbutton.x,xev.xbutton.y);
41958 				if (ABS(zmptrp->ibet[iop-1]) > 1) ilnkerr = 1;
41959 				break;
41960 		    }
41961 
41962 		    if (!iop) {
41963 			iop = 1;
41964 			strcpy(ZMEerr,"No suitable variable chosen");
41965 			ierr = 1;
41966 		    }
41967 		    if (iop > isel) {
41968 			iop = 1;
41969 			strcpy(ZMEerr,"ERROR: Link only to earlier defined variable");
41970 			ierr = 1;
41971 		    }
41972 		    if (ilnkerr) {
41973 			iop = 1;
41974 			strcpy(ZMEerr,"ERROR: CAN Not link to a linked variable");
41975 			ierr = 1;
41976 		    }
41977 		    if (ierr) {
41978 			if (*ibell) XBell(display,0);
41979       			RedrawStatus();
41980 		    }
41981 		    iop = iop * ltype;
41982 		    if (iop == -1) iop = 1;
41983 		    doit = 0;
41984             }
41985 	}
41986       }
41987     }
41988     switch (iop) {
41989 	case 0: icol = ZC_CONST; break;
41990 	case 1: icol = ZC_VAR; break;
41991 	default: icol = ZC_LINK;
41992     }
41993     switch (itype) {
41994 	case 0:
41995 		zmptrp->ibl[isel] = iop;
41996 		BLbox[isel].col = icol;
41997 		BLbox[isel].changed = 1;
41998 		break;
41999 	case 1:
42000 		zmptrp->ialph[isel] = iop;
42001 		ALPHbox[isel].col = icol;
42002 		ALPHbox[isel].changed = 1;
42003 		break;
42004 	case 2:
42005 		zmptrp->ibet[isel] = iop;
42006 		BETbox[isel].col = icol;
42007 		BETbox[isel].changed = 1;
42008 		break;
42009     }
42010     /*fprintf(stderr,"itype %d , %d\n",itype,iop);*/
42011     if (ABS(iop) > 1) {GetQZME();*Sinct = 530; }
42012     return (ierr);
42013 }
42014 
SwitchOffAnim()42015 void SwitchOffAnim()
42016 {
42017 	if (!animptr.on) return;
42018 
42019 	animptr.on = 0;
42020 	if (animptr.part) zmpart->ipart = animptr.part;
42021 	*animptr.variable = animptr.varinit;
42022 	if (!animptr.ssdone) SSdone[istruct] = 0;
42023 	AnimLinks(animptr.varinit);
42024 	anim();
42025 	if (*ipdbon) presetp();
42026         update_res = -1;
42027 	animptr.part = 0;
42028 	animptr.ssdone = 1;
42029 	if (ANIMup) {
42030 	   XDestroyWindow(display,ANIMwin);
42031 	   ANIMup = 0;
42032 	}
42033 	XSync(display, False);
42034 }
42035 
AnimLinks(vartmp)42036 void AnimLinks(vartmp)
42037 double vartmp;
42038 {
42039 	int i;
42040 
42041 	switch (animptr.vartype) {
42042 	   case 0:
42043 		sprintf(BLbox[animptr.isel].str,"%f",vartmp);
42044 		PromptBox(&BLbox[animptr.isel]);
42045 		break;
42046 	   case 1:
42047 		sprintf(ALPHbox[animptr.isel].str,"%f",vartmp);
42048 		PromptBox(&ALPHbox[animptr.isel]);
42049 		break;
42050 	   case 2:
42051 		sprintf(BETbox[animptr.isel].str,"%f",vartmp);
42052 		PromptBox(&BETbox[animptr.isel]);
42053 		break;
42054 	}
42055 
42056 	if (zmpart->ipart) return;
42057 
42058 	for (i=0; i<*zmptrp->nz; i++) {
42059 	    switch (animptr.vartype) {
42060 		case 0:
42061 		   if (zmptrp->ibl[i] > 1 &&
42062 			zmptrp->ibl[i] - 1 == animptr.isel)
42063 			zmptrp->bl[i] = vartmp;
42064 		   break;
42065 		case 1:
42066 		   if (zmptrp->ialph[i] > 1 &&
42067 			zmptrp->ialph[i] - 1 == animptr.isel)
42068 			zmptrp->alph[i] = vartmp;
42069 		   break;
42070 		case 2:
42071 		   if (ABS(zmptrp->ibet[i]) > 1 &&
42072 			ABS(zmptrp->ibet[i]) - 1 == animptr.isel) {
42073 			if (zmptrp->ibet[i] > 0) {
42074 			   zmptrp->bet[i] = vartmp;
42075 			} else {
42076 			   zmptrp->bet[i] = -vartmp;
42077 			}
42078 		   }
42079 		   break;
42080 	    }
42081 	}
42082 }
42083 
DefSlide(sc,win,x,y,w,h,sh,wn,wpos,rat,callback)42084 void DefSlide(sc,win,x,y,w,h,sh,wn,wpos,rat,callback)
42085 SLIDESTRU	*sc;
42086 Window		win;
42087 int		x,y;
42088 unsigned int	w,h;
42089 int		sh;
42090 int		*wn;
42091 int		*wpos;
42092 float		*rat;
42093 ptr_void_proc	callback;
42094 {
42095   sc->win = win;
42096   sc->x = x;  sc->y = y;  sc->w = w;  sc->h = h;
42097   sc->wn = wn;
42098   sc->wpos = wpos;
42099   sc->ratio = rat;
42100   *sc->ratio = *wpos / *wn;
42101   sc->sh = sh;
42102   sc->callback = callback;
42103 }
42104 
42105 
RedrawSlide(sc)42106 void RedrawSlide(sc)
42107 SLIDESTRU *sc;
42108 {
42109   int slidey,slideh;
42110 
42111   slideh = sc->sh;
42112   slidey = (int) (sc->h - sc->sh) * (*sc->ratio);
42113 
42114   butje(sc->win, sc->x, sc->y,        sc->w, sc->h ,3,0,0,0,None,0,0,0);
42115   butje(sc->win, sc->x, sc->y+slidey, sc->w, slideh,3,0,0,1,None,0,0,0);
42116 
42117 }
42118 
SlideScroll(sc,x,y)42119 int SlideScroll(sc,x,y)
42120 SLIDESTRU *sc;
42121 int x;
42122 int y;
42123 {
42124   int i,inslide,wposold;
42125   XEvent xev;
42126 
42127   inslide = 0;
42128   if (VIERKANT(x, y, sc->x, sc->y, sc->w, sc->h)) {
42129 	inslide = 1;
42130   }
42131 
42132   wposold = -1;
42133   while (inslide) {
42134 
42135 	if (*sc->wpos > *sc->wn) *sc->wpos = *sc->wn;
42136 	if (*sc->wpos < 0) *sc->wpos = 0;
42137 
42138         if (*sc->wpos != wposold) {
42139 	   RedrawSlide(sc);
42140 	   if (sc->win == OMAPwin) sc->callback();
42141 	   XSync(display,True);
42142 	}
42143 	wposold = *sc->wpos;
42144 
42145 	   XNextEvent(display, &xev);
42146 	   switch (xev.type) {
42147 		case ButtonRelease:
42148 		case LeaveNotify:
42149 		   return(1);
42150 		   break;
42151 		case MotionNotify:
42152 		   if (xev.xmotion.window == sc->win)  {
42153 			*sc->ratio = ((float) xev.xmotion.y - (float) sc->y)
42154 				/ (float) (sc->h - sc->sh);
42155 			if (*sc->ratio < 0.0) *sc->ratio = 0.0;
42156 			if (*sc->ratio > 1.0) *sc->ratio = 1.0;
42157 			*sc->wpos = *sc->wn * (*sc->ratio);
42158 		   }
42159 		   break;
42160 	   }
42161   }
42162 
42163   return(0);
42164 
42165 }
42166 
DefScroll(sc,win,x,y,w,h,wn,wpos,wh,callback)42167 void DefScroll(sc,win,x,y,w,h,wn,wpos,wh,callback)
42168 SCRSTRU		*sc;
42169 Window		win;
42170 int		x,y;
42171 unsigned int	w,h;
42172 int		*wn;
42173 int		*wpos;
42174 int		wh;
42175 ptr_void_proc	callback;
42176 {
42177   sc->win = win;
42178   sc->x = x;  sc->y = y;  sc->w = w;  sc->h = h;
42179   sc->wn = wn;
42180   sc->wpos = wpos;
42181   sc->wh = wh;
42182   sc->callback = callback;
42183 }
42184 
42185 
RedrawScroll(sc)42186 void RedrawScroll(sc)
42187 SCRSTRU		*sc;
42188 {
42189   int slidey,slideh;
42190   float ZMEScrRatio;
42191 
42192   if (*sc->wn > 0) ZMEScrRatio = (sc->wh*1.0) / (*sc->wn);
42193   else ZMEScrRatio = 1.0;
42194   if (ZMEScrRatio > 1.0) ZMEScrRatio = 1.0;
42195   slideh = (int) sc->h * ZMEScrRatio;
42196   if (slideh < 5) slideh = SCRMIN;
42197   if (*sc->wn > 0) ZMEScrRatio = (*sc->wpos)*1.0 / (*sc->wn);
42198   else ZMEScrRatio = 0.0;
42199   slidey = (int) sc->h * ZMEScrRatio;
42200   if (sc->h - slidey < slideh) slidey = sc->h - slideh;
42201 
42202   butje(sc->win, sc->x, sc->y,        sc->w, sc->h ,3,0,0,0,None,0,0,0);
42203   butje(sc->win, sc->x, sc->y+slidey, sc->w, slideh,3,0,0,1,None,0,0,0);
42204 
42205 }
42206 
DeActZME()42207 void DeActZME()
42208 {
42209   int i,j,type,iptr;
42210 
42211   if (!ZMEup) return;
42212 
42213   if (qboxes[QBZMAT].active) {
42214 	qboxes[QBZMAT].active = 0;
42215 	PromptBox(&qboxes[QBZMAT]);
42216 	return;
42217   }
42218   if (EXPbox[0].active) {
42219 	EXPbox[0].active = 0;
42220 	PromptBox(&EXPbox[0]);
42221 	return;
42222   }
42223   activeZME(&type,&i,&j);
42224   switch(type) {
42225   case 0:
42226 	IANZbox[i].col = ZC_DEF;
42227 	IANZbox[i].active = 0;
42228 	if (zmptrp->imap[i]-1 >= 0)
42229 		xyzp->iaton[zmptrp->imap[i]-1] = 1;
42230 	break;
42231   case 1:
42232 	iptr = izz(i,0)-1;
42233 	if (iptr < *zmptrp->nz && iptr >= 0) {
42234 		IANZbox[iptr].col = ZC_DEF;
42235 		xyzp->iaton[zmptrp->imap[iptr]-1] = 1;
42236 	}
42237 	IANZbox[i].col = ZC_DEF;
42238 	BLbox[i].active = 0;
42239 	if (zmptrp->imap[i]-1 >= 0)
42240 		xyzp->iaton[zmptrp->imap[i]-1] = 1;
42241 	break;
42242   case 2:
42243 	for (j=0; j<2; j++) {
42244 		iptr = izz(i,j)-1;
42245 		if (iptr < *zmptrp->nz && iptr >= 0) {
42246 			IANZbox[iptr].col = ZC_DEF;
42247 			xyzp->iaton[zmptrp->imap[iptr]-1] = 1;
42248 		}
42249 	}
42250 	IANZbox[i].col = ZC_DEF;
42251 	ALPHbox[i].active = 0;
42252 	if (zmptrp->imap[i]-1 >= 0)
42253 		xyzp->iaton[zmptrp->imap[i]-1] = 1;
42254 	break;
42255   case 3:
42256 	for (j=0; j<3; j++) {
42257 		iptr = izz(i,j)-1;
42258 		if (iptr < *zmptrp->nz && iptr >= 0) {
42259 			IANZbox[iptr].col = ZC_DEF;
42260 			xyzp->iaton[zmptrp->imap[iptr]-1] = 1;
42261 		}
42262 	}
42263 	IANZbox[i].col = ZC_DEF;
42264 	BETbox[i].active = 0;
42265 	if (zmptrp->imap[i]-1 >= 0)
42266 		xyzp->iaton[zmptrp->imap[i]-1] = 1;
42267 	break;
42268   case 4:
42269 	iptr = izz(i,j)-1;
42270 	if (iptr < *zmptrp->nz && iptr >= 0) {
42271 		IANZbox[iptr].col = ZC_DEF;
42272 		xyzp->iaton[zmptrp->imap[iptr]-1] = 1;
42273 	}
42274 	IANZbox[i].col = ZC_DEF;
42275 	IZbox[i*4+j].active = 0;
42276 	if (zmptrp->imap[i]-1 >= 0)
42277 		xyzp->iaton[zmptrp->imap[i]-1] = 1;
42278 	break;
42279   }
42280   update_sel = 1;
42281 }
42282 
UndoZME()42283 void UndoZME()
42284 {
42285   int i,j,type;
42286 
42287   activeZME(&type,&i,&j);
42288   switch(type) {
42289   case 0:
42290         if (zmptrp->ianz[i] >= 0 && zmptrp->ianz[i] < 100)
42291              sprintf(stemp,"%s",elements[zmptrp->ianz[i]]);
42292         else sprintf(stemp,"%s","?");
42293 	strcpy(IANZbox[i].str,stemp);
42294 	PromptBox(&IANZbox[i]);
42295 	break;
42296   case 1:
42297 	sprintf(stemp,"%f",zmptrp->bl[i]);
42298 	strcpy(BLbox[i].str,stemp);
42299 	PromptBox(&BLbox[i]);
42300 	break;
42301   case 2:
42302 	sprintf(stemp,"%f",zmptrp->alph[i]);
42303 	strcpy(ALPHbox[i].str,stemp);
42304 	PromptBox(&ALPHbox[i]);
42305 	break;
42306   case 3:
42307 	sprintf(stemp,"%f",zmptrp->bet[i]);
42308 	strcpy(BETbox[i].str,stemp);
42309 	PromptBox(&BETbox[i]);
42310 	break;
42311   case 4:
42312 	sprintf(stemp,"%d",izz(i,j));
42313 	strcpy(IZbox[i*4+j].str,stemp);
42314 	PromptBox(&IZbox[i*4+j]);
42315 	break;
42316   }
42317 }
42318 
42319 
activeZME(type,row,column)42320 void activeZME(type,row,column)
42321 int *type;
42322 int *row;
42323 int *column;
42324 {
42325   int i,j;
42326 
42327   *type = -1;
42328   *column = 0;
42329   for (i=0; i<*zmptrp->nz; i++) {
42330 	if (IANZbox[i].active) {
42331 	   *type = 0; *row = i;
42332 	}
42333 	if (BLbox[i].active) {
42334 	   *type = 1; *row = i;
42335 	}
42336 	if (ALPHbox[i].active) {
42337 	   *type = 2; *row = i;
42338 	}
42339 	if (BETbox[i].active) {
42340 	   *type = 3; *row = i;
42341 	}
42342 	for (j=0; j<4; j++) {
42343 		if (IZbox[i*4+j].active) {
42344 	   	   *type = 4; *row = i; *column = j;
42345 		}
42346 	}
42347   }
42348 }
42349 
FindInd(ival,iarr,idimens)42350 int FindInd(ival,iarr,idimens)
42351 int ival;
42352 int *iarr;
42353 int idimens;
42354 {
42355 	int i;
42356 
42357 	for (i=0; i<idimens; i++)
42358 		if (ival == iarr[i]) return(i);
42359 	return(-1);
42360 }
42361 
42362 typedef unsigned char Byte;
42363 #ifdef _LONGLONG
42364 typedef unsigned int Card;
42365 #else
42366 typedef unsigned long Card;
42367 #endif
42368 
42369 static XImage *image;
42370 static FILE *GIFFile;
42371 static int LZWClrCode;
42372 static int LZWEOICode;
42373 static short store1[4096];
42374 static short store2[4096];
42375 static short HashTable[256];
42376 static Byte UsedColors[4096];
42377 static int UsedCol[256];
42378 static Byte Buffer[256];
42379 static Byte MapPixel[256];
42380 static Card BitBuffer;
42381 static int BitBufLen;
42382 static int ByteCount;
42383 static int CodeSize;
42384 static Byte pix2col[256],red[256],green[256],blue[256];
42385 
CompressCMap()42386 int CompressCMap()
42387 {
42388     register int i,x,y, NumUsedColors;
42389 
42390     for (i=0; i<256; i++) {
42391         MapPixel[colors[i]] = i;
42392         Buffer[i] = 0;
42393         UsedCol[i] = 5;
42394     }
42395 
42396     NumUsedColors = 0;
42397 
42398     for (x=0; x < width; x++) {
42399 	for (y=0; y < height; y++) {
42400 	    i = MapPixel[XGetPixel(image,x,y)];
42401 	    if( !Buffer[i] )
42402 	    {   UsedCol[NumUsedColors++] = i;
42403 		Buffer[i] = NumUsedColors;
42404 	    }
42405 	}
42406     }
42407 
42408     for (i=0; i<256; i++)
42409         MapPixel[i] = Buffer[MapPixel[i]]-1;
42410     return (NumUsedColors);
42411 }
42412 
MapPixel24(pixval)42413 int MapPixel24(pixval)
42414     unsigned long pixval;
42415 {
42416     int i;
42417 
42418     for (i=255; i>=0; i--) {
42419 	if (pixval == colors[i]) return(i);
42420     }
42421 
42422     return(0);
42423 }
42424 
MapPixel24U(pixval,NumUsedColors)42425 int MapPixel24U(pixval,NumUsedColors)
42426     unsigned long pixval;
42427     int NumUsedColors;
42428 {
42429     int i;
42430 
42431     for (i=0; i<NumUsedColors; i++) {
42432 	if (pixval == colors[UsedCol[i]]) return(i);
42433     }
42434 
42435     return(0);
42436 }
42437 
FakeCompress24()42438 int FakeCompress24()
42439 {
42440     register int i,x,y, NumUsedColors;
42441 
42442     for (i=0; i<256; i++) {
42443         Buffer[i] = 0;
42444         UsedCol[i] = 5;
42445     }
42446 
42447     NumUsedColors = 0;
42448 
42449     for (x=0; x < width; x++) {
42450 	for (y=0; y < height; y++) {
42451 	    i = MapPixel24(XGetPixel(image,x,y));
42452 	    if( !Buffer[i] )
42453 	    {   UsedCol[NumUsedColors++] = i;
42454 		Buffer[i] = NumUsedColors;
42455 	    }
42456 	}
42457     }
42458 
42459     return (NumUsedColors);
42460 }
42461 
42462 
LZWwrite(code)42463 void LZWwrite(code)
42464     int code;
42465 {
42466     register int max;
42467 
42468     max = (code==LZWEOICode)? 0 : 7;
42469     BitBuffer |= ((Card)code<<BitBufLen);
42470     BitBufLen += CodeSize;
42471 
42472     while (BitBufLen > max) {
42473          Buffer[ByteCount++]=BitBuffer;
42474          BitBuffer >>= 8;
42475          BitBufLen -= 8;
42476 
42477         if (ByteCount==255) {
42478 	    fputc(0xff,GIFFile);
42479             fwrite((char*)Buffer,1,255,GIFFile);
42480             ByteCount = 0;
42481         }
42482     }
42483 }
42484 
compress(BitsPerPixel,NumUsedColors,imag,do24)42485 void compress(BitsPerPixel,NumUsedColors,imag,do24)
42486     int BitsPerPixel;
42487     int NumUsedColors;
42488     int do24;
42489     Byte *imag;
42490 {
42491     register int i,CurrentColor;
42492     register int Prefix,next,last,ilast;
42493     register unsigned long pixel;
42494     register short *prev;
42495     register int x,y;
42496     int istart;
42497 
42498     ByteCount=0; BitBuffer=0; BitBufLen=0;
42499 
42500     LZWClrCode = (1<<BitsPerPixel);
42501     LZWEOICode = LZWClrCode + 1;
42502     ilast = (LZWClrCode<<1) - LZWEOICode;
42503     BitsPerPixel++;
42504 
42505     for( i=0; i<NumUsedColors; i++ )
42506         HashTable[i]=0;
42507     CodeSize = BitsPerPixel;
42508     next = 1; last = ilast;
42509 
42510 /* begin of compression */
42511 
42512     LZWwrite(LZWClrCode);
42513 
42514     istart = 0;
42515     Prefix = 0;
42516     prev = (short *)0;
42517 
42518     for (y=0; y<height; y++) {
42519         for (x=0; x<width; x++) {
42520 	    if (do24 == 2) {
42521 		pixel = imag[(height-(y+1))*width+x];
42522 	    } else {
42523 		pixel = XGetPixel(image,x,y);
42524 	    }
42525 	    if (!istart) {
42526 		if (do24 == 2) Prefix = pix2col[pixel];
42527 		else if (do24) Prefix = MapPixel24U(pixel,NumUsedColors);
42528 		else Prefix = MapPixel[pixel];
42529                 prev = HashTable+Prefix;
42530                 istart = 1;
42531                 continue;
42532             }
42533 
42534 	    if (do24 == 2) CurrentColor = pix2col[pixel];
42535 	    else if (do24) CurrentColor = MapPixel24U(pixel,NumUsedColors);
42536             else CurrentColor = MapPixel[pixel];
42537 
42538             while (*prev && (UsedColors[*prev] != (Byte)CurrentColor))
42539                 prev = store1+*prev;
42540 
42541             if (*prev) {
42542 		Prefix = *prev+LZWEOICode; prev = store2+*prev;
42543             } else {
42544 		LZWwrite(Prefix);
42545                 if (next==last) {
42546 		    if (CodeSize==12) {
42547 			LZWwrite(LZWClrCode);
42548                         Prefix = CurrentColor;  prev = HashTable+CurrentColor;
42549                         for( i=0; i<NumUsedColors; i++ )
42550                             HashTable[i] = 0;
42551                         CodeSize = BitsPerPixel;
42552                         next = 1; last = ilast;
42553                         continue;
42554                     }
42555                     last = (last<<1)+LZWEOICode;
42556                     CodeSize++;
42557                 }
42558                 *prev = next;
42559                 store1[next] = 0; store2[next] = 0;
42560                 UsedColors[next] = CurrentColor;
42561                 prev = HashTable+CurrentColor; Prefix = CurrentColor;
42562                 next++;
42563             }
42564         }
42565     }
42566 
42567 
42568     LZWwrite(Prefix);
42569 
42570 /* end of compression */
42571 
42572     LZWwrite(LZWEOICode);
42573 
42574 /* write last buffer */
42575 
42576     if (ByteCount) {
42577 	fputc(ByteCount,GIFFile);
42578         fwrite((char*)Buffer,1,ByteCount,GIFFile);
42579     }
42580 
42581 /* zero byte count terminates Raster Data stream */
42582 
42583     fputc(0x00,GIFFile);
42584 }
42585 
42586 
ToGIF(win,filename)42587 void ToGIF(win,filename)
42588     char *filename;
42589     Drawable win;
42590 {
42591     int i,NumUsedColors,BitsPerPixel,do24;
42592     XColor exact_def;
42593     Byte *imag = NULL;
42594 
42595     GIFFile = fopen(filename,"w");
42596     if (!GIFFile) {
42597 	fprintf(stderr,"Output Error: Unable to create GIF file %s\n",filename);
42598 	return;
42599     }
42600 
42601     do24 = 0;
42602     if (DisplayPlanes(display, screen) > 8) do24 = 1;
42603 
42604     image = XGetImage(display,win,0,0,width,height,AllPlanes,ZPixmap);
42605 
42606     if (image == NULL) {
42607 	fprintf(stderr,"Output Error: Unable to create GIF file\n");
42608 	return;
42609     }
42610 
42611     if (do24) NumUsedColors = FakeCompress24();
42612     else NumUsedColors = CompressCMap();
42613 
42614     if (NumUsedColors<2) {
42615 	XDestroyImage(image);
42616 	return;
42617     }
42618 
42619     for (BitsPerPixel=0; BitsPerPixel<8; BitsPerPixel++)
42620         if( (1<<BitsPerPixel)>=NumUsedColors ) break;
42621     NumUsedColors = 1<<BitsPerPixel;
42622 
42623 /* Signature */
42624 
42625     fwrite("GIF87a",1,6,GIFFile);
42626 
42627 /* Screen descriptor */
42628 
42629     fputc(width&0xff,GIFFile);  fputc((width>>8)&0xff,GIFFile);
42630     fputc(height&0xff,GIFFile);  fputc((height>>8)&0xff,GIFFile);
42631     fputc(0xf0|(BitsPerPixel-1),GIFFile);
42632     fputc(0x00,GIFFile);
42633     fputc(0x00,GIFFile);
42634 
42635 /* Global Colormap */
42636 
42637 
42638 
42639     for (i=0; i<NumUsedColors; i++) {
42640 	exact_def.pixel = colors[UsedCol[i]];
42641 	XQueryColor(display,cmap,&exact_def);
42642         fputc((int)exact_def.red>>8,GIFFile);
42643         fputc((int)exact_def.green>>8,GIFFile);
42644         fputc((int)exact_def.blue>>8,GIFFile);
42645     }
42646 
42647 /* Image Descriptor */
42648 
42649     fputc(',',GIFFile);
42650     fputc(0x00,GIFFile); fputc(0x00,GIFFile);
42651     fputc(0x00,GIFFile); fputc(0x00,GIFFile);
42652     fputc(width&0xff,GIFFile); fputc((width>>8)&0xff,GIFFile);
42653     fputc(height&0xff,GIFFile); fputc((height>>8)&0xff,GIFFile);
42654     fputc(0x00,GIFFile); fputc(BitsPerPixel,GIFFile);
42655 
42656 /* Raster Data */
42657 
42658     compress(BitsPerPixel,NumUsedColors,imag,do24);
42659 
42660 /* Gif Terminator */
42661 
42662     fputc(';',GIFFile);
42663     fclose(GIFFile);
42664 
42665     XDestroyImage(image);
42666     return;
42667 }
42668 
42669 #define RANGE(a,b,c) { if (a < b) a = b;  if (a > c) a = c; }
42670 #define MAXCOL  256
42671 #define BOX_DIM  128
42672 
42673 typedef unsigned short histcell;
42674 typedef unsigned short * histptr;
42675 typedef unsigned short hist1d[32];
42676 typedef hist1d hist2d[64];
42677 typedef hist2d hist3d[32];
42678 static hist2d * histogram;
42679 
42680 typedef struct {
42681   int rmin, rmax;
42682   int gmin, gmax;
42683   int bmin, bmax;
42684   int volume;
42685   long colorcount;
42686 } box;
42687 typedef box * boxptr;
42688 
42689 static short * fserrors;
42690 static int * maxerr;
42691 static unsigned char * clmap[3];
42692 static int num_colors;
42693 
initz(s,len)42694 void initz(s, len)
42695      char   *s;
42696      size_t  len;
42697 {
42698   for ( ; len>0; len--) *s++ = 0;
42699 }
42700 
inithis(rgbimg,npix)42701 void inithis(rgbimg, npix)
42702 Byte *rgbimg;
42703 int   npix;
42704 {
42705   histptr histp;
42706 
42707   initz((char *) histogram, sizeof(hist3d));
42708 
42709   while (npix-- > 0) {
42710     histp = & histogram[rgbimg[0]/8] [rgbimg[1]/4] [rgbimg[2]/8];
42711     if (++(*histp) <= 0)
42712       (*histp)--;
42713     rgbimg += 3;
42714   }
42715 }
42716 
cbmax(boxlist,nbox)42717 boxptr cbmax(boxlist, nbox)
42718 boxptr boxlist;
42719 int nbox;
42720 {
42721   boxptr boxp, w = NULL;
42722   int i, maxc = 0;
42723 
42724   for (i = 0, boxp = boxlist; i < nbox; i++, boxp++) {
42725     if (boxp->colorcount > maxc && boxp->volume > 0) {
42726       w = boxp;
42727       maxc = boxp->colorcount;
42728     }
42729   }
42730   return w;
42731 }
42732 
42733 
colmax(bl,nbox)42734 boxptr colmax(bl, nbox)
42735 boxptr bl;
42736 int nbox;
42737 {
42738   boxptr boxp;
42739   int i;
42740   int maxv = 0;
42741   boxptr wh = NULL;
42742 
42743   for (i = 0, boxp = bl; i < nbox; i++, boxp++) {
42744     if (boxp->volume > maxv) {
42745       wh = boxp;
42746       maxv = boxp->volume;
42747     }
42748   }
42749   return wh;
42750 }
42751 
42752 /* based on jpeg library routine */
42753 
boxupd(boxp)42754 void boxupd(boxp)
42755 boxptr boxp;
42756 {
42757   histptr histp;
42758   int r,g,b;
42759   int rmin,rmax,gmin,gmax,bmin,bmax;
42760   int dr,dg,db;
42761   long ccount;
42762 
42763   rmin = boxp->rmin;
42764   rmax = boxp->rmax;
42765   gmin = boxp->gmin;
42766   gmax = boxp->gmax;
42767   bmin = boxp->bmin;
42768   bmax = boxp->bmax;
42769 
42770   if (rmax > rmin)
42771     for (r = rmin; r <= rmax; r++)
42772       for (g = gmin; g <= gmax; g++) {
42773 	histp = &histogram[r][g][bmin];
42774 	for (b = bmin; b <= bmax; b++)
42775 	  if (*histp++ != 0) {
42776 	    boxp->rmin = rmin = r;
42777 	    goto have_rmin;
42778 	  }
42779       }
42780  have_rmin:
42781   if (rmax > rmin)
42782     for (r = rmax; r >= rmin; r--)
42783       for (g = gmin; g <= gmax; g++) {
42784 	histp = &histogram[r][g][bmin];
42785 	for (b = bmin; b <= bmax; b++)
42786 	  if (*histp++ != 0) {
42787 	    boxp->rmax = rmax = r;
42788 	    goto have_rmax;
42789 	  }
42790       }
42791  have_rmax:
42792   if (gmax > gmin)
42793     for (g = gmin; g <= gmax; g++)
42794       for (r = rmin; r <= rmax; r++) {
42795 	histp = &histogram[r][g][bmin];
42796 	for (b = bmin; b <= bmax; b++)
42797 	  if (*histp++ != 0) {
42798 	    boxp->gmin = gmin = g;
42799 	    goto have_gmin;
42800 	  }
42801       }
42802  have_gmin:
42803   if (gmax > gmin)
42804     for (g = gmax; g >= gmin; g--)
42805       for (r = rmin; r <= rmax; r++) {
42806 	histp = &histogram[r][g][bmin];
42807 	for (b = bmin; b <= bmax; b++)
42808 	  if (*histp++ != 0) {
42809 	    boxp->gmax = gmax = g;
42810 	    goto have_gmax;
42811 	  }
42812       }
42813  have_gmax:
42814   if (bmax > bmin)
42815     for (b = bmin; b <= bmax; b++)
42816       for (r = rmin; r <= rmax; r++) {
42817 	histp = &histogram[r][gmin][b];
42818 	for (g = gmin; g <= gmax; g++, histp += 32)
42819 	  if (*histp != 0) {
42820 	    boxp->bmin = bmin = b;
42821 	    goto have_bmin;
42822 	  }
42823       }
42824  have_bmin:
42825   if (bmax > bmin)
42826     for (b = bmax; b >= bmin; b--)
42827       for (r = rmin; r <= rmax; r++) {
42828 	histp = &histogram[r][gmin][b];
42829 	for (g = gmin; g <= gmax; g++, histp += 32)
42830 	  if (*histp != 0) {
42831 	    boxp->bmax = bmax = b;
42832 	    goto have_bmax;
42833 	  }
42834       }
42835  have_bmax:
42836 
42837   dr = (rmax - rmin) * 16;
42838   dg = (gmax - gmin) * 12;
42839   db = (bmax - bmin) *  8;
42840   boxp->volume = dr*dr + dg*dg + db*db;
42841 
42842   ccount = 0;
42843   for (r = rmin; r <= rmax; r++)
42844     for (g = gmin; g <= gmax; g++) {
42845       histp = &histogram[r][g][bmin];
42846       for (b = bmin; b <= bmax; b++, histp++)
42847 	if (*histp != 0) {
42848 	  ccount++;
42849 	}
42850     }
42851   boxp->colorcount = ccount;
42852 }
42853 
setavg(bl,nbox,nc)42854 int setavg(bl, nbox, nc)
42855 boxptr bl;
42856 int nbox, nc;
42857 {
42858   int n,dr,dg,db,cmax;
42859   boxptr b1,b2;
42860 
42861   while (nbox < nc) {
42862 
42863     if (nbox*2 <= nc) {
42864       b1 = cbmax(bl, nbox);
42865     } else {
42866       b1 = colmax(bl, nbox);
42867     }
42868 
42869     if (b1 == NULL) break;
42870 
42871     b2 = &bl[nbox];
42872 
42873     *b2 = *b1; /* copy box at b1 to box at b2 */
42874 
42875     dr = (b1->rmax - b1->rmin) * 16;
42876     dg = (b1->gmax - b1->gmin) * 12;
42877     db = (b1->bmax - b1->bmin) *  8;
42878 
42879     cmax = dg; n = 1;
42880     if (dr > cmax) { cmax = dr; n = 0; }
42881     if (db > cmax) n = 2;
42882 
42883     switch (n) {
42884     case 0:
42885       b1->rmax = AVG(b1->rmax,b1->rmin);
42886       b2->rmin = b1->rmax+1;
42887       break;
42888     case 1:
42889       b1->gmax = AVG(b1->gmax,b1->gmin);
42890       b2->gmin = b1->gmax+1;
42891       break;
42892     case 2:
42893       b1->bmax = AVG(b1->bmax,b1->bmin);
42894       b2->bmin = b1->bmax+1;
42895       break;
42896     }
42897 
42898     boxupd(b1);
42899     boxupd(b2);
42900     nbox++;
42901   }
42902   return nbox;
42903 }
42904 
42905 
setclr(boxp,ic)42906 void setclr(boxp, ic)
42907 boxptr boxp;
42908 int ic;
42909 {
42910   histptr histp;
42911   int r,g,b;
42912   int tel,tot,rtot,gtot,btot;
42913 
42914   tot = rtot = gtot = btot = 0;
42915 
42916   for (r = boxp->rmin; r <= boxp->rmax; r++)
42917     for (g = boxp->gmin; g <= boxp->gmax; g++) {
42918       histp = &histogram[r][g][boxp->bmin];
42919       for (b = boxp->bmin; b <= boxp->bmax; b++) {
42920 	if ((tel = *histp++) != 0) {
42921 	  tot += tel;
42922 	  rtot += (r*8 + 4) * tel;
42923 	  gtot += (g*4 + 2) * tel;
42924 	  btot += (b*8 + 4) * tel;
42925 	}
42926       }
42927     }
42928 
42929   clmap[0][ic] = (unsigned char) ((rtot + (tot/2)) / tot);
42930   clmap[1][ic] = (unsigned char) ((gtot + (tot/2)) / tot);
42931   clmap[2][ic] = (unsigned char) ((btot + (tot/2)) / tot);
42932 }
42933 
42934 #define AB2(a,b) ((a)*(a)*(b)*(b))
42935 
appcols(rgbmin,cl)42936 int appcols(rgbmin,cl)
42937 int *rgbmin;
42938 unsigned char *cl;
42939 {
42940   int i,j, ct, ncolors;
42941   int dmaxje, dmin, dmax;
42942   int dmincl[MAXCOL];
42943   int rgbext[3][4], rgbfac[3], rgbmlt[3];
42944 
42945   rgbfac[0] = 24; rgbfac[1] = 28; rgbfac[2] = 24;
42946   rgbmlt[0] = 2; rgbmlt[1] = 3; rgbmlt[2] = 1;
42947 
42948   for (j = 0; j < 3; j++) {
42949      rgbext[j][0] = rgbmin[j];
42950      rgbext[j][1] = rgbmin[j] + rgbfac[j];
42951      rgbext[j][2] = (2*rgbmin[j] + rgbfac[j])/2;
42952      rgbext[j][3] = rgbmlt[j];
42953   }
42954 
42955   dmaxje = 0x7FFFFFFFL;
42956 
42957   for (i = 0; i < num_colors; i++) {
42958 
42959     dmin = dmax = 0;
42960 
42961     for (j = 0; j < 3; j++) {
42962 
42963 	ct = clmap[j][i];
42964 
42965 	if (ct < rgbext[j][0]) {
42966 
42967 	   dmin += AB2(ct-rgbext[j][0],rgbext[j][3]);
42968 	   dmax += AB2(ct-rgbext[j][1],rgbext[j][3]);
42969 
42970 	} else if (ct > rgbext[j][1]) {
42971 
42972 	   dmin += AB2(ct-rgbext[j][1],rgbext[j][3]);
42973 	   dmax += AB2(ct-rgbext[j][0],rgbext[j][3]);
42974 
42975 	} else {
42976 
42977 	   if (ct <= rgbext[j][2]) {
42978 		dmax += AB2(ct-rgbext[j][1],rgbext[j][3]);
42979 	   } else {
42980 		dmax += AB2(ct-rgbext[j][0],rgbext[j][3]);
42981 	   }
42982 
42983 	}
42984     }
42985 
42986     dmincl[i] = dmin;
42987 
42988     if (dmax < dmaxje) dmaxje = dmax;
42989   }
42990 
42991   ncolors = 0;
42992   for (i = 0; i < num_colors; i++) {
42993     if (dmincl[i] <= dmaxje)
42994       cl[ncolors++] = (unsigned char) i;
42995   }
42996   return ncolors;
42997 }
42998 
42999 
optcols(rgbmin,numcolors,cl,bc)43000 void optcols(rgbmin, numcolors, cl, bc)
43001 int *rgbmin;
43002 int numcolors;
43003 unsigned char *cl;
43004 unsigned char *bc;
43005 {
43006   int i, ir, ig, ib, ic;
43007   int * bptr;
43008   unsigned char * cptr;
43009   int drgb2, drgb2t, drgb2tt;
43010   int tr, tg, tb;
43011   int dr, dg, db;
43012   int optdrgb2[BOX_DIM];
43013 
43014   bptr = optdrgb2;
43015 
43016   for (i = BOX_DIM-1; i >= 0; i--)
43017     *bptr++ = 0x7FFFFFFFL;
43018 
43019   for (i = 0; i < numcolors; i++) {
43020 
43021     ic = cl[i];
43022     drgb2 = 0;
43023 
43024     dr = (rgbmin[0] - (int) clmap[0][ic]) * 2;
43025     drgb2 += dr*dr;
43026     dg = (rgbmin[1] - (int) clmap[1][ic]) * 3;
43027     drgb2 += dg*dg;
43028     db = (rgbmin[2] - (int) clmap[2][ic]) * 1;
43029     drgb2 += db*db;
43030 
43031     dr = dr*32 + 256;
43032     dg = dg*24 + 144;
43033     db = db*16 + 64;
43034 
43035     bptr = optdrgb2;
43036     cptr = bc;
43037     tr = dr;
43038 
43039     for (ir = 3; ir >= 0; ir--) {
43040       drgb2t = drgb2;
43041       tg = dg;
43042 
43043       for (ig = 7; ig >= 0; ig--) {
43044 	drgb2tt = drgb2t;
43045 	tb = db;
43046 
43047 	for (ib = 3; ib >= 0; ib--) {
43048 	  if (drgb2tt < *bptr) {
43049 	    *bptr = drgb2tt;
43050 	    *cptr = (unsigned char) ic;
43051 	  }
43052 	  drgb2tt += tb;
43053 	  tb += 128;
43054 	  bptr++;
43055 	  cptr++;
43056 	}
43057 	drgb2t += tg;
43058 	tg += 288;
43059       }
43060       drgb2 += tr;
43061       tr += 512;
43062     }
43063   }
43064 }
43065 
ininvcm(r,g,b)43066 void ininvcm(r,g,b)
43067 int r,g,b;
43068 {
43069   int rgbmin[3];
43070   int i, j, k;
43071   unsigned char * cptr;
43072   histptr ptr;
43073   unsigned char cl[MAXCOL], bc[BOX_DIM];
43074   int nc;
43075 
43076   r = r/4;
43077   g = g/8;
43078   b = b/4;
43079 
43080   rgbmin[0] = r*32 + 4;
43081   rgbmin[1] = g*32 + 2;
43082   rgbmin[2] = b*32 + 4;
43083 
43084   nc = appcols(rgbmin, cl);
43085 
43086   optcols(rgbmin, nc, cl, bc);
43087 
43088   r = r*4;
43089   g = g*8;
43090   b = b*4;
43091 
43092   cptr = bc;
43093 
43094   for (i = 0; i < 4; i++)
43095 
43096     for (j = 0; j < 8; j++) {
43097 
43098       ptr = &histogram[r+i][g+j][b];
43099 
43100       for (k = 0; k < 4; k++)
43101 	*ptr++ = (unsigned short) (*cptr++ + 1);
43102 
43103     }
43104 
43105 }
43106 
map_pixels(rgbimg,width,height,imag,rtoggle)43107 void map_pixels(rgbimg, width, height, imag, rtoggle)
43108 Byte *rgbimg, *imag;
43109 int   width, height;
43110 int rtoggle;
43111 {
43112   int cur[3],bel[3],bpr[3];
43113   short * errorptr;
43114   unsigned char *inptr,*outptr;
43115   histptr tmpptr;
43116   int j, dir, dir3;
43117   int row, col;
43118 
43119   for (row = 0; row < height; row++) {
43120 
43121     inptr  = &rgbimg[row*width * 3];
43122     outptr = &imag[row*width];
43123 
43124     if (rtoggle) {
43125 
43126       inptr += (width-1)*3;
43127       outptr += width-1;
43128       dir = -1;
43129       dir3 = -3;
43130       errorptr = fserrors + (width+1)*3;
43131       rtoggle = False;
43132 
43133     } else {
43134 
43135       dir = 1;
43136       dir3 = 3;
43137       errorptr = fserrors;
43138       rtoggle = True;
43139 
43140     }
43141 
43142     for (j = 0; j < 3; j++) {
43143 	cur[j] = 0; bel[j] = 0; bpr[j] = 0;
43144     }
43145 
43146     for (col = width; col > 0; col--) {
43147 
43148       for (j = 0; j < 3; j++) {
43149 	cur[j] = (cur[j] + errorptr[dir3+j] + 8)/16;
43150 	cur[j] = maxerr[cur[j]];
43151 	cur[j] += inptr[j];
43152 	RANGE(cur[j], 0, 255);
43153       }
43154 
43155       tmpptr = &histogram[cur[0]/8][cur[1]/4][cur[2]/8];
43156 
43157       if (*tmpptr == 0)
43158 	ininvcm(cur[0]/8, cur[1]/4, cur[2]/8);
43159 
43160       *outptr = (unsigned char) (*tmpptr - 1);
43161       for (j = 0; j < 3; j++)
43162 	   cur[j] -= (int) clmap[j][*tmpptr - 1];
43163 
43164       { int nxterr, dc;
43165 
43166 	for (j = 0; j < 3; j++) {
43167 	   nxterr = cur[j];
43168 	   dc = cur[j] * 2;
43169 	   cur[j] += dc;
43170 	   errorptr[j] = (short) (bpr[j] + cur[j]);
43171 	   cur[j] += dc;
43172 	   bpr[j] = bel[j] + cur[j];
43173 	   bel[j] = nxterr;
43174 	   cur[j] += dc;
43175 	}
43176 
43177       }
43178 
43179       inptr += dir3;
43180       outptr += dir;
43181       errorptr += dir3;
43182     }
43183 
43184     for (j = 0; j < 3; j++)
43185 	errorptr[j] = (short) bpr[j];
43186   }
43187 }
43188 
43189 
init_err()43190 void init_err()
43191 {
43192   int i, j;
43193 
43194   maxerr = (int *) malloc((size_t) ((255*2+1) * sizeof(int)));
43195   if (!maxerr) return;
43196 
43197   maxerr += 255;
43198 
43199   j = 0;
43200   for (i = 0; i < 16; i++, j++) {
43201     maxerr[i] = j; maxerr[-i] = -j;
43202   }
43203   for (; i < 48; i++, j += (i&1) ? 0 : 1) {
43204     maxerr[i] = j; maxerr[-i] = -j;
43205   }
43206   for (; i <= 255; i++) {
43207     maxerr[i] = j; maxerr[-i] = -j;
43208   }
43209 }
43210 
pickcol(nc)43211 void pickcol(nc)
43212 int nc;
43213 {
43214   box bl[MAXCOL];
43215   int nbox;
43216   int i;
43217 
43218   nbox = 1;
43219 
43220   bl[0].rmin = bl[0].gmin = bl[0].bmin = 0;
43221   bl[0].rmax = bl[0].bmax = 31;
43222   bl[0].gmax = 63;
43223 
43224   boxupd(bl);
43225 
43226   nbox = setavg(bl, nbox, nc);
43227 
43228   for (i = 0; i < nbox; i++)
43229     setclr(&bl[i], i);
43230 
43231   num_colors = nbox;
43232 
43233 }
43234 
quant(rgbimg,width,height,imag,nc)43235 int quant(rgbimg, width, height, imag, nc)
43236 Byte *rgbimg, *imag;
43237 int   width, height, nc;
43238 {
43239   size_t fssize = (width + 2) * (3 * sizeof(short));
43240 
43241   if (maxerr == NULL) init_err();
43242 
43243   histogram = (hist2d *) malloc(sizeof(hist3d));
43244   fserrors = (short *) malloc(fssize);
43245 
43246   if (! maxerr || ! histogram || ! fserrors) {
43247     if (histogram) free(histogram);
43248     if (fserrors) free(fserrors);
43249     fprintf(stderr,"24->8 failed to allocate workspace\n");
43250     return 1;
43251   }
43252 
43253   inithis(rgbimg, width*height);
43254 
43255   pickcol(nc);
43256 
43257   initz((char *) histogram, sizeof(hist3d));
43258   initz((char *) fserrors, fssize);
43259 
43260   map_pixels(rgbimg, width, height, imag, False);
43261 
43262   free(histogram);
43263   free(fserrors);
43264 
43265   return 0;
43266 }
43267 
43268 static int curson = 0;
43269 
43270 #if defined(VMS) || defined(UNDERSC)
curs(on)43271 void curs(on)
43272 #else
43273 #ifdef CRAY
43274 void CURS(on)
43275 #else
43276 void curs_(on)
43277 #endif
43278 #endif
43279 int *on;
43280 {
43281 
43282    if (!xison) return;
43283    if (animptr.on) return;
43284 
43285    if (*on) {
43286         curson = 1;
43287 	XDefineCursor(display, win, WaitCursor);
43288 	XDefineCursor(display, winMC, WaitCursor);
43289 	XDefineCursor(display, winC, WaitCursor);
43290 	XDefineCursor(display, fsel.win, WaitCursor);
43291 	XDefineCursor(display, ZMEwin, WaitCursor);
43292 	if (specup) XDefineCursor(display, winspec, WaitCursor);
43293 	if (FRup) XDefineCursor(display, FrBox, WaitCursor);
43294 	if (FLXup) XDefineCursor(display, FLXwin, WaitCursor);
43295 	if (STRup) XDefineCursor(display, STRwin, WaitCursor);
43296 	if (STRCup) XDefineCursor(display, STRCwin, WaitCursor);
43297 	if (OMAPup) XDefineCursor(display, OMAPwin, WaitCursor);
43298 	if (SRCHup) XDefineCursor(display, SRCHwin, WaitCursor);
43299    } else {
43300         curson = 0;
43301 	XUndefineCursor(display, win);
43302 	XUndefineCursor(display, winMC);
43303 	XUndefineCursor(display, winC);
43304 	XUndefineCursor(display, fsel.win);
43305 	XUndefineCursor(display, ZMEwin);
43306 	if (specup) XUndefineCursor(display, winspec);
43307 	if (FRup) XUndefineCursor(display, FrBox);
43308 	if (FLXup) XUndefineCursor(display, FLXwin);
43309 	if (STRup) XUndefineCursor(display, STRwin);
43310 	if (STRCup) XUndefineCursor(display, STRCwin);
43311 	if (OMAPup) XUndefineCursor(display, OMAPwin);
43312 	if (SRCHup) XUndefineCursor(display, SRCHwin);
43313    }
43314    XSync(display, False);
43315 }
43316 
43317 #if defined(VMS) || defined(UNDERSC)
messg(istat)43318 void messg(istat)
43319 #else
43320 #ifdef CRAY
43321 void MESSG(istat)
43322 #else
43323 void messg_(istat)
43324 #endif
43325 #endif
43326 int *istat;
43327 {
43328    char statstr[200];
43329    int x,y,w,h;
43330 
43331    if (!xison) return;
43332 #ifdef DOGL
43333    if (xyzp->ixp == NULL) return;
43334    dispsf();
43335 #endif
43336 
43337    switch (*istat) {
43338 	case 0:
43339 		strcpy(statstr,"Optimisation complete");
43340 		break;
43341 	case 1:
43342 		strcpy(statstr,"Error Job");
43343 		break;
43344 	case 2:
43345 		strcpy(statstr,"Some Required Potential Energy\nParameters are Undefined\nSee the file jobname.log");
43346 		break;
43347 	case 3:
43348 		strcpy(statstr,"Incomplete Convergence");
43349 		break;
43350 	case 4:
43351 		strcpy(statstr,"Too many Parameters");
43352 		break;
43353 	case 5:
43354 		strcpy(statstr,"Job Aborted");
43355 		break;
43356 	case 6:
43357 		strcpy(statstr,"Job started");
43358 		break;
43359 	case 7:
43360 		strcpy(statstr,"WARNING: reading connectivity from file molden_connect");
43361 		break;
43362 	case 8:
43363 		strcpy(statstr,"ERROR: couldnt open mapfile");
43364 		break;
43365 	case 9:
43366 		strcpy(statstr,"ERROR: error reading mapfile");
43367 		break;
43368 	case 10:
43369 		strcpy(statstr,"ERROR: dimensions grid dont match first grid");
43370 		break;
43371 	case 11:
43372 		strcpy(statstr,"WARNING: current grid does not hold density !");
43373 		break;
43374 	case 12:
43375 		strcpy(statstr,"WARNING: could not open file !");
43376 		break;
43377 	case 13:
43378 		strcpy(statstr,"WARNING: Only Hetatm atoms may be selected !");
43379 		break;
43380 	case 14:
43381 		strcpy(statstr,"WARNING EEM: element missing parameters!");
43382 		break;
43383 	case 15:
43384 		strcpy(statstr,"WARNING Mol2: untyped atoms !");
43385 		break;
43386 	case 16:
43387 		InitOmap(0);
43388 		omapr = 1;
43389 		return;
43390 		break;
43391 	case 17:
43392 		strcpy(statstr,"WARNING Mol2: atom type inconsistancy, please retyp !");
43393 		break;
43394 	case 18:
43395 		strcpy(statstr,"Succesfully wrote file resrot");
43396 		break;
43397 	case 19:
43398 		strcpy(statstr,"Did not find file resrot");
43399 		break;
43400 	case 20:
43401 		strcpy(statstr,"Optimisation aborted");
43402 		break;
43403 	case 21:
43404 		strcpy(statstr,"MD complete");
43405 		break;
43406 	case 22:
43407 		InitOmap(1);
43408 		omapr = 2;
43409 		return;
43410 		break;
43411 	default:
43412 		break;
43413    }
43414 
43415    x = event.xbutton.x_root; y = event.xbutton.y_root;
43416    w = DisplayWidth(display,screen);
43417    h = DisplayHeight(display,screen);
43418    if (x < 0 || x > w) x = w / 2;
43419    if (y < 0 || y > h) y = h / 2;
43420 
43421    if (DoCan(x,y,statstr,0)) {}
43422 }
43423 
MkDistWin(int * asel,int opt,float val)43424 void MkDistWin(int *asel,int opt,float val)
43425 {
43426    int nval;
43427 
43428    dstpxini = 1;
43429 
43430    if (monoscr || colcells <= 32) {
43431 	XSetForeground(display, gc, colors[7]);
43432 	XFillRectangle(display,distpix,gc,0,0,DBWIDE,DBHIGH-5);
43433 	if (monoscr) XSetForeground(display, gc, colors[0]);
43434 	else XSetForeground(display, gc, colors[6]);
43435 	XDrawRectangle(display,distpix,gc,0,0,DBWIDE,DBHIGH-5);}
43436    else {
43437 	XSetForeground(display, gc, colors[190]);
43438 	XFillRectangle(display,distpix,gc,0,0,DBWIDE,DBHIGH);
43439 	butje(distpix,0,0,DBWIDE,DBHIGH,3,0,0,1,None,0,0,0);
43440    }
43441    XSetForeground(display, gc, colors[0]);
43442 /*
43443    if (monoscr) XSetForeground(display, gc, colors[0]);
43444    else  XSetForeground(display, gc, colors[9]);
43445 */
43446 
43447 
43448    switch(opt) {
43449    case 6:	sprintf(stemp,"J-Coupling %#11.5f",val);
43450 		nval = 22;
43451 		aselkeep[0] = asel[0];
43452 		aselkeep[1] = asel[1];
43453 		monmode = opt;
43454 		break;
43455    case 5:	sprintf(stemp,"Electrost. Pot. %#11.5f",val);
43456 		nval = 27;break;
43457    case 4:	sprintf(stemp,"Dihedral %#8.3f Degrees",val);
43458 		nval = 25;break;
43459    case 3:	sprintf(stemp,"Covalent Angle %#8.3f Degrees",val);
43460 		nval = 31;break;
43461    case 2:	sprintf(stemp, "         %#11.5f a.u.",val);
43462 		nval=25;
43463 		XDrawString(display,distpix,gc,10,35,stemp,nval);
43464 		sprintf(stemp, "Distance %#11.5f Angstrom",val*toangs);
43465 		nval=29;
43466 		aselkeep[0] = asel[0];
43467 		aselkeep[1] = asel[1];
43468 		monmode = opt;
43469 		break;
43470    default:	break;
43471    }
43472    XDrawString(display, distpix, gc, 10, 15, stemp, nval);
43473 
43474    if (opt == 2 || opt == 6) {
43475 	ActBut(&clbut[BMONI],1);
43476    } else {
43477 	ActBut(&clbut[BMONI],0);
43478    }
43479 
43480    if (!distup) {
43481 	XMapRaised(display,DISTwin);
43482 	RedrawDIST();
43483 	distup = 1;
43484    } else {
43485 	RedrawDIST();
43486    }
43487 
43488 }
43489 
RedrawDIST()43490 void RedrawDIST()
43491 {
43492  int i;
43493 
43494    if (dstpxini) {
43495 	XCopyArea(display,distpix,DISTwin,gc,0,0,DBWIDE,DBHIGH,0,0);
43496    } else {
43497 	XSetForeground(display, gc, colors[190]);
43498 	XFillRectangle(display,DISTwin,gc,0,0,DBWIDE,DBHIGH);
43499 	butje(DISTwin,0,0,DBWIDE,DBHIGH,3,0,0,1,None,0,0,0);
43500 	XSetForeground(display, gc, colors[0]);
43501    }
43502 
43503    for (i=0; i<NCLBUT; i++) DrwBut(&clbut[i]);
43504 }
43505 
ButtonsDIST(i)43506 int ButtonsDIST(i)
43507 int i;
43508 {
43509  int j,iscon1,iscon2;
43510 
43511 
43512 	switch (i) {
43513 	case BCLOSE:
43514 		distup = 0;
43515 		if (!bcksvg.UpSVG) signal(SIGALRM,SIG_IGN);
43516 		XUnmapWindow(display,DISTwin);
43517 		return(0);
43518 		break;
43519 	case BMONI:
43520 		if (monmode == 2) {
43521 #if defined(VMS) || defined(UNDERSC)
43522 		   setmon(aselkeep,&anum);
43523 #else
43524 #ifdef CRAY
43525 		   SETMON(aselkeep,&anum);
43526 #else
43527 		   setmon_(aselkeep,&anum);
43528 #endif
43529 #endif
43530 		} else if (monmode == 6) {
43531 		   double coupl;
43532 
43533 		   coupl = jcoupl[(aselkeep[0]-1)*NAT->natoms + aselkeep[1]-1];
43534 #if defined(VMS) || defined(UNDERSC)
43535 		   stjmon(&coupl,aselkeep,&TWO);
43536 #else
43537 #ifdef CRAY
43538 		   STJMON(&coupl,aselkeep,&TWO);
43539 #else
43540 		   stjmon_(&coupl,aselkeep,&TWO);
43541 #endif
43542 #endif
43543 		}
43544 		if (has_opengl && (*fancy || *fullgl)) {
43545 		   update_model = 0;
43546 		   dispsf();
43547 		} else {
43548 		   update_model = 1;
43549 		   return(1);
43550 		}
43551 		break;
43552 	case BCLR:
43553 #if defined(VMS) || defined(UNDERSC)
43554 		clrmon();
43555 #else
43556 #ifdef CRAY
43557 		CLRMON();
43558 #else
43559 		clrmon_();
43560 #endif
43561 #endif
43562 		if (has_opengl && *fancy ) {
43563 		   update_model = 0;
43564 		   dispsf();
43565 		} else {
43566 		   update_model = 1;
43567 		   return(1);
43568 		}
43569 		break;
43570 	case BCNTCT:
43571 		if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
43572 			   "Select Atom for close contact",1)) {
43573 		   bflag = 1; bretval = 461;
43574 		   XDefineCursor(display,win,AtomCursor);
43575 		   return(0);
43576 		}
43577 		break;
43578 	case BCONN:
43579 		iscon1 = -1;
43580 		iscon2 = -1;
43581 		for (j=0; j<xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)]; j++) {
43582 		   if (ABS(xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)+1+j]) == aselkeep[1])
43583 			iscon1 = j;
43584        		}
43585 		for (j=0; j<xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)]; j++) {
43586 		   if (ABS(xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)+1+j]) == aselkeep[0])
43587 			iscon2 = j;
43588        		}
43589 		if (iscon1 != -1 || iscon2 != -1) {
43590 		    if (iscon1 != -1) {
43591 			for (j=iscon1; j<xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)]-1; j++)
43592 			   xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)+1+j] =
43593 				xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)+2+j];
43594 			xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)] =
43595 				xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)] - 1;
43596 		    }
43597 		    if (iscon2 != -1) {
43598 			for (j=iscon2; j<xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)]-1; j++)
43599 			   xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)+1+j] =
43600 				xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)+2+j];
43601 			xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)] =
43602 				xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)] - 1;
43603 		    }
43604 		} else {
43605 		   if (xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)] < MXCON) {
43606 			xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)] =
43607 			   xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)] + 1;
43608 			xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)+xyzp->iconn[(aselkeep[0]-1)*(MXCON+1)]] =
43609 			aselkeep[1];
43610 		   }
43611 		   if (xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)] < MXCON) {
43612 			xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)] =
43613 			   xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)] + 1;
43614 			xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)+xyzp->iconn[(aselkeep[1]-1)*(MXCON+1)]] =
43615 			aselkeep[0];
43616 		   }
43617 		}
43618 		update_model = 1;
43619 		return(1);
43620 		break;
43621 	}
43622 }
43623 
ChangeLevel(button12,cursorx,cursory)43624 int ChangeLevel(button12,cursorx,cursory)
43625 int button12;
43626 int cursorx;
43627 int cursory;
43628 {
43629  int i,j,jx,jy;
43630  int PEH,PH,PW,NE,MW;
43631 
43632  if (*doesp) {
43633     NE = potcom->nplev+1;
43634     if (hlpsrf->itsrf) NE = 5;
43635     PEH = 20;
43636     PW = 70;
43637     PH = NE*PEH;
43638     MW = 10;
43639     jx = width-70-20;
43640     jy = 20;
43641     if (VIERKANT(cursorx, cursory, jx-MW, jy-MW, PW+2*MW, PH+2*MW)) {
43642 
43643          if (button12 == 1) {
43644    	     qboxstr(&qboxes[QCSPACE],NULL,1,0,-1,DEFQX,DEFQY,QBOXWIDE,QBOXHIGH,
43645 		     0,"Level Spacing ? ",NULL,0,3,590,-1,dummyproc);
43646          } else {
43647 	     if (!(has_opengl && (*fancy || *fullgl) && hlpsrf->itsrf)) {
43648 		if (DoPopUp(win,cursorx-20,cursory,NULL,&j,0) == -1) return 0;
43649 		i = (cursory - jy) / PEH;
43650 		if (i > potcom->nplev) i = potcom->nplev;
43651 		potcom->ipcol[i] = j;
43652 		*Sinct = 591;
43653 	     }
43654 	 }
43655 	 update_model = 1;
43656          return(1);
43657     }
43658 
43659  }
43660  return(0);
43661 }
43662 
FindEsp(button12,cursorx,cursory)43663 int FindEsp(button12,cursorx,cursory)
43664 int button12;
43665 int cursorx;
43666 int cursory;
43667 {
43668  int i;
43669 
43670  update_model = 0;
43671  if (hlpsrf->itsrf) return(0);
43672 
43673  if (*doesp) {
43674 	i = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,*xyzp->iatoms,
43675 			cursorx,cursory,MINDIFF);
43676 	if (i >= 0) {
43677 	    MkDistWin(xyzp->iaton,5,esp[i]);
43678             return(1);
43679         } else {
43680 	    if (ChangeLevel(button12,cursorx,cursory)) return(1);
43681 	}
43682 
43683  }
43684 
43685  return(0);
43686 
43687 }
43688 
PlotColIndex()43689 void PlotColIndex()
43690 {
43691   int i,PEH,PH,PW,NE,MW,jx,jy;
43692 
43693   NE = potcom->nplev+1;
43694   if (hlpsrf->itsrf) NE = 5;
43695   PEH = 20;
43696   PW = 70;
43697   PH = NE*PEH;
43698   MW = 10;
43699 
43700   jx = width-PW-20;
43701   jy = 20;
43702 
43703 
43704   if (hlpsrf->itsrf) {
43705      if (has_opengl && (*fancy || *fullgl) ) {
43706 	butje(win,jx-MW,jy-MW,PW+2*MW,PH+2*MW,3,0,0,1,None,0,0,0);
43707 	for (i=0; i < NE; i++) {
43708 	   XSetForeground(display, gc, mappedcols[i]);
43709 	   XFillRectangle(display, win, gc, jx,jy+(i * PH)/NE, PW,PEH);
43710 	}
43711      }
43712   } else {
43713      if (has_opengl && (*fancy || *fullgl) ) {
43714 	butje(win,jx-MW,jy-MW,PW+2*MW,PH+2*MW,3,0,0,1,None,0,0,0);
43715 	for (i=0; i < NE; i++) {
43716 	   XSetForeground(display, gc, colors[potcom->ipcol[i]]);
43717 	   XFillRectangle(display, win, gc, jx,jy+(i * PH)/NE, PW,PEH);
43718 	}
43719      } else {
43720 	butje(molcur,jx-MW,jy-MW,PW+2*MW,PH+2*MW,3,0,0,1,None,0,0,0);
43721 	for (i=0; i < NE; i++) {
43722 	   XSetForeground(display, gc, colors[potcom->ipcol[i]]);
43723 	   XFillRectangle(display, molcur, gc, jx,jy+(i * PH)/NE, PW,PEH);
43724 	}
43725      }
43726   }
43727 
43728   XSetForeground(display, gc, Black);
43729   if (hlpsrf->itsrf) {
43730      if (has_opengl && (*fancy || *fullgl) ) {
43731 	for (i=0; i < 5; i++) {
43732 	   sprintf(stemp, "%#11.5f",valcol[i]);
43733 	   XDrawString(display,win,gc,jx-10,jy+14+(i * PH)/NE,
43734 	   	stemp,strlen(stemp));
43735 	}
43736      }
43737   } else {
43738      for (i=0; i < NE-1; i++) {
43739 	sprintf(stemp, "%#11.5f",potcom->plevel[i]);
43740 	if (has_opengl && (*fancy || *fullgl) )
43741 	   XDrawString(display,win,gc,jx-10,jy+4+((i+1) * PH)/NE,
43742 		stemp,strlen(stemp));
43743 	else
43744 	   XDrawString(display,molcur,gc,jx-10,jy+4+((i+1) * PH)/NE,
43745 		stemp,strlen(stemp));
43746      }
43747   }
43748 }
43749 
43750 #if defined(VMS) || defined(UNDERSC)
butset(class,butnr,on)43751 void butset(class,butnr,on)
43752 #else
43753 #ifdef CRAY
43754 void BUTSET(class,butnr,on)
43755 #else
43756 void butset_(class,butnr,on)
43757 #endif
43758 #endif
43759 int *class;
43760 int *butnr;
43761 int *on;
43762 {
43763 	if (!xison) return;
43764 
43765 	switch(*class) {
43766 	case 0: if (*on) TogUp(&dbut[*butnr]);
43767 		else TogDown(&dbut[*butnr]);
43768 		RedrawwinC(0,0,WINCWIDE,WINCHIGH);
43769 		break;
43770 	case 1: if (*on) TogUp(&cbut[*butnr]);
43771 		else TogDown(&cbut[*butnr]);
43772 	/*	RedrawwinMC(0,0,WINMCWIDE,WINMCHIGH);*/
43773 		break;
43774 	case 2: if (*on) TogUp(&ZMEbut[*butnr]);
43775 		else TogDown(&ZMEbut[*butnr]);
43776 		RedrawZME();
43777 		break;
43778 	}
43779 }
43780 
OnTop()43781 void OnTop()
43782 {
43783 int i;
43784 
43785 	if (ZMEup) DirBox(ZMEwin,1);
43786 
43787 	if (CHGup) DirBox(CHGwin,1);
43788 	if (SRFup) DirBox(SRFwin,1);
43789 	if (MLTup) DirBox(MLTwin,1);
43790 	if (PARup) DirBox(PARwin,1);
43791 	if (FLXup) DirBox(FLXwin,1);
43792 	if (fsel.qbrfile) DirBox(fsel.win,1);
43793 	if (qbres) DirBox(RESwin,1);
43794 	if (geoup) DirBox(wingeo,1);
43795 	if (cnvup) DirBox(wincnv,1);
43796 	if (distup) DirBox(DISTwin,1);
43797 	if (ANIMup) DirBox(ANIMwin,1);
43798 	if (ATMup) DirBox(ATMwin,1);
43799 	if (COLup) DirBox(COLwin,1);
43800 	if (SEQup) DirBox(SEQwin,1);
43801 	if (TNKup) DirBox(TNKwin,1);
43802 	if (FLRup) DirBox(FLRwin,1);
43803 	if (ONIup) DirBox(ONIwin,1);
43804 	if (specup) DirBox(winspec,1);
43805 	if (scoup) DirBox(winsco,1);
43806 	if (Movup) DirBox(MOVwin,1);
43807 	if (OMAPup) DirBox(OMAPwin,1);
43808 
43809 	if (denmode) DirBox(winC,1);
43810 	else DirBox(winMC,1);
43811 
43812 	if (STRCup) DirBox(STRCwin,1);
43813 	if (STRup) DirBox(STRwin,1);
43814 
43815 	for (i=0; i<NQBOX; i++)
43816 		if (qboxes[i].pop && qboxes[i].active)
43817 			XMapRaised(display,qboxes[i].win);
43818 }
43819 
InitCOL()43820 void InitCOL()
43821 {
43822    int i;
43823 
43824    COLup = 1;
43825 
43826    COLwin = CreateWindow("Element Property Editor","-0+0",COLWINW,COLWINHT,
43827 	 		 infobg,infofg,(Window)0);
43828    XSelectInput(display, COLwin, EnterWindowMask |
43829 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask);
43830    XMapWindow(display,COLwin);
43831 
43832    WinObj[26].win = &COLwin;
43833    WinObj[26].subwin = NULL;
43834    WinObj[26].butarr = colbut;
43835    WinObj[26].numbut = NBUTSC;
43836    WinObj[26].winup = &COLup;
43837    WinObj[26].redraw = RedrawCOL;
43838 
43839    DefBut(&colbut[0], COLwin, COLOffx, 5, 50, 23, "Close", infobg, 0);
43840    DefBut(&colbut[1], COLwin, COLOffx+225, 5, 120, 23, "Radius", infobg, 0);
43841 
43842    for (i=0; i < TABBUTN; i++) {
43843 	if (i==TABBUTN-1)
43844 	   DefBut(&AtmBut[i],COLwin, COLOffx+COLBord+TabPos[i][1]*(ZMETABH+1),
43845 		COLOffy+COLBord+TabPos[i][0]*(ZMETABH+1), ZMETABH, ZMETABH,
43846         	   elements[99], infobg, -elmptr->icol[98]);
43847 	else
43848 	   DefBut(&AtmBut[i],COLwin, COLOffx+COLBord+TabPos[i][1]*(ZMETABH+1),
43849 		COLOffy+COLBord+TabPos[i][0]*(ZMETABH+1), ZMETABH, ZMETABH,
43850         	   elements[i+1], infobg, -elmptr->icol[i]);
43851    }
43852 
43853    qboxstr(&qboxes[QRADI],&COLwin,1,0,190,COLOffx+345,5,
43854 	120,38,2," "," ",SUBLEN2,QPOSREAL,2000,-1,colcall);
43855 
43856    ipropopt = 0;
43857    colbut[1].str = propopts[ipropopt];
43858 }
43859 
RedrawCOL()43860 void RedrawCOL()
43861 {
43862    int i;
43863 
43864    if (!COLup) return;
43865 
43866    if (monoscr) {
43867 	XSetFillStyle(display, gc, FillStippled);
43868 	XSetStipple(display, gc, hlfgrey);
43869 	XSetForeground(display, gc, infobg);
43870 	XFillRectangle(display, COLwin, gc, 0, COLOffy-COLFRBord,
43871 		COLWINW, COLWINH+1);
43872 	XSetFillStyle(display,gc,FillSolid);
43873    } else {
43874 	butje(COLwin,0,0,COLWINW-1,COLOffy-COLFRBord+1,1,0,0,1,None,0,0,0);
43875         XSetForeground(display, gc, infobg);
43876 	butje(COLwin,0,COLOffy-COLFRBord,COLWINW-1,COLWINH,
43877 			1,0,0,1,None,0,0,0);
43878    }
43879 
43880 
43881    ULineString(COLwin, "Edit Property:",COLOffx+120, 20);
43882 
43883    for (i=0; i<NBUTSC; i++) DrwBut(&colbut[i]);
43884 
43885    if (ipropopt) PromptBox(&qboxes[QRADI]);
43886 
43887    butje(COLwin, COLOffx+1, COLOffy, COLWINIW, COLWINIH,2,0,2,0,None,0,0,0);
43888    for (i=0; i<TABBUTN; i++) DrwBut(&AtmBut[i]);
43889 
43890    if (propat == 98) SelBut(&AtmBut[TABBUTN-1]);
43891    else SelBut(&AtmBut[propat]);
43892 
43893 }
43894 
RButtonsCOL(i)43895 void RButtonsCOL(i)
43896 int i;
43897 {
43898     LSSTRU List;
43899 
43900     SetRadius();
43901 
43902     switch (i) {
43903     case 0: XDestroyWindow(display,COLwin);COLup = 0; break;
43904     case 1: List.list = propopts; List.nents = 4;
43905 	    if (DoPopUp(COLwin,
43906 			colbut[1].x+60,colbut[1].y+BUTTH,
43907 			&List,&ipropopt,1) == -1) break;
43908 	    colbut[1].str = propopts[ipropopt];
43909 	    switch (ipropopt) {
43910 	    case PVDWRAD:
43911 		sprintf(qboxes[QRADI].str,"%f",elmptr->vdwr[propat]);
43912 		break;
43913 	    case PDISRAD:
43914 		sprintf(qboxes[QRADI].str,"%f",elmptr->vrad[propat]*toangs);
43915 		break;
43916 	    case PESPRAD:
43917 		sprintf(qboxes[QRADI].str,"%f",espvdw[propat]);
43918 		break;
43919 	    }
43920 	    qboxes[QRADI].curpos = strlen(qboxes[QRADI].str);
43921 	    RedrawCOL();
43922  	    break;
43923     }
43924 }
43925 
ButtonsCOL(i)43926 void ButtonsCOL(i)
43927 int i;
43928 {
43929     int csel,updown;
43930 
43931 
43932     SetRadius();
43933 
43934     if (i==TABBUTN-1) propat = 98;
43935     else propat = i;
43936 
43937     switch (ipropopt) {
43938     case PATMCOL:
43939 	updown = AtmBut[i].y+BUTTH;
43940 	if (i > 85 || (i > 56 && i < 71) ) updown = updown - NUMCOL*14;
43941 	if (DoPopUp(COLwin,AtmBut[i].x-8,updown,NULL,&csel,0) == -1) return;
43942 	elmptr->icol[propat] = csel;
43943 #if defined(VMS) || defined(UNDERSC)
43944 	wrtres();
43945 #else
43946 #ifdef CRAY
43947 	WRTRES();
43948 #else
43949 	wrtres_();
43950 #endif
43951 #endif
43952 
43953 	DefBut(&AtmBut[i],COLwin,
43954 		COLOffx+COLBord+TabPos[i][1]*(ZMETABH+1),
43955 		COLOffy+COLBord+TabPos[i][0]*(ZMETABH+1),
43956 		ZMETABH, ZMETABH, elements[propat+1], infobg,
43957 		-elmptr->icol[propat]);
43958 
43959 	DrwBut(&AtmBut[i]);
43960 
43961 	break;
43962     case PVDWRAD:
43963 	sprintf(qboxes[QRADI].str,"%f",elmptr->vdwr[propat]);
43964 	qboxes[QRADI].curpos = strlen(qboxes[QRADI].str);
43965 	RedrawCOL();
43966 #if defined(VMS) || defined(UNDERSC)
43967 	doconn();
43968 #else
43969 #ifdef CRAY
43970 	DOCONN();
43971 #else
43972 	doconn_();
43973 #endif
43974 #endif
43975 #ifdef DOGL
43976         ogsetel20(propat);
43977         ogsetel20_bs(propat);
43978         ogsetel12(propat);
43979         ogsetel12_bs(propat);
43980 #endif
43981 	break;
43982     case PDISRAD:
43983 	sprintf(qboxes[QRADI].str,"%f",elmptr->vrad[propat]*toangs);
43984 	qboxes[QRADI].curpos = strlen(qboxes[QRADI].str);
43985 	RedrawCOL();
43986 	break;
43987     case PESPRAD:
43988 	sprintf(qboxes[QRADI].str,"%f",espvdw[propat]);
43989 	qboxes[QRADI].curpos = strlen(qboxes[QRADI].str);
43990 	RedrawCOL();
43991 	break;
43992     }
43993 
43994 }
43995 
SetRadius()43996 void SetRadius()
43997 {
43998      switch (ipropopt) {
43999      case PATMCOL:
44000 		break;
44001      case PVDWRAD:
44002 		elmptr->vdwr[propat] = atof(qboxes[QRADI].str);
44003 		break;
44004      case PDISRAD:
44005 		elmptr->vrad[propat] = atof(qboxes[QRADI].str)/toangs;
44006 		break;
44007      case PESPRAD:
44008 		espvdw[propat] = atof(qboxes[QRADI].str);
44009 		break;
44010      }
44011 
44012 }
44013 
colcall(char * str)44014 void colcall(char* str)
44015 {
44016 	SetRadius();
44017 #if defined(VMS) || defined(UNDERSC)
44018 	doconn();
44019 #else
44020 #ifdef CRAY
44021 	DOCONN();
44022 #else
44023 	doconn_();
44024 #endif
44025 #endif
44026 }
44027 
CreateCellPar()44028 void CreateCellPar()
44029 {
44030   int i;
44031 
44032   if (CPup) {
44033 	XMapRaised(display,CPwin);
44034 	return;
44035   }
44036 
44037   CPup = 1;
44038 
44039   CPwin = CreateWindow("Edit Cell Parameters","-80-80",
44040 			 CPBOXWIDE,CPBOXHIGH,infobg,infofg,(Window)0);
44041   XSelectInput(display, CPwin, EnterWindowMask |
44042 	ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask);
44043 
44044   XMapWindow(display,CPwin);
44045 
44046   WinObj[14].win = &CPwin;
44047   WinObj[14].subwin = NULL;
44048   WinObj[14].butarr = cpbut;
44049   WinObj[14].numbut = NBUTCP;
44050   WinObj[14].winup = &CPup;
44051   WinObj[14].redraw = RedrawCP;
44052 
44053   DefBut(&cpbut[BCPAPP], CPwin, 70, 5+8*(BUTTN+8), 50, 23,
44054 	"Apply", infobg, -15);
44055 
44056   DefBut(&cpbut[BCPCAN], CPwin, 70+60, 5+8*(BUTTN+8), 50, 23,
44057 	"Close", infobg, -15);
44058 
44059   for (i=0; i<8; i++) {
44060 	qboxstr(&qboxes[QCPA+i],&CPwin,0,0,190,CPBOXOFFX,CPBOXOFFY+i*(BUTTN+5),
44061 		200,QBOXHIGH,2,cellpars[i],"10.0",9,2,2000,-1,dummyproc);
44062   }
44063   qboxes[QCPSPGN].qbopt = 1;
44064   qboxes[QCPSPGS].qbopt = 0;
44065   qboxes[QCPSPGN].changed = 0;
44066   qboxes[QCPSPGS].changed = 0;
44067   UpdateCP();
44068 }
44069 
UpdateCP()44070 void UpdateCP()
44071 {
44072  int i,j;
44073  double todeg;
44074 
44075  todeg = 45.0e0/atan(1.0e0);
44076 
44077  for (j=0; j<6; j++) {
44078 	if (j<3) sprintf(qboxes[QCPA+j].str,"%-9.4f",
44079 			cell->cellc[j]);
44080 	else if (j<6) sprintf(qboxes[QCPA+j].str,"%-9.3f",
44081 			cell->cellc[j]*todeg);
44082 	qboxes[QCPA+j].curpos = strlen(qboxes[QCPA+j].str);
44083  }
44084  sprintf(qboxes[QCPSPGN].str,"%d",cell->nspg);
44085  qboxes[QCPSPGN].curpos = strlen(qboxes[QCPSPGN].str);
44086 
44087  if (cell->nspg != 0) {
44088    i = fndchr(spacegr[cell->nspg - 1],' ');
44089    if (i == 0) i = 7;
44090    str2qbox(&qboxes[QCPSPGS],spacegr[cell->nspg - 1],i);
44091    qboxes[QCPSPGS].str[i] = '\0';
44092  } else {
44093    str2qbox(&qboxes[QCPSPGS],"unknown",-1);
44094  }
44095 
44096  if (cell->nspg == 1 || cell->nspg == 2) CPopt = 0;
44097  if ((cell->nspg >= 3 && cell->nspg <= 15) ||
44098 	cell->nspg == 231 ) CPopt = 1;
44099  if (cell->nspg >= 16 && cell->nspg <= 74) CPopt = 2;
44100  if ((cell->nspg >= 75 && cell->nspg <= 194) ||
44101        (cell->nspg >= 232 && cell->nspg <= 238)) CPopt = 3;
44102  if (cell->nspg >= 195 && cell->nspg <= 230) CPopt = 4;
44103 
44104 }
44105 
RedrawCP()44106 void RedrawCP()
44107 {
44108   int i;
44109 
44110   butje(CPwin,0,0,CPBOXWIDE,CPBOXHIGH,4,0,0,1,None,0,0,0);
44111   for (i=0; i<NBUTCP; i++) DrwBut(&cpbut[i]);
44112   for (i=0; i<8; i++) PromptBox(&qboxes[QCPA+i]);
44113 }
44114 
ButtonsCP(x,y)44115 int ButtonsCP(x,y)
44116 int x,y;
44117 {
44118  int i,j;
44119 
44120  i = Clickwin(cpbut,NBUTCP,x,y,1);
44121  if (i>=0) {
44122 	switch (i) {
44123 	case BCPAPP:
44124 
44125 	   for (j=0; j<6; j++)
44126 		cell->cellc[j] = atof(qboxes[QCPA+j].str);
44127 
44128 	   if (qboxes[QCPSPGN].changed) {
44129 
44130 		cell->nspg = atoi(qboxes[QCPSPGN].str);
44131 
44132 	   }
44133 
44134 	   if (qboxes[QCPSPGS].changed) {
44135 		int n, fnd;
44136 		char spgtmp[] = "       ";
44137 
44138 		n = strlen(qboxes[QCPSPGS].str);
44139 		if (n > 7) n = 7;
44140 		strncpy(spgtmp,qboxes[QCPSPGS].str,n);
44141 
44142 		fnd = 0;
44143 		for (i=0; i<MXSG; i++)
44144 		   if (strcasecmp(spgtmp, spacegr[i]) == 0) {
44145 			cell->nspg = i + 1;
44146 			fnd = 1;
44147 		   }
44148 		if (!fnd) {
44149 		   strcpy(molwstr,"Unrecognized Spacegroup !");
44150 		   StatusStr(0,1);
44151 		}
44152 	   }
44153 	   qboxes[QCPSPGN].changed = 0;
44154 	   qboxes[QCPSPGS].changed = 0;
44155 
44156 #if defined(VMS) || defined(UNDERSC)
44157 	   chgpar(xyzp->ianz,xyzp->coo,
44158 #else
44159 #ifdef CRAY
44160 	   CHGPAR(xyzp->ianz,xyzp->coo,
44161 #else
44162 	   chgpar_(xyzp->ianz,xyzp->coo,
44163 #endif
44164 #endif
44165 	   &cell->natc,&cell->icent,&cell->nspg,&cell->ichx,
44166 	   &cell->nopr,cell->ir,cell->it,
44167 	   &cell->xyzc[0],&cell->xyzc[1],&cell->xyzc[2],
44168 	   &cell->xyzc[3],&cell->xyzc[4],&cell->xyzc[5],
44169 	   &cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
44170 	   &cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
44171 
44172 	   UpdateCP();
44173 	   RedrawCP();
44174 	   return(1);
44175 	   break;
44176 
44177 	case BCPCAN:
44178 	   XDestroyWindow(display,CPwin);
44179 	   CPup = 0;
44180 	   break;
44181 	default: break;
44182 	}
44183  } else {
44184 	i = ClickBox(&qboxes[QCPA],8,x,y);
44185 	if (i>=0) {
44186 		for (j=0; j<8; j++) qboxes[QCPA+j].active = 0;
44187 		if (i == 6) qboxes[QCPSPGN].active = 1;
44188 		if (i == 7) qboxes[QCPSPGS].active = 1;
44189 		else if (CPact[CPopt][i]) qboxes[QCPA+i].active = 1;
44190 		RedrawCP();
44191 	}
44192 
44193  }
44194 
44195  return(0);
44196 
44197 }
44198 
InitISO(x,y)44199 void InitISO(x,y)
44200 int x,y;
44201 {
44202    char wgeom[64];
44203 
44204    ISOup = 1;
44205 
44206    sprintf(wgeom,"+%d+%d",x,y);
44207 
44208    ISOwin = CreateWindow("Isodensity Window",wgeom,ISOWINW,ISOWINH,
44209 	 		 infobg,infofg,(Window)0);
44210    XSelectInput(display, ISOwin, EnterWindowMask |
44211 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask);
44212    XMapWindow(display,ISOwin);
44213 
44214    WinObj[19].win = &ISOwin;
44215    WinObj[19].subwin = NULL;
44216    WinObj[19].butarr = isobut;
44217    WinObj[19].numbut = NBUTISO;
44218    WinObj[19].winup = &ISOup;
44219    WinObj[19].redraw = NULL;
44220 
44221    DefBut(&isobut[0], ISOwin, ISOWINW/2+15, 15+2*QBOXHIGH, 50, 23, "Number of Surfaces", infobg, ZMBCOL);
44222    isobut[0].str = ChainLength[surface->nvalc-1];
44223    DefBut(&isobut[1], ISOwin, ISOWINW/2-50/2, 250, 50, 23, "OK", infobg, ZMBCOL);
44224 
44225    qboxstr(&qboxes[QEDGE],&ISOwin,1,0,190,ISOOffx,15,
44226 	200,QBOXHIGH,2,"Grid Size        "," ",SUBLEN2,QPOSREAL,2000,-1,
44227 	dummyproc);
44228 
44229    qboxstr(&qboxes[QNPTS],&ISOwin,0,0,190,ISOOffx,15+1*QBOXHIGH,
44230 	200,QBOXHIGH,2,"Number of Points "," ",SUBLEN2,QPOSINT,2000,-1,
44231 	dummyproc);
44232 
44233    qboxstr(&qboxes[QVALC1],&ISOwin,0,0,190,ISOOffx,15+3*QBOXHIGH,
44234 	200,QBOXHIGH,2,"Contour Value1   "," ",SUBLEN2,QPOSREAL,2000,-1,
44235 	dummyproc);
44236 
44237    qboxstr(&qboxes[QVALC2],&ISOwin,0,0,190,ISOOffx,15+4*QBOXHIGH,
44238 	200,QBOXHIGH,2,"Contour Value2   "," ",SUBLEN2,QPOSREAL,2000,-1,
44239 	dummyproc);
44240 
44241    qboxstr(&qboxes[QVALC3],&ISOwin,0,0,190,ISOOffx,15+5*QBOXHIGH,
44242 	200,QBOXHIGH,2,"Contour Value3   "," ",SUBLEN2,QPOSREAL,2000,-1,
44243 	dummyproc);
44244 
44245    sprintf(qboxes[QEDGE].str,"%f",surface->edge);
44246    sprintf(qboxes[QVALC1].str,"%f",surface->ctval[0]);
44247    sprintf(qboxes[QVALC2].str,"%f",surface->ctval[1]);
44248    sprintf(qboxes[QVALC3].str,"%f",surface->ctval[2]);
44249    sprintf(qboxes[QNPTS].str,"%d",surface->nspts);
44250    qboxes[QEDGE].curpos = strlen(qboxes[QEDGE].str);
44251    qboxes[QVALC1].curpos = strlen(qboxes[QVALC1].str);
44252    qboxes[QVALC2].curpos = strlen(qboxes[QVALC2].str);
44253    qboxes[QVALC3].curpos = strlen(qboxes[QVALC3].str);
44254    qboxes[QNPTS].curpos = strlen(qboxes[QNPTS].str);
44255 
44256 }
44257 
RedrawISO()44258 void RedrawISO()
44259 {
44260   int i;
44261 
44262   butje(ISOwin,0,0,ISOWINW,ISOWINH,4,0,0,1,None,0,0,0);
44263   for (i=0; i<NBUTISO; i++) DrwBut(&isobut[i]);
44264   ULineString(ISOwin, "Number of Surfaces:",ISOOffx, 30+2*QBOXHIGH);
44265   PromptBox(&qboxes[QEDGE]);
44266   PromptBox(&qboxes[QVALC1]);
44267   PromptBox(&qboxes[QVALC2]);
44268   PromptBox(&qboxes[QVALC3]);
44269   PromptBox(&qboxes[QNPTS]);
44270 }
44271 
ButtonsISO(i)44272 int ButtonsISO(i)
44273 int i;
44274 {
44275   switch (i) {
44276   case 1:
44277 	surface->edge = atof(qboxes[QEDGE].str);
44278 	surface->ctval[0] = atof(qboxes[QVALC1].str);
44279 	surface->ctval[1] = atof(qboxes[QVALC2].str);
44280 	surface->ctval[2] = atof(qboxes[QVALC3].str);
44281 	surface->nspts = atoi(qboxes[QNPTS].str);
44282 	XDestroyWindow(display,ISOwin);
44283 	ISOup = 0;
44284 	*Sinct = ISOt;
44285 	return(1);
44286 	break;
44287   case 0:	{
44288 	LSSTRU List;
44289 	List.list = ChainLength; List.nents = 3;
44290 	if (DoPopUp(ISOwin,isobut[0].x+20,isobut[0].y,
44291 		&List,&surface->nvalc,0) == -1) break;
44292 	   surface->nvalc++;
44293 	   isobut[0].str = ChainLength[surface->nvalc-1];
44294 	   DrwBut(&isobut[0]);
44295 	}
44296 	break;
44297   }
44298   return(0);
44299 }
44300 
InitATM(x,y)44301 void InitATM(x,y)
44302 int x,y;
44303 {
44304    char wgeom[64];
44305 
44306    ATMup = 1;
44307 
44308    sprintf(wgeom,"+%d+%d",x,y);
44309 
44310    ATMwin = CreateWindow("Atom Attributes Window",wgeom,ATMWINW,ATMWINH,
44311 	 		 infobg,infofg,(Window)0);
44312    subATM = CreateWindow("Subwindow","",10,10,
44313                             colors[0],colors[15],ATMwin);
44314    XSelectInput(display, ATMwin, KeyPressMask | ExposureMask | ButtonPressMask
44315 	| ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask |
44316 	SubstructureNotifyMask | PointerMotionMask | EnterWindowMask);
44317    XMapWindow(display,ATMwin);
44318 
44319    WinObj[20].win = &ATMwin;
44320    WinObj[20].subwin = &subATM;
44321    WinObj[20].butarr = butATM;
44322    WinObj[20].numbut = NBUTATM;
44323    WinObj[20].winup = &ATMup;
44324    WinObj[20].redraw = RedrawATM;
44325 
44326    DefBut(&butATM[1],ATMwin, 100, 15, 100, 23, "Force Field", infobg, ZMBCOL);
44327    butATM[1].str = ForceFields[*fftyp];
44328    butATM[1].explstr = "Select a Force Field to type atoms with";
44329 
44330    DefBut(&butATM[2],ATMwin, 100, 15+BUTTN, 100, 23, "Total Charge", infobg,
44331 	ZMBCOL);
44332    butATM[2].str = copt[itcopt];
44333    butATM[2].explstr = "Select the total charge of the molecule";
44334 
44335    DefBut(&butATM[0], ATMwin, 170, 15+3*BUTTN, 70, 23, "AtomColor", infobg,
44336 	ZMBCOL);
44337    butATM[0].explstr = "Select substructure color of the atom.\nSelect atom: 2nd Mouse Button";
44338 
44339    DefBut(&butATM[3], ATMwin, ATMWINW/2-50/2, 315, 50, 23, "OK", infobg, ZMBCOL);
44340    butATM[3].explstr = "Close the window";
44341 
44342    DefBut(&butATM[4], ATMwin, 210, 15, 30, 23, "OPT", infobg, ZMBCOL);
44343    butATM[4].explstr = "Setup Tinker/AMBFOR optimisation\nAMBFOR is Molden\'s own optimiser\nfor AMBER/GAFF force fields\nGAFF is for small molecules";
44344 
44345    DefBut(&butATM[5], ATMwin, 210, 15+BUTTN, 30, 23, "E q", infobg, ZMBCOL);
44346    butATM[5].explstr = "Calculate van der Waals and \nElectrostatic energies between\n atoms with different residue numbers";
44347 
44348    qboxstr(&qboxes[QCHARG],&ATMwin,1,0,190,ATMOffx,35+4*BUTTN,
44349 	110,QBOXHIGH,2,"Charge"," ",10,QREAL,2000,-1,dummyproc);
44350    qboxes[QCHARG].explstr = "Partial charge of selected atom\nSelect atom: 2nd Mouse Button";
44351 
44352    qboxstr(&qboxes[QRSD],&ATMwin,0,0,190,ATMOffx+115,35+4*BUTTN,
44353 	100,QBOXHIGH,2,"Residue"," ",4,QREAL,2000,-1,dummyproc);
44354    qboxes[QRSD].explstr = "Residue number of selected atom\nSelect atom: 2nd Mouse Button";
44355 
44356    qboxstr(&qboxes[QATOM],&ATMwin,0,0,190,ATMOffx+55,36+2*BUTTN,
44357 	100,QBOXHIGH,2,"Number:"," ",6,QPOSINT,2000,-1,dummyproc);
44358    qboxes[QATOM].explstr = "Number of selected atom\nType a number \nto change Atom selected";
44359 
44360    DefList(&fftlist,ATMwin,6,35+5*BUTTN+QBOXHIGH,ATMWINW-37,110,
44361 	NULL,9,typs[1],NULL,NULL,NULL,Ntyps[1],NULL);
44362 
44363    UpdateATM();
44364 
44365 }
44366 
UpdateATM()44367 void UpdateATM()
44368 {
44369    int i;
44370 
44371    sprintf(qboxes[QCHARG].str,"%f",xyzp->qat[ATMsel]);
44372    qboxes[QCHARG].curpos = strlen(qboxes[QCHARG].str);
44373    qboxes[QCHARG].dflt = &xyzp->qat[ATMsel];
44374    sprintf(qboxes[QRSD].str,"%d",xyzp->iresid[ATMsel]);
44375    qboxes[QRSD].curpos = strlen(qboxes[QRSD].str);
44376    qboxes[QRSD].iflt = &xyzp->iresid[ATMsel];
44377    sprintf(qboxes[QATOM].str,"%d",ATMselp);
44378    qboxes[QATOM].curpos = strlen(qboxes[QATOM].str);
44379    qboxes[QATOM].iflt = &ATMselp;
44380    fftlist.list.ilst = ffptr[*fftyp];
44381    if (xyzp->ityp[ATMsel] < 0) {
44382 	fftlist.list.list = typsn[*fftyp];
44383 	fftlist.list.nents = Ntypsn[*fftyp];
44384 	fftlist.scrbar.wn = Ntypsn[*fftyp];
44385    } else {
44386 	fftlist.list.list = typs[*fftyp];
44387 	fftlist.list.nents = Ntyps[*fftyp];
44388 	fftlist.scrbar.wn = Ntyps[*fftyp];
44389    }
44390 
44391    if (ffptr[*fftyp] == NULL) {
44392 	fftlist.select = abs(xyzp->ityp[ATMsel]) - 1;
44393    } else {
44394 	fftlist.select = -1;
44395 	for (i=0; i<*Ntyps[*fftyp]; i++)
44396 	   if (abs(xyzp->ityp[ATMsel]) - 1 == fftlist.list.ilst[i]) fftlist.select = i;
44397    }
44398    if (fftlist.select >= *fftlist.list.nents) fftlist.select = 0;
44399    if (fftlist.select == -1 && ffptr[*fftyp] != NULL
44400 	&& fftlist.list.ilst != NULL) {
44401 	for (i=0; i<*Ntyps[*fftyp]; i++) {
44402 	   if (xyzp->ianz[ATMsel] == ffatnr[*fftyp][i]) {
44403 		fftlist.lpnt = i;
44404 		break;
44405 	   }
44406 	}
44407    } else {
44408 	if (fftlist.select != -1) {
44409 	   fftlist.lpnt = fftlist.select - 4;
44410 	}
44411    }
44412    if (fftlist.lpnt < 0) fftlist.lpnt = 0;
44413    if (fftlist.lpnt > *fftlist.list.nents - fftlist.mxents)
44414 	fftlist.lpnt = *fftlist.list.nents - fftlist.mxents;
44415    if (! *fftyp) {
44416 	fftlist.select = 0;
44417 	fftlist.lpnt = 0;
44418 	*fftlist.scrbar.wpos = 0;
44419    }
44420    butATM[1].str = ForceFields[*fftyp];
44421 }
44422 
RedrawATM()44423 void RedrawATM()
44424 {
44425   int i;
44426   char nrstr[80];
44427   char atstr[3];
44428 
44429   butje(ATMwin,0,0,ATMWINW,75,4,0,0,1,None,0,0,0);
44430   butje(ATMwin,0,75,ATMWINW,ATMWINH-75,4,0,0,1,None,0,0,0);
44431   LineString(ATMwin, "Force Field ",ATMOffx, 30);
44432   LineString(ATMwin, "Total Charge",ATMOffx, 30+BUTTN);
44433   strcpy(atstr,"  ");
44434   if (ATMsel >= 0 && ATMsel < *xyzp->mxnat) {
44435      if (xyzp->ianz[ATMsel] >= 0 && xyzp->ianz[ATMsel] < MXEL)
44436 	strcpy(atstr,elements[xyzp->ianz[ATMsel]]);
44437 
44438   }
44439 
44440   sprintf(nrstr,"Atom: %s", atstr);
44441   LineString(ATMwin, nrstr,ATMOffx, 30+3*BUTTN);
44442   ULineString(ATMwin,"Atom Type",ATMOffx, 43+4*BUTTN+QBOXHIGH);
44443   for (i=0; i<NBUTATM; i++) DrwBut(&butATM[i]);
44444   PromptBox(&qboxes[QCHARG]);
44445   PromptBox(&qboxes[QRSD]);
44446   PromptBox(&qboxes[QATOM]);
44447   RedrawList(&fftlist);
44448 }
44449 
ButtonsATM(i)44450 int ButtonsATM(i)
44451 int i;
44452 {
44453   int ff,nuse;
44454 
44455   switch (i) {
44456   case 0:	{
44457 	if (DoPopUp(ATMwin,butATM[0].x-8,butATM[0].y+BUTTH,
44458 			NULL,&xyzp->iatclr[ATMsel],0) == -1) break;
44459 	   DrwBut(&butATM[0]);
44460 	   *Sinct = 0;
44461 	   return(1);
44462 	}
44463 	break;
44464   case 1:	{
44465 	LSSTRU List;
44466 	List.list = ForceFields; List.nents = 8;
44467 	if (DoPopUp(ATMwin,butATM[1].x+20,butATM[1].y,
44468 			&List,fftyp,0) == -1) break;
44469 	   butATM[1].str = ForceFields[*fftyp];
44470 	   DrwBut(&butATM[1]);
44471 #if defined(VMS) || defined(UNDERSC)
44472 	   dotyp(&cell->ichx);
44473 #else
44474 #ifdef CRAY
44475 	   DOTYP(&cell->ichx);
44476 #else
44477 	   dotyp_(&cell->ichx);
44478 #endif
44479 #endif
44480 	   Progs = TnkProgs;
44481 	   nprogs = 6;
44482 	   if (*fftyp == 7) {
44483 		Progs = AmbProgs;
44484 		nprogs = 3;
44485 		*tnkprg = 0;
44486 	   }
44487            UpdateATM();
44488            RedrawATM();
44489 	   return(1);
44490 	}
44491 	break;
44492   case 2:	{
44493 	LSSTRU List; int totch;
44494 
44495 	List.list = copt; List.nents = 7;
44496 	if (DoPopUp(ATMwin,butATM[2].x+20,butATM[2].y,
44497 		&List,&itcopt,0) == -1) break;
44498 	   butATM[2].str = copt[itcopt];
44499 	   DrwBut(&butATM[2]);
44500 	   totch = itcopt -3;
44501 #if defined(VMS) || defined(UNDERSC)
44502 	   fixchg(&totch,xyzp->qat);
44503 #else
44504 #ifdef CRAY
44505 	   FIXCHG(&totch,xyzp->qat);
44506 #else
44507 	   fixchg_(&totch,xyzp->qat);
44508 #endif
44509 #endif
44510 	   qdpptr->ihasq = 1;
44511            UpdateATM();
44512            RedrawATM();
44513 	   return(1);
44514 	}
44515 	break;
44516   case 3:
44517 #ifdef DOGL
44518 	if ((*fancy || *fullgl) && has_opengl) ogunsel();
44519 #endif
44520 	XDestroyWindow(display,ATMwin);
44521 	ATMup = 0;
44522 	*Sinct = ATMt;
44523 	return(1);
44524 	break;
44525   case 4:
44526 	if ( ! ((*fftyp >= 1 && *fftyp <= 4) || *fftyp == 7) ) {
44527 	   if (DoCan(event.xbutton.x_root,
44528 		event.xbutton.y_root,"No Tinker or AMBFOR Force Field Selected !",0)) {}
44529 	} else {
44530 	   if ( ! ((*fftyp >= 1 && *fftyp <= 4) || *fftyp == 7) ) {
44531 		ff = 1;
44532 		if (pdb) ff = 7;
44533 	   } else {
44534 		ff = *fftyp;
44535 	   }
44536 	   if (typit(ff,0)) {
44537 		if (DoCan(event.xbutton.x_root,
44538 		   event.xbutton.y_root,"Found UnTyped Atoms !",0)) {}
44539 	   } else {
44540 		*iixyz = 6;
44541 		if (TNKup) {
44542 		   XMapRaised(display,TNKwin);
44543 		   RedrawTNK();
44544 		} else {
44545 		   InitTNK(event.xbutton.x_root,
44546 			event.xbutton.y_root);
44547 		}
44548 	   }
44549 	}
44550 	break;
44551   case 5:
44552 	*icalc = 1;
44553 	fprintf(stderr,"\n - vdWaals only for H,C,N,O,S,Cl\n\
44554  - residue 0 is not considered in residue-residue electrostatics\n");
44555 #if defined(VMS) || defined(UNDERSC)
44556 	nuse = 0; calcij(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44557 	nuse = 2; calcij(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44558 	nuse = 3; calcij(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44559 	nuse = 4; calcij(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44560 #else
44561 #ifdef CRAY
44562 	nuse = 0; CALCIJ(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44563 	nuse = 2; CALCIJ(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44564 	nuse = 3; CALCIJ(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44565 	nuse = 4; CALCIJ(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44566 #else
44567 	nuse = 0; calcij_(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44568 	nuse = 2; calcij_(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44569 	nuse = 3; calcij_(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44570 	nuse = 4; calcij_(&nuse,xyzp->coo,xyzp->ianz,xyzp->iresid,xyzp->iconn,xyzp->qat);
44571 #endif
44572 #endif
44573 	break;
44574   }
44575   return(0);
44576 }
44577 
44578 #define ROWLEN 10
44579 
InitSEQ(x,y)44580 void InitSEQ(x,y)
44581 int x,y;
44582 {
44583    int i,row,col;
44584    char wgeom[64];
44585 
44586    SEQup = 1;
44587 
44588    sprintf(wgeom,"+%d+%d",x,y);
44589 
44590    SEQwin = CreateWindow("Build Sequence Window",wgeom,SEQWINW,SEQWINH,
44591 	 		 infobg,infofg,(Window)0);
44592    XSelectInput(display, SEQwin, KeyPressMask | ExposureMask | ButtonPressMask
44593 	| ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
44594    XMapWindow(display,SEQwin);
44595 
44596    WinObj[21].win = &SEQwin;
44597    WinObj[21].subwin = NULL;
44598    WinObj[21].butarr = butSEQ;
44599    WinObj[21].numbut = NBUTSEQ;
44600    WinObj[21].winup = &SEQup;
44601    WinObj[21].redraw = RedrawSEQ;
44602 
44603    DefBut(&butSEQ[0], SEQwin, 100, SEQCONFY, 100, 23, "Alpha", infobg, ZMBCOL);
44604    butSEQ[0].str = Conformations[iconform];
44605 
44606    DefBut(&butSEQ[1], SEQwin, SEQOffx,      SEQBROWY, 75, 23, "Build",
44607 	infobg, ZMBCOL);
44608 
44609    DefBut(&butSEQ[2], SEQwin, SEQOffx+90,   SEQBROWY, 75, 23, "Undo",
44610 	infobg, ZMBCOL);
44611 
44612    DefBut(&butSEQ[4], SEQwin, SEQOffx+2*90, SEQBROWY, 75, 23, "Read",
44613 	infobg, ZMBCOL);
44614 
44615    DefBut(&butSEQ[3], SEQwin, SEQOffx+3*90, SEQBROWY, 75, 23, "Close",
44616 	infobg, ZMBCOL);
44617 
44618    for (i=0; i < NAminos; i++) {
44619       row = i / ROWLEN;
44620       col = i - row*ROWLEN;
44621       DefBut(&butSEQ[5+i], SEQwin, SEQOffx+col*40, SEQRESY+row*30, 35, 23,
44622 	AminoAcids[i], infobg, ZMBCOL);
44623    }
44624 
44625    qboxstr(&qboxes[QPHI],&SEQwin,1,0,190,210,SEQCONFY-5,
44626         100,QBOXHIGH,2,"PHI"," ",SUBLEN2,QREAL,2000,-1,dummyproc);
44627    qboxstr(&qboxes[QPSI],&SEQwin,0,0,190,320,SEQCONFY-5,
44628         100,QBOXHIGH,2,"PSI"," ",SUBLEN2,QREAL,2000,-1,dummyproc);
44629 
44630    phi_angle = phis[iconform];
44631    psi_angle = psis[iconform];
44632    sprintf(qboxes[QPHI].str,"%-9.3f",phi_angle);
44633    sprintf(qboxes[QPSI].str,"%-9.3f",psi_angle);
44634    qboxes[QPHI].curpos = strlen(qboxes[QPHI].str);
44635    qboxes[QPSI].curpos = strlen(qboxes[QPSI].str);
44636 }
44637 
RedrawSEQ()44638 void RedrawSEQ()
44639 {
44640   int i;
44641 
44642   butje(SEQwin,0,0,SEQWINW,SEQWINH,4,0,0,1,None,0,0,0);
44643 
44644   LineString(SEQwin, "Residues:",SEQOffx, SEQRESY - 10);
44645   LineString(SEQwin, "Conformation:",SEQOffx, SEQCONFY+13);
44646   for (i=0; i<NBUTSEQ; i++) DrwBut(&butSEQ[i]);
44647   UpdateSeqStat();
44648   PromptBox(&qboxes[QPHI]);
44649   PromptBox(&qboxes[QPSI]);
44650 
44651 }
44652 
UpdateSeqStat()44653 void UpdateSeqStat()
44654 {
44655   int i;
44656   int il;
44657 
44658   il = NSeq-16;
44659   if (il < 0) il = 0;
44660 
44661   strcpy(SeqStat," ");
44662   for (i=il; i < NSeq; i++) {
44663 	strcat(SeqStat,AminoAcids[Sequence[i]]);
44664 	if (i < NSeq-1) strcat(SeqStat,"-");
44665   }
44666 
44667   butje(SEQwin,SEQOffx,SEQSTATY,SEQWINW-2*SEQOffx,30,2,0,2,0,None,0,0,0);
44668   LineString(SEQwin, SeqStat,SEQOffx, SEQSTATY+18);
44669 
44670 }
44671 
ButtonsSEQ(i)44672 int ButtonsSEQ(i)
44673 int i;
44674 {
44675   int residue, newSQ;
44676 
44677   switch (i) {
44678   case 0:	{
44679 	LSSTRU List;
44680 	List.list = Conformations; List.nents = 3;
44681 	   if (DoPopUp(SEQwin,butSEQ[0].x+4,butSEQ[0].y+BUTTH-5,
44682 		&List,&iconform,0) == -1) break;
44683 	   butSEQ[0].str = Conformations[iconform];
44684 	   phi_angle = phis[iconform];
44685 	   psi_angle = psis[iconform];
44686 	   sprintf(qboxes[QPHI].str,"%-9.3f",phi_angle);
44687 	   sprintf(qboxes[QPSI].str,"%-9.3f",psi_angle);
44688 	   qboxes[QPHI].curpos = strlen(qboxes[QPHI].str);
44689 	   qboxes[QPSI].curpos = strlen(qboxes[QPSI].str);
44690 	   PromptBox(&qboxes[QPHI]);
44691 	   PromptBox(&qboxes[QPSI]);
44692 	   DrwBut(&butSEQ[0]);
44693 	}
44694 	break;
44695   case 1:
44696 	phi_angle = atof(qboxes[QPHI].str);
44697 	psi_angle = atof(qboxes[QPSI].str);
44698 	newSQ = LastAmino;
44699 	if (InsertAmino != -1) {
44700 	   if (ReplaceAmino)
44701 		ReplaceSequence(Sequence,NSeq,iconform,InsertAmino);
44702 	   else
44703 		idum1 = InsertSequence(Sequence,NSeq,iconform,InsertAmino,0,NULL);
44704 	   InsertAmino = -1;
44705 	   ReplaceAmino = 0;
44706 	   NSeq = 0;
44707 	   UpdateSeqStat();
44708 	   XSync(display, False);
44709 	   XDestroyWindow(display,SEQwin);
44710 	   SEQup = 0;
44711 	} else {
44712 	   ReplaceAmino = 0;
44713 	   AddSequence(Sequence,NSeq,iconform);
44714 	   NSeq = 0;
44715 	   UpdateSeqStat();
44716 	}
44717 	if (ZMEAA) {
44718 	   *Sinct = 530;
44719 	} else {
44720 	   make_aa();
44721 	   SetQZME();
44722 /*
44723 	   TogUp(&ZMEswitch[0]);
44724 	   EXPbox[0].fake = 0;
44725 */
44726 	   UpdateZME(); RedrawZME();
44727 	}
44728 	if (newSQ == -1) {
44729 #if defined(VMS) || defined(UNDERSC)
44730 	   dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
44731 	   conpdb();docent();doscal();setxyv();doclr();qupd();
44732 #else
44733 #ifdef CRAY
44734 	   DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
44735 	   CONPDB();DOCENT();DOSCAL();SETXYV();doclr();QUPD();
44736 #else
44737    	   dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
44738 	   conpdb_();docent_();doscal_();setxyv_();doclr();qupd_();
44739 #endif
44740 #endif
44741 	}
44742 	return(1);
44743 	break;
44744   case 2:
44745 	NSeq--;
44746 	if (NSeq < 0) NSeq = 0;
44747 	UpdateSeqStat();
44748 	break;
44749   case 3:
44750 	XDestroyWindow(display,SEQwin);
44751 	SEQup = 0;
44752 	break;
44753   case 4:
44754 	if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
44755 	   "Protein File, per line:\n\n\
44756 3 letter amino acid code Phi Psi [Omega] [Chi1] [Chi2] [Chi3] [Chi4]\n\n\
44757 The current Conformation will be assigned to it",0)) {}
44758 	qboxstr(&qboxes[QPROT],NULL,1,0,-1, DEFQX,DEFQY,
44759 	   QBOXWIDE,QBOXHIGH,0,"Protein Filename ? ",NULL,0,0,
44760 	   640,0,dummyproc);
44761 	break;
44762   default:
44763 	residue = i - 5;
44764 	if (residue >= 0 && residue < NAminos) {
44765 	   if (NSeq < MAXSEQ-1) {
44766 		Sequence[NSeq] = residue;
44767 		NSeq++;
44768 	   }
44769 	}
44770 	UpdateSeqStat();
44771 	break;
44772   }
44773   return(0);
44774 }
44775 
44776 #if defined(VMS) || defined(UNDERSC)
addchg()44777 void addchg()
44778 #else
44779 #ifdef CRAY
44780 void ADDCHG()
44781 #else
44782 void addchg_()
44783 #endif
44784 #endif
44785 {
44786 	int ir,ifft;
44787 
44788 	ifft = *fftyp;
44789         *fftyp = 7;
44790 
44791 #if defined(VMS) || defined(UNDERSC)
44792 	clceem(&calfptr->ishoh);
44793 #else
44794 #ifdef CRAY
44795 	CLCEEM(&calfptr->ishoh);
44796 #else
44797 	clceem_(&calfptr->ishoh);
44798 #endif
44799 #endif
44800         *fftyp = ifft;
44801 	ir = abs(xyzp->iresid[0]);
44802 	clfstrptr->ihetq[ir] = 0;
44803 	clfstrptr->ihqset[ir] = 1;
44804 }
44805 
InitTNK(x,y)44806 void InitTNK(x,y)
44807 int x,y;
44808 {
44809    char wgeom[64];
44810    int i,xmax;
44811 
44812    TNKup = 1;
44813 
44814    Progs = TnkProgs;
44815    nprogs = 6;
44816    AddChrg = 0;
44817 
44818    if (*ipdbon && calfptr->ncalf) {
44819 	Cutoff = 1;
44820    } else {
44821 	Cutoff = 0;
44822    }
44823 
44824    if (*fftyp == 7) {
44825 	Progs = AmbProgs;
44826 	nprogs = 3;
44827 	AddChrg = 1;
44828 	*tnkprg = 0;
44829    }
44830 
44831    xmax = DisplayWidth(display,screen) - TNKWINW;
44832    if (x > xmax) x = xmax;
44833    sprintf(wgeom,"+%d+%d",x,y);
44834 
44835    TNKwin = CreateWindow("Tinker/AMBFOR Preferences",wgeom,TNKWINW,TNKWINH,
44836 	 		 infobg,infofg,(Window)0);
44837    XSelectInput(display, TNKwin, KeyPressMask | ExposureMask | ButtonPressMask
44838 	| ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask
44839 	| SubstructureNotifyMask | PointerMotionMask | EnterWindowMask);
44840    subTNK = CreateWindow("Subwindow","",10,10,
44841                             colors[0],colors[15],TNKwin);
44842    XMapWindow(display,TNKwin);
44843 
44844    WinObj[22].win = &TNKwin;
44845    WinObj[22].subwin = &subTNK;
44846    WinObj[22].butarr = butTNK;
44847    WinObj[22].numbut = NBUTTNK;
44848    WinObj[22].winup = &TNKup;
44849    WinObj[22].redraw = RedrawTNK;
44850 
44851    DefBut(&butTNK[0], TNKwin, 100, TNKRESY, 80, 23, "minimize", infobg, ZMBCOL);
44852    butTNK[0].str = Progs[*tnkprg];
44853    butTNK[0].explstr = "Choose optimisation/MD program";
44854 
44855    DefBut(&butTNK[1], TNKwin, 100, TNKRESY+TNKBWIDE, 15, 15, " ",
44856 	infobg, ZMBCOL);
44857    butTNK[1].explstr = "Detach Job:\ndont wait for the job to finish";
44858 
44859    DefBut(&butTNK[2], TNKwin, 100, TNKRESY+2*TNKBWIDE, 15, 15, " ",
44860 	infobg, ZMBCOL);
44861    butTNK[2].explstr = "Archive Job:\ncreate archive file with multiple\nintermediate structures";
44862 
44863    DefBut(&butTNK[3], TNKwin, TNKOffx, TNKBROWY, 75, 23, "GO",
44864 	infobg, ZMBCOL);
44865    butTNK[3].explstr = "Start the optimisation/MD";
44866 
44867    DefBut(&butTNK[4], TNKwin, TNKOffx+100, TNKBROWY, 75, 23, "Close",
44868 	infobg, ZMBCOL);
44869    butTNK[4].explstr = "close this window";
44870 
44871    DefBut(&butTNK[5], TNKwin, 100, TNKRESY+3*TNKBWIDE, 15, 15, " ",
44872 	infobg, ZMBCOL);
44873    butTNK[5].explstr = "Calculate partial charges";
44874 
44875 
44876    DefBut(&butTNK[6], TNKwin, TNKOffx+200, TNKBROWY, 100, 23, "Constrain",
44877 	infobg, ZMBCOL);
44878    butTNK[6].explstr = "Select rigid and flexible parts";
44879 
44880    DefBut(&butTNK[7], TNKwin, 100, TNKRESY+4*TNKBWIDE, 15, 15, " ",
44881 	infobg, ZMBCOL);
44882    butTNK[7].explstr = "Use/Create periodic water box";
44883 
44884    DefBut(&butTNK[8], TNKwin, 210, TNKRESY+4*TNKBWIDE, 15, 15, " ",
44885 	infobg, ZMBCOL);
44886    butTNK[8].explstr = "Use cutoffs and switch functions (Faster)";
44887 
44888    if (hasmpi) {
44889 	DefBut(&butTNK[9], TNKwin, 300, TNKRESY+4*TNKBWIDE, 15, 15, " ",
44890 		infobg, ZMBCOL);
44891 	butTNK[9].explstr = "Use multiple processors";
44892 	DefBut(&butTNK[10], TNKwin, 350, TNKRESY+4*TNKBWIDE-5, 30, 23, " ",
44893 		infobg, ZMBCOL);
44894 	butTNK[10].explstr = "Use # processors";
44895 	butTNK[10].str = Processors[useproc-1];
44896    }
44897 
44898    if (*tnkbg) {
44899 	TogDown(&butTNK[1]);
44900    } else {
44901 	TogUp(&butTNK[1]);
44902    }
44903 
44904    if (*arch) {
44905 	TogDown(&butTNK[2]);
44906    } else {
44907 	TogUp(&butTNK[2]);
44908    }
44909 
44910    if (AddChrg) {
44911 	TogDown(&butTNK[5]);
44912    } else {
44913 	TogUp(&butTNK[5]);
44914    }
44915 
44916    if (Cutoff) {
44917 	TogDown(&butTNK[8]);
44918    } else {
44919 	TogUp(&butTNK[8]);
44920    }
44921 
44922    if (hasmpi) {
44923 	if (usempi) {
44924 	   TogDown(&butTNK[9]);
44925 	} else {
44926 	   TogUp(&butTNK[9]);
44927 	}
44928    }
44929 
44930    qboxstr(&qboxes[QGRD],&TNKwin,0,0,190,210,TNKRESY-5,
44931         200,QBOXHIGH,2,"RMS Gradient"," ",SUBLEN1,QREAL,2000,-1,dummyproc);
44932    qboxstr(&qboxes[QTNKJN],&TNKwin,1,0,190,210,TNKRESY+TNKBWIDE-5,
44933         200,QBOXHIGH,2,"Job Name",NULL,SUBLEN2,0,2000,-1,dummyproc);
44934    qboxstr(&qboxes[QARCH],&TNKwin,0,0,190,210,TNKRESY+2*TNKBWIDE-5,
44935         200,QBOXHIGH,2,"Archive Update Freq.",NULL,SUBLEN1,QPOSINT,2000,-1,dummyproc);
44936    qboxstr(&qboxes[QMAXIT],&TNKwin,0,0,190,210,TNKRESY+3*TNKBWIDE-5,
44937         200,QBOXHIGH,2,"Max. Iteration",NULL,SUBLEN1,QPOSINT,2000,-1,dummyproc);
44938 
44939    *currgrd = mxgrads[*tnkprg];
44940    sprintf(qboxes[QGRD].str,"%-9.3f",*currgrd);
44941    qboxes[QGRD].explstr = "Gradient at which the optimisation\n is considered finished";
44942    sprintf(qboxes[QARCH].str,"%d",*archfrq);
44943    qboxes[QARCH].explstr = "How frequent an intermediate structure \nshould be added to the archive file";
44944    sprintf(qboxes[QTNKJN].str,"molin");
44945    qboxes[QTNKJN].explstr = "Job name and basename of output files";
44946    strcp(tnkjn,qboxes[QTNKJN].str,SUBLEN2);
44947    TrmStr(&qboxes[QTNKJN]);
44948    sprintf(qboxes[QMAXIT].str,"%d",*tnkit);
44949    qboxes[QMAXIT].explstr = "Maximum number of iterations of the \noptimisation/MD";
44950    qboxes[QGRD].curpos = strlen(qboxes[QGRD].str);
44951    qboxes[QARCH].curpos = strlen(qboxes[QARCH].str);
44952    qboxes[QTNKJN].curpos = strlen(qboxes[QTNKJN].str);
44953    qboxes[QMAXIT].curpos = strlen(qboxes[QMAXIT].str);
44954 
44955 }
44956 
RedrawTNK()44957 void RedrawTNK()
44958 {
44959   int i;
44960 
44961   butje(TNKwin,0,0,TNKWINW,TNKWINH,4,0,0,1,None,0,0,0);
44962 
44963   LineString(TNKwin, "Optimizer:",TNKOffx, TNKRESY+13);
44964   LineString(TNKwin, "Archive",TNKOffx, TNKRESY+2*TNKBWIDE+11);
44965   LineString(TNKwin, "Detach Job",TNKOffx, TNKRESY+TNKBWIDE+11);
44966   if (Progs == AmbProgs) {
44967 	LineString(TNKwin, "Calc. Charge",TNKOffx, TNKRESY+3*TNKBWIDE+11);
44968 	for (i=0; i<ntnkb; i++) DrwBut(&butTNK[i]);
44969 	if (*tnkprg == 1) {
44970 	   qboxes[QGRD].prompt = "Temperature";
44971 	   qboxes[QMAXIT].prompt = "No. of steps";
44972 	} else {
44973 	   qboxes[QGRD].prompt = "RMS Gradient";
44974 	   qboxes[QMAXIT].prompt = "Max. Iteration";
44975 	}
44976         LineString(TNKwin, "Water Box",TNKOffx, TNKRESY+4*TNKBWIDE+11);
44977         LineString(TNKwin, "Use Cutoff",235, TNKRESY+4*TNKBWIDE+11);
44978 	if (hasmpi) LineString(TNKwin, "MPI",325, TNKRESY+4*TNKBWIDE+11);
44979   } else {
44980 	for (i=0; i<NBUTTNK-6; i++) DrwBut(&butTNK[i]);
44981 	qboxes[QGRD].prompt = "RMS Gradient";
44982 	qboxes[QMAXIT].prompt = "Max. Iteration";
44983   }
44984   PromptBox(&qboxes[QGRD]);
44985   PromptBox(&qboxes[QARCH]);
44986   PromptBox(&qboxes[QTNKJN]);
44987   PromptBox(&qboxes[QMAXIT]);
44988 
44989 }
44990 
ChkJobName()44991 int ChkJobName()
44992 {
44993    char JobName[MAXSTRLEN];
44994 
44995    strcpy(JobName,qboxes[QTNKJN].str);
44996    strcat(JobName,".xyz");
44997    if (strcmp(strname,JobName) == 0) {
44998 	DoCan(event.xbutton.x_root, event.xbutton.y_root,
44999 	"Jobname and file currently read can not be the same.",0);
45000 	return(0);
45001    }
45002    return(1);
45003 }
45004 
ButtonsTNK(i)45005 int ButtonsTNK(i)
45006 int i;
45007 {
45008   int nwat;
45009 
45010   switch (i) {
45011   case 0:	{
45012 	LSSTRU List;
45013 	List.list = Progs; List.nents = nprogs;
45014 	   if (DoPopUp(TNKwin,butTNK[0].x+4,butTNK[0].y+BUTTH-5,
45015 		&List,tnkprg,0) == -1) break;
45016 	   butTNK[0].str = Progs[*tnkprg];
45017 	   if (Progs == AmbProgs) {
45018 		pbc->icell = 0;
45019 		butTNK[10].str = Processors[useproc-1];
45020 		if (*tnkprg == 1) {
45021 		   *currgrd = 298.0;
45022 		   sprintf(qboxes[QGRD].str,"%-7.2f",*currgrd);
45023 		   *tnkit = 1000;
45024 		   sprintf(qboxes[QMAXIT].str,"%-5d",*tnkit);
45025 		} else {
45026 	   	   *currgrd = mxgrads[0];
45027 		   sprintf(qboxes[QGRD].str,"%-7.2f",*currgrd);
45028 		   *tnkit = 999;
45029 		   sprintf(qboxes[QMAXIT].str,"%-d",*tnkit);
45030 		   if (*tnkprg == 2) {
45031 			pbc->icell = 1;
45032 #if defined(VMS) || defined(UNDERSC)
45033 			fdat(&EIGHTEEN,&ZERO,&ZERO,&ZERO,&ZERO,&ZERO);
45034 #else
45035 #ifdef CRAY
45036 			FDAT(&EIGHTEEN,&ZERO,&ZERO,&ZERO,&ZERO,&ZERO);
45037 #else
45038 			fdat_(&EIGHTEEN,&ZERO,&ZERO,&ZERO,&ZERO,&ZERO);
45039 #endif
45040 #endif
45041 		   }
45042 		}
45043 		qboxes[QGRD].curpos = strlen(qboxes[QGRD].str);
45044 		qboxes[QMAXIT].curpos = strlen(qboxes[QMAXIT].str);
45045 	  	RedrawTNK();
45046 	   } else {
45047 	   	*currgrd = mxgrads[*tnkprg];
45048 	   	sprintf(qboxes[QGRD].str,"%-9.3f",*currgrd);
45049 		qboxes[QGRD].curpos = strlen(qboxes[QGRD].str);
45050 	   	PromptBox(&qboxes[QGRD]);
45051 
45052 		if (*tnkprg == 4) {
45053 		   List.list = xtinkopts; List.nents = 2;
45054 		   if (DoPopUp(TNKwin,butTNK[0].x-8,butTNK[0].y+BUTTH,
45055 				&List,iqopt,0) == -1) {int idum; idum = 1;}
45056 		}
45057 		DrwBut(&butTNK[0]);
45058 	   }
45059 	}
45060 	break;
45061   case 1:
45062 /* background */
45063 	*tnkbg = ! TogBut(&butTNK[1]);
45064 	break;
45065   case 2:
45066 /* archive */
45067 	*arch = ! TogBut(&butTNK[2]);
45068 	break;
45069   case 3:
45070 /* go */
45071 	if (ChkJobName()) {
45072 #ifdef DOGL
45073 	   ogunsel();
45074 #endif
45075 	   if (*ipdbon) {
45076 #ifdef DOGL
45077 		if (!bckrig) empty_ribb();
45078 #endif
45079 
45080 #if defined(VMS) || defined(UNDERSC)
45081 		quwat(&nwat);
45082 #else
45083 #ifdef CRAY
45084 		QUWAT(&nwat);
45085 #else
45086 		quwat_(&nwat);
45087 #endif
45088 #endif
45089 		if (nwat > 0) {
45090 		    if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
45091 		"Waters without Hydrogens detected.\n Should Molden clean up waters ?",1)) {
45092 			if (*fftyp != 7) typit(7,0);
45093 #if defined(VMS) || defined(UNDERSC)
45094 			evwat();
45095 #else
45096 #ifdef CRAY
45097 			EVWAT();
45098 #else
45099 			evwat_();
45100 #endif
45101 #endif
45102 #ifdef DOGL
45103 			if (*fancy) {
45104 			   oghet(0);
45105 			} else {
45106 			   oglines();
45107 			}
45108 			update_model = 0;
45109 #endif
45110 			update_struct();
45111 		    }
45112 	       }
45113 
45114 	   }
45115 	   *currgrd = atof(qboxes[QGRD].str);
45116 	   *archfrq = atoi(qboxes[QARCH].str);
45117 	   *tnkit = atoi(qboxes[QMAXIT].str);
45118 	   cpstr(qboxes[QTNKJN].str,tnkjn,SUBLEN1);
45119 	   XDestroyWindow(display,TNKwin);
45120 	   TNKup = 0;
45121    	   if (*fftyp == 7) {
45122 		*iixyz = 11;
45123 	   } else {
45124 		if (*tnkprg == 4) {
45125 		   *iixyz = 10;
45126 		} else {
45127 		   *iixyz = 6;
45128 		}
45129 	   }
45130 	   if (AddChrg) {
45131 #if defined(VMS) || defined(UNDERSC)
45132 		clceem(&calfptr->ishoh);
45133 #else
45134 #ifdef CRAY
45135 		CLCEEM(&calfptr->ishoh);
45136 #else
45137 		clceem_(&calfptr->ishoh);
45138 #endif
45139 #endif
45140 	   }
45141 	   if (*ibox || Box) *igfmap = 0;
45142 
45143 	   *Sinct = 151;
45144 	   return(1);
45145 	}
45146 	break;
45147   case 4:
45148 /* close */
45149 	*currgrd = atof(qboxes[QGRD].str);
45150 	*archfrq = atoi(qboxes[QARCH].str);
45151 	*tnkit = atoi(qboxes[QMAXIT].str);
45152 	cpstr(qboxes[QTNKJN].str,tnkjn,SUBLEN1);
45153 	XDestroyWindow(display,TNKwin);
45154 	TNKup = 0;
45155 	break;
45156   case 5:
45157 /* Calculate Charge */
45158 	AddChrg = ! TogBut(&butTNK[5]);
45159 	break;
45160   case 6:
45161 	if (!FLRup) CreateFLR();
45162 	break;
45163   case 7:
45164 /* Box */
45165 	Box = ! TogBut(&butTNK[7]);
45166 	break;
45167   case 8:
45168 /* Cutoffs */
45169 	Cutoff = ! TogBut(&butTNK[8]);
45170 	break;
45171   case 9:
45172 /* mpi */
45173 	if (hasmpi) usempi = ! TogBut(&butTNK[9]);
45174 	break;
45175   case 10:
45176 /* number of processors */
45177 	{
45178 	LSSTRU List;
45179 	List.list = Processors; List.nents = maxproc;
45180 	if (DoPopUp(TNKwin,butTNK[10].x+1,
45181 		   butTNK[10].y-(maxproc/2)*BUTTH,&List,&useproc,0) == -1) break;
45182 	useproc++;
45183 	butTNK[10].str = Processors[useproc-1];
45184 	DrwBut(&butTNK[10]);
45185 	}
45186 	break;
45187   default:
45188 	break;
45189   }
45190   return(0);
45191 }
45192 
rearr(itarr,arr)45193 void rearr(itarr,arr)
45194 int *itarr;
45195 int *arr;
45196 {
45197    int j;
45198 
45199    for (j=0; j<*zmptrp->nz; j++) {
45200 	itarr[j] = arr[zmptrp->imap[j]-1];
45201    }
45202    for (j=0; j<*zmptrp->nz; j++) {
45203 	arr[j] = itarr[j];
45204    }
45205 }
45206 
rearrs(itarr,arr)45207 void rearrs(itarr,arr)
45208 int *itarr;
45209 short int *arr;
45210 {
45211    int j;
45212 
45213    for (j=0; j<*zmptrp->nz; j++) {
45214 	itarr[j] = (int) arr[zmptrp->imap[j]-1];
45215    }
45216    for (j=0; j<*zmptrp->nz; j++) {
45217 	arr[j] = (short int) itarr[j];
45218    }
45219 }
45220 
rearrd(itarr,arr)45221 void rearrd(itarr,arr)
45222 double *itarr;
45223 double *arr;
45224 {
45225    int j;
45226 
45227    for (j=0; j<*zmptrp->nz; j++) {
45228 	itarr[j] = arr[zmptrp->imap[j]-1];
45229    }
45230    for (j=0; j<*zmptrp->nz; j++) {
45231 	arr[j] = itarr[j];
45232    }
45233 }
45234 
rearrz(itarr)45235 void rearrz(itarr)
45236 int *itarr;
45237 {
45238    int j;
45239 
45240    for (j=0; j<*zmptrp->nz; j++) itarr[j] = -1;
45241    for (j=0; j<*zmptrp->nz; j++) {
45242 	if (zmptrp->imap[j] > 0) {
45243 	   itarr[zmptrp->imap[j]-1] = j;
45244 	}
45245    }
45246 }
45247 
mapchk()45248 int mapchk()
45249 {
45250    int j;
45251 
45252     if (*ialtyp) return(1);
45253 
45254     for (j=0; j<*zmptrp->nz; j++) {
45255 	if (zmptrp->imap[j]-1 != j) {
45256 	    return(0) ;
45257 	}
45258     }
45259     return (1);
45260 }
45261 
45262 #if defined(VMS) || defined(UNDERSC)
dozmt(ioke)45263 int dozmt(ioke)
45264 #else
45265 #ifdef CRAY
45266 int DOZMT(ioke)
45267 #else
45268 int dozmt_(ioke)
45269 #endif
45270 #endif
45271 int *ioke;
45272 {
45273 
45274 
45275         *ioke = 0;
45276         if (!xison) return 0;
45277 	if (!*zmptrp->ihaszm) {
45278 	   if (!DoCan(200,100,
45279 		"Do You want to create a Z-matrix for this molecule ?",1)) {
45280 	     *ioke = 1;
45281 	     if (*xyzp->iatoms > *zmptrp->mxzat - 100) {
45282 		*ioke = 0;
45283                 if (AllocZMat(*xyzp->mxnat,ZERO)) *ioke = 1;
45284 	     }
45285 	   }
45286 	}
45287 	return 1;
45288 }
45289 
DoPDB(int ivis)45290 int DoPDB(int ivis)
45291 {
45292 int i,j,k;
45293 double d;
45294 int *iarr;
45295 double *darr;
45296 int imarr[NUMCAL];
45297 int ioke,ido;
45298 
45299 	ido = 0;
45300 	if (ivis) {
45301 	   if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
45302                 "Do You want to create a Z-matrix for this protein ?",1)) {
45303 		ido = 1;
45304 	   }
45305 	} else {
45306 	   ido = 1;
45307 	}
45308 
45309 	if (!*zmptrp->ihaszm) {
45310 	   if (ido) {
45311 	     ioke = 1;
45312 	     if (*xyzp->iatoms > *zmptrp->mxzat - 100) {
45313 		ioke = 0;
45314 		if (AllocZMat(*xyzp->mxnat,ZERO)) ioke = 1;
45315 	     }
45316 
45317 	     if (ioke) {
45318 #if defined(VMS) || defined(UNDERSC)
45319 		curs(&ONE);
45320 		XSync(display, False);
45321         	pdbzmt();
45322 #else
45323 #ifdef CRAY
45324 		CURS(&ONE);
45325 		XSync(display, False);
45326         	PDBZMT();
45327 #else
45328 		curs_(&ONE);
45329 		XSync(display, False);
45330         	pdbzmt_();
45331 #endif
45332 #endif
45333 		if (*zmptrp->ihaszm) {
45334 
45335 		   if ((iarr = (int *) malloc((sizeof j)*(*zmptrp->mxzat)))
45336 				!= NULL) {
45337 
45338 			rearr(iarr,xyzp->iatclr);
45339 			rearr(iarr,xyzp->iresid);
45340 			rearr(iarr,xyzp->iaton);
45341 			rearrs(iarr,xyzp->ityp);
45342 			rearrs(iarr,xyzp->ipdbt);
45343 
45344 			rearrz(iarr);
45345 			for (k=0; k<6; k++) {
45346 			   for (j=0; j<calfptr->ncalf; j++)
45347 				imarr[j] = calfptr->icalf[j][k];
45348 
45349 			   for (j=0; j<calfptr->ncalf; j++) {
45350 				if (imarr[j]-1 >= 0)
45351 				   calfptr->icalf[j][k] = iarr[imarr[j]-1]+1;
45352 			   }
45353 			}
45354 
45355 			free(iarr);
45356 		   }
45357 
45358 		   if ((darr = (double *) malloc((sizeof d)*(*zmptrp->mxzat)))
45359 				!= NULL) {
45360 
45361 			rearrd(darr,xyzp->qat);
45362 			free(darr);
45363 		   }
45364 
45365 /* old, with centering */   /*conpdb();chkbck();docent();doclr();qupd();*/
45366 
45367 		   UpdHet();
45368 #if defined(VMS) || defined(UNDERSC)
45369 		   dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
45370 		   conpdb();chkbck(&ONE);doclr();qupd();
45371 		   if (*backb) {
45372 			for (i=0;i<4;i++)
45373 			   acthel(&ONE,&i,&clfhptr->isndcl[i],&ZERO);
45374 		   }
45375 #else
45376 #ifdef CRAY
45377 		   DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
45378 		   CONPDB();CHKBCK(&ONE);doclr();QUPD();
45379 		   if (*backb) {
45380 			for (i=0;i<4;i++)
45381 			   ACTHEL(&ONE,&i,&clfhptr->isndcl[i],&ZERO);
45382 		   }
45383 #else
45384 		   dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
45385 		   conpdb_();chkbck_(&ONE);doclr();qupd_();
45386 		   if (*backb) {
45387 			for (i=0;i<4;i++)
45388 			   acthel_(&ONE,&i,&clfhptr->isndcl[i],&ZERO);
45389 		   }
45390 #endif
45391 #endif
45392 		   if (*backb) {
45393 			int it;
45394             		for (i=0;i < calfptr->ncalf;i++) {
45395 			   if (calfptr->reson[i] > 0) {
45396 		   		if (calfptr->iamino[i] > 23) {
45397             	   		   for (j=0;j<6;j++)  {
45398 				     it = calfptr->icalf[i][j];
45399 				     if (it > 0 && it < NUMCAL)
45400 			   		xyzp->iaton[calfptr->icalf[i][j]-1] = 1;
45401 				   }
45402 		   		} else {
45403             			   for (j=0;j<4;j++)  {
45404 				      it = calfptr->icalf[i][j];
45405 				      if (it > 0 && it < NUMCAL)
45406 			   		xyzp->iaton[calfptr->icalf[i][j]-1] = 1;
45407 				   }
45408 		   		}
45409 			   }
45410 	    		}
45411 		   }
45412 		   make_aa();
45413 
45414 		   if (ZMEup) {
45415 			SetQZME();
45416 			if (ZME_window_pos >= *zmptrp->nz) ZME_window_pos = 0;
45417 			RedrawZME();
45418 			RedrawScroll(&zscroll);
45419 		   }
45420 		}
45421 		SSdone[istruct] = 0;
45422 #if defined(VMS) || defined(UNDERSC)
45423 		curs(&ZERO);
45424 #else
45425 #ifdef CRAY
45426 		CURS(&ZERO);
45427 #else
45428 		curs_(&ZERO);
45429 #endif
45430 #endif
45431 	 	return(1);
45432 	      } else {
45433 		sprintf(ZMEerr,
45434 			"Couldnt allocate memory for Z-Matrix");
45435 		RedrawStatus();
45436 	      }
45437 	   } else {
45438 	      InitZME();
45439 	   }
45440 	}
45441 
45442 	return(0);
45443 }
45444 
DelCellAtoms()45445 void DelCellAtoms()
45446 {
45447 int i,j,k,nstor,nold,kcon,ab,noab;
45448 
45449 	i = 0;
45450 	nstor = *xyzp->mxnat - cell->natc;
45451 	while (i < cell->natc) {
45452 	  if (xyzp->iaton[i] == 2) {
45453 	    for (j=i; j < cell->natc - 1; j++) {
45454 		xyzp->iatclr[nstor+j] = xyzp->iatclr[nstor+j+1];
45455 		xyzp->ianz[nstor+j] = xyzp->ianz[nstor+j+1];
45456 		xyzp->ipdbt[nstor+j] = xyzp->ipdbt[nstor+j+1];
45457 		xyzp->ityp[nstor+j] = xyzp->ityp[nstor+j+1];
45458 		xyzp->qat[j] = xyzp->qat[j+1];
45459 		for (k=0; k < 3; k++)
45460 		   xyzp->coo[(nstor+j)*3+k] = xyzp->coo[(nstor+j+1)*3+k];
45461 		kcon = 0;
45462 		for (k=0; k < xyzp->iconn[(nstor+j+1)*(MXCON+1)]; k++) {
45463 		   noab = xyzp->iconn[(nstor+j+1)*(MXCON+1)+k+1];
45464 		   ab = ABS(noab);
45465 		   if (ab > i+1) {
45466 			if (noab > 0) {
45467 			   xyzp->iconn[(nstor+j)*(MXCON+1)+kcon+1] = noab - 1;
45468 			} else {
45469 			   xyzp->iconn[(nstor+j)*(MXCON+1)+kcon+1] = noab + 1;
45470 			}
45471 			kcon++;
45472 		   } else if (ab != i+1) {
45473 			xyzp->iconn[(nstor+j)*(MXCON+1)+kcon+1] = noab;
45474 			kcon++;
45475 		   }
45476 		}
45477 		xyzp->iconn[(nstor+j)*(MXCON+1)] = kcon;
45478 		xyzp->iaton[j] = xyzp->iaton[j+1];
45479 	    }
45480 	    cell->natc = cell->natc - 1;
45481 	    for (j=0; j < i; j++) {
45482 		kcon = 0;
45483 		for (k=0; k < xyzp->iconn[(nstor+j)*(MXCON+1)]; k++) {
45484 		   noab = xyzp->iconn[(nstor+j)*(MXCON+1)+k+1];
45485 		   ab = ABS(noab);
45486 		   if (ab > i+1) {
45487 			if (noab > 0) {
45488 			   xyzp->iconn[(nstor+j)*(MXCON+1)+kcon+1] = noab - 1;
45489 			} else {
45490 			   xyzp->iconn[(nstor+j)*(MXCON+1)+kcon+1] = noab + 1;
45491 			}
45492 			kcon++;
45493 		   } else if (ab != i+1) {
45494 			xyzp->iconn[(nstor+j)*(MXCON+1)+kcon+1] = noab;
45495 			kcon++;
45496 		   }
45497 		}
45498 		xyzp->iconn[(nstor+j)*(MXCON+1)] = kcon;
45499 	    }
45500 	  } else {
45501 	    i++;
45502 	  }
45503 	}
45504 	nold = nstor;
45505 	nstor = *xyzp->mxnat - cell->natc;
45506 	for (j=cell->natc - 1; j >= 0; j--) {
45507 	   xyzp->iatclr[nstor+j] = xyzp->iatclr[nold+j];
45508 	   xyzp->ianz[nstor+j] = xyzp->ianz[nold+j];
45509 	   xyzp->ipdbt[nstor+j] = xyzp->ipdbt[nold+j];
45510 	   xyzp->ityp[nstor+j] = xyzp->ityp[nold+j];
45511  	   for (k=0; k < 3; k++)
45512 		xyzp->coo[(nstor+j)*3+k] = xyzp->coo[(nold+j)*3+k];
45513 	   for (k=0; k < xyzp->iconn[(nold+j)*(MXCON+1)]+1; k++)
45514 		xyzp->iconn[(nstor+j)*(MXCON+1)+k] = xyzp->iconn[(nold+j)*(MXCON+1)+k];
45515 	}
45516 	update_sel = 1;
45517 }
45518 
MoveCellAtoms(CellTrans)45519 void MoveCellAtoms(CellTrans)
45520 double *CellTrans;
45521 {
45522 int i,k,nstor;
45523 
45524 	i = 0;
45525 	nstor = *xyzp->mxnat - cell->natc;
45526 
45527 	for (i=0; i < cell->natc; i++) {
45528 	    if (xyzp->iaton[i] == 2) {
45529 		for (k=0; k < 3; k++)
45530 		   xyzp->coo[(nstor+i)*3+k] =
45531 			xyzp->coo[(nstor+i)*3+k] + CellTrans[k];
45532 	    }
45533 	}
45534 }
45535 
InitCellDelTrans(dtopt)45536 void InitCellDelTrans(dtopt)
45537 int dtopt;
45538 {
45539   int i,CTdelbck;
45540 
45541   CTdelbck = CTdel;
45542   CTdel = dtopt;
45543 
45544   if (CTup) {
45545 	if (dtopt != CTdelbck) RedrawCT();
45546 	return;
45547   }
45548 
45549   CTup = 1;
45550 
45551   CTwin = CreateWindow("Translate / Delete Cell Atoms","-80-80",
45552 			 CTBOXWIDE,CTBOXHIGH,infobg,infofg,(Window)0);
45553   XSelectInput(display, CTwin, EnterWindowMask |
45554 	ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask);
45555 
45556   XMapWindow(display,CTwin);
45557 
45558   WinObj[15].win = &CTwin;
45559   WinObj[15].subwin = NULL;
45560   WinObj[15].butarr = ctbut;
45561   WinObj[15].numbut = NBUTCT;
45562   WinObj[15].winup = &CTup;
45563   WinObj[15].redraw = RedrawCT;
45564 
45565   DefBut(&ctbut[0], CTwin, 70, 5+3*(BUTTN+5), 50, 23,
45566 	"Apply", infobg, -15);
45567 
45568   DefBut(&ctbut[1], CTwin, 70+60, 5+3*(BUTTN+5), 50, 23,
45569 	"Close", infobg, -15);
45570 
45571   DefBut(&ctbut[2], CTwin, 70, 5+2*(BUTTN+5), 50, 23,
45572 	"Select", infobg, -15);
45573 
45574   DefBut(&ctbut[3], CTwin, 70+60, 5+2*(BUTTN+5), 70, 23,
45575 	"DeSelect", infobg, -15);
45576 
45577   for (i=0; i<3; i++) {
45578 	qboxstr(&qboxes[QCTA+i],&CTwin,0,0,190,CTBOXOFFX+i*80,CTBOXOFFY,
45579 		75,QBOXHIGH,2,cellvec[i],"0.0",9,QREAL,2000,-1,dummyproc);
45580 	qboxes[QCTA+i].dflt = &CellTran[i];
45581   }
45582 }
45583 
RedrawCT()45584 void RedrawCT()
45585 {
45586   int i;
45587 
45588   butje(CTwin,0,0,CTBOXWIDE,CTBOXHIGH,4,0,0,1,None,0,0,0);
45589   for (i=0; i<NBUTCT; i++) DrwBut(&ctbut[i]);
45590   if (!CTdel) for (i=0; i<3; i++) PromptBox(&qboxes[QCTA+i]);
45591 }
45592 
ButtonsCT(x,y)45593 int ButtonsCT(x,y)
45594 int x,y;
45595 {
45596  int i,j;
45597 
45598  i = Clickwin(ctbut,NBUTCT,x,y,1);
45599  if (i>=0) {
45600 	switch (i) {
45601 	case 0:
45602 	   if (CTdel) {
45603 		DelCellAtoms();
45604 	   } else {
45605 		for (j=0; j<3; j++)
45606 		   CellTran[j] = atof(qboxes[QCTA+j].str);
45607 		RedrawCT();
45608 		MoveCellAtoms(CellTran);
45609 	   }
45610 	   SelDel = 0;
45611 	   Selecting = 0;
45612 	   update_sel = 1;
45613 	   if (!CTdel && CTconn) return(2);
45614 	   else return(1);
45615 	   break;
45616 
45617 	case 1:
45618 	   for (i=0; i < *xyzp->iatoms; i++ )
45619 		if (xyzp->iaton[i] > 1) xyzp->iaton[i] = 1;
45620 	   SelDel = 0;
45621 	   XDestroyWindow(display,CTwin);
45622 	   CTup = 0;
45623 	   break;
45624 	case 2:
45625 	   if (!CTsdone) {
45626 		if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
45627 		   selstr,0)) {}
45628 		CTsdone = 1;
45629 	   }
45630 	   Selecting = 1; ZoomEnable = True;
45631 	   Select = True; SelDel = 1;
45632 	   break;
45633 	case 3:
45634 	   if (!CTdsdone) {
45635 		if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
45636 		   dselstr,0)) {}
45637 		CTdsdone = 1;
45638 	   }
45639 	   Selecting = 1; ZoomEnable = True;
45640 	   Select = False; SelDel = 1;
45641 	   update_sel = 1;
45642 	   break;
45643 	default: break;
45644 	}
45645  } else if (!CTdel) {
45646 	i = ClickBox(&qboxes[QCTA],3,x,y);
45647 	if (i>=0) {
45648 		for (j=0; j<3; j++) qboxes[QCTA+j].active = 0;
45649 		qboxes[QCTA+i].active = 1;
45650 		RedrawCT();
45651 	}
45652 
45653  }
45654 
45655  update_sel = 1;
45656  return(0);
45657 
45658 }
45659 
InitMovie(x,y)45660 void InitMovie(x,y)
45661 int x,y;
45662 {
45663   int i;
45664   char wgeom[64];
45665 
45666 
45667   sprintf(wgeom,"+%d+%d",x-20,y);
45668 
45669   if (Movup) {
45670 	RedrawMOV();
45671 	return;
45672   }
45673 
45674   Movup = 1;
45675 
45676   MOVwin = CreateWindow("Create Movie Window",wgeom,
45677 			 MOVWINW,MOVWINH,infobg,infofg,(Window)0);
45678   XSelectInput(display, MOVwin,
45679 		SubstructureNotifyMask | ExposureMask | KeyPressMask |
45680 		ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
45681 		LeaveWindowMask | PointerMotionMask | EnterWindowMask);
45682   subMOV = CreateWindow("Subwindow","",10,10,
45683                             colors[0],colors[15],MOVwin);
45684 
45685   XMapWindow(display,MOVwin);
45686 
45687   WinObj[37].win = &MOVwin;
45688   WinObj[37].subwin = &subMOV;
45689   WinObj[37].butarr = movbut;
45690   WinObj[37].numbut = 5;
45691   WinObj[37].winup = &Movup;
45692   WinObj[37].redraw = RedrawMOV;
45693 
45694   DefBut(&movbut[0], MOVwin, 20, 5+2*(BUTTN+5), 15, 15,
45695 	" ", infobg, -15);
45696   movbut[0].explstr = "Clean up bmp snapshots after \nmovie creation.";
45697 
45698   DefBut(&movbut[3], MOVwin, 20, 3*(BUTTN+5), 60, 23,
45699 	"Current ", infobg, -15);
45700   movbut[3].explstr = "Screen resolution for movie.";
45701 
45702   DefBut(&movbut[1], MOVwin, 20, 4*(BUTTN+5), 50, 23,
45703 	"Record", infobg, -15);
45704   movbut[1].explstr = "Begin recording of the movie.";
45705 
45706   DefBut(&movbut[2], MOVwin, 20+60, 4*(BUTTN+5), 150, 23,
45707 	"Stop & Create Movie", infobg, -15);
45708   movbut[2].explstr = "Stop recording and write the movie.";
45709 
45710   DefBut(&movbut[4], MOVwin, 160, 5+3*(BUTTN+5), 15, 15,
45711 	" ", infobg, -15);
45712   movbut[4].explstr = "Approximate movie play time by \nsimulation time.";
45713 
45714   rmsnap = 1;
45715   TogDown(&movbut[0]);
45716 
45717   timsnap = 0;
45718   TogUp(&movbut[4]);
45719 
45720   qboxstr(&qboxes[QMOV],&MOVwin,0,0,190,CTBOXOFFX,CTBOXOFFY,
45721 		200,QBOXHIGH,2,"Movie filename:","molden.avi",
45722 		SUBLEN1,QSTRING,2000,0,dummyproc);
45723 
45724   qboxes[QMOV].active = 1;
45725 }
45726 
RedrawMOV()45727 void RedrawMOV()
45728 {
45729   int i;
45730 
45731   butje(MOVwin,0,0,MOVWINW,MOVWINH,4,0,0,1,None,0,0,0);
45732   for (i=0; i<5; i++) DrwBut(&movbut[i]);
45733   LineString(MOVwin, "Clean up snap shots when done", 50, 18+2*(BUTTN+5));
45734   LineString(MOVwin, "Resolution", 90, 18+3*(BUTTN+5));
45735   LineString(MOVwin, "Real Time", 180, 18+3*(BUTTN+5));
45736   PromptBox(&qboxes[QMOV]);
45737 }
45738 
ButtonsMOV(i)45739 int ButtonsMOV(i)
45740 int i;
45741 {
45742    struct timeval tv;
45743    int fps;
45744 
45745 	switch (i) {
45746 	case 0:
45747 	   if (rmsnap) {
45748 		rmsnap = 0;
45749 	   	TogUp(&movbut[0]);
45750 	   } else {
45751 		rmsnap = 1;
45752 	   	TogDown(&movbut[0]);
45753 	   }
45754 	   RedrawMOV();
45755 	   break;
45756 
45757 	case 1:
45758 	   if (record) {
45759 		record = 0;
45760 	   	TogUp(&movbut[1]);
45761 	   } else {
45762 		record = 1;
45763 	   	TogDown(&movbut[1]);
45764                 setgif(1);
45765 		tmpfmt = *igffrm;
45766 		tmpmxg = *picmax;
45767 		*picmax = 1000;
45768 		*igffrm = 3;
45769 		gettimeofday(&tv,NULL);
45770 		Tbeg = tv.tv_sec;
45771 	   }
45772 	   RedrawMOV();
45773 	   break;
45774 
45775 	case 2:
45776 
45777 	   *igffrm = tmpfmt;
45778 	   *picmax = tmpmxg;
45779 	   TogUp(&movbut[1]);
45780            setgif(1);
45781 
45782 	   if ( (access(qboxes[QMOV].str,F_OK) == 0 &&
45783 		!isdir(qboxes[QMOV].str)) ) {
45784 		if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
45785 		"File already exists.\nPlease choose other file name.",1)) {
45786 		   i = -1;
45787 		}
45788 	   } else {
45789 		record = 0;
45790 		if (timsnap) {
45791 		   gettimeofday(&tv,NULL);
45792 		   Tend = tv.tv_sec;
45793 		   fps = picnum/(Tend-Tbeg);
45794 		} else {
45795 		    fps = 10;
45796 		}
45797 	   	sprintf(stemp,
45798 		   "avconv -r %d -i %s%%03d.bmp -target pal-dvd -s %dx%d %s",
45799 		   fps,GifFile,width,height,qboxes[QMOV].str);
45800 		system(stemp);
45801 		if (rmsnap) system("rm mol*.bmp");
45802 		XDestroyWindow(display,MOVwin);
45803 		Movup = 0;
45804 	   }
45805 	   break;
45806 
45807 	case 3:
45808 	   {
45809 	   int restyp;
45810 	   LSSTRU List;
45811 
45812 	   List.list = rsopt; List.nents = 2;
45813 	   if (DoPopUp(MOVwin,movbut[3].x+1,movbut[3].y+BUTTH,
45814 			    &List,&restyp,0) == -1)  break;
45815 	   switch (restyp) {
45816 		case 0:
45817               		XResizeWindow(display, win, 640, 480);
45818 	      		width = 640; height = 480;
45819 			break;
45820 		case 1:
45821               		XResizeWindow(display, win, 1280, 720);
45822 	      		width = 1280; height = 720;
45823 			break;
45824 		default:
45825 			break;
45826 	   }
45827 	   movbut[3].str = rsopt[restyp];
45828 	   RedrawMOV();
45829 #ifdef DOGL
45830 	   if (has_opengl && (*fancy || *fullgl)) {
45831 		Reshape(1);
45832 		Aspect = (float) width / (float) height;
45833 	   }
45834 #endif
45835 	   }
45836 	   break;
45837 
45838 	case 4:
45839 	   if (timsnap) {
45840 		timsnap = 0;
45841 	   	TogUp(&movbut[4]);
45842 	   } else {
45843 		timsnap = 1;
45844 	   	TogDown(&movbut[4]);
45845 	   }
45846 	   RedrawMOV();
45847 	   break;
45848 
45849 	default: break;
45850 	}
45851 
45852 
45853 }
45854 
make_aa()45855 void make_aa()
45856 {
45857    int i,nz,sidechainstart,iamino,ichi;
45858 
45859    for (i=0; i < calfptr->ncalf; i++) {
45860 	aaptr[i].iamino = &(calfptr->iamino[i]);
45861 	iamino = *aaptr[i].iamino;
45862         if (iamino < 1 || iamino > 23) continue;
45863 	nz = calfptr->icalf[i][0] - 1;
45864 	aaptr[i].phi = nz+1;
45865 	aaptr[i].psi = nz+2;
45866 	aaptr[i].omega = nz;
45867 
45868 	aaptr[i].chi1 = -1;
45869 	aaptr[i].chi2 = -1;
45870 	aaptr[i].chi3 = -1;
45871 	aaptr[i].chi4 = -1;
45872 
45873 	sidechainstart = nz+5;
45874 
45875 	if (iamino == 15) {
45876 	   sidechainstart = nz+4;
45877 	   if (zmptrp->ianz[nz+2] == 8) {
45878 		sidechainstart--;
45879 	   }
45880 	} else {
45881 /* if start residue there might be an N missing at nz+2 */
45882 
45883 	   if (zmptrp->ianz[nz+4] != 1 && zmptrp->ianz[nz+3] == 1)
45884 		sidechainstart--;
45885 	}
45886 
45887 	ichi = aminozmt[iamino-1].chis[0];
45888 	if (ichi != -1)
45889 	   aaptr[i].chi1 = sidechainstart-1+ichi;
45890 	ichi = aminozmt[iamino-1].chis[1];
45891 	if (ichi != -1) {
45892 	   int hsi = 0;
45893 	   int ispec = 0;
45894 
45895 	   if (zmptrp->ianz[sidechainstart-1+ichi] == 1) hsi = 1;
45896 	   if (iamino == 4 || iamino == 3) ispec = 1;
45897 
45898 	   if (!ispec || (ispec && hsi) ) {
45899 		 aaptr[i].chi2 = sidechainstart-1+ichi;
45900 	   }
45901 	}
45902 	ichi = aminozmt[iamino-1].chis[2];
45903 	if (ichi != -1)
45904 	   aaptr[i].chi3 = sidechainstart-1+ichi;
45905 	ichi = aminozmt[iamino-1].chis[3];
45906 	if (ichi != -1)
45907 	   aaptr[i].chi4 = sidechainstart-1+ichi;
45908 
45909 /*
45910         fprintf(stderr,"%d \n",*aaptr[i].iamino - 1);
45911         fprintf(stderr,"aa %d %s %f %f %f\n",i,AminoAcids[*aaptr[i].iamino - 1],
45912 		zmptrp->bet[aaptr[i].phi],zmptrp->bet[aaptr[i].psi],
45913 		zmptrp->bet[aaptr[i].omega]);
45914 */
45915    }
45916 
45917    if (calfptr->ncalf > 0) {
45918 	ZMEAA = 1;
45919    } else {
45920 	ZMEAA = 0;
45921    }
45922 }
45923 
aaexp(aastr,sl)45924 void aaexp(aastr,sl)
45925 char* aastr;
45926 int sl;
45927 {
45928    int i,j,k,istrt,nque,olfnd,exfnd,que[MXEXP];
45929 
45930    nque = -1;
45931    if (sl > MXEXP) sl = MXEXP;
45932 
45933    for (i=0; i < sl; i++) {
45934       for (j=0; j < 20; j++) {
45935 	if (strncasecmp(&aastr[i],AAlet[j],1) == 0) {
45936 	   nque++;
45937 	   que[nque] = j + 1;
45938 	}
45939       }
45940    }
45941    nque++;
45942    if (nque != sl) {
45943 	strcpy(ZMEerr,"Unrecognized one letter");
45944 	RedrawStatus();
45945 	return;
45946    }
45947 
45948    istrt = 0;
45949    olfnd = 0;
45950    if (oqlen == nque) {
45951       olfnd = 1;
45952       for (j=0; j < nque; j++) if (que[j] != oque[j]) olfnd = 0;
45953       if (olfnd) istrt = oqpos + 1;
45954    }
45955 
45956 
45957    for (i=istrt; i < calfptr->ncalf; i++) {
45958       exfnd = 1;
45959       for (j=0; j < nque; j++) {
45960 	if (calfptr->iamino[i+j] != que[j]) exfnd = 0;
45961       }
45962       if (exfnd) {
45963 	ZME_window_pos = i;
45964 	UpdateZME();
45965 	RedrawScroll(&zscroll);
45966 	for (k=0; k < nque; k++) oque[k] = que[k];
45967 	oqlen = nque;
45968 	oqpos = i;
45969         strcpy(ZMEerr,"Match!");
45970         RedrawStatus();
45971         return;
45972       }
45973    }
45974 
45975    if (olfnd) {
45976       oqpos = 0;
45977       strcpy(ZMEerr,"End of sequence!");
45978    } else {
45979       strcpy(ZMEerr,"NO match!");
45980    }
45981    RedrawStatus();
45982 }
45983 
FreeAllFirst()45984 void FreeAllFirst()
45985 {
45986 	int j;
45987 
45988 	if (xyz.mxorg) {
45989 	   free(xyz.coo);
45990 	   free(xyz.rzp);
45991 	   free(xyz.qat);
45992 	   free(xyz.isurf);
45993 	   free(xyz.lwrit);
45994 	   free(xyz.lring);
45995 	   free(xyz.ianz);
45996 	   free(xyz.iaton);
45997 	   free(xyz.iatclr);
45998 	   free(xyz.iresid);
45999 	   free(xyz.ixp);
46000 	   free(xyz.iyp);
46001 	   free(xyz.iconn);
46002 	   free(xyz.inat);
46003 	   free(xyz.ityp);
46004 	   free(xyz.ipdbt);
46005 	}
46006 
46007 	if (dorb.mxorg) {
46008 	   free(dorb.focc);
46009 	   free(dorb.focb);
46010 	   free(dorb.vectrs);
46011 	   free(dorb.vectrb);
46012 	   free(dorb.p);
46013 	   free(dorb.paa);
46014 	   free(dorb.phi);
46015 	   free(dorb.dxpsi);
46016 	   free(dorb.dypsi);
46017 	   free(dorb.dzpsi);
46018 	   free(dorb.averag);
46019 	   free(dorb.dphi);
46020 	   free(dorb.eiga);
46021 	   free(dorb.eigb);
46022 	   free(dorb.stoalfa);
46023 	   free(dorb.stobnorm);
46024 	   free(dorb.istos);
46025 	   free(orb.qd);
46026 	   free(orb.pd);
46027 	   free(orb.gd);
46028 	   free(orb.hd);
46029 	}
46030 
46031 	if (sgrd.mxorg) {
46032 	   free(sgrd.denn);
46033 	   free(sgrd.pmnn);
46034 	   free(sgrd.dens);
46035 	   free(sgrd.denst);
46036 	   free(sgrd.edx);
46037 	   free(sgrd.edy);
46038 	   free(sgrd.rz);
46039 	   free(sgrd.bucket);
46040 	   free(sgrd.iedlog);
46041 	   free(sgrd.ix);
46042 	   free(sgrd.iy);
46043 	}
46044 	if (geopntr.mxorg) {
46045 	   free(geopntr.formax);
46046 	   free(geopntr.forrms);
46047 	   free(geopntr.dismax);
46048 	   free(geopntr.disrms);
46049 	   free(geopntr.epoints);
46050 	   free(geopntr.isav);
46051 	}
46052 	if (zmptr.mxzorg) {
46053 	   free(zmptr.bl);
46054 	   free(zmptr.ibl);
46055 	   free(zmptr.alph);
46056 	   free(zmptr.ialph);
46057 	   free(zmptr.bet);
46058 	   free(zmptr.ibet);
46059 	   free(zmptr.imap);
46060 	   free(zmptr.ianz);
46061 	   free(zmptr.iz);
46062 	   free(stoc.cstoc);
46063 	   free(stoc.czstoc);
46064 	   free(stoc.astoc);
46065 	   free(stoc.bstoc);
46066 	   free(stoc.ianstc);
46067 	   free(IANZbox);
46068 	   free(BLbox);
46069 	   free(ALPHbox);
46070 	   free(BETbox);
46071 	   free(IZbox);
46072  	}
46073 	for (j=0; j<hetptr.NHetAtm; j++) {
46074 	   if (hetptr.Allocated[j]) free(hetptr.HetAtm[j]);
46075 	}
46076 }
46077 
FreePixmaps()46078 void FreePixmaps()
46079 {
46080    XFreePixmap(display,stipple);
46081    XFreePixmap(display,qwgrey);
46082    XFreePixmap(display,tqwgrey);
46083    XFreePixmap(display,molPix);
46084    XFreePixmap(display,upPix);
46085    XFreePixmap(display,downPix);
46086    XFreePixmap(display,lPix);
46087    XFreePixmap(display,rPix);
46088    XFreePixmap(display,ballPix);
46089    XFreePixmap(display,HourPix);
46090    XFreePixmap(display,gPix);
46091    XFreePixmap(display,SkullPix);
46092    XFreePixmap(display,FFPix);
46093    XFreePixmap(display,MLFPix);
46094    XFreePixmap(display,HPix);
46095    XFreePixmap(display,VRMLPix);
46096    XFreePixmap(display,AlignPix);
46097    XFreePixmap(display,OrigPix);
46098    XFreePixmap(display,CellPix);
46099    XFreePixmap(display,SurfPix);
46100    XFreePixmap(display,FotoPix);
46101    XFreePixmap(display,ColPix);
46102    XFreePixmap(display,slowPix);
46103    XFreePixmap(display,fastPix);
46104    XFreePixmap(display,blastPix);
46105    XFreePixmap(display,BigPix);
46106    XFreePixmap(display,OGLPix);
46107    XFreePixmap(display,icon_pixmap);
46108 #ifdef DOGL
46109    glXDestroyContext(display,cx);
46110 #endif
46111 }
46112 
FreeOne(sel)46113 void FreeOne(sel)
46114 int sel;
46115 {
46116 	int j;
46117 
46118 	xyzp   = &COO[sel]->coo;
46119 	geop   = &COO[sel]->geop;
46120 	zmptrp = &COO[sel]->zmt;
46121 	stocp  = &COO[sel]->stoc;
46122 	dorbp  = &COO[sel]->dorb;
46123 	orbp   = &COO[sel]->orb;
46124 
46125 	if (xyzp->mxorg) FreeCoo(*xyzp);
46126 
46127 	if (dorbp->mxorg) {
46128 	   free(dorbp->focc);
46129 	   free(dorbp->focb);
46130 	   free(dorbp->vectrs);
46131 	   free(dorbp->vectrb);
46132 	   free(dorbp->p);
46133 	   free(dorbp->paa);
46134 	   free(dorbp->phi);
46135 	   free(dorbp->dxpsi);
46136 	   free(dorbp->dypsi);
46137 	   free(dorbp->dzpsi);
46138 	   free(dorbp->averag);
46139 	   free(dorbp->dphi);
46140 	   free(dorbp->eiga);
46141 	   free(dorbp->eigb);
46142 	   free(dorbp->stoalfa);
46143 	   free(dorbp->stobnorm);
46144 	   free(dorbp->istos);
46145 	   free(orbp->qd);
46146 	   free(orbp->pd);
46147 	   free(orbp->gd);
46148 	   free(orbp->hd);
46149 	}
46150 
46151 	if (geop->mxorg) {
46152 	   free(geop->formax);
46153 	   free(geop->forrms);
46154 	   free(geop->dismax);
46155 	   free(geop->disrms);
46156 	   free(geop->epoints);
46157 	   free(geop->isav);
46158 	}
46159 
46160 	if (zmptrp->mxzorg) {
46161 	   free(zmptrp->bl);
46162 	   free(zmptrp->ibl);
46163 	   free(zmptrp->alph);
46164 	   free(zmptrp->ialph);
46165 	   free(zmptrp->bet);
46166 	   free(zmptrp->ibet);
46167 	   free(zmptrp->imap);
46168 	   free(zmptrp->ianz);
46169 	   free(zmptrp->iz);
46170 	   free(stocp->cstoc);
46171 	   free(stocp->czstoc);
46172 	   free(stocp->astoc);
46173 	   free(stocp->bstoc);
46174 	   free(stocp->ianstc);
46175 	   free(COO[sel]->fname);
46176 	   free(COO[sel]->IANZbox);
46177 	   free(COO[sel]->BLbox);
46178 	   free(COO[sel]->ALPHbox);
46179 	   free(COO[sel]->BETbox);
46180 	   free(COO[sel]->IZbox);
46181 	}
46182 	if (COO[sel]->pdbcode != NULL) free(COO[sel]->pdbcode);
46183 	if (COO[sel]->memfil.str != NULL) {
46184 	   free(COO[sel]->memfil.line_index);
46185 	   free(COO[sel]->memfil.str);
46186 	   COO[sel]->memfil.str = NULL;
46187 	}
46188 	if (COO[sel]->hetatm.NHetAtm > 0) {
46189 	      for (j=0; j<COO[sel]->hetatm.NHetAtm; j++) {
46190 		if (COO[sel]->hetatm.Allocated[j]) free(COO[sel]->hetatm.HetAtm[j]);
46191 	      }
46192 	}
46193 	if (COO[sel]->mfdata.mollin != NULL) free(COO[sel]->mfdata.mollin);
46194 	if (COO[sel]->mlftit != NULL) free(COO[sel]->mlftit);
46195 
46196 	free(COO[sel]);
46197 
46198 	if (watres[sel] != NULL) free(watres[sel]);
46199 	if (watanz[sel] != NULL) free(watanz[sel]);
46200 	if (watcoo[sel] != NULL) free(watcoo[sel]);
46201 	if (watcon[sel] != NULL) free(watcon[sel]);
46202 	if (watmap[sel] != NULL) free(watmap[sel]);
46203 	if (watqat[sel] != NULL) free(watqat[sel]);
46204 	if (wattyp[sel] != NULL) free(wattyp[sel]);
46205 
46206 	empty_model(sel,0);
46207 
46208 }
46209 
FreeAll(delpix)46210 void FreeAll(delpix)
46211 int delpix;
46212 {
46213    int i,mul;
46214    int n;
46215    char cmdfil[MAXSTRLEN];
46216 
46217    mul = 0;
46218    if (multstruct==NULL) {
46219 	mul = 0;
46220    } else {
46221       if (*multstruct) mul = 1;
46222    }
46223 
46224    if (!mul) {
46225 	FreeAllFirst();
46226    } else {
46227 
46228       for (i=0; i<nstruct; i++) {
46229 	if (bcksvg.UpSVG && bcksvg.istruct == i) {
46230 	   if (strstr(COO[istruct]->fname,".sdf")) {
46231 		killob();
46232 		wrsvgs();
46233 		bcksvg.UpSVG = 0;
46234 	   }
46235 	}
46236 	FreeOne(i);
46237       }
46238    }
46239    if (delpix) FreePixmaps();
46240 
46241    if (pdbcode != NULL) {
46242 	if (pdbcode == pdbcbck) {
46243 	   free(pdbcode);
46244 	}
46245    }
46246 }
46247 
DeleteOne()46248 void DeleteOne()
46249 {
46250    int i,j;
46251 
46252    update_model = 0;
46253    if (nstruct == 1) {
46254 	DeleteAll();
46255    } else {
46256 	FreeOne(istruct);
46257 	free(strfiles[istruct]);
46258 	for (i=0; i<nstruct-1; i++)
46259 	    if (i >= istruct) {
46260 		COO[i]       = COO[i+1];
46261 		strfiles[i]  = strfiles[i+1];
46262 		scl[i]       = scl[i+1];
46263 #ifdef DOGL
46264 		MoveOne(i);
46265 #endif
46266 	    }
46267 #ifdef DOGL
46268 	initOne(nstruct-1);
46269 #endif
46270 	strfiles[nstruct-1] = NULL;
46271 	COO[nstruct-1] = NULL;
46272 	nstruct--;
46273 	if (istruct > nstruct - 1) istruct = nstruct - 1;
46274 	if (istruct < 0) istruct = 0;
46275 	strlist.select = istruct;
46276 	RedrawSTR();
46277 
46278 	NewActiveStruct();
46279 
46280 	doclr();
46281 	if (NMols[istruct] == -1) update_model = 1;
46282 	update_struct();
46283    }
46284 }
46285 
DeleteAll()46286 void DeleteAll()
46287 {
46288    int i;
46289 
46290    FreeAll(0);
46291    for (i=0; i<nstruct; i++) {
46292 	free(strfiles[i]);
46293 	strfiles[i] = NULL;
46294 	COO[i] = NULL;
46295    }
46296 
46297    istruct = nstruct = 0;
46298    nfilesstart = 0;
46299    NSurf[0] = 0;
46300 
46301    xyzp   = &xyz;
46302    geop   = &geopntr;
46303    zmptrp = &zmptr;
46304    stocp  = &stoc;
46305    dorbp  = &dorb;
46306    orbp   = &orb;
46307 
46308    IANZbox = IANZboxes;
46309    BLbox = BLboxes;
46310    ALPHbox = ALPHboxes;
46311    BETbox = BETboxes;
46312    IZbox = (QBOXSTRU *) IZboxes;
46313 
46314    *backb = 0;
46315    *xyz.iatoms = 0;
46316    *zmptr.nz = 0;
46317    *zmptr.ihaszm = 0;
46318    calfptr->ncalf = 0;
46319    zmptr.mxzorg = 0;
46320    geo1ptr->gcvav = 0;
46321    cnvptr->icvav1 = 0;
46322    cnvptr->icvav2 = 0;
46323    out_spec = NULL;
46324    FRQ->nfreq = 0;
46325 
46326    XDestroyWindow(display,STRwin);STRup = 0;
46327 
46328    doclr();
46329    update_model = 1;
46330    update_struct();
46331 }
46332 
AllocZMat(ZSize,first)46333 int AllocZMat(ZSize,first)
46334 int ZSize;
46335 int first;
46336 {
46337    int memstat,i,j;
46338    double f;
46339    int ii;
46340    QBOXSTRU *TMPIANZbox;
46341    QBOXSTRU *TMPBLbox;
46342    QBOXSTRU *TMPALPHbox;
46343    QBOXSTRU *TMPBETbox;
46344    QBOXSTRU *TMPIZbox;
46345 
46346    memstat = 1;
46347 
46348    if (first) {
46349 	ZSize = MAXAT;
46350    } else {
46351 	TMPzmptr = *zmptrp;
46352 	TMPstoc = *stocp;
46353 	TMPIANZbox = IANZbox;
46354 	TMPBLbox = BLbox;
46355 	TMPALPHbox = ALPHbox;
46356 	TMPBETbox = BETbox;
46357 	TMPIZbox = IZbox;
46358    }
46359 
46360    if ((zmptrp->bl = (double *) malloc((sizeof f)*ZSize)) == NULL) {
46361 	memstat = 0;
46362    }
46363 
46364    if ((zmptrp->ibl = (int *) malloc((sizeof ii)*ZSize)) == NULL) {
46365 	memstat = 0;
46366    }
46367 
46368    if ((zmptrp->alph = (double *) malloc((sizeof f)*ZSize)) == NULL) {
46369 	memstat = 0;
46370    }
46371 
46372    if ((zmptrp->ialph = (int *) malloc((sizeof ii)*ZSize)) == NULL) {
46373 	memstat = 0;
46374    }
46375 
46376    if ((zmptrp->bet = (double *) malloc((sizeof f)*ZSize)) == NULL) {
46377 	memstat = 0;
46378    }
46379 
46380    if ((zmptrp->ibet = (int *) malloc((sizeof ii)*ZSize)) == NULL) {
46381 	memstat = 0;
46382    }
46383 
46384    if ((zmptrp->imap = (int *) malloc((sizeof ii)*ZSize)) == NULL) {
46385 	memstat = 0;
46386    }
46387 
46388    if ((zmptrp->ianz = (int *) malloc((sizeof ii)*ZSize)) == NULL) {
46389 	memstat = 0;
46390    }
46391 
46392    if ((zmptrp->iz = (int *) malloc((sizeof ii)*ZSize*4)) == NULL) {
46393 	memstat = 0;
46394    }
46395 
46396    if ((stocp->cstoc = (double *) malloc((sizeof f)*ZSize*3)) == NULL) {
46397 	memstat = 0;
46398    }
46399 
46400    if ((stocp->czstoc = (double *) malloc((sizeof f)*ZSize*3)) == NULL) {
46401 	memstat = 0;
46402    }
46403 
46404    if ((stocp->astoc = (double *) malloc((sizeof f)*ZSize)) == NULL) {
46405 	memstat = 0;
46406    }
46407 
46408    if ((stocp->bstoc = (double *) malloc((sizeof f)*ZSize)) == NULL) {
46409 	memstat = 0;
46410    }
46411 
46412    if ((stocp->ianstc = (int *) malloc((sizeof ii)*ZSize)) == NULL) {
46413 	memstat = 0;
46414    }
46415 
46416    if ((IANZbox = (QBOXSTRU *) malloc((sizeof TMPbox)*ZSize)) == NULL) {
46417 	memstat = 0;
46418    }
46419 
46420    if ((BLbox = (QBOXSTRU *) malloc((sizeof TMPbox)*ZSize)) == NULL) {
46421 	memstat = 0;
46422    }
46423 
46424    if ((ALPHbox = (QBOXSTRU *) malloc((sizeof TMPbox)*ZSize)) == NULL) {
46425 	memstat = 0;
46426    }
46427 
46428    if ((BETbox = (QBOXSTRU *) malloc((sizeof TMPbox)*ZSize)) == NULL) {
46429 	memstat = 0;
46430    }
46431 
46432    if ((IZbox = (QBOXSTRU *) malloc((sizeof TMPbox)*ZSize*4)) == NULL) {
46433 	memstat = 0;
46434    }
46435 
46436    if (!memstat) {
46437 	fprintf(stderr,"Out of memory\n");
46438 	if (!first) {
46439 	   *zmptrp = TMPzmptr;
46440 	   *stocp = TMPstoc;
46441 	}
46442 	return(0);
46443    } else {
46444 	if (first) {
46445 
46446 	   zmptrp->ibl[0] = 0;
46447 	   zmptrp->ialph[0] = zmptrp->ialph[1] = 0;
46448 	   zmptrp->ibet[0] = zmptrp->ibet[1] = zmptrp->ibet[2] = 0;
46449 	   zmptrp->bl[0] = 0.0;
46450 	   zmptrp->alph[0] = zmptrp->alph[1] = 0.0;
46451 	   zmptrp->bet[0] = zmptrp->bet[1] = zmptrp->bet[2] = 0.0;
46452 	   for (i=0; i<ZSize*4; i++) zmptrp->iz[i] = 0;
46453 
46454 	   zmptrp->nz = zmptr.nz;
46455 	   zmptrp->ihaszm = zmptr.ihaszm;
46456 	   zmptrp->mxzat = zmptr.mxzat;
46457 
46458 	} else {
46459 
46460 	   for (i=0; i < *zmptrp->mxzat; i++) {
46461 		zmptrp->bl[i] = TMPzmptr.bl[i];
46462 		zmptrp->ibl[i] = TMPzmptr.ibl[i];
46463 		zmptrp->alph[i] = TMPzmptr.alph[i];
46464 		zmptrp->ialph[i] = TMPzmptr.ialph[i];
46465 		zmptrp->bet[i] = TMPzmptr.bet[i];
46466 		zmptrp->ibet[i] = TMPzmptr.ibet[i];
46467 		zmptrp->imap[i] = TMPzmptr.imap[i];
46468 		zmptrp->ianz[i] = TMPzmptr.ianz[i];
46469 		for (j=0; j<3; j++)
46470 		   zmptrp->iz[i*4+j] = TMPzmptr.iz[i*4+j];
46471 		IANZbox[i] = TMPIANZbox[i];
46472 		BLbox[i] = TMPBLbox[i];
46473 		ALPHbox[i] = TMPALPHbox[i];
46474 		BETbox[i] = TMPBETbox[i];
46475 		for (j=0; j<3; j++)
46476 		   IZbox[i*4+j] = TMPIZbox[i*4+j];
46477 
46478 	   }
46479 	   if (TMPzmptr.mxzorg) {
46480 		FreeZmt(TMPzmptr,TMPstoc,
46481 			TMPIANZbox,TMPBLbox,TMPALPHbox,TMPBETbox,TMPIZbox);
46482 	   }
46483 
46484 	}
46485 	if (COO[istruct] != NULL) {
46486 		COO[istruct]->IANZbox = IANZbox;
46487 		COO[istruct]->BLbox   = BLbox;
46488 		COO[istruct]->ALPHbox = ALPHbox;
46489 		COO[istruct]->BETbox  = BETbox;
46490 		COO[istruct]->IZbox   = IZbox;
46491 	}
46492 	zmptrp->mxzorg = 1;
46493 	*zmptrp->mxzat = ZSize;
46494 	return(ZSize);
46495    }
46496 }
46497 
46498 #if defined(VMS) || defined(UNDERSC)
allorb(ZSizep,first)46499 void allorb(ZSizep,first)
46500 #else
46501 #ifdef CRAY
46502 void ALLORB(ZSizep,first)
46503 #else
46504 void allorb_(ZSizep,first)
46505 #endif
46506 #endif
46507 int *ZSizep;
46508 int *first;
46509 {
46510    int memstat;
46511    double d;
46512    float f;
46513    int i;
46514    int ZSize;
46515 
46516    memstat = 1;
46517    if (*first) {
46518 	ZSize = MAXORB;
46519    } else {
46520 	ZSize = *ZSizep;
46521 	TMPdorb = *dorbp;
46522 	TMPorb = *orbp;
46523    }
46524 
46525 
46526    if ((dorbp->focc = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46527 	memstat = 0;
46528    }
46529 
46530    if ((dorbp->focb = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46531 	memstat = 0;
46532    }
46533 
46534    if ((dorbp->vectrs = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46535 	memstat = 0;
46536    }
46537 
46538    if ((dorbp->vectrb = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46539 	memstat = 0;
46540    }
46541 
46542    if ((dorbp->p = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46543 	memstat = 0;
46544    }
46545 
46546    if ((dorbp->paa = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46547 	memstat = 0;
46548    }
46549 
46550    if ((dorbp->phi = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46551 	memstat = 0;
46552    }
46553 
46554    if ((dorbp->dphi = (double *) malloc((sizeof d)*ZSize*3)) == NULL) {
46555 	memstat = 0;
46556    }
46557 
46558    if ((dorbp->dxpsi = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46559 	memstat = 0;
46560    }
46561 
46562    if ((dorbp->dypsi = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46563 	memstat = 0;
46564    }
46565 
46566    if ((dorbp->dzpsi = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46567 	memstat = 0;
46568    }
46569 
46570 
46571    if ((dorbp->averag = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46572 	memstat = 0;
46573    }
46574 
46575    if ((dorbp->eiga = (float *) malloc((sizeof f)*ZSize)) == NULL) {
46576 	memstat = 0;
46577    }
46578 
46579    if ((dorbp->eigb = (float *) malloc((sizeof f)*ZSize)) == NULL) {
46580 	memstat = 0;
46581    }
46582 
46583    if ((dorbp->stoalfa = (float *) malloc((sizeof f)*ZSize)) == NULL) {
46584 	memstat = 0;
46585    }
46586 
46587    if ((dorbp->stobnorm = (float *) malloc((sizeof f)*ZSize)) == NULL) {
46588 	memstat = 0;
46589    }
46590 
46591    if ((dorbp->istos = (int *) malloc((sizeof i)*ZSize*5)) == NULL) {
46592 	memstat = 0;
46593    }
46594 
46595    if ((orbp->qd = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46596 	memstat = 0;
46597    }
46598 
46599    if ((orbp->pd = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46600 	memstat = 0;
46601    }
46602 
46603    if ((orbp->gd = (double *) malloc((sizeof d)*ZSize*3)) == NULL) {
46604 	memstat = 0;
46605    }
46606 
46607    if ((orbp->hd = (double *) malloc((sizeof d)*ZSize*6)) == NULL) {
46608 	memstat = 0;
46609    }
46610 
46611    if (!memstat) {
46612 	fprintf(stderr,"Out of memory\n");
46613 	if (!*first) {
46614 	   *dorbp = TMPdorb;
46615 	   *orbp = TMPorb;
46616 	}
46617    } else {
46618 	if (*first) {
46619 	   dorbp->ncols  = dorb.ncols;
46620 	   dorbp->ncolb  = dorb.ncolb;
46621 	   dorbp->nocc   = dorb.nocc;
46622 	   dorbp->nocb   = dorb.nocb;
46623 	   dorbp->naorbs = dorb.naorbs;
46624 	   dorbp->mxorb  = dorb.mxorb;
46625  	} else {
46626 	   if (TMPdorb.mxorg) {
46627 		free(TMPdorb.focc);
46628 	   	free(TMPdorb.focb);
46629 		free(TMPdorb.vectrs);
46630 		free(TMPdorb.vectrb);
46631 		free(TMPdorb.p);
46632 		free(TMPdorb.paa);
46633 		free(TMPdorb.phi);
46634 		free(TMPdorb.dphi);
46635 		free(TMPdorb.dxpsi);
46636 		free(TMPdorb.dypsi);
46637 		free(TMPdorb.dzpsi);
46638 		free(TMPdorb.averag);
46639 		free(TMPdorb.eiga);
46640 		free(TMPdorb.eigb);
46641 		free(TMPdorb.stoalfa);
46642 		free(TMPdorb.stobnorm);
46643 		free(TMPdorb.istos);
46644 		free(TMPorb.qd);
46645 		free(TMPorb.pd);
46646 		free(TMPorb.gd);
46647 		free(TMPorb.hd);
46648 	   }
46649 	}
46650 	dorbp->mxorg  = 1;
46651 	*dorbp->mxorb = ZSize;
46652    }
46653 }
46654 
46655 #define LNBUCK 10
46656 
46657 #if defined(VMS) || defined(UNDERSC)
allgrd(ZSizep)46658 void allgrd(ZSizep)
46659 #else
46660 #ifdef CRAY
46661 void ALLGRD(ZSizep)
46662 #else
46663 void allgrd_(ZSizep)
46664 #endif
46665 #endif
46666 int *ZSizep;
46667 {
46668    int memstat;
46669    double d;
46670    int i;
46671    int ZSize;
46672 
46673    ZSize = *ZSizep;
46674    memstat = 1;
46675 
46676    TMPsgrd = sgrd;
46677 
46678    if ((sgrd.denn = (double *) malloc((sizeof d)*ZSize*ZSize*ZSize)) == NULL) {
46679 	memstat = 0;
46680    }
46681 
46682    if ((sgrd.pmnn = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46683 	memstat = 0;
46684    }
46685 
46686    if ((sgrd.dens = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46687 	memstat = 0;
46688    }
46689 
46690    if ((sgrd.denst = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46691 	memstat = 0;
46692    }
46693 
46694    if ((sgrd.edx = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46695 	memstat = 0;
46696    }
46697 
46698    if ((sgrd.edy = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46699 	memstat = 0;
46700    }
46701 
46702    if ((sgrd.rz = (double *) malloc((sizeof d)*ZSize*ZSize)) == NULL) {
46703 	memstat = 0;
46704    }
46705 
46706    if ((sgrd.bucket = (double *) malloc((sizeof d)*(ZSize + LNBUCK))) == NULL) {
46707 	memstat = 0;
46708    }
46709 
46710    if ((sgrd.iedlog = (int *) malloc((sizeof i)*ZSize*ZSize)) == NULL) {
46711 	memstat = 0;
46712    }
46713 
46714    if ((sgrd.ix = (int *) malloc((sizeof i)*ZSize*ZSize)) == NULL) {
46715 	memstat = 0;
46716    }
46717 
46718    if ((sgrd.iy = (int *) malloc((sizeof i)*ZSize*ZSize)) == NULL) {
46719 	memstat = 0;
46720    }
46721 
46722 
46723    if (!memstat) {
46724 	fprintf(stderr,"Out of memory\n");
46725 	sgrd = TMPsgrd;
46726    } else {
46727 	if (TMPsgrd.mxorg) {
46728 	   free(TMPsgrd.denn);
46729 	   free(TMPsgrd.pmnn);
46730 	   free(TMPsgrd.dens);
46731 	   free(TMPsgrd.denst);
46732 	   free(TMPsgrd.edx);
46733 	   free(TMPsgrd.edy);
46734 	   free(TMPsgrd.rz);
46735 	   free(TMPsgrd.bucket);
46736 	   free(TMPsgrd.iedlog);
46737 	   free(TMPsgrd.ix);
46738 	   free(TMPsgrd.iy);
46739 	}
46740 	sgrd.mxorg = 1;
46741 	*sgrd.mx3d = ZSize;
46742 	*sgrd.mx3d2 = ZSize*ZSize;
46743    }
46744 }
46745 
46746 #if defined(VMS) || defined(UNDERSC)
allgeo(ZSizep,first)46747 void allgeo(ZSizep,first)
46748 #else
46749 #ifdef CRAY
46750 void ALLGEO(ZSizep,first)
46751 #else
46752 void allgeo_(ZSizep,first)
46753 #endif
46754 #endif
46755 int *ZSizep;
46756 int *first;
46757 {
46758    int memstat;
46759    double d;
46760    int i, mxpnto,mxorgo;
46761    int ZSize;
46762 
46763    memstat = 1;
46764    if (*first) {
46765 	ZSize = MAXPNT;
46766    } else {
46767 	ZSize = *ZSizep;
46768 	TMPgeopntr = *geop;
46769    }
46770 
46771    if ((geop->formax = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46772 	memstat = 0;
46773    }
46774 
46775    if ((geop->forrms = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46776 	memstat = 0;
46777    }
46778 
46779    if ((geop->dismax = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46780 	memstat = 0;
46781    }
46782 
46783    if ((geop->disrms = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46784 	memstat = 0;
46785    }
46786 
46787    if ((geop->epoints = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46788 	memstat = 0;
46789    }
46790 
46791    if ((geop->isav = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46792 	memstat = 0;
46793    }
46794 
46795    if (!memstat) {
46796 	fprintf(stderr,"Out of memory\n");
46797 	if (!*first) *geop = TMPgeopntr;
46798    } else {
46799 	if (TMPgeopntr.mxorg) {
46800 		free(TMPgeopntr.formax);
46801 		free(TMPgeopntr.forrms);
46802 		free(TMPgeopntr.dismax);
46803 		free(TMPgeopntr.disrms);
46804 		free(TMPgeopntr.epoints);
46805 		free(TMPgeopntr.isav);
46806 	}
46807 	geop->mxorg = 1;
46808 	geo1ptr->mxpnt = ZSize;
46809    }
46810 }
46811 
46812 typedef struct {
46813   int ptr;
46814   float depth;
46815 } DepthIndex;
46816 
46817 DepthIndex dptdemo;
46818 DepthIndex dpt[NUMAT];
46819 DepthIndex *dptptr = dpt;
46820 static int dptsiz = NUMAT;
46821 
46822 typedef struct {
46823   int ptr;
46824   int depth;
46825 } IntIndex;
46826 
46827 IntIndex idpt[MXCON+1];
46828 IntIndex *intptr = idpt;
46829 
FreeCoo(txyz)46830 void FreeCoo(txyz)
46831 COOSTRU txyz;
46832 {
46833    free(txyz.coo);
46834    free(txyz.rzp);
46835    free(txyz.qat);
46836    free(txyz.isurf);
46837    free(txyz.icont);
46838    free(txyz.lwrit);
46839    free(txyz.lring);
46840    free(txyz.ianz);
46841    free(txyz.iaton);
46842    free(txyz.iatclr);
46843    free(txyz.iresid);
46844    free(txyz.ixp);
46845    free(txyz.iyp);
46846    free(txyz.iconn);
46847    free(txyz.inat);
46848    free(txyz.ityp);
46849    free(txyz.ipdbt);
46850 }
46851 
FreeZmt(tzmt,tstoc,tbox1,tbox2,tbox3,tbox4,tbox5)46852 void FreeZmt(tzmt,tstoc,tbox1,tbox2,tbox3,tbox4,tbox5)
46853 ZMSTRU tzmt;
46854 STOCSTRU tstoc;
46855 QBOXSTRU *tbox1,*tbox2,*tbox3,*tbox4,*tbox5;
46856 {
46857    free(tzmt.bl);
46858    free(tzmt.ibl);
46859    free(tzmt.alph);
46860    free(tzmt.ialph);
46861    free(tzmt.bet);
46862    free(tzmt.ibet);
46863    free(tzmt.imap);
46864    free(tzmt.ianz);
46865    free(tzmt.iz);
46866    free(tstoc.cstoc);
46867    free(tstoc.czstoc);
46868    free(tstoc.astoc);
46869    free(tstoc.bstoc);
46870    free(tstoc.ianstc);
46871    free(tbox1);
46872    free(tbox2);
46873    free(tbox3);
46874    free(tbox4);
46875    free(tbox5);
46876 }
46877 
46878 #if defined(VMS) || defined(UNDERSC)
allcoo(ZSizep,first)46879 void allcoo(ZSizep,first)
46880 #else
46881 #ifdef CRAY
46882 void ALLCOO(ZSizep,first)
46883 #else
46884 void allcoo_(ZSizep,first)
46885 #endif
46886 #endif
46887 int *ZSizep;
46888 int *first;
46889 {
46890    int memstat;
46891    double d;
46892    int i;
46893    short int j;
46894    int ZSize;
46895 
46896    memstat = 1;
46897    if (*first) {
46898         if (*first == 1) {
46899 	   ZSize = NUMAT;
46900 	} else {
46901 	   ZSize = *ZSizep;
46902 	}
46903    } else {
46904 	ZSize = *xyzp->mxnat + *ZSizep;
46905 	TMPxyz = *xyzp;
46906    }
46907 
46908    if ((xyzp->coo = (double *) malloc((sizeof d)*ZSize*3)) == NULL) {
46909 	memstat = 0;
46910    }
46911 
46912    if ((xyzp->rzp = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46913 	memstat = 0;
46914    }
46915 
46916    if ((xyzp->qat = (double *) malloc((sizeof d)*ZSize)) == NULL) {
46917 	memstat = 0;
46918    }
46919 
46920    if ((xyzp->isurf = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46921 	memstat = 0;
46922    }
46923 
46924    if ((xyzp->icont = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46925 	memstat = 0;
46926    }
46927 
46928    if ((xyzp->lwrit = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46929 	memstat = 0;
46930    }
46931 
46932    if ((xyzp->lring = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46933 	memstat = 0;
46934    }
46935 
46936    if ((xyzp->ianz = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46937 	memstat = 0;
46938    }
46939 
46940    if ((xyzp->iaton = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46941 	memstat = 0;
46942    }
46943 
46944    if ((xyzp->iatclr = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46945 	memstat = 0;
46946    }
46947 
46948    if ((xyzp->iresid = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46949 	memstat = 0;
46950    }
46951 
46952    if ((xyzp->ixp = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46953 	memstat = 0;
46954    }
46955 
46956    if ((xyzp->iyp = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46957 	memstat = 0;
46958    }
46959 
46960    if ((xyzp->iconn = (int *) malloc((sizeof i)*ZSize*(MXCON+1))) == NULL) {
46961 	memstat = 0;
46962    }
46963 
46964    if ((xyzp->inat = (int *) malloc((sizeof i)*ZSize)) == NULL) {
46965 	memstat = 0;
46966    }
46967 
46968    if ((xyzp->ityp = (short int *) malloc((sizeof j)*ZSize)) == NULL) {
46969 	memstat = 0;
46970    }
46971 
46972    if ((xyzp->ipdbt = (short int *) malloc((sizeof j)*ZSize)) == NULL) {
46973 	memstat = 0;
46974    }
46975 
46976    if (ZSize > dptsiz) {
46977 	if ((dptptr = (DepthIndex *) malloc((sizeof dptdemo)*ZSize)) == NULL) {
46978 	   memstat = 0;
46979 	} else {
46980 	   dptsiz = ZSize;
46981 	}
46982    }
46983 
46984    if (!memstat) {
46985 	fprintf(stderr,"Out of memory\n");
46986 	if (!*first) *xyzp = TMPxyz;
46987    } else {
46988 	if (*first) {
46989 	   xyzp->iatoms = xyz.iatoms;
46990 	   xyzp->ncont = xyz.ncont;
46991 	   xyzp->mxnat = xyz.mxnat;
46992 	   for (i=0; i < ZSize; i++) {
46993 		xyzp->qat[i] = 0.0;
46994 		xyzp->ianz[i] = 0;
46995 		xyzp->ityp[i] = 0;
46996 		xyzp->iaton[i] = 0;
46997 		xyzp->iatclr[i] = 1;
46998 		xyzp->iresid[i] = 0;
46999 		xyzp->ipdbt[i] = 0;
47000 		xyzp->lring[i] = 0;
47001 	   }
47002 	} else {
47003 	   for (i=0; i < *xyzp->iatoms; i++) {
47004 	   	for (j=0; j<3; j++) xyzp->coo[i*3+j] = TMPxyz.coo[i*3+j];
47005 		xyzp->qat[i] = TMPxyz.qat[i];
47006 		xyzp->ianz[i] = TMPxyz.ianz[i];
47007 		xyzp->iaton[i] = TMPxyz.iaton[i];
47008 		xyzp->iatclr[i] = TMPxyz.iatclr[i];
47009 		xyzp->iresid[i] = TMPxyz.iresid[i];
47010 		xyzp->ityp[i] = TMPxyz.ityp[i];
47011 		xyzp->ipdbt[i] = TMPxyz.ipdbt[i];
47012 		xyzp->lring[i] = TMPxyz.lring[i];
47013 		xyzp->isurf[i] = TMPxyz.isurf[i];
47014 		for (j=0; j<MXCON; j++)
47015 		   xyzp->iconn[i*(MXCON+1)+j] = TMPxyz.iconn[i*(MXCON+1)+j];
47016 	   }
47017 	   if (TMPxyz.mxorg) FreeCoo(TMPxyz);
47018 	}
47019 	xyzp->mxorg = 1;
47020 	*(xyzp->mxnat) = ZSize;
47021    }
47022 }
47023 
allConf(xyzc,ZSize)47024 int allConf(xyzc,ZSize)
47025 double **xyzc;
47026 int ZSize;
47027 {
47028    int memstat;
47029    double d;
47030 
47031    memstat = 1;
47032 
47033    if ((*xyzc = (double *) malloc((sizeof d)*ZSize*3)) == NULL) {
47034 	memstat = 0;
47035    }
47036 
47037    if (!memstat) {
47038 	fprintf(stderr,"Out of memory\n");
47039 	return(0);
47040    }
47041 
47042    return(1);
47043 }
47044 
allFConf(xyzc,ZSize)47045 int allFConf(xyzc,ZSize)
47046 float **xyzc;
47047 int ZSize;
47048 {
47049    int memstat;
47050    float f;
47051 
47052    memstat = 1;
47053 
47054    if ((*xyzc = (float *) malloc((sizeof f)*ZSize*3)) == NULL) {
47055 	memstat = 0;
47056    }
47057 
47058    if (!memstat) {
47059 	fprintf(stderr,"Out of memory\n");
47060 	return(0);
47061    }
47062 
47063    return(1);
47064 }
47065 
alldck(xyzc,ZSizep)47066 void alldck(xyzc,ZSizep)
47067 COOSTRU *xyzc;
47068 int *ZSizep;
47069 {
47070    int memstat;
47071    double d;
47072    int i;
47073    short int j;
47074    int ZSize;
47075 
47076    memstat = 1;
47077    ZSize = *ZSizep;
47078 
47079    if ((xyzc->coo = (double *) malloc((sizeof d)*ZSize*3)) == NULL) {
47080 	memstat = 0;
47081    }
47082 
47083    if ((xyzc->qat = (double *) malloc((sizeof d)*ZSize)) == NULL) {
47084 	memstat = 0;
47085    }
47086 
47087 
47088    if ((xyzc->ianz = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47089 	memstat = 0;
47090    }
47091 
47092    if ((xyzc->iaton = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47093 	memstat = 0;
47094    }
47095 
47096    if ((xyzc->iconn = (int *) malloc((sizeof i)*ZSize*(MXCON+1))) == NULL) {
47097 	memstat = 0;
47098    }
47099 
47100    if ((xyzc->iatclr = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47101 	memstat = 0;
47102    }
47103 
47104    if ((xyzc->iresid = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47105 	memstat = 0;
47106    }
47107 
47108    if ((xyzc->isurf = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47109 	memstat = 0;
47110    }
47111 
47112    if ((xyzc->lwrit = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47113 	memstat = 0;
47114    }
47115 
47116    if ((xyzc->lring = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47117 	memstat = 0;
47118    }
47119 
47120    if ((xyzc->icont = (int *) malloc((sizeof i)*ZSize)) == NULL) {
47121 	memstat = 0;
47122    }
47123 
47124    if ((xyzc->ityp = (short int *) malloc((sizeof j)*ZSize)) == NULL) {
47125 	memstat = 0;
47126    }
47127 
47128    xyzc->rzp   = NULL;
47129    xyzc->ipdbt = NULL;
47130    xyzc->ixp    = NULL;
47131    xyzc->iyp    = NULL;
47132    xyzc->inat   = NULL;
47133 
47134    if (!memstat) {
47135 	fprintf(stderr,"Out of memory\n");
47136    } else {
47137 	xyzc->iatoms = 0;
47138 	for (i=0; i < ZSize; i++) {
47139 		xyzc->qat[i] = 0.0;
47140 		xyzc->ianz[i] = 0;
47141 		xyzc->ityp[i] = 0;
47142 		xyzc->lring[i] = 0;
47143 		xyzc->lwrit[i] = 0;
47144 		xyzc->iaton[i] = 2;
47145 	}
47146 	xyzc->mxorg = 1;
47147    }
47148 }
47149 
47150 #if defined(VMS) || defined(UNDERSC)
almgrd()47151 void almgrd()
47152 #else
47153 #ifdef CRAY
47154 void ALMGRD()
47155 #else
47156 void almgrd_()
47157 #endif
47158 #endif
47159 {
47160    int memstat;
47161    double d;
47162    int ZSize;
47163 
47164    if (*mgrd.mx3d >= *sgrd.mx3d) return;
47165 
47166    ZSize = *sgrd.mx3d;
47167    memstat = 1;
47168 
47169    TMPmgrd = mgrd;
47170 
47171    if ((mgrd.fmap = (double *) malloc((sizeof d)*ZSize*ZSize*ZSize)) == NULL) {
47172 	memstat = 0;
47173    }
47174 
47175    if (!memstat) {
47176 	fprintf(stderr,"Out of memory\n");
47177 	mgrd = TMPmgrd;
47178    } else {
47179 	if (TMPmgrd.mxorg) {
47180 	   free(TMPmgrd.fmap);
47181 	}
47182 	mgrd.mxorg = 1;
47183 	*mgrd.mx3d = ZSize;
47184    }
47185 }
47186 
EditCOL()47187 void EditCOL()
47188 {
47189    int i;
47190    XColor exact_def;
47191 
47192    ECOLup = 1;
47193 
47194    ECOLwin = CreateWindow("Color Editor","-0+0",ECOLWINW,ECOLWINH,
47195 	 		 infobg,infofg,(Window)0);
47196    XSelectInput(display, ECOLwin,
47197 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask
47198 		| ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
47199    XMapWindow(display,ECOLwin);
47200 
47201    WinObj[25].win = &ECOLwin;
47202    WinObj[25].subwin = NULL;
47203    WinObj[25].butarr = butecol;
47204    WinObj[25].numbut = 1;
47205    WinObj[25].winup = &ECOLup;
47206    WinObj[25].redraw = RedrawECOL;
47207 
47208    DefBut(&butecol[0], ECOLwin, 100, 140, 50, 23,
47209 	"Close", infobg, -15);
47210 
47211    for (i=0; i<3; i++) {
47212 	ecolwn[i] = 70535; ecolwpos[i] = 0;
47213 	DefScroll(&ecolscr[i],ECOLwin,20+i*40,30,20,100,&ecolwn[i],&ecolwpos[i],5000,NULL);
47214    }
47215 
47216    exact_def.pixel = colors[activecolor];
47217    XQueryColor(display, cmap, &exact_def);
47218 
47219    ecolwpos[0] = 65535 - exact_def.red;
47220    ecolwpos[1] = 65535 - exact_def.green;
47221    ecolwpos[2] = 65535 - exact_def.blue;
47222 
47223 }
47224 
RedrawECOL()47225 void RedrawECOL()
47226 {
47227    int i;
47228 
47229    if (!ECOLup) return;
47230 
47231    butje(ECOLwin,0,0,ECOLWINW,ECOLWINH,4,0,-15,1,None,0,0,0);
47232    ULineString(ECOLwin,"Red",20,20);
47233    ULineString(ECOLwin,"Green",60,20);
47234    ULineString(ECOLwin,"Blue",100,20);
47235    for (i=0; i<3; i++) RedrawScroll(&ecolscr[i]);
47236    XSetForeground(display, gc, colors[activecolor] );
47237    XFillRectangle(display, ECOLwin, gc, 140, 30, 100, 100);
47238 
47239    DrwBut(&butecol[0]);
47240 
47241 }
47242 
SetPalCol(updateshades)47243 void SetPalCol(updateshades)
47244 int updateshades;
47245 {
47246    XColor exact_def;
47247    int r,g,b;
47248 
47249    r = (65535 - ecolwpos[0]);
47250    g = (65535 - ecolwpos[1]);
47251    b = (65535 - ecolwpos[2]);
47252    exact_def.red = (unsigned short) r;
47253    exact_def.green = (unsigned short) g;
47254    exact_def.blue = (unsigned short) b;
47255 
47256    XFreeColors(display, cmap,&colors[activecolor],1,0);
47257 
47258    if (XAllocColor(display, cmap, &exact_def) ) {
47259 	colors[activecolor] = exact_def.pixel;
47260 	colorr[activecolor] = exact_def.red;
47261 	colorg[activecolor] = exact_def.green;
47262 	colorb[activecolor] = exact_def.blue;
47263    }
47264    if (updateshades) {
47265 	ParseBasicColor(activecolor,0);
47266 #if defined(VMS) || defined(UNDERSC)
47267 	wrtres();
47268 #else
47269 #ifdef CRAY
47270 	WRTRES();
47271 #else
47272 	wrtres_();
47273 #endif
47274 #endif
47275    }
47276    RedrawECOL();
47277 }
47278 
47279 #if defined(VMS) || defined(UNDERSC)
wrtres()47280 void wrtres()
47281 #else
47282 #ifdef CRAY
47283 void WRTRES()
47284 #else
47285 void wrtres_()
47286 #endif
47287 #endif
47288 {
47289    int i;
47290    unsigned short r,g,b;
47291    char wfile[500];
47292    char *hm;
47293    FILE *out;
47294 
47295 #ifdef __CYGWIN__
47296    strcpy(wfile,".moldenrc");
47297 #else
47298    hm = getenv("HOME");
47299    if (hm == NULL) return;
47300    strcpy(wfile,hm);
47301    strcat(wfile,"/.moldenrc");
47302 #endif
47303 
47304    out = fopen(wfile,"w");
47305    if (out != NULL) {
47306 	for (i=1; i<99; i++) {
47307 	   fprintf(out,"%s %d %f\n",elements[i],elmptr->icol[i-1],
47308 		elmptr->vdwr[i-1]);
47309 	}
47310 	fprintf(out,"background %d \n",IBGcolor);
47311 	fprintf(out,"oglbackground %d \n",OBGcolor);
47312 	fprintf(out,"backgroundmode %d \n",BGmode);
47313 	fprintf(out,"palette ");
47314 	for (i=1; i<15; i++) {
47315 	   r = colorr[i] / 256;
47316 	   g = colorg[i] / 256;
47317 	   b = colorb[i] / 256;
47318 	   fprintf(out,"#%02X%02X%02X ",r,g,b);
47319 	}
47320 	fprintf(out,"\n");
47321 	if (*ball) {
47322 	   fprintf(out,"newrot\n");
47323 	} else {
47324 	   fprintf(out,"oldrot\n");
47325 	}
47326 	if (DelayRemember && *ideltm) {
47327 	   fprintf(out,"delaytime %d\n",*ideltm);
47328 	}
47329 	if (*igffrm != 1) {
47330 	   fprintf(out,"snapformat %d\n",*igffrm);
47331 	}
47332 
47333    }
47334    fclose(out);
47335 }
47336 
UpdateDPT()47337 void UpdateDPT()
47338 {
47339    double i;
47340 
47341    *uscl = (double) (5.0*(double) dptwpos[0] / 200.0);
47342    if (*uscl <= 0.0) *uscl = 0.01;
47343 
47344    update_struct();
47345 
47346 }
47347 
47348 
InitDPT()47349 void InitDPT()
47350 {
47351    int i;
47352 
47353    DPTup = 1;
47354 
47355    DPTwin = CreateWindow("Depth Editor","-0+0",ECOLWINW,ECOLWINH,
47356 	 		 infobg,infofg,(Window)0);
47357    XSelectInput(display, DPTwin,
47358 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask
47359 		| ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
47360    XMapWindow(display,DPTwin);
47361 
47362    WinObj[23].win = &DPTwin;
47363    WinObj[23].subwin = NULL;
47364    WinObj[23].butarr = butdpt;
47365    WinObj[23].numbut = 2;
47366    WinObj[23].winup = &DPTup;
47367    WinObj[23].redraw = RedrawDPT;
47368 
47369    DefBut(&butdpt[0], DPTwin, 100, 140, 50, 23,
47370 	"Close", infobg, -15);
47371 
47372    DefBut(&butdpt[1], DPTwin, 100, 10, 120, 23,
47373 	"Max. Linewdith", infobg, -15);
47374 
47375    for (i=0; i<1; i++) {
47376 	dptwn[i] = 240; dptwpos[i] = 100;
47377 	DefScroll(&dptscr[i],DPTwin,20+i*40,30,20,100,&dptwn[i],&dptwpos[i],40,UpdateDPT);
47378    }
47379 
47380 }
47381 
RedrawDPT()47382 void RedrawDPT()
47383 {
47384    int i;
47385 
47386    if (!DPTup) return;
47387 
47388    butje(DPTwin,0,0,ECOLWINW,ECOLWINH,4,0,-15,1,None,0,0,0);
47389    ULineString(DPTwin,"Shade Depth",20,20);
47390    for (i=0; i<1; i++) RedrawScroll(&dptscr[i]);
47391 
47392    DrwBut(&butdpt[0]);
47393    DrwBut(&butdpt[1]);
47394 
47395 }
47396 
WriteCML()47397 void WriteCML()
47398 {
47399   int i;
47400   char wfile[500];
47401   FILE *out;
47402 
47403   strcpy(wfile,"molecule.cml");
47404 
47405   out = fopen(wfile,"w");
47406   if (out != NULL) {
47407 	fprintf(out,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
47408 	fprintf(out,"<!DOCTYPE molecule SYSTEM \"cml.dtd\" [\n");
47409 	fprintf(out,"<!ATTLIST list convention CDATA #IMPLIED>\n");
47410 	fprintf(out,"]>\n");
47411 
47412 	fprintf(out,"<molecule id=\"mol\">\n");
47413 	fprintf(out,"  <atomArray>\n");
47414 
47415         fprintf(out,"    <stringArray builtin=\"elementType\">\n");
47416 	for (i=0; i<*xyzp->iatoms; i++)
47417 	   fprintf(out,"%s ",elements[xyzp->ianz[i]]);
47418 	fprintf(out,"\n");
47419 	fprintf(out,"    </stringArray>\n");
47420 
47421 	fprintf(out,"    <floatArray builtin=\"x3\">\n");
47422 	fprintf(out,"      ");
47423 	for (i=0; i<*xyzp->iatoms; i++)
47424 	   fprintf(out,"%f ",xyzp->coo[i*3]*toangs);
47425 	fprintf(out,"\n");
47426 	fprintf(out,"    </floatArray>\n");
47427 
47428 	fprintf(out,"    <floatArray builtin=\"y3\">\n");
47429 	fprintf(out,"      ");
47430 	for (i=0; i<*xyzp->iatoms; i++)
47431 	   fprintf(out,"%f ",xyzp->coo[i*3+1]*toangs);
47432 	fprintf(out,"\n");
47433 	fprintf(out,"    </floatArray>\n");
47434 
47435 	fprintf(out,"    <floatArray builtin=\"z3\">\n");
47436 	fprintf(out,"      ");
47437 	for (i=0; i<*xyzp->iatoms; i++)
47438 	   fprintf(out,"%f ",xyzp->coo[i*3+2]*toangs);
47439 	fprintf(out,"\n");
47440 	fprintf(out,"    </floatArray>\n");
47441 
47442 	fprintf(out,"  </atomArray>\n");
47443 	fprintf(out,"</molecule>\n");
47444 
47445 	fclose(out);
47446   }
47447 }
47448 
InitMAP()47449 void InitMAP()
47450 {
47451   int i;
47452 
47453   MAPup = 1;
47454 
47455   MAPwin = CreateWindow("Mapped Surface","-0+0",MAPWINW,MAPWINH,
47456 	 		 infobg,infofg,(Window)0);
47457   XSelectInput(display, MAPwin, EnterWindowMask |
47458 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask);
47459   XMapWindow(display,MAPwin);
47460 
47461   WinObj[27].win = &MAPwin;
47462   WinObj[27].subwin = NULL;
47463   WinObj[27].butarr = mapbut;
47464   WinObj[27].numbut = NBUTSM;
47465   WinObj[27].winup = &MAPup;
47466   WinObj[27].redraw = RedrawMAP;
47467 
47468   DefBut(&mapbut[0], MAPwin, 125, 355, 50, 23,
47469 	"Apply", infobg, -15);
47470 
47471   DefBut(&mapbut[1], MAPwin, 375, 355, 50, 23,
47472 	"Cancel", infobg, -15);
47473 
47474   DefBut(&mapbut[2], MAPwin, 370, 40, 120, 23, "wrlfile", infobg, 0);
47475   mapbut[2].str = mapopts[*imapopt];
47476 
47477   DefBut(&mapbut[3], MAPwin, 370, 70, 120, 23, "output", infobg, 0);
47478   mapbut[3].str = viropts[iviropt];
47479 
47480   DefBut(&mapbut[4], MAPwin, 390, 180, 15, 15, "", infobg, 0);
47481   DefBut(&mapbut[5], MAPwin, 390, 200, 15, 15, "", infobg, 0);
47482   DefBut(&mapbut[6], MAPwin, 20, 40, 70, 23, "Map file:", infobg, 0);
47483 
47484   if (*icpsa) TogDown(&mapbut[4]);
47485   if (*idtpsa) TogDown(&mapbut[5]);
47486 
47487   qboxstr(&qboxes[QMFILE],&MAPwin,0,0,190,15,40,
47488 	350,QBOXHIGH,2,"                 ","0.0",SUBLEN1,QSTRING,2000,0,dummyproc);
47489   strcp(mfile,qboxes[QMFILE].str,SUBLEN1);
47490   TrmStr(&qboxes[QMFILE]);
47491   qboxes[QMFILE].curpos = strlen(qboxes[QMFILE].str);
47492 
47493   qboxstr(&qboxes[QVFILE],&MAPwin,0,0,190,15,70,
47494 	350,QBOXHIGH,2,"VRML/OpenGL file:","0.0",SUBLEN1,QSTRING,2000,0,dummyproc);
47495   if (*ivtwo >= 3) {
47496 	strcp(oglfile,qboxes[QVFILE].str,SUBLEN1);
47497   } else {
47498 	strcp(vfile,qboxes[QVFILE].str,SUBLEN1);
47499   }
47500   TrmStr(&qboxes[QVFILE]);
47501   qboxes[QVFILE].curpos = strlen(qboxes[QVFILE].str);
47502 
47503   if (*ipsi) {
47504 	qboxstr(&qboxes[QCNTVAL],&MAPwin,0,0,190,15,MAPOFFY,
47505 	250,QBOXHIGH,2,"Contour Value    ","0.1",12,QREAL,2000,-1,dummyproc);
47506   } else {
47507 	qboxstr(&qboxes[QCNTVAL],&MAPwin,0,0,190,15,MAPOFFY,
47508 	250,QBOXHIGH,2,"Contour Value    ","0.02",12,QREAL,2000,-1,dummyproc);
47509   }
47510   sprintf(qboxes[QCNTVAL].str,"%f", cntval);
47511   qboxes[QCNTVAL].curpos = strlen(qboxes[QCNTVAL].str);
47512 
47513   for (i=0; i<5; i++) {
47514 	qboxstr(&qboxes[QCOLVAL1+i],&MAPwin,0,0,190,38,MAPOFFY+60+i*30,
47515 		180,QBOXHIGH,2,mapstr[i],"0.0",12,QREAL,2000,-1,dummyproc);
47516 	qboxes[QCOLVAL1+i].dflt = &mapval[i];
47517 	sprintf(qboxes[QCOLVAL1+i].str,"%f",mapval[i]);
47518 	qboxes[QCOLVAL1+i].curpos = strlen(qboxes[QCOLVAL1+i].str);
47519   }
47520 
47521   qboxstr(&qboxes[QPOLVAL1],&MAPwin,0,0,190,MAPOFFX+140,MAPOFFY,
47522 	110,QBOXHIGH,2,"<","0.001",12,QREAL,2000,-1,dummyproc);
47523   sprintf(qboxes[QPOLVAL1].str,"%f", *pol);
47524   qboxes[QPOLVAL1].curpos = strlen(qboxes[QPOLVAL1].str);
47525 
47526   qboxstr(&qboxes[QPOLVAL2],&MAPwin,0,0,190,MAPOFFX+250,MAPOFFY,
47527 	105,QBOXHIGH,2,">","0.001",12,QREAL,2000,-1,dummyproc);
47528   sprintf(qboxes[QPOLVAL2].str,"%f", *pol2);
47529   qboxes[QPOLVAL2].curpos = strlen(qboxes[QPOLVAL2].str);
47530 
47531   qboxes[QMFILE].active = 1;
47532 }
47533 
RedrawMAP()47534 void RedrawMAP()
47535 {
47536    int i;
47537 
47538    if (!MAPup) return;
47539 
47540    butje(MAPwin,0,0,MAPWINW,MAPWINH,4,0,-15,1,None,0,0,0);
47541 
47542    ULineString(MAPwin,"Select Types:",373,25);
47543    LineString(MAPwin,"Apolar potential range (for PSA):",280,120);
47544    ULineString(MAPwin,"Color         Elec. potential:",38,182);
47545    LineString(MAPwin,"Mark PSA        ",280,195);
47546    LineString(MAPwin,"Incl. Topol. PSA",280,215);
47547 
47548 /*
47549    XSetForeground(display, gc, colors[activecolor] );
47550    XFillRectangle(display, MAPwin, gc, 140, 30, 100, 100);
47551 */
47552 
47553    for (i=0; i<NBUTSM; i++) DrwBut(&mapbut[i]);
47554    for (i=0; i<8; i++) PromptBox(&qboxes[QVFILE+i]);
47555    PromptBox(&qboxes[QPOLVAL1]);
47556    PromptBox(&qboxes[QPOLVAL2]);
47557 
47558 }
47559 
ButtonsMAP(i)47560 int ButtonsMAP(i)
47561 int i;
47562 {
47563    LSSTRU List;
47564    int j;
47565 
47566    switch(i) {
47567    case 0:
47568 	*Sinct = 600;
47569 	cpstr(qboxes[QCNTVAL].str,Sstr,strlen(qboxes[QCNTVAL].str));
47570 	*Snstr = strlen(qboxes[QCNTVAL].str);
47571 	cntval = atof(qboxes[QCNTVAL].str);
47572 	*pol = atof(qboxes[QPOLVAL1].str);
47573 	*pol2 = atof(qboxes[QPOLVAL2].str);
47574 	for (j=0; j<5; j++) mapval[j] = atof(qboxes[QCOLVAL1+j].str);
47575 	if (iviropt == 0) *ivtwo = 1;
47576 	if (iviropt == 1) *ivtwo = 3;
47577 	if (iviropt == 2) *ivtwo = 4;
47578 	cpstr(qboxes[QMFILE].str,mfile,SUBLEN1);
47579 	if (iviropt == 1) {
47580 	    cpstr(qboxes[QVFILE].str,oglfile,SUBLEN1);
47581         } else {
47582 	    cpstr(qboxes[QVFILE].str,vfile,SUBLEN1);
47583 	}
47584 	XDestroyWindow(display,MAPwin);MAPup = 0;
47585 	*mapit = 1;
47586 	return(1);
47587 	break;
47588    case 1:
47589 	XDestroyWindow(display,MAPwin);MAPup = 0;
47590 	break;
47591    case 2: List.list = mapopts; List.nents = 2;
47592 	   if (DoPopUp(MAPwin,mapbut[2].x+60,mapbut[2].y+BUTTH,
47593 		&List,imapopt,1) == -1) break;
47594 	   mapbut[2].str = mapopts[*imapopt];
47595 	break;
47596    case 3: List.list = viropts; List.nents = 3;
47597 	   if (DoPopUp(MAPwin,mapbut[3].x+60,mapbut[3].y+BUTTH,
47598 		&List,&iviropt,1) == -1) break;
47599 	   mapbut[3].str = viropts[iviropt];
47600 	   if (iviropt >= 1) {
47601 		strcp(oglfile,qboxes[QVFILE].str,SUBLEN1);
47602 	   } else {
47603 		strcp(vfile,qboxes[QVFILE].str,SUBLEN1);
47604 	   }
47605 	   TrmStr(&qboxes[QVFILE]);
47606 	   qboxes[QVFILE].curpos = strlen(qboxes[QVFILE].str);
47607 	   RedrawMAP();
47608 	break;
47609    case 4:
47610 	if (*icpsa) {
47611 	   *icpsa = 0;
47612 	   TogUp(&mapbut[4]);
47613 	} else {
47614 	   *icpsa = 1;
47615 	   TogDown(&mapbut[4]);
47616 	}
47617 	break;
47618    case 5:
47619 	if (*idtpsa) {
47620 	   *idtpsa = 0;
47621 	   TogUp(&mapbut[5]);
47622 	} else {
47623 	   *idtpsa = 1;
47624 	   TogDown(&mapbut[5]);
47625 	}
47626 	break;
47627    case 6:
47628 	gsel.qbrfile = 1;
47629 	gsel.subopt = 1;
47630 	FileSelectList(&gsel);
47631 	break;
47632    }
47633    return(0);
47634 }
47635 
InitVIR()47636 void InitVIR()
47637 {
47638 
47639   VIRup = 1;
47640 
47641   VIRwin = CreateWindow("VR file","-0+0",VIRWINW,VIRWINH,
47642 	 		 infobg,infofg,(Window)0);
47643   XSelectInput(display, VIRwin, EnterWindowMask |
47644 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask);
47645   XMapWindow(display,VIRwin);
47646 
47647   WinObj[28].win = &VIRwin;
47648   WinObj[28].subwin = NULL;
47649   WinObj[28].butarr = virbut;
47650   WinObj[28].numbut = 2;
47651   WinObj[28].winup = &VIRup;
47652   WinObj[28].redraw = RedrawVIR;
47653 
47654   DefBut(&virbut[0], VIRwin, 125, 110, 50, 23,
47655 	"Apply", infobg, -15);
47656 
47657   DefBut(&virbut[1], VIRwin, 375, 110, 50, 23,
47658 	"Cancel", infobg, -15);
47659 
47660   qboxstr(&qboxes[QSVFILE],&VIRwin,0,0,190,15,30,
47661 	450,QBOXHIGH,2,"Output file:","0.0",SUBLEN1,QSTRING,2000,0,dummyproc);
47662 
47663   switch(*ivtwo) {
47664 	case 0:
47665 	case 1:
47666 		strcp(vfile,qboxes[QSVFILE].str,SUBLEN1);
47667 		break;
47668 	case 2:
47669 		strcp(povfile,qboxes[QSVFILE].str,SUBLEN1);
47670 		break;
47671 	case 3:
47672 		strcp(oglfile,qboxes[QSVFILE].str,SUBLEN1);
47673 		break;
47674   }
47675   TrmStr(&qboxes[QSVFILE]);
47676   qboxes[QSVFILE].curpos = strlen(qboxes[QSVFILE].str);
47677 
47678   if (*ipsi) {
47679 	qboxstr(&qboxes[QSCNT],&VIRwin,0,0,190,15,70,
47680 	250,QBOXHIGH,2,"Contour Value    ","0.1",12,QREAL,2000,-1,dummyproc);
47681   } else {
47682 	qboxstr(&qboxes[QSCNT],&VIRwin,0,0,190,15,70,
47683 	250,QBOXHIGH,2,"Contour Value    ","0.02",12,QREAL,2000,-1,dummyproc);
47684   }
47685 
47686   qboxes[QSVFILE].active = 1;
47687 }
47688 
RedrawVIR()47689 void RedrawVIR()
47690 {
47691    int i;
47692 
47693    if (!VIRup) return;
47694 
47695    butje(VIRwin,0,0,VIRWINW,VIRWINH,4,0,-15,1,None,0,0,0);
47696 
47697    for (i=0; i<2; i++) DrwBut(&virbut[i]);
47698    for (i=0; i<2; i++) PromptBox(&qboxes[QSVFILE+i]);
47699 
47700 }
47701 
ButtonsVIR(i)47702 int ButtonsVIR(i)
47703 int i;
47704 {
47705 
47706    switch(i) {
47707    case 0:
47708 	*Sinct = 600;
47709 	cpstr(qboxes[QSCNT].str,Sstr,strlen(qboxes[QSCNT].str));
47710 	*Snstr = strlen(qboxes[QSCNT].str);
47711 	switch(*ivtwo) {
47712 	case 0:
47713 	case 1:
47714 		cpstr(qboxes[QSVFILE].str,vfile,SUBLEN1);
47715 		break;
47716 	case 2:
47717 		cpstr(qboxes[QSVFILE].str,povfile,SUBLEN1);
47718 		break;
47719 	case 3:
47720 		cpstr(qboxes[QSVFILE].str,oglfile,SUBLEN1);
47721 		break;
47722 	}
47723 	XDestroyWindow(display,VIRwin);VIRup = 0;
47724 	return(1);
47725 	break;
47726    case 1:
47727 	XDestroyWindow(display,VIRwin);VIRup = 0;
47728 	break;
47729    }
47730    return(0);
47731 }
47732 
47733 #define MAXONIERR 70
47734 static char ONIerr[MAXONIERR];
47735 
CreateONI()47736 void CreateONI()
47737 {
47738   int i;
47739 
47740   ONIup = 1;
47741 
47742   ONIwin = CreateWindow("Oniom","-80-80",
47743                          OBOXWIDE,OBOXHIGH,infobg,infofg,(Window)0);
47744   subONI = CreateWindow("Subwindow","",10,10,
47745                             colors[0],colors[15],ONIwin);
47746   XSelectInput(display, ONIwin,
47747         ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask |
47748 	SubstructureNotifyMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask);
47749 
47750   XMapWindow(display,ONIwin);
47751 
47752   WinObj[38].win = &ONIwin;
47753   WinObj[38].subwin = &subONI;
47754   WinObj[38].butarr = onbut;
47755   WinObj[38].numbut = NBUTSO;
47756   WinObj[38].winup = &ONIup;
47757   WinObj[38].redraw = RedrawONI;
47758 
47759   DefBut(&onbut[OMETHH], ONIwin, OBOXOFFX, 30,         OBOXBLEN, 23,
47760         "Method", infobg, -15);
47761   onbut[OMETHH].explstr = "Method for the High quality layer";
47762 
47763   DefBut(&onbut[OBASSH], ONIwin, OBOXOFFX, 30+BUTTN,   OBOXBLEN, 23,
47764         "Basis Set", infobg, -15);
47765   onbut[OBASSH].explstr = "Basis Set for the High quality layer\nIf applicable";
47766 
47767   DefBut(&onbut[OCHARH], ONIwin, OBOXOFFX, 30+2*BUTTN, OBOXBLEN, 23,
47768         "Charge", infobg, -15);
47769   onbut[OCHARH].explstr = "Total charge of the High quality layer";
47770 
47771   DefBut(&onbut[OMULTH], ONIwin, OBOXOFFX, 30+3*BUTTN, OBOXBLEN, 23,
47772         "Multiplicity", infobg, -15);
47773   onbut[OMULTH].explstr = "Spin multiplicity of the High quality layer";
47774 
47775   DefBut(&onbut[OALLH],  ONIwin, OBOXOFFX, 30+4*BUTTN, OBOXBLEN, 23,
47776         "All H", infobg, -ONIHCOL);
47777   onbut[OALLH].explstr = "All atoms are assigned to the High quality layer";
47778 
47779   DefBut(&onbut[OSELH],  ONIwin, OBOXOFFX, 35+6*BUTTN, OBOXBLEN, 23,
47780         "Apply H", infobg, -ONIHCOL);
47781   onbut[OSELH].explstr = "Assign currently selected atoms\nto the High quality layer";
47782 
47783 
47784   DefBut(&onbut[OMETHM], ONIwin, OBOXOFFX+110, 30,         OBOXBLEN, 23,
47785         "Method", infobg, -15);
47786   onbut[OMETHM].explstr = "Method for the Medium quality layer";
47787 
47788   DefBut(&onbut[OBASSM], ONIwin, OBOXOFFX+110, 30+BUTTN,   OBOXBLEN, 23,
47789         "Basis Set", infobg, -15);
47790   onbut[OBASSM].explstr = "Basis Set for the Medium quality layer\nIf applicable";
47791 
47792   DefBut(&onbut[OCHARM], ONIwin, OBOXOFFX+110, 30+2*BUTTN, OBOXBLEN, 23,
47793         "Charge", infobg, -15);
47794   onbut[OCHARM].explstr = "Total charge of the Medium quality layer";
47795 
47796   DefBut(&onbut[OMULTM], ONIwin, OBOXOFFX+110, 30+3*BUTTN, OBOXBLEN, 23,
47797         "Multiplicity", infobg, -15);
47798   onbut[OMULTM].explstr = "Spin multiplicity of the Medium quality layer";
47799 
47800   DefBut(&onbut[OALLM],  ONIwin, OBOXOFFX+110, 30+4*BUTTN, OBOXBLEN, 23,
47801         "All M", infobg,-ONIMCOL);
47802   onbut[OALLM].explstr = "All atoms are assigned to\nthe Medium quality layer";
47803 
47804   DefBut(&onbut[OSELM],  ONIwin, OBOXOFFX+110, 35+6*BUTTN, OBOXBLEN, 23,
47805         "Apply M", infobg,-ONIMCOL);
47806   onbut[OSELM].explstr = "Assign currently selected atoms\nto the Medium quality layer";
47807 
47808 
47809   DefBut(&onbut[OMETHL], ONIwin, OBOXOFFX+220, 30,         OBOXBLEN, 23,
47810         "Method", infobg, -15);
47811   onbut[OMETHL].explstr = "Method for the Low quality layer";
47812 
47813   DefBut(&onbut[OBASSL], ONIwin, OBOXOFFX+220, 30+BUTTN,   OBOXBLEN, 23,
47814         "Basis Set", infobg, -15);
47815   onbut[OBASSL].explstr = "Basis Set for the Low quality layer\nIf applicable";
47816 
47817   DefBut(&onbut[OCHARL], ONIwin, OBOXOFFX+220, 30+2*BUTTN, OBOXBLEN, 23,
47818         "Charge", infobg, -15);
47819   onbut[OCHARL].explstr = "Total charge of the Low quality layer";
47820 
47821   DefBut(&onbut[OMULTL], ONIwin, OBOXOFFX+220, 30+3*BUTTN, OBOXBLEN, 23,
47822         "Multiplicity", infobg, -15);
47823   onbut[OMULTL].explstr = "Spin multiplicity of the Low quality layer";
47824 
47825   DefBut(&onbut[OALLL],  ONIwin, OBOXOFFX+220, 30+4*BUTTN, OBOXBLEN, 23,
47826         "All L", infobg,-ONILCOL);
47827   onbut[OALLL].explstr = "All atoms are assigned to\nthe Low quality layer";
47828 
47829   DefBut(&onbut[OSELL],  ONIwin, OBOXOFFX+220, 35+6*BUTTN, OBOXBLEN, 23,
47830         "Apply L", infobg,-ONILCOL);
47831   onbut[OSELL].explstr = "Assign currently selected atoms\nto the Low quality layer";
47832 
47833 
47834   DefBut(&onbut[OSEL],   ONIwin, OBOXOFFX,     35+5*BUTTN, OBOXBLEN+20, 23,
47835         "Select by pointer", infobg, -15);
47836   onbut[OSEL].explstr = "Select atoms to be assigned to layer\nSelect: Left mouse button+drag+release";
47837 
47838   DefBut(&onbut[OUSEL],  ONIwin, OBOXOFFX+125, 35+5*BUTTN, OBOXBLEN-20, 23,
47839         "DeSelect", infobg,-15);
47840   onbut[OUSEL].explstr = "Deselect atoms to be assigned to layer\nDeselect: Left mouse button+drag+release";
47841 
47842   DefBut(&onbut[OSELR],  ONIwin, OBOXOFFX+220, 35+5*BUTTN, OBOXBLEN, 23,
47843         "Select residue", infobg,-15);
47844   onbut[OSELR].explstr = "Select residue to be assigned to layer\nSelect: click residue with left mouse button";
47845   if (*ipdbon == 0) ActBut(&onbut[OSELR],0);
47846 
47847 
47848   DefBut(&onbut[OCOLO],  ONIwin, OBOXOFFX+10, 35+10*BUTTN, 15, 15,
47849         " ", infobg,-15);
47850   onbut[OCOLO].explstr = "Use different colors for each layer";
47851 
47852   DefBut(&onbut[OCLOS],  ONIwin, OBOXOFFX+110, 35+11*BUTTN, OBOXBLEN, 23,
47853         "Close", infobg,-15);
47854 
47855   DefBut(&onbut[OAMBCH], ONIwin, OBOXOFFX+120, 35+10*BUTTN, 15, 15,
47856         " ", infobg,-15);
47857   onbut[OAMBCH].explstr = "Write amber charges and atom types\nas part of the atom label";
47858 
47859   onbut[OMETHH].str = mopt[imopth];
47860   onbut[OBASSH].str = bopt[ibopth];
47861   onbut[OCHARH].str = copt[jobcom->icopth+3];
47862   onbut[OMULTH].str = spopt[jobcom->ispopth-1];
47863   onbut[OMETHL].str = mopt[imoptl];
47864   onbut[OBASSL].str = bopt[iboptl];
47865   onbut[OCHARL].str = copt[jobcom->icoptl+3];
47866   onbut[OMULTL].str = spopt[jobcom->ispoptl-1];
47867   onbut[OMETHM].str = mopt[imoptm];
47868   onbut[OBASSM].str = bopt[iboptm];
47869   onbut[OCHARM].str = copt[jobcom->icoptm+3];
47870   onbut[OMULTM].str = spopt[jobcom->ispoptm-1];
47871 
47872   if (*fftyp != 3) {
47873      for (i=0;i<*xyzp->iatoms;i++) {
47874 	xyzp->ityp[i] = 0;
47875      }
47876   }
47877 
47878   ParseLine();
47879 
47880   if (*atcol) {
47881 	TogUp(&onbut[OCOLO]);
47882   } else {
47883 	TogDown(&onbut[OCOLO]);
47884   }
47885 
47886   if (*ambchg) {
47887 	TogDown(&onbut[OAMBCH]);
47888   } else {
47889 	TogUp(&onbut[OAMBCH]);
47890   }
47891 }
47892 
RedrawONI()47893 void RedrawONI()
47894 {
47895   int i;
47896 
47897   butje(ONIwin,0,0,OBOXWIDE,OBOXHIGH,4,0,0,1,None,0,0,0);
47898   ULineString(ONIwin,"High",OBOXOFFX+30,21);
47899   ULineString(ONIwin,"Medium",OBOXOFFX+140,21);
47900   ULineString(ONIwin,"Low",OBOXOFFX+250,21);
47901   ULineString(ONIwin,"Color by Layer",OBOXOFFX+30,46+10*BUTTN);
47902   ULineString(ONIwin,"write amber charges",OBOXOFFX+140,46+10*BUTTN);
47903   for (i=0; i<NBUTSO; i++) DrwBut(&onbut[i]);
47904 
47905   RedrawONIStatus();
47906 
47907 }
47908 
ButtonsONI(i)47909 int ButtonsONI(i)
47910 int i;
47911 {
47912   LSSTRU List;
47913   int ret=0;
47914   int nat;
47915 
47916   switch (i) {
47917   case OMETHH:
47918                 List.list = mopt; List.nents = moptn;
47919                 if (DoPopUp(ONIwin,
47920 			onbut[OMETHH].x+OBOXBLEN/2,onbut[OMETHH].y+BUTTH,
47921                         &List,&imopth,1) == -1) break;
47922                 onbut[OMETHH].str = mopt[imopth];
47923                 break;
47924   case OBASSH:
47925                 List.list = bopt; List.nents = boptn;
47926                 if (DoPopUp(ONIwin,
47927 			onbut[OBASSH].x+OBOXBLEN/2,onbut[OBASSH].y+BUTTH,
47928                         &List,&ibopth,1) == -1) break;
47929                 onbut[OBASSH].str = bopt[ibopth];
47930                 break;
47931   case OMETHL:
47932                 List.list = mopt; List.nents = moptn;
47933                 if (DoPopUp(ONIwin,
47934 			onbut[OMETHL].x+OBOXBLEN/2,onbut[OMETHL].y+BUTTH,
47935                         &List,&imoptl,1) == -1) break;
47936                 onbut[OMETHL].str = mopt[imoptl];
47937                 break;
47938   case OBASSL:
47939                 List.list = bopt; List.nents = boptn;
47940                 if (DoPopUp(ONIwin,
47941 			onbut[OBASSL].x+OBOXBLEN/2,onbut[OBASSL].y+BUTTH,
47942                         &List,&iboptl,1) == -1) break;
47943                 onbut[OBASSL].str = bopt[iboptl];
47944                 break;
47945   case OMETHM:
47946                 List.list = mopt; List.nents = moptn;
47947                 if (DoPopUp(ONIwin,
47948 			onbut[OMETHM].x+OBOXBLEN/2,onbut[OMETHM].y+BUTTH,
47949                         &List,&imoptm,1) == -1) break;
47950                 onbut[OMETHM].str = mopt[imoptm];
47951                 break;
47952   case OBASSM:
47953                 List.list = bopt; List.nents = boptn;
47954                 if (DoPopUp(ONIwin,
47955 			onbut[OBASSM].x+OBOXBLEN/2,onbut[OBASSM].y+BUTTH,
47956                         &List,&iboptm,1) == -1) break;
47957                 onbut[OBASSM].str = bopt[iboptm];
47958                 break;
47959   case OALLH:
47960                 strcpy(ONIerr,"H level for all atoms");
47961                 RedrawONIStatus();
47962                 for ( i = 0; i < *xyzp->iatoms; i++ ) {
47963                    if (xyzp->ityp[i] >= 10000)
47964 			xyzp->ityp[i] -= (xyzp->ityp[i]/10000)*10000
47965 ;
47966                    xyzp->iatclr[i] = ONIHCOL;
47967                 }
47968 		ret = 1;
47969                 break;
47970   case OALLM:
47971                 strcpy(ONIerr,"M level for all atoms");
47972                 RedrawONIStatus();
47973                 for ( i = 0; i < *xyzp->iatoms; i++ ) {
47974                    if (xyzp->ityp[i] >= 20000) {
47975                       xyzp->ityp[i] -= 10000;
47976                    } else {
47977                       if (xyzp->ityp[i]<10000) xyzp->ityp[i] += 10000;
47978                    }
47979                    xyzp->iatclr[i] = ONIMCOL;
47980                 }
47981 		ret = 1;
47982                 break;
47983   case OALLL:
47984                 strcpy(ONIerr,"L level for all atoms");
47985                 RedrawONIStatus();
47986                 for ( i = 0; i < *xyzp->iatoms; i++ ) {
47987                    if (xyzp->ityp[i] < 20000)
47988 			xyzp->ityp[i] += (2-xyzp->ityp[i]/10000)*10000;
47989                    xyzp->iatclr[i] = ONILCOL;
47990                 }
47991 		ret = 1;
47992                 break;
47993   case OSELH:
47994                 Selecting = 0;
47995                 nat = 0;
47996                 for ( i = 0; i < *xyzp->iatoms; i++ ) if (xyzp->iaton[i] > 1) nat++;
47997                 if (!nat) {
47998                         strcpy(ONIerr,"Invalid Selection: No atoms selected");
47999                         if (*ibell) XBell(display,0);
48000                         RedrawONIStatus();
48001                         return(0);
48002                 }
48003                 if (nat > *zmptrp->mxzat) {
48004                    strcpy(ONIerr,"Invalid Selection: Too many atoms selected");
48005                    if (*ibell) XBell(display,0);
48006                    RedrawONIStatus();
48007                    for ( i = 0; i < *xyzp->iatoms; i++ )
48008                         if (xyzp->iaton[i] >= 2) xyzp->iaton[i] = 1;
48009                    ret = 1;
48010                 }
48011                 else {
48012                    strcpy(ONIerr,"Selected atoms at H level");
48013                    RedrawONIStatus();
48014                    for ( i = 0; i < *xyzp->iatoms; i++ ) {
48015                         if (xyzp->iaton[i] >= 2) {
48016                             if (xyzp->ityp[i] >= 10000) xyzp->ityp[i] -=
48017                                 (xyzp->ityp[i] /10000)*10000;
48018                                 xyzp->iatclr[i] = ONIHCOL;
48019                         }
48020                         xyzp->iaton[i] = 1;
48021                    }
48022 		   ret = 1;
48023                 }
48024                 break;
48025   case OSELM:
48026 		Selecting = 0;
48027 		nat = 0;
48028 		for ( i = 0; i < *xyzp->iatoms; i++ ) if (xyzp->iaton[i] > 1) nat++;
48029 		if (!nat) {
48030 			strcpy(ONIerr,"Invalid Selection: No atoms selected");
48031 			if (*ibell) XBell(display,0);
48032 			RedrawONIStatus();
48033 			return(0);
48034 		}
48035 		if (nat > *zmptrp->mxzat) {
48036 		   strcpy(ONIerr,"Invalid Selection: Too many atoms selected");
48037 		   if (*ibell) XBell(display,0);
48038 		   RedrawONIStatus();
48039 		   for ( i = 0; i < *xyzp->iatoms; i++ )
48040 			if (xyzp->iaton[i] >= 2) xyzp->iaton[i] = 1;
48041 	  	   ret = 1;
48042 		}
48043 		else {
48044 		   strcpy(ONIerr,"Selected atoms at M level");
48045 		   RedrawONIStatus();
48046 		   for ( i = 0; i < *xyzp->iatoms; i++ ) {
48047 			if (xyzp->iaton[i] >= 2) {
48048 				if (xyzp->ityp[i] >= 20000) {
48049 		      		   xyzp->ityp[i] -= 10000;
48050 		   		} else {
48051 		   	   	   if (xyzp->ityp[i] < 10000)
48052 				   xyzp->ityp[i] += 10000;
48053 		   		}
48054 			       xyzp->iatclr[i] = ONIMCOL;
48055 			}
48056 			xyzp->iaton[i] = 1;
48057 		   }
48058 		   ret = 1;
48059 	        }
48060 		break;
48061   case OSELL:
48062 		Selecting = 0;
48063 		nat = 0;
48064 		for ( i = 0; i < *xyzp->iatoms; i++ ) if (xyzp->iaton[i] > 1) nat++;
48065 		if (!nat) {
48066 			strcpy(ONIerr,"Invalid Selection: No atoms selected");
48067 			if (*ibell) XBell(display,0);
48068 			RedrawONIStatus();
48069 			return(0);
48070 		}
48071 		if (nat > *zmptrp->mxzat) {
48072 
48073 		   strcpy(ONIerr,"Invalid Selection: Too many atoms selected");
48074 		   if (*ibell) XBell(display,0);
48075 		   RedrawONIStatus();
48076 		   for ( i = 0; i < *xyzp->iatoms; i++ )
48077 			if (xyzp->iaton[i] >= 2) xyzp->iaton[i] = 1;
48078 	  	   ret = 1;
48079 
48080 		} else {
48081 
48082 		   strcpy(ONIerr,"Selected atoms at L level");
48083 		   RedrawONIStatus();
48084 		   for ( i = 0; i < *xyzp->iatoms; i++ ) {
48085 			if (xyzp->iaton[i] >= 2) {
48086 			   if (xyzp->ityp[i] < 20000) xyzp->ityp[i] +=
48087                               (2-xyzp->ityp[i]/10000)*10000;
48088 			   xyzp->iatclr[i] = ONILCOL;
48089 			}
48090 			xyzp->iaton[i] = 1;
48091 		   }
48092 		   ret = 1;
48093 
48094   	        }
48095 		break;
48096   case OSEL:
48097                 strcpy(ONIerr,selstr);
48098                 RedrawONIStatus();
48099                 DeActZME();
48100                 Selecting = 1;
48101                 ZoomEnable = True;Select = True;
48102                 break;
48103   case OUSEL:
48104                 strcpy(ONIerr,dselstr);
48105                 RedrawONIStatus();
48106                 ZoomEnable = True;Select = False;
48107                 break;
48108   case OSELR:
48109 		if (*ipdbon) {
48110 		   strcpy(ONIerr,"Pick a residue");
48111 		   RedrawONIStatus();
48112 		   bflag = 1; bretval = 565;
48113 		   XDefineCursor(display,win,AtomCursor);
48114 		} else {
48115 		   ActBut(&onbut[OSELR],0);
48116 		}
48117                 break;
48118   case OCOLO:
48119 		TogBut(&cbut[BATCOL]);
48120 		TogBut(&onbut[OCOLO]);
48121 		if (*atcol) *atcol = 0;
48122 		else *atcol = 1;
48123                 *Sinct = 400;*Sincp = 0;
48124 		ret = 1;
48125                 break;
48126   case OCLOS:
48127 	        XDestroyWindow(display,ONIwin);ONIup = 0;
48128 		return(0);
48129                 break;
48130   case OCHARH:
48131 		List.list = copt; List.nents = 7;
48132 		if (DoPopUp(ONIwin,
48133 			onbut[OCHARH].x+OBOXBLEN/2,onbut[OCHARH].y+BUTTH,
48134 			&List,&jobcom->icopth,1) == -1) break;
48135 		jobcom->icopth = jobcom->icopth - 3;
48136 		onbut[OCHARH].str = copt[jobcom->icopth+3];
48137 		break;
48138   case OMULTH:
48139 		List.list = spopt; List.nents = 8;
48140 		if (DoPopUp(ONIwin,
48141 			onbut[OMULTH].x+OBOXBLEN/2,onbut[OMULTH].y+BUTTH,
48142 			&List,&jobcom->ispopth,1) == -1) break;
48143 		jobcom->ispopth = jobcom->ispopth + 1;
48144 		onbut[OMULTH].str = spopt[jobcom->ispopth-1];
48145 		break;
48146   case OCHARM:
48147 		List.list = copt; List.nents = 7;
48148 		if (DoPopUp(ONIwin,
48149 			onbut[OCHARM].x+OBOXBLEN/2,onbut[OCHARM].y+BUTTH,
48150 			&List,&jobcom->icoptm,1) == -1) break;
48151 		jobcom->icoptm = jobcom->icoptm - 3;
48152 		onbut[OCHARM].str = copt[jobcom->icoptm+3];
48153 		break;
48154   case OMULTM:
48155 		List.list = spopt; List.nents = 8;
48156 		if (DoPopUp(ONIwin,
48157 			onbut[OMULTM].x+OBOXBLEN/2,onbut[OMULTM].y+BUTTH,
48158 			&List,&jobcom->ispoptm,1) == -1) break;
48159 		jobcom->ispoptm = jobcom->ispoptm + 1;
48160 		onbut[OMULTM].str = spopt[jobcom->ispoptm-1];
48161 		break;
48162   case OCHARL:
48163 		List.list = copt; List.nents = 7;
48164 		if (DoPopUp(ONIwin,
48165 			onbut[OCHARL].x+OBOXBLEN/2,onbut[OCHARL].y+BUTTH,
48166 			&List,&jobcom->icoptl,1) == -1) break;
48167 		jobcom->icoptl = jobcom->icoptl - 3;
48168 		onbut[OCHARL].str = copt[jobcom->icoptl+3];
48169 		break;
48170   case OMULTL:
48171 		List.list = spopt; List.nents = 8;
48172 		if (DoPopUp(ONIwin,
48173 			onbut[OMULTL].x+OBOXBLEN/2,onbut[OMULTL].y+BUTTH,
48174 			&List,&jobcom->ispoptl,1) == -1) break;
48175 		jobcom->ispoptl = jobcom->ispoptl + 1;
48176 		onbut[OMULTL].str = spopt[jobcom->ispoptl-1];
48177 		break;
48178   case OAMBCH:
48179 		TogBut(&onbut[OAMBCH]);
48180 		if (*ambchg) *ambchg = 0;
48181 		else *ambchg = 1;
48182 		break;
48183   default: break;
48184   }
48185 
48186   if (SUBup) {
48187      RedrawSUB();
48188      ParseLine();
48189      PromptBox(&qboxes[QGLIN1]);
48190      PromptBox(&qboxes[QGLIN2]);
48191   }
48192   RedrawONI();
48193 
48194   update_sel = 1;
48195 
48196   if (ret) {
48197      return(1);
48198   } else {
48199      return(0);
48200   }
48201 
48202 }
48203 
48204 
RedrawONIStatus()48205 void RedrawONIStatus()
48206 {
48207 
48208  if (!ONIup) return;
48209 
48210  butje(ONIwin,0,220,OBOXWIDE-1,40,1,0,0,1,None,0,0,0);
48211  butje(ONIwin,ZMEZOffx,220+10,OBOXWIDE-2*ZMEZOffx,20,2,0,2,0,None,0,0,0);
48212  XSetForeground(display, gc, infobg);
48213  XDrawString(display,ONIwin,gc,ZMEZOffx+5,220+24,ONIerr,strlen(ONIerr));
48214 }
48215 
48216 
DeActOButs()48217 void DeActOButs()
48218 {
48219   ActBut(&onbut[OMETHL],2);
48220   ActBut(&onbut[OBASSL],2);
48221   ActBut(&onbut[OALLL],2);
48222   ActBut(&onbut[OSELL],2);
48223 }
48224 
ActOButs()48225 void ActOButs()
48226 {
48227   ActBut(&onbut[OMETHL],1);
48228   ActBut(&onbut[OBASSL],1);
48229   ActBut(&onbut[OALLL],1);
48230   ActBut(&onbut[OSELL],1);
48231 }
48232 
48233 
CreateFLR()48234 void CreateFLR()
48235 {
48236   int i;
48237 
48238   FLRup = 1;
48239   bckrig = 0;
48240   *icst = 1;
48241 
48242   FLRwin = CreateWindow("FlexRigid","-80-80",
48243                          FBOXWIDE,FBOXHIGH,infobg,infofg,(Window)0);
48244   subFLR = CreateWindow("Subwindow","",10,10,
48245                             colors[0],colors[15],FLRwin);
48246   XSelectInput(display, FLRwin,
48247         ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask |
48248 	SubstructureNotifyMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask);
48249 
48250   XMapWindow(display,FLRwin);
48251 
48252   WinObj[39].win = &FLRwin;
48253   WinObj[39].subwin = &subFLR;
48254   WinObj[39].butarr = flrbut;
48255   WinObj[39].numbut = NBUTSF;
48256   WinObj[39].winup = &FLRup;
48257   WinObj[39].redraw = RedrawFLR;
48258 
48259   DefBut(&flrbut[FRIGD],  FLRwin, FBOXOFFX, 30, FBOXBLEN, 23,
48260         "All Rigid", infobg, -FRIGCOL);
48261   flrbut[FRIGD].explstr = "All atoms are assigned rigid";
48262 
48263   DefBut(&flrbut[FSELR],  FLRwin, FBOXOFFX, 35+5*BUTTN, FBOXBLEN, 23,
48264         "Selection Rigid", infobg, -FRIGCOL);
48265   flrbut[FSELR].explstr = "Assign currently selected atoms rigid";
48266 
48267 
48268   DefBut(&flrbut[FFLEX],  FLRwin, FBOXOFFX+110, 30, FBOXBLEN, 23,
48269         "All Flexible", infobg,-FLEXCOL);
48270   flrbut[FFLEX].explstr = "All atoms are assigned flexible";
48271 
48272   DefBut(&flrbut[FSELF],  FLRwin, FBOXOFFX+110, 35+5*BUTTN, FBOXBLEN+20, 23,
48273         "Selection Flexible", infobg,-FLEXCOL);
48274   flrbut[FSELF].explstr = "Assign currently selected atoms flexible";
48275 
48276   DefBut(&flrbut[FSEL],   FLRwin, FBOXOFFX,     35+2*BUTTN, FBOXBLEN+20, 23,
48277         "Select by pointer", infobg, -15);
48278   flrbut[FSEL].explstr = "Select atoms to be assigned rigid/flexible\nSelect: Left mouse button+drag+release";
48279 
48280   DefBut(&flrbut[FUSEL],  FLRwin, FBOXOFFX+125, 35+2*BUTTN, FBOXBLEN-20, 23,
48281         "DeSelect", infobg,-15);
48282   flrbut[FUSEL].explstr = "Deselect atoms to be assigned\nDeselect: Left mouse button+drag+release";
48283 
48284   DefBut(&flrbut[FSELA],  FLRwin, FBOXOFFX+220, 35+2*BUTTN, FBOXBLEN, 23,
48285         "Select residue", infobg,-15);
48286   flrbut[FSELA].explstr = "Select residue to be assigned rigid/flexible\nSelect: click residue with left mouse button";
48287   if (*ipdbon == 0) ActBut(&flrbut[FSELR],0);
48288 
48289   DefBut(&flrbut[FCONT],  FLRwin, FBOXOFFX, 35+3*BUTTN, FBOXBLEN+105, 23,
48290         "residue/ligand + neighbours", infobg,-15);
48291   flrbut[FCONT].explstr = "Select residue/ligand + neighbours \nto be assigned rigid/flexible.\nSelect: click residue with left mouse button";
48292   if (*ipdbon == 0) ActBut(&flrbut[FCONT],0);
48293 
48294   DefBut(&flrbut[FBACK],  FLRwin, FBOXOFFX, 39+6*BUTTN, 15, 15,
48295         " ", infobg,-15);
48296   flrbut[FBACK].explstr = "Backbone rigid";
48297 
48298   DefBut(&flrbut[FCLOS],  FLRwin, FBOXOFFX+110, 35+7*BUTTN, FBOXBLEN, 23,
48299         "Close", infobg,-15);
48300 
48301   if (bckrig) {
48302 	TogDown(&flrbut[FBACK]);
48303   } else {
48304 	TogUp(&flrbut[FBACK]);
48305   }
48306 
48307   for ( i = 0; i < *xyzp->iatoms; i++ ) {
48308 	xyzp->isurf[i] = 1;
48309 	xyzp->iatclr[i] = FLEXCOL;
48310   }
48311 }
48312 
RedrawFLR()48313 void RedrawFLR()
48314 {
48315   int i;
48316 
48317   butje(FLRwin,0,0,FBOXWIDE,FBOXHIGH,4,0,0,1,None,0,0,0);
48318   ULineString(FLRwin,"Selection:",FBOXOFFX,46+1*BUTTN);
48319   ULineString(FLRwin,"Apply selection:",FBOXOFFX,49+4*BUTTN);
48320   LineString(FLRwin,"Backbone rigid",FBOXOFFX+20,49+6*BUTTN);
48321   for (i=0; i<NBUTSF; i++) DrwBut(&flrbut[i]);
48322 
48323 
48324 }
48325 
ButtonsFLR(k)48326 int ButtonsFLR(k)
48327 int k;
48328 {
48329   LSSTRU List;
48330   int ret=0;
48331   int i,j;
48332 
48333   switch (k) {
48334   case FRIGD:
48335                 for (i=0; i < *xyzp->iatoms; i++ ) {
48336 		   xyzp->isurf[i] = 0;
48337                    xyzp->iatclr[i] = FRIGCOL;
48338                 }
48339 		ret = 1;
48340                 break;
48341   case FFLEX:
48342                 for ( i = 0; i < *xyzp->iatoms; i++ ) {
48343 		   xyzp->isurf[i] = 1;
48344                    xyzp->iatclr[i] = FLEXCOL;
48345                 }
48346 		if (bckrig) {
48347 		    for (i=0; i < calfptr->ncalf; i++ ) {
48348 			for (j=0; j < 4; j++ ) {
48349 			    if (calfptr->icalf[i][j] >= 0) {
48350 				xyzp->isurf[calfptr->icalf[i][j]-1] = 0;
48351 				xyzp->iatclr[calfptr->icalf[i][j]-1] = FRIGCOL;
48352 			    }
48353 			}
48354 		    }
48355 		}
48356 		ret = 1;
48357                 break;
48358   case FSELR:
48359                 Selecting = 0;
48360                 for (i=0; i<*xyzp->iatoms; i++ ) {
48361                         if (xyzp->iaton[i] >= 2) {
48362 			   xyzp->isurf[i] = 0;
48363                            xyzp->iaton[i] = 1;
48364 			   xyzp->iatclr[i] = FRIGCOL;
48365 			}
48366                 }
48367 		ret = 1;
48368                 break;
48369   case FSELF:
48370 		Selecting = 0;
48371                 for (i = 0;i < *xyzp->iatoms; i++ ) {
48372                         if (xyzp->iaton[i] >= 2) {
48373 			   xyzp->isurf[i] = 1;
48374                            xyzp->iaton[i] = 1;
48375 			   xyzp->iatclr[i] = FLEXCOL;
48376 			}
48377                 }
48378 		ret = 1;
48379 		break;
48380   case FSEL:
48381                 Selecting = 1;
48382                 ZoomEnable = True;Select = True;
48383                 break;
48384   case FUSEL:
48385                 ZoomEnable = True;Select = False;
48386                 break;
48387   case FSELA:
48388 		if (*ipdbon) {
48389 		   bflag = 1; bretval = 565;
48390 		   XDefineCursor(display,win,AtomCursor);
48391 		} else {
48392 		   ActBut(&flrbut[FSELR],0);
48393 		}
48394                 break;
48395   case FCLOS:
48396 	        XDestroyWindow(display,FLRwin);FLRup = 0;
48397 		return(0);
48398                 break;
48399   case FBACK:
48400 		TogBut(&flrbut[FBACK]);
48401 		if (bckrig) bckrig = 0;
48402 		else bckrig = 1;
48403 		break;
48404   case FCONT:
48405 		if (*ipdbon) {
48406 		   bflag = 1; bretval = 566;
48407 		   XDefineCursor(display,win,AtomCursor);
48408 		} else {
48409 		   ActBut(&flrbut[FCONT],0);
48410 		}
48411 		break;
48412   default: break;
48413   }
48414 
48415   RedrawFLR();
48416 
48417   update_sel = 1;
48418 
48419   if (ret) {
48420      return(1);
48421   } else {
48422      return(0);
48423   }
48424 
48425 }
48426 
calc_spectrum(int iupd)48427 void calc_spectrum(int iupd)
48428 {
48429 
48430   int i, j, spnew;
48431   double intensity, frq, center, rel_offset;
48432   double (*lineshape)(double);
48433   double spec_mx_tmp;
48434 
48435   spec_mx_tmp = spec_mx;
48436 
48437   if (iupd && specup) {
48438 	hwhm = atof(qboxes[QHW].str);
48439 	freq_scale = atof(qboxes[QSSCAL].str);
48440 	min_freq = atoi(qboxes[QMINF].str);
48441 	max_freq = atoi(qboxes[QMAXF].str);
48442   }
48443 
48444   if (hwhm < 1.0e-10) {
48445     fprintf(stderr, "The specified HWHM of %f is too small.\n", hwhm);
48446     fprintf(stderr, "This program is exiting in calc_intensities\n");
48447     exit(1);
48448   }
48449 
48450   if (lorentzian) {
48451     lineshape = lorentz;
48452   }
48453   else {
48454     lineshape = gauss;
48455   }
48456 
48457   n_freqs = 1 + (max_freq - min_freq)/freq_step;
48458 
48459   spnew = sizeof(double)*2*n_freqs;
48460 
48461   if (spnew > specsize) {
48462      if (specsize > 0) free(out_spec);
48463      if ((out_spec = (double *) malloc(spnew)) == NULL) {
48464 	fprintf(stderr, "Memory allocation error for spectrum\n");
48465 	return;
48466      } else {
48467 	specsize = spnew;
48468      }
48469   }
48470 
48471   for (i=0; i < n_freqs; i++) {
48472     intensity = 0.0;
48473     frq = min_freq + i*freq_step;
48474     for (j=0; j < *spnfrq; j++) {
48475       center = (double) spfrq[j]*freq_scale;
48476       rel_offset = (frq - center) / hwhm;
48477       intensity += spint[j] * lineshape(rel_offset);
48478     }
48479     out_spec[i] = intensity;
48480   }
48481 
48482   INTextr();
48483   if (iupd && (spec_mx_tmp != spec_mx)) spec_mx = spec_mx_tmp;
48484 
48485 /*
48486   for (i=1; i < n_freqs; i++) {
48487      fprintf(stderr,"%d %11.6f\n",i,out_spec[i]);
48488   }
48489 */
48490   return;
48491 }
48492 
write_spectrum(char * fname,int orient,int opt)48493 void write_spectrum(char *fname, int orient, int opt) {
48494 
48495 	specps = 1;
48496 	spout = fopen(fname,"w");
48497 	fprintf(spout,"%%!PS-Adobe-1.0%%\n");
48498 	fprintf(spout,"%%%%Title: Molden\n");
48499 	if (orient) {
48500 	   fprintf(spout,"%%%%BoundingBox: 0 0 612 792\n");
48501 	} else {
48502 	   if (opt) {
48503 	      //fprintf(spout,"%%%%BoundingBox: 40 -250 500 50\n");
48504 	   } else {
48505 	      fprintf(spout,"%%%%BoundingBox: 40 -550 770 50\n");
48506 	   }
48507 	}
48508 	fprintf(spout,"/m { moveto } def\n");
48509 	fprintf(spout,"/l { lineto } def\n");
48510 	fprintf(spout,"/Helvetica-Bold findfont [ 5   0   0  5   0   0] makefont setfont\n");
48511 	fprintf(spout,"%%%%EndProlog\n");
48512 	fprintf(spout,"0 setgray\n");
48513 	if (orient) {
48514 	   fprintf(spout,"90 rotate\n");
48515 	}
48516 	if (opt) {
48517 	   fprintf(spout,"1.75 1.75 scale\n");
48518 	   fprintf(spout,"-20 280 translate\n");
48519 	} else {
48520 	   fprintf(spout,"1.3 2.0 scale\n");
48521 	   fprintf(spout,"10 0 translate\n");
48522         }
48523         drwspec();
48524 	fprintf(spout,"showpage\n");
48525 	fclose(spout);
48526 	specps = 0;
48527 }
48528 
wrjdx(filename)48529 void wrjdx(filename)
48530     char *filename;
48531 {
48532     int i,j,k,ifrq,xmax,xmin;
48533     double frq,yscale;
48534     FILE *jdxfile,*molfile,*xyzfile;
48535     char line[MAXCMD];
48536     char tline[MAXCMD];
48537     char *q;
48538 
48539     jdxfile = fopen(filename,"w");
48540     if (!jdxfile) {
48541 	fprintf(stderr,"Output Error: Unable to create jdx file %s\n",filename);
48542 	return;
48543     }
48544 
48545     yscale = 1.0 / spec_mx;
48546     fprintf(jdxfile,"##TITLE=molden generated spectrum\n");
48547     fprintf(jdxfile,"##JCAMP-DX=4.24\n");
48548     fprintf(jdxfile,"##DATA TYPE=INFRARED SPECTRUM\n");
48549 
48550     molfile = fopen("mol.mol","r");
48551     if (molfile) {
48552 	fprintf(jdxfile,"##$MODELS=\n");
48553 	fprintf(jdxfile,"<Models>\n");
48554 	fprintf(jdxfile,"<ModelData id=\"mol\" type=\"MOL\">\n");
48555 
48556 	while (fgets(line,MAXCMD,molfile) != NULL) {
48557     	   fprintf(jdxfile,"%s",line);
48558 	}
48559     	fclose(molfile);
48560         fprintf(jdxfile,"</ModelData>\n");
48561 
48562 	xyzfile = fopen("mol.xyz","r");
48563 	if (xyzfile) {
48564 
48565 	   fprintf(jdxfile,"<ModelData id=\"1\" type=\"XYZVIB\" baseModel=\"mol\" vibrationScale=\".1\">\n");
48566 
48567 	   for (i=0; i < FRQ->nfreq; i++) {
48568 		ifrq = i + 1;
48569 #if defined(VMS) || defined(UNDERSC)
48570 		nrmi(&ifrq);
48571 #else
48572 #ifdef CRAY
48573 		NRMI(&ifrq);
48574 #else
48575 		nrmi_(&ifrq);
48576 #endif
48577 #endif
48578 		fgets(line,MAXCMD,xyzfile);
48579 		fprintf(jdxfile,"%s",line);
48580 		fgets(line,MAXCMD,xyzfile);
48581 		fprintf(jdxfile,"%d Freq: %#5.1f %s",ifrq,FRQ->freq[i],line);
48582 
48583 		k = 0;
48584 		while (fgets(line,MAXCMD,xyzfile) != NULL) {
48585 		   q = strchr(line,'\n');
48586 		   sprintf(q," %#12.6f %#12.6f %#12.6f\n",
48587 			FRQ->a[k][0]*toangs,FRQ->a[k][1]*toangs,FRQ->a[k][2]*toangs);
48588 		   fprintf(jdxfile,"%s",line);
48589 		   k++;
48590 		}
48591 
48592 		rewind(xyzfile);
48593 	   }
48594     	   fclose(xyzfile);
48595            fprintf(jdxfile,"</ModelData>\n");
48596 	}
48597         fprintf(jdxfile,"</Models>\n");
48598 
48599     }
48600 
48601     fprintf(jdxfile,"##$PEAKS=\n");
48602     fprintf(jdxfile,"<Peaks type=\"IR\" xUnitsExpected=\"1/cm\">\n");
48603     for (i=0; i < FRQ->nfreq; i++)  {
48604 	ifrq = i + 1;
48605 	if (i>0 && i < FRQ->nfreq-1) {
48606 	   xmin = (int) (FRQ->freq[i] - (FRQ->freq[i] - FRQ->freq[i-1]) / 2.0);
48607 	   xmax = (int) (FRQ->freq[i] + (FRQ->freq[i+1] - FRQ->freq[i]) / 2.0);
48608 	   xmax--;
48609 	} else {
48610 	   if (i == 0) {
48611 		xmin = 0;
48612 	   	xmax = (int) (FRQ->freq[i] + (FRQ->freq[i+1] - FRQ->freq[i]) / 2.0);
48613 	        xmax--;
48614 	   }
48615 	   if (i == FRQ->nfreq-1) {
48616 		xmin = (int) (FRQ->freq[i] - (FRQ->freq[i] - FRQ->freq[i-1]) / 2.0);
48617 	   	xmax = max_freq;
48618 	   }
48619 	}
48620 	fprintf(jdxfile,"<PeakData id=\"%d\" title=\"Freq %#6.1f\" peakShape=\"broad\" model=\"1.%d\" xMax=\"%d\" xMin=\"%d\">\n",ifrq,FRQ->freq[i],ifrq,xmax,xmin);
48621     }
48622     fprintf(jdxfile,"</Peaks>\n");
48623 
48624     fprintf(jdxfile,"##XUNITS=1/CM\n");
48625     fprintf(jdxfile,"##YUNITS=ABSORBANCE\n");
48626     fprintf(jdxfile,"##XLABEL=Wavenumbers (cm-1)\n");
48627     fprintf(jdxfile,"##YLABEL=%% Absorbance\n");
48628     fprintf(jdxfile,"##XFACTOR=1\n");
48629     fprintf(jdxfile,"##YFACTOR=1\n");
48630     fprintf(jdxfile,"##DELTAX=1\n");
48631     fprintf(jdxfile,"##FIRSTX=%d\n",min_freq);
48632     fprintf(jdxfile,"##LASTX=%d\n",max_freq);
48633     fprintf(jdxfile,"##FIRSTY=%f\n",spec_mn);
48634     fprintf(jdxfile,"##MAXX=%d\n",max_freq);
48635     fprintf(jdxfile,"##MINX=%d\n",min_freq);
48636     fprintf(jdxfile,"##MAXY=%f\n",spec_mx);
48637     fprintf(jdxfile,"##MINY=%f\n",spec_mn);
48638     fprintf(jdxfile,"##NPOINTS=%d\n",n_freqs);
48639     fprintf(jdxfile,"##XYDATA=(X++(Y..Y))\n");
48640 
48641     for (i=0; i < n_freqs; i += 5) {
48642 	frq = min_freq + i*freq_step;
48643 	fprintf(jdxfile,"%-11.6f",frq);
48644 	for (j=0; j < 5; j++) {
48645 	   if (i+j < n_freqs) {
48646 		fprintf(jdxfile," %6.4f",out_spec[i+j]*yscale);
48647 	   }
48648 	}
48649 	fprintf(jdxfile,"\n");
48650     }
48651     fprintf(jdxfile,"##END=\n");
48652 /*
48653 387.000000 0.9245 0.9240 0.9235 0.9231 0.9227
48654 */
48655 
48656     fclose(jdxfile);
48657 
48658 
48659     return;
48660 }
48661 
48662 #if defined(VMS) || defined(UNDERSC)
jdxwr()48663 void jdxwr()
48664 #else
48665 #ifdef CRAY
48666 void JDXWR()
48667 #else
48668 void jdxwr_()
48669 #endif
48670 #endif
48671 {
48672   char *fnam    = "mol.jdx";
48673   wrjdx(fnam);
48674 }
48675 
write_xmgr(char * fname)48676 void write_xmgr(char *fname) {
48677 int i;
48678 double frq;
48679 
48680 	spout = fopen(fname,"w");
48681 	for (i=0; i < n_freqs; i++) {
48682 	   frq = min_freq + i*freq_step;
48683 	   fprintf(spout,"%11.6f %11.6f\n",frq,out_spec[i]);
48684 	}
48685 	fclose(spout);
48686 }
48687 
wrtcallb(char * str)48688 void wrtcallb(char *str)
48689 {
48690 	write_spectrum(str,1,0);
48691 	drwspec();
48692 }
48693 
updcallb(char * str)48694 void updcallb(char *str)
48695 {
48696 	if (nmrptr->ihsnmr) prep_nmr();
48697 	calc_spectrum(1);
48698 	drwspec();
48699 }
48700 
srccallb(char * str)48701 void srccallb(char *str)
48702 {
48703 	PDBquery(str);
48704 }
48705 
ButtonsSPC(i)48706 int ButtonsSPC(i)
48707 int i;
48708 {
48709   int iupd;
48710   float tmp;
48711 
48712   switch (i) {
48713   case 0:	{
48714 	LSSTRU List;
48715 	List.list = pktyp; List.nents = 2;
48716 	if (DoPopUp(winspec,spbut[0].x+20,spbut[0].y,
48717 		&List,&lorentzian,0) == -1) return 0;
48718 	   spbut[0].str = pktyp[lorentzian];
48719 	   DrwBut(&spbut[0]);
48720         }
48721         break;
48722   case 1:	{
48723 	   LSSTRU List; List.nents = 2;
48724 
48725 	   if (FRQ->ihasi) {
48726 		if (*ihasex) {
48727 		    List.nents = 1;
48728 		    List.list = uvsptyp;
48729 		} else {
48730 		    List.list = sptyp;
48731 		}
48732 
48733 		if (DoPopUp(winspec,spbut[1].x+20,spbut[1].y,
48734 		    &List,&spmode,0) == -1) return 0;
48735 		if (*ihasex) {
48736 		   spbut[1].str = *uvsptyp;
48737 		   spint = FRQ->frint;
48738 		} else {
48739 		   spbut[1].str = sptyp[spmode];
48740         	   if (spmode) {
48741 			spint = FRQ->ramint;
48742 	   	   } else {
48743 			spint = FRQ->frint;
48744 		   }
48745 		}
48746 
48747 	   	frlist.list.flst = spint;
48748            	if (FRup) RedrawList(&frlist);
48749 	   	DrwBut(&spbut[1]);
48750 
48751 	   } else if (nmrptr->ihsnmr) {
48752 
48753 		List.list = nmrsptyp;
48754 
48755 		if (DoPopUp(winspec,spbut[1].x+20,spbut[1].y,
48756 		    &List,&spmode,0) == -1) return 0;
48757 		spbut[1].str = nmrsptyp[spmode];
48758 		if (spmode) {
48759 		    NMRnuc = 6;
48760 		    nmrref  = &nmr13Cref;
48761 		    freq_step = nmr13Cstep;
48762 		} else {
48763 		    NMRnuc = 1;
48764 		    nmrref  = &nmr1Href;
48765 		    freq_step = nmr1Hstep;
48766 		}
48767 		sprintf(qboxes[QTMS].str,"%6.2f",*nmrref);
48768 		qboxes[QTMS].curpos = strlen(qboxes[QTMS].str);
48769 		qboxes[QTMS].qflt = nmrref;
48770 	   	DrwBut(&spbut[1]);
48771 		prep_nmr();
48772 		FRQextr();
48773 		sprintf(qboxes[QMINF].str,"%d",min_freq);
48774 		sprintf(qboxes[QMAXF].str,"%d",max_freq);
48775 		qboxes[QMINF].curpos = strlen(qboxes[QMINF].str);
48776 		qboxes[QMAXF].curpos = strlen(qboxes[QMAXF].str);
48777            }
48778         }
48779         break;
48780   case 2:	{
48781         XDestroyWindow(display,winspec);
48782         specup = 0;
48783 	if (nmrptr->ihsnmr) TogUp(&cbut[BFORC]);
48784 	if (peaks != NULL) {
48785 	   free(peaks);
48786 	   peaks = NULL;
48787 	}
48788 	if (inten != NULL) {
48789 	   free(inten);
48790 	   inten = NULL;
48791 	}
48792 	return(0);
48793         }
48794         break;
48795   case 3:
48796 	qboxstr(&qboxes[QSFIL],NULL,1,0,-1,DEFQX,DEFQY,
48797 		QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
48798 		0,0,2000,0,wrtcallb);
48799         break;
48800   case 4:
48801 	qboxstr(&qboxes[QSFIL],NULL,1,0,-1,DEFQX,DEFQY,
48802 		QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
48803 		0,0,2000,0,write_xmgr);
48804         break;
48805   case 5:
48806         qboxstr(&qboxes[QSFIL],NULL,1,0,-1,DEFQX,DEFQY,
48807                 QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,
48808                 0,0,2000,0,wrjdx);
48809         break;
48810   case 6:
48811 	avch3(); prep_nmr();
48812         break;
48813   }
48814 
48815   iupd = 1;
48816   if (nmrptr->ihsnmr) {
48817 	iupd = 0;
48818 	tmp = atof(qboxes[QTMS].str);
48819 	if (tmp != *nmrref) iupd = 1;
48820 	*nmrref = tmp;
48821 	tmp = atof(qboxes[QFREQ].str);
48822 	if (tmp != NMRbas) iupd = 1;
48823 	NMRbas = tmp;
48824 	if (iupd) prep_nmr();
48825   }
48826   calc_spectrum(iupd);
48827   sprintf(qboxes[QIMAX].str,"%-4.2f",spec_mx);
48828   qboxes[QIMAX].curpos = strlen(qboxes[QIMAX].str);
48829 
48830   drwspec();
48831 }
48832 
InitDelay()48833 void InitDelay()
48834 {
48835 
48836   DELup = 1;
48837 
48838   DELAYwin = CreateWindow("Delay Time","-0+0",DELWINW,DELWINH,
48839 	 		 infobg,infofg,(Window)0);
48840   XSelectInput(display, DELAYwin, EnterWindowMask |
48841 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask);
48842   XMapWindow(display,DELAYwin);
48843 
48844   WinObj[29].win = &DELAYwin;
48845   WinObj[29].subwin = NULL;
48846   WinObj[29].butarr = delbut;
48847   WinObj[29].numbut = 3;
48848   WinObj[29].winup = &DELup;
48849   WinObj[29].redraw = RedrawDEL;
48850 
48851   DefBut(&delbut[0], DELAYwin, 50, 75, 50, 23,
48852 	"Apply", infobg, -15);
48853   DefBut(&delbut[1], DELAYwin, 200, 75, 50, 23,
48854 	"Close", infobg, -15);
48855   DefBut(&delbut[2], DELAYwin, 125, 75, 50, 23,
48856 	"Save", infobg, -15);
48857 
48858   qboxstr(&qboxes[QDEL],&DELAYwin,0,0,190,15,30,
48859 	250,QBOXHIGH,2,"Delay Time [msec] Next Structure ","1",12,
48860 	QPOSINT,2000,-1,dummyproc);
48861 
48862   qboxes[QDEL].iflt = ideltm;
48863   sprintf(qboxes[QDEL].str,"%d",*ideltm);
48864   qboxes[QDEL].curpos = strlen(qboxes[QDEL].str);
48865   qboxes[QDEL].active = 1;
48866 }
48867 
RedrawDEL()48868 void RedrawDEL()
48869 {
48870 
48871    if (!DELup) return;
48872 
48873    butje(DELAYwin,0,0,DELWINW,DELWINH,4,0,0,1,None,0,0,0);
48874 
48875    DrwBut(&delbut[0]);
48876    DrwBut(&delbut[1]);
48877    DrwBut(&delbut[2]);
48878    PromptBox(&qboxes[QDEL]);
48879 
48880 }
48881 
ButtonsDEL(i)48882 int ButtonsDEL(i)
48883 int i;
48884 {
48885 
48886    switch(i) {
48887    case 0:
48888 	*ideltm = atoi(qboxes[QDEL].str);
48889 	break;
48890    case 1:
48891 	*ideltm = atoi(qboxes[QDEL].str);
48892 	XDestroyWindow(display,DELAYwin);DELup = 0;
48893 	break;
48894    case 2:
48895 	*ideltm = atoi(qboxes[QDEL].str);
48896 	DelayRemember = 1;
48897 #if defined(VMS) || defined(UNDERSC)
48898 	wrtres();
48899 #else
48900 #ifdef CRAY
48901 	WRTRES();
48902 #else
48903 	wrtres_();
48904 #endif
48905 #endif
48906 	break;
48907    }
48908 }
48909 
48910 #if defined(VMS) || defined(UNDERSC)
srfclr()48911 void srfclr()
48912 #else
48913 #ifdef CRAY
48914 void SRFCLR()
48915 #else
48916 void srfclr_()
48917 #endif
48918 #endif
48919 {
48920     int i;
48921 
48922     if (*ipdbon) {
48923 	if (RIBindex[istruct].end[3] < RIBindex[istruct].start[3]) {
48924 	     NSurf[istruct] = RIBindex[istruct].start[2] +
48925 				RIBindex[istruct].nrna;
48926 	} else {
48927 	     NSurf[istruct] = RIBindex[istruct].start[3] +
48928 				RIBindex[istruct].ncoil;
48929 	}
48930     }
48931     else NSurf[istruct] = 0;
48932     *natorg = 0;
48933     if (NSurf[istruct] < 0) NSurf[istruct] = 0;
48934 }
48935 
cmprot(a,b)48936 static int cmprot(a,b)
48937 RESROTSTRU *a, *b;
48938 {
48939     if (a->etot > b->etot) return 1;
48940     else
48941        if (a->etot == b->etot) return  0;
48942        else          return -1;
48943 }
48944 
48945 #if defined(VMS) || defined(UNDERSC)
stowat(ino)48946 void stowat(ino)
48947 #else
48948 #ifdef CRAY
48949 void STOWAT(ino)
48950 #else
48951 void stowat_(ino)
48952 #endif
48953 #endif
48954 int *ino;
48955 {
48956    int i,j,k,kk,n,ncon;
48957    int icnn[MXCON+1];
48958 
48959    if (!*ipdbon) return;
48960 
48961    if (watcoo[istruct] == NULL ||
48962 	(watcoo[istruct] != NULL && *ino > nwater[istruct])) {
48963       if (watcoo[istruct] != NULL) free(watcoo[istruct]);
48964       if ((watcoo[istruct] =
48965 	(double *) malloc((sizeof(double))*(*ino*3))) == NULL) {
48966 	fprintf(stderr, "Memory allocation error for store water\n");
48967 	return;
48968       }
48969    }
48970 
48971    if (watanz[istruct] == NULL ||
48972 	(watanz[istruct] != NULL && *ino > nwater[istruct])) {
48973       if (watanz[istruct] != NULL) free(watanz[istruct]);
48974       if ((watanz[istruct] =
48975 	(int *) malloc((sizeof(int))*(*ino))) == NULL) {
48976 	fprintf(stderr, "Memory allocation error for store water\n");
48977 	return;
48978       }
48979    }
48980 
48981    if (watres[istruct] == NULL ||
48982 	(watres[istruct] != NULL && *ino > nwater[istruct])) {
48983       if (watres[istruct] != NULL) free(watres[istruct]);
48984       if ((watres[istruct] =
48985 	(int *) malloc((sizeof(int))*(*ino))) == NULL) {
48986 	fprintf(stderr, "Memory allocation error for store water\n");
48987 	return;
48988       }
48989    }
48990 
48991    if (watcon[istruct] == NULL ||
48992 	(watcon[istruct] != NULL && *ino > nwater[istruct])) {
48993       if (watcon[istruct] != NULL) free(watcon[istruct]);
48994       if ((watcon[istruct] =
48995 	(int *) malloc((sizeof(int))*(MXCON+1)*(*ino))) == NULL) {
48996 	fprintf(stderr, "Memory allocation error for store water\n");
48997 	return;
48998       }
48999    }
49000 
49001    if (watqat[istruct] == NULL ||
49002 	(watqat[istruct] != NULL && *ino > nwater[istruct])) {
49003       if (watqat[istruct] != NULL) free(watqat[istruct]);
49004       if ((watqat[istruct] =
49005 	(double *) malloc((sizeof(double))*(*ino))) == NULL) {
49006 	fprintf(stderr, "Memory allocation error for store water\n");
49007 	return;
49008       }
49009    }
49010 
49011    if (wattyp[istruct] == NULL ||
49012 	(wattyp[istruct] != NULL && *ino > nwater[istruct])) {
49013       if (wattyp[istruct] != NULL) free(wattyp[istruct]);
49014       if ((wattyp[istruct] =
49015 	(short int *) malloc((sizeof(short int))*(*ino))) == NULL) {
49016 	fprintf(stderr, "Memory allocation error for store water\n");
49017 	return;
49018       }
49019    }
49020 
49021    if (watmap[istruct] == NULL ||
49022 	(watmap[istruct] != NULL && *ino > nwater[istruct])) {
49023       if (watmap[istruct] != NULL) free(watmap[istruct]);
49024       if ((watmap[istruct] =
49025 	(int *) malloc((sizeof(int))*(*xyzp->mxnat))) == NULL) {
49026 	fprintf(stderr, "Memory allocation error for store water\n");
49027 	return;
49028       }
49029    }
49030    n = 0;
49031    for (i=0; i < *xyzp->iatoms; i++ ) {
49032 	watmap[istruct][i] = -1;
49033 	if (xyzp->ianz[i] < 100 && xyzp->iaton[i] == 1) {
49034 	    watmap[istruct][i] = n;
49035 	    n++;
49036 	}
49037    }
49038 
49039    n = 0;
49040    for (i=0; i < *xyzp->iatoms; i++ ) {
49041 	if (xyzp->ianz[i] < 100 && xyzp->iaton[i] == 1) {
49042 	    for (k=0; k < 3; k++)
49043 		watcoo[istruct][n*3+k] = xyzp->coo[i*3+k];
49044 	    watanz[istruct][n] = xyzp->ianz[i];
49045 	    watqat[istruct][n] = xyzp->qat[i];
49046 	    wattyp[istruct][n] = xyzp->ityp[i];
49047 	    watres[istruct][n] = xyzp->iresid[i];
49048 	    ncon = 0;
49049 	    for (k=0; k < xyzp->iconn[i*(MXCON+1)]; k++) {
49050 		kk = xyzp->iconn[i*(MXCON+1)+1+k];
49051 		if (kk > 0 && kk < *xyzp->mxnat) {
49052 		   kk--;
49053 		   if (watmap[istruct][kk] != -1) {
49054 			icnn[ncon] = watmap[istruct][kk];
49055 			ncon++;
49056 		   }
49057 		}
49058 	    }
49059 	    watcon[istruct][n*(MXCON+1)] = ncon;
49060 	    for (k=0; k < ncon; k++)
49061 		watcon[istruct][n*(MXCON+1)+k+1] = icnn[k];
49062 	    n++;
49063 	}
49064    }
49065    nwater[istruct] = n;
49066    free(watmap[istruct]);
49067    watmap[istruct] = NULL;
49068 
49069 }
49070 
49071 /*
49072 int watcon(coo1,coo2)
49073 double *coo1;
49074 double *coo2;
49075 {
49076   double v[3],d;
49077   int i, iflag;
49078 
49079   iflag = 0;
49080 
49081   for (i=0; i<3; i++) v[i] = coo2[i] - coo1[i];
49082   d = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
49083   if (d > 0.0) d = sqrt(d);
49084   if (d*0.52917706 < 1.2) iflag = 1;
49085 
49086   return(iflag);
49087 }
49088 */
49089 
reswat()49090 void reswat()
49091 {
49092    int i,j,k,n,ia,ic,icnn[2],ncon;
49093 
49094    if (!*ipdbon || (*ipdbon && zmpart->ipart) ) return;
49095 
49096    if (watcoo[istruct] == NULL || watanz[istruct] == NULL ||
49097 	watres[istruct] == NULL) return;
49098 
49099    ia = *xyzp->iatoms;
49100    n = nwater[istruct];
49101    if (n+ia > *xyzp->mxnat)  {
49102 	n = *xyzp->mxnat - ia;
49103 	fprintf(stderr,"Not enough room to restore all waters !!!!\n");
49104    }
49105 
49106    for (i=0; i < n; i++ ) {
49107 	for (k=0; k < 3; k++)
49108 	   xyzp->coo[(i+ia)*3+k] = watcoo[istruct][i*3+k];
49109 	xyzp->iconn[(i+ia)*(MXCON+1)] = watcon[istruct][i*(MXCON+1)];
49110 	for (k=1; k < MXCON+1; k++)
49111 	   xyzp->iconn[(i+ia)*(MXCON+1)+k] =
49112 		ia + watcon[istruct][i*(MXCON+1)+k] + 1;
49113 	xyzp->ianz[ia+i] = watanz[istruct][i];
49114 	xyzp->qat[ia+i] = watqat[istruct][i];
49115 	xyzp->ityp[ia+i] = wattyp[istruct][i];
49116 	xyzp->iresid[ia+i] = watres[istruct][i];
49117 	xyzp->iatclr[ia+i] = 1;
49118 	if (*backb && !calfptr->ihets[ABS(watres[istruct][i])] ) {
49119 	   xyzp->iaton[ia+i] = 0;
49120 	} else {
49121 	   xyzp->iaton[ia+i] = 1;
49122 	}
49123    }
49124    *xyzp->iatoms = ia + n;
49125 }
49126 
RescoreResrot()49127 void RescoreResrot()
49128 {
49129    int i,j,l,n,i7=7;
49130    char wfile[500];
49131 
49132 /* fftyp ? , charges ? (only when also doing ligand ?)
49133    PMF score and ambfor use same array
49134 */
49135 
49136 /*
49137    if (itypBackup == NULL) {
49138       if ((itypBackup = (short int *) malloc((sizeof(short int))*(*xyzp->mxnat))) == NULL) {
49139 	fprintf(stderr, "Memory allocation error for itypBackup\n");
49140 	return;
49141       } else {
49142           for (i=0; i<*xyzp->mxnat; i++) itypBackup[i] = xyzp->ityp[i];
49143       }
49144    }
49145 */
49146    *fftyp = 7;
49147    cell->ichx = 0;
49148 
49149 #if defined(VMS) || defined(UNDERSC)
49150    dotyp(&cell->ichx);
49151 #else
49152 #ifdef CRAY
49153    DOTYP(&cell->ichx);
49154 #else
49155    dotyp_(&cell->ichx);
49156 #endif
49157 #endif
49158 
49159    tnk_single = 1;
49160    for (j=0; j<nresrot; j++) {
49161 	showresrot(j);
49162 	sprintf(wfile, "rescore%03d",j);
49163 	cpstr(wfile,tnkjn,SUBLEN1);
49164 #if defined(VMS) || defined(UNDERSC)
49165 	wrtsng();
49166 #else
49167 #ifdef CRAY
49168 	WRTSNG();
49169 #else
49170 	wrtsng_();
49171 #endif
49172 #endif
49173 	*tnkprg = 0;
49174 	doamb(wfile);
49175 	resrot[j].etot = newen;
49176    }
49177    tnk_single = 0;
49178    for (j=0; j<nresrot; j++) flxen[j] = resrot[j].etot;
49179 #ifdef DOGL
49180    for (j=0; j<resrot[0].ndrs; j++) ogres(resrot[0].idrs[j],1,0);
49181    dispsf();
49182 #endif
49183    RedrawList(&flxlist);
49184 }
49185 
SaveResrot()49186 void SaveResrot()
49187 {
49188    int i,j, istat;
49189    char wfile[500];
49190    FILE *out;
49191 
49192    istat = 18;
49193    strcpy(wfile,"resrot");
49194 
49195    out = fopen(wfile,"w");
49196    if (out != NULL) {
49197 	fprintf(out,"%d %d\n",nresrot,resrot[0].ndrs);
49198 	for (i=0; i<nresrot; i++) {
49199 	   fprintf(out,"ResRot %d etot %8.3f\n",i,resrot[i].etot);
49200 	   for (j=0; j<resrot[0].ndrs; j++) {
49201 		fprintf(out,"%d %d\n",
49202 		resrot[i].idrs[j],resrot[i].rot[j]);
49203 	   }
49204 	}
49205 	fclose(out);
49206 
49207 #if defined(VMS) || defined(UNDERSC)
49208 	messg(&istat);
49209 #else
49210 #ifdef CRAY
49211 	MESSG(&istat);
49212 #else
49213 	messg_(&istat);
49214 #endif
49215 #endif
49216    }
49217 }
49218 
LoadResrot()49219 void LoadResrot()
49220 {
49221    int i,itmp,j, istat;
49222    double etmp;
49223    char wfile[500];
49224    char stmp1[6];
49225    char stmp2[4];
49226    char stmp3[8];
49227    FILE *out;
49228 
49229    istat = 19;
49230    strcpy(wfile,"resrot");
49231 
49232    out = fopen(wfile,"r");
49233    if (out != NULL) {
49234 	fscanf(out,"%d %d",&nresrot,&resrot[0].ndrs);
49235         fprintf(stderr,"nresrot %d ndrs %d\n",nresrot,resrot[0].ndrs);
49236 	for (i=0; i<nresrot; i++) {
49237 	   resrot[i].ndrs = resrot[0].ndrs;
49238 	   fscanf(out,"%6s %d %4s %8s",stmp1,&itmp,stmp2,stmp3);
49239 	   sscanf(stmp3,"%lf",&etmp);
49240            resrot[i].etot = etmp;
49241 	   for (j=0; j<resrot[0].ndrs; j++) {
49242 		fscanf(out,"%d %d\n",
49243 		&resrot[i].idrs[j],&resrot[i].rot[j]);
49244 	   }
49245 	}
49246 	fclose(out);
49247 	for (j=0; j<nresrot; j++) flxen[j] = resrot[j].etot;
49248 	for (j=0; j<resrot[0].ndrs; j++) {
49249 	   for (i=0; i < *xyzp->iatoms; i++) {
49250 		if (xyzp->iresid[i] == resrot[0].idrs[j]) xyzp->iatclr[i] = 1;
49251 	   }
49252 #ifdef DOGL
49253 	   ogres(resrot[0].idrs[j],1,0);
49254 #endif
49255 	}
49256 #ifdef DOGL
49257 	dispsf();
49258 #endif
49259 	RedrawList(&flxlist);
49260 
49261    } else {
49262 
49263 #if defined(VMS) || defined(UNDERSC)
49264 	messg(&istat);
49265 #else
49266 #ifdef CRAY
49267 	MESSG(&istat);
49268 #else
49269 	messg_(&istat);
49270 #endif
49271 #endif
49272    }
49273 }
49274 
initflx()49275 void initflx()
49276 {
49277   if (FLXup) return;
49278 
49279 #if defined(VMS) || defined(UNDERSC)
49280    dfipar();
49281 #else
49282 #ifdef CRAY
49283    DFIPAR();
49284 #else
49285    dfipar_();
49286 #endif
49287 #endif
49288 
49289   FLXup = 1;
49290   pmfrot->ndrs = 0;
49291   FLXwin = CreateWindow("Scan Rotamer Space","-0+0",FLXWINW,FLXWINH,
49292 	 		 infobg,infofg,(Window)0);
49293   XSelectInput(display, FLXwin,
49294 	ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask |
49295 	ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
49296 
49297   XMapWindow(display,FLXwin);
49298 
49299   WinObj[32].win = &FLXwin;
49300   WinObj[32].subwin = NULL;
49301   WinObj[32].butarr = flxbut;
49302   WinObj[32].numbut = 9;
49303   WinObj[32].winup = &FLXup;
49304   WinObj[32].redraw = RedrawFLX;
49305 
49306   DefBut(&flxbut[0], FLXwin, 30, 10, 140, 23,
49307 	"Scan Rotamer Space", infobg, -15);
49308   DefBut(&flxbut[2], FLXwin, 180, 10, 120, 23,
49309 	"Clear Flex. Res.", infobg, -15);
49310   DefBut(&flxbut[1], FLXwin,  30, 215, 60, 23,
49311 	"Close", infobg, -15);
49312   DefBut(&flxbut[3], FLXwin,  30, 185, 60, 23,
49313 	"Save", infobg, -15);
49314   DefBut(&flxbut[4], FLXwin, 120, 185, 60, 23,
49315 	"Load", infobg, -15);
49316   DefBut(&flxbut[5], FLXwin,  30, 155, 60, 23,
49317 	"Rescore", infobg, -15);
49318   DefBut(&flxbut[6], FLXwin, 120, 155, 60, 23,
49319 	"Sort", infobg, -15);
49320   DefBut(&flxbut[7], FLXwin, 30, 130, 20, 20,
49321 	" ", infobg, -15);
49322   DefBut(&flxbut[8], FLXwin, 180, 130, 20, 20,
49323 	" ", infobg, -15);
49324   DefList(&flxlist,FLXwin,DIRX,DIRY,DIRW,80,
49325 	NULL,5,NULL,NULL,flxen,NULL,&nresrot,NULL);
49326 
49327   if (*idoh) TogDown(&flxbut[7]);
49328   else TogUp(&flxbut[7]);
49329 
49330 }
49331 
RedrawFLX()49332 void RedrawFLX()
49333 {
49334    int i;
49335 
49336    if (!FLXup) return;
49337 
49338    butje(FLXwin,0,0,FLXWINW,FLXWINH,4,0,0,1,None,0,0,0);
49339 
49340    for (i=0; i < 9; i++) DrwBut(&flxbut[i]);
49341 
49342    LineString(FLXwin, "Include H...H Pot.", 60, 145);
49343    LineString(FLXwin, "Show Opt.", 200, 145);
49344 
49345    RedrawList(&flxlist);
49346 
49347 }
49348 
ButtonsFLX(i)49349 int ButtonsFLX(i)
49350 int i;
49351 {
49352    int j,k,l;
49353 
49354    switch(i) {
49355    case 0:
49356 	opt3rot();
49357 	RedrawList(&flxlist);
49358 	break;
49359    case 1:
49360 	DeAllocRot();
49361 	update_model = 0;
49362 	pmfrot->ndrs = 0;
49363 	XDestroyWindow(display,FLXwin);FLXup = 0;
49364 	break;
49365    case 2:
49366 	nresrot = 0;
49367 #if defined(VMS) || defined(UNDERSC)
49368         chkbck(&ZERO);
49369 #else
49370 #ifdef CRAY
49371 	CHKBCK(&ZERO);
49372 #else
49373 	chkbck_(&ZERO);
49374 #endif
49375 #endif
49376 	for (l=0; l<resrot[0].ndrs; l++) {
49377 	   for (i=0; i < *xyzp->iatoms; i++) {
49378 		if (xyzp->iresid[i] == resrot[0].idrs[l]) {
49379 		   xyzp->iatclr[i] = 12;
49380 		}
49381 	   }
49382 #ifdef DOGL
49383 	   ogres(resrot[0].idrs[l],1,0);
49384 #endif
49385 	}
49386 	resrot[0].ndrs = 0;
49387 	pmfrot->ndrs = 0;
49388 	update_model = 0;
49389 #ifdef DOGL
49390 	dispsf();
49391 #endif
49392 	RedrawList(&flxlist);
49393 	break;
49394    case 3:
49395 	SaveResrot();
49396 	break;
49397    case 4:
49398 	LoadResrot();
49399 	break;
49400    case 5:
49401 	RescoreResrot();
49402 	break;
49403    case 6:
49404 	qsort((RESROTSTRU *) resrot, nresrot, sizeof(RESROTSTRU), cmprot);
49405 	for (j=0; j<nresrot; j++) flxen[j] = resrot[j].etot;
49406 	RedrawList(&flxlist);
49407 	break;
49408    case 7:
49409 	if (*idoh) {
49410 	   *idoh = 0;
49411 	   TogUp(&flxbut[7]);
49412 	} else {
49413 	   *idoh = 1;
49414 	   TogDown(&flxbut[7]);
49415 	}
49416 	break;
49417    case 8:
49418 	if (vis) {
49419 	   vis = 0;
49420 	   TogUp(&flxbut[8]);
49421 	} else {
49422 	   vis = 1;
49423 	   TogDown(&flxbut[8]);
49424 	}
49425 	break;
49426    }
49427 }
49428 
InitPar()49429 void InitPar()
49430 {
49431   PARup = 1;
49432   PARwin = CreateWindow("H-bond parameters","-0+0",PARWINW,PARWINH,
49433 	 		 infobg,infofg,(Window)0);
49434   XSelectInput(display, PARwin,
49435 	ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask |
49436 	ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
49437 
49438   XMapWindow(display,PARwin);
49439 
49440   WinObj[33].win = &PARwin;
49441   WinObj[33].subwin = NULL;
49442   WinObj[33].butarr = parbut;
49443   WinObj[33].numbut = 3;
49444   WinObj[33].winup = &PARup;
49445   WinObj[33].redraw = RedrawPAR;
49446 
49447   DefBut(&parbut[0], PARwin, 25, 210, 70, 23,
49448 	"Close", infobg, -15);
49449 
49450   DefBut(&parbut[1], PARwin, 25, 180, 200, 23,
49451 	"Recalculate H-bonds", infobg, -15);
49452 
49453   DefBut(&parbut[2], PARwin, 230, 180, 60, 23,
49454 	"Reset", infobg, -15);
49455 
49456    qboxstr(&qboxes[QHBMIN],&PARwin,0,0,190,30,15+0*QBOXHIGH,
49457 	255,QBOXHIGH,2,"Min. H-bond distance   (Ang):"," ",
49458 	SUBLEN2,QPOSREAL,2000,-1,
49459 	dummyproc);
49460 
49461    qboxstr(&qboxes[QHBMAX],&PARwin,0,0,190,30,15+1*QBOXHIGH,
49462 	255,QBOXHIGH,2,"Max. H-bond distance   (Ang):"," ",
49463 	SUBLEN2,QPOSREAL,2000,-1,
49464 	dummyproc);
49465 
49466    qboxstr(&qboxes[QHAMIN],&PARwin,0,0,190,30,15+2*QBOXHIGH,
49467 	255,QBOXHIGH,2,"Min. angle Donor-H..Acc(Deg):"," ",
49468 	SUBLEN2,QPOSREAL,2000,-1,
49469 	dummyproc);
49470 
49471    qboxstr(&qboxes[QHAMAX],&PARwin,0,0,190,30,15+3*QBOXHIGH,
49472 	255,QBOXHIGH,2,"Max. angle Donor-H..Acc(Deg):"," ",
49473 	SUBLEN2,QPOSREAL,2000,-1,
49474 	dummyproc);
49475 
49476    sprintf(qboxes[QHBMIN].str,"%f",hbpars->hdmin*toangs);
49477    sprintf(qboxes[QHBMAX].str,"%f",hbpars->hdmax*toangs);
49478    sprintf(qboxes[QHAMIN].str,"%f",hbpars->hamin);
49479    sprintf(qboxes[QHAMAX].str,"%f",hbpars->hamax);
49480 
49481    qboxes[QHBMIN].curpos = strlen(qboxes[QHBMIN].str);
49482    qboxes[QHBMAX].curpos = strlen(qboxes[QHBMAX].str);
49483    qboxes[QHAMIN].curpos = strlen(qboxes[QHAMIN].str);
49484    qboxes[QHAMAX].curpos = strlen(qboxes[QHAMAX].str);
49485 
49486    qboxes[QHBMIN].active = 1;
49487    qboxes[QHBMAX].active = 0;
49488    qboxes[QHAMIN].active = 0;
49489    qboxes[QHAMAX].active = 0;
49490 }
49491 
RedrawPAR()49492 void RedrawPAR()
49493 {
49494    int i;
49495 
49496    if (!PARup) return;
49497 
49498    butje(PARwin,0,0,PARWINW,PARWINH,4,0,0,1,None,0,0,0);
49499 
49500    for (i=0; i < 3; i++) DrwBut(&parbut[i]);
49501 
49502    PromptBox(&qboxes[QHBMIN]);
49503    PromptBox(&qboxes[QHBMAX]);
49504    PromptBox(&qboxes[QHAMIN]);
49505    PromptBox(&qboxes[QHAMAX]);
49506 }
49507 
ButtonsPAR(i)49508 int ButtonsPAR(i)
49509 int i;
49510 {
49511 
49512    switch(i) {
49513    case 0:
49514 	update_model = 0;
49515 	hbpars->hdmin = atof(qboxes[QHBMIN].str)/toangs;
49516 	hbpars->hdmax = atof(qboxes[QHBMAX].str)/toangs;
49517 	hbpars->hamin = atof(qboxes[QHAMIN].str);
49518 	hbpars->hamax = atof(qboxes[QHAMAX].str);
49519 	XDestroyWindow(display,PARwin);PARup = 0;
49520 	break;
49521    case 1:
49522 	update_model = 1;
49523 	hbpars->hdmin = atof(qboxes[QHBMIN].str)/toangs;
49524 	hbpars->hdmax = atof(qboxes[QHBMAX].str)/toangs;
49525 	hbpars->hamin = atof(qboxes[QHAMIN].str);
49526 	hbpars->hamax = atof(qboxes[QHAMAX].str);
49527 #if defined(VMS) || defined(UNDERSC)
49528 	nohcon();
49529 	dohcon(&ZERO);
49530 #else
49531 #ifdef CRAY
49532 	NOHCON();
49533 	DOHCON(&ZERO);
49534 #else
49535 	nohcon_();
49536 	dohcon_(&ZERO);
49537 #endif
49538 #endif
49539 	update_struct();
49540 	return(1);
49541 	break;
49542    case 2:
49543 	hbpars->hdmin = 1.50/toangs;
49544 	hbpars->hdmax = 3.15/toangs;
49545 	hbpars->hamin = 145.0;
49546 	hbpars->hamax = 215.0;
49547 	sprintf(qboxes[QHBMIN].str,"%f",hbpars->hdmin*toangs);
49548 	sprintf(qboxes[QHBMAX].str,"%f",hbpars->hdmax*toangs);
49549 	sprintf(qboxes[QHAMIN].str,"%f",hbpars->hamin);
49550 	sprintf(qboxes[QHAMAX].str,"%f",hbpars->hamax);
49551 	qboxes[QHBMIN].curpos = strlen(qboxes[QHBMIN].str);
49552 	qboxes[QHBMAX].curpos = strlen(qboxes[QHBMAX].str);
49553 	qboxes[QHAMIN].curpos = strlen(qboxes[QHAMIN].str);
49554 	qboxes[QHAMAX].curpos = strlen(qboxes[QHAMAX].str);
49555 	PromptBox(&qboxes[QHBMIN]);
49556 	PromptBox(&qboxes[QHBMAX]);
49557 	PromptBox(&qboxes[QHAMIN]);
49558 	PromptBox(&qboxes[QHAMAX]);
49559 	break;
49560    }
49561    return(0);
49562 }
49563 
UpdateSTRC()49564 void UpdateSTRC()
49565 {
49566    int i;
49567 
49568    if (!STRCup) return;
49569 
49570    DefList(&strclist,STRCwin,STRX,20,STRW,80,
49571 	NULL,5,sndstr[istruct],NULL,NULL,SSon[istruct],&NSurf[istruct],NULL);
49572 
49573 }
49574 
inistrc()49575 void inistrc()
49576 {
49577   int j,tel,act;
49578   if (!xison) return;
49579 
49580   STRCup = 1;
49581   STRCwin = CreateWindow("Surfaces","-100+525",STRWINW,STRWINH+BUTTN+5,
49582 	 		 infobg,infofg,(Window)0);
49583   subSTRC = CreateWindow("Subwindow","",10,10,
49584                             colors[0],colors[15],STRCwin);
49585   XSelectInput(display, STRCwin,
49586 	SubstructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask | PointerMotionMask | EnterWindowMask);
49587 
49588   XMapWindow(display,STRCwin);
49589 
49590   WinObj[36].win = &STRCwin;
49591   WinObj[36].subwin = &subSTRC;
49592   WinObj[36].butarr = strcbut;
49593   WinObj[36].numbut = STRCBN;
49594   WinObj[36].winup = &STRCup;
49595   WinObj[36].redraw = RedrawSTRC;
49596 
49597   DefBut(&strcbut[0], STRCwin, STRX, 110, 90, 23,
49598 	"Set Color", infobg, -15);
49599   strcbut[0].explstr = "Set Surface Color";
49600 
49601   DefBut(&strcbut[1], STRCwin, STRX+120, 115, 15, 15,
49602 	" ", infobg, -15);
49603   strcbut[1].explstr = "Render surfaces transparent";
49604 
49605   DefBut(&strcbut[2], STRCwin, STRX+120, 115+BUTTH, 15, 15,
49606 	" ", infobg, -15);
49607   strcbut[2].explstr = "Render surfaces as lines";
49608 
49609   DefBut(&strcbut[3], STRCwin, STRX, 110+2*BUTTN, 90, 23,
49610 	"Delete Active", infobg, -15);
49611   strcbut[3].explstr = "Delete Active Surface";
49612 
49613   DefBut(&strcbut[4], STRCwin, STRX, 110+4*BUTTN, 50, 23,
49614 	"Helix", infobg, -15);
49615   strcbut[4].explstr = "activate Helix";
49616 
49617   DefBut(&strcbut[5], STRCwin, STRX+60, 110+4*BUTTN, 50, 23,
49618 	"Beta", infobg, -15);
49619   strcbut[5].explstr = "activate Beta sheet";
49620 
49621   DefBut(&strcbut[6], STRCwin, STRX+2*60, 110+4*BUTTN, 50, 23,
49622 	"RNA", infobg, -15);
49623   strcbut[6].explstr = "activate RNA/DNA";
49624 
49625   DefBut(&strcbut[7], STRCwin, STRX+3*60, 110+4*BUTTN, 50, 23,
49626 	"Coil", infobg, -15);
49627   strcbut[7].explstr = "activate Coil";
49628 
49629   DefBut(&strcbut[8], STRCwin, STRX, 110+5*BUTTN, 75, 23,
49630 	"Activ. All", infobg, -15);
49631   strcbut[8].explstr = "Activate All surfaces";
49632 
49633   DefBut(&strcbut[9], STRCwin, STRX+80, 110+5*BUTTN, 90, 23,
49634 	"Deactiv. All", infobg, -15);
49635   strcbut[9].explstr = "Deactivate All surfaces";
49636 
49637   DefBut(&strcbut[12], STRCwin, STRX+180, 110+5*BUTTN, 45, 23,
49638 	"Invert", infobg, -15);
49639   strcbut[12].explstr = "Invert Activations";
49640 
49641   DefBut(&strcbut[11], STRCwin, STRX+120, 115+6*BUTTN, 70, 23,
49642 	"Write All", infobg, -15);
49643   strcbut[11].explstr = "Write all surfaces to molden.ogl";
49644 
49645   DefBut(&strcbut[10], STRCwin, STRX, 115+6*BUTTN, 60, 23,
49646 	"Close", infobg, -15);
49647   strcbut[10].explstr = "Close window";
49648 
49649   DefBut(&strcbut[13], STRCwin, STRX, 110+BUTTN, 60, 23,
49650 	"Clip", infobg, -15);
49651   strcbut[13].explstr = "Clip Surface";
49652 
49653   tel = 0;
49654   act = -1;
49655   for (j=0; j<MAXSURF; j++) {
49656 	if (SSon[istruct][j]) {
49657 	   tel++; act = j;
49658 	}
49659   }
49660 
49661   if (tel == 1) {
49662      if (trns[istruct][act]) {
49663 	   TogDown(&strcbut[1]);
49664 	   TRANSb = 1;
49665      } else {
49666 	   TogUp(&strcbut[1]);
49667 	   TRANSb = 0;
49668      }
49669   }
49670 
49671   if (DoLines) {
49672 	TogDown(&strcbut[2]);
49673   } else {
49674 	TogUp(&strcbut[2]);
49675   }
49676 
49677   if (denmode) {
49678 	ActBut(&strcbut[4],2);
49679 	ActBut(&strcbut[5],2);
49680 	ActBut(&strcbut[6],2);
49681 	ActBut(&strcbut[7],2);
49682   }
49683 
49684   UpdateSTRC();
49685 
49686 }
49687 
RedrawSTRC()49688 void RedrawSTRC()
49689 {
49690    int i,j,tel,act;
49691 
49692    if (!STRCup) return;
49693 
49694    butje(STRCwin,0,0,STRWINW,STRWINH+BUTTN+5,4,0,0,1,None,0,0,0);
49695 
49696    for (i=0; i < STRCBN; i++) DrwBut(&strcbut[i]);
49697 
49698    tel = 0;
49699    act = -1;
49700    for (j=0; j<MAXSURF; j++) {
49701 	if (SSon[istruct][j]) {
49702 	   tel++; act = j;
49703 	}
49704    }
49705 
49706    if (tel == 1) {
49707      if (trns[istruct][act]) {
49708 	   TogDown(&strcbut[1]);
49709 	   TRANSb = 1;
49710      } else {
49711 	   TogUp(&strcbut[1]);
49712 	   TRANSb = 0;
49713      }
49714    }
49715 
49716    LineString(STRCwin, "Transparent", STRX+140,128);
49717    LineString(STRCwin, "Lines", STRX+140,128+BUTTH);
49718    ULineString(STRCwin, "Activate:", STRX,128+3*BUTTN);
49719 
49720    RedrawList(&strclist);
49721 
49722 }
49723 
ButtonsSTRC(i)49724 int ButtonsSTRC(i)
49725 int i;
49726 {
49727    LSSTRU List; int j,k,nsrf;
49728 
49729    switch(i) {
49730    case 0:
49731 	if (DoPopUp(STRCwin,
49732 	   strcbut[0].x,strcbut[0].y-100, NULL,&j,0) == -1) break;
49733 	for (k=0; k < NSurf[istruct]; k++)
49734 	   if (SSon[istruct][k]) SetSurfColor(k,j);
49735 	break;
49736    case 1:
49737 	TRANSb = ! TogBut(&strcbut[1]);
49738 	for (j=0; j < NSurf[istruct]; j++)
49739 	   if (SSon[istruct][j]) trns[istruct][j] = TRANSb;
49740 	break;
49741    case 2:
49742 	DoLines = ! TogBut(&strcbut[2]);
49743 	break;
49744    case 3:
49745 	DeleteActiveSurfaces();
49746 	break;
49747    case 4:
49748 	for (j=RIBindex[istruct].start[0];
49749 		j <= RIBindex[istruct].end[0]; j++) {
49750 		if (j == -1) break;
49751 		SSon[istruct][j] = 1;
49752 	}
49753 	break;
49754    case 5:
49755 	for (j=RIBindex[istruct].start[1];
49756 		j <= RIBindex[istruct].end[1]; j++) {
49757 		if (j == -1) break;
49758 		SSon[istruct][j] = 1;
49759 	}
49760 	break;
49761    case 6:
49762 	for (j=RIBindex[istruct].start[2];
49763 		j <= RIBindex[istruct].end[2]; j++) {
49764 		if (j == -1) break;
49765 		SSon[istruct][j] = 1;
49766 	}
49767 	break;
49768    case 7:
49769 	for (j=RIBindex[istruct].start[3];
49770 		j <= RIBindex[istruct].end[3]; j++) {
49771 		if (j == -1) break;
49772 		SSon[istruct][j] = 1;
49773 	}
49774 	break;
49775    case 8:
49776 	for (j=0; j < NSurf[istruct]; j++) SSon[istruct][j] = 1;
49777 	break;
49778    case 9:
49779 	for (j=0; j < NSurf[istruct]; j++) SSon[istruct][j] = 0;
49780 	break;
49781    case 10:
49782 	XDestroyWindow(display,STRCwin);STRCup = 0;
49783 	return(0);
49784 	break;
49785    case 11:
49786 #if defined(VMS) || defined(UNDERSC)
49787 	curs(&ONE);
49788 	wrtall();
49789 	curs(&ZERO);
49790 #else
49791 #ifdef CRAY
49792 	CURS(&ONE);
49793 	wrtall();
49794 	CURS(&ZERO);
49795 #else
49796 	curs_(&ONE);
49797 	wrtall();
49798 	curs_(&ZERO);
49799 #endif
49800 #endif
49801 	strcpy(molwstr,"Wrote file molden.ogl");
49802 	StatusStr(0,0);
49803 	break;
49804    case 12:
49805 	for (j=0; j < NSurf[istruct]; j++) {
49806 	   if (SSon[istruct][j]) {
49807 		SSon[istruct][j] = 0;
49808 	   } else {
49809 		SSon[istruct][j] = 1;
49810 	   }
49811 	}
49812 	break;
49813    case 13:
49814 	IniOmap();
49815 	break;
49816    }
49817 
49818    dispsf();
49819    RedrawSTRC();
49820    return(0);
49821 }
49822 
iniselh()49823 void iniselh()
49824 {
49825   int j,tel,act;
49826   if (!xison) return;
49827 
49828   SELHup = 1;
49829   SELHwin = CreateWindow("Optimize Hydrogens","-100+525",
49830 		SELHWINW,SELHWINH+20, infobg,infofg,(Window)0);
49831   subSELH = CreateWindow("Subwindow","",10,10,
49832                             colors[0],colors[15],SELHwin);
49833   XSelectInput(display, SELHwin,
49834 	SubstructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask | PointerMotionMask | EnterWindowMask);
49835 
49836   XMapWindow(display,SELHwin);
49837 
49838   WinObj[40].win = &SELHwin;
49839   WinObj[40].subwin = &subSELH;
49840   WinObj[40].butarr = selhbut;
49841   WinObj[40].numbut = SELHBN;
49842   WinObj[40].winup = &SELHup;
49843   WinObj[40].redraw = RedrawSELH;
49844 
49845   DefBut(&selhbut[0], SELHwin, STRX+10, 20, 15, 15,
49846 	" ", infobg, -15);
49847   selhbut[0].explstr = "Add hydrogens to hetatm's";
49848 
49849   DefBut(&selhbut[1], SELHwin, STRX+10, 20+BUTTH, 15, 15,
49850 	" ", infobg, -15);
49851   selhbut[1].explstr = "Complete incomplete Residues";
49852 
49853   DefBut(&selhbut[2], SELHwin, STRX+10, 20+2*BUTTH, 15, 15,
49854 	" ", infobg, -15);
49855   selhbut[2].explstr = "Flip GLN/ASN residues";
49856 
49857   DefBut(&selhbut[3], SELHwin, STRX+10, 20+3*BUTTH, 15, 15,
49858 	" ", infobg, -15);
49859   selhbut[3].explstr = "For histidines choose HID or HIE";
49860 
49861   DefBut(&selhbut[4], SELHwin, STRX+10, 20+4*BUTTH, 15, 15,
49862 	" ", infobg, -15);
49863   selhbut[4].explstr = "Optimise OH and SH orientations";
49864 
49865   DefBut(&selhbut[5], SELHwin, STRX+10, 20+5*BUTTH, 15, 15,
49866 	" ", infobg, -15);
49867   selhbut[5].explstr = "Add Hydrogens to waters";
49868 
49869   DefBut(&selhbut[6], SELHwin, STRX+10, 20+6*BUTTN, 60, 23,
49870 	"Optimise", infobg, -15);
49871   selhbut[6].explstr = "Optimise Hydrogens";
49872 
49873   HLIG = 1;
49874   TogDown(&selhbut[0]);
49875 
49876   HINC = 1;
49877   TogDown(&selhbut[1]);
49878 
49879   HFLP = 1;
49880   TogDown(&selhbut[2]);
49881 
49882   HHIS = 1;
49883   TogDown(&selhbut[3]);
49884 
49885   HRES = 1;
49886   TogDown(&selhbut[4]);
49887 
49888   HWAT = 1;
49889   TogDown(&selhbut[5]);
49890 
49891 }
49892 
RedrawSELH()49893 void RedrawSELH()
49894 {
49895    int i,j,tel,act;
49896 
49897    if (!SELHup) return;
49898 
49899    butje(SELHwin,0,0,SELHWINW,SELHWINH+20,4,0,0,1,None,0,0,0);
49900 
49901    for (i=0; i < SELHBN; i++) DrwBut(&selhbut[i]);
49902 
49903    LineString(SELHwin, "Add hydrogens to ligands", STRX+30,33);
49904    LineString(SELHwin, "Complete Residues", STRX+30,33+BUTTH);
49905    LineString(SELHwin, "Flip ASN/GLN", STRX+30,33+2*BUTTH);
49906    LineString(SELHwin, "Choose HISTIDINE: HID or HIE",
49907 					STRX+30,33+3*BUTTH);
49908    LineString(SELHwin, "Optimise OH and SH positions",
49909 					STRX+30,33+4*BUTTH);
49910    LineString(SELHwin, "Add Hydrogens to relevant waters ",
49911 					STRX+30,33+5*BUTTH);
49912 
49913 }
49914 
ButtonsSELH(i)49915 int ButtonsSELH(i)
49916 int i;
49917 {
49918    int j,k;
49919 
49920    switch(i) {
49921    case 0:
49922 	HLIG = ! TogBut(&selhbut[0]);
49923 	break;
49924    case 1:
49925 	HINC = ! TogBut(&selhbut[1]);
49926 	break;
49927    case 2:
49928 	HFLP = ! TogBut(&selhbut[2]);
49929 	break;
49930    case 3:
49931 	HHIS = ! TogBut(&selhbut[3]);
49932 	break;
49933    case 4:
49934 	HRES = ! TogBut(&selhbut[4]);
49935 	break;
49936    case 5:
49937 	HWAT = ! TogBut(&selhbut[5]);
49938 	break;
49939    case 6:
49940 	XDestroyWindow(display,SELHwin);SELHup = 0;
49941 #if defined(VMS) || defined(UNDERSC)
49942 	curs(&ONE);
49943 	opthyd();
49944 	curs(&ZERO);
49945 #else
49946 #ifdef CRAY
49947 	CURS(&ONE);
49948 	OPTHYD();
49949 	CURS(&ZERO);
49950 #else
49951 	curs_(&ONE);
49952 	opthyd_();
49953 	curs_(&ZERO);
49954 #endif
49955 #endif
49956 	return(0);
49957 	break;
49958    }
49959 
49960    dispsf();
49961    return(0);
49962 }
49963 
InitSRCH(x,y)49964 void InitSRCH(x,y)
49965 int x,y;
49966 {
49967    char wgeom[64];
49968 
49969    SRCHup = 1;
49970 
49971    sprintf(wgeom,"+%d+%d",x,y);
49972 
49973    SRCHwin = CreateWindow("Search PDB Window",wgeom,SRCHWINW,SRCHWINH,
49974 	 		 infobg,infofg,(Window)0);
49975    subSRCH = CreateWindow("Subwindow","",10,10,
49976                             colors[0],colors[15],SRCHwin);
49977    XSelectInput(display, SRCHwin, KeyPressMask | ExposureMask | ButtonPressMask
49978 	| ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask |
49979 	SubstructureNotifyMask | PointerMotionMask | EnterWindowMask);
49980    XMapWindow(display,SRCHwin);
49981 
49982    WinObj[41].win = &SRCHwin;
49983    WinObj[41].subwin = &subSRCH;
49984    WinObj[41].butarr = butSRCH;
49985    WinObj[41].numbut = SRCHBN;
49986    WinObj[41].winup = &SRCHup;
49987    WinObj[41].redraw = RedrawSRCH;
49988 
49989    DefBut(&butSRCH[0],SRCHwin, 42, 7, 80, 23, "Search PDB", infobg, ZMBCOL);
49990    butSRCH[0].explstr = "Search PDB with the entered keywords";
49991 
49992    DefBut(&butSRCH[1],SRCHwin, 10, 35+QBOXHIGH+110+110, 100, 23,
49993 	"Load PDB code", infobg, ZMBCOL);
49994    butSRCH[1].explstr = "Load structure of selected PDB code";
49995 
49996    DefBut(&butSRCH[2], SRCHwin, 10, 35+QBOXHIGH+110+110+BUTTN, 70, 23,
49997 	"Close", infobg, ZMBCOL);
49998    butSRCH[2].explstr = "Close this window";
49999 
50000    qboxstr(&qboxes[QSRCH],&SRCHwin,1,0,190,10,35,
50001 	275,QBOXHIGH,2,"Query","",25,QSTRING,2000,-1,srccallb);
50002    qboxes[QSRCH].explstr = "Search string to query the PDB";
50003 
50004    DefList(&srchlist,SRCHwin,6,35+QBOXHIGH+20,SRCHWINW-37,110,
50005 	NULL,9,pdbres,NULL,NULL,NULL,&npdbres,NULL);
50006 
50007 
50008 }
50009 
50010 #define MXPDBL 40
RedrawSRCH()50011 void RedrawSRCH()
50012 {
50013   int i,l;
50014   char tmpstr[MXPDBL+7];
50015   char *sptr = NULL;
50016 
50017   sprintf(stemp,"Matching PDB codes (%d):",npdbres);
50018   butje(SRCHwin,0,0,SRCHWINW,SRCHWINH,4,0,0,1,None,0,0,0);
50019   ULineString(SRCHwin,stemp,10, 43+QBOXHIGH);
50020   l = strlen(qrb_title);
50021   if (l > MXPDBL) {
50022 	i = 0;
50023 	sptr = qrb_title;
50024 	while (sptr < qrb_title + l) {
50025 	   if ((qrb_title+l)-sptr < MXPDBL) {
50026 		strcpy(tmpstr,"       ");
50027 		strcat(tmpstr,sptr);
50028 	   } else {
50029 		if (i == 0) {
50030 		   strcpy(tmpstr,"Title: ");
50031 		   strncat(tmpstr,sptr,MXPDBL);
50032 		} else {
50033 		   strcpy(tmpstr,"       ");
50034 		   strncat(tmpstr,sptr,MXPDBL);
50035 		}
50036 	   }
50037 	   LineString(SRCHwin,tmpstr,10, 43+QBOXHIGH+110+35+i*15);
50038 	   sptr += MXPDBL; i++;
50039 	}
50040   } else {
50041 	strcpy(tmpstr,"Title: ");
50042 	strcat(tmpstr,qrb_title);
50043 	LineString(SRCHwin,tmpstr,10, 43+QBOXHIGH+110+35);
50044   }
50045   sprintf(stemp,"Organism: %s",organism);
50046   LineString(SRCHwin,stemp,10, 43+QBOXHIGH+110+90);
50047 
50048   for (i=0; i<SRCHBN; i++) DrwBut(&butSRCH[i]);
50049 
50050   PromptBox(&qboxes[QSRCH]);
50051   RedrawList(&srchlist);
50052 }
50053 
ButtonsSRCH(i)50054 int ButtonsSRCH(i)
50055 int i;
50056 {
50057 
50058   switch (i) {
50059   case 0:
50060 	if (!CheckWGET()) {
50061 	   PDBquery(qboxes[QSRCH].str);
50062 	}
50063 	break;
50064   case 1:
50065 	if (!CheckWGET()) {
50066 	    GetPDBWWW(pdbres[srchlist.select],strname);
50067 	    if (ParseFile(strname,pdbres[srchlist.select])) return 1;
50068 	}
50069 	break;
50070   case 2:
50071 	XDestroyWindow(display,SRCHwin);
50072 	SRCHup = 0;
50073 	break;
50074   }
50075   return(0);
50076 }
50077 
InitANIM(x,y)50078 void InitANIM(x,y)
50079 int x,y;
50080 {
50081    char wgeom[64];
50082 
50083    ANIMup = 1;
50084 
50085    sprintf(wgeom,"+%d+%d",x,y);
50086 
50087    ANIMwin = CreateWindow("Animate Variable",wgeom,ANIMWINW,ANIMWINH,
50088 	 		 infobg,infofg,(Window)0);
50089    subANIM = CreateWindow("Subwindow","",10,10,
50090                             colors[0],colors[15],ANIMwin);
50091    XSelectInput(display, ANIMwin, ExposureMask | ButtonPressMask
50092 	| ButtonMotionMask | LeaveWindowMask |
50093 	SubstructureNotifyMask | PointerMotionMask | EnterWindowMask);
50094    XMapWindow(display,ANIMwin);
50095 
50096    WinObj[42].win = &ANIMwin;
50097    WinObj[42].subwin = &subANIM;
50098    WinObj[42].butarr = butANIM;
50099    WinObj[42].numbut = ANIMBN;
50100    WinObj[42].winup = &ANIMup;
50101    WinObj[42].redraw = RedrawANIM;
50102 
50103    DefBut(&butANIM[0],ANIMwin, 10, 7, 70, 23, "-1 frame", infobg, ZMBCOL);
50104    butANIM[0].explstr = "Move one frame backwards";
50105 
50106    DefBut(&butANIM[1],ANIMwin, 80, 7, 30, 23, "", infobg, ZMBCOL);
50107    butANIM[1].explstr = "Start/Stop animation of\nvariable";
50108 
50109    DefBut(&butANIM[2],ANIMwin, 110, 7, 70, 23, "+1 frame", infobg, ZMBCOL);
50110    butANIM[2].explstr = "Move one frame forwards";
50111 
50112    DefBut(&butANIM[3], ANIMwin, 10, 7+BUTTN, 170, 23,
50113 	"Take current value", infobg, ZMBCOL);
50114    butANIM[3].explstr = "Take current value and\nclose window";
50115 
50116    DefBut(&butANIM[4], ANIMwin, 10, 7+2*BUTTN, 170, 23,
50117 	"Rest. value and Close", infobg, ZMBCOL);
50118    butANIM[4].explstr = "Restore original value of the\nvariable and close this window";
50119 
50120    butANIM[1].pix = rPix;
50121    butANIM[1].pw  = r_width;
50122    butANIM[1].ph  = r_height;
50123 }
50124 
RedrawANIM()50125 void RedrawANIM()
50126 {
50127   int i;
50128 
50129   butje(ANIMwin,0,0,ANIMWINW,ANIMWINH,4,0,0,1,None,0,0,0);
50130 
50131   for (i=0; i<ANIMBN; i++) DrwBut(&butANIM[i]);
50132 
50133 }
50134 
ButtonsANIM(i)50135 int ButtonsANIM(i)
50136 int i;
50137 {
50138 
50139   switch (i) {
50140   case 0:
50141 	ANIMNXT = 0;
50142 	butANIM[1].pix = rPix;
50143 	DrwBut(&butANIM[1]);
50144 	animptr.vdirection = -1;
50145 	break;
50146   case 1:
50147 	if (ANIMNXT) {
50148 	   ANIMNXT = 0;
50149 	   butANIM[1].pix = rPix;
50150 	} else {
50151 	   ANIMNXT = 1;
50152 	   butANIM[1].pix = stopPix;
50153 	}
50154 	DrwBut(&butANIM[1]);
50155 	break;
50156   case 2:
50157 	ANIMNXT = 0;
50158 	butANIM[1].pix = rPix;
50159 	DrwBut(&butANIM[1]);
50160 	animptr.vdirection = 1;
50161 	break;
50162   case 3:
50163 	XDestroyWindow(display,ANIMwin);
50164 	ANIMup = 0;
50165 	animptr.varinit = *animptr.variable;
50166 	return(1);
50167 	break;
50168   case 4:
50169 	XDestroyWindow(display,ANIMwin);
50170 	ANIMup = 0;
50171 	return(1);
50172 	break;
50173   }
50174   return(0);
50175 }
50176 
inistr()50177 void inistr()
50178 {
50179   if (!xison) return;
50180 
50181   STRup = 1;
50182   STRwin = CreateWindow("Structures","-80+525",STRWINW,STRWINH,
50183 	 		 infobg,infofg,(Window)0);
50184   subSTR = CreateWindow("Subwindow","",10,10,
50185                             colors[0],colors[15],STRwin);
50186   XSelectInput(display, STRwin,
50187 	SubstructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask | PointerMotionMask | EnterWindowMask);
50188 
50189   XMapWindow(display,STRwin);
50190 
50191   WinObj[35].win = &STRwin;
50192   WinObj[35].subwin = &subSTR;
50193   WinObj[35].butarr = strbut;
50194   WinObj[35].numbut = 5;
50195   WinObj[35].winup = &STRup;
50196   WinObj[35].redraw = RedrawSTR;
50197 
50198   DefBut(&strbut[0], STRwin, STRX, 110, 90, 23,
50199 	"Delete Active", infobg, -15);
50200   strbut[0].explstr = "Delete the currently active\ndisplayed structure";
50201 
50202   DefBut(&strbut[1], STRwin, STRX+100, 110, 80, 23,
50203 	"Delete All", infobg, -15);
50204   strbut[1].explstr = "Delete all structures";
50205 
50206   DefBut(&strbut[2], STRwin, STRX, 80+STRSH, 60, 23,
50207 	"Combine", infobg, -15);
50208   strbut[2].explstr = "Add structure from the lower list\nto structure from the upper list";
50209 
50210   DefBut(&strbut[3], STRwin, STRX+70, 80+STRSH, 60, 23,
50211 	"Align", infobg, -15);
50212   strbut[3].explstr = "Align structure from the lower list\nto structure from the upper list";
50213 
50214   DefBut(&strbut[4], STRwin, STRX+140, 80+STRSH, 90, 23,
50215 	"Align+Combine", infobg, -15);
50216   strbut[4].explstr = "Align and add structure from the lower list\nto structure from the upper list";
50217 
50218   DefList(&strlist,STRwin,STRX,20,STRW,80,
50219 	NULL,5,strfiles,NULL,NULL,NULL,&nstruct,NULL);
50220   strlist.select = istruct;
50221   strlist.lpnt = 0;
50222   DefList(&str2list,STRwin,STRX,STRSH,STRW,65,
50223 	NULL,4,strfiles,NULL,NULL,NULL,&nstruct,NULL);
50224   str2list.select = 0;
50225   str2list.lpnt = 0;
50226 
50227 }
50228 
RedrawSTR()50229 void RedrawSTR()
50230 {
50231    int i;
50232 
50233    if (!STRup) return;
50234 
50235    butje(STRwin,0,0,STRWINW,STRWINH,4,0,0,1,None,0,0,0);
50236 
50237    for (i=0; i < 5; i++) DrwBut(&strbut[i]);
50238 
50239    RedrawList(&strlist);
50240    RedrawList(&str2list);
50241 
50242 }
50243 
ButtonsSTR(i)50244 int ButtonsSTR(i)
50245 int i;
50246 {
50247    LSSTRU List; int j;
50248 
50249    switch(i) {
50250    case 0:
50251 	DeleteOne();
50252 	break;
50253    case 1:
50254 	DeleteAll();
50255 	break;
50256    case 2:
50257 	if (str2list.select > 0 && strlist.select < nstruct)
50258 	   sstruct = str2list.select;
50259 	if (sstruct>0 && sstruct <= nstruct) {
50260 #if defined(VMS) || defined(UNDERSC)
50261 	   curs(&ONE);
50262 #else
50263 #ifdef CRAY
50264 	   CURS(&ONE);
50265 #else
50266 	   curs_(&ONE);
50267 #endif
50268 #endif
50269 	   CombineStructs(sstruct,1,1);
50270 	   update_model = 1;
50271 	   update_struct();
50272 #if defined(VMS) || defined(UNDERSC)
50273 	   curs(&ZERO);
50274 #else
50275 #ifdef CRAY
50276 	   CURS(&ZERO);
50277 #else
50278 	   curs_(&ZERO);
50279 #endif
50280 #endif
50281 	} else {
50282 	   if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
50283 		"Structure should be in the range\n 1 to # of structures",0)) {}
50284 	}
50285 	break;
50286    case 3:
50287 	if (str2list.select > 0 && strlist.select < nstruct)
50288 	   sstruct = str2list.select;
50289 	if (sstruct>0 && sstruct <= nstruct) {
50290 #if defined(VMS) || defined(UNDERSC)
50291 	   curs(&ONE);
50292 #else
50293 #ifdef CRAY
50294 	   CURS(&ONE);
50295 #else
50296 	   curs_(&ONE);
50297 #endif
50298 #endif
50299 	   AlignStructs(sstruct,0);
50300 	   update_model = 1;
50301 	   update_struct();
50302 #if defined(VMS) || defined(UNDERSC)
50303 	   curs(&ZERO);
50304 #else
50305 #ifdef CRAY
50306 	   CURS(&ZERO);
50307 #else
50308 	   curs_(&ZERO);
50309 #endif
50310 #endif
50311 	} else {
50312 	   if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
50313 		"Structure should be in the range\n 1 to # of structures",0)) {}
50314 	}
50315 	break;
50316    case 4:
50317 	if (str2list.select > 0 && strlist.select < nstruct)
50318 	   sstruct = str2list.select;
50319 	if (sstruct>0 && sstruct <= nstruct) {
50320 	   int pdb1,pdb2;
50321 
50322 	   pdb1    =  COO[istruct]->pdb;
50323 	   pdb2    =  COO[sstruct]->pdb;
50324 
50325 	   if ((pdb1 && pdb2) || (!pdb1 && !pdb2)) {
50326 #if defined(VMS) || defined(UNDERSC)
50327 		curs(&ONE);
50328 #else
50329 #ifdef CRAY
50330 		CURS(&ONE);
50331 #else
50332 		curs_(&ONE);
50333 #endif
50334 #endif
50335 		if (AlignStructs(sstruct,1)) CombineStructs(sstruct,0,1);
50336 		update_model = 1;
50337 		update_struct();
50338 #if defined(VMS) || defined(UNDERSC)
50339 		curs(&ZERO);
50340 #else
50341 #ifdef CRAY
50342 		CURS(&ZERO);
50343 #else
50344 		curs_(&ZERO);
50345 #endif
50346 #endif
50347 	   } else {
50348 	        if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
50349 		"You can not align a protein and a small molecule\nUse interactive docking under the alignment icon.",0))
50350 		break;
50351 	   }
50352 	} else {
50353 	   if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
50354 		"Structure should be in the range\n 1 to # of structures",0))
50355 		break;
50356 	}
50357 	break;
50358    }
50359    RedrawSTR();
50360    return(0);
50361 }
50362 
inichg(iopt)50363 void inichg(iopt)
50364 int iopt;
50365 {
50366   int i,ne = 0;
50367 
50368   if (!xison) return;
50369 
50370   CHGopt = iopt;
50371   CHGother = 0;
50372 
50373   if (iopt == 1) {
50374      for (i=0; i<*xyzp->iatoms; i++) {
50375 	if (xyzp->ianz[i] >= 0 && xyzp->ianz[i] < 99)
50376 	   ne = ne + xyzp->ianz[i];
50377      }
50378   } else {
50379      for (i=0; i<*xyzp->iatoms; i++) {
50380 	if (xyzp->iresid[i] == CHGopt)
50381 	   if (xyzp->ianz[i] >= 0 && xyzp->ianz[i] < 99)
50382 		ne = ne + xyzp->ianz[i];
50383      }
50384   }
50385 
50386   if (ne % 2) {
50387 	strcpy(chgtmp,"Hint: The neutral molecule has unpaired electrons");
50388   } else {
50389 	strcpy(chgtmp,"Hint: The neutral molecule has NO unpaired electrons");
50390   }
50391 
50392   CHGup = 1;
50393   CHGwin = CreateWindow("Select Total Charge","-200+200",CHGWINW,CHGWINH,
50394 	 		 infobg,infofg,(Window)0);
50395   XSelectInput(display, CHGwin,
50396 	ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask |
50397 	ButtonMotionMask | LeaveWindowMask | EnterWindowMask);
50398 
50399   XMapWindow(display,CHGwin);
50400 
50401   WinObj[34].win = &CHGwin;
50402   WinObj[34].subwin = NULL;
50403   WinObj[34].butarr = chgbut;
50404   WinObj[34].numbut = 3;
50405   WinObj[34].winup = &CHGup;
50406   WinObj[34].redraw = RedrawCHG;
50407 
50408   DefBut(&chgbut[0], CHGwin, 110, 20+BUTTN, 70, 23,
50409 	"Charge", infobg, -15);
50410 
50411   DefBut(&chgbut[1], CHGwin, 25, 35+3*BUTTN, 70, 23,
50412 	"Apply", infobg, -15);
50413 
50414   DefBut(&chgbut[2], CHGwin, 225, 20+BUTTN, 70, 23,
50415 	"Apply", infobg, -15);
50416 
50417   if (iopt == 1) {
50418      icopt = 3;
50419   } else {
50420      int aCHGopt;
50421 
50422      aCHGopt = abs(CHGopt);
50423 
50424      if (aCHGopt < MXHETA) {
50425 	if (!clfstrptr->ihqset[aCHGopt]) LigandQ(CHGopt);
50426 	if (clfstrptr->ihqset[aCHGopt]) {
50427 	   if (clfstrptr->ihetq[aCHGopt] < -3 ||
50428 		clfstrptr->ihetq[aCHGopt] > 3) {
50429 		icopt = 7;
50430 	   } else {
50431 		icopt = clfstrptr->ihetq[aCHGopt] + 3;
50432 	   }
50433 	} else {
50434 	   icopt = 3;
50435 	}
50436      } else {
50437 	icopt = 3;
50438      }
50439   }
50440 
50441   if (icopt > 7) {
50442 	chgbut[0].str = copt[7];
50443   } else {
50444 	chgbut[0].str = copt[icopt];
50445   }
50446   chgbut[2].str = eems[ieemopt];
50447 
50448   qboxstr(&qboxes[QCHRG2],&CHGwin,1,0,190,25,25+2*BUTTN,
50449 	150,QBOXHIGH,2,"Total Charge","",10,QREAL,2000,-1,dummyproc);
50450   qboxes[QCHRG2].explstr = "Partial charge of selected residue\n";
50451   qboxes[QCHRG2].active = 0;
50452 
50453 }
50454 
RedrawCHG()50455 void RedrawCHG()
50456 {
50457    int i;
50458 
50459    if (!CHGup) return;
50460 
50461    butje(CHGwin,0,0,CHGWINW,CHGWINH,4,0,0,1,None,0,0,0);
50462 
50463    for (i=0; i < 3; i++) DrwBut(&chgbut[i]);
50464 
50465    LineString(CHGwin, chgtmp, 25, 35);
50466    LineString(CHGwin, "Total Charge: ", 25, 35+BUTTN);
50467    if (CHGother) PromptBox(&qboxes[QCHRG2]);
50468 }
50469 
ButtonsCHG(i)50470 int ButtonsCHG(i)
50471 int i;
50472 {
50473    LSSTRU List;
50474 
50475    switch(i) {
50476    case 0:
50477 	List.list = copt; List.nents = 8;
50478 	if (DoPopUp(CHGwin,
50479 	        chgbut[0].x+35,chgbut[0].y-2*BUTTH,
50480 	        &List,&icopt,1) == -1) break;
50481 	if (icopt <= 6) {
50482 	   chgbut[0].str = copt[icopt];
50483 	   DrwBut(&chgbut[0]);
50484 	} else {
50485 	   CHGother = 1;
50486 	   qboxes[QCHRG2].active = 1;
50487 	   RedrawCHG();
50488 	}
50489 	return(0);
50490 	break;
50491    case 1:
50492 	XDestroyWindow(display,CHGwin);CHGup = 0;
50493 	*Sincp = ieemopt+1;
50494 	if (CHGother) {
50495 	   if (strlen(qboxes[QCHRG2].str) > 0) {
50496 		*itot = atoi(qboxes[QCHRG2].str);
50497 	   }
50498 	} else {
50499 	   *itot = icopt - 3;
50500 	}
50501 
50502 	if (CHGopt == 1) {
50503 	    LigandHydroQ(1,1,1,*itot);
50504 #ifdef DOGL
50505 	    if (*fancy) {
50506 		oghet(0);
50507 	    } else {
50508 		oglines();
50509 	    }
50510 	    update_model = 0;
50511 #else
50512 	    update_model = 1;
50513 #endif
50514 	    update_struct();
50515 
50516 	} else {
50517 	    int aCHGopt;
50518 
50519 	    aCHGopt = abs(CHGopt);
50520 
50521 	    if (aCHGopt < MXHETA) {
50522 		if (CHGother) {
50523 		   if (strlen(qboxes[QCHRG2].str) > 0) {
50524 			clfstrptr->ihetq[aCHGopt] = atoi(qboxes[QCHRG2].str);
50525 		   }
50526 		} else {
50527 		   clfstrptr->ihetq[aCHGopt] = icopt - 3;
50528 		}
50529 	    }
50530 
50531 	    if (ieemopt == 4) {
50532 #if defined(VMS) || defined(UNDERSC)
50533 		calgas(&CHGopt,&CHGstat);
50534 #else
50535 #ifdef CRAY
50536 		CALGAS(&CHGopt,&CHGstat);
50537 #else
50538 		calgas_(&CHGopt,&CHGstat);
50539 #endif
50540 #endif
50541 	    } else {
50542 #if defined(VMS) || defined(UNDERSC)
50543 		eem(Sincp,&CHGopt,&CHGstat);
50544 #else
50545 #ifdef CRAY
50546 		EEM(Sincp,&CHGopt,&CHGstat);
50547 #else
50548 		eem_(Sincp,&CHGopt,&CHGstat);
50549 #endif
50550 #endif
50551 	    }
50552 #ifdef DOGL
50553 	    update_model = 0;
50554 #else
50555 	    update_model = 1;
50556 #endif
50557 	    update_struct();
50558 	}
50559 	return(0);
50560 	break;
50561    case 2:
50562 	{
50563 	List.list = eems; List.nents = 5;
50564 
50565 	if (DoPopUp(CHGwin,chgbut[2].x+1,
50566 		chgbut[2].y+BUTTH,&List,&ieemopt,0) == -1) return(0);
50567 	chgbut[2].str = eems[ieemopt];
50568 	DrwBut(&chgbut[2]);
50569 	}
50570 	break;
50571    }
50572    return(0);
50573 }
50574 
50575 #if defined(VMS) || defined(UNDERSC)
initsrf()50576 void initsrf()
50577 #else
50578 #ifdef CRAY
50579 void INITSRF()
50580 #else
50581 void initsrf_()
50582 #endif
50583 #endif
50584 {
50585   if (SRFup) return;
50586 
50587   SRFup = 1;
50588 
50589   srfsep = 1;
50590   srftyp = 1;
50591   SRFwin = CreateWindow("Create Surface","-0+0",SRFWINW,SRFWINH,
50592 	 		 infobg,infofg,(Window)0);
50593   subSRF = CreateWindow("Subwindow","",10,10,
50594                             colors[0],colors[15],SRFwin);
50595   XSelectInput(display, SRFwin, SubstructureNotifyMask |
50596 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask |
50597 	LeaveWindowMask | PointerMotionMask | EnterWindowMask);
50598   XMapWindow(display,SRFwin);
50599 
50600   WinObj[31].win = &SRFwin;
50601   WinObj[31].subwin = &subSRF;
50602   WinObj[31].butarr = srfbut;
50603   WinObj[31].numbut = 6;
50604   WinObj[31].winup = &SRFup;
50605   WinObj[31].redraw = RedrawSRF;
50606 
50607   DefBut(&srfbut[0], SRFwin, 50, 25, 15, 15,
50608 	" ", infobg, -15);
50609   srfbut[0].explstr = "Color code the electrostatic potential\ncalculated from point charges onto the surface";
50610 
50611   DefBut(&srfbut[1], SRFwin, 50, 50, 15, 15,
50612 	" ", infobg, -15);
50613   srfbut[1].explstr = "Use only nearby (fast) or all (slow)\npoint charges to calculate the potential";
50614 
50615   DefBut(&srfbut[2], SRFwin, 50, 130, 100, 23,
50616 	"Create Surface", infobg, -15);
50617   srfbut[2].explstr = "Create surface of selected residues.\nClick 2nd MB on residue ->Add to Surface";
50618 
50619   DefBut(&srfbut[3], SRFwin, 210, 25, 50, 23,
50620 	"Color", infobg, -15);
50621   srfbut[3].explstr = "When no potential is mapped\nselect color of surface";
50622 
50623   DefBut(&srfbut[4], SRFwin, 50, 75, 15, 15,
50624 	" ", infobg, -15);
50625   srfbut[4].explstr = "Use a separate grid for each residue.\nYields higher quality but slower surfaces";
50626 
50627   DefBut(&srfbut[5], SRFwin, 50, 100, 120, 23,
50628 	" ", infobg, -15);
50629   srfbut[5].explstr = "Use solvent accessible surface or\napproxim. electron density surfaces";
50630 
50631   srfbut[5].str = srf2opt[srftyp];
50632   srfbut[3].fg = -cursrfcoli;
50633 
50634   if (hlpsrf->srfmap) {
50635 	TogDown(&srfbut[0]);
50636   } else {
50637 	TogUp(&srfbut[0]);
50638   }
50639 
50640   if (hlpsrf->srfloc) {
50641 	TogDown(&srfbut[1]);
50642   } else {
50643 	TogUp(&srfbut[1]);
50644   }
50645 
50646   if (srfsep) {
50647 	TogDown(&srfbut[4]);
50648   } else {
50649 	TogUp(&srfbut[4]);
50650   }
50651 }
50652 
50653 
RedrawSRF()50654 void RedrawSRF()
50655 {
50656    if (!SRFup) return;
50657 
50658    butje(SRFwin,0,0,SRFWINW,SRFWINH,4,0,0,1,None,0,0,0);
50659 
50660    DrwBut(&srfbut[0]);
50661    DrwBut(&srfbut[1]);
50662    DrwBut(&srfbut[2]);
50663    DrwBut(&srfbut[3]);
50664    DrwBut(&srfbut[4]);
50665    DrwBut(&srfbut[5]);
50666 
50667    LineString(SRFwin, "Map Electrostatic Pot.", 70, 35);
50668    LineString(SRFwin, "Local potential (fast)", 70, 60);
50669    LineString(SRFwin, "Each Res. Separate Surf.", 70, 85);
50670    LineString(SRFwin, "Surface type", 175, 115);
50671 
50672 }
50673 
ButtonsSRF(i)50674 int ButtonsSRF(i)
50675 int i;
50676 {
50677    int j,k,calc, NStmp;
50678 
50679    switch(i) {
50680    case 0:
50681 	hlpsrf->srfmap = 1 - TogBut(&srfbut[0]);
50682 	break;
50683    case 1:
50684 	hlpsrf->srfloc = 1 - TogBut(&srfbut[1]);
50685 	break;
50686    case 2:
50687 	update_model = 0;
50688 	XDestroyWindow(display,SRFwin);SRFup = 0;
50689 	calc = 1;
50690 
50691 	if (srftyp) {
50692 
50693 	   NStmp = NSurf[istruct];
50694 
50695 	   if (hlpsrf->srfmap) {
50696 		molsrf(cursrfcoli,1,1);
50697 	   } else {
50698 		molsrf(cursrfcoli,1,0);
50699 	   }
50700 
50701 	} else {
50702 
50703 	   NStmp = NSurf[istruct];
50704 	   if (hlpsrf->srfmap) hlpsrf->srfmap = 3;
50705 	   if (srfsep) {
50706 	     if (DEBUG) fprintf(stderr,"surface residues\n");
50707 	     for (j=0; j<calfptr->ncalf; j++) {
50708 		if (calfptr->iams[j]) {
50709 		   if (DEBUG) fprintf(stderr,"%d\n",j);
50710                    for (k=0; k<*xyzp->iatoms; k++) {
50711 			if (xyzp->iresid[k] == j+1) {xyzp->isurf[k] = 1;}
50712 			else {xyzp->isurf[k] = 0;}
50713 		   }
50714 #if defined(VMS) || defined(UNDERSC)
50715 	   	   asurf(&hlpsrf->srfmap,&calc);csrft(xyzp->isurf);
50716 #else
50717 #ifdef CRAY
50718 	   	   ASURF(&hlpsrf->srfmap,&calc);CSRFT(xyzp->isurf);
50719 #else
50720 	   	   asurf_(&hlpsrf->srfmap,&calc);csrft_(xyzp->isurf);
50721 #endif
50722 #endif
50723 		}
50724 	     }
50725 	     for (j=4; j<hetptr.NHetAtm; j++) {
50726 		if (calfptr->ihets[j]) {
50727 		   if (DEBUG) fprintf(stderr,"%d\n",j);
50728                    for (k=0; k<*xyzp->iatoms; k++) {
50729 			if (xyzp->iresid[k] == -j) {xyzp->isurf[k] = 1;}
50730 			else {xyzp->isurf[k] = 0;}
50731 		   }
50732 #if defined(VMS) || defined(UNDERSC)
50733 	   	   asurf(&hlpsrf->srfmap,&calc);csrft(xyzp->isurf);
50734 #else
50735 #ifdef CRAY
50736 	   	   ASURF(&hlpsrf->srfmap,&calc);CSRFT(xyzp->isurf);
50737 #else
50738 	   	   asurf_(&hlpsrf->srfmap,&calc);csrft_(xyzp->isurf);
50739 #endif
50740 #endif
50741 		}
50742 	     }
50743 	   } else {
50744 #if defined(VMS) || defined(UNDERSC)
50745 	     alasrf();asurf(&hlpsrf->srfmap,&calc);csrft(xyzp->isurf);
50746 #else
50747 #ifdef CRAY
50748 	     ALASRF();ASURF(&hlpsrf->srfmap,&calc);CSRFT(xyzp->isurf);
50749 #else
50750 	     alasrf_();asurf_(&hlpsrf->srfmap,&calc);csrft_(xyzp->isurf);
50751 #endif
50752 #endif
50753 	   }
50754 	}
50755 	for (j=0; j<calfptr->ncalf; j++) calfptr->iams[j] = 0;
50756 	for (j=0; j<MXHETA; j++) calfptr->ihets[j] = 0;
50757 	for (k=NStmp; k<NSurf[istruct]; k++)
50758 	    for (j=0; j<4; j++)
50759 		diffuseColor[istruct][k][j] = cursrfcol[0][j];
50760 	dispsf();
50761 	break;
50762    case 3:
50763 	if (DoPopUp(SRFwin,
50764 		srfbut[3].x-8,srfbut[3].y+BUTTH,
50765 		NULL,&cursrfcoli,0) == -1) break;
50766 #ifdef DOGL
50767 	if (has_opengl) {
50768 	   cursrfcol[0][0] = ((GLfloat) colorr[cursrfcoli]) / 65535.0 ;
50769 	   cursrfcol[0][1] = ((GLfloat) colorg[cursrfcoli]) / 65535.0 ;
50770 	   cursrfcol[0][2] = ((GLfloat) colorb[cursrfcoli]) / 65535.0 ;
50771 	   cursrfcol[0][3] = 1.0;
50772 	   srfbut[3].fg = -cursrfcoli;
50773 	   DrwBut(&srfbut[3]);
50774 	}
50775 #endif
50776 	break;
50777    case 4:
50778 	srfsep = 1 - TogBut(&srfbut[4]);
50779 	break;
50780    case 5:
50781 	{
50782 	LSSTRU List;
50783 	List.list = srf2opt; List.nents = 2; int iii;
50784 	if (DoPopUp(SRFwin,
50785 		srfbut[5].x-8,srfbut[5].y+BUTTH,
50786 		&List,&srftyp,0) == -1) break;
50787 	srfbut[5].str = srf2opt[srftyp];
50788 	DrwBut(&srfbut[5]);
50789 	}
50790 	break;
50791    }
50792 }
50793 
GenSVG(imxe,svgs)50794 void GenSVG(imxe,svgs)
50795 int *imxe;
50796 SVGFSTRUC **svgs;
50797 {
50798   char str[500];
50799   int n,i;
50800 
50801   if (getob()) {
50802 	if (COO[istruct]->fname == NULL) {
50803 	   *svgs = NULL;
50804 	   *imxe = NFLS;
50805 	   return;
50806 	}
50807 	if (strstr(COO[istruct]->fname,".sdf")) {
50808 	   if (!COO[istruct]->svgdone) {
50809 		sprintf(str,"/bin/rm /tmp/b*.svg");
50810 		n = strlen(str);
50811 #if defined(VMS) || defined(UNDERSC)
50812 		exstr(str,&n,&ZERO);
50813 #else
50814 #ifdef CRAY
50815 		EXSTR(str,&n,&ZERO);
50816 #else
50817 		exstr_(str,&n,&ZERO);
50818 #endif
50819 #endif
50820 		if (OBloc) {
50821 		   sprintf(str,
50822 		   "%sobabel -isdf %s --gen2D -m -d -osvg -xC -xd -O /tmp/b.svg &> /dev/null &",
50823 		   exepath[0],COO[istruct]->fname);
50824 
50825 		} else {
50826 		   sprintf(str,
50827 		   "/usr/local/bin/obabel -isdf %s --gen2D -m -d -osvg -xC -xd -O /tmp/b.svg &> /dev/null &",
50828 		   COO[istruct]->fname);
50829 		}
50830 		n = strlen(str);
50831 		excmd(str,&bcksvg.pid);
50832 		if (COO[istruct]->svgs == NULL &&
50833 			COO[istruct]->ntits == ntits) {
50834 	 	   COO[istruct]->svgs =
50835 			(SVGFSTRUC *) malloc(sizeof(SVGFSTRUC)*(ntits));
50836 		}
50837 
50838 		for (i=bcksvg.CurSVG; i < ntits; i++) {
50839 		   COO[istruct]->svgs[i].ncmd = 0;
50840 		   COO[istruct]->svgs[i].w = 1.0;
50841 		   COO[istruct]->svgs[i].h = 1.0;
50842 		   COO[istruct]->svgs[i].array = NULL;
50843 		}
50844 
50845 		GetExact();
50846 #ifdef HASTIMER
50847 		Timer(100,3);
50848 #else
50849 		signal(SIGALRM,handle_svgfile);
50850 		alarm(2);
50851 #endif
50852 		*imxe = 2;
50853 		*svgs = COO[istruct]->svgs;
50854 		bcksvg.UpSVG = 1;
50855 		bcksvg.NUpSVG = ntits;
50856 		bcksvg.istruct = istruct;
50857 	   } else {
50858 		*imxe = 2;
50859 		*svgs = COO[istruct]->svgs;
50860 	   }
50861 	} else {
50862 	   *svgs = NULL;
50863 	   *imxe = NFLS;
50864 	}
50865   } else {
50866 	*svgs = NULL;
50867 	*imxe = NFLS;
50868   }
50869 
50870 }
50871 
initMLT()50872 void initMLT()
50873 {
50874   int n,i,imxe;
50875   SVGFSTRUC *svgs;
50876 
50877   COO[istruct]->ntits = ntits;
50878   COO[istruct]->mlftit = mlftit;
50879 
50880   if (MLTup) {
50881      if (COO[istruct]->fname != NULL) {
50882 	if (strstr(COO[istruct]->fname,".sdf")) {
50883   getob();
50884 	   if (!COO[istruct]->svgdone) {
50885 		if (rdsvgs()) {
50886 		   GenSVG(&imxe,&COO[istruct]->svgs);
50887 		}
50888 	   }
50889 	   imxe = 2;
50890 	} else {
50891 	   COO[istruct]->svgdone = 1;
50892 	   imxe = NFLS;
50893 	}
50894      } else {
50895 	imxe = NFLS;
50896      }
50897      DefList(&mltlist,MLTwin,DIRX,DIRY,DIRW,DIRH,NULL,
50898 			imxe,COO[istruct]->mlftit,NULL,NULL,NULL,
50899 			&COO[istruct]->ntits,COO[istruct]->svgs);
50900 
50901      RedrawMLT();
50902      return;
50903   }
50904 
50905   if (bcksvg.UpSVG) return;
50906 
50907   MLTup = 1;
50908   MLTwide = 0;
50909 
50910   MLTwin = CreateWindow("Multi-mol file","-0+0",MLTWINW,MLTWINH,
50911 	 		 infobg,infofg,(Window)0);
50912   subMLT = CreateWindow("Subwindow","",10,10,
50913                             colors[0],colors[15],MLTwin);
50914   XSelectInput(display, MLTwin, SubstructureNotifyMask |
50915 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask |
50916 	LeaveWindowMask | PointerMotionMask | EnterWindowMask);
50917 
50918   XMapWindow(display,MLTwin);
50919 
50920   WinObj[30].win = &MLTwin;
50921   WinObj[30].subwin = &subMLT;
50922   WinObj[30].butarr = mltbut;
50923 
50924   if (COO[istruct]->fname != NULL) {
50925     if (!strstr(COO[istruct]->fname,".sdf")) {
50926 	Nmltb = 1;
50927     } else {
50928 	Nmltb = NMLTBUT;
50929     }
50930   } else {
50931     Nmltb = 1;
50932   }
50933   WinObj[30].numbut = Nmltb;
50934   WinObj[30].winup = &MLTup;
50935   WinObj[30].redraw = RedrawMLT;
50936 
50937   DefBut(&mltbut[0], MLTwin, 35, 250, 50, 23, "Close", infobg, -15);
50938   mltbut[0].explstr = "Close Window";
50939 
50940   DefBut(&mltbut[1], MLTwin, 105, 250, 160, 23, "Create Fingerprint Index", infobg, -15);
50941   mltbut[1].explstr = "Prepare for fingerprint searching";
50942 
50943   DefBut(&mltbut[2], MLTwin, 279, 250, 50, 23, "Search", infobg, -15);
50944   mltbut[2].explstr = "Search fingerprint index for\n similar compounds";
50945 
50946   DefBut(&mltbut[3], MLTwin, 279, 310, 50, 23, "Go->", infobg, -15);
50947   mltbut[3].explstr = "Search query against fingerprint index";
50948 
50949   if (!bcksvg.UpSVG && !COO[istruct]->svgdone) {
50950 	if (rdsvgs()) {
50951 	   GenSVG(&imxe,&svgs);
50952 	} else {
50953 	   imxe = 2;
50954 	   svgs = COO[istruct]->svgs;
50955 	}
50956   } else {
50957 	imxe = 2;
50958 	svgs = COO[istruct]->svgs;
50959   }
50960 
50961   DefList(&mltlist,MLTwin,DIRX,DIRY,DIRW,DIRH,NULL,
50962 			imxe,COO[istruct]->mlftit,NULL,NULL,NULL,
50963 			&COO[istruct]->ntits,svgs);
50964   mltlist.select = mfdata->imol-1;
50965   if (mltlist.select < 0) mltlist.select = 0;
50966 
50967   qboxstr(&qboxes[QRESF],&MLTwin,0,0,190,35,290,200,35,2,
50968 		"Result file:","res.sdf",0,QSTRING,2000,0,obsrch);
50969 
50970   qboxstr(&qboxes[QQUERY],&MLTwin,0,0,190,35,320,200,35,2,
50971 		"Query file :","",0,QSTRING,2000,0,obsrch);
50972 
50973   qboxstr(&qboxes[QNRES],&MLTwin,0,0,190,35,350,200,35,2,
50974 		"Tanimoto coefficient >=","0.6",4,QPOSREAL,2000,-1,obsrch);
50975 
50976   qboxes[QRESF].active = 1;
50977   WinName(win,mlftit[mltlist.select]);
50978 }
50979 
50980 
RedrawMLT()50981 void RedrawMLT()
50982 {
50983    int i;
50984 
50985    if (!MLTup) return;
50986 
50987    if (MLTwide) {
50988 	butje(MLTwin,0,0,MLTWINW,MLTWINH+MLTWIDE,4,0,0,1,None,0,0,0);
50989    } else {
50990 	butje(MLTwin,0,0,MLTWINW,MLTWINH,4,0,0,1,None,0,0,0);
50991    }
50992 
50993    RedrawList(&mltlist);
50994 
50995    for (i=0; i < Nmltb; i++) {
50996 	DrwBut(&mltbut[i]);
50997    }
50998 
50999    if (MLTwide) {
51000 	PromptBox(&qboxes[QRESF]);
51001 	PromptBox(&qboxes[QQUERY]);
51002 	PromptBox(&qboxes[QNRES]);
51003    }
51004 
51005    XFlush(display);
51006 }
51007 
ButtonsMLT(i)51008 int ButtonsMLT(i)
51009 int i;
51010 {
51011    int j,k;
51012    char xstr1[MAXCMD];
51013    char *last1;
51014    char *dot1;
51015    int n1,stat;
51016 
51017    switch(i) {
51018    case 0:
51019 	if (MLTup) {
51020 	    XDestroyWindow(display,MLTwin);
51021 	    MLTup = 0;
51022 	    if (COO[istruct]->fname != NULL) {
51023 		if (strstr(COO[istruct]->fname,".sdf")) {
51024 		   if (bcksvg.UpSVG) {
51025 			killob();
51026 			bcksvg.UpSVG = 0;
51027 		   }
51028 		}
51029 	    }
51030 	}
51031 	break;
51032    case 1:
51033 	stat = 1;
51034 	last1 = COO[istruct]->fname;
51035 	if (last1 != NULL) {
51036 	   dot1 = strrchr(last1,'.');
51037 	   if (dot1 != NULL) {
51038 		n1 = (int) (dot1 - last1);
51039 		strncpy(xstr1,last1,n1);
51040 		xstr1[n1] = '\0';
51041 		strcat(xstr1,".fs");
51042 	   } else {
51043 		stat = 0;
51044 	   }
51045 	} else {
51046 	   stat = 0;
51047 	}
51048 
51049 	if (stat) {
51050 	   if (access(xstr1,F_OK) == 0) {
51051 		if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
51052 	"A fingerprint index already exists for this file.\n Refresh index ?",1)) {
51053 		   obfp();
51054 		}
51055 	   } else {
51056 	      obfp();
51057 	   }
51058 	} else {
51059 	   obfp();
51060 	}
51061 	break;
51062    case 2:
51063 	stat = 1;
51064 	last1 = COO[istruct]->fname;
51065 	if (last1 != NULL) {
51066 	   dot1 = strrchr(last1,'.');
51067 	   if (dot1 != NULL) {
51068 		n1 = (int) (dot1 - last1);
51069 		strncpy(xstr1,last1,n1);
51070 		xstr1[n1] = '\0';
51071 		strcat(xstr1,".fs");
51072 	   } else {
51073 		stat = 0;
51074 	   }
51075 	} else {
51076 	   stat = 0;
51077 	}
51078 
51079 	if (stat) {
51080 	   if (access(xstr1,F_OK) != 0) {
51081 		if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
51082 	"No fingerprint index exists for this file.\n First create index ",1)) { }
51083 	   } else {
51084 		XResizeWindow(display, MLTwin, MLTWINW, MLTWINH+200);
51085 		size_hints.flags =  USSize;
51086 		size_hints.width = MLTWINW;
51087 		size_hints.height = MLTWINH + MLTWIDE;
51088 		XSetNormalHints(display, MLTwin, &size_hints);
51089 		XResizeWindow(display, MLTwin, MLTWINW,size_hints.height);
51090 		MLTwide = 1;
51091 		RedrawMLT();
51092 	   }
51093 	}
51094 	break;
51095    case 3:
51096 	obsrch(xstr1);
51097 	break;
51098    }
51099 }
51100 
initPHRM()51101 void initPHRM()
51102 {
51103   int n,i;
51104 
51105   PHRMup = 1;
51106 
51107   PHRMwin = CreateWindow("Pharmacophore query editor","-0+0",PHRMWINW,PHRMWINH,
51108 	 		 infobg,infofg,(Window)0);
51109   subPHRM = CreateWindow("Subwindow","",10,10,
51110                             colors[0],colors[15],PHRMwin);
51111 
51112   XSelectInput(display, PHRMwin, KeyPressMask | ExposureMask | ButtonPressMask
51113 	| ButtonReleaseMask | ButtonMotionMask | LeaveWindowMask |
51114 	SubstructureNotifyMask | PointerMotionMask | EnterWindowMask);
51115 
51116   XMapWindow(display,PHRMwin);
51117 
51118   WinObj[43].win = &PHRMwin;
51119   WinObj[43].subwin = &subPHRM;
51120   WinObj[43].butarr = PHRMbut;
51121   WinObj[43].numbut = PHRMBUT;
51122   WinObj[43].winup  = &PHRMup;
51123   WinObj[43].redraw = RedrawPHRM;
51124 
51125   DefBut(&PHRMbut[0], PHRMwin, 35, 320, 50, 23, "Close", infobg, -15);
51126   PHRMbut[0].explstr = "Close Window";
51127 
51128   DefBut(&PHRMbut[1], PHRMwin, 90, 320, 50, 23, "Save", infobg, -15);
51129   PHRMbut[1].explstr = "Save Pharmacophore Query";
51130 
51131   DefBut(&PHRMbut[2], PHRMwin, 145, 320, 50, 23, "Open", infobg, -15);
51132   PHRMbut[2].explstr = "Open Pharmacophore Query";
51133 
51134   DefBut(&PHRMbut[3], PHRMwin, 300, 40, 50, 23, "Create", infobg, -15);
51135   PHRMbut[3].explstr = "Add Pharmacophore Feature";
51136 
51137   DefBut(&PHRMbut[4], PHRMwin, 300, 70, 50, 23, "Delete", infobg, -15);
51138   PHRMbut[4].explstr = "Delete Pharmacophore Feature";
51139 
51140   DefBut(&PHRMbut[5], PHRMwin, 35, 250, 50, 23, "Apply", infobg, -15);
51141   PHRMbut[5].explstr = "Finalize Pharmacophore Feature";
51142 
51143   DefBut(&PHRMbut[6], PHRMwin, 90, 250, 120, 23, " ", infobg, -15);
51144   PHRMbut[6].explstr = "Choose Feature Type";
51145 
51146   DefBut(&PHRMbut[7], PHRMwin, 200, 320, 50, 23, "Search", infobg, -15);
51147   PHRMbut[7].explstr = "Search .sdf file with pharmacophore";
51148 
51149   DefList(&PHRMlist,PHRMwin,DIRX,DIRY,DIRW-20,DIRH,NULL,
51150 			10,pharm.str,NULL,NULL,NULL,
51151 			&pharm.NSelFeat,NULL);
51152 
51153   PHRMlist.select = 0;
51154   PHRMlist.wwin = 300;
51155 
51156   qboxstr(&qboxes[QPHRMT],&PHRMwin,0,0,190,35,10,200,35,2,
51157 		"Title:","res.json",0,QSTRING,2000,0,dummyproc);
51158   strcpy(qboxes[QPHRMT].str,mkjson());
51159 
51160   qboxstr(&qboxes[QPHRMR],&PHRMwin,0,0,190,35,285,200,35,2,
51161 		"Radius :","",0,QREAL,2000,-1,PHRMrad);
51162 
51163   qboxes[QRESF].active = 1;
51164   WinName(win,"Pharmacophore query editor");
51165 }
51166 
RedrawPHRM()51167 void RedrawPHRM()
51168 {
51169    int i;
51170 
51171    if (!PHRMup) return;
51172 
51173    butje(PHRMwin,0,0,PHRMWINW,PHRMWINH,4,0,0,1,None,0,0,0);
51174 
51175    RedrawList(&PHRMlist);
51176 
51177    for (i=0; i < PHRMBUT; i++) {
51178 	DrwBut(&PHRMbut[i]);
51179    }
51180 
51181    PromptBox(&qboxes[QPHRMT]);
51182    PromptBox(&qboxes[QPHRMR]);
51183 
51184    XFlush(display);
51185 }
51186 
ButtonsPHRM(i)51187 int ButtonsPHRM(i)
51188 int i;
51189 {
51190    int j,k;
51191 
51192    switch(i) {
51193    case 0:
51194 	if (PHRMup) {
51195 	    XDestroyWindow(display,PHRMwin);
51196 	    dispsf();
51197 	    PHRMup = 0;
51198 	}
51199 	break;
51200    case 1:
51201 	WriteJSON(qboxes[QPHRMT].str);
51202 	break;
51203    case 2:
51204 	gsel.qbrfile = 1;
51205 	gsel.subopt = 0;
51206 	gsel.flist.select = -1;
51207 	gsel.Callwin = PHRMwin;
51208 	strcpy(gsel.pntr," ");
51209 	strcpy(qboxes[QSUBSTR].str,"json");
51210 	getfiles(&gsel,gsel.lastdir);
51211 	FileSelectList(&gsel);
51212 
51213 	break;
51214    case 3:
51215 	if (FeatSel != -1) {
51216 	    pharm.NSelFeat++;
51217 	    pharm.index[pharm.NSelFeat-1] = FeatSel;
51218 	    pharm.array[FeatSel].incl = 1;
51219 	    pharm.str[pharm.NSelFeat-1] = (char *) malloc(sizeof(char)*17);
51220 	    strcpy(pharm.str[pharm.NSelFeat-1],FeatStr[pharm.array[FeatSel].type]);
51221 	    PHRMbut[6].str = FeatStr[pharm.array[FeatSel].type];
51222 	    sprintf(qboxes[QPHRMR].str,"%f",
51223 		pharm.array[pharm.index[pharm.NSelFeat-1]].rad*0.52917706);
51224 	    PHRMlist.select = pharm.NSelFeat-1;
51225 	    if (PHRMup) {
51226 		ogfeatures();
51227 		dispsf();
51228 		XMapRaised(display,PHRMwin);
51229 		RedrawPHRM();
51230 	    }
51231 	}
51232 	break;
51233    case 4:  {
51234 	int n,i;
51235 
51236 	n = PHRMlist.select;
51237 
51238 	pharm.array[pharm.index[n]].incl = 0;
51239 	for (i=n; i < pharm.NSelFeat-1; i++) {
51240 	   pharm.index[i] = pharm.index[i+1];
51241 	   pharm.str[i]   = pharm.str[i+1];
51242 	}
51243 	pharm.NSelFeat--;
51244 	if (pharm.NSelFeat < 0) pharm.NSelFeat = 0;
51245 	if (pharm.NSelFeat) {
51246 	   if (n > pharm.NSelFeat-1) PHRMlist.select = pharm.NSelFeat - 1;
51247 	} else {
51248 	   PHRMlist.select = 0;
51249 	}
51250 	UpdPHRM();
51251 
51252 	}
51253 	break;
51254    case 5:
51255 	strcpy(pharm.str[PHRMlist.select],
51256 		FeatStr[pharm.array[pharm.index[PHRMlist.select]].type]);
51257 	pharm.array[pharm.index[PHRMlist.select]].rad  =
51258 		atof(qboxes[QPHRMR].str) / 0.52917706;
51259 	UpdPHRM();
51260 	break;
51261 
51262    case 6: {
51263 	int type,i,ind,fnd;
51264 	float x,y,z;
51265 	LSSTRU List;
51266 	List.list = FeatStr; List.nents = 6;
51267 	if (DoPopUp(PHRMwin,PHRMbut[6].x+20,PHRMbut[6].y,
51268 			&List,&type,0) == -1) break;
51269 	ind = pharm.index[PHRMlist.select];
51270 	x = pharm.array[ind].cor[0];
51271 	y = pharm.array[ind].cor[1];
51272 	z = pharm.array[ind].cor[2];
51273 
51274 	fnd = 0;
51275 
51276         for (i=0; i<pharm.nfeat; i++) {
51277 	   if ( pharm.array[i].cor[0] == x &&
51278 		pharm.array[i].cor[1] == y &&
51279 		pharm.array[i].cor[2] == z) {
51280 		if (pharm.array[i].type == type) {
51281 		   fnd = 1;
51282 		   PHRMbut[6].str = FeatStr[type];
51283 		   DrwBut(&PHRMbut[6]);
51284 		   pharm.array[ind].incl = 0;
51285 		   pharm.index[PHRMlist.select] = i;
51286 		   pharm.array[pharm.index[PHRMlist.select]].incl = 1;
51287 		}
51288 	   }
51289 	}
51290 
51291 	if (!fnd) {
51292 	   DoCan(event.xbutton.x_root, event.xbutton.y_root,
51293 	"Could not find annotated feature of the \n specified kind with those coordinates.",0);
51294 	}
51295 
51296 	UpdPHRM();
51297 	}
51298 	break;
51299    case 7: initPSRCH(qboxes[QPHRMT].str);
51300 	break;
51301 
51302    deafult:
51303 	break;
51304 
51305    }
51306 }
51307 
initPSRCH(query)51308 void initPSRCH(query)
51309 char *query;
51310 {
51311   int n,i;
51312 
51313   PSRCHup = 1;
51314   PSRCHquery = query;
51315 
51316   PSRCHwin = CreateWindow("Pharmacophore Search Database","-0+0",
51317 	PSRCHWINW,PSRCHWINH, infobg,infofg,(Window)0);
51318 
51319   subPSRCH = CreateWindow("Subwindow","",10,10,
51320                             colors[0],colors[15],PSRCHwin);
51321 
51322   XSelectInput(display, PSRCHwin, SubstructureNotifyMask |
51323 	KeyPressMask | ExposureMask | ButtonPressMask | ButtonReleaseMask |
51324 	LeaveWindowMask | PointerMotionMask | EnterWindowMask);
51325 
51326   XMapWindow(display,PSRCHwin);
51327 
51328   WinObj[44].win = &PSRCHwin;
51329   WinObj[44].subwin = &subPSRCH;
51330   WinObj[44].butarr = PSRCHbut;
51331   WinObj[44].numbut = PSRCHBUT;
51332   WinObj[44].winup  = &PSRCHup;
51333   WinObj[44].redraw = RedrawPSRCH;
51334 
51335   DefBut(&PSRCHbut[0], PSRCHwin, 95, 100, 55, 23, "Close", infobg, -15);
51336   PSRCHbut[0].explstr = "Close Window";
51337 
51338   DefBut(&PSRCHbut[1], PSRCHwin, 35, 100, 55, 23, "Search", infobg, -15);
51339   PSRCHbut[1].explstr = "Search DB with Pharmacophore Query";
51340 
51341   DefBut(&PSRCHbut[2], PSRCHwin, 35, 40, 150, 23, "Create DB Index", infobg, -15);
51342   PSRCHbut[2].explstr = "Create search index for DB/sdf file";
51343 
51344   DefBut(&PSRCHbut[3], PSRCHwin, 250, 8, 50, 23, "Open", infobg, -15);
51345   PSRCHbut[3].explstr = "Open DB/.sdf file";
51346 
51347   qboxstr(&qboxes[QSCSDF],&PSRCHwin,0,0,190,35,10,200,35,2,
51348 		"Database:"," ",0,QSTRING,2000,0,dummyproc);
51349 
51350   qboxstr(&qboxes[QCRIND],&PSRCHwin,0,0,190,35,70,200,35,2,
51351 		"Results:","",0,QSTRING,2000,0,dummyproc);
51352   strcpy(qboxes[QCRIND].str,"phrm.sdf");
51353 
51354   qboxes[QSCSDF].active = 1;
51355   WinName(win,"Pharmacophore Search Database");
51356 }
51357 
RedrawPSRCH()51358 void RedrawPSRCH()
51359 {
51360    int i;
51361 
51362    if (!PSRCHup) return;
51363 
51364    butje(PSRCHwin,0,0,PSRCHWINW,PSRCHWINH,4,0,0,1,None,0,0,0);
51365 
51366    for (i=0; i < PSRCHBUT; i++) {
51367 	DrwBut(&PSRCHbut[i]);
51368    }
51369 
51370    PromptBox(&qboxes[QSCSDF]);
51371    PromptBox(&qboxes[QCRIND]);
51372 
51373    XFlush(display);
51374 }
51375 
ButtonsPSRCH(i)51376 int ButtonsPSRCH(i)
51377 int i;
51378 {
51379    int j,k,n;
51380    char cmdfil[512];
51381    char *dbtmp;
51382    char *resf;
51383    char str[500];
51384    char line[MAXCMD];
51385    FILE *f;
51386 
51387    switch(i) {
51388    case 0:
51389 	if (PSRCHup) {
51390 	    XDestroyWindow(display,PSRCHwin);
51391 	    dispsf();
51392 	    PSRCHup = 0;
51393 	}
51394 	break;
51395    case 1:
51396 	if (access(qboxes[QCRIND].str,F_OK) == 0) {
51397 	    fprintf(stderr,"File: %s exists !\nMoved to .org\n",
51398 		qboxes[QCRIND].str);
51399 	    rename(qboxes[QCRIND].str,mkext(qboxes[QCRIND].str,".sdf.org"));
51400 	    resf = mkext(qboxes[QCRIND].str,".svgs");
51401 	    if (access(resf,F_OK) == 0) {
51402 		rename(resf,mkext(resf,".svgs.org"));
51403 	    }
51404 	}
51405 	dbtmp = mkdb();
51406 	if (PHRMloc) {
51407 #if defined(DARWIN)
51408 		strcpy(str,"/tmp/log");
51409 		sprintf(cmdfil,
51410 		"%spharmer -cmd dbsearch -dbdir %s -in %s -out %s > %s",exepath[0],
51411 		dbtmp,PSRCHquery,qboxes[QCRIND].str,str);
51412 #else
51413 		sprintf(cmdfil,
51414 		"%spharmer -cmd dbsearch -dbdir %s -in %s -out %s 2>&1 | tee /tmp/log",exepath[0],
51415 		dbtmp,PSRCHquery,qboxes[QCRIND].str);
51416 #endif
51417 	} else {
51418 		sprintf(cmdfil,
51419 		"/usr/local/bin/pharmer -cmd dbsearch -dbdir %s -in %s -out %s 2>&1 | tee /tmp/log",
51420 		dbtmp,PSRCHquery,qboxes[QCRIND].str);
51421 	}
51422 	n = strlen(cmdfil);
51423 #if defined(VMS) || defined(UNDERSC)
51424 	curs(&ONE);
51425 #else
51426 #ifdef CRAY
51427 	CURS(&ONE);
51428 #else
51429 	curs_(&ONE);
51430 #endif
51431 #endif
51432 
51433 #if defined(VMS) || defined(UNDERSC)
51434 	exstr(cmdfil,&n,&ZERO);
51435 #else
51436 #ifdef CRAY
51437 	EXSTR(cmdfil,&n,&ZERO);
51438 #else
51439 	exstr_(cmdfil,&n,&ZERO);
51440 #endif
51441 #endif
51442 
51443 #if defined(VMS) || defined(UNDERSC)
51444 	curs(&ZERO);
51445 #else
51446 #ifdef CRAY
51447 	CURS(&ZERO);
51448 #else
51449 	curs_(&ZERO);
51450 #endif
51451 #endif
51452 	f  = fopen("/tmp/log","r");
51453 	if (f == NULL) {
51454 	   fprintf(stderr,"Error opening log file /tmp/log\n");
51455 	} else {
51456 	   while(1) {
51457 		if (fgets(line,MAXCMD,f) == NULL) break;
51458 		if (strstr(line,"NumResults:")) {
51459 	   	   DoCan(event.xbutton.x_root, event.xbutton.y_root,line,0);
51460 	   	   break;
51461 		}
51462 	   }
51463 	}
51464 	qboxes[QREADF].qbinct = 480;
51465 	strcpy(qboxes[QSUBSTR].str,"");
51466 
51467 	break;
51468    case 2:
51469 	dbtmp = mkdb();
51470 	if (PHRMloc) {
51471 		sprintf(cmdfil,
51472 		"%spharmer -cmd dbcreate -dbdir %s -in %s",exepath[0],
51473 		dbtmp,qboxes[QSCSDF].str);
51474 	} else {
51475 		sprintf(cmdfil,
51476 		"/usr/local/bin/pharmer -cmd dbcreate -dbdir %s -in %s",
51477 		dbtmp,qboxes[QSCSDF].str);
51478 	}
51479 	n = strlen(cmdfil);
51480 	if (isdir(dbtmp)) {
51481 	   sprintf(cmdfil,"Directory %s exists !\nIf you want to create a new DB,\nfirst remove the old one !\n",dbtmp);
51482 	   DoCan(event.xbutton.x_root, event.xbutton.y_root,cmdfil,0);
51483 	   break;
51484 	}
51485 #if defined(VMS) || defined(UNDERSC)
51486 	curs(&ONE);
51487 #else
51488 #ifdef CRAY
51489 	CURS(&ONE);
51490 #else
51491 	curs_(&ONE);
51492 #endif
51493 #endif
51494 
51495 #if defined(VMS) || defined(UNDERSC)
51496 	exstr(cmdfil,&n,&ZERO);
51497 #else
51498 #ifdef CRAY
51499 	EXSTR(cmdfil,&n,&ZERO);
51500 #else
51501 	exstr_(cmdfil,&n,&ZERO);
51502 #endif
51503 #endif
51504 
51505 #if defined(VMS) || defined(UNDERSC)
51506 	curs(&ZERO);
51507 #else
51508 #ifdef CRAY
51509 	CURS(&ZERO);
51510 #else
51511 	curs_(&ZERO);
51512 #endif
51513 #endif
51514 	break;
51515    case 3:
51516 	gsel.qbrfile = 1;
51517 	gsel.subopt = 0;
51518 	gsel.flist.select = -1;
51519 	gsel.Callwin = PSRCHwin;
51520 	strcpy(gsel.pntr," ");
51521 	strcpy(qboxes[QSUBSTR].str,".sdf");
51522 	getfiles(&gsel,gsel.lastdir);
51523 	FileSelectList(&gsel);
51524 	break;
51525    default:
51526 	break;
51527    }
51528 }
51529 
51530 #if defined(VMS) || defined(UNDERSC)
dlystr()51531 void dlystr()
51532 #else
51533 #ifdef CRAY
51534 void DLYSTR()
51535 #else
51536 void dlystr_()
51537 #endif
51538 #endif
51539 {
51540 
51541    if (! *ideltm) return;
51542 #ifdef HASTIMER
51543 	Timer(*ideltm,0);
51544 #endif
51545 }
51546 
delayt()51547 void delayt()
51548 {
51549    if (! *ideltm) return;
51550 #ifdef HASTIMER
51551    fprintf(stderr,"ideltm %d\n",*ideltm);
51552    Timer(*ideltm,1);
51553 #endif
51554 }
51555 
WinName(Window win,char * wname)51556 void WinName(Window win,char *wname)
51557 {
51558    if (XStringListToTextProperty(&wname,1,&windowProp)) {
51559 	XSetWMName(display,win, &windowProp);
51560 	XFree(windowProp.value);
51561    }
51562 }
51563 
AddAce(ires)51564 int AddAce(ires)
51565 int ires;
51566 {
51567    int hs[3],i,iatje,atm,row,itel;
51568 
51569 /* look for N to which cap is to be attached */
51570 
51571    for (i=0; i < 3; i++) hs[i] = -1;
51572 
51573    if (ires == -1) {
51574 
51575 	row = GetRow(1);
51576 	if (row < 0) return(0);
51577 
51578 	row = izz(row,0)-1;
51579 	if (row < 0) return(0);
51580 
51581 	atm = zmptrp->imap[row]-1;
51582 	if (atm < 0) return(0);
51583 
51584    } else {
51585 	atm = calfptr->icalf[ires-1][1]-1;
51586 	if (atm < 0) return(0);
51587    }
51588 
51589    itel = 0;
51590    for (i=0; i < xyzp->iconn[atm*(MXCON+1)]; i++) {
51591 	iatje = xyzp->iconn[atm*(MXCON+1)+1+i]-1;
51592 	if (xyzp->ianz[iatje] == 1 && itel < 3) {
51593 		hs[itel] = MapAtom(iatje+1);
51594 		itel++;
51595 	}
51596    }
51597 
51598    if (hs[0] > hs[1]) {
51599 	itel = hs[0]; hs[0] = hs[1]; hs[1] = itel;
51600    }
51601 
51602    if (hs[0] > hs[2]) {
51603 	itel = hs[0]; hs[0] = hs[2]; hs[1] = itel;
51604    }
51605 
51606    if (hs[1] > 0) {
51607       AddFrag(ACE,6,120.0,0.0,hs[1],1,1,1);
51608       zmptrp->bet[hs[1]] = 180.0;
51609       SetQZME();
51610    }
51611    if (hs[2] > 0) {
51612       DelLine(hs[2],1,0,NULL);
51613       SetQZME();
51614    }
51615    make_aa();
51616    UpdateZME();
51617 
51618    return(1);
51619 }
51620 
AddCap(ires)51621 int AddCap(ires)
51622 int ires;
51623 {
51624    int icap,row,orow,iatje,i;
51625 
51626    icap = 0;
51627    for (i=0; i < calfptr->nchain; i++) {
51628 	if (ires == calfptr->ianf[i]) icap = 1;
51629 	if (ires == calfptr->islu[i]) icap = 2;
51630    }
51631    if (icap == 0) {
51632 	strcpy(ZMEerr,"Not end or begin chain !");
51633 	RedrawStatus();
51634    } else if (icap == 1) {
51635 	if (!AddAce(ires)) return(0);
51636 	SetQZME();
51637 	update_res = -1;
51638 	update_model = 1;
51639    } else if (icap == 2) {
51640 	row = calfptr->icalf[ires-1][2]-1;
51641 	if (row < 0) return(0);
51642 	orow = -1;
51643 	for (i=0; i < xyzp->iconn[row*(MXCON+1)]; i++) {
51644 	   iatje = xyzp->iconn[row*(MXCON+1)+1+i]-1;
51645 	   if (xyzp->ianz[iatje] == 8) {
51646 		orow = MapAtom(iatje+1);
51647 		break;
51648 	   }
51649 	}
51650 	if (orow < 0) return(0);
51651 	AddFrag(NME,6,109.471,180.0,orow,1,1,1);
51652 	SetQZME();
51653 	update_res = -1;
51654 	update_model = 1;
51655    }
51656    return(1);
51657 
51658 }
51659 
GetFrag(int iopt,int x,int y)51660 int GetFrag(int iopt, int x, int y)
51661 {
51662    LSSTRU List; int ifrg; int perio; int ichl; int iamin; int iret; int minone;
51663    int idomp;
51664 
51665    if (iopt) {
51666       List.list = fragmnts; List.nents = nfrags;
51667       if (*ipdbon) List.nents = nfrags + 4;
51668    } else {
51669       List.list = fragments; List.nents = nfrag;
51670    }
51671 
51672    iret = -1;
51673 
51674    if ( ! (ZMEup && ! ZMEsel && ! ZMEmode && ! Selecting)) return(iret);
51675 
51676 
51677    if (iopt) {
51678 	if (DoPopUp(win,x,y,&List,&ifrg,0) == -1) return(iret);
51679    } else {
51680 	if (DoPopUp(ZMEwin,
51681 		ZMEbut[ZMEFRG].x+1,ZMEbut[ZMEFRG].y-7*BUTTH,
51682 		&List,&ifrg,0) == -1) return(iret);
51683    }
51684    if (iopt) ifrg++;
51685 
51686    if (ifrg < 21) calfptr->issdon = 0;
51687 
51688    idomp = 0;
51689    if (ialtyp == NULL) idomp = 1;
51690    else if (*ialtyp != 1) idomp = 1;
51691    else idomp = 0;
51692 
51693    if (idomp) map_prop();
51694 
51695    switch (ifrg) {
51696 	case 0:
51697 	   if (iopt) break;
51698 	   qboxstr(&qboxes[QFRAG],NULL,1,0,-1,DEFQX,DEFQY,
51699 		QBOXWIDE,QBOXHIGH,0,"Filename ? ",NULL,0,0,
51700 		540,0,dummyproc);
51701 	   break;
51702 	case 1: AddXH3(6,1); iret = 1; break;
51703 	case 2: AddFrag(CHCH2,5,120.0,180.0,-1,1,1,1); iret = 1; break;
51704 	case 3: AddFrag(CHO,3,120.0,180.0,-1,1,1,1); iret = 1; break;
51705 	case 4: AddFrag(COOH,4,120.0,180.0,-1,1,1,1); iret = 1; break;
51706 	case 5: AddXH3(7,1); iret = 1; break;
51707 	case 6: AddFrag(OH,2,109.471,180.0,-1,1,1,1); iret = 1; break;
51708 	case 7: AddFrag(CHCH,5,90.0,180.0,-1,1,1,1); iret = 1; break;
51709 	case 8: AddCycloHexane(); iret = 1; break;
51710 	case 9: AddFrag(benzyl,BENZLEN,120.0,180.0,-1,1,1,1); iret = 1; break;
51711 	case 10: AddFrag(cyclopentane,PENT,109.471,-90.0,-1,1,1,1); iret = 1; break;
51712 	case 11: AddFrag(pyrrole,PYRROLE,120.0,180.0,-1,1,1,1); iret = 1; break;
51713 	case 12: AddFrag(CL,1,109.471,180.0,-1,1,1,1); iret = 1; break;
51714 	case 13: AddFrag(BR,1,109.471,180.0,-1,1,1,1); iret = 1; break;
51715 	case 14: AddFrag(I,1,109.471,180.0,-1,1,1,1); iret = 1; break;
51716 	case 15: AddFrag(OCH3,5,109.471,180.0,-1,1,1,1); iret = 1; break;
51717 	case 16: AddFrag(SH,2,109.471,180.0,-1,1,1,1); iret = 1; break;
51718 	case 17: AddFrag(NO2,3,117.38,180.0,-1,1,1,1); iret = 1; break;
51719 	case 18: AddFrag(CH4,5,117.38,180.0,-1,1,1,1); iret = 1; break;
51720 	case 19:
51721 		if (iopt) {
51722 		   if (!AddAce(-1)) return 0;
51723 		   iret = 1; break;
51724 		}
51725 		RedrawZME(); XFlush(display); XSync(display,False);
51726 		List.list = Periodic; List.nents = 2;
51727 		if (DoPopUp(ZMEwin,
51728 			ZMEbut[ZMEFRG].x+1,ZMEbut[ZMEFRG].y-6*BUTTH,
51729 			&List,&perio,0) == -1) break;
51730 		List.list = ChainLength; List.nents = 10;
51731 		RedrawZME(); XFlush(display); XSync(display,False);
51732 		if (perio == 2) break;
51733 		if (DoPopUp(ZMEwin,
51734 			ZMEbut[ZMEFRG].x+1,ZMEbut[ZMEFRG].y-6*BUTTH,
51735 			&List,&ichl,0) == -1) break;
51736 		*ipdbon = 0;
51737 		scrfrg(perio,ichl); iret = 1; break;
51738 	case 20:
51739 
51740         /* add FOR cap (iopt==1) or add amino acid */
51741 
51742 		if (iopt) {
51743 		   AddFrag(FOR,3,120.0,180.0,-1,1,1,1);
51744 		   iret = 1; break;
51745 		}
51746 		RedrawZME(); XFlush(display); XSync(display,False);
51747 		List.list = AmiOpt; List.nents = 4;
51748 		if (DoPopUp(ZMEwin,
51749 			ZMEbut[ZMEFRG].x+1,ZMEbut[ZMEFRG].y+7*BUTTH,
51750 			&List,&iamin,0) == -1) break;
51751 		if (iamin == 1 || iamin == 2 || iamin == 3) {
51752   	   	   if (DoCan(event.xbutton.x_root,
51753 			event.xbutton.y_root,
51754 			"Click on an atom of the residue",0)) {
51755 		   }
51756 		   bflag = 1;
51757 		   if (iamin == 1) bretval = 321;
51758 		   else bretval = 322;
51759 		   if (iamin == 3) ReplaceAmino = 1;
51760 		} else {
51761 		   List.list = AminoCaps; List.nents = NAminos+4;
51762 		   if (DoPopUp(ZMEwin,
51763 			ZMEbut[ZMEFRG].x+1,ZMEbut[ZMEFRG].y-10*BUTTH,
51764 			&List,&iamin,0) == -1) break;
51765 		   minone = -1;
51766 		   if (iamin == 14) {
51767 			AddAmino(iamin,&minone, -70.0,113.0,
51768 			NULL,NULL,NULL,NULL,NULL,iconform,1,1);
51769 		   } else if (iamin == 20) {
51770 			AddFrag(ACE,6,120.0,180.0,-1,1,1,1);
51771 		   } else if (iamin == 21) {
51772 			AddFrag(FOR,3,120.0,180.0,-1,1,1,1);
51773 		   } else if (iamin == 22) {
51774 			AddFrag(NME,6,109.471,180.0,-1,1,1,1);
51775 		   } else if (iamin == 23) {
51776 			AddXH3(7,1);
51777 		   } else {
51778 			AddAmino(iamin,&minone, -119.0,113.0,
51779 			NULL,NULL,NULL,NULL,NULL,iconform,1,1);
51780 			calfptr->reson[calfptr->ncalf-1] = 1;
51781 			update_model = 1;
51782 		   }
51783 		}
51784 		iret = 1; break;
51785 	case 21:
51786 		if (iopt) {
51787 		   AddFrag(NME,6,120.0,180.0,-1,1,1,1);
51788 		   iret = 1; break;
51789 		}
51790 		if (SEQup) {
51791 		    XMapRaised(display,SEQwin);
51792 		    RedrawSEQ();
51793 		} else {
51794 		    InitSEQ(event.xbutton.x_root,
51795 			event.xbutton.y_root+20);
51796 		}
51797 		iret = 0; break;
51798 	case 22:
51799 		AddFrag(NH2,3,120.0,180.0,-1,1,1,1);
51800 		iret = 1; break;
51801 	}
51802 
51803   return(iret);
51804 }
51805 
exit_casel()51806 void exit_casel()
51807 {
51808 	DisDir = 0;
51809 	DisAmino = -1;
51810 	CurAmino = -1;
51811 	update_casel = 0;
51812 	strcpy(molwstr,"Exiting Amino Acid range select");
51813 	StatusStr(0,1);
51814 }
51815 
motion_screen(inct,incp)51816 void motion_screen(inct,incp)
51817 int *inct;
51818 int *incp;
51819 {
51820 
51821    if (expldat.active) return;
51822 
51823    if (event.xmotion.window == win) {
51824 
51825       while(XCheckTypedWindowEvent(display, win, MotionNotify,&event));
51826 
51827       if ( *ball && (moving || gmoving)) {
51828         update_model = 0;
51829 	if (XCheckMaskEvent(display,ButtonReleaseMask,&event)) {
51830 	   if ((*fancy || *fullgl) && has_opengl)
51831 		motion(event.xmotion.x, event.xmotion.y, 1);
51832 	   moving = 0;
51833 	} else {
51834 	   while (XCheckMaskEvent(display,ButtonMotionMask,&event));
51835 	   *incp = (event.xmotion.x - startx);
51836 	   if (btype == 0) {
51837 		*inct = 421;
51838 	   } else if (btype == 1) {
51839 		*inct = 415;
51840 	   } else if (btype == 2) {
51841 		*inct = 417;
51842 	   } else if (btype == 3) {
51843 		*inct = 422;
51844 	   }
51845 	   doclr();
51846 #if defined(VMS) || defined(UNDERSC)
51847 	   mktrn(inct,incp);
51848 #else
51849 #ifdef CRAY
51850        	   MKTRN(inct,incp);
51851 #else
51852        	   mktrn_(inct,incp);
51853 #endif
51854 #endif
51855 	   *incp = (event.xmotion.y - starty);
51856 	   if (btype == 0) {
51857 		*inct = -421;
51858 	   } else if (btype == 1) {
51859 		*inct = 416;
51860 	   }
51861 
51862 #if defined(VMS) || defined(UNDERSC)
51863 	   mktrn(inct,incp);
51864            if ((*fancy || *fullgl) && has_opengl)
51865 		motion(event.xmotion.x, event.xmotion.y, 0);
51866 	   else qupd();
51867 #else
51868 #ifdef CRAY
51869        	   MKTRN(inct,incp);
51870 	   if ((*fancy || *fullgl) && has_opengl)
51871 		motion(event.xmotion.x, event.xmotion.y, 0);
51872 	   else QUPD();
51873 #else
51874            mktrn_(inct,incp);
51875 	   if ((*fancy || *fullgl) && has_opengl)
51876 		motion(event.xmotion.x, event.xmotion.y, 0);
51877 	   else qupd_();
51878 #endif
51879 #endif
51880 	   startx = event.xmotion.x;
51881 	   starty = event.xmotion.y;
51882 	   *inct = 0;
51883 	   XFlush(display);
51884 	   if (!expldat.active) XSync(display, False);
51885 	}
51886    } else {
51887 	int Ca;
51888 
51889 	if (!ZoomSelection && !denmode) {
51890 
51891 	     if (*ipdbon) {
51892 
51893 	        if (*fancy || *fullgl) {
51894 		   if (update_casel) {
51895 			Ca = FindCa(xyzp->iaton,xyzp->iyp,xyzp->ixp,
51896 			event.xmotion.x,event.xmotion.y,MINDIFF);
51897 
51898 			if (Ca >= 0 && DisDir == 0) {
51899 			   if (!calfptr->reson[Ca]) {
51900 				if (Ca + 2  == DisAmino) DisDir = -1;
51901 				if (Ca == DisAmino) DisDir = 1;
51902 			   }
51903 			}
51904 
51905 			if (Ca >= 0 && DisDir != 0) {
51906 			   if (Ca+1  == DisAmino + DisDir) {
51907 			      if (calfptr->reson[Ca]) {
51908 				exit_casel();
51909 				Ca = -1;
51910 			      }
51911 			   }
51912 			}
51913 
51914 			if (Ca >= 0 && DisDir != 0 &&
51915 				Ca+1 == DisAmino + DisDir &&
51916 				!calfptr->reson[Ca]) {
51917 
51918 			   DisAmino = DisAmino + DisDir;
51919 #if defined(VMS) || defined(UNDERSC)
51920 			   actami(&DisAmino,&ZERO,&ONE,&ZERO);
51921 #else
51922 #ifdef CRAY
51923 			   ACTAMI(&DisAmino,&ZERO,&ONE,&ZERO);
51924 #else
51925 			   actami_(&DisAmino,&ZERO,&ONE,&ZERO);
51926 #endif
51927 #endif
51928 #ifdef DOGL
51929 			   ogsarr();
51930 			   ogres(DisAmino,ONE,1);
51931 #else
51932 			   return;
51933 #endif
51934 			}
51935 
51936 		   }
51937 		   Ca = FindCa(xyzp->iaton,xyzp->iyp,xyzp->ixp,
51938 			event.xmotion.x,event.xmotion.y,MINDIFF);
51939 
51940 		   if (Ca >= 0) {
51941 		           parse_label(Ca,0,xyzp->ixp,xyzp->iyp);
51942 		           if (OMAPup && omapfol && !omaplck) res_dens(Ca,1);
51943 		   } else {
51944 		           Ca = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
51945 				*xyzp->iatoms,
51946 				event.xmotion.x,event.xmotion.y,MINDIFF);
51947 		           if (Ca>=0) parse_labelp(xyzp->iresid[Ca]-1,Ca,
51948 				xyzp->ixp,xyzp->iyp);
51949 		           else parse_labelp(RESUND,0,xyzp->ixp,xyzp->iyp);
51950 		           if (OMAPup && omapfol && !omaplck && Ca > 0)
51951 				res_dens(Ca,0);
51952 		   }
51953 
51954 	        } else {
51955 
51956 		   if ((event.xmotion.state & ControlMask) &&
51957 		       (event.xmotion.state & ShiftMask) ) {
51958 		   } else {
51959 			Ca = FindCaP(event.xmotion.x,event.xmotion.y,MINDIFF);
51960 
51961 			if (Ca >= 0) {
51962 			   parse_labelp(Ca,0,xyzp->ixp,xyzp->iyp);
51963 			} else {
51964 		   	   Ca = FindSel(xyzp->iaton,xyzp->iyp,xyzp->ixp,0,
51965 				*xyzp->iatoms,
51966 				event.xmotion.x,event.xmotion.y,MINDIFF);
51967 		   	   if (Ca>=0) parse_labelp(xyzp->iresid[Ca]-1,Ca,
51968 				xyzp->ixp,xyzp->iyp);
51969 		   	   else parse_labelp(RESUND,0,xyzp->ixp,xyzp->iyp);
51970 			}
51971 		   }
51972 	        }
51973 	     }
51974 
51975 	}
51976       }
51977    }
51978 
51979 }
51980 
ressel()51981 void ressel()
51982 {
51983       int i,j,ires;
51984 
51985 
51986 	for (ires = 1; ires < calfptr->ncalf+1; ires++ ) {
51987 	   if (calfptr->iams[ires-1]) {
51988 #if defined(VMS) || defined(UNDERSC)
51989 		getpdb(&ires,ipdb,ihpdb);
51990 #else
51991 #ifdef CRAY
51992 		GETPDB(&ires,ipdb,ihpdb);
51993 #else
51994 		getpdb_(&ires,ipdb,ihpdb);
51995 #endif
51996 #endif
51997 		for (i=0; i<MXSYM; i++) {
51998 		   if (ipdb[i] > 0) xyzp->iaton[ipdb[i]-1] = 2;
51999 		}
52000 
52001 		for (i=0; i<3*MXHSYM; i++) {
52002 		   if (ihpdb[i] > 0) xyzp->iaton[ihpdb[i]-1] = 2;
52003 		}
52004 	   }
52005 
52006 	}
52007 }
52008 
clrsave()52009 void clrsave()
52010 {
52011    int i;
52012 
52013    for (i=0; i<count; i++)
52014 	if (savecom[i].points != NULL) {
52015 	    free(savecom[i].points);
52016 	    savecom[i].points = NULL;
52017 	}
52018    cnt = 0;
52019    count = 0;
52020    scount = 0;
52021 }
52022 
52023 #if defined(VMS) || defined(UNDERSC)
setsup()52024 void setsup()
52025 #else
52026 #ifdef CRAY
52027 void SETSUP()
52028 #else
52029 void setsup_()
52030 #endif
52031 #endif
52032 {
52033    update_sel = 1;
52034 }
52035 
52036 static FILE *out;
52037 static int dowrt = 0;
52038 #define MAXNAM 512
52039 static char ogfil[MAXNAM];
52040 static double z0[] = {0.0,0.0,0.0};
52041 static double zx[] = {1.0,0.0,0.0};
52042 static double zy[] = {0.0,1.0,0.0};
52043 
launchViewer(opt)52044 void launchViewer(opt)
52045 int opt;
52046 {
52047     int pid;
52048 
52049 #ifdef DARWIN
52050     pid = fork();
52051 #else
52052     pid = vfork();
52053 #endif
52054     switch(pid) {
52055     case -1:
52056           fprintf(stderr,"Couldnt Fork\n");
52057           break;
52058     case 0:       /*child */
52059 #ifdef __CYGWIN__
52060 	  if (opt) {
52061              execlp("./mogl","mogl","-r","-b","0",ogfil,NULL);
52062 	  } else {
52063              execlp("./mogl","mogl",ogfil,NULL);
52064 	  }
52065 #else
52066 	  if (opt) {
52067              execlp("moldenogl","moldenogl","-r","-b","0",ogfil,NULL);
52068 	  } else {
52069              execlp("moldenogl","moldenogl",ogfil,NULL);
52070 	  }
52071 #endif
52072 	  _exit(0);
52073           break;
52074     default:      /*parent*/
52075           break;
52076     }
52077 }
52078 
52079 #if defined(VMS) || defined(UNDERSC)
oginsp(double * r,double * adjus,int * natoms,int * nat,int * iatclr,int * icol,double * xsym,double * ysym,double * zsym,double * vdwr,int * mopt,int * conn,int * nconn,int * iconn,int * ofil)52080 void oginsp(double *r, double *adjus, int *natoms, int *nat, int *iatclr, int *icol,
52081 #else
52082 #ifdef CRAY
52083 void OGINSP(double *r, double *adjus, int *natoms, int *nat, int *iatclr, int *icol,
52084 #else
52085 void oginsp_(double *r, double *adjus, int *natoms, int *nat, int *iatclr, int *icol,
52086 #endif
52087 #endif
52088 
52089        double *xsym, double *ysym, double *zsym, double *vdwr,
52090        int *mopt, int *conn, int *nconn, int *iconn, int *ofil)
52091 {
52092 
52093     dowrt = 1;
52094     out = fopen(ogfil,"w");
52095 
52096     if (out == NULL) {
52097           fprintf(stderr,"Unable to open file %s\n",ogfil);
52098 	  dowrt = 0;
52099 	  return;
52100     }
52101 
52102     fprintf(out,"[MOLDENOGL]\n");
52103     ogwrmol(r,adjus,natoms,nat,xsym,ysym,zsym,vdwr);
52104 
52105 }
52106 
52107 #if defined(VMS) || defined(UNDERSC)
ognorm(double * v1,double * v2,double * v3)52108 void ognorm(double *v1, double *v2, double *v3)
52109 #else
52110 #ifdef CRAY
52111 void OGNORM(double *v1, double *v2, double *v3)
52112 #else
52113 void ognorm_(double *v1, double *v2, double *v3)
52114 #endif
52115 #endif
52116 {
52117     if (dowrt) fprintf(out,"%f %f %f\n",*v1,*v2,*v3);
52118 }
52119 
52120 #if defined(VMS) || defined(UNDERSC)
ogvert(double * v1,double * v2,double * v3)52121 void ogvert(double *v1, double *v2, double *v3)
52122 #else
52123 #ifdef CRAY
52124 void OGVERT(double *v1, double *v2, double *v3)
52125 #else
52126 void ogvert_(double *v1, double *v2, double *v3)
52127 #endif
52128 #endif
52129 {
52130     if (dowrt) fprintf(out,"%f %f %f\n",*v1,*v2,*v3);
52131 }
52132 
52133 #if defined(VMS) || defined(UNDERSC)
ogcol(double * v1,double * v2,double * v3)52134 void ogcol(double *v1, double *v2, double *v3)
52135 #else
52136 #ifdef CRAY
52137 void OGCOL(double *v1, double *v2, double *v3)
52138 #else
52139 void ogcol_(double *v1, double *v2, double *v3)
52140 #endif
52141 #endif
52142 {
52143     if (dowrt) fprintf(out,"%f %f %f\n",*v1,*v2,*v3);
52144 }
52145 
ogwrmol(double * r,double * adjus,int * natoms,int * nat,double * xsym,double * ysym,double * zsym,double * vdwr)52146 void ogwrmol(double *r, double *adjus, int *natoms, int *nat,
52147         double *xsym, double *ysym, double *zsym, double *vdwr)
52148 {
52149       int i,j,k,ia,ja,nconn;
52150       double dmaxsq, dijsq, st, tmp1[3], tmp2[3];
52151       int iconn[30];
52152 
52153       if (!dowrt) return;
52154 
52155       if (*adjus != 1.0) {
52156          fprintf(out,"[MOLECULE] AU CONN\n");
52157       } else {
52158          fprintf(out,"[MOLECULE] CONN\n");
52159       }
52160 
52161       fprintf(out,"%f %f %f\n",r[0],r[1],r[2]);
52162       fprintf(out,"%d\n",*natoms);
52163       for (i=0; i<*natoms; i++) {
52164 
52165          ia = nat[i];
52166 	 tmp1[0] = -1.0 * ysym[i] / r[0];
52167 	 tmp1[1] = -1.0 * xsym[i] / r[0];
52168 	 tmp1[2] = -1.0 * zsym[i] / r[0];
52169 
52170 
52171          nconn = 0;
52172          for (j=0; j<*natoms; j++) {
52173 
52174             ja = nat[j];
52175 	    tmp2[0] = -1.0 * ysym[j] / r[0];
52176 	    tmp2[1] = -1.0 * xsym[j] / r[0];
52177 	    tmp2[2] = -1.0 * zsym[j] / r[0];
52178 
52179             dmaxsq = (vdwr[ia] + vdwr[ja]);
52180             dmaxsq = dmaxsq * dmaxsq;
52181 
52182             dijsq = 0.0;
52183 
52184             st = (xsym[i] - xsym[j])*(*adjus);
52185 	    st *= st;
52186 	    dijsq = dijsq + st;
52187 
52188 	    st = (ysym[i] - ysym[j])*(*adjus);
52189 	    st *= st;
52190 	    dijsq = dijsq + st;
52191 
52192 	    st = (zsym[i] - zsym[j])*(*adjus);
52193 	    st *= st;
52194 	    dijsq = dijsq + st;
52195 
52196             if (i != j && dijsq < dmaxsq) {
52197 		iconn[nconn] = j+1;
52198 		nconn++;
52199             }
52200 
52201          }
52202          fprintf(out,"%d %f %f %f %d",nat[i],xsym[i],ysym[i],zsym[i],nconn);
52203 	 for (k=0; k<nconn; k++)
52204 	   fprintf(out," %d",iconn[k]);
52205          fprintf(out,"\n");
52206       }
52207 
52208 }
52209 
52210 #if defined(VMS) || defined(UNDERSC)
oginid(double * r,double * adjus,int * natoms,int * nat,int * icol,double * xsym,double * ysym,double * zsym,double * vdwr,double * cnst,int * nnpts1,int * nnpts2,int * iorb,double * dens)52211 void oginid(double *r, double *adjus, int *natoms, int *nat, int *icol,
52212 #else
52213 #ifdef CRAY
52214 void OGINID(double *r, double *adjus, int *natoms, int *nat, int *icol,
52215 #else
52216 void oginid_(double *r, double *adjus, int *natoms, int *nat, int *icol,
52217 #endif
52218 #endif
52219        double *xsym, double *ysym, double *zsym, double *vdwr,
52220        double *cnst, int *nnpts1, int *nnpts2, int *iorb, double *dens)
52221 {
52222 
52223    dowrt = 1;
52224    out = fopen(ogfil,"w");
52225 
52226    if (out == NULL) {
52227        fprintf(stderr,"Unable to open file %s\n",ogfil);
52228        dowrt = 0;
52229        return;
52230    }
52231 
52232    fprintf(out,"[MOLDENOGL]\n");
52233    ogwrmol(r,adjus,natoms,nat,xsym,ysym,zsym,vdwr);
52234    BuildList(r,cnst,nnpts1,nnpts2,iorb,dens);
52235 
52236    if (dowrt) fclose(out);
52237    dowrt = 0;
52238 
52239    if (!has_opengl) launchViewer(1);
52240 
52241 }
52242 
52243 #if defined(VMS) || defined(UNDERSC)
ogspst()52244 void ogspst()
52245 #else
52246 #ifdef CRAY
52247 void OGSPST()
52248 #else
52249 void ogspst_()
52250 #endif
52251 #endif
52252 {
52253 
52254     if (dowrt) fclose(out);
52255     dowrt = 0;
52256 
52257     if (!has_opengl) launchViewer(1);
52258 
52259 }
52260 
52261 #if defined(VMS) || defined(UNDERSC)
parogf(str,nlen)52262 void parogf(str,nlen)
52263 #else
52264 #ifdef CRAY
52265 void PAROGF(str,nlen)
52266 #else
52267 void parogf_(str,nlen)
52268 #endif
52269 #endif
52270 
52271 #ifdef VMS
52272 struct dsc$descriptor_s *str;
52273 #else
52274 #ifdef CRAY
52275 _fcd str;
52276 #else
52277 char *str;
52278 #endif
52279 #endif
52280 int *nlen;
52281 
52282 {
52283   int i;
52284 
52285   if (*nlen >= MAXNAM) {
52286 	fprintf(stderr,"filename too long !\n");
52287 	*nlen = MAXNAM - 1;
52288   }
52289 #ifdef VMS
52290   for (i=0; i<*nlen; i++)
52291          ogfil[i] = str->dsc$a_pointer[i];
52292 #else
52293 #ifdef CRAY
52294    strncpy(ogfil,_fcdtocp(str),*nlen);
52295 #else
52296    for (i=0; i<*nlen+1; i++) ogfil[i] = '\0';
52297    strncpy(ogfil,str,*nlen);
52298 #endif
52299 #endif
52300 
52301 }
52302 
52303 #if defined(VMS) || defined(UNDERSC)
viewer()52304 void viewer()
52305 #else
52306 #ifdef CRAY
52307 void VIEWER()
52308 #else
52309 void viewer_()
52310 #endif
52311 #endif
52312 {
52313    if (!has_opengl) launchViewer(0);
52314 }
52315 
BuildList(r,cnst,nnpts1,nnpts2,iorb,dens)52316 void BuildList(r,cnst,nnpts1,nnpts2,iorb,dens)
52317 double *r;
52318 double *cnst;
52319 int *nnpts1;
52320 int *nnpts2;
52321 int *iorb;
52322 double *dens;
52323 {
52324 
52325      int i,j,noff1,noff2,npts1,npts2;
52326      double v[3], rpts;
52327      double vec1[3], vn1[3];
52328      float hinv1,hinv2;
52329 
52330 /*
52331      a grid of n*n points has n-1*n-1 squares
52332      and twice as much triangular polygons
52333      so 2*(npts-1)**2
52334      npts is 80 at maximum so lets make it 12800
52335 */
52336 
52337       npts1 = *nnpts1;
52338       npts2 = *nnpts2;
52339       noff1 = npts1/2;
52340       noff2 = npts2/2;
52341       rpts = (double) (npts1-1);
52342       hinv1 = r[1]/ (npts2*r[0]);
52343       hinv2 = 1.0/ npts1;
52344 
52345       if (dowrt) {
52346 	if (*iorb) {
52347 	   fprintf(out,"[ELEVATIONGRID] \"Orbital %d\"\n",*iorb);
52348 	} else {
52349 	   fprintf(out,"[ELEVATIONGRID] \"Density\"\n");
52350 	}
52351       }
52352 
52353       for (i=0; i<npts1-1; i++) {
52354          for (j=0; j<npts2-1; j++) {
52355 /*
52356         first triangle
52357 */
52358             vec1[0] = (double) (j-noff2);
52359             vec1[1] = (double) (i-noff1);
52360             vec1[2] = dens[j+i*npts2]*(*cnst)*rpts;
52361 
52362 	    znorm(rpts,*cnst,dens,vn1,npts1,npts2,i,j);
52363 
52364 #if defined(VMS) || defined(UNDERSC)
52365             ognorm(&vn1[0],&vn1[1],&vn1[2]);
52366 #else
52367 #ifdef CRAY
52368             OGNORM(&vn1[0],&vn1[1],&vn1[2]);
52369 #else
52370             ognorm_(&vn1[0],&vn1[1],&vn1[2]);
52371 #endif
52372 #endif
52373 
52374 	    v[0] = vec1[0]*hinv1;
52375 	    v[1] = vec1[1]*hinv2;
52376 	    v[2] = vec1[2]*hinv1;
52377 #if defined(VMS) || defined(UNDERSC)
52378 	    ogvert(&v[0],&v[1],&v[2]);
52379 #else
52380 #ifdef CRAY
52381 	    OGVERT(&v[0],&v[1],&v[2]);
52382 #else
52383 	    ogvert_(&v[0],&v[1],&v[2]);
52384 #endif
52385 #endif
52386 
52387             vec1[0] = (double) (j+1-noff2);
52388             vec1[1] = (double) (i-noff1);
52389             vec1[2] = dens[j+1+i*npts2]*(*cnst)*rpts;
52390 
52391 	    znorm(rpts,*cnst,dens,vn1,npts1,npts2,i,j+1);
52392 
52393 #if defined(VMS) || defined(UNDERSC)
52394             ognorm(&vn1[0],&vn1[1],&vn1[2]);
52395 #else
52396 #ifdef CRAY
52397             OGNORM(&vn1[0],&vn1[1],&vn1[2]);
52398 #else
52399             ognorm_(&vn1[0],&vn1[1],&vn1[2]);
52400 #endif
52401 #endif
52402 
52403 	    v[0] = vec1[0]*hinv1;
52404 	    v[1] = vec1[1]*hinv2;
52405 	    v[2] = vec1[2]*hinv1;
52406 #if defined(VMS) || defined(UNDERSC)
52407 	    ogvert(&v[0],&v[1],&v[2]);
52408 #else
52409 #ifdef CRAY
52410 	    OGVERT(&v[0],&v[1],&v[2]);
52411 #else
52412 	    ogvert_(&v[0],&v[1],&v[2]);
52413 #endif
52414 #endif
52415 
52416             vec1[0] = (double) (j+1-noff2);
52417             vec1[1] = (double) (i+1-noff1);
52418             vec1[2] = dens[j+1+(i+1)*npts2]*(*cnst)*rpts;
52419 
52420 	    znorm(rpts,*cnst,dens,vn1,npts1,npts2,i+1,j+1);
52421 
52422 #if defined(VMS) || defined(UNDERSC)
52423             ognorm(&vn1[0],&vn1[1],&vn1[2]);
52424 #else
52425 #ifdef CRAY
52426             OGNORM(&vn1[0],&vn1[1],&vn1[2]);
52427 #else
52428             ognorm_(&vn1[0],&vn1[1],&vn1[2]);
52429 #endif
52430 #endif
52431 
52432 	    v[0] = vec1[0]*hinv1;
52433 	    v[1] = vec1[1]*hinv2;
52434 	    v[2] = vec1[2]*hinv1;
52435 #if defined(VMS) || defined(UNDERSC)
52436 	    ogvert(&v[0],&v[1],&v[2]);
52437 #else
52438 #ifdef CRAY
52439 	    OGVERT(&v[0],&v[1],&v[2]);
52440 #else
52441 	    ogvert_(&v[0],&v[1],&v[2]);
52442 #endif
52443 #endif
52444 
52445             vec1[0] = (double) (j-noff2);
52446             vec1[1] = (double) (i+1-noff1);
52447             vec1[2] = dens[j+(i+1)*npts2]*(*cnst)*rpts;
52448 
52449 	    znorm(rpts,*cnst,dens,vn1,npts1,npts2,i+1,j);
52450 
52451 #if defined(VMS) || defined(UNDERSC)
52452             ognorm(&vn1[0],&vn1[1],&vn1[2]);
52453 #else
52454 #ifdef CRAY
52455             OGNORM(&vn1[0],&vn1[1],&vn1[2]);
52456 #else
52457             ognorm_(&vn1[0],&vn1[1],&vn1[2]);
52458 #endif
52459 #endif
52460 
52461 	    v[0] = vec1[0]*hinv1;
52462 	    v[1] = vec1[1]*hinv2;
52463 	    v[2] = vec1[2]*hinv1;
52464 #if defined(VMS) || defined(UNDERSC)
52465 	    ogvert(&v[0],&v[1],&v[2]);
52466 #else
52467 #ifdef CRAY
52468 	    OGVERT(&v[0],&v[1],&v[2]);
52469 #else
52470 	    ogvert_(&v[0],&v[1],&v[2]);
52471 #endif
52472 #endif
52473 
52474          }
52475       }
52476 
52477 
52478 }
52479 
crossprd(v1,v2,d)52480 void crossprd(v1,v2,d)
52481 double *v1;
52482 double *v2;
52483 double *d;
52484 {
52485 /*
52486 
52487        calculates cross product:  (v1) x (v2) = d
52488                                    ---     ---    -
52489 */
52490       int i;
52491       double dlen;
52492 
52493       d[0] = v2[1]*v1[2]-v2[2]*v1[1];
52494       d[1] = v2[2]*v1[0]-v2[0]*v1[2];
52495       d[2] = v2[0]*v1[1]-v2[1]*v1[0];
52496       dlen = sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]);
52497 
52498       if (dlen > 0 ) for (i=0; i<3; i++) d[i] = d[i] / dlen;
52499 }
52500 
CROSS(v1,v2,v3)52501 void CROSS(v1,v2,v3)
52502 double *v1;
52503 double *v2;
52504 double *v3;
52505 {
52506 
52507       v3[0] = v2[1]*v1[2]-v2[2]*v1[1];
52508       v3[1] = v2[2]*v1[0]-v2[0]*v1[2];
52509       v3[2] = v2[0]*v1[1]-v2[1]*v1[0];
52510 
52511 }
52512 
improduct(double * a,double * b,double * c)52513 void improduct(double *a, double *b, double *c)
52514 {
52515       int i;
52516 
52517       *c = 0.0;
52518 
52519       for (i=0; i<3; i++) *c = *c + a[i]*b[i];
52520 }
52521 
crpsin(a,b,c,d)52522 void crpsin(a,b,c,d)
52523 double *a;
52524 double *b;
52525 double *c;
52526 double *d;
52527 {
52528 /*
52529 
52530        calculates cross product:  (b-a) x (c-a) = d
52531                                    ---     ---    -
52532 */
52533       int i;
52534       double v1[3],v2[3],dlen;
52535 
52536       for (i=0; i<3; i++) {
52537          v1[i] = b[i]-a[i];
52538          v2[i] = c[i]-a[i];
52539       }
52540 
52541       d[0] = v2[1]*v1[2]-v2[2]*v1[1];
52542       d[1] = v2[2]*v1[0]-v2[0]*v1[2];
52543       d[2] = v2[0]*v1[1]-v2[1]*v1[0];
52544       dlen = sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]);
52545 
52546       if (dlen > 0 ) for (i=0; i<3; i++) d[i] = d[i] / dlen;
52547 }
52548 
vln(double * a)52549 double vln( double *a)
52550 {
52551       double vl;
52552       double tot;
52553 
52554       tot = a[0]*a[0]+a[1]*a[1]+a[2]*a[2];
52555 
52556       vl = 0.0;
52557       if (tot > 0.0) vl = sqrt(tot);
52558 
52559       return(vl);
52560 
52561 }
52562 
znorm(double rpts,double cnst,double * dens,double * vn,int npts1,int npts2,int i,int j)52563 void znorm(double rpts, double cnst, double *dens, double *vn,
52564 	   int npts1, int npts2, int i, int j)
52565 {
52566      double vl,z1[3],z2[3],z3[3],nx[3],ny[3];
52567      int k;
52568 
52569      if (j+1 < npts2) {
52570          z1[0] = 1.0; z1[1] = 0.0;
52571          z1[2] = cnst*rpts*(dens[j+1+i*npts2]-dens[j+i*npts2]);
52572          crpsin(z0,z1,zy,z2);
52573      } else {
52574          for (k=0; k<3; k++) z2[k] = z0[k];
52575      }
52576 
52577      if (j-1 >= 0) {
52578          z1[0] = -1.0; z1[1] = 0.0;
52579          z1[2] = cnst*rpts*(dens[j-1+i*npts2]-dens[j+i*npts2]);
52580          crpsin(z0,zy,z1,z3);
52581      } else {
52582          for (k=0; k<3; k++) z3[k] = z0[k];
52583      }
52584 
52585      for (k=0; k<3; k++) nx[k] = z3[k] + z2[k];
52586      vl = vln(nx);
52587      for (k=0; k<3; k++) nx[k] = nx[k] / vl;
52588 
52589      if (i+1 < npts1) {
52590          z1[0] = 0.0; z1[1] = 1.0;
52591          z1[2] = cnst*rpts*(dens[j+(i+1)*npts2]-dens[j+i*npts2]);
52592          crpsin(z0,z1,zx,z2);
52593      } else {
52594          for (k=0; k<3; k++) z2[k] = z0[k];
52595      }
52596 
52597      if (i-1 >= 0) {
52598          z1[0] = 0.0; z1[1] = -1.0;
52599          z1[2] = cnst*rpts*(dens[j+(i-1)*npts2]-dens[j+i*npts2]);
52600          crpsin(z0,zx,z1,z3);
52601      } else {
52602          for (k=0; k<3; k++) z3[k] = z0[k];
52603      }
52604 
52605      for (k=0; k<3; k++) ny[k] = z3[k] + z2[k];
52606      vl = vln(ny);
52607      for (k=0; k<3; k++) ny[k] = ny[k] / vl;
52608 
52609      for (k=0; k<3; k++) vn[k] = ny[k] - nx[k];
52610      vl = vln(vn);
52611      for (k=0; k<3; k++) vn[k] = vn[k] / vl;
52612 
52613 }
52614 
52615 #if defined(VMS) || defined(UNDERSC)
initog(int * iwrt)52616 void initog(int *iwrt)
52617 #else
52618 #ifdef CRAY
52619 void INITOG(int *iwrt)
52620 #else
52621 void initog_(int *iwrt)
52622 #endif
52623 #endif
52624 {
52625  int i;
52626 
52627  /* just dummy */
52628 
52629   i = *iwrt;
52630 
52631 }
52632 
52633 #if defined(VMS) || defined(UNDERSC)
ogbeg(isurf,iorb,cntval)52634 void ogbeg(isurf,iorb,cntval)
52635 #else
52636 #ifdef CRAY
52637 void OGBEG(isurf,iorb,cntval)
52638 #else
52639 void ogbeg_(isurf,iorb,cntval)
52640 #endif
52641 #endif
52642 int *isurf;
52643 int *iorb;
52644 double *cntval;
52645 {
52646       int surf,surfabs;
52647       double cval;
52648 
52649       if (!dowrt) return;
52650 
52651       surf = *isurf;
52652       surfabs = abs(surf);
52653 
52654       cval = *cntval;
52655       if (surfabs == 2) cval = cval * -1.0;
52656 
52657       if (surfabs == 3) {
52658 	   fprintf(out,"[SURFACE] MAPPED \"Density %3d isocontour %7.4f\"\n",*iorb,cval);
52659       } else {
52660 	if (surf<0) {
52661 	   fprintf(out,"[SURFACE] TRANS COLOR 1.0 1.0 0.0 \"Density %3d isocontour %7.4f\"\n",*iorb,cval);
52662 	} else {
52663 	   fprintf(out,"[SURFACE] \"Orbital %3d isocontour %7.4f\"\n",*iorb,cval);
52664 	}
52665       }
52666 
52667 }
52668 
52669 #if defined(VMS) || defined(UNDERSC)
ogend()52670 void ogend()
52671 #else
52672 #ifdef CRAY
52673 void OGEND()
52674 #else
52675 void ogend_()
52676 #endif
52677 #endif
52678 {
52679       int i;
52680 
52681       i = 0;
52682 }
52683 
52684 
initnthe()52685 void initnthe()
52686 {
52687    int i,j;
52688 
52689    for (i=0; i<MAXSTRUCT; i++) scl[i] = 1.0;
52690 }
52691 
dveclen(double * a)52692 double dveclen(double *a)
52693 {
52694       double vl;
52695       double tot;
52696 
52697       tot = a[0]*a[0]+a[1]*a[1]+a[2]*a[2];
52698 
52699       vl = 0.0;
52700       if (tot > 0.0) vl = (double) sqrt(tot);
52701 
52702       return(vl);
52703 
52704 }
52705 
getusr(tmps)52706 int getusr(tmps)
52707 char* tmps;
52708 {
52709 
52710    char *tmpf;
52711    int i,j,status;
52712 
52713    strcpy(tmps,"");
52714    tmpf = getenv("APPDATA");
52715    if (tmpf != NULL) {
52716 	strcat(tmps,tmpf);
52717 	j = strlen(tmps);
52718 	for (i=0; i<j; i++)
52719 	   if (tmps[i] == '\\') tmps[i] = '/';
52720 	strcat(tmps,"/Molden");
52721 	if (access(tmps,F_OK) != 0) {
52722 	    status = mkdir(tmps, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
52723 	    if (status == -1) {
52724 		fprintf(stderr,"Directory %s not created\n",tmps);
52725 		return(0);
52726 	    }
52727 	}
52728 	strcat(tmps,"/srf");
52729    }
52730    return(1);
52731 }
52732 
52733 #ifdef DOGL
52734 
52735 #ifndef __glut_h__
52736 /* Mouse buttons. */
52737 #define GLUT_LEFT_BUTTON                0
52738 #define GLUT_MIDDLE_BUTTON              1
52739 #define GLUT_RIGHT_BUTTON               2
52740 
52741 /* Mouse button  state. */
52742 #define GLUT_DOWN                       0
52743 #define GLUT_UP                         1
52744 
52745 /* glutGetModifiers return mask. */
52746 #define GLUT_ACTIVE_SHIFT               1
52747 #define GLUT_ACTIVE_CTRL                2
52748 #define GLUT_ACTIVE_ALT                 4
52749 
52750 #endif
52751 
52752 #define TRDEF 0.6
52753 
52754 static float ribcol[7][4] =
52755 {
52756   {0.0,0.0,1.0,0.6},
52757   {1.0,0.0,1.0,0.6},
52758   {0.0,1.0,0.0,0.6},
52759   {0.6,0.6,0.6,0.6},
52760   {0.5,1.0,0.5,0.6},
52761   {1.0,1.0,1.0,0.6},
52762   {1.0,0.5,0.5,0.6}
52763 };
52764 
52765 static int started_ogl = 0;
52766 static int ecol = 2;
52767 static int gbgcol = 6;
52768 static double tr_val = TRDEF;
52769 static int hires = 1;
52770 static int perspon = 1;
52771 static int lines = 0;
52772 static int PERSP = 0;
52773 static int AXES = 0;
52774 static int l1on = 0;
52775 static int l2on = 0;
52776 static int l3on = 1;
52777 static int stacks = 10;
52778 static int DoCap = 0;
52779 static GLfloat fdens = 0.03;
52780 static int DoLights = 0;
52781 static int DoNorms = 0;
52782 static int ColBG = -1;
52783 
52784 /* Some <math.h> files do not define M_PI... */
52785 #ifndef M_PI
52786 #define M_PI 3.141592654
52787 #endif
52788 #define TORAD M_PI/180.0
52789 
52790 static float materialColor[8][4] =
52791 {
52792   {0.8, 0.8, 0.8, 1.0},
52793   {0.8, 0.0, 0.0, 1.0},
52794   {0.0, 0.8, 0.0, 1.0},
52795   {0.0, 0.0, 0.8, 1.0},
52796   {0.0, 0.8, 0.8, 1.0},
52797   {0.8, 0.0, 0.8, 1.0},
52798   {0.8, 0.8, 0.0, 1.0},
52799   {1.0, 0.5, 0.5, 1.0},
52800 };
52801 
52802 static float AmbientNul[4] = {0.1,0.1,0.1,0.0};
52803 
52804 static float light0_position[MAXSTRUCT][4];
52805 static float light1_position[MAXSTRUCT][4];
52806 static float light2_position[MAXSTRUCT][4];
52807 static float light0_position_def[] = {-2.0, -2.0, 0.0, 1.0};
52808 static float light1_position_def[] = {4.0, 4.0, 4.0, 1.0};
52809 static float light2_position_def[] = {0.0, 0.0, 4.0, 1.0};
52810 
52811 static int molon = 1;
52812 static int AmbAndDiff = 0;
52813 static int mmoving = 0;
52814 static int mstartx, mstarty;
52815 
52816 static int smoving = 0;
52817 static int sstarty;
52818 
52819 #define MXMOL 1000
52820 static GLuint theSurf[MAXSTRUCT][MAXSURF];
52821 static GLuint theMol[MAXSTRUCT][MXMOL];
52822 static GLuint theLines[MAXSTRUCT];
52823 static GLuint theFLines[MAXSTRUCT];
52824 static GLuint thePoints[MAXSTRUCT];
52825 static GLuint theForces[MAXSTRUCT];
52826 static GLuint theSArrow[MAXSTRUCT];
52827 static GLuint theFeat[MAXSTRUCT];
52828 static GLuint theAFeat[MAXSTRUCT];
52829 static GLuint theDipole[MAXSTRUCT];
52830 static GLuint theIntSurf[MAXSTRUCT];
52831 static GLuint theIntSurf2[MAXSTRUCT];
52832 static GLuint theLigSurf[MAXSTRUCT];
52833 static GLuint theBox[MAXSTRUCT];
52834 static GLuint theNorm;
52835 static GLuint theAxes;
52836 static GLuint theBack;
52837 static GLuint theElem_20[MXEL];
52838 static GLuint theElem_20_bs[MXEL];
52839 static GLuint theElem_12[MXEL];
52840 static GLuint theElem_12_bs[MXEL];
52841 static GLuint theElsm;
52842 static GLuint theRes[MAXSTRUCT][NUMCAL];
52843 static GLuint theBck[MAXSTRUCT][NUMCAL];
52844 static GLuint theMon[MAXSTRUCT];
52845 static GLuint theSel[MAXSTRUCT];
52846 static GLUquadricObj *cyl;
52847 static GLUquadricObj *sphere;
52848 static GLUquadricObj *disk;
52849 
52850 #define ROTINCR 5.0
52851 static GLfloat xrot = -45.0;
52852 static GLfloat yrot = 240.0;
52853 
ResetRes()52854 void ResetRes()
52855 {
52856    int j;
52857 
52858    for (j=0; j<NUMCAL; j++) {
52859         glDeleteLists(theRes[istruct][j],1);
52860 	theRes[istruct][j] = -1;
52861 	theBck[istruct][j] = -1;
52862    }
52863 }
52864 
MoveOne(i)52865 void MoveOne(i)
52866 int i;
52867 {
52868 	int j,k;
52869 
52870 	SSdone[i]    = SSdone[i+1];
52871 	NSurf[i]     = NSurf[i+1];
52872 	NMols[i]     = NMols[i+1];
52873 	CMols[i]     = CMols[i+1];
52874 
52875 	theLines[i]  = theLines[i+1];
52876 	theFLines[i] = theFLines[i+1];
52877 	thePoints[i] = thePoints[i+1];
52878 	theForces[i] = theForces[i+1];
52879 	theSArrow[i] = theSArrow[i+1];
52880 	theFeat[i]   = theFeat[i+1];
52881 	theAFeat[i]  = theAFeat[i+1];
52882 	theDipole[i] = theDipole[i+1];
52883 	theIntSurf[i] = theIntSurf[i+1];
52884 	theIntSurf2[i] = theIntSurf2[i+1];
52885 	theLigSurf[i] = theLigSurf[i+1];
52886 	theBox[i]    = theBox[i+1];
52887 	theMon[i]    = theMon[i+1];
52888 	theSel[i]    = theSel[i+1];
52889 
52890 	for (j=0;j < MAXSURF;j++) {
52891 	   theSurf[i][j] = theSurf[i+1][j];
52892 	   SSon[i][j]    = SSon[i+1][j];
52893 	   SStyp[i][j]   = SStyp[i+1][j];
52894 	   Schain[i][j]   = Schain[i+1][j];
52895 	   sndstr[i][j]  = sndstr[i+1][j];
52896 	   srfvert[i][j] = srfvert[i+1][j];
52897 	   clp[i][j]    = clp[i+1][j];
52898 	   trns[i][j]    = trns[i+1][j];
52899 	   for (k=0;k < 4;k++)
52900 		diffuseColor[i][j][k] = diffuseColor[i+1][j][k];
52901 	}
52902 
52903 	for (j=0;j < NUMCAL;j++) {
52904 	   theRes[i][j] = theRes[i+1][j];
52905 	   theBck[i][j] = theBck[i+1][j];
52906 	}
52907 
52908 	for (j=0;j < MAXMOL;j++)
52909 	   theMol[i][j] = theMol[i+1][j];
52910 
52911 	for (j=0;j < 4;j++) {
52912 	   light0_position[i][j] = light0_position[i+1][j];
52913 	   light1_position[i][j] = light1_position[i+1][j];
52914 	   light2_position[i][j] = light2_position[i+1][j];
52915 	}
52916 
52917 	nwater[i] = nwater[i+1];
52918 	watcoo[i] = watcoo[i+1];
52919 	watanz[i] = watanz[i+1];
52920 	watres[i] = watres[i+1];
52921 	watcon[i] = watcon[i+1];
52922 	watqat[i] = watqat[i+1];
52923 	wattyp[i] = wattyp[i+1];
52924 	watmap[i] = watmap[i+1];
52925 
52926 	RedrawSTRC();
52927 }
52928 
RibClear(ist)52929 void RibClear(ist)
52930 int ist;
52931 {
52932    int j;
52933 
52934    for (j=0; j<4; j++) {
52935 	RIBindex[ist].start[j] = -1;
52936 	RIBindex[ist].end[j] = -1;
52937    }
52938 
52939    RIBindex[ist].nhelx = 0;
52940    RIBindex[ist].nbeta = 0;
52941    RIBindex[ist].nrna = 0;
52942    RIBindex[ist].ncoil = 0;
52943 }
52944 
initOne(i)52945 void initOne(i)
52946 int i;
52947 {
52948    int j,k;
52949 
52950    SSdone[i] = -1;
52951    NSurf[i] = 0;
52952    NMols[i] = -1;
52953    CMols[i] = 0;
52954    theLines[i] = -1;
52955    theFLines[i] = -1;
52956    thePoints[i] = -1;
52957    theForces[i] = -1;
52958    theSArrow[i] = -1;
52959    theFeat[i]   = -1;
52960    theAFeat[i]  = -1;
52961    theDipole[i] = -1;
52962    theIntSurf[i] = -1;
52963    theIntSurf2[i] = -1;
52964    theLigSurf[i] = -1;
52965 
52966    for (j=0; j<4; j++) {
52967       light0_position[i][j] = light0_position_def[j];
52968       light1_position[i][j] = light1_position_def[j];
52969       light2_position[i][j] = light2_position_def[j];
52970    }
52971    for (j=0; j<MAXSURF; j++) {
52972 	theSurf[i][j] = -1;
52973 	sndstr[i][j] = NULL;
52974 	srfvert[i][j] = NULL;
52975 	nvert[i][j] = 0;
52976 	nvrtmx[i][j] = 0;
52977 	Schain[i][j] = -1;
52978 	clp[i][j] = 0;
52979 	trns[i][j] = 0;
52980 	for (k=0; k<4; k++) {
52981 	   diffuseColor[i][j][k] = diffColor[j][k];
52982 	   specularColor[j][k] = specColor[k];
52983 	}
52984    }
52985    for (j=0; j<MAXMOL; j++) theMol[i][j] = -1;
52986    for (j=0; j<NUMCAL; j++) {
52987       theRes[i][j] = -1;
52988       theBck[i][j] = -1;
52989    }
52990 
52991    RibClear(i);
52992 
52993    nwater[i] = 0;
52994    watcoo[i] = NULL;
52995    watanz[i] = NULL;
52996    watres[i] = NULL;
52997    watcon[i] = NULL;
52998    watqat[i] = NULL;
52999    wattyp[i] = NULL;
53000    watmap[i] = NULL;
53001 }
53002 
initthe()53003 void initthe()
53004 {
53005    int i;
53006 
53007    for (i=0; i<MAXSTRUCT; i++) initOne(i);
53008 }
53009 
deletebox()53010 void deletebox()
53011 {
53012    if (theBox[istruct] > 0)
53013 	glDeleteLists(theBox[istruct],1);
53014    theBox[istruct] = -1;
53015 }
53016 
srfprop()53017 void srfprop()
53018 {
53019 	SetSurfColor(omapsrf,7);
53020         clp[istruct][omapsrf] = 1;
53021 	trns[istruct][omapsrf] = 1;
53022 	if (omapPandN) {
53023 	   trns[istruct][omapsrf] = 0;
53024 	   SetSurfColor(omapsrf,6);
53025 	   SetSurfColor(omapsrf+1,5);
53026            clp[istruct][omapsrf+1] = 1;
53027 	   trns[istruct][omapsrf+1] = 0;
53028 	}
53029 	TRANS = 0;
53030 }
53031 
DeleteSurface(isrf)53032 void DeleteSurface(isrf)
53033 int isrf;
53034 {
53035    int i,j,k,NStmp;
53036 
53037 
53038    if (omapsrf < 0) return;
53039 
53040    NStmp = NSurf[istruct];
53041 
53042    glDeleteLists(theSurf[istruct][isrf],1);
53043    free(sndstr[istruct][isrf]);
53044    free(srfvert[istruct][isrf]);
53045 
53046    for (j=0; j<4; j++) {
53047 	if (isrf < RIBindex[istruct].start[j]) {
53048 			RIBindex[istruct].start[j]--;
53049 			RIBindex[istruct].end[j]--;
53050 	} else if (isrf >= RIBindex[istruct].start[j]
53051 		        && isrf <= RIBindex[istruct].end[j]) {
53052 			RIBindex[istruct].end[j]--;
53053 			if (RIBindex[istruct].start[j] ==
53054 				RIBindex[istruct].end[j]) {
53055 			   RIBindex[istruct].start[j] = -1;
53056 			   RIBindex[istruct].end[j] = -1;
53057 			}
53058 	}
53059 
53060    }
53061 
53062    for (j=isrf; j<NSurf[istruct]-1; j++) {
53063 	for (k=0; k<3; k++)
53064 	   diffuseColor[istruct][j][k] = diffuseColor[istruct][j+1][k];
53065 	theSurf[istruct][j] = theSurf[istruct][j+1];
53066 	SSon[istruct][j] = SSon[istruct][j+1];
53067 	clp[istruct][j] = clp[istruct][j+1];
53068 	trns[istruct][j] = trns[istruct][j+1];
53069 	SStyp[istruct][j] = SStyp[istruct][j+1];
53070 	Schain[istruct][j] = Schain[istruct][j+1];
53071 	sndstr[istruct][j] = sndstr[istruct][j+1];
53072 	srfvert[istruct][j] = srfvert[istruct][j+1];
53073 	nvert[istruct][j] = nvert[istruct][j+1];
53074 	nvrtmx[istruct][j] = nvrtmx[istruct][j+1];
53075    }
53076    NSurf[istruct]--;
53077    if (NSurf[istruct] < 0) NSurf[istruct] = 0;
53078 
53079 
53080    for (j=NSurf[istruct]; j < NStmp; j++) {
53081 	theSurf[istruct][j] = -1;
53082 	SSon[istruct][j] = 0;
53083 	clp[istruct][j] = 0;
53084 	trns[istruct][j] = 0;
53085 	srfvert[istruct][j] = NULL;
53086 	nvert[istruct][j] = 0;
53087 	nvrtmx[istruct][j] = 0;
53088 	sndstr[istruct][j] = NULL;
53089    }
53090 }
53091 
DeleteActiveSurfaces()53092 void DeleteActiveSurfaces()
53093 {
53094   int i,j,k,NStmp;
53095 
53096   i = 0;
53097 
53098   NStmp = NSurf[istruct];
53099 
53100   while (i<NSurf[istruct]) {
53101 
53102 	if (SSon[istruct][i]) {
53103 
53104 	   glDeleteLists(theSurf[istruct][i],1);
53105 	   free(sndstr[istruct][i]);
53106 	   free(srfvert[istruct][i]);
53107 
53108 	   for (j=0; j<4; j++) {
53109 		if (i < RIBindex[istruct].start[j]) {
53110 			RIBindex[istruct].start[j]--;
53111 			RIBindex[istruct].end[j]--;
53112 		} else if (i >= RIBindex[istruct].start[j]
53113 		        && i <= RIBindex[istruct].end[j]) {
53114 			RIBindex[istruct].end[j]--;
53115 			if (RIBindex[istruct].start[j] ==
53116 				RIBindex[istruct].end[j]) {
53117 			   RIBindex[istruct].start[j] = -1;
53118 			   RIBindex[istruct].end[j] = -1;
53119 			}
53120 		}
53121 
53122 	   }
53123 
53124 	   for (j=i; j<NSurf[istruct]-1; j++) {
53125 		for (k=0; k<3; k++)
53126 		   diffuseColor[istruct][j][k] =
53127 			 diffuseColor[istruct][j+1][k];
53128 		theSurf[istruct][j] = theSurf[istruct][j+1];
53129 		SSon[istruct][j] = SSon[istruct][j+1];
53130 		clp[istruct][j] = clp[istruct][j+1];
53131 		trns[istruct][j] = trns[istruct][j+1];
53132 		SStyp[istruct][j] = SStyp[istruct][j+1];
53133 		Schain[istruct][j] = Schain[istruct][j+1];
53134 		sndstr[istruct][j] = sndstr[istruct][j+1];
53135 		srfvert[istruct][j] = srfvert[istruct][j+1];
53136 		nvert[istruct][j] = nvert[istruct][j+1];
53137 		nvrtmx[istruct][j] = nvrtmx[istruct][j+1];
53138 	   }
53139 	   NSurf[istruct]--;
53140 	   if (NSurf[istruct] < 0) NSurf[istruct] = 0;
53141 
53142 	} else {
53143 	   i++;
53144 	}
53145   }
53146 
53147   for (j=NSurf[istruct]; j < NStmp; j++) {
53148 	theSurf[istruct][j] = -1;
53149 	SSon[istruct][j] = 0;
53150 	clp[istruct][j] = 0;
53151 	trns[istruct][j] = 0;
53152 	srfvert[istruct][j] = NULL;
53153 	nvert[istruct][j] = 0;
53154 	nvrtmx[istruct][j] = 0;
53155 	sndstr[istruct][j] = NULL;
53156   }
53157 }
53158 
bckgrad()53159 void bckgrad()
53160 {
53161 
53162     glDisable(GL_LIGHTING);
53163     glDisable(GL_DEPTH_TEST);
53164     glDepthMask(GL_FALSE);
53165 
53166     glDisable(GL_POLYGON_STIPPLE);
53167     glDisable(GL_BLEND);
53168 
53169     glMatrixMode(GL_MODELVIEW);
53170     glPushMatrix();
53171     glLoadIdentity();
53172 
53173     glMatrixMode (GL_PROJECTION);
53174     glPushMatrix();
53175     glLoadIdentity();
53176     gluOrtho2D(0.0, 1.0, 0.0, 1.0);
53177 
53178     glMatrixMode(GL_MODELVIEW);
53179     glPushMatrix();
53180     glLoadIdentity();
53181 
53182     if (StarNet) {
53183 	theBack = glGenLists(1);
53184 	glNewList(theBack, GL_COMPILE_AND_EXECUTE);
53185     }
53186 
53187     glBegin(GL_QUADS);
53188       glColor3fv(&gradcol[1][0]);
53189       glVertex2f(0.0f, 0.0f);
53190       glColor3fv(&gradcol[0][0]);
53191       glVertex2f(0.0f, 1.0f);
53192       glColor3fv(&gradcol[0][0]);
53193       glVertex2f(1.0f, 1.0f);
53194       glColor3fv(&gradcol[1][0]);
53195       glVertex2f(1.0f, 0.0f);
53196     glEnd();
53197 
53198     if (StarNet) glEndList();
53199 
53200     glPopMatrix();
53201 
53202     glMatrixMode (GL_PROJECTION);
53203     glPopMatrix();
53204 
53205     glMatrixMode(GL_MODELVIEW);
53206     glPopMatrix();
53207 
53208     glEnable(GL_DEPTH_TEST);
53209     glDepthMask(GL_TRUE);
53210     glEnable(GL_LIGHTING);
53211 }
53212 
53213 static GLuint base;
53214 
makeRasterFont(Display * dpy)53215 void makeRasterFont(Display *dpy)
53216 {
53217     Font id;
53218     GLuint first, last;
53219 
53220     if (labinfo == NULL) {
53221 	id = mfinfo->fid;
53222 	first = (GLuint) mfinfo->min_char_or_byte2;
53223 	last = (GLuint) mfinfo->max_char_or_byte2;
53224     } else {
53225 	id = labinfo->fid;
53226 	first = (GLuint) labinfo->min_char_or_byte2;
53227 	last = (GLuint) labinfo->max_char_or_byte2;
53228     }
53229 
53230     last++;
53231 
53232     base = glGenLists((GLsizei) last);
53233     if (base == 0) {
53234         fprintf(stderr,"out of display lists\n");
53235         exit(0);
53236     }
53237     glXUseXFont(id, (int) first, (int) last, (int) base);
53238 }
53239 
initPrintStrings(int front)53240 void initPrintStrings(int front)
53241 {
53242 	/*glXMakeCurrent(display,win,cx);*/
53243 	if (front) glDrawBuffer(GL_FRONT);
53244 	glDisable(GL_LIGHTING);
53245 	glDisable(GL_DEPTH_TEST);
53246 	glDepthMask(GL_FALSE);
53247 	glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
53248 
53249 	glMatrixMode( GL_PROJECTION );
53250 	glPushMatrix();
53251 	glLoadIdentity();
53252 	glMatrixMode( GL_MODELVIEW );
53253 	glPushMatrix();
53254 }
53255 
endPrintStrings()53256 void endPrintStrings()
53257 {
53258 	glPopMatrix();
53259 	glMatrixMode( GL_PROJECTION );
53260 	glPopMatrix();
53261 
53262 	glPopAttrib();
53263 
53264 	glFlush();
53265 	glDrawBuffer(GL_BACK);
53266 	glEnable(GL_DEPTH_TEST);
53267 	glDepthMask(GL_TRUE);
53268 	glEnable(GL_LIGHTING);
53269 }
53270 
printString(int x,int y,int init,char * s)53271 void printString(int x, int y, int init, char *s)
53272 {
53273    GLfloat r,g,b;
53274    glDisable(GL_FOG);
53275    if (init) initPrintStrings(1);
53276 
53277 	glLoadIdentity();
53278 
53279 	y = height  - y;
53280 
53281 	glViewport( x - 1, y - 1, 0, 0 );
53282 
53283 	r = ((GLfloat) colorr[*ifntcl]) / 65535.0 ;
53284 	g = ((GLfloat) colorg[*ifntcl]) / 65535.0 ;
53285 	b = ((GLfloat) colorb[*ifntcl]) / 65535.0 ;
53286 
53287 	glColor3f(r,g,b);
53288 	glRasterPos4f( 0, 0, 1, 1 );
53289 
53290 	glPushAttrib(GL_LIST_BIT);
53291 	glListBase((GLuint) base);
53292 	glCallLists((GLsizei) strlen(s), GL_UNSIGNED_BYTE, (unsigned *) s);
53293 	glPopAttrib();
53294 
53295    if (init) endPrintStrings();
53296    glEnable(GL_FOG);
53297 }
53298 
53299 
53300 static void
setColor(int c)53301 setColor(int c)
53302 {
53303       GLfloat ambientColor[4] = {0.0, 0.0, 0.0, 0.0};
53304       GLfloat mat_specular[4] = {0.8, 0.8, 0.8, 1.0 };
53305 
53306       glMaterialfv(GL_FRONT_AND_BACK,
53307         GL_AMBIENT, ambientColor);
53308       glMaterialfv(GL_FRONT_AND_BACK,
53309         GL_DIFFUSE, &materialColor[c][0]);
53310       glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
53311       glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 130);
53312 }
53313 
53314 
setAtomColor(int c)53315 void setAtomColor(int c)
53316 {
53317       GLfloat tmp_Color[4];
53318       int i;
53319       GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
53320 
53321       tmp_Color[0] = ((GLfloat) colorr[c+1]) / 65535.0 ;
53322       tmp_Color[1] = ((GLfloat) colorg[c+1]) / 65535.0 ;
53323       tmp_Color[2] = ((GLfloat) colorb[c+1]) / 65535.0 ;
53324       tmp_Color[3] = 0.5;
53325 
53326       if (AmbAndDiff) {
53327          glMaterialfv(GL_FRONT_AND_BACK,
53328            GL_AMBIENT_AND_DIFFUSE, tmp_Color);
53329       } else {
53330          glMaterialfv(GL_FRONT_AND_BACK,
53331            GL_AMBIENT, AmbientNul);
53332          glMaterialfv(GL_FRONT_AND_BACK,
53333            GL_DIFFUSE, tmp_Color);
53334       }
53335       glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
53336       glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100);
53337 
53338 }
53339 
53340 
ogrod(int ic,float * p1,float * p2,double rad,int hiresol,int dsk)53341 void ogrod(int ic, float *p1, float *p2, double rad, int hiresol, int dsk)
53342 {
53343       int i;
53344       double cosa;
53345       float angle, vl;
53346       float v1[3], v2[3], v3[3], p3[3];
53347       float todeg;
53348 
53349 
53350       todeg = 45.0 / atan(1.0);
53351 
53352       for (i=0; i<3; i++) {
53353          v1[i] = p2[i] - p1[i];
53354          v2[i] = 0.0;
53355          p3[i] = v1[i]/2.0 + p1[i];
53356       }
53357       v2[2] = 1.0;
53358 
53359       improd(v1,v2,&cosa);
53360 
53361       if (fabs(cosa) == 1.0) {
53362 
53363          for (i=0; i<3; i++) v3[i] = 0.0;
53364          v3[1] = 1.0;
53365          angle = 0.0;
53366 	 if (cosa < 0) angle = 180.0;
53367 
53368       } else {
53369 
53370          angle = (float) acos(cosa)*todeg;
53371          cross(v2,v1,v3);
53372          vl = veclen(v3);
53373          for (i=0; i<3; i++) v3[i] = v3[i] / vl;
53374 
53375       }
53376 
53377 
53378       glPushMatrix();
53379       glTranslatef(p1[0],p1[1],p1[2]);
53380       glRotatef(angle,v3[0],v3[1],v3[2]);
53381       setAtomColor(ic);
53382       vl = veclen(v1);
53383       if (hiresol) {
53384 	 gluCylinder( cyl, rad, rad, vl, 15, 1 );
53385       } else {
53386 	 gluCylinder( cyl, rad, rad, vl, 6, 1 );
53387 	 gluQuadricOrientation(disk, (GLenum)GLU_INSIDE);
53388 	 if (dsk) gluDisk(disk, 0, rad, 6, 1);
53389          glTranslatef(0.0,0.0,vl);
53390 	 if (dsk == 2) gluDisk(disk, 0, rad, 6, 1);
53391 	 gluQuadricOrientation(disk, (GLenum)GLU_OUTSIDE);
53392       }
53393       glPopMatrix();
53394 
53395 }
53396 
ogarrow(int ic,float * p1,float * p2,double rad)53397 void ogarrow(int ic, float *p1, float *p2, double rad)
53398 {
53399       int i;
53400       double cosa, radf;
53401       float angle, vl, conelen;
53402       float v1[3], v2[3], v3[3], p3[3];
53403       float todeg;
53404 
53405 
53406       radf = 0.5*rad;
53407       conelen = 0.3;
53408       todeg = 45.0 / atan(1.0);
53409 
53410       for (i=0; i<3; i++) {
53411          v1[i] = p2[i] - p1[i];
53412          v2[i] = 0.0;
53413          p3[i] = v1[i]/2.0 + p1[i];
53414       }
53415       v2[2] = 1.0;
53416 
53417       improd(v1,v2,&cosa);
53418 
53419       if (fabs(cosa) == 1.0) {
53420 
53421          for (i=0; i<3; i++) v3[i] = 0.0;
53422          v3[1] = 1.0;
53423          angle = 0.0;
53424 	 if (cosa < 0) angle = 180.0;
53425 
53426       } else {
53427 
53428          angle = (float) acos(cosa)*todeg;
53429          cross(v2,v1,v3);
53430          vl = veclen(v3);
53431          for (i=0; i<3; i++) v3[i] = v3[i] / vl;
53432 
53433       }
53434 
53435 
53436       glPushMatrix();
53437       glTranslatef(p1[0],p1[1],p1[2]);
53438       glRotatef(angle,v3[0],v3[1],v3[2]);
53439       if (ic >= 0) setAtomColor(ic);
53440       vl = veclen(v1);
53441       v3[0] = 0.0; v3[1] = 0.0; v3[2] = vl - conelen;
53442       if (v3[2] <= 0.0) v3[2] = conelen;
53443       gluCylinder( cyl, radf, radf, v3[2], 15, 1 );
53444       glTranslatef(v3[0],v3[1],v3[2]);
53445       gluCylinder( cyl, rad, 0.0, conelen, 15, 1 );
53446       glPopMatrix();
53447 
53448 }
53449 #define NSELE 4
53450 int SelElem[NSELE] = {0,5,6,7};
53451 
ogsetel20(int j)53452 void ogsetel20(int j)
53453 {
53454       double rad;
53455 
53456       theElem_20[j] = glGenLists(1);
53457       glNewList(theElem_20[j], GL_COMPILE);
53458       rad = elmptr->vdwr[j]*1.4/0.52917706;
53459       gluSphere(sphere, rad, 20, 20);
53460       glEndList();
53461 }
53462 
ogsetel20_bs(int j)53463 void ogsetel20_bs(int j)
53464 {
53465       double rad;
53466 
53467       theElem_20_bs[j] = glGenLists(1);
53468       glNewList(theElem_20_bs[j], GL_COMPILE);
53469       rad = elmptr->vdwr[j]*0.5/0.52917706;
53470       gluSphere(sphere, rad, 20, 20);
53471       glEndList();
53472 }
53473 
ogsetel12(int j)53474 void ogsetel12(int j)
53475 {
53476       double rad;
53477 
53478       theElem_12[j] = glGenLists(1);
53479       glNewList(theElem_12[j], GL_COMPILE);
53480       rad = elmptr->vdwr[j]*1.4/0.52917706;
53481       gluSphere(sphere, rad, 12, 12);
53482       glEndList();
53483 }
53484 
ogsetel12_bs(int j)53485 void ogsetel12_bs(int j)
53486 {
53487       double rad;
53488 
53489       theElem_12_bs[j] = glGenLists(1);
53490       glNewList(theElem_12_bs[j], GL_COMPILE);
53491       rad = elmptr->vdwr[j]*0.5/0.52917706;
53492       gluSphere(sphere, rad, 12, 12);
53493       glEndList();
53494 }
53495 
ogelem()53496 void ogelem()
53497 {
53498     int i;
53499     double rad;
53500 
53501     for (i=0; i<MXEL; i++) {
53502       theElem_20[i] = -1;
53503       theElem_20_bs[i] = -1;
53504       theElem_12[i] = -1;
53505       theElem_12_bs[i] = -1;
53506     }
53507 
53508     for (i=0; i<NSELE; i++) {
53509 
53510       ogsetel20(SelElem[i]);
53511       ogsetel20_bs(SelElem[i]);
53512       ogsetel12(SelElem[i]);
53513       ogsetel12_bs(SelElem[i]);
53514 
53515     }
53516 
53517     theElsm = glGenLists(1);
53518     glNewList(theElsm, GL_COMPILE);
53519     rad = 0.13/0.52917706;
53520     gluSphere(sphere, rad, 12, 12);
53521     glEndList();
53522 
53523 }
53524 
ogChkElem()53525 void ogChkElem()
53526 {
53527     int i,ia;
53528     int ElPres[MXEL];
53529 
53530     for (i=0; i<MXEL; i++) ElPres[i] = 0;
53531     for (i=0; i < *xyzp->iatoms; i++) {
53532 	ia = xyzp->ianz[i]-1;
53533 	ElPres[ia] = 1;
53534     }
53535 
53536     for (i=0; i<MXEL; i++) {
53537 
53538       if (ElPres[i]) {
53539 	ogsetel20(i);
53540 	ogsetel20_bs(i);
53541 	ogsetel12(i);
53542 	ogsetel12_bs(i);
53543       }
53544 
53545     }
53546 
53547 }
53548 
ogfstsph(int ic,int ia,float * p1,int type)53549 void ogfstsph(int ic, int ia, float *p1, int type)
53550 {
53551 
53552       glPushMatrix();
53553       glTranslatef(p1[0],p1[1],p1[2]);
53554       setAtomColor(ic);
53555       if (type && ! (*ivdwpl == 2)) {
53556 	 glCallList(theElsm);
53557       } else {
53558          if (*ivdwpl == 2) {
53559 	   if (*ipdbon && *xyzp->iatoms > 500 && !has_shader) {
53560 	    glCallList(theElem_12_bs[ia]);
53561 	   } else {
53562 	    glCallList(theElem_20_bs[ia]);
53563 	   }
53564 	 } else {
53565 	   if (*ipdbon && *xyzp->iatoms > 500 && !has_shader) {
53566 	    glCallList(theElem_12[ia]);
53567 	   } else {
53568 	    glCallList(theElem_20[ia]);
53569 	   }
53570 	 }
53571       }
53572       glPopMatrix();
53573 
53574 }
53575 
ogsphere(int ic,float * p1,double rad,int hiresol)53576 void ogsphere(int ic, float *p1, double rad, int hiresol)
53577 {
53578 
53579       glPushMatrix();
53580       glTranslatef(p1[0],p1[1],p1[2]);
53581       setAtomColor(ic);
53582       if (hiresol) {
53583 	 if (*ipdbon && *xyzp->iatoms > 500 && !has_shader) {
53584 	    gluSphere(sphere, rad, 12, 12);
53585 	 } else {
53586 	    gluSphere(sphere, rad, 20, 20);
53587 	 }
53588       } else {
53589 	 if (*ipdbon) {
53590 	    gluSphere(sphere, rad, 5, 5);
53591 	 } else {
53592 	    gluSphere(sphere, rad, 10, 10);
53593 	 }
53594       }
53595       glPopMatrix();
53596 
53597 }
53598 
ogatbnd(iatom,dijsq)53599 void ogatbnd(iatom,dijsq)
53600 int iatom;
53601 double *dijsq;
53602 {
53603     double roddef, colv[3];
53604     float tmp1[3],tmp2[3], tmp3[3];
53605     int i,j,k,l,m,n, ia,ja,ic,jc,it,ir,jr,ido, dsurf, dcell, doclr;
53606     int cell_up, cell_low;
53607     int issolv, ncon, lowres;
53608 
53609     for (l=0; l<3; l++)
53610 	tmp1[l] = (float) xyzp->coo[iatom*3+l];
53611     *dijsq = tmp1[0]*tmp1[0] + tmp1[1]*tmp1[1] + tmp1[2]*tmp1[2];
53612 
53613     if (xyzp->iaton[iatom] <= 0 || iatom < 0) return;
53614     cell_low = cell_up = 0;
53615     if (cellpnt->iclon) {
53616 	cell_low = cellpnt->iclpnt[0]-1;
53617 	cell_up = cell_low + 7;
53618     }
53619 
53620     lowres = 0;
53621     if (*ipdbon && !*backb && *xyzp->iatoms > 500 && !has_shader) lowres = 1;
53622 
53623     doclr = 0;
53624     if (xyzp->iatclr != NULL && !*atcol) doclr = 1;
53625 
53626     if (xyzp->iaton[iatom] >= 1  && !(xyzp->iresid[iatom] <= 0
53627 	&& xyzp->iresid[iatom] >= -3 && xyzp->ianz[iatom] == 100)) {
53628 
53629 	 dsurf = 0;
53630 	 if (iatom > *natorg-1 && *natorg != 0) dsurf = 1;
53631 
53632 	 dcell = 0;
53633  	 if (dsurf && (iatom <= cell_up && iatom >= cell_low)) dcell = 1;
53634 
53635          ia = xyzp->ianz[iatom];
53636 
53637 	 if (doclr) {
53638             ic = xyzp->iatclr[iatom]-1;
53639 	 } else {
53640 	    ic = 0;
53641 	    if (ia >=1 ) ic = elmptr->icol[ia-1]-1;
53642 	 }
53643 
53644 	 if (!(dsurf && !dcell)) {
53645 
53646 	 if (*ivdwpl == 1 && *fancy && !dsurf) {
53647 
53648  	   if (cellpnt->iclon && iatom <= cell_up && iatom >= cell_low) {
53649 		ogfstsph(ic,ia-1,tmp1,0);
53650 		roddef = elmptr->vdwr[ia-1]/0.52917706;
53651 		for (k=0; k<xyzp->iconn[iatom*(MXCON+1)]; k++) {
53652 		   m = xyzp->iconn[iatom*(MXCON+1)+k+1];
53653 		   j = ABS(m) - 1;
53654 		   if (j > iatom) {
53655 			for (l=0; l<3; l++)
53656 			   tmp3[l] = (float) xyzp->coo[j*3+l];
53657 			ogrod(ic,tmp1,tmp3,roddef,1,0);
53658 		   }
53659 		}
53660 	   } else {
53661 		if (idorad) {
53662 		   roddef = xyzp->qat[iatom]/0.52917706;
53663 		} else {
53664 		   roddef = elmptr->vdwr[ia-1]*1.4/0.52917706;
53665 		}
53666 		ogfstsph(ic,ia-1,tmp1,0);
53667 	   }
53668 
53669 	 } else {
53670 
53671 	   issolv = 0;
53672 	   it = xyzp->iconn[iatom*(MXCON+1)];
53673 	   if (*ipdbon && xyzp->iresid[iatom] == -(calfptr->ishoh) && it) issolv = 1;
53674 
53675            roddef = 0.13/0.52917706;
53676 
53677            if (!issolv && *fancy) {
53678               if ((lowres && !it) || !lowres) {
53679 		ogfstsph(ic,ia-1,tmp1,1);
53680 	      } else {
53681 		if ( *ivdwpl == 2) {
53682 	   	   ogfstsph(ic,ia-1,tmp1,0);
53683 		}
53684 	      }
53685 	   }
53686 
53687 	   ir = xyzp->iresid[iatom];
53688 
53689            for (k=0; k<xyzp->iconn[iatom*(MXCON+1)]; k++) {
53690 
53691 	    m = xyzp->iconn[iatom*(MXCON+1)+k+1];
53692             j = ABS(m) - 1;
53693 	    if (j < 0 || j > *xyzp->mxnat) return;
53694 
53695 	    if (xyzp->iconn[iatom*(MXCON+1)+k+1] < 0)
53696 		    roddef = (0.13/0.52917706)/4.0;
53697             ja = xyzp->ianz[j];
53698 
53699 	    if (doclr) {
53700                jc = xyzp->iatclr[j]-1;
53701 	    } else {
53702                jc = elmptr->icol[ja-1]-1;
53703 	    }
53704             for (l=0; l<3; l++)
53705 		tmp2[l] = (float) xyzp->coo[j*3+l];
53706 
53707 	    jr = xyzp->iresid[j];
53708             ido = 1;
53709 
53710             if (ic == jc && ir == jr) {
53711                if (j > iatom) {
53712                   for (l=0; l<3; l++) tmp3[l] = tmp2[l];
53713 		  ido = 2;
53714                } else {
53715                   ido = 0;
53716                }
53717             } else {
53718                for (l=0; l<3; l++)
53719                   tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
53720             }
53721 
53722             if (ido) {
53723 		if (*fancy) {
53724 		   if (issolv)
53725 		      ogrod(ic,tmp1,tmp3,roddef,0,0);
53726 	   	   else
53727 		      if (lowres) ogrod(ic,tmp1,tmp3,roddef,0,ido);
53728 		      else ogrod(ic,tmp1,tmp3,roddef,1,0);
53729 		} else {
53730 		   colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
53731 		   colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
53732 		   colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
53733 		   if (m < 0) {
53734 			glEnd();
53735 			glLineStipple(4,0xAAAA);
53736 			glEnable(GL_LINE_STIPPLE);
53737 			glBegin(GL_LINES);
53738 		   }
53739 		   glColor4d(colv[0],colv[1],colv[2],tr_val);
53740 		   glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
53741 		   glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
53742 		   if (m < 0) {
53743 			glEnd();
53744 			glDisable(GL_LINE_STIPPLE);
53745 			glBegin(GL_LINES);
53746 			isdraw = 1;
53747 		   }
53748 		}
53749 	    }
53750 
53751 	   } /* end for k */
53752 	 } /* end if (*ivdwpl && !dsurf)*/
53753 	 }
53754      } /* end if (xyzp->iaton[i] >= 1 */
53755 }
53756 
53757 #if defined(VMS) || defined(UNDERSC)
ogmon()53758 void ogmon()
53759 #else
53760 #ifdef CRAY
53761 void OGMON()
53762 #else
53763 void ogmon_()
53764 #endif
53765 #endif
53766 {
53767     int i,i1,i2,j,l,doclr,ia,ic;
53768     double roddef, colv[3];
53769     float tmp1[3],tmp2[3], tmp3[3];
53770 
53771 /* consider making this routine do the same for solid and fullgl stick */
53772 
53773     if (! (*fancy || *fullgl)) return;
53774     if (!xison) return;
53775 
53776       roddef = (0.13/0.52917706)/4.0;
53777       doclr = 0;
53778       if (xyzp->iatclr != NULL && !*atcol) doclr = 1;
53779 
53780       if (!glIsList(theMon[istruct])) glDeleteLists(theMon[istruct],1);
53781 
53782       theMon[istruct] = glGenLists(1);
53783       glNewList(theMon[istruct], GL_COMPILE_AND_EXECUTE);
53784 
53785       if (*fancy) {
53786         glDisable(GL_COLOR_MATERIAL);
53787       } else {
53788 	glDisable(GL_LIGHTING);
53789 	glLineWidth(1.0);
53790 	glLineStipple(4,0xAAAA);
53791 	glEnable(GL_LINE_STIPPLE);
53792 	glEnable(GL_LINE_SMOOTH);
53793 	glEnable(GL_COLOR_MATERIAL);
53794 	glBegin(GL_LINES);
53795       }
53796 
53797 
53798       for (i=0; i<monptr->ndm; i++) {
53799 
53800 	 i1 = monptr->idmon[i][0] - 1;
53801 	 i2 = monptr->idmon[i][1] - 1;
53802 
53803 	 for (l=0; l<3; l++)
53804 	    tmp1[l] = (float) xyzp->coo[i1*3+l];
53805 	 for (l=0; l<3; l++)
53806 	    tmp2[l] = (float) xyzp->coo[i2*3+l];
53807 	 for (l=0; l<3; l++)
53808 	    tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
53809 
53810          ia = xyzp->ianz[i1];
53811 	 if (doclr) {
53812             ic = xyzp->iatclr[i1]-1;
53813 	 } else {
53814             ic = elmptr->icol[ia-1]-1;
53815 	 }
53816 
53817          if (*fancy) {
53818 		ogrod(ic,tmp1,tmp3,roddef,0,0);
53819 	 } else {
53820 		colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
53821 		colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
53822 		colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
53823 		glColor4d(colv[0],colv[1],colv[2],tr_val);
53824 		glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
53825 		glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
53826 	 }
53827 
53828          ia = xyzp->ianz[i2];
53829 	 if (doclr) {
53830             ic = xyzp->iatclr[i2]-1;
53831 	 } else {
53832             ic = elmptr->icol[ia-1]-1;
53833 	 }
53834 
53835          if (*fancy) {
53836 		ogrod(ic,tmp2,tmp3,roddef,0,0);
53837 	 } else {
53838 		colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
53839 		colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
53840 		colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
53841 		glColor4d(colv[0],colv[1],colv[2],tr_val);
53842 		glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
53843 		glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
53844 	 }
53845 
53846       }
53847 
53848       if (! *fancy) {
53849 	glEnd();
53850 	glDisable(GL_LINE_STIPPLE);
53851 	glDisable(GL_COLOR_MATERIAL);
53852 	glEnable(GL_LIGHTING);
53853       }
53854 
53855       glEndList();
53856 }
53857 
ogunsel()53858 void ogunsel()
53859 {
53860  int j;
53861 
53862     for (j=0; j < *zmptrp->nz; j++)
53863          if (xyzp->iaton[j] >= 2) xyzp->iaton[j] = 1;
53864     for (j=0; j < *xyzp->iatoms; j++)
53865          if (xyzp->iaton[j] >= 2) xyzp->iaton[j] = 1;
53866     update_sel = 1;
53867 }
53868 
ogsel()53869 void ogsel()
53870 {
53871   int i;
53872   float tmp[3];
53873   GLdouble srad;
53874 
53875   theSel[istruct] = glGenLists(1);
53876   glNewList(theSel[istruct], GL_COMPILE_AND_EXECUTE);
53877 
53878   for (i=0; i<*xyzp->iatoms; i++) {
53879         tmp[0] = (float) (xyzp->coo[i*3]);
53880         tmp[1] = (float) (xyzp->coo[i*3+1]);
53881         tmp[2] = (float) (xyzp->coo[i*3+2]);
53882         if (xyzp->iaton[i] >= 2)  {
53883            if (ZMEup || aflag || cflag || ATMup || SelDel || ONIup ||
53884 		scoup || NMRup) {
53885 	      if (*ivdwpl == 1) {
53886 		srad = 3.0;
53887               } else if (*ivdwpl == 2) {
53888 		srad = (0.55/0.52917706);
53889               } else {
53890 		srad = (1.5*0.13/0.52917706);
53891 	      }
53892 	      ogsphere(rimcols[xyzp->iaton[i]]-1,tmp,srad,0);
53893 	   }
53894 	}
53895   }
53896   glEndList();
53897   update_sel = 0;
53898 }
53899 
updfog(iset)53900 void updfog(iset)
53901 int iset;
53902 {
53903    int l;
53904 
53905    if (posz > 0.0) posz = sqrt(posz);
53906    scl[istruct] = posz;
53907    if (scl[istruct] == 0.0) scl[istruct] = 1.0;
53908    posz = -1.6*posz;
53909    for (l=0; l<3; l++)
53910 	light2_position[istruct][l] = light2_position_def[l]*scl[istruct]*5.0;
53911    if (iset) poszset = 1;
53912 }
53913 
ogbck(isec)53914 void ogbck(isec)
53915 int isec;
53916 {
53917       int i,j,ires;
53918       double dijsq;
53919 
53920 	if (!(has_opengl && (*fancy || *fullgl) )) return;
53921 
53922 	if (*fancy) ogChkElem();
53923 	for (ires = 1; ires < calfptr->ncalf+1; ires++ ) {
53924 	   if (calfptr->isal[ires-1] == isec) {
53925 #if defined(VMS) || defined(UNDERSC)
53926 		getpdb(&ires,ipdb,ihpdb);
53927 #else
53928 #ifdef CRAY
53929 		GETPDB(&ires,ipdb,ihpdb);
53930 #else
53931 		getpdb_(&ires,ipdb,ihpdb);
53932 #endif
53933 #endif
53934 		theBck[istruct][ires-1] = glGenLists(1);
53935 		glNewList(theBck[istruct][ires-1], GL_COMPILE);
53936 
53937 		for (i=0; i<3; i++) {
53938 		   if (ipdb[i] > 0) {
53939 			xyzp->iaton[ipdb[i]-1] = 1;
53940 			ogatbnd(ipdb[i]-1,&dijsq);
53941 		   }
53942 		}
53943 		glEndList();
53944 	   }
53945 
53946 	}
53947 }
53948 
ogres_(ires,iopt,iupd)53949 void ogres_(ires,iopt,iupd)
53950 int *ires;
53951 int *iopt;
53952 int *iupd;
53953 {
53954      ogres(*ires,*iopt,*iupd);
53955 }
53956 
ogres(ires,iopt,iupd)53957 void ogres(ires,iopt,iupd)
53958 int ires;
53959 int iopt;
53960 int iupd;
53961 {
53962       int i,j;
53963       double dijsq;
53964 
53965       if (!((*fancy || *fullgl) && has_opengl)) {
53966 	update_struct();
53967 	return;
53968       }
53969 
53970       if (!calfptr->reson[ires-1]) return;
53971 /*
53972       glDeleteLists(theRes[istruct][ires-1],1);
53973       theRes[istruct][ires-1] = -1;
53974 */
53975 
53976 #if defined(VMS) || defined(UNDERSC)
53977       getpdb(&ires,ipdb,ihpdb);
53978 #else
53979 #ifdef CRAY
53980       GETPDB(&ires,ipdb,ihpdb);
53981 #else
53982       getpdb_(&ires,ipdb,ihpdb);
53983 #endif
53984 #endif
53985 
53986       if (!glIsList(theRes[istruct][ires-1]))
53987 		theRes[istruct][ires-1] = glGenLists(1);
53988       glNewList(theRes[istruct][ires-1], GL_COMPILE);
53989 
53990       if (*fancy) {
53991         glDisable(GL_COLOR_MATERIAL);
53992       } else {
53993 	glDisable(GL_LIGHTING);
53994 	glLineWidth(2.0);
53995 	glEnable(GL_LINE_SMOOTH);
53996 	glEnable(GL_COLOR_MATERIAL);
53997 	glBegin(GL_LINES);
53998       }
53999 
54000       for (i=0; i<MXSYM; i++) {
54001 	if (ipdb[i] > 0) {
54002 	   ogatbnd(ipdb[i]-1,&dijsq);
54003 	   if (!iopt && (!addfile || !poszset) ) if (dijsq > posz) posz = dijsq;
54004 	}
54005       }
54006       for (i=0; i<3*MXHSYM; i++) {
54007 	if (ihpdb[i] > 0) {
54008 	   ogatbnd(ihpdb[i]-1,&dijsq);
54009 	   if (!iopt && (!addfile || !poszset) ) if (dijsq > posz) posz = dijsq;
54010 	}
54011       }
54012 
54013       if (! *fancy) {
54014 	glEnd();
54015 	glDisable(GL_COLOR_MATERIAL);
54016 	glEnable(GL_LIGHTING);
54017       }
54018 
54019       glEndList();
54020       if (iupd) dispsf();
54021 }
54022 
54023 
oghet(int iopt)54024 void oghet(int iopt)
54025 {
54026     double dijsq;
54027     int i, ioff, num_atoms;
54028 
54029     theMol[istruct][NMols[istruct]] = glGenLists(1);
54030     glNewList(theMol[istruct][NMols[istruct]], GL_COMPILE);
54031     glDisable(GL_COLOR_MATERIAL);
54032 
54033     ioff = 0;
54034     num_atoms = *xyzp->iatoms;
54035 
54036     if (!iopt && (*irtcel && *ialtyp) && *iscst < num_atoms)
54037 	num_atoms = *iscst;
54038 
54039     if (iopt) {
54040 	ioff = *iscst;
54041         num_atoms = *nscnd;
54042     }
54043 
54044     for (i=ioff; i<ioff+num_atoms; i++) {
54045        if (xyzp->iresid[i] < -3) {
54046 	ogatbnd(i,&dijsq);
54047 	if (!iopt && (!addfile || !poszset) ) if (dijsq > posz) posz = dijsq;
54048        }
54049     }
54050 
54051     glEndList();
54052 }
54053 
ogpdb(int iopt)54054 void ogpdb(int iopt)
54055 {
54056     double roddef, dijsq;
54057     float tmp1[3];
54058     int ires, i,j,k,l,m, doclr, ioff, num_atoms;
54059     int cell_low, cell_up;
54060 
54061     if (!(*fancy || *fullgl) ) return;
54062 
54063     glXMakeCurrent(display, win, cx);
54064     if (!iopt && !addfile) posz = 0.0;
54065 
54066     glPopMatrix();
54067     glPushMatrix();
54068 
54069     if (NMols[istruct] >= MXMOL - 1) return;
54070 
54071     if (NMols[istruct] != -1 && !iopt) {
54072        NMols[istruct] = -1;
54073        NMols[istruct]++;
54074        glDeleteLists(theMol[istruct][NMols[istruct]],1);
54075        theMol[istruct][NMols[istruct]] = -1;
54076     } else NMols[istruct]++;
54077 
54078     if (*xyzp->iatoms == 0) return;
54079 
54080     if (iopt) {
54081 	glDeleteLists(theMol[istruct][1],1);
54082 	theMol[istruct][1] = -1;
54083 	NMols[istruct] = 1;
54084     }
54085 
54086 /* do residues */
54087 
54088     for (ires=0;ires < calfptr->ncalf;ires++) {
54089 	l = calfptr->icalf[ires][0];
54090 	for (i=0; i<3; i++)
54091 	   tmp1[i] = (float) xyzp->coo[l*3+i];
54092 	dijsq = tmp1[0]*tmp1[0] + tmp1[1]*tmp1[1] + tmp1[2]*tmp1[2];
54093 	if (!iopt && (!addfile || !poszset) ) if (dijsq > posz) posz = dijsq;
54094     }
54095 
54096     if (!iopt) {
54097 	for ( ires = 1; ires < calfptr->ncalf+1; ires++ ) {
54098 	   ogres(ires,iopt,0);
54099 	}
54100     }
54101 
54102 
54103 /* do other non amino atoms */
54104 
54105     oghet(iopt);
54106 
54107     if (!iopt && (!addfile || !poszset) ) updfog(1);
54108 
54109     dispsf();
54110 }
54111 
54112 
ogmoll(int iopt)54113 void ogmoll(int iopt)
54114 {
54115     double dijsq;
54116     int i,j,k,l, doclr, ioff, num_atoms;
54117     int cell_low, cell_up;
54118 
54119     if (!(*fancy || *fullgl)) return;
54120 
54121     if (*fancy) ogChkElem();
54122 
54123     if (*ipdbon) {
54124 	ogpdb(iopt);
54125 	return;
54126     }
54127 
54128     glXMakeCurrent(display, win, cx);
54129     if (!iopt && !addfile) posz = 0.0;
54130 
54131     glPopMatrix();
54132     glPushMatrix();
54133 
54134     if (NMols[istruct] >= MXMOL - 1) return;
54135 
54136     if (NMols[istruct] != -1 && !iopt) {
54137        NMols[istruct] = -1;
54138        NMols[istruct]++;
54139        glDeleteLists(theMol[istruct][NMols[istruct]],1);
54140        theMol[istruct][NMols[istruct]] = -1;
54141     } else NMols[istruct]++;
54142 
54143     if (*xyzp->iatoms == 0) return;
54144 
54145     if (iopt) {
54146 	glDeleteLists(theMol[istruct][1],1);
54147 	theMol[istruct][1] = -1;
54148 	NMols[istruct] = 1;
54149     }
54150 
54151     theMol[istruct][NMols[istruct]] = glGenLists(1);
54152     glNewList(theMol[istruct][NMols[istruct]], GL_COMPILE);
54153     glDisable(GL_COLOR_MATERIAL);
54154 
54155 
54156     ioff = 0;
54157     num_atoms = *xyzp->iatoms;
54158     if (!iopt && (*irtcel && *ialtyp) && *iscst < num_atoms)
54159 	num_atoms = *iscst;
54160     if (iopt) {
54161 	ioff = *iscst;
54162         num_atoms = *nscnd;
54163     }
54164 
54165     for (i=ioff; i<ioff+num_atoms; i++) {
54166        ogatbnd(i,&dijsq);
54167        if (!iopt && (!addfile || !poszset) ) if (dijsq > posz) posz = dijsq;
54168     }
54169 
54170     glEndList();
54171 
54172     if (!iopt && (!addfile || !poszset) ) updfog(1);
54173 
54174     dispsf();
54175 }
54176 
ogmlxyz()54177 void ogmlxyz()
54178 {
54179     double roddef, dmaxsq, dijsq, dsq, adj;
54180     float tmp1[3],tmp2[3], tmp3[3];
54181     int i,j,k,l, ia, ic, ja, ido;
54182 
54183 
54184     if (!*ifdogl) return;
54185 
54186 #if defined(VMS) || defined(UNDERSC)
54187     dodcnt(rotptr->td);
54188 #else
54189 #ifdef CRAY
54190     DODCNT(rotptr->td);
54191 #else
54192     dodcnt_(rotptr->td);
54193 #endif
54194 #endif
54195 
54196     adj = *adjuss;
54197     glXMakeCurrent(display, win, cx);
54198     posz = 0.0;
54199     dijsq = 0.0;
54200 
54201     roddef = (0.13/adj);
54202 
54203     glPopMatrix();
54204     glPushMatrix();
54205 
54206     glDeleteLists(theMol[istruct][0],1);
54207     theMol[istruct][0] = -1;
54208     NMols[istruct] = 1;
54209 
54210     theMol[istruct][0] = glGenLists(1);
54211     glNewList(theMol[istruct][0], GL_COMPILE);
54212     glDisable(GL_COLOR_MATERIAL);
54213 
54214     for (i=0; i< NAT->natoms; i++) {
54215 
54216          ia = NAT->nat[i];
54217          ic = elmptr->icol[ia-1]-1;
54218 
54219 
54220          for (l=0; l<3; l++)
54221             tmp1[l] = (float) XYZ->xyz[i][l];
54222 
54223 	 dijsq = tmp1[0]*tmp1[0] + tmp1[1]*tmp1[1] + tmp1[2]*tmp1[2];
54224 	 if (dijsq > 0.0) dijsq = sqrt(dijsq);
54225 	 if (dijsq > posz) posz = dijsq;
54226 
54227 
54228 	 if (*ivdwpl) {
54229 
54230 	   roddef = elmptr->vdwr[ia-1]*1.4/adj;
54231            ogsphere(ic,tmp1,roddef,hires);
54232 
54233 	 } else {
54234 
54235            roddef = (0.13/adj);
54236 
54237            ogsphere(ic,tmp1,roddef,0);
54238 
54239            for (j=0; j< NAT->natoms; j++) {
54240 
54241             ja = NAT->nat[j];
54242             for (l=0; l<3; l++)
54243 	       tmp2[l] = (float) XYZ->xyz[j][l];
54244 
54245 	    dsq = 0;
54246             for (l=0; l<3; l++) {
54247                 tmp3[l] = (tmp2[l] - tmp1[l]);
54248 		dsq = dsq + tmp3[l]*tmp3[l];
54249 	    }
54250             dmaxsq = (elmptr->vdwr[ia-1] + elmptr->vdwr[ja-1])/adj;
54251             dmaxsq = dmaxsq * dmaxsq;
54252 
54253 	    if (dsq < dmaxsq) ido = 1;
54254 	    else ido = 0;
54255 
54256             if (ja == ia) {
54257                if (j > i) {
54258                   for (l=0; l<3; l++) tmp3[l] = tmp2[l];
54259                } else {
54260                   ido = 0;
54261                }
54262             } else {
54263                for (l=0; l<3; l++)
54264                   tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
54265             }
54266 
54267             if (ido) ogrod(ic,tmp1,tmp3,roddef,1,0);
54268 
54269 	   } /* end for k */
54270 	 } /* end if (*ivdwpl)*/
54271     } /* end for (i=0; i<*natoms; i++) { */
54272 
54273 
54274     glEndList();
54275 
54276     updfog(0);
54277 
54278     dispsf();
54279 }
54280 
oglines()54281 void oglines()
54282 {
54283     double dmaxsq, dijsq, colv[3];
54284     float tmp1[3],tmp2[3], tmp3[3];
54285     int i,j,k,l,m, ia, ic, ja, ido, doclr, dsurf ;
54286 
54287 
54288     if (!addfile) posz = 0.0;
54289 
54290     doclr = 0;
54291     if (xyzp->iatclr != NULL && !*atcol) doclr = 1;
54292 
54293     if (NMols[istruct] >= MXMOL - 1) return;
54294     if (*xyzp->iatoms == 0) return;
54295 
54296     if (theLines[istruct] > 0) glDeleteLists(theLines[istruct],1);
54297     theLines[istruct] = -1;
54298     theLines[istruct] = glGenLists(1);
54299 
54300     if (theFLines[istruct] > 0) glDeleteLists(theFLines[istruct],1);
54301     theFLines[istruct] = -1;
54302     theFLines[istruct] = glGenLists(1);
54303 
54304     if (thePoints[istruct] > 0) glDeleteLists(thePoints[istruct],1);
54305     thePoints[istruct] = -1;
54306     thePoints[istruct] = glGenLists(1);
54307 
54308 /*
54309 theLines is intended as lines in combination with solid atoms
54310 the lines would be used to display a mesh surface
54311 */
54312 
54313     glNewList(theLines[istruct], GL_COMPILE);
54314     glDisable(GL_LIGHTING);
54315     glLineWidth(2.0);
54316     glEnable(GL_LINE_SMOOTH);
54317     glEnable(GL_COLOR_MATERIAL);
54318     glBegin(GL_LINES);
54319 
54320     for (i=0; i<*xyzp->iatoms; i++) {
54321 
54322 	if (xyzp->iaton[i] >= 1  &&
54323 	   !(xyzp->iresid[i] <= 0 && xyzp->iresid[i] >= -3 && xyzp->ianz[i] == 100)) {
54324 
54325 	 dsurf = 0;
54326 	 if (i >= *natorg && *natorg != 0) dsurf = 1;
54327 
54328 	 if (dsurf) {
54329 
54330             ia = xyzp->ianz[i];
54331 	    if (doclr || *doesp) {
54332                ic = xyzp->iatclr[i]-1;
54333 	    } else {
54334                ic = elmptr->icol[ia-1]-1;
54335             }
54336             for (l=0; l<3; l++)
54337                tmp1[l] = (float) xyzp->coo[i*3+l];
54338 
54339 
54340            for (k=0; k<xyzp->iconn[i*(MXCON+1)]; k++) {
54341 
54342 
54343             m = xyzp->iconn[i*(MXCON+1)+k+1];
54344             j = ABS(m) - 1;
54345             ja = xyzp->ianz[j];
54346 
54347             for (l=0; l<3; l++)
54348 	       tmp2[l] = (float) xyzp->coo[j*3+l];
54349 
54350 
54351             ido = 1;
54352             if (ja == ia) {
54353                if (j > i) {
54354                   for (l=0; l<3; l++) tmp3[l] = tmp2[l];
54355                } else {
54356                   ido = 0;
54357                }
54358             } else {
54359                for (l=0; l<3; l++)
54360                   tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
54361             }
54362 
54363             if (ido) {
54364 	       colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
54365 	       colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
54366 	       colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
54367 	       if (m < 0) {
54368 		   glEnd();
54369 		   glLineStipple(4,0xAAAA);
54370 		   glEnable(GL_LINE_STIPPLE);
54371 		   glBegin(GL_LINES);
54372 	       }
54373 	       glColor4d(colv[0],colv[1],colv[2],tr_val);
54374 	       glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54375 	       glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
54376 	       if (m < 0) {
54377 		   glEnd();
54378 		   glDisable(GL_LINE_STIPPLE);
54379 		   glBegin(GL_LINES);
54380 	       }
54381 
54382 	    }
54383 
54384 	   }
54385 	 }
54386 	}
54387     }
54388 
54389     glEnd();
54390 
54391     for (i=0; i<*xyzp->iatoms; i++) {
54392 
54393 	if (xyzp->iaton[i] >= 1  &&
54394 	   !(xyzp->iresid[i] <= 0 && xyzp->iresid[i] >= -3 && xyzp->ianz[i] == 100) && xyzp->iconn[i*(MXCON+1)] == 0 && ! *fancy) {
54395 
54396             ia = xyzp->ianz[i];
54397 	    if (doclr || *doesp) {
54398                ic = xyzp->iatclr[i]-1;
54399 	    } else {
54400                ic = elmptr->icol[ia-1]-1;
54401             }
54402 
54403 	    colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
54404 	    colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
54405 	    colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
54406 
54407             for (l=0; l<3; l++) {
54408                tmp1[l] = (float) xyzp->coo[i*3+l];
54409 	    }
54410             glBegin(GL_LINES);
54411 	    glColor4d(colv[0],colv[1],colv[2],tr_val);
54412 	    for (j=0; j<6; j++) {
54413 		glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54414            	for (l=0; l<3; l++) {
54415 		   tmp3[l] = (float)(tmp1[l] + CV[j][l]);
54416 		}
54417 		glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
54418 	    }
54419             glEnd();
54420 	}
54421     }
54422 
54423     glDisable(GL_COLOR_MATERIAL);
54424     glEnable(GL_LIGHTING);
54425     glEndList();
54426 
54427 /*
54428 theFLines is intended as lines replacing the solid atoms (non residues) in full opengl
54429 */
54430 
54431     glNewList(theFLines[istruct], GL_COMPILE);
54432     glDisable(GL_LIGHTING);
54433     glEnable(GL_COLOR_MATERIAL);
54434     glLineWidth(2.0);
54435     glEnable(GL_LINE_SMOOTH);
54436     glBegin(GL_LINES);
54437 
54438     for (i=0; i<*xyzp->iatoms; i++) {
54439 
54440 	if (xyzp->iaton[i] >= 1  &&
54441 	   !(xyzp->iresid[i] <= 0 && xyzp->iresid[i] >= -3 && xyzp->ianz[i] == 100)) {
54442 
54443 	 dsurf = 0;
54444 	 if (i >= *natorg && *natorg != 0) dsurf = 1;
54445 
54446 	 if (!dsurf && xyzp->iresid[i] < 0) {
54447 /* if we go for the option below: in line mode replacing an amino acid
54448    would cause the old amino acid to be still there (TheFlines displaylist).
54449    The display of the replaced residue is done by ogres, which puts it into
54450    TheRes display list.
54451    In solid mode this displaylist TheFlines is not visualized */
54452 /*	 if (!dsurf) { */
54453             ia = xyzp->ianz[i];
54454 	    if (doclr || *doesp) {
54455                ic = xyzp->iatclr[i]-1;
54456 	    } else {
54457                ic = elmptr->icol[ia-1]-1;
54458             }
54459             for (l=0; l<3; l++)
54460                tmp1[l] = (float) xyzp->coo[i*3+l];
54461 
54462 
54463            for (k=0; k<xyzp->iconn[i*(MXCON+1)]; k++) {
54464 
54465 
54466             m = xyzp->iconn[i*(MXCON+1)+k+1];
54467             j = ABS(m) - 1;
54468             ja = xyzp->ianz[j];
54469 
54470             for (l=0; l<3; l++)
54471 	       tmp2[l] = (float) xyzp->coo[j*3+l];
54472 
54473 
54474             ido = 1;
54475             if (ja == ia) {
54476                if (j > i) {
54477                   for (l=0; l<3; l++) tmp3[l] = tmp2[l];
54478                } else {
54479                   ido = 0;
54480                }
54481             } else {
54482                for (l=0; l<3; l++)
54483                   tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
54484             }
54485 
54486             if (ido) {
54487 	       colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
54488 	       colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
54489 	       colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
54490 	       if (m < 0) {
54491 		   glEnd();
54492 		   glLineStipple(4,0xAAAA);
54493 		   glEnable(GL_LINE_STIPPLE);
54494 		   glBegin(GL_LINES);
54495 	       }
54496 	       glColor4d(colv[0],colv[1],colv[2],tr_val);
54497 	       glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54498 	       glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
54499 	       if (m < 0) {
54500 		   glEnd();
54501 		   glDisable(GL_LINE_STIPPLE);
54502 		   glBegin(GL_LINES);
54503 	       }
54504 
54505 	    }
54506 
54507 	   }
54508 	 }
54509 	}
54510     }
54511 
54512 
54513     glEnd();
54514     glDisable(GL_COLOR_MATERIAL);
54515     glEnable(GL_LIGHTING);
54516     glEndList();
54517 
54518     glNewList(thePoints[istruct], GL_COMPILE);
54519     glDisable(GL_LIGHTING);
54520     glPointSize(2.5);
54521     glEnable(GL_COLOR_MATERIAL);
54522     glBegin(GL_POINTS);
54523 
54524     for (i=0; i<*xyzp->iatoms; i++) {
54525 
54526         for (l=0; l<3; l++)
54527             tmp1[l] = (float) xyzp->coo[i*3+l];
54528 	dijsq = tmp1[0]*tmp1[0] + tmp1[1]*tmp1[1] + tmp1[2]*tmp1[2];
54529 	if (dijsq > posz) posz = dijsq;
54530 
54531 	if (xyzp->iaton[i] >= 1  &&
54532 	   !(xyzp->iresid[i] <= 0 && xyzp->iresid[i] >= -3 &&
54533 	     xyzp->ianz[i] == 100)) {
54534 
54535            m = xyzp->iconn[i*(MXCON+1)];
54536 
54537 	   if (!m || (m == 1 && xyzp->iconn[i*(MXCON+1)+1] < 0)) {
54538 
54539                ia = xyzp->ianz[i];
54540 	       if (doclr || *doesp) {
54541                   ic = xyzp->iatclr[i]-1;
54542 	       } else {
54543                   ic = elmptr->icol[ia-1]-1;
54544                }
54545 
54546 	       colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
54547 	       colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
54548 	       colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
54549 	       glColor4d(colv[0],colv[1],colv[2],tr_val);
54550 	       glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54551 
54552 	   }
54553 	}
54554     }
54555 
54556 
54557     glEnd();
54558     glDisable(GL_COLOR_MATERIAL);
54559     glEnable(GL_LIGHTING);
54560     glEndList();
54561 
54562     if (!addfile) updfog(0);
54563 }
54564 
tofloat(double d[3],float f[3])54565 void tofloat(double d[3], float f[3])
54566 {
54567   int i;
54568 
54569   for (i=0; i<3; i++) f[i] = (float) d[i];
54570 
54571 }
54572 
ogbox()54573 void ogbox()
54574 {
54575     double tmp1[3],tmp2[3], tmp3[3],roddef;
54576     float tmp1f[3],tmp2f[3], tmp3f[3];
54577     double o[3] = { 0.0,0.0,0.0 };
54578     double x[3] = { 1.0,0.0,0.0 };
54579     double y[3] = { 0.0,1.0,0.0 };
54580     double z[3] = { 0.0,0.0,1.0 };
54581     double xy[3] = { 1.0,1.0,0.0 };
54582     double xz[3] = { 1.0,0.0,1.0 };
54583     double yz[3] = { 0.0,1.0,1.0 };
54584     double xyz[3] = { 1.0,1.0,1.0 };
54585 
54586     if (!has_box) return;
54587 
54588     roddef = 0.20/0.52917706;
54589 
54590     if (theBox[istruct] > 0) glDeleteLists(theBox[istruct],1);
54591     theBox[istruct] = -1;
54592     theBox[istruct] = glGenLists(1);
54593 
54594     glNewList(theBox[istruct], GL_COMPILE_AND_EXECUTE);
54595     if (*fancy) {
54596         glDisable(GL_COLOR_MATERIAL);
54597     } else {
54598 	glDisable(GL_LIGHTING);
54599 	glLineWidth(2.0);
54600 	glEnable(GL_LINE_SMOOTH);
54601 	glEnable(GL_COLOR_MATERIAL);
54602 	glBegin(GL_LINES);
54603     }
54604 
54605     rotbck_(&o[0],&o[1],&o[2],tmp1);
54606     rotbck_(&x[0],&x[1],&x[2],tmp2);
54607     tofloat(tmp1,tmp1f);
54608 
54609     if (*fancy) {
54610 	tofloat(tmp2,tmp2f);
54611 	ogrod(0,tmp1f,tmp2f,roddef,1,0);
54612     } else {
54613 	glColor4d(1.0,0.0,0.0,tr_val);
54614 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54615 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54616     }
54617 
54618     rotbck_(&y[0],&y[1],&y[2],tmp2);
54619 
54620     if (*fancy) {
54621 	tofloat(tmp2,tmp2f);
54622 	ogrod(2,tmp1f,tmp2f,roddef,1,0);
54623     } else {
54624 	glColor4d(0.0,1.0,0.0,tr_val);
54625 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54626 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54627     }
54628 
54629     rotbck_(&z[0],&z[1],&z[2],tmp2);
54630 
54631     if (*fancy) {
54632 	tofloat(tmp2,tmp2f);
54633 	ogrod(3,tmp1f,tmp2f,roddef,1,0);
54634     } else {
54635 	glColor4d(0.0,0.0,1.0,tr_val);
54636 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54637 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54638     }
54639 
54640     rotbck_(&x[0],&x[1],&x[2],tmp1);
54641     rotbck_(&xy[0],&xy[1],&xy[2],tmp2);
54642 
54643     if (*fancy) {
54644 	tofloat(tmp1,tmp1f);
54645 	tofloat(tmp2,tmp2f);
54646 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54647     } else {
54648 	glColor4d(1.0,1.0,1.0,tr_val);
54649 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54650 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54651     }
54652 
54653     rotbck_(&y[0],&y[1],&y[2],tmp1);
54654     rotbck_(&xy[0],&xy[1],&xy[2],tmp2);
54655 
54656     if (*fancy) {
54657 	tofloat(tmp1,tmp1f);
54658 	tofloat(tmp2,tmp2f);
54659 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54660     } else {
54661 	glColor4d(1.0,1.0,1.0,tr_val);
54662 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54663 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54664     }
54665 
54666     rotbck_(&x[0],&x[1],&x[2],tmp1);
54667     rotbck_(&xz[0],&xz[1],&xz[2],tmp2);
54668 
54669     if (*fancy) {
54670 	tofloat(tmp1,tmp1f);
54671 	tofloat(tmp2,tmp2f);
54672 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54673     } else {
54674 	glColor4d(1.0,1.0,1.0,tr_val);
54675 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54676 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54677     }
54678 
54679     rotbck_(&z[0],&z[1],&z[2],tmp1);
54680     rotbck_(&xz[0],&xz[1],&xz[2],tmp2);
54681 
54682     if (*fancy) {
54683 	tofloat(tmp1,tmp1f);
54684 	tofloat(tmp2,tmp2f);
54685 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54686     } else {
54687 	glColor4d(1.0,1.0,1.0,tr_val);
54688 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54689 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54690     }
54691 
54692     rotbck_(&z[0],&z[1],&z[2],tmp1);
54693     rotbck_(&yz[0],&yz[1],&yz[2],tmp2);
54694 
54695     if (*fancy) {
54696 	tofloat(tmp1,tmp1f);
54697 	tofloat(tmp2,tmp2f);
54698 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54699     } else {
54700 	glColor4d(1.0,1.0,1.0,tr_val);
54701 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54702 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54703     }
54704 
54705     rotbck_(&y[0],&y[1],&y[2],tmp1);
54706     rotbck_(&yz[0],&yz[1],&yz[2],tmp2);
54707 
54708     if (*fancy) {
54709 	tofloat(tmp1,tmp1f);
54710 	tofloat(tmp2,tmp2f);
54711 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54712     } else {
54713 	glColor4d(1.0,1.0,1.0,tr_val);
54714 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54715 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54716     }
54717 
54718     rotbck_(&xyz[0],&xyz[1],&xyz[2],tmp1);
54719     rotbck_(&xy[0],&xy[1],&xy[2],tmp2);
54720 
54721     if (*fancy) {
54722 	tofloat(tmp1,tmp1f);
54723 	tofloat(tmp2,tmp2f);
54724 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54725     } else {
54726 	glColor4d(1.0,1.0,1.0,tr_val);
54727 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54728 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54729     }
54730 
54731     rotbck_(&xyz[0],&xyz[1],&xyz[2],tmp1);
54732     rotbck_(&xz[0],&xz[1],&xz[2],tmp2);
54733 
54734     if (*fancy) {
54735 	tofloat(tmp1,tmp1f);
54736 	tofloat(tmp2,tmp2f);
54737 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54738     } else {
54739 	glColor4d(1.0,1.0,1.0,tr_val);
54740 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54741 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54742     }
54743 
54744     rotbck_(&xyz[0],&xyz[1],&xyz[2],tmp1);
54745     rotbck_(&yz[0],&yz[1],&yz[2],tmp2);
54746 
54747     if (*fancy) {
54748 	tofloat(tmp1,tmp1f);
54749 	tofloat(tmp2,tmp2f);
54750 	ogrod(14,tmp1f,tmp2f,roddef,1,0);
54751     } else {
54752 	glColor4d(1.0,1.0,1.0,tr_val);
54753 	glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54754 	glVertex3d(tmp2[0],tmp2[1],tmp2[2]);
54755     }
54756 
54757     glEnd();
54758     glDisable(GL_COLOR_MATERIAL);
54759     glEnable(GL_LIGHTING);
54760     glEndList();
54761 
54762 }
54763 
ogfeatures()54764 void ogfeatures()
54765 {
54766     int i,col;
54767     double colv[3];
54768     float tmp[3],tmp0[3],tmp1[3];
54769     GLdouble srad;
54770 
54771     if (theFeat[istruct] > 0) glDeleteLists(theFeat[istruct],1);
54772     theFeat[istruct] = -1;
54773     theFeat[istruct] = glGenLists(1);
54774     glNewList(theFeat[istruct], GL_COMPILE);
54775 
54776     for (i=0; i< pharm.nfeat; i++) {
54777         tmp[0] = (pharm.array[i].cor[0]);
54778         tmp[1] = (pharm.array[i].cor[1]);
54779         tmp[2] = (pharm.array[i].cor[2]);
54780 	col = FeatCol[pharm.array[i].type];
54781 	if (pharm.array[i].type == 0) {
54782 		srad = 0.2;
54783 		ogsphere(col,tmp,srad,1);
54784 		tmp0[0] = tmp[0] + pharm.array[i].vec1[0];
54785 		tmp0[1] = tmp[1] + pharm.array[i].vec1[1];
54786 		tmp0[2] = tmp[2] + pharm.array[i].vec1[2];
54787 		ogsphere(col,tmp0,srad,1);
54788 		tmp1[0] = tmp[0] + pharm.array[i].vec2[0];
54789 		tmp1[1] = tmp[1] + pharm.array[i].vec2[1];
54790 		tmp1[2] = tmp[2] + pharm.array[i].vec2[2];
54791 		ogsphere(col,tmp1,srad,1);
54792 
54793 	        colv[0] = ((GLdouble) colorr[col+1]) / 65535.0 ;
54794 	        colv[1] = ((GLdouble) colorg[col+1]) / 65535.0 ;
54795 	        colv[2] = ((GLdouble) colorb[col+1]) / 65535.0 ;
54796 		glDisable(GL_LIGHTING);
54797 		glLineWidth(2.0);
54798 		glEnable(GL_LINE_SMOOTH);
54799 		glEnable(GL_COLOR_MATERIAL);
54800 		glBegin(GL_LINES);
54801 	        glColor4d(colv[0],colv[1],colv[2],tr_val);
54802 	        glVertex3d(tmp0[0],tmp0[1],tmp0[2]);
54803 	        glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54804 		glEnd();
54805 		glEnable(GL_LIGHTING);
54806 		glDisable(GL_COLOR_MATERIAL);
54807 
54808 	} else if (pharm.array[i].type == 1 || pharm.array[i].type == 2) {
54809 		srad = 0.2;
54810 		ogsphere(col,tmp,srad,1);
54811 		tmp0[0] = tmp[0] + pharm.array[i].vec1[0];
54812 		tmp0[1] = tmp[1] + pharm.array[i].vec1[1];
54813 		tmp0[2] = tmp[2] + pharm.array[i].vec1[2];
54814 		ogsphere(col,tmp0,srad,1);
54815 
54816 	        colv[0] = ((GLdouble) colorr[col+1]) / 65535.0 ;
54817 	        colv[1] = ((GLdouble) colorg[col+1]) / 65535.0 ;
54818 	        colv[2] = ((GLdouble) colorb[col+1]) / 65535.0 ;
54819 		glDisable(GL_LIGHTING);
54820 		glLineWidth(2.0);
54821 		glEnable(GL_LINE_SMOOTH);
54822 		glEnable(GL_COLOR_MATERIAL);
54823 		glBegin(GL_LINES);
54824 	        glColor4d(colv[0],colv[1],colv[2],tr_val);
54825 	        glVertex3d(tmp[0],tmp[1],tmp[2]);
54826 	        glVertex3d(tmp0[0],tmp0[1],tmp0[2]);
54827 		glEnd();
54828 		glEnable(GL_LIGHTING);
54829 		glDisable(GL_COLOR_MATERIAL);
54830 
54831 	} else {
54832 		srad = 0.2;
54833 		ogsphere(col,tmp,srad,1);
54834 	}
54835     }
54836 
54837     glEndList();
54838 
54839     if (theAFeat[istruct] > 0) glDeleteLists(theAFeat[istruct],1);
54840     theAFeat[istruct] = -1;
54841     theAFeat[istruct] = glGenLists(1);
54842     glNewList(theAFeat[istruct], GL_COMPILE);
54843 
54844     for (i=0; i< pharm.nfeat; i++) {
54845 	if (pharm.array[i].incl) {
54846            tmp[0] = (pharm.array[i].cor[0]);
54847            tmp[1] = (pharm.array[i].cor[1]);
54848            tmp[2] = (pharm.array[i].cor[2]);
54849 	   col = FeatCol[pharm.array[i].type];
54850 	   srad = (pharm.array[i].rad);
54851 	   ogsphere(col,tmp,srad,1);
54852 	}
54853     }
54854 
54855     glEndList();
54856 }
54857 
ogforces()54858 void ogforces()
54859 {
54860     double colv[3], roddef;
54861     float tmp1[3],tmp2[3], tmp3[3];
54862     int i,j,k,l,ic;
54863 
54864     roddef = (0.13/0.52917706);
54865 
54866     if (theForces[istruct] > 0) glDeleteLists(theForces[istruct],1);
54867     theForces[istruct] = -1;
54868     theForces[istruct] = glGenLists(1);
54869     glNewList(theForces[istruct], GL_COMPILE);
54870 
54871     ic = 0;
54872 
54873     for (i=0; i<*xyzp->iatoms; i++) {
54874 
54875 	if (xyzp->iaton[i] >= 1  &&
54876 	   !(xyzp->iresid[i] <= 0 && xyzp->iresid[i] >= -3 && xyzp->ianz[i] == 100)) {
54877 
54878 
54879 
54880            for (k=0; k<3; k++)
54881              tmp1[k] = (float) xyzp->coo[i*3+k];
54882 
54883            for (k=0; k<3; k++)
54884              tmp3[k] = (float) fcptr->fc[i][k];
54885 
54886 
54887 	   colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
54888 	   colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
54889 	   colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
54890 /*
54891 	   glColor4d(colv[0],colv[1],colv[2],tr_val);
54892 	   glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
54893 	   glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
54894 */
54895            ogarrow(ic,tmp1,tmp3,roddef);
54896 
54897 
54898 	}
54899     }
54900 
54901 
54902     glEndList();
54903 
54904 }
54905 
ogsarr()54906 void ogsarr()
54907 {
54908     double colv[3], roddef;
54909     float tmp1[3],tmp3[3];
54910     int k,l,m;
54911 
54912     roddef = (0.8/0.52917706);
54913     l = calfptr->icalf[DisAmino-1][0]-1;
54914     m = calfptr->icalf[DisAmino+DisDir-1][0]-1;
54915 
54916     if (theSArrow[istruct] > 0) glDeleteLists(theSArrow[istruct],1);
54917     theSArrow[istruct] = -1;
54918     theSArrow[istruct] = glGenLists(1);
54919     glNewList(theSArrow[istruct], GL_COMPILE);
54920 
54921     for (k=0; k<3; k++)
54922              tmp1[k] = (float) xyzp->coo[l*3+k];
54923 
54924     for (k=0; k<3; k++)
54925              tmp3[k] = (float) xyzp->coo[m*3+k];
54926 
54927     colv[0] = ((GLdouble) colorr[1]) / 65535.0 ;
54928     colv[1] = ((GLdouble) colorg[1]) / 65535.0 ;
54929     colv[2] = ((GLdouble) colorb[1]) / 65535.0 ;
54930 
54931     ogarrow(0,tmp1,tmp3,roddef);
54932 
54933     glEndList();
54934 
54935 }
54936 
ogdipole()54937 void ogdipole()
54938 {
54939     double colv[3], tmp2[3], roddef;
54940     float tmp1[3], tmp3[3];
54941     int i,k,ic;
54942 
54943     roddef = (0.13/0.52917706);
54944 
54945     glDeleteLists(theDipole[istruct],1);
54946 
54947     theDipole[istruct] = -1;
54948     theDipole[istruct] = glGenLists(1);
54949 
54950     glNewList(theDipole[istruct], GL_COMPILE);
54951 
54952     ic = 2;
54953 
54954 #if defined(VMS) || defined(UNDERSC)
54955     cntvec(
54956 #else
54957 
54958 #ifdef CRAY
54959     CNTVEC(
54960 #else
54961     cntvec_(
54962 #endif
54963 #endif
54964 	tmp2,xyzp->coo,xyzp->ianz,xyzp->iatoms);
54965 
54966     for (k=0; k<3; k++)
54967         tmp1[k] = (float) tmp2[k];
54968 
54969     for (k=0; k<3; k++)
54970         tmp3[k] = (float) (qdpptr->dipo[k] + tmp2[k]);
54971 
54972     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
54973     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
54974     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
54975 
54976     ogarrow(ic,tmp1,tmp3,roddef);
54977 
54978     glEndList();
54979 
54980 }
54981 
ogaxes()54982 void ogaxes()
54983 {
54984     double roddef;
54985     int i,ic=-1;
54986 
54987     roddef = (0.13/0.52917706);
54988 
54989     glDeleteLists(theAxes,1);
54990 
54991     theAxes = -1;
54992     theAxes = glGenLists(1);
54993 
54994     glNewList(theAxes, GL_COMPILE);
54995 
54996 
54997     ogsphere(1,&AxesXYZ[0][0],0.5*roddef,0);
54998 
54999     for (i=1; i<4; i++) {
55000 	glMaterialfv(GL_FRONT_AND_BACK,
55001            GL_AMBIENT_AND_DIFFUSE, &AxesCol[i][0]);
55002 	ogarrow(ic,&AxesXYZ[0][0],&AxesXYZ[i][0],roddef);
55003     }
55004 
55005     glEndList();
55006 
55007 }
55008 
55009 #if defined(VMS) || defined(UNDERSC)
ogbegg(isurf,iopt,ityp,iorb,cntval,mapped,name)55010 void ogbegg(isurf,iopt,ityp,iorb,cntval,mapped,name)
55011 #else
55012 #ifdef CRAY
55013 void OGBEGG(isurf,iopt,ityp,iorb,cntval,mapped,name)
55014 #else
55015 void ogbegg_(isurf,iopt,ityp,iorb,cntval,mapped,name)
55016 #endif
55017 #endif
55018 int *isurf;
55019 int *mapped;
55020 int *iopt;
55021 int *ityp;
55022 int *iorb;
55023 double* cntval;
55024 char *name;
55025 {
55026       int itrns,isf,i,n,len,two;
55027       double cval;
55028       char *endquote;
55029       char *srftyp[] = { "orbital", "normal density", "laplacian",
55030 			 "mapped surface",
55031 			 "elec. pot.","diff. density","ELF",
55032 			 "unknown"};
55033 
55034       if (xison) {
55035 	glXMakeCurrent(display, win, cx);
55036 	glPopMatrix();
55037 	glPushMatrix();
55038       }
55039 
55040       itrns = 0;
55041       if (*isurf < 0) {
55042 	  itrns = 1;
55043       }
55044       TRANS = itrns;
55045       isf = abs(*isurf); isf--;
55046 
55047       cval = *cntval;
55048 
55049       NSurf[istruct]++;
55050 
55051       if (TRANS) {
55052          trns[istruct][NSurf[istruct]-1] = 1;
55053       }
55054       two = 1;
55055 
55056       if (*iopt) {
55057 	switch(*ityp) {
55058 	case 0:
55059 	  sndstr[istruct][NSurf[istruct]-1] = (char *) malloc(31);
55060 	  sprintf(sndstr[istruct][NSurf[istruct]-1],
55061 			"Orbital %3d isocontour %7.4f",*iorb,cval);
55062 	  break;
55063 	default:
55064 	  len = strlen(srftyp[*ityp]) + 20;
55065 	  sndstr[istruct][NSurf[istruct]-1] = (char *) malloc(len);
55066 	  sprintf(sndstr[istruct][NSurf[istruct]-1],
55067 			"%s isocontour %7.4f",srftyp[*ityp],cval);
55068 	  break;
55069 	}
55070         if (*ityp == 1 || *ityp == 3) two = 0;
55071       } else {
55072 	  endquote = strchr(name,'\"');
55073 	  if (endquote != NULL) endquote[0] = '\0';
55074 	  sndstr[istruct][NSurf[istruct]-1] = (char *) malloc(strlen(name)+1);
55075 	  strcpy(sndstr[istruct][NSurf[istruct]-1], name);
55076       }
55077 
55078       allocvert(MXVERT4,1);
55079 
55080       if (!xison) return;
55081 
55082       if (theSurf[istruct][NSurf[istruct]-1] > 0)
55083 	glDeleteLists(theSurf[istruct][NSurf[istruct]-1],1);
55084       theSurf[istruct][NSurf[istruct]-1] = glGenLists(1);
55085 
55086       if (denmode) {
55087 	  n = NSurf[istruct] - 2;
55088 	  if (NSurf[istruct] > 1 && (two && isf) ) n--;
55089 
55090 	  for (i=0; i<=n; i++) SSon[istruct][i] = 0;
55091       }
55092 
55093       if (isf > 1) isf = 1;
55094 
55095       SSon[istruct][NSurf[istruct]-1] = 1;
55096       clp[istruct][NSurf[istruct]-1] = 0;
55097       trns[istruct][NSurf[istruct]-1] = itrns;
55098 
55099       if (!STRCup && denmode) inistrc();
55100       RedrawSTRC();
55101 
55102       for (i=0; i<3; i++) {
55103 	diffuseColor[istruct][NSurf[istruct]-1][i] = cursrfcol[isf][i];
55104 	specularColor[NSurf[istruct]-1][i] = specColor[i];
55105       }
55106 
55107       glNewList(theSurf[istruct][NSurf[istruct]-1], GL_COMPILE);
55108 
55109       SStyp[istruct][NSurf[istruct]-1] = 0;
55110       Schain[istruct][NSurf[istruct]-1] = -1;
55111       if (*mapped) {
55112         glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
55113 	glEnable(GL_COLOR_MATERIAL);
55114 	SStyp[istruct][NSurf[istruct]-1] = 1;
55115       }
55116 
55117       glBegin(GL_TRIANGLES);
55118 }
55119 
55120 #if defined(VMS) || defined(UNDERSC)
ogendd(ichain)55121 void ogendd(ichain)
55122 #else
55123 #ifdef CRAY
55124 void OGENDD(ichain)
55125 #else
55126 void ogendd_(ichain)
55127 #endif
55128 #endif
55129 int *ichain;
55130 {
55131       glEnd();
55132       glDisable(GL_COLOR_MATERIAL);
55133       glEndList();
55134       if (*ichain != -1) Schain[istruct][NSurf[istruct]-1] = *ichain;
55135 }
55136 
allocvert(siz,first)55137 void allocvert(siz,first)
55138 int siz;
55139 int first;
55140 {
55141    VRTSTRU *spnt;
55142    VRTSTRU tmp;
55143    int i;
55144 
55145    spnt = srfvert[istruct][NSurf[istruct]-1];
55146 
55147    if (first) {
55148 	nvert[istruct][NSurf[istruct]-1] = 0;
55149 	nvrtmx[istruct][NSurf[istruct]-1] = 0;
55150    }
55151 
55152    srfvert[istruct][NSurf[istruct]-1] =
55153 	(VRTSTRU *) malloc((sizeof tmp)*siz);
55154 
55155 
55156    if (srfvert[istruct][NSurf[istruct]-1] == NULL) {
55157 	srfvert[istruct][NSurf[istruct]-1] = spnt;
55158 	dovrt = 0;
55159 	fprintf(stderr,"failed to allocate memory to store vertices \n");
55160    } else {
55161 	if (spnt != NULL) {
55162 	    if (!first) {
55163 		for (i=0; i<nvert[istruct][NSurf[istruct]-1]-1; i++)
55164 		    srfvert[istruct][NSurf[istruct]-1][i] = spnt[i];
55165 	    }
55166 	    free(spnt);
55167 	}
55168 	nvrtmx[istruct][NSurf[istruct]-1] = siz;
55169    }
55170 }
55171 
putvrt(v1,v2,v3,type)55172 void putvrt(v1,v2,v3,type)
55173 double *v1;
55174 double *v2;
55175 double *v3;
55176 int type;
55177 {
55178       int isrf,siz;
55179 
55180       if (!dovrt) return;
55181 
55182       isrf = NSurf[istruct]-1;
55183 
55184       nvert[istruct][isrf]++;
55185 
55186       if (nvert[istruct][isrf] > nvrtmx[istruct][isrf]) {
55187 	  switch (nvrtmx[istruct][isrf]) {
55188 	  case 0:
55189 		siz = MXVERT;
55190 		break;
55191 	  case MXVERT:
55192 		siz = MXVERT2;
55193 		break;
55194 	  case MXVERT2:
55195 		siz = MXVERT3;
55196 		break;
55197 	  case MXVERT3:
55198 		siz = MXVERT4;
55199 		break;
55200 	  case MXVERT4:
55201 		siz = MXVERT5;
55202 		break;
55203 	  case MXVERT5:
55204 		siz = MXVERT6;
55205 		break;
55206 	  case MXVERT6:
55207 		siz = MXVERT7;
55208 		break;
55209 	  case MXVERT7:
55210 		siz = MXVERT8;
55211 		break;
55212 	  case MXVERT8:
55213 		siz = MXVERT9;
55214 		break;
55215 	  case MXVERT9:
55216 		siz = MXVERT10;
55217 		break;
55218 	  case MXVERT10:
55219 		siz = MXVERT11;
55220 		break;
55221 	  case MXVERT11:
55222 		siz = MXVERT12;
55223 		break;
55224 	  default:
55225 		siz = 0;
55226 	  }
55227 	  if (siz) allocvert(siz,0);
55228 	  else dovrt = 0;
55229 
55230       }
55231       if (dovrt) {
55232 	srfvert[istruct][isrf][nvert[istruct][isrf]-1].vert[0] = (float) *v1;
55233 	srfvert[istruct][isrf][nvert[istruct][isrf]-1].vert[1] = (float) *v2;
55234 	srfvert[istruct][isrf][nvert[istruct][isrf]-1].vert[2] = (float) *v3;
55235 	srfvert[istruct][isrf][nvert[istruct][isrf]-1].type = type;
55236       }
55237 }
55238 
55239 #if defined(VMS) || defined(UNDERSC)
ogcoll(double * v1,double * v2,double * v3)55240 void ogcoll(double *v1, double *v2, double *v3)
55241 #else
55242 #ifdef CRAY
55243 void OGCOLL(double *v1, double *v2, double *v3)
55244 #else
55245 void ogcoll_(double *v1, double *v2, double *v3)
55246 #endif
55247 #endif
55248 {
55249 
55250 
55251       putvrt(v1,v2,v3,0);
55252 
55253       glColor4d(*v1,*v2,*v3,tr_val);
55254 }
55255 
55256 
ogelev(name)55257 void ogelev(name)
55258 char *name;
55259 {
55260       int i;
55261       char *endquote;
55262 
55263       glPopMatrix();
55264       glPushMatrix();
55265 
55266       NSurf[istruct]++;
55267       endquote = strchr(name,'\"');
55268       if (endquote != NULL) endquote[0] = '\0';
55269       sndstr[istruct][NSurf[istruct]-1] = (char *) malloc(strlen(name)+1);
55270       strcpy(sndstr[istruct][NSurf[istruct]-1],name);
55271       allocvert(MXVERT,1);
55272 
55273       theSurf[istruct][NSurf[istruct]-1] = glGenLists(1);
55274       glNewList(theSurf[istruct][NSurf[istruct]-1], GL_COMPILE);
55275 
55276       for (i=0; i<4; i++)
55277 	diffuseColor[istruct][NSurf[istruct]-1][i] = materialColor[ecol][i];
55278       SStyp[istruct][NSurf[istruct]-1] = 2;
55279       Schain[istruct][NSurf[istruct]-1] = -1;
55280 
55281       glBegin(GL_QUADS);
55282 }
55283 
55284 #if defined(VMS) || defined(UNDERSC)
ogribb(iscnd)55285 void ogribb(iscnd)
55286 #else
55287 #ifdef CRAY
55288 void OGRIBB(iscnd)
55289 #else
55290 void ogribb_(iscnd)
55291 #endif
55292 #endif
55293 int *iscnd;
55294 {
55295       int i;
55296 
55297       if (NSurf[istruct] >= MAXSURF) return;
55298 
55299       NSurf[istruct]++;
55300       if (sndstr[istruct][NSurf[istruct]-1] != NULL)
55301 	free(sndstr[istruct][NSurf[istruct]-1]);
55302 
55303       switch (*iscnd) {
55304 	case 0:
55305 		RIBindex[istruct].nhelx++;
55306 		sndstr[istruct][NSurf[istruct]-1] =
55307 			(char *) malloc(10);
55308 		sprintf(sndstr[istruct][NSurf[istruct]-1],
55309 			"Helix %d",RIBindex[istruct].nhelx);
55310 		break;
55311 	case 1:
55312 		RIBindex[istruct].nbeta++;
55313 		sndstr[istruct][NSurf[istruct]-1] =
55314 			(char *) malloc(9);
55315 		sprintf(sndstr[istruct][NSurf[istruct]-1],
55316 			"Beta %d",RIBindex[istruct].nbeta);
55317 		break;
55318 	case 2:
55319 		RIBindex[istruct].nrna++;
55320 		sndstr[istruct][NSurf[istruct]-1] =
55321 			(char *) malloc(8);
55322 		sprintf(sndstr[istruct][NSurf[istruct]-1],
55323 			"RNA %d",RIBindex[istruct].nrna);
55324 		break;
55325 	case 3:
55326 		RIBindex[istruct].ncoil++;
55327 		sndstr[istruct][NSurf[istruct]-1] =
55328 			(char *) malloc(9);
55329 		sprintf(sndstr[istruct][NSurf[istruct]-1],
55330 			"Coil %d",RIBindex[istruct].ncoil);
55331 		break;
55332       }
55333 
55334       if (theSurf[istruct][NSurf[istruct]-1] > 0)
55335 	glDeleteLists(theSurf[istruct][NSurf[istruct]-1],1);
55336       theSurf[istruct][NSurf[istruct]-1] = glGenLists(1);
55337       allocvert(MXVERT,1);
55338       glEnable(GL_COLOR_MATERIAL);
55339       glNewList(theSurf[istruct][NSurf[istruct]-1], GL_COMPILE);
55340       SStyp[istruct][NSurf[istruct]-1] = 2;
55341       Schain[istruct][NSurf[istruct]-1] = -1;
55342 
55343       glBegin(GL_QUADS);
55344 }
55345 
putbyte(outf,val)55346 void putbyte(outf,val)
55347 FILE *outf;
55348 unsigned char val;
55349 {
55350         unsigned char buf[1];
55351 
55352         buf[0] = val;
55353         fwrite(buf,1,1,outf);
55354 }
55355 
putshort(outf,val)55356 void putshort(outf,val)
55357 FILE *outf;
55358 unsigned short val;
55359 {
55360         unsigned char buf[2];
55361 
55362         buf[0] = (val>>8);
55363         buf[1] = (val>>0);
55364         fwrite(buf,2,1,outf);
55365     }
55366 
putlong(outf,val)55367 static int putlong(outf,val)
55368 FILE *outf;
55369 unsigned long val;
55370 {
55371 	unsigned char buf[4];
55372 
55373 	buf[0] = (val>>24);
55374 	buf[1] = (val>>16);
55375 	buf[2] = (val>>8);
55376 	buf[3] = (val>>0);
55377 	return fwrite(buf,4,1,outf);
55378 }
55379 
WOGLGIF(filename)55380 int WOGLGIF(filename)
55381     char *filename;
55382 {
55383   int   ColorMapSize, BitsPerPixel;
55384   int   i,j,nc;
55385   int   numcols;
55386   Byte *imag;
55387   Byte  rmap[256],gmap[256],bmap[256];
55388 
55389   int rowlen;
55390   GLubyte *rgbbuf;
55391   GLint viewport[4];
55392 
55393   GIFFile = fopen(filename,"w+b");
55394   if (!GIFFile) {
55395 	fprintf(stderr,"Output Error: Unable to create GIF file %s\n",filename);
55396 	return(0);
55397   }
55398 
55399   glGetIntegerv(GL_VIEWPORT, viewport);
55400 
55401   rowlen = viewport[2];
55402   if (width < rowlen) rowlen = width;
55403 
55404   glPixelStorei(GL_PACK_ROW_LENGTH,rowlen);
55405   glPixelStorei(GL_PACK_ALIGNMENT,1);
55406 
55407   rgbbuf = (GLubyte *)malloc(3*rowlen*height*sizeof(GLubyte));
55408   if (!rgbbuf) {
55409        fprintf(stderr,"moldenogl: couldn't allocate memory\n");
55410        fclose(GIFFile);
55411        return(1);
55412   }
55413   glReadBuffer(GL_FRONT);
55414   glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,rgbbuf);
55415 
55416   numcols = 256;
55417   imag = (Byte *) malloc((size_t) (width * height));
55418 
55419   if (!imag) {
55420 	fprintf(stderr,"Unable to malloc in WriteGIF()");
55421 	return(1);
55422   }
55423 
55424   clmap[0] = (unsigned char *) rmap;
55425   clmap[1] = (unsigned char *) gmap;
55426   clmap[2] = (unsigned char *) bmap;
55427 
55428   if (quant((Byte *) rgbbuf, width, height, imag, numcols) ) {
55429 	free(imag);  return(1);
55430   }
55431 
55432   for (i=0; i<numcols; i++) {
55433 	pix2col[i] = red[i] = green[i] = blue[i] = 0;
55434   }
55435 
55436   nc = 0;
55437 
55438   for (i=0; i<numcols; i++) {
55439     for (j=0; j<i; j++) {
55440       if (rmap[i] == rmap[j] && gmap[i] == gmap[j] &&
55441 	  bmap[i] == bmap[j]) break;
55442     }
55443 
55444     if (j==i) {
55445       pix2col[i] = nc;
55446       red[nc]   = rmap[i];
55447       green[nc] = gmap[i];
55448       blue[nc]  = bmap[i];
55449       nc++;
55450     }
55451     else pix2col[i] = pix2col[j];
55452   }
55453 
55454   for (BitsPerPixel=1; BitsPerPixel<8; BitsPerPixel++)
55455     if ( (1<<BitsPerPixel) >= nc) break;
55456 
55457   ColorMapSize = 1 << BitsPerPixel;
55458 
55459   fwrite("GIF87a", (size_t) 1, (size_t) 6, GIFFile);
55460   fputc(width&0xff,GIFFile);  fputc((width>>8)&0xff,GIFFile);
55461   fputc(height&0xff,GIFFile);  fputc((height>>8)&0xff,GIFFile);
55462 
55463   fputc(0xf0|(BitsPerPixel-1),GIFFile);
55464 
55465   fputc(0, GIFFile);
55466   fputc(0, GIFFile);
55467 
55468   for (i=0; i<ColorMapSize; i++) {
55469       fputc(red[i], GIFFile);
55470       fputc(green[i], GIFFile);
55471       fputc(blue[i], GIFFile);
55472   }
55473 
55474   fputc( ',', GIFFile );
55475 
55476   fputc(0x00,GIFFile); fputc(0x00,GIFFile);
55477   fputc(0x00,GIFFile); fputc(0x00,GIFFile);
55478   fputc(width&0xff,GIFFile); fputc((width>>8)&0xff,GIFFile);
55479   fputc(height&0xff,GIFFile); fputc((height>>8)&0xff,GIFFile);
55480   fputc(0x00,GIFFile); fputc(BitsPerPixel,GIFFile);
55481 
55482   compress(BitsPerPixel, nc, imag, 2);
55483 
55484   fputc(';',GIFFile);
55485   fclose(GIFFile);
55486   free(rgbbuf);
55487   free(imag);
55488 
55489   return(0);
55490 }
55491 
save_rgb(rgbfile)55492 void save_rgb(rgbfile)
55493 char *rgbfile;
55494 {
55495 	FILE *of;
55496         char iname[80];
55497         int i, k, x, y, rowlen;
55498 	int Xsize, Ysize;
55499 	GLubyte *rgbbuf;
55500 	GLint viewport[4];
55501 
55502         of = fopen(rgbfile,"w");
55503 
55504         if (!of) {
55505             fprintf(stderr,"moldenogl: can't open output file\n");
55506             return;
55507         }
55508 
55509 	glGetIntegerv(GL_VIEWPORT, viewport);
55510 	Xsize = width;
55511 	Ysize = height;
55512 
55513 	rowlen = viewport[2];
55514 	if (width < rowlen) rowlen = width;
55515 
55516 	glPixelStorei(GL_PACK_ROW_LENGTH,rowlen);
55517 	glPixelStorei(GL_PACK_ALIGNMENT,1);
55518 
55519 	rgbbuf = (GLubyte *)malloc(3*rowlen*height*sizeof(GLubyte));
55520 	if (!rgbbuf) {
55521 	   fprintf(stderr,"moldenogl: couldn't allocate memory\n");
55522 	   fclose(of);
55523 	   return;
55524 	}
55525 	glReadBuffer(GL_FRONT);
55526 	glReadPixels(viewport[0],viewport[1],Xsize,Ysize,GL_RGB,GL_UNSIGNED_BYTE,rgbbuf);
55527 
55528         putshort(of,474);	/* MAGIC		*/
55529         putbyte(of,0);		/* STORAGE is VERBATIM	*/
55530         putbyte(of,257);	/* BPC is 257          	*/
55531         putshort(of,3);		/* DIMENSION is 3	*/
55532         putshort(of,Xsize);	/* XSIZE               	*/
55533         putshort(of,Ysize);	/* YSIZE               	*/
55534         putshort(of,3);		/* ZSIZE               	*/
55535         putlong(of,0);		/* PIXMIN is 0         	*/
55536         putlong(of,255);	/* PIXMAX is 255       	*/
55537         for(i=0; i<4; i++)	/* DUMMY 4 bytes 	*/
55538             putbyte(of,0);
55539         strcpy(iname,"Moldenogl");
55540         fwrite(iname,80,1,of);	/* IMAGENAME  		*/
55541         putlong(of,0);		/* COLORMAP is 0 	*/
55542 
55543         for(i=0; i<404; i++)
55544             putbyte(of,0);
55545 
55546 /* red */
55547         k=0;
55548         for(i=0;i< Xsize*Ysize; i++){
55549          fwrite( &rgbbuf[k] ,sizeof(*rgbbuf), 1, of);
55550          k=k+3;
55551         }
55552 
55553 /* green */
55554         k=0;
55555         for(i=0;i< Xsize*Ysize; i++){
55556          fwrite( &rgbbuf[k+1] ,sizeof(*rgbbuf), 1, of);
55557          k=k+3;
55558         }
55559 
55560 /* blue */
55561         k=0;
55562         for(i=0;i< Xsize*Ysize; i++){
55563          fwrite( &rgbbuf[k+2] ,sizeof(*rgbbuf), 1, of);
55564          k=k+3;
55565         }
55566 
55567         fclose(of);
55568 	free(rgbbuf);
55569 }
55570 
55571 unsigned char bmp_header[]=
55572 { 'B','M', 0,0,0,0, 0,0, 0,0, 54,0,0,0,
55573   40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0, 0,0,0,0, 0,0,0,0,
55574   0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };
55575 
WLSBL(val,arr)55576 static void WLSBL(val,arr)
55577     int val;
55578     unsigned char* arr;
55579 {
55580     arr[0] = (char) (val&0xff);
55581     arr[1] = (char) ((val>>8) &0xff);
55582     arr[2] = (char) ((val>>16)&0xff);
55583     arr[3] = (char) ((val>>24)&0xff);
55584 }
55585 
save_bmp(rgbfile)55586 void save_bmp(rgbfile)
55587 char *rgbfile;
55588 { int i,j;
55589   FILE *fp;
55590   GLubyte *rgbbuf;
55591   GLubyte rgbtmp[3];
55592   GLint viewport[4];
55593   int Xsize, Ysize, rowlen;
55594   int pad;
55595 
55596   fp = fopen(rgbfile,"wb");
55597 
55598   if (!fp) {
55599        fprintf(stderr,"moldenogl: can't open output file\n");
55600        return;
55601   }
55602 
55603   glGetIntegerv(GL_VIEWPORT, viewport);
55604 
55605   Xsize = width;
55606   Ysize = height;
55607 
55608   rowlen = viewport[2];
55609   if (width < rowlen) rowlen = width;
55610 
55611   glPixelStorei(GL_PACK_ROW_LENGTH,rowlen);
55612 /*  glPixelStorei(GL_PACK_ROW_LENGTH,Ysize);*/
55613   glPixelStorei(GL_PACK_ALIGNMENT,1);
55614 
55615   rgbbuf = (GLubyte *)malloc(3*rowlen*Ysize*sizeof(GLubyte));
55616   if (!rgbbuf) {
55617 	fprintf(stderr,"moldenogl: couldn't allocate memory\n");
55618 	fclose(fp);
55619 	return;
55620   }
55621   glReadBuffer(GL_FRONT);
55622   glReadPixels(viewport[0],viewport[1],Xsize,Ysize,GL_RGB,GL_UNSIGNED_BYTE,rgbbuf);
55623 
55624 /* The number of bytes on a screenline should be wholly devisible by 4 */
55625 
55626   pad = (Xsize*3)%4;
55627   if (pad) pad = 4 - pad;
55628 
55629   WLSBL((int) (3*Xsize+pad)*Ysize+54,bmp_header+2);
55630   WLSBL((int) Xsize,bmp_header+18);
55631   WLSBL((int) Ysize,bmp_header+22);
55632   WLSBL((int) 3*Xsize*Ysize,bmp_header+34);
55633 
55634   fwrite(bmp_header,1,54,fp);
55635 
55636   for (i=0;i<Ysize;i++) {
55637     for (j=0;j<Xsize;j++) {
55638 	rgbtmp[0] = rgbbuf[(j+rowlen*i)*3+2];
55639 	rgbtmp[1] = rgbbuf[(j+rowlen*i)*3+1];
55640 	rgbtmp[2] = rgbbuf[(j+rowlen*i)*3+0];
55641 	fwrite(rgbtmp,3,1,fp);
55642     }
55643     rgbtmp[0] = (char) 0;
55644     for (j=0;j<pad;j++) fwrite(rgbtmp,1,1,fp);
55645   }
55646   fclose(fp);
55647   free(rgbbuf);
55648 }
55649 
55650 
empty_ribb()55651 void empty_ribb()
55652 {
55653   int i,j;
55654   int SSont[MAXSURF],NStmp;
55655 
55656   for (i=0; i < 4; i++) {
55657 	for (j=RIBindex[istruct].start[i];
55658 		j <= RIBindex[istruct].end[i]; j++) {
55659 		if (j >= 0) SSon[istruct][j] = -1;
55660 	}
55661   }
55662 
55663   NStmp = 0;
55664   for (i=0; i < NSurf[istruct]; i++)
55665 	if (SSon[istruct][i] != -1) {
55666 		SSont[NStmp] = SSon[istruct][i];
55667 		NStmp++;
55668 	}
55669 
55670   for (i=0; i < NSurf[istruct]; i++)
55671 	SSon[istruct][i] = 0;
55672 
55673   for (i=0; i < 4; i++) {
55674 	for (j=RIBindex[istruct].start[i];
55675 		j <= RIBindex[istruct].end[i]; j++) {
55676 		if (j >= 0) SSon[istruct][j] = 1;
55677 	}
55678   }
55679 
55680   DeleteActiveSurfaces();
55681 
55682   for (i=0; i < NSurf[istruct]; i++)
55683 	SSon[istruct][i] = SSont[i];
55684 
55685   RIBindex[istruct].nhelx = 0;
55686   RIBindex[istruct].nbeta = 0;
55687   RIBindex[istruct].nrna = 0;
55688   RIBindex[istruct].ncoil = 0;
55689 
55690   SSdone[istruct] = -1;
55691 
55692 }
55693 
empty_model(sel,updis)55694 void empty_model(sel,updis)
55695 int sel;
55696 int updis;
55697 {
55698   int i;
55699 
55700   if (!has_opengl) return;
55701 
55702   if (theMol[sel][0] != -1)
55703 	glDeleteLists(theMol[sel][0],1);
55704   theMol[sel][0] = (GLuint) -1;
55705   for (i=0; i<NSurf[sel]; i++) {
55706       if (theSurf[sel][i] != -1)
55707 	glDeleteLists(theSurf[sel][i],1);
55708       theSurf[sel][i] = -1;
55709       if (sndstr[sel][i] != NULL) free(sndstr[sel][i]);
55710       sndstr[sel][i] = NULL;
55711       if (srfvert[sel][i] != NULL) free(srfvert[sel][i]);
55712       srfvert[sel][i] = NULL;
55713       nvert[sel][i] = 0;
55714       nvrtmx[sel][i] = 0;
55715       Schain[sel][i] = -1;
55716       clp[sel][i] = -1;
55717       trns[sel][i] = -1;
55718       if (!addfile) SSon[sel][i] = 0;
55719   }
55720 
55721   RIBindex[sel].nhelx = 0;
55722   RIBindex[sel].nbeta = 0;
55723   RIBindex[sel].nrna = 0;
55724   RIBindex[sel].ncoil = 0;
55725 
55726   for (i=0; i<4; i++) {
55727 	RIBindex[sel].start[i] = -1;
55728 	RIBindex[sel].end[i] = -1;
55729   }
55730 
55731   if (*ipdbon) {
55732       for (i=0; i<calfptr->ncalf; i++) {
55733 	if (theRes[sel][i] != -1)
55734 	   glDeleteLists(theRes[sel][i],1);
55735 	theRes[sel][i] = -1;
55736 	if (theBck[sel][i] != -1)
55737 	   glDeleteLists(theBck[sel][i],1);
55738 	theBck[sel][i] = -1;
55739       }
55740   }
55741   if (theLines[sel] != -1)
55742       glDeleteLists(theLines[sel],1);
55743   theLines[sel] = -1;
55744 
55745   if (theFLines[sel] != -1)
55746       glDeleteLists(theFLines[sel],1);
55747   theFLines[sel] = -1;
55748 
55749   if (thePoints[sel] != -1)
55750       glDeleteLists(thePoints[sel],1);
55751   thePoints[sel] = -1;
55752 
55753   if (theForces[sel] != -1)
55754       glDeleteLists(theForces[sel],1);
55755   theForces[sel] = -1;
55756 
55757   if (theSArrow[sel] != -1)
55758       glDeleteLists(theSArrow[sel],1);
55759   theSArrow[sel] = -1;
55760 
55761   if (theFeat[sel] != -1)
55762       glDeleteLists(theFeat[sel],1);
55763   theFeat[sel] = -1;
55764 
55765   if (theIntSurf[sel] != -1)
55766       glDeleteLists(theIntSurf[sel],1);
55767   theIntSurf[sel] = -1;
55768 
55769   if (theIntSurf2[sel] != -1)
55770       glDeleteLists(theIntSurf2[sel],1);
55771   theIntSurf2[sel] = -1;
55772 
55773   if (theLigSurf[sel] != -1)
55774       glDeleteLists(theLigSurf[sel],1);
55775   theLigSurf[sel] = -1;
55776 
55777   if (theMon[sel] != -1)
55778       glDeleteLists(theMon[sel],1);
55779   theMon[sel] = -1;
55780 
55781   if (theSel[sel] != -1)
55782       glDeleteLists(theSel[sel],1);
55783   theSel[sel] = -1;
55784 
55785   if (theBox[sel] != -1)
55786       glDeleteLists(theBox[sel],1);
55787   theBox[sel] = -1;
55788 
55789   SSdone[sel] = -1;
55790   NSurf[sel] = 0;
55791 
55792   if (updis) {
55793      if ((((*fancy || *fullgl) && !denmode) || (*ifdogl && denmode))
55794 	&& has_opengl) dispsf();
55795   }
55796   RedrawSTRC();
55797 }
55798 
setcl(i)55799 void setcl(i)
55800 int i;
55801 {
55802   if (glIsEnabled(GL_COLOR_MATERIAL)) {
55803 	glColor4f(diffuseColor[istruct][i][0], diffuseColor[istruct][i][1],
55804 	diffuseColor[istruct][i][2],(GLfloat) tr_val);
55805   }
55806 
55807   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuseColor[istruct][i][0]);
55808   if (denmode) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientDColor);
55809   else glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientColor);
55810   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specularColor[i][0]);
55811   glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);
55812 }
55813 
55814 #if defined(VMS) || defined(UNDERSC)
setcll()55815 void setcll()
55816 #else
55817 #ifdef CRAY
55818 void SETCLL()
55819 #else
55820 void setcll_()
55821 #endif
55822 #endif
55823 {
55824   int isrf,i;
55825   float grcol[4] = {0.6,0.6,0.6,0.6};
55826   float spcol[4] = {0.8,0.8,0.8,1.0};
55827 
55828   glEnd();
55829   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, grcol);
55830   if (denmode) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientDColor);
55831   else glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientColor);
55832   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spcol);
55833   glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100);
55834   isrf = NSurf[istruct]-1;
55835   nvert[istruct][isrf]++;
55836   srfvert[istruct][isrf][nvert[istruct][isrf]-1].type = 2;
55837   glBegin(GL_QUADS);
55838   glColor4d(grcol[0], grcol[1], grcol[2], grcol[3]);
55839 }
55840 
pldst()55841 void pldst()
55842 {
55843   int i,i1,i2,ixt,iyt,i8;
55844   char s[9];
55845 
55846   i8 = 8;
55847   XSetForeground(display, gc, colors[15]);
55848 
55849   for (i=0; i<monptr->ndm; i++) {
55850 	i1 = monptr->idmon[i][0] - 1;
55851 	i2 = monptr->idmon[i][1] - 1;
55852 	ixt = (xyzp->ixp[i1] + xyzp->ixp[i2])/2;
55853 	iyt = (xyzp->iyp[i1] + xyzp->iyp[i2])/2;
55854 	sprintf(s,"%8.3f",monptr->rdm[i]);
55855 
55856 #if defined(VMS) || defined(UNDERSC)
55857 	drwstr(&ixt,&iyt,s,&i8,&MONE);
55858 #else
55859 #ifdef CRAY
55860 	DRWSTR(&ixt,&iyt,s,&i8,&MONE);
55861 #else
55862 	drwstr_(&ixt,&iyt,s,&i8,&MONE);
55863 #endif
55864 #endif
55865   }
55866 }
55867 
prtMat(Mat)55868 void prtMat(Mat)
55869 GLdouble *Mat;
55870 {
55871      fprintf(stderr,"modelV:\n");
55872      fprintf(stderr,"%f %f %f %f\n",Mat[0],Mat[1],Mat[2],Mat[3]);
55873      fprintf(stderr,"%f %f %f %f\n",Mat[4],Mat[5],Mat[6],Mat[7]);
55874      fprintf(stderr,"%f %f %f %f\n",Mat[8],Mat[9],Mat[10],Mat[11]);
55875      fprintf(stderr,"%f %f %f %f\n",Mat[12],Mat[13],Mat[14],Mat[15]);
55876 }
55877 
55878 static GLdouble InvModelMat[16];
55879 
InvRotMat()55880 void InvRotMat()
55881 {
55882   GLdouble modelMatrix[16];
55883 
55884   glMatrixMode(GL_MODELVIEW);
55885   glPushMatrix();
55886   glLoadIdentity();
55887   glRotatef(45.0,0.0,1.0,0.0);
55888   glGetDoublev(GL_MODELVIEW_MATRIX,InvModelMat);
55889   //invmat(modelMatrix,InvModelMat);
55890   glPopMatrix();
55891 }
55892 
ModelMatInv()55893 void ModelMatInv()
55894 {
55895   GLdouble modelMatrix[16];
55896 
55897   glMatrixMode(GL_MODELVIEW);
55898   glPushMatrix();
55899   glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
55900   invmat(modelMatrix,InvModelMat);
55901   glPopMatrix();
55902 }
55903 
SetGLSLVar()55904 void SetGLSLVar()
55905 {
55906 
55907   if (has_shader) {
55908 #ifdef GL_COLOR_ATTACHMENT0_EXT
55909 	if (DoShadow) {
55910 	    glUseProgramObjectARB(program[11]);
55911 	} else {
55912 #endif
55913 	    glUseProgramObjectARB(program[0]);
55914 	    if (*shade) {
55915 		glUniform1iARB(dofog, 1);
55916 	    } else {
55917 		glUniform1iARB(dofog, 0);
55918 	    }
55919 	    if (DoBlur) {
55920 		glUniform1iARB(doblur, 1);
55921 	    } else glUniform1iARB(doblur, 0);
55922 	    if (DoSSAO) {
55923 		glUniform1iARB(dossao, 1);
55924 	    } else glUniform1iARB(dossao, 0);
55925 	    if (DoShad) {
55926 		glUniform1iARB(DoShadLoc, 1);
55927 	    } else glUniform1iARB(DoShadLoc, 0);
55928 	    if (TRANS) {
55929 		glUniform1iARB(dotrns, 1);
55930 	    } else glUniform1iARB(dotrns, 0);
55931 #ifdef GL_COLOR_ATTACHMENT0_EXT
55932 	}
55933 #endif
55934   }
55935 }
55936 
trnsproj0()55937 void trnsproj0()
55938 {
55939   double sc;
55940 
55941   glMatrixMode(GL_PROJECTION);
55942   glLoadIdentity();
55943 
55944   if (*persp) {
55945 	glFrustum(-0.2*Aspect,0.2*Aspect,-0.2,0.2,0.3,600.0);
55946   } else {
55947 	glOrtho(1.0*Aspect,-1.0*Aspect,1.0,-1.0,-10.0,300.0);
55948   }
55949 
55950   glMatrixMode(GL_MODELVIEW);
55951   glLoadIdentity();
55952 
55953   if (*persp) {
55954 	glTranslatef( 1.0*posptr->yv, -1.0*posptr->xv, -2.0*posptr->zv);
55955   } else {
55956 	sc = -1.0 / scalptr->scal;
55957 	glScalef(sc,sc,-1.0*sc);
55958 	glTranslatef( 1.0*posptr->yv, -1.0*posptr->xv, 0.0);
55959   }
55960   glEnable(GL_NORMALIZE);
55961 }
55962 
trnsproj1()55963 void trnsproj1()
55964 {
55965 #ifdef GL_COLOR_ATTACHMENT0_EXT
55966   if (DoShadow) glRotatef(25.0,0.0,1.0,0.0);
55967 #endif
55968 
55969   glMultMatrixd((const GLdouble *) RR);
55970 
55971   if (denmode) glTranslatef(-rotptr->td[0] ,-rotptr->td[1],-rotptr->td[2]);
55972   else glTranslatef(-rotptr->t[0] ,-rotptr->t[1],-rotptr->t[2]);
55973 }
55974 
dispsf()55975 void dispsf()
55976 {
55977   int i,j,j1,Ca,sizt,idres,ilptr;
55978   int zero = 0;
55979   double ca,sa,x,y,z,tn[3];
55980   GLdouble modelMatrix[16];
55981   GLdouble projMatrix[16];
55982   GLint viewport[4];
55983   GLdouble tmp1[3],tmp2[3],xt,yt,zt,srad;
55984 
55985   float tmp[3];
55986   float axes_light[] = {0.0, 0.0, -4.0, 1};
55987 
55988   glXMakeCurrent(display, win, cx);
55989 
55990   glDisable(GL_CULL_FACE);
55991   glClearDepth(1);
55992   if (DoShadow) {
55993 	glClearColor(0.0, 0.0, 0.0, 1.0);
55994   } else {
55995 	glClearColor(gradcol[0][0],gradcol[0][1],gradcol[0][2],1.0);
55996   }
55997 
55998 #ifdef GL_COLOR_ATTACHMENT0_EXT
55999   if ((DoBlur || DoSSAO) && has_fbo) {
56000 	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
56001 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[0]);
56002 	glDrawBuffers(2,buffers);
56003   }
56004 
56005 /*
56006 	glEnable(GL_CULL_FACE);
56007 	glCullFace(GL_FRONT);
56008 */
56009 
56010 
56011   if (DoShadow && has_fbo) {
56012 	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
56013 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[0]);
56014 	glDrawBuffers(1,buffers);
56015 	glEnable(GL_CULL_FACE);
56016 	glCullFace(GL_FRONT);
56017   }
56018 
56019 #endif
56020 
56021 #ifdef GL_ARB_shader_objects
56022   if (has_shader) glUseProgramObjectARB(0);
56023 #endif
56024   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
56025 
56026 #ifdef GL_COLOR_ATTACHMENT0_EXT
56027   if (!DoShadow) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
56028 #endif
56029 
56030   for (i=0; i < 3; i++) {
56031      RR[i][1] = rotptr->rx[i];
56032      RR[i][0] = -rotptr->ry[i];
56033      RR[i][2] = rotptr->rz[i];
56034   }
56035 
56036   if (!DoShadow) if (BGmode) bckgrad();
56037 
56038 #ifdef GL_COLOR_ATTACHMENT0_EXT
56039   if (DoSSAO && has_fbo) {
56040 	   glDrawBuffer(GL_COLOR_ATTACHMENT2_EXT);
56041 	   glClearColor(0.0, 0.0, 0.0, 1.0);
56042 	   glClear(GL_COLOR_BUFFER_BIT);
56043 	   glDrawBuffers(3,buffers);
56044   }
56045 #endif
56046 
56047   if (AXES) {
56048 
56049 /* create the projection and model matrix for the axes */
56050 
56051      glMatrixMode(GL_PROJECTION);
56052      glLoadIdentity();
56053      glMatrixMode(GL_MODELVIEW);
56054      glLoadIdentity();
56055      glLightfv(GL_LIGHT2, GL_POSITION, axes_light);
56056      glScalef(1.0,1.0,-1.0);
56057      glTranslatef(-0.8 ,-0.8, 0.0);
56058      glScalef(0.1,0.1,0.1);
56059      glMultMatrixd((const GLdouble *) RR);
56060      glCallList(theAxes);
56061 
56062      glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
56063      glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
56064      glGetIntegerv(GL_VIEWPORT,viewport);
56065 
56066      for (i=1; i<4; i++) {
56067         if (gluProject((GLdouble) AxesXYZ[i][0],(GLdouble) AxesXYZ[i][1],(GLdouble) AxesXYZ[i][2],modelMatrix,projMatrix,viewport,&xt,&yt,&zt)) {
56068            AxesProj[i][0] = (height - (int) yt);
56069            AxesProj[i][1] = (int) xt;
56070 	}
56071      }
56072 /*
56073    remark: there is a difference between lighting in xwindow and OpenGL
56074            the opengl z-axis is pointing the opposite direction of the
56075            xwindows z-axis (with respect to shading
56076    The glScalef(1.0,1.0,-1.0); has to do with that
56077 */
56078   }
56079 
56080 SHADOW:
56081 
56082   trnsproj0();
56083   glMatrixMode(GL_MODELVIEW);
56084 
56085 /*  glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, &gradcol[1][0]);*/
56086   glLightfv(GL_LIGHT0, GL_POSITION, light0_position[istruct]);
56087   if (DoLights) {
56088      glPushMatrix();
56089      glTranslatef(light0_position[istruct][0],light0_position[istruct][1],
56090 		  light0_position[istruct][2]);
56091      gluSphere(sphere, 1, 10, 10);
56092      glPopMatrix();
56093   }
56094 
56095   glLightfv(GL_LIGHT1, GL_POSITION, light1_position[istruct]);
56096   if (DoLights) {
56097      glPushMatrix();
56098      glTranslatef(light1_position[istruct][0],light1_position[istruct][1],
56099 		  light1_position[istruct][2]);
56100      gluSphere(sphere, 1, 10, 10);
56101      glPopMatrix();
56102   }
56103 
56104   glLightfv(GL_LIGHT2, GL_POSITION, light2_position[istruct]);
56105   if (DoLights) {
56106      glPushMatrix();
56107      glTranslatef(light2_position[istruct][0],light2_position[istruct][1],
56108 		  light2_position[istruct][2]);
56109      gluSphere(sphere, 1, 10, 10);
56110      glPopMatrix();
56111   }
56112 
56113 
56114 /*  glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, &AxesCol[0][0]);*/
56115 
56116   trnsproj1();
56117 
56118 #ifdef GL_COLOR_ATTACHMENT0_EXT
56119   if (DoShadow) {
56120      setTextureMatrix();
56121   } else if (DoShad) {
56122      glPushMatrix();
56123      glMatrixMode(GL_TEXTURE);
56124      glActiveTextureARB(GL_TEXTURE7);
56125      glLoadIdentity();
56126      glMultMatrixd(TexMat);
56127      glMatrixMode(GL_MODELVIEW);
56128      glPopMatrix();
56129   }
56130 #endif
56131 
56132   glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
56133   glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
56134   glGetIntegerv(GL_VIEWPORT,viewport);
56135   if (viewport[2] != width || viewport[3] != height) {
56136 	glViewport(0,0,width,height);
56137 	viewport[2] = width; viewport[3] = height;
56138   }
56139 
56140   for (i=0; i<*xyzp->iatoms; i++) {
56141         tmp1[0] = (GLdouble) (xyzp->coo[i*3]);
56142         tmp1[1] = (GLdouble) (xyzp->coo[i*3+1]);
56143         tmp1[2] = (GLdouble) (xyzp->coo[i*3+2]);
56144         if (gluProject(tmp1[0],tmp1[1],tmp1[2],modelMatrix,projMatrix,viewport,&xt,&yt,&zt)) {
56145            xyzp->ixp[i] = (height - (int) yt);
56146            xyzp->iyp[i] = (int) xt;
56147            xyzp->rzp[i] = (double) zt;
56148 	   if (*persp && zt > 1.0) xyzp->rzp[i] = -1.0;
56149 	}
56150   }
56151 
56152   for (i=0; i< pharm.nfeat; i++) {
56153         tmp1[0] = (GLdouble) (pharm.array[i].cor[0]);
56154         tmp1[1] = (GLdouble) (pharm.array[i].cor[1]);
56155         tmp1[2] = (GLdouble) (pharm.array[i].cor[2]);
56156         if (gluProject(tmp1[0],tmp1[1],tmp1[2],modelMatrix,projMatrix,viewport,&xt,&yt,&zt)) {
56157            pharm.ixp[i] = (height - (int) yt);
56158            pharm.iyp[i] = (int) xt;
56159            pharm.rzp[i] = (double) zt;
56160 	}
56161   }
56162 
56163   EnableFog();
56164 
56165   if (update_sel) {
56166      ogsel();
56167   } else {
56168      glCallList(theSel[istruct]);
56169   }
56170 
56171   if (has_shader) {
56172 #ifdef GL_COLOR_ATTACHMENT0_EXT
56173 	if (DoShadow) {
56174 #ifdef GL_ARB_shader_objects
56175 	    glUseProgramObjectARB(program[11]);
56176 #endif
56177 	} else {
56178 #endif
56179 #ifdef GL_ARB_shader_objects
56180 	    glUseProgramObjectARB(program[0]);
56181 	    if (*shade) {
56182 		glUniform1iARB(dofog, 1);
56183 	    } else {
56184 		glUniform1iARB(dofog, 0);
56185 	    }
56186 	    if (DoBlur) {
56187 		glUniform1iARB(doblur, 1);
56188 	    } else glUniform1iARB(doblur, 0);
56189 	    if (DoSSAO) {
56190 		glUniform1iARB(dossao, 1);
56191 	    } else glUniform1iARB(dossao, 0);
56192 	    if (DoShad) {
56193 		glUniform1iARB(DoShadLoc, 1);
56194 	    } else glUniform1iARB(DoShadLoc, 0);
56195 	    if (!*fancy) glUseProgramObjectARB(0);
56196 #endif
56197 #ifdef GL_COLOR_ATTACHMENT0_EXT
56198 	}
56199 #endif
56200   }
56201 
56202 #ifdef GL_COLOR_ATTACHMENT0_EXT
56203 #ifdef GL_ARB_shader_objects
56204   if (!DoShadow && DoShad) {
56205 
56206      if (*fancy) {
56207 	glUseProgramObjectARB(program[0]);
56208 	glUniform1iARB(DoShadLoc,0);
56209      }
56210   }
56211 #endif
56212 #endif
56213 
56214   if (*ipdbon && (*fancy || *fullgl)) {
56215 	for (i=0; i<calfptr->ncalf; i++) {
56216           if (calfptr->reson[i]) {glCallList(theRes[istruct][i]);}
56217 	  else {
56218 	     int isa;
56219 
56220 	     isa = calfptr->isal[i];
56221 	     if (isa >= 0 && isa < MXHETA) {
56222 		if (!calfptr->ihet[calfptr->isal[i]])
56223 		   glCallList(theBck[istruct][i]);
56224 	     }
56225 	  }
56226 	}
56227   }
56228 
56229   glDisable(GL_COLOR_MATERIAL);
56230 
56231 
56232   if (*fancy || denmode) {
56233 	glCallList(theMol[istruct][0]);
56234 	if (*irtcel && *ialtyp) glCallList(theMol[istruct][1]);
56235   }
56236 
56237   if (*fancy || *fullgl) {
56238 	if (monptr->ndm) glCallList(theMon[istruct]);
56239   }
56240 
56241   if (PHRMup) glCallList(theFeat[istruct]);
56242 
56243   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
56244 
56245   if (has_shader) glUseProgramObjectARB(0);
56246 
56247 
56248   if (PHRMup) glCallList(theAFeat[istruct]);
56249 
56250   glCallList(theLines[istruct]);
56251   if (DoNorms) glCallList(theNorm);
56252   if (DoIntSurf) {
56253 	if (!IntSurfDone) {
56254 	   if (*ipdbon) {
56255 		ogIntSurf();
56256 	   } else {
56257 		ogLigSurf();
56258 	   }
56259 	}
56260 	glCallList(theIntSurf[istruct]);
56261 	glCallList(theIntSurf2[istruct]);
56262 	glCallList(theLigSurf[istruct]);
56263   }
56264 
56265   if (!*fancy && !denmode && *fullgl) {
56266 	glCallList(theFLines[istruct]);
56267 	glCallList(thePoints[istruct]);
56268   }
56269 
56270   SetGLSLVar();
56271 
56272   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
56273 
56274   if (*forces_yes_no) glCallList(theForces[istruct]);
56275   if (update_casel) glCallList(theSArrow[istruct]);
56276   if (qdpptr->idipon) glCallList(theDipole[istruct]);
56277 
56278   if (theBox[istruct] != -1) glCallList(theBox[istruct]);
56279 
56280   for (i=0; i<NSurf[istruct]; i++) {
56281 
56282     if (OMAPtype) {
56283        glPopMatrix();
56284        glPushMatrix();
56285     }
56286     if (SSon[istruct][i]) {
56287       if (DoLines && Schain[istruct][i] == -1) {
56288 	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
56289 	glLineWidth(2.0);
56290       } else {
56291 	if (!DoShadow) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
56292       }
56293 
56294       if (clp[istruct][i]) {
56295 	 glEnable(GL_CLIP_PLANE0);
56296 	 glEnable(GL_CLIP_PLANE1);
56297 	 glEnable(GL_CLIP_PLANE2);
56298 	 glEnable(GL_CLIP_PLANE3);
56299 	 glEnable(GL_CLIP_PLANE4);
56300 	 glEnable(GL_CLIP_PLANE5);
56301 
56302 	 if (OMAPtype) {
56303 	   theEQ1[3] =  (scalptr->scali*(-2.0*omaprat[0] + 1.0) + 2.0*posptr->zv );
56304 	   theEQ2[3] =  (scalptr->scali*(2.0*omaprat[1] - 1.0) - 2.0*posptr->zv );
56305 	 } else {
56306 	   theEQ1[3] =  EQ[0];
56307 	   theEQ2[3] =  (-EQ[0] + slab[0]);
56308 	 }
56309 
56310 	 theEQ3[3] =  EQ[1];
56311 	 theEQ4[3] =  (-EQ[1] + slab[1]);
56312 
56313 	 theEQ5[3] =  EQ[2];
56314 	 theEQ6[3] =  (-EQ[2] + slab[2]);
56315 
56316 	 glClipPlane(GL_CLIP_PLANE0,theEQ1);
56317 	 glClipPlane(GL_CLIP_PLANE1,theEQ2);
56318 	 glClipPlane(GL_CLIP_PLANE2,theEQ3);
56319 	 glClipPlane(GL_CLIP_PLANE3,theEQ4);
56320 	 glClipPlane(GL_CLIP_PLANE4,theEQ5);
56321 	 glClipPlane(GL_CLIP_PLANE5,theEQ6);
56322       }
56323 
56324       if (trns[istruct][i]) {
56325 //      if (trns[istruct][i] && Schain[istruct][i] == -1) {
56326          glEnable(GL_BLEND);
56327          glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
56328 	 diffuseColor[istruct][i][3] = tr_val;
56329 #ifdef GL_ARB_shader_objects
56330 	 glUseProgramObjectARB(program[0]);
56331 	 dotrns   = glGetUniformLocationARB(program[0], "dotrns");
56332 	 glUniform1iARB(dotrns, 1);
56333 	 if (DoShadow) glUseProgramObjectARB(program[11]);
56334 #endif
56335       } else {
56336 	 diffuseColor[istruct][i][3] = 1.0;
56337          glDisable(GL_BLEND);
56338 #ifdef GL_ARB_shader_objects
56339 
56340 	 glUseProgramObjectARB(program[0]);
56341 	 glUniform1iARB(dotrns, 0);
56342 	 if (DoShadow) glUseProgramObjectARB(program[11]);
56343 #endif
56344       }
56345 
56346       setcl(i);
56347 
56348 #ifdef GL_ARB_shader_objects
56349       if (has_shader) {
56350 	glUseProgramObjectARB(program[0]);
56351 	if (SStyp[istruct][i] == 1) {
56352 		glUniform1iARB(colmat, 1);
56353 	} else {
56354 		glUniform1iARB(colmat, 0);
56355 	}
56356 	if (DoShadow) glUseProgramObjectARB(program[11]);
56357       }
56358 #endif
56359 
56360       if (OMAPtype) {
56361 	  trnsproj0();
56362 	  trnsproj1();
56363       }
56364 
56365       glCallList(theSurf[istruct][i]);
56366 
56367 #ifdef GL_ARB_shader_objects
56368       if (has_shader && SStyp[istruct][i] == 1) {
56369 		glUseProgramObjectARB(program[0]);
56370 		glUniform1iARB(colmat, 0);
56371 		if (DoShadow) glUseProgramObjectARB(program[11]);
56372       }
56373 #endif
56374 
56375       if (clp[istruct][i]) {
56376 	 glDisable(GL_CLIP_PLANE0);
56377 	 glDisable(GL_CLIP_PLANE1);
56378 	 glDisable(GL_CLIP_PLANE2);
56379 	 glDisable(GL_CLIP_PLANE3);
56380 	 glDisable(GL_CLIP_PLANE4);
56381 	 glDisable(GL_CLIP_PLANE5);
56382       }
56383     }
56384 
56385   }
56386 
56387 //  if (theBox[istruct] != -1) glCallList(theBox[istruct]);
56388 
56389   if (DoDockCenter) {
56390      ogDockSphere();
56391   }
56392 
56393 #ifdef GL_COLOR_ATTACHMENT0_EXT
56394   if (has_fbo) {
56395 
56396      if (DoShadow) {
56397 	if (DoMIPMAP) glGenerateMipmapEXT(GL_TEXTURE_2D);
56398 	blurShadowMap();
56399 
56400 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
56401 	glClearColor(gradcol[0][0],gradcol[0][1],gradcol[0][2],1.0);
56402 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
56403 	glDisable(GL_CULL_FACE);
56404 	glUseProgramObjectARB(0);
56405 	if (BGmode) bckgrad();
56406 	//glEnable(GL_NORMALIZE);
56407 	glShadeModel(GL_SMOOTH);
56408 	glActiveTexture(GL_TEXTURE7);
56409 	glBindTexture(GL_TEXTURE_2D,fbo.texid[0]);
56410 	//glLightfv(GL_LIGHT2, GL_POSITION, lightPos);
56411 	glEnable(GL_CULL_FACE);
56412 	//glEnable(GL_POLYGON_OFFSET_FILL);
56413 	//glPolygonOffset(-1.2, 4);
56414 	glCullFace(GL_BACK);
56415 	DoShadow = 0;
56416 	goto SHADOW;
56417      }
56418 
56419 
56420      if (DoBlur) DepthBlur();
56421 
56422      if (DoSSAO) SSAO();
56423   }
56424 
56425   if (DoShad) DoShadow = 1;
56426 #endif
56427 
56428 #ifdef GL_ARB_shader_objects
56429   if (has_shader) glUseProgramObjectARB(0);
56430 #endif
56431 
56432   glFlush();
56433   glXWaitGL();
56434   if (StarNetOld) glXSwapBuffers(display, win);
56435   if (!gmoving && !mmoving && !smoving) {
56436     glXWaitGL();
56437     if (StarNetOld) XSetForeground(display, gc, colors[*ifntcl]);
56438     if (!StarNetOld) initPrintStrings(0);
56439     for (i=0; i<*xyzp->iatoms; i++) {
56440         j = i + 1;
56441 	idres = 0;
56442 	ilptr = qdpptr->iqon;
56443 	if (xyzp->iresid[i] > 0) {
56444 	   if (calfptr->lab[xyzp->iresid[i]-1] > 0) {
56445 		idres = 1;
56446 		ilptr = calfptr->lab[xyzp->iresid[i]-1];
56447 		ilptr--;ilptr--;
56448 	   }
56449 	} else {
56450 	   if (clfstrptr->labhet[ABS(xyzp->iresid[i])] > 0) {
56451 		idres = 1;
56452 		ilptr = clfstrptr->labhet[ABS(xyzp->iresid[i])];
56453 		ilptr--;ilptr--;
56454 	   }
56455 	}
56456         if ((*dolabs || idres == 1) && !denmode) {
56457           if (xyzp->iaton[i] >= 1 && xyzp->rzp[i] > 0.0 )  {
56458 #if defined(VMS) || defined(UNDERSC)
56459    	   pllab(&xyzp->ixp[i],&xyzp->iyp[i],&xyzp->ianz[i],&j,
56460 #else
56461 #ifdef CRAY
56462    	   PLLAB(&xyzp->ixp[i],&xyzp->iyp[i],&xyzp->ianz[i],&j,
56463 #else
56464    	   pllab_(&xyzp->ixp[i],&xyzp->iyp[i],&xyzp->ianz[i],&j,
56465 #endif
56466 #endif
56467 		&xyzp->qat[i],&zero,&ilptr,&xyzp->iresid[i],&zero);
56468           }
56469         }
56470     }
56471     if (*dolabs && !denmode) {
56472 #if defined(VMS) || defined(UNDERSC)
56473      plalab(&qdpptr->iqon);
56474 #else
56475 #ifdef CRAY
56476      PLALAB(&qdpptr->iqon);
56477 #else
56478      plalab_(&qdpptr->iqon);
56479 #endif
56480 #endif
56481     }
56482 
56483     if (!denmode && *ipdbon)
56484 #if defined(VMS) || defined(UNDERSC)
56485      reslab();
56486 #else
56487 #ifdef CRAY
56488      RESLAB();
56489 #else
56490      reslab_();
56491 #endif
56492 #endif
56493 
56494     pldst();
56495 
56496     if (AXES) {
56497 	for (i=1; i<4; i++) {
56498 #if defined(VMS) || defined(UNDERSC)
56499 	   drwstr(&AxesProj[i][0],&AxesProj[i][1],AxesStr[i],&ONE,&MONE);
56500 #else
56501 #ifdef CRAY
56502 	   DRWSTR(&AxesProj[i][0],&AxesProj[i][1],AxesStr[i],&ONE,&MONE);
56503 #else
56504 	   drwstr_(&AxesProj[i][0],&AxesProj[i][1],AxesStr[i],&ONE,&MONE);
56505 #endif
56506 #endif
56507 	}
56508     }
56509 
56510     if (cellpnt->iclon) {
56511 	for (i=0; i<4; i++) {
56512 	   j = cellpnt->iclpnt[i] - 1;
56513 	   j1 = j + 1;
56514 #if defined(VMS) || defined(UNDERSC)
56515 	   drwstr(&xyzp->ixp[j],&xyzp->iyp[j],CellStr[i],&TWO,&j1);
56516 #else
56517 #ifdef CRAY
56518 	   DRWSTR(&xyzp->ixp[j],&xyzp->iyp[j],CellStr[i],&TWO,&j1);
56519 #else
56520 	   drwstr_(&xyzp->ixp[j],&xyzp->iyp[j],CellStr[i],&TWO,&j1);
56521 #endif
56522 #endif
56523 	}
56524     }
56525     if (!StarNetOld) endPrintStrings();
56526   }
56527 
56528   if (FeatSel != -1 && PHRMup) {
56529      if (pharm.array[FeatSel].incl == 1) {
56530 	DrCircle(pharm.iyp[FeatSel],pharm.ixp[FeatSel],
56531 		pharm.array[FeatSel].rad,50);
56532      } else {
56533 	DrCircle(pharm.iyp[FeatSel],pharm.ixp[FeatSel],
56534 		0.2,50);
56535      }
56536   }
56537 
56538   if (has_fbo) {
56539 	if ( !(DoBlur || DoSSAO)) glXSwapBuffers(display, win);
56540   } else {
56541 	if (!StarNetOld) glXSwapBuffers(display, win);
56542   }
56543 
56544   if (!gmoving && !mmoving && !smoving) {
56545     if (*doesp && !denmode) {
56546 	glFlush();
56547 	glXWaitGL();
56548 	PlotColIndex();
56549 	XFlush(display);
56550 	glXWaitX();
56551     }
56552   }
56553 
56554   glXMakeCurrent(display,win,cx);
56555 
56556   rsold = RESUND;
56557 
56558   if (DEBUG) fprintf( stderr, "dispsf \n");
56559 
56560 }
56561 
56562 
Reshape(update)56563 void Reshape(update)
56564 int update;
56565 {
56566   int i,dx,dy;
56567   GLint loc;
56568 
56569   gmoving = 0;
56570   Aspect = (float) width / (float) height;
56571   glViewport(0, 0, width, height);
56572 
56573 #ifdef GL_ARB_shader_objects
56574   if (has_shader && has_fbo) {
56575 	glUseProgramObjectARB(program[1]);
56576 	loc   = glGetUniformLocationARB(program[1], "Width");
56577 	glUniform1iARB(loc, width);
56578 	loc   = glGetUniformLocationARB(program[1], "Height");
56579 	glUniform1iARB(loc, height);
56580 
56581 #ifdef GL_COLOR_ATTACHMENT0_EXT
56582 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[0]);
56583 
56584 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo.depth[0]);
56585 	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
56586 		width, height);
56587 
56588 	glBindTexture(GL_TEXTURE_2D, fbo.texid[0]);
56589 	glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
56590 		    width, height, 0, GL_RGBA, GL_FLOAT, NULL);
56591 
56592 	glBindTexture(GL_TEXTURE_2D, fbo.texid1[0]);
56593 	glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
56594 		    width, height, 0, GL_RGBA, GL_FLOAT, NULL);
56595 
56596 	glBindTexture(GL_TEXTURE_2D, fbo.texid2[0]);
56597 	glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
56598 		    width, height, 0, GL_RGBA, GL_FLOAT, NULL);
56599 
56600 	glBindTexture(GL_TEXTURE_2D, fbo.texid3[0]);
56601 	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24,
56602 		width, height, 0,
56603 		GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
56604 
56605 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[1]);
56606 
56607 	glBindTexture(GL_TEXTURE_2D, fbo.texid[1]);
56608 	glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
56609 		    width, height, 0, GL_RGBA, GL_FLOAT, NULL);
56610 
56611 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
56612 
56613 	for (i = 2; i < NUM_FBOS; i++) {
56614 	   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[i]);
56615 
56616 	  glBindTexture(GL_TEXTURE_2D, fbo.texid[i]);
56617 	  glTexImage2D(GL_TEXTURE_2D, 0, fbo_type,
56618 		    width, height,
56619 			0, GL_RGBA, GL_FLOAT, NULL);
56620 	}
56621 #endif
56622 
56623 	glUseProgramObjectARB(program[3]);
56624 	loc   = glGetUniformLocationARB(program[3], "Width");
56625 	glUniform1iARB(loc, width*2);
56626 
56627 	glUseProgramObjectARB(program[4]);
56628 	loc   = glGetUniformLocationARB(program[4], "Height");
56629 	glUniform1iARB(loc, height*2);
56630 
56631 	glUseProgramObjectARB(program[7]);
56632 	loc   = glGetUniformLocationARB(program[7], "Width");
56633 	glUniform1iARB(loc, width*2);
56634 	loc   = glGetUniformLocationARB(program[7], "Height");
56635 	glUniform1iARB(loc, height*2);
56636 
56637 	glUseProgramObjectARB(program[8]);
56638 	loc   = glGetUniformLocationARB(program[8], "width");
56639 	glUniform1iARB(loc, width);
56640 	loc   = glGetUniformLocationARB(program[8], "height");
56641 	glUniform1iARB(loc, height);
56642 
56643 #ifdef GL_COLOR_ATTACHMENT0_EXT
56644 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo.frame[0]);
56645 	glUseProgramObjectARB(program[0]);
56646 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
56647 #endif
56648 
56649   }
56650 #endif
56651   if (update) {
56652 	dispsf();
56653 	update_model = 0;
56654   } else {
56655 	update_model = 1;
56656   }
56657 }
56658 
56659 
Reshapi()56660 void Reshapi()
56661 {
56662   int dx,dy;
56663 
56664 /*
56665   dx = dy = 0;
56666   Vsize = width;
56667   if (height > width) Vsize = height;
56668   if (height > width) dx = (GLint) -(height - width)/2;
56669   else dy = (GLint) ABS(height - width)/2;
56670 
56671   glViewport(dx, dy, Vsize, Vsize);
56672 */
56673   glViewport(0, 0, width, height);
56674 }
56675 
56676 
Key(unsigned char key)56677 void Key( unsigned char key)
56678 {
56679    int i,j;
56680 
56681    if (gmoving) return;
56682 
56683    update_model = 0;
56684 
56685    switch (key) {
56686    case 'x':
56687       light0_position[istruct][0] += 0.5;
56688       break;
56689    case 'X':
56690       light0_position[istruct][0] -= 0.5;
56691       break;
56692    case 'y':
56693       light0_position[istruct][1] += 0.5;
56694       break;
56695    case 'Y':
56696       light0_position[istruct][1] -= 0.5;
56697       break;
56698    case 'z':
56699       light0_position[istruct][2] += 0.5;
56700       break;
56701    case 'Z':
56702       light0_position[istruct][2] -= 0.5;
56703       break;
56704    case 'i':
56705       light1_position[istruct][0] += 0.5;
56706       break;
56707    case 'I':
56708       light1_position[istruct][0] -= 0.5;
56709       break;
56710    case 'j':
56711       light1_position[istruct][1] += 0.5;
56712       break;
56713    case 'J':
56714       light1_position[istruct][1] -= 0.5;
56715       break;
56716    case 'k':
56717       light1_position[istruct][2] += 0.5;
56718       break;
56719    case 'K':
56720       light1_position[istruct][2] -= 0.5;
56721       break;
56722    case '<':
56723    case ',':
56724       light2_position[istruct][2] -= 0.5;
56725       break;
56726    case '>':
56727    case '.':
56728       light2_position[istruct][2] += 0.5;
56729       break;
56730    case 'B':
56731       if (DoIntSurf) {
56732 	DoIntSurf = 0;
56733       } else {
56734 	DoIntSurf = 1;
56735 	if (*ipdbon) {
56736 	   XDefineCursor(display,win,AtomCursor);
56737 	   bflag = 1; bretval = 563;
56738 	   DCKBYPASS = 1;
56739 	}
56740       }
56741       break;
56742    case 'l':
56743       if (DoLines) {
56744 	DoLines = 0;
56745       } else {
56746 	DoLines = 1;
56747       }
56748       break;
56749    case 'Q':
56750    case 'q':
56751       if (DoNorms) {
56752 	DoNorms = 0;
56753       } else {
56754 	DoNorms = 1;
56755       }
56756       break;
56757    case 'P':
56758    case 'p':
56759       if (*persp) *persp = 0;
56760       else *persp = 1;
56761       TogBut(&cbut[BPERSP]);
56762       break;
56763    case 'T':
56764    case 't':
56765       if (STRCup) TRANSb = ! TogBut(&strcbut[1]);
56766       else if (TRANSb) TRANSb = 0;
56767       else TRANSb = 1;
56768       for (j=0; j < NSurf[istruct]; j++)
56769 	   if (SSon[istruct][j]) trns[istruct][j] = TRANSb;
56770       break;
56771    case '+':
56772    case '=':
56773       if (AXES) AXES = 0;
56774       else AXES = 1;
56775       break;
56776    case 'U':
56777    case 'u':
56778       if (idorad) idorad = 0;
56779       else idorad = 1;
56780       update_model = 1;
56781       break;
56782    case '1':
56783       if (l1on) {
56784 	l1on = 0;
56785 	glDisable(GL_LIGHT0);
56786       } else {
56787 	l1on = 1;
56788 	glEnable(GL_LIGHT0);
56789       }
56790       break;
56791    case '2':
56792       if (l2on) {
56793 	l2on = 0;
56794 	glDisable(GL_LIGHT1);
56795       } else {
56796 	l2on = 1;
56797 	glEnable(GL_LIGHT1);
56798       }
56799       break;
56800    case '3':
56801       if (l3on) {
56802 	l3on = 0;
56803 	glDisable(GL_LIGHT2);
56804       } else {
56805 	l3on = 1;
56806 	glEnable(GL_LIGHT2);
56807       }
56808       break;
56809    case '0':
56810       if (DoLights) {
56811 	DoLights = 0;
56812       } else {
56813 	DoLights = 1;
56814       }
56815       break;
56816    case 'b':
56817       if (DoBlur) {
56818 	DoBlur = 0;
56819       } else {
56820 	DoBlur = 1;
56821       }
56822       break;
56823    case 'S':
56824       if (DoSSAO) {
56825 	DoSSAO = 0;
56826       } else {
56827 	DoSSAO = 1;
56828       }
56829       break;
56830    case 'N':
56831    case 'n':
56832       CMols[istruct]++;
56833       if (CMols[istruct] >= NMols[istruct]) CMols[istruct] = 0;
56834       break;
56835    case 'w':
56836       if (hires) hires = 0;
56837       else hires = 1;
56838       update_model = 1;
56839       break;
56840    case 'G':
56841       EQ[0] += 10.0;
56842       break;
56843    case 'g':
56844       EQ[0] -= 10.0;
56845       break;
56846    case 'D':
56847       break;
56848    case 'd':
56849       break;
56850    case 'R':
56851    case 'r':
56852       if (has_shader) {
56853 	if (DoShad) DoShad = 0;
56854 	else {
56855 	  DoShad = 1;
56856 	  DoShadow = 1;
56857 	  DoSSAO = 0;
56858 	  DoBlur = 0;
56859 	  for (i=0; i<4; i++) lightPos[i] = light2_position[istruct][i];
56860 	  lightPos[0] = 20.0;
56861 	  lightPos[2] = 0.0;
56862 	}
56863       }
56864       break;
56865    }
56866    SetGLSLVar();
56867    update_struct();
56868 }
56869 
EnableFog()56870 void EnableFog()
56871 {
56872       int i,fstart, fend;
56873 
56874       if (!*shade || denmode) {
56875           glDisable(GL_FOG);
56876       } else {
56877          glEnable(GL_FOG);
56878          glFogi (GL_FOG_MODE, GL_LINEAR);
56879          glFogfv (GL_FOG_COLOR, fogColor);
56880 	 for (i=0; i<4; i++) {
56881 	    fog.fogcolor[i] = fogColor[i];
56882 	 }
56883          glHint (GL_FOG_HINT, GL_DONT_CARE);
56884 	 fstart = posptr->zv;
56885 	 fend = fstart + scalptr->scali*2.0*(*uscl);
56886 	 fog.fstart = fstart;
56887 	 fog.fend = fend;
56888 	 fog.fscale = 1.0 / (fend - fstart);;
56889 	 glFogf (GL_FOG_START, fstart);
56890 	 glFogf (GL_FOG_END, fend);
56891        }
56892 }
56893 
56894 extern void
motion(int x,int y,int iopt)56895 motion(int x, int y, int iopt)
56896 {
56897  int i;
56898 
56899   if (iopt) {
56900      gmoving = 0;
56901      mmoving = 0;
56902      smoving = 0;
56903 #if defined(VMS) || defined(UNDERSC)
56904      qupd();
56905 #else
56906 #ifdef CRAY
56907      QUPD();
56908 #else
56909      qupd_();
56910 #endif
56911 #endif
56912      return;
56913   }
56914 
56915   if (mmoving) {
56916     posx = posx + (x - mstartx) / 600.0;
56917     posy = posy - (y - mstarty) / 600.0;
56918     mstartx = x;
56919     mstarty = y;
56920   }
56921   if (smoving) {
56922     posz = posz - (y - sstarty) / 60.0;
56923     /*
56924     if (posz < 0.005 && !PERSP) posz = 0.005;
56925     */
56926     sstarty = y;
56927   }
56928 #if defined(VMS) || defined(UNDERSC)
56929   qupd();
56930 #else
56931 #ifdef CRAY
56932   QUPD();
56933 #else
56934   qupd_();
56935 #endif
56936 #endif
56937 }
56938 
mouseu(int button,int state,int x,int y)56939 void mouseu(int button, int state, int x, int y)
56940 {
56941 
56942   if (button == GLUT_LEFT_BUTTON || button == GLUT_MIDDLE_BUTTON) {
56943       gmoving = 0;
56944       mmoving = 0;
56945       smoving = 0;
56946   }
56947 }
56948 
moused(int button,unsigned int state,int x,int y)56949 void moused(int button, unsigned int state, int x, int y)
56950 {
56951 
56952   if (button == GLUT_LEFT_BUTTON || button == GLUT_MIDDLE_BUTTON) {
56953       if (state & ShiftMask) {
56954          mmoving = 1;
56955          mstartx = x;
56956          mstarty = y;
56957       } else if (state & ControlMask) {
56958          smoving = 1;
56959          sstarty = y;
56960       } else {
56961          gmoving = 1;
56962       }
56963   }
56964 }
56965 
setobg()56966 void setobg()
56967 {
56968    float colv[4];
56969    int i;
56970    colv[0] = ((GLfloat) colorr[OBGcolor]) / 65535.0 ;
56971    colv[1] = ((GLfloat) colorg[OBGcolor]) / 65535.0 ;
56972    colv[2] = ((GLfloat) colorb[OBGcolor]) / 65535.0 ;
56973 
56974    for (i=0; i<3; i++) gradcol[0][i] = colv[i];
56975 
56976    glClearColor(colv[0],colv[1],colv[2],1.0);
56977 
56978 /*
56979    fogColor[0] = ((GLfloat) colorr[OBGcolor]) / 65535.0 ;
56980    fogColor[1] = ((GLfloat) colorg[OBGcolor]) / 65535.0 ;
56981    fogColor[2] = ((GLfloat) colorb[OBGcolor]) / 65535.0 ;
56982 */
56983    fogColor[0] = ((GLfloat) colorr[0]) / 65535.0 ;
56984    fogColor[1] = ((GLfloat) colorg[0]) / 65535.0 ;
56985    fogColor[2] = ((GLfloat) colorb[0]) / 65535.0 ;
56986 }
56987 
initOpengl()56988 void initOpengl()
56989 {
56990 
56991     int i,bgmenu,animmenu,trmenu,capmenu;
56992 
56993 /*
56994 4th value of a position determines if we are using a positional light (1.0)
56995                                                 or a directional light (0.0)
56996 */
56997     static float lmodel_ambient[] = {0.2, 0.2, 0.2, 0.2};
56998     static float light0_ambient[] = {0.1, 0.1, 0.1, 1.0};
56999     static float light0_diffuse[] = {1.0, 1.0, 1.0, 1.0};
57000     static float light0_specular[] = {1.0, 1.0, 1.0, 0.0};
57001     static float light1_ambient[] = {0.1, 0.1, 0.1, 1.0};
57002     static float light1_diffuse[] = {1.0, 1.0, 1.0, 1.0};
57003     static float light1_specular[] = {1.0, 1.0, 1.0, 0.0};
57004     static float light2_ambient[] = {0.1, 0.1, 0.1, 1.0};
57005     static float light2_diffuse[] = {0.8, 0.8, 0.8, 1.0};
57006     static float light2_specular[] = {0.8, 0.8, 0.8, 0.0};
57007     int argc = 2;
57008 #ifdef WIN32
57009     char *argv[] = {"mogl","yes"};
57010 #else
57011     char *argv[] = {"moldenogl","yes"};
57012 #endif
57013 
57014     if (started_ogl) return;
57015     started_ogl = 1;
57016 
57017     glXMakeCurrent(display, win, cx);
57018     glMatrixMode(GL_MODELVIEW);
57019     glLoadIdentity();
57020 
57021     glEnable(GL_DEPTH_TEST);
57022 
57023     if (l1on) glEnable(GL_LIGHT0);
57024     else glDisable(GL_LIGHT0);
57025     if (l2on) glEnable(GL_LIGHT1);
57026     else glDisable(GL_LIGHT1);
57027     if (l3on) glEnable(GL_LIGHT2);
57028     else glDisable(GL_LIGHT2);
57029 
57030     glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
57031     glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
57032     glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
57033     glLightfv(GL_LIGHT0, GL_POSITION, light0_position[0]);
57034 
57035     glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
57036     glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
57037     glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
57038     glLightfv(GL_LIGHT1, GL_POSITION, light1_position[0]);
57039 
57040     glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
57041     glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_diffuse);
57042     glLightfv(GL_LIGHT2, GL_SPECULAR, light2_specular);
57043     glLightfv(GL_LIGHT2, GL_POSITION, light2_position[0]);
57044 
57045     glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 0.0);
57046     glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0);
57047     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
57048 
57049     glEnable(GL_LIGHTING);
57050 
57051     glEnable(GL_NORMALIZE);
57052     glShadeModel(GL_SMOOTH);
57053     glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
57054     glLineWidth(1.0);
57055 
57056     OBGcolor = *ibgclo;
57057     BGmode = *ibgmod;
57058     setobg();
57059 
57060     PERSP = perspon;
57061 
57062 #if defined(DARWIN) || defined(__CYGWIN__)
57063     *fullgl = 1;
57064     *ifogl = 1;
57065 #endif
57066 
57067     glClearIndex(0.0);
57068     glClearDepth(1);
57069 
57070     glPushMatrix();
57071     glLoadIdentity();
57072 
57073     cyl = gluNewQuadric();
57074     sphere = gluNewQuadric();
57075     disk = gluNewQuadric();
57076 
57077     ogaxes();
57078 
57079     Reshapi();
57080 
57081     InvRotMat();
57082 }
57083 
57084 
ogind()57085 void ogind()
57086 {
57087  int i;
57088 
57089 
57090     oglines();
57091     if (*forces_yes_no) ogforces();
57092     ogfeatures();
57093 
57094     if (denmode) {
57095 	ogmlxyz();
57096 	update_model = 0;
57097     }
57098     else {
57099 	if (*irtcel && *ialtyp) {
57100 	   if (NMols[istruct] != 1) ogmoll(0);
57101 	   ogmoll(1);
57102 	}
57103 	else {
57104 	   ogmoll(0);
57105 	}
57106     }
57107 
57108     if (*ipdbon && SSdone[istruct] == 0) {
57109        empty_ribb();
57110 #if defined(VMS) || defined(UNDERSC)
57111        ribgl(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
57112 #else
57113 #ifdef CRAY
57114        RIBGL(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
57115 #else
57116        ribgl_(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
57117 #endif
57118 #endif
57119        SSdone[istruct] = 1;
57120 
57121        for (i=0; i<4; i++)
57122 	if (!monoscr && calfptr->ihet[i] == 1) sndon(i,0,0);
57123 
57124     }
57125 
57126     glXWaitGL();
57127     dispsf();
57128 }
57129 
DelHet(het)57130 void DelHet(het)
57131 int het;
57132 {
57133  int i,j,k,istart,iend,fnd,ndel;
57134  int tmpres,kcon, ab, noab;
57135 
57136     fnd = 0;
57137     istart = 0;
57138     iend = -1;
57139 
57140     for (j=0; j < *xyzp->iatoms; j++) {
57141 	if (xyzp->iresid[j] == het) {
57142 	   if (!fnd) {
57143 	      istart = j;
57144 	      fnd = 1;
57145 	   }
57146 	   iend = j;
57147 	}
57148     }
57149 
57150     if (iend == -1 ) return;
57151     ndel = iend - istart + 1;
57152 
57153     for (j=istart; j < *xyzp->iatoms - ndel; j++) {
57154 	xyzp->iatclr[j] = xyzp->iatclr[j+ndel];
57155 	tmpres = xyzp->iresid[j+ndel];
57156 	if (tmpres < het) tmpres++;
57157 	xyzp->iresid[j] = tmpres;
57158 	xyzp->iaton[j] = xyzp->iaton[j+ndel];
57159 	xyzp->ianz[j] = xyzp->ianz[j+ndel];
57160 	xyzp->ipdbt[j] = xyzp->ipdbt[j+ndel];
57161 	xyzp->ityp[j] = xyzp->ityp[j+ndel];
57162 	if (qdpptr->ihasq) xyzp->qat[j] = xyzp->qat[j+ndel];
57163 	for (k=0; k < 3; k++) {
57164 	   xyzp->coo[j*3+k] = xyzp->coo[(j+ndel)*3+k];
57165 	}
57166 	kcon = 0;
57167 	for (k=0; k < xyzp->iconn[(j+ndel)*(MXCON+1)]; k++) {
57168 	   noab = xyzp->iconn[(j+ndel)*(MXCON+1)+k+1];
57169 	   ab = ABS(noab) - 1;
57170 	   if (ab > istart + ndel) {
57171 		if (noab > 0) {
57172 		   xyzp->iconn[j*(MXCON+1)+kcon+1] = noab - ndel;
57173 		} else {
57174 		   xyzp->iconn[j*(MXCON+1)+kcon+1] = noab + ndel;
57175 		}
57176 		kcon++;
57177 	   } else if (ab < istart) {
57178 		xyzp->iconn[j*(MXCON+1)+kcon+1] = noab;
57179 		kcon++;
57180 	   }
57181 	}
57182 	xyzp->iconn[j*(MXCON+1)] = kcon;
57183     }
57184 
57185     for (j=0; j < istart; j++) {
57186 	kcon = 0;
57187 	for (k=0; k < xyzp->iconn[j*(MXCON+1)]; k++) {
57188 	   noab = xyzp->iconn[j*(MXCON+1)+k+1];
57189 	   ab = ABS(noab) - 1;
57190 	   if (ab > istart + ndel) {
57191 		if (noab > 0) {
57192 		   xyzp->iconn[j*(MXCON+1)+kcon+1] = noab - ndel;
57193 		} else {
57194 		   xyzp->iconn[j*(MXCON+1)+kcon+1] = noab + ndel;
57195 		}
57196 		kcon++;
57197 	   } else if (ab < istart) {
57198 		xyzp->iconn[j*(MXCON+1)+kcon+1] = noab;
57199 		kcon++;
57200 	   }
57201 	}
57202 	xyzp->iconn[j*(MXCON+1)] = kcon;
57203     }
57204 
57205     for (j=0; j < calfptr->ncalf; j++) {
57206 	for (k=0; k < 4; k++)
57207 	   if (calfptr->icalf[j][k] >= istart)
57208 		calfptr->icalf[j][k] = calfptr->icalf[j][k] - ndel;
57209     }
57210 
57211     for (j=ABS(het); j < hetptr.NHetAtm; j++) {
57212 	hetptr.Allocated[j] = hetptr.Allocated[j+1];
57213 	hetptr.HetAtm[j] = hetptr.HetAtm[j+1];
57214 	calfptr->ihet[j] = calfptr->ihet[j+1];
57215     }
57216     if (hetptr.Allocated[hetptr.NHetAtm-1])
57217 	free(hetptr.HetAtm[hetptr.NHetAtm-1]);
57218     hetptr.NHetAtm--;
57219 
57220     *xyzp->iatoms = *xyzp->iatoms - ndel;
57221     if (*natorg > 0) *natorg = *natorg - ndel;
57222     *zmptrp->ihaszm = 0;
57223     ZMEAA = 0;
57224     update_model = 1;
57225 }
57226 
57227 #if defined(VMS) || defined(UNDERSC)
ognrm(double * v1,double * v2,double * v3)57228 void ognrm(double *v1, double *v2, double *v3)
57229 #else
57230 #ifdef CRAY
57231 void OGNRM(double *v1, double *v2, double *v3)
57232 #else
57233 void ognrm_(double *v1, double *v2, double *v3)
57234 #endif
57235 #endif
57236 {
57237 
57238       putvrt(v1,v2,v3,0);
57239 
57240       glNormal3d(*v1,*v2,*v3);
57241 }
57242 
57243 #if defined(VMS) || defined(UNDERSC)
ogvrt(double * v1,double * v2,double * v3)57244 void ogvrt(double *v1, double *v2, double *v3)
57245 #else
57246 #ifdef CRAY
57247 void OGVRT(double *v1, double *v2, double *v3)
57248 #else
57249 void ogvrt_(double *v1, double *v2, double *v3)
57250 #endif
57251 #endif
57252 {
57253       putvrt(v1,v2,v3,1);
57254 
57255       glVertex3d(*v1,*v2,*v3);
57256 }
57257 
chkrib(iop)57258 void chkrib(iop)
57259 int iop;
57260 {
57261    int i,j;
57262 
57263    for (i=RIBindex[istruct].end[iop];
57264 	i >= RIBindex[istruct].start[iop]; i--) {
57265 	if (nvert[istruct][i] <= 0) {
57266 		free(sndstr[istruct][i]);
57267 		free(srfvert[istruct][i]);
57268 		glDeleteLists(theSurf[istruct][i],1);
57269 		for (j=i; j < RIBindex[istruct].end[iop]; j++) {
57270 		   sndstr[istruct][j] = sndstr[istruct][j+1];
57271 		   srfvert[istruct][j] = srfvert[istruct][j+1];
57272 		   nvrtmx[istruct][j] = nvrtmx[istruct][j+1];
57273 		   nvert[istruct][j] = nvert[istruct][j+1];
57274 		   theSurf[istruct][j] = theSurf[istruct][j+1];
57275 		   Schain[istruct][j] = Schain[istruct][j+1];
57276 		}
57277 		j = RIBindex[istruct].end[iop];
57278 		sndstr[istruct][j] = NULL;
57279 		srfvert[istruct][j] = NULL;
57280 		nvrtmx[istruct][j] = 0;
57281 		nvert[istruct][j] = 0;
57282 		theSurf[istruct][j] = -1;
57283 		NSurf[istruct]--;
57284 		if (NSurf[istruct] < 0) NSurf[istruct] = 0;
57285 		RIBindex[istruct].end[iop]--;
57286 		switch (iop) {
57287 		case 0:
57288 			RIBindex[istruct].nhelx--;
57289 			break;
57290 		case 1:
57291 			RIBindex[istruct].nbeta--;
57292 			break;
57293 		case 2:
57294 			RIBindex[istruct].nrna--;
57295 			break;
57296 		case 3:
57297 			RIBindex[istruct].ncoil--;
57298 			break;
57299 		default:
57300 			break;
57301 		}
57302 	}
57303    }
57304 
57305 }
57306 
chncol(ich,col,iupd)57307 void chncol(ich,col,iupd)
57308 int ich;
57309 int col;
57310 int iupd;
57311 {
57312    int i;
57313 
57314    for (i=0; i < NSurf[istruct]; i++)
57315 	if (Schain[istruct][i] == ich+1) SetSurfColor(i,col+1);
57316    if (iupd) dispsf();
57317 }
57318 
57319 #if defined(VMS) || defined(UNDERSC)
ribpnt(int * iopt,int * isnd)57320 void ribpnt(int *iopt, int *isnd)
57321 #else
57322 #ifdef CRAY
57323 void RIBPNT(int *iopt, int *isnd)
57324 #else
57325 void ribpnt_(int *iopt, int *isnd)
57326 #endif
57327 #endif
57328 {
57329     if (*iopt) {
57330 	RIBindex[istruct].start[*isnd] =  NSurf[istruct];
57331     } else {
57332 	RIBindex[istruct].end[*isnd] = NSurf[istruct]-1;
57333 	chkrib(*isnd);
57334     }
57335 }
57336 
57337 #if defined(VMS) || defined(UNDERSC)
sribcol(int * iribc)57338 void sribcol(int *iribc)
57339 #else
57340 #ifdef CRAY
57341 void SRIBCOL(int *iribc)
57342 #else
57343 void sribcol_(int *iribc)
57344 #endif
57345 #endif
57346 {
57347 	int i;
57348 
57349 	for (i=0; i<3; i++)
57350 		diffuseColor[istruct][NSurf[istruct]-1][i] = ribcol[*iribc][i];
57351 }
57352 
57353 #if defined(VMS) || defined(UNDERSC)
bldlst()57354 void bldlst()
57355 #else
57356 #ifdef CRAY
57357 void BLDLST()
57358 #else
57359 void bldlst_()
57360 #endif
57361 #endif
57362 {
57363 
57364      int i,j,k,npts1,npts2;
57365      double v[3], rpts,vl, g[3], c[3];
57366      double vec1[3], vn1[3],sc;
57367      float hinv1,hinv2;
57368 
57369 /*
57370      a grid of n*n points has n-1*n-1 squares
57371      and twice as much triangular polygons
57372      so 2*(npts-1)**2
57373      npts is 80 at maximum so lets make it 12800
57374 */
57375 
57376       if (!*ifdogl) return;
57377 
57378 #if defined(VMS) || defined(UNDERSC)
57379       curs(&ONE);
57380       cvtcom();
57381 #else
57382 #ifdef CRAY
57383       CURS(&ONE);
57384       CVTCOM();
57385 #else
57386       curs_(&ONE);
57387       cvtcom_();
57388 #endif
57389 #endif
57390       update_model = 1;
57391       NSurf[istruct]++;
57392       if (theSurf[istruct][NSurf[istruct]-1] > 0)
57393 	glDeleteLists(theSurf[istruct][NSurf[istruct]-1],1);
57394       theSurf[istruct][NSurf[istruct]-1] = -1;
57395       theSurf[istruct][NSurf[istruct]-1] = glGenLists(1);
57396 
57397       if (NSurf[istruct] > 1) {
57398 
57399 	  for (i=0; i<= NSurf[istruct] - 2; i++)
57400 		SSon[istruct][i] = 0;
57401       }
57402 
57403       SSon[istruct][NSurf[istruct]-1] = 1;
57404       clp[istruct][NSurf[istruct]-1] = 0;
57405       trns[istruct][NSurf[istruct]-1] = 0;
57406 
57407       if (*ipsi) {
57408 	  sndstr[istruct][NSurf[istruct]-1] = (char *) malloc(21);
57409 	  sprintf(sndstr[istruct][NSurf[istruct]-1],
57410 			"Orbital %3d in plane",*ipsi);
57411       } else {
57412 	  sndstr[istruct][NSurf[istruct]-1] = (char *) malloc(17);
57413 	  sprintf(sndstr[istruct][NSurf[istruct]-1],
57414 			"Density in plane");
57415       }
57416       allocvert(MXVERT,1);
57417 
57418       if (!STRCup) inistrc();
57419       RedrawSTRC();
57420 
57421       diffuseColor[istruct][NSurf[istruct]-1][0] = 0.0;
57422       diffuseColor[istruct][NSurf[istruct]-1][1] = 1.0;
57423       diffuseColor[istruct][NSurf[istruct]-1][2] = 0.0;
57424       diffuseColor[istruct][NSurf[istruct]-1][3] = 0.8;
57425 
57426       for (i=0; i<3; i++) {
57427 	specularColor[NSurf[istruct]-1][i] = specColor[i];
57428       }
57429 
57430       glNewList(theSurf[istruct][NSurf[istruct]-1], GL_COMPILE);
57431       SStyp[istruct][NSurf[istruct]-1] = 2;
57432       Schain[istruct][NSurf[istruct]-1] = -1;
57433 
57434       glBegin(GL_QUADS);
57435 
57436       npts1 = hlpsrf->nps1;
57437       npts2 = hlpsrf->nps2;
57438       sc = -1.0*(*scle);
57439 /*
57440       rpts = (double) (npts1-1);
57441 */
57442       rpts = (double) (npts1);
57443       hinv1 = 1.0/ npts2;
57444       hinv2 = 1.0/ npts1;
57445 
57446       for (i=0; i<npts1-1; i++) {
57447          for (j=0; j<npts2-1; j++) {
57448 /*
57449         first triangle
57450 */
57451             vec1[0] = (double) (j);
57452             vec1[1] = (double) (i);
57453             vec1[2] = sgrd.dens[j+i*npts2]*sc*rpts;
57454 
57455 	    znorm(rpts,sc,sgrd.dens,vn1,npts1,npts2,i,j);
57456 
57457 #if defined(VMS) || defined(UNDERSC)
57458             rtgbck(&vn1[0],&vn1[1],&vn1[2],g);
57459             ognrm(&g[0],&g[1],&g[2]);
57460 #else
57461 #ifdef CRAY
57462             RTGBCK(&vn1[0],&vn1[1],&vn1[2],g);
57463             OGNRM(&g[0],&g[1],&g[2]);
57464 #else
57465             rtgbck_(&vn1[0],&vn1[1],&vn1[2],g);
57466             ognrm_(&g[0],&g[1],&g[2]);
57467 #endif
57468 #endif
57469 
57470 	    v[0] = vec1[0]*hinv1;
57471 	    v[1] = vec1[1]*hinv2;
57472 	    v[2] = vec1[2]*hinv1;
57473 #if defined(VMS) || defined(UNDERSC)
57474             rttbck(&v[0],&v[1],&v[2],c);
57475 	    ogvrt(&c[0],&c[1],&c[2]);
57476 #else
57477 #ifdef CRAY
57478             RTTBCK(&v[0],&v[1],&v[2],c);
57479 	    OGVRT(&c[0],&c[1],&c[2]);
57480 #else
57481             rttbck_(&v[0],&v[1],&v[2],c);
57482 	    ogvrt_(&c[0],&c[1],&c[2]);
57483 #endif
57484 #endif
57485 
57486             vec1[0] = (double) (j+1);
57487             vec1[1] = (double) (i);
57488             vec1[2] = sgrd.dens[j+1+i*npts2]*sc*rpts;
57489 
57490 	    znorm(rpts,sc,sgrd.dens,vn1,npts1,npts2,i,j+1);
57491 
57492 #if defined(VMS) || defined(UNDERSC)
57493             rtgbck(&vn1[0],&vn1[1],&vn1[2],g);
57494             ognrm(&g[0],&g[1],&g[2]);
57495 #else
57496 #ifdef CRAY
57497             RTGBCK(&vn1[0],&vn1[1],&vn1[2],g);
57498             OGNRM(&g[0],&g[1],&g[2]);
57499 #else
57500             rtgbck_(&vn1[0],&vn1[1],&vn1[2],g);
57501             ognrm_(&g[0],&g[1],&g[2]);
57502 #endif
57503 #endif
57504 
57505 	    v[0] = vec1[0]*hinv1;
57506 	    v[1] = vec1[1]*hinv2;
57507 	    v[2] = vec1[2]*hinv1;
57508 #if defined(VMS) || defined(UNDERSC)
57509             rttbck(&v[0],&v[1],&v[2],c);
57510 	    ogvrt(&c[0],&c[1],&c[2]);
57511 #else
57512 #ifdef CRAY
57513             RTTBCK(&v[0],&v[1],&v[2],c);
57514 	    OGVRT(&c[0],&c[1],&c[2]);
57515 #else
57516             rttbck_(&v[0],&v[1],&v[2],c);
57517 	    ogvrt_(&c[0],&c[1],&c[2]);
57518 #endif
57519 #endif
57520 
57521             vec1[0] = (double) (j+1);
57522             vec1[1] = (double) (i+1);
57523             vec1[2] = sgrd.dens[j+1+(i+1)*npts2]*sc*rpts;
57524 
57525 	    znorm(rpts,sc,sgrd.dens,vn1,npts1,npts2,i+1,j+1);
57526 
57527 #if defined(VMS) || defined(UNDERSC)
57528             rtgbck(&vn1[0],&vn1[1],&vn1[2],g);
57529             ognrm(&g[0],&g[1],&g[2]);
57530 #else
57531 #ifdef CRAY
57532             RTGBCK(&vn1[0],&vn1[1],&vn1[2],g);
57533             OGNRM(&g[0],&g[1],&g[2]);
57534 #else
57535             rtgbck_(&vn1[0],&vn1[1],&vn1[2],g);
57536             ognrm_(&g[0],&g[1],&g[2]);
57537 #endif
57538 #endif
57539 
57540 	    v[0] = vec1[0]*hinv1;
57541 	    v[1] = vec1[1]*hinv2;
57542 	    v[2] = vec1[2]*hinv1;
57543 #if defined(VMS) || defined(UNDERSC)
57544             rttbck(&v[0],&v[1],&v[2],c);
57545 	    ogvrt(&c[0],&c[1],&c[2]);
57546 #else
57547 #ifdef CRAY
57548             RTTBCK(&v[0],&v[1],&v[2],c);
57549 	    OGVRT(&c[0],&c[1],&c[2]);
57550 #else
57551             rttbck_(&v[0],&v[1],&v[2],c);
57552 	    ogvrt_(&c[0],&c[1],&c[2]);
57553 #endif
57554 #endif
57555 
57556             vec1[0] = (double) (j);
57557             vec1[1] = (double) (i+1);
57558             vec1[2] = sgrd.dens[j+(i+1)*npts2]*sc*rpts;
57559 
57560 	    znorm(rpts,sc,sgrd.dens,vn1,npts1,npts2,i+1,j);
57561 
57562 #if defined(VMS) || defined(UNDERSC)
57563             rtgbck(&vn1[0],&vn1[1],&vn1[2],g);
57564             ognrm(&g[0],&g[1],&g[2]);
57565 #else
57566 #ifdef CRAY
57567             RTGBCK(&vn1[0],&vn1[1],&vn1[2],g);
57568             OGNRM(&g[0],&g[1],&g[2]);
57569 #else
57570             rtgbck_(&vn1[0],&vn1[1],&vn1[2],g);
57571             ognrm_(&g[0],&g[1],&g[2]);
57572 #endif
57573 #endif
57574 
57575 	    v[0] = vec1[0]*hinv1;
57576 	    v[1] = vec1[1]*hinv2;
57577 	    v[2] = vec1[2]*hinv1;
57578 #if defined(VMS) || defined(UNDERSC)
57579             rttbck(&v[0],&v[1],&v[2],c);
57580 	    ogvrt(&c[0],&c[1],&c[2]);
57581 #else
57582 #ifdef CRAY
57583             RTTBCK(&v[0],&v[1],&v[2],c);
57584 	    OGVRT(&c[0],&c[1],&c[2]);
57585 #else
57586             rttbck_(&v[0],&v[1],&v[2],c);
57587 	    ogvrt_(&c[0],&c[1],&c[2]);
57588 #endif
57589 #endif
57590 
57591          }
57592       }
57593 
57594       glEnd();
57595       glDisable(GL_BLEND);
57596       glDisable(GL_COLOR_MATERIAL);
57597       glDisable(GL_CULL_FACE);
57598       glEndList();
57599       dispsf();
57600 #if defined(VMS) || defined(UNDERSC)
57601       curs(&ZERO);
57602 #else
57603 #ifdef CRAY
57604       CURS(&ZERO);
57605 #else
57606       curs_(&ZERO);
57607 #endif
57608 #endif
57609 
57610 }
57611 
57612 static int surf_info = 1;
57613 
57614 
WrtAtm(inp,iatom,SrfArr,lwrit,nc)57615 void WrtAtm(inp,iatom,SrfArr,lwrit,nc)
57616 FILE *inp;
57617 int iatom;
57618 int SrfArr;
57619 int *lwrit;
57620 int *nc;
57621 {
57622    int ir;
57623    float r;
57624 
57625    ir = xyzp->iresid[iatom];
57626 
57627    switch (xyzp->ianz[iatom]) {
57628 	case 1:
57629 	    r = 1.0;
57630 	    break;
57631 	case 5:
57632 	    r = 1.75;
57633 	    break;
57634 	case 6:
57635 	    r = 1.85;
57636 	    break;
57637 	case 8:
57638 	    r = 1.6;
57639 	    break;
57640 	case 15:
57641 	    r = 2.0;
57642 	    break;
57643 	case 16:
57644 	    r = 2.0;
57645 	    break;
57646 	default:
57647 	    r = 1.5;
57648    }
57649 
57650    if (!SrfArr || (SrfArr && ( (ir > 0 && calfptr->iams[ir-1]) ||
57651 			       (ir < 0 && calfptr->ihets[ABS(ir)]))) ) {
57652 	lwrit[*nc] = iatom; *nc = *nc + 1;
57653 	fprintf(inp,"%d %f %8.3f %8.3f %8.3f\n", iatom,r,
57654 		xyzp->coo[iatom*3  ]*toangs,
57655 		xyzp->coo[iatom*3+1]*toangs,
57656 		xyzp->coo[iatom*3+2]*toangs);
57657    }
57658 }
57659 
molsrf(SurfCol,SrfArr,MapSrf)57660 void molsrf(SurfCol,SrfArr,MapSrf)
57661 int SurfCol;
57662 int SrfArr;
57663 int MapSrf;
57664 {
57665    char cmdfil[MAXCMD];
57666    char cmdtmp[MAXCMD] = "surf ";
57667    char tmps[MAXCMD] = "";
57668    char fn[] = "/tmp/fileXXXXXX";
57669    char *tmpf, *p, *q;
57670    int i,j, iat, ir, irt, ires, nc, co, kk, io, fft,pid;
57671    double g[3], c[3], col[3], pot;
57672    FILE *out, *inp;
57673 
57674 #if defined(VMS) || defined(UNDERSC)
57675    curs(&ONE);
57676 #else
57677 #ifdef CRAY
57678    CURS(&ONE);
57679 #else
57680    curs_(&ONE);
57681 #endif
57682 #endif
57683 
57684    if (MapSrf && *fftyp != 3 ) {
57685 	fft = *fftyp;
57686 	for (i=0; i<*xyzp->iatoms; i++)
57687 	   xyzp->lwrit[i] = (int) xyzp->ityp[i];
57688 
57689 	*fftyp = 3;
57690 #if defined(VMS) || defined(UNDERSC)
57691 	dotyp(&ZERO);
57692 #else
57693 #ifdef CRAY
57694 	DOTYP(&ZERO);
57695 #else
57696 	dotyp_(&ZERO);
57697 #endif
57698 #endif
57699 	for (i=0; i<*xyzp->iatoms; i++)
57700 	   xyzp->ityp[i] = (short int) xyzp->lwrit[i];
57701 	*fftyp = fft;
57702    }
57703 
57704    inp = NULL;
57705 
57706 #ifdef __CYGWIN__
57707    if (getusr(tmps)) tmpf = tmps;
57708 #else
57709    tmpf = mktemp(fn);
57710 #endif
57711 
57712 
57713    inp = fopen(tmpf,"w");
57714    if (inp == NULL) return;
57715 
57716    nc = 0;
57717 
57718    if (*ipdbon && !(calfptr->ncalf == 0)) {
57719 	for (ires = 1; ires < calfptr->ncalf+1; ires++ ) {
57720 #if defined(VMS) || defined(UNDERSC)
57721 	   getpdb(&ires,ipdb,ihpdb);
57722 #else
57723 #ifdef CRAY
57724 	   GETPDB(&ires,ipdb,ihpdb);
57725 #else
57726    	   getpdb_(&ires,ipdb,ihpdb);
57727 #endif
57728 #endif
57729 
57730 	   for (i=0; i<MXSYM; i++) {
57731 		if (ipdb[i] > 0) {
57732 		   WrtAtm(inp,ipdb[i]-1,SrfArr,xyzp->lwrit,&nc);
57733 		}
57734 	   }
57735 
57736 	   for (i=0; i<MXHSYM*3; i++) {
57737 		if (ihpdb[i] > 0) {
57738 		   WrtAtm(inp,ihpdb[i]-1,SrfArr,xyzp->lwrit,&nc);
57739 		}
57740 	   }
57741 
57742 	}
57743 
57744 	for (j=4; j<hetptr.NHetAtm; j++) {
57745 	   if (calfptr->ihets[j]) {
57746         	for (i=0; i<*xyzp->iatoms; i++) {
57747 		   if (xyzp->iresid[i] == -j)
57748 			WrtAtm(inp,i,0,xyzp->lwrit,&nc);
57749 		}
57750 	   }
57751 	}
57752 
57753    } else {
57754 	for (i=0; i<*xyzp->iatoms; i++)
57755 		WrtAtm(inp,i,0,xyzp->lwrit,&nc);
57756    }
57757 
57758    fclose(inp);
57759 
57760 #ifdef __CYGWIN__
57761    sprintf(cmdfil,"%ssurf.exe",exepath[0]);
57762 #else
57763    sprintf(cmdfil,"%ssurf",exepath[0]);
57764 #endif
57765 
57766 
57767    if (! (access(cmdfil,F_OK) == 0 && !isdir(cmdfil))) {
57768 #ifdef __CYGWIN__
57769 	sprintf(cmdfil,"%ssurf/surf.exe",exepath[0]);
57770 #else
57771 	sprintf(cmdfil,"%ssurf/surf",exepath[0]);
57772 #endif
57773 	if (!(access(cmdfil,F_OK) == 0)) {
57774 	   sprintf(cmdfil,"surf");
57775 	}
57776    }
57777 
57778    if (surf_info) {
57779       fprintf(stderr,"\nThis surface is made with SURF from UNC-Chapel Hill.\n");
57780       fprintf(stderr,"  The reference is:\n\n");
57781       fprintf(stderr,"A. Varshney, F. P. Brooks, W. V. Wright, \n");
57782       fprintf(stderr,"Linearly Scalable Computation \n");
57783       fprintf(stderr,"of Smooth Molecular Surfaces, \n");
57784       fprintf(stderr,"IEEE Comp. Graphics and Applications, \n");
57785       fprintf(stderr,"v. 14 (1994) pp. 19-25.\n\n");
57786       surf_info = 0;
57787    }
57788 
57789 #ifdef __CYGWIN__
57790    if (p = strstr(cmdfil,".exe")) p[0] = '\0';
57791 
57792 
57793     pid = vfork();
57794     switch(pid) {
57795     case -1:
57796           fprintf(stderr,"Couldnt Fork\n");
57797           break;
57798     case 0:       /*child */
57799 	  execlp(cmdfil,"surf","-W","1",tmpf,NULL);
57800 	  _exit(0);
57801           break;
57802     default:      /*parent*/
57803 	  wait(&pid);
57804           break;
57805     }
57806 #else
57807    strcpy(cmdtmp,cmdfil);
57808    strcat(cmdtmp," -W 1 ");
57809    strcat(cmdtmp,tmpf);
57810 
57811    system(cmdtmp);
57812 #endif
57813 
57814    strcpy(cmdtmp,tmpf);
57815    strcat(cmdtmp,".tri");
57816 
57817    if ((out = fopen(cmdtmp, "r")) == NULL) {
57818       fprintf(stderr,"Can not open triangle file !: %s\n",cmdtmp);
57819 #if defined(VMS) || defined(UNDERSC)
57820       curs(&ZERO);
57821 #else
57822 #ifdef CRAY
57823       CURS(&ZERO);
57824 #else
57825       curs_(&ZERO);
57826 #endif
57827 #endif
57828       return;
57829    }
57830 
57831    SetSurfColor(NSurf[istruct],SurfCol);
57832 
57833    theSurf[istruct][NSurf[istruct]] = glGenLists(1);
57834    SSon[istruct][NSurf[istruct]] = 1;
57835    clp[istruct][NSurf[istruct]] = 0;
57836    trns[istruct][NSurf[istruct]] = 0;
57837 
57838    glNewList(theSurf[istruct][NSurf[istruct]], GL_COMPILE);
57839    NSurf[istruct]++;
57840 
57841    sndstr[istruct][NSurf[istruct]-1] = (char *) malloc(21);
57842    sprintf(sndstr[istruct][NSurf[istruct]-1], "Solvent Acc. Surface");
57843    allocvert(MXVERT,1);
57844 
57845 
57846    SStyp[istruct][NSurf[istruct]-1] = 0;
57847    Schain[istruct][NSurf[istruct]-1] = -1;
57848 
57849 /* if color per triangle */
57850 
57851    if (MapSrf) {
57852         glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
57853         glEnable(GL_COLOR_MATERIAL);
57854 	SStyp[istruct][NSurf[istruct]-1] = 1;
57855    }
57856 
57857    glBegin(GL_TRIANGLES);
57858 
57859    irt = -1;
57860    if (out != NULL) {
57861 	   while (fscanf(out,"%d",&iat) != EOF) {
57862 
57863 	     if (MapSrf) {
57864 		iat = xyzp->lwrit[iat];
57865 		ir = xyzp->iresid[iat];
57866 		if (ir != irt || irt == -1) {
57867 			nc = 0;
57868 
57869 			if (ir < -3) {
57870 
57871 			   for (i=0; i < *xyzp->iatoms; i++) {
57872 			       if (xyzp->iresid[i] == ir) {
57873 				   xyzp->icont[nc] = i+1;
57874 				   nc++;
57875 			       }
57876 			   }
57877 
57878 			} else {
57879 #if defined(VMS) || defined(UNDERSC)
57880 			   getpdb(&ir,ipdb,ihpdb);
57881 #else
57882 #ifdef CRAY
57883 			   GETPDB(&ir,ipdb,ihpdb);
57884 #else
57885 			   getpdb_(&ir,ipdb,ihpdb);
57886 #endif
57887 #endif
57888 
57889 			   for (i=0; i<MXSYM; i++)
57890 				if (ipdb[i] > 0) {
57891 				   xyzp->icont[nc] = ipdb[i];
57892 				   nc++;
57893 				}
57894 
57895 			   for (i=0; i<MXHSYM*3; i++)
57896 				if (ihpdb[i] > 0) {
57897 				   xyzp->icont[nc] = ihpdb[i];
57898 				   nc++;
57899 				}
57900 			   if (ir > 1) {
57901 			    /* n,h backbone previous residue */
57902 			    xyzp->icont[nc] = calfptr->icalf[ir-2][1];
57903 			    nc++;
57904 			    xyzp->icont[nc] = calfptr->icalf[ir-2][3];
57905 			    nc++;
57906 			   }
57907 			   if (ir < calfptr->ncalf) {
57908 			    /* c=o backbone next residue */
57909 			    co = calfptr->icalf[ir][2];
57910 			    if (co > 0) {
57911 			    xyzp->icont[nc] = co;
57912 			    nc++;
57913 			    for (i=0; i < xyzp->iconn[(co-1)*(MXCON+1)]; i++) {
57914 				kk = xyzp->iconn[(co-1)*(MXCON+1)+i+1];
57915 				if (xyzp->ianz[kk-1] == 8) io = kk;
57916 			    }
57917 			    xyzp->icont[nc] = io;
57918 			    nc++;
57919 			    }
57920 			   }
57921 			}
57922 			*xyzp->ncont = nc;
57923 
57924 		   irt = ir;
57925 		}
57926 	     }
57927 
57928 	     for (i=0; i < 3; i++ ) {
57929 
57930 		fscanf(out,"%lf %lf %lf %lf %lf %lf",
57931 		  &c[0],&c[1],&c[2],&g[0],&g[1],&g[2]);
57932 
57933 		for (j=0; j < 3; j++ ) c[j] = c[j]/toangs;
57934 
57935 		if (MapSrf) {
57936 #if defined(VMS) || defined(UNDERSC)
57937 		   clmond(c,&pot,&ONE,
57938 			xyzp->coo,xyzp->qat,xyzp->icont,xyzp->ncont);
57939 		   parcol(&pot,col);
57940 		   ogcoll(&col[0],&col[1],&col[2]);
57941 #else
57942 #ifdef CRAY
57943 		   CLMOND(c,&pot,&ONE,
57944 			xyzp->coo,xyzp->qat,xyzp->icont,xyzp->ncont);
57945 		   PARCOL(&pot,col);
57946 		   OGCOLL(&col[0],&col[1],&col[2]);
57947 #else
57948 		   clmond_(c,&pot,&ONE,
57949 			xyzp->coo,xyzp->qat,xyzp->icont,xyzp->ncont);
57950 		   parcol_(&pot,col);
57951 		   ogcoll_(&col[0],&col[1],&col[2]);
57952 #endif
57953 #endif
57954 		}
57955 #if defined(VMS) || defined(UNDERSC)
57956 		ognrm(&g[0],&g[1],&g[2]);
57957 		ogvrt(&c[0],&c[1],&c[2]);
57958 #else
57959 #ifdef CRAY
57960 		OGNRM(&g[0],&g[1],&g[2]);
57961 		OGVRT(&c[0],&c[1],&c[2]);
57962 #else
57963 		ognrm_(&g[0],&g[1],&g[2]);
57964 		ogvrt_(&c[0],&c[1],&c[2]);
57965 #endif
57966 #endif
57967 	     }
57968 
57969 	   }
57970 	   glEnd();
57971 	   if (MapSrf) {
57972 		glDisable(GL_COLOR_MATERIAL);
57973 	   }
57974 	   glEndList();
57975 	   fclose(out);
57976 	   unlink(tmpf);
57977 	   unlink(cmdtmp);
57978 	   dispsf();
57979 	   UpdateSTRC();
57980    }
57981 
57982 
57983 #if defined(VMS) || defined(UNDERSC)
57984    curs(&ZERO);
57985 #else
57986 #ifdef CRAY
57987    CURS(&ZERO);
57988 #else
57989    curs_(&ZERO);
57990 #endif
57991 #endif
57992 }
57993 
57994 #else
57995 
57996 /* =====================================
57997  * backup functions for no openGL
57998  * =====================================
57999 */
58000 
chncol(ich,col,iupd)58001 void chncol(ich,col,iupd)
58002 int ich;
58003 int col;
58004 int iupd;
58005 {
58006   int i;
58007       i = 0;
58008 }
58009 
ogforces()58010 void ogforces()
58011 {
58012   int i;
58013       i = 0;
58014 }
58015 
wrtall()58016 void wrtall()
58017 {
58018   int i;
58019       i = 0;
58020 }
58021 
DeleteActiveSurfaces()58022 void DeleteActiveSurfaces()
58023 {
58024   int i;
58025       i = 0;
58026 }
58027 
58028 #if defined(VMS) || defined(UNDERSC)
bldlst()58029 void bldlst()
58030 #else
58031 #ifdef CRAY
58032 void BLDLST()
58033 #else
58034 void bldlst_()
58035 #endif
58036 #endif
58037 {
58038   int i;
58039 
58040   i = 0;
58041 }
58042 
molsrf(SurfCol,SrfArr,MapSrf)58043 void molsrf(SurfCol,SrfArr,MapSrf)
58044 int SurfCol;
58045 int SrfArr;
58046 int MapSrf;
58047 {
58048   int dummy;
58049 
58050   dummy = 0;
58051 }
58052 
58053 #if defined(VMS) || defined(UNDERSC)
ogbegg(isurf,iopt,ityp,iorb,cntval,mapped,name)58054 void ogbegg(isurf,iopt,ityp,iorb,cntval,mapped,name)
58055 #else
58056 #ifdef CRAY
58057 void OGBEGG(isurf,iopt,ityp,iorb,cntval,mapped,name)
58058 #else
58059 void ogbegg_(isurf,iopt,ityp,iorb,cntval,mapped,name)
58060 #endif
58061 #endif
58062 int *isurf;
58063 int *iorb;
58064 int *ityp;
58065 int *iopt;
58066 double *cntval;
58067 int *mapped;
58068 char *name;
58069 {
58070   int i;
58071 
58072   i = 0;
58073 }
58074 
58075 #if defined(VMS) || defined(UNDERSC)
ogcoll(double * v1,double * v2,double * v3)58076 void ogcoll(double *v1, double *v2, double *v3)
58077 #else
58078 #ifdef CRAY
58079 void OGCOLL(double *v1, double *v2, double *v3)
58080 #else
58081 void ogcoll_(double *v1, double *v2, double *v3)
58082 #endif
58083 #endif
58084 {
58085   int i;
58086 
58087   i = 0;
58088 }
58089 
58090 #if defined(VMS) || defined(UNDERSC)
ognrm(double * v1,double * v2,double * v3)58091 void ognrm(double *v1, double *v2, double *v3)
58092 #else
58093 #ifdef CRAY
58094 void OGNRM(double *v1, double *v2, double *v3)
58095 #else
58096 void ognrm_(double *v1, double *v2, double *v3)
58097 #endif
58098 #endif
58099 {
58100   int i;
58101 
58102   i = 0;
58103 
58104 }
58105 
58106 #if defined(VMS) || defined(UNDERSC)
ogvrt(double * v1,double * v2,double * v3)58107 void ogvrt(double *v1, double *v2, double *v3)
58108 #else
58109 #ifdef CRAY
58110 void OGVRT(double *v1, double *v2, double *v3)
58111 #else
58112 void ogvrt_(double *v1, double *v2, double *v3)
58113 #endif
58114 #endif
58115 {
58116   int i;
58117 
58118   i = 0;
58119 
58120 }
58121 
58122 #if defined(VMS) || defined(UNDERSC)
sribcol(int * iribc)58123 void sribcol(int *iribc)
58124 #else
58125 #ifdef CRAY
58126 void SRIBCOL(int *iribc)
58127 #else
58128 void sribcol_(int *iribc)
58129 #endif
58130 #endif
58131 {
58132 
58133   int i;
58134 
58135   i = 0;
58136 
58137 }
58138 
58139 #if defined(VMS) || defined(UNDERSC)
ogribb(iscnd)58140 void ogribb(iscnd)
58141 #else
58142 #ifdef CRAY
58143 void OGRIBB(iscnd)
58144 #else
58145 void ogribb_(iscnd)
58146 #endif
58147 #endif
58148 int *iscnd;
58149 {
58150       int i;
58151 
58152       i = 0;
58153 }
58154 
58155 #if defined(VMS) || defined(UNDERSC)
ogmon()58156 void ogmon()
58157 #else
58158 #ifdef CRAY
58159 void OGMON()
58160 #else
58161 void ogmon_()
58162 #endif
58163 #endif
58164 {
58165       int i;
58166 
58167       i = 0;
58168 }
58169 
58170 #if defined(VMS) || defined(UNDERSC)
ogendd(ichain)58171 void ogendd(ichain)
58172 #else
58173 #ifdef CRAY
58174 void OGENDD(ichain)
58175 #else
58176 void ogendd_(ichain)
58177 #endif
58178 #endif
58179 int *ichain;
58180 {
58181       int i;
58182 
58183       i = 0;
58184 }
58185 
58186 #if defined(VMS) || defined(UNDERSC)
ribpnt(int * iopt,int * isnd)58187 void ribpnt(int *iopt, int *isnd)
58188 #else
58189 #ifdef CRAY
58190 void RIBPNT(int *iopt, int *isnd)
58191 #else
58192 void ribpnt_(int *iopt, int *isnd)
58193 #endif
58194 #endif
58195 {
58196       int i;
58197 
58198       i = 0;
58199 }
58200 
58201 #if defined(VMS) || defined(UNDERSC)
setcll()58202 void setcll()
58203 #else
58204 #ifdef CRAY
58205 void SETCLL()
58206 #else
58207 void setcll_()
58208 #endif
58209 #endif
58210 {
58211       int i;
58212 
58213       i = 0;
58214 }
58215 
dispsf()58216 void dispsf()
58217 {
58218   int i;
58219 
58220   i = 0;
58221 }
58222 
ogind()58223 void ogind()
58224 {
58225   int i;
58226 
58227   i = 0;
58228 }
58229 
ogmoll(int iopt)58230 void ogmoll(int iopt)
58231 {
58232   int i;
58233 
58234   i = 0;
58235 }
58236 
Key(unsigned char key)58237 void  Key(unsigned char key)
58238 {
58239   int i;
58240 
58241   i = 0;
58242 }
58243 
moused(int button,unsigned int state,int x,int y)58244 void moused(int button, unsigned int state, int x, int y)
58245 {
58246   int i;
58247 
58248   i = 0;
58249 }
58250 
ResetRes()58251 void ResetRes()
58252 {
58253   int i;
58254 
58255   i = 0;
58256 }
58257 
mouseu(int button,int state,int x,int y)58258 void mouseu(int button, int state, int x, int y)
58259 {
58260   int i;
58261 
58262   i = 0;
58263 }
58264 
motion(int x,int y,int iopt)58265 void motion(int x, int y, int iopt)
58266 {
58267   int i;
58268 
58269   i = 0;
58270 }
58271 
Reshape(int update)58272 void Reshape(int update)
58273 {
58274   int i;
58275 
58276   i = 0;
58277 }
58278 
empty_model(sel,updis)58279 void empty_model(sel,updis)
58280 int sel;
58281 int updis;
58282 {
58283   int i;
58284 
58285       i = 0;
58286 }
58287 
DelHet(int het)58288 void DelHet(int het)
58289 {
58290   int i;
58291 
58292       i = 0;
58293 }
58294 
ogfeatures()58295 void ogfeatures()
58296 {
58297 }
58298 
58299 #endif
58300 
58301 #include <math.h>
58302 
58303 static union
58304 {   double d;
58305     struct
58306     {
58307 #ifdef LITTLE_ENDIAN
58308       int j, i;
58309 #else
58310       int i, j;
58311 #endif
58312     } n;
58313 } _eco;
58314 
58315 #define EXPA (1048576/M_LN2)
58316 #define EXPC 60801
58317 
58318 #define EXP(y) (_eco.n.i = EXPA*(y) + (1072693248 - EXPC), _eco.d)
58319 
58320 #if defined(VMS) || defined(UNDERSC)
fexp(y)58321 double fexp(y)
58322 #else
58323 #ifdef CRAY
58324 double FEXP(y)
58325 #else
58326 double fexp_(y)
58327 #endif
58328 #endif
58329 double *y;
58330 {
58331   return (EXP(*y));
58332 }
58333 /*
58334 typedef struct {
58335   int ptr;
58336   float depth;
58337 } DepthIndex;
58338 
58339 DepthIndex dpt[NUMAT];
58340 */
58341 
58342 static int
compare(const void * a,const void * b)58343 compare(const void *a, const void *b)
58344 {
58345   DepthIndex *p1 = (DepthIndex *) a;
58346   DepthIndex *p2 = (DepthIndex *) b;
58347   float diff = p2->depth - p1->depth;
58348 
58349   if (diff > 0.0) {
58350     return -1;
58351   } else if (diff < 0.0) {
58352     return 1;
58353   } else {
58354     return 0;
58355   }
58356 }
58357 
compi(const void * a,const void * b)58358 static int compi(const void *a, const void *b)
58359 {
58360   IntIndex *p1 = (IntIndex *) a;
58361   IntIndex *p2 = (IntIndex *) b;
58362 /*
58363   return (p1->depth > p2->depth) - (p2->depth > p1->depth);
58364   return (p1->depth > p2->depth) ? 1 : ((p1->depth < p2->depth) ? -1 : 0);
58365 */
58366   return (p2->depth > p1->depth) ? 1 : ((p2->depth < p1->depth) ? -1 : 0);
58367 }
58368 
SI(const void * a,const void * b)58369 static int SI(const void *a, const void *b)
58370 {
58371   return (*(int*)a - *(int*)b);
58372 }
58373 
ActualiseBackbone(int iset)58374 void ActualiseBackbone(int iset)
58375 {
58376    int j;
58377 
58378    if (*backb) {
58379 	TogDown(&cbut[BBACKB]);
58380 	ActBut(&cbut[BFORC],1);
58381 	ActBut(&cbut[BINCRF],1);
58382 	ActBut(&cbut[BHBOND],1);
58383 	ActBut(&cbut[BDECRF],1);
58384 	ActBut(&cbut[BUNSC],1);
58385 	preset(iset);
58386    } else {
58387 	TogUp(&cbut[BBACKB]);
58388 	ActBut(&cbut[BFORC],0);
58389 	ActBut(&cbut[BINCRF],0);
58390 	ActBut(&cbut[BDECRF],0);
58391 	ActBut(&cbut[BUNSC],0);
58392 	ActBut(&cbut[BHBOND],0);
58393 	if (iset) {
58394 	   for (j=0; j < MXHETA; j++)
58395 		calfptr->ihet[j] = 0;
58396 	   for (j=0; j < calfptr->ncalf; j++)
58397 		calfptr->reson[j] = 1;
58398 	   for (j=0; j < *xyzp->iatoms; j++ )
58399 		xyzp->iaton[j] = 1;
58400 	}
58401 	update_sel = 1;
58402    }
58403 }
58404 
DoBackbone()58405 void DoBackbone()
58406 {
58407    int j;
58408 
58409    TogBut(&cbut[BBACKB]);
58410    if (!*backb) {
58411 	*backb = 1;
58412 	*ionoff = 1;
58413 	ActBut(&cbut[BFORC],1);
58414 	ActBut(&cbut[BINCRF],1);
58415 	ActBut(&cbut[BHBOND],1);
58416 	ActBut(&cbut[BDECRF],1);
58417 	ActBut(&cbut[BUNSC],1);
58418 	preset(1);
58419    } else {
58420 	*backb = 0;
58421 	ActBut(&cbut[BFORC],0);
58422 	ActBut(&cbut[BINCRF],0);
58423 	ActBut(&cbut[BDECRF],0);
58424 	ActBut(&cbut[BUNSC],0);
58425 	ActBut(&cbut[BHBOND],0);
58426 	for (j=0; j < MXHETA; j++)
58427 	   calfptr->ihet[j] = 0;
58428 	for (j=0; j < calfptr->ncalf; j++)
58429 	   calfptr->reson[j] = 1;
58430 	for (j=0; j < *xyzp->iatoms; j++ )
58431 	   xyzp->iaton[j] = 1;
58432 	update_sel = 1;
58433    }
58434 }
58435 
58436 #if defined(VMS) || defined(UNDERSC)
srti(n,iror,inat)58437 void srti(n,iror,inat)
58438 #else
58439 #ifdef CRAY
58440 void SRTI(n,iror,inat)
58441 #else
58442 void srti_(n,iror,inat)
58443 #endif
58444 #endif
58445 int *n;
58446 int *iror;
58447 int *inat;
58448 {
58449    int i,j;
58450 
58451    for (i=0; i<*n; i++) {
58452 	intptr[i].depth = (int) iror[i];
58453 	intptr[i].ptr = i;
58454    }
58455    qsort(intptr,*n, sizeof(IntIndex), compi);
58456    for (i=0; i<*n; i++) inat[i] = intptr[i].ptr;
58457 }
58458 
58459 #if defined(VMS) || defined(UNDERSC)
rqsrt(n,rzp,inat)58460 void rqsrt(n,rzp,inat)
58461 #else
58462 #ifdef CRAY
58463 void RQSRT(n,rzp,inat)
58464 #else
58465 void rqsrt_(n,rzp,inat)
58466 #endif
58467 #endif
58468 int *n;
58469 double *rzp;
58470 int *inat;
58471 {
58472    int i,j;
58473 
58474    for (i=0; i<*n; i++) {
58475 	dptptr[i].depth = (float) rzp[i];
58476 	dptptr[i].ptr = i + 1;
58477    }
58478    qsort(dptptr,*n, sizeof(DepthIndex), compare);
58479    for (i=0; i<*n; i++) inat[i] = dptptr[i].ptr;
58480 }
58481 
SaveResXYZ(ires)58482 void SaveResXYZ(ires)
58483 int ires;
58484 {
58485    int i,j;
58486 
58487 
58488    if (ResChanged == NULL) {
58489       if ((ResChanged = (int *) malloc((sizeof(int))*NUMCAL)) == NULL) {
58490 	fprintf(stderr, "Memory allocation error for ResChanged\n");
58491 	return;
58492       } else {
58493           for (i=0; i<NUMCAL; i++) ResChanged[i] = 0;
58494       }
58495    }
58496 
58497    CurrRes = ires;
58498 
58499    if (!ResChanged[ires-1]) {
58500 #if defined(VMS) || defined(UNDERSC)
58501       getpdb(&ires,ipdb,ihpdb);
58502 #else
58503 #ifdef CRAY
58504       GETPDB(&ires,ipdb,ihpdb);
58505 #else
58506       getpdb_(&ires,ipdb,ihpdb);
58507 #endif
58508 #endif
58509       for (i=0; i<MXSYM; i++) for (j=0; j<3; j++)
58510 	if (ipdb[i] > 0) xyzpdb[i][j] = xyzp->coo[(ipdb[i]-1)*3+j];
58511 
58512       for (i=0; i<MXHSYM*3; i++) for (j=0; j<3; j++)
58513 	if (ihpdb[i] > 0) xyzhpdb[i][j] = xyzp->coo[(ihpdb[i]-1)*3+j];
58514 
58515       ResChanged[ires-1] = 1;
58516    }
58517 
58518 
58519 }
58520 
rmsdres()58521 double rmsdres()
58522 {
58523    int i,j, numatoms;
58524    int tmpipdb[MXSYM], tmpihpdb[MXHSYM*3];
58525    double rmsd,rmsdh, rtmp;
58526 
58527 
58528    for (i=0; i<MXSYM; i++) tmpipdb[i] = 0;
58529    for (i=0; i<MXHSYM*3; i++) tmpihpdb[i] = 0;
58530 
58531 #if defined(VMS) || defined(UNDERSC)
58532    getpdb(&CurrRes,tmpipdb,tmpihpdb);
58533 #else
58534 #ifdef CRAY
58535    GETPDB(&CurrRes,tmpipdb,tmpihpdb);
58536 #else
58537    getpdb_(&CurrRes,tmpipdb,tmpihpdb);
58538 #endif
58539 #endif
58540 
58541    rmsd = 0;
58542    numatoms = 0;
58543 
58544    for (i=0; i<MXSYM; i++) {
58545         if (tmpipdb[i]) {
58546            numatoms++;
58547            fprintf(stderr,"%d org %f %f %f rot %f %f %f \n",i+1,xyzpdb[i][0]*toangs,xyzpdb[i][1]*toangs,xyzpdb[i][2]*toangs,xyzp->coo[(tmpipdb[i]-1)*3]*toangs,xyzp->coo[(tmpipdb[i]-1)*3+1]*toangs,xyzp->coo[(tmpipdb[i]-1)*3+2]*toangs);
58548            for (j=0; j<3; j++) {
58549 	      rtmp = (xyzpdb[i][j] - xyzp->coo[(tmpipdb[i]-1)*3+j]);
58550 	      rmsd = rmsd + rtmp*rtmp;
58551 	   }
58552 	}
58553    }
58554 
58555    rmsd = toangs*sqrt(rmsd/((float) numatoms));
58556    fprintf(stderr,"RMSD current rotamer with starting geometry: %f\n",rmsd);
58557 
58558    numatoms = 0;
58559    rmsdh = 0;
58560 
58561    for (i=0; i<MXHSYM*3; i++) {
58562         if (tmpihpdb[i]) {
58563            numatoms++;
58564            for (j=0; j<3; j++) {
58565 	      rtmp = (xyzhpdb[i][j] - xyzp->coo[(tmpihpdb[i]-1)*3+j]);
58566 	      rmsdh = rmsdh + rtmp*rtmp;
58567 	   }
58568 	}
58569    }
58570 
58571    rmsdh = toangs*sqrt(rmsdh/((float) numatoms));
58572    fprintf(stderr,"RMSDH current rotamer with starting geometry: %f\n",rmsdh);
58573 
58574    return(rmsd);
58575 }
58576 
zmt2cor(ires,iopt)58577 void zmt2cor(ires,iopt)
58578 int ires;
58579 int iopt;
58580 {
58581 
58582    update_model = 1;
58583 #if defined(VMS) || defined(UNDERSC)
58584    dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58585    doclr();
58586    if (iopt) conpdb();
58587 #ifdef DOGL
58588    ogres(ires,ONE,1);
58589    update_model = 0;
58590 #endif
58591    qupd();
58592    curs(&ZERO);
58593 #else
58594 #ifdef CRAY
58595    DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58596    doclr();
58597    if (iopt) CONPDB();
58598 #ifdef DOGL
58599    ogres(ires,ONE,1);
58600    update_model = 0;
58601 #endif
58602    QUPD();
58603    CURS(&ZERO);
58604 #else
58605    dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58606    doclr();
58607    if (iopt) conpdb_();
58608 #ifdef DOGL
58609    ogres(ires,ONE,1);
58610    update_model = 0;
58611 #endif
58612    qupd_();
58613    curs_(&ZERO);
58614 #endif
58615 #endif
58616    presetp();
58617    *Sinct = 0;
58618 }
58619 
scanrot(ires,aminotyp)58620 void scanrot(ires,aminotyp)
58621 int ires;
58622 int aminotyp;
58623 {
58624    int i,OptRot;
58625    double rmsd,rtmp;
58626 
58627 
58628    SaveResXYZ(ires);
58629 
58630 #if defined(VMS) || defined(UNDERSC)
58631    curs(&ONE);
58632 #else
58633 #ifdef CRAY
58634    CURS(&ONE);
58635 #else
58636    curs_(&ONE);
58637 #endif
58638 #endif
58639 
58640    rmsd = 1000000.0;
58641    OptRot = -1;
58642 
58643    if (ZMEup) {
58644       for (i=0; i<aminozmt[aminotyp].nrots; i++) {
58645 
58646         if (aminozmt[aminotyp].chis[0] != -1)
58647 	  zmptrp->bet[aaptr[ires-1].chi1] = aminozmt[aminotyp].rots[i].rots[0];
58648         if (aminozmt[aminotyp].chis[1] != -1)
58649   	  zmptrp->bet[aaptr[ires-1].chi2] = aminozmt[aminotyp].rots[i].rots[1];
58650         if (aminozmt[aminotyp].chis[2] != -1)
58651 	  zmptrp->bet[aaptr[ires-1].chi3] = aminozmt[aminotyp].rots[i].rots[2];
58652         if (aminozmt[aminotyp].chis[3] != -1)
58653 	  zmptrp->bet[aaptr[ires-1].chi4] = aminozmt[aminotyp].rots[i].rots[3];
58654         SetQZME();
58655 
58656         FindZRange(ires);
58657 
58658 #if defined(VMS) || defined(UNDERSC)
58659         dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58660 #else
58661 #ifdef CRAY
58662         DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58663 #else
58664         dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58665 #endif
58666 #endif
58667         rtmp = rmsdres();
58668         if (rtmp < rmsd) {
58669 	  rmsd = rtmp;
58670 	  OptRot = i;
58671         }
58672 
58673      }
58674 
58675      fprintf(stderr,"\nBest Rotamer fit: %d\n",OptRot+1);
58676 
58677      if (aminozmt[aminotyp].chis[0] != -1)
58678 	zmptrp->bet[aaptr[ires-1].chi1] =
58679 		aminozmt[aminotyp].rots[OptRot].rots[0];
58680      if (aminozmt[aminotyp].chis[1] != -1)
58681 	zmptrp->bet[aaptr[ires-1].chi2] =
58682 		aminozmt[aminotyp].rots[OptRot].rots[1];
58683      if (aminozmt[aminotyp].chis[2] != -1)
58684 	zmptrp->bet[aaptr[ires-1].chi3] =
58685 		aminozmt[aminotyp].rots[OptRot].rots[2];
58686      if (aminozmt[aminotyp].chis[3] != -1)
58687 	zmptrp->bet[aaptr[ires-1].chi4] =
58688 		aminozmt[aminotyp].rots[OptRot].rots[3];
58689 
58690      SetQZME();
58691 
58692      if (ZME_window_pos >= calfptr->ncalf) ZME_window_pos = 0;
58693      if (calfptr->ncalf < ZME_window_high) RedrawZME();
58694      else UpdateZME();
58695      RedrawScroll(&zscroll);
58696 
58697      FindZRange(ires);
58698      zmt2cor(ires,0);
58699 
58700    } else {
58701 
58702      pmfrot->ndrs = 1;
58703      pmfrot->idrs[0] = ires;
58704      AllocRot();
58705 
58706      for (i=0; i<RDrots[aminotyp].nrots; i++) {
58707 	rotset(ires,i);
58708         rtmp = rmsdres();
58709         if (rtmp < rmsd) {
58710 	  rmsd = rtmp;
58711 	  OptRot = i;
58712         }
58713      }
58714      rotset(ires,OptRot);
58715      DeAllocRot();
58716 #ifdef DOGL
58717      ogres(ires,ONE,1);
58718 #endif
58719    }
58720 }
58721 
58722 
58723 void bestrot(int print);
58724 
onerot(ires,print)58725 void onerot(ires,print)
58726 int ires;
58727 int print;
58728 {
58729 
58730 #if defined(VMS) || defined(UNDERSC)
58731    dfipar();
58732 #else
58733 #ifdef CRAY
58734    DFIPAR();
58735 #else
58736    dfipar_();
58737 #endif
58738 #endif
58739 
58740    pmfrot->ndrs = 1;
58741    pmfrot->idrs[0] = ires;
58742    (void) bestrot(print);
58743 }
58744 
setrot(irs,irot)58745 void setrot(irs,irot)
58746 int irs;
58747 int irot;
58748 {
58749 	int aminotyp;
58750 
58751 	aminotyp = calfptr->iamino[irs-1]-1;
58752         if (aminozmt[aminotyp].chis[0] != -1)
58753    	   zmptrp->bet[aaptr[irs-1].chi1] =
58754 			aminozmt[aminotyp].rots[irot].rots[0];
58755         if (aminozmt[aminotyp].chis[1] != -1)
58756 	   zmptrp->bet[aaptr[irs-1].chi2] =
58757 			aminozmt[aminotyp].rots[irot].rots[1];
58758         if (aminozmt[aminotyp].chis[2] != -1)
58759 	   zmptrp->bet[aaptr[irs-1].chi3] =
58760 			aminozmt[aminotyp].rots[irot].rots[2];
58761         if (aminozmt[aminotyp].chis[3] != -1)
58762 	   zmptrp->bet[aaptr[irs-1].chi4] =
58763 			aminozmt[aminotyp].rots[irot].rots[3];
58764 
58765 }
58766 
bestrot(int print)58767 void bestrot(int print)
58768 {
58769    int i,l,l1,irs,aminotyp,OptRot[MXDRES];
58770    double scor,rtmp;
58771 
58772 /* assign atom types */
58773 
58774 #if defined(VMS) || defined(UNDERSC)
58775    curs(&ONE);
58776    dfiass();
58777 #else
58778 #ifdef CRAY
58779    CURS(&ONE);
58780    DFIASS();
58781 #else
58782    curs_(&ONE);
58783    dfiass_();
58784 #endif
58785 #endif
58786 
58787 /*
58788    Calculate (once) the static interaction between flexible residues
58789    (all rotamers) and the non-flexible-residues
58790 */
58791 
58792    if (!ZMEup) {
58793       DeAllocRot();
58794       AllocRot();
58795    }
58796 
58797 /*   fprintf(stderr,"ndrs %d\n",pmfrot->ndrs);*/
58798 
58799    for (l=0; l<pmfrot->ndrs; l++) {
58800 
58801       scor = 1000000.0;
58802       OptRot[l] = -1;
58803 
58804       irs = pmfrot->idrs[l];
58805       aminotyp = calfptr->iamino[irs-1]-1;
58806 
58807       if (print) {
58808 	 fprintf(stderr,"%s %d\n",AminoAcids[aminotyp],calfptr->irsnr[irs-1]);
58809       }
58810 
58811       if (ZMEup) {
58812        for (i=0; i<aminozmt[aminotyp].nrots; i++) {
58813 
58814 	 setrot(irs,i);
58815 
58816          SetQZME();
58817 
58818          FindZRange(irs);
58819 
58820 	 pmfrot->lrots[l] = i + 1;
58821 	 l1 = l + 1;
58822 
58823 /*
58824 dfirot: rotamer with all non flexible sidechains and
58825         rotamer with backbone part of flexible sidechains and
58826         internal rotamer energy (fixed or self pmf ?)
58827 */
58828 
58829 #if defined(VMS) || defined(UNDERSC)
58830          dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58831          dfirot(&l1);
58832 #else
58833 #ifdef CRAY
58834          DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58835          DFIROT(&l1);
58836 #else
58837          dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58838          dfirot_(&l1);
58839 #endif
58840 #endif
58841 
58842          rtmp = pmfrot->estat[i][l];
58843 	 if (print) {
58844 	     fprintf(stderr,"\nRotamer %d %f\n",i,rtmp);
58845 	 }
58846          if (rtmp < scor) {
58847 	     scor = rtmp;
58848 	     OptRot[l] = i;
58849          }
58850 
58851        }
58852 
58853       } else {
58854 
58855        for (i=0; i<RDrots[aminotyp].nrots; i++) {
58856 
58857 	 rotset(irs,i);
58858 
58859 	 pmfrot->lrots[l] = i + 1;
58860 	 l1 = l + 1;
58861 
58862 
58863 #if defined(VMS) || defined(UNDERSC)
58864          dfirot(&l1);
58865 #else
58866 #ifdef CRAY
58867          DFIROT(&l1);
58868 #else
58869          dfirot_(&l1);
58870 #endif
58871 #endif
58872 
58873          rtmp = pmfrot->estat[i][l];
58874 	 if (print) {
58875 	     fprintf(stderr,"\nRotamer %d %f\n",i,rtmp);
58876 	 }
58877          if (rtmp < scor) {
58878 	     scor = rtmp;
58879 	     OptRot[l] = i;
58880          }
58881 
58882        }
58883       }
58884    }
58885 
58886    if (print) {
58887 	fprintf(stderr,"\nBest Rotamer fit: %d\n",OptRot[0]+1);
58888    }
58889 
58890    for (l=0; l<pmfrot->ndrs; l++) {
58891 
58892       irs = pmfrot->idrs[l];
58893 
58894       if (ZMEup) {
58895 	setrot(irs,OptRot[l]);
58896       } else {
58897 	rotset(irs,OptRot[l]);
58898       }
58899 
58900    }
58901 
58902    if (ZMEup) {
58903 	SetQZME();
58904 
58905 	if (ZME_window_pos >= calfptr->ncalf) ZME_window_pos = 0;
58906 	if (calfptr->ncalf < ZME_window_high) RedrawZME();
58907 	else UpdateZME();
58908 	RedrawScroll(&zscroll);
58909 
58910 	if (pmfrot->ndrs == 1) FindZRange(pmfrot->idrs[0]);
58911 
58912 #if defined(VMS) || defined(UNDERSC)
58913 	dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58914 	doclr();
58915 #ifdef DOGL
58916 	for (l=0; l<pmfrot->ndrs; l++)
58917 	   ogres(pmfrot->idrs[l],ONE,ONE);
58918 	update_model = 0;
58919 #endif
58920 	qupd();
58921 	curs(&ZERO);
58922 #else
58923 #ifdef CRAY
58924 	DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58925 	doclr();
58926 #ifdef DOGL
58927 	for (l=0; l<pmfrot->ndrs; l++)
58928 	   ogres(pmfrot->idrs[l],ONE,ONE);
58929 	update_model = 0;
58930 #endif
58931 	QUPD();
58932 	CURS(&ZERO);
58933 #else
58934 	dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
58935 	doclr();
58936 #ifdef DOGL
58937 	for (l=0; l<pmfrot->ndrs; l++)
58938 	   ogres(pmfrot->idrs[l],ONE,ONE);
58939 	update_model = 0;
58940 #endif
58941 	qupd_();
58942 	curs_(&ZERO);
58943 #endif
58944 #endif
58945 	presetp();
58946    } else {
58947 	for (l=0; l<pmfrot->ndrs; l++) {
58948 #if defined(VMS) || defined(UNDERSC)
58949 	   actami(&pmfrot->idrs[l],&ZERO,&ONE,&ZERO);
58950 #else
58951 #ifdef CRAY
58952 	   ACTAMI(&pmfrot->idrs[l],&ZERO,&ONE,&ZERO);
58953 #else
58954 	   actami_(&pmfrot->idrs[l],&ZERO,&ONE,&ZERO);
58955 #endif
58956 #endif
58957 	   rsold = RESUND;
58958 #ifdef DOGL
58959 	   ogres(pmfrot->idrs[l],ONE,ONE);
58960 #endif
58961 	}
58962 #ifdef DOGL
58963 	update_model = 0;
58964 #endif
58965 #if defined(VMS) || defined(UNDERSC)
58966 	curs(&ZERO);
58967 #else
58968 #ifdef CRAY
58969 	CURS(&ZERO);
58970 #else
58971 	curs_(&ZERO);
58972 #endif
58973 #endif
58974 	presetp();
58975    }
58976 
58977 }
58978 
prresrot(eupl)58979 void prresrot(eupl)
58980 double eupl;
58981 {
58982    int i,j;
58983 
58984    fprintf(stderr,"nresrot %d eupl %f\n",nresrot,eupl);
58985    for (i=0; i<MXROTRES; i++) {
58986       fprintf(stderr,"ResRot %d ",i);
58987       for (j=0; j<resrot[0].ndrs; j++) {
58988           fprintf(stderr,"res%2d %d rot %d, ",
58989 		j,resrot[i].idrs[j],resrot[i].rot[j]);
58990       }
58991       fprintf(stderr," etot %8.3f\n",resrot[i].etot);
58992    }
58993 }
58994 
showresrot(sol)58995 void showresrot(sol)
58996 int sol;
58997 {
58998    int l;
58999 
59000 
59001    if (ZMEup) {
59002 
59003 	for (l=0; l<resrot[sol].ndrs; l++) {
59004 	   setrot(resrot[sol].idrs[l],resrot[sol].rot[l]);
59005 	}
59006 
59007 	zmpart->imx = resrot[sol].mx;
59008 	zmpart->imn = resrot[sol].mn;
59009 
59010 	SetQZME();
59011 
59012 	if (ZME_window_pos >= calfptr->ncalf) ZME_window_pos = 0;
59013 	if (calfptr->ncalf < ZME_window_high) RedrawZME();
59014 	else UpdateZME();
59015 	RedrawScroll(&zscroll);
59016 
59017 #if defined(VMS) || defined(UNDERSC)
59018 
59019 	dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59020 	doclr();
59021 #ifdef DOGL
59022 	for (l=0; l<resrot[sol].ndrs; l++)
59023 	ogres(resrot[sol].idrs[l],ONE,0);
59024 	update_model = 0;
59025 #endif
59026 	qupd();
59027 	curs(&ZERO);
59028 
59029 #else
59030 
59031 #ifdef CRAY
59032 
59033 	DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59034 	doclr();
59035 #ifdef DOGL
59036 	for (l=0; l<resrot[sol].ndrs; l++)
59037 	ogres(resrot[sol].idrs[l],ONE,0);
59038 	update_model = 0;
59039 #endif
59040 	QUPD();
59041 	CURS(&ZERO);
59042 
59043 #else
59044 
59045 	dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59046 	doclr();
59047 #ifdef DOGL
59048 	for (l=0; l<resrot[sol].ndrs; l++)
59049 	ogres(resrot[sol].idrs[l],ONE,0);
59050 	update_model = 0;
59051 #endif
59052 	qupd_();
59053 	curs_(&ZERO);
59054 
59055 #endif
59056 
59057 #endif
59058    } else {
59059 
59060 	for (l=0; l<resrot[sol].ndrs; l++) {
59061 	   rotset(resrot[sol].idrs[l],resrot[sol].rot[l]);
59062 	}
59063 
59064 	doclr();
59065 #if defined(VMS) || defined(UNDERSC)
59066 	qupd();
59067 	curs(&ZERO);
59068 #else
59069 #ifdef CRAY
59070 	QUPD();
59071 	CURS(&ZERO);
59072 #else
59073 	qupd_();
59074 	curs_(&ZERO);
59075 #endif
59076 #endif
59077 #ifdef DOGL
59078 	for (l=0; l<resrot[sol].ndrs; l++)
59079 	   ogres(resrot[sol].idrs[l],ONE,0);
59080 	update_model = 0;
59081 #endif
59082    }
59083    presetp();
59084 }
59085 
59086 
opt3rot()59087 void opt3rot()
59088 {
59089    int i,j,k,l,l1,m,n,mx,mn,aminotyp,debug;
59090    int irs0,irs[6],rots[6],j0,j1,j2,j3,j4,j5;
59091    double etot,eupl;
59092 
59093    debug = 0;
59094 
59095    if (pmfrot->ndrs == 0) return;
59096 
59097    DeAllocRot();
59098    AllocRot();
59099 /* assign atom types */
59100 
59101 #if defined(VMS) || defined(UNDERSC)
59102    curs(&ONE);
59103    dfiass();
59104 #else
59105 #ifdef CRAY
59106    CURS(&ONE);
59107    DFIASS();
59108 #else
59109    curs_(&ONE);
59110    dfiass_();
59111 #endif
59112 #endif
59113 
59114 /*
59115    Calculate (once) the static interaction between flexible residues
59116    (all rotamers) and the non-flexible-residues
59117 */
59118 
59119    fprintf(stderr,"ndrs %d\n",pmfrot->ndrs);
59120 
59121    zmpart->idcur = 0;
59122    for (l=0; l<pmfrot->ndrs; l++) {
59123 
59124       irs0 = pmfrot->idrs[l];
59125       aminotyp = calfptr->iamino[irs0-1]-1;
59126 
59127       if (ZMEup) {
59128 	for (i=0; i<aminozmt[aminotyp].nrots; i++) {
59129 
59130 	 setrot(irs0,i);
59131 
59132          SetQZME();
59133 
59134          FindZRange(irs0);
59135 
59136 	 pmfrot->lrots[l] = i + 1;
59137 	 l1 = l + 1;
59138 
59139 /*
59140 dfirot: rotamer with all non flexible sidechains and
59141         rotamer with backbone part of flexible sidechains and
59142         internal rotamer energy (fixed or self pmf ?)
59143 */
59144 
59145 #if defined(VMS) || defined(UNDERSC)
59146          dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59147          dfirot(&l1);
59148 #else
59149 #ifdef CRAY
59150          DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59151          DFIROT(&l1);
59152 #else
59153          dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59154          dfirot_(&l1);
59155 #endif
59156 #endif
59157 
59158 	}
59159       } else {
59160 
59161 	for (i=0; i< RDrots[aminotyp].nrots; i++) {
59162 
59163 	 rotset(irs0,i);
59164 
59165 	 pmfrot->lrots[l] = i + 1;
59166 	 l1 = l + 1;
59167 
59168 #if defined(VMS) || defined(UNDERSC)
59169          dfirot(&l1);
59170 #else
59171 #ifdef CRAY
59172          DFIROT(&l1);
59173 #else
59174          dfirot_(&l1);
59175 #endif
59176 #endif
59177 
59178 	}
59179       }
59180    }
59181 
59182    if (ZMEup) {
59183 	mx = -1; mn = *zmptrp->mxzat;
59184    }
59185 
59186    for (l=0; l<6; l++) rots[l] = 1;
59187    for (l=0; l<pmfrot->ndrs; l++) {
59188       if (pmfrot->ndrs >= l+1) {
59189 	irs[l] = pmfrot->idrs[l];
59190 	if (ZMEup) {
59191 	   rots[l] = aminozmt[calfptr->iamino[irs[l]-1]-1].nrots;
59192 	   FindZRange(irs[l]);
59193 	   if (zmpart->imx > mx) mx = zmpart->imx;
59194 	   if (zmpart->imn < mn) mn = zmpart->imn;
59195 	} else {
59196 	   rots[l] = RDrots[calfptr->iamino[irs[l]-1]-1].nrots;
59197 	}
59198       }
59199    }
59200    if (ZMEup) {
59201 	zmpart->imx = mx; zmpart->imn = mn;
59202    }
59203 
59204    nresrot = 1;
59205    resrot[0].etot = 100000.0;
59206    eupl = 100000.0;
59207 
59208 /*
59209    fprintf(stderr,"rots[0] %d rots[1] %d\n",rots[0],rots[1]);
59210 */
59211 
59212    for (j0=0; j0<rots[0]; j0++) {
59213 	if (ZMEup) {
59214 	   setrot(irs[0],j0);
59215 	} else {
59216 	   rotset(irs[0],j0);
59217 	}
59218 
59219 	for (j1=0; j1<rots[1]; j1++) {
59220 	   if (ZMEup) {
59221 		if (pmfrot->ndrs > 1) setrot(irs[1],j1);
59222 	   } else {
59223 		if (pmfrot->ndrs > 1) rotset(irs[1],j1);
59224 	   }
59225 
59226 	   for (j2=0; j2<rots[2]; j2++) {
59227 		if (ZMEup) {
59228 		   if (pmfrot->ndrs > 2) setrot(irs[2],j2);
59229 		} else {
59230 		   if (pmfrot->ndrs > 2) rotset(irs[2],j2);
59231 		}
59232 
59233 		for (j3=0; j3<rots[3]; j3++) {
59234 		   if (ZMEup) {
59235 			if (pmfrot->ndrs > 3) setrot(irs[3],j3);
59236 		   } else {
59237 			if (pmfrot->ndrs > 3) rotset(irs[3],j3);
59238 		   }
59239 
59240 		   for (j4=0; j4<rots[4]; j4++) {
59241 			if (ZMEup) {
59242 			   if (pmfrot->ndrs > 4) setrot(irs[4],j4);
59243 			} else {
59244 			   if (pmfrot->ndrs > 4) rotset(irs[4],j4);
59245 			}
59246 
59247 			for (j5=0; j5<rots[5]; j5++) {
59248 			   if (ZMEup) {
59249 				if (pmfrot->ndrs > 5) setrot(irs[5],j5);
59250 				SetQZME();
59251 #if defined(VMS) || defined(UNDERSC)
59252 				dumzm(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59253 				dfiflx(&etot);
59254 #else
59255 #ifdef CRAY
59256 				DUMZM(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59257 				DFIFLX(&etot);
59258 #else
59259 				dumzm_(xyzp->coo,xyzp->ianz,xyzp->iatoms);
59260 				dfiflx_(&etot);
59261 #endif
59262 #endif
59263 			   } else {
59264 				if (pmfrot->ndrs > 5) rotset(irs[5],j5);
59265 #if defined(VMS) || defined(UNDERSC)
59266 				dfiflx(&etot);
59267 #else
59268 #ifdef CRAY
59269 				DFIFLX(&etot);
59270 #else
59271 				dfiflx_(&etot);
59272 #endif
59273 #endif
59274 			   }
59275 
59276 
59277 /* sum in static contributions */
59278 
59279 			   etot = etot + pmfrot->estat[j0][0];
59280 			   if (pmfrot->ndrs > 1)
59281 				etot = etot + pmfrot->estat[j1][1];
59282 			   if (pmfrot->ndrs > 2)
59283 				etot = etot + pmfrot->estat[j2][2];
59284 			   if (pmfrot->ndrs > 3)
59285 				etot = etot + pmfrot->estat[j3][3];
59286 			   if (pmfrot->ndrs > 4)
59287 				etot = etot + pmfrot->estat[j4][4];
59288 			   if (pmfrot->ndrs > 5)
59289 				etot = etot + pmfrot->estat[j5][5];
59290 /*
59291    fprintf(stderr,"\nRotcomb res1 %d rot %d, res2 %d rot %d, res3 %d rot %d etot %8.3f eupl %8.3f\n",pmfrot->idrs[0],j0,pmfrot->idrs[1],j1,pmfrot->idrs[2],j2,etot,eupl);
59292 */
59293 
59294 /*
59295    copy rotamer sequence with corres. energy to results array
59296    when its energy etot is smaller than the higest energy of the current
59297    array (eupl)
59298    Since the first element is set at the start to a HIGH value, the condition
59299    etot < eupl will always be satisfied untill the HIGH value is in the last
59300    element of the array and then will disappear.
59301 */
59302 
59303 
59304 			   if (etot < eupl) {
59305 			     for (n=0; n < nresrot; n++) {
59306 			      if (etot < resrot[n].etot) {
59307 				for (k=nresrot-1; k >= n; k--) {
59308 				   if (k+1 <MXROTRES) {
59309 					resrot[k+1] = resrot[k];
59310 				   }
59311 				}
59312 		   		resrot[n].ndrs = pmfrot->ndrs;
59313 		   		resrot[n].etot = etot;
59314 		   		resrot[n].idrs[0] = pmfrot->idrs[0];
59315 		   		resrot[n].idrs[1] = pmfrot->idrs[1];
59316 		   		resrot[n].idrs[2] = pmfrot->idrs[2];
59317 		   		resrot[n].idrs[3] = pmfrot->idrs[3];
59318 		   		resrot[n].idrs[4] = pmfrot->idrs[4];
59319 		   		resrot[n].idrs[5] = pmfrot->idrs[5];
59320 		   		resrot[n].rot[0] = j0;
59321 		   		resrot[n].rot[1] = j1;
59322 		   		resrot[n].rot[2] = j2;
59323 		   		resrot[n].rot[3] = j3;
59324 		   		resrot[n].rot[4] = j4;
59325 		   		resrot[n].rot[5] = j5;
59326 		   		resrot[n].mx = zmpart->imx;
59327 		   		resrot[n].mn = zmpart->imn;
59328 				if (nresrot < MXROTRES ) nresrot++;
59329 			        eupl = resrot[nresrot-1].etot;
59330 				break;
59331 			      }
59332 			     }
59333 			   }
59334                 	   if (debug) prresrot(eupl);
59335 			}
59336 		    }
59337 		}
59338 	    }
59339 	}
59340    }
59341 
59342 
59343    fprintf(stderr,"\nRotOpt:\n");
59344    for (j=0; j<resrot[0].ndrs; j++) {
59345           fprintf(stderr,"%2d res %d rot %d, \n",
59346 		j,resrot[0].idrs[j],resrot[0].rot[j]);
59347    }
59348    fprintf(stderr," etot %8.3f\n",resrot[0].etot);
59349 
59350    for (j=0; j<nresrot; j++) flxen[j] = resrot[j].etot;
59351 
59352    showresrot(0);
59353    zmpart->idcur = 1;
59354 }
59355 
59356 #define MAGIC 1993
59357 #define MAXFNAME 512
59358 #define TOANGS 0.52917706e0
59359 #define MAXFRM 100000
59360 
59361 /* little <-> big endian swap */
59362 
bswp(void * v)59363 void bswp(void *v) {
59364   int *P;
59365 
59366   P = (int *) v;
59367   *P = (*P&0xff000000)>>24 | (*P&0x00ff0000)>> 8  |
59368        (*P&0x0000ff00)<< 8 | (*P&0x000000ff)<<24 ;
59369 
59370 }
59371 
bswp8(void * v)59372 void bswp8(void *v) {
59373   int *P;
59374   int b1, b2;
59375 
59376   P = (int *) v;
59377 
59378   b1 = P[0];
59379   b1 = (b1&0xff000000)>>24 | (b1&0x00ff0000)>>8  |
59380        (b1&0x0000ff00)<<8  | (b1&0x000000ff)<<24;
59381 
59382   b2 = P[1];
59383   b2 = (b2&0xff000000)>>24 | (b2&0x00ff0000)>>8  |
59384        (b2&0x0000ff00)<<8  | (b2&0x000000ff)<<24;
59385 
59386   P[0] = b2;
59387   P[1] = b1;
59388 }
59389 
trint(FILE * fptr,int * i)59390 int trint(FILE *fptr, int *i)
59391 {
59392    if (fread(i, 4, 1, fptr) != 1) return -1;
59393    if (strx.swap) bswp(i);
59394    return 0;
59395 }
59396 
trdble(FILE * fptr,double * r)59397 int trdble(FILE *fptr, double *r)
59398 {
59399    float dum;
59400 
59401    if (strx.prec == sizeof(float)) {
59402 	if (fread(&dum, (size_t) strx.prec, 1, fptr) != (size_t) 1) return -1;
59403 	if (strx.swap) bswp(&dum);
59404 	*r = (double) dum;
59405    } else if (strx.prec == sizeof(double)) {
59406 	if (fread(r, (size_t) strx.prec, 1, fptr) != (size_t) 1) return -1;
59407 	if (strx.swap) bswp8(r);
59408    }
59409    return 0;
59410 }
59411 
trstr(FILE * fptr,char * str)59412 int trstr(FILE *fptr, char *str)
59413 {
59414    int nstr;
59415 
59416    if (trint(fptr,&nstr) < 0) return -1;
59417 
59418    if (fread(str,1,(size_t) nstr,fptr) != (size_t) nstr) return -1;
59419    str[nstr] = '\n';
59420    return nstr;
59421 }
59422 
cntstr(FILE * fptr,char * str)59423 int cntstr(FILE *fptr, char *str)
59424 {
59425    int nstr,tup,pad;
59426 
59427    if (trint(fptr, &nstr) < 0) return -1;
59428 
59429    tup = nstr/sizeof(int);
59430    pad = nstr - tup*sizeof(int);
59431    if (pad) nstr = (tup+1)*sizeof(int);
59432 
59433    if (fread(str,1,(size_t) nstr,fptr) != (size_t) nstr) return -1;
59434    str[nstr] = '\n';
59435    return nstr;
59436 }
59437 
59438 #if defined(VMS) || defined(UNDERSC)
gettrr(int * step,int * istat)59439 void gettrr(int *step,int *istat)
59440 #else
59441 #ifdef CRAY
59442 void GETTRR(int *step,int *istat)
59443 #else
59444 void gettrr_(int *step,int *istat)
59445 #endif
59446 #endif
59447 {
59448    int iframe,debug,istp1,istp2;
59449    char filename[MAXFNAME];
59450 
59451    debug = 0;
59452 
59453    strcpy(filename,grostr[0]);
59454    *istat = 0;
59455 
59456    if (init_trr(filename) < 0) {
59457         *istat = -1;
59458    } else {
59459 
59460 	geo1ptr->gcvav = 1;
59461 	geo1ptr->ifmxav = 0;
59462 	geo1ptr->ifrmav = 0;
59463 	geo1ptr->idmxav = 0;
59464 	geo1ptr->idrmav = 0;
59465 	geo1ptr->ieav = 0;
59466 	geo1ptr->ngeoms = 0;
59467 	geo1ptr->nepnts = 0;
59468 	geo1ptr->dmaxt = 0.0;
59469 	geo1ptr->fmaxt = 0.0;
59470 	geo1ptr->drmst = 0.0;
59471 	geo1ptr->frmst = 0.0;
59472 	iframe = 1;
59473 	while(!gfrm(&iframe,step,0)) {
59474 	   if (iframe == 1) istp1 = *step;
59475 	   if (iframe == 2) istp2 = *step;
59476 	   iframe++;
59477 	}
59478 	geo1ptr->ngeoms = strx.nframes = iframe;
59479 	if (debug) fprintf(stderr,"# frames %d\n",strx.nframes);
59480  	*step = istp2 - istp1;
59481    }
59482 
59483 }
59484 
cltrr()59485 void cltrr()
59486 {
59487    fclose(strx.fptr);
59488 }
59489 
init_trr(char * fileroot)59490 int init_trr(char *fileroot)
59491 {
59492    char filename[MAXFNAME];
59493 
59494 /* uses the xdr trajectory reading routines for the .trr file:
59495    xdr trajectory file */
59496 
59497    strx.box = strx.vir = strx.pres = strx.x = strx.natoms = strx.swap = 0;
59498    strx.fpos = (long *) malloc(sizeof(long)*MAXFRM);
59499    memset(strx.fpos,-1,sizeof(long)*MAXFRM);
59500 
59501    sprintf(filename,"%s.trr",fileroot);
59502 
59503    strx.fptr = fopen(filename, "rb");
59504    if (strx.fptr == NULL) {
59505 	fprintf(stderr,"Didnt find trajectory file: %s\n\n",filename);
59506 	return -1;
59507    }
59508    return 0;
59509 }
59510 
header_trr(int * step)59511 int header_trr(int *step)
59512 {
59513    char sdummy[80];
59514    int magic;
59515    int dummy;
59516    double rdum;
59517 
59518    if (trint(strx.fptr,&magic) < 0) return -1;
59519    if (magic != MAGIC) {
59520 	bswp(&magic);
59521 	if (magic != MAGIC) {
59522 	   fprintf(stderr,"Magic number mismatch\n");
59523 	   return -1;
59524 	}
59525 	strx.swap = 1;
59526    }
59527 
59528    if (trint(strx.fptr,&dummy) < 0) return -1;
59529    if (trstr(strx.fptr,sdummy) < 0) return -1;
59530    if (trint(strx.fptr,&dummy) < 0) return -1;
59531    if (trint(strx.fptr,&dummy) < 0) return -1;
59532    if (trint(strx.fptr,&strx.box) < 0) return -1;
59533    if (trint(strx.fptr,&strx.vir) < 0) return -1;
59534    if (trint(strx.fptr,&strx.pres) < 0) return -1;
59535    if (trint(strx.fptr,&dummy) < 0) return -1;
59536    if (trint(strx.fptr,&dummy) < 0) return -1;
59537    if (trint(strx.fptr,&strx.x) < 0) return -1;
59538    if (trint(strx.fptr,&strx.v) < 0) return -1;
59539    if (trint(strx.fptr,&strx.f) < 0) return -1;
59540    if (trint(strx.fptr,&strx.natoms) < 0) return -1;
59541    if (trint(strx.fptr,step) < 0) return -1;
59542    if (trint(strx.fptr,&dummy) < 0) return -1;
59543 
59544 /*
59545    fprintf(stderr,"box %d vir %d pres %d x %d v %d f %d natoms %d\n",
59546        strx.box,strx.vir,strx.pres,strx.x,strx.v,strx.f,strx.natoms);
59547 */
59548 
59549    if (strx.x) strx.prec = strx.x/(strx.natoms*3);
59550    else if (strx.v) strx.prec = strx.v/(strx.natoms*3);
59551    else if (strx.f) strx.prec = strx.f/(strx.natoms*3);
59552 
59553    if (trdble(strx.fptr,&rdum) < 0) return -1;
59554    if (trdble(strx.fptr,&rdum) < 0) return -1;
59555 
59556    return 0;
59557 }
59558 
59559 #if defined(VMS) || defined(UNDERSC)
gtfrm(int * frame)59560 void gtfrm(int *frame)
59561 #else
59562 #ifdef CRAY
59563 void GTFRM(int *frame)
59564 #else
59565 void gtfrm_(int *frame)
59566 #endif
59567 #endif
59568 {
59569    int idum,step;
59570 
59571    idum = 0;
59572 
59573    if (gfrm(frame,&step,1)) idum = 1;
59574 }
59575 
gfrm(int * frame,int * step,int set)59576 int gfrm(int *frame,int *step,int set)
59577 {
59578    int i,j,frame_done,ioff;
59579    double v[3][3],rdum,vdum[3];
59580 /*
59581 should set coordinate atom first read of trr (to set fpos)
59582 because only after rdgro, coordinates are converted to bohr
59583 we need them in angs after rdgro and in bohr after gfrm
59584 */
59585 
59586    if (!strx.fptr) return -1;
59587 
59588    if (strx.fpos[(*frame)-1] == -1) {
59589 	strx.fpos[(*frame)-1] = ftell(strx.fptr);
59590         frame_done = 0;
59591    } else {
59592 	fseek(strx.fptr, strx.fpos[(*frame)-1], SEEK_SET);
59593         frame_done = 1;
59594    }
59595 
59596    if (header_trr(step) < 0) return -1;
59597 
59598    if (strx.box) {
59599       for (i=0; i < 3; i++) {
59600 	for (j=0; j < 3; j++) {
59601 	   if (trdble(strx.fptr,&v[i][j]) < 0) return -1;
59602 	   v[i][j] = v[i][j]*10.0/TOANGS;
59603 	}
59604       }
59605       if (cellpnt->iclon) {
59606 	ioff = cellpnt->iclpnt[0];
59607 	if (set) {
59608 	   for (i=0; i < 3; i++)
59609 	      for (j=0; j < 3; j++) xyzp->coo[(i+ioff)*3+j] = v[i][j];
59610 	   for (j=0; j < 3; j++) xyzp->coo[(ioff+3)*3+j] = v[0][j] + v[1][j];
59611 	   for (j=0; j < 3; j++) xyzp->coo[(ioff+4)*3+j] = v[1][j] + v[2][j];
59612 	   for (j=0; j < 3; j++) xyzp->coo[(ioff+5)*3+j] = v[0][j] + v[2][j];
59613 	   for (j=0; j < 3; j++) xyzp->coo[(ioff+6)*3+j] = v[0][j] + v[1][j] + v[2][j];
59614 	}
59615       }
59616    }
59617    if (strx.vir) {
59618       for (i=0; i < 9; i++)
59619 	if (trdble(strx.fptr,&rdum) < 0) return -1;
59620    }
59621    if (strx.pres) {
59622       for (i=0; i < 9; i++)
59623 	if (trdble(strx.fptr,&rdum) < 0) return -1;
59624    }
59625 
59626    if (strx.x) {
59627       for (i=0; i < strx.natoms; i++) {
59628 	for (j=0; j < 3; j++) {
59629 	   if (trdble(strx.fptr,&vdum[j]) < 0) return -1;
59630 	   if (set) xyzp->coo[i*3+j] = vdum[j]*10.0/TOANGS;
59631 	}
59632       }
59633    }
59634 
59635    if (frame_done) return 0;
59636 
59637    if (strx.v) {
59638       for (i=0; i < strx.natoms; i++) {
59639 	for (j=0; j < 3; j++) {
59640 	   if (trdble(strx.fptr,&vdum[j]) < 0) return -1;
59641 	}
59642       }
59643    }
59644 
59645    if (strx.f) {
59646       for (i=0; i < strx.natoms; i++) {
59647 	for (j=0; j < 3; j++) {
59648 	   if (trdble(strx.fptr,&vdum[j]) < 0) return -1;
59649 	}
59650       }
59651    }
59652 
59653    return 0;
59654 }
59655 
cledr()59656 void cledr()
59657 {
59658    fclose(stre.fptr);
59659 }
59660 
59661 #if defined(VMS) || defined(UNDERSC)
getene(int * nstep,int * istat)59662 void getene(int *nstep,int *istat)
59663 #else
59664 #ifdef CRAY
59665 void GETENE(int *nstep,int *istat)
59666 #else
59667 void getene_(int *nstep,int *istat)
59668 #endif
59669 #endif
59670 {
59671    int i,iframe,iold,step,istp1,istp2,nestp,nepnts,nepntst;
59672    double ener,eprepos,rfrac;
59673    char filename[MAXFNAME];
59674 
59675 /* preposterous value */
59676 
59677    eprepos = 1.54321e-20;
59678    strcpy(filename,grostr[0]);
59679    *istat = 0;
59680 
59681    geo1ptr->ieav = 0;
59682 
59683 MOREMEM:
59684 
59685    if (init_edr(filename) < 0) {
59686         *istat = -1;
59687    } else {
59688 
59689 	geo1ptr->nepnts = 0;
59690 	for (i=0;i<geo1ptr->mxpnt;i++) geop->epoints[i] = eprepos;
59691 	iframe = 0;
59692 	while(!efrm(&step,&ener)) {
59693 	   if (iframe == 0) istp1 = step;
59694 	   if (iframe == 1) {
59695 		istp2 = step;
59696 		nestp = istp2 - istp1;
59697 		rfrac = (double) nestp / (double) *nstep;
59698 	   }
59699 	   iframe++;
59700 	   nepntst = nepnts = (int) (((double)(iframe-1))*rfrac);
59701 	   if (nepnts <= geo1ptr->mxpnt) geop->epoints[nepnts] = ener;
59702 	}
59703 	if (nepntst > geo1ptr->mxpnt) {
59704 
59705 	   nepntst++;
59706 #if defined(VMS) || defined(UNDERSC)
59707 	   allgeo(&nepntst,&ZERO);
59708 #else
59709 #ifdef CRAY
59710 	   ALLGEO(&nepntst,&ZERO);
59711 #else
59712 	   allgeo_(&nepntst,&ZERO);
59713 #endif
59714 #endif
59715 	   rewind(stre.fptr);
59716 	   goto MOREMEM;
59717 	}
59718 	geo1ptr->nepnts = nepnts+1;
59719 	geo1ptr->ieav = 1;
59720 	iold = 0;
59721 	for (i=0;i<geo1ptr->nepnts;i++) {
59722 	   if (geop->epoints[i] == eprepos)
59723 		geop->epoints[i] = geop->epoints[iold];
59724 	   else iold = i;
59725 	}
59726 	(void) cledr();
59727 #if defined(VMS) || defined(UNDERSC)
59728 	gmmcnv(geop->formax,geop->forrms,geop->dismax,geop->disrms,
59729 		geop->epoints,geop->isav);
59730 #else
59731 #ifdef CRAY
59732 	GMMCNV(geop->formax,geop->forrms,geop->dismax,geop->disrms,
59733 		geop->epoints,geop->isav);
59734 #else
59735 	gmmcnv_(geop->formax,geop->forrms,geop->dismax,geop->disrms,
59736 		geop->epoints,geop->isav);
59737 #endif
59738 #endif
59739 
59740    }
59741 
59742 }
59743 
init_edr(char * fileroot)59744 int init_edr(char *fileroot)
59745 {
59746    char filename[MAXFNAME];
59747    char sdummy[80];
59748    int i,nre;
59749 
59750    sprintf(filename,"%s.edr",fileroot);
59751 
59752    stre.fptr = fopen(filename, "rb");
59753    if (!stre.fptr) {
59754 	fprintf(stderr,"Didnt find energy file: %s\n\n",filename);
59755 	return -1;
59756    }
59757 
59758    if (trint(stre.fptr,&nre) < 0) return -1;
59759 
59760    for (i=0;i<nre;i++) {
59761 	if (cntstr(stre.fptr,sdummy) < 0) return -1;
59762 	if (strstr(sdummy,"Total Energy")) stre.etot = i;
59763    }
59764 
59765    return 0;
59766 }
59767 
header_edr(int * step,int * nre)59768 int header_edr(int *step,int *nre)
59769 {
59770    int i;
59771    int dummy, nblock;
59772    double rdum;
59773 
59774 /* edr does not work with magic number ? */
59775 
59776 /* t, step, nre, ndisre, nblock, esize, dsize dum */
59777 
59778    if (trdble(stre.fptr,&rdum) < 0) return -1;
59779    if (trint(stre.fptr,step) < 0) return -1;
59780    if (trint(stre.fptr,nre) < 0) return -1;
59781    if (trint(stre.fptr,&dummy) < 0) return -1;
59782    if (trint(stre.fptr,&nblock) < 0) return -1;
59783    for (i=0;i<nblock;i++)
59784 	if (trint(stre.fptr,&dummy) < 0) return -1;
59785    if (trint(stre.fptr,&dummy) < 0) return -1;
59786    if (trint(stre.fptr,&dummy) < 0) return -1;
59787    if (trint(stre.fptr,&dummy) < 0) return -1;
59788 
59789    return 0;
59790 }
59791 
59792 
efrm(int * step,double * ener)59793 int efrm(int *step,double *ener)
59794 {
59795    int i,nre;
59796    double rdum;
59797 
59798    if (header_edr(step,&nre) < 0) return -1;
59799 
59800    for (i=0; i < nre; i++) {
59801 	if (trdble(stre.fptr,&rdum) < 0) return -1;
59802 	if (i == stre.etot) *ener = rdum;
59803 	if (trdble(stre.fptr,&rdum) < 0) return -1;
59804 	if (trdble(stre.fptr,&rdum) < 0) return -1;
59805 	if (trdble(stre.fptr,&rdum) < 0) return -1;
59806    }
59807 
59808    return 0;
59809 }
59810 
SetExplButton(win,x,y)59811 void SetExplButton(win,x,y)
59812 Window win;
59813 int x,y;
59814 {
59815    BSTRU *arr; int nbut,fnd,i,j; Window sub;
59816    QBOXSTRU *qbptr[5] = {IANZbox,BLbox,ALPHbox,BETbox,IZbox};
59817    int *winup = NULL;
59818 
59819    if (animptr.on || *movie || tnkfrk) return;
59820    if (expldat.active) return;
59821 
59822    fnd = 0;
59823    for (i = 0; i < NOBJS; i++) {
59824 	if (WinObj[i].win != NULL && WinObj[i].subwin != NULL &&
59825 	    WinObj[i].butarr != NULL) {
59826 	   if (win == *WinObj[i].win) {
59827 		arr = WinObj[i].butarr; nbut = WinObj[i].numbut;
59828 		sub = *WinObj[i].subwin;
59829 		winup = WinObj[i].winup;
59830 		fnd = 1;
59831 	   }
59832 	}
59833    }
59834    if (!fnd) return;
59835 
59836    fnd = 0;
59837 
59838    i = Clickwin(arr,nbut,x,y,0);
59839 
59840    if (i >= 0) {
59841 
59842 	if (arr[i].explstr != NULL && arr[i].active) {
59843 
59844 		expldat.button = i;
59845 		expldat.win = sub;
59846 		expldat.winup = winup;
59847 		expldat.barr = arr;
59848 		expldat.borq = 0;
59849 		fnd = 1;
59850 	}
59851 
59852    } else {
59853 	i = CheckBox(qboxes,NQBOX,win,x,y);
59854 	if (i >= 0) {
59855 	   if (qboxes[i].explstr != NULL) {
59856 		expldat.button = i;
59857 		expldat.win = sub;
59858 		expldat.winup = winup;
59859 		expldat.qarr = qboxes;
59860 		expldat.borq = 1;
59861 		fnd = 1;
59862 	   }
59863 	}
59864 	if (!fnd && win == ZMEwin) {
59865 	   for (j=0; j < 5; j++) {
59866 	     if (!fnd) {
59867 		int n;
59868 		n = *zmptrp->nz;
59869 		if (j == 4) n = *zmptrp->nz*4;
59870 		i = CheckBox(qbptr[j],n,win,x,y);
59871 		if (i >= 0) {
59872 		   if ((qbptr[j])[i].explstr != NULL) {
59873 			expldat.button = i;
59874 			expldat.win = sub;
59875 			expldat.winup = winup;
59876 			expldat.qarr = qbptr[j];
59877 			expldat.borq = 1;
59878 			fnd = 1;
59879 		   }
59880 		}
59881 	     }
59882 	   }
59883 	}
59884    }
59885 
59886    if (fnd) {
59887 #ifdef HASTIMER
59888 	Timer(1500,2);
59889 #else
59890 	signal(SIGALRM,handle_explalarm);
59891 	alarm(2);
59892 #endif
59893    } else {
59894 	signal(SIGALRM,SIG_IGN);
59895    }
59896 }
59897 
59898 #if defined(VMS) || defined(UNDERSC)
chktmp()59899 void chktmp()
59900 #else
59901 #ifdef CRAY
59902 void CHKTMP()
59903 #else
59904 void chktmp_()
59905 #endif
59906 #endif
59907 {
59908 #ifdef __CYGWIN__
59909 int status;
59910 
59911    if (access("/cygdrive/c/tmp",F_OK) != 0) {
59912 	status = mkdir("/cygdrive/c/tmp", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
59913 	if (status == -1) fprintf(stderr,"Directory C:\\tmp not found\n");
59914    }
59915 
59916 #endif
59917 
59918 }
59919 
59920 struct stat s_buf;
59921 
dos2u(path)59922 int dos2u(path)
59923 char *path;
59924 {
59925 	FILE *in, *out;
59926 	int ch, rval = 0;
59927 	char temppath [16];
59928 	struct utimbuf { time_t actime, modtime; } ut_buf;
59929 
59930 	strcpy (temppath, "./clntmp");
59931 	strcat (temppath, "XXXXXX");
59932 	mktemp (temppath);
59933 
59934 	if ((in=fopen (path, "r")) == (FILE *) 0) return 1;
59935 
59936 	if ((out=fopen (temppath, "w")) == (FILE *) 0) {
59937 	   fclose (in);
59938 	   return 1;
59939 	}
59940 
59941 	while ((ch = getc(in)) != EOF) {
59942 	   if ( (ch != '\015' && ch != '\032') &&
59943 		(putc (ch, out) == EOF) ) {
59944 		rval = 1;
59945 		break;
59946 	   }
59947 	}
59948 
59949 	if (fclose(in) == EOF) rval = 1;
59950 	if (fclose(out) == EOF) rval = 1;
59951 
59952 	ut_buf.actime = s_buf.st_atime;
59953 	ut_buf.modtime = s_buf.st_mtime;
59954 	if (utime(temppath, &ut_buf) == -1) rval = 1;
59955 
59956 	if (unlink(path) == -1) rval = 1;
59957 
59958 	if (rval) {
59959 	   unlink(temppath);
59960 	   return 1;
59961 	}
59962 
59963 	if (link(temppath,path) == -1) {
59964 	   fprintf (stderr, "Problems renaming '%s' to '%s'\n", temppath, path);
59965 	} else {
59966 	   unlink (temppath);
59967 	}
59968 	return 0;
59969 }
59970 
mvhlpat(nlines,nato1)59971 void mvhlpat(nlines,nato1)
59972 int nlines;
59973 int *nato1;
59974 {
59975     int i,j,k,iat1;
59976 
59977 /*
59978 Nato1 is the first atom that is not a real atom, but a fake help
59979 atom for Xwindows secondary structure visualisation.
59980 These fake atoms are going to move nlines up. In the freed space
59981 added atoms of a ligand can be placed.
59982 Of course nlines have to be added to iatoms.
59983 iatoms = real atoms + fake atoms
59984 */
59985     iat1  = *xyzp->iatoms;
59986 
59987     *nato1 = iat1;
59988     for (j=iat1-1; j >= 0; j--) {
59989  	if (xyzp->ianz[j] != 100) {
59990 		*nato1 = j+1;
59991 		break;
59992 	}
59993     }
59994 
59995     for (j=iat1-1; j >= *nato1; j--) {
59996 	xyzp->iatclr[j+nlines] = xyzp->iatclr[j];
59997 	xyzp->iresid[j+nlines] = xyzp->iresid[j];
59998 	xyzp->iaton[j+nlines] = xyzp->iaton[j];
59999 	xyzp->ianz[j+nlines] = xyzp->ianz[j];
60000 	for (k=0; k < 3; k++)
60001 	   xyzp->coo[(j+nlines)*3+k] = xyzp->coo[j*3+k];
60002 	for (k=0; k < xyzp->iconn[j*(MXCON+1)]; k++) {
60003 	   xyzp->iconn[(j+nlines)*(MXCON+1)+k+1] =
60004 		xyzp->iconn[j*(MXCON+1)+k+1] + nlines;
60005 	}
60006 	xyzp->iconn[(j+nlines)*(MXCON+1)] = xyzp->iconn[j*(MXCON+1)];
60007     }
60008 }
60009 
60010 #define STR1COL 0
60011 #define STR2COL 11
60012 
AlignStructs(str2,copy)60013 int AlignStructs(str2,copy)
60014 int str2;
60015 int copy;
60016 {
60017 
60018   int i,j,k,l,nlines,ires,memstat,istmp;
60019   int iat1,iat2,itot,nato1,nato2,nres1,nres2,nhet1,nhet2;
60020   double d;
60021   COOSTRU *xyzp1;
60022   COOSTRU *xyzp2;
60023   CALFSTRU *calf1;
60024   CALFSTRU *calf2;
60025 
60026     xyzp1   = xyzp;
60027     xyzp2   = &COO[str2]->coo;
60028     calf1   = calfptr;
60029     calf2   = &COO[str2]->calf;
60030 
60031     iat1    = *xyzp->iatoms;
60032     iat2    = COO[str2]->iatoms;
60033     nato1   = *natorg;
60034     if (nato1 < iat1) nato1 = iat1;
60035     nato2   = COO[str2]->natorg;
60036     if (nato2 < iat2) nato2 = iat2;
60037     nres1   = calfptr->ncalf;
60038     nres2   = COO[str2]->calf.ncalf;
60039     nhet1   = hetptr.NHetAtm-4;
60040     nhet2   = COO[str2]->hetatm.NHetAtm-4;
60041 
60042     if (nres1 <= 0 || nres2 <= 0) {
60043 
60044 /* small molecule alignment */
60045 
60046 	if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
60047 " - Use the standard rotation, translation and zoom in/out.\n\
60048  - Use the Esc to switch between rotation of part or the whole structure\n\
60049  - Use the Tab to enter the select mode; select 3 couples of atoms to align\n\
60050    A couple= atom structure1 (red), atom structure2 (white)",1)) {
60051 	   *iscst = iat1; *nscnd = iat2; *ialtyp = 3;
60052 	   CombineStructs(str2,1,1);
60053 	   doalign = 1; *irtcel = 2; *irtval = 2; *atcol = 0;
60054 	   TogDown(&cbut[BATCOL]);
60055 #if defined(VMS) || defined(UNDERSC)
60056 	   aln2ml(ialtyp,&idum1);
60057 #else
60058 #ifdef CRAY
60059 	   ALN2ML(ialtyp,&idum1);
60060 #else
60061 	   aln2ml_(ialtyp,&idum1);
60062 #endif
60063 #endif
60064 	   return(0);
60065 	}
60066 	return(0);
60067     }
60068 
60069 /* protein alignment */
60070 
60071    if (copy) {
60072 	if ((COOt = (double *) malloc((sizeof d)*(*xyzp2->mxnat)*3)) == NULL) {
60073 	   memstat = 0;
60074 	} else {
60075 	   for (i=0; i < iat2; i++ ) {
60076 		for (k=0; k < 3; k++) {
60077 		   COOt[i*3+k] = xyzp2->coo[i*3+k];
60078 		}
60079 	   }
60080 	}
60081    } else {
60082 	COOt = xyzp2->coo;
60083    }
60084 
60085 #if defined(VMS) || defined(UNDERSC)
60086     curs(&ONE);
60087     supimp( xyzp1->coo,COOt,&iat1,&iat2,
60088     	calf1->iamino,calf2->iamino,calf1->icalf,calf2->icalf,
60089     	&calf1->ncalf,&calf2->ncalf,calf1->isal,calf2->isal);
60090     curs(&ZERO);
60091 #else
60092 #ifdef CRAY
60093     CURS(&ONE);
60094     SUPIMP( xyzp1->coo,COOt,&iat1,&iat2,
60095     	calf1->iamino,calf2->iamino,calf1->icalf,calf2->icalf,
60096     	&calf1->ncalf,&calf2->ncalf,calf1->isal,calf2->isal);
60097     CURS(&ZERO);
60098 #else
60099     curs_(&ONE);
60100     supimp_( xyzp1->coo,COOt,&iat1,&iat2,
60101     	 calf1->iamino,calf2->iamino,calf1->icalf,calf2->icalf,
60102     	&calf1->ncalf,&calf2->ncalf,calf1->isal,calf2->isal);
60103     curs_(&ZERO);
60104 #endif
60105 #endif
60106     if (!copy) {
60107 #if defined(VMS) || defined(UNDERSC)
60108 	cntvec(
60109 #else
60110 
60111 #ifdef CRAY
60112 	CNTVEC(
60113 #else
60114 	cntvec_(
60115 #endif
60116 #endif
60117 	   COO[str2]->rot.t,xyzp2->coo,xyzp2->ianz,xyzp2->iatoms);
60118         istmp = istruct;
60119         istruct = str2;
60120 	NewActiveStruct();
60121 #ifdef DOGL
60122         RibClear(istruct);
60123         NSurf[istruct] = 0;
60124 #if defined(VMS) || defined(UNDERSC)
60125         ribgl(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
60126         chkbck(&ONE);
60127 #else
60128 #ifdef CRAY
60129         RIBGL(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
60130         CHKBCK(&ONE);
60131 #else
60132         ribgl_(calfptr->ianf,&calfptr->nchain,&calfptr->ncalf,xyzp->iatoms);
60133         chkbck_(&ONE);
60134 #endif
60135 #endif
60136 
60137         SSdone[istruct] = 1;
60138         for (i=0; i<4; i++)
60139     	    if (calfptr->ihet[i]) sndon(i,0,0);
60140 #endif
60141         istruct = istmp;
60142 	NewActiveStruct();
60143     }
60144     return(1);
60145 
60146 }
60147 
CombineStructs(str2,notaligned,new_struct)60148 void CombineStructs(str2,notaligned,new_struct)
60149 int str2;
60150 int notaligned;
60151 int new_struct;
60152 {
60153 
60154   int i,j,k,l,nlines,ires,pdb1,pdb2,nchstr1,str1;
60155   int iat1,iat2,itot,nato1,nato2,nres1,nres2,nhet1,nhet2;
60156   double tmp1[3],tmp2[3],tmp3[3],rad1,rad2,vl;
60157   COOSTRU *xyzpn;
60158   COOSTRU *xyzp1;
60159   COOSTRU *xyzp2;
60160   CALFSTRU *calf1;
60161   CALFSTRU *calf2;
60162   CALFSTRU *calfn;
60163 
60164   if (new_struct) {
60165 
60166      str1 = istruct;
60167      ZMEAA = 0;
60168      aflag = 0; bflag = 0; cflag = 0; dflag = 0;
60169      LastAmino = -1;
60170      CurAmino = -1;
60171      do3dx = 0; *do3d = 1;
60172      FRQ->ihasi = 0;
60173      HETLABSTRU hetlab = {.NHetLab = 0};
60174 
60175      if (*multstruct) {
60176 
60177 	if (nstruct == MAXSTRUCT) {
60178 
60179 	    if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
60180 		"Reached maximum number supported structures",0)) {}
60181 
60182 	} else {
60183 
60184 	    if (nstruct == 0 && nfilesstart != 0) {
60185 		SaveFirstStruct();
60186 		nstruct++;
60187 	    }
60188 
60189 	    AllocateStructure(&COO[nstruct]);
60190 
60191 	    if (nstruct != 0) SaveActiveStruct();
60192 
60193 	    if (COO[nstruct] == NULL) {
60194 		   if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
60195 			     "Failed to allocate memory for structure",0)) {}
60196 	    } else {
60197 		   char combstr[MAXCMD];
60198 		   char xstr1[MAXCMD];
60199 		   char xstr2[MAXCMD];
60200 		   char *last1, *last2;
60201 		   char *dot1, *dot2;
60202 		   int n1=0,n2=0;
60203 
60204 		   last1 = rindex(COO[str1]->fname,'/');
60205 		   if (last1 != NULL) {
60206 			last1++;
60207 			dot1 = strchr(last1,'.');
60208 			if (dot1 != NULL) {
60209 			   n1 = (int) (dot1 - last1);
60210 			   strncpy(xstr1,last1,n1);
60211 			   xstr1[n1] = '\0';
60212 			}
60213 		   }
60214 		   last2 = rindex(COO[str2]->fname,'/');
60215 		   if (last2 != NULL) {
60216 			last2++;
60217 			dot2 = strchr(last2,'.');
60218 			if (dot2 != NULL) {
60219 			   n2 = (int) (dot2 - last2);
60220 			   strncpy(xstr2,last2,n2);
60221 			   xstr2[n2] = '\0';
60222 			}
60223 		   }
60224 		   if (n1 != 0 && n2 != 0) {
60225 			sprintf(combstr,"%s+%s",xstr1,xstr2);
60226 		   } else {
60227 			if (COO[str1]->pdbcode != NULL &&
60228 				COO[str2]->pdbcode != NULL) {
60229 			   sprintf(combstr,"%s+%s",
60230 			   COO[str1]->pdbcode,COO[str2]->pdbcode);
60231 			} else {
60232 			   sprintf(combstr,"%s+%s",
60233 			   COO[str1]->fname,COO[str2]->fname);
60234 			}
60235 		   }
60236 		   AllocateSubStructures(combstr,0);
60237 	    }
60238 	}
60239      }
60240      ntits = 0;
60241      *backb = 0;
60242      if (COO[str1]->backb || COO[str2]->backb) *backb = 1;
60243      empty_model(istruct,1);
60244      COO[istruct]->pdbcode = NULL;
60245      COO[istruct]->hetatm.NHetAtm = 0;
60246   }
60247 
60248 
60249   if (new_struct) {
60250     xyzp1   = &COO[str1]->coo;
60251     xyzp2   = &COO[str2]->coo;
60252     xyzpn   = xyzp;
60253     calf1   = &COO[str1]->calf;
60254     calf2   = &COO[str2]->calf;
60255     calfn   = calfptr;
60256     pdb1    =  COO[str1]->pdb;
60257     pdb2    =  COO[str2]->pdb;
60258 
60259     iat1    = COO[str1]->iatoms;
60260     iat2    = COO[str2]->iatoms;
60261   } else {
60262 
60263     xyzp1   = xyzp;
60264     xyzp2   = &COO[str2]->coo;
60265     xyzpn   = xyzp;
60266     calf1   = calfptr;
60267     calf2   = &COO[str2]->calf;
60268     pdb1    =  *ipdbon;
60269     pdb2    =  COO[str2]->pdb;
60270 
60271     iat1    = *xyzp->iatoms;
60272     iat2    = COO[str2]->iatoms;
60273   }
60274 
60275   if (notaligned) {
60276      COOt = xyzp2->coo;
60277   }
60278 
60279 
60280     nato1 = iat1;
60281     for (j=iat1-1; j >= 0; j--) {
60282  	if (xyzp1->ianz[j] != 100) {
60283 		nato1 = j+1;
60284 		break;
60285 	}
60286     }
60287 
60288     nato2 = iat2;
60289     for (j=iat2-1; j >= 0; j--) {
60290  	if (xyzp2->ianz[j] != 100) {
60291 		nato2 = j+1;
60292 		break;
60293 	}
60294     }
60295 
60296     if (pdb1) {
60297 	nres1   = COO[str1]->calf.ncalf;
60298 	nhet1   = COO[str1]->hetatm.NHetAtm-4;
60299     } else {
60300 	nres1   = 0;
60301 	nhet1   = 1;
60302     }
60303 
60304     if (pdb2) {
60305 	nres2   = COO[str2]->calf.ncalf;
60306 	nhet2   = COO[str2]->hetatm.NHetAtm-4;
60307     } else {
60308 	nres2   = 0;
60309 	nhet2   = 1;
60310     }
60311 
60312     itot = iat1 + iat2;
60313 
60314     if (itot > *xyzp->mxnat - 500) {
60315 	itot = itot + 500;
60316 #if defined(VMS) || defined(UNDERSC)
60317 	allcoo(&itot,&ZERO);
60318 #else
60319 #ifdef CRAY
60320 	ALLCOO(&itot,&ZERO);
60321 #else
60322 	allcoo_(&itot,&ZERO);
60323 #endif
60324 #endif
60325     }
60326 
60327     if (nres1 <= 0 && nres2 <= 0 && notaligned) {
60328 #if defined(VMS) || defined(UNDERSC)
60329 	cntvec(
60330 #else
60331 
60332 #ifdef CRAY
60333 	CNTVEC(
60334 #else
60335 	cntvec_(
60336 #endif
60337 #endif
60338 	tmp1,xyzp1->coo,xyzp1->ianz,xyzp1->iatoms);
60339 	getrad(tmp1,xyzp1->coo,xyzp1->iatoms,&rad1);
60340 #if defined(VMS) || defined(UNDERSC)
60341 	cntvec(
60342 #else
60343 
60344 #ifdef CRAY
60345 	CNTVEC(
60346 #else
60347 	cntvec_(
60348 #endif
60349 #endif
60350 	tmp2,COOt,xyzp2->ianz,xyzp2->iatoms);
60351 	getrad(tmp2,COOt,xyzp2->iatoms,&rad2);
60352 	for (j=0; j<3; j++) tmp3[j] = tmp2[j] - tmp1[j];
60353 	vl = dveclen(tmp3);
60354 	if (vl > rad1 + 5.0) {
60355 	   if (!DoCan(event.xbutton.x_root,event.xbutton.y_root,
60356 	      "Molecules very far apart !.\n Move to visible range ?",1)) {
60357 		for (j=0; j<3; j++) {
60358 		    tmp3[j] = -tmp3[j]*(rad1+rad2)/vl - tmp3[j];
60359 		}
60360 		for (j=0; j< *xyzp2->iatoms ; j++)
60361 #if defined(VMS) || defined(UNDERSC)
60362 		   trcoo(tmp3,&COOt[j*3]);
60363 #else
60364 
60365 #ifdef CRAY
60366 		   TRCOO(tmp3,&COOt[j*3]);
60367 #else
60368 		   trcoo_(tmp3,&COOt[j*3]);
60369 #endif
60370 #endif
60371 #if defined(VMS) || defined(UNDERSC)
60372 		cntvec(
60373 #else
60374 
60375 #ifdef CRAY
60376 		CNTVEC(
60377 #else
60378 		cntvec_(
60379 #endif
60380 #endif
60381 		   tmp2,COOt,xyzp2->ianz,xyzp2->iatoms);
60382 		for (j=0; j<3; j++) {
60383 		    rotptr->t[j] = (tmp1[j] + tmp2[j])/2.0;
60384 		}
60385 
60386 	   }
60387 	}
60388     }
60389 
60390     for (j=0; j < iat1; j++) {
60391 	xyzpn->iatclr[j] = xyzp1->iatclr[j];
60392 
60393 	xyzpn->iresid[j] = xyzp1->iresid[j];
60394 	xyzpn->iaton[j] = xyzp1->iaton[j];
60395 	xyzpn->ianz[j] = xyzp1->ianz[j];
60396 	xyzpn->ipdbt[j]  = xyzp1->ipdbt[j];
60397 	xyzpn->ityp[j]   = xyzp1->ityp[j];
60398 	xyzpn->qat[j]    = xyzp1->qat[j];
60399 	for (k=0; k < 3; k++)
60400 	   xyzpn->coo[j*3+k] = xyzp1->coo[j*3+k];
60401 	for (k=0; k < xyzp1->iconn[j*(MXCON+1)]; k++) {
60402 	   xyzpn->iconn[j*(MXCON+1)+k+1] =
60403 		xyzp1->iconn[j*(MXCON+1)+k+1];
60404 	}
60405 	xyzpn->iconn[j*(MXCON+1)] = xyzp1->iconn[j*(MXCON+1)];
60406     }
60407 
60408 /*
60409     MOVE FAKE ATOMS for secundary structure visualisation xwindows
60410     of the FIRST structure.
60411     They only should have connections amongst themselves
60412 */
60413 
60414     nlines = nato2;
60415 
60416     for (j=0; j < iat1; j++) xyzpn->iatclr[j] = STR1COL + 1;
60417 
60418     for (j=iat1-1; j >= nato1; j--) {
60419 	xyzpn->iatclr[j+nlines] = xyzp1->iatclr[j];
60420 	xyzpn->iresid[j+nlines] = xyzp1->iresid[j];
60421 	xyzpn->iaton[j+nlines] = xyzp1->iaton[j];
60422 	xyzpn->ianz[j+nlines] = xyzp1->ianz[j];
60423 	for (k=0; k < 3; k++)
60424 	   xyzpn->coo[(j+nlines)*3+k] = xyzp1->coo[j*3+k];
60425 	for (k=0; k < xyzp1->iconn[j*(MXCON+1)]; k++) {
60426 	   xyzpn->iconn[(j+nlines)*(MXCON+1)+k+1] =
60427 		xyzp1->iconn[j*(MXCON+1)+k+1] + nlines;
60428 	}
60429 	xyzpn->iconn[(j+nlines)*(MXCON+1)] = xyzp1->iconn[j*(MXCON+1)];
60430     }
60431 
60432 /*
60433    COPY FAKE ATOMS for secundary structure visualisation xwindows
60434    of the SECOND structure TO the FIRST structure.
60435 */
60436 
60437     nlines = iat1;
60438     for (j=nato2; j < iat2; j++) {
60439 	xyzpn->iatclr[j+nlines] = xyzp2->iatclr[j];
60440 	xyzpn->iresid[j+nlines] = xyzp2->iresid[j];
60441 	xyzpn->iaton[j+nlines] = xyzp2->iaton[j];
60442 	xyzpn->ianz[j+nlines] = xyzp2->ianz[j];
60443 	for (k=0; k < 3; k++)
60444 	   xyzpn->coo[(j+nlines)*3+k] = COOt[j*3+k];
60445 	for (k=0; k < xyzp2->iconn[j*(MXCON+1)]; k++) {
60446 	   xyzpn->iconn[(j+nlines)*(MXCON+1)+k+1] =
60447 		xyzp2->iconn[j*(MXCON+1)+k+1] + nlines;
60448 	}
60449 	xyzpn->iconn[(j+nlines)*(MXCON+1)] = xyzp2->iconn[j*(MXCON+1)];
60450     }
60451 
60452 /*
60453    COPY REAL ATOMS of the SECOND structure TO the FIRST structure.
60454 */
60455     nlines = nato1;
60456     for (j=0; j < nato2; j++) {
60457 	ires = xyzp2->iresid[j];
60458 	if (pdb1 && pdb2) {
60459 	   if (ires > 0) {
60460 		xyzpn->iresid[j+nlines] = nres1 + xyzp2->iresid[j];
60461 	   } else if (ires < -3) {
60462 		xyzpn->iresid[j+nlines] = xyzp2->iresid[j] - (nhet1);
60463 	   } else {
60464 		xyzpn->iresid[j+nlines] = xyzp2->iresid[j];
60465    	   }
60466 	} else {
60467 	   if (pdb1) {
60468 		xyzpn->iresid[j+nlines] = -COO[str1]->hetatm.NHetAtm;
60469 	   } else {
60470 		xyzpn->iresid[j+nlines] = -4;
60471 	   }
60472 	}
60473 
60474 /*
60475 	xyzpn->iatclr[j+nlines] = xyzp2->iatclr[j];
60476 */
60477 	xyzpn->iatclr[j+nlines] = STR2COL + 1;
60478 	xyzpn->iaton[j+nlines]  = xyzp2->iaton[j];
60479 	xyzpn->ianz[j+nlines]   = xyzp2->ianz[j];
60480 	xyzpn->ipdbt[j+nlines]  = xyzp2->ipdbt[j];
60481 	xyzpn->ityp[j+nlines]   = xyzp2->ityp[j];
60482 	xyzpn->qat[j+nlines]    = xyzp2->qat[j];
60483 
60484 	for (k=0; k < 3; k++)
60485 	   xyzpn->coo[(j+nlines)*3+k] = COOt[j*3+k];
60486 	for (k=0; k < xyzp2->iconn[j*(MXCON+1)]; k++) {
60487 	   i = xyzp2->iconn[j*(MXCON+1)+k+1];
60488 	   if (i >= 0) {
60489 	      xyzpn->iconn[(j+nlines)*(MXCON+1)+k+1] =
60490 		xyzp2->iconn[j*(MXCON+1)+k+1] + nlines;
60491 	   } else {
60492 	      xyzpn->iconn[(j+nlines)*(MXCON+1)+k+1] =
60493 		xyzp2->iconn[j*(MXCON+1)+k+1] - nlines;
60494 	   }
60495 	}
60496 	xyzpn->iconn[(j+nlines)*(MXCON+1)] = xyzp2->iconn[j*(MXCON+1)];
60497     }
60498     *natorg = nato1 + nato2;
60499     *xyzp->iatoms = iat1 + iat2;
60500 
60501     calfn->ncalf = nres1 + nres2;
60502     for (i=0; i < nres1; i++) {
60503 	   calfn->reson[i] = calf1->reson[i];
60504 	   calfn->isal[i] = calf1->isal[i];
60505 	   calfn->irsnr[i] = calf1->irsnr[i];
60506 	   calfn->iamino[i] = calf1->iamino[i];
60507 	   calfn->iams[i] = 0;
60508            for (j=0; j < 6; j++)
60509 		calfn->icalf[i][j] = calf1->icalf[i][j];
60510     }
60511     for (i=0; i < nres2; i++) {
60512 	if (nres1+i < NUMCAL) {
60513 	   calfn->reson[nres1+i] = calf2->reson[i];
60514 	   calfn->isal[nres1+i] = calf2->isal[i];
60515 	   calfn->irsnr[nres1+i] = calf2->irsnr[i] + nres1;
60516 	   calfn->iamino[nres1+i] = calf2->iamino[i];
60517 	   calfn->iams[nres1+i] = 0;
60518            for (j=0; j < 6; j++)
60519 		calfn->icalf[nres1+i][j] = calf2->icalf[i][j] + nato1;
60520 	}
60521     }
60522     if (calfn->ncalf >= NUMCAL) calfn->ncalf = NUMCAL-1;
60523 
60524     for (i=0; i < calf1->nchain; i++) {
60525 	calfn->ianf[i] = calf1->ianf[i];
60526 	calfn->islu[i] = calf1->islu[i];
60527     }
60528     for (i=0; i < calf2->nchain; i++) {
60529 	calfn->ianf[calf1->nchain+i] = calf2->ianf[i] + nres1;
60530 	calfn->islu[calf1->nchain+i] = calf2->islu[i] + nres1;
60531     }
60532     nchstr1 = calf1->nchain;
60533     calfn->nchain = calf1->nchain + calf2->nchain;
60534 
60535     if (pdb1 && pdb2) {
60536 	for (j=0; j<nhet1+4; j++) {
60537 	   if (j < MXHETA) {
60538 	      if (new_struct) {
60539 		int n;
60540 		hetptr.Allocated[j] = 1;
60541 		n = strlen(COO[str1]->hetatm.HetAtm[j]);
60542 		hetptr.HetAtm[j] = (char *) malloc(n+1);
60543 		strcpy(hetptr.HetAtm[j],COO[str1]->hetatm.HetAtm[j]);
60544 	      } else {
60545 	        hetptr.Allocated[j] = COO[str1]->hetatm.Allocated[j];
60546 	        hetptr.HetAtm[j] = COO[str1]->hetatm.HetAtm[j];
60547 	      }
60548 	      calfn->ihet[j] = calf1->ihet[j];
60549 	   }
60550 	}
60551 	hetptr.NHetAtm = nhet1+4;
60552 	for (j=0; j<nhet2; j++) {
60553 	   if (hetptr.NHetAtm+j < MXHETA) {
60554 	      if (new_struct) {
60555 		int n;
60556 		hetptr.Allocated[hetptr.NHetAtm+j] = 1;
60557 		n = strlen(COO[str2]->hetatm.HetAtm[4+j]);
60558 		hetptr.HetAtm[hetptr.NHetAtm+j] = (char *) malloc(n+1);
60559 		strcpy(hetptr.HetAtm[hetptr.NHetAtm+j],
60560 			COO[str2]->hetatm.HetAtm[4+j]);
60561 	      } else {
60562 	        hetptr.Allocated[hetptr.NHetAtm+j] =
60563 			COO[str2]->hetatm.Allocated[4+j];
60564 	        hetptr.HetAtm[hetptr.NHetAtm+j] = COO[str2]->hetatm.HetAtm[4+j];
60565 	      }
60566 	      calfn->ihet[hetptr.NHetAtm+j] = calf2->ihet[4+j];
60567 	   }
60568 	}
60569 	hetptr.NHetAtm = nhet1 + nhet2 + 4;
60570 	if (hetptr.NHetAtm >= MXHETA) hetptr.NHetAtm = MXHETA-1;
60571 	*ipdbon = 1;
60572 
60573     } else {
60574 	int n;
60575 
60576 	hetptr.Allocated[hetptr.NHetAtm] = 0;
60577 	n = strlen(COO[str2]->fname);
60578 	hetptr.HetAtm[hetptr.NHetAtm] = (char *) malloc(n+1);
60579 	hetptr.HetAtm[hetptr.NHetAtm] = COO[str2]->fname;
60580 	calfn->ihet[hetptr.NHetAtm] = 1;
60581 
60582 	if ( pdb1 || pdb2) {
60583 	   hetptr.NHetAtm = nhet1 + 1 + 4;
60584 	} else {
60585 	   hetptr.NHetAtm++;
60586 	}
60587     }
60588 
60589     alnptr->nalign = 2;
60590     alnptr->istst[0] = iat1;
60591     alnptr->istst[1] = iat2;
60592     alnptr->istres[0] = nres1;
60593     alnptr->istres[1] = calfn->ncalf;
60594     alnptr->istch[0] = nchstr1;
60595     alnptr->istch[1] = calfn->nchain;
60596     alnptr->istcol[0] = STR1COL;
60597     alnptr->istcol[1] = STR2COL;
60598 
60599 #ifdef DOGL
60600     RibClear(istruct);
60601     NSurf[istruct] = 0;
60602 #if defined(VMS) || defined(UNDERSC)
60603     ribgl(calfn->ianf,&calfn->nchain,&calfn->ncalf,xyzpn->iatoms);
60604     chkbck(&ONE);
60605 #else
60606 #ifdef CRAY
60607     RIBGL(calfn->ianf,&calfn->nchain,&calfn->ncalf,xyzpn->iatoms);
60608     CHKBCK(&ONE);
60609 #else
60610     ribgl_(calfn->ianf,&calfn->nchain,&calfn->ncalf,xyzpn->iatoms);
60611     chkbck_(&ONE);
60612 #endif
60613 #endif
60614 
60615     SSdone[istruct] = 1;
60616     for (i=0; i<4; i++)
60617 	if (calfn->ihet[i]) sndon(i,0,0);
60618 
60619     ColorByStruct();
60620     ActualiseBackbone(0);
60621     dispsf();
60622 #endif
60623     if (!notaligned) {
60624 	if (COOt != NULL) free(COOt);
60625     } else {
60626 	vl = dst_coo(xyzp1,xyzp2,nato1,nato2);
60627 	fprintf(stderr,"RMSD %.3f\n",vl);
60628     }
60629 
60630 }
60631 
AddAtom(i,j,k,bl,alpha,dih,ires)60632 void AddAtom(i,j,k,bl,alpha,dih,ires)
60633 int i,j,k,ires;
60634 double bl,alpha,dih;
60635 {
60636 	int iret;
60637 
60638 #if defined(VMS) || defined(UNDERSC)
60639 	atadd(&i,&j,&k,&ONE,&bl,&alpha,&dih,&iret,
60640 #else
60641 #ifdef CRAY
60642 	ATADD(&i,&j,&k,&ONE,&bl,&alpha,&dih,&iret,
60643 #else
60644 	atadd_(&i,&j,&k,&ONE,&bl,&alpha,&dih,&iret,
60645 #endif
60646 #endif
60647 	 xyzp->ianz,xyzp->iaton,xyzp->iatclr,xyzp->iconn,xyzp->iresid,
60648 	 xyzp->ityp,xyzp->ipdbt,&calfptr->ncalf,calfptr->icalf,xyzp->coo);
60649 	if (iret != 0 && iret < *xyzp->mxnat)
60650  		xyzp->iresid[iret-1] = ires;
60651 }
60652 
LigandHydro(het)60653 void LigandHydro(het)
60654 int het;
60655 {
60656 
60657   int i,j,k,l,nc,xc,ir,ix,iy,iz,size,j1,is,nsp2,ic0,ic1;
60658   int nat,fnd,istart,iend,itot;
60659   int ic[3];
60660   int *sp,*icn;
60661   float aret,da1,da2,da3;
60662   double bl,alpha,dih;
60663   int asel[6],anum,iret;
60664 
60665   size = *xyzp->mxnat;
60666   sp = (int *) malloc((sizeof i)*size);
60667 
60668   icn = (int *) malloc((sizeof i)*size*(MXCON+1));
60669 
60670   for (j=0; j < *xyzp->iatoms; j++)
60671      for (k=0; k < MXCON+1; k++)
60672 	icn[k+j*(MXCON+1)] = xyzp->iconn[k+j*(MXCON+1)];
60673 
60674   for (j=0; j < *xyzp->iatoms; j++) {
60675      sp[j] = 0;
60676      j1 = j + 1;
60677 
60678 /* Oxygen */
60679 
60680      if (xyzp->ianz[j] == 8) {
60681 
60682 	for (k=0; k < 3; k++) ic[k] = -1;
60683 
60684 	nc = icn[j*(MXCON+1)];
60685 
60686 	if (nc == 1) {
60687 	   for (k=0; k < nc; k++)
60688 		ic[k] = icn[j*(MXCON+1)+k+1];
60689 
60690 	   ix = ic[0];
60691 	   xc = icn[(ix-1)*(MXCON+1)];
60692 
60693 	   if (xc > 0 && xc <= 4) {
60694 		l = 0;
60695 		for (k=0; k < xc; k++) {
60696 		   iy = icn[(ix-1)*(MXCON+1)+k+1];
60697 		   if (iy != j1) {
60698 			ic[l] = iy;
60699 			l++;
60700 		   }
60701 		}
60702 		alpha = 0.0;
60703 		for (k=0; k < l; k++) {
60704 		   asel[0] = j1;
60705 		   asel[1] = ix;
60706 		   asel[2] = ic[k];
60707 		   anum = 3;
60708 
60709 #if defined(VMS) || defined(UNDERSC)
60710 		   tomold(&aret,asel,&anum);
60711 #else
60712 #ifdef CRAY
60713 		   TOMOLD(&aret,asel,&anum);
60714 #else
60715 		   tomold_(&aret,asel,&anum);
60716 #endif
60717 #endif
60718 		   alpha = alpha + aret;
60719 		}
60720 
60721 		alpha = alpha / (double) l;
60722 
60723 		da1 = ABS(alpha-109.47);
60724 		da2 = ABS(alpha-120.0);
60725 
60726 		if (da1 < da2) {
60727 		   sp[j] = 3;
60728 
60729 		   AddAtom(ic[0],ix,j1,1.090,109.47,180.0,xyzp->iresid[j]);
60730 
60731 		} else {
60732 
60733 		   sp[j] = 2;
60734 		}
60735 	   }
60736 
60737 	} else if (nc == 2) {
60738 	   sp[j] = 3;
60739 
60740 	}
60741      }
60742 
60743 /* Carbon */
60744 
60745      if (xyzp->ianz[j] == 6) {
60746 	ix = -1;
60747 	iy = -1;
60748 	for (k=0; k < 3; k++) ic[k] = -1;
60749 
60750 	nc = icn[j*(MXCON+1)];
60751 	if (nc <= 3) {
60752 	   for (k=0; k < nc; k++)
60753 		ic[k] = icn[j*(MXCON+1)+k+1];
60754 
60755 	}
60756 
60757 	if (nc == 1) {
60758 
60759 	    ix = ic[0];
60760 	    xc = icn[(ix-1)*(MXCON+1)];
60761 
60762 	    if (xc > 0 && xc <= 4) {
60763 		l = 0;
60764 		for (k=0; k < xc; k++) {
60765 		   iy = icn[(ix-1)*(MXCON+1)+k+1];
60766 		   if (iy != j1) {
60767 			ic[l] = iy;
60768 			l++;
60769 		   }
60770 		}
60771 		alpha = 0.0;
60772 		for (k=0; k < l; k++) {
60773 		   asel[0] = j1;
60774 		   asel[1] = ix;
60775 		   asel[2] = ic[k];
60776 		   anum = 3;
60777 
60778 #if defined(VMS) || defined(UNDERSC)
60779 		   tomold(&aret,asel,&anum);
60780 #else
60781 #ifdef CRAY
60782 		   TOMOLD(&aret,asel,&anum);
60783 #else
60784 		   tomold_(&aret,asel,&anum);
60785 #endif
60786 #endif
60787 		   alpha = alpha + aret;
60788 		}
60789 
60790 		alpha = alpha / (double) l;
60791 
60792 		da1 = ABS(alpha-109.47);
60793 		da2 = ABS(alpha-120.0);
60794 		da3 = ABS(alpha-180.0);
60795 
60796 /*
60797 fprintf(stderr,"%d da1 %f da2 %f da3 %f l %d alpha %f\n",j1,da1,da2,da3,l,alpha);
60798 */
60799 
60800 		if ((da1 < da2 && da1 < da3) || xc == 4) {
60801 		   sp[j] = 3;
60802 
60803 		   AddAtom(ic[0],ix,j1,1.090,109.47,180.0,xyzp->iresid[j]);
60804 		   AddAtom(ic[0],ix,j1,1.090,109.47,60.0,xyzp->iresid[j]);
60805 		   AddAtom(ic[0],ix,j1,1.090,109.47,-60.0,xyzp->iresid[j]);
60806 
60807 		} else if (da2 < da1 && da2 < da3) {
60808 
60809 		   sp[j] = 2;
60810 
60811 /* defer adding hydrogens until second round */
60812 
60813 		} else {
60814 
60815 		   sp[j] = 1;
60816 
60817 		   AddAtom(ic[0],ix,j1,1.090,179.9,0.0,xyzp->iresid[j]);
60818 
60819 		}
60820 	    }
60821 
60822         }
60823 
60824 	if (nc == 2) {
60825 
60826 /* calc angle */
60827 
60828 	   asel[0] = ic[0];
60829 	   asel[1] = j1;
60830 	   asel[2] = ic[1];
60831 	   anum = 3;
60832 
60833 #if defined(VMS) || defined(UNDERSC)
60834 	   tomold(&aret,asel,&anum);
60835 #else
60836 #ifdef CRAY
60837 	   TOMOLD(&aret,asel,&anum);
60838 #else
60839 	   tomold_(&aret,asel,&anum);
60840 #endif
60841 #endif
60842 	   da1 = ABS(aret-109.47);
60843 	   da2 = ABS(aret-120.0);
60844 	   da3 = ABS(aret-180.0);
60845 /*
60846  C, 2 connections:
60847 
60848  ang = 109.47 Sp3 => add 2 Hyd.
60849  ang = 120.0  Sp2 => add 1 Hyd.
60850  ang = 180.0  Sp  => add 0 Hyd.
60851 */
60852 
60853 	   if (da1 < da2 && da1 < da3) {
60854 		sp[j] = 3;
60855 
60856 		AddAtom(ic[0],ic[1],j1,1.090,109.47,120.0,xyzp->iresid[j]);
60857 		AddAtom(ic[0],ic[1],j1,1.090,109.47,-120.0,xyzp->iresid[j]);
60858 
60859 	   } else if (da2 < da1 && da2 < da3) {
60860 
60861 		sp[j] = 2;
60862 
60863 /* defer adding hydrogens to second round */
60864 
60865 	   } else {
60866 		sp[j] = 1;
60867 	   }
60868 	}
60869 
60870 	if (nc == 3) {
60871 
60872 /* calc dihedral */
60873 
60874 	   asel[0] = ic[0];
60875 	   asel[1] = j+1;
60876 	   asel[2] = ic[1];
60877 	   asel[3] = ic[2];
60878 	   anum = 4;
60879 
60880 #if defined(VMS) || defined(UNDERSC)
60881 	   tomold(&aret,asel,&anum);
60882 #else
60883 #ifdef CRAY
60884 	   TOMOLD(&aret,asel,&anum);
60885 #else
60886 	   tomold_(&aret,asel,&anum);
60887 #endif
60888 #endif
60889 
60890 /*
60891 
60892  C, 3 connections:
60893 
60894  dih = 120.0  Sp3 => add 1 Hyd.
60895  dih = 180.0  Sp2 => add 0 Hyd.
60896 */
60897 
60898 	   is = SIGN(aret);
60899 	   aret = ABS(aret);
60900 	   da1 = ABS(180.0 - aret);
60901 	   da2 = ABS(120.0 - aret);
60902 	   if (da1 < da2) {
60903 		sp[j] = 2;
60904 	   } else {
60905 		sp[j] = 3;
60906 
60907 		AddAtom(ic[0],ic[1],j1,1.090,109.47,is*120.0,xyzp->iresid[j]);
60908 	   }
60909 	}
60910      }
60911   }
60912 
60913 /*
60914    Second round
60915 */
60916 
60917   for (j=0; j < *xyzp->iatoms; j++) {
60918      j1 = j + 1;
60919 
60920      if (xyzp->ianz[j] == 8 && sp[j] == 2) {
60921 	for (k=0; k < 3; k++) ic[k] = -1;
60922 
60923 	nc = icn[j*(MXCON+1)];
60924 
60925 	if (nc == 1) {
60926 	   for (k=0; k < nc; k++)
60927 		ic[k] = icn[j*(MXCON+1)+k+1];
60928 
60929 	   ix = ic[0];
60930 	   xc = icn[(ix-1)*(MXCON+1)];
60931 
60932 	   nsp2 = 0; if (sp[ix-1] == 2) nsp2 = 1;
60933 	   if (xc > 0 && xc <= 4) {
60934 		l = 0;
60935 		for (k=0; k < xc; k++) {
60936 		   iy = icn[(ix-1)*(MXCON+1)+k+1];
60937 		   if (iy != j1) {
60938 			if (sp[iy-1] == 2) nsp2++;
60939 			ic[l] = iy;
60940 			l++;
60941 		   }
60942 		}
60943 		if (l == 2 && nsp2 == 3) {
60944 		   sp[j] = 3;
60945 
60946 		   AddAtom(ic[0],ix,j1,1.090,109.47,180.0,xyzp->iresid[j]);
60947 		}
60948 	    }
60949 	}
60950      }
60951 
60952      if (xyzp->ianz[j] == 6 && sp[j] == 2) {
60953 	ix = -1;
60954 	iy = -1;
60955 	for (k=0; k < 3; k++) ic[k] = -1;
60956 
60957 	nc = icn[j*(MXCON+1)];
60958 	if (nc <= 3) {
60959 	   for (k=0; k < nc; k++)
60960 		ic[k] = icn[j*(MXCON+1)+k+1];
60961 
60962 	}
60963 
60964 	if (nc == 1) {
60965 
60966 	    ix = ic[0];
60967 	    xc = icn[(ix-1)*(MXCON+1)];
60968 
60969 	    if (xc > 0 && xc <= 4) {
60970 		l = 0;
60971 		nsp2 = sp[ix-1];
60972 		for (k=0; k < xc; k++) {
60973 		   iy = icn[(ix-1)*(MXCON+1)+k+1];
60974 		   if (iy != j1) {
60975 			if (sp[iy-1] == 2) nsp2++;
60976 			ic[l] = iy;
60977 			l++;
60978 		   }
60979 		}
60980 		alpha = 0.0;
60981 		for (k=0; k < l; k++) {
60982 		   asel[0] = j1;
60983 		   asel[1] = ix;
60984 		   asel[2] = ic[k];
60985 		   anum = 3;
60986 
60987 #if defined(VMS) || defined(UNDERSC)
60988 		   tomold(&aret,asel,&anum);
60989 #else
60990 #ifdef CRAY
60991 		   TOMOLD(&aret,asel,&anum);
60992 #else
60993 		   tomold_(&aret,asel,&anum);
60994 #endif
60995 #endif
60996 		   alpha = alpha + aret;
60997 		}
60998 
60999 		alpha = alpha / (double) l;
61000 
61001 		da1 = ABS(alpha-109.47);
61002 		da2 = ABS(alpha-120.0);
61003 		da3 = ABS(alpha-180.0);
61004 
61005 		if (da2 < da1 && da2 < da3) {
61006 
61007 		   if (nsp2 >= 2) {
61008 
61009 			sp[j] = 3;
61010 
61011 		        AddAtom(ic[0],ix,j1,1.090,109.47,180.0,
61012 				xyzp->iresid[j]);
61013 		        AddAtom(ic[0],ix,j1,1.090,109.47,60.0,
61014 				xyzp->iresid[j]);
61015 		        AddAtom(ic[0],ix,j1,1.090,109.47,-60.0,
61016 				xyzp->iresid[j]);
61017 
61018 		   } else {
61019 
61020 			sp[j] = 2;
61021 
61022 		        AddAtom(ic[0],ix,j1,1.090,120.0,0.0,
61023 				xyzp->iresid[j]);
61024 		        AddAtom(ic[0],ix,j1,1.090,120.0,180.0,
61025 				xyzp->iresid[j]);
61026 
61027 		   }
61028 
61029 		}
61030 
61031 	    }
61032 
61033         }
61034 
61035 	if (nc == 2) {
61036 
61037 /* calc angle */
61038 
61039 	   asel[0] = ic[0];
61040 	   asel[1] = j1;
61041 	   asel[2] = ic[1];
61042 	   anum = 3;
61043 
61044 #if defined(VMS) || defined(UNDERSC)
61045 	   tomold(&aret,asel,&anum);
61046 #else
61047 #ifdef CRAY
61048 	   TOMOLD(&aret,asel,&anum);
61049 #else
61050 	   tomold_(&aret,asel,&anum);
61051 #endif
61052 #endif
61053 	   da1 = ABS(aret-109.47);
61054 	   da2 = ABS(aret-120.0);
61055 	   da3 = ABS(aret-180.0);
61056 /*
61057  C, 2 connections:
61058 
61059  ang = 109.47 Sp3 => add 2 Hyd.
61060  ang = 120.0  Sp2 => add 1 Hyd.
61061  ang = 180.0  Sp  => add 0 Hyd.
61062 */
61063 
61064 	   if (da2 < da1 && da2 < da3) {
61065 
61066 	    ic0 = 1; ic1 = 1;
61067 	    ix = ic[0];
61068 	    iy = ic[1];
61069 
61070 	    xc = icn[(ix-1)*(MXCON+1)];
61071 
61072 	    if (xc > 0 && xc <= 3) {
61073 		l = 0;
61074 		nsp2 = sp[ix-1];
61075 		for (k=0; k < xc; k++) {
61076 		   iz = icn[(ix-1)*(MXCON+1)+k+1];
61077 		   if (iz != j1) {
61078 			if (sp[iz-1] == 2) nsp2++;
61079 			ic[l] = iz;
61080 			l++;
61081 		   }
61082 		}
61083 
61084 		for (k=0; k < l; k++) {
61085 
61086 		   asel[0] = ic[k];
61087 		   asel[1] = ix;
61088 		   asel[2] = j1;
61089 		   asel[3] = iy;
61090 		   anum = 4;
61091 
61092 #if defined(VMS) || defined(UNDERSC)
61093 		   tomold(&aret,asel,&anum);
61094 #else
61095 #ifdef CRAY
61096 		   TOMOLD(&aret,asel,&anum);
61097 #else
61098 		   tomold_(&aret,asel,&anum);
61099 #endif
61100 #endif
61101 		   da1 = ABS(aret-180.0);
61102 		   da2 = ABS(aret-0.0);
61103 		   if (da2 < da1) da1 = da2;
61104 		   if (da1 > 10.0) ic0 = 0;
61105 		}
61106 
61107 	    } else {
61108 		ic0 = 0;
61109 	    }
61110 
61111 	    xc = icn[(iy-1)*(MXCON+1)];
61112 
61113 	    if (xc > 0 && xc <= 3) {
61114 		l = 0;
61115 		nsp2 = sp[iy-1];
61116 		for (k=0; k < xc; k++) {
61117 		   iz = icn[(iy-1)*(MXCON+1)+k+1];
61118 		   if (iz != j1) {
61119 			if (sp[iz-1] == 2) nsp2++;
61120 			ic[l] = iz;
61121 			l++;
61122 		   }
61123 		}
61124 
61125 		for (k=0; k < l; k++) {
61126 
61127 		   asel[0] = ic[k];
61128 		   asel[1] = iy;
61129 		   asel[2] = j1;
61130 		   asel[3] = ix;
61131 		   anum = 4;
61132 
61133 #if defined(VMS) || defined(UNDERSC)
61134 		   tomold(&aret,asel,&anum);
61135 #else
61136 #ifdef CRAY
61137 		   TOMOLD(&aret,asel,&anum);
61138 #else
61139 		   tomold_(&aret,asel,&anum);
61140 #endif
61141 #endif
61142 		   da1 = ABS(aret-180.0);
61143 		   da2 = ABS(aret-0.0);
61144 		   if (da2 < da1) da1 = da2;
61145 		   if (da1 > 10.0) ic1 = 0;
61146 		}
61147 
61148 	    } else {
61149 		ic1 = 0;
61150 	    }
61151 
61152 	    if (ic0 || ic1) {
61153 
61154 		sp[j] = 2;
61155 
61156 		AddAtom(ix,iy,j1,1.090,120.0,180.0,xyzp->iresid[j]);
61157 
61158 	    } else {
61159 
61160 		sp[j] = 3;
61161 
61162 		AddAtom(ix,iy,j1,1.090,109.47,120.0,xyzp->iresid[j]);
61163 		AddAtom(ix,iy,j1,1.090,109.47,-120.0,xyzp->iresid[j]);
61164 
61165 	    }
61166 
61167 	   }
61168 	}
61169 
61170      }
61171   }
61172 
61173 /*
61174    Third round
61175 */
61176 
61177   for (j=0; j < *xyzp->iatoms; j++) {
61178      j1 = j + 1;
61179 
61180      if (xyzp->ianz[j] == 7) {
61181 
61182 	ix = -1;
61183 	iy = -1;
61184 	for (k=0; k < 3; k++) ic[k] = -1;
61185 
61186 	nc = icn[j*(MXCON+1)];
61187 	if (nc <= 3) {
61188 	   for (k=0; k < nc; k++)
61189 		ic[k] = icn[j*(MXCON+1)+k+1];
61190 
61191 	}
61192 
61193 	if (nc == 1) {
61194 
61195 	    ix = ic[0];
61196 	    xc = icn[(ix-1)*(MXCON+1)];
61197 
61198 	    if (xc > 0 && xc <= 4) {
61199 		l = 0;
61200 		for (k=0; k < xc; k++) {
61201 		   iy = icn[(ix-1)*(MXCON+1)+k+1];
61202 		   if (iy != j1) {
61203 			ic[l] = iy;
61204 			l++;
61205 		   }
61206 		}
61207 		alpha = 0.0;
61208 		for (k=0; k < l; k++) {
61209 		   asel[0] = j1;
61210 		   asel[1] = ix;
61211 		   asel[2] = ic[k];
61212 		   anum = 3;
61213 
61214 #if defined(VMS) || defined(UNDERSC)
61215 		   tomold(&aret,asel,&anum);
61216 #else
61217 #ifdef CRAY
61218 		   TOMOLD(&aret,asel,&anum);
61219 #else
61220 		   tomold_(&aret,asel,&anum);
61221 #endif
61222 #endif
61223 		   alpha = alpha + aret;
61224 		}
61225 
61226 		alpha = alpha / (double) l;
61227 
61228 		da1 = ABS(alpha-109.47);
61229 		da2 = ABS(alpha-120.0);
61230 		da3 = ABS(alpha-180.0);
61231 
61232 		if ((da1 < da2 && da1 < da3) || xc == 4) {
61233 		   sp[j] = 3;
61234 
61235 		   AddAtom(ic[0],ix,j1,1.090,109.47,180.0,xyzp->iresid[j]);
61236 		   AddAtom(ic[0],ix,j1,1.090,109.47,60.0,xyzp->iresid[j]);
61237 
61238 		} else if (da2 < da1 && da2 < da3) {
61239 
61240 		   sp[j] = 2;
61241 
61242 		   AddAtom(ic[0],ix,j1,1.090,120.0,180.0,xyzp->iresid[j]);
61243 
61244 
61245 		} else {
61246 
61247 		   sp[j] = 1;
61248 
61249 
61250 		}
61251 	    }
61252 
61253         }
61254 
61255 	if (nc == 2) {
61256 
61257 /* calc angle */
61258 
61259 	   asel[0] = ic[0];
61260 	   asel[1] = j1;
61261 	   asel[2] = ic[1];
61262 	   anum = 3;
61263 
61264 #if defined(VMS) || defined(UNDERSC)
61265 	   tomold(&aret,asel,&anum);
61266 #else
61267 #ifdef CRAY
61268 	   TOMOLD(&aret,asel,&anum);
61269 #else
61270 	   tomold_(&aret,asel,&anum);
61271 #endif
61272 #endif
61273 	   da1 = ABS(aret-109.47);
61274 	   da2 = ABS(aret-120.0);
61275 	   da3 = ABS(aret-180.0);
61276 /*
61277  N, 2 connections:
61278 
61279  ang = 109.47 Sp3 => add 1 Hyd.
61280  ang = 120.0  Sp2 => add 0 Hyd.
61281  ang = 180.0  Sp  => add 0 Hyd.
61282 */
61283 
61284 	   if (da1 < da2 && da1 < da3) {
61285 		sp[j] = 3;
61286 
61287 		AddAtom(ic[0],ic[1],j1,1.090,109.47,120.0,xyzp->iresid[j]);
61288 
61289 	   } else if (da2 < da1 && da2 < da3) {
61290 
61291 		sp[j] = 2;
61292 
61293 
61294 	   } else {
61295 		sp[j] = 1;
61296 	   }
61297 	}
61298      }
61299   }
61300 
61301   *zmptrp->ihaszm = 0;
61302   ZMEAA = 0;
61303   free(sp);
61304   free(icn);
61305 }
61306 
61307 #if defined(VMS) || defined(UNDERSC)
chkmpi()61308 void chkmpi()
61309 #else
61310 #ifdef CRAY
61311 void CHKMPI()
61312 #else
61313 void chkmpi_()
61314 #endif
61315 #endif
61316 {
61317  FILE *pip;
61318  char line[256];
61319  char *p;
61320  char *pth;
61321  int ns = 10000;
61322  int ts;
61323 
61324 #ifndef __CYGWIN__
61325  if ((pip = popen("/usr/bin/locate mpirun 2>&1","r")) ) {
61326 	while ( fgets(line,sizeof line, pip) ) {
61327 	   ts = strlen(line);
61328 	   if ((p = strrchr(line, '/'))) {
61329 		p++;
61330 		if (strlen(p) == 7 && ts < ns ) {
61331 		   if (strlen(line) < MAXCMD) {
61332 			strcpy(mpicmd,line);
61333 			if ((p = strrchr(mpicmd,'\n'))) *p = '\0';
61334 			ns = ts;
61335 		   }
61336 		}
61337 	   }
61338 	}
61339 	pclose(pip);
61340 	strcpy(line," ");
61341 	if (getexe(0,1,line)) {
61342 	    hasmpi = 1;
61343 	    strcpy(mpilib,mpicmd);
61344 	    if ((p = strrchr(mpilib, '/'))) {
61345 		p--;p--;p--;
61346 		*p= '\0';
61347 		strcat(mpilib,"lib");
61348 		pth = getenv("LD_LIBRARY_PATH");
61349 		if (pth != NULL) {
61350 		   strcpy(npth,pth);
61351 		   strcat(npth,":");
61352 		   strcat(npth,mpilib);
61353 		}
61354 
61355 	    }
61356 
61357 	    if ((pip = popen("grep -c processor /proc/cpuinfo","r")) ) {
61358 		while ( fgets(line,sizeof line, pip) ) {
61359 		    maxproc = atoi(line);
61360 		    useproc = maxproc;
61361 		}
61362 		pclose(pip);
61363 	    }
61364 	}
61365  }
61366 #endif
61367 
61368  if (hasmpi) {
61369 	ntnkb++;
61370 	ntnkb++;
61371  }
61372 
61373 }
61374 
UpdHet2(nlin)61375 void UpdHet2(nlin)
61376 int nlin;
61377 {
61378    int i,j,ir;
61379 
61380    for (i=0; i < hetlab.NHetLab; i++ )
61381 	hetlab.iat[i] = hetlab.iat[i] + nlin;
61382 
61383 }
61384 
UpdHet()61385 void UpdHet()
61386 {
61387    int i,j,ir;
61388    HETLABSTRU thetlab;
61389 
61390    thetlab.NHetLab = 0;
61391    for (j=0; j<*zmptrp->nz; j++) {
61392 	for (i=0; i < hetlab.NHetLab; i++ ) {
61393 	   if (hetlab.iat[i] == zmptrp->imap[j]) {
61394 		thetlab.iat[thetlab.NHetLab] = j+1;
61395 		thetlab.HetLab[thetlab.NHetLab] = hetlab.HetLab[i];
61396 		thetlab.NHetLab++;
61397 	   }
61398 	}
61399    }
61400    hetlab = thetlab;
61401 
61402 }
61403 
61404 #if defined(VMS) || defined(UNDERSC)
gethet(int * iat,int * status,char * str)61405 void gethet(int *iat,int *status,char *str)
61406 #else
61407 #ifdef CRAY
61408 void GETHET(int *iat,int *status,char *str)
61409 #else
61410 void gethet_(int *iat,int *status,char *str)
61411 #endif
61412 #endif
61413 {
61414    int i,n;
61415 
61416    *status = 0;
61417    if (clfstrptr->ihashz) {
61418 	for (i=0; i < hetlab.NHetLab; i++ ) {
61419 	   if (hetlab.iat[i] == *iat) {
61420 		n = strlen(hetlab.HetLab[i]);
61421 		strncpy(str,hetlab.HetLab[i],n);
61422 		*status = 1;
61423 	   }
61424 	}
61425    }
61426 
61427 }
61428 
DoWGET(wwwstr,argm,retstr)61429 int DoWGET(wwwstr,argm,retstr)
61430 char *wwwstr;
61431 char *argm;
61432 char *retstr;
61433 {
61434    char cmdfil[500];
61435    char cmdtmp[500];
61436    char fn1[] = "/tmp/fileXXXXXX";
61437    char fn2[] = "/tmp/fileXXXXXX";
61438    char *wget = "wget";
61439    char errstr[500] = "";
61440    int i,istat,igoogle,istat1,pid;
61441    char *p;
61442    FILE *out;
61443 
61444 #if defined(VMS) || defined(UNDERSC)
61445    curs(&ONE);
61446 #else
61447 #ifdef CRAY
61448    CURS(&ONE);
61449 #else
61450    curs_(&ONE);
61451 #endif
61452 #endif
61453 
61454    istat = 1;
61455    igoogle = 1;
61456 
61457 #ifdef __CYGWIN__
61458    getusr(retstr);
61459    sprintf(cmdtmp,"%s%s.exe",exepath[0],wget);
61460    spaesc(cmdtmp);
61461 #else
61462 #ifdef DARWIN
61463    sprintf(cmdtmp,"%s%s",exepath[0],wget);
61464    if (!(access(cmdtmp,F_OK) == 0 && !isdir(cmdtmp))) {
61465       strcpy(cmdtmp,wget);
61466    }
61467 #else
61468    strcpy(cmdtmp,wget);
61469 #endif
61470    strcpy(retstr,mktemp(fn1));
61471    strcpy(errstr,mktemp(fn2));
61472 #endif
61473 
61474 
61475 #ifdef __CYGWIN__
61476 
61477    if ((access(cmdtmp,F_OK) == 0 && !isdir(cmdtmp))) {
61478 
61479 	if (p = strstr(cmdtmp,".exe")) p[0] = '\0';
61480 
61481 	 strcpy(cmdfil,wwwstr);
61482 	 strcat(cmdfil,argm);
61483 
61484 	 pid = vfork();
61485 	 switch(pid) {
61486 	 case -1:
61487           fprintf(stderr,"Couldnt Fork\n");
61488           break;
61489 	 case 0:       /*child */
61490 	  execlp(cmdtmp,"wget",cmdfil,"-O",retstr,NULL);
61491 	  _exit(0);
61492           break;
61493 	 default:      /*parent*/
61494 	  wait(&pid);
61495           break;
61496 	}
61497 	istat = 0;
61498    } else {
61499 	fprintf(stderr,"%s not found\n",cmdtmp);
61500    }
61501 #else
61502    strcat(cmdtmp," \"");
61503    strcat(cmdtmp,wwwstr);
61504    if (strstr(cmdtmp,"google") == NULL) igoogle = 0;
61505    if (argm != NULL) {
61506 	strcat(cmdtmp,argm);
61507    }
61508    if (strstr(wwwstr,"cml")) {
61509 	strcat(cmdtmp,".cml");
61510    } else if (strstr(wwwstr,"coordinates")) {
61511 	strcat(cmdtmp,".ccp4");
61512 	igoogle = 1;
61513    } else {
61514 	if (!igoogle) strcat(cmdtmp,".ent.gz");
61515    }
61516    strcat(cmdtmp,"\" -O ");
61517    strcat(cmdtmp,retstr);
61518    if (!igoogle) strcat(cmdtmp,".gz");
61519    strcat(cmdtmp," 2> ");
61520    strcat(cmdtmp,errstr);
61521 
61522    fprintf(stderr,"Dowget: %s\n",cmdtmp);
61523 
61524    istat = system(cmdtmp);
61525 
61526    istat = 1;
61527    out = fopen(errstr,"r");
61528    if (out != NULL) {
61529 	while (fgets(cmdtmp,MAXCMD,out) != NULL) {
61530 	   if (strstr(cmdtmp,"connected") != NULL) {
61531 		istat = 0;
61532 	   }
61533 	}
61534 	fclose(out);
61535    }
61536 
61537    if (!igoogle) {
61538       strcpy(cmdtmp,"gunzip ");
61539       strcat(cmdtmp,retstr);
61540       strcat(cmdtmp,".gz");
61541 
61542       istat1 = system(cmdtmp);
61543    }
61544 
61545 #endif
61546 
61547 #if defined(VMS) || defined(UNDERSC)
61548    curs(&ZERO);
61549 #else
61550 #ifdef CRAY
61551    CURS(&ZERO);
61552 #else
61553    curs_(&ZERO);
61554 #endif
61555 #endif
61556    return(istat);
61557 
61558 }
61559 
CheckWGET()61560 int CheckWGET()
61561 {
61562    char *wwwstr = "http://www.google.com/index.html";
61563    char retstr[500] = "";
61564    int status;
61565 
61566    if (!hasWGET) {
61567         status = DoWGET(wwwstr,"",retstr);
61568 	if (!status) {
61569 	    hasWGET = 1;
61570 	} else {
61571 	    fprintf(stderr,"\nWARNING:\nThe standard HETATM hydrogen adding routine,\ndepends on the program \"wget\".\nYou can download wget from : http://ftp.gnu.org/gnu/wget/\n");
61572 
61573 	}
61574    } else {
61575 	status = 0;
61576    }
61577 
61578    return(status);
61579 
61580 }
61581 
GetPDBWWW(het,retstr)61582 void GetPDBWWW(het,retstr)
61583 char *het;
61584 char *retstr;
61585 {
61586 //   char *wwwstr = "http://www.rcsb.org/pdb/downloadFile.do?fileFormat=pdb&compression=NO&structureId=";
61587    char *wwwstr = "ftp://ftp.wwpdb.org/pub/pdb/data/structures/all/pdb/pdb";
61588 
61589    DoWGET(wwwstr,het,retstr);
61590 }
61591 
PDBquery(het)61592 int PDBquery(het)
61593 char *het;
61594 {
61595    char *strid, *tmpid;
61596    FILE *pout;
61597    char line[MAXCMD];
61598    int i,ret=0;
61599 
61600    char *wwwstr = "http://www.rcsb.org/pdb/search/navbarsearch.do?inputQuickSearch=";
61601 
61602    if (npdbres > 0) {
61603 	for (i=0; i < npdbres; i++)
61604 		free(pdbres[i]);
61605    }
61606 
61607    DoWGET(wwwstr,het,resfil);
61608 
61609    npdbres = 0;
61610 
61611    pout = fopen(resfil,"r");
61612    if (pout != NULL) {
61613 	while (fgets(line,MAXCMD,pout) != NULL) {
61614 	   strid = strstr(line,"downloadFile");
61615 	   if (strid != NULL) {
61616 		strid = strstr(line,"structureId=");
61617 	   	if (strid != NULL) {
61618 		   tmpid = (char *) malloc(sizeof(char)*(4+1));
61619 		   strncpy(tmpid,strid+12,4);
61620 		   tmpid[4] = '\0';
61621 		   pdbres[npdbres] = tmpid;
61622 		   if (npdbres < MAXRES) {
61623 			npdbres++;
61624 		   } else {
61625 			break;
61626 		   }
61627 		}
61628 	   }
61629 	}
61630 	fclose(pout);
61631 	ret = 1;
61632    }
61633 
61634 /*
61635    for (i=0; i < npdbres; i++)
61636 	fprintf(stderr,"PDBID: %s\n",pdbres[i]);
61637 */
61638 
61639    RedrawSRCH();
61640    return(ret);
61641 }
61642 
PDBentry(het)61643 int PDBentry(het)
61644 char *het;
61645 {
61646    char *strid, *tmpid;
61647    FILE *pout;
61648    char line[MAXCMD];
61649    int i,fnd=0,ret=0;
61650 
61651    strcpy(strname,"structureId=");
61652    strcat(strname,het);
61653 
61654    pout = fopen(resfil,"r");
61655    if (pout != NULL) {
61656 	while (fgets(line,MAXCMD,pout) != NULL) {
61657 	   strid = strstr(line,"qrb_title");
61658 	   if (strid != NULL) {
61659 		strid = strstr(line,strname);
61660 	   	if (strid != NULL) {
61661 		   fgets(line,MAXCMD,pout);
61662 		   fgets(line,MAXCMD,pout);
61663 		   strid = strchr(line,'\n');
61664 		   if (strid != NULL) strid[0] = '\0';
61665 		   for (tmpid = line; *tmpid == '\t'; tmpid++);
61666 		   strcpy(qrb_title,tmpid);
61667 		   /*fprintf(stderr,"title: %s\n",qrb_title);*/
61668 		   fnd = 1;
61669 		}
61670 	   }
61671 	   if (fnd) {
61672 	        strid = strstr(line," Organism: ");
61673 	   	if (strid != NULL) {
61674 		   fgets(line,MAXCMD,pout);
61675 		   fgets(line,MAXCMD,pout);
61676 		   fgets(line,MAXCMD,pout);
61677 		   fgets(line,MAXCMD,pout);
61678 		   fgets(line,MAXCMD,pout);
61679 		   tmpid = strchr(line,'>');
61680 		   if (tmpid != NULL) {
61681 			tmpid++;
61682 			strid = strchr(tmpid,'<');
61683 			if (strid != NULL) {
61684 			   i = (int) (strid - tmpid);
61685 		   	   strncpy(organism,tmpid,i);
61686 			   organism[i] = '\0';
61687 			   /*fprintf(stderr,"org: %s\n",organism);*/
61688 			   break;
61689 			}
61690 		   }
61691 		}
61692 	   }
61693 	}
61694 	fclose(pout);
61695 	ret = 1;
61696    }
61697    RedrawSRCH();
61698    return(ret);
61699 }
61700 
GetOMAPWWW(het,retstr)61701 int GetOMAPWWW(het,retstr)
61702 char *het;
61703 char *retstr;
61704 {
61705    struct stat filestat;
61706    char *wwwstr = "http://eds.bmc.uu.se/cgi-bin/eds/gen_zip.pl?pdbCode=";
61707    char wwwstr2[MAXSTRLEN];
61708    int pid,ist;
61709 
61710    unsetenv("TMP");
61711    unsetenv("TEMP");
61712    unsetenv("TMPDIR");
61713 
61714    sprintf(wwwstr2,"http://www.ebi.ac.uk/pdbe/coordinates/files/%s",het);
61715 
61716    DoWGET(wwwstr2,"",retstr);
61717 
61718 #ifdef __CYGWIN__
61719 	    sprintf(stemp,"%s/%s.omap",het,het);
61720 	    pid = vfork();
61721 	    switch(pid) {
61722 	    case -1:
61723 	 	fprintf(stderr,"Couldnt Fork\n");
61724 		break;
61725 	    case 0:	/*child */
61726 		execlp("tar","tar","-zxvf",retstr,stemp,
61727 			"--strip-components","1",NULL);
61728 		_exit(0);
61729 		break;
61730 	    default:	/*parent*/
61731 		wait(&pid);
61732 		break;
61733 	    }
61734 #else
61735    stat(retstr,&filestat);
61736 
61737    if (filestat.st_size) {
61738 
61739 #endif
61740 	    sprintf(wwwstr2,"./%s.ccp4",het);
61741 	    ist = OSCopyFile(retstr,wwwstr2);
61742 	    *Sinct = 585; *Snstr = 11;
61743 	    cpstr(wwwstr2,Sstr,strlen(wwwstr2));
61744 	    return(1);
61745 
61746 #ifndef __CYGWIN__
61747    } else {
61748 	DoCan(event.xbutton.x_root, event.xbutton.y_root,
61749 	"No CCP4 file available.\nCheck at http://www.ebi.ac.uk/pdbe/coordinates/files/",0);
61750    }
61751 #else
61752    }
61753 #endif
61754    return(0);
61755 }
61756 
LigandQ(ihet)61757 void LigandQ(ihet)
61758 int ihet;
61759 {
61760    FILE *out;
61761    char cmdtmp[500] = "";
61762    char cmdfil[500];
61763    char *spntr;
61764    char *het;
61765    int i,j,istat,aihet,ifnd;
61766    int fnd,iend,itch=-15;
61767 
61768    char *wwwtotq = "ftp://ftp.ebi.ac.uk/pub/databases/msd/pdbechem/files/cml/";
61769 
61770    aihet = abs(ihet);
61771 
61772    if (aihet >= MXHETA) {
61773 	fprintf(stderr,"\nLigandQ: hetatm residue outside array bounds\n\n");
61774 	return;
61775    }
61776 
61777    fnd = 0;
61778    iend = -1;
61779 
61780    for (j=0; j < *xyzp->iatoms; j++) {
61781 	if (xyzp->iresid[j] == ihet) {
61782 	   if (!fnd) {
61783 	      fnd = 1;
61784 	   }
61785 	   iend = j;
61786 	}
61787    }
61788 
61789    if (iend == -1 ) return;
61790 
61791    het = (char *) malloc(80);
61792 
61793 
61794    strcpy(het,hetptr.HetAtm[aihet]);
61795 
61796    het[3] = '\0';
61797 
61798    fprintf(stderr,"\nRetrieving Ligand Charge from PDBeChem\n\n");
61799 
61800    istat = DoWGET(wwwtotq,het,cmdtmp);
61801 
61802    ifnd = 0;
61803 
61804    out = fopen(cmdtmp,"r");
61805 
61806    if (out != NULL) {
61807 	while (fgets(cmdfil,MAXCMD,out) != NULL) {
61808 	   if (strstr(cmdfil,"formalCharge") != NULL) {
61809 		spntr = strstr(cmdfil,"formalCharge=\"");
61810 		if (spntr) {
61811 		    spntr = spntr + 14;
61812 		    sscanf(spntr,"%d",&itch);
61813 		}
61814 		ifnd = 1;
61815 		break;
61816 	   }
61817 	}
61818 	fclose(out);
61819 	if (ifnd) {
61820 	   fprintf(stderr,"formalCharge %d\n",itch);
61821 	   clfstrptr->ihetq[aihet] = itch;
61822 	   clfstrptr->ihqset[aihet] = 1;
61823 	} else {
61824 	   fprintf(stderr,"NO formalCharge found\n");
61825 	}
61826    }
61827 }
61828 /* Ligand2Amino NOT used */
61829 
Ligand2Amino(ihet)61830 int Ligand2Amino(ihet)
61831 int ihet;
61832 {
61833    int i,j,k,nc,iac;
61834 
61835    iac = 0;
61836    for (j=0; j < *xyzp->iatoms; j++) {
61837 
61838 	if (xyzp->iresid[j] == ihet) {
61839 
61840 	  nc = xyzp->iconn[j*(MXCON+1)];
61841 
61842 	  for (k=0; k < nc; k++) {
61843 		i = xyzp->iconn[j*(MXCON+1)+k+1];
61844 
61845 		if (i > 0) if (xyzp->iresid[i] != ihet) iac++;
61846 	  }
61847 	}
61848     }
61849     return(iac);
61850 }
61851 
CheckHydro(ihet)61852 int CheckHydro(ihet)
61853 int ihet;
61854 {
61855    int i,j,inoth,ih,aihet;
61856 
61857    inoth = 0; ih = 0;
61858 
61859    for (j=0; j < *xyzp->iatoms; j++) {
61860 	if (xyzp->iresid[j] == ihet) {
61861 	    if (xyzp->ianz[j] == 1) ih++;
61862 	    else inoth++;
61863 	}
61864    }
61865 
61866    aihet = abs(ihet);
61867    if (((float) ih/(float) inoth) > 0.2) clfstrptr->ihhadd[aihet] = 1;
61868 
61869    return(ih);
61870 }
61871 
61872 /*
61873 - HEM:
61874   CAC 1*H (HAC) is added
61875   CAB 1*H (HAB) is added
61876   O2A 1*H (H2A) we choose NOT to add it
61877   O2B 1*H (H2B) we choose NOT to add it
61878 
61879   Discription HEM should include 2H's for CAB,CAC. It does not, This means
61880   the connections with amino acids are taken into account.
61881 
61882   discription HEM includes Fe (probably Fe2+, offsets 2*COO- charges:
61883   total Neutral, which is the initial formal charge given. But
61884   actually it should be 2+, because the description uses 2*COOH).
61885 
61886   Message 1: do NOT subtract because of connections with amino acids.
61887   Message 2: exclude FE from partial charge calculation, and set q(FE)=+2
61888 */
61889 
isPO4(iat)61890 int isPO4(iat)
61891 int iat;
61892 {
61893     int xc,io,icns,k,l,la;
61894 
61895     if (xyzp->ianz[iat] != 15) return 0;
61896     xc = xyzp->iconn[iat*(MXCON+1)];
61897 
61898     io = 0;
61899     icns = 0;
61900 
61901     for (k=0; k < xc; k++) {
61902 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
61903 	la = abs(l);
61904 	if (la > 0) {
61905 	   if (xyzp->ianz[la-1] == 8) io++;
61906 	   if (xyzp->ianz[la-1] == 6 || xyzp->ianz[la-1] == 7 || xyzp->ianz[la-1] >= 16) icns++;
61907 	}
61908     }
61909 
61910     if (io == 4 || (io+icns == 4 && io >= 2) ) return 1;
61911     return 0;
61912 }
61913 
isCOO(iat)61914 int isCOO(iat)
61915 int iat;
61916 {
61917     int xc,io,ic,ih,k,l,la;
61918 
61919     xc = xyzp->iconn[iat*(MXCON+1)];
61920     if (xyzp->ianz[iat] != 6) return 0;
61921 
61922     io = 0;
61923     ic = 0;
61924     ih = 0;
61925 
61926     for (k=0; k < xc; k++) {
61927 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
61928 	la = abs(l);
61929 	if (la > 0) {
61930 	   if (xyzp->ianz[la-1] == 8) io++;
61931 	   if (xyzp->ianz[la-1] == 6) ic++;
61932 	   if (xyzp->ianz[la-1] == 1) ih++;
61933 	}
61934     }
61935 
61936     if (io == 2 && ic == 1 && ih == 0) return 1;
61937     return 0;
61938 }
61939 
isBH4(iat)61940 int isBH4(iat)
61941 int iat;
61942 {
61943     int xc,io,ic,is,k,l,la;
61944 
61945     xc = xyzp->iconn[iat*(MXCON+1)];
61946     if (xyzp->ianz[iat] != 5) return 0;
61947 
61948     io = 0;
61949     ic = 0;
61950     is = 0;
61951 
61952     for (k=0; k < xc; k++) {
61953 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
61954 	la = abs(l);
61955 	if (la > 0) {
61956 	   if (xyzp->ianz[la-1] == 8) io++;
61957 	   if (xyzp->ianz[la-1] == 6) ic++;
61958 	   if (xyzp->ianz[la-1] == 16) is++;
61959 	}
61960     }
61961 
61962     if (io + ic + is == 4) return 1;
61963     return 0;
61964 }
61965 
TertN(iat,con)61966 int TertN(iat,con)
61967 int iat;
61968 int *con;
61969 {
61970     int xc,i,io,ic,ich,ir,k,l,la,iout,iat1;
61971 
61972     ic = 0; ich = 0;
61973     xc = xyzp->iconn[iat*(MXCON+1)];
61974     ir = xyzp->iresid[iat];
61975     iat1 = iat + 1;
61976     iout = 0;
61977 
61978 #if defined(VMS) || defined(UNDERSC)
61979     getrng(&iat1,&iout,xyzp->ianz,xyzp->iconn);
61980 #else
61981 #ifdef CRAY
61982     GETRNG(&iat1,&iout,xyzp->ianz,xyzp->iconn);
61983 #else
61984     getrng_(&iat1,&iout,xyzp->ianz,xyzp->iconn);
61985 #endif
61986 #endif
61987 
61988     if (iout) return 0;
61989 
61990     for (k=0; k < xc; k++) {
61991 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
61992 	la = abs(l);
61993 	if (la > 0) {
61994 	   if (xyzp->ianz[la-1] == 6) {
61995 		if (ic < 3) con[ic] = la;
61996 		ic++;
61997 	   }
61998 	   if (xyzp->ianz[la-1] == 1) ich++;
61999 	}
62000     }
62001     if (ic == 3 && ! (ich == 1)) return 1;
62002     return 0;
62003 }
62004 
isit_metal(ian)62005 int isit_metal(ian)
62006 int ian;
62007 {
62008   int k;
62009 
62010   for (k=0; k < MEXCL; k++) {
62011 	if (ian == mets->ianexc[k]) return 1;
62012   }
62013 
62014   return 0;
62015 }
62016 
LigandHydroPBE(ihet)62017 void LigandHydroPBE(ihet)
62018 int ihet;
62019 {
62020    FILE *out;
62021    char cmdtmp[500];
62022    char cmdfil[500];
62023    char chemid[10];
62024    char chemidOld[10] = "-1";
62025    char *spntr;
62026    char *het;
62027    char *htmp;
62028    double angles3[3] = {180.0,60.0,-60.0};
62029    double angles3a[2] = {120.0,-120.0};
62030    double angles2[3] = {0.0,180.0};
62031    double v[3];
62032    int ic[MXCON];
62033    int ice[MXCON];
62034    int mce[MXCON];
62035    int con[3];
62036    int i,j,k,l,l0,j1,k0,la,lanz,n,np,is,xc,ix,iy,idum,size,npdbe,hasH,aihet;
62037    int *sp, *nh, *ian, *ifl, *noth;
62038    int imode,log,nc,nce,nmce,fnd,iend,natoms,istat,itch=0,iac,notu,nht,ir,lr;
62039    float aret;
62040    int asel[6],anum;
62041    char **hetz;
62042    char *strp;
62043    char *wwwstr = "ftp://ftp.ebi.ac.uk/pub/databases/msd/pdbechem/files/cml/";
62044    aihet = abs(ihet);
62045 
62046    if (aihet >= MXHETA) {
62047 	fprintf(stderr,"\nLigandHydroPBE: hetatm residue outside array bounds\n\n");
62048 	return;
62049    }
62050 
62051    fnd = 0;
62052    iend = -1;
62053    imode = 1;
62054 
62055    for (j=0; j < *xyzp->iatoms; j++) {
62056 	if (xyzp->iresid[j] == ihet) {
62057 	   if (!fnd) {
62058 	      fnd = 1;
62059 	   }
62060 	   iend = j;
62061 	}
62062    }
62063 
62064    if (iend == -1 ) return;
62065 
62066    size = MXHETLAB;
62067 
62068    sp   = (int *) malloc((sizeof i)*size);
62069    nh   = (int *) malloc((sizeof i)*size);
62070    noth = (int *) malloc((sizeof i)*size);
62071    ifl  = (int *) malloc((sizeof i)*size);
62072    hetz = (char **) malloc((sizeof *hetz)*size);
62073 
62074    for (i=0; i < size; i++) {
62075 	nh[i] = 0; noth[i] = -1; sp[i] = 0; ifl[i] = 0; hetz[i] = NULL;
62076    }
62077 
62078    het = (char *) malloc(80);
62079    strp = hetptr.HetAtm[aihet];
62080    if (strp[0] == ' ') strp++;
62081    strcpy(het,strp);
62082    het[3] = '\0';
62083 
62084    if (!HetTmp.init) iniHetTmp();
62085    ChkHetCoo(aihet);
62086 
62087    fprintf(stderr,"\nRetrieving Ligand information from PDBeChem\n\n");
62088 
62089    iac = Ligand2Amino(ihet);
62090 
62091    sprintf(cmdtmp,"%s/plush",exepath[0]);
62092    if (isdir(cmdtmp)) {
62093       sprintf(cmdtmp,"%s/plush/%s",exepath[0],het);
62094       imode = 0;
62095    } else {
62096       istat = DoWGET(wwwstr,het,cmdtmp);
62097       imode = 1;
62098    }
62099 
62100    out = fopen(cmdtmp,"r");
62101 
62102    npdbe = 0;
62103    if (out != NULL) {
62104 	while (fgets(cmdfil,MAXCMD,out) != NULL) {
62105 	   if (imode) {
62106 		if (strstr(cmdfil,"formalCharge") != NULL) {
62107 		   spntr = strstr(cmdfil,"formalCharge=\"");
62108 		   if (spntr) {
62109 		    spntr = spntr + 14;
62110 		    sscanf(spntr,"%d",&itch);
62111 		   }
62112 		   break;
62113 		}
62114 	   } else {
62115 		if (strstr(cmdfil,"Charge") != NULL) {
62116 		   spntr = strstr(cmdfil,"Charge=\"");
62117 		   if (spntr) {
62118 		    spntr = spntr + 8;
62119 		    sscanf(spntr,"%d",&itch);
62120 		   }
62121 		   break;
62122 		}
62123 	   }
62124 	}
62125 	fprintf(stderr,"formalCharge %d\n",itch);
62126 	clfstrptr->ihetq[aihet] = itch;
62127 	clfstrptr->ihqset[aihet] = 1;
62128 
62129 
62130    	if (imode) {
62131 	   while (fgets(cmdfil,MAXCMD,out) != NULL) {
62132 		if (strstr(cmdfil,"atomArray") != NULL) break;
62133 	   }
62134 	}
62135 	while (fgets(cmdfil,MAXCMD,out) != NULL) {
62136 
62137 	    if (imode) {
62138 
62139 		   if (strstr(cmdfil,"atom id=") != NULL) {
62140 			spntr = strstr(cmdfil,"atom id=\"");
62141 			if (spntr) {
62142 			    /*spntr = spntr + 3;*/
62143 			    spntr = spntr + 9;
62144 		   	    sscanf(spntr,"%[^\"]",chemid);
62145 
62146 			    if (strcmp(chemidOld,"-1") == 0) {
62147 
62148 				strcpy(chemidOld,chemid);
62149 				hetz[0] = (char *) malloc(strlen(chemid)+1);
62150 				strcpy(hetz[0],chemid);
62151 
62152 			    } else if (strcmp(chemid,chemidOld) != 0) {
62153 
62154 				strcpy(chemidOld,chemid);
62155 				npdbe++;
62156 				hetz[npdbe] =
62157 					(char *) malloc(strlen(chemid)+1);
62158 				strcpy(hetz[npdbe],chemid);
62159 
62160 			    }
62161 
62162 			    spntr = strstr(cmdfil,"hydrogenCount=\"");
62163 			    if (spntr) {
62164 				spntr = spntr + 15;
62165 		   	        sscanf(spntr,"%d",&nh[npdbe]);
62166 			    }
62167 
62168 			}
62169 		   }
62170 
62171 	    } else {
62172 
62173 		   if (strstr(cmdfil,"lab=") != NULL) {
62174 			spntr = strstr(cmdfil,"lab=\"");
62175 			if (spntr) {
62176 			    spntr = spntr + 5;
62177 		   	    sscanf(spntr,"%[^\"]",chemid);
62178 
62179 			    if (strcmp(chemidOld,"-1") == 0) {
62180 
62181 				strcpy(chemidOld,chemid);
62182 				hetz[0] = (char *) malloc(strlen(chemid)+1);
62183 				strcpy(hetz[0],chemid);
62184 
62185 			    } else if (strcmp(chemid,chemidOld) != 0) {
62186 
62187 				strcpy(chemidOld,chemid);
62188 				npdbe++;
62189 				hetz[npdbe] =
62190 					(char *) malloc(strlen(chemid)+1);
62191 				strcpy(hetz[npdbe],chemid);
62192 
62193 			    }
62194 
62195 			    spntr = strstr(cmdfil,"NH=\"");
62196 			    if (spntr) {
62197 				spntr = spntr + 4;
62198 		   	        sscanf(spntr,"%d",&nh[npdbe]);
62199 			    }
62200 
62201 			    spntr = strstr(cmdfil,"NOTH=\"");
62202 			    if (spntr) {
62203 				spntr = spntr + 6;
62204 		   	        sscanf(spntr,"%d",&noth[npdbe]);
62205 			    }
62206 
62207 			}
62208 		   }
62209 
62210 
62211 	    } /* end imode */
62212 	} /* end while */
62213 	fclose(out);
62214    } /* end if out != NULL */
62215    npdbe++;
62216 
62217    nht = 0;
62218 
62219    if (npdbe == 1) goto nolab;
62220 
62221    clfstrptr->ihhadd[aihet] = 1;
62222 
62223    i = -1;
62224 
62225    natoms = iend + 1;
62226 
62227    for (j=0; j < natoms; j++) {
62228 
62229 	if (xyzp->iresid[j] == ihet) {
62230 
62231 	  i++;
62232 	  j1 = j + 1;
62233 
62234 	  l0 = -1;
62235 	  for (l=0; l < hetlab.NHetLab; l++)
62236 		if (hetlab.iat[l] == j1) l0 = l;
62237 
62238 	  if (l0 == -1) {
62239 		fprintf(stderr,
62240 		"LigandHydroPBE: atom %d : pdb label not found!\n",j1);
62241 	  	return;
62242 	  }
62243 
62244 
62245 	  k0 = -1;
62246 
62247 	  for (l=0; l < npdbe; l++) {
62248 		htmp = hetlab.HetLab[l0];
62249 		for (k=0; k < strlen(htmp); k++) {
62250 		    if (htmp[0]!=' ') break;
62251 		    htmp++;
62252 		}
62253 		n = 0;
62254 		for (k=0; k < strlen(htmp); k++) {
62255 		    if (htmp[k]==' ') break;
62256 		    n++;
62257 		}
62258 		if (n == strlen(hetz[l])) {
62259 		  if (strncmp(htmp,hetz[l],n) == 0) {
62260 		    k0 = l;
62261 		    break;
62262 		  }
62263 		}
62264 	  }
62265 
62266 	  hasH = 0;
62267 	  nc = 0;
62268 	  nce = 0;
62269 	  nmce = 0;
62270 	  xc = xyzp->iconn[j*(MXCON+1)];
62271 	  ir = xyzp->iresid[j];
62272 
62273 	  for (k=0; k < 3; k++) ic[k] = -1;
62274 
62275 	  for (k=0; k < xc; k++) {
62276 		l = xyzp->iconn[j*(MXCON+1)+k+1];
62277 		la = abs(l);
62278 		lanz = 0;
62279 		lr = -1;
62280 		if (la > 0) {
62281 		   lanz = xyzp->ianz[la-1];
62282 	  	   lr = xyzp->iresid[la-1];
62283 		}
62284 
62285 		if (ir == lr) {
62286 		   if (l > 0 && lanz > 1) {
62287 			ic[nc] = l;
62288 			nc++;
62289 		   } else if (lanz == 1) {
62290 			hasH = 1;
62291 		   }
62292 		} else {
62293 		   if (!isit_metal(lanz) && !isBH4(j)) {
62294 			ice[nce] = l;
62295 			nce++;
62296 		   } else {
62297 			mce[nmce] = l;
62298 			nmce++;
62299 		   }
62300 		}
62301 	  }
62302 
62303 	  if (k0 != -1) {
62304 	     if (strcmp(het,"HEM") == 0) {
62305 		if (strcmp(hetz[k0],"O2A") == 0 ||
62306 		    strcmp(hetz[k0],"O2D") == 0) {
62307 			nht = nht + nh[k0];
62308 			k0 = -1;
62309 		}
62310 	     }
62311 	  }
62312 
62313 	  if (k0 != -1 && hasH) ifl[k0] = 1;
62314 
62315 	  if (k0 != -1 && !hasH) {
62316 
62317 	   notu = nht;
62318 	   nht = nht + nh[k0];
62319 
62320            ifl[k0] = 1;
62321 
62322 	   if (nce != 0 || nmce != 0) {
62323 		if (noth[k0] != -1) {
62324 
62325 		   if (noth[k0] == nc + nce) {
62326 	              for (k=0; k < nce; k++) {
62327 			ic[nc] = ice[k];
62328 			nc++;
62329 		      }
62330 		   } else {
62331 	              for (k=0; k < nce; k++) {
62332 			nh[k0]--;
62333 			nht--;
62334 			ic[nc] = ice[k];
62335 			nc++;
62336 		      }
62337 		   }
62338 
62339 		} else {
62340 	           for (k=0; k < nce; k++) {
62341 			nh[k0]--;
62342 			nht--;
62343 			ic[nc] = ice[k];
62344 			nc++;
62345 		   }
62346 	           for (k=0; k < nmce; k++) {
62347 			ic[nc] = mce[k];
62348 			nc++;
62349 		   }
62350 		}
62351 	   }
62352 /*
62353 fprintf(stderr,"Lab %s nc %d nh[k0] %d\n",hetlab.HetLab[l0],nc,nh[k0]);
62354 */
62355 	   switch(nc) {
62356 		case 1:
62357 			ix = ic[0];
62358 			xc = xyzp->iconn[(ix-1)*(MXCON+1)];
62359 
62360 			if (xc > 0 && xc <= 4) {
62361 			   l = 0;
62362 			   for (k=0; k < xc; k++) {
62363 				iy = xyzp->iconn[(ix-1)*(MXCON+1)+k+1];
62364 				if (iy != j1) {
62365 				    ic[l] = iy;
62366 				    l++;
62367 				}
62368 			   }
62369 			   switch(nh[k0]) {
62370 				case 3:
62371 /* 1 + 3 = 4 connections; atom is C sp3, N sp3 */
62372 					for (k=0; k < 3; k++) {
62373 					   AddAtom(ic[0],ix,j1,1.090,109.47,
62374 						   angles3[k], xyzp->iresid[j]);
62375 				           nht--;
62376 					}
62377 					break;
62378 				case 2:
62379 /* 1 + 2 = 3 connections; atom is C sp2 or N sp3,sp2 */
62380 					for (k=0; k < 2; k++) {
62381 					   AddAtom(ic[0],ix,j1,1.090,120.0,
62382 						   angles2[k], xyzp->iresid[j]);
62383 				           nht--;
62384 					}
62385 					break;
62386 				case 1:
62387 /* 1 + 1 = 2 connections; atom is C sp or N sp2 or O sp3 */
62388 					switch(xyzp->ianz[j]) {
62389 					   case 7:
62390 					   	AddAtom(ic[0],ix,j1,
62391 						1.090,120.0,180.0,
62392 						xyzp->iresid[j]);
62393 				        	nht--;
62394 						break;
62395 					   case 8:
62396 						if (!isPO4(ix-1) && !isCOO(ix-1)) {
62397 				   		   AddAtom(ic[0],ix,j1,
62398 							   1.090,109.47,180.0,
62399 							   xyzp->iresid[j]);
62400 				        	   nht--;
62401 						} else {
62402 						}
62403 						break;
62404 					   case 16:
62405 					   	AddAtom(ic[0],ix,j1,
62406 						1.090,109.47,180.0,
62407 						xyzp->iresid[j]);
62408 				        	nht--;
62409 						break;
62410 					   case 6:
62411 					   	AddAtom(ic[0],ix,j1,
62412 						1.090,179.9,0.0,
62413 						xyzp->iresid[j]);
62414 				        	nht--;
62415 						break;
62416 					   default:
62417 						break;
62418 					}
62419 					break;
62420 				default:
62421 					break;
62422 			   }
62423 			}
62424 
62425 			break;
62426 		case 2:
62427 			switch(nh[k0]) {
62428 /* 2 + 2 = 4 connections; atom is C sp3 */
62429 			   case 2:
62430 				   if (xyzp->ianz[j] == 8) break;
62431 				   for (k=0; k < nh[k0]; k++) {
62432 					AddAtom(ic[0],ic[1],j1,1.090,109.47,
62433 					angles3a[k],xyzp->iresid[j]);
62434 				        nht--;
62435 				   }
62436 				   break;
62437 			   case 1:
62438 /* 2 + 1 = 3 connections; atom is  C sp2  or N sp3,sp2 */
62439 				   if (xyzp->ianz[j] == 8) break;
62440 				   AddAtom(ic[0],ic[1],j1,1.090,120.0,
62441 					180.0,xyzp->iresid[j]);
62442 				   nht--;
62443 				   break;
62444 			   default:
62445 				   break;
62446 			}
62447 			break;
62448 		case 3:
62449 			switch(nh[k0]) {
62450 			   case 1:
62451 /* 3 + 1 = 4 connections; atom is C sp3 */
62452 				   asel[0] = ic[0];
62453 				   asel[1] = j1;
62454 				   asel[2] = ic[1];
62455 				   asel[3] = ic[2];
62456 				   anum = 4;
62457 
62458 #if defined(VMS) || defined(UNDERSC)
62459 				   tomold(&aret,asel,&anum);
62460 #else
62461 #ifdef CRAY
62462 	 			   TOMOLD(&aret,asel,&anum);
62463 #else
62464 				   tomold_(&aret,asel,&anum);
62465 #endif
62466 #endif
62467 
62468 				   is = SIGN(aret);
62469 				   AddAtom(ic[0],ic[1],j1,1.090,109.47,
62470 					is*120.0,xyzp->iresid[j]);
62471 				   nht--;
62472 				   break;
62473 			   default:
62474 				   break;
62475 			}
62476 			break;
62477 		default:
62478 			break;
62479 	   }
62480 	  }
62481 	}
62482 
62483    }
62484 
62485    *zmptrp->ihaszm = 0;
62486    ZMEAA = 0;
62487    fnd = 0;
62488    for (j=0; j < npdbe; j++) {
62489 	if (nh[j] != 0 && ifl[j] == 0) {
62490 	    fnd++;
62491 	}
62492    }
62493 
62494    if (fnd) {
62495 
62496 	fprintf(stderr,
62497 	   "\nSome labels in PBE entry %s, not found in HETATM from pdb file\n\n",het);
62498 
62499 	fprintf(stderr,"PBE labels:\n\n");
62500 	for (j=0; j < npdbe; j++)
62501 	   fprintf(stderr,"%s nh %d used %d\n",hetz[j],nh[j],ifl[j]);
62502 
62503 	fprintf(stderr,"\npdb file HETATM labels:\n\n");
62504 
62505 	for (j=0; j < *xyzp->iatoms; j++)
62506 	   if (xyzp->iresid[j] == ihet) {
62507 		j1 = j + 1;
62508 
62509 		l0 = -1;
62510 		for (l=0; l < hetlab.NHetLab; l++)
62511 		   if (hetlab.iat[l] == j1) l0 = l;
62512 
62513 		if (l0 != -1)
62514 	   	   fprintf(stderr,"atom %d %s\n",j1,hetlab.HetLab[l0]);
62515 	   }
62516    }
62517 
62518 nolab:
62519 
62520    if (nht) {
62521 
62522 	   fprintf(stderr,"\nSome Hydrogens not used:\n");
62523 	   fprintf(stderr,"\nDecreasing formal charge by %d units\n",nht);
62524 /*
62525 	if (iac) {
62526 	   fprintf(stderr,"\n%s has connections with amino acids:\n",het);
62527 	   fprintf(stderr,"\nIncreasing formal charge by %d units\n",iac);
62528 	}
62529 
62530 	clfstrptr->ihetq[aihet] =
62531 		clfstrptr->ihetq[aihet] - nht + iac;
62532 */
62533 	clfstrptr->ihetq[aihet] =
62534 		clfstrptr->ihetq[aihet] - nht;
62535 
62536 	fprintf(stderr,"New formalCharge %d\n",clfstrptr->ihetq[aihet]);
62537    }
62538 
62539    np = 0;
62540    for (j=0; j < natoms; j++) {
62541 	if (xyzp->iresid[j] == ihet) {
62542 	   if (xyzp->ianz[j] == 7) {
62543 		if (TertN(j,con)) {
62544 		   j1 = j + 1;
62545 		   n = *xyzp->iatoms;
62546 		   for (l=0; l<3; l++) {
62547 		      v[l] = 0.0;
62548 		      v[l] = v[l] +
62549 			(xyzp->coo[(con[0]-1)*3+l] - xyzp->coo[j*3+l]);
62550 		      v[l] = v[l] +
62551 			(xyzp->coo[(con[1]-1)*3+l] - xyzp->coo[j*3+l]);
62552 		      v[l] = v[l] +
62553 			(xyzp->coo[(con[2]-1)*3+l] - xyzp->coo[j*3+l]);
62554 		      xyzp->coo[n*3+l] = xyzp->coo[j*3+l] - v[l];
62555 		   }
62556 
62557 		   asel[0] = j1;
62558 		   asel[1] = con[0];
62559 		   asel[2] = con[1];
62560 		   asel[3] = con[2];
62561 		   anum = 4;
62562 
62563 #if defined(VMS) || defined(UNDERSC)
62564 		   tomold(&aret,asel,&anum);
62565 #else
62566 #ifdef CRAY
62567 		   TOMOLD(&aret,asel,&anum);
62568 #else
62569 		   tomold_(&aret,asel,&anum);
62570 #endif
62571 #endif
62572 /*		   fprintf(stderr,"aret %f\n",aret);*/
62573 
62574 		   if (ABS(aret) > 15.0) {
62575 			asel[0] = n+1;
62576 			asel[1] = j1;
62577 			asel[2] = con[1];
62578 			asel[3] = con[0];
62579 			anum = 4;
62580 			*xyzp->iatoms = *xyzp->iatoms + 1;
62581 
62582 #if defined(VMS) || defined(UNDERSC)
62583 			tomold(&aret,asel,&anum);
62584 #else
62585 #ifdef CRAY
62586 			TOMOLD(&aret,asel,&anum);
62587 #else
62588 			tomold_(&aret,asel,&anum);
62589 #endif
62590 #endif
62591 			*xyzp->iatoms = *xyzp->iatoms - 1;
62592 			AddAtom(con[0],con[1],j1,1.090,109.47,aret,ihet);
62593 			clfstrptr->ihetq[aihet] = clfstrptr->ihetq[aihet] + 1;
62594 			np++;
62595 		   }
62596 		}
62597 	   }
62598 	}
62599    }
62600 
62601    if (np) {
62602 	fprintf(stderr,"Protonated %d Tertiary Nitrogen(s) \nNew formalCharge %d\n",np,clfstrptr->ihetq[aihet]);
62603    }
62604 
62605    free(sp);
62606    free(nh);
62607    free(ifl);
62608    for (j=0; j < npdbe; j++)
62609 	if (hetz != NULL) free(hetz[j]);
62610    free(hetz);
62611    free(het);
62612 
62613 
62614 }
62615 
62616 /*
62617   specify:
62618 
62619   DoHyd		Add Hydrogens
62620   DoChg		Calculate Charge, with ieemopt and CHGtot
62621   DoFF		Type by Ambfor Force Field
62622 */
62623 
LigandHydroQ(DoHyd,DoChg,DoFF,CHGtot)62624 void LigandHydroQ(DoHyd,DoChg,DoFF,CHGtot)
62625 int DoHyd;
62626 int DoChg;
62627 int DoFF;
62628 int CHGtot;
62629 {
62630       int i,imn,nhmol,TmpEemOpt,CHGstat,onemol;
62631       CHGstat = 0;
62632 
62633       TmpEemOpt = ieemopt + 1;
62634 
62635       if (*ipdbon) {
62636 
62637 #if defined(VMS) || defined(UNDERSC)
62638 	numhed(&nhmol,
62639 #else
62640 #ifdef CRAY
62641 	NUMHED(&nhmol,
62642 #else
62643 	numhed_(&nhmol,
62644 #endif
62645 #endif
62646 	xyzp->iresid);
62647 
62648 	onemol = 0;
62649 	if (nhmol == 4) onemol = 1;
62650 
62651 	for (i=4; i<nhmol+1; i++) {
62652 
62653 	    imn = -i;
62654 
62655 	    if (i != calfptr->ishoh) {
62656 
62657 		if (clfstrptr->ihashz) {
62658 		    fprintf(stderr,"\nHETATM residue %s\n\n",hetptr.HetAtm[i]);
62659 		} else {
62660 		    fprintf(stderr,"\nHETATM residue %d\n\n",(i-4));
62661 		}
62662 
62663 		if (DoHyd) CheckHydro(imn);
62664 
62665 		if (DoHyd && !clfstrptr->ihhadd[i]) LigandHydroPBE(imn);
62666 
62667 		if (DoFF) {
62668 
62669 		    if (clfstrptr->ihqset[i]) {
62670 			*itot = clfstrptr->ihetq[i];
62671 		    } else {
62672 			if (onemol) {
62673 			   *itot = CHGtot;
62674 			} else {
62675 			   *itot = 0;
62676 			}
62677 		    }
62678 
62679 		    *fftyp = 7;
62680 		    typit(7,1);
62681 		}
62682 
62683 		if (DoChg) {
62684 
62685 		    if (clfstrptr->ihqset[i]) {
62686 			*itot = clfstrptr->ihetq[i];
62687 		    } else {
62688 			if (onemol) {
62689 			   *itot = CHGtot;
62690 			} else {
62691 			   *itot = 0;
62692 			}
62693 		    }
62694 
62695 		    if (ieemopt == 4) {
62696 
62697 #if defined(VMS) || defined(UNDERSC)
62698 			calgas(&imn,&CHGstat);
62699 #else
62700 #ifdef CRAY
62701 			CALGAS(&imn,&CHGstat);
62702 #else
62703 			calgas_(&imn,&CHGstat);
62704 #endif
62705 #endif
62706 		    } else {
62707 
62708 #if defined(VMS) || defined(UNDERSC)
62709 			eem(&TmpEemOpt,&imn,&CHGstat);
62710 #else
62711 #ifdef CRAY
62712 			EEM(&TmpEemOpt,&imn,&CHGstat);
62713 #else
62714 			eem_(&TmpEemOpt,&imn,&CHGstat);
62715 #endif
62716 #endif
62717 		    }
62718 
62719 		    if (CHGstat)
62720 			fprintf(stderr,
62721 			"WARNING: element missing charge scheme parameters!\n");
62722 		}
62723 	    }
62724 	}
62725 
62726 
62727       } else {
62728 
62729 	*itot = CHGtot;
62730 
62731 	if (ieemopt == 4) {
62732 
62733 #if defined(VMS) || defined(UNDERSC)
62734 	    calgas(&ONE,&CHGstat);
62735 #else
62736 #ifdef CRAY
62737 	    CALGAS(&ONE,&CHGstat);
62738 #else
62739 	    calgas_(&ONE,&CHGstat);
62740 #endif
62741 #endif
62742 
62743 	} else {
62744 
62745 #if defined(VMS) || defined(UNDERSC)
62746 	    eem(&TmpEemOpt,&ONE,&CHGstat);
62747 #else
62748 #ifdef CRAY
62749 	    EEM(&TmpEemOpt,&ONE,&CHGstat);
62750 #else
62751 	    eem_(&TmpEemOpt,&ONE,&CHGstat);
62752 #endif
62753 #endif
62754 	}
62755 	if (CHGstat)
62756 	    fprintf(stderr,
62757 		"WARNING: element missing charge scheme parameters!\n");
62758       }
62759 
62760 
62761 }
62762 
LigandStruct(het)62763 void LigandStruct(het)
62764 int het;
62765 {
62766 
62767   int i,j,k,l,n,nc,ir,istr;
62768   int nat,fnd,istart,iend,itot,ahet;
62769   COOSTRU *xyzpo;
62770 
62771     ahet = ABS(het);
62772 
62773     if (ahet >= MXHETA) {
62774 	fprintf(stderr,"\nLigandStruct: hetatm residue outside array bounds\n\n");
62775 	return;
62776     }
62777 
62778     istr = istruct;
62779 
62780     if (istruct == 0 && (&(COO[istruct]->coo) == NULL)) {
62781 	    SaveFirstStruct();
62782 	    nstruct++;
62783     }
62784 
62785     xyzpo   = &COO[istruct]->coo;
62786 
62787     fnd = 0;
62788     istart = 0;
62789     iend = -1;
62790 
62791     if (xyzpo->iatoms != NULL) {
62792     for (j=0; j < *xyzpo->iatoms; j++) {
62793 	if (xyzpo->iresid[j] == het) {
62794 	   if (!fnd) {
62795 	      istart = j;
62796 	      fnd = 1;
62797 	   }
62798 	   iend = j;
62799 	}
62800     }
62801     }
62802 
62803     if (iend == -1 ) return;
62804 
62805     nat = iend - istart + 1;
62806 
62807     AllocateStructure(&COO[nstruct]);
62808     if (nstruct != 0) SaveActiveStruct();
62809 
62810     if (ahet < MXHETA) {
62811 	if (hetptr.Allocated[4]) free(hetptr.HetAtm[4]);
62812 	if (COO[istr]->hetatm.Allocated[ahet]) {
62813 		n = strlen(COO[istr]->hetatm.HetAtm[ahet]);
62814 		hetptr.HetAtm[4] = (char *) malloc(n+1);
62815 		strncpy(hetptr.HetAtm[4],COO[istr]->hetatm.HetAtm[ahet],n);
62816 		hetptr.HetAtm[4][n] = '\0';
62817 		hetptr.Allocated[4] = 1;
62818 	}
62819     }
62820 
62821     AllocateSubStructures(COO[istr]->hetatm.HetAtm[ahet],0);
62822 
62823     if (nat > *xyzp->mxnat) {
62824 	itot = nat + 500;
62825 #if defined(VMS) || defined(UNDERSC)
62826 	allcoo(&itot,&ZERO);
62827 #else
62828 #ifdef CRAY
62829 	ALLCOO(&itot,&ZERO);
62830 #else
62831 	allcoo_(&itot,&ZERO);
62832 #endif
62833 #endif
62834     }
62835 
62836     for (j=0; j < nat; j++) {
62837 	xyzp->iresid[j] = -4;
62838 	xyzp->iatclr[j] = xyzpo->iatclr[j+istart];
62839 	xyzp->iaton[j]  = xyzpo->iaton[j+istart];
62840 	xyzp->ianz[j]   = xyzpo->ianz[j+istart];
62841 	xyzp->ipdbt[j]  = xyzpo->ipdbt[j+istart];
62842 	xyzp->ityp[j]   = xyzpo->ityp[j+istart];
62843 	xyzp->qat[j]    = xyzpo->qat[j+istart];
62844 	xyzp->isurf[j]  = xyzpo->isurf[j+istart];
62845 
62846 	for (k=0; k < 3; k++)
62847 	   xyzp->coo[j*3+k] = xyzpo->coo[(j+istart)*3+k];
62848 
62849 	nc = 0;
62850 	for (k=0; k < xyzpo->iconn[(j+istart)*(MXCON+1)]; k++) {
62851 	   i = xyzpo->iconn[(j+istart)*(MXCON+1)+k+1];
62852 	   ir = xyzpo->iresid[i-1];
62853 	   if (ir == het) {
62854 		if (i >= 0) {
62855 		   xyzp->iconn[j*(MXCON+1)+nc+1] =
62856 			xyzpo->iconn[(j+istart)*(MXCON+1)+k+1] - istart;
62857 		} else {
62858 		   xyzp->iconn[j*(MXCON+1)+nc+1] =
62859 			xyzpo->iconn[(j+istart)*(MXCON+1)+k+1] + istart;
62860 		}
62861 		nc++;
62862 	   }
62863 	}
62864 	xyzp->iconn[j*(MXCON+1)] = nc;
62865     }
62866     *natorg = nat;
62867     *xyzp->iatoms = nat;
62868     clfstrptr->ihashz = 0;
62869     *ipdbon = 0;
62870     *backb = 0;
62871 
62872 #if defined(VMS) || defined(UNDERSC)
62873     docent();doscal();
62874 #else
62875 #ifdef CRAY
62876     DOCENT();DOSCAL();
62877 #else
62878     docent_();doscal_();
62879 #endif
62880 #endif
62881     posptr->zv = 2.0*scalptr->scali;
62882     posptr->xv = 0.0;
62883     posptr->yv = 0.0;
62884 #ifdef DOGL
62885     posz = scalptr->scali;
62886     updfog(0);
62887 #endif
62888 
62889     update_model = 1;
62890     update_struct();
62891     RedrawSTR();
62892 
62893     ZMEswitch[0].toggle = 1; ZMEAA = 0; EXPbox[0].fake = 1;
62894     LastAmino = -1;
62895     CurAmino = -1;
62896 
62897     for (j=0; j < *xyzp->iatoms; j++) {
62898 	if (xyzp->ianz[j] < 100) {
62899 	   xyzp->iaton[j] = 2;
62900 	} else {
62901 	   xyzp->iaton[j] = 1;
62902 	}
62903     }
62904 
62905 #if defined(VMS) || defined(UNDERSC)
62906     intzmt(&ZERO);
62907 #else
62908 #ifdef CRAY
62909     INTZMT(&ZERO);
62910 #else
62911     intzmt_(&ZERO);
62912 #endif
62913 #endif
62914 
62915     for (j=0; j < *xyzp->iatoms; j++) xyzp->iaton[j] = 1;
62916 
62917     pdb = 0;
62918     calfptr->ncalf = 0;
62919     hetptr.NHetAtm = 5;
62920 
62921 }
62922 
62923 #ifdef DOGL
62924 
62925 #if defined(VMS) || defined(UNDERSC)
oglin()62926 void oglin()
62927 #else
62928 #ifdef CRAY
62929 void OGLIN()
62930 #else
62931 void oglin_()
62932 #endif
62933 #endif
62934 {
62935 
62936       theLines[istruct] = glGenLists(1);
62937 
62938       glNewList(theLines[istruct], GL_COMPILE);
62939 
62940       glDisable(GL_LIGHTING);
62941       glEnable(GL_COLOR_MATERIAL);
62942       glBegin(GL_LINES);
62943 }
62944 
ogrdmol(char * top,double * r,double * adjus,int * natoms,int * nat,int * iatclr,double * coo,int * iopt,int * conn,int * iconn)62945 void ogrdmol(char *top, double *r, double *adjus, int *natoms, int *nat,
62946 	int *iatclr, double *coo, int *iopt, int *conn, int *iconn)
62947 {
62948       int i,j,atcol;
62949 
62950       *adjus = 0.529177;
62951       if (strstr(top,"AU")) *adjus = 1.0;
62952       *conn = 0;
62953       if (strstr(top,"CONN")) *conn = 1;
62954       *iopt = 0;
62955       if (strstr(top,"UNSCALED")) *iopt = 1;
62956       atcol = 1;
62957       if (strstr(top,"GRPCOL")) atcol = 0;
62958 
62959       if (*iopt) {
62960         r[0] = 1.0;
62961       } else {
62962 	fgets(top,100,out);
62963 	sscanf(top,"%lf %lf %lf",&r[0],&r[1],&r[2]);
62964       }
62965       fgets(top,100,out);
62966       sscanf(top,"%d",natoms);
62967 
62968       for (i=0; i<*natoms; i++) {
62969 	  fgets(top,132,out);
62970 	  if (atcol) {
62971 	    sscanf(top,"%d %lf %lf %lf %d %d %d %d %d %d %d %d %d %d %d %d %d",
62972 		&nat[i],&coo[i*3],&coo[i*3+1],&coo[i*3+2],
62973 		&iconn[i*(MXCON+1)],
62974 		&iconn[i*(MXCON+1)+1],&iconn[i*(MXCON+1)+2],
62975 		&iconn[i*(MXCON+1)+3],&iconn[i*(MXCON+1)+4],
62976 		&iconn[i*(MXCON+1)+5],&iconn[i*(MXCON+1)+6],
62977 		&iconn[i*(MXCON+1)+7],&iconn[i*(MXCON+1)+8],
62978 		&iconn[i*(MXCON+1)+9],&iconn[i*(MXCON+1)+10],
62979 		&iconn[i*(MXCON+1)+11],&iconn[i*(MXCON+1)+12]);
62980 	  } else {
62981 	    sscanf(top,"%d %d %lf %lf %lf %d %d %d %d %d %d %d %d %d %d %d %d %d",
62982 		&nat[i],&iatclr[i],&coo[i*3],&coo[i*3+1],&coo[i*3+2],
62983 		&iconn[i*(MXCON+1)],
62984 		&iconn[i*(MXCON+1)+1],&iconn[i*(MXCON+1)+2],
62985 		&iconn[i*(MXCON+1)+3],&iconn[i*(MXCON+1)+4],
62986 		&iconn[i*(MXCON+1)+5],&iconn[i*(MXCON+1)+6],
62987 		&iconn[i*(MXCON+1)+7],&iconn[i*(MXCON+1)+8],
62988 		&iconn[i*(MXCON+1)+9],&iconn[i*(MXCON+1)+10],
62989 		&iconn[i*(MXCON+1)+11],&iconn[i*(MXCON+1)+12]);
62990 	  }
62991 	  xyzp->iaton[i] = 1;
62992 	  for (j=0; j<3; j++)
62993 		coo[i*3+j] = coo[i*3+j]/(*adjus);
62994       }
62995 }
62996 
ogsize(int * natoms,double * coo,double * r)62997 void ogsize(int *natoms, double *coo, double *r)
62998 {
62999    int i;
63000    double dijsq;
63001 
63002    for (i=0; i<*natoms; i++) {
63003 	dijsq = coo[i*3]*coo[i*3] +
63004 		coo[i*3+1]*coo[i*3+1] +
63005 		coo[i*3+2]*coo[i*3+2];
63006 	dijsq = dijsq / (r[0]*r[0]);
63007 	if (dijsq > 0.0) dijsq = sqrt(dijsq);
63008 	if (dijsq > posz) posz = dijsq;
63009 
63010    }
63011 }
63012 
dist(double * coo,double * dsq)63013 void dist(double *coo, double *dsq)
63014 {
63015   double d;
63016 
63017   d = coo[0]*coo[0] + coo[1]*coo[1] + coo[2]*coo[2];
63018   if (d > 0.0) d = sqrt(d);
63019   if (d > *dsq) *dsq = d;
63020 }
63021 
dentr()63022 void dentr()
63023 {
63024    int i;
63025    double t;
63026 
63027    for (i=0; i<*xyzp->iatoms; i++) {
63028 	t = xyzp->coo[i*3];
63029 	xyzp->coo[i*3] = -1.0*xyzp->coo[i*3+1];
63030 	xyzp->coo[i*3+1] = -1.0*t;
63031 	xyzp->coo[i*3+2] = -1.0*xyzp->coo[i*3+2];
63032    }
63033 }
63034 
ogxyz(out)63035 void ogxyz(out)
63036 FILE *out;
63037 {
63038     double tmp[3], dsq, dmaxsq, adj;
63039     int i,j,l,ia,ja,nc,icnn[MXCON];
63040 
63041     adj = *adjuss;
63042 
63043     fprintf(out,"[MOLECULE] UNSCALED CONN\n");
63044     fprintf(out,"%d\n",NAT->natoms);
63045 
63046     for (i=0; i< NAT->natoms; i++) {
63047 
63048            ia = NAT->nat[i];
63049 	   nc = 0;
63050 
63051            for (j=0; j< NAT->natoms; j++) {
63052 
63053             ja = NAT->nat[j];
63054 
63055 	    dsq = 0;
63056             for (l=0; l<3; l++) {
63057                 tmp[l] = (XYZ->xyz[j][l] - XYZ->xyz[i][l]);
63058 		dsq = dsq + tmp[l]*tmp[l];
63059 	    }
63060             dmaxsq = (elmptr->vdwr[ia-1] + elmptr->vdwr[ja-1])/adj;
63061             dmaxsq = dmaxsq * dmaxsq;
63062 
63063 	    if (i != j && dsq < dmaxsq && nc < MXCON) {
63064 		icnn[nc] = j+1;
63065 		nc++;
63066 	    }
63067 
63068 	   }
63069 
63070 	   for (j=0; j<3; j++)
63071 		tmp[j] = (XYZ->xyz[i][j]-rotptr->t[j]) * adj;
63072 
63073 	   fprintf(out,"%3d %12.6f %12.6f %12.6f %2d",
63074 		NAT->nat[i],tmp[0],tmp[1],tmp[2],nc);
63075 	   for (j=0; j<nc; j++)
63076 		fprintf(out," %5d ",icnn[j]);
63077 	   fprintf(out,"\n");
63078 
63079     }
63080 
63081 }
63082 
woglmol(out)63083 void woglmol(out)
63084 FILE *out;
63085 {
63086    int i,j,k, nc, doit, natoms, icnn[MXCON];
63087    double tmp[3],t[3];
63088 
63089    fprintf(out,"[MOLECULE] UNSCALED GRPCOL CONN\n");
63090 
63091    for (i=0; i<*xyzp->iatoms; i++) xyzp->lring[i] = 0;
63092 
63093    natoms = 0;
63094 
63095    for (i=0; i<*xyzp->iatoms; i++) {
63096 	doit = 0;
63097 	if (*ipdbon) {
63098 	   if (xyzp->iresid[i] > 0) {
63099 		if (calfptr->reson[xyzp->iresid[i]-1] == 1) doit = 1;
63100 	   } else if (xyzp->iresid[i] < -3) {
63101 		doit = 1;
63102 	   }
63103 	} else {
63104 	   doit = 1;
63105 	}
63106 	if (xyzp->ianz[i] < 100 && xyzp->ianz[i] > 0 &&
63107 	    xyzp->iaton[i] > 0 && doit) {
63108 	    natoms++;
63109 	    xyzp->lring[i] = natoms;
63110 	}
63111    }
63112 
63113    fprintf(out,"%d\n",natoms);
63114 
63115    for (i=0; i<*xyzp->iatoms; i++) {
63116 
63117 	nc = 0;
63118 	for (k=0; k < xyzp->iconn[i*(MXCON+1)]; k++) {
63119 	   j = xyzp->iconn[i*(MXCON+1)+k+1];
63120 	   if (j >= 0) {
63121 		if (xyzp->lring[j-1] > 0) {
63122 		   icnn[nc] = xyzp->lring[j-1];
63123 		   nc++;
63124 		}
63125 	   }
63126 	}
63127 
63128 	doit = 0;
63129 	if (*ipdbon) {
63130 	   if (xyzp->iresid[i] > 0) {
63131 		if (calfptr->reson[xyzp->iresid[i]-1] == 1) doit = 1;
63132 	   } else if (xyzp->iresid[i] < -3) {
63133 		doit = 1;
63134 	   }
63135 	} else {
63136 	   doit = 1;
63137 	}
63138 
63139 	if (xyzp->iaton[i] > 0 && doit) {
63140 	   for (j=0; j<3; j++)
63141 		tmp[j] = (xyzp->coo[i*3+j]-rotptr->t[j]) * (double)toangs;
63142 	   fprintf(out,"%3d %2d %12.6f %12.6f %12.6f %2d",
63143 		xyzp->ianz[i],xyzp->iatclr[i],tmp[0],tmp[1],tmp[2],nc);
63144 	   for (j=0; j<nc; j++)
63145 		fprintf(out," %5d ",icnn[j]);
63146 	   fprintf(out,"\n");
63147 
63148 	}
63149    }
63150 }
63151 
wrtall()63152 void wrtall()
63153 {
63154    int i,j,k,snd;
63155    char colstr[18];
63156    FILE *out;
63157    double tmp[3],adj;
63158 
63159 
63160    out = fopen("molden.ogl","w");
63161    if (out == NULL) {
63162       fprintf(stderr,"Couldnt open file molden.ogl\n");
63163       return;
63164    }
63165 
63166    fprintf(out,"[MOLDENOGL]\n");
63167 
63168    if (denmode) {
63169 	adj = *adjuss;
63170 	ogxyz(out);
63171    } else {
63172 	adj = toangs;
63173 	woglmol(out);
63174    }
63175 
63176    if (!dovrt) fprintf(stderr,"Due to failed memory allocation, written surfaces may be incomplete\n");
63177 
63178    for (i=0; i < NSurf[istruct]; i++) {
63179 
63180 	if (nvert[istruct][i] > 4 && srfvert[istruct][i] != NULL) {
63181 
63182 	   sprintf(colstr,"COLOR %3.1f %3.1f %3.1f",
63183 		diffuseColor[istruct][i][0],
63184 		diffuseColor[istruct][i][1],
63185 		diffuseColor[istruct][i][2]);
63186 
63187 	   switch(SStyp[istruct][i]) {
63188 	   case 0:
63189 		fprintf(out,"[SURFACE] %s \"%s\"\n",
63190 			colstr,sndstr[istruct][i]);
63191 		break;
63192 	   case 1:
63193 		fprintf(out,"[SURFACE] MAPPED %s \"%s\"\n",
63194 			colstr,sndstr[istruct][i]);
63195 		break;
63196 	   case 2:
63197 		snd = 0;
63198 		for (j=0; j < 4; j++) {
63199 		   if (i >= RIBindex[istruct].start[j]
63200 		    && i <= RIBindex[istruct].end[j]) {
63201 	   		fprintf(out,"[RIBBON] %s %s \"%s\"\n",
63202 				strsnd[j],colstr,sndstr[istruct][i]);
63203 			snd = 1;
63204 		   }
63205 		}
63206 		if (!snd) fprintf(out,"[ELEVATIONGRID] %s \"%s\"\n",
63207 		   colstr,sndstr[istruct][i]);
63208 		break;
63209 	   }
63210 
63211 	   for (j=0; j < nvert[istruct][i]; j++) {
63212 		k = srfvert[istruct][i][j].type;
63213 		if (k == 2) {
63214 		   fprintf(out,"[HELIXIN]\n");
63215 		} else if (k == 1) {
63216 		   for (k=0; k < 3; k++)
63217 		    tmp[k] =
63218 			(srfvert[istruct][i][j].vert[k] - rotptr->t[k])*adj;
63219 		   fprintf(out,"%f %f %f\n",tmp[0],tmp[1],tmp[2]);
63220 		} else {
63221 		   for (k=0; k < 3; k++)
63222 		    tmp[k] = srfvert[istruct][i][j].vert[k];
63223 		   fprintf(out,"%f %f %f\n",tmp[0],tmp[1],tmp[2]);
63224 		}
63225 	   }
63226 	}
63227    }
63228 
63229    fclose(out);
63230 }
63231 
srfcen()63232 void srfcen()
63233 {
63234    int i,j,k,n;
63235    float cen[3],dt,dist;
63236 
63237    n = 0;
63238    for (i=0; i < 3; i++) cen[i] = 0.0;
63239 
63240    for (i=0; i < NSurf[istruct]; i++) {
63241 	for (j=0; j < nvert[istruct][i]; j++) {
63242 		k = srfvert[istruct][i][j].type;
63243 		if (k == 1) {
63244 		   for (k=0; k < 3; k++)
63245 			cen[k] = cen[k] + srfvert[istruct][i][j].vert[k];
63246 		   n++;
63247 		}
63248 	}
63249    }
63250 
63251    for (i=0; i < 3; i++) rotptr->t[i] = cen[i]/(double) n;
63252 
63253    scalptr->scali = 0.0;
63254    for (i=0; i < NSurf[istruct]; i++) {
63255 	for (j=0; j < nvert[istruct][i]; j++) {
63256 		k = srfvert[istruct][i][j].type;
63257 		if (k == 1) {
63258 		   dist = 0.0;
63259 		   for (k=0; k < 3; k++) {
63260 			dt = (srfvert[istruct][i][j].vert[k] - rotptr->t[k]);
63261 			dist = dist + dt*dt;
63262 		   }
63263 		   if (dist > scalptr->scali) scalptr->scali = dist;
63264 		}
63265 	}
63266    }
63267    scalptr->scali = sqrt(scalptr->scali);
63268    scalptr->scal = scalptr->scali*2.4*scalptr->smag;
63269    posptr->zv = scalptr->scali;
63270    posptr->xv = 0.0;
63271    posptr->yv = 0.0;
63272    posptr->pincr = 0.02*scalptr->scali;
63273    posz = scalptr->scali;
63274    updfog(0);
63275 
63276 }
63277 
rdoglfile(infile)63278 int rdoglfile(infile)
63279 char *infile;
63280 {
63281    double adjus, r[3];
63282    int conn, mopt, mapped, iorb, isurf, ityp, icolset;
63283    int iopt,fend,i,j,ic,ichain,elev,ribb,surf,loop,iribc,iscnd;
63284    char rdstr[132];
63285    char *colstr;
63286    char *namestr;
63287    double v[3],vt[3],vc[3],dis,cntval;
63288    float coltmp[3];
63289 
63290    if (has_opengl) {
63291       *ifogl = 1;
63292       *fancy = 1;
63293    } else {
63294       return(1);
63295    }
63296 
63297    dis = 0.0;
63298    posz = 0.0;
63299    *ipdbon = 0;
63300    NSurf[istruct] = 0;
63301    iorb = -1;
63302    cntval = 0.0;
63303    ichain = -1;
63304 
63305    RIBindex[istruct].nhelx = 0;
63306    RIBindex[istruct].nbeta = 0;
63307    RIBindex[istruct].nrna = 0;
63308    RIBindex[istruct].ncoil = 0;
63309 
63310    for (i=0; i<4; i++) {
63311 	RIBindex[istruct].start[i] = -1;
63312 	RIBindex[istruct].end[i] = -1;
63313    }
63314 
63315    out = fopen(infile,"r");
63316    if (out == NULL) {
63317       fprintf(stderr,"Couldnt open file %s\n",infile);
63318       return(1);
63319    }
63320 
63321    fgets(rdstr,100,out);
63322    if (strncmp(rdstr,"[MOLDENOGL]",11) != 0) {
63323       fprintf(stderr,"This is not an [MOLDENOGL] file !\n");
63324       return(1);
63325    }
63326 
63327    iopt = 0;
63328 
63329    while(!(fend = feof(out))) {
63330       fgets(rdstr,100,out);
63331       if (strstr(rdstr,"[MOLECULE]") == NULL) goto Surf;
63332       ogrdmol(rdstr,r,&adjus,xyzp->iatoms,xyzp->ianz,xyzp->iatclr,
63333 	xyzp->coo,&mopt,&conn,xyzp->iconn);
63334       if (!mopt) dentr();
63335       ogsize(xyzp->iatoms,xyzp->coo,r);
63336       ogmoll(0);
63337 #if defined(VMS) || defined(UNDERSC)
63338       docent();doscal();setxyv();
63339 #else
63340 #ifdef CRAY
63341       DOCENT();DOSCAL();SETXYV();
63342 #else
63343       docent_();doscal_();setxyv_();
63344 #endif
63345 #endif
63346    }
63347 
63348 
63349 Surf:
63350 
63351    loop = 0;
63352 
63353    elev = 0;
63354    ribb = 0;
63355    lines = 0;
63356    surf = 0;
63357    isurf = 1;
63358    ityp = 0;
63359    mapped = 0;
63360 
63361    while(!(fend = feof(out))) {
63362 
63363       if (loop) fgets(rdstr,100,out);
63364       loop = 1;
63365 
63366       if (strncmp(rdstr,"[LINES",6) == 0) {
63367 #if defined(VMS) || defined(UNDERSC)
63368 	if (surf) ogend();
63369 	oglin();
63370 #else
63371 #ifdef CRAY
63372 	if (surf) OGEND();
63373 	OGLIN();
63374 #else
63375 	if (surf) ogend_();
63376 	oglin_();
63377 #endif
63378 #endif
63379 	surf++;
63380 	lines = 1;
63381 	continue;
63382       }
63383 
63384       iribc = -1;
63385       if (strstr(rdstr,"[COL STRANDTOP]") != NULL) iribc = 0;
63386       if (strstr(rdstr,"[COL STRANDBOTTOM]") != NULL) iribc = 1;
63387       if (strstr(rdstr,"[COL HELIXOUT]") != NULL) iribc = 2;
63388       if (strstr(rdstr,"[COL HELIXIN]") != NULL) iribc = 3;
63389       if (strstr(rdstr,"[COL RNA]") != NULL) iribc = 4;
63390       if (strstr(rdstr,"[COL COIL]") != NULL) iribc = 5;
63391       if (iribc != -1) {
63392 	colstr = strstr(rdstr,"]");
63393 	if (colstr != NULL) {
63394 	   colstr = colstr + 1;
63395 	   sscanf(colstr,"%f %f %f",&ribcol[iribc][0],
63396 		&ribcol[iribc][1],&ribcol[iribc][2]);
63397 	}
63398 	continue;
63399       }
63400 
63401       if (strncmp(rdstr,"[SURFACE",8) == 0 ||
63402 	  strncmp(rdstr,"[ELEVATION",10) == 0 ||
63403 	  strncmp(rdstr,"[RIBBON",7) == 0) {
63404 	lines = 0;
63405 #if defined(VMS) || defined(UNDERSC)
63406 	if (surf) ogendd(&ichain);
63407 #else
63408 #ifdef CRAY
63409 	if (surf) OGENDD(&ichain);
63410 #else
63411 	if (surf) ogendd_(&ichain);
63412 #endif
63413 #endif
63414 	icolset = 0;
63415 	colstr = strstr(rdstr,"COLOR");
63416 	if (colstr != NULL) {
63417 	   icolset = 1;
63418 	   colstr = colstr + 5;
63419 	   sscanf(colstr,"%f %f %f",&coltmp[0],&coltmp[1],&coltmp[2]);
63420 	   for (i=0; i<3; i++) {
63421 		diffuseColor[istruct][surf][i] = coltmp[i];
63422 		cursrfcol[isurf-1][i] = coltmp[i];
63423 	   }
63424 	}
63425 
63426 	namestr = strstr(rdstr,"\"");
63427 	if (namestr != NULL) {
63428 	   namestr++;
63429 	} else {
63430 	   namestr = unknown;
63431 	}
63432 
63433 	if (strncmp(rdstr,"[RIBBON",7) == 0) {
63434            iribc = -1;
63435 	   if (strstr(rdstr,"STRANDTOP") != NULL) iribc = 0;
63436 	   if (strstr(rdstr,"STRANDBOTTOM") != NULL) iribc = 1;
63437 	   if (strstr(rdstr,"HELIXOUT") != NULL) iribc = 2;
63438 	   if (strstr(rdstr,"HELIXIN") != NULL) iribc = 3;
63439 	   if (strstr(rdstr,"RNA") != NULL) iribc = 4;
63440 	   if (strstr(rdstr,"COIL") != NULL) iribc = 5;
63441 
63442 	}
63443 
63444 
63445 	if (strstr(rdstr,"MAPPED") != NULL) {
63446 		mapped = 1;
63447 	} else {
63448 		mapped = 0;
63449 	}
63450 
63451 	iopt = 1;
63452 	colstr = strstr(rdstr,"TRANS");
63453 	if (colstr != NULL) {
63454 	   colstr = colstr + 5;
63455 	   iopt = -iopt;
63456 	   if (sscanf(colstr,"%lf",&tr_val) <= 0) {
63457 		tr_val = TRDEF;
63458 	   }
63459 	}
63460 
63461 	if (strncmp(rdstr,"[ELEVATION",10) == 0 ||
63462 	    strncmp(rdstr,"[RIBBON",7) == 0) {
63463 	   if (strncmp(rdstr,"[ELEVATION",10) == 0) {
63464 		elev = 1;
63465 		ogelev(namestr);
63466 	   } else {
63467 		ribb = 1;
63468 		switch (iribc) {
63469 		case 0:
63470 		case 1:
63471 			iscnd = 1;
63472 			break;
63473 		case 2:
63474 		case 3:
63475 			iscnd = 0;
63476 			break;
63477 		case 4:
63478 			iscnd = 2;
63479 			break;
63480 		case 5:
63481 			iscnd = 3;
63482 			break;
63483 		}
63484 #if defined(VMS) || defined(UNDERSC)
63485 		ogribb(&iscnd);
63486 #else
63487 #ifdef CRAY
63488 		OGRIBB(&iscnd);
63489 #else
63490 		ogribb_(&iscnd);
63491 #endif
63492 #endif
63493 		if (iribc != -1)
63494 
63495 		   if (RIBindex[istruct].start[iscnd] == -1)
63496 			RIBindex[istruct].start[iscnd] = NSurf[istruct]-1;
63497 		   RIBindex[istruct].end[iscnd] = NSurf[istruct]-1;
63498 
63499 		   if (icolset) {
63500 			for (i=0; i<3; i++)
63501 			   diffuseColor[istruct][NSurf[istruct]-1][i] =
63502 				coltmp[i];
63503 		   } else {
63504 			for (i=0; i<3; i++)
63505 			   diffuseColor[istruct][NSurf[istruct]-1][i] =
63506 				ribcol[iribc][i];
63507 		   }
63508 		}
63509 
63510 	} else {
63511 	   elev = 0; ribb = 0;
63512 #if defined(VMS) || defined(UNDERSC)
63513 	   ogbegg(&isurf,&ZERO,&ityp,&iorb,&cntval,&mapped,namestr);
63514 #else
63515 #ifdef CRAY
63516 	   OGBEGG(&isurf,&ZERO,&ityp,&iorb,&cntval,&mapped,namestr);
63517 #else
63518 	   ogbegg_(&isurf,&ZERO,&ityp,&iorb,&cntval,&mapped,namestr);
63519 #endif
63520 #endif
63521 	   isurf++;
63522 	   if (isurf > 2) isurf = 1;
63523 	}
63524 	surf++;
63525 	fgets(rdstr,100,out);
63526       }
63527 
63528       if (lines) {
63529 
63530 /*
63531 Yes you are right the x and y coordinates are swapped in molden
63532 Have to fix it sometime
63533 */
63534 	sscanf(rdstr,"%d %lf %lf %lf %lf %lf %lf",
63535 		&ic,&v[1],&v[0],&v[2],&vt[1],&vt[0],&vt[2]);
63536 	for (j=0; j<3; j++) {
63537 	   v[j] = r[0]*v[j] / adjus;
63538 	   vt[j] = r[0]*vt[j] / adjus;
63539 	}
63540 
63541 	vc[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
63542 	vc[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
63543 	vc[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
63544 
63545 #if defined(VMS) || defined(UNDERSC)
63546 	ogcoll(&vc[0],&vc[1],&vc[2]);
63547 	ogvrt(&v[0],&v[1],&v[2]);
63548 	ogvrt(&vt[0],&vt[1],&vt[2]);
63549 #else
63550 #ifdef CRAY
63551 	OGCOLL(&vc[0],&vc[1],&vc[2]);
63552 	OGVRT(&v[0],&v[1],&v[2]);
63553 	OGVRT(&vt[0],&vt[1],&vt[2]);
63554 #else
63555 	ogcoll_(&vc[0],&vc[1],&vc[2]);
63556 	ogvrt_(&v[0],&v[1],&v[2]);
63557 	ogvrt_(&vt[0],&vt[1],&vt[2]);
63558 #endif
63559 #endif
63560 	continue;
63561 
63562       }
63563 
63564       if (mapped) {
63565 	sscanf(rdstr,"%lf %lf %lf",&v[0],&v[1],&v[2]);
63566 	v[0] = fabs(v[0]);
63567 #if defined(VMS) || defined(UNDERSC)
63568 	ogcoll(&v[0],&v[1],&v[2]);
63569 #else
63570 #ifdef CRAY
63571 	OGCOLL(&v[0],&v[1],&v[2]);
63572 #else
63573 	ogcoll_(&v[0],&v[1],&v[2]);
63574 #endif
63575 #endif
63576         fgets(rdstr,100,out);
63577       }
63578 
63579       if (strncmp(rdstr,"[HELIXIN",8) == 0) {
63580 #if defined(VMS) || defined(UNDERSC)
63581 	sribcol(&THREE);
63582 	setcll();
63583 	if (icolset) {
63584 	   for (i=0; i<3; i++)
63585 		diffuseColor[istruct][NSurf[istruct]-1][i] = coltmp[i];
63586 	} else {
63587 	   sribcol(&TWO);
63588 	}
63589 #else
63590 #ifdef CRAY
63591 	SRIBCOL(&THREE);
63592 	SETCLL();
63593 	if (icolset) {
63594 	   for (i=0; i<3; i++)
63595 		diffuseColor[istruct][NSurf[istruct]-1][i] = coltmp[i];
63596 	} else {
63597 	   SRIBCOL(&TWO);
63598 	}
63599 #else
63600 	sribcol_(&THREE);
63601 	setcll_();
63602 	if (icolset) {
63603 	   for (i=0; i<3; i++)
63604 		diffuseColor[istruct][NSurf[istruct]-1][i] = coltmp[i];
63605 	} else {
63606 	   sribcol_(&TWO);
63607 	}
63608 #endif
63609 #endif
63610         fgets(rdstr,100,out);
63611       }
63612 
63613       sscanf(rdstr,"%lf %lf %lf",&v[0],&v[1],&v[2]);
63614 /*      for (j=0; j<3; j++) v[j] = 1.0*v[j];*/
63615 #if defined(VMS) || defined(UNDERSC)
63616       ognrm(&v[0],&v[1],&v[2]);
63617 #else
63618 #ifdef CRAY
63619       OGNRM(&v[0],&v[1],&v[2]);
63620 #else
63621       ognrm_(&v[0],&v[1],&v[2]);
63622 #endif
63623 #endif
63624 
63625       fgets(rdstr,100,out);
63626       sscanf(rdstr,"%lf %lf %lf",&v[0],&v[1],&v[2]);
63627       for (j=0; j<3; j++) v[j] = r[0]*v[j] / adjus;
63628 
63629 #if defined(VMS) || defined(UNDERSC)
63630       ogvrt(&v[0],&v[1],&v[2]);
63631 #else
63632 #ifdef CRAY
63633       OGVRT(&v[0],&v[1],&v[2]);
63634 #else
63635       ogvrt_(&v[0],&v[1],&v[2]);
63636 #endif
63637 #endif
63638       dist(v,&dis);
63639 
63640       if (elev || ribb) {
63641 
63642        for (i=0; i<3; i++) {
63643 
63644          fgets(rdstr,100,out);
63645          sscanf(rdstr,"%lf %lf %lf",&v[0],&v[1],&v[2]);
63646 /*         for (j=0; j<3; j++) v[j] = 1.0*v[j];*/
63647 
63648 #if defined(VMS) || defined(UNDERSC)
63649          ognrm(&v[0],&v[1],&v[2]);
63650 #else
63651 #ifdef CRAY
63652          OGNRM(&v[0],&v[1],&v[2]);
63653 #else
63654          ognrm_(&v[0],&v[1],&v[2]);
63655 #endif
63656 #endif
63657          fgets(rdstr,100,out);
63658          sscanf(rdstr,"%lf %lf %lf",&v[0],&v[1],&v[2]);
63659 	 for (j=0; j<3; j++) v[j] = r[0]*v[j] / adjus;
63660 
63661 #if defined(VMS) || defined(UNDERSC)
63662          ogvrt(&v[0],&v[1],&v[2]);
63663 #else
63664 #ifdef CRAY
63665          OGVRT(&v[0],&v[1],&v[2]);
63666 #else
63667          ogvrt_(&v[0],&v[1],&v[2]);
63668 #endif
63669 #endif
63670          dist(v,&dis);
63671         }
63672 
63673       }
63674    }
63675 
63676    if (dis > posz) posz = dis;
63677    scalptr->scali = posz;
63678    posptr->zv = posz;
63679 
63680 #if defined(VMS) || defined(UNDERSC)
63681    ogendd(&ichain);
63682 #else
63683 #ifdef CRAY
63684    OGENDD(&ichain);
63685 #else
63686    ogendd_(&ichain);
63687 #endif
63688 #endif
63689 
63690    for (i=0; i<NSurf[istruct]; i++) {
63691 	SSon[istruct][i] = 1;
63692 	clp[istruct][i] = 0;
63693 	trns[istruct][i] = 0;
63694    }
63695 
63696 
63697    fclose(out);
63698 
63699    if (*xyzp->iatoms == 0) srfcen();
63700 
63701    plcnrm();
63702 
63703    dispsf();
63704 
63705    if (surf > 1) inistrc();
63706 
63707    UpdateSTRC();
63708    RedrawSTRC();
63709 
63710    return(0);
63711 
63712 }
63713 #else
rdoglfile(infile)63714 int rdoglfile(infile)
63715 char *infile;
63716 {
63717    lViewer(infile);
63718    return(1);
63719 }
63720 #endif
63721 
63722 #define TOANG 0.52917706
63723 
calsrf(v1,v2,v3)63724 double calsrf(v1,v2,v3)
63725 double *v1;
63726 double *v2;
63727 double *v3;
63728 {
63729    double a,b,c,s,opp, t1[3],t2[3],t3[3];
63730    int i;
63731 
63732    for (i = 0; i < 3; i++) {
63733 	t1[i] = v1[i] - v2[i];
63734 	t2[i] = v2[i] - v3[i];
63735 	t3[i] = v1[i] - v3[i];
63736    }
63737 
63738    a = vln(t1);
63739    b = vln(t2);
63740    c = vln(t3);
63741    s = (a + b + c) / 2.0;
63742    opp = sqrt(s*(s-a)*(s-b)*(s-c))*TOANG*TOANG;
63743 
63744    return(opp);
63745 
63746 }
63747 
clsrf(v1,v2,v3)63748 double clsrf(v1,v2,v3)
63749 double *v1;
63750 double *v2;
63751 double *v3;
63752 {
63753    double a,b,c,s,opp, t1[3],t2[3],t3[3];
63754    int i;
63755 
63756    for (i = 0; i < 3; i++) {
63757 	t1[i] = v1[i] - v2[i];
63758 	t2[i] = v2[i] - v3[i];
63759 	t3[i] = v1[i] - v3[i];
63760    }
63761 
63762    a = vln(t1);
63763    b = vln(t2);
63764    c = vln(t3);
63765    s = (a + b + c) / 2.0;
63766    opp = sqrt(s*(s-a)*(s-b)*(s-c));
63767 
63768    return(opp);
63769 
63770 }
63771 
subdivide(v1,v2,v3,c1,c2,c3,pol,pol2,psa,tsa,exs,depth)63772 void subdivide(v1,v2,v3,c1,c2,c3,pol,pol2,psa,tsa,exs,depth)
63773 double *v1;
63774 double *v2;
63775 double *v3;
63776 double c1;
63777 double c2;
63778 double c3;
63779 double pol;
63780 double pol2;
63781 double *psa;
63782 double *tsa;
63783 double *exs;
63784 int depth;
63785 {
63786 
63787    double v12[3], v23[3], v31[3], val[3], c12,c23,c31, ctot, fr, s;
63788    int i, ires;
63789 
63790    ires = 0;
63791    ctot = 0.0;
63792 
63793    if (c1 > pol)  {ires++;ctot=ctot+(c1-pol);}
63794    if (c2 > pol)  {ires++;ctot=ctot+(c2-pol);}
63795    if (c3 > pol)  {ires++;ctot=ctot+(c3-pol);}
63796    if (ires) ctot = ctot / (double) ires;
63797 
63798    if (!ires) {
63799 	ctot = 0.0;
63800 	if (c1 < pol2)  {ires++;ctot=ctot+(c1-pol2);}
63801 	if (c2 < pol2)  {ires++;ctot=ctot+(c2-pol2);}
63802 	if (c3 < pol2)  {ires++;ctot=ctot+(c3-pol2);}
63803 	if (ires) ctot = ctot / (double) ires;
63804    }
63805 
63806 /*
63807    if (c1 < pol)  ires++;
63808    if (c2 < pol)  ires++;
63809    if (c3 < pol)  ires++;
63810 */
63811 
63812    fr = (double) ires / 3.0;
63813 
63814    if (ires == 3 || !depth) {
63815         s = calsrf(v1,v2,v3);
63816 	*psa = *psa + fr*s;
63817 	*tsa = *tsa + s;
63818 	*exs = *exs + fabs(fr*s*ctot);
63819 	return;
63820 
63821    } else {
63822 
63823 	for (i = 0; i < 3; i++) {
63824 
63825 	   v12[i] = (v1[i] + v2[i]) / 2.0;
63826 	   v23[i] = (v2[i] + v3[i]) / 2.0;
63827 	   v31[i] = (v3[i] + v1[i]) / 2.0;
63828 	}
63829 
63830 	c12 = (c1 + c2) / 2.0;
63831 	c23 = (c2 + c3) / 2.0;
63832 	c31 = (c3 + c1) / 2.0;
63833 
63834 	subdivide(v1, v12, v31, c1, c12, c31, pol, pol2, psa, tsa, exs, depth-1);
63835 	subdivide(v2, v23, v12, c2, c23, c12, pol, pol2, psa, tsa, exs, depth-1);
63836 	subdivide(v3, v31, v23, c3, c31, c23, pol, pol2, psa, tsa, exs, depth-1);
63837 	subdivide(v12, v23, v31, c12, c23, c31, pol, pol2, psa, tsa, exs, depth-1);
63838 
63839    }
63840 
63841 }
63842 
63843 #if defined(VMS) || defined(UNDERSC)
calpsa(v,cval,pol,pol2,psa,tsa,exs,depth)63844 void calpsa(v,cval,pol,pol2,psa,tsa,exs,depth)
63845 #else
63846 #ifdef CRAY
63847 void CALPSA(v,cval,pol,pol2,psa,tsa,exs,depth)
63848 #else
63849 void calpsa_(v,cval,pol,pol2,psa,tsa,exs,depth)
63850 #endif
63851 #endif
63852 double v[3][3];
63853 double *cval;
63854 double *pol;
63855 double *pol2;
63856 double *psa;
63857 double *tsa;
63858 double *exs;
63859 int *depth;
63860 {
63861    double v1[3], v2[3], v3[3];
63862    int i;
63863 
63864    for (i = 0; i < 3; i++) {
63865 	v1[i] = v[0][i];
63866 	v2[i] = v[1][i];
63867 	v3[i] = v[2][i];
63868    }
63869    subdivide(v1,v2,v3,cval[0],cval[1],cval[2],*pol,*pol2,psa,tsa,exs,*depth);
63870 
63871 }
63872 
63873 #if defined(VMS) || defined(UNDERSC)
tstpsa(cval,pol,pol2,ires)63874 void tstpsa(cval,pol,pol2,ires)
63875 #else
63876 #ifdef CRAY
63877 void TSTPSA(cval,pol,pol2,ires)
63878 #else
63879 void tstpsa_(cval,pol,pol2,ires)
63880 #endif
63881 #endif
63882 double *cval;
63883 double *pol;
63884 double *pol2;
63885 int *ires;
63886 {
63887    *ires = 0;
63888 
63889    if (cval[0] > *pol)  (*ires)++;
63890    if (cval[1] > *pol)  (*ires)++;
63891    if (cval[2] > *pol)  (*ires)++;
63892 
63893    if (! *ires) {
63894 	if (cval[0] < *pol2)  (*ires)++;
63895 	if (cval[1] < *pol2)  (*ires)++;
63896 	if (cval[2] < *pol2)  (*ires)++;
63897    }
63898 
63899 /*
63900    if (fabs(cval[0]) > *pol)  (*ires)++;
63901    if (fabs(cval[1]) > *pol)  (*ires)++;
63902    if (fabs(cval[2]) > *pol)  (*ires)++;
63903 */
63904 
63905 }
63906 
63907 #define X .525731112119133606
63908 #define Z .850650808352039932
63909 #define SCV 2.0
63910 
63911 
63912 
63913 static double icosa[12][3] = {
63914 
63915    {-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
63916 
63917    {0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
63918 
63919    {Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0}
63920 
63921 };
63922 
63923 static int tricnt = 0;
63924 static int curat = 0;
63925 static int *idoa = NULL;
63926 static int *ipola = NULL;
63927 static int *nats;
63928 static int *nata;
63929 static double *vpcm;
63930 static double icofi[1280][3][3];
63931 
63932 static int icoind[20][3] = {
63933 
63934    {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
63935 
63936    {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
63937 
63938    {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
63939 
63940    {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
63941 
normalize(v)63942 void normalize(v)
63943 double *v;
63944 {
63945    double d;
63946 
63947    d = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
63948 
63949    if (d != 0.0) {
63950 
63951 	v[0] /= d; v[1] /= d; v[2] /= d;
63952 
63953    }
63954 
63955 
63956 }
63957 
subd(v1,v2,v3,depth)63958 void subd(v1,v2,v3,depth)
63959 double *v1;
63960 double *v2;
63961 double *v3;
63962 int depth;
63963 {
63964 
63965    double v12[3], v23[3], v31[3];
63966    int i;
63967 
63968    if (!depth) {
63969 	for (i = 0; i < 3; i++) {
63970            icofi[tricnt][0][i] = v1[i];
63971            icofi[tricnt][1][i] = v2[i];
63972            icofi[tricnt][2][i] = v3[i];
63973 	}
63974 	tricnt++;
63975 	if (tricnt > 1280)
63976 	   fprintf(stderr,"more triangles than storage allocated\n");
63977 
63978 	return;
63979 
63980    } else {
63981 
63982 	for (i = 0; i < 3; i++) {
63983 
63984 	   v12[i] = (v1[i] + v2[i]) / 2.0;
63985 	   v23[i] = (v2[i] + v3[i]) / 2.0;
63986 	   v31[i] = (v3[i] + v1[i]) / 2.0;
63987 	}
63988 
63989 	normalize(v12);
63990 	normalize(v23);
63991 	normalize(v31);
63992 
63993 	subd(v1, v12, v31, depth-1);
63994 	subd(v2, v23, v12, depth-1);
63995 	subd(v3, v31, v23, depth-1);
63996 	subd(v12, v23, v31, depth-1);
63997 
63998    }
63999 
64000 }
64001 
isfree(v1,v2,vr)64002 int isfree(v1,v2,vr)
64003 double *v1;
64004 double *v2;
64005 double vr;
64006 {
64007   double dx,d2;
64008   int i;
64009 
64010   d2 = 0.0;
64011 
64012   for (i = 0; i < 3; i++) {
64013 	dx = v1[i] - v2[i];
64014 	d2 = d2 + dx*dx;
64015   }
64016 
64017   if (d2 < vr*vr) return(0);
64018   return(1);
64019 
64020 }
64021 
verfree(v1,v2,v3)64022 int verfree(v1,v2,v3)
64023 double *v1;
64024 double *v2;
64025 double *v3;
64026 {
64027    int i,j, icnt, icnt1,icnt2,icnt3;
64028    double vr;
64029 
64030    icnt1 = 1;
64031    icnt2 = 1;
64032    icnt3 = 1;
64033 
64034    for (i=0; i < *nats; i++ ) {
64035 	if (i != curat && idoa[i]) {
64036 	    vr = vpcm[nata[i]-1];
64037 	    if (nata[i] == 1 && ipola[i] == 2) vr = 1.125 / (double) toangs;
64038 	    if (nata[i] == 1 && ipola[i] == 3) vr = 1.1 / (double) toangs;
64039 	    if (denmode) {
64040 		if (!isfree(v1,&XYZ->xyz[i][0],vr)) icnt1 = 0;
64041 		if (!isfree(v2,&XYZ->xyz[i][0],vr)) icnt2 = 0;
64042 		if (!isfree(v3,&XYZ->xyz[i][0],vr)) icnt3 = 0;
64043 	    } else {
64044 		if (!isfree(v1,&xyzp->coo[i*3],vr)) icnt1 = 0;
64045 		if (!isfree(v2,&xyzp->coo[i*3],vr)) icnt2 = 0;
64046 		if (!isfree(v3,&xyzp->coo[i*3],vr)) icnt3 = 0;
64047 	    }
64048 	}
64049    }
64050 
64051    icnt = icnt1 + icnt2 + icnt3;
64052    return(icnt);
64053 }
64054 
subd2(v1,v2,v3,psa,depth)64055 void subd2(v1,v2,v3,psa,depth)
64056 double *v1;
64057 double *v2;
64058 double *v3;
64059 double *psa;
64060 int depth;
64061 {
64062 
64063    double v12[3], v23[3], v31[3], fr, s;
64064    double colr[3] = {1.0,0.0,0.0};
64065    double colg[3] = {0.0,1.0,0.0};
64066    double colb[3] = {0.0,0.0,1.0};
64067    double *col;
64068    int i,j, ires;
64069 
64070    ires = verfree(v1,v2,v3);
64071 
64072    fr = (double) ires / 3.0;
64073 
64074    if (ires == 0 && !depth) return;
64075 
64076    if (ires == 3 || !depth) {
64077         s = calsrf(v1,v2,v3);
64078 	*psa = *psa + fr*s;
64079 
64080 	if (ipola[curat] >= 2) {
64081 	    col = colb;
64082 	} else if (ipola[curat] == 1) {
64083 	    col = colr;
64084 	} else {
64085 	    col = colg;
64086 	}
64087 	for (j = 0; j < 3; j++) {
64088 	   if (denmode) {
64089 		v12[j] = XYZ->xyz[curat][j] - v1[j];
64090 	   } else {
64091 		v12[j] = xyzp->coo[curat*3+j] - v1[j];
64092 	   }
64093 	}
64094 	normalize(v12);
64095 #if defined(VMS) || defined(UNDERSC)
64096 	ogcoll(&col[0],&col[1],&col[2]);
64097 	ognrm(&v12[0],&v12[1],&v12[2]);
64098 	ogvrt(&v1[0],&v1[1],&v1[2]);
64099 #else
64100 #ifdef CRAY
64101 	OGCOLL(&col[0],&col[1],&col[2]);
64102 	OGNRM(&v12[0],&v12[1],&v12[2]);
64103 	OGVRT(&v1[0],&v1[1],&v1[2]);
64104 #else
64105 	ogcoll_(&col[0],&col[1],&col[2]);
64106 	ognrm_(&v12[0],&v12[1],&v12[2]);
64107 	ogvrt_(&v1[0],&v1[1],&v1[2]);
64108 #endif
64109 #endif
64110 
64111 	for (j = 0; j < 3; j++) {
64112 	   if (denmode) {
64113 		v12[j] = XYZ->xyz[curat][j] - v2[j];
64114 	   } else {
64115 		v12[j] = xyzp->coo[curat*3+j] - v2[j];
64116 	   }
64117 	}
64118 	normalize(v12);
64119 #if defined(VMS) || defined(UNDERSC)
64120 	ogcoll(&col[0],&col[1],&col[2]);
64121 	ognrm(&v12[0],&v12[1],&v12[2]);
64122 	ogvrt(&v2[0],&v2[1],&v2[2]);
64123 #else
64124 #ifdef CRAY
64125 	OGCOLL(&col[0],&col[1],&col[2]);
64126 	OGNRM(&v12[0],&v12[1],&v12[2]);
64127 	OGVRT(&v2[0],&v2[1],&v2[2]);
64128 #else
64129 	ogcoll_(&col[0],&col[1],&col[2]);
64130 	ognrm_(&v12[0],&v12[1],&v12[2]);
64131 	ogvrt_(&v2[0],&v2[1],&v2[2]);
64132 #endif
64133 #endif
64134 
64135 	for (j = 0; j < 3; j++) {
64136 	   if (denmode) {
64137 		v12[j] = XYZ->xyz[curat][j] - v3[j];
64138 	   } else {
64139 		v12[j] = xyzp->coo[curat*3+j] - v3[j];
64140 	   }
64141 	}
64142 	normalize(v12);
64143 #if defined(VMS) || defined(UNDERSC)
64144 	ogcoll(&col[0],&col[1],&col[2]);
64145 	ognrm(&v12[0],&v12[1],&v12[2]);
64146 	ogvrt(&v3[0],&v3[1],&v3[2]);
64147 #else
64148 #ifdef CRAY
64149 	OGCOLL(&col[0],&col[1],&col[2]);
64150 	OGNRM(&v12[0],&v12[1],&v12[2]);
64151 	OGVRT(&v3[0],&v3[1],&v3[2]);
64152 #else
64153 	ogcoll_(&col[0],&col[1],&col[2]);
64154 	ognrm_(&v12[0],&v12[1],&v12[2]);
64155 	ogvrt_(&v3[0],&v3[1],&v3[2]);
64156 #endif
64157 #endif
64158 
64159 	return;
64160 
64161    } else {
64162 
64163 	for (i = 0; i < 3; i++) {
64164 
64165 	   v12[i] = (v1[i] + v2[i]) / 2.0;
64166 	   v23[i] = (v2[i] + v3[i]) / 2.0;
64167 	   v31[i] = (v3[i] + v1[i]) / 2.0;
64168 	}
64169 
64170 	subd2(v1, v12, v31, psa, depth-1);
64171 	subd2(v2, v23, v12, psa, depth-1);
64172 	subd2(v3, v31, v23, psa, depth-1);
64173 	subd2(v12, v23, v31, psa, depth-1);
64174 
64175    }
64176 
64177 }
64178 
64179 
icosah(coo,scl)64180 double icosah(coo,scl)
64181 double *coo;
64182 double scl;
64183 {
64184    int i,j;
64185    double v1[3], v2[3], v3[3], psa, d2, dx, vr, vr2;
64186 
64187    psa = 0.0;
64188 
64189    vr = scl;
64190 
64191    for (i=0; i < *nats; i++ ) {
64192 	d2 = 0.0;
64193 	for (j = 0; j < 3; j++) {
64194 	   if (denmode) {
64195 	      dx = coo[j] - XYZ->xyz[i][j];
64196 	   } else {
64197 	      dx = coo[j] - xyzp->coo[i*3+j];
64198 	   }
64199 	   d2 = d2 + dx*dx;
64200 	}
64201 	vr2 = vpcm[nata[i]-1];
64202 	if (nata[i] == 1 && ipola[i] == 2) vr2 = 1.125 / (double) toangs;
64203 	if (nata[i] == 1 && ipola[i] == 3) vr2 = 1.1 / (double) toangs;
64204 	vr2 = vr2 + vr;
64205 	idoa[i] = 0;
64206 	if (d2 < vr2*vr2) idoa[i] = 1;
64207    }
64208 
64209    for (i = 0; i < 1280; i++) {
64210 	for (j = 0; j < 3; j++) {
64211 	   v1[j] = coo[j] + scl*icofi[i][0][j];
64212 	   v2[j] = coo[j] + scl*icofi[i][1][j];
64213 	   v3[j] = coo[j] + scl*icofi[i][2][j];
64214 	}
64215 	subd2(v1, v2, v3, &psa, 3);
64216    }
64217    fprintf(stderr,"psa atom %4d: %8.3f\n",curat+1,psa);
64218    return(psa);
64219 }
64220 
64221 #if defined(VMS) || defined(UNDERSC)
tpsa()64222 void tpsa()
64223 #else
64224 #ifdef CRAY
64225 void TPSA()
64226 #else
64227 void tpsa_()
64228 #endif
64229 #endif
64230 {
64231    int i,j,k, ichain, mapped, oglon;
64232    double psa,tsa,vr, vr2, v1[3],v2[3],v3[3],dx,d2,s;
64233    char *namestr = "Topol. Pol. surface";
64234 
64235    if (denmode) {
64236 	nats = &NAT->natoms;
64237 	nata = NAT->nat;
64238    } else {
64239 	nats = xyzp->iatoms;
64240 	nata = xyzp->ianz;
64241    }
64242 
64243    ichain = -1;
64244    mapped = 1;
64245    tsa = 0.0;
64246    psa = 0.0;
64247 
64248    tricnt = 0;
64249 
64250    for (i = 0; i < 20; i++) {
64251 
64252 	for (j = 0; j < 3; j++) {
64253 	   v1[j] = icosa[icoind[i][0]][j];
64254 	   v2[j] = icosa[icoind[i][1]][j];
64255 	   v3[j] = icosa[icoind[i][2]][j];
64256 	}
64257 	subd(v1, v2, v3, 3);
64258 
64259    }
64260 
64261    if ((idoa = (int *) malloc((sizeof i)*(*nats))) == NULL) {
64262 	fprintf(stderr,"failed to allocate memory\n");
64263 	return;
64264    }
64265 
64266    if ((ipola = (int *) malloc((sizeof i)*(*nats))) == NULL) {
64267 	fprintf(stderr,"failed to allocate memory\n");
64268 	return;
64269    }
64270 
64271    if ((vpcm = (double *) malloc((sizeof vr)*MXEL)) == NULL) {
64272 	fprintf(stderr,"failed to allocate memory\n");
64273 	return;
64274    }
64275 
64276    for (i=0; i < MXEL; i++ ) {
64277 	vpcm[i] = SCV*elmptr->vdwr[i]/(double) toangs;
64278    }
64279 
64280    vpcm[0] = 1.5 / (double) toangs;
64281    vpcm[5] = 1.92 / (double) toangs;
64282    vpcm[6] = 1.82 / (double) toangs;
64283    vpcm[7] = 1.74 / (double) toangs;
64284 
64285    for (i=0; i < *nats; i++ ) {
64286 	ipola[i] = 0;
64287 	if (nata[i] == 8 || nata[i] == 7) ipola[i] = 1;
64288 	if (nata[i] == 1) {
64289 	   vr = elmptr->vdwr[nata[i]-1]/(double) toangs;
64290 	   for (j=0; j < *nats; j++ ) {
64291 		d2 = 0.0;
64292 		for (k = 0; k < 3; k++) {
64293 		   if (denmode) {
64294 			dx = XYZ->xyz[j][k] - XYZ->xyz[i][k];
64295 		   } else {
64296 			dx = xyzp->coo[j*3+k] - xyzp->coo[i*3+k];
64297 		   }
64298 		   d2 = d2 + dx*dx;
64299 		}
64300 		vr2 = elmptr->vdwr[nata[j]-1]/(double) toangs;
64301 		vr2 = vr2 + vr;
64302 		if (d2 < vr2*vr2 && nata[j] == 7) ipola[i] = 2;
64303 		if (d2 < vr2*vr2 && nata[j] == 8) ipola[i] = 3;
64304 	   }
64305 	}
64306    }
64307 
64308 
64309 /*
64310   SCV scale vdw radii to be compatible with publication by Palm
64311   they took their radii from PCmodel
64312 */
64313 
64314 #if defined(VMS) || defined(UNDERSC)
64315    curs(&ONE);
64316    ogbegg(&ichain,&ZERO,&THREE,&i,&tsa,&mapped,namestr);
64317 #else
64318 #ifdef CRAY
64319    CURS(&ONE);
64320    OGBEGG(&ichain,&ZERO,&THREE,&i,&tsa,&mapped,namestr);
64321 #else
64322    curs_(&ONE);
64323    ogbegg_(&ichain,&ZERO,&THREE,&i,&tsa,&mapped,namestr);
64324 #endif
64325 #endif
64326 
64327    for (i=0; i < *nats; i++ ) {
64328 	curat = i;
64329 	vr = vpcm[nata[i]-1];
64330 	if (nata[i] == 1 && ipola[i] == 2) vr = 1.125 / (double) toangs;
64331 	if (nata[i] == 1 && ipola[i] == 3) vr = 1.1 / (double) toangs;
64332 	if (denmode) {
64333 	   s = icosah(&XYZ->xyz[i][0],vr);
64334 	} else {
64335 	   s = icosah(&xyzp->coo[i*3],vr);
64336 	}
64337 	tsa = tsa + s;
64338 	if (ipola[i]) psa = psa + s;
64339    }
64340 
64341 #if defined(VMS) || defined(UNDERSC)
64342    ogendd(&ichain);
64343    curs(&ZERO);
64344 #else
64345 #ifdef CRAY
64346    OGENDD(&ichain);
64347    CURS(&ZERO);
64348 #else
64349    ogendd_(&ichain);
64350    curs_(&ZERO);
64351 #endif
64352 #endif
64353    fprintf(stderr,"\nTotal Topological Polar Surface Area: %8.3f\n",psa);
64354    fprintf(stderr,"Total surface: %8.3f\n",tsa);
64355 
64356    free(ipola);
64357    free(idoa);
64358    free(vpcm);
64359    ipola = NULL;
64360    idoa = NULL;
64361    vpcm = NULL;
64362 
64363 #ifdef DOGL
64364    oglon = (*fancy || *fullgl);
64365    if (denmode) oglon = *ifdogl;
64366    if (oglon && has_opengl) dispsf();
64367 #endif
64368 }
64369 
64370 /*
64371 mxpeak 2^^mxcpl
64372 */
64373 
64374 
fndhnmr(iat,jcut,hcont,ncont)64375 void fndhnmr(iat,jcut,hcont,ncont)
64376 int iat;
64377 float jcut;
64378 int *hcont;
64379 int *ncont;
64380 {
64381     int i,j,k,l,jat;
64382     float jc,nuc1;
64383 
64384     *ncont = 0;
64385     nuc1 = (float) nmrptr->nucshld[iat];
64386 
64387     jat = -1;
64388     for (i=0; i < xyzp->iconn[iat*(MXCON+1)]; i++) {
64389 	jat = xyzp->iconn[iat*(MXCON+1)+i+1] - 1;
64390 	if (jat >= 0) break;
64391     }
64392     if (jat < 0) return;
64393 
64394     for (i=0; i < xyzp->iconn[jat*(MXCON+1)]; i++) {
64395 	j = xyzp->iconn[jat*(MXCON+1)+i+1];
64396 	if (j >= 0) {
64397 	    if (xyzp->ianz[j-1] == 1) {
64398 		if (j-1 > iat) {
64399 		   jc = (float) jcoupl[(j-1)*NAT->natoms + iat];
64400 		} else {
64401 		   jc = (float) jcoupl[iat*NAT->natoms + j-1];
64402 		}
64403 		if (ABS(jc) > jcut && nuc1 != (float) nmrptr->nucshld[j-1]) {
64404 		   hcont[*ncont] = j - 1;
64405 		   (*ncont)++;
64406 		}
64407 	    } else {
64408 		for (k=0; k < xyzp->iconn[(j-1)*(MXCON+1)]; k++) {
64409 		   l = xyzp->iconn[(j-1)*(MXCON+1)+k+1];
64410 		   if (l >= 0 && l != jat) {
64411 			if (xyzp->ianz[l-1] == 1) {
64412 			    if (l-1 > iat) {
64413 				jc = (float) jcoupl[(l-1)*NAT->natoms + iat];
64414 			    } else {
64415 				jc = (float) jcoupl[iat*NAT->natoms + l-1];
64416 			    }
64417 			    if (ABS(jc) > jcut && nuc1 != (float) nmrptr->nucshld[l-1]) {
64418 				hcont[*ncont] = l - 1;
64419 				(*ncont)++;
64420 			    }
64421 			}
64422 		   }
64423 		}
64424 	    }
64425 	}
64426     }
64427 }
64428 
javch3(ih)64429 void javch3(ih)
64430 int *ih;
64431 {
64432     int i,j,jj;
64433     double jav;
64434 
64435     for (i=0; i < NAT->natoms; i++) {
64436 	jav = 0.0;
64437 	for (j=0; j < 3; j++) {
64438 		if (ih[j] > i) {
64439 		   jav = jav + jcoupl[ih[j]*NAT->natoms + i];
64440 		} else {
64441 		   jav = jav + jcoupl[i    *NAT->natoms + ih[j]];
64442 		}
64443 	}
64444 	jav = jav / 3.0;
64445 	for (j=0; j < 3; j++) {
64446 		if (ih[j] > i) {
64447 		   jcoupl[ih[j]*NAT->natoms + i]     = jav;
64448 		} else {
64449 		   jcoupl[i    *NAT->natoms + ih[j]] = jav;
64450 		}
64451 	}
64452     }
64453 }
64454 
avch3()64455 void avch3()
64456 {
64457     int i,j,jj,nh,ih[3];
64458     double nucav;
64459 
64460     for (i=0; i < NAT->natoms; i++) {
64461 
64462 	if (xyzp->ianz[i] == 6) {
64463 
64464 	    nh = 0;
64465 	    nucav = 0.0;
64466 
64467 	    for (j=0; j < xyzp->iconn[i*(MXCON+1)]; j++) {
64468 
64469 		jj = xyzp->iconn[i*(MXCON+1)+j+1]-1;
64470 		if (jj >= 0) {
64471 		   if (xyzp->ianz[jj] == 1) {
64472 			ih[nh] = jj;
64473 			nh++;
64474 			nucav = nucav + nmrptr->nucshld[jj];
64475 		   }
64476 		}
64477 	    }
64478 	    if (nh == 3) {
64479 		nucav = nucav / 3.0;
64480 	        for (j=0; j < nh; j++) nmrptr->nucshld[ih[j]] = nucav;
64481 		javch3(ih);
64482 	    }
64483 	}
64484     }
64485 }
64486 
nmrsplit(tpeaks,tinten,npeaks,splt)64487 void nmrsplit(tpeaks,tinten,npeaks,splt)
64488 float *tpeaks;
64489 double *tinten;
64490 int *npeaks;
64491 float splt;
64492 {
64493   int i,j,ntp;
64494   float tp;
64495   double ti;
64496 
64497   ntp = *npeaks;
64498 
64499   for (i=0; i < *npeaks; i++) {
64500 	tp = tpeaks[i];
64501 	ti = tinten[i]/2.0;
64502 	tpeaks[i] = tp + splt;
64503 	tinten[i] = ti;
64504 	tpeaks[ntp] = tp - splt;
64505 	tinten[ntp] = ti;
64506 	ntp++;
64507   }
64508   *npeaks = ntp;
64509 }
64510 
prep_nmr()64511 void prep_nmr() {
64512 
64513   int i, j, ncl_peaks,npeaks,cl_peaks[mxcpl];
64514   float f, splt;
64515   float tpeaks[mxpeak];
64516   double d,tinten[mxpeak];
64517 
64518   NMRup = 1;
64519 
64520   if (peaks == NULL) {
64521      if ((peaks = (float *) malloc((sizeof f)*NAT->natoms*mxpeak)) == NULL) {
64522 	fprintf(stderr, "Memory allocation error for nmr spectrum\n");
64523 	return;
64524      }
64525 
64526      if ((inten = (double *) malloc((sizeof d)*NAT->natoms*mxpeak)) == NULL) {
64527 	fprintf(stderr, "Memory allocation error for nmr spectrum\n");
64528 	return;
64529      }
64530   }
64531 
64532   npks = 0;
64533 
64534   for (i=0; i < NAT->natoms; i++) {
64535 
64536     if (xyzp->ianz[i] == NMRnuc) {
64537 
64538 	tpeaks[0] = *nmrref - (float) nmrptr->nucshld[i];
64539 	tinten[0] = 1.0;
64540 	npeaks = 1;
64541 
64542 	if (NMRnuc == 1 && nmrptr->ihsnmr == 2) {
64543 	    fndhnmr(i,jcut,cl_peaks,&ncl_peaks);
64544 	    for (j=0; j < ncl_peaks; j++) {
64545 
64546 		if (cl_peaks[j] > i) {
64547 		    splt = (float) jcoupl[cl_peaks[j]*NAT->natoms + i]/NMRbas;
64548 		} else {
64549 		    splt = (float) jcoupl[i*NAT->natoms + cl_peaks[j]]/NMRbas;
64550 		}
64551 
64552 		nmrsplit(tpeaks,tinten,&npeaks,splt);
64553 	    }
64554 	}
64555 
64556 	for (j=0; j < npeaks; j++) {
64557 	   peaks[npks] = tpeaks[j];
64558 	   inten[npks] = tinten[j];
64559            npks++;
64560 	}
64561     }
64562   }
64563 
64564 }
64565 
click_nmr_spec(indx)64566 void click_nmr_spec(indx)
64567 int indx;
64568 {
64569     int i,iat;
64570     float frq,dfrq,dfrqmn;
64571 
64572     if (indx < 0 || indx >= NAT->natoms*mxpeak) return;
64573 
64574     frq = spfrq[indx];
64575     dfrqmn = 10000.0;
64576     iat = -1;
64577 
64578     for (i=0; i < NAT->natoms; i++) {
64579 	if (xyzp->ianz[i] == NMRnuc) {
64580 	    dfrq = ABS(frq - (*nmrref - (float) nmrptr->nucshld[i]));
64581 	    if (dfrq < dfrqmn) {
64582 		dfrqmn = dfrq;
64583 		iat = i;
64584 	    }
64585 	}
64586     }
64587 
64588     if (iat != -1) {
64589 	for (i=0; i < NAT->natoms; i++) xyzp->iaton[i] = 1;
64590 
64591 	for (i=0; i < NAT->natoms; i++) {
64592 	    if (xyzp->ianz[i] == NMRnuc) {
64593 		dfrq = ABS(frq - (*nmrref - (float) nmrptr->nucshld[i]));
64594 		if (dfrq == dfrqmn) {
64595 		    xyzp->iaton[i] = 3;
64596 		}
64597 	    }
64598 	}
64599 
64600 	update_sel = 1;
64601 	update_model = 0;
64602 	update_struct();
64603     }
64604 
64605 }
64606 
FRQextr()64607 void FRQextr()
64608 {
64609     int i;
64610 
64611     min_freq = 100000;
64612     max_freq = -100000;
64613     for (i=0; i < npks; i++) {
64614 	   if (spfrq[i] < min_freq) min_freq = (int) spfrq[i];
64615 	   if (spfrq[i] > max_freq) max_freq = (int) spfrq[i];
64616     }
64617     if (min_freq > 0) min_freq = 0;
64618 
64619     if (spmode) {
64620 	if (max_freq < 220) max_freq = 220;
64621     } else {
64622 	if (max_freq < 10) max_freq = 10;
64623     }
64624 }
64625 
getrad(t,coo,iatoms,dret)64626 void getrad(t,coo,iatoms,dret)
64627 double *t;
64628 double* coo;
64629 int *iatoms;
64630 double *dret;
64631 {
64632    double d2,dx,dmx;
64633    int j,k;
64634 
64635    dmx = 0.0;
64636 
64637    for (j=0; j < *iatoms; j++ ) {
64638 	d2 = 0.0;
64639 	for (k = 0; k < 3; k++) {
64640 	    dx = t[k] - coo[j*3+k];
64641 	    d2 = d2 + dx*dx;
64642 	}
64643 	if (d2 > dmx) dmx = d2;
64644    }
64645    dmx = sqrt(dmx);
64646    *dret = dmx;
64647 }
64648 
64649 /*
64650 prtcad_()
64651 {
64652    prtcal_(calfptr->icalf,&calfptr->ncalf,calfptr->ianf,calfptr->islu,
64653 	&calfptr->nchain,calfptr->iamino,calfptr->isal);
64654 }
64655 */
64656 
setiat(int iatoms)64657 void setiat(int iatoms)
64658 {
64659 #if defined(VMS) || defined(UNDERSC)
64660    setatms(&iatoms);
64661 #else
64662 #ifdef CRAY
64663    SETATMS(&iatoms);
64664 #else
64665    setatms_(&iatoms);
64666 #endif
64667 #endif
64668 }
64669 
prt_(iop,iatoms)64670 void prt_(iop,iatoms)
64671 int *iop;
64672 int *iatoms;
64673 {
64674    int i,it,j,k;
64675 
64676    fprintf(stderr,"%d iatoms %d \n",*iop,*iatoms);
64677 /*
64678    it = calfptr->icalf[12][0]-1;
64679    fprintf(stderr,"%d icalf(1,13) %d coo %f  %f %f\n",*iop,it+1,
64680 			xyzp->coo[it*3],xyzp->coo[it*3+1],
64681 			xyzp->coo[it*3+2]);
64682    fprintf(stderr,"%d ATMsel %d coo %f  %f %f\n",*iop,ATMsel+1,
64683 			xyzp->coo[ATMsel*3],xyzp->coo[ATMsel*3+1],
64684 			xyzp->coo[ATMsel*3+2]);
64685 */
64686 
64687 }
64688 
64689 #ifdef DOGL
64690 
DrCircle(int cx,int cy,float r,int nseg)64691 void DrCircle(int cx,int cy,float r,int nseg)
64692 {
64693 	float c,s,t,x,y,angle;
64694 	int i;
64695 
64696 	angle = 2*3.1415926 / (float) nseg;
64697 	c = cosf(angle);
64698 	s = sinf(angle);
64699 
64700 	if (*persp) {
64701 	   x = 0.5*height*r/(float) posptr->zv;
64702 	} else {
64703 	   x = 0.5*height*r/(float) scalptr->scal;
64704 	}
64705 
64706         y = 0;
64707 
64708 	glMatrixMode (GL_MODELVIEW);
64709 	glLoadIdentity();
64710 	glMatrixMode (GL_PROJECTION);
64711 	glLoadIdentity();
64712 	gluOrtho2D(0.0, width, 0.0, height);
64713 	glDisable(GL_LIGHTING);
64714 	glDisable(GL_DEPTH_TEST);
64715 	glDisable(GL_COLOR_MATERIAL);
64716 	glLineStipple(4,0xAAAA);
64717 	glEnable(GL_LINE_STIPPLE);
64718 
64719         glColor3f(1.0, 1.0, 1.0);
64720 	glBegin(GL_LINE_LOOP);
64721 
64722 	for(i = 0; i < nseg; i++) {
64723 	   glVertex2f(x + (float) cx,height - (y + (float) cy));
64724 
64725 	   t = x;
64726 	   x = c * x - s * y;
64727 	   y = s * t + c * y;
64728 	}
64729 
64730 	glEnd();
64731 	glDisable(GL_LINE_STIPPLE);
64732 }
64733 
rubber(iopt)64734 void rubber(iopt)
64735 int iopt;
64736 {
64737    GLfloat x1,y1,x2,y2;
64738    int v2dx,v2dy;
64739 
64740    glDisable(GL_LIGHTING);
64741    glDisable(GL_DEPTH_TEST);
64742    glDepthMask(GL_FALSE);
64743 
64744    glLineWidth(1.0);
64745 
64746    glMatrixMode(GL_MODELVIEW);
64747    glLoadIdentity();
64748    glMatrixMode(GL_PROJECTION);
64749    glLoadIdentity();
64750 
64751    gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
64752    glRasterPos2f(-1.0,-1.0);
64753 
64754    if (iopt) {
64755 	v2dx = width;
64756 	v2dy = height;
64757    } else {
64758 	v2dx = width;
64759 	v2dy = width;
64760 	if (v2dx > height) {
64761 	   v2dx = height;
64762 	   v2dy = height;
64763 	}
64764    }
64765 
64766    glReadBuffer(GL_BACK);
64767    glDrawBuffer(GL_FRONT);
64768    glCopyPixels(0,0,v2dx,v2dy,GL_COLOR);
64769    glFlush();
64770 
64771    x1 = 2.0*((float) ZoomX1/(float) v2dx) - 1.0;
64772    y1 = 2.0*((float) (v2dy - ZoomY1 )/(float) v2dy) - 1.0;
64773    x2 = 2.0*( ((float) ZoomX1 + (float) ZoomW)/(float) v2dx) - 1.0;
64774    y2 = 2.0*( ((float) v2dy - (float) ZoomY1 - (float) ZoomH) /(float) v2dy) - 1.0;
64775    glDisable(GL_COLOR_MATERIAL);
64776 
64777    if (StarNet) {
64778 	   theDens = glGenLists(1);
64779 	   glNewList(theDens, GL_COMPILE_AND_EXECUTE);
64780    }
64781 
64782    glBegin(GL_LINE_LOOP);
64783    glColor3f(1.0f, 1.0f, 1.0f);
64784    glVertex2f(x1,y1);
64785    glVertex2f(x2,y1);
64786    glVertex2f(x2,y2);
64787    glVertex2f(x1,y2);
64788    glVertex2f(x1,y1);
64789    glEnd();
64790 
64791    if (StarNet) {
64792 	glEndList();
64793 	glDeleteLists(theDens,1);
64794    }
64795 
64796    glFlush();
64797    glDrawBuffer(GL_BACK);
64798 
64799    glEnable(GL_DEPTH_TEST);
64800    glDepthMask(GL_TRUE);
64801    glEnable(GL_LIGHTING);
64802 
64803    glMatrixMode (GL_PROJECTION);
64804    glPopMatrix();
64805    glMatrixMode(GL_MODELVIEW);
64806    glPopMatrix();
64807 
64808 }
64809 
plcnrm()64810 void plcnrm()
64811 {
64812    int isrf,i,j;
64813    float n[3],v[3];
64814    isrf = NSurf[istruct]-1;
64815 
64816    theNorm = glGenLists(1);
64817    glNewList(theNorm, GL_COMPILE);
64818    glDisable(GL_LIGHTING);
64819    glLineWidth(1.0);
64820    glEnable(GL_LINE_SMOOTH);
64821    glBegin(GL_LINES);
64822 
64823    for (i = 0; i < nvert[istruct][isrf]; i++) {
64824 	if (srfvert[istruct][isrf][i].type == 1) {
64825 	   v[0] = srfvert[istruct][isrf][i].vert[0];
64826 	   v[1] = srfvert[istruct][isrf][i].vert[1];
64827 	   v[2] = srfvert[istruct][isrf][i].vert[2];
64828 	   glVertex3d(v[0],v[1],v[2]);
64829 	   for (j = 0; j < 3; j++) v[j] = v[j] + n[j];
64830 	   glVertex3d(v[0],v[1],v[2]);
64831 /*	   fprintf(stderr,"1 %f %f %f\n",v[0],v[1],v[2]);*/
64832 	} else {
64833 	   n[0] = srfvert[istruct][isrf][i].vert[0];
64834 	   n[1] = srfvert[istruct][isrf][i].vert[1];
64835 	   n[2] = srfvert[istruct][isrf][i].vert[2];
64836 /*	   fprintf(stderr,"0 %f %f %f\n",n[0],n[1],n[2]);*/
64837 	}
64838    }
64839 
64840    glEnd();
64841    glEnable(GL_LIGHTING);
64842    glEndList();
64843 }
64844 
64845 
64846 
64847 typedef struct {
64848 	unsigned char idLength;
64849 	unsigned char colorMapType;
64850 	unsigned char imageTypeCode;
64851 	unsigned char colorMapSpec[5];
64852 	unsigned short xOrigin;
64853 	unsigned short yOrigin;
64854 	unsigned short width;
64855 	unsigned short height;
64856 	unsigned char bpp;
64857 	unsigned char imageDesc;
64858 } tga_header;
64859 
64860 tga_header tgaheader;
64861 static FILE *TGAFile;
64862 unsigned char *imageData;
64863 
Load_TGA(filename)64864 void Load_TGA(filename)
64865     char *filename;
64866 {
64867     int i;
64868     unsigned int color_mode=GL_RGB;
64869 
64870     TGAFile = fopen(filename,"r");
64871 
64872     if (!TGAFile) {
64873 	fprintf(stderr,"Output Error: Unable to read TGA file %s\n",filename);
64874 	return;
64875     }
64876 
64877     if (fread((char *) &tgaheader, 18, 1, TGAFile) != 1)
64878        fprintf(stderr,"error reading header\n");
64879 
64880     int imageSize = tgaheader.width * tgaheader.height * (tgaheader.bpp/8);
64881     imageData = (unsigned char *) malloc(imageSize);
64882 
64883     fprintf(stderr,"tga: width %d height %d bpp %d\n",tgaheader.width,tgaheader.height,tgaheader.bpp);
64884 
64885     if (fread((char *) imageData, sizeof(char)*imageSize, 1, TGAFile) != 1)
64886 	fprintf(stderr,"error reading tga data\n");
64887 
64888     if (tgaheader.bpp == 24) {
64889 	for (i = 0; i < imageSize; i+=3) {
64890 	   char c = imageData[i];
64891 	   imageData[i] = imageData[i+2];
64892 	   imageData[i+2] = c;
64893 	}
64894     } else {
64895 	if (tgaheader.bpp == 32) {
64896 	   for (i = 0; i < imageSize; i+=4) {
64897 		char c = imageData[i];
64898 		imageData[i] = imageData[i+2];
64899 		imageData[i+2] = c;
64900 	   }
64901 	   color_mode = GL_RGBA;
64902 	}
64903     }
64904 
64905     fclose(TGAFile);
64906 
64907     glGenTextures(1,(GLuint *) &rndid);
64908     glBindTexture(GL_TEXTURE_2D,rndid);
64909 
64910     glTexImage2D(GL_TEXTURE_2D,0,color_mode,tgaheader.width,tgaheader.height,
64911 	0,color_mode,GL_UNSIGNED_BYTE,imageData);
64912 
64913 }
64914 
64915 #else
plcnrm()64916 void plcnrm()
64917 {
64918 }
64919 #endif
64920 
64921 
64922 static float B1[3],B2[3],B3[3],ORI[3];
64923 static float Bt1[3],Bt2[3],Bt3[3],ORI2[3];
64924 
64925 typedef struct {
64926 		int type;
64927 		int n;
64928 		float v1[3];
64929 		float v2[3];
64930 		float polar1;
64931 		float polar2;
64932 		float azimuth1;
64933 		float azimuth2;
64934 		float polarb1;
64935 		float polarb2;
64936 		float azimuthb1;
64937 		float azimuthb2;
64938 		float radius;
64939 		float rp;
64940 		float maxarc[2];
64941 		float ene;
64942 		float chgsc[2];
64943 		float dissc[2];
64944 		float angsc[3];
64945 		float center[3];
64946 		} AREASTRU;
64947 
64948 #define EHBOND  -2.35
64949 #define EVDW    -0.35
64950 #define RHBOND1  1.9
64951 #define RHBOND2  1.8
64952 #define RVDW1    4.0
64953 #define RVDW2    4.5
64954 #define RVDW3    4.8
64955 #define DELHBOND 1.2
64956 #define DELVDW   1.6
64957 
64958 
64959 static AREASTRU EMPT = {0,0,
64960 			{0.0,0.0,0.0},{0.0,0.0,0.0},
64961 			0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
64962 			RHBOND2,RHBOND2,{DELHBOND,DELHBOND},EHBOND,
64963 			{0.0,0.0},{0.0,0.0},
64964 			{0.0,0.0,0.0},{0.0,0.0,0.0}};
64965 
64966 static AREASTRU COOmin = {1,3,
64967 			{-1.0,0.0,0.0},{0.0,1.0,0.0},
64968 			-50.0,50.0,40.0,80.0,130.0,230.0,40.0,80.0,
64969 			RHBOND2,RHBOND2,{DELHBOND,DELHBOND},EHBOND,
64970 			{1.766,-0.15},{0.3,0.7},
64971 			{20.0,60.0,1.0},{0.0,0.0,0.0}};
64972 
64973 static AREASTRU CO = {2,2,
64974 			{-1.0,0.0,0.0},{0.0,0.0,0.0},
64975 			0.0,70.0,0.0,0.0,0.0,0.0,0.0,0.0,
64976 			RHBOND1,RHBOND1,{DELHBOND,DELHBOND},EHBOND,
64977 			{1.766,-0.15},{0.3,0.7},
64978 			{5.0,70.0,1.0},{0.0,0.0,0.0}};
64979 
64980 static AREASTRU ONH = {2,2,
64981 			{-1.0,0.0,0.0},{0.0,0.0,0.0},
64982 			0.0,70.0,0.0,0.0,0.0,0.0,0.0,0.0,
64983 			RHBOND1,RHBOND1,{DELHBOND,DELHBOND},EHBOND,
64984 			{1.766,-0.15},{0.3,0.7},
64985 			{0.0,50.0,0.6},{0.0,0.0,0.0}};
64986 
64987 static AREASTRU NHP = {2,2,
64988 			{-1.0,0.0,0.0},{0.0,0.0,0.0},
64989 			0.0,40.0,0.0,0.0,0.0,0.0,0.0,0.0,
64990 			RHBOND2,RHBOND2,{DELHBOND,DELHBOND},EHBOND,
64991 			{1.766,-0.15},{0.3,0.7},
64992 			{0.0,50.0,0.6},{0.0,0.0,0.0}};
64993 
64994 static AREASTRU NARYL = {5,3,
64995 			{-1.0,-1.0,0.0},{0.0,0.0,0.0},
64996 			0.0,40.0,0.0,0.0,0.0,0.0,0.0,0.0,
64997 			RHBOND1,RHBOND1,{DELHBOND,DELHBOND},EHBOND,
64998 			{1.766,-0.15},{0.3,0.7},
64999 			{20.0,60.0,1.0},{0.0,0.0,0.0}};
65000 
65001 static AREASTRU AMID1 = {5,3,
65002 			{0.0,0.0,1.0},{0.0,0.0,0.0},
65003 			0.0,35.0,0.0,0.0,0.0,0.0,0.0,0.0,
65004 			RVDW1,RVDW1,{DELVDW,DELVDW},EVDW,
65005 			{1.0,0.0},{0.6,1.0},
65006 			{0.0,55.0,1.0},{0.5,0.0,0.0}};
65007 
65008 static AREASTRU AMID2 = {5,3,
65009 			{0.0,0.0,-1.0},{0.0,0.0,0.0},
65010 			0.0,35.0,0.0,0.0,0.0,0.0,0.0,0.0,
65011 			RVDW1,RVDW1,{DELVDW,DELVDW},EVDW,
65012 			{1.0,0.0},{0.6,1.0},
65013 			{0.0,55.0,1.0},{0.5,0.0,0.0}};
65014 
65015 static AREASTRU NAMINO = {6,4,
65016 			{-1.0,-1.0,-1.0},{0.0,0.0,0.0},
65017 			0.0,40.0,0.0,0.0,0.0,0.0,0.0,0.0,
65018 			RHBOND1,RHBOND1,{DELHBOND,DELHBOND},EHBOND,
65019 			{1.0,0.0},{0.3,0.7},
65020 			{20.0,60.0,1.0},{0.0,0.0,0.0}};
65021 
65022 static AREASTRU SPH1 = {3,1,
65023 			{0.0,0.0,0.0},{0.0,0.0,0.0},
65024 			0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
65025 			RVDW1,RVDW1,{DELVDW,DELVDW},EVDW,
65026 			{1.0,0.0},{-1.0,-1.0},
65027 			{0.0,360.0,0.0},{0.0,0.0,0.0}};
65028 static AREASTRU SPH2 = {3,1,
65029 			{0.0,0.0,0.0},{0.0,0.0,0.0},
65030 			0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
65031 			RVDW3,RVDW3,{DELVDW,DELVDW},EVDW,
65032 			{1.0,0.0},{-1.0,-1.0},
65033 			{0.0,360.0,0.0},{0.0,0.0,0.0}};
65034 static AREASTRU CH3_PHE = {3,1,
65035 			{0.0,0.0,0.0},{0.0,0.0,0.0},
65036 			0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
65037 			RVDW2,RVDW1,{DELVDW,DELVDW},EVDW,
65038 			{1.0,0.0},{0.6,1.0},
65039 			{0.0,360.0,0.0},{0.0,0.0,0.0}};
65040 static AREASTRU PHC1 = {4,3,
65041 			{0.0,0.0,1.0},{0.0,0.0,0.0},
65042 			0.0,70.0,0.0,0.0,0.0,0.0,0.0,0.0,
65043 			RVDW2,RVDW2,{DELVDW,DELVDW},EVDW,
65044 			{1.0,0.0},{0.6,1.0},
65045 			{0.0,20.0,1.0},{0.5,0.0,0.0}};
65046 static AREASTRU PHC2 = {4,3,
65047 			{0.0,0.0,-1.0},{0.0,0.0,0.0},
65048 			0.0,70.0,0.0,0.0,0.0,0.0,0.0,0.0,
65049 			RVDW2,RVDW2,{DELVDW,DELVDW},EVDW,
65050 			{1.0,0.0},{0.6,1.0},
65051 			{0.0,20.0,1.0},{0.5,0.0,0.0}};
65052 static AREASTRU PHR = {4,3,
65053 			{-1.0,-1.0,0.0},{0.0,0.0,0.0},
65054 			0.0,60.0,0.0,0.0,0.0,0.0,0.0,0.0,
65055 			RVDW2,RVDW2,{DELVDW,DELVDW},EVDW,
65056 			{1.0,0.0},{0.6,1.0},
65057 			{0.0,30.0,1.0},{0.0,0.0,0.0}};
65058 static AREASTRU OSP3 = {1,3,
65059 			{1.0,0.0,0.0},{0.0,1.0,0.0},
65060 			-80.0,80.0,80.0,150.0,0.0,0.0,0.0,0.0,
65061 			RHBOND1,RHBOND1,{DELHBOND,DELHBOND},EHBOND,
65062 			{1.766,-0.15},{0.3,0.7},
65063 			{0.0,40.0,0.6},{0.0,0.0,0.0}};
65064 static AREASTRU OSP2 = {1,3,
65065 			{1.0,0.0,0.0},{0.0,1.0,0.0},
65066 			-60.0,60.0,90.0,160.0,0.0,0.0,0.0,0.0,
65067 			RHBOND1,RHBOND1,{DELHBOND,DELHBOND},EHBOND,
65068 			{1.766,-0.15},{0.3,0.7},
65069 			{0.0,40.0,0.6},{0.0,0.0,0.0}};
65070 static AREASTRU COC = {7,3,
65071 			{1.0,-1.0,0.0},{1.0,1.0,0.0},
65072 			-80.0,80.0,55.0,125.0,0.0,0.0,0.0,0.0,
65073 			RHBOND1,RHBOND1,{DELHBOND,DELHBOND},EHBOND,
65074 			{1.766,-0.15},{0.3,0.7},
65075 			{75.0,140.0,0.0},{0.0,0.0,0.0}};
65076 
65077 #define H_ACC   0
65078 #define H_DON   1
65079 #define CH      2
65080 #define CH2     3
65081 #define CH3     4
65082 #define PHE_CH3 5
65083 #define ARO     6
65084 #define AMIDE   7
65085 #define SULFUR  8
65086 #define PHENYL_CENTER  9
65087 #define PHENYL_RING   10
65088 #define METAL  11
65089 #define METAL_ACC     12
65090 
65091 // INCRSTRUC explanation:
65092 //
65093 // type: above are the possible values of the 'type' element defined
65094 //
65095 // area: area is the interaction geometry for the interaction
65096 //
65097 // npts: npts is the number of points in the interaction surface array
65098 // points: pointer to the interaction surface array
65099 //
65100 // n = the number of atoms defining this interaction point
65101 // atom[0-3] is the atoms index in the cooordinate array
65102 // c[0-3][3] are the atoms coordinates
65103 //
65104 // for a ligand interaction point these are all defined by a call
65105 // to AllInt()
65106 // for a protein interaction point only the atom coordinates c[0-3][3] are set
65107 // since the rest can be derived through the type element
65108 //
65109 // nfrag: the member 'n' determines the number of atoms thats is used to
65110 //        define the interaction geometry. From this FrgInt() determines
65111 //        the number of different fragments these atoms belong to (nfrag)
65112 //
65113 // frag[0-3]: the fragment index for the max 4 number of fragments
65114 
65115 
65116 typedef struct {
65117 		int type;
65118 		AREASTRU area;
65119 		int ohlig;
65120 		int ohsame;
65121 		double ORI[3];
65122 		double c[4][3];
65123 		double q0;
65124 		double q1;
65125 		double q2;
65126 		double q3;
65127 		int frag[4];
65128 		int nfrag;
65129 		int atom[4];
65130 		int n;
65131 		int npts;
65132 		int link;
65133 		int conf;
65134 		int nconf;
65135 		int ConfArr[200];
65136 		int res;
65137 		double *points;
65138 		} INCRSTRU;
65139 
65140 static INCRSTRU *inttyp[20000];
65141 #define MAXLIGSTRU 10000
65142 static INCRSTRU *ligtyp[MAXLIGSTRU];
65143 static int nintp = 0;
65144 static int lintp = 0;
65145 static int lintconf = 0;
65146 static INCRSTRU modtyp;
65147 void cal_area(INCRSTRU *i);
65148 
65149 typedef struct {
65150 		float d;
65151 		uint16_t grp1;
65152 		uint16_t ind1;
65153 		uint16_t pnt1;
65154 		uint16_t grp2;
65155 		uint16_t ind2;
65156 		uint16_t pnt2;
65157 		} CROSSSTRU;
65158 
65159 typedef struct {
65160 		int ind;
65161 		int n;
65162 		} HASHSTRU;
65163 
65164 typedef struct {
65165 		CROSSSTRU *XDist;
65166 		int l;
65167 		HASHSTRU *XHash;
65168 		int n;
65169 		} GRPSTRU;
65170 
65171 #define MAXTRI 300000
65172 #define MAXSTRI 50000
65173 #define CLOSEC 1.0
65174 #define CLUSRMS  0.1
65175 #define VDWSCAL  0.01
65176 #define MAXSOL  25
65177 
65178 static float vdwscal = 1.0;
65179 
65180 typedef struct {
65181 		float d12;
65182 		float d13;
65183 		float d23;
65184 		float p1[3];
65185 		float p2[3];
65186 		float p3[3];
65187 		int lig[3];
65188 		int ohlig[3];
65189 		int grp[3];
65190 		int atindx[3];
65191 		int frag;
65192 		int frags[3];
65193 		int conf;
65194 		int nconf;
65195 		int ConfArr[200];
65196 		int active;
65197 		} TRISSTRU;
65198 
65199 static TRISSTRU TriS[MAXSTRI];
65200 
65201 static int ntriS = -1;
65202 
65203 // p1c,p2c,p3c contains translated and rotated ligand interaction point
65204 // coordinates
65205 
65206 // P1,P2,P3 contains original untranslated and unrotated ligand interaction
65207 // point coordinates
65208 
65209 typedef struct {
65210 		float d12;
65211 		float d13;
65212 		float d23;
65213 		float p1[3];
65214 		float p2[3];
65215 		float p3[3];
65216 		int lig[3];
65217 		int ohlig[3];
65218 		int prot[3];
65219 		float p1c[3];
65220 		float p2c[3];
65221 		float p3c[3];
65222 		float P1[3];
65223 		float P2[3];
65224 		float P3[3];
65225 		float Cen[3];
65226 		float Out[3];
65227 		float CenO[3];
65228 		float OutO[3];
65229 		float OutOrg[3];
65230 		float e12;
65231 		float eint;
65232 		float etot;
65233 		int frag;
65234 		int frags[3];
65235 		int grp[3];
65236 		int idx[3];
65237 		int triS;
65238 		int conf;
65239 		int nconf;
65240 		double *coo;
65241 		double *oh[3];
65242 		double t[3];
65243 		double R1[4][4];
65244 		double R2[4][4];
65245 		} TRISTRU;
65246 
65247 typedef struct {
65248 		double *coo;
65249 		} CARSTRU;
65250 
65251 static TRISTRU Tri1;
65252 static TRISTRU Tri2;
65253 static TRISTRU EmpTri;
65254 static TRISTRU *TriArr[MAXTRI];
65255 static TRISTRU *TriFin[MAXSTRI];
65256 static TRISTRU *TriArrCopy[MAXTRI];
65257 static CARSTRU *TriC[MAXTRI];
65258 static int ntris = -1;
65259 static int ntrif = -1;
65260 
65261 //  N = number of single bonds to rotate over
65262 //  sng[1..N][0-1] two atoms of each single bond. Set in ProcLig
65263 //  ityp gaff atom type of ligands atoms
65264 //  NFRAG = number of fragments
65265 //  ifrg[1..ndocka] = fragment number for each atom
65266 //  SngFrg[1..N][0-1] the two atoms of each single bond,
65267 //                    the fragment number of each side [0] and [1]
65268 //  FrgSngN[1..NFRAG] = number of rotatable bonds fragment is connected to
65269 //  FrgSng[1..NFRAG][9] = for each fragment, the MAX 9 single bonds pointers
65270 //                        the fragment is connected to
65271 //  irsd[1..ndocka] = sp hybridisation number per atom, f.e. sp3 => 4
65272 //                    SEE IHBT array
65273 //  irng[1..ndocka] = is atom part of a ring =1
65274 
65275 #define MXLIGA 1000
65276 
65277 typedef struct {
65278 		int N;
65279 		int NFRAG;
65280 		int irsd[MXLIGA];
65281 		int irng[MXLIGA];
65282 		int jrng[MXLIGA];
65283 		int ifrg[MXLIGA];
65284 		int sng[MXLIGA][2];
65285 		int dupsng[MXLIGA];
65286 		int sngrot[MXLIGA];
65287 		int SngFrg[MXLIGA][2];
65288 		int FrgSng[MXLIGA][9];
65289 		int FrgSngN[MXLIGA];
65290 		int sngdone[MXLIGA];
65291 		short int ityp[MXLIGA];
65292 		} SNGSTRU;
65293 
65294 static SNGSTRU singleb;
65295 
65296 typedef struct {
65297 		int i;
65298 		int j;
65299 		double dd;
65300 		int stat;
65301 		int *Arr;
65302 		int N;
65303 		} LDAT;
65304 
65305 typedef struct {
65306 		int Num;
65307 		int *Arr;
65308 		int N;
65309 		int CC;
65310 		} NNODE;
65311 
65312 typedef struct node
65313 {
65314     struct node *prev_node;
65315     LDAT info;
65316     struct node *next_node;
65317 } node;
65318 
65319 node *begin=NULL;
65320 
65321 void ogAxs();
65322 void ogAxs2();
65323 void xyzROT4(double R[4][4],float *vt);
65324 void RemCC_One(int L);
65325 void RemCloseC_One(int L,int all);
65326 void Frst_Rot(float *cc,float *uu,double sina,double cosa,double R[4][4]);
65327 void Trans_Tri(TRISTRU *Tri1,TRISTRU *Tri2);
65328 void PrtTrip(int indx,int ligind1,int ligind2);
65329 float CalInt(int ind1,int ind2,double *points,double t[3],double R1[4][4],double R2[4][4],float *OutO, float *OutOrg, int deb);
65330 void dsply_List(node *begin);
65331 void set_List(node *begin,node **barr,int *N,int MXARR);
65332 void replc_List(node *begin,int val,int nval);
65333 void upd_List(node **barr,int *N,node *delnode);
65334 struct node *addtoemptylist(node *begin,LDAT data_element);
65335 struct node *addatendlist(node *begin,LDAT data_element);
65336 struct node *insertdd(node *begin,node **barr,int *N,LDAT data_element);
65337 struct node *deletenode(node *begin,node *delnode,LDAT *data_element,node **barr,int *N);
65338 struct node *dlnode(node *begin,LDAT *data_element);
65339 
65340 /* group R and RH */
65341 static int GrpR[6] = {6,8,7,16,15,9};
65342 static int GrpRH[] = {6,8,7,16,15,9,1};
65343 
65344 static short int Cany[] = {7,6,5,8};
65345 static short int C2ar[] = {8,6};
65346 static short int Nany[] = {12,11,10,13,14,15,16};
65347 static short int N2ar[] = {11,13};
65348 static short int Nplan[] = {14,15};
65349 static short int Oany[] = {18,17,19};
65350 static short int Odbl[] = {18,19};
65351 static short int Sany[] = {23,22,24,25};
65352 static short int Aany[] = {11,13,15,6,8,23};
65353 static short int DONG[] = {18,17,12,11,10,13,14,15,16};
65354 
65355 static int MTXCOO1 = -1;
65356 static int MTXCOO2 = -1;
65357 static int MTXCO1 = -1;
65358 static int MTXCO2 = -1;
65359 static int MTXCO3 = -1;
65360 
65361 
65362 static int isq[6][3] = { 0,1,3, 0,3,1, 1,0,3, 3,0,1, 1,3,0, 3,1,0};
65363 
65364 static float gfvdw[MXGFF][2] = {
65365      {   0.0000, 0.0000},
65366      {   1.9080, 0.0860},
65367      {   1.9080, 0.0860},
65368      {   1.9080, 0.0860},
65369      {   1.9080, 0.1094},
65370      {   1.9080, 0.0860},
65371      {   1.9080, 0.0860},
65372      {   1.9080, 0.0860},
65373      {   1.9080, 0.0860},
65374      {   1.9080, 0.0860},
65375      {   1.9080, 0.0860},
65376      {   1.9080, 0.0860},
65377      {   1.9080, 0.0860},
65378      {   1.9080, 0.0860},
65379      {   1.9080, 0.0860},
65380      {   1.9080, 0.0860},
65381      {   1.9080, 0.0860},
65382      {   1.9080, 0.0860},
65383      {   1.3870, 0.0157},
65384      {   1.2870, 0.0157},
65385      {   1.1870, 0.0157},
65386      {   1.4090, 0.0150},
65387      {   1.3590, 0.0150},
65388      {   1.4590, 0.0150},
65389      {   1.4870, 0.0157},
65390      {   0.6000, 0.0157},
65391      {   0.0000, 0.0000},
65392      {   0.6000, 0.0157},
65393      {   0.6000, 0.0157},
65394      {   0.0000, 0.0000},
65395      {   1.1000, 0.0157},
65396      {   1.75  , 0.061 },
65397      {   1.948 , 0.265 },
65398      {   2.22  , 0.320 },
65399      {   2.35  , 0.40  },
65400      {   1.8240, 0.1700},
65401      {   1.8240, 0.1700},
65402      {   1.8240, 0.1700},
65403      {   1.8240, 0.1700},
65404      {   1.8240, 0.1700},
65405      {   1.8240, 0.1700},
65406      {   1.8240, 0.1700},
65407      {   1.8240, 0.1700},
65408      {   1.8240, 0.1700},
65409      {   1.8240, 0.1700},
65410      {   1.8240, 0.1700},
65411      {   1.8240, 0.1700},
65412      {   1.8240, 0.1700},
65413      {   1.6612, 0.2100},
65414      {   1.7210, 0.2104},
65415      {   1.6837, 0.1700},
65416      {   1.7683, 0.1520},
65417      {   2.1000, 0.2000},
65418      {   2.1000, 0.2000},
65419      {   2.1000, 0.2000},
65420      {   2.1000, 0.2000},
65421      {   2.1000, 0.2000},
65422      {   2.1000, 0.2000},
65423      {   2.1000, 0.2000},
65424      {   2.1000, 0.2000},
65425      {   2.1000, 0.2000},
65426      {   2.1000, 0.2000},
65427      {   2.1000, 0.2000},
65428      {   2.0000, 0.2500},
65429      {   2.0000, 0.2500},
65430      {   2.0000, 0.2500},
65431      {   2.0000, 0.2500},
65432      {   2.0000, 0.2500},
65433      {   2.0000, 0.2500},
65434      {   2.0000, 0.2500},
65435      {   2.0000, 0.2500},
65436      {   1.9080, 0.0860}
65437 };
65438 
65439 #define MXGTOR 638
65440 #define MXTORS 4*NUMATM
65441 
65442 static int gftcon[MXGTOR][4] = {
65443      { 1, 2, 2, 1},
65444      { 1, 2, 3, 1},
65445      { 1, 2,13, 1},
65446      { 1, 2,14, 1},
65447      { 1, 2, 4, 1},
65448      { 1, 2,17, 1},
65449      { 1, 2,18, 1},
65450      { 1, 2,11, 1},
65451      { 1, 2,12, 1},
65452      { 1, 2, 5, 1},
65453      { 1, 2,15, 1},
65454      { 1, 2,16, 1},
65455      { 1, 2, 6, 1},
65456      { 1, 2, 9, 1},
65457      { 1, 2,10, 1},
65458      { 1, 2,36, 1},
65459      { 1, 2,38, 1},
65460      { 1, 2,43, 1},
65461      { 1, 2,44, 1},
65462      { 1, 2,45, 1},
65463      { 1, 2,46, 1},
65464      { 1, 2,41, 1},
65465      { 1, 2,48, 1},
65466      { 1, 2,50, 1},
65467      { 1, 2,51, 1},
65468      { 1, 2,58, 1},
65469      { 1, 2,53, 1},
65470      { 1, 2,58, 1},
65471      { 1, 2,59, 1},
65472      { 1, 2,60, 1},
65473      { 1, 2,61, 1},
65474      { 1, 2,54, 1},
65475      { 1, 2,55, 1},
65476      { 1, 2,62, 1},
65477      { 1, 2,56, 1},
65478      { 1, 2,63, 1},
65479      { 1, 2,68, 1},
65480      { 1, 2,69, 1},
65481      { 1, 2,66, 1},
65482      { 1, 2,70, 1},
65483      { 1, 2,67, 1},
65484      { 1, 2,71, 1},
65485      { 1, 3, 3, 1},
65486      { 1, 3,13, 1},
65487      { 1, 3,14, 1},
65488      { 1,13,13, 1},
65489      { 1,14,14, 1},
65490      { 1,13,14, 1},
65491      { 1, 3, 4, 1},
65492      { 1, 3, 5, 1},
65493      { 1, 3, 6, 1},
65494      { 1, 3, 9, 1},
65495      { 1, 3,10, 1},
65496      { 1, 3,11, 1},
65497      { 1, 3,12, 1},
65498      { 1, 3,17, 1},
65499      { 1, 3,18, 1},
65500      { 1, 3,15, 1},
65501      { 1, 3,16, 1},
65502      { 1, 3,36, 1},
65503      { 1, 3,38, 1},
65504      { 1, 3,39, 1},
65505      { 1, 3,40, 1},
65506      { 1, 3,41, 1},
65507      { 1, 3,42, 1},
65508      { 1, 3,43, 1},
65509      { 1, 3,44, 1},
65510      { 1, 3,45, 1},
65511      { 1, 3,46, 1},
65512      { 1, 3,47, 1},
65513      { 1, 3,48, 1},
65514      { 1, 3,50, 1},
65515      { 1, 3,51, 1},
65516      { 1, 3,53, 1},
65517      { 1, 3,57, 1},
65518      { 1, 3,58, 1},
65519      { 1, 3,59, 1},
65520      { 1, 3,60, 1},
65521      { 1, 3,61, 1},
65522      { 1, 3,54, 1},
65523      { 1, 3,55, 1},
65524      { 1, 3,62, 1},
65525      { 1, 3,56, 1},
65526      { 1, 3,63, 1},
65527      { 1, 3,65, 1},
65528      { 1, 3,68, 1},
65529      { 1, 3,69, 1},
65530      { 1, 3,66, 1},
65531      { 1, 3,70, 1},
65532      { 1, 3,67, 1},
65533      { 1, 3,71, 1},
65534      { 1, 4, 4, 1},
65535      { 1, 4,11, 1},
65536      { 1, 4,12, 1},
65537      { 1,11,12, 1},
65538      { 1,11,11, 1},
65539      { 1,12,12, 1},
65540      { 1, 9,10, 1},
65541      { 1, 9, 9, 1},
65542      { 1,10,10, 1},
65543      { 1, 4, 5, 1},
65544      { 1, 4, 6, 1},
65545      { 1, 4,36, 1},
65546      { 1, 4,38, 1},
65547      { 1, 4,45, 1},
65548      { 1, 4,46, 1},
65549      { 1,11,45, 1},
65550      { 1,12,46, 1},
65551      { 1, 4,43, 1},
65552      { 1, 4,44, 1},
65553      { 1, 9,44, 1},
65554      { 1,10,43, 1},
65555      { 1, 9,43, 1},
65556      { 1,10,44, 1},
65557      { 1, 4,39, 1},
65558      { 1, 4,40, 1},
65559      { 1, 4,41, 1},
65560      { 1, 9,41, 1},
65561      { 1,10,41, 1},
65562      { 1, 4,47, 1},
65563      { 1, 4,48, 1},
65564      { 1, 4,50, 1},
65565      { 1, 4,51, 1},
65566      { 1, 4,53, 1},
65567      { 1, 4,60, 1},
65568      { 1, 4,61, 1},
65569      { 1,11,61, 1},
65570      { 1,11,60, 1},
65571      { 1,12,61, 1},
65572      { 1, 4,58, 1},
65573      { 1, 4,59, 1},
65574      { 1, 9,58, 1},
65575      { 1, 9,59, 1},
65576      { 1,10,58, 1},
65577      { 1,10,59, 1},
65578      { 1, 4,54, 1},
65579      { 1, 4,55, 1},
65580      { 1,11,55, 1},
65581      { 1,12,55, 1},
65582      { 1, 4,62, 1},
65583      { 1,11,62, 1},
65584      { 1,12,62, 1},
65585      { 1, 4,56, 1},
65586      { 1,11,56, 1},
65587      { 1,12,56, 1},
65588      { 1, 4,63, 1},
65589      { 1,11,63, 1},
65590      { 1,12,63, 1},
65591      { 1, 4,68, 1},
65592      { 1, 4,69, 1},
65593      { 1, 4,66, 1},
65594      { 1,11,66, 1},
65595      { 1,12,66, 1},
65596      { 1, 4,70, 1},
65597      { 1,11,70, 1},
65598      { 1,12,70, 1},
65599      { 1, 4,67, 1},
65600      { 1,11,67, 1},
65601      { 1,12,67, 1},
65602      { 1, 4,71, 1},
65603      { 1,11,71, 1},
65604      { 1,12,71, 1},
65605      { 1, 5, 5, 1},
65606      { 1,15,15, 1},
65607      { 1,16,16, 1},
65608      { 1, 5, 6, 1},
65609      { 1, 5,36, 1},
65610      { 1,15,36, 1},
65611      { 1,16,36, 1},
65612      { 1, 5,38, 1},
65613      { 1, 5,45, 1},
65614      { 1, 5,46, 1},
65615      { 1, 5,39, 1},
65616      { 1, 5,40, 1},
65617      { 1, 5,41, 1},
65618      { 1, 5,47, 1},
65619      { 1, 5,48, 1},
65620      { 1, 5,50, 1},
65621      { 1, 5,51, 1},
65622      { 1, 5,53, 1},
65623      { 1, 5,60, 1},
65624      { 1, 5,61, 1},
65625      { 1, 5,54, 1},
65626      { 1, 5,55, 1},
65627      { 1, 5,62, 1},
65628      { 1, 5,56, 1},
65629      { 1, 5,63, 1},
65630      { 1, 5,68, 1},
65631      { 1, 5,69, 1},
65632      { 1, 5,66, 1},
65633      { 1, 5,70, 1},
65634      { 1, 5,67, 1},
65635      { 1, 5,71, 1},
65636      { 1, 5, 9, 1},
65637      { 1, 5,10, 1},
65638      { 1, 6, 6, 1},
65639      { 1, 6, 7, 1},
65640      { 1, 6, 8, 1},
65641      { 1, 7, 7, 1},
65642      { 1, 8, 8, 1},
65643      { 1, 6,36, 1},
65644      { 1, 6,38, 1},
65645      { 1, 6,45, 1},
65646      { 1, 6,46, 1},
65647      { 1, 6,40, 1},
65648      { 1, 6,41, 1},
65649      { 1, 6,42, 1},
65650      { 1, 6,43, 1},
65651      { 1, 6,44, 1},
65652      { 1, 6,47, 1},
65653      { 1, 9,47, 1},
65654      { 1,10,47, 1},
65655      { 1, 6,48, 1},
65656      { 1, 6,50, 1},
65657      { 1, 6,51, 1},
65658      { 1, 6,53, 1},
65659      { 1, 6,60, 1},
65660      { 1, 6,61, 1},
65661      { 1, 6,58, 1},
65662      { 1, 6,59, 1},
65663      { 1, 6,54, 1},
65664      { 1, 6,55, 1},
65665      { 1, 6,62, 1},
65666      { 1, 6,56, 1},
65667      { 1, 6,63, 1},
65668      { 1, 6,68, 1},
65669      { 1, 6,69, 1},
65670      { 1, 6,66, 1},
65671      { 1, 6,70, 1},
65672      { 1, 6,67, 1},
65673      { 1, 6,71, 1},
65674      { 1,36, 9, 1},
65675      { 1,36,10, 1},
65676      { 1,36,36, 1},
65677      { 1,36,38, 1},
65678      { 1,36,45, 1},
65679      { 1,36,46, 1},
65680      { 1,36,39, 1},
65681      { 1,36,40, 1},
65682      { 1,36,41, 1},
65683      { 1,36,43, 1},
65684      { 1,36,44, 1},
65685      { 1,36,47, 1},
65686      { 1,36,48, 1},
65687      { 1,36,50, 1},
65688      { 1,36,51, 1},
65689      { 1,36,53, 1},
65690      { 1,36,60, 1},
65691      { 1,36,61, 1},
65692      { 1,36,58, 1},
65693      { 1,36,59, 1},
65694      { 1,36,54, 1},
65695      { 1,36,55, 1},
65696      { 1,36,62, 1},
65697      { 1,36,56, 1},
65698      { 1,36,63, 1},
65699      { 1,36,68, 1},
65700      { 1,36,69, 1},
65701      { 1,36,66, 1},
65702      { 1,36,70, 1},
65703      { 1,36,67, 1},
65704      { 1,36,71, 1},
65705      { 1,37, 4, 1},
65706      { 1,37, 5, 1},
65707      { 1,37, 6, 1},
65708      { 1,37, 9, 1},
65709      { 1,37,10, 1},
65710      { 1,37,11, 1},
65711      { 1,37,12, 1},
65712      { 1,37,17, 1},
65713      { 1,37,18, 1},
65714      { 1,37,15, 1},
65715      { 1,37,16, 1},
65716      { 1,37,36, 1},
65717      { 1,37,37, 1},
65718      { 1,37,38, 1},
65719      { 1,37,39, 1},
65720      { 1,37,40, 1},
65721      { 1,37,41, 1},
65722      { 1,37,42, 1},
65723      { 1,37,43, 1},
65724      { 1,37,44, 1},
65725      { 1,37,45, 1},
65726      { 1,37,46, 1},
65727      { 1,37,47, 1},
65728      { 1,37,48, 1},
65729      { 1,37,50, 1},
65730      { 1,37,51, 1},
65731      { 1,37,53, 1},
65732      { 1,37,57, 1},
65733      { 1,37,58, 1},
65734      { 1,37,59, 1},
65735      { 1,37,60, 1},
65736      { 1,37,61, 1},
65737      { 1,37,54, 1},
65738      { 1,37,55, 1},
65739      { 1,37,62, 1},
65740      { 1,37,56, 1},
65741      { 1,37,63, 1},
65742      { 1,37,65, 1},
65743      { 1,37,68, 1},
65744      { 1,37,69, 1},
65745      { 1,37,66, 1},
65746      { 1,37,70, 1},
65747      { 1,37,67, 1},
65748      { 1,37,71, 1},
65749      { 1,38,38, 1},
65750      { 1,38,45, 1},
65751      { 1,38,46, 1},
65752      { 1,45,46, 1},
65753      { 1,45,45, 1},
65754      { 1,46,46, 1},
65755      { 1,43,43, 1},
65756      { 1,44,44, 1},
65757      { 1,43,44, 1},
65758      { 1,38,43, 1},
65759      { 1,38,44, 1},
65760      { 1,38,39, 1},
65761      { 1,45,39, 1},
65762      { 1,46,39, 1},
65763      { 1,38,40, 1},
65764      { 1,45,40, 1},
65765      { 1,46,40, 1},
65766      { 1,38,41, 1},
65767      { 1,45,41, 1},
65768      { 1,46,41, 1},
65769      { 1,41,43, 1},
65770      { 1,41,44, 1},
65771      { 1,38,47, 1},
65772      { 1,45,47, 1},
65773      { 1,46,47, 1},
65774      { 1,38,48, 1},
65775      { 1,45,48, 1},
65776      { 1,46,48, 1},
65777      { 1,38,50, 1},
65778      { 1,45,50, 1},
65779      { 1,46,50, 1},
65780      { 1,38,51, 1},
65781      { 1,45,51, 1},
65782      { 1,46,51, 1},
65783      { 1,43,51, 1},
65784      { 1,43,69, 1},
65785      { 1,38,53, 1},
65786      { 1,38,60, 1},
65787      { 1,38,61, 1},
65788      { 1,45,61, 1},
65789      { 1,38,58, 1},
65790      { 1,38,59, 1},
65791      { 1,43,53, 1},
65792      { 1,44,53, 1},
65793      { 1,43,58, 1},
65794      { 1,44,59, 1},
65795      { 1,44,58, 1},
65796      { 1,43,59, 1},
65797      { 1,45,60, 1},
65798      { 1,46,61, 1},
65799      { 1,38,54, 1},
65800      { 1,38,55, 1},
65801      { 1,45,55, 1},
65802      { 1,46,55, 1},
65803      { 1,38,56, 1},
65804      { 1,45,56, 1},
65805      { 1,46,56, 1},
65806      { 1,45,62, 1},
65807      { 1,46,62, 1},
65808      { 1,38,68, 1},
65809      { 1,45,68, 1},
65810      { 1,46,68, 1},
65811      { 1,38,69, 1},
65812      { 1,45,69, 1},
65813      { 1,46,69, 1},
65814      { 1,38,66, 1},
65815      { 1,45,70, 1},
65816      { 1,46,70, 1},
65817      { 1,38,67, 1},
65818      { 1,45,71, 1},
65819      { 1,46,71, 1},
65820      { 1,39,39, 1},
65821      { 1,39,40, 1},
65822      { 1,39,41, 1},
65823      { 1,39,47, 1},
65824      { 1,39,48, 1},
65825      { 1,39,50, 1},
65826      { 1,39,51, 1},
65827      { 1,39,53, 1},
65828      { 1,39,60, 1},
65829      { 1,39,61, 1},
65830      { 1,39,54, 1},
65831      { 1,39,55, 1},
65832      { 1,39,62, 1},
65833      { 1,39,56, 1},
65834      { 1,39,63, 1},
65835      { 1,39,68, 1},
65836      { 1,39,69, 1},
65837      { 1,39,66, 1},
65838      { 1,39,70, 1},
65839      { 1,39,67, 1},
65840      { 1,39,71, 1},
65841      { 1,40,40, 1},
65842      { 1,40,41, 1},
65843      { 1,40,47, 1},
65844      { 1,40,48, 1},
65845      { 1,40,50, 1},
65846      { 1,40,51, 1},
65847      { 1,40,53, 1},
65848      { 1,40,60, 1},
65849      { 1,40,61, 1},
65850      { 1,40,54, 1},
65851      { 1,40,55, 1},
65852      { 1,40,62, 1},
65853      { 1,40,56, 1},
65854      { 1,40,63, 1},
65855      { 1,40,68, 1},
65856      { 1,40,69, 1},
65857      { 1,40,66, 1},
65858      { 1,40,70, 1},
65859      { 1,40,67, 1},
65860      { 1,40,71, 1},
65861      { 1,41,41, 1},
65862      { 1,41,47, 1},
65863      { 1,41,48, 1},
65864      { 1,41,50, 1},
65865      { 1,41,51, 1},
65866      { 1,41,53, 1},
65867      { 1,41,60, 1},
65868      { 1,41,61, 1},
65869      { 1,41,54, 1},
65870      { 1,41,55, 1},
65871      { 1,41,62, 1},
65872      { 1,41,56, 1},
65873      { 1,41,63, 1},
65874      { 1,41,68, 1},
65875      { 1,41,69, 1},
65876      { 1,41,66, 1},
65877      { 1,41,70, 1},
65878      { 1,41,67, 1},
65879      { 1,41,71, 1},
65880      { 1,47,47, 1},
65881      { 1,47,48, 1},
65882      { 1,47,50, 1},
65883      { 1,47,51, 1},
65884      { 1,47,53, 1},
65885      { 1,47,60, 1},
65886      { 1,47,61, 1},
65887      { 1,47,54, 1},
65888      { 1,47,55, 1},
65889      { 1,47,62, 1},
65890      { 1,47,56, 1},
65891      { 1,47,63, 1},
65892      { 1,47,68, 1},
65893      { 1,47,69, 1},
65894      { 1,47,66, 1},
65895      { 1,47,70, 1},
65896      { 1,47,67, 1},
65897      { 1,47,71, 1},
65898      { 1,48,48, 1},
65899      { 1,48,50, 1},
65900      { 1,48,51, 1},
65901      { 1,48,53, 1},
65902      { 1,48,60, 1},
65903      { 1,48,61, 1},
65904      { 1,48,54, 1},
65905      { 1,48,55, 1},
65906      { 1,48,62, 1},
65907      { 1,48,56, 1},
65908      { 1,48,63, 1},
65909      { 1,48,68, 1},
65910      { 1,48,69, 1},
65911      { 1,48,66, 1},
65912      { 1,48,70, 1},
65913      { 1,48,67, 1},
65914      { 1,48,71, 1},
65915      { 1,50,50, 1},
65916      { 1,50,51, 1},
65917      { 1,50,53, 1},
65918      { 1,50,60, 1},
65919      { 1,50,61, 1},
65920      { 1,50,54, 1},
65921      { 1,50,55, 1},
65922      { 1,50,62, 1},
65923      { 1,50,56, 1},
65924      { 1,50,63, 1},
65925      { 1,50,68, 1},
65926      { 1,50,69, 1},
65927      { 1,50,66, 1},
65928      { 1,50,70, 1},
65929      { 1,50,67, 1},
65930      { 1,50,71, 1},
65931      { 1,51,51, 1},
65932      { 1,51,69, 1},
65933      { 1,51,68, 1},
65934      { 1,51,66, 1},
65935      { 1,51,70, 1},
65936      { 1,51,67, 1},
65937      { 1,51,71, 1},
65938      { 1,51,53, 1},
65939      { 1,51,60, 1},
65940      { 1,51,61, 1},
65941      { 1,51,54, 1},
65942      { 1,51,55, 1},
65943      { 1,51,62, 1},
65944      { 1,51,56, 1},
65945      { 1,51,63, 1},
65946      { 1,53,53, 1},
65947      { 1,53,60, 1},
65948      { 1,53,61, 1},
65949      { 1,53,58, 1},
65950      { 1,53,59, 1},
65951      { 1,60,60, 1},
65952      { 1,61,61, 1},
65953      { 1,58,58, 1},
65954      { 1,59,59, 1},
65955      { 1,58,59, 1},
65956      { 1,53,54, 1},
65957      { 1,60,54, 1},
65958      { 1,61,54, 1},
65959      { 1,53,55, 1},
65960      { 1,60,62, 1},
65961      { 1,61,62, 1},
65962      { 1,53,56, 1},
65963      { 1,60,63, 1},
65964      { 1,61,63, 1},
65965      { 1,53,68, 1},
65966      { 1,60,68, 1},
65967      { 1,61,68, 1},
65968      { 1,53,69, 1},
65969      { 1,60,69, 1},
65970      { 1,61,69, 1},
65971      { 1,53,66, 1},
65972      { 1,60,70, 1},
65973      { 1,61,70, 1},
65974      { 1,53,67, 1},
65975      { 1,60,71, 1},
65976      { 1,61,71, 1},
65977      { 1,54,54, 1},
65978      { 1,54,55, 1},
65979      { 1,54,62, 1},
65980      { 1,54,56, 1},
65981      { 1,54,63, 1},
65982      { 1,54,68, 1},
65983      { 1,54,69, 1},
65984      { 1,54,66, 1},
65985      { 1,54,70, 1},
65986      { 1,54,67, 1},
65987      { 1,54,71, 1},
65988      { 1,55,55, 1},
65989      { 1,62,62, 1},
65990      { 1,55,56, 1},
65991      { 1,62,63, 1},
65992      { 1,55,66, 1},
65993      { 1,62,70, 1},
65994      { 1,55,67, 1},
65995      { 1,62,71, 1},
65996      { 1,55,68, 1},
65997      { 1,62,68, 1},
65998      { 1,55,69, 1},
65999      { 1,62,69, 1},
66000      { 1,56,56, 1},
66001      { 1,63,63, 1},
66002      { 1,56,68, 1},
66003      { 1,63,68, 1},
66004      { 1,56,69, 1},
66005      { 1,63,69, 1},
66006      { 1,56,66, 1},
66007      { 1,63,70, 1},
66008      { 1,56,67, 1},
66009      { 1,63,71, 1},
66010      { 1,68,68, 1},
66011      { 1,68,69, 1},
66012      { 1,68,66, 1},
66013      { 1,68,70, 1},
66014      { 1,68,67, 1},
66015      { 1,68,71, 1},
66016      { 1,69,69, 1},
66017      { 1,69,66, 1},
66018      { 1,69,70, 1},
66019      { 1,69,67, 1},
66020      { 1,69,71, 1},
66021      { 1,66,66, 1},
66022      { 1,70,70, 1},
66023      { 1,66,67, 1},
66024      { 1,70,71, 1},
66025      { 1,67,67, 1},
66026      { 1,71,71, 1},
66027      { 5, 2,68,29},
66028      { 4, 4,69, 5},
66029      { 4, 4,36, 2},
66030      { 2,36,53, 4},
66031      {36, 5, 2,36},
66032      { 2,36, 5, 2},
66033      { 5, 5,36, 2},
66034      { 5, 5, 2,36},
66035      { 4,45,56,49},
66036      { 4,46,56,49},
66037      {11,45,56,49},
66038      {11,46,56,49},
66039      {12,45,56,49},
66040      {12,46,56,49},
66041      {26,36, 2,49},
66042      { 5,69,69, 5},
66043      { 5,39,47, 6},
66044      { 5,39,56,49},
66045      { 6,47,50,27},
66046      {50,56,51, 5},
66047      {51,56,51, 5},
66048      {19, 5, 2,49},
66049      {25, 5, 2,49},
66050      {25, 5, 5,25},
66051      {25, 5, 5, 5},
66052      {25, 5, 4, 4},
66053      {27,50, 5, 5},
66054      {27,50, 2,49},
66055      { 4, 4, 2,49},
66056      { 5, 4, 4, 5},
66057      { 5, 5, 5, 5},
66058      { 5, 5,39, 5},
66059      { 5, 5,51, 5},
66060      { 5, 5,51, 2},
66061      { 5,51, 5,51},
66062      { 5,51, 5,41},
66063      {49, 2,51, 5},
66064      {51, 5,41, 4},
66065      {51, 5, 5,51},
66066      {51, 5, 5,50},
66067      {50, 5, 5,50},
66068      {32, 5, 5,32},
66069      {33, 5, 5,33},
66070      {34, 5, 5,34},
66071      {19, 5, 5,51},
66072      {19, 5, 5,50},
66073      {19, 5, 5,32},
66074      {19, 5, 5,33},
66075      {19, 5, 5,34},
66076      {25, 5, 5,51},
66077      {25, 5, 5,50},
66078      {25, 5, 5,32},
66079      {25, 5, 5,33},
66080      {25, 5, 5,34}
66081 };
66082 
66083 static float gftor1[MXGTOR][2] = {
66084      {0.00,  0.0},
66085      {0.00,  0.0},
66086      {0.00,  0.0},
66087      {0.00,  0.0},
66088      {0.00,  0.0},
66089      {0.00,  0.0},
66090      {0.00,  0.0},
66091      {0.00,  0.0},
66092      {0.00,  0.0},
66093      {0.00,  0.0},
66094      {0.00,  0.0},
66095      {0.00,  0.0},
66096      {0.00,  0.0},
66097      {0.00,  0.0},
66098      {0.00,  0.0},
66099      {0.00,  0.0},
66100      {0.00,  0.0},
66101      {0.00,  0.0},
66102      {0.00,  0.0},
66103      {0.00,  0.0},
66104      {0.00,  0.0},
66105      {0.00,  0.0},
66106      {0.00,  0.0},
66107      {0.00,  0.0},
66108      {0.00,  0.0},
66109      {0.00,  0.0},
66110      {0.00,  0.0},
66111      {0.00,  0.0},
66112      {0.00,  0.0},
66113      {0.00,  0.0},
66114      {0.00,  0.0},
66115      {0.00,  0.0},
66116      {0.00,  0.0},
66117      {0.00,  0.0},
66118      {0.00,  0.0},
66119      {0.00,  0.0},
66120      {0.00,  0.0},
66121      {0.00,  0.0},
66122      {0.00,  0.0},
66123      {0.00,  0.0},
66124      {0.00,  0.0},
66125      {0.00,  0.0},
66126      {0.00,  0.0},
66127      {0.00,  0.0},
66128      {0.00,  0.0},
66129      {0.00,  0.0},
66130      {0.00,  0.0},
66131      {0.00,  0.0},
66132      {0.00,  0.0},
66133      {0.00,  0.0},
66134      {0.00,  0.0},
66135      {0.00,  0.0},
66136      {0.00,  0.0},
66137      {0.00,  0.0},
66138      {0.00,  0.0},
66139      {0.00,  0.0},
66140      {0.00,  0.0},
66141      {0.00,  0.0},
66142      {0.00,  0.0},
66143      {0.00,  0.0},
66144      {0.00,  0.0},
66145      {0.00,  0.0},
66146      {0.00,  0.0},
66147      {0.00,  0.0},
66148      {0.00,  0.0},
66149      {0.00,  0.0},
66150      {0.00,  0.0},
66151      {0.00,  0.0},
66152      {0.00,  0.0},
66153      {0.00,  0.0},
66154      {0.00,  0.0},
66155      {0.00,  0.0},
66156      {0.00,  0.0},
66157      {0.00,  0.0},
66158      {0.00,  0.0},
66159      {0.00,  0.0},
66160      {0.00,  0.0},
66161      {0.00,  0.0},
66162      {0.00,  0.0},
66163      {0.00,  0.0},
66164      {0.00,  0.0},
66165      {0.00,  0.0},
66166      {0.00,  0.0},
66167      {0.00,  0.0},
66168      {0.00,  0.0},
66169      {0.00,  0.0},
66170      {0.00,  0.0},
66171      {0.00,  0.0},
66172      {0.00,  0.0},
66173      {0.00,  0.0},
66174      {0.00,  0.0},
66175      {0.00,  0.0},
66176      {0.00,  0.0},
66177      {0.00,  0.0},
66178      {0.00,  0.0},
66179      {0.00,  0.0},
66180      {0.00,  0.0},
66181      {0.00,  0.0},
66182      {0.00,  0.0},
66183      {0.00,  0.0},
66184      {0.00,  0.0},
66185      {0.00,  0.0},
66186      {0.00,  0.0},
66187      {0.00,  0.0},
66188      {0.00,  0.0},
66189      {0.00,  0.0},
66190      {0.00,  0.0},
66191      {0.00,  0.0},
66192      {0.00,  0.0},
66193      {0.00,  0.0},
66194      {0.00,  0.0},
66195      {0.00,  0.0},
66196      {0.00,  0.0},
66197      {0.00,  0.0},
66198      {0.00,  0.0},
66199      {0.00,  0.0},
66200      {0.00,  0.0},
66201      {0.00,  0.0},
66202      {0.00,  0.0},
66203      {0.00,  0.0},
66204      {0.00,  0.0},
66205      {0.00,  0.0},
66206      {0.00,  0.0},
66207      {0.00,  0.0},
66208      {0.00,  0.0},
66209      {0.00,  0.0},
66210      {0.00,  0.0},
66211      {0.00,  0.0},
66212      {0.00,  0.0},
66213      {0.00,  0.0},
66214      {0.00,  0.0},
66215      {0.00,  0.0},
66216      {0.00,  0.0},
66217      {0.00,  0.0},
66218      {0.00,  0.0},
66219      {0.00,  0.0},
66220      {0.00,  0.0},
66221      {0.00,  0.0},
66222      {0.00,  0.0},
66223      {0.00,  0.0},
66224      {0.00,  0.0},
66225      {0.00,  0.0},
66226      {0.00,  0.0},
66227      {0.00,  0.0},
66228      {0.00,  0.0},
66229      {0.00,  0.0},
66230      {0.00,  0.0},
66231      {0.00,  0.0},
66232      {0.00,  0.0},
66233      {0.00,  0.0},
66234      {0.00,  0.0},
66235      {0.00,  0.0},
66236      {0.00,  0.0},
66237      {0.00,  0.0},
66238      {0.00,  0.0},
66239      {0.00,  0.0},
66240      {0.00,  0.0},
66241      {0.00,  0.0},
66242      {0.00,  0.0},
66243      {0.00,  0.0},
66244      {0.00,  0.0},
66245      {0.00,  0.0},
66246      {0.00,  0.0},
66247      {0.00,  0.0},
66248      {0.00,  0.0},
66249      {0.00,  0.0},
66250      {0.00,  0.0},
66251      {0.00,  0.0},
66252      {0.00,  0.0},
66253      {0.00,  0.0},
66254      {0.00,  0.0},
66255      {0.00,  0.0},
66256      {0.00,  0.0},
66257      {0.00,  0.0},
66258      {0.00,  0.0},
66259      {0.00,  0.0},
66260      {0.00,  0.0},
66261      {0.00,  0.0},
66262      {0.00,  0.0},
66263      {0.00,  0.0},
66264      {0.00,  0.0},
66265      {0.00,  0.0},
66266      {0.00,  0.0},
66267      {0.00,  0.0},
66268      {0.00,  0.0},
66269      {0.00,  0.0},
66270      {0.00,  0.0},
66271      {0.00,  0.0},
66272      {0.00,  0.0},
66273      {0.00,  0.0},
66274      {0.00,  0.0},
66275      {0.00,  0.0},
66276      {0.00,  0.0},
66277      {0.00,  0.0},
66278      {0.00,  0.0},
66279      {0.00,  0.0},
66280      {0.00,  0.0},
66281      {0.00,  0.0},
66282      {0.00,  0.0},
66283      {0.00,  0.0},
66284      {0.00,  0.0},
66285      {0.00,  0.0},
66286      {0.00,  0.0},
66287      {0.00,  0.0},
66288      {0.00,  0.0},
66289      {0.00,  0.0},
66290      {0.00,  0.0},
66291      {0.00,  0.0},
66292      {0.00,  0.0},
66293      {0.00,  0.0},
66294      {0.00,  0.0},
66295      {0.00,  0.0},
66296      {0.00,  0.0},
66297      {0.00,  0.0},
66298      {0.00,  0.0},
66299      {0.00,  0.0},
66300      {0.00,  0.0},
66301      {0.00,  0.0},
66302      {0.00,  0.0},
66303      {0.00,  0.0},
66304      {0.00,  0.0},
66305      {0.00,  0.0},
66306      {0.00,  0.0},
66307      {0.00,  0.0},
66308      {0.00,  0.0},
66309      {0.00,  0.0},
66310      {0.00,  0.0},
66311      {0.00,  0.0},
66312      {0.00,  0.0},
66313      {0.00,  0.0},
66314      {0.00,  0.0},
66315      {0.00,  0.0},
66316      {0.00,  0.0},
66317      {0.00,  0.0},
66318      {0.00,  0.0},
66319      {0.00,  0.0},
66320      {0.00,  0.0},
66321      {0.00,  0.0},
66322      {0.00,  0.0},
66323      {0.00,  0.0},
66324      {0.00,  0.0},
66325      {0.00,  0.0},
66326      {0.00,  0.0},
66327      {0.00,  0.0},
66328      {0.00,  0.0},
66329      {0.00,  0.0},
66330      {0.00,  0.0},
66331      {0.00,  0.0},
66332      {0.00,  0.0},
66333      {0.00,  0.0},
66334      {0.00,  0.0},
66335      {0.00,  0.0},
66336      {0.00,  0.0},
66337      {0.00,  0.0},
66338      {0.00,  0.0},
66339      {0.00,  0.0},
66340      {0.00,  0.0},
66341      {0.00,  0.0},
66342      {0.00,  0.0},
66343      {0.00,  0.0},
66344      {0.00,  0.0},
66345      {0.00,  0.0},
66346      {0.00,  0.0},
66347      {0.00,  0.0},
66348      {0.00,  0.0},
66349      {0.00,  0.0},
66350      {0.00,  0.0},
66351      {0.00,  0.0},
66352      {0.00,  0.0},
66353      {0.00,  0.0},
66354      {0.00,  0.0},
66355      {0.00,  0.0},
66356      {0.00,  0.0},
66357      {0.00,  0.0},
66358      {0.00,  0.0},
66359      {0.00,  0.0},
66360      {0.00,  0.0},
66361      {0.00,  0.0},
66362      {0.00,  0.0},
66363      {0.00,  0.0},
66364      {0.00,  0.0},
66365      {0.00,  0.0},
66366      {0.00,  0.0},
66367      {0.00,  0.0},
66368      {0.00,  0.0},
66369      {0.00,  0.0},
66370      {0.00,  0.0},
66371      {0.00,  0.0},
66372      {0.00,  0.0},
66373      {0.00,  0.0},
66374      {0.00,  0.0},
66375      {0.00,  0.0},
66376      {0.00,  0.0},
66377      {0.00,  0.0},
66378      {0.00,  0.0},
66379      {0.00,  0.0},
66380      {0.00,  0.0},
66381      {0.00,  0.0},
66382      {0.00,  0.0},
66383      {0.00,  0.0},
66384      {0.00,  0.0},
66385      {0.00,  0.0},
66386      {0.00,  0.0},
66387      {0.00,  0.0},
66388      {0.00,  0.0},
66389      {0.00,  0.0},
66390      {2.80,  0.0},
66391      {2.80,  0.0},
66392      {2.80,  0.0},
66393      {2.80,  0.0},
66394      {0.00,  0.0},
66395      {0.00,  0.0},
66396      {0.00,  0.0},
66397      {0.00,  0.0},
66398      {0.00,  0.0},
66399      {2.80,  0.0},
66400      {2.80,  0.0},
66401      {0.00,  0.0},
66402      {0.00,  0.0},
66403      {0.00,  0.0},
66404      {0.00,  0.0},
66405      {0.00,  0.0},
66406      {0.00,  0.0},
66407      {0.00,  0.0},
66408      {0.00,  0.0},
66409      {0.00,  0.0},
66410      {0.00,  0.0},
66411      {0.00,  0.0},
66412      {0.00,  0.0},
66413      {0.00,  0.0},
66414      {0.00,  0.0},
66415      {0.00,  0.0},
66416      {0.00,  0.0},
66417      {0.00,  0.0},
66418      {0.00,  0.0},
66419      {0.00,  0.0},
66420      {0.00,  0.0},
66421      {0.00,  0.0},
66422      {0.00,  0.0},
66423      {0.00,  0.0},
66424      {0.00,  0.0},
66425      {0.00,  0.0},
66426      {0.00,  0.0},
66427      {0.00,  0.0},
66428      {0.00,  0.0},
66429      {0.00,  0.0},
66430      {0.00,  0.0},
66431      {0.00,  0.0},
66432      {0.00,  0.0},
66433      {0.00,  0.0},
66434      {0.00,  0.0},
66435      {0.00,  0.0},
66436      {0.00,  0.0},
66437      {0.00,  0.0},
66438      {0.60,  0.0},
66439      {0.60,  0.0},
66440      {0.00,  0.0},
66441      {0.00,  0.0},
66442      {0.00,  0.0},
66443      {0.00,  0.0},
66444      {0.00,  0.0},
66445      {0.00,  0.0},
66446      {0.00,  0.0},
66447      {0.00,  0.0},
66448      {0.00,  0.0},
66449      {0.00,  0.0},
66450      {0.00,  0.0},
66451      {0.00,  0.0},
66452      {1.30,180.0},
66453      {1.30,180.0},
66454      {1.30,180.0},
66455      {0.00,  0.0},
66456      {0.00,  0.0},
66457      {0.00,  0.0},
66458      {0.00,  0.0},
66459      {6.80,180.0},
66460      {6.80,180.0},
66461      {0.00,  0.0},
66462      {0.00,  0.0},
66463      {0.00,  0.0},
66464      {0.00,  0.0},
66465      {0.00,  0.0},
66466      {0.00,  0.0},
66467      {0.00,  0.0},
66468      {0.00,  0.0},
66469      {0.00,  0.0},
66470      {0.00,  0.0},
66471      {0.00,  0.0},
66472      {0.00,  0.0},
66473      {0.00,  0.0},
66474      {0.00,  0.0},
66475      {0.00,  0.0},
66476      {0.00,  0.0},
66477      {0.00,  0.0},
66478      {0.00,  0.0},
66479      {0.00,  0.0},
66480      {0.00,  0.0},
66481      {0.00,  0.0},
66482      {0.00,  0.0},
66483      {0.00,  0.0},
66484      {0.00,  0.0},
66485      {0.00,  0.0},
66486      {0.00,  0.0},
66487      {0.00,  0.0},
66488      {0.00,  0.0},
66489      {0.00,  0.0},
66490      {0.00,  0.0},
66491      {0.00,  0.0},
66492      {0.00,  0.0},
66493      {0.00,  0.0},
66494      {0.00,  0.0},
66495      {0.00,  0.0},
66496      {0.00,  0.0},
66497      {0.00,  0.0},
66498      {0.00,  0.0},
66499      {0.00,  0.0},
66500      {0.00,  0.0},
66501      {0.00,  0.0},
66502      {0.00,  0.0},
66503      {0.00,  0.0},
66504      {0.00,  0.0},
66505      {0.00,  0.0},
66506      {0.00,  0.0},
66507      {0.00,  0.0},
66508      {0.00,  0.0},
66509      {0.00,  0.0},
66510      {0.00,  0.0},
66511      {0.00,  0.0},
66512      {0.00,  0.0},
66513      {0.00,  0.0},
66514      {0.00,  0.0},
66515      {0.00,  0.0},
66516      {0.00,  0.0},
66517      {0.00,  0.0},
66518      {0.00,  0.0},
66519      {0.00,  0.0},
66520      {0.00,  0.0},
66521      {0.00,  0.0},
66522      {0.00,  0.0},
66523      {0.00,  0.0},
66524      {1.50,  0.0},
66525      {0.00,  0.0},
66526      {0.00,  0.0},
66527      {0.00,  0.0},
66528      {0.00,  0.0},
66529      {0.00,  0.0},
66530      {0.00,  0.0},
66531      {0.00,  0.0},
66532      {0.00,  0.0},
66533      {0.00,  0.0},
66534      {0.00,  0.0},
66535      {0.00,  0.0},
66536      {0.00,  0.0},
66537      {0.00,  0.0},
66538      {0.00,  0.0},
66539      {0.00,  0.0},
66540      {0.00,  0.0},
66541      {0.00,  0.0},
66542      {0.00,  0.0},
66543      {0.00,  0.0},
66544      {0.00,  0.0},
66545      {0.00,  0.0},
66546      {0.00,  0.0},
66547      {0.00,  0.0},
66548      {0.00,  0.0},
66549      {0.00,  0.0},
66550      {0.00,  0.0},
66551      {0.00,  0.0},
66552      {0.00,  0.0},
66553      {0.00,  0.0},
66554      {0.00,  0.0},
66555      {0.00,  0.0},
66556      {0.00,  0.0},
66557      {0.00,  0.0},
66558      {0.00,  0.0},
66559      {0.00,  0.0},
66560      {0.00,  0.0},
66561      {0.00,  0.0},
66562      {0.70,  0.0},
66563      {0.70,  0.0},
66564      {0.00,  0.0},
66565      {0.00,  0.0},
66566      {0.00,  0.0},
66567      {0.00,  0.0},
66568      {5.00,  0.0},
66569      {5.00,  0.0},
66570      {9.50,180.0},
66571      {9.50,180.0},
66572      {1.00,  0.0},
66573      {0.00,  0.0},
66574      {0.00,  0.0},
66575      {0.00,  0.0},
66576      {0.00,  0.0},
66577      {0.00,  0.0},
66578      {0.00,  0.0},
66579      {2.00,180.0},
66580      {2.00,180.0},
66581      {2.00,180.0},
66582      {0.00,  0.0},
66583      {0.00,  0.0},
66584      {0.00,  0.0},
66585      {0.00,  0.0},
66586      {0.00,  0.0},
66587      {0.00,  0.0},
66588      {0.00,  0.0},
66589      {0.00,  0.0},
66590      {0.00,  0.0},
66591      {0.00,  0.0},
66592      {0.00,  0.0},
66593      {0.00,  0.0},
66594      {0.00,  0.0},
66595      {0.00,  0.0},
66596      {0.00,  0.0},
66597      {1.20,  0.0},
66598      {1.20,  0.0},
66599      {1.20,  0.0},
66600      {0.00,  0.0},
66601      {0.00,  0.0},
66602      {0.00,  0.0},
66603      {0.00,  0.0},
66604      {1.90,  0.0},
66605      {1.90,  0.0},
66606      {0.00,  0.0},
66607      {0.00,  0.0},
66608      {0.00,  0.0},
66609      {0.00,  0.0},
66610      {0.00,  0.0},
66611      {0.00,  0.0},
66612      {0.00,  0.0},
66613      {0.00,  0.0},
66614      {0.00,  0.0},
66615      {0.00,  0.0},
66616      {0.00,  0.0},
66617      {0.00,  0.0},
66618      {0.00,  0.0},
66619      {0.90,  0.0},
66620      {0.90,  0.0},
66621      {0.00,  0.0},
66622      {0.00,  0.0},
66623      {0.00,  0.0},
66624      {0.00,  0.0},
66625      {0.00,  0.0},
66626      {0.00,  0.0},
66627      {0.00,  0.0},
66628      {0.00,  0.0},
66629      {0.00,  0.0},
66630      {0.00,  0.0},
66631      {0.00,  0.0},
66632      {0.00,  0.0},
66633      {0.00,  0.0},
66634      {0.85,  0.0},
66635      {0.00,  0.0},
66636      {0.00,  0.0},
66637      {0.25,180.0},
66638      {0.25,180.0},
66639      {0.00,  0.0},
66640      {0.00,  0.0},
66641      {0.00,  0.0},
66642      {0.00,  0.0},
66643      {0.00,  0.0},
66644      {0.00,  0.0},
66645      {0.00,  0.0},
66646      {0.00,  0.0},
66647      {0.00,  0.0},
66648      {0.00,  0.0},
66649      {0.00,  0.0},
66650      {0.00,  0.0},
66651      {0.00,  0.0},
66652      {0.00,  0.0},
66653      {0.00,  0.0},
66654      {0.00,  0.0},
66655      {0.00,  0.0},
66656      {0.00,  0.0},
66657      {0.00,  0.0},
66658      {0.00,  0.0},
66659      {0.00,  0.0},
66660      {0.00,  0.0},
66661      {0.00,  0.0},
66662      {0.00,  0.0},
66663      {0.00,  0.0},
66664      {0.00,  0.0},
66665      {0.00,  0.0},
66666      {0.00,  0.0},
66667      {0.00,  0.0},
66668      {1.30,180.0},
66669      {0.00,  0.0},
66670      {1.20,180.0},
66671      {1.90,180.0},
66672      {1.70,180.0},
66673      {0.80,  0.0},
66674      {0.53,  0.0},
66675      {0.00,  0.0},
66676      {2.30,  0.0},
66677      {2.30,  0.0},
66678      {2.30,  0.0},
66679      {2.30,  0.0},
66680      {2.30,  0.0},
66681      {2.30,  0.0},
66682      {2.00,  0.0},
66683      {0.00,  0.0},
66684      {0.00,  0.0},
66685      {0.00,  0.0},
66686      {1.20,  0.0},
66687      {0.00,  0.0},
66688      {0.00,  0.0},
66689      {0.80,  0.0},
66690      {0.80,  0.0},
66691      {0.00,  0.0},
66692      {0.00,  0.0},
66693      {1.15,  0.0},
66694      {0.25,  0.0},
66695      {1.90,  0.0},
66696      {0.00,  0.0},
66697      {1.90,180.0},
66698      {0.20,180.0},
66699      {0.00,  0.0},
66700      {0.00,  0.0},
66701      {0.80,180.0},
66702      {1.35,180.0},
66703      {0.00,  0.0},
66704      {1.40,180.0},
66705      {2.50,  0.0},
66706      {0.00,  0.0},
66707      {0.00,  0.0},
66708      {0.00,  0.0},
66709      {1.20,180.0},
66710      {0.45,180.0},
66711      {0.00,180.0},
66712      {0.25,  0.0},
66713      {0.25,  0.0},
66714      {0.19,  0.0},
66715      {0.25,  0.0},
66716      {0.55,  0.0},
66717      {0.25,  0.0},
66718      {0.25,  0.0},
66719      {0.19,  0.0},
66720      {0.25,  0.0},
66721      {0.55,  0.0}
66722 };
66723 
66724 static float gftor2[MXGTOR][2] = {
66725      {0.300, 180.000},
66726      {0.000, 180.000},
66727      {0.000, 180.000},
66728      {0.000, 180.000},
66729      {2.175, 180.000},
66730      {2.175, 180.000},
66731      {2.175, 180.000},
66732      {2.175, 180.000},
66733      {2.175, 180.000},
66734      {0.000, 180.000},
66735      {0.000, 180.000},
66736      {0.000, 180.000},
66737      {3.625, 180.000},
66738      {2.875, 180.000},
66739      {2.875, 180.000},
66740      {2.500, 180.000},
66741      {4.150, 180.000},
66742      {4.000, 180.000},
66743      {4.000, 180.000},
66744      {0.200, 180.000},
66745      {0.200, 180.000},
66746      {1.450, 180.000},
66747      {0.450, 180.000},
66748      {2.300, 180.000},
66749      {2.700, 180.000},
66750      {2.000, 180.000},
66751      {6.650, 180.000},
66752      {2.000, 180.000},
66753      {2.000, 180.000},
66754      {0.000, 180.000},
66755      {0.000, 180.000},
66756      {1.550, 180.000},
66757      {1.350, 180.000},
66758      {1.350, 180.000},
66759      {1.000,   0.000},
66760      {1.000,   0.000},
66761      {2.250, 180.000},
66762      {3.100, 180.000},
66763      {0.200, 180.000},
66764      {0.200, 180.000},
66765      {0.500,   0.000},
66766      {0.500,   0.000},
66767      {0.000, 180.000},
66768      {0.000, 180.000},
66769      {0.000, 180.000},
66770      {0.000, 180.000},
66771      {0.000, 180.000},
66772      {0.000, 180.000},
66773      {0.000, 180.000},
66774      {0.000, 180.000},
66775      {0.000, 180.000},
66776      {0.000, 180.000},
66777      {0.000, 180.000},
66778      {0.000, 180.000},
66779      {0.000, 180.000},
66780      {0.000, 180.000},
66781      {0.000, 180.000},
66782      {0.000, 180.000},
66783      {0.000, 180.000},
66784      {0.000, 180.000},
66785      {0.000, 180.000},
66786      {0.000, 180.000},
66787      {0.000, 180.000},
66788      {0.000, 180.000},
66789      {0.000, 180.000},
66790      {0.000, 180.000},
66791      {0.000, 180.000},
66792      {0.000, 180.000},
66793      {0.000, 180.000},
66794      {0.000, 180.000},
66795      {0.000, 180.000},
66796      {0.000, 180.000},
66797      {0.000, 180.000},
66798      {0.000, 180.000},
66799      {0.000, 180.000},
66800      {0.000, 180.000},
66801      {0.000, 180.000},
66802      {0.000, 180.000},
66803      {0.000, 180.000},
66804      {0.000, 180.000},
66805      {0.000, 180.000},
66806      {0.000, 180.000},
66807      {0.000, 180.000},
66808      {0.000, 180.000},
66809      {0.000, 180.000},
66810      {0.000, 180.000},
66811      {0.000, 180.000},
66812      {0.000, 180.000},
66813      {0.000, 180.000},
66814      {0.000, 180.000},
66815      {0.000, 180.000},
66816      {6.650, 180.000},
66817      {6.650, 180.000},
66818      {6.650, 180.000},
66819      {6.650, 180.000},
66820      {1.000, 180.000},
66821      {1.000, 180.000},
66822      {4.000, 180.000},
66823      {4.000, 180.000},
66824      {4.000, 180.000},
66825      {0.000,   0.000},
66826      {2.550, 180.000},
66827      {0.650, 180.000},
66828      {4.150, 180.000},
66829      {4.150, 180.000},
66830      {4.150, 180.000},
66831      {0.800, 180.000},
66832      {0.800, 180.000},
66833      {4.750, 180.000},
66834      {4.750, 180.000},
66835      {4.750, 180.000},
66836      {4.750, 180.000},
66837      {4.750, 180.000},
66838      {4.750, 180.000},
66839      {0.300, 180.000},
66840      {0.000,   0.000},
66841      {0.625, 180.000},
66842      {1.700, 180.000},
66843      {1.700, 180.000},
66844      {0.675, 180.000},
66845      {0.750, 180.000},
66846      {1.050, 180.000},
66847      {1.050, 180.000},
66848      {6.650, 180.000},
66849      {6.650, 180.000},
66850      {6.650, 180.000},
66851      {6.650, 180.000},
66852      {0.950, 180.000},
66853      {0.950, 180.000},
66854      {4.750, 180.000},
66855      {4.750, 180.000},
66856      {4.750, 180.000},
66857      {4.750, 180.000},
66858      {4.750, 180.000},
66859      {4.750, 180.000},
66860      {0.450, 180.000},
66861      {6.650, 180.000},
66862      {6.650, 180.000},
66863      {6.650, 180.000},
66864      {0.325,   0.000},
66865      {0.325,   0.000},
66866      {0.325,   0.000},
66867      {6.650, 180.000},
66868      {6.650, 180.000},
66869      {6.650, 180.000},
66870      {1.4333, 180.000},
66871      {1.4333, 180.000},
66872      {1.4333, 180.000},
66873      {0.500, 180.000},
66874      {1.100, 180.000},
66875      {6.650, 180.000},
66876      {6.650, 180.000},
66877      {6.650, 180.000},
66878      {0.600,   0.000},
66879      {0.600,   0.000},
66880      {0.600,   0.000},
66881      {6.650, 180.000},
66882      {6.650, 180.000},
66883      {6.650, 180.000},
66884      {1.2667, 180.000},
66885      {1.2667, 180.000},
66886      {1.2667, 180.000},
66887      {0.000,   0.000},
66888      {0.000,   0.000},
66889      {0.000,   0.000},
66890      {0.000,   0.000},
66891      {0.000,   0.000},
66892      {0.000,   0.000},
66893      {0.000,   0.000},
66894      {0.000,   0.000},
66895      {0.000,   0.000},
66896      {0.000,   0.000},
66897      {0.000,   0.000},
66898      {0.000,   0.000},
66899      {0.000,   0.000},
66900      {0.000,   0.000},
66901      {0.000,   0.000},
66902      {0.000,   0.000},
66903      {0.000,   0.000},
66904      {0.2667, 180.000},
66905      {0.2667, 180.000},
66906      {0.2667, 180.000},
66907      {0.000,   0.000},
66908      {0.000,   0.000},
66909      {0.000,   0.000},
66910      {0.000,   0.000},
66911      {0.000,   0.000},
66912      {0.000,   0.000},
66913      {0.000,   0.000},
66914      {0.000,   0.000},
66915      {0.000,   0.000},
66916      {0.000,   0.000},
66917      {0.000,   0.000},
66918      {0.000,   0.000},
66919      {0.000,   0.000},
66920      {3.625, 180.000},
66921      {3.625, 180.000},
66922      {3.625, 180.000},
66923      {1.000, 180.000},
66924      {1.000, 180.000},
66925      {0.450, 180.000},
66926      {0.000,   0.000},
66927      {0.000,   0.000},
66928      {0.000,   0.000},
66929      {1.750,   0.000},
66930      {0.300, 180.000},
66931      {4.800, 180.0},
66932      {4.800, 180.0},
66933      {4.800, 180.0},
66934      {1.050, 180.000},
66935      {1.050, 180.000},
66936      {1.050, 180.000},
66937      {0.600, 180.000},
66938      {0.900, 180.000},
66939      {0.900, 180.000},
66940      {0.600, 180.000},
66941      {0.600, 180.000},
66942      {0.600, 180.000},
66943      {4.800, 180.000},
66944      {4.800, 180.000},
66945      {0.000, 180.000},
66946      {0.525, 180.000},
66947      {0.525, 180.000},
66948      {1.4667, 180.000},
66949      {1.4667, 180.000},
66950      {0.000, 180.000},
66951      {0.400, 180.000},
66952      {0.300,   0.000},
66953      {0.300,   0.000},
66954      {1.300, 180.000},
66955      {1.300, 180.000},
66956      {1.650, 180.000},
66957      {1.650, 180.000},
66958      {1.150,   0.000},
66959      {0.400,   0.000},
66960      {0.400,   0.000},
66961      {0.400,   0.000},
66962      {1.075,   0.000},
66963      {0.950,   0.000},
66964      {0.700,   0.000},
66965      {4.800, 180.000},
66966      {4.800, 180.000},
66967      {1.100,   0.000},
66968      {1.375, 180.000},
66969      {1.500,   0.000},
66970      {1.100,   0.000},
66971      {1.000, 180.000},
66972      {1.000, 180.000},
66973      {4.800, 180.000},
66974      {4.800, 180.000},
66975      {1.000, 180.000},
66976      {2.250,   0.000},
66977      {0.325,   0.000},
66978      {0.325,   0.000},
66979      {2.200, 180.000},
66980      {2.200, 180.000},
66981      {1.100,   0.000},
66982      {1.500,   0.000},
66983      {0.000,   0.000},
66984      {0.000,   0.000},
66985      {1.100, 180.000},
66986      {1.100, 180.000},
66987      {0.000, 180.000},
66988      {0.000, 180.000},
66989      {0.000, 180.000},
66990      {0.000, 180.000},
66991      {0.000, 180.000},
66992      {0.000, 180.000},
66993      {0.000, 180.000},
66994      {0.000, 180.000},
66995      {0.000, 180.000},
66996      {0.000, 180.000},
66997      {0.000, 180.000},
66998      {0.000, 180.000},
66999      {0.000, 180.000},
67000      {0.000, 180.000},
67001      {0.000, 180.000},
67002      {0.000, 180.000},
67003      {0.000, 180.000},
67004      {0.000, 180.000},
67005      {0.000, 180.000},
67006      {0.000, 180.000},
67007      {0.000, 180.000},
67008      {0.000, 180.000},
67009      {0.000, 180.000},
67010      {0.000, 180.000},
67011      {0.000, 180.000},
67012      {0.000, 180.000},
67013      {0.000, 180.000},
67014      {0.000, 180.000},
67015      {0.000, 180.000},
67016      {0.000, 180.000},
67017      {0.000, 180.000},
67018      {0.000, 180.000},
67019      {0.000, 180.000},
67020      {0.000, 180.000},
67021      {0.000, 180.000},
67022      {0.000, 180.000},
67023      {0.000, 180.000},
67024      {0.000, 180.000},
67025      {0.000, 180.000},
67026      {0.000, 180.000},
67027      {0.000, 180.000},
67028      {0.000, 180.000},
67029      {0.000, 180.000},
67030      {0.000, 180.000},
67031      {3.000, 180.000},
67032      {3.000, 180.000},
67033      {3.000, 180.000},
67034      {3.000, 180.000},
67035      {1.200, 180.000},
67036      {1.200, 180.000},
67037      {4.000, 180.000},
67038      {4.000, 180.000},
67039      {4.000, 180.000},
67040      {3.000, 180.000},
67041      {3.000, 180.000},
67042      {6.100, 180.000},
67043      {6.100, 180.000},
67044      {6.100, 180.000},
67045      {8.000, 180.000},
67046      {8.000, 180.000},
67047      {8.000, 180.000},
67048      {1.700, 180.000},
67049      {1.700, 180.000},
67050      {1.700, 180.000},
67051      {4.800, 180.000},
67052      {4.800, 180.000},
67053      {2.800, 180.000},
67054      {2.800, 180.000},
67055      {2.800, 180.000},
67056      {0.750, 180.000},
67057      {0.750, 180.000},
67058      {0.750, 180.000},
67059      {3.200, 180.000},
67060      {3.200, 180.000},
67061      {3.200, 180.000},
67062      {3.000, 180.000},
67063      {3.000, 180.000},
67064      {3.000, 180.000},
67065      {4.800, 180.000},
67066      {4.800, 180.000},
67067      {5.400, 180.000},
67068      {5.400, 180.000},
67069      {5.400, 180.000},
67070      {5.400, 180.000},
67071      {5.400, 180.000},
67072      {5.400, 180.000},
67073      {5.400, 180.000},
67074      {5.400, 180.000},
67075      {6.600, 180.000},
67076      {6.600, 180.000},
67077      {6.600, 180.000},
67078      {6.600, 180.000},
67079      {0.000,   0.000},
67080      {0.000,   0.000},
67081      {2.100, 180.000},
67082      {6.650, 180.000},
67083      {6.650, 180.000},
67084      {6.650, 180.000},
67085      {6.6667, 180.000},
67086      {0.000,   0.000},
67087      {0.000,   0.000},
67088      {0.000,   0.000},
67089      {0.000,   0.000},
67090      {2.100, 180.000},
67091      {2.100, 180.000},
67092      {2.100, 180.000},
67093      {2.800, 180.000},
67094      {2.800, 180.000},
67095      {2.800, 180.000},
67096      {6.650, 180.000},
67097      {0.000,   0.000},
67098      {0.000,   0.000},
67099      {6.6667, 180.000},
67100      {0.000,   0.000},
67101      {0.000,   0.000},
67102      {2.250,   0.000},
67103      {0.000,   0.000},
67104      {1.600,   0.000},
67105      {1.900,   0.000},
67106      {4.000, 180.000},
67107      {2.200,   0.000},
67108      {1.800,   0.000},
67109      {3.200, 180.000},
67110      {3.200, 180.000},
67111      {3.200, 180.000},
67112      {2.350,   0.000},
67113      {2.100, 180.000},
67114      {2.100, 180.000},
67115      {3.000, 180.000},
67116      {3.000, 180.000},
67117      {3.100,   0.000},
67118      {2.600,   0.000},
67119      {3.750,   0.000},
67120      {3.750,   0.000},
67121      {3.1333,   0.000},
67122      {3.1333,   0.000},
67123      {0.000,   0.000},
67124      {0.000,   0.000},
67125      {0.000,   0.000},
67126      {0.000,   0.000},
67127      {0.000,   0.000},
67128      {0.000,   0.000},
67129      {0.000,   0.000},
67130      {0.000,   0.000},
67131      {0.000,   0.000},
67132      {0.000,   0.000},
67133      {0.000,   0.000},
67134      {0.000,   0.000},
67135      {0.000,   0.000},
67136      {0.000,   0.000},
67137      {0.000,   0.000},
67138      {0.000,   0.000},
67139      {0.000,   0.000},
67140      {0.000,   0.000},
67141      {0.000,   0.000},
67142      {0.000,   0.000},
67143      {0.900,   0.000},
67144      {1.200,   0.000},
67145      {6.000, 180.000},
67146      {1.000,   0.000},
67147      {0.650,   0.000},
67148      {1.000, 180.000},
67149      {1.000, 180.000},
67150      {1.000, 180.000},
67151      {1.450,   0.000},
67152      {0.000,   0.000},
67153      {0.000,   0.000},
67154      {0.8333, 180.000},
67155      {0.8333, 180.000},
67156      {1.800,   0.000},
67157      {7.800,   0.000},
67158      {1.050,   0.000},
67159      {1.050,   0.000},
67160      {3.6667, 180.000},
67161      {3.6667, 180.000},
67162      {0.000,   0.000},
67163      {2.550, 180.000},
67164      {1.500,   0.000},
67165      {0.000,   0.000},
67166      {1.400, 180.000},
67167      {1.400, 180.000},
67168      {1.400, 180.000},
67169      {2.350,   0.000},
67170      {0.000,   0.000},
67171      {0.000,   0.000},
67172      {0.800,   0.000},
67173      {0.800,   0.000},
67174      {1.600,   0.000},
67175      {2.100,   0.000},
67176      {0.750,   0.000},
67177      {0.750,   0.000},
67178      {0.100, 180.000},
67179      {0.100, 180.000},
67180      {1.800, 180.000},
67181      {3.900, 180.000},
67182      {3.000, 180.000},
67183      {0.300, 180.000},
67184      {0.300, 180.000},
67185      {0.300, 180.000},
67186      {1.900, 180.000},
67187      {0.575, 180.000},
67188      {0.575, 180.000},
67189      {2.400,   0.000},
67190      {2.400,   0.000},
67191      {2.300, 180.000},
67192      {2.700, 180.000},
67193      {2.600, 180.000},
67194      {2.600, 180.000},
67195      {0.3333,   0.000},
67196      {0.3333,   0.000},
67197      {1.600,   0.000},
67198      {1.600,   0.000},
67199      {1.500, 180.000},
67200      {1.500, 180.000},
67201      {1.500, 180.000},
67202      {0.000,   0.000},
67203      {0.000,   0.000},
67204      {0.000,   0.000},
67205      {0.000,   0.000},
67206      {0.000,   0.000},
67207      {2.400,   0.000},
67208      {2.400,   0.000},
67209      {0.000,   0.000},
67210      {0.000,   0.000},
67211      {0.000,   0.000},
67212      {0.000,   0.000},
67213      {0.000,   0.000},
67214      {2.200,   0.000},
67215      {1.800,   0.000},
67216      {0.000,   0.000},
67217      {0.000,   0.000},
67218      {1.200, 180.000},
67219      {1.200, 180.000},
67220      {3.000, 180.000},
67221      {3.000, 180.000},
67222      {3.000, 180.000},
67223      {2.200,   0.000},
67224      {1.050, 180.000},
67225      {1.050, 180.000},
67226      {0.800,   0.000},
67227      {0.800,   0.000},
67228      {6.600, 180.000},
67229      {6.600, 180.000},
67230      {6.600, 180.000},
67231      {6.600, 180.000},
67232      {6.600, 180.000},
67233      {1.200, 180.000},
67234      {1.200, 180.000},
67235      {7.200, 180.000},
67236      {7.200, 180.000},
67237      {7.200, 180.000},
67238      {0.000,   0.000},
67239      {0.000,   0.000},
67240      {0.000,   0.000},
67241      {6.650, 180.000},
67242      {2.450,   0.000},
67243      {2.450,   0.000},
67244      {6.6667, 180.000},
67245      {0.000,   0.000},
67246      {0.000,   0.000},
67247      {1.400, 180.000},
67248      {1.400, 180.000},
67249      {1.400, 180.000},
67250      {1.400, 180.000},
67251      {1.400, 180.000},
67252      {1.400, 180.000},
67253      {6.650, 180.000},
67254      {1.500,   0.000},
67255      {1.500,   0.000},
67256      {6.6667, 180.000},
67257      {0.000,   0.000},
67258      {0.000,   0.000},
67259      {0.000,   0.000},
67260      {0.000,   0.000},
67261      {0.000,   0.000},
67262      {1.8333, 180.000},
67263      {1.8333, 180.000},
67264      {4.600,   0.000},
67265      {0.000,   0.000},
67266      {3.850,   0.000},
67267      {3.850,   0.000},
67268      {0.000,   0.000},
67269      {0.000,   0.000},
67270      {6.650, 180.000},
67271      {1.450, 180.000},
67272      {6.650, 180.000},
67273      {0.3167, 180.000},
67274      {6.650, 180.000},
67275      {0.000,   0.000},
67276      {6.650, 180.000},
67277      {0.000,   0.000},
67278      {0.000,   0.000},
67279      {0.000,   0.000},
67280      {0.600, 180.000},
67281      {0.600, 180.000},
67282      {6.6667, 180.000},
67283      {0.600,   0.000},
67284      {0.000,   0.000},
67285      {0.000,   0.000},
67286      {3.800, 180.000},
67287      {3.800, 180.000},
67288      {6.6667, 180.000},
67289      {0.000,   0.000},
67290      {6.6667, 180.000},
67291      {0.000,   0.000},
67292      {0.000,   0.000},
67293      {0.000,   0.000},
67294      {0.000,   0.000},
67295      {0.000,   0.000},
67296      {4.6667, 180.000},
67297      {4.6667, 180.000},
67298      {0.000,   0.000},
67299      {0.000,   0.000},
67300      {0.000,   0.000},
67301      {3.0667, 180.000},
67302      {3.0667, 180.000},
67303      {6.650, 180.000},
67304      {0.000,   0.000},
67305      {6.6667, 180.000},
67306      {4.3333, 180.000},
67307      {6.6667, 180.000},
67308      {0.1556, 180.000},
67309      {2.250, 180.000},
67310      {1.100, 180.000},
67311      {0.650, 180.000},
67312      {1.000, 180.000},
67313      {2.000, 180.000},
67314      {0.850, 180.000},
67315      {0.000,   0.000},
67316      {0.070,   0.000},
67317      {0.000,   0.000},
67318      {0.000,   0.000},
67319      {0.000,   0.000},
67320      {0.000,   0.000},
67321      {0.000,   0.000},
67322      {0.000,   0.000},
67323      {2.500, 180.0},
67324      {3.500,   0.000},
67325      {1.900,   0.000},
67326      {3.000, 180.0},
67327      {1.500,   0.000},
67328      {1.200,   0.000},
67329      {1.200,   0.000},
67330      {0.000,   0.000},
67331      {0.000,   0.000},
67332      {0.000,   0.000},
67333      {0.000,   0.000},
67334      {0.000,   0.000},
67335      {0.000,   0.000},
67336      {2.300, 180.000},
67337      {2.175, 180.000},
67338      {6.650, 180.000},
67339      {0.250, 180.000},
67340      {0.480, 180.000},
67341      {0.100, 180.000},
67342      {0.000,   0.000},
67343      {0.850, 180.000},
67344      {0.650,   0.000},
67345      {2.700, 180.000},
67346      {0.000,   0.000},
67347      {1.175,   0.000},
67348      {1.175,   0.000},
67349      {1.175,   0.000},
67350      {0.000,   0.000},
67351      {0.000,   0.000},
67352      {0.000,   0.000},
67353      {0.000,   0.000},
67354      {0.000,   0.000},
67355      {0.000,   0.000},
67356      {0.000,   0.000},
67357      {0.000,   0.000},
67358      {0.000,   0.000},
67359      {0.000,   0.000},
67360      {0.000,   0.000},
67361      {0.000,   0.000},
67362      {0.000,   0.000}
67363 };
67364 
67365 static float gftor3[MXGTOR][2] = {
67366      {  0.000,   0.000},
67367      {  0.000,   0.000},
67368      {  0.000,   0.000},
67369      {  0.000,   0.000},
67370      {  0.000,   0.000},
67371      {  0.000,   0.000},
67372      {  0.000,   0.000},
67373      {  0.000,   0.000},
67374      {  0.000,   0.000},
67375      {  0.000,   0.000},
67376      {  0.000,   0.000},
67377      {  0.000,   0.000},
67378      {  0.000,   0.000},
67379      {  0.000,   0.000},
67380      {  0.000,   0.000},
67381      {  0.000,   0.000},
67382      {  0.000,   0.000},
67383      {  0.000,   0.000},
67384      {  0.000,   0.000},
67385      {  0.000,   0.000},
67386      {  0.000,   0.000},
67387      {  0.000,   0.000},
67388      {  0.000,   0.000},
67389      {  0.000,   0.000},
67390      {  0.000,   0.000},
67391      {  0.000,   0.000},
67392      {  0.000,   0.000},
67393      {  0.000,   0.000},
67394      {  0.000,   0.000},
67395      {  0.000,   0.000},
67396      {  0.000,   0.000},
67397      {  0.000,   0.000},
67398      {  0.000,   0.000},
67399      {  0.000,   0.000},
67400      {  0.000,   0.000},
67401      {  0.000,   0.000},
67402      {  0.000,   0.000},
67403      {  0.000,   0.000},
67404      {  0.000,   0.000},
67405      {  0.000,   0.000},
67406      {  0.000,   0.000},
67407      {  0.000,   0.000},
67408      {  0.000,   0.000},
67409      {  0.000,   0.000},
67410      {  0.000,   0.000},
67411      {  0.000,   0.000},
67412      {  0.000,   0.000},
67413      {  0.000,   0.000},
67414      {  0.000,   0.000},
67415      {  0.000,   0.000},
67416      {  0.000,   0.000},
67417      {  0.000,   0.000},
67418      {  0.000,   0.000},
67419      {  0.000,   0.000},
67420      {  0.000,   0.000},
67421      {  0.000,   0.000},
67422      {  0.000,   0.000},
67423      {  0.000,   0.000},
67424      {  0.000,   0.000},
67425      {  0.000,   0.000},
67426      {  0.000,   0.000},
67427      {  0.000,   0.000},
67428      {  0.000,   0.000},
67429      {  0.000,   0.000},
67430      {  0.000,   0.000},
67431      {  0.000,   0.000},
67432      {  0.000,   0.000},
67433      {  0.000,   0.000},
67434      {  0.000,   0.000},
67435      {  0.000,   0.000},
67436      {  0.000,   0.000},
67437      {  0.000,   0.000},
67438      {  0.000,   0.000},
67439      {  0.000,   0.000},
67440      {  0.000,   0.000},
67441      {  0.000,   0.000},
67442      {  0.000,   0.000},
67443      {  0.000,   0.000},
67444      {  0.000,   0.000},
67445      {  0.000,   0.000},
67446      {  0.000,   0.000},
67447      {  0.000,   0.000},
67448      {  0.000,   0.000},
67449      {  0.000,   0.000},
67450      {  0.000,   0.000},
67451      {  0.000,   0.000},
67452      {  0.000,   0.000},
67453      {  0.000,   0.000},
67454      {  0.000,   0.000},
67455      {  0.000,   0.000},
67456      {  0.000,   0.000},
67457      {  0.000,   0.000},
67458      {  0.000,   0.000},
67459      {  0.000,   0.000},
67460      {  0.000,   0.000},
67461      {  0.000,   0.000},
67462      {  0.000,   0.000},
67463      {  0.000,   0.000},
67464      {  0.000,   0.000},
67465      {  0.000,   0.000},
67466      {  0.000,   0.000},
67467      {  0.000,   0.000},
67468      {  0.000,   0.000},
67469      {  0.000,   0.000},
67470      {  0.000,   0.000},
67471      {  0.000,   0.000},
67472      {  0.000,   0.000},
67473      {  0.000,   0.000},
67474      {  0.000,   0.000},
67475      {  0.000,   0.000},
67476      {  0.000,   0.000},
67477      {  0.000,   0.000},
67478      {  0.000,   0.000},
67479      {  0.000,   0.000},
67480      {  0.000,   0.000},
67481      {  0.000, 180.000},
67482      {  0.000,   0.000},
67483      {  0.000,   0.000},
67484      {  0.000,   0.000},
67485      {  0.000,   0.000},
67486      {  0.000,   0.000},
67487      {  0.000,   0.000},
67488      {  0.000,   0.000},
67489      {  0.000,   0.000},
67490      {  0.000,   0.000},
67491      {  0.000,   0.000},
67492      {  0.000,   0.000},
67493      {  0.000,   0.000},
67494      {  0.000,   0.000},
67495      {  0.000,   0.000},
67496      {  0.000,   0.000},
67497      {  0.000,   0.000},
67498      {  0.000,   0.000},
67499      {  0.000,   0.000},
67500      {  0.000,   0.000},
67501      {  0.000,   0.000},
67502      {  0.000,   0.000},
67503      {  0.000,   0.000},
67504      {  0.000,   0.000},
67505      {  0.000,   0.000},
67506      {  0.000,   0.000},
67507      {  0.000,   0.000},
67508      {  0.000,   0.000},
67509      {  0.000,   0.000},
67510      {  0.000,   0.000},
67511      {  0.000,   0.000},
67512      {  0.000,   0.000},
67513      {  0.000,   0.000},
67514      {  0.000,   0.000},
67515      {  0.000,   0.000},
67516      {  0.000,   0.000},
67517      {  0.000,   0.000},
67518      {  0.000,   0.000},
67519      {  0.000,   0.000},
67520      {  0.000,   0.000},
67521      {  0.000,   0.000},
67522      {  0.000,   0.000},
67523      {  0.000,   0.000},
67524      {  0.000,   0.000},
67525      {  0.000,   0.000},
67526      {  0.000,   0.000},
67527      {  0.000,   0.000},
67528      {  0.156,   0.000},
67529      {  0.156,   0.000},
67530      {  0.156,   0.000},
67531      {  0.000,   0.000},
67532      {  0.000,   0.000},
67533      {  0.000,   0.000},
67534      {  0.000,   0.000},
67535      {  0.000,   0.000},
67536      {  0.000,   0.000},
67537      {  0.000,   0.000},
67538      {  0.300,   0.000},
67539      {  0.156,   0.000},
67540      {  0.000,   0.000},
67541      {  0.000,   0.000},
67542      {  0.000,   0.000},
67543      {  0.167,   0.000},
67544      {  0.383,   0.000},
67545      {  0.000,   0.000},
67546      {  0.000,   0.000},
67547      {  0.000,   0.000},
67548      {  0.133,   0.000},
67549      {  0.133,   0.000},
67550      {  0.133,   0.000},
67551      {  0.022,   0.000},
67552      {  0.022,   0.000},
67553      {  0.250,   0.000},
67554      {  0.333,   0.000},
67555      {  0.200,   0.000},
67556      {  0.200,   0.000},
67557      { 0.1444,   0.000},
67558      { 0.1444,   0.000},
67559      {  0.000,   0.000},
67560      {  0.000,   0.000},
67561      {  0.000,   0.000},
67562      {  0.000,   0.000},
67563      {  0.000,   0.000},
67564      {  0.000,   0.000},
67565      {  0.000,   0.000},
67566      {  0.000,   0.000},
67567      {  0.000, 180.000},
67568      {  0.000, 180.000},
67569      {  0.000,  80.000},
67570      {  0.000,   0.000},
67571      {  0.000,   0.000},
67572      {  0.000,   0.000},
67573      {  0.000,   0.000},
67574      {  0.000,   0.000},
67575      {  0.000,   0.000},
67576      {  0.000,   0.000},
67577      {  0.000,   0.000},
67578      {  0.000,   0.000},
67579      {  0.000,   0.000},
67580      {  0.000,   0.000},
67581      {  0.000,   0.000},
67582      {  0.000,   0.000},
67583      {  0.000,   0.000},
67584      {  0.000,   0.000},
67585      {  0.000,   0.000},
67586      {  0.000,   0.000},
67587      {  0.000,   0.000},
67588      {  0.000,   0.000},
67589      {  0.000,   0.000},
67590      {  0.000,   0.000},
67591      {  0.000,   0.000},
67592      {  0.000,   0.000},
67593      {  0.000,   0.000},
67594      {  0.000,   0.000},
67595      {  0.000,   0.000},
67596      {  0.000,   0.000},
67597      {  0.000,   0.000},
67598      {  0.000,   0.000},
67599      {  0.000,   0.000},
67600      {  0.000,   0.000},
67601      {  0.000,   0.000},
67602      {  0.000,   0.000},
67603      {  0.000,   0.000},
67604      {  0.000,   0.000},
67605      {  0.000,   0.000},
67606      {  0.000,   0.000},
67607      {  0.000,   0.000},
67608      {  0.000,   0.000},
67609      {  0.000,   0.000},
67610      {  0.000,   0.000},
67611      {  0.000,   0.000},
67612      {  0.000,   0.000},
67613      {  0.000,   0.000},
67614      {  0.000,   0.000},
67615      {  0.000,   0.000},
67616      {  0.000,   0.000},
67617      {  0.000,   0.000},
67618      {  0.000,   0.000},
67619      {  0.000,   0.000},
67620      {  0.000,   0.000},
67621      {  0.000,   0.000},
67622      {  0.000,   0.000},
67623      {  0.000,   0.000},
67624      {  1.500,   0.000},
67625      {  1.500,   0.000},
67626      {  0.000,   0.000},
67627      {  0.000,   0.000},
67628      {  0.000,   0.000},
67629      {  0.000,   0.000},
67630      {  0.000,   0.000},
67631      {  0.000,   0.000},
67632      {  0.000,   0.000},
67633      {  0.000,   0.000},
67634      {  0.000,   0.000},
67635      {  0.000,   0.000},
67636      {  0.000,   0.000},
67637      {  0.000,   0.000},
67638      {  0.000,   0.000},
67639      {  0.000,   0.000},
67640      {  0.000,   0.000},
67641      {  0.000,   0.000},
67642      {  0.000,   0.000},
67643      {  0.000,   0.000},
67644      {  0.000,   0.000},
67645      {  0.000,   0.000},
67646      {  0.000,   0.000},
67647      {  0.000,   0.000},
67648      {  0.000,   0.000},
67649      {  0.000,   0.000},
67650      {  0.000,   0.000},
67651      {  0.000,   0.000},
67652      {  0.000,   0.000},
67653      {  0.000,   0.000},
67654      {  0.000,   0.000},
67655      {  0.000,   0.000},
67656      {  0.000,   0.000},
67657      {  0.000,   0.000},
67658      {  0.000,   0.000},
67659      {  0.000,   0.000},
67660      {  0.000,   0.000},
67661      {  0.000,   0.000},
67662      {  0.000,   0.000},
67663      {  0.000,   0.000},
67664      {  0.000,   0.000},
67665      {  0.000,   0.000},
67666      {  0.000,   0.000},
67667      {  0.000,   0.000},
67668      {  0.000,   0.000},
67669      {  0.000,   0.000},
67670      {  0.000,   0.000},
67671      {  0.000,   0.000},
67672      {  0.000,   0.000},
67673      {  0.000,   0.000},
67674      {  0.000,   0.000},
67675      {  0.000,   0.000},
67676      {  0.000,   0.000},
67677      {  0.000,   0.000},
67678      {  0.000,   0.000},
67679      {  0.000,   0.000},
67680      {  0.000,   0.000},
67681      {  0.000,   0.000},
67682      {  0.000,   0.000},
67683      {  0.000,   0.000},
67684      {  0.000,   0.000},
67685      {  0.000,   0.000},
67686      {  0.000,   0.000},
67687      {  0.000,   0.000},
67688      {  0.000,   0.000},
67689      {  0.000,   0.000},
67690      {  0.000,   0.000},
67691      {  0.000,   0.000},
67692      {  0.000,   0.000},
67693      {  0.000,   0.000},
67694      {  0.000,   0.000},
67695      {  0.000,   0.000},
67696      {  0.000,   0.000},
67697      {  0.000,   0.000},
67698      {  0.000,   0.000},
67699      {  0.000,   0.000},
67700      {  0.000,   0.000},
67701      {  0.000,   0.000},
67702      {  0.000,   0.000},
67703      {  0.000,   0.000},
67704      {  0.000,   0.000},
67705      {  0.000,   0.000},
67706      {  0.000,   0.000},
67707      {  0.000,   0.000},
67708      {  0.000,   0.000},
67709      {  0.000,   0.000},
67710      {  0.000,   0.000},
67711      {  0.000,   0.000},
67712      {  0.000,   0.000},
67713      {  0.000,   0.000},
67714      {  0.000,   0.000},
67715      {  0.000,   0.000},
67716      {  0.000,   0.000},
67717      {  0.000,   0.000},
67718      {  0.000,   0.000},
67719      {  0.000,   0.000},
67720      {  0.000,   0.000},
67721      {  0.000,   0.000},
67722      {  0.000,   0.000},
67723      {  0.000,   0.000},
67724      {  0.000,   0.000},
67725      {  0.000,   0.000},
67726      {  0.000,   0.000},
67727      {  1.000, 180.000},
67728      {  1.000, 180.000},
67729      {  1.000, 180.000},
67730      {  1.000, 180.000},
67731      {  0.000,   0.000},
67732      {  0.000,   0.000},
67733      {  0.000,   0.000},
67734      {  0.000,   0.000},
67735      {  0.000,   0.000},
67736      {  0.000,   0.000},
67737      {  0.000,   0.000},
67738      {  1.500, 180.000},
67739      {  1.500, 180.000},
67740      {  0.000,   0.000},
67741      {  0.500, 180.000},
67742      {  0.500, 180.000},
67743      {  0.000,   0.000},
67744      {  0.250,   0.000},
67745      {  0.000,   0.000},
67746      {  0.000,   0.000},
67747      {  0.000,   0.000},
67748      {  0.000,   0.000},
67749      {  0.000,   0.000},
67750      {  0.000,   0.000},
67751      {  0.000,   0.000},
67752      {  0.000,   0.000},
67753      {  0.000,   0.000},
67754      {  0.000,   0.000},
67755      {  0.000,   0.000},
67756      {  0.000,   0.000},
67757      {  0.000,   0.000},
67758      {  0.000,   0.000},
67759      {  0.000,   0.000},
67760      {  0.000,   0.000},
67761      {  0.000,   0.000},
67762      {  0.000,   0.000},
67763      {  0.000,   0.000},
67764      { 0.1888,   0.000},
67765      { 0.2333,   0.000},
67766      { 0.1833,   0.000},
67767      { 0.0833, 180.000},
67768      { 0.3333,   0.000},
67769      { 0.5666,   0.000},
67770      { 1.6666, 180.000},
67771      { 1.6666, 180.000},
67772      { 1.6666, 180.000},
67773      {  0.150,   0.000},
67774      {  0.050,   0.000},
67775      {  0.050,   0.000},
67776      { 0.0888,   0.000},
67777      { 0.0888,   0.000},
67778      { 0.6666,   0.000},
67779      { 0.3333,   0.000},
67780      { 0.2833,   0.000},
67781      { 0.2833,   0.000},
67782      { 0.1333,   0.000},
67783      { 0.1333,   0.000},
67784      {  0.000,   0.000},
67785      {  0.000,   0.000},
67786      {  0.000,   0.000},
67787      {  0.000,   0.000},
67788      {  0.000,   0.000},
67789      {  0.000,   0.000},
67790      {  0.000,   0.000},
67791      {  0.000,   0.000},
67792      {  0.000,   0.000},
67793      {  1.100,   0.000},
67794      {  1.100,   0.000},
67795      {  0.000,   0.000},
67796      {  0.000,   0.000},
67797      {  0.000,   0.000},
67798      {  0.000,   0.000},
67799      {  0.000,   0.000},
67800      {  0.000,   0.000},
67801      {  0.000,   0.000},
67802      {  0.000,   0.000},
67803      {  1.800, 180.000},
67804      {  0.000,   0.000},
67805      {  0.000,   0.000},
67806      {  0.000,   0.000},
67807      {  0.000,   0.000},
67808      {  0.000,   0.000},
67809      {  0.000,   0.000},
67810      {  0.000,   0.000},
67811      {  1.175,   0.000},
67812      {  1.175,   0.000},
67813      {  0.000,   0.000},
67814      {  0.000,   0.000},
67815      {  0.000,   0.000},
67816      {  0.000,   0.000},
67817      {  0.100, 180.000},
67818      {  0.100, 180.000},
67819      {  0.000,   0.000},
67820      {  0.000,   0.000},
67821      {  0.000,   0.000},
67822      {  0.000,   0.000},
67823      {  0.000,   0.000},
67824      {  0.000,   0.000},
67825      {  0.000,   0.000},
67826      {  0.000,   0.000},
67827      {  0.000,   0.000},
67828      {  0.000,   0.000},
67829      {  0.000,   0.000},
67830      {  0.400,   0.000},
67831      {  0.400,   0.000},
67832      {  0.000,   0.000},
67833      {  0.000,   0.000},
67834      {  0.000,   0.000},
67835      {  0.000,   0.000},
67836      {  0.000,   0.000},
67837      {  0.000,   0.000},
67838      {  0.000,   0.000},
67839      {  0.000,   0.000},
67840      {  0.000,   0.000},
67841      {  0.000,   0.000},
67842      {  0.000,   0.000},
67843      {  0.400, 180.000},
67844      {  0.000,   0.000},
67845      {  0.000,   0.000},
67846      { 0.5333,   0.000},
67847      { 0.5333,   0.000},
67848      {  0.000,   0.000},
67849      {  0.000,   0.000},
67850      {  0.000,   0.000},
67851      {  0.000,   0.000},
67852      {  0.000,   0.000},
67853      {  0.000,   0.000},
67854      {  0.000,   0.000},
67855      {  0.000,   0.000},
67856      {  0.000,   0.000},
67857      {  1.650,   0.000},
67858      {  1.650,   0.000},
67859      {  0.000,   0.000},
67860      {  0.000,   0.000},
67861      {  0.000,   0.000},
67862      {  0.000,   0.000},
67863      {  0.000,   0.000},
67864      {  0.000,   0.000},
67865      {  0.000,   0.000},
67866      {  0.000,   0.000},
67867      {  0.000,   0.000},
67868      {  0.000,   0.000},
67869      {  0.000,   0.000},
67870      {  0.000,   0.000},
67871      {  0.000,   0.000},
67872      {  0.000,   0.000},
67873      {  0.000,   0.000},
67874      {  0.000,   0.000},
67875      {  0.000,   0.000},
67876      {  0.000,   0.000},
67877      {  0.000,   0.000},
67878      {  0.000,   0.000},
67879      {  0.000,   0.000},
67880      {  0.000,   0.000},
67881      {  0.000,   0.000},
67882      {  0.000,   0.000},
67883      {  0.000,   0.000},
67884      {  0.000,   0.000},
67885      {  0.000,   0.000},
67886      {  0.000,   0.000},
67887      {  0.000,   0.000},
67888      {  0.000,   0.000},
67889      {  0.000,   0.000},
67890      {  0.000,   0.000},
67891      {  0.000,   0.000},
67892      {  0.000,   0.000},
67893      {  0.000,   0.000},
67894      {  0.000,   0.000},
67895      {  0.000,   0.000},
67896      {  0.000,   0.000},
67897      {  0.000,   0.000},
67898      {  0.400, 180.000},
67899      {  0.400, 180.000},
67900      {  0.500,   0.000},
67901      {  0.000,   0.000},
67902      {  0.000,   0.000},
67903      {  0.000,   0.000},
67904      {  0.000,   0.000},
67905      {  0.000,   0.000},
67906      {  1.150,   0.000},
67907      {  0.000,   0.000},
67908      {  0.000,   0.000},
67909      { 0.2666,   0.000},
67910      { 0.2666,   0.000},
67911      {  0.000,   0.000},
67912      {  0.000,   0.000},
67913      {  0.000,   0.000},
67914      {  0.000,   0.000},
67915      {  0.000,   0.000},
67916      {  0.000,   0.000},
67917      {  0.000,   0.000},
67918      { 0.1166,   0.000},
67919      {  0.000,   0.000},
67920      {  0.000,   0.000},
67921      {  0.000,   0.000},
67922      {  0.000,   0.000},
67923      {  0.000,   0.000},
67924      {  0.000,   0.000},
67925      {  0.300,   0.000},
67926      {  0.300,   0.000},
67927      {  0.000,   0.000},
67928      {  0.000,   0.000},
67929      {  0.000,   0.000},
67930      { 0.2666,   0.000},
67931      {  0.000,   0.000},
67932      { 0.2777,   0.000},
67933      {  5.600,   0.000},
67934      {  5.300,   0.000},
67935      {  0.700,   0.000},
67936      {  0.700,   0.000},
67937      {  0.000,   0.000},
67938      {  0.000,   0.000},
67939      {  0.000,   0.000},
67940      {  0.300,   0.000},
67941      {  0.300,   0.000},
67942      {  0.000,   0.000},
67943      {  0.000,   0.000},
67944      {  0.000,   0.000},
67945      {  0.625,   0.000},
67946      {  0.000,   0.000},
67947      {  0.000,   0.000},
67948      {  0.000,   0.000},
67949      {  0.000,   0.000},
67950      {  0.000,   0.000},
67951      {  0.700, 180.000},
67952      {  0.000,   0.000},
67953      {  0.000,   0.000},
67954      {  0.000,   0.000},
67955      {  0.000,   0.000},
67956      {  0.150, 180.000},
67957      {  0.000,   0.000},
67958      {  0.000,   0.000},
67959      {  0.000,   0.000},
67960      {  0.000,   0.000},
67961      {  0.000,   0.000},
67962      {  0.000,   0.000},
67963      {  0.000,   0.000},
67964      {  0.000,   0.000},
67965      {  0.600,   0.000},
67966      {  1.900,   0.000},
67967      {  2.300,   0.000},
67968      {  0.000,   0.000},
67969      {  0.250,   0.000},
67970      {  0.250,   0.000},
67971      {  0.080, 180.000},
67972      {  0.080, 180.000},
67973      {  0.150,   0.000},
67974      {  0.160,   0.000},
67975      {  0.380, 180.000},
67976      {  0.160,   0.000},
67977      {  0.000,   0.000},
67978      {  0.300,   0.000},
67979      {  0.000,   0.000},
67980      {  0.180,   0.000},
67981      {  0.300,   0.000},
67982      {  0.383,   0.000},
67983      {  0.383,   0.000},
67984      {  0.100,   0.000},
67985      {  0.383,   0.000},
67986      {  0.000,   0.000},
67987      {  0.000,   0.000},
67988      {  0.144,   0.000},
67989      {  0.144,   0.000},
67990      {  0.144,   0.000},
67991      {  0.000,   0.000},
67992      {  0.000,   0.000},
67993      {  0.000,   0.000},
67994      {  0.000,   0.000},
67995      {  0.000,   0.000},
67996      {  0.000,   0.000},
67997      {  0.000,   0.000},
67998      {  0.000,   0.000},
67999      {  0.000,   0.000},
68000      {  0.000,   0.000},
68001      {  0.000,   0.000},
68002      {  0.000,   0.000},
68003      {  0.000,   0.000}
68004 };
68005 
68006 static float gftor4[MXGTOR][2] = {
68007      {  0.0,   0.0},
68008      {  0.0,   0.0},
68009      {  0.0,   0.0},
68010      {  0.0,   0.0},
68011      {  0.0,   0.0},
68012      {  0.0,   0.0},
68013      {  0.0,   0.0},
68014      {  0.0,   0.0},
68015      {  0.0,   0.0},
68016      {  0.0,   0.0},
68017      {  0.0,   0.0},
68018      {  0.0,   0.0},
68019      {  0.0,   0.0},
68020      {  0.0,   0.0},
68021      {  0.0,   0.0},
68022      {  0.0,   0.0},
68023      {  0.0,   0.0},
68024      {  0.0,   0.0},
68025      {  0.0,   0.0},
68026      {  0.0,   0.0},
68027      {  0.0,   0.0},
68028      { 0.35, 180.0},
68029      {  0.0,   0.0},
68030      {  0.0,   0.0},
68031      {  0.0,   0.0},
68032      {  0.0,   0.0},
68033      {  0.0,   0.0},
68034      {  0.0,   0.0},
68035      {  0.0,   0.0},
68036      {  0.0,   0.0},
68037      {  0.0,   0.0},
68038      {  0.0,   0.0},
68039      {  0.0,   0.0},
68040      {  0.0,   0.0},
68041      {  0.0,   0.0},
68042      {  0.0,   0.0},
68043      {  0.0,   0.0},
68044      {  0.0,   0.0},
68045      {  0.0,   0.0},
68046      {  0.0,   0.0},
68047      {  0.0,   0.0},
68048      {  0.0,   0.0},
68049      {  0.0,   0.0},
68050      {  0.0,   0.0},
68051      {  0.0,   0.0},
68052      {  0.0,   0.0},
68053      {  0.0,   0.0},
68054      {  0.0,   0.0},
68055      {  0.0,   0.0},
68056      {  0.0,   0.0},
68057      {  0.0,   0.0},
68058      {  0.0,   0.0},
68059      {  0.0,   0.0},
68060      {  0.0,   0.0},
68061      {  0.0,   0.0},
68062      {  0.0,   0.0},
68063      {  0.0,   0.0},
68064      {  0.0,   0.0},
68065      {  0.0,   0.0},
68066      {  0.0,   0.0},
68067      {  0.0,   0.0},
68068      {  0.0,   0.0},
68069      {  0.0,   0.0},
68070      {  0.0,   0.0},
68071      {  0.0,   0.0},
68072      {  0.0,   0.0},
68073      {  0.0,   0.0},
68074      {  0.0,   0.0},
68075      {  0.0,   0.0},
68076      {  0.0,   0.0},
68077      {  0.0,   0.0},
68078      {  0.0,   0.0},
68079      {  0.0,   0.0},
68080      {  0.0,   0.0},
68081      {  0.0,   0.0},
68082      {  0.0,   0.0},
68083      {  0.0,   0.0},
68084      {  0.0,   0.0},
68085      {  0.0,   0.0},
68086      {  0.0,   0.0},
68087      {  0.0,   0.0},
68088      {  0.0,   0.0},
68089      {  0.0,   0.0},
68090      {  0.0,   0.0},
68091      {  0.0,   0.0},
68092      {  0.0,   0.0},
68093      {  0.0,   0.0},
68094      {  0.0,   0.0},
68095      {  0.0,   0.0},
68096      {  0.0,   0.0},
68097      {  0.0,   0.0},
68098      {  0.0,   0.0},
68099      {  0.0,   0.0},
68100      {  0.0,   0.0},
68101      {  0.0,   0.0},
68102      {  0.0,   0.0},
68103      {  0.0,   0.0},
68104      {  0.0,   0.0},
68105      {  0.0,   0.0},
68106      {  0.0,   0.0},
68107      {  0.0,   0.0},
68108      {  0.0,   0.0},
68109      {  0.0,   0.0},
68110      {  0.0,   0.0},
68111      {  0.0,   0.0},
68112      {  0.0,   0.0},
68113      {  0.0,   0.0},
68114      {  0.0,   0.0},
68115      {  0.0,   0.0},
68116      {  0.0,   0.0},
68117      {  0.0,   0.0},
68118      {  0.0,   0.0},
68119      {  0.0,   0.0},
68120      {  0.0,   0.0},
68121      {  0.0,   0.0},
68122      {  0.0,   0.0},
68123      {  0.0,   0.0},
68124      {  0.0,   0.0},
68125      {  0.0,   0.0},
68126      {  0.0,   0.0},
68127      {  0.0,   0.0},
68128      {  0.0,   0.0},
68129      {  0.0,   0.0},
68130      {  0.0,   0.0},
68131      {  0.0,   0.0},
68132      {  0.0,   0.0},
68133      {  0.0,   0.0},
68134      {  0.0,   0.0},
68135      {  0.0,   0.0},
68136      {  0.0,   0.0},
68137      {  0.0,   0.0},
68138      {  0.0,   0.0},
68139      {  0.0,   0.0},
68140      {  0.0,   0.0},
68141      {  0.0,   0.0},
68142      {  0.0,   0.0},
68143      {  0.0,   0.0},
68144      {  0.0,   0.0},
68145      {  0.0,   0.0},
68146      {  0.0,   0.0},
68147      {  0.0,   0.0},
68148      {  0.0,   0.0},
68149      {  0.0,   0.0},
68150      {  0.0,   0.0},
68151      {  0.0,   0.0},
68152      {  0.0,   0.0},
68153      {  0.0,   0.0},
68154      {  0.0,   0.0},
68155      {  0.0,   0.0},
68156      {  0.0,   0.0},
68157      {  0.0,   0.0},
68158      {  0.0,   0.0},
68159      {  0.0,   0.0},
68160      {  0.0,   0.0},
68161      {  0.0,   0.0},
68162      {  0.0,   0.0},
68163      {  0.0,   0.0},
68164      {  0.0,   0.0},
68165      {  0.0,   0.0},
68166      {  0.0,   0.0},
68167      {  0.0,   0.0},
68168      {  0.0,   0.0},
68169      {  0.0,   0.0},
68170      {  0.0,   0.0},
68171      {  0.0,   0.0},
68172      {  0.0,   0.0},
68173      {  0.0,   0.0},
68174      {  0.0,   0.0},
68175      {  0.0,   0.0},
68176      {  0.0,   0.0},
68177      {  0.0,   0.0},
68178      {  0.0,   0.0},
68179      {  0.0,   0.0},
68180      {  0.0,   0.0},
68181      {  0.0,   0.0},
68182      {  0.0,   0.0},
68183      {  0.0,   0.0},
68184      {  0.0,   0.0},
68185      {  0.0,   0.0},
68186      {  0.0,   0.0},
68187      {  0.0,   0.0},
68188      {  0.0,   0.0},
68189      {  0.0,   0.0},
68190      {  0.0,   0.0},
68191      {  0.0,   0.0},
68192      {  0.0,   0.0},
68193      {  0.0,   0.0},
68194      {  0.0,   0.0},
68195      {  0.0,   0.0},
68196      {  0.0,   0.0},
68197      {  0.0,   0.0},
68198      {  0.0,   0.0},
68199      {  0.0,   0.0},
68200      {  0.0,   0.0},
68201      {  0.0,   0.0},
68202      {  0.0,   0.0},
68203      {  0.0,   0.0},
68204      {  0.0,   0.0},
68205      {  0.0,   0.0},
68206      {  0.0,   0.0},
68207      {  0.0,   0.0},
68208      {  0.0,   0.0},
68209      {  0.0,   0.0},
68210      {  0.0,   0.0},
68211      {  0.0,   0.0},
68212      {  0.0,   0.0},
68213      {  0.0,   0.0},
68214      {  0.0,   0.0},
68215      {  0.0,   0.0},
68216      {  0.0,   0.0},
68217      {  0.0,   0.0},
68218      {  0.0,   0.0},
68219      {  0.0,   0.0},
68220      {  0.0,   0.0},
68221      {  0.0,   0.0},
68222      {  0.0,   0.0},
68223      {  0.0,   0.0},
68224      {  0.0,   0.0},
68225      {  0.0,   0.0},
68226      {  0.0,   0.0},
68227      {  0.0,   0.0},
68228      {  0.0,   0.0},
68229      {  0.0,   0.0},
68230      {  0.0,   0.0},
68231      {  0.0,   0.0},
68232      {  0.0,   0.0},
68233      {  0.0,   0.0},
68234      {  0.0,   0.0},
68235      {  0.0,   0.0},
68236      {  0.0,   0.0},
68237      {  0.0,   0.0},
68238      {  0.0,   0.0},
68239      {  0.0,   0.0},
68240      {  0.0,   0.0},
68241      {  0.0,   0.0},
68242      {  0.0,   0.0},
68243      {  0.0,   0.0},
68244      {  0.0,   0.0},
68245      {  0.0,   0.0},
68246      {  0.0,   0.0},
68247      {  0.0,   0.0},
68248      {  0.0,   0.0},
68249      {  0.0,   0.0},
68250      {  0.0,   0.0},
68251      {  0.0,   0.0},
68252      {  0.0,   0.0},
68253      {  0.0,   0.0},
68254      {  0.0,   0.0},
68255      {  0.0,   0.0},
68256      {  0.0,   0.0},
68257      {  0.0,   0.0},
68258      {  0.0,   0.0},
68259      {  0.0,   0.0},
68260      {  0.0,   0.0},
68261      {  0.0,   0.0},
68262      {  0.0,   0.0},
68263      {  0.0,   0.0},
68264      {  0.0,   0.0},
68265      {  0.0,   0.0},
68266      {  0.0,   0.0},
68267      {  0.0,   0.0},
68268      {  0.0,   0.0},
68269      {  0.0,   0.0},
68270      {  0.0,   0.0},
68271      {  0.0,   0.0},
68272      {  0.0,   0.0},
68273      {  0.0,   0.0},
68274      {  0.0,   0.0},
68275      {  0.0,   0.0},
68276      {  0.0,   0.0},
68277      {  0.0,   0.0},
68278      {  0.0,   0.0},
68279      {  0.0,   0.0},
68280      {  0.0,   0.0},
68281      {  0.0,   0.0},
68282      {  0.0,   0.0},
68283      {  0.0,   0.0},
68284      {  0.0,   0.0},
68285      {  0.0,   0.0},
68286      {  0.0,   0.0},
68287      {  0.0,   0.0},
68288      {  0.0,   0.0},
68289      {  0.0,   0.0},
68290      {  0.0,   0.0},
68291      {  0.0,   0.0},
68292      {  0.0,   0.0},
68293      {  0.0,   0.0},
68294      {  0.0,   0.0},
68295      {  0.0,   0.0},
68296      {  0.0,   0.0},
68297      {  0.0,   0.0},
68298      {  0.0,   0.0},
68299      {  0.0,   0.0},
68300      {  0.0,   0.0},
68301      {  0.0,   0.0},
68302      {  0.0,   0.0},
68303      {  0.0,   0.0},
68304      {  0.0,   0.0},
68305      {  0.0,   0.0},
68306      {  0.0,   0.0},
68307      {  0.0,   0.0},
68308      {  0.0,   0.0},
68309      {  0.0,   0.0},
68310      {  0.0,   0.0},
68311      {  0.0,   0.0},
68312      {  0.0,   0.0},
68313      {  0.0,   0.0},
68314      {  0.0,   0.0},
68315      {  0.0,   0.0},
68316      {  0.0,   0.0},
68317      {  0.0,   0.0},
68318      {  0.0,   0.0},
68319      {  0.0,   0.0},
68320      {  0.0,   0.0},
68321      {  0.0,   0.0},
68322      {  0.0,   0.0},
68323      {  0.0,   0.0},
68324      {  0.0,   0.0},
68325      {  0.0,   0.0},
68326      {  0.0,   0.0},
68327      {  0.0,   0.0},
68328      {  0.0,   0.0},
68329      {  0.0,   0.0},
68330      {  0.0,   0.0},
68331      {  0.0,   0.0},
68332      {  0.0,   0.0},
68333      {  0.0,   0.0},
68334      {  0.0,   0.0},
68335      {  0.0,   0.0},
68336      {  0.0,   0.0},
68337      {  0.0,   0.0},
68338      {  0.0,   0.0},
68339      {  0.0,   0.0},
68340      {  0.0,   0.0},
68341      {  0.0,   0.0},
68342      {  0.0,   0.0},
68343      {  0.0,   0.0},
68344      {  0.0,   0.0},
68345      {  0.0,   0.0},
68346      {  0.0,   0.0},
68347      {  0.0,   0.0},
68348      {  0.0,   0.0},
68349      {  0.0,   0.0},
68350      {  0.0,   0.0},
68351      {  0.0,   0.0},
68352      {  0.0,   0.0},
68353      {  0.0,   0.0},
68354      {  0.0,   0.0},
68355      {  0.0,   0.0},
68356      {  0.0,   0.0},
68357      {  0.0,   0.0},
68358      {  0.0,   0.0},
68359      {  0.0,   0.0},
68360      {  0.0,   0.0},
68361      {  0.0,   0.0},
68362      {  0.0,   0.0},
68363      {  0.0,   0.0},
68364      {  0.0,   0.0},
68365      {  0.0,   0.0},
68366      {  0.0,   0.0},
68367      {  0.0,   0.0},
68368      {  0.0,   0.0},
68369      {  0.0,   0.0},
68370      {  0.0,   0.0},
68371      {  0.0,   0.0},
68372      {  0.0,   0.0},
68373      {  0.0,   0.0},
68374      {  0.0,   0.0},
68375      {  0.0,   0.0},
68376      {  0.0,   0.0},
68377      {  0.0,   0.0},
68378      {  0.0,   0.0},
68379      {  0.0,   0.0},
68380      {  0.0,   0.0},
68381      {  0.0,   0.0},
68382      {  0.0,   0.0},
68383      {  0.0,   0.0},
68384      {  0.0,   0.0},
68385      {  0.0,   0.0},
68386      {  0.0,   0.0},
68387      {  0.0,   0.0},
68388      {  0.0,   0.0},
68389      {  0.0,   0.0},
68390      {  0.0,   0.0},
68391      {  0.0,   0.0},
68392      {  0.0,   0.0},
68393      {  0.0,   0.0},
68394      {  0.0,   0.0},
68395      {  0.0,   0.0},
68396      {  0.0,   0.0},
68397      {  0.0,   0.0},
68398      {  0.0,   0.0},
68399      {  0.0,   0.0},
68400      {  0.0,   0.0},
68401      {  0.0,   0.0},
68402      {  0.0,   0.0},
68403      {  0.0,   0.0},
68404      {  0.0,   0.0},
68405      {  0.0,   0.0},
68406      {  0.0,   0.0},
68407      {  0.0,   0.0},
68408      {  0.0,   0.0},
68409      {  0.0,   0.0},
68410      {  0.0,   0.0},
68411      {  0.0,   0.0},
68412      {  0.0,   0.0},
68413      {  0.0,   0.0},
68414      {  0.0,   0.0},
68415      {  0.0,   0.0},
68416      {  0.0,   0.0},
68417      {  0.0,   0.0},
68418      {  0.0,   0.0},
68419      {  0.0,   0.0},
68420      {  0.0,   0.0},
68421      {  0.0,   0.0},
68422      {  0.0,   0.0},
68423      {  0.0,   0.0},
68424      {  0.0,   0.0},
68425      {  0.0,   0.0},
68426      {  0.0,   0.0},
68427      {  0.0,   0.0},
68428      {  0.0,   0.0},
68429      {  0.0,   0.0},
68430      {  0.0,   0.0},
68431      {  0.0,   0.0},
68432      {  0.0,   0.0},
68433      {  0.0,   0.0},
68434      {  0.0,   0.0},
68435      {  0.0,   0.0},
68436      {  0.0,   0.0},
68437      {  0.0,   0.0},
68438      {  0.0,   0.0},
68439      {  0.0,   0.0},
68440      {  0.0,   0.0},
68441      {  0.0,   0.0},
68442      {  0.0,   0.0},
68443      {  0.0,   0.0},
68444      {  0.0,   0.0},
68445      {  0.0,   0.0},
68446      {  0.0,   0.0},
68447      {  0.0,   0.0},
68448      {  0.0,   0.0},
68449      {  0.0,   0.0},
68450      {  0.0,   0.0},
68451      {  0.0,   0.0},
68452      {  0.0,   0.0},
68453      {  0.0,   0.0},
68454      {  0.0,   0.0},
68455      {  0.0,   0.0},
68456      {  0.0,   0.0},
68457      {  0.0,   0.0},
68458      {  0.0,   0.0},
68459      {  0.0,   0.0},
68460      {  0.0,   0.0},
68461      {  0.0,   0.0},
68462      {  0.4, 180.0},
68463      {  0.0,   0.0},
68464      {  0.0,   0.0},
68465      {  0.0,   0.0},
68466      {  0.0,   0.0},
68467      {  0.0,   0.0},
68468      {  0.0,   0.0},
68469      {  0.0,   0.0},
68470      {  0.0,   0.0},
68471      {  0.0,   0.0},
68472      {  0.0,   0.0},
68473      {  0.0,   0.0},
68474      {  0.0,   0.0},
68475      {  0.0,   0.0},
68476      {  0.0,   0.0},
68477      {  0.0,   0.0},
68478      {  0.0,   0.0},
68479      {  0.0,   0.0},
68480      {  0.0,   0.0},
68481      {  0.0,   0.0},
68482      {  0.0,   0.0},
68483      {  0.0,   0.0},
68484      {  0.0,   0.0},
68485      {  0.0,   0.0},
68486      {  0.0,   0.0},
68487      {  0.0,   0.0},
68488      {  0.0,   0.0},
68489      {  0.0,   0.0},
68490      {  0.0,   0.0},
68491      {  0.0,   0.0},
68492      {  0.0,   0.0},
68493      {  0.0,   0.0},
68494      {  0.0,   0.0},
68495      {  0.0,   0.0},
68496      {  0.0,   0.0},
68497      {  0.0,   0.0},
68498      {  0.0,   0.0},
68499      {  0.0,   0.0},
68500      {  0.0,   0.0},
68501      {  0.0,   0.0},
68502      {  0.0,   0.0},
68503      {  0.0,   0.0},
68504      {  0.0,   0.0},
68505      {  0.0,   0.0},
68506      {  0.0,   0.0},
68507      {  0.0,   0.0},
68508      {  0.0,   0.0},
68509      {  0.0,   0.0},
68510      {  0.0,   0.0},
68511      {  0.0,   0.0},
68512      {  0.0,   0.0},
68513      {  0.0,   0.0},
68514      {  0.0,   0.0},
68515      {  0.0,   0.0},
68516      {  0.0,   0.0},
68517      {  0.0,   0.0},
68518      {  0.0,   0.0},
68519      {  0.0,   0.0},
68520      {  0.0,   0.0},
68521      {  0.0,   0.0},
68522      {  0.0,   0.0},
68523      {  0.0,   0.0},
68524      {  0.0,   0.0},
68525      {  0.0,   0.0},
68526      {  0.0,   0.0},
68527      {  0.0,   0.0},
68528      {  0.0,   0.0},
68529      {  0.0,   0.0},
68530      {  0.0,   0.0},
68531      {  0.0,   0.0},
68532      {  0.0,   0.0},
68533      {  0.0,   0.0},
68534      {  0.0,   0.0},
68535      {  0.0,   0.0},
68536      {  0.0,   0.0},
68537      {  0.0,   0.0},
68538      {  0.0,   0.0},
68539      {  0.0,   0.0},
68540      {  0.0,   0.0},
68541      {  0.0,   0.0},
68542      {  0.0,   0.0},
68543      {  0.0,   0.0},
68544      {  0.0,   0.0},
68545      {  0.0,   0.0},
68546      {  0.0,   0.0},
68547      {  0.0,   0.0},
68548      {  0.0,   0.0},
68549      {  0.0,   0.0},
68550      {  0.0,   0.0},
68551      {  0.0,   0.0},
68552      {  0.0,   0.0},
68553      {  0.0,   0.0},
68554      {  0.0,   0.0},
68555      {  0.0,   0.0},
68556      {  0.0,   0.0},
68557      {  0.0,   0.0},
68558      {  0.0,   0.0},
68559      {  0.0,   0.0},
68560      {  0.0,   0.0},
68561      {  0.0,   0.0},
68562      {  0.0,   0.0},
68563      {  0.0,   0.0},
68564      {  0.0,   0.0},
68565      {  0.0,   0.0},
68566      {  0.0,   0.0},
68567      {  0.0,   0.0},
68568      {  0.0,   0.0},
68569      {  0.0,   0.0},
68570      {  0.0,   0.0},
68571      {  0.0,   0.0},
68572      {  0.0,   0.0},
68573      {  0.0,   0.0},
68574      {  0.0,   0.0},
68575      {  0.0,   0.0},
68576      {  0.0,   0.0},
68577      {  0.0,   0.0},
68578      {  0.0,   0.0},
68579      {  0.0,   0.0},
68580      {  0.0,   0.0},
68581      {  0.0,   0.0},
68582      {  0.0,   0.0},
68583      {  0.0,   0.0},
68584      {  0.0,   0.0},
68585      {  0.0,   0.0},
68586      {  0.0,   0.0},
68587      {  0.0,   0.0},
68588      {  0.0,   0.0},
68589      {  0.0,   0.0},
68590      {  0.0,   0.0},
68591      {  0.0,   0.0},
68592      {  0.0,   0.0},
68593      {  0.0,   0.0},
68594      {  0.0,   0.0},
68595      {  0.0,   0.0},
68596      {  0.0,   0.0},
68597      {  0.5, 180.0},
68598      {  0.1,   0.0},
68599      {  0.0,   0.0},
68600      {  0.0,   0.0},
68601      {  0.0,   0.0},
68602      {  0.0,   0.0},
68603      {  0.0,   0.0},
68604      {  0.0,   0.0},
68605      {  0.0,   0.0},
68606      {  0.0,   0.0},
68607      {  0.0,   0.0},
68608      {  0.0,   0.0},
68609      {  0.0,   0.0},
68610      {  0.0,   0.0},
68611      {  0.0,   0.0},
68612      {  0.0,   0.0},
68613      {  0.0,   0.0},
68614      {  0.0,   0.0},
68615      {  0.0,   0.0},
68616      {  0.0,   0.0},
68617      {  0.0,   0.0},
68618      {  0.0,   0.0},
68619      {  0.0,   0.0},
68620      {  0.0,   0.0},
68621      {  0.0,   0.0},
68622      {  0.0,   0.0},
68623      {  0.0,   0.0},
68624      {  0.0,   0.0},
68625      {  0.0,   0.0},
68626      {  0.0,   0.0},
68627      {  0.0,   0.0},
68628      {  0.0,   0.0},
68629      {  0.0,   0.0},
68630      {  0.0,   0.0},
68631      {  0.0,   0.0},
68632      {  0.0,   0.0},
68633      {  0.0,   0.0},
68634      {  0.0,   0.0},
68635      {  0.0,   0.0},
68636      {  0.0,   0.0},
68637      {  0.0,   0.0},
68638      {  0.0,   0.0},
68639      {  0.0,   0.0},
68640      {  0.0,   0.0},
68641      {  0.0,   0.0},
68642      {  0.0,   0.0},
68643      {  0.0,   0.0},
68644      {  0.0,   0.0}
68645 };
68646 
init_incrstru()68647 void init_incrstru()
68648 {
68649 	int i,j;
68650 
68651 	modtyp.type   = -1;
68652 	modtyp.area   = EMPT;
68653 	modtyp.ohlig  = 0;
68654 	modtyp.ohsame = 0;
68655 	modtyp.nfrag  = 0;
68656 	modtyp.n      = 0;
68657 	modtyp.npts   = 0;
68658 	modtyp.link   = -1;
68659 	modtyp.conf   = -1;
68660 	modtyp.npts   = 0;
68661 	modtyp.npts   = -1;
68662 
68663 	for (i = 0; i < 3; i++) {
68664 	   modtyp.frag[i] = -1;
68665 	   modtyp.atom[i] = -1;
68666 	   modtyp.ORI[i] = 0.0;
68667 	   for (j = 0; j < 4; j++) {
68668 		modtyp.c[j][i] = 0.0;
68669 	   }
68670 	}
68671 
68672 	for (i = 0; i < 200; i++) {
68673 	   modtyp.ConfArr[i] = -1;
68674 	}
68675 
68676 	modtyp.q0 = 0.0;
68677 	modtyp.q1 = 0.0;
68678 	modtyp.q2 = 0.0;
68679 	modtyp.q3 = 0.0;
68680 
68681 	modtyp.points = NULL;
68682 }
68683 
init_tristru()68684 void init_tristru()
68685 {
68686 	int i,j;
68687 
68688 	EmpTri.frag   = -1;
68689 	EmpTri.triS   = -1;
68690 	EmpTri.conf   = -1;
68691 	EmpTri.nconf  = 0;
68692 
68693 	for (i = 0; i < 3; i++) {
68694 	   EmpTri.p1[i] = 0.0;
68695 	   EmpTri.p2[i] = 0.0;
68696 	   EmpTri.p3[i] = 0.0;
68697 	   EmpTri.p1c[i] = 0.0;
68698 	   EmpTri.p2c[i] = 0.0;
68699 	   EmpTri.p3c[i] = 0.0;
68700 	   EmpTri.P1[i] = 0.0;
68701 	   EmpTri.P2[i] = 0.0;
68702 	   EmpTri.P3[i] = 0.0;
68703 	   EmpTri.Cen[i] = 0.0;
68704 	   EmpTri.CenO[i] = 0.0;
68705 	   EmpTri.Out[i] = 0.0;
68706 	   EmpTri.OutO[i] = 0.0;
68707 	   EmpTri.OutOrg[i] = 0.0;
68708 	   EmpTri.t[i] = 0.0;
68709 	}
68710 
68711 	for (i = 0; i < 3; i++) {
68712 	   EmpTri.lig[i]   = -1;
68713 	   EmpTri.ohlig[i] = -1;
68714 	   EmpTri.prot[i]  = -1;
68715 	   EmpTri.frags[i] = -1;
68716 	   EmpTri.grp[i]   = -1;
68717 	}
68718 
68719 	for (i = 0; i < 4; i++) {
68720 	   for (j = 0; j < 4; j++) {
68721 		EmpTri.R1[j][i] = 0.0;
68722 		EmpTri.R2[j][i] = 0.0;
68723 	   }
68724 	}
68725 
68726 	EmpTri.d12 = 0.0;
68727 	EmpTri.d13 = 0.0;
68728 	EmpTri.d23 = 0.0;
68729 	EmpTri.e12 = 0.0;
68730 	EmpTri.eint = 0.0;
68731 	EmpTri.etot = 0.0;
68732 
68733 	EmpTri.coo = NULL;
68734 	EmpTri.oh[0] = NULL;
68735 	EmpTri.oh[1] = NULL;
68736 	EmpTri.oh[2] = NULL;
68737 }
68738 
ChkLig(int ATMselp)68739 int ChkLig(int ATMselp)
68740 {
68741   if (ATMselp < lintp && DCKLIGPROC) return 1;
68742   return 0;
68743 }
68744 
ChkProt(int ATMselp)68745 int ChkProt(int ATMselp)
68746 {
68747   if (ATMselp < nintp && DCKPROTPROC) return 1;
68748   return 0;
68749 }
68750 
NoCH_Prot(int * iclos)68751 void NoCH_Prot(int *iclos)
68752 {
68753    int k,l,la;
68754 
68755    for (k=0; k<*xyzp->iatoms; k++) {
68756 	if (iclos[k]) {
68757 	   if (xyzp->ianz[k] == 1) {
68758 		l = xyzp->iconn[k*(MXCON+1)+1];
68759 		la = abs(l);
68760 		if (la > 0) if (xyzp->ianz[la-1] == 6) iclos[k] = 0;
68761 	   }
68762 	}
68763    }
68764 }
68765 
NoCH_Lig(int * frg)68766 void NoCH_Lig(int *frg)
68767 {
68768    int k,l,la;
68769 
68770    for (k=0; k < ndocka; k++) {
68771 	if (frg[k]) {
68772 	   if (DCKxyz.ianz[k] == 1) {
68773 		l = DCKxyz.iconn[k*(MXCON+1)+1];
68774 		la = abs(l);
68775 		if (la > 0) if (DCKxyz.ianz[la-1] == 6) frg[k] = 0;
68776 	   }
68777 	}
68778    }
68779 }
68780 
FillOpt(int * iclos,int i)68781 void FillOpt(int *iclos,int i)
68782 {
68783    int j,k,kmin1,kmin2;
68784    float dd,tt,dmin1,dmin2;
68785 
68786 // Fill iclos array with protein atoms closer than OPTradius to ligand pose //
68787 
68788    dmin1 = 10000.0;
68789    dmin2 = 10000.0;
68790    kmin1 = -1;
68791    kmin2 = -1;
68792 
68793    for (k=0; k<*xyzp->iatoms; k++) {
68794 
68795 	dd = 0.0;
68796 	iclos[k] = 0;
68797 
68798 //	if (xyzp->iresid[k] > 0 && xyzp->ianz[k] != 1) {
68799 	if (xyzp->iresid[k] > 0) {
68800 	    for (j=0; j<3; j++) {
68801 		tt = ((float) xyzp->coo[k*3+j] - TriArr[i]->Cen[j]);
68802 		dd = dd + tt*tt;
68803 	    }
68804 	    dd = sqrt(dd)*toangs;
68805 	    if (dd < OPTRadius) {
68806 		iclos[k] = 1;
68807 		if (dd < dmin1) {
68808 		   dmin1 = dd;
68809 		   kmin1 = k;
68810 		} else {
68811 		   if (dd < dmin2) {
68812 			dmin2 = dd;
68813 			kmin2 = k;
68814 		   }
68815 		}
68816 	    }
68817 	}
68818    }
68819 
68820    if (kmin1 != -1) iclos[kmin1] = 2;
68821    if (kmin2 != -1) iclos[kmin2] = 2;
68822 }
68823 
FillCOpt(int * iclos,int i)68824 void FillCOpt(int *iclos,int i)
68825 {
68826    int j,k,l,ia;
68827    float dd,tt,dmin;
68828 
68829 // This different from FillOpt in that FillOpt only looks
68830 // for protein atoms close to TriArr[i]->Cen
68831 // FillCOpt looks at atoms close to singleb.sng[l][0]
68832 
68833    dmin = 10000.0;
68834 
68835    for (k=0; k<*xyzp->iatoms; k++) {
68836 
68837 	dd = 0.0;
68838 	iclos[k] = 0;
68839 
68840 	if (xyzp->iresid[k] > 0) {
68841 	  for (l=0; l < singleb.N; l++) {
68842 	    ia = singleb.sng[l][0];
68843 	    for (j=0; j<3; j++) {
68844 		tt = ((float) xyzp->coo[k*3+j] - TriArr[i]->coo[ia*3+j]);
68845 		dd = dd + tt*tt;
68846 	    }
68847 	    dd = sqrt(dd)*toangs;
68848 	    if (dd < OPTRadius) {
68849 		iclos[k] = 1;
68850 		if (dd < dmin) {
68851 		   dmin = dd;
68852 		}
68853 	    }
68854 	  }
68855 	}
68856    }
68857 
68858 }
68859 
FillFull(int * iclos,int i)68860 void FillFull(int *iclos,int i)
68861 {
68862    int j,k,l,ia;
68863    float dd,tt,dmin;
68864 
68865 // This different from FillOpt in that FillOpt only looks
68866 // for protein atoms close to TriArr[i]->Cen
68867 // FillCOpt looks at atoms close to singleb.sng[l][0]
68868 
68869    dmin = 10000.0;
68870 
68871    for (k=0; k<*xyzp->iatoms; k++) {
68872 
68873 	dd = 0.0;
68874 	iclos[k] = 0;
68875 
68876 	if (xyzp->iresid[k] > 0) {
68877 	  for (l=0; l < ndocka; l++) {
68878 	    for (j=0; j<3; j++) {
68879 		tt = ((float) xyzp->coo[k*3+j] - TriArr[i]->coo[l*3+j]);
68880 		dd = dd + tt*tt;
68881 	    }
68882 	    dd = sqrt(dd)*toangs;
68883 	    if (dd < OPTRadius) {
68884 		iclos[k] = 1;
68885 		if (dd < dmin) {
68886 		   dmin = dd;
68887 		}
68888 	    }
68889 	  }
68890 	}
68891    }
68892 
68893 }
68894 
FillClos(int * iclos,int itri)68895 void FillClos(int *iclos,int itri)
68896 {
68897    int j,k,l,ia;
68898    float dd,tt,dmin;
68899 
68900 // This different from FillOpt in that FillOpt only looks
68901 // for protein atoms close to TriArr[i]->Cen
68902 // FillClos looks at atoms close to all atoms of the ligand pose
68903 
68904    for (k=0; k<*xyzp->iatoms; k++) {
68905 
68906 	dd = 0.0;
68907 	iclos[k] = 0;
68908 
68909 	if (xyzp->iresid[k] > 0) {
68910 	  for (l=0; l < ndocka; l++) {
68911 	    for (j=0; j<3; j++) {
68912 		tt = ((float) xyzp->coo[k*3+j] - TriArr[itri]->coo[l*3+j]);
68913 		dd = dd + tt*tt;
68914 	    }
68915 	    dd = sqrt(dd)*toangs;
68916 	    if (dd < OPTRadius) iclos[k] = 1;
68917 	  }
68918 	}
68919    }
68920 
68921 }
68922 
ChkBump(int * iclos,int i)68923 void ChkBump(int *iclos,int i)
68924 {
68925    int j,k,l,kmin,jmin,il,it;
68926    float dd,dl,tt,dmin,vdwr1,vdwr2,dir[3],ddif,xx;
68927 
68928    dmin = 10000.0;
68929    kmin = -1;
68930    jmin = -1;
68931 
68932    for (j=0; j<*xyzp->iatoms; j++) {
68933 	if (iclos[j] == 2) {
68934 	   kmin = j;
68935 	   it = (int) xyzp->ityp[j];
68936 	   il = chgvdwptr->ambvdt[it-1]-1;
68937 	   vdwr1 = (float) chgvdwptr->ambvw1[il];
68938 	   iclos[j] = 1;
68939 	   break;
68940 	}
68941    }
68942 
68943 
68944    for (j=0; j < ndocka; j++) {
68945 
68946      if (DCKxyz.ianz[j] != 1) {
68947 	dd = 0.0;
68948 	for (k=0; k<3; k++) {
68949 	   tt = (float) (TriArr[i]->coo[j*3+k] - xyzp->coo[kmin*3+k]);
68950 	   tt = tt*toangs;
68951 	   dd = dd + tt*tt;
68952 	}
68953 	dd = sqrt(dd);
68954 
68955 	if (dd < dmin) {
68956 	   dmin = dd;
68957 	   jmin = j;
68958 	}
68959      }
68960    }
68961 
68962 
68963    if (jmin != -1) {
68964 
68965 	it = (int) singleb.ityp[jmin];
68966 	if (it < 0) {
68967 	   il = ABS(it) - 1;
68968 	   vdwr2 = (float) chgvdwptr->gfvdw[il][0];
68969 	}
68970 
68971 	dd = 0.0;
68972 	for (k=0; k<3; k++) {
68973 	   dir[k] = (float) (TriArr[i]->coo[jmin*3+k] - xyzp->coo[kmin*3+k]);
68974 	   dir[k] = dir[k]*toangs;
68975 	   dd = dd + dir[k]*dir[k];
68976 	}
68977 	dd = sqrt(dd);
68978 
68979 	if (dd < vdwr1+vdwr2) {
68980 
68981 //fprintf(stderr,"bumping up Tri %d dd %f vdwr1+vdwr2 %f jmin %d kmin %d\n",i,dd,vdwr1+vdwr2,jmin,kmin);
68982 
68983 	   dl = veclen(dir);
68984 	   for (k=0; k<3; k++) dir[k] = dir[k]/dl;
68985 
68986 	   ddif = vdwr1 + vdwr2 - dd + 0.1;
68987 
68988 	   for (k=0; k<3; k++) dir[k] = dir[k]*ddif/toangs;
68989 
68990 	   for (j=0; j < ndocka; j++) {
68991 		for (k=0; k<3; k++) {
68992 		   TriArr[i]->coo[j*3+k] = TriArr[i]->coo[j*3+k]
68993 			+ (double) dir[k];
68994 		}
68995 	   }
68996 
68997 	   for (k=0; k<3; k++) {
68998 		TriArr[i]->Cen[k]  = TriArr[i]->Cen[k] + dir[k];
68999 	   }
69000 
69001 	} else {
69002 //fprintf(stderr,"NOT bumping up Tri %d dd %f vdwr1+vdwr2 %f\n",i,dd,vdwr1+vdwr2);
69003 	}
69004    }
69005 
69006    dmin = 10000.0;
69007    kmin = -1;
69008    jmin = -1;
69009 
69010    for (j=0; j<*xyzp->iatoms; j++) {
69011 	if (iclos[j] == 2) {
69012 	   kmin = j;
69013 	   it = (int) xyzp->ityp[j];
69014 	   il = chgvdwptr->ambvdt[it-1]-1;
69015 	   vdwr1 = (float) chgvdwptr->ambvw1[il];
69016 	   iclos[j] = 1;
69017 	   break;
69018 	}
69019    }
69020 
69021 
69022    for (j=0; j < ndocka; j++) {
69023 
69024      if (DCKxyz.ianz[j] != 1) {
69025 	dd = 0.0;
69026 	for (k=0; k<3; k++) {
69027 	   tt = (float) (TriArr[i]->coo[j*3+k] - xyzp->coo[kmin*3+k]);
69028 	   tt = tt*toangs;
69029 	   dd = dd + tt*tt;
69030 	}
69031 	dd = sqrt(dd);
69032 
69033 	if (dd < dmin) {
69034 	   dmin = dd;
69035 	   jmin = j;
69036 	}
69037      }
69038    }
69039 
69040 
69041    if (jmin != -1) {
69042 
69043 	it = (int) singleb.ityp[jmin];
69044 	if (it < 0) {
69045 	   il = ABS(it) - 1;
69046 	   vdwr2 = (float) chgvdwptr->gfvdw[il][0];
69047 	}
69048 
69049 	dd = 0.0;
69050 	for (k=0; k<3; k++) {
69051 	   dir[k] = (float) (TriArr[i]->coo[jmin*3+k] - xyzp->coo[kmin*3+k]);
69052 	   dir[k] = dir[k]*toangs;
69053 	   dd = dd + dir[k]*dir[k];
69054 	}
69055 	dd = sqrt(dd);
69056 
69057 	if (dd < vdwr1+vdwr2) {
69058 
69059 //fprintf(stderr,"bumping up Tri %d dd %f vdwr1+vdwr2 %f jmin %d kmin %d\n",i,dd,vdwr1+vdwr2,jmin,kmin);
69060 
69061 	   dl = veclen(dir);
69062 	   for (k=0; k<3; k++) dir[k] = dir[k]/dl;
69063 
69064 	   ddif = vdwr1 + vdwr2 - dd;
69065 
69066 	   for (k=0; k<3; k++) dir[k] = dir[k]*ddif/toangs;
69067 
69068 	   for (j=0; j < ndocka; j++) {
69069 		for (k=0; k<3; k++) {
69070 		   TriArr[i]->coo[j*3+k] = TriArr[i]->coo[j*3+k]
69071 			+ (double) dir[k];
69072 		}
69073 	   }
69074 
69075 	   for (k=0; k<3; k++) {
69076 		TriArr[i]->Cen[k]  = TriArr[i]->Cen[k] + dir[k];
69077 	   }
69078 
69079 	} else {
69080 //fprintf(stderr,"NOT bumping up Tri %d dd %f vdwr1+vdwr2 %f\n",i,dd,vdwr1+vdwr2);
69081 	}
69082    }
69083 }
69084 
AssChg(float * q)69085 void AssChg(float *q)
69086 {
69087    int i,it;
69088 
69089    typit(7,1);
69090 
69091    for (i=0; i < *xyzp->iatoms; i++) {
69092 	it = (int) xyzp->ityp[i];
69093 	if (! (it < 0)) {
69094 	   q[i] = (float) chgvdwptr->ambchg[it-1];
69095 	} else {
69096 	   q[i] = 0.0;
69097 	}
69098    }
69099 }
69100 
AssVDW(float * vdwr,float * vdwe)69101 void AssVDW(float *vdwr, float *vdwe)
69102 {
69103    int i,it,il;
69104 
69105    for (i=0; i < *xyzp->iatoms; i++) {
69106 	it = (int) xyzp->ityp[i];
69107 	if (! (it <= 0)) {
69108 	   il = chgvdwptr->ambvdt[it-1]-1;
69109 	   vdwr[i] = (float) chgvdwptr->ambvw1[il];
69110 	   vdwe[i] = (float) chgvdwptr->ambvw2[il];
69111 	} else {
69112 	   vdwr[i] = 0.0;
69113 	   vdwe[i] = 0.0;
69114 	}
69115    }
69116 }
69117 
AssVDWL(float * vdwr,float * vdwe,float * q)69118 void AssVDWL(float *vdwr, float *vdwe,float *q)
69119 {
69120    int i,it,il;
69121 
69122    for (i=0; i < ndocka; i++) {
69123 	it = (int) singleb.ityp[i];
69124 	if (it < 0) {
69125 	   il = ABS(it) - 1;
69126 	   vdwr[i] = (float) chgvdwptr->gfvdw[il][0];
69127 	   vdwe[i] = (float) chgvdwptr->gfvdw[il][1];
69128 	   q[i] = (float) DCKxyz.qat[i];
69129 
69130 	} else {
69131 	   vdwr[i] = 0.0;
69132 	   vdwe[i] = 0.0;
69133 	   q[i] = 0.0;
69134 	}
69135    }
69136 }
69137 
69138 #define MXDIH 4
69139 
69140 static int jact[MXDIH][MXLIGA];
69141 static int jopt[MXDIH][MXLIGA];
69142 
69143 //#define DCKSCLASH 3.0
69144 #define DCKSCLASH 7.0
69145 #define BIGD 10000.0
69146 
CalClash(iclos,itri,vdwr,vdwrl,coo,idih)69147 float CalClash(iclos,itri,vdwr,vdwrl,coo,idih)
69148 int *iclos;
69149 int itri;
69150 float *vdwr;
69151 float *vdwrl;
69152 double *coo;
69153 int idih;
69154 {
69155    int i,j,k;
69156    float tt,dd,dmin,vdwr1,vdwr2,vsum;
69157 
69158    for (i=0; i<*xyzp->iatoms; i++) {
69159 
69160 	vdwr1 = vdwr[i];
69161 
69162 	if (iclos[i]) {
69163 	   for (j=0; j < ndocka; j++) {
69164 
69165 	     if (jopt[idih][j] == 1) {
69166 		vdwr2 = vdwrl[j];
69167 		if (DCKxyz.ianz[j] == 1) vdwr2 = 0.0;
69168 		vsum = vdwr1 + vdwr2;
69169 		vsum = vsum*vsum;
69170 		dd = 0.0;
69171 
69172 		for (k=0; k<3; k++) {
69173 		   tt = (float) (coo[j*3+k] - xyzp->coo[i*3+k]);
69174 		   tt = tt*toangs;
69175 		   dd = dd + tt*tt;
69176 		}
69177 
69178 		if (dd+DCKSCLASH < vsum) return(BIGD);
69179 	     }
69180 	   }
69181 	}
69182    }
69183 
69184    return(0.0);
69185 }
69186 
CalTorQ(float * rwxyz,int ndocka,float * F)69187 float CalTorQ(float *rwxyz,int ndocka,float *F)
69188 {
69189    int k,l;
69190    float Tres[3],R[3],Tl,Tmin;
69191 /*   float tx,ty,tz,vec[3],TminA,TminB,TminC,TotResX,TotResY,TotResZ;*/
69192 /*   float Res[3],F[3][ndocka];*/
69193    float Res[3];
69194 
69195 /*
69196    TotResX = 0.0; TotResY = 0.0; TotResZ = 0.0;
69197 */
69198    Tres[0] = 0.0; Tres[1] = 0.0; Tres[2] = 0.0;
69199    Tmin = 10000.0;
69200 
69201    for (k=0; k < ndocka; k++) {
69202 
69203 /*
69204 		tx = TriArr[i]->coo[k*3+0] - TriArr[i]->Cen[0];
69205 		ty = TriArr[i]->coo[k*3+1] - TriArr[i]->Cen[1];
69206 		tz = TriArr[i]->coo[k*3+2] - TriArr[i]->Cen[2];
69207 
69208 		vec[0] = tx; vec[1] = 0.0; vec[2] = 0.0;
69209 		cross(vec,&F[0][i],Res);
69210 		TotResX = TotResX + Res[0];
69211 
69212 		vec[0] = 0.0; vec[1] = ty; vec[2] = 0.0;
69213 		cross(vec,&F[0][i],Res);
69214 		TotResY = TotResY + Res[1];
69215 
69216 		vec[0] = 0.0; vec[1] = 0.0; vec[2] = tz;
69217 		cross(vec,&F[0][i],Res);
69218 		TotResZ = TotResZ + Res[2];
69219 */
69220 
69221 	for (l=0; l < 3; l++) {
69222 	   R[l] = rwxyz[k*3+l];
69223 	}
69224 
69225 	cross(R,&F[k],Res);
69226 
69227 	for (l=0; l < 3; l++) {
69228 	   Tres[l] = Tres[l] + Res[l];
69229 	}
69230    }
69231 
69232    Tl = sqrt(Tres[0]*Tres[0] + Tres[1]*Tres[1] + Tres[2]*Tres[2]);
69233    return(Tl);
69234 }
69235 
AllArr(float ** q,float ** vdwr,float ** vdwe,int ** iclos,float ** F)69236 int AllArr(float **q, float **vdwr, float **vdwe, int **iclos, float **F)
69237 {
69238    int i;
69239    float f;
69240 
69241    if ((*q = (float *) malloc((sizeof f)*(*xyzp->iatoms))) == NULL) {
69242 	return(0);
69243    }
69244 
69245    if ((*vdwr = (float *) malloc((sizeof f)*(*xyzp->iatoms))) == NULL) {
69246 	return(0);
69247    }
69248 
69249    if ((*vdwe = (float *) malloc((sizeof f)*(*xyzp->iatoms))) == NULL) {
69250 	return(0);
69251    }
69252 
69253    if ((*iclos = (int *) malloc((sizeof i)*(*xyzp->iatoms))) == NULL) {
69254 	return(0);
69255    }
69256 
69257    if ((*F = (float *) malloc(3*(sizeof f)*(*xyzp->iatoms))) == NULL) {
69258 	return(0);
69259    }
69260 
69261    return(1);
69262 }
69263 
Newxyz(float a,float * dir,float * cwxyz)69264 void Newxyz(float a, float *dir, float *cwxyz)
69265 {
69266    float z[3],E;
69267    int l,j;
69268 
69269    for (l=0; l < 3; l++) {
69270 	z[l] = a*dir[l];
69271    }
69272 
69273    for (j=0; j < ndocka; j++) {
69274 	for (l=0; l < 3; l++) cwxyz[3*j+l] = cwxyz[3*j+l] + z[l];
69275    }
69276 
69277 // return a not correct, it needs to return E as function of cwxyz
69278 // as calculated by CalcFE
69279 
69280    return;
69281 }
69282 
CalcE(float * cxyz,int ohind,int * iclos,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel)69283 float CalcE(float *cxyz,int ohind, int *iclos,
69284 		float *q,float *vdwr,float *vdwe,
69285 		float *ql,float *vdwrl,float *vdwel)
69286 {
69287    int i,j,k,l;
69288    float vr[3],rv,rv2,rs2,rs3,rsum,rinv,epsm,p6,p12;
69289    float e,ev,eq,econv;
69290 
69291    ev = 0.0; eq = 0.0;
69292    econv = 332.05382;
69293 
69294    for (i=0; i < *xyzp->iatoms; i++) {
69295      if (iclos[i]) {
69296 	   for (l=0; l < 3; l++) {
69297 		vr[l] = (cxyz[l] - (float) xyzp->coo[i*3+l]);
69298 		vr[l] =  vr[l]*toangs;
69299 	   }
69300 	   rv2 = vr[0]*vr[0] + vr[1]*vr[1] + vr[2]*vr[2];
69301 	   rv = sqrt(rv2);
69302 	   rinv = 1.0/rv;
69303 	   rsum = vdwr[i] + vdwrl[ohind];
69304 	   epsm = sqrt(vdwe[i]*vdwel[ohind]);
69305 	   rs2 = rsum*rsum;
69306 	   rs3 = rs2*rsum;
69307 	   p6   = (rs3*rs3) / (rv2*rv2*rv2);
69308 	   p12  = p6 * p6;
69309 
69310 	   e    = epsm * (p12 - 2.0*p6);
69311 
69312 	   ev   = ev + e;
69313 
69314 	   e = q[i]*ql[ohind]*econv*rinv;
69315 
69316 	   eq = eq + e;
69317      }
69318    }
69319 
69320    return(eq + ev);
69321 
69322 }
69323 
CalcFE(float * cool,double * coo,int * iclos,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel,float * F,float * E,float * dir,int * frg)69324 void CalcFE(float *cool,double *coo,int *iclos,
69325 		float *q,float *vdwr,float *vdwe,
69326 		float *ql,float *vdwrl,float *vdwel,
69327 		float *F,float *E,float *dir,int *frg)
69328 {
69329    int i,j,k,l;
69330    float vr[3],rv,rv2,rs2,rs3,rsum,rinv,epsm,p6,p12;
69331    float de,e,ev,eq,econv,Fj[3];
69332 
69333    ev = 0.0; eq = 0.0;
69334    econv = 332.05382;
69335 
69336    for (j=0; j < ndocka; j++) {
69337      for (l=0; l < 3; l++) {
69338 	F[j*3+l] = 0.0;
69339      }
69340    }
69341 
69342 
69343    for (i=0; i < *xyzp->iatoms; i++) {
69344      if (iclos[i]) {
69345 	for (j=0; j < ndocka; j++) {
69346 	 if (frg[j]) {
69347 	   for (l=0; l < 3; l++) {
69348 		vr[l] = (cool[j*3+l] - (float) coo[i*3+l]);
69349 		vr[l] =  vr[l]*toangs;
69350 	   }
69351 	   rv2 = vr[0]*vr[0] + vr[1]*vr[1] + vr[2]*vr[2];
69352 	   rv = sqrt(rv2);
69353 	   rinv = 1.0/rv;
69354 	   rsum = vdwr[i] + vdwrl[j];
69355 	   epsm = sqrt(vdwe[i]*vdwel[j]);
69356 	   rs2 = rsum*rsum;
69357 	   rs3 = rs2*rsum;
69358 	   p6   = (rs3*rs3) / (rv2*rv2*rv2);
69359 	   p12  = p6 * p6;
69360 
69361 	   e    = epsm * (p12 - 2.0*p6);
69362 	   de   = epsm * (p12 - p6) * (-12.0/rv);
69363 	   de   = de / rv;
69364 
69365 	   for (l=0; l < 3; l++) {
69366 		Fj[l] = de * vr[l];
69367 	   }
69368 
69369 	   ev   = ev + VDWSCAL*e;
69370 
69371 	   for (l=0; l < 3; l++) {
69372 		F[j*3+l] = F[j*3+l] + Fj[l];
69373 	   }
69374 
69375 	   e = q[i]*ql[j]*econv*rinv;
69376 
69377 	   de = -e*rinv*rinv;
69378 
69379 	   for (l=0; l < 3; l++) {
69380 		F[j*3+l] = F[j*3+l] + + de * vr[l];
69381 	   }
69382 
69383 	   eq = eq + e;
69384 	 }
69385 	}
69386      }
69387    }
69388 
69389    *E = eq + ev;
69390 
69391    for (l=0; l < 3; l++) dir[l] = 0.0;
69392 
69393    for (j=0; j < ndocka; j++) {
69394 	for (l=0; l < 3; l++) dir[l] = dir[l] + F[j*3+l];
69395    }
69396 
69397 }
69398 
CaljFE(float * cool,double * coo,int * iclos,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel,float * F,float * E,float * dir,int * frg)69399 void CaljFE(float *cool,double *coo,int *iclos,
69400 		float *q,float *vdwr,float *vdwe,
69401 		float *ql,float *vdwrl,float *vdwel,
69402 		float *F,float *E,float *dir,int *frg)
69403 {
69404    int i,j,k,l;
69405    float vr[3],rv,rv2,rs2,rs3,rsum,rinv,epsm,p6,p12;
69406    float de,e,ev,eq,econv,Fj[3];
69407 
69408    ev = 0.0; eq = 0.0;
69409    econv = 332.05382;
69410 
69411    for (j=0; j < ndocka; j++) {
69412      for (l=0; l < 3; l++) {
69413 	F[j*3+l] = 0.0;
69414      }
69415    }
69416 
69417    for (i=0; i < *xyzp->iatoms; i++) {
69418      if (iclos[i]) {
69419 	for (j=0; j < ndocka; j++) {
69420 	   for (l=0; l < 3; l++) {
69421 		vr[l] = (cool[j*3+l] - (float) coo[i*3+l]);
69422 		vr[l] =  vr[l]*toangs;
69423 	   }
69424 	   rv2 = vr[0]*vr[0] + vr[1]*vr[1] + vr[2]*vr[2];
69425 	   rv = sqrt(rv2);
69426 	   rinv = 1.0/rv;
69427 	   rsum = vdwr[i] + vdwrl[j];
69428 	   epsm = sqrt(vdwe[i]*vdwel[j]);
69429 	   rs2 = rsum*rsum;
69430 	   rs3 = rs2*rsum;
69431 	   p6   = (rs3*rs3) / (rv2*rv2*rv2);
69432 	   p12  = p6 * p6;
69433 
69434 	   e    = epsm * (p12 - 2.0*p6);
69435 	   de   = epsm * (p12 - p6) * (-12.0/rv);
69436 
69437 	   de   = de / rv;
69438 
69439 	   for (l=0; l < 3; l++) {
69440 		Fj[l] = de * vr[l];
69441 	   }
69442 
69443 	   ev   = ev + e;
69444 
69445 	   for (l=0; l < 3; l++) {
69446 		F[j*3+l] = F[j*3+l] + Fj[l];
69447 	   }
69448 
69449 	   e = q[i]*ql[j]*econv*rinv;
69450 
69451 	   de = -e*rinv*rinv;
69452 
69453 	   for (l=0; l < 3; l++) {
69454 		F[j*3+l] = F[j*3+l] + + de * vr[l];
69455 	   }
69456 
69457 	   eq = eq + e;
69458 	}
69459      }
69460    }
69461 
69462    *E = eq + ev;
69463 
69464    for (l=0; l < 3; l++) dir[l] = 0.0;
69465 
69466    for (j=0; j < ndocka; j++) {
69467 	for (l=0; l < 3; l++) dir[l] = dir[l] + F[j*3+l];
69468    }
69469 }
69470 
golden(float * cool,double * coo,int * iclos,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel,float * F,float a,float b,float * dir,int * frg)69471 float golden(float *cool,double *coo,int *iclos,
69472 		float *q,float *vdwr,float *vdwe,
69473 		float *ql,float *vdwrl,float *vdwel,
69474 		float *F,float a,float b,
69475 		float *dir,int *frg)
69476 {
69477    float c,d,gr,tol,Ec,Ed,dum[3];
69478    float wxyz[3*MXLIGA];
69479    int i,j;
69480 
69481    gr = (sqrt(5.0) - 1.0) / 2.0;
69482    tol = 1.0e-5;
69483 
69484    c = a + (b - a)*(1.0-gr);
69485    d = a + (b - a)*gr;
69486 
69487    while (ABS(c-d) > tol) {
69488 
69489 	for (i=0; i < ndocka; i++) {
69490 	   for (j=0; j < 3; j++) {
69491 		wxyz[3*i+j] = cool[3*i+j];
69492 	   }
69493 	}
69494 
69495 	Newxyz(c,dir,wxyz);
69496 	CalcFE(wxyz,coo,iclos,q,vdwr,vdwe,
69497 			ql,vdwrl,vdwel,F,&Ec,dum,frg);
69498 
69499 	for (i=0; i < ndocka; i++) {
69500 	   for (j=0; j < 3; j++) {
69501 		wxyz[3*i+j] = cool[3*i+j];
69502 	   }
69503 	}
69504 
69505 	Newxyz(d,dir,wxyz);
69506 	CalcFE(wxyz,coo,iclos,q,vdwr,vdwe,
69507 			ql,vdwrl,vdwel,F,&Ed,dum,frg);
69508 	if (Ec < Ed) {
69509 	   b = d;
69510 	   d = c;
69511 	   c = a + (1.0-gr)*(b-a);
69512 	} else {
69513 	   a = c;
69514 	   c = d;
69515 	   d = a + gr*(b-a);
69516 	}
69517    }
69518 
69519    for (i=0; i < ndocka; i++) {
69520 	for (j=0; j < 3; j++) {
69521 	    cool[3*i+j] = wxyz[3*i+j] ;
69522 	}
69523    }
69524 
69525    return((b+a)/2.0);
69526 }
69527 
Rxyz(float xin,float yin,float zin,int a,int b,int c,float * xout,float * yout,float * zout)69528 void Rxyz(float xin, float yin, float zin,
69529 	  int a, int b, int c,
69530 	  float *xout, float *yout, float *zout)
69531 {
69532   float csa,sna,csb,snb,csc,snc;
69533 
69534   Get_FTsin(a,&sna,&csa);
69535   Get_FTsin(b,&snb,&csb);
69536   Get_FTsin(c,&snc,&csc);
69537 
69538 
69539   *xout = xin*csa*csb + yin*(csa*snb*snc - sna*csc) +
69540 		        zin*(csa*snb*csc + sna*snc);
69541   *yout = xin*sna*csb + yin*(sna*snb*snc + csa*csc) +
69542 		        zin*(sna*snb*csc - csa*snc);
69543   *zout = -xin*snb + yin*csb*snc + zin*csb*csc;
69544 }
69545 
Trans2Cen(float * coot,int itri,int ndocka)69546 void Trans2Cen(float *coot, int itri, int ndocka)
69547 {
69548    int i,j;
69549 
69550    for (i=0; i < ndocka; i++) {
69551 	for (j=0; j < 3; j++) {
69552 	   coot[3*i+j] = ((float) TriArr[itri]->coo[3*i+j] -
69553 				TriArr[itri]->Cen[j]);
69554 	}
69555    }
69556 }
69557 
Cen2Trans(float * coot,int itri,int ndocka)69558 void Cen2Trans(float *coot, int itri, int ndocka)
69559 {
69560    int i,j;
69561 
69562    for (i=0; i < ndocka; i++) {
69563 	for (j=0; j < 3; j++) {
69564 	   coot[3*i+j] = (coot[3*i+j] + (float) TriArr[itri]->Cen[j]);
69565 	}
69566    }
69567 }
69568 
PickFrags(int * indx,int itri,int ndocka)69569 void PickFrags(int *indx, int itri, int ndocka)
69570 {
69571    int i,j;
69572 
69573    for (i=0; i < ndocka; i++) {
69574 	indx[i] = 0;
69575 	if (singleb.ifrg[i] == TriArr[itri]->frags[0] ||
69576 	    singleb.ifrg[i] == TriArr[itri]->frags[1] ||
69577 	    singleb.ifrg[i] == TriArr[itri]->frags[2]) indx[i] = 1;
69578    }
69579 }
69580 
PickFrag(int * indx,int itri,int ndocka)69581 void PickFrag(int *indx, int itri, int ndocka)
69582 {
69583    int i,j;
69584 
69585    for (i=0; i < ndocka; i++) {
69586 	indx[i] = 0;
69587 	if (singleb.ifrg[i] == TriArr[itri]->frag) indx[i] = 1;
69588    }
69589 }
69590 
PickFull(int * indx,int itri,int ndocka)69591 void PickFull(int *indx, int itri, int ndocka)
69592 {
69593    int i;
69594 
69595    for (i=0; i < ndocka; i++) indx[i] = 1;
69596 }
69597 
ChkFrag(int * indx,int ndocka)69598 int ChkFrag(int *indx,int ndocka)
69599 {
69600    int i,j;
69601 
69602    for (i=0; i < ndocka; i++) {
69603 	if (indx[i] == 1) return(1);
69604    }
69605    return(0);
69606 }
69607 
Write_Results(File_Name,Tri,ntri,xyz,Eopt,maxi)69608 int Write_Results(File_Name,Tri,ntri,xyz,Eopt,maxi)
69609 char *File_Name;
69610 TRISTRU *Tri[MAXTRI];
69611 int ntri;
69612 COOSTRU *xyz;
69613 int Eopt;
69614 int maxi;
69615 {
69616    int ierr,i,n,iattmp,ipdbtmp,maxsol,itel;
69617    int *ianztmp;
69618    short int *ityptmp;
69619 
69620    cpstr(File_Name,tmpfil,SUBLEN1);
69621    ierr = 0;
69622 
69623 #if defined(VMS) || defined(UNDERSC)
69624    filop(&SEVENTYSEVEN,&ONE,&ZERO,&ZERO,&ierr);
69625 #else
69626 #ifdef CRAY
69627    FILOP(&SEVENTYSEVEN,&ONE,&ZERO,&ZERO,&ierr);
69628 #else
69629    filop_(&SEVENTYSEVEN,&ONE,&ZERO,&ZERO,&ierr);
69630 #endif
69631 #endif
69632 
69633    if (ierr) {
69634 	if (DoCan(event.xbutton.x_root,event.xbutton.y_root,
69635 	 "WARNING: was not able to write docking output",0)) {
69636 		i = 0;
69637 	}
69638 	return(0);
69639    }
69640 
69641 if (debugdck) fprintf(stderr,"\nWrite_Results: %s\n\n",File_Name);
69642 
69643    ianztmp = xyzp->ianz;
69644    ityptmp = xyzp->ityp;
69645    xyzp->ianz = xyz->ianz;
69646    xyzp->ityp = xyz->ityp;
69647 
69648    iattmp = *xyzp->iatoms;
69649    *xyzp->iatoms = ndocka;
69650    ipdbtmp = *ipdbon;
69651    *ipdbon = 0;
69652 
69653    eneptr->iener = 1;
69654 
69655    if (maxi) {
69656 	maxsol = dcksol;
69657 	n = MINI(ntri,maxsol);
69658    } else {
69659 	n = ntri;
69660    }
69661 
69662 if (debugdck) fprintf(stderr,"Write_Results: n %d\n",n);
69663 
69664    itel = 0;
69665    for (i = 0; i < n; i++ ) {
69666       if (Tri[i] != NULL && Tri[i]->coo != NULL) {
69667 	if (Eopt) {
69668 	   eneptr->energy = Tri[i]->eint;
69669 
69670 	   if (!debugdck) {
69671 		fprintf(stderr,"#%d E=%.3f\n",i,Tri[i]->eint);
69672 	   } else {
69673 		fprintf(stderr,"#%d E=%.3f lig %d %d %d prot %d %d %d\n",i,Tri[i]->eint,Tri[i]->lig[0],Tri[i]->lig[1],Tri[i]->lig[2],Tri[i]->prot[0],Tri[i]->prot[1],Tri[i]->prot[2]);
69674 	   }
69675 	} else {
69676 	   eneptr->energy = Tri[i]->etot;
69677 
69678 	   if (!debugdck) {
69679 		fprintf(stderr,"#%d E=%.3f\n",i,Tri[i]->etot);
69680 	   } else {
69681 		fprintf(stderr,"#%d E=%.3f lig %d %d %d prot %d %d %d\n",i,Tri[i]->etot,Tri[i]->lig[0],Tri[i]->lig[1],Tri[i]->lig[2],Tri[i]->prot[0],Tri[i]->prot[1],Tri[i]->prot[2]);
69682 	   }
69683 	}
69684 //	Prt_Coo(Tri[i]->P1,100);
69685 //	Prt_Coo(Tri[i]->P2,100);
69686 //	Prt_Coo(Tri[i]->P3,100);
69687 
69688 #if defined(VMS) || defined(UNDERSC)
69689 	wrmod(&SEVENTYSEVEN,
69690 #else
69691 #ifdef CRAY
69692 	WRMOD(&SEVENTYSEVEN,
69693 #else
69694 	wrmod_(&SEVENTYSEVEN,
69695 #endif
69696 #endif
69697 	Tri[i]->coo,xyz->qat,xyz->ianz,xyz->iaton,xyz->iatclr,xyz->iconn,
69698 	xyz->iresid,xyz->lring,xyz->inat,xyz->ityp,xyz->ipdbt,
69699 	calfptr->icalf,&calfptr->ncalf,calfptr->iamino,&calfptr->ishoh,
69700 	&cell->natc,&cell->nspg,&cell->ichx,
69701 	&cell->cellc[0],&cell->cellc[1],&cell->cellc[2],
69702 	&cell->cellc[3],&cell->cellc[4],&cell->cellc[5]);
69703 	   itel++;
69704       }
69705    }
69706 
69707    eneptr->iener = 0;
69708    *xyzp->iatoms = iattmp;
69709    *ipdbon = ipdbtmp;
69710    xyzp->ianz = ianztmp;
69711    xyzp->ityp = ityptmp;
69712 
69713    fprintf(stderr,"\n");
69714 
69715 #if defined(VMS) || defined(UNDERSC)
69716    filclo(&SEVENTYSEVEN);
69717 #else
69718 #ifdef CRAY
69719    FILCLO(&SEVENTYSEVEN);
69720 #else
69721    filclo_(&SEVENTYSEVEN);
69722 #endif
69723 #endif
69724 
69725 }
69726 
Write_Mol(File_Name)69727 int Write_Mol(File_Name)
69728 char *File_Name;
69729 {
69730    int ierr,i,n,iattmp,ipdbtmp,maxsol,itel;
69731    int *ianztmp, mxnatd, ihaszmd;
69732    short int *ityptmp;
69733    COOSTRU *pp;
69734 
69735    pp = xyzp;
69736 
69737    cpstr(File_Name,tmpfil,SUBLEN1);
69738    ierr = 0;
69739 
69740 #if defined(VMS) || defined(UNDERSC)
69741    filop(&SEVENTYSEVEN,&ONE,&ZERO,&ZERO,&ierr);
69742 #else
69743 #ifdef CRAY
69744    FILOP(&SEVENTYSEVEN,&ONE,&ZERO,&ZERO,&ierr);
69745 #else
69746    filop_(&SEVENTYSEVEN,&ONE,&ZERO,&ZERO,&ierr);
69747 #endif
69748 #endif
69749 
69750    if (ierr) {
69751       fprintf(stderr,"WARNING: was not able to write mol from ligand");
69752    }
69753 
69754 
69755    iattmp = *xyzp->iatoms;
69756    ipdbtmp = *ipdbon;
69757    mxnatd = *(xyzp->mxnat);
69758    ihaszmd = *(zmptrp->ihaszm);
69759 
69760    *xyzp->iatoms = ndocka;
69761    *ipdbon = 0;
69762 
69763 #if defined(VMS) || defined(UNDERSC)
69764    outmod(&SEVENTYSEVEN,
69765 #else
69766 #ifdef CRAY
69767    OUTMOD(&SEVENTYSEVEN,
69768 #else
69769    outmod_(&SEVENTYSEVEN,
69770 #endif
69771 #endif
69772 	DCKxyz.coo,DCKxyz.ianz,DCKxyz.iconn);
69773 
69774    *xyzp->iatoms = iattmp;
69775    *ipdbon = ipdbtmp;
69776    *(xyzp->mxnat)  = mxnatd;
69777    *(zmptrp->ihaszm) = ihaszmd;
69778 
69779 #if defined(VMS) || defined(UNDERSC)
69780    filclo(&SEVENTYSEVEN);
69781 #else
69782 #ifdef CRAY
69783    FILCLO(&SEVENTYSEVEN);
69784 #else
69785    filclo_(&SEVENTYSEVEN);
69786 #endif
69787 #endif
69788 
69789 }
69790 
RotTri(int itri,int lowa,int higha,int angstp,float * wxyz,float * rwxyz,float * cwxyz,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel,float * F,float * dir,int * frg,int * iclos)69791 void RotTri(int itri, int lowa, int higha, int angstp,
69792 		float *wxyz, float *rwxyz, float *cwxyz,
69793 		float *q, float *vdwr, float *vdwe,
69794 		float *ql, float *vdwrl, float *vdwel, float *F,
69795 		float *dir, int *frg, int *iclos)
69796 {
69797 // lowa -4 hiang  5 angstp 1.0 BmpCheck 1 ECheck 1
69798 // lowa -9 hiang 10 angstp 5.0 BmpCheck 0 ECheck 0
69799 
69800    int k,l,j;
69801    float Emin,E,vl,tdir[3],c;
69802    int angx,angy,angz,angxm,angym,angzm;
69803    int anglex,angley,anglez;
69804 
69805    Emin = 10000.0;
69806    angxm = 10000; angym = 10000; angzm = 10000;
69807 
69808 // translate origin to center of triangle
69809 
69810 
69811    Trans2Cen(wxyz,itri,ndocka);
69812 
69813 ///* loop over a,b,c angles to calculate Energy as function of angles */
69814 
69815    for (angx=lowa; angx < higha; angx++) {
69816 	anglex = angx*angstp;
69817 
69818 	for (angy=lowa; angy < higha; angy++) {
69819 	    angley = angy*angstp;
69820 
69821 	    for (angz=lowa; angz < higha; angz++) {
69822 		anglez = angz*angstp;
69823 
69824 // do rotation around x,y,x axes (Rx,Ry,Rz) and copy to rwxyz
69825 
69826 		for (k=0; k < ndocka; k++) {
69827 		    Rxyz(wxyz[k*3], wxyz[k*3+1], wxyz[k*3+2],
69828 			anglex,angley,anglez,
69829 			&rwxyz[k*3], &rwxyz[k*3+1], &rwxyz[k*3+2]);
69830 		}
69831 
69832 		Cen2Trans(rwxyz,itri,ndocka);
69833 
69834 // calculate forces and energy on rotated ligand coordinates
69835 
69836 if (Match_tri(TriArr[itri],11,1,13,69,70,12)) {
69837 fprintf(stderr,"RotTri: angx %d angy %d angz %d\n\n",angx,angy,angz);
69838 }
69839 		CalcFE(rwxyz,xyzp->coo,iclos,q,vdwr,vdwe,
69840 			ql,vdwrl,vdwel,F,&E,dir,frg);
69841 
69842 if (Match_tri(TriArr[itri],11,1,13,69,70,12)) {
69843 fprintf(stderr,"RotTri: E %.3f Emin %.3f\n\n",E,Emin);
69844 }
69845 		if (E < Emin)  {
69846 		    Emin = E;
69847 		    for (k=0; k < ndocka; k++) {
69848 			for (l=0; l < 3; l++)  {
69849 			   cwxyz[k*3+l] = rwxyz[k*3+l];
69850 			}
69851 		    }
69852 		    angxm = angx;
69853 		    angym = angy;
69854 		    angzm = angz;
69855 		}
69856 
69857 	    } // end for anglez
69858 	} // end for angley
69859    } // end for anglex
69860 
69861 if (debugdck) fprintf(stderr,"RotTri Emin %.3f\n",Emin);
69862 
69863    if (Emin < 50.0) {
69864 //   if (Emin < BIGD) {
69865 
69866 	TriArr[itri]->eint = Emin;
69867 
69868 	for (k=0; k < ndocka; k++) {
69869 		   for (l=0; l < 3; l++) {
69870 			TriArr[itri]->coo[k*3+l] = (double) cwxyz[k*3+l];
69871 		   }
69872 	}
69873 
69874 	CalcFE(cwxyz,xyzp->coo,iclos,q,vdwr,vdwe,
69875 		ql,vdwrl,vdwel,F,&E,dir,frg);
69876 
69877 	vl = veclen(dir); if (vl == 0.0) return;
69878 
69879 	for (l=0; l < 3; l++) dir[l] = -dir[l] / vl;
69880 
69881 	c = golden(cwxyz,xyzp->coo,iclos,q,vdwr,vdwe,
69882 			ql,vdwrl,vdwel,F,0.0,1.0,dir,frg);
69883 
69884 	CalcFE(cwxyz,xyzp->coo,iclos,q,vdwr,vdwe,
69885 			ql,vdwrl,vdwel,F,&E,dir,frg);
69886 
69887 if (debugdck) fprintf(stderr,"RotTri E %.3f\n",E);
69888 
69889 	if (E < 0.0) {
69890 //	if (E < 100.0) {
69891 
69892 	   TriArr[itri]->eint = E;
69893 
69894 	   for (k=0; k < ndocka; k++) {
69895 		for (l=0; l < 3; l++) {
69896 		   TriArr[itri]->coo[k*3+l] = (double) cwxyz[k*3+l];
69897 		}
69898 	   }
69899 
69900 
69901 	   for (l=0; l < 3; l++) {
69902 		tdir[l] = (cwxyz[l] - rwxyz[l]);
69903 		TriArr[itri]->Cen[l] = TriArr[itri]->Cen[l] + (double) tdir[l];
69904 	   }
69905 
69906 	} else {
69907 	   TriArr[itri]->eint = 0.0;
69908 	}
69909    }
69910 
69911 
69912 }
69913 
struct_cmp(const AREASTRU * lhs,const AREASTRU * rhs)69914 int struct_cmp(const AREASTRU * lhs, const AREASTRU * rhs)
69915 {
69916     return memcmp(lhs, rhs, sizeof(AREASTRU));
69917 }
69918 
OHFnd(TRISTRU * Tri,double * cooProt,int it)69919 void OHFnd(TRISTRU *Tri,double *cooProt,int it)
69920 {
69921    int i,j,iopt,indx,il;
69922    double dd,tt,ddmin;
69923 
69924    ddmin = BIGD;
69925    iopt = -1;
69926 
69927    for (i=0; i<36; i++) {
69928 	dd = 0.0;
69929 	for (j=0; j<3; j++) {
69930 	   tt = cooProt[j] + Tri->oh[it][i*3+j];
69931 	   tt =  tt * tt;
69932 	   dd = dd + tt;
69933 	   if (dd < ddmin) {
69934 		ddmin = dd;
69935 		iopt = i;
69936 	   }
69937 	}
69938    }
69939 
69940    if (iopt != -1) {
69941 
69942 	indx = Tri->lig[it];
69943 	il = ligtyp[indx]->atom[0];
69944 
69945 	for (j=0; j<3; j++) {
69946 	   Tri->coo[il*3+j] = Tri->oh[it][iopt*3+j];
69947 	}
69948 
69949    }
69950 }
69951 
OHAllInt(C,indx,at1,at2,at3,coo,ohcoo,iconf,link,ohsame,jj)69952 void OHAllInt(C,indx,at1,at2,at3,coo,ohcoo,iconf,link,ohsame,jj)
69953 COOSTRU *C;
69954 int *indx;
69955 int at1;
69956 int at2;
69957 double *coo;
69958 double *ohcoo;
69959 int iconf;
69960 int link;
69961 int ohsame;
69962 int jj;
69963 {
69964    int j;
69965    INCRSTRU tmptyp;
69966 
69967    ligtyp[*indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
69968    memcpy(ligtyp[*indx], &modtyp, sizeof(INCRSTRU));
69969 
69970    for (j=0; j<3; j++) {
69971 //	ligtyp[*indx]->c[0][j] = ohcoo[jj*6+j];
69972 	ligtyp[*indx]->c[0][j] = ohcoo[jj*3+j];
69973 	ligtyp[*indx]->c[1][j] = coo[(at2)*3+j];
69974 	ligtyp[*indx]->c[2][j] = coo[(at3)*3+j];
69975 	ligtyp[*indx]->atom[0] = at1;
69976 	ligtyp[*indx]->atom[1] = at2;
69977 	ligtyp[*indx]->atom[2] = at3;
69978 	ligtyp[*indx]->n = 2;
69979    }
69980 
69981    ligtyp[*indx]->type = H_DON;
69982    ligtyp[*indx]->area = ONH;
69983    ligtyp[*indx]->conf = iconf;
69984    ligtyp[*indx]->link = link;
69985    ligtyp[*indx]->ohlig = 1;
69986    ligtyp[*indx]->ohsame = ohsame;
69987 
69988    cal_area(ligtyp[*indx]);
69989    (*indx)++;
69990 }
69991 
OHGenRot(double * coo,double ** GenOH,int i1,int i2,int i3,int n,int iang)69992 void OHGenRot(double *coo, double **GenOH, int i1, int i2, int i3,
69993 		int n, int iang)
69994 {
69995 
69996 // i1 is C, i2 is O is Origin (O), i3 is H
69997 
69998    int i,j;
69999    float v1[3],v2[3],v3[3],O[3],XX,YY,arad;
70000    float v12[3],v32[3],cosa,sina,csa,sna,vl,todeg;
70001    double *OHPTR;
70002 
70003    todeg = 45.0e0/atan(1.0e0);
70004 
70005    if (!allConf(GenOH,n)) exit(-1);
70006 
70007    OHPTR = *GenOH;
70008 
70009    for (j=0; j<3; j++) {
70010 	O[j]   = (float) (coo[i2*3+j]);
70011 	v12[j] = (float) (coo[i1*3+j] - coo[i2*3+j]);
70012 	v32[j] = (float) (coo[i3*3+j] - coo[i2*3+j]);
70013 	v1[j]  = v12[j];
70014    }
70015 
70016    vecnrm(v1);
70017    cross(v1,v32,v3);
70018    vecnrm(v3);
70019    cross(v1,v3,v2);
70020    IMPRD(v32,v2,&cosa,1);
70021    IMPRD(v32,v1,&sina,1);
70022    vl = veclen(v32);
70023 
70024    XX = vl*cosa;
70025    YY = vl*sina;
70026 
70027    for (i=0; i<n; i++) {
70028 	arad = (float) (i*iang);
70029 	csa = cos(arad/todeg);
70030 	sna = sin(arad/todeg);
70031 
70032 	for (j=0; j<3; j++) {
70033 	   OHPTR[i*3+j] = (float) (O[j] + XX*(csa*v2[j] + sna*v3[j]) + YY*v1[j]);
70034 	}
70035 
70036    }
70037 
70038 }
70039 
OHRot(TRISTRU * Tri,int i1,int i2,int i3,int it)70040 void OHRot(TRISTRU *Tri, int i1, int i2, int i3, int it)
70041 {
70042 
70043 // i1 is C, i2 is O is Origin (O), i3 is H
70044 
70045    int i,j;
70046    float v1[3],v2[3],v3[3],O[3],XX,YY,arad;
70047    float v12[3],v32[3],cosa,sina,csa,sna,vl,todeg;
70048 
70049    todeg = 45.0e0/atan(1.0e0);
70050 
70051    if (!allConf(&Tri->oh[it],36)) exit(-1);
70052 
70053    for (j=0; j<3; j++) {
70054 	O[j]   = (float) (Tri->coo[i2*3+j]);
70055 	v12[j] = (float) (Tri->coo[i1*3+j] - Tri->coo[i2*3+j]);
70056 	v32[j] = (float) (Tri->coo[i3*3+j] - Tri->coo[i2*3+j]);
70057 	v1[j]  = v12[j];
70058    }
70059 
70060    vecnrm(v1);
70061    cross(v1,v32,v3);
70062    vecnrm(v3);
70063    cross(v1,v3,v2);
70064    IMPRD(v32,v2,&cosa,1);
70065    IMPRD(v32,v1,&sina,1);
70066    vl = veclen(v32);
70067 
70068    XX = vl*cosa;
70069    YY = vl*sina;
70070 
70071    for (i=0; i<36; i++) {
70072 	arad = (float) (i*10);
70073 	csa = cos(arad/todeg);
70074 	sna = sin(arad/todeg);
70075 
70076 	for (j=0; j<3; j++) {
70077 	   Tri->oh[it][i*3+j] = O[j] + XX*(csa*v2[j] + sna*v3[j]) + YY*v1[j];
70078 	}
70079 
70080    }
70081 
70082 }
70083 
RotOH(int indx,int i1,int i2,int i3,int * iclos,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel)70084 void RotOH(int indx, int i1, int i2, int i3, int *iclos,
70085 		float *q,float *vdwr,float *vdwe,
70086 		float *ql,float *vdwrl,float *vdwel)
70087 {
70088    int i,j;
70089    float v1[3],v2[3],v3[3],cxyz[3],O[3],XX,YY,E,Emin,cminxyz[3],arad;
70090    float v12[3],v32[3],cosa,sina,csa,sna,vl,x,y,todeg;
70091 
70092    todeg = 45.0e0/atan(1.0e0);
70093    Emin = 10000.0;
70094 
70095 fprintf(stderr,"RotOH: %d %d %d\n",i1,i2,i3);
70096    for (j=0; j<3; j++) {
70097 	O[j]   = TriArr[indx]->coo[i2*3+j];
70098 	v12[j] = TriArr[indx]->coo[i1*3+j] - TriArr[indx]->coo[i2*3+j];
70099 	v32[j] = TriArr[indx]->coo[i3*3+j] - TriArr[indx]->coo[i2*3+j];
70100 	v1[j]  = v12[j];
70101    }
70102 
70103    vecnrm(v1);
70104    cross(v1,v32,v3);
70105    vecnrm(v3);
70106    cross(v1,v3,v2);
70107    IMPRD(v32,v2,&cosa,1);
70108    IMPRD(v32,v1,&sina,1);
70109    vl = veclen(v32);
70110 
70111    XX = vl*cosa;
70112    YY = vl*sina;
70113 
70114    for (i=0; i<72; i++) {
70115 	arad = (float) (i*5);
70116 	csa = cos(arad/todeg);
70117 	sna = sin(arad/todeg);
70118 // rotation is about v1 and thus in the plane spanned by v2 and v3
70119 
70120 
70121 // cxyz contains the rotated H coordinates
70122 
70123 	for (j=0; j<3; j++) {
70124 	   cxyz[j] = O[j] + XX*(csa*v2[j] + sna*v3[j]) + YY*v1[j];
70125 	}
70126 
70127 	E = CalcE(cxyz,i3,iclos,q,vdwr,vdwe,ql,vdwrl,vdwel);
70128 	if (E < Emin) {
70129 	   E = Emin;
70130 	   for (j=0; j<3; j++) {
70131 		cminxyz[j] = cxyz[j];
70132 	   }
70133 	}
70134    }
70135 
70136    for (j=0; j<3; j++) {
70137 	TriArr[indx]->coo[i3*3+j] = cminxyz[j];
70138    }
70139 
70140 // the optimised H position also has an effect on the interaction points
70141 // But since this is in principle ligand pose dependent, we CAN NOT
70142 // store this in the ligtyp array. We have to create a specific
70143 // memory location for this and flag this in the ligtyp array
70144 
70145 }
70146 
cmpeint(const void * a,const void * b)70147 static int cmpeint(const void * a,const void * b)
70148 {
70149     TRISTRU **Tria = (TRISTRU **) a;
70150     TRISTRU **Trib = (TRISTRU **) b;
70151     if ((*Tria) == NULL || (*Trib) == NULL) return -1;
70152     if ((*Tria)->eint > (*Trib)->eint) return 1;
70153     else
70154        if ((*Tria)->eint == (*Trib)->eint) return  0;
70155        else          return -1;
70156 }
70157 
cmptriF(const void * a,const void * b)70158 static int cmptriF(const void * a,const void * b)
70159 {
70160     TRISTRU **Tria = (TRISTRU **) a;
70161     TRISTRU **Trib = (TRISTRU **) b;
70162     if ((*Tria)->etot > (*Trib)->etot) return 1;
70163     else
70164        if ((*Tria)->etot == (*Trib)->etot) return  0;
70165        else          return -1;
70166 }
70167 
Match_Tri(TRISSTRU Tri,int l1,int l2,int l3)70168 int Match_Tri(TRISSTRU Tri,int l1,int l2,int l3)
70169 {
70170 
70171     if (Tri.lig[0] == l1 &&
70172 	Tri.lig[1] == l2 &&
70173 	Tri.lig[2] == l3 ) {
70174 	return(1);
70175    }
70176 
70177 return(0);
70178 
70179 }
70180 
Match_tri(TRISTRU * Tri,int l1,int l2,int l3,int p1,int p2,int p3)70181 int Match_tri(TRISTRU * Tri,int l1,int l2,int l3,int p1,int p2,int p3)
70182 {
70183 
70184 if (Tri->lig[0] == l1 &&
70185     Tri->lig[1] == l2 &&
70186     Tri->lig[2] == l3 ) {
70187     if (Tri->prot[0] == p1 &&
70188 	Tri->prot[1] == p2 &&
70189 	Tri->prot[2] == p3 ) {
70190 	return(1);
70191    }
70192 }
70193 
70194 return(0);
70195 
70196 }
70197 
70198 static int ADPAIR1[MAXLIGSTRU] = {MAXLIGSTRU*(-1)};
70199 static int ADPAIR2[MAXLIGSTRU] = {MAXLIGSTRU*(-1)};
70200 static int PAIRT[MAXLIGSTRU] = {MAXLIGSTRU*(0)};
70201 
Get_Att_Frag(int ifrag,int * FrgArr,int * FrgN)70202 void Get_Att_Frag(int ifrag,int *FrgArr,int *FrgN)
70203 {
70204    int i;
70205 
70206    for (i=0; i < singleb.N; i++) {
70207 	if (singleb.SngFrg[i][0] == ifrag || singleb.SngFrg[i][1] == ifrag) {
70208 	   if (singleb.SngFrg[i][0] == ifrag) {
70209 		FrgArr[*FrgN] = singleb.SngFrg[i][1];
70210 	   }
70211 	   if (singleb.SngFrg[i][1] == ifrag) {
70212 		FrgArr[*FrgN] = singleb.SngFrg[i][0];
70213 	   }
70214 	   (*FrgN)++;
70215 	}
70216    }
70217 }
70218 
R2Tri(float * v1,float * cen,float * wxyz,int dg,int itri)70219 void R2Tri(float *v1, float *cen, float *wxyz, int dg, int itri)
70220 {
70221    int i,j,deg;
70222    float pt[3],CEN[3];
70223    double R1[4][4],sina,cosa;
70224 
70225    Get_Tsin(dg,&sina,&cosa);
70226 
70227    CEN[0] = 0.0; CEN[1] = 0.0; CEN[2] = 0.0;
70228 
70229    vecnrm(v1);
70230 
70231    Frst_Rot(CEN,v1,sina,cosa,R1);
70232 
70233    for (i=0; i<ndocka; i++) {
70234 
70235 
70236      for (j=0; j < 3; j++) {
70237 	wxyz[3*i+j] = ((float) TriArr[itri]->coo[3*i+j] - cen[j]);
70238      }
70239 
70240 
70241      for (j=0; j<3; j++) {
70242 	pt[j] = wxyz[i*3+j];
70243      }
70244 
70245      xyzROT4(R1,pt);
70246 
70247      for (j=0; j<3; j++) {
70248 	wxyz[i*3+j] = pt[j] + cen[j];
70249      }
70250 
70251    }
70252 
70253 }
70254 
70255 
TriRot(int itri,float * wxyz,float * cwxyz,float * cen,float * v1,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel,float * F,float * dir,int * frg,int * iclos)70256 void TriRot(int itri, float *wxyz, float *cwxyz, float *cen, float *v1,
70257 		float *q, float *vdwr, float *vdwe,
70258 		float *ql, float *vdwrl, float *vdwel, float *F,
70259 		float *dir, int *frg, int *iclos)
70260 {
70261 
70262    int k,l;
70263    float Emin,E,tdir[3];
70264    int ang;
70265    float angle;
70266 
70267    Emin = BIGD;
70268 
70269 // translate origin to center of triangle
70270 
70271    for (ang=-60; ang < 61; ang++) {
70272 
70273 	R2Tri(v1,cen,wxyz,ang,itri);
70274 
70275 // calculate forces and energy on rotated ligand coordinates
70276 
70277 	CalcFE(wxyz,xyzp->coo,iclos,q,vdwr,vdwe,
70278 			ql,vdwrl,vdwel,F,&E,dir,frg);
70279 
70280 	if (E < Emin)  {
70281 	    Emin = E;
70282 	    for (k=0; k < ndocka; k++) {
70283 		for (l=0; l < 3; l++)  {
70284 		   cwxyz[k*3+l] = wxyz[k*3+l];
70285 		}
70286 	    }
70287 	}
70288 
70289    }
70290 
70291    if (Emin < BIGD) {
70292 
70293 	TriArr[itri]->eint = Emin;
70294 
70295 	for (k=0; k < ndocka; k++) {
70296 	    for (l=0; l < 3; l++) {
70297 		TriArr[itri]->coo[k*3+l] = (double) cwxyz[k*3+l];
70298 	    }
70299 	}
70300 
70301    } else {
70302 	TriArr[itri]->eint = 0.0;
70303    }
70304 
70305 
70306 }
70307 
GenCen(int itri,float * v,float * cen)70308 int GenCen(int itri,float *v,float *cen)
70309 {
70310    int i,j,ind1,ind2,lig[3],itel;
70311    double co[3][3];
70312 
70313    itel = 0;
70314 
70315    for (i=0; i < 3; i++) {
70316 	lig[i] = TriArr[itri]->lig[i];
70317 
70318 	if (ligtyp[lig[i]]->type == H_ACC) {
70319 
70320 	   for (j=0; j < 3; j++) {
70321 		co[itel][j] = TriArr[itri]->coo[3*ligtyp[lig[i]]->atom[0]+j];
70322 	   }
70323 	   itel++;
70324 
70325 	} else if (ligtyp[lig[i]]->type == H_DON) {
70326 
70327 	   for (j=0; j < 3; j++) {
70328 		co[itel][j] = TriArr[itri]->coo[3*ligtyp[lig[i]]->atom[1]+j];
70329 	   }
70330 	   itel++;
70331 	}
70332    }
70333 
70334    if (itel == 2) {
70335       for (j=0; j < 3; j++) {
70336 	v[j] = co[1][j] - co[0][j];
70337 	cen[j] = (co[1][j] + co[0][j])/2.0;
70338       }
70339       return(1);
70340    } else {
70341       return(0);
70342    }
70343 }
70344 
IsAccDon(int itri)70345 int IsAccDon(int itri)
70346 {
70347    int i,lig[3],typ[3],ida[3];
70348 
70349    if (itri < 0) return(0);
70350 
70351    for (i=0; i < 3; i++) {
70352 	ida[i] = 0;
70353 	lig[i] = TriArr[itri]->lig[i];
70354 	typ[i] = ligtyp[lig[i]]->type;
70355 	if (typ[i] == H_ACC || typ[i] == H_DON) ida[i] = 1;
70356    }
70357 
70358    if (ida[0] && ida[1] && ida[2]) return(1);
70359 
70360    return(0);
70361 }
70362 
OptTris()70363 int OptTris()
70364 {
70365    int i,j,k,l,n,it,*iclos;
70366    float *F,E,a,b,c,vl;
70367    float *q,*vdwr,*vdwe,dir[3],tdir[3];
70368    float ql[MXLIGA],vdwrl[MXLIGA],vdwel[MXLIGA];
70369    int frg[MXLIGA],FrgArr[9],FrgN;
70370    float *wxyz,*rwxyz,*cwxyz,*tmpxyz,cen[3],vrot[3],Ebck;
70371 
70372    if (!AllArr(&q,&vdwr,&vdwe,&iclos,&F)) return(0);
70373 
70374    allFConf(&wxyz,ndocka);
70375    allFConf(&rwxyz,ndocka);
70376    allFConf(&cwxyz,ndocka);
70377    allFConf(&tmpxyz,ndocka);
70378 
70379    AssChg(q);
70380    AssVDW(vdwr,vdwe);
70381    AssVDWL(vdwrl,vdwel,ql);
70382 
70383    FrgN = 0;
70384    Get_Att_Frag(ADPAIR1[0],FrgArr,&FrgN);
70385    Get_Att_Frag(ADPAIR2[0],FrgArr,&FrgN);
70386 
70387    if (IsAccDon(0)) {
70388       vdwscal = VDWSCAL;
70389    }
70390 
70391 if (debugdck) fprintf(stderr,"OptTris: ntris %d\n\n",ntris);
70392 
70393    for (i=0; i < ntris; i++) {
70394 	if (TriArr[i] != NULL) {
70395 
70396 	    FillOpt(iclos,i);
70397 
70398 	    ChkBump(iclos,i);
70399 
70400 
70401 // translate origin to center of triangle
70402 
70403 	    Trans2Cen(wxyz,i,ndocka);
70404 
70405 	    if (MapConformers) {
70406 		PickFrag(frg,i,ndocka);
70407 	    } else {
70408 		PickFrags(frg,i,ndocka);
70409 	    }
70410 
70411 
70412 if (Match_tri(TriArr[i],11,1,13,69,70,12)) {
70413 fprintf(stderr,"OptTris: frg\n\n");
70414 for (j=0; j < ndocka; j++) {
70415 fprintf(stderr,"frg[%d] %d\n",j,frg[j]);
70416 }
70417 fprintf(stderr,"OptTris: iclos\n\n");
70418 for (j=0; j < *xyzp->iatoms; j++) {
70419 if (iclos[j]) {
70420 fprintf(stderr,"iclos[%d] %d\n",j,iclos[j]);
70421 }
70422 }
70423 }
70424 	    RotTri(i,-9,10,5,
70425 		wxyz,rwxyz,cwxyz,q,vdwr,vdwe,
70426 		ql,vdwrl,vdwel,F,dir,frg,iclos);
70427 
70428 	    if (TriArr[i]->eint < 0.0) {
70429 
70430 		RotTri(i,-4,5,1,
70431 		wxyz,rwxyz,cwxyz,q,vdwr,vdwe,
70432 		ql,vdwrl,vdwel,F,dir,frg,iclos);
70433 
70434 		RotTri(i,-4,5,1,
70435 		wxyz,rwxyz,cwxyz,q,vdwr,vdwe,
70436 		ql,vdwrl,vdwel,F,dir,frg,iclos);
70437 
70438 		if (GenCen(i,vrot,cen)) {
70439 
70440 		   Ebck = TriArr[i]->eint;
70441 
70442 		   FillFull(iclos,i);
70443 
70444 		   PickFull(frg,i,ndocka);
70445 
70446 		   TriRot(i,wxyz,cwxyz,cen,vrot,q,vdwr,vdwe,
70447 			ql,vdwrl,vdwel,F,dir,frg,iclos);
70448 
70449 		   TriArr[i]->eint = Ebck;
70450 		}
70451 
70452 	    } else {
70453 		if (TriArr[i]->coo != NULL) free(TriArr[i]->coo);
70454 		free(TriArr[i]);
70455 		TriArr[i] = NULL;
70456 	    }
70457 
70458 	}
70459    }
70460 
70461    Compress_Tri_L();
70462 
70463 if (debugdck) {
70464    for (i=0; i < ntris; i++) {
70465 	if (TriArr[i] != NULL) {
70466 	   PrtTrip(i,9,25);
70467 	}
70468    }
70469 }
70470 
70471    if (ntris > 0) {
70472 	if (MapConformers) {
70473 	   qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmptriF);
70474 	} else {
70475 	   qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmpeint);
70476 	}
70477    }
70478 
70479    vdwscal = 1.0;
70480 
70481 if (debugdck) Write_Results("optdock.mol2",TriArr,ntris,&DCKxyz,1,1);
70482 
70483 }
70484 
gttpar(iat,it,trs1,trs2,trs3,trs4,ityp)70485 int gttpar(iat,it,trs1,trs2,trs3,trs4,ityp)
70486 int iat[4];
70487 int it[4];
70488 float trs1[4];
70489 float trs2[4];
70490 float trs3[4];
70491 float trs4[4];
70492 short int *ityp;
70493 {
70494       float todeg,angl;
70495       int first = 1,i1,i2,i3,i4,ita,itb,itc,itd;
70496       int l,istat,it1,it2,it3,it4;
70497 
70498       todeg = 45.0e0 / atan(1.0e0);
70499       istat = 0;
70500 
70501       i1 = (int) ityp[iat[0]];
70502       i2 = (int) ityp[iat[1]];
70503       i3 = (int) ityp[iat[2]];
70504       i4 = (int) ityp[iat[3]];
70505 
70506       it[0] = iat[0];
70507       it[1] = iat[1];
70508       it[2] = iat[2];
70509       it[3] = iat[3];
70510 
70511       ita = ABS(i1);
70512       if (ita == 72) ita = 6;
70513 
70514       itb = ABS(i2);
70515       if (itb == 72) itb = 6;
70516 
70517       itc = ABS(i3);
70518       if (itc == 72) itc = 6;
70519 
70520       itd = ABS(i4);
70521       if (itd == 72) itd = 6;
70522 
70523       it1 = ita;
70524       it2 = itb;
70525       it3 = itc;
70526       it4 = itd;
70527 
70528       if (itb < itc) {
70529          it1 = ita;
70530          it2 = itb;
70531          it3 = itc;
70532          it4 = itd;
70533       } else if (itc < itb) {
70534          it1 = itd;
70535          it2 = itc;
70536          it3 = itb;
70537          it4 = ita;
70538       } else if (ita < itd) {
70539          it1 = ita;
70540          it2 = itb;
70541          it3 = itc;
70542          it4 = itd;
70543       } else if (itd < ita) {
70544          it1 = itd;
70545          it2 = itc;
70546          it3 = itb;
70547          it4 = ita;
70548       }
70549 
70550 next:
70551 
70552       istat = 0;
70553       for (l=0;l<MXGTOR;l++) {
70554           if ((gftcon[l][0] == it1) &&
70555 	      (gftcon[l][1] == it2) &&
70556 	      (gftcon[l][2] == it3) &&
70557 	      (gftcon[l][3] == it4) ) {
70558 
70559                  istat = 1;
70560 
70561                  trs1[0] = gftor1[l][0];
70562                  trs1[1] = gftor1[l][1];
70563                  angl = gftor1[l][1] / todeg;
70564                  trs1[2] = cos(angl);
70565                  trs1[3] = sin(angl);
70566 
70567                  trs2[0] = gftor2[l][0];
70568                  trs2[1] = gftor2[l][1];
70569                  angl = gftor2[l][1] / todeg;
70570                  trs2[2] = cos(angl);
70571                  trs2[3] = sin(angl);
70572 
70573                  trs3[0] = gftor3[l][0];
70574                  trs3[1] = gftor3[l][1];
70575                  angl = gftor3[l][1] / todeg;
70576                  trs3[2] = cos(angl);
70577                  trs3[3] = sin(angl);
70578 
70579                  trs4[0] = gftor4[l][0];
70580                  trs4[1] = gftor4[l][1];
70581                  angl = gftor4[l][1] / todeg;
70582                  trs4[2] = cos(angl);
70583                  trs4[3] = sin(angl);
70584 
70585 	  }
70586       }
70587 
70588       if (istat == 0 && first) {
70589 	it1 = 1;
70590 	it4 = 1;
70591 	first = 0;
70592 	goto next;
70593       }
70594 
70595       if (istat == 0)
70596             fprintf(stderr,"No torsion parameter: %3d %3d %3d %3d\n",\
70597 		it[0],it[1],it[2],it[3]);
70598 
70599       return(istat);
70600 }
70601 
70602 // torset initialises torsion parameters, based on two atoms
70603 // calls gttpar: gets parameters from gftor1,2,3,4 arrays
70604 // based on connectivity of atom types (gftcon array)
70605 // sets it[4] array
70606 //
70607 // first call torset then tors for calc etors (with it[4] as input)
70608 // based on value of torsion angle, calculated from coordinates
70609 //
70610 // tors calculates Etors or Eimp_tors, depending on value idoimp
70611 
torset(ia1,ia2,nt,it,trs1,trs2,trs3,trs4,iconn,ityp)70612 int torset(ia1,ia2,nt,it,trs1,trs2,trs3,trs4,iconn,ityp)
70613 int ia1;
70614 int ia2;
70615 int *nt;
70616 int it[MXTORS][4];
70617 float trs1[MXTORS][4];
70618 float trs2[MXTORS][4];
70619 float trs3[MXTORS][4];
70620 float trs4[MXTORS][4];
70621 int *iconn;
70622 short int *ityp;
70623 {
70624       int iat[4],j,k,l,itt[4];
70625       float trs1t[4],trs2t[4],trs3t[4],trs4t[4];
70626 
70627       iat[1] = ia1;
70628       iat[2] = ia2;
70629       *nt = 0;
70630 
70631       for (j=0; j < iconn[iat[1]*(MXCON+1)]; j++) {
70632 
70633 	iat[0] = iconn[iat[1]*(MXCON+1)+1+j] - 1;
70634 
70635 	if (iat[0] >= 0 && iat[0] != iat[2]) {
70636 
70637 	   for (k=0; k < iconn[iat[2]*(MXCON+1)]; k++) {
70638 		iat[3] = iconn[iat[2]*(MXCON+1)+1+k] - 1;
70639 
70640 		if (iat[3] >= 0 && (iat[3] != iat[1] && iat[3] != iat[0]) ) {
70641 
70642 		   if (gttpar(iat,itt,trs1t,trs2t,trs3t,trs4t,ityp)) {
70643 			if (*nt < MXTORS) {
70644 			   for (l=0; l < 4; l++) {
70645 				it  [*nt][l] = itt[l];
70646 				trs1[*nt][l] = trs1t[l];
70647 				trs2[*nt][l] = trs2t[l];
70648 				trs3[*nt][l] = trs3t[l];
70649 				trs4[*nt][l] = trs4t[l];
70650 			   }
70651 			   (*nt)++;
70652 			}
70653 		   } else {
70654 		      fprintf(stderr,"torsion parameter not found\n");
70655 		      return(0);
70656 		   }
70657 
70658 		}
70659 
70660 	   }
70661 
70662 	}
70663 
70664       }
70665 
70666       return(1);
70667 }
70668 
tors(et,nt,it,trs1,trs2,trs3,trs4,coo)70669 void tors(et,nt,it,trs1,trs2,trs3,trs4,coo)
70670 float *et;
70671 int nt;
70672 int it[MXTORS][4];
70673 float trs1[MXTORS][4];
70674 float trs2[MXTORS][4];
70675 float trs3[MXTORS][4];
70676 float trs4[MXTORS][4];
70677 double *coo;
70678 // double coo or float coo ? check with dckxyz
70679 // improd outputs a double *, here used as float *; need conversion !!!
70680 {
70681 
70682    int i,j,ia,ib,ic,id,nterms;
70683    float cosna[4],sinna[4],v[4],sa[4],ca[4],phi[4];
70684    float va[3],vb[3],vc[3],vd[3],vba[3],vcb[3],vdc[3],vca[3],vdb[3];
70685    float vt[3],vu[3],vtu[3];
70686    float rt2,ru2,rtru,rcb,e;
70687 
70688    *et = 0.0;
70689 
70690 // ia,ib,ic,id should run from 0-n, and therfor so should iti[] and it[]
70691 
70692    nterms = 4;
70693 
70694    for (i=0; i < nt; i++) {
70695 
70696       ia = it[i][0];
70697       ib = it[i][1];
70698       ic = it[i][2];
70699       id = it[i][3];
70700 
70701 // coordinates of atoms a,b,c,d
70702 
70703       for (j=0; j <3; j++) {
70704 	va[j] = ((float) coo[ia*3+j])*toangs;
70705 	vb[j] = ((float) coo[ib*3+j])*toangs;
70706 	vc[j] = ((float) coo[ic*3+j])*toangs;
70707 	vd[j] = ((float) coo[id*3+j])*toangs;
70708       }
70709 
70710 // vectors ba, cb, dc, ca, db
70711 
70712       vsubt(vb,va,vba);
70713       vsubt(vc,vb,vcb);
70714       vsubt(vd,vc,vdc);
70715       vsubt(vc,va,vca);
70716       vsubt(vd,vb,vdb);
70717 
70718 // t outvector ba x cb, u outvector cb x dc
70719 
70720       cross(vba,vcb,vt);
70721       cross(vcb,vdc,vu);
70722 
70723 // tu outvector t x u
70724 
70725       cross(vt,vu,vtu);
70726 
70727       rt2 = vt[0]*vt[0] + vt[1]*vt[1] + vt[2]*vt[2];
70728       ru2 = vu[0]*vu[0] + vu[1]*vu[1] + vu[2]*vu[2];
70729 
70730       rtru = veclen(vu)*veclen(vt);
70731 
70732       if (rtru > 0.0) {
70733 
70734 	rcb = veclen(vcb);
70735 
70736 	IMPRD(vt,vu,&cosna[0],1);
70737 	IMPRD(vcb,vtu,&sinna[0],0);
70738 
70739 	sinna[0] = sinna[0] / (rcb*rtru);
70740 
70741 // torsional parameters
70742 
70743 	v [0] = trs1[i][0];
70744 	ca[0] = trs1[i][2];
70745 	sa[0] = trs1[i][3];
70746 
70747 	v [1] = trs2[i][0];
70748 	ca[1] = trs2[i][2];
70749 	sa[1] = trs2[i][3];
70750 
70751 	v [2] = trs3[i][0];
70752 	ca[2] = trs3[i][2];
70753 	sa[2] = trs3[i][3];
70754 
70755 	v [3] = trs4[i][0];
70756 	ca[3] = trs4[i][2];
70757 	sa[3] = trs4[i][3];
70758 
70759 
70760 	for (j=0; j < nterms-1; j++) {
70761 	   cosna[j+1] = cosna[0]*cosna[j] - sinna[0]*sinna[j];
70762 	   sinna[j+1] = cosna[0]*sinna[j] + sinna[0]*cosna[j];
70763 	}
70764 
70765 	e = 0.0;
70766 
70767 	for (j=0; j < nterms; j++) {
70768 	   phi[j]  = 1.0 + (cosna[j]*ca[j] + sinna[j]*sa[j]);
70769 	   e = e + v[j]*phi[j];
70770 	}
70771 
70772 	*et = *et + e;
70773 
70774       }
70775    }
70776 
70777 }
70778 
CalTorS(isng,xyz,coo,nt,it,trs1,trs2,trs3,trs4)70779 float CalTorS(isng,xyz,coo,nt,it,trs1,trs2,trs3,trs4)
70780 int isng;
70781 COOSTRU *xyz;
70782 double *coo;
70783 int *nt;
70784 int it[MXTORS][4];
70785 float trs1[MXTORS][4];
70786 float trs2[MXTORS][4];
70787 float trs3[MXTORS][4];
70788 float trs4[MXTORS][4];
70789 {
70790    int i,ia1,ia2,err;
70791    float et;
70792 
70793    ia1 = singleb.sng[isng][0];
70794    ia2 = singleb.sng[isng][1];
70795    et = 0.0;err = 1;
70796 
70797    *nt = 0;
70798    err = torset(ia1,ia2,nt,it,trs1,trs2,trs3,trs4,
70799 		xyz->iconn,singleb.ityp);
70800 
70801    if (err)  tors(&et,*nt,it,trs1,trs2,trs3,trs4,coo);
70802 
70803    return et;
70804 }
70805 
CalTorE(xyz)70806 void CalTorE(xyz)
70807 COOSTRU *xyz;
70808 {
70809    int i,nt,it[MXTORS][4],ia1,ia2;
70810    float trs1[MXTORS][4];
70811    float trs2[MXTORS][4];
70812    float trs3[MXTORS][4];
70813    float trs4[MXTORS][4];
70814    float et;
70815 
70816    for (i=0; i < singleb.N; i++) {
70817 	ia1 = singleb.sng[i][0];
70818 	ia2 = singleb.sng[i][1];
70819 	nt = 0; et = 0.0;
70820 	if (torset(ia1,ia2,&nt,it,trs1,trs2,trs3,trs4,
70821 		xyz->iconn,singleb.ityp)) {
70822 	   tors(&et,nt,it,trs1,trs2,trs3,trs4,xyz->coo);
70823 	}
70824    }
70825 }
70826 
vdwlj(ev,xyz)70827 void vdwlj(ev,xyz)
70828 float *ev;
70829 COOSTRU *xyz;
70830 {
70831       int i,j,k,i1,i2;
70832       float vr[3],v14sc,vdwr1,vdwr2,vdwe1,vdwe2,rv2,rsum,epsm,rv,
70833 		rs2,rs3,p6,p12,e;
70834 
70835       *ev = 0.0;
70836       v14sc = 0.5;
70837 
70838 // we only do this for 1..4 interactions
70839 
70840       for (i=0; i<ndocka; i++) {
70841 
70842 	i1 = (int) xyz->ityp[i];
70843 	i1 = ABS(i1)-1;
70844 	vdwr1 = gfvdw[i1][0];
70845         vdwe1 = gfvdw[i1][1];
70846 
70847 	if (vdwe1 != 0.0) {
70848 
70849 	   for (k=i+1; k<ndocka; k++) {
70850 
70851 		i2 = (int) xyz->ityp[k];
70852 		i2 = ABS(i2)-1;
70853 		vdwr2 = gfvdw[i2][0];
70854         	vdwe2 = gfvdw[i2][1];
70855 
70856 		if (vdwe2 != 0.0) {
70857 
70858 		  for (j=0; j<3; j++) {
70859 			vr[j] = (xyz->coo[i*3+j] - xyz->coo[k*3+j])*toangs;
70860 		  }
70861 
70862 		  rv2 = vr[0]*vr[0] + vr[1]*vr[1] + vr[2]*vr[2];
70863 
70864 
70865 //          [ (Rmin)**12       (Rmin)**6 ]
70866 // e = eps  [ (----)     - 2.0 (----)    ]
70867 //          [ ( r  )           ( r  )    ]
70868 
70869 
70870 		  rsum = vdwr1 + vdwr2;
70871 		  epsm = sqrt(vdwe1 * vdwe2);
70872 		  epsm = epsm * v14sc;
70873 		  rv   = sqrt(rv2);
70874 		  rs2  = rsum*rsum;
70875 		  rs3  = rs2*rsum;
70876 		  p6   = (rs3*rs3) / (rv2*rv2*rv2);
70877 		  p12  = p6 * p6;
70878 
70879 		  e    = epsm * (p12 - 2.0*p6);
70880 
70881 		  *ev   = *ev + e;
70882 
70883 		}
70884 
70885 	   }
70886 	}
70887       }
70888 
70889 }
70890 
vdwS(isng,xyz,coo)70891 float vdwS(isng,xyz,coo)
70892 int isng;
70893 COOSTRU *xyz;
70894 double *coo;
70895 {
70896       int i,j,k,i1,i2,ia1,ia2,ia3,ia4;
70897       float vr[3],v14sc,vdwr1,vdwr2,vdwe1,vdwe2,rv2,rsum,epsm,rv,
70898 		rs2,rs3,p6,p12,e,ev;
70899 
70900       ev = 0.0;
70901       v14sc = 0.5;
70902 
70903       ia1 = singleb.sng[isng][0];
70904       ia2 = singleb.sng[isng][1];
70905 
70906 // we only do this for 1..4 interactions
70907 
70908       for (i=0; i < xyz->iconn[ia1*(MXCON+1)]; i++) {
70909 
70910 	ia3 = xyz->iconn[ia1*(MXCON+1)+1+i] - 1;
70911 
70912 	if (ia3 != ia2) {
70913 
70914 	   i1 = (int) xyz->ityp[ia3];
70915 	   i1 = ABS(i1)-1;
70916 	   vdwr1 = gfvdw[i1][0];
70917            vdwe1 = gfvdw[i1][1];
70918 
70919 	   if (vdwe1 != 0.0) {
70920 
70921 	     for (k=0; k < xyz->iconn[ia2*(MXCON+1)]; k++) {
70922 
70923 		ia4 = xyz->iconn[ia2*(MXCON+1)+1+k] - 1;
70924 
70925 		if (ia4 != ia1) {
70926 
70927 		   i2 = (int) xyz->ityp[ia4];
70928 		   i2 = ABS(i2)-1;
70929 		   vdwr2 = gfvdw[i2][0];
70930         	   vdwe2 = gfvdw[i2][1];
70931 
70932 		   if (vdwe2 != 0.0) {
70933 
70934 			for (j=0; j<3; j++) {
70935 			   vr[j] = (coo[ia3*3+j] - coo[ia4*3+j])*toangs;
70936 			}
70937 
70938 			rv2 = vr[0]*vr[0] + vr[1]*vr[1] + vr[2]*vr[2];
70939 
70940 
70941 //          [ (Rmin)**12       (Rmin)**6 ]
70942 // e = eps  [ (----)     - 2.0 (----)    ]
70943 //          [ ( r  )           ( r  )    ]
70944 
70945 
70946 			rsum = vdwr1 + vdwr2;
70947 			epsm = sqrt(vdwe1 * vdwe2);
70948 			epsm = epsm * v14sc;
70949 			rv   = sqrt(rv2);
70950 			rs2  = rsum*rsum;
70951 			rs3  = rs2*rsum;
70952 			p6   = (rs3*rs3) / (rv2*rv2*rv2);
70953 			p12  = p6 * p6;
70954 
70955 			e    = epsm * (p12 - 2.0*p6);
70956 
70957 			ev   = ev + e;
70958 
70959 		   }
70960 		}
70961 
70962 	     } // for k
70963 	   } // ifend vdwe1 != 0
70964 	} // ifend ia3 != ia2
70965       }
70966 
70967       return(ev);
70968 }
70969 
Create_Vecs(ia1,ia2,v1,v2,v3,k,xyz)70970 void Create_Vecs(ia1,ia2,v1,v2,v3,k,xyz)
70971 int ia1;
70972 int ia2;
70973 float *v1;
70974 float *v2;
70975 float *v3;
70976 int k;
70977 COOSTRU *xyz;
70978 {
70979     int i,j,ia3;
70980     float vl,v23[3];
70981 
70982     for (j=0; j < 3; j++) {
70983 	v1[j] = ((float) (TriArr[k]->coo[ia1*3+j] -
70984 			TriArr[k]->coo[ia2*3+j]));
70985     }
70986 
70987     vl = veclen(v1);
70988 
70989     for (j=0; j < 3; j++) {
70990 	v1[j] = v1[j] / vl;
70991     }
70992 
70993     for (i=0; i < xyz->iconn[ia2*(MXCON+1)]; i++) {
70994 
70995 	   ia3 = xyz->iconn[ia2*(MXCON+1)+1+i] - 1;
70996 
70997 	   if (ia3 != ia1) {
70998 
70999 		for (j=0; j < 3; j++) {
71000 		   v23[j] = ((float) (TriArr[k]->coo[ia3*3+j] -
71001 		   		   TriArr[k]->coo[ia2*3+j]));
71002 		}
71003 		break;
71004 	   }
71005 
71006     }
71007 
71008     cross(v1,v23,v2);
71009 
71010     vl = veclen(v2);
71011 
71012     for (j=0; j < 3; j++) {
71013 	v2[j] = v2[j] / vl;
71014     }
71015 
71016     cross(v1,v2,v3);
71017 
71018 }
71019 
71020 
RotDih(ia1,ia2,euc,coo,feuc,angle,v1,v2,v3,idx)71021 void RotDih(ia1,ia2,euc,coo,feuc,angle,v1,v2,v3,idx)
71022 int ia1;
71023 int ia2;
71024 double *euc;
71025 double *coo;
71026 float *feuc;
71027 float angle;
71028 float *v1;
71029 float *v2;
71030 float *v3;
71031 int idx;
71032 {
71033      int i,j,k;
71034      float v23[3],x,y,z,x2,y2,cosa,sina;
71035      double cc;
71036 
71037      cosa = cos(angle);
71038      sina = sin(angle);
71039 
71040      for (k=0; k < ndocka; k++) {
71041 
71042 	 if (jact[idx][k] == 1 && k != ia1 && k != ia2) {
71043 
71044 	   for (j=0; j < 3; j++) {
71045 		v23[j] = (float) (coo[k*3+j] - coo[ia2*3+j]);
71046 	   }
71047 
71048 	   IMPRD(v1,v23,&z,0);
71049 	   IMPRD(v2,v23,&y,0);
71050 	   IMPRD(v3,v23,&x,0);
71051 
71052 	   x2 = (cosa*x - sina*y);
71053 	   y2 = (sina*x + cosa*y);
71054 
71055 // new coordinates
71056 
71057 	   for (j=0; j < 3; j++) {
71058 		cc = (double) (v1[j]*z + v2[j]*y2 + v3[j]*x2);
71059 		euc[k*3+j] = coo[ia2*3+j] + cc;
71060 		feuc[k*3+j] = (float) euc[k*3+j];
71061 	   }
71062 
71063 	 } else {
71064 	   for (j=0; j < 3; j++) {
71065 		euc[k*3+j] = coo[k*3+j];
71066 		feuc[k*3+j] = (float) euc[k*3+j];
71067 	   }
71068 	 }
71069      } // end for k
71070 
71071 }
71072 
cplig(euc,coo)71073 void cplig(euc,coo)
71074 double *euc;
71075 double *coo;
71076 {
71077      int i,j;
71078 
71079      for (i=0; i < ndocka; i++) {
71080 	for (j=0; j < 3; j++) {
71081 	    euc[i*3+j] = coo[i*3+j];
71082 	}
71083      }
71084 
71085 }
71086 
71087 
FindCooAngles(int ias[2][MXDIH],int sngs[MXDIH],int ndih,int itri,int * iclos,int * frg,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel,float * F,double * euc,double * coo,COOSTRU * xyz,int * nt,int it[MXTORS][4],float trs1[MXTORS][4],float trs2[MXTORS][4],float trs3[MXTORS][4],float trs4[MXTORS][4])71088 float FindCooAngles(int ias[2][MXDIH], int sngs[MXDIH],
71089 			int ndih, int itri, int *iclos,int *frg,
71090 			float *q,float *vdwr,float *vdwe,
71091 			float *ql,float *vdwrl,float *vdwel,float *F,
71092 			double *euc,double *coo,COOSTRU *xyz,
71093 			int *nt,int it[MXTORS][4],
71094 			float trs1[MXTORS][4],
71095 			float trs2[MXTORS][4],
71096 			float trs3[MXTORS][4],
71097 			float trs4[MXTORS][4])
71098 {
71099      int ang1,ang2,ang3,ang4,k;
71100      float angle1,angle2,angle3,angle4,todeg;
71101      float p1,p2,pf,dir[3],emin,tmin;
71102      float v1[3],v2[3],v3[3];
71103      float *feuc,*feuc1,*feuc2,*feuc3;
71104      double *euc1,*euc2,*euc3,*finc;
71105 
71106      allFConf(&feuc,ndocka);
71107      allFConf(&feuc1,ndocka);
71108      allFConf(&feuc2,ndocka);
71109      allFConf(&feuc3,ndocka);
71110      allConf(&euc1,ndocka);
71111      allConf(&euc2,ndocka);
71112      allConf(&euc3,ndocka);
71113      allConf(&finc,ndocka);
71114 
71115 // need buffer to store orig coordinates !! Can be feuc ???
71116 // coo has the ligand pose
71117 
71118      todeg = 45.0 / atan(1.0);
71119 
71120      emin = BIGD;
71121      tmin = BIGD;
71122 
71123      for (ang1=-2; ang1 < 3; ang1++) {
71124 
71125 	angle1 = (((float) ang1)*30.0)/todeg;
71126 	Create_Vecs(ias[0][0],ias[1][0],v1,v2,v3,itri,xyz);
71127 	RotDih(ias[0][0],ias[1][0],euc,coo,feuc,angle1,v1,v2,v3,0);
71128 
71129 	if (CalClash(iclos,itri,vdwr,vdwrl,euc,0) == BIGD) {
71130 
71131 	   continue;
71132 
71133 	} else {
71134 
71135 	   p1 = CalTorS(sngs[0],xyz,euc,nt,it,trs1,trs2,trs3,trs4);
71136 
71137 	   CaljFE(feuc,xyzp->coo,iclos,
71138 		q,vdwr,vdwe,ql,vdwrl,vdwel,F,&p2,dir,frg);
71139 
71140 	   if (p2 < emin) {
71141 		emin = p2;
71142 		tmin = p1;
71143 		cplig(finc,euc);
71144 	   }
71145 	}
71146 
71147 	if (ndih > 1) {
71148 
71149 	 for (ang2=-2; ang2 < 3; ang2++) {
71150 
71151 	   angle2 = (((float) ang2)*30.0)/todeg;
71152 	   Create_Vecs(ias[0][1],ias[1][1],v1,v2,v3,itri,xyz);
71153 	   RotDih(ias[0][1],ias[1][1],euc1,euc,feuc1,angle2,v1,v2,v3,1);
71154 
71155 	   if (CalClash(iclos,itri,vdwr,vdwrl,euc1,1) == BIGD) {
71156 		continue;
71157 	   } else {
71158 
71159 		p1 = CalTorS(sngs[1],xyz,euc1,nt,it,trs1,trs2,trs3,trs4);
71160 
71161 		CaljFE(feuc1,xyzp->coo,iclos,
71162 			q,vdwr,vdwe,ql,vdwrl,vdwel,F,&p2,dir,frg);
71163 
71164 		if (p2 < emin) {
71165 		   emin = p2;
71166 		   tmin = p1;
71167 		   cplig(finc,euc1);
71168 		}
71169 
71170 	   }
71171 
71172 	   if (ndih > 2) {
71173 
71174 	      for (ang3=-2; ang3 < 3; ang3++) {
71175 
71176 		angle3 = (((float) ang3)*30.0)/todeg;
71177 		Create_Vecs(ias[0][2],ias[1][2],v1,v2,v3,itri,xyz);
71178 	   	RotDih(ias[0][2],ias[1][2],euc2,euc1,feuc2,angle3,
71179 			v1,v2,v3,2);
71180 		if (CalClash(iclos,itri,vdwr,vdwrl,euc2,2) == BIGD) {
71181 		   continue;
71182 		} else {
71183 
71184 		   p1 = CalTorS(sngs[2],xyz,euc2,nt,it,trs1,trs2,trs3,trs4);
71185 
71186 		   CaljFE(feuc2,xyzp->coo,iclos,
71187 			q,vdwr,vdwe,ql,vdwrl,vdwel,F,&p2,dir,frg);
71188 
71189 		   if (p2 < emin) {
71190 			emin = p2;
71191 			tmin = p1;
71192 			cplig(finc,euc2);
71193 		   }
71194 
71195 		}
71196 
71197 		if (ndih > 3) {
71198 
71199 		  for (ang4=-2; ang4 < 3; ang4++) {
71200 
71201 		   angle4 = (((float) ang4)*30.0)/todeg;
71202 		   Create_Vecs(ias[0][3],ias[1][3],v1,v2,v3,itri,xyz);
71203 	   	   RotDih(ias[0][3],ias[1][3],euc3,euc2,feuc3,angle4,
71204 				v1,v2,v3,3);
71205 		   if (CalClash(iclos,itri,vdwr,vdwrl,euc3,3) == BIGD) {
71206 			continue;
71207 		   } else {
71208 			p1 = CalTorS(sngs[3],xyz,euc3,
71209 				nt,it,trs1,trs2,trs3,trs4);
71210 
71211 			CaljFE(feuc3,xyzp->coo,iclos,
71212 				q,vdwr,vdwe,ql,vdwrl,vdwel,F,&p2,dir,frg);
71213 
71214 			if (p2 < emin) {
71215 			   emin = p2;
71216 			   tmin = p1;
71217 			   cplig(finc,euc3);
71218 			}
71219 		   }
71220 		  }
71221 		}
71222 
71223 	      }
71224 	   }
71225 
71226 	 }
71227 	}
71228      }
71229 
71230 /* this part is for when MXDIH is raised to six !!!
71231      if (ndih > 4) {
71232 
71233       for (ang1=-2; ang1 < 3; ang1++) {
71234 
71235 	angle1 = (((float) ang1)*30.0)/todeg;
71236 	Create_Vecs(ias[0][4],ias[1][4],v1,v2,v3,itri,xyz);
71237 	RotDih(ias[0][4],ias[1][4],euc,coo,feuc,angle1,v1,v2,v3,4);
71238 
71239 	if (CalClash(iclos,itri,vdwr,vdwrl,euc,4) == BIGD) {
71240 
71241 	   continue;
71242 
71243 	} else {
71244 
71245 	   p1 = CalTorS(sngs[4],xyz,euc,nt,it,trs1,trs2,trs3,trs4);
71246 
71247 	   CaljFE(feuc,xyzp->coo,iclos,
71248 		q,vdwr,vdwe,ql,vdwrl,vdwel,F,&p2,dir,frg);
71249 
71250 	   if (p2 < emin) {
71251 		emin = p2;
71252 		tmin = p1;
71253 		cplig(finc,euc);
71254 	   }
71255 	}
71256 
71257 	if (ndih > 5) {
71258 
71259 	 for (ang2=-2; ang2 < 3; ang2++) {
71260 
71261 	   angle2 = (((float) ang2)*30.0)/todeg;
71262 	   Create_Vecs(ias[0][5],ias[1][5],v1,v2,v3,itri,xyz);
71263 	   RotDih(ias[0][5],ias[1][5],euc1,euc,feuc1,angle2,v1,v2,v3,5);
71264 
71265 	   if (CalClash(iclos,itri,vdwr,vdwrl,euc1,5) == BIGD) {
71266 		continue;
71267 	   } else {
71268 
71269 		p1 = CalTorS(sngs[5],xyz,euc1,nt,it,trs1,trs2,trs3,trs4);
71270 
71271 		CaljFE(feuc1,xyzp->coo,iclos,
71272 			q,vdwr,vdwe,ql,vdwrl,vdwel,F,&p2,dir,frg);
71273 
71274 		if (p2 < emin) {
71275 		   emin = p2;
71276 		   tmin = p1;
71277 		   cplig(finc,euc1);
71278 		}
71279 
71280 	   }
71281 
71282 	 }
71283 	}
71284       }
71285      }
71286 */
71287 
71288      if (emin == BIGD) {
71289 //	RemCC_One(itri);
71290      } else {
71291 	cplig(euc,finc);
71292      }
71293 
71294      free(finc);
71295      free(euc1);
71296      free(euc2);
71297      free(euc3);
71298      free(feuc);
71299      free(feuc1);
71300      free(feuc2);
71301      free(feuc3);
71302 
71303 if (debugdck) fprintf(stderr,"\nFindCooAngles: tmin %.3f Emin %.3f\n\n",tmin,emin);
71304 
71305      if (tmin == BIGD) tmin = 0.0;
71306      if (emin == BIGD) emin = 0.0;
71307 
71308      return(tmin+emin);
71309 }
71310 
71311 
FindOAngles(int ias[2][MXDIH],int sngs[MXDIH],int ndih,int itri,int * iclos,int * frg,double * euc,COOSTRU * xyz,double * coo,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel,float * F)71312 float FindOAngles(int ias[2][MXDIH], int sngs[MXDIH],
71313 		int ndih, int itri, int *iclos, int *frg,
71314 		double *euc, COOSTRU *xyz, double *coo,
71315 		float *q,float *vdwr,float *vdwe,
71316 		float *ql,float *vdwrl,float *vdwel, float *F)
71317 {
71318    int nt,k;
71319    int     it[MXTORS][4];
71320    float trs1[MXTORS][4];
71321    float trs2[MXTORS][4];
71322    float trs3[MXTORS][4];
71323    float trs4[MXTORS][4];
71324    float Emin;
71325 
71326    nt = 0;
71327 
71328 // coo ligand pose in -> euc is adjusted optimised pose
71329 
71330    Emin = FindCooAngles(ias,sngs,ndih,itri,iclos,frg,
71331 			q,vdwr,vdwe,
71332 			ql,vdwrl,vdwel,F,
71333 			euc,coo,xyz,&nt,it,trs1,trs2,trs3,trs4);
71334 
71335    return(Emin);
71336 
71337 // keep lowest prof ?? and the associated euc ??
71338 }
71339 
FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,co,coo,xyz,nt,it,trs1,trs2,trs3,trs4)71340 float FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,co,coo,xyz,
71341 			nt,it,trs1,trs2,trs3,trs4)
71342 int isng;
71343 int ic[3];
71344 int ia2;
71345 int itel;
71346 float v1[3];
71347 float v2[3];
71348 float v3[3];
71349 float angle;
71350 double co[3][3];
71351 double *coo;
71352 COOSTRU *xyz;
71353 int *nt;
71354 int it[MXTORS][4];
71355 float trs1[MXTORS][4];
71356 float trs2[MXTORS][4];
71357 float trs3[MXTORS][4];
71358 float trs4[MXTORS][4];
71359 {
71360      int i,j,in;
71361      float cosa,sina,v23[3],x,y,z,x2,y2,p1,p2;
71362 
71363        cosa = cos(angle);
71364        sina = sin(angle);
71365 
71366 // restore original coordinates
71367 
71368        for (i=0; i < itel; i++) {
71369 	 if (ic[i] >= 0) {
71370 	   for (j=0; j < 3; j++) {
71371 		coo[ic[i]*3+j] = co[i][j];
71372 	   }
71373 	 }
71374        }
71375 
71376        for (i=0; i < itel; i++) {
71377 
71378 	   in = ic[i];
71379 
71380 	   if (in >= 0 && in < ndocka) {
71381 	      for (j=0; j < 3; j++) {
71382 		v23[j] = (float) (coo[in*3+j] - coo[ia2*3+j]);
71383 	      }
71384 	   }
71385 
71386 	   IMPRD(v1,v23,&z,0);
71387 	   IMPRD(v2,v23,&y,0);
71388 	   IMPRD(v3,v23,&x,0);
71389 
71390 	   x2 = (cosa*x - sina*y);
71391 	   y2 = (sina*x + cosa*y);
71392 
71393 // new coordinates
71394 
71395 	   if (in >= 0 && in < ndocka) {
71396 		for (j=0; j < 3; j++) {
71397 			coo[in*3+j] = coo[ia2*3+j] +
71398 				(v1[j]*z + v2[j]*y2 + v3[j]*x2);
71399 		}
71400 	   }
71401         }
71402 	p1 = CalTorS(isng,xyz,coo,nt,it,trs1,trs2,trs3,trs4);
71403         p2 = vdwS(isng,xyz,coo);
71404 	return(p1+p2);
71405 
71406 }
71407 
71408 
FindAngles(int first,int ia2,int isng,int itel,int * ic,COOSTRU * xyz,double co[3][3],double * coo,float * v1,float * v2,float * v3,float * angopt,float * toropt)71409 void FindAngles(int first, int ia2, int isng, int itel, int *ic,
71410 		COOSTRU *xyz, double co[3][3], double *coo,
71411 		float *v1, float *v2, float *v3,
71412 		float *angopt, float *toropt)
71413 {
71414    int i,j,ang,angp1,angm1,ango[3],nt,nprof;
71415    float cosa,sina,angle,todeg,oute,prof[36];
71416    float anglep5,anglem5,outep5,outem5;
71417    int it[MXTORS][4];
71418    float trs1[MXTORS][4];
71419    float trs2[MXTORS][4];
71420    float trs3[MXTORS][4];
71421    float trs4[MXTORS][4];
71422 
71423    todeg = 45.0 / atan(1.0);
71424 
71425    nprof = 0;
71426    nt = 0;
71427 
71428    for (ang=0; ang < 36; ang++) {
71429         prof[ang] = 0.0;
71430 	angle = (((float) ang)*10.0)/todeg;
71431 	if (first) {
71432 	  prof[ang] = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,
71433 			co,xyz->coo,xyz,&nt,it,trs1,trs2,trs3,trs4);
71434 	} else {
71435 	  prof[ang] = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,
71436 			co,coo,xyz,&nt,it,trs1,trs2,trs3,trs4);
71437 	}
71438 	if (prof[ang] == 0.0) nprof++;
71439 
71440    }
71441 
71442    if (nprof == 36 && singleb.dupsng[isng] == 1) {
71443 	toropt[0] = 0.0;
71444 	angopt[0] = 0.0;
71445 	return;
71446    }
71447 
71448    angopt[0] = -BIGD;
71449    angopt[1] = -BIGD;
71450    angopt[2] = -BIGD;
71451 
71452    toropt[0] =  BIGD;
71453    toropt[1] =  BIGD;
71454    toropt[2] =  BIGD;
71455 
71456    itel = -1;
71457 
71458    for (ang=0; ang < 36; ang++) {
71459 
71460 	if (ang == 0) {
71461 	   angm1 = 35;
71462 	   angp1 = ang + 1;
71463 
71464 	} else if (ang == 35) {
71465 	   angm1 = ang - 1;
71466 	   angp1 = 0;
71467 	} else {
71468 	   angm1 = ang - 1;
71469 	   angp1 = ang + 1;
71470 	}
71471 
71472 	if (prof[ang] < prof[angm1] && prof[ang] < prof[angp1]) {
71473 	   itel++;
71474 	   toropt[itel] = prof[ang];
71475 	   angopt[itel] = ((float) ang)*10.0;
71476 	   ango[itel]   = ang;
71477 	}
71478    }
71479 
71480    itel++;
71481 
71482    if (itel == 2) toropt[2] = 0.0;
71483 
71484    for (i=0; i < itel; i++) {
71485 
71486 	angle   = ango[i]*10 + 5 ;
71487 	anglep5 = ((int) angle) / todeg;
71488 
71489 	if (first) {
71490 	  outep5 = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,anglep5,
71491 			co,xyz->coo,xyz,
71492 			&nt,it,trs1,trs2,trs3,trs4);
71493 	} else {
71494 	  outep5 = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,anglep5,
71495 			co,coo,xyz,&nt,it,trs1,trs2,trs3,trs4);
71496 	}
71497 
71498 	angle   = ango[i]*10 - 5 ;
71499 	anglem5 = ((int) angle) / todeg;
71500 
71501 
71502 	if (first) {
71503 	  outem5 = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,anglem5,
71504 			co,xyz->coo,xyz,
71505 			&nt,it,trs1,trs2,trs3,trs4);
71506 	} else {
71507 	  outem5 = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,anglem5,
71508 			co,coo,xyz,
71509 			&nt,it,trs1,trs2,trs3,trs4);
71510 	}
71511 
71512 	if (outep5 < toropt[i]) {
71513 
71514 	  toropt[i] = outep5;
71515 	  angopt[i] = anglep5;
71516 
71517 	  for (j=0; j < 5; j++) {
71518 
71519 	    angle = ango[i]*10 + j + 1;
71520 	    angle = ((int) angle) / todeg;
71521 
71522 
71523 	    if (first) {
71524 		oute = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,
71525 			co,xyz->coo,xyz,
71526 			&nt,it,trs1,trs2,trs3,trs4);
71527 	    } else {
71528 		oute = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,
71529 			co,coo,xyz,
71530 			&nt,it,trs1,trs2,trs3,trs4);
71531 	    }
71532 
71533 	    if (oute < toropt[i]) {
71534 		toropt[i] = oute;
71535 	  	angopt[i] = angle;
71536 	    }
71537 
71538 	  }
71539 	}
71540 
71541 	if (outem5 < toropt[i]) {
71542 
71543 	  toropt[i] = outem5;
71544 	  angopt[i] = anglem5;
71545 
71546 	  for (j=0; j < 5; j++) {
71547 
71548 	    angle = ango[i]*10 - 5 + j;
71549 	    angle = ((int) angle) / todeg;
71550 
71551 	    if (first) {
71552 		oute = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,
71553 			co,xyz->coo,xyz,
71554 			&nt,it,trs1,trs2,trs3,trs4);
71555 	    } else {
71556 		oute = FindOptAngles(isng,ic,ia2,itel,v1,v2,v3,angle,
71557 			co,coo,xyz,
71558 			&nt,it,trs1,trs2,trs3,trs4);
71559 	    }
71560 
71561 	    if (oute < toropt[i]) {
71562 		toropt[i] = oute;
71563 	  	angopt[i] = angle;
71564 	    }
71565 
71566 	  }
71567 	}
71568    }
71569 
71570    if (itel == 0) {
71571 
71572 	angopt[0] = 0.0;
71573 	angopt[1] = 120.0;
71574 	angopt[2] = 240.0;
71575 	itel = 3;
71576 
71577    } else {
71578    }
71579 
71580    for (i=0; i < itel; i++) {
71581 	for (j=0; j < 3; j++) {
71582 	 if (ic[i] >= 0 && ic[i] < ndocka) {
71583 	   if (first) {
71584 		xyz->coo[ic[i]*3+j] = co[i][j];
71585 	   } else {
71586 		coo[ic[i]*3+j] = co[i][j];
71587 	   }
71588 	 }
71589 	}
71590    }
71591 
71592 }
71593 
CalcInter(double * cool,double * coo,int * iclos,float * q,float * vdwr,float * vdwe,float * ql,float * vdwrl,float * vdwel)71594 float CalcInter(double *cool,double *coo,int *iclos,
71595 		float *q,float *vdwr,float *vdwe,
71596 		float *ql,float *vdwrl,float *vdwel)
71597 {
71598    int i,j,l;
71599    float vr[3],rv,rv2,rs2,rs3,rsum,rinv,epsm,p6,p12;
71600    float e,ev,eq,econv;
71601    float evmax;
71602    int ivmax,jvmax;
71603 
71604    ev = 0.0; eq = 0.0;
71605    econv = 332.05382;
71606    evmax = 0.0;
71607 
71608    for (i=0; i < *xyzp->iatoms; i++) {
71609      if (iclos[i]) {
71610 	for (j=0; j < ndocka; j++) {
71611 
71612 	   for (l=0; l < 3; l++) {
71613 		vr[l] =  (float) (cool[j*3+l] - coo[i*3+l]);
71614 		vr[l] =  vr[l]*toangs;
71615 	   }
71616 
71617 	   rv2 = vr[0]*vr[0] + vr[1]*vr[1] + vr[2]*vr[2];
71618 	   rv = sqrt(rv2);
71619 	   rinv = 1.0/rv;
71620 	   rsum = vdwr[i] + vdwrl[j];
71621 	   epsm = sqrt(vdwe[i]*vdwel[j]);
71622 	   rs2 = rsum*rsum;
71623 	   rs3 = rs2*rsum;
71624 	   p6   = (rs3*rs3) / (rv2*rv2*rv2);
71625 	   p12  = p6 * p6;
71626 
71627 	   e    = epsm * (p12 - 2.0*p6);
71628 
71629 if (e > evmax) {
71630 	evmax = e;
71631 	ivmax = i;
71632 	jvmax = j;
71633 }
71634 	   ev   = ev + VDWSCAL*e;
71635 
71636 	   e = q[i]*ql[j]*econv*rinv;
71637 
71638 	   eq = eq + e;
71639 	}
71640      }
71641    }
71642 
71643 //fprintf(stderr,"CalcInter: evmax %.3f prot %d lig %d\n\n",evmax,ivmax,jvmax);
71644    return(eq+ev);
71645 
71646 }
71647 
Conformers_Energies(xyz)71648 void Conformers_Energies(xyz)
71649 COOSTRU *xyz;
71650 {
71651    int k,l,*iclos;
71652    float *q,*vdwr,*vdwe,*F;
71653    float Eintra,Einter;
71654    float ql[MXLIGA],vdwrl[MXLIGA],vdwel[MXLIGA];
71655    int nt;
71656    int     it[MXTORS][4];
71657    float trs1[MXTORS][4];
71658    float trs2[MXTORS][4];
71659    float trs3[MXTORS][4];
71660    float trs4[MXTORS][4];
71661 
71662    if (!AllArr(&q,&vdwr,&vdwe,&iclos,&F)) return;
71663 
71664    AssChg(q);
71665    AssVDW(vdwr,vdwe);
71666    AssVDWL(vdwrl,vdwel,ql);
71667 
71668    nt = 0;
71669 
71670    for (k=0; k < ntris; k++) {
71671 
71672       if (TriArr[k]->coo != NULL) {
71673 
71674 	FillClos(iclos,k);
71675 
71676 	Eintra = 0.0;
71677 
71678 	for (l=0; l < singleb.N; l++) {
71679 	   Eintra = Eintra +
71680 		CalTorS(l,xyz,TriArr[k]->coo,&nt,it,trs1,trs2,trs3,trs4);
71681 	}
71682 
71683 	TriArr[k]->e12 = Eintra;
71684 
71685 	Einter = CalcInter(TriArr[k]->coo,xyzp->coo,iclos,
71686 		q,vdwr,vdwe,ql,vdwrl,vdwel);
71687 
71688 	TriArr[k]->eint = Einter;
71689 	TriArr[k]->etot = Einter + Eintra;
71690 
71691 	if (TriArr[k]->etot > 0.0 && MapConformers) {
71692 	    if (TriArr[k]->coo != NULL) free(TriArr[k]->coo);
71693 	    free(TriArr[k]);
71694 	    TriArr[k] = NULL;
71695 	}
71696      }
71697    }
71698 
71699    Compress_Tri_L();
71700 
71701    free(q);
71702    free(vdwr);
71703    free(vdwe);
71704    free(F);
71705 }
71706 
Optimise_Conformers(ias,sngs,ndih,xyz)71707 void Optimise_Conformers(ias,sngs,ndih,xyz)
71708 int ias[2][MXDIH];
71709 int sngs[MXDIH];
71710 int ndih;
71711 COOSTRU *xyz;
71712 {
71713    int i,j,k,*iclos;
71714    int ia1,ia2,ia3,ic[3],itel,isng;
71715    double *euc;
71716    float *q,*vdwr,*vdwe,*F,Etor;
71717    float ql[MXLIGA],vdwrl[MXLIGA],vdwel[MXLIGA];
71718    int frg[MXLIGA];
71719 
71720    if (ndih == 0) return;
71721 
71722    if (!AllArr(&q,&vdwr,&vdwe,&iclos,&F)) return;
71723    allConf(&euc,ndocka);
71724 
71725    AssChg(q);
71726    AssVDW(vdwr,vdwe);
71727    AssVDWL(vdwrl,vdwel,ql);
71728 
71729    for (k=0; k < MXLIGA; k++) frg[k] = 1;
71730 
71731    for (k=0; k < singleb.N; k++) singleb.sngdone[k] = 0;
71732 
71733 // create orthogonal set of axes, v1,v2,v3: v1 is the rotation axis (z)
71734 
71735    for (k=0; k < ntris; k++) {
71736 
71737 if (debugdck) fprintf(stderr,"Optimise_Conformers: TriArr[%d]->eint %.3f\n",k,TriArr[k]->eint);
71738       if ((TriArr[k]->eint < 0.0 || !MapConformers)
71739 		&& TriArr[k]->coo != NULL) {
71740 
71741 	FillCOpt(iclos,k);
71742 
71743 	Etor = FindOAngles(ias,sngs,ndih,k,iclos,frg,
71744 		euc,xyz,TriArr[k]->coo,
71745 		q,vdwr,vdwe,
71746 		ql,vdwrl,vdwe,F);
71747 
71748 // toropt is not declared. But it also not correct the prof
71749 // answer consists of two components: the torsion part is
71750 // the real eint(ernal) part. The second has to do with
71751 // ligand - protein ineractions
71752 
71753 
71754 	if (TriArr[k] != NULL && TriArr[k]->coo != NULL) {
71755 
71756 	   if (Etor < 0.0 ) {
71757 if (debugdck) fprintf(stderr,"Optimise_Conformers: Etor %.3f\n",Etor);
71758 		TriArr[k]->eint = Etor;
71759 
71760 		for (i=0; i < ndocka; i++) {
71761 		   for (j=0; j < 3; j++) {
71762 			TriArr[k]->coo[i*3+j] = euc[i*3+j];
71763 		   }
71764 		}
71765 	   }
71766 	}
71767 
71768      }
71769    }
71770 
71771 }
71772 
Loop_Opt_Dih(Ifrag,xyz,ivis)71773 void Loop_Opt_Dih(Ifrag,xyz,ivis)
71774 int Ifrag;
71775 COOSTRU *xyz;
71776 int ivis;
71777 {
71778   int i,j,k,l,m,ia1,ia2,iact[MXLIGA],ifrag,jfrag,IFRG[9],NFRG,frg;
71779   int jfrg[9],nfrag,DFRG[MXLIGA];
71780   int ias[2][MXDIH],sngs[MXDIH],ndih;
71781 
71782   ndih = 0;
71783   IFRG[0] = Ifrag;
71784   NFRG = 1;
71785 //fprintf(stderr,"Loop_Opt_Dih: Ifrag %d\n",Ifrag);
71786 
71787   for (i=0; i < MXDIH; i++) {
71788      for (k=0; k < MXLIGA; k++) {
71789 	jact[i][k] = 0;
71790 	jopt[i][k] = 0;
71791      }
71792   }
71793 
71794   for (k=0; k < singleb.NFRAG; k++) DFRG[k] = 0;
71795 
71796   while (1) {
71797 
71798    for (k=0; k < NFRG; k++) {
71799 
71800       ifrag = IFRG[k];
71801       DFRG[ifrag] = 1;
71802       nfrag = 0;
71803 
71804       for (j=0; j < singleb.FrgSngN[ifrag]; j++) {
71805 	frg = 0;
71806 	l = singleb.FrgSng[ifrag][j];
71807 
71808 	if (!DFRG[singleb.SngFrg[l][0]] && DFRG[singleb.SngFrg[l][1]]) frg = 1;
71809 	if (DFRG[singleb.SngFrg[l][0]] && !DFRG[singleb.SngFrg[l][1]]) frg = 1;
71810 
71811 	if (frg) {
71812            for (i=0; i < ndocka; i++) iact[i] = 0;
71813 
71814 	   jfrag = singleb.SngFrg[l][0];
71815 	   if (!DFRG[jfrag]) jfrg[nfrag] = jfrag;
71816 
71817 	   jfrag = singleb.SngFrg[l][1];
71818 	   if (!DFRG[jfrag]) jfrg[nfrag] = jfrag;
71819 
71820 	   if (singleb.ifrg[singleb.sng[l][0]] == ifrag) {
71821 		ia1 = singleb.sng[l][0];
71822 		ia2 = singleb.sng[l][1];
71823 	   } else {
71824 		ia2 = singleb.sng[l][0];
71825 		ia1 = singleb.sng[l][1];
71826 	   }
71827 
71828 	   DFRG[jfrg[nfrag]] = 1;
71829 
71830 	   if (singleb.dupsng[l] == 2) {
71831 	      if (ndih < MXDIH) {
71832 		ias[0][ndih] = ia1;
71833 		ias[1][ndih] = ia2;
71834 		xyz->iatclr[ia1] = 15;
71835 		xyz->iatclr[ia2] = 15;
71836 		sngs[ndih] = l;
71837 	   	if (Create_Act(ia1,ia2,iact,xyz)) {
71838 		   for (m=0; m < ndocka; m++) {
71839 			jact[ndih][m] = iact[m];
71840 		   }
71841 
71842 	   	}
71843 		ndih++;
71844 	      }
71845 	   }
71846 	   nfrag++;
71847 	}
71848       }
71849    }
71850 
71851 //fprintf(stderr,"Loop_Opt_Dih: nfrag %d\n",nfrag);
71852    if (nfrag == 0) goto OPT;
71853 
71854    NFRG = nfrag;
71855    for (k=0; k < NFRG; k++) IFRG[k] = jfrg[k];
71856   }
71857 
71858 OPT:
71859 
71860   if (debugdck) fprintf(stderr,"Loop_Opt_Dih: ndih %d\n",ndih);
71861 
71862   for (k=0; k < ndih; k++) {
71863 //     fprintf(stderr,"idih %d\n",k);
71864      for (i=0; i < ndocka; i++) {
71865 	if (k == ndih-1) {
71866 	   jopt[k][i] = jact[k][i];
71867 	} else {
71868 	   if (jact[k][i] == 1 && jact[k+1][i] == 0) {
71869 		jopt[k][i] = 1;
71870 	   } else {
71871 		jopt[k][i] = 0;
71872 	   }
71873 	}
71874      }
71875   }
71876 
71877   if (!ivis) Optimise_Conformers(ias,sngs,ndih,xyz);
71878 
71879   return;
71880 
71881 }
71882 
Create_Conformers_Single(ia1,ia2,isng,iact,xyz)71883 void Create_Conformers_Single(ia1,ia2,isng,iact,xyz)
71884 int ia1;
71885 int ia2;
71886 int isng;
71887 int *iact;
71888 COOSTRU *xyz;
71889 {
71890    int i,j,k,l;
71891    int ia3,ic[3],itel,ntrift,first;
71892    float v1[3],v2[3],v3[3],v23[3],vl,x,y,z,x2,y2;
71893    float cosa,sina,angle,todeg,angopt[3],toropt[3];
71894    double co[3][3];
71895    static TRISTRU *FinTmp[MAXSTRI];
71896 
71897    todeg = 45.0 / atan(1.0);
71898 
71899    singleb.dupsng[isng] = IsSymFrg(isng,xyz);
71900 
71901 // create orthogonal set of axes, v1,v2,v3: v1 is the rotation axis (z)
71902 
71903    if (ntrif == -1) {
71904 	ntrift = 1;
71905 	first = 1;
71906    } else {
71907 	ntrift = ntrif;
71908 	for (k=0; k < ntrift; k++) {
71909 	   FinTmp[k] = TriFin[k];
71910 	   TriFin[k] = NULL;
71911 	}
71912 	ntrif = -1;
71913 	first = 0;
71914    }
71915 
71916    for (k=0; k < ntrift; k++) {
71917 
71918      for (j=0; j < 3; j++) {
71919 	if (first) {
71920 	   v1[j] = ((float) (xyz->coo[ia1*3+j] - xyz->coo[ia2*3+j]));
71921 	} else {
71922 	   v1[j] = ((float) (FinTmp[k]->coo[ia1*3+j] - FinTmp[k]->coo[ia2*3+j]));
71923 	}
71924      }
71925 
71926      vl = veclen(v1);
71927 
71928      for (j=0; j < 3; j++) {
71929 	v1[j] = v1[j] / vl;
71930      }
71931 
71932      for (i=0; i < xyz->iconn[ia2*(MXCON+1)]; i++) {
71933 
71934 	ia3 = xyz->iconn[ia2*(MXCON+1)+1+i] - 1;
71935 
71936 	if (ia3 != ia1) {
71937 	   for (j=0; j < 3; j++) {
71938 		if (first) {
71939 		   v23[j] = ((float) (xyz->coo[ia3*3+j] -
71940 				xyz->coo[ia2*3+j]));
71941 		} else {
71942 		   v23[j] = ((float) (FinTmp[k]->coo[ia3*3+j] -
71943 				FinTmp[k]->coo[ia2*3+j]));
71944 		}
71945 	   }
71946 	   break;
71947 	}
71948 
71949      }
71950 
71951      cross(v1,v23,v2);
71952 
71953      vl = veclen(v2);
71954 
71955      for (j=0; j < 3; j++) {
71956 	v2[j] = v2[j] / vl;
71957      }
71958 
71959      cross(v1,v2,v3);
71960 
71961 // retrieve the three atoms connected to ia2, that need to be rotated
71962 
71963      itel = -1;
71964 
71965      ic[0] = -1; ic[1] = -1; ic[2] = -1;
71966 
71967      for (i=0; i < xyz->iconn[ia2*(MXCON+1)]; i++) {
71968 
71969        ia3 = xyz->iconn[ia2*(MXCON+1)+1+i] - 1;
71970 
71971        if (ia3 != ia1) {
71972 	  itel++;
71973 	  ic[itel] = ia3;
71974 
71975 	  for (j=0; j < 3; j++) {
71976 	     if (first) {
71977 		co[itel][j] = xyz->coo[ic[itel]*3+j];
71978 	     } else {
71979 		co[itel][j] = FinTmp[k]->coo[ic[itel]*3+j];
71980 	     }
71981 	  }
71982        }
71983      }
71984 
71985      itel++;
71986 
71987 // find three optimal angles for rotation
71988 // allocate play temporary structure,such that etors can be calculated
71989 
71990      if (first) {
71991 	FindAngles(first,ia2,isng,itel,ic,
71992 		xyz,co,NULL,
71993 		v1,v2,v3,angopt,toropt);
71994      } else {
71995 	FindAngles(first,ia2,isng,itel,ic,
71996 		xyz,co,FinTmp[k]->coo,
71997 		v1,v2,v3,angopt,toropt);
71998      }
71999 
72000 
72001 // now create max three new conformations
72002 
72003      for (l=0; l < singleb.dupsng[isng]; l++) {
72004 
72005 	angle = angopt[l]/todeg;
72006 	cosa  = cos(angle);
72007 	sina  = sin(angle);
72008 
72009 	if (ntrif >= MAXSTRI-1) return;
72010 
72011 	ntrif++;
72012 	if (TriFin[ntrif] == NULL) {
72013 	   TriFin[ntrif] = (TRISTRU *) malloc(sizeof(TRISTRU));
72014 	   memcpy(TriFin[ntrif], &EmpTri, sizeof(TRISTRU));
72015 	}
72016 
72017 	allConf(&TriFin[ntrif]->coo,ndocka);
72018 
72019 // allocated space for new conformer,but what to copy into it ?
72020 // docked base fragment ?? Or loop over placements of base fragments ??
72021 
72022 	if (first) {
72023 	   TriFin[ntrif]->eint = 0.0;
72024 	} else {
72025 	   TriFin[ntrif]->eint = FinTmp[k]->eint + toropt[l];
72026 	}
72027 
72028 	for (i=0; i < ndocka; i++) {
72029          for (j=0; j<3; j++) {
72030 	   if (first) {
72031 		TriFin[ntrif]->coo[i*3+j] = xyz->coo[i*3+j];
72032 	   } else {
72033 		TriFin[ntrif]->coo[i*3+j] = FinTmp[k]->coo[i*3+j];
72034 	   }
72035          }
72036 	}
72037 
72038 	for (i=0; i < ndocka; i++) {
72039 
72040 	   if (iact[i] == 1 && i != ia1 && i != ia2) {
72041 	      for (j=0; j < 3; j++) {
72042 		v23[j] = ((float) (TriFin[ntrif]->coo[i*3+j] -
72043 				TriFin[ntrif]->coo[ia2*3+j]));
72044 	      }
72045 	      IMPRD(v1,v23,&z,0);
72046 	      IMPRD(v2,v23,&y,0);
72047 	      IMPRD(v3,v23,&x,0);
72048 
72049 // x2 and y2 could be reversed
72050 
72051 	      x2 = (cosa*x - sina*y);
72052 	      y2 = (sina*x + cosa*y);
72053 
72054 	      for (j=0; j < 3; j++) {
72055 		TriFin[ntrif]->coo[i*3+j] =  TriFin[ntrif]->coo[ia2*3+j] +
72056 				v1[j]*z + v2[j]*y2 + v3[j]*x2;
72057 	      }
72058 	   }
72059 	}
72060      }
72061 
72062      if (ntrift != 1 && first) {
72063 	if (FinTmp[k]->coo != NULL) free(FinTmp[k]->coo);
72064 	free(FinTmp[k]);
72065      }
72066    }
72067 
72068    ntrif++;
72069 
72070 
72071 }
72072 
Create_Act(IA1,IA2,iact,xyz)72073 int Create_Act(IA1,IA2,iact,xyz)
72074 int IA1;
72075 int IA2;
72076 int iact[MXLIGA];
72077 COOSTRU *xyz;
72078 {
72079    int i,j,k,ia1,ia2,ia3,iflg;
72080    int icn[MXLIGA],icno[MXLIGA],ICN[MXLIGA],ICNO[MXLIGA],ncn,NCN,ndck;
72081 
72082 
72083    for (j=0; j < MXLIGA; j++) {
72084 	icn[j] = 0;
72085 	icno[j] = 0;
72086 	ICN[j] = -1;
72087 	ICNO[j] = -1;
72088    }
72089 
72090    ICN[0]  = IA2;
72091    ICNO[0] = IA1;
72092    NCN = 1;
72093 
72094 NEXTR:
72095    ncn = -1;
72096 
72097    for (j=0; j < NCN; j++) {
72098       ia2 = ICN[j];
72099       ia1 = ICNO[j];
72100       for (i=0; i < xyz->iconn[ia2*(MXCON+1)]; i++) {
72101 	ia3 = xyz->iconn[ia2*(MXCON+1)+1+i] - 1;
72102 	if (ia3 != ia1 && iact[ia3] == 0) {
72103 	   iflg = 0;
72104 	   for (k=0; k < ncn; k++) {
72105 		if (icn[k] == ia3) iflg = 1;
72106 	   }
72107 	   if (!iflg) {
72108 		iact[ia3] = 1;
72109 		if (ncn < MXLIGA-1) {
72110 		   ncn++;
72111 		   icn[ncn]  = ia3;
72112 		   icno[ncn] = ia2;
72113 		} else {
72114 		   ncn = -1;
72115 		}
72116 	   }
72117 	}
72118       }
72119    }
72120    ncn++;
72121 
72122    ndck = 0;
72123    for (j=0; j < ndocka; j++) {
72124 	if (iact[j] == 1) ndck++;
72125    }
72126 
72127    if (ncn == 0) {
72128 	if (ndck == ndocka) return(0);
72129 	return(1);
72130    }
72131 
72132    NCN = ncn;
72133    for (i=0; i < NCN; i++) {
72134 	ICN[i]  = icn[i];
72135 	ICNO[i] = icno[i];
72136    }
72137    goto NEXTR;
72138    return(0);
72139 }
72140 
72141 // what about xyz, have to pass on to Create_Conformers_Single ?
72142 
CopyLig(xyz)72143 void CopyLig(xyz)
72144 COOSTRU *xyz;
72145 {
72146    int i,j;
72147 
72148    if (TriFin[0] == NULL) {
72149 	   TriFin[0] = (TRISTRU *) malloc(sizeof(TRISTRU));
72150 	   memcpy(TriFin[0], &EmpTri, sizeof(TRISTRU));
72151    }
72152    allConf(&TriFin[0]->coo,ndocka);
72153 
72154    for (i=0; i < ndocka; i++) {
72155       for (j = 0; j < 3; j++ ) {
72156 	TriFin[0]->coo[i*3+j] = xyz->coo[i*3+j];
72157       }
72158    }
72159 
72160    ntrif = 1;
72161 }
72162 
Create_Conformers(Ifrag,xyz)72163 void Create_Conformers(Ifrag,xyz)
72164 int Ifrag;
72165 COOSTRU *xyz;
72166 {
72167    int i,j,k,l,ia1,ia2,iact[MXLIGA],ifrag,jfrag,IFRG[9],NFRG,frg;
72168    int jfrg[9],nfrag,DFRG[MXLIGA];
72169 
72170    IFRG[0] = Ifrag;
72171    NFRG = 1;
72172 
72173    for (k=0; k < singleb.NFRAG; k++) DFRG[k] = 0;
72174 
72175 while (1) {
72176 
72177    nfrag = 0;
72178    for (k=0; k < NFRG; k++) {
72179 
72180       ifrag = IFRG[k];
72181       DFRG[ifrag] = 1;
72182 
72183       for (j=0; j < singleb.FrgSngN[ifrag]; j++) {
72184 	frg = 0;
72185 	l = singleb.FrgSng[ifrag][j];
72186 
72187 	if (!DFRG[singleb.SngFrg[l][0]] && DFRG[singleb.SngFrg[l][1]]) frg = 1;
72188 	if (DFRG[singleb.SngFrg[l][0]] && !DFRG[singleb.SngFrg[l][1]]) frg = 1;
72189 
72190 	if (frg) {
72191            for (i=0; i < ndocka; i++) iact[i] = 0;
72192 
72193 	   jfrag = singleb.SngFrg[l][0];
72194 	   if (!DFRG[jfrag]) jfrg[nfrag] = jfrag;
72195 
72196 	   jfrag = singleb.SngFrg[l][1];
72197 	   if (!DFRG[jfrag]) jfrg[nfrag] = jfrag;
72198 
72199 	   if (singleb.ifrg[singleb.sng[l][0]] == ifrag) {
72200 		ia1 = singleb.sng[l][0];
72201 		ia2 = singleb.sng[l][1];
72202 	   } else {
72203 		ia2 = singleb.sng[l][0];
72204 		ia1 = singleb.sng[l][1];
72205 	   }
72206 
72207 	   DFRG[jfrg[nfrag]] = 1;
72208 
72209 	   if (Create_Act(ia1,ia2,iact,xyz)) {
72210 	   }
72211 	   Create_Conformers_Single(ia1,ia2,l,iact,xyz);
72212 	   if (singleb.FrgSngN[ifrag] >= 1) nfrag++;
72213 	}
72214       }
72215    }
72216 
72217 if (nfrag == 0) fprintf(stderr,"Create_Conformers: nfrag == 0\n");
72218    if (nfrag == 0) return;
72219 
72220    NFRG = nfrag;
72221    for (k=0; k < NFRG; k++) IFRG[k] = jfrg[k];
72222 }
72223 
72224 // This only takes care of the first series of connected. NOT
72225 // the ones connected to those !!
72226 }
72227 
72228 
dst(Tri1,Tri2)72229 double dst(Tri1,Tri2)
72230 TRISTRU *Tri1;
72231 TRISTRU *Tri2;
72232 {
72233    int i,j;
72234    double dd,tt;
72235 
72236    dd = 0.0;
72237 
72238    for (i = 0; i < ndocka; i++ ) {
72239       for (j = 0; j < 3; j++ ) {
72240 	tt = (Tri1->coo[i*3+j] - Tri2->coo[i*3+j]);
72241 	dd = dd + tt*tt;
72242       }
72243    }
72244    dd = dd / ndocka;
72245    dd = sqrt(dd);
72246    return(dd);
72247 }
72248 
dst_coo(xyzp1,xyzp2,nato1,nato2)72249 double dst_coo(xyzp1,xyzp2,nato1,nato2)
72250 COOSTRU *xyzp1;
72251 COOSTRU *xyzp2;
72252 int nato1;
72253 int nato2;
72254 {
72255    int i,j;
72256    double dd,tt;
72257 
72258    dd = 0.0;
72259 
72260    if (nato2 < nato1) return(-1.0);
72261 
72262    for (i = 0; i < nato1; i++ ) {
72263       for (j = 0; j < 3; j++ ) {
72264 	tt = (xyzp1->coo[i*3+j] - xyzp2->coo[i*3+j])*toangs;
72265 	dd = dd + tt*tt;
72266       }
72267    }
72268    dd = dd / (nato1);
72269    dd = sqrt(dd);
72270    return(dd);
72271 }
72272 
cmpldat(a,b)72273 static int cmpldat(a,b)
72274 LDAT *a, *b;
72275 {
72276     if (a->dd > b->dd) return 1;
72277     else
72278        if (a->dd == b->dd) return  0;
72279        else          return -1;
72280 }
72281 
cmptri(const void * a,const void * b)72282 static int cmptri(const void * a,const void * b)
72283 {
72284     TRISTRU **Tria = (TRISTRU **) a;
72285     TRISTRU **Trib = (TRISTRU **) b;
72286     if ((*Tria) == NULL || (*Trib) == NULL) return 0;
72287     if ((*Tria)->e12 > (*Trib)->e12) return  1;
72288     if ((*Tria)->e12 < (*Trib)->e12) return -1;
72289     return 0;
72290 
72291 }
72292 
ldateq(a,b)72293 static int ldateq(a,b)
72294 LDAT *a, *b;
72295 {
72296     if (a->dd == b->dd && a->i == b->i && a->j == b->j) return 1;
72297     return 0;
72298 }
72299 
dsply_List(node * begin)72300 void dsply_List(node *begin)
72301 {
72302     int n,i;
72303     node *p;
72304 
72305     n = 0;
72306     if (begin == NULL) {
72307         fprintf(stderr,"List is empty\n");
72308         return;
72309     }
72310 
72311     p = begin;
72312 
72313     fprintf(stderr,"List is :\n");
72314 
72315     while (p != NULL) {
72316         fprintf(stderr,"(i=%d,j=%d,dd=%f,stat=%d)",
72317 		p->info.i,p->info.j,p->info.dd,p->info.stat);
72318 
72319 	if (p->info.N > 0) {
72320            fprintf(stderr,"(Arr=");
72321 	   for (i=0; i<p->info.N; i++) {
72322 		fprintf(stderr,"%3d,",p->info.Arr[i]);
72323 	   }
72324 	}
72325         fprintf(stderr,")\n");
72326 
72327 
72328         p = p->next_node;
72329 	n++;
72330     }
72331 
72332     fprintf(stderr,"\n");
72333     fprintf(stderr,"# %d Elemnts\n",n);
72334 }
72335 
set_List(node * begin,node ** barr,int * N,int MXARR)72336 void set_List(node *begin,node **barr,int *N,int MXARR)
72337 {
72338     node *p;
72339 
72340     *N = 0;
72341     if (begin == NULL) return;
72342 
72343     p = begin;
72344 
72345     while(p != NULL) {
72346 	barr[*N] = p;
72347         p = p->next_node;
72348 	(*N)++;
72349 	if (*N == MXARR) return;
72350     }
72351 }
72352 
max_List(node * begin)72353 int max_List(node *begin)
72354 {
72355     node *p;
72356     LDAT info;
72357     int mx;
72358 
72359     mx = 0;
72360     if (begin == NULL) return(mx);
72361 
72362     p = begin;
72363     info = p->info;
72364     mx = info.i;
72365     if (info.j > mx) mx = info.j;
72366 
72367     while(p != NULL) {
72368 	info = p->info;
72369 	if (info.i > mx) mx = info.i;
72370 	if (info.j > mx) mx = info.j;
72371         p = p->next_node;
72372     }
72373 
72374     return(mx);
72375 }
72376 
upd_List(node ** barr,int * N,node * delnode)72377 void upd_List(node **barr,int *N,node *delnode)
72378 {
72379     int i,j;
72380 
72381     for (i=0; i < *N; i++) {
72382 	if (barr[i] == delnode) {
72383 	   (*N)--;
72384 	   for (j=i; j < *N; j++) {
72385 		barr[j] = barr[j+1];
72386 	   }
72387 	}
72388     }
72389 }
72390 
replc_List(node * begin,int val,int nval)72391 void replc_List(node *begin,int val,int nval)
72392 {
72393     int n,i,j;
72394     node *p;
72395 
72396     n = 0;
72397 
72398     if (begin==NULL) {
72399         return;
72400     }
72401 
72402     p = begin;
72403     while (p != NULL) {
72404 	i = p->info.i; j = p->info.j;
72405 	if (i == val || j == val) {
72406 	   if (i == val) i = nval;
72407 	   if (j == val) j = nval;
72408 	   if (i < j) {
72409 		   p->info.i = i;
72410 		   p->info.j = j;
72411 	   } else {
72412 		   p->info.i = j;
72413 		   p->info.j = i;
72414 	   }
72415 	}
72416         p=p->next_node;
72417 	n++;
72418     }
72419 }
72420 
addtoemptylist(node * begin,LDAT data_element)72421 node *addtoemptylist(node *begin,LDAT data_element)
72422 {
72423     node *temp;
72424     temp=(node *)malloc(sizeof(node));
72425     temp->info=data_element;
72426     temp->prev_node=NULL;
72427     temp->next_node=NULL;
72428     begin=temp;
72429     return begin;
72430 }
72431 
addatendlist(node * begin,LDAT data_element)72432 node *addatendlist(node *begin,LDAT data_element)
72433 {
72434     node *temp,*p;
72435 
72436     if (begin == NULL) {
72437         printf("List is empty\n");
72438         return NULL;
72439     }
72440 
72441     temp = (node *) malloc(sizeof(node));
72442     temp->info = data_element;
72443 
72444     p=begin;
72445     while (p->next_node != NULL)
72446         p=p->next_node;
72447 
72448     p->next_node=temp;
72449     temp->next_node=NULL;
72450     temp->prev_node=p;
72451     return begin;
72452 }
72453 
insertdd(node * begin,node ** barr,int * N,LDAT data_element)72454 node *insertdd(node *begin,node **barr,int *N,LDAT data_element)
72455 {
72456     node *temp,*p,*tp,*tn;
72457     int n;
72458 
72459     temp = (node *) malloc(sizeof(node));
72460     temp->info = data_element;
72461     temp->next_node = NULL;
72462     temp->prev_node = NULL;
72463 
72464     p = begin;
72465     tp = NULL;
72466 
72467     n = 0;
72468     while (p != NULL) {
72469         if (p->next_node == NULL)  {
72470 
72471             temp->prev_node=p;
72472             temp->next_node=p->next_node;
72473             p->next_node = temp;
72474 	    goto NEXT;
72475 
72476 	} else if (p->prev_node == NULL) {
72477 	   if (p->info.dd < data_element.dd) {
72478               temp->prev_node = NULL;
72479               temp->next_node= p;
72480               p->prev_node = temp;
72481 	      begin = temp;
72482 	      goto NEXT;
72483 	   }
72484 
72485 	} else {
72486 
72487 	   if (p->info.dd < data_element.dd &&
72488 	    p->next_node->info.dd >= data_element.dd) {
72489 
72490             temp->prev_node=p;
72491             temp->next_node=p->next_node;
72492 
72493             p->next_node->prev_node = temp;
72494 
72495             p->next_node = temp;
72496 	    goto NEXT;
72497            }
72498 
72499         }
72500 	tp = p;
72501         p = p->next_node;
72502 	n++;
72503     }
72504 NEXT:
72505     return begin;
72506 }
72507 
deletenode(node * begin,node * delnode,LDAT * data_element,node ** barr,int * N)72508 node *deletenode(node *begin,node *delnode,LDAT *data_element,node **barr,int *N)
72509 {
72510     node *temp,*tp,*tn;
72511 
72512     if (begin == NULL) {
72513 	goto NEXT;
72514     }
72515 
72516     if (begin->next_node == NULL) {
72517         if (begin->info.i == data_element->i &&
72518 		begin->info.j == data_element->j) {
72519             temp  = begin;
72520             begin = NULL;
72521 	    data_element->dd = temp->info.dd;
72522 	    delnode = begin;
72523 
72524         } else {
72525 	    delnode = NULL;
72526 
72527         }
72528 	goto NEXT;
72529     }
72530 
72531 
72532     if (begin->info.i == data_element->i &&
72533 	begin->info.j == data_element->j) {
72534 
72535         temp=begin;
72536 	data_element->dd = temp->info.dd;
72537         begin=begin->next_node;
72538         begin->prev_node=NULL;
72539 	delnode = begin;
72540 	goto NEXT;
72541     }
72542 
72543     temp=begin->next_node;
72544     tp = begin;
72545     tn = temp->next_node;
72546 
72547     while (temp->next_node != NULL) {
72548 
72549         if (temp->info.i == data_element->i &&
72550 		temp->info.j == data_element->j) {
72551 
72552             if (tp != NULL) {
72553 		if (tp->next_node != NULL) {
72554 		   tp->next_node = temp->next_node;
72555 		}
72556 	    }
72557             if (tn != NULL) {
72558 		tn->prev_node = temp->prev_node;
72559 	    }
72560 	    delnode = temp;
72561 	    goto NEXT;
72562         }
72563 	tp = temp;
72564         temp=temp->next_node;
72565 	tn = temp->next_node;
72566     }
72567 
72568     if (temp->info.i == data_element->i &&
72569 	temp->info.j == data_element->j) {
72570 	data_element->dd = temp->info.dd;
72571 
72572         temp->prev_node->next_node=NULL;
72573 	delnode = temp;
72574 	goto NEXT;
72575     }
72576 
72577     delnode = NULL;
72578 NEXT:
72579     upd_List(barr,N,delnode);
72580     return begin;
72581 }
72582 
dlnode(node * p,LDAT * data_element)72583 node *dlnode(node *p,LDAT *data_element)
72584 {
72585     node *temp,*tp,*tn,*ipp;
72586     int ip = 0;
72587 
72588     if (p == NULL) {
72589 	goto NEXT;
72590     }
72591 
72592     if (p->next_node == NULL) {
72593         if (p->info.i == data_element->i &&
72594 		p->info.j == data_element->j) {
72595             temp  = p;
72596             p = NULL;
72597 	    data_element->dd = temp->info.dd;
72598         }
72599 	goto NEXT;
72600     }
72601 
72602 
72603     if (p->info.i == data_element->i &&
72604 	p->info.j == data_element->j) {
72605 
72606         temp=p;
72607 	data_element->dd = temp->info.dd;
72608 	ipp = p->prev_node;
72609         p=p->next_node;
72610 	p->prev_node=ipp;
72611 	goto NEXT;
72612     }
72613 
72614     temp=p->next_node;
72615     tp = p;
72616     tn = temp->next_node;
72617 
72618     while (temp->next_node != NULL) {
72619 
72620         if (temp->info.i == data_element->i &&
72621 		temp->info.j == data_element->j) {
72622 
72623             if (tp != NULL) {
72624 		if (tp->next_node != NULL) {
72625 		   tp->next_node = temp->next_node;
72626 		}
72627 	    }
72628             if (tn != NULL) {
72629 		tn->prev_node = temp->prev_node;
72630 	    }
72631 	    goto NEXT;
72632         }
72633 	tp = temp;
72634         temp=temp->next_node;
72635 	tn = temp->next_node;
72636     }
72637 
72638     if (temp->info.i == data_element->i &&
72639 	temp->info.j == data_element->j) {
72640 	data_element->dd = temp->info.dd;
72641 
72642         temp->prev_node->next_node=NULL;
72643 	goto NEXT;
72644     }
72645 
72646 NEXT:
72647     return p;
72648 }
72649 
Add2Delarr(node * delnode,node ** delarr,int * N,int MXARR)72650 void Add2Delarr(node *delnode,node **delarr,int *N,int MXARR)
72651 {
72652     if (delnode == NULL) return;
72653 
72654     if (*N < MXARR) {
72655 	delarr[(*N)] =  delnode;
72656 	(*N)++;
72657     }
72658 }
72659 
FreeDelarr(node ** delarr,int * N)72660 void FreeDelarr(node **delarr,int *N)
72661 {
72662     int i;
72663 
72664     for (i=0; i < *N; i++) {
72665 	if (delarr[i] != NULL) free(delarr[i]);
72666     }
72667 }
72668 
get_info(node * begin,LDAT data_element)72669 LDAT get_info(node *begin,LDAT data_element)
72670 {
72671     node *temp;
72672     LDAT nulinfo;
72673 
72674     nulinfo.i = -1; nulinfo.j = -1;
72675     if (begin == NULL) {
72676         return nulinfo;
72677     }
72678 
72679     if (begin->next_node == NULL) {
72680 
72681         if (begin->info.i == data_element.i &&
72682 		begin->info.j == data_element.j) {
72683             return begin->info;
72684         } else {
72685             return nulinfo;
72686         }
72687     }
72688 
72689 
72690     if (begin->info.i == data_element.i &&
72691 		begin->info.j == data_element.j) {
72692         return begin->info;
72693     }
72694 
72695     temp = begin->next_node;
72696 
72697     while (temp->next_node != NULL) {
72698 
72699         if (temp->info.i == data_element.i &&
72700 		temp->info.j == data_element.j) {
72701 	    if (sizeof(LDAT) == sizeof(temp->info)) return temp->info;
72702         }
72703         temp=temp->next_node;
72704     }
72705 
72706     if (temp->info.i == data_element.i &&
72707 		temp->info.j == data_element.j) {
72708 
72709         return temp->info;
72710     }
72711 
72712     return nulinfo;
72713 }
72714 
delC(arr,n,value)72715 void delC(arr,n,value)
72716 int *arr;
72717 int *n;
72718 int value;
72719 {
72720     int i,j,k;
72721 
72722     k = -1;
72723 
72724     for (i=0; i < *n; i++) {
72725 	if (arr[i] == value) {
72726 	   k = i;
72727 	}
72728     }
72729 
72730     if (k == -1) return;
72731 
72732     (*n)--;
72733     for (i=k; i < *n; i++) {
72734 	arr[i] = arr[i+1];
72735     }
72736 }
72737 
repC(arr,n,value,nval)72738 void repC(arr,n,value,nval)
72739 int *arr;
72740 int *n;
72741 int value;
72742 int nval;
72743 {
72744     int i;
72745 
72746     for (i=0; i < *n; i++) {
72747 	if (arr[i] == value) {
72748 	   arr[i] = nval;
72749 	}
72750     }
72751 
72752 }
72753 
redC(arr,n,nval)72754 void redC(arr,n,nval)
72755 int *arr;
72756 int *n;
72757 int nval;
72758 {
72759     int i,j,frst,nn;
72760 
72761 
72762     frst = -1;
72763     i = 0;
72764 
72765     while (i < *n) {
72766 	if (arr[i] == nval) {
72767 	   if (frst != -1) {
72768 		nn = (*n) - 1;
72769 		for (j=i; j < nn; j++) {
72770 		   arr[j] = arr[j+1];
72771 		}
72772 		(*n)--;
72773 	   } else {
72774 		frst = 0;
72775 	   }
72776 	}
72777 	i++;
72778     }
72779 
72780 }
72781 
delArr(arr,n,value)72782 void delArr(arr,n,value)
72783 LDAT *arr;
72784 int *n;
72785 int value;
72786 {
72787     int i;
72788 
72789     (*n)--;
72790     for (i=value; i < *n; i++) {
72791 	arr[i] = arr[i+1];
72792     }
72793 }
72794 
prL(int * L,int N,int C1)72795 void prL(int *L,int N,int C1)
72796 {
72797    int kk;
72798    for (kk=0; kk < N; kk++) {
72799       fprintf(stderr,"L[%d] %d\n",C1,L[kk]);
72800    }
72801 }
72802 
rd_tmpArr(tmpArr,K,L,N)72803 int rd_tmpArr(tmpArr,K,L,N)
72804 LDAT **tmpArr;
72805 int *K;
72806 int *L[MAXTRI];
72807 int N[MAXTRI];
72808 {
72809     int i,j;
72810     FILE *of;
72811     LDAT *tArr;
72812     int NN;
72813     int LL[1000];
72814 
72815 
72816     of = fopen("tmparr","r");
72817 
72818     if (of == NULL) {
72819 	fprintf(stderr,"Error opening file tmparr\n");
72820  	return(-1);
72821     }
72822 
72823     *K = 0;
72824 
72825     fread(K, (size_t) sizeof(int), (size_t) 1, of);
72826 
72827     tArr = (LDAT *) malloc((*K)*sizeof(LDAT));
72828 
72829     for (i=0; i < *K; i++) {
72830 	fread(&tArr[i], (size_t) sizeof(LDAT), (size_t) 1, of);
72831     }
72832 
72833     *tmpArr = tArr;
72834 
72835     for (i=0; i < *K; i++) {
72836 	fread(&N[i], (size_t) sizeof(int), 1, of);
72837 	L[i] = (int *) malloc(N[i]*sizeof(int));
72838     }
72839 
72840 
72841     for (i=0; i < *K; i++) {
72842 	fread(&LL, (size_t) sizeof(int), (size_t) N[i], of);
72843 	for (j=0; j < N[i]; j++) {
72844 	   L[i][j] = LL[j];
72845 	}
72846     }
72847 
72848     fclose(of);
72849 
72850     return(0);
72851 }
72852 
Chk_NNode(int * Arr,int N,int val)72853 int Chk_NNode(int *Arr,int N,int val)
72854 {
72855 	int i;
72856 
72857 	for (i=0; i < N; i++)
72858 	   if (Arr[i] == val) return(1);
72859 	return(0);
72860 }
72861 
Cr_NNode(NNODE ** NewNodes,int * NNewNodes,int Cnew,int C1,int C2,int mx)72862 void Cr_NNode(NNODE **NewNodes,int *NNewNodes,int Cnew,int C1,int C2,int mx)
72863 {
72864 	int i,j;
72865 
72866 /*
72867 fprintf(stderr,"in Cr_NNode: NNewNodes %3d Cnew %3d C1 %3d C2 %3d mx %3d\n",*NNewNodes,Cnew,C1,C2,mx);
72868 */
72869 	NewNodes[*NNewNodes] = (NNODE *) malloc(sizeof(NNODE));
72870 	NewNodes[*NNewNodes]->Num = Cnew;
72871 	NewNodes[*NNewNodes]->Arr = (int *) malloc(sizeof(int)*1000);
72872 	NewNodes[*NNewNodes]->CC = 0;
72873 
72874 	if (C1 <= mx && C2 <= mx) {
72875 
72876 	   NewNodes[*NNewNodes]->Arr[0] = C1;
72877 	   NewNodes[*NNewNodes]->Arr[1] = C2;
72878 	   NewNodes[*NNewNodes]->N = 2;
72879 
72880 	} else if (C1 > mx && C2 > mx) {
72881 
72882 	   NewNodes[*NNewNodes]->N = 0;
72883 	   for (i=0; i < *NNewNodes; i++) {
72884 		if (NewNodes[i] != NULL) {
72885 		   if (NewNodes[i]->Num == C1 || NewNodes[i]->Num == C2) {
72886 			for (j=0; j < NewNodes[i]->N ; j++) {
72887 			   if (!Chk_NNode(NewNodes[*NNewNodes]->Arr,
72888 				NewNodes[*NNewNodes]->N, NewNodes[i]->Arr[j])) {
72889 			   NewNodes[*NNewNodes]->Arr[NewNodes[*NNewNodes]->N] =
72890 						NewNodes[i]->Arr[j];
72891 			   NewNodes[*NNewNodes]->N++;
72892 			   }
72893 			}
72894 		   }
72895 		}
72896 	   }
72897 
72898 	} else if (C1 > mx && C2 <= mx) {
72899 
72900 	   NewNodes[*NNewNodes]->Arr[0] = C2;
72901 	   NewNodes[*NNewNodes]->N = 1;
72902 
72903 	   for (i=0; i < *NNewNodes; i++) {
72904 		if (NewNodes[i] != NULL) {
72905 		   if (NewNodes[i]->Num == C1) {
72906 			for (j=0; j < NewNodes[i]->N ; j++) {
72907 			   NewNodes[*NNewNodes]->Arr[NewNodes[*NNewNodes]->N] =
72908 						NewNodes[i]->Arr[j];
72909 			   NewNodes[*NNewNodes]->N++;
72910 			}
72911 		   }
72912 		}
72913 	   }
72914 
72915 	} else if (C2 > mx && C1 <= mx) {
72916 
72917 	   NewNodes[*NNewNodes]->Arr[0] = C1;
72918 	   NewNodes[*NNewNodes]->N = 1;
72919 
72920 	   for (i=0; i < *NNewNodes; i++) {
72921 		if (NewNodes[i] != NULL) {
72922 		   if (NewNodes[i]->Num == C2) {
72923 			for (j=0; j < NewNodes[i]->N ; j++) {
72924 			   NewNodes[*NNewNodes]->Arr[NewNodes[*NNewNodes]->N] =
72925 						NewNodes[i]->Arr[j];
72926 			   NewNodes[*NNewNodes]->N++;
72927 			}
72928 		   }
72929 		}
72930 	   }
72931 
72932 	}
72933 	(*NNewNodes)++;
72934 }
72935 
Get_NNode(NNODE ** NewNodes,int * NNewNodes,int Ctar,int mx)72936 int Get_NNode(NNODE **NewNodes,int *NNewNodes,int Ctar,int mx)
72937 {
72938 	int i,j;
72939 
72940 	for (i=0; i < *NNewNodes; i++) {
72941 	   if (NewNodes[i] != NULL) {
72942 		if (NewNodes[i]->Num == Ctar) return(i);
72943 	   }
72944 	}
72945 
72946 	return(-1);
72947 }
72948 
Prt_NNode(NNODE ** NewNodes,int * NNewNodes)72949 void Prt_NNode(NNODE **NewNodes,int *NNewNodes)
72950 {
72951 	int i,j;
72952 
72953 	for (i=0; i < *NNewNodes; i++) {
72954 	   if (NewNodes[i] != NULL) {
72955 		fprintf(stderr,"New Node %3d: CC %d {\n",NewNodes[i]->Num,NewNodes[i]->CC);
72956 		for (j=0; j < NewNodes[i]->N ; j++)
72957 			fprintf(stderr,"%3d",NewNodes[i]->Arr[j]);
72958 		fprintf(stderr,"\n}\n");
72959 	   }
72960 	}
72961 
72962 }
72963 
Clus_Min_NNode(NNODE ** NewNodes,int * NNewNodes)72964 void Clus_Min_NNode(NNODE **NewNodes,int *NNewNodes)
72965 {
72966 	int i,j,imn;
72967 	float emin;
72968 
72969 	emin = 10000.0;
72970 	imn = -1;
72971 
72972 	for (i=0; i < *NNewNodes; i++) {
72973 	   if (NewNodes[i] != NULL) {
72974 	      if (NewNodes[i]->CC) {
72975 		for (j=0; j < NewNodes[i]->N ; j++) {
72976 		   if (TriArr[NewNodes[i]->Arr[j]] != NULL) {
72977 		      if (TriArr[NewNodes[i]->Arr[j]]->e12 < emin) {
72978 			emin = TriArr[NewNodes[i]->Arr[j]]->e12;
72979 			imn  = NewNodes[i]->Arr[j];
72980 		      }
72981 		   }
72982 		}
72983 		if (imn != -1) {
72984 		   for (j=0; j < NewNodes[i]->N ; j++) {
72985 			if (NewNodes[i]->Arr[j] != imn) {
72986 			   free(TriArr[NewNodes[i]->Arr[j]]);
72987 			   TriArr[NewNodes[i]->Arr[j]] = NULL;
72988 			}
72989 		   }
72990 
72991 		}
72992 	      }
72993 	   }
72994 	}
72995 
72996 }
72997 
Test_Linkage(N,L,K,tmpArr)72998 void Test_Linkage(N,L,K,tmpArr)
72999 int N[MAXTRI];
73000 int *L[MAXTRI];
73001 int *K;
73002 LDAT *tmpArr;
73003 {
73004     if (N[0] == 0) L[0] = (int *) malloc(2*sizeof(int));
73005     if (N[1] == 0) L[1] = (int *) malloc(2*sizeof(int));
73006     if (N[2] == 0) L[2] = (int *) malloc(2*sizeof(int));
73007 
73008     *K = 3;
73009     L[0][0] = 1; L[0][1] = 2; N[0] = 2; tmpArr[0].dd = 3.0; tmpArr[0].i = 0; tmpArr[0].j = 1;
73010     L[1][0] = 0; L[1][1] = 2; N[1] = 2; tmpArr[1].dd = 4.0; tmpArr[1].i = 1; tmpArr[1].j = 2;
73011     L[2][0] = 0; L[2][1] = 1; N[2] = 2; tmpArr[2].dd = 5.0; tmpArr[2].i = 0; tmpArr[2].j = 2;
73012 
73013 }
73014 
TmpLig(INCRSTRU * ligtmp,int indx,int ind)73015 void TmpLig(INCRSTRU *ligtmp,int indx,int ind)
73016 {
73017    int j;
73018 
73019    ligtmp =  (INCRSTRU *) malloc(sizeof(INCRSTRU));
73020 
73021    memcpy(ligtmp, ligtyp[ind], sizeof(INCRSTRU));
73022 
73023    for (j=0; j<3; j++) {
73024 	ligtmp->c[0][j] = TriArr[indx]->coo[ligtmp->atom[0]*3+j];
73025    }
73026 
73027    cal_area(ligtmp);
73028 }
73029 
CalcAllInt(int deb,int all)73030 void CalcAllInt(int deb,int all)
73031 {
73032     int i,j,k,ido,grpj,grpk;
73033     float etot;
73034     INCRSTRU *ligtmp;
73035 
73036 // all = 1: calculate interaction of matching ligand points with protein
73037 //          interaction points
73038 //
73039 // all = 0: calculate interaction of matching ligand points with protein
73040 //          interaction points, but only those belonging to the fragment
73041 //          of the triangle in TriArr
73042 //
73043 // The latter is a score by fragment
73044 
73045     for (i=0; i < ntris; i++) {
73046 	if (TriArr[i] != NULL) {
73047 
73048 	   if (deb) fprintf(stderr,"TriArr[%3d]:\n\n",i);
73049 
73050 	   etot = 0.0;
73051 
73052 	   for (j=0; j < lintp; j++) {
73053 
73054 	      grpj = Find_Group(ligtyp[j]->type);
73055 	      grpj = Find_Matching_Group(grpj);
73056 
73057 	      ido = 0;
73058 
73059 	      if (!all) {
73060 		if (ligtyp[j]->conf != -1)  {
73061 
73062 		   if (TriArr[i]->frags[0] == ligtyp[j]->frag[0] ||
73063 		       TriArr[i]->frags[1] == ligtyp[j]->frag[0] ||
73064 		       TriArr[i]->frags[2] == ligtyp[j]->frag[0]) ido = 1;
73065 		} else {
73066 		   if (ligtyp[j]->nfrag == 1)
73067 			if (TriArr[i]->frag == ligtyp[j]->frag[0]) ido = 1;
73068 		}
73069 	      } else {
73070 		ido = 1;
73071 	      }
73072 
73073 	      if (ido) {
73074 		for (k=0; k < nintp; k++) {
73075 	         grpk = Find_Group(inttyp[k]->type);
73076 		 if (grpj == grpk) {
73077 
73078  			etot = etot +
73079 			CalInt(k,j,ligtyp[j]->points,TriArr[i]->t,
73080 				TriArr[i]->R1,TriArr[i]->R2,
73081 				TriArr[i]->OutO,TriArr[i]->OutOrg,deb);
73082 		 }
73083 		}
73084 	      }
73085 	   }
73086 	   TriArr[i]->e12 = etot;
73087 	   if (all) TriArr[i]->etot = TriArr[i]->e12 + TriArr[i]->eint;
73088 
73089 	   if (deb) fprintf(stderr,"etot = %f\n\ne12 %.3f eint %.3f\n",
73090 			etot,TriArr[i]->e12,TriArr[i]->eint);
73091 	}
73092     }
73093 }
73094 
73095 /* wrt_TriArr and rd_TriArr have not been tested,
73096    they probably need more work */
73097 
wrt_TriArr()73098 void wrt_TriArr()
73099 {
73100     int i,j;
73101     FILE *of;
73102 
73103     of = fopen("TriArr","w");
73104 
73105     fwrite(&ntris, (size_t) sizeof(int), (size_t) 1, of);
73106 
73107     for (i=0; i < ntris; i++) {
73108 	fwrite(TriArr[i], (size_t) sizeof(TRISTRU), (size_t) 1, of);
73109     }
73110 
73111     fwrite(&ndocka, (size_t) sizeof(int), (size_t) 1, of);
73112 
73113     for (i=0; i < ntris; i++) {
73114 	fwrite(TriArr[i]->coo, (size_t) sizeof(double)*ndocka*3, (size_t) 1, of);
73115     }
73116 
73117     fclose(of);
73118 }
73119 
rd_TriArr()73120 void rd_TriArr()
73121 {
73122     int i,j;
73123     FILE *of;
73124 
73125     of = fopen("TriArr","r");
73126 
73127     fread(&ntris, (size_t) sizeof(int), (size_t) 1, of);
73128 
73129     for (i=0; i < ntris; i++) {
73130 	TriArr[i] = (TRISTRU *) malloc(sizeof(TRISTRU));
73131 	fread(TriArr[i], (size_t) sizeof(TRISTRU), (size_t) 1, of);
73132     }
73133 
73134     fread(&ndocka, (size_t) sizeof(int), (size_t) 1, of);
73135 
73136     for (i=0; i < ntris; i++) {
73137 	TriArr[i]->coo = (double *) malloc(sizeof(double)*ndocka*3);
73138 	fread(TriArr[i]->coo, (size_t) sizeof(double)*ndocka*3, (size_t) 1, of);
73139     }
73140 
73141     fclose(of);
73142 }
73143 
wrt_tmpArr(tmpArr,K,L,N)73144 void wrt_tmpArr(tmpArr,K,L,N)
73145 LDAT *tmpArr;
73146 int K;
73147 int *L[MAXTRI];
73148 int N[MAXTRI];
73149 {
73150     int i,j;
73151     FILE *of;
73152     int LL[1000];
73153 
73154     of = fopen("tmparr","w");
73155 
73156 
73157     fwrite(&K, (size_t) sizeof(int), (size_t) 1, of);
73158 
73159     for (i=0; i < K; i++) {
73160 	fwrite(&tmpArr[i], (size_t) sizeof(LDAT), (size_t) 1, of);
73161     }
73162 
73163     for (i=0; i < K; i++) {
73164 	fwrite(&N[i], (size_t) sizeof(int), 1, of);
73165     }
73166 
73167     for (i=0; i < K; i++) {
73168 	for (j=0; j < N[i]; j++) {
73169 	   LL[j] = L[i][j];
73170 	}
73171 	fwrite(&LL, (size_t) sizeof(int), (size_t) N[i], of);
73172     }
73173 
73174     fclose(of);
73175 }
73176 
73177 #define MAXNNODE 10000
73178 
Linkage_List()73179 void Linkage_List()
73180 {
73181     int i,j,k,K,l,n,iN,nt,frst,inm;
73182     double dd,ddthresh,*DDc1,*DDc2;
73183     LDAT *tmpArr;
73184     LDAT info,info_tmp;
73185     NNODE *NewNodes[MAXNNODE];
73186     int tmpi[MAXTRI],N[MAXTRI],*L[MAXTRI];
73187     int NN1,NN2,NARR,BTEL,NDEL,MXARR;
73188     int *L1,*L2,NNewNodes;
73189     int C1,C2,Ci,Cj,Cnew,stat,istat,mx,inode,inode1,inode2,OldN;
73190     node *p,*delnode,**BARR,**DELARR;
73191 
73192     ddthresh = CLUSRMS/toangs;
73193     NNewNodes = 0;
73194 
73195     for (i=0; i < MAXNNODE; i++) {
73196 	NewNodes[i] = NULL;
73197     }
73198 
73199     K = 0;
73200     NDEL = 0;
73201 
73202     n = ntris;
73203 
73204     if (n == 1) return;
73205 
73206     nt = (n*(n+1))/2;
73207 
73208     tmpArr = (LDAT *) malloc(nt*sizeof(LDAT));
73209 
73210     for (i=0; i < nt; i++) {
73211 	tmpArr[i].stat = -1;
73212 	tmpArr[i].Arr = NULL;
73213 	tmpArr[i].N = 0;
73214     }
73215 
73216     k = -1;
73217     for (i=0; i < n; i++) {
73218 	inm = 0;
73219 	for (j=0; j < n; j++) {
73220 	   if (TriArr[i] != NULL && TriArr[j] != NULL) {
73221 	      dd = dst(TriArr[i],TriArr[j]);
73222 	      if (j > i) {
73223 		if (dd <= 0.000001) {
73224 	    	   if (TriArr[j]->coo != NULL) free(TriArr[j]->coo);
73225 	           free(TriArr[j]);
73226 	           TriArr[j] = (TRISTRU *) NULL;
73227 		   for (l=0; l < j; l++) {
73228 			if (N[l] > 0) {
73229 			   delC(L[l],&N[l],j);
73230 			   delC(tmpi,&inm,j);
73231 			}
73232 		   }
73233 		   for (l=0; l < k+1; l++)
73234 			if (tmpArr[l].i == j || tmpArr[l].j == j)
73235 			   tmpArr[l].dd = -1.0;
73236 		} else if (dd < ddthresh) {
73237 		   k++;
73238 		   if (nt > k) {
73239 			tmpArr[k].dd = dd;
73240 			tmpArr[k].i = i;
73241 			tmpArr[k].j = j;
73242 			tmpArr[k].stat = -1;
73243 		   } else {
73244 			fprintf(stderr,"k %d > nt %d\n",k,nt);
73245 		   }
73246 		   tmpi[inm] = j;
73247 		   inm++;
73248 		}
73249 	      } else if (j == i) {
73250 	      } else {
73251 		if (dd >  0.000001 && dd < ddthresh) {
73252 		   tmpi[inm] = j;
73253 		   inm++;
73254 		}
73255 	      }
73256 	   }
73257 	}
73258 
73259 	if (inm > 0) {
73260 	   N[i] = inm;
73261 	   qsort(tmpi, inm, sizeof(int), SI);
73262 	   L[i] = (int *) malloc((k+1)*sizeof(int));
73263 	   for (l=0; l < inm; l++)  L[i][l] = tmpi[l];
73264 	} else {
73265 	   N[i] = 0;
73266 	   L[i] = NULL;
73267 	}
73268     }
73269 
73270     K = k + 1;
73271 
73272 if (debugdck) fprintf(stderr,"0 K %d\n",K);
73273 
73274     for (i=0; i < k+1; i++)
73275 	while (tmpArr[i].dd == -1.0 && K > 0) delArr(tmpArr,&K,i);
73276 
73277 if (debugdck) fprintf(stderr,"aft delArr K %d\n",K);
73278 
73279     if (!K) return;
73280 
73281     if (0) wrt_tmpArr(tmpArr,K,L,N);
73282 
73283     if (0) Test_Linkage(N,L,&K,tmpArr);
73284 
73285     CalcAllInt(0,0);
73286 
73287     qsort((LDAT *) tmpArr, K, sizeof(LDAT), cmpldat);
73288 
73289 if (debugdck) fprintf(stderr,"K %d\n",K);
73290     MXARR = K + 1000;
73291 
73292     BARR = (node **) malloc(MXARR*sizeof(node *));
73293     DELARR = (node **) malloc(MXARR*sizeof(node *));
73294 
73295     frst = -1;
73296 
73297     for (i=0; i < K; i++) {
73298 	if ( frst == -1) {
73299 	   begin = addtoemptylist(begin,tmpArr[i]);
73300 	   frst = 0;
73301 	} else {
73302 	   begin = addatendlist(begin,tmpArr[i]);
73303 	}
73304     }
73305 
73306     set_List(begin,BARR,&NARR,MXARR);
73307     mx = max_List(begin);
73308 
73309     p = BARR[0]; BTEL = 0;
73310     Cnew = mx + 1;
73311 
73312     delnode = NULL;
73313 
73314     while (p != NULL) {
73315 
73316 	if (debugdck) dsply_List(begin);
73317 
73318 	C1 = p->info.i;
73319 	C2 = p->info.j;
73320 
73321 	if (debugdck) {
73322 fprintf(stderr,"Cluster candidate C1 %d C2 %d N[C1] %d N[C2] %d\n\n",C1,C2,N[C1],N[C2]);
73323 prL(L[C1],N[C1],C1);
73324 fprintf(stderr,"\n");
73325 prL(L[C2],N[C2],C2);
73326 fprintf(stderr,"\n");
73327 	}
73328 
73329 	delC(L[C1],&N[C1],C2);
73330 	delC(L[C2],&N[C2],C1);
73331 
73332 	stat = p->info.stat;
73333 	iN = p->info.N;
73334 
73335 	begin = deletenode(begin,delnode,&p->info,BARR,&NARR);
73336 	p = dlnode(p,&p->info);
73337 	Add2Delarr(delnode,DELARR,&NDEL,MXARR);
73338 
73339 	N[Cnew] = N[C1] + N[C2];
73340 	L[Cnew] = (int *) malloc(K*sizeof(int));
73341 	N[Cnew] = 0;
73342 
73343 	NN1 = N[C1];
73344 	NN2 = N[C2];
73345 	L1 = (int *) malloc(NN1*sizeof(int));
73346 	L2 = (int *) malloc(NN2*sizeof(int));
73347 	DDc1 = (double *) malloc(NN1*sizeof(double));
73348 	DDc2 = (double *) malloc(NN2*sizeof(double));
73349 
73350 	for (Ci=0; Ci < NN1; Ci++) L1[Ci] = L[C1][Ci];
73351 	for (Cj=0; Cj < NN2; Cj++) L2[Cj] = L[C2][Cj];
73352 
73353 	if (Get_NNode(NewNodes,&NNewNodes,Cnew,mx) == -1)
73354 		Cr_NNode(NewNodes,&NNewNodes,Cnew,C1,C2,mx);
73355 
73356 	if (stat == -1) {
73357 	   info.stat = 1;
73358 	   info.Arr = (int *) malloc(sizeof(int)*1000);
73359 	   info.Arr[0] = C1;
73360 	   info.Arr[1] = C2;
73361 	   info.N = 2;
73362 	} else {
73363 	   info.stat = stat + 1;
73364 	   info.N = 0;
73365 
73366 	   if (C1 > mx) {
73367 		inode1 = Get_NNode(NewNodes,&NNewNodes,C1,mx);
73368 		if (inode1 != -1) {
73369 	   	    for (i=0; i < NewNodes[inode1]->N; i++) {
73370 			if (!Chk_NNode(info.Arr,info.N,
73371 				NewNodes[inode1]->Arr[i])) {
73372 			   info.Arr[info.N] = NewNodes[inode1]->Arr[i];
73373 			   info.N++;
73374 			}
73375 		    }
73376 		}
73377 	   } else {
73378 		info.Arr[info.N] = C1;
73379 		info.N++;
73380 	   }
73381 
73382   	   if (C2 > mx) {
73383 		inode2 = Get_NNode(NewNodes,&NNewNodes,C2,mx);
73384 		if (inode2 != -1) {
73385 	   	   for (i=0; i < NewNodes[inode2]->N; i++) {
73386 			if (!Chk_NNode(info.Arr,info.N,
73387 				NewNodes[inode2]->Arr[i])) {
73388 			   info.Arr[info.N] = NewNodes[inode2]->Arr[i];
73389 			   info.N++;
73390 			}
73391 		   }
73392 		}
73393 	   } else {
73394 		info.Arr[info.N] = C2;
73395 		info.N++;
73396 	   }
73397 	}
73398 
73399 	set_List(begin,BARR,&NARR,MXARR);
73400 	if (N[C1] == 0 && N[C2] == 0) NewNodes[NNewNodes-1]->CC = 1;
73401 
73402 	if (0) Prt_NNode(NewNodes,&NNewNodes);
73403 
73404 	if (NARR == 0) goto NEXT;
73405 
73406 	OldN = info.N;
73407 
73408 	while (N[C1] != 0 || N[C2] != 0) {
73409 
73410 	   for (Ci=0; Ci < NN1; Ci++) {
73411 
73412 	      if (L1[Ci] < C1) {
73413 		      info.i = L1[Ci]; info.j = C1;
73414 	      } else {
73415 		      info.i = C1; info.j = L1[Ci];
73416 	      }
73417 	      info_tmp = get_info(begin,info);
73418 	      DDc1[Ci] = info_tmp.dd;
73419 
73420 
73421 	      if (!Chk_NNode(L2,NN2,L1[Ci])) {
73422 
73423 		   if (L1[Ci] < C1) {
73424 		      info.i = L1[Ci]; info.j = C1;
73425 		   } else {
73426 		      info.i = C1; info.j = L1[Ci];
73427 		   }
73428 		   info_tmp = get_info(begin,info);
73429 
73430 		   if (! (info_tmp.i == -1 && info_tmp.j == -1) ) {
73431 
73432 		      info.i = L1[Ci]; info.j = Cnew;
73433 		      info.dd = DDc1[Ci];
73434 		      info.N = OldN;
73435 
73436 		      if (info.i > mx) {
73437 			inode = Get_NNode(NewNodes,&NNewNodes,info.i,mx);
73438 			if (inode != -1) {
73439 	   		   for (i=0; i < NewNodes[inode]->N; i++) {
73440 				info.Arr[info.N] = NewNodes[inode]->Arr[i];
73441 				info.N++;
73442 			   }
73443 			}
73444 		      }
73445 
73446 		      begin = insertdd(begin,BARR,&NARR,info);
73447 		      set_List(begin,BARR,&NARR,MXARR);
73448 		      info.N = OldN;
73449 
73450 		      L[L1[Ci]][N[L1[Ci]]] = Cnew;
73451 		      N[L1[Ci]]++;
73452 
73453 		      L[Cnew][N[Cnew]] = L1[Ci]; N[Cnew]++;
73454 
73455 		      delC(L[C1],&N[C1],L1[Ci]);
73456 
73457 		      delC(L[Ci],&N[Ci],C1);
73458 		      delC(L[Ci],&N[Ci],C2);
73459 		   }
73460 	      }
73461 
73462 	      if (L1[Ci] < C1) {
73463 		      info.i = L1[Ci]; info.j = C1;
73464 	      } else {
73465 		      info.i = C1; info.j = L1[Ci];
73466 	      }
73467 	      begin = deletenode(begin,delnode,&info,BARR,&NARR);
73468 	      Add2Delarr(delnode,DELARR,&NDEL,MXARR);
73469 
73470 	   }
73471 
73472 	   for (Cj=0; Cj < NN2; Cj++) {
73473 
73474 		if (L2[Cj] < C2) {
73475 		      info.i = L2[Cj]; info.j = C2;
73476 		} else {
73477 		      info.i = C2; info.j = L2[Cj];
73478 		}
73479 	        info_tmp = get_info(begin,info);
73480 	        DDc2[Cj] = info_tmp.dd;
73481 
73482 		if (!Chk_NNode(L1,NN1,L2[Cj])) {
73483 
73484 		   if (L2[Cj] < C2) {
73485 		      info.i = L2[Cj]; info.j = C2;
73486 		   } else {
73487 		      info.i = C2;     info.j = L2[Cj];
73488 		   }
73489 		   info_tmp = get_info(begin,info);
73490 
73491 		   if (! (info_tmp.i == -1 && info_tmp.j == -1)) {
73492 
73493 		      info.i = L2[Cj]; info.j = Cnew;
73494 		      info.dd = DDc2[Cj];
73495 		      info.N = OldN;
73496 
73497 		      if (info.i > mx) {
73498 			inode = Get_NNode(NewNodes,&NNewNodes,info.i,mx);
73499 			if (inode != -1) {
73500 	   		   for (i=0; i < NewNodes[inode]->N; i++) {
73501 				info.Arr[info.N] = NewNodes[inode]->Arr[i];
73502 				info.N++;
73503 			   }
73504 			}
73505 		      }
73506 
73507 		      begin = insertdd(begin,BARR,&NARR,info);
73508 		      set_List(begin,BARR,&NARR,MXARR);
73509 		      info.N = OldN;
73510 
73511 		      L[L2[Cj]][N[L2[Cj]]] = Cnew;
73512 		      N[L2[Cj]]++;
73513 
73514 		      L[Cnew][N[Cnew]] = L2[Cj]; N[Cnew]++;
73515 
73516 		      delC(L[C2],&N[C2],L2[Cj]);
73517 
73518 		      delC(L[Cj],&N[Cj],C1);
73519 		      delC(L[Cj],&N[Cj],C2);
73520 		   }
73521 		}
73522 
73523 		if (L2[Cj] < C2) {
73524 		      info.i = L2[Cj]; info.j = C2;
73525 		} else {
73526 		      info.i = C2; info.j = L2[Cj];
73527 		}
73528 		begin = deletenode(begin,delnode,&info,BARR,&NARR);
73529 	        Add2Delarr(delnode,DELARR,&NDEL,MXARR);
73530 
73531 	   }
73532 
73533 	   for (Ci=0; Ci < NN1; Ci++) {
73534 	      delC(L[Ci],&N[Ci],C1);
73535 	      for (Cj=0; Cj < NN2; Cj++) {
73536 
73537 		delC(L[Cj],&N[Cj],C2);
73538 
73539 		if (L1[Ci] < L2[Cj]) {
73540 
73541 		   delC(L[C1],&N[C1],L1[Ci]);
73542 
73543 		} else if (L1[Ci] > L2[Cj]) {
73544 
73545 		   delC(L[C2],&N[C2],L2[Cj]);
73546 
73547 		} else if (L1[Ci] == L2[Cj]) {
73548 
73549 
73550 		   if (L1[Ci] < C1) {
73551 		      info.i = L1[Ci]; info.j = C1;
73552 		   } else {
73553 		      info.i = C1; info.j = L1[Ci];
73554 		   }
73555 		   begin = deletenode(begin,delnode,&info,BARR,&NARR);
73556 	           Add2Delarr(delnode,DELARR,&NDEL,MXARR);
73557 
73558 		   if (L1[Ci] < C2) {
73559 		      info.i = L1[Ci]; info.j = C2;
73560 		   } else {
73561 		      info.i = C2; info.j = L1[Ci];
73562 		   }
73563 		   begin = deletenode(begin,delnode,&info,BARR,&NARR);
73564 	           Add2Delarr(delnode,DELARR,&NDEL,MXARR);
73565 
73566 		   info.i = L1[Ci]; info.j = Cnew;
73567 		   info.dd = MAXI(DDc1[Ci],DDc2[Cj]);
73568 
73569 		   info.N = OldN;
73570 
73571 		   if (info.i > mx) {
73572 			inode = Get_NNode(NewNodes,&NNewNodes,info.i,mx);
73573 			if (inode != -1) {
73574 	   		   for (i=0; i < NewNodes[inode]->N; i++) {
73575 				info.Arr[info.N] = NewNodes[inode]->Arr[i];
73576 				info.N++;
73577 			   }
73578 			}
73579 		   }
73580 
73581 
73582 		   begin = insertdd(begin,BARR,&NARR,info);
73583 		   info.N = OldN;
73584 		   set_List(begin,BARR,&NARR,MXARR);
73585 
73586 		   L[L1[Ci]][N[L1[Ci]]] = Cnew;
73587 		   N[L1[Ci]]++;
73588 
73589 		   L[Cnew][N[Cnew]] = L1[Ci]; N[Cnew]++;
73590 
73591 		   delC(L[C1],&N[C1],L1[Ci]);
73592 		   delC(L[C2],&N[C2],L2[Cj]);
73593 
73594 		   delC(L[Ci],&N[Ci],C1);
73595 		   delC(L[Cj],&N[Cj],C2);
73596 
73597 		}
73598 	      }
73599 
73600 	   }
73601 	}
73602 
73603 	for (i=0; i < Cnew; i++) {
73604 	   repC(L[i],&N[i],C1,Cnew);
73605 	   repC(L[i],&N[i],C2,Cnew);
73606 	   redC(L[i],&N[i],Cnew);
73607 	}
73608 
73609 	for (j=0; j < Cnew+1; j++) {
73610 	   for (i=0; i < Cnew; i++) {
73611 		redC(L[i],&N[i],j);
73612 	   }
73613 	}
73614 
73615 	replc_List(begin,C1,Cnew);
73616 	replc_List(begin,C2,Cnew);
73617 	replc_List(p,C1,Cnew);
73618 	replc_List(p,C2,Cnew);
73619 
73620 	Cnew++; BTEL++;
73621 	if (BTEL >= NARR) {
73622 	   if (NARR == 0) goto NEXT;
73623 	   BTEL = 0;
73624 	}
73625 	p = BARR[BTEL];
73626 	free(L1);
73627 	free(L2);
73628 	L1 = NULL;
73629 	L2 = NULL;
73630     }
73631 
73632 NEXT:
73633     Clus_Min_NNode(NewNodes,&NNewNodes);
73634 
73635     return;
73636 
73637 }
73638 
rndf(float num)73639 static float rndf(float num)
73640 {
73641     float integer = ceilf(num);
73642     if (num > 0)
73643         return integer - num > 0.5f ? integer - 1.0f : integer;
73644     return integer - num >= 0.5f ? integer - 1.0f : integer;
73645 }
73646 
issCOO(iat,io1,io2)73647 int issCOO(iat,io1,io2)
73648 int iat;
73649 int *io1;
73650 int *io2;
73651 {
73652     int xc,io,ic,ih,k,l,la;
73653 
73654     xc = xyzp->iconn[iat*(MXCON+1)];
73655     if (xyzp->ianz[iat] != 6) return 0;
73656 
73657     *io1 = -1;
73658     *io2 = -1;
73659     io = 0;
73660     ic = 0;
73661     ih = 0;
73662 
73663     for (k=0; k < xc; k++) {
73664 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73665 	la = abs(l);
73666 	if (la > 0) {
73667 	   if (xyzp->ianz[la-1] == 8)  {
73668 		io++;
73669 		if (io == 1) *io1 = la-1;
73670 		if (io == 2) *io2 = la-1;
73671 	   }
73672 	   if (xyzp->ianz[la-1] == 6) ic++;
73673 	   if (xyzp->ianz[la-1] == 1) ih++;
73674 	}
73675     }
73676 
73677     if (io == 2 && ic == 1 && ih == 0) return 1;
73678     return 0;
73679 }
73680 
isAZIDE(iat)73681 int isAZIDE(iat)
73682 int iat;
73683 {
73684     int xc,io,ic,ih,k,l,la,n;
73685 
73686     xc = xyzp->iconn[iat*(MXCON+1)];
73687     if (!(xyzp->ianz[iat] == 7 && isANY(xyzp->ityp[iat],N2ar,2))) return 0;
73688 
73689     n = 0;
73690 
73691     for (k=0; k < xc; k++) {
73692 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73693 	la = abs(l);
73694 	if (la > 0) {
73695 	   if (xyzp->ianz[la-1] == 7 &&
73696 		isANY(xyzp->ityp[la-1],Nany,7)) {
73697 		n++;
73698 	   }
73699 	}
73700     }
73701     if (n == 2) return 1;
73702     return 0;
73703 }
73704 
isNaryl(iat,io1,io2)73705 int isNaryl(iat,io1,io2)
73706 int iat;
73707 int *io1;
73708 int *io2;
73709 {
73710     int xc,io,ic,ih,k,l,la,n;
73711 
73712     xc = xyzp->iconn[iat*(MXCON+1)];
73713     if (!(xyzp->ianz[iat] == 7 && isANY(xyzp->ityp[iat],N2ar,2) && xc == 2)) return 0;
73714 
73715     n = 0;
73716     *io1 = -1;
73717     *io2 = -1;
73718 
73719     for (k=0; k < xc; k++) {
73720 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73721 	la = abs(l);
73722 	if (la > 0) {
73723 	   if (isANY(xyzp->ianz[la-1],GrpR,6)) {
73724 		n++;
73725 		if (n == 1) *io1 = la - 1;
73726 		if (n == 2) *io2 = la - 1;
73727 	   }
73728 	}
73729     }
73730     if (n == 2) return 1;
73731     return 0;
73732 }
73733 
isNamino(iat,io1,io2,io3)73734 int isNamino(iat,io1,io2,io3)
73735 int iat;
73736 int *io1;
73737 int *io2;
73738 int *io3;
73739 {
73740     int xc,io,ic,ih,k,l,la,n;
73741 
73742     xc = xyzp->iconn[iat*(MXCON+1)];
73743     if (!(xyzp->ianz[iat] == 7 && xyzp->ityp[iat] == 10 && xc == 3)) return 0;
73744 
73745     n = 0;
73746     *io1 = -1;
73747     *io2 = -1;
73748     *io3 = -1;
73749 
73750     for (k=0; k < xc; k++) {
73751 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73752 	la = abs(l);
73753 	if (la > 0) {
73754 	   if (isANY(xyzp->ianz[la-1],GrpRH,7)) {
73755 		n++;
73756 		if (n == 1) *io1 = la - 1;
73757 		if (n == 2) *io2 = la - 1;
73758 		if (n == 3) *io3 = la - 1;
73759 	   }
73760 	}
73761     }
73762     if (n == 3) return 1;
73763     return 0;
73764 }
73765 
isOH(iat,io1)73766 int isOH(iat,io1)
73767 int iat;
73768 int *io1;
73769 {
73770     int xc,io,ic,ih,k,l,la,n;
73771 
73772     xc = xyzp->iconn[iat*(MXCON+1)];
73773     if (!(xyzp->ianz[iat] == 8 && isANY(xyzp->ityp[iat],Oany,3) && xc == 2))
73774 		return 0;
73775 
73776     n = 0;
73777     *io1 = -1;
73778 
73779     for (k=0; k < xc; k++) {
73780 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73781 	la = abs(l);
73782 	if (la > 0) {
73783 	   if (xyzp->ianz[la-1] == 1) {
73784 		n++;
73785 		*io1 = la - 1;
73786 	   } else {
73787 		if (isANY(xyzp->ianz[la-1],GrpRH,7)) n++;
73788 	   }
73789 	}
73790     }
73791     if (n == 2) return 1;
73792     return 0;
73793 }
73794 
isNT(iat,io1)73795 int isNT(iat,io1)
73796 int iat;
73797 int *io1;
73798 {
73799     int xc,io,ic,ih,k,l,la,n;
73800 
73801     xc = xyzp->iconn[iat*(MXCON+1)];
73802     if (!(xyzp->ianz[iat] == 7 && isANY(xyzp->ityp[iat],Nany,7) && xc == 1)) return 0;
73803 
73804     n = 0;
73805     *io1 = -1;
73806 
73807     for (k=0; k < xc; k++) {
73808 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73809 	la = abs(l);
73810 	if (la > 0) {
73811 	   if (isANY(xyzp->ianz[la-1],GrpRH,7)) {
73812 		n++;
73813 		if (n == 1) *io1 = la - 1;
73814 	   }
73815 	}
73816     }
73817     if (n == 1) return 1;
73818     return 0;
73819 }
73820 
isSNH(iat,io1,io2)73821 int isSNH(iat,io1,io2)
73822 int iat;
73823 int *io1;
73824 int *io2;
73825 {
73826     int xc,io,ic,ih,k,l,la,n;
73827 
73828     xc = xyzp->iconn[iat*(MXCON+1)];
73829     if (!(xyzp->ianz[iat] == 7 && isANY(xyzp->ityp[iat],Nany,7) && xc == 2)) return 0;
73830 
73831     n = 0;
73832     ih = 0;
73833     *io1 = -1;
73834     *io2 = -1;
73835 
73836     for (k=0; k < xc; k++) {
73837 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73838 	la = abs(l);
73839 	if (la > 0) {
73840 	   if (isANY(xyzp->ityp[la-1],Sany,4)) {
73841 		n++;
73842 		if (n == 1) *io1 = la - 1;
73843 	   }
73844 	   if (xyzp->ianz[la-1] == 1) {
73845 		ih++;
73846 		if (ih == 1) *io2 = la - 1;
73847 	   }
73848 	}
73849     }
73850     if (n == 1 && ih == 1) return 1;
73851     return 0;
73852 }
73853 
isAMID(iat,np,io2)73854 int isAMID(iat,np,io2)
73855 int iat;
73856 int *np;
73857 int *io2;
73858 {
73859     int xc,xn,i,k,l,la,ll,lla,no,nn,nh;
73860 
73861     xc = xyzp->iconn[iat*(MXCON+1)];
73862     if (!(xyzp->ianz[iat] == 6 && xyzp->ityp[iat] == 6 && xc == 3)) return 0;
73863 
73864     no = 0; nn = 0; nh = 0;
73865     *np = -1;
73866     *io2 = -1;
73867 
73868     for (k=0; k < xc; k++) {
73869 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73870 	la = abs(l);
73871 	if (la > 0) {
73872 	   if (xyzp->ianz[la-1] == 8 && xyzp->ityp[la-1] == 18) {
73873 		no++;
73874 		if (no == 1) *io2 = la - 1;
73875 	   }
73876 	   if (xyzp->ianz[la-1] == 7 &&
73877 		(xyzp->ityp[la-1] == 14 || xyzp->ityp[la-1] == 15)) {
73878 		nn++;
73879 		if (nn == 1) *np = la - 1;
73880 		xn = xyzp->iconn[(la-1)*(MXCON+1)];
73881 		for (i=0; i < xn; i++) {
73882 		   ll = xyzp->iconn[(la-1)*(MXCON+1)+i+1];
73883 		   lla = abs(ll);
73884 		   if (lla > 0) {
73885 	   		if (xyzp->ianz[lla-1] == 1) nh++;
73886 		   }
73887 		}
73888 	   }
73889 	}
73890     }
73891     if (no == 1 && nn == 1 && nh >= 1) return 1;
73892     return 0;
73893 }
73894 
isRF(iat,io1)73895 int isRF(iat,io1)
73896 int iat;
73897 int *io1;
73898 {
73899     int xc,k,l,la,n;
73900 
73901     xc = xyzp->iconn[iat*(MXCON+1)];
73902     if (!(xyzp->ianz[iat] == 9 && xc == 1)) return 0;
73903 
73904     n = 0;
73905     *io1 = -1;
73906 
73907     for (k=0; k < xc; k++) {
73908 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73909 	la = abs(l);
73910 	if (la > 0) {
73911 	   if (isANY(xyzp->ianz[la-1],GrpR,6)) {
73912 		n++;
73913 		if (n == 1) *io1 = la - 1;
73914 	   }
73915 	}
73916     }
73917     if (n == 1) return 1;
73918     return 0;
73919 }
73920 
isCO(iat,io1)73921 int isCO(iat,io1)
73922 int iat;
73923 int *io1;
73924 {
73925     int xc,io,ic,ih,k,l,la;
73926 
73927     xc = xyzp->iconn[iat*(MXCON+1)];
73928     if (!(xyzp->ianz[iat] == 6 && isANY(xyzp->ityp[iat],C2ar,2))) return 0;
73929 
73930     *io1 = -1;
73931     io = 0;
73932 
73933     for (k=0; k < xc; k++) {
73934 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73935 	la = abs(l);
73936 	if (la > 0) {
73937 	   if (xyzp->ianz[la-1] == 8 &&
73938 		xyzp->iconn[(la-1)*(MXCON+1)] == 1) {
73939 		if (xyzp->ityp[la-1] == 18)  {
73940 		   io++;
73941 		   if (io == 1) *io1 = la-1;
73942 		}
73943 	   }
73944 	}
73945     }
73946 
73947     if (io == 1) return 1;
73948     return 0;
73949 }
73950 
isCOmin(iat,io1)73951 int isCOmin(iat,io1)
73952 int iat;
73953 int *io1;
73954 {
73955     int xc,io,ic,ih,k,l,la;
73956 
73957     xc = xyzp->iconn[iat*(MXCON+1)];
73958     if (!(xyzp->ianz[iat] == 6 && isANY(xyzp->ityp[iat],Cany,4))) return 0;
73959 
73960     *io1 = -1;
73961     io = 0;
73962 
73963     for (k=0; k < xc; k++) {
73964 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73965 	la = abs(l);
73966 	if (la > 0) {
73967 	   if (xyzp->ianz[la-1] == 8 &&
73968 		xyzp->iconn[(la-1)*(MXCON+1)] == 1) {
73969 		if (xyzp->ityp[la-1] == 17)  {
73970 		   io++;
73971 		   if (io == 1) *io1 = la-1;
73972 		}
73973 	   }
73974 	}
73975     }
73976 
73977     if (io == 1) return 1;
73978     return 0;
73979 }
73980 
isSO(iat,io1,io2)73981 int isSO(iat,io1,io2)
73982 int iat;
73983 int *io1;
73984 int *io2;
73985 {
73986     int xc,io,ic,ih,k,l,la;
73987 
73988     xc = xyzp->iconn[iat*(MXCON+1)];
73989 
73990     if (xyzp->ianz[iat] != 16 || isANY(xyzp->ityp[iat],Sany,4)) return 0;
73991 
73992     *io1 = -1;
73993     *io2 = -1;
73994     io = 0;
73995 
73996     for (k=0; k < xc; k++) {
73997 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
73998 	la = abs(l);
73999 	if (la > 0) {
74000 	   if (xyzp->ianz[la-1] == 8 && xyzp->iconn[(la-1)*(MXCON+1)] == 1)  {
74001 		if (isANY(xyzp->ityp[la-1],Oany,3)) {
74002 		io++;
74003 		if (io == 1) *io1 = la-1;
74004 		if (io == 2) *io2 = la-1;
74005 		}
74006 	   }
74007 	}
74008     }
74009 
74010     if (io == 1 || io == 2) return 1;
74011     return 0;
74012 }
74013 
isCH3R(iat)74014 int isCH3R(iat)
74015 int iat;
74016 {
74017     int xc,i,ir,ih,k,l,la;
74018 
74019     if (xyzp->ianz[iat] != 6 || xyzp->ityp[iat] != 5) return 0;
74020 
74021     xc = xyzp->iconn[iat*(MXCON+1)];
74022 
74023     ih = 0;
74024     ir = 0;
74025 
74026     for (k=0; k < xc; k++) {
74027 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74028 	la = abs(l);
74029 	if (la > 0) {
74030 	   if (xyzp->ianz[la-1] == 1) ih++;
74031 	   if (isANY(xyzp->ianz[la-1],GrpR,6)) ir++;
74032 	}
74033     }
74034 
74035     if (ih == 3 && ir == 1) return 1;
74036     if (ih == 2 && ir == 2) return 2;
74037     if (ih == 1 && ir == 3) return 3;
74038     return 0;
74039 }
74040 
isS3(iat)74041 int isS3(iat)
74042 int iat;
74043 {
74044 
74045     if (xyzp->ianz[iat] == 16 && xyzp->ityp[iat] == 22) return 1;
74046 
74047     return 0;
74048 }
74049 
isCarR(iat)74050 int isCarR(iat)
74051 int iat;
74052 {
74053     int xc,i,ir,ih,k,l,la;
74054 
74055     if (xyzp->ianz[iat] != 6 || xyzp->ityp[iat] != 8) return 0;
74056 
74057     xc = xyzp->iconn[iat*(MXCON+1)];
74058 
74059     ih = 0;
74060     ir = 0;
74061 
74062     for (k=0; k < xc; k++) {
74063 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74064 	la = abs(l);
74065 	if (la > 0) {
74066 	   if (xyzp->ianz[la-1] == 1) ih++;
74067 	   if (isANY(xyzp->ianz[la-1],GrpR,6)) ir++;
74068 	}
74069     }
74070 
74071     if (ih == 0 && ir == 3) return 1;
74072     if (ih == 1 && ir == 2) return 2;
74073     return 0;
74074 }
74075 
isPO(iat,io1,io2,io3)74076 int isPO(iat,io1,io2,io3)
74077 int iat;
74078 int *io1;
74079 int *io2;
74080 int *io3;
74081 {
74082     int xc,io,ic,ih,k,l,la;
74083 
74084     xc = xyzp->iconn[iat*(MXCON+1)];
74085 
74086     if (xyzp->ianz[iat] != 15 || xyzp->ityp[iat] != 26) return 0;
74087 
74088     *io1 = -1;
74089     *io2 = -1;
74090     *io3 = -1;
74091     io = 0;
74092 
74093     for (k=0; k < xc; k++) {
74094 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74095 	la = abs(l);
74096 	if (la > 0) {
74097 	   if (xyzp->ianz[la-1] == 8 && xyzp->iconn[(la-1)*(MXCON+1)] == 1)  {
74098 		if (isANY(xyzp->ityp[la-1],Oany,3)) {
74099 		io++;
74100 		if (io == 1) *io1 = la-1;
74101 		if (io == 2) *io2 = la-1;
74102 		if (io == 3) *io3 = la-1;
74103 		}
74104 	   }
74105 	}
74106     }
74107 
74108     if (io >1 && io <= 3) return 1;
74109     return 0;
74110 }
74111 
isNO2(iat,io1,io2)74112 int isNO2(iat,io1,io2)
74113 int iat;
74114 int *io1;
74115 int *io2;
74116 {
74117     int xc,io,ic,ih,k,l,la;
74118 
74119     xc = xyzp->iconn[iat*(MXCON+1)];
74120 
74121     if (xyzp->ianz[iat] != 7 || !isANY(xyzp->ityp[iat],N2ar,2)) return 0;
74122 
74123     *io1 = -1;
74124     *io2 = -1;
74125     io = 0;
74126 
74127     for (k=0; k < xc; k++) {
74128 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74129 	la = abs(l);
74130 	if (la > 0) {
74131 	   if (xyzp->ianz[la-1] == 8 && xyzp->iconn[(la-1)*(MXCON+1)] == 1)  {
74132 		if (xyzp->ityp[la-1] == 18) {
74133 		io++;
74134 		if (io == 1) *io1 = la-1;
74135 		if (io == 2) *io2 = la-1;
74136 		}
74137 	   }
74138 	}
74139     }
74140 
74141     if (io == 2) return 1;
74142     return 0;
74143 }
74144 
isNO(iat,io1)74145 int isNO(iat,io1)
74146 int iat;
74147 int *io1;
74148 {
74149     int xc,io,ic,ih,k,l,la;
74150 
74151     xc = xyzp->iconn[iat*(MXCON+1)];
74152 
74153     if (xyzp->ianz[iat] != 7 || !isANY(xyzp->ityp[iat],Nany,7)) return 0;
74154 
74155     *io1 = -1;
74156     io = 0;
74157 
74158     for (k=0; k < xc; k++) {
74159 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74160 	la = abs(l);
74161 	if (la > 0) {
74162 	   if (xyzp->ianz[la-1] == 8 && xyzp->iconn[(la-1)*(MXCON+1)] == 1)  {
74163 		if (isANY(xyzp->ityp[la-1],Oany,3)) {
74164 		io++;
74165 		if (io == 1) *io1 = la-1;
74166 		}
74167 	   }
74168 	}
74169     }
74170 
74171     if (io == 1) return 1;
74172     return 0;
74173 }
74174 
isCOH(iat,ic,ih,it)74175 int isCOH(iat,ic,ih,it)
74176 int iat;
74177 int *ic;
74178 int *ih;
74179 int *it;
74180 {
74181     int xc,icc,ihh,k,l,la;
74182 
74183     xc = xyzp->iconn[iat*(MXCON+1)];
74184 
74185     if (xyzp->ianz[iat] != 8 || xyzp->ityp[iat] != 17) return 0;
74186 
74187     *ic = -1;
74188     *ih = -1;
74189     icc = 0;
74190     ihh = 0;
74191 
74192     for (k=0; k < xc; k++) {
74193 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74194 	la = abs(l);
74195 	if (l > 0) {
74196 	   *it = xyzp->ityp[la-1];
74197 // 5 = C.3 6 = C.2 8 = C.ar
74198 	   if (xyzp->ianz[la-1] == 6 && (*it == 5 || *it == 6 || *it == 8))  {
74199 		icc++;
74200 		if (icc == 1) *ic = la-1;
74201 	   }
74202 	   if (xyzp->ianz[la-1] == 1)  {
74203 		ihh++;
74204 		if (ihh == 1) *ih = la-1;
74205 	   }
74206 	}
74207     }
74208 
74209     if (icc == 1 && ihh == 1) return 1;
74210     return 0;
74211 }
74212 
isC3OH(iat,ic,ih)74213 int isC3OH(iat,ic,ih)
74214 int iat;
74215 int *ic;
74216 int *ih;
74217 {
74218     int xc,icc,ihh,k,l,la;
74219 
74220     xc = xyzp->iconn[iat*(MXCON+1)];
74221 
74222     if (xyzp->ianz[iat] != 8 || xyzp->ityp[iat] != 17) return 0;
74223 
74224     *ic = -1;
74225     *ih = -1;
74226     icc = 0;
74227     ihh = 0;
74228 
74229     for (k=0; k < xc; k++) {
74230 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74231 	la = abs(l);
74232 	if (la > 0) {
74233 	   if (xyzp->ianz[la-1] == 6 && xyzp->ityp[la-1] == 5)  {
74234 		icc++;
74235 		if (icc == 1) *ic = la-1;
74236 	   }
74237 	   if (xyzp->ianz[la-1] == 1)  {
74238 		ihh++;
74239 		if (ihh == 1) *ih = la-1;
74240 	   }
74241 	}
74242     }
74243 
74244     if (icc == 1 && ihh == 1) return 1;
74245     return 0;
74246 }
74247 
isC2OH(iat,ic,ih)74248 int isC2OH(iat,ic,ih)
74249 int iat;
74250 int *ic;
74251 int *ih;
74252 {
74253     int xc,icc,ihh,k,l,la;
74254 
74255     xc = xyzp->iconn[iat*(MXCON+1)];
74256 
74257     if (xyzp->ianz[iat] != 8 || xyzp->ityp[iat] != 17) return 0;
74258 
74259     *ic = -1;
74260     *ih = -1;
74261     icc = 0;
74262     ihh = 0;
74263 
74264     for (k=0; k < xc; k++) {
74265 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74266 	la = abs(l);
74267 	if (la > 0) {
74268 	   if (xyzp->ianz[la-1] == 6 &&
74269 		(xyzp->ityp[la-1] == 6 || xyzp->ityp[la-1] == 8))  {
74270 		icc++;
74271 		if (icc == 1) *ic = la-1;
74272 	   }
74273 	   if (xyzp->ianz[la-1] == 1)  {
74274 		ihh++;
74275 		if (ihh == 1) *ih = la-1;
74276 	   }
74277 	}
74278     }
74279 
74280     if (icc == 1 && ihh == 1) return 1;
74281     return 0;
74282 }
74283 
isCOC(iat,ic1,ic2)74284 int isCOC(iat,ic1,ic2)
74285 int iat;
74286 int *ic1;
74287 int *ic2;
74288 {
74289     int xc,icc,ihh,k,l,la;
74290 
74291     xc = xyzp->iconn[iat*(MXCON+1)];
74292 
74293     if (xyzp->ianz[iat] != 8 || xyzp->ityp[iat] != 17) return 0;
74294 
74295     *ic1 = -1;
74296     *ic2 = -1;
74297     icc = 0;
74298 
74299     for (k=0; k < xc; k++) {
74300 	l = xyzp->iconn[iat*(MXCON+1)+k+1];
74301 	la = abs(l);
74302 	if (la > 0) {
74303 	   if (isANY(xyzp->ianz[la-1],GrpR,6)) {
74304 		icc++;
74305 		if (icc == 1) *ic1 = la-1;
74306 		if (icc == 2) *ic2 = la-1;
74307 	   }
74308 	}
74309     }
74310 
74311     if (icc == 2) return 1;
74312     return 0;
74313 }
74314 
isC3RNG(C,iring,oring,n)74315 void isC3RNG(C,iring,oring,n)
74316 COOSTRU *C;
74317 int iring[6];
74318 int oring[6];
74319 int n;
74320 {
74321    int i,j,k;
74322 
74323    for (i=0; i < n; i++) {
74324 	oring[i] = 0;
74325 	if (isANY(C->ityp[iring[i]],C2ar,2)) {
74326 	   for (j=0; j < C->iconn[(iring[i])*(MXCON+1)]; j++) {
74327 	      k = C->iconn[(iring[i])*(MXCON+1)+1+j]-1;
74328 	      if (C->ianz[k] == 1) oring[i] = 1;
74329 	   }
74330 	}
74331    }
74332 }
74333 
ReORNG(C,iring,n)74334 void ReORNG(C,iring,n)
74335 COOSTRU *C;
74336 int iring[6];
74337 int n;
74338 {
74339    int i,ii,j,k,jring[6];
74340 
74341    for (i=0; i < n; i++) {
74342 	if (C->lwrit[iring[i]] == 0) {
74343 	   k = i;
74344 	   break;
74345 	}
74346    }
74347 
74348 
74349    j = 0;
74350    for (i=k; i < k+n; i++) {
74351 	ii = i;
74352 	if (i > n-1) ii =  i - n;
74353 	jring[j] = iring[ii];
74354 	j++;
74355    }
74356    for (i=0; i < n; i++) iring[i] = jring[i];
74357 }
74358 
isDON(typ)74359 int isDON(typ)
74360 short int typ;
74361 {
74362    int i,ret;
74363 
74364    ret = 0;
74365 
74366    for (i=0; i < 9; i++) if (typ == DONG[i]) ret = 1;
74367 
74368    return(ret);
74369 }
74370 
isANY(ele,arr,n)74371 int isANY(ele,arr,n)
74372 short int ele;
74373 short int *arr;
74374 int n;
74375 
74376 {
74377    int i,ret;
74378 
74379    ret = 0;
74380 
74381    for (i=0; i < n; i++) if (ele == arr[i]) ret = 1;
74382 
74383    return(ret);
74384 }
74385 
RNGmin1(iring,n)74386 void RNGmin1(iring,n)
74387 int iring[6];
74388 int n;
74389 {
74390    int i;
74391 
74392    for (i=0; i < n; i++) {
74393 	iring[i] = iring[i] - 1;
74394    }
74395 }
74396 
RNGput(iring,n,ival)74397 void RNGput(iring,n,ival)
74398 int iring[6];
74399 int n;
74400 int ival;
74401 {
74402    int i;
74403 
74404    for (i=0; i < n; i++) {
74405 	if (singleb.jrng[iring[i]] == 0) {
74406 	   singleb.jrng[iring[i]] = ival;
74407 	}
74408    }
74409 }
74410 
Has_Con(C,ele,ian,iele)74411 int Has_Con(C,ele,ian,iele)
74412 COOSTRU *C;
74413 int ele;
74414 int ian;
74415 int iele[3];
74416 {
74417    int i,j,k,ret;
74418 
74419    ret = 0;
74420    k = -1;
74421    for (i=0; i < 4; i++) iele[i] = -1;
74422 
74423    for (i=0; i < C->iconn[(ele)*(MXCON+1)]; i++) {
74424 	j = C->iconn[(ele)*(MXCON+1)+1+i]-1;
74425 	if (C->ianz[j] == ian) {
74426 	   ret = 1;
74427 	   k++;
74428 	   iele[k] = j;
74429 	}
74430    }
74431 
74432    return(ret);
74433 }
74434 
ReleaseLig()74435 void ReleaseLig()
74436 {
74437    int i;
74438 
74439    for (i=0; i<lintp; i++) {
74440 	free(ligtyp[i]);
74441    }
74442 }
74443 
AllInt(C,indx,at1,at2,at3,at4,n,grp1,grp2,coo,iconf,link)74444 void AllInt(C,indx,at1,at2,at3,at4,n,grp1,grp2,coo,iconf,link)
74445 COOSTRU *C;
74446 int *indx;
74447 int at1;
74448 int at2;
74449 int at3;
74450 int at4;
74451 int n;
74452 int grp1;
74453 AREASTRU grp2;
74454 double *coo;
74455 int iconf;
74456 int link;
74457 {
74458    int j;
74459    INCRSTRU tmptyp;
74460 
74461    ligtyp[*indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
74462    memcpy(ligtyp[*indx], &modtyp, sizeof(INCRSTRU));
74463 
74464    for (j=0; j<3; j++) {
74465 	switch(n) {
74466 	case 1:
74467 		ligtyp[*indx]->c[0][j] = coo[(at1)*3+j];
74468 		ligtyp[*indx]->atom[0] = at1;
74469 		ligtyp[*indx]->n = 1;
74470 		break;
74471 	case 2:
74472 		ligtyp[*indx]->c[0][j] = coo[(at1)*3+j];
74473 		ligtyp[*indx]->c[1][j] = coo[(at2)*3+j];
74474 		ligtyp[*indx]->atom[0] = at1;
74475 		ligtyp[*indx]->atom[1] = at2;
74476 		ligtyp[*indx]->n = 2;
74477 		break;
74478 	case 3:
74479 		ligtyp[*indx]->c[0][j] = coo[(at1)*3+j];
74480 		ligtyp[*indx]->c[1][j] = coo[(at2)*3+j];
74481 		ligtyp[*indx]->c[2][j] = coo[(at3)*3+j];
74482 		ligtyp[*indx]->atom[0] = at1;
74483 		ligtyp[*indx]->atom[1] = at2;
74484 		ligtyp[*indx]->atom[2] = at3;
74485 		ligtyp[*indx]->n = 3;
74486 		break;
74487 	case 4:
74488 		ligtyp[*indx]->c[0][j] = coo[(at1)*3+j];
74489 		ligtyp[*indx]->c[1][j] = coo[(at2)*3+j];
74490 		ligtyp[*indx]->c[2][j] = coo[(at3)*3+j];
74491 		ligtyp[*indx]->c[3][j] = coo[(at4)*3+j];
74492 		ligtyp[*indx]->atom[0] = at1;
74493 		ligtyp[*indx]->atom[1] = at2;
74494 		ligtyp[*indx]->atom[2] = at3;
74495 		ligtyp[*indx]->atom[3] = at4;
74496 		ligtyp[*indx]->n = 4;
74497 		break;
74498 	default:
74499 		break;
74500 	}
74501    }
74502    ligtyp[*indx]->type = grp1;
74503    ligtyp[*indx]->area = grp2;
74504    ligtyp[*indx]->conf = iconf;
74505    ligtyp[*indx]->link = link;
74506    ligtyp[*indx]->ohlig = 0;
74507    ligtyp[*indx]->ohsame = 0;
74508 
74509    cal_area(ligtyp[*indx]);
74510    (*indx)++;
74511 }
74512 
FrgInt(indx)74513 void FrgInt(indx)
74514 int indx;
74515 {
74516 // Set members frag and nfrag of structure ligtyp (INCRSTRU)
74517 
74518    int fragi[4],at1,at2,at3,at4,f0n1,f0n2,f0n3,f1n2,f1n3,f2n3;
74519 
74520    at1 = ligtyp[indx]->atom[0];
74521    at2 = ligtyp[indx]->atom[1];
74522    at3 = ligtyp[indx]->atom[2];
74523    at4 = ligtyp[indx]->atom[3];
74524 
74525    switch(ligtyp[indx]->n) {
74526 	case 1:
74527 		ligtyp[indx]->frag[0] = singleb.ifrg[at1];
74528 		ligtyp[indx]->nfrag = 1;
74529 		break;
74530 	case 2:
74531 		fragi[0] = singleb.ifrg[at1];
74532 		fragi[1] = singleb.ifrg[at2];
74533 
74534 		ligtyp[indx]->frag[0] = fragi[0];
74535 
74536 		if (fragi[0] != fragi[1]) {
74537 		   ligtyp[indx]->frag[1] = fragi[1];
74538 		   ligtyp[indx]->nfrag = 2;
74539 		} else {
74540 		   ligtyp[indx]->nfrag = 1;
74541 		}
74542 		break;
74543 	case 3:
74544 		fragi[0] = singleb.ifrg[at1];
74545 		fragi[1] = singleb.ifrg[at2];
74546 		fragi[2] = singleb.ifrg[at3];
74547 
74548 		ligtyp[indx]->frag[0] = fragi[0];
74549 
74550 		if (fragi[0] != fragi[1]) {
74551 
74552 		   ligtyp[indx]->frag[1] = fragi[1];
74553 
74554 		   if (fragi[0] != fragi[2]) {
74555 			if (fragi[1] != fragi[2]) {
74556 			   ligtyp[indx]->frag[2] = fragi[2];
74557 			   ligtyp[indx]->nfrag = 3;
74558 			} else {
74559 			   ligtyp[indx]->nfrag = 2;
74560 			}
74561 		   } else {
74562 			ligtyp[indx]->nfrag = 2;
74563 		   }
74564 
74565 		} else {
74566 
74567 		   if (fragi[0] != fragi[2]) {
74568 			ligtyp[indx]->frag[1] = fragi[2];
74569 			ligtyp[indx]->nfrag = 2;
74570 		   } else {
74571 			ligtyp[indx]->nfrag = 1;
74572 		   }
74573 
74574 		}
74575 		break;
74576 	case 4:
74577 
74578 		fragi[0] = singleb.ifrg[at1];
74579 		fragi[1] = singleb.ifrg[at2];
74580 		fragi[2] = singleb.ifrg[at3];
74581 		fragi[3] = singleb.ifrg[at4];
74582 
74583 		f0n1 = 0; if (fragi[0] == fragi[1]) f0n1 = 1;
74584 		f0n2 = 0; if (fragi[0] == fragi[2]) f0n2 = 1;
74585 		f0n3 = 0; if (fragi[0] == fragi[3]) f0n3 = 1;
74586 		f1n2 = 0; if (fragi[1] == fragi[2]) f1n2 = 1;
74587 		f1n3 = 0; if (fragi[1] == fragi[3]) f1n3 = 1;
74588 		f2n3 = 0; if (fragi[2] == fragi[3]) f2n3 = 1;
74589 
74590 		if (f0n1 && f0n2 && f0n3) {
74591 // all four atoms are from the same fragment
74592 
74593 		   ligtyp[indx]->frag[0] = fragi[0];
74594 		   ligtyp[indx]->nfrag = 1;
74595 
74596 		} else if ((f0n1 && f1n2 && !f0n3) ||
74597 		   ((f1n2 && f2n3 && !f0n1) || (f2n3 && f0n3 && !f1n2)) ||
74598 			   (f0n1 && f1n3 && !f2n3)) {
74599 
74600 // three atoms are from the same fragment, ONE is NOT: two fragments
74601 
74602 		   if (f0n1 && f1n2 && !f0n3) {
74603 			ligtyp[indx]->frag[0] = fragi[0];
74604 			ligtyp[indx]->frag[1] = fragi[3];
74605 		   }
74606 
74607 		   if ((f1n2 && f2n3 && !f0n1) ||
74608 		       (f2n3 && f0n3 && !f1n2)) {
74609 			ligtyp[indx]->frag[0] = fragi[0];
74610 			ligtyp[indx]->frag[1] = fragi[1];
74611 		   }
74612 
74613 		   if (f0n1 && f1n3 && !f2n3) {
74614 			ligtyp[indx]->frag[0] = fragi[0];
74615 			ligtyp[indx]->frag[1] = fragi[2];
74616 		   }
74617 
74618 		   ligtyp[indx]->nfrag = 2;
74619 
74620 		} else if ((f0n1 && f2n3 && !f1n2) ||
74621 			   (f0n2 && f1n3 && !f0n1) ||
74622 			   (f0n3 && f1n2 && !f0n1)) {
74623 // two atoms are from one fragment, two others are from other frag:
74624 // two fragments
74625 
74626 
74627 		   if (f0n1 && f2n3 && !f1n2) {
74628 			ligtyp[indx]->frag[0] = fragi[0];
74629 			ligtyp[indx]->frag[1] = fragi[2];
74630 		   }
74631 		   if (f0n2 && f1n3 && !f0n1) {
74632 			ligtyp[indx]->frag[0] = fragi[0];
74633 			ligtyp[indx]->frag[1] = fragi[1];
74634 		   }
74635 		   if (f0n3 && f1n2 && !f0n1) {
74636 			ligtyp[indx]->frag[0] = fragi[0];
74637 			ligtyp[indx]->frag[1] = fragi[1];
74638 		   }
74639 
74640 		   ligtyp[indx]->nfrag = 2;
74641 
74642 		} else if ((f0n1 && !f0n2 && !f0n3) ||
74643 			   (f0n2 && !f0n1 && !f0n3) ||
74644 			   (f0n3 && !f0n1 && !f0n2) ||
74645 			   (f1n2 && !f0n1 && !f1n3) ||
74646 			   (f1n3 && !f0n1 && !f1n2) ||
74647 			   (f2n3 && !f0n2 && !f1n2) ) {
74648 
74649 // two atoms are from one fragment, two others are from different frags:
74650 // three fragments
74651 		   ligtyp[indx]->nfrag = 3;
74652 
74653 		   if (f0n1 && !f0n2 && !f0n3) {
74654 			ligtyp[indx]->frag[0] = fragi[0];
74655 			ligtyp[indx]->frag[1] = fragi[2];
74656 			ligtyp[indx]->frag[2] = fragi[3];
74657 		   }
74658 
74659 		   if ((f0n2 && !f0n1 && !f0n3) ||
74660 		       (f1n2 && !f0n1 && !f1n3)) {
74661 			ligtyp[indx]->frag[0] = fragi[0];
74662 			ligtyp[indx]->frag[1] = fragi[1];
74663 			ligtyp[indx]->frag[2] = fragi[3];
74664 		   }
74665 
74666 		   if ((f0n3 && !f0n1 && !f0n2) ||
74667 		       (f1n3 && !f0n1 && !f1n2) ||
74668 		       (f2n3 && !f0n2 && !f1n2)) {
74669 
74670 			ligtyp[indx]->frag[0] = fragi[0];
74671 			ligtyp[indx]->frag[1] = fragi[1];
74672 			ligtyp[indx]->frag[2] = fragi[2];
74673 		   }
74674 
74675 		} else {
74676 
74677 // all four atoms are from different fragments
74678 
74679 		   ligtyp[indx]->frag[0] = fragi[0];
74680 		   ligtyp[indx]->frag[1] = fragi[1];
74681 		   ligtyp[indx]->frag[2] = fragi[2];
74682 		   ligtyp[indx]->frag[3] = fragi[3];
74683 		   ligtyp[indx]->nfrag = 4;
74684 		}
74685 		break;
74686 	default:
74687 		break;
74688    }
74689 }
74690 
ceil_odd(arcl)74691 int ceil_odd(arcl)
74692 float arcl;
74693 {
74694    int ires;
74695 
74696    ires = (int) ceil(arcl);
74697    if (ires % 2 != 1)  ires++;
74698    return ires;
74699 
74700 }
74701 
equidist_npts(inttyp,b1,b2,b3,e1l)74702  int equidist_npts(inttyp,b1,b2,b3,e1l)
74703  INCRSTRU *inttyp;
74704  double *b1;
74705  double *b2;
74706  double *b3;
74707  double e1l;
74708  {
74709    int ncirc[2],i,j,ntmp;
74710    float arcl[2], polrange,azirange;
74711    float a,D,D1,D2,theta,phi,thetad,phid,r,a1[2],a2[2],p1[2],p2[2],rq;
74712    int indx = 0, N,M1,M2,m,n;
74713    double x,y,z;
74714 
74715    if (inttyp->area.type == 3) {
74716 	polrange = 180.0;
74717    } else {
74718 	polrange = inttyp->area.polar2 - inttyp->area.polar1;
74719    }
74720 
74721    if (inttyp->area.type == 2 || inttyp->area.type == 3 || inttyp->area.type == 4) {
74722 	azirange = 360.0;
74723    } else {
74724 	azirange = inttyp->area.azimuth2 - inttyp->area.azimuth1;
74725    }
74726 
74727    arcl[0] = 1.0 + 2.0*PI*inttyp->area.rp * polrange /
74728   	(360.0*inttyp->area.maxarc[0]);
74729 
74730    arcl[1] = 1.0 + 2.0*PI*inttyp->area.rp * azirange /
74731 	(360.0*inttyp->area.maxarc[1]);
74732 
74733    ncirc[0] = ceil_odd(arcl[0]);
74734    ncirc[1] = ceil_odd(arcl[1]);
74735 
74736    polrange = polrange / (float) (ncirc[0] - 1);
74737    azirange = azirange / (float) (ncirc[1] - 1);
74738 
74739    a1[0] = inttyp->area.azimuth1;
74740    a1[1] = inttyp->area.azimuth2;
74741 
74742    if (inttyp->area.type == 1) {
74743 	a2[0] = inttyp->area.azimuthb1;
74744 	a2[1] = inttyp->area.azimuthb2;
74745    } else {
74746 	a2[0] = 0.0;
74747 	a2[1] = 180.0;
74748    }
74749 
74750    p1[0] = inttyp->area.polar1;
74751    p1[1] = inttyp->area.polar2;
74752    p2[0] = inttyp->area.polarb1;
74753    p2[1] = inttyp->area.polarb2;
74754 
74755    r = inttyp->area.rp;
74756    N = 4.0*PI*r*r/
74757 	(inttyp->area.maxarc[0]*inttyp->area.maxarc[1]);
74758 /*
74759    N = 4.0*PI*r*r/
74760 	(inttyp->area.maxarc[0]*inttyp->area.maxarc[1]);
74761    N = 2000;
74762 */
74763 
74764    rq = r/inttyp->area.maxarc[0];
74765    N = 4.0*PI*rq*rq;
74766 /*fprintf(stderr,"equi: N %d\n",N);*/
74767    N = 2000;
74768    r = r/toangs;
74769    a = 4.0*PI*r*r/N;
74770    D = sqrt(a);
74771    M1 = rndf(PI/D);
74772 /*fprintf(stderr,"equi: D %f PI/D %f M1 %d\n",D,PI/D,M1);*/
74773    D1 = PI/ (float) M1;
74774    D2 = a / D1;
74775 
74776    indx = 0;
74777 
74778    if (inttyp->area.type == 2 || inttyp->area.type == 3 ||
74779 		inttyp->area.type == 4) {
74780 
74781 	if (inttyp->area.polar1 == 0.0) {
74782 	   indx = 1;
74783 	} else {
74784 	   indx = 0;
74785 	}
74786 
74787 	ntmp = ncirc[0];
74788 	if (inttyp->area.type == 3) ntmp = ncirc[0]-1;
74789 
74790 	for (i = 1; i < ntmp; i++) {
74791 
74792 	   theta = inttyp->area.polar1 + i*polrange;
74793 
74794  	   for (j = 0; j < ncirc[1]-1; j++) {
74795 	      phi = inttyp->area.azimuth1 + j*azirange;
74796 
74797 	      indx++;
74798 	   }
74799 	}
74800 	if (inttyp->area.type == 3) indx++;
74801 
74802    } else {
74803 
74804 /*fprintf(stderr,"cal_area M1 %d \n",M1);*/
74805 	for (m = 0; m < M1; m++) {
74806 
74807 	   theta = PI * (((float) m) + 0.5) / ((float) M1);
74808 	   thetad = theta*180.0/PI;
74809 	   M2 = rndf(2.0*PI*sin(theta)/D2);
74810 
74811 	   for (n = 0; n < M2; n++) {
74812 
74813 		phi = 2.0*PI*((float) n) / ((float) M2);
74814 		phid = phi*180.0/PI;
74815 		if (phid > 270.0) phid = phid - 360.0;
74816 
74817 		if ((phid >= p1[0] && phid <= p1[1]) ||
74818 		    (phid >= p2[0] && phid <= p2[1]) ) {
74819 		if ((thetad >= a1[0] && thetad <= a1[1])  ||
74820 		    (thetad >= a2[0] && thetad <= a2[1]) ) {
74821 
74822 	   	indx++;
74823 
74824 		} /* if end */
74825 
74826 
74827 	   } /* if end */
74828 	} /* for n end */
74829      } /* for m end */
74830    }
74831 
74832    return indx;
74833  }
74834 
equidist_sphere(inttyp,b1,b2,b3,ori)74835  void equidist_sphere(inttyp,b1,b2,b3,ori)
74836  INCRSTRU *inttyp;
74837  double *b1;
74838  double *b2;
74839  double *b3;
74840  double *ori;
74841  {
74842    int ncirc[2],i,j,ntmp;
74843    float arcl[2], polrange,azirange;
74844    float a,D,D1,D2,theta,phi,thetad,phid,r,a1[2],a2[2],p1[2],p2[2],rq;
74845    int indx = 0, N,M1,M2,m,n;
74846    double x,y,z;
74847 
74848    if (inttyp->area.type == 3) {
74849 	polrange = 180.0;
74850    } else {
74851 	polrange = inttyp->area.polar2 - inttyp->area.polar1;
74852    }
74853 
74854    if (inttyp->area.type == 2 || inttyp->area.type == 3 ||
74855 	inttyp->area.type == 4) {
74856 	azirange = 360.0;
74857    } else {
74858 	azirange = inttyp->area.azimuth2 - inttyp->area.azimuth1;
74859    }
74860 
74861    arcl[0] = 1.0 + PI*inttyp->area.rp * polrange /
74862   	(180.0*inttyp->area.maxarc[0]);
74863 
74864    arcl[1] = 1.0 + PI*inttyp->area.rp * azirange /
74865 	(180.0*inttyp->area.maxarc[1]);
74866 
74867    ncirc[0] = ceil_odd(arcl[0]);
74868    ncirc[1] = ceil_odd(arcl[1]);
74869 
74870    polrange = polrange / (float) (ncirc[0] - 1);
74871    azirange = azirange / (float) (ncirc[1] - 1);
74872 
74873 
74874    r = inttyp->area.rp;
74875 /*
74876    N = 4.0*PI*r*r/
74877 	(inttyp->area.maxarc[0]*inttyp->area.maxarc[1]);
74878    N = 2000;
74879 */
74880 
74881    a1[0] = inttyp->area.azimuth1;
74882    a1[1] = inttyp->area.azimuth2;
74883 
74884    if (inttyp->area.type == 1) {
74885 	a2[0] = inttyp->area.azimuthb1;
74886 	a2[1] = inttyp->area.azimuthb2;
74887    } else {
74888 	a2[0] = 0.0;
74889 	a2[1] = 180.0;
74890    }
74891 
74892    p1[0] = inttyp->area.polar1;
74893    p1[1] = inttyp->area.polar2;
74894    p2[0] = inttyp->area.polarb1;
74895    p2[1] = inttyp->area.polarb2;
74896 
74897 
74898    rq = r/inttyp->area.maxarc[0];
74899    N = 4.0*PI*rq*rq;
74900    r = r/toangs;
74901    N = 2000;
74902    a = 4.0*PI*r*r/N;
74903    D = sqrt(a);
74904    M1 = rndf(PI/D);
74905    D1 = PI/ (float) M1;
74906    D2 = a / D1;
74907 
74908    indx = 0;
74909 
74910    if (inttyp->area.type == 2 || inttyp->area.type == 3 || inttyp->area.type == 4) {
74911 
74912 	x = 0.0;
74913 	y = 0.0;
74914 	z = r;
74915 
74916 	if (inttyp->area.polar1 == 0.0) {
74917 
74918 	   inttyp->points[0] = ori[0] + x*b3[0] + y*b2[0] + z*b1[0];
74919 	   inttyp->points[1] = ori[1] + x*b3[1] + y*b2[1] + z*b1[1];
74920 	   inttyp->points[2] = ori[2] + x*b3[2] + y*b2[2] + z*b1[2];
74921 
74922 	   indx = 1;
74923 	} else {
74924 	   indx = 0;
74925 	}
74926 
74927 	ntmp = ncirc[0];
74928 	if (inttyp->area.type == 3) ntmp = ncirc[0]-1;
74929 
74930 	for (i = 1; i < ntmp; i++) {
74931 
74932 //	   theta = ((double) i)*polrange;
74933 	   theta = (double) inttyp->area.polar1 + ((double) i)*polrange;
74934 	   theta = PI*theta / 180.0;
74935 
74936 
74937  	   for (j = 0; j < ncirc[1]-1; j++) {
74938 
74939 	      phi = ((double) j)*azirange;
74940 	      phi = PI*phi / 180.0;
74941 
74942 	      x = r*sin(theta)*cos(phi);
74943 	      y = r*sin(theta)*sin(phi);
74944 	      z = r*cos(theta);
74945 
74946 	      inttyp->points[indx*3+0] = ori[0] + x*b3[0] + y*b2[0] + z*b1[0];
74947 	      inttyp->points[indx*3+1] = ori[1] + x*b3[1] + y*b2[1] + z*b1[1];
74948 	      inttyp->points[indx*3+2] = ori[2] + x*b3[2] + y*b2[2] + z*b1[2];
74949 	      indx++;
74950 	   }
74951 	}
74952 
74953 	if (inttyp->area.type == 3) {
74954 
74955 	   x = 0.0;
74956 	   y = 0.0;
74957 	   z = -r;
74958 
74959 	   inttyp->points[indx*3+0] = ori[0] + x*b3[0] + y*b2[0] + z*b1[0];
74960 	   inttyp->points[indx*3+1] = ori[1] + x*b3[1] + y*b2[1] + z*b1[1];
74961 	   inttyp->points[indx*3+2] = ori[2] + x*b3[2] + y*b2[2] + z*b1[2];
74962 
74963 	   indx++;
74964 	}
74965 
74966    } else {
74967 
74968 	for (m = 0; m < M1; m++) {
74969 	   theta = PI * (((float) m) + 0.5) / ((float) M1);
74970 	   thetad = theta*180.0/PI;
74971 	   M2 = rndf(2.0*PI*sin(theta)/D2);
74972 	   for (n = 0; n < M2; n++) {
74973 		phi = 2.0*PI*((float) n) / ((float) M2);
74974 		phid = phi*180.0/PI;
74975 		if (phid > 270.0) phid = phid - 360.0;
74976 
74977 		if ((phid >= p1[0] && phid <= p1[1]) ||
74978 		    (phid >= p2[0] && phid <= p2[1]) ) {
74979 		  if ((thetad >= a1[0] && thetad <= a1[1])  ||
74980 		       (thetad >= a2[0] && thetad <= a2[1]) ) {
74981 
74982 		   x = r*sin(theta)*cos(phi);
74983 		   y = r*sin(theta)*sin(phi);
74984 	 	   z = r*cos(theta);
74985 
74986 		   inttyp->points[indx*3+0] =
74987 			inttyp->c[0][0] + x*b2[0] + y*b3[0] + z*b1[0];
74988 	   	   inttyp->points[indx*3+1] =
74989 			inttyp->c[0][1] + x*b2[1] + y*b3[1] + z*b1[1];
74990 	   	   inttyp->points[indx*3+2] =
74991 			inttyp->c[0][2] + x*b2[2] + y*b3[2] + z*b1[2];
74992 
74993 	   	   indx++;
74994 
74995 		  } /* if end */
74996 
74997 
74998 	        } /* if end */
74999 	   } /* for n end */
75000 	} /* for m end */
75001    }
75002 
75003  }
75004 
cal_area(inttyp)75005  void cal_area(inttyp)
75006  INCRSTRU *inttyp;
75007  {
75008  int ncirc[2],i,j,indx,bole;
75009  float arcl[2], polrange,azirange,phi,theta;
75010  double e0[3],e1[3],e2[3],e3[3],ori[3];
75011  double b1[3],b2[3],b3[3];
75012  double x,y,z,e1l,e2l,e1lt,e2lt;
75013 
75014  e1[0] = 0.0; e1[1] = 0.0; e1[2] = 1.0;
75015  e2[0] = 1.0; e2[1] = 0.0; e2[2] = 0.0;
75016  e3[0] = 0.0; e3[1] = 1.0; e3[2] = 0.0;
75017 
75018  for (i = 0; i < 3; i++) {
75019     if (inttyp->area.type != 3) {
75020 	e1[i] =  inttyp->c[1][i] - inttyp->c[0][i];
75021 	if (inttyp->area.type != 2 && inttyp->area.type != 3) {
75022 	   e2[i] =  inttyp->c[2][i] - inttyp->c[0][i];
75023 	}
75024 	if (inttyp->area.type == 6) {
75025 	   e3[i] =  inttyp->c[3][i] - inttyp->c[0][i];
75026 	}
75027     }
75028  }
75029 
75030  for (i = 0; i < 3; i++) {
75031 	ori[i] = inttyp->c[0][i] +
75032 		inttyp->area.center[0]*e1[i] +
75033 		inttyp->area.center[1]*e2[i] +
75034 		inttyp->area.center[2]*e3[i];
75035 	ORI[i] = (float) ori[i];
75036 	inttyp->ORI[i] = ori[i];
75037  }
75038 
75039 
75040 /*
75041 transform to orthogonal basis:
75042 FIRST normalize e1,e2,e3
75043 */
75044 
75045  e1l = dveclen(e1);
75046  e2l = dveclen(e2);
75047 
75048  if (inttyp->area.type != 6) {
75049     for (i = 0; i < 3; i++) {
75050 	e1[i] = e1[i] / e1l;
75051 	e2[i] = e2[i] / e2l;
75052     }
75053     crossprd(e1,e2,e3);
75054  }
75055 
75056  for (i = 0; i < 3; i++) {
75057 	b1[i] = e1[i];
75058 	b2[i] = e2[i];
75059 	b3[i] = e3[i];
75060  }
75061 
75062  for (i = 0; i < 3; i++) {
75063     if (inttyp->area.type != 3) {
75064 	e1[i] = inttyp->area.v1[0]*b1[i] + inttyp->area.v1[1]*b2[i] +
75065 		inttyp->area.v1[2]*b3[i];
75066 	if (inttyp->area.type != 2 && inttyp->area.type != 3 &&
75067 		inttyp->area.type != 4 && inttyp->area.type != 5 &&
75068 		inttyp->area.type != 6) {
75069 	   e2[i] = inttyp->area.v2[0]*b1[i] + inttyp->area.v2[1]*b2[i] +
75070 		inttyp->area.v2[2]*b3[i];
75071 	}
75072     }
75073  }
75074 
75075  e1lt = dveclen(e1);
75076  e2lt = dveclen(e2);
75077 
75078  for (i = 0; i < 3; i++) {
75079 	e1[i] = e1[i] / e1lt;
75080 	e2[i] = e2[i] / e2lt;
75081 	b1[i] = e1[i];
75082  }
75083 
75084  crossprd(e1,e2,e3);
75085 
75086  if (inttyp->area.type == 5 || inttyp->area.type == 6) {
75087     crossprd(e1,e3,e2);
75088     for (i = 0; i < 3; i++) {
75089 	b1[i] = e1[i];
75090 	b2[i] = e2[i];
75091 	b3[i] = e3[i];
75092     }
75093     inttyp->area.type = 2;
75094 
75095  } else {
75096     crossprd(e1,e3,b2);
75097     crossprd(b1,b2,b3);
75098  }
75099 
75100  for (i = 0; i < 3; i++) {
75101 	B1[i] = (float) b1[i];
75102 	B2[i] = (float) b2[i];
75103 	B3[i] = (float) b3[i];
75104  }
75105 
75106  inttyp->npts = equidist_npts(inttyp,b1,b2,b3,e1l);
75107 
75108  if (inttyp->npts != 0) {
75109 
75110     inttyp->points =  (double *) malloc((sizeof x)*(inttyp->npts+1)*3);
75111 
75112     equidist_sphere(inttyp,b1,b2,b3,ori);
75113  }
75114 
75115 }
75116 
75117 #define DCKCOFF  10.0
75118 #define DCKCMIN  1.5
75119 #define DCKDEV   0.55
75120 #define N_GROUPS      7
75121 
75122 #define H_ACC_GROUP   0
75123 #define H_DON_GROUP   1
75124 #define PHC_GROUP     2
75125 #define PHR_GROUP     3
75126 #define ARO_GROUP     4
75127 #define MET_GROUP     5
75128 #define MACC_GROUP    6
75129 
75130 static double dckcoff = DCKCOFF;
75131 static int FiltAD =  0;
75132 static int prE =  0;
75133 static int hpr =  1;
75134 static int DistI[N_GROUPS];
75135 static int PDist[N_GROUPS];
75136 static int NDist[N_GROUPS];
75137 static int *IDist[N_GROUPS];
75138 static GRPSTRU XGRP[N_GROUPS][N_GROUPS];
75139 
cmpcrs(a,b)75140 int cmpcrs(a,b)
75141 CROSSSTRU *a, *b;
75142 {
75143     if (a->d > b->d) return 1;
75144     else
75145        if (a->d == b->d) return  0;
75146        else          return -1;
75147 }
75148 
CmpORI(ORI1,ORI2)75149 int CmpORI(ORI1,ORI2)
75150 double *ORI1;
75151 double *ORI2;
75152 {
75153     int i,j;
75154 
75155     for (i=0; i < 3; i++)  if (ORI1[i] != ORI2[i]) return 1;
75156 
75157     return 0;
75158 }
75159 
GetCrossGroup(grp1,grp2,fill)75160 int GetCrossGroup(grp1,grp2,fill)
75161 int grp1;
75162 int grp2;
75163 int fill;
75164 {
75165     int i,j,k,l,m,n,id1,id2;
75166     double dd,tt;
75167 
75168     n = 0;
75169 
75170     for (i=0; i < DistI[grp1]; i++) {
75171 	id1 = IDist[grp1][i];
75172 	for (k=0; k < inttyp[id1]->npts; k++) {
75173 	   for (j=i+1; j < DistI[grp2]; j++) {
75174 	     id2 = IDist[grp2][j];
75175 	     if (CmpORI(inttyp[id1]->ORI, inttyp[id2]->ORI)) {
75176 		for (l=0; l < inttyp[IDist[grp2][j]]->npts; l++) {
75177 		   dd = 0.0;
75178 		   for (m=0; m < 3; m++) {
75179 		   	tt = inttyp[id1]->points[k*3+m] -
75180 			     inttyp[id2]->points[l*3+m];
75181 			dd = dd + tt*tt;
75182 
75183 		   }
75184 		   dd = sqrt(dd)*toangs;
75185 		   if (dd < dckcoff && dd > DCKCMIN) {
75186 			if (! ((id1 == id2) && (k == l))) {
75187 
75188 			 if (fill) {
75189 			   XGRP[grp1][grp2].XDist[n].d = (float) dd;
75190 			   XGRP[grp1][grp2].XDist[n].grp1 = grp1;
75191 			   XGRP[grp1][grp2].XDist[n].ind1 = IDist[grp1][i];
75192 			   XGRP[grp1][grp2].XDist[n].pnt1 = k;
75193 			   XGRP[grp1][grp2].XDist[n].grp2 = grp2;
75194 			   XGRP[grp1][grp2].XDist[n].ind2 = IDist[grp2][j];
75195 			   XGRP[grp1][grp2].XDist[n].pnt2 = l;
75196 			 }
75197 			 n++;
75198 			}
75199 		   }
75200 		}
75201 	      }
75202 	   }
75203 	}
75204     }
75205 
75206     return n;
75207 }
75208 
ScanCrossGroup(grp1,grp2,ind1,ind2)75209 void ScanCrossGroup(grp1,grp2,ind1,ind2)
75210 int grp1;
75211 int grp2;
75212 int ind1;
75213 int ind2;
75214 {
75215     int i;
75216 
75217     fprintf(stderr,"ScanCrossGroup: [%d,%d] for distances between interactionpoints %d %d\n\n",grp1,grp2,ind1,ind2);
75218     for (i=0; i < XGRP[grp1][grp2].n; i++) {
75219 	if (XGRP[grp1][grp2].XDist[i].ind1 == ind1 &&
75220 	    XGRP[grp1][grp2].XDist[i].ind2 == ind2) {
75221 fprintf(stderr,"d %.3f pnt1 %d pnt2 %d\n",XGRP[grp1][grp2].XDist[i].d,XGRP[grp1][grp2].XDist[i].pnt1,XGRP[grp1][grp2].XDist[i].pnt2);
75222 	}
75223 
75224     }
75225 
75226 }
75227 
ScanCrossGroupDist(grp1,grp2,ind1,ind2,d)75228 void ScanCrossGroupDist(grp1,grp2,ind1,ind2,d)
75229 int grp1;
75230 int grp2;
75231 int ind1;
75232 int ind2;
75233 float d;
75234 {
75235    int i,ii,iii,j,idmin,idmax,d100,n;
75236    float dd,dmin,dmax;
75237    GRPSTRU *grp_p01;
75238    CROSSSTRU *xrsii;
75239 
75240    d100 = (int) dckcoff*dckcoff;
75241 
75242    dmin = ABS(d - DCKDEV);
75243    if (dmin > (float) dckcoff) {
75244 	idmin = d100;
75245    } else if (dmin < DCKCMIN) {
75246 	idmin = 1;
75247    } else {
75248 	idmin = (int) rndf(dmin*10.0);
75249 	if (idmin > d100) return;
75250    }
75251 
75252    dmax = ABS(d + DCKDEV);
75253    if (dmax > (float) dckcoff) {
75254 	idmax = d100;
75255    } else if (dmax < DCKCMIN) {
75256 	idmax = 1;
75257    } else {
75258 	idmax = (int) rndf(dmax*10.0);
75259 	if (idmax > d100) idmax = d100;
75260    }
75261 
75262    fprintf(stderr,"ScanCrossGroupD: [%d,%d] for distances %.3f between interactionpoints %d %d\n\n",grp1,grp2,d,ind1,ind2);
75263    for (i=0; i < XGRP[grp1][grp2].n; i++) {
75264 	if (XGRP[grp1][grp2].XDist[i].ind1 == ind1 &&
75265 	    XGRP[grp1][grp2].XDist[i].ind2 == ind2) {
75266 	   if (ABS(XGRP[grp1][grp2].XDist[i].d-d) < DCKDEV) {
75267 fprintf(stderr,"d %.3f pnt1 %d pnt2 %d\n",XGRP[grp1][grp2].XDist[i].d,XGRP[grp1][grp2].XDist[i].pnt1,XGRP[grp1][grp2].XDist[i].pnt2);
75268 	   }
75269 	}
75270 
75271    }
75272 
75273    fprintf(stderr,"ScanCrossGroupD: [%d,%d] for distances %.3f via XHash of interaction points %d %d\n\n",grp1,grp2,d,ind1,ind2);
75274    fprintf(stderr,"ScanCrossGroupD: [%d,%d] for distances %.3f via XHash idmin %d idmax %d\n\n",grp1,grp2,d,idmin,idmax);
75275    grp_p01 = &XGRP[grp1][grp2];
75276 
75277    for (i = idmin; i < idmax+1; i++ ) {
75278 	n   = grp_p01->XHash[i].n;
75279 	ii  = grp_p01->XHash[i].ind;
75280 
75281 	if (ii+n >= grp_p01->n) break;
75282 
75283 	for (j = 0; j < n; j++ ) {
75284 
75285 	   iii = ii + j;
75286 	   xrsii = &grp_p01->XDist[iii];
75287 
75288 	   if (i == idmin && j == 0) fprintf(stderr,"dist[%d,%d] %.3f \n",iii,ii,xrsii->d);
75289 	   if (ABS(xrsii->d-d) < DCKDEV && xrsii->ind1 == ind1 && xrsii->ind2 == ind2) {
75290 		fprintf(stderr,"d %.3f pnt1 %d pnt2 %d iii %d\n",
75291 			xrsii->d,xrsii->pnt1,xrsii->pnt2,iii);
75292 	   }
75293 	}
75294    }
75295 }
75296 
PrtInt(int i1,int i2,int i3,int j1,int j2,int j3)75297 void PrtInt(int i1,int i2,int i3,int j1,int j2,int j3)
75298 {
75299     int i,j,k,m;
75300     double dd,tt;
75301     double d12,d13,d23;
75302     double d12min,d13min,d23min;
75303     double d12max,d13max,d23max;
75304     double D12,D13,D23;
75305     double v1[3],v2[3],v3[3];
75306 
75307 // This function test for the existance of a triplet (i1,i2,i3)
75308 // of protein interaction points, against a ligand triplet (j1,j2,j3)
75309 // THIS IS ACCOMPLISHED without the setup_distances tables !!
75310 
75311 // First create distances from ligand interaction points
75312 
75313     if (j1 >= lintp || j2 >= lintp || j3 >= lintp) return;
75314 
75315     for (i = 0; i<3; i++ ) {
75316       v1[i] = ligtyp[j1]->ORI[i] - ligtyp[j2]->ORI[i];
75317       v2[i] = ligtyp[j2]->ORI[i] - ligtyp[j3]->ORI[i];
75318       v3[i] = ligtyp[j1]->ORI[i] - ligtyp[j3]->ORI[i];
75319     }
75320     D12 = dveclen(v1)*toangs;
75321     D23 = dveclen(v2)*toangs;
75322     D13 = dveclen(v3)*toangs;
75323 
75324     d12min = BIGD; d13min = BIGD; d23min = BIGD;
75325     d12max = 0.0; d13max = 0.0; d23max = 0.0;
75326 fprintf(stderr,"find protein interaction triples for interaction points %d,%d,%d \n",i1,i2,i3);
75327 fprintf(stderr,"within distances from ligand interaction triple: %d,%d,%d\n",j1,j2,j3);
75328 fprintf(stderr,"ligand distance: D12 %.3f D13 %.3f D23 %.3f\n",D12,D13,D23);
75329 fprintf(stderr,"dckcoff: %.3f\n",dckcoff);
75330 
75331     if (i1 >= nintp || i2 >= nintp || i3 >= nintp) return;
75332 
75333     for (i=0; i<inttyp[i1]->npts; i++) {
75334        for (j=0; j<inttyp[i2]->npts; j++) {
75335 
75336 	  d12 = 0.0;
75337 	  for (m=0; m < 3; m++) {
75338 	  	tt = inttyp[i1]->points[i*3+m] -
75339 		     inttyp[i2]->points[j*3+m];
75340 		d12 = d12 + tt*tt;
75341 	  }
75342 	  d12 = sqrt(d12)*toangs;
75343 	  if (d12 < d12min) d12min = d12;
75344 	  if (d12 > d12max) d12max = d12;
75345 
75346           for (k=0; k<inttyp[i3]->npts; k++) {
75347 		d13 = 0.0;
75348 		for (m=0; m < 3; m++) {
75349 		   	tt = inttyp[i1]->points[i*3+m] -
75350 			     inttyp[i3]->points[k*3+m];
75351 			d13 = d13 + tt*tt;
75352 		}
75353 		d13 = sqrt(d13)*toangs;
75354 		if (d13 < d13min) d13min = d13;
75355 		if (d13 > d13max) d13max = d13;
75356 
75357 		d23 = 0.0;
75358 		for (m=0; m < 3; m++) {
75359 		   	tt = inttyp[i2]->points[j*3+m] -
75360 			     inttyp[i3]->points[k*3+m];
75361 			d23 = d23 + tt*tt;
75362 
75363 		}
75364 		d23 = sqrt(d23)*toangs;
75365 		if (d23 < d23min) d23min = d23;
75366 		if (d23 > d23max) d23max = d23;
75367 
75368 		if (d12 < dckcoff && d13 < dckcoff && d23 < dckcoff) {
75369 	if (ABS(d12-D12) < DCKDEV && ABS(d13-D13) < DCKDEV &&
75370 		ABS(d23-D23) < DCKDEV) {
75371 		   fprintf(stderr,"i,j,k %d,%d,%d d12 %.3f d13 %.3f d23 %.3f\n",i,j,k,d12,d13,d23);
75372 	}
75373 	if (ABS(d12-D12) < 1.5*DCKDEV && ABS(d13-D13) < 1.5*DCKDEV &&
75374 		ABS(d23-D23) < 1.5*DCKDEV) {
75375 		   fprintf(stderr,"1.5: i,j,k %d,%d,%d d12 %.3f d13 %.3f d23 %.3f\n",i,j,k,d12,d13,d23);
75376 	}
75377 		}
75378 	  }
75379        }
75380     }
75381     fprintf(stderr,"d12min %.3f d13min %.3f d23min %.3f\n",d12min,d13min,d23min);
75382     fprintf(stderr,"d12max %.3f d13max %.3f d23max %.3f\n",d12max,d13max,d23max);
75383 }
75384 
Setup_Distance_Tables()75385 void Setup_Distance_Tables()
75386 {
75387     int i,j,k,l,m,n,jnew,ll,kk;
75388     double dd,tt;
75389     double d12,d13,d23;
75390     int done;
75391 
75392 
75393     for (i=0; i<N_GROUPS; i++) {
75394 	PDist[i] = 0;
75395 	NDist[i] = 0;
75396 	DistI[i] = 0;
75397     }
75398 
75399     for (i=0; i<nintp; i++) {
75400 	switch (inttyp[i]->type) {
75401 	case H_ACC:
75402 		PDist[H_ACC_GROUP] = PDist[H_ACC_GROUP] + inttyp[i]->npts;
75403 		NDist[H_ACC_GROUP]++;
75404 		break;
75405 
75406 	case H_DON:
75407 		PDist[H_DON_GROUP] = PDist[H_DON_GROUP] + inttyp[i]->npts;
75408 		NDist[H_DON_GROUP]++;
75409 		break;
75410 
75411 	case PHENYL_CENTER:
75412 		PDist[PHC_GROUP] = PDist[PHC_GROUP] + inttyp[i]->npts;
75413 		NDist[PHC_GROUP]++;
75414 		break;
75415 
75416 	case AMIDE:
75417 	case PHE_CH3:
75418 	case PHENYL_RING:
75419 		PDist[PHR_GROUP] = PDist[PHR_GROUP] + inttyp[i]->npts;
75420 		NDist[PHR_GROUP]++;
75421 		break;
75422 
75423 	case CH:
75424 	case CH2:
75425 	case CH3:
75426 	case SULFUR:
75427 	case ARO:
75428 		PDist[ARO_GROUP] = PDist[ARO_GROUP] + inttyp[i]->npts;
75429 		NDist[ARO_GROUP]++;
75430 		break;
75431 
75432 	case METAL:
75433 		PDist[MET_GROUP] = PDist[MET_GROUP] + inttyp[i]->npts;
75434 		NDist[MET_GROUP]++;
75435 		break;
75436 
75437 	case METAL_ACC:
75438 		PDist[MACC_GROUP] = PDist[MACC_GROUP] + inttyp[i]->npts;
75439 		NDist[MACC_GROUP]++;
75440 		break;
75441 	}
75442     }
75443 
75444     for (i=0; i<N_GROUPS; i++) {
75445 	IDist[i] = (int *) malloc(sizeof(int)*NDist[i]);
75446     }
75447 
75448     for (i=0; i<nintp; i++) {
75449 	switch (inttyp[i]->type) {
75450 	case H_ACC:
75451 		IDist[H_ACC_GROUP][DistI[H_ACC_GROUP]] = i;
75452 		DistI[H_ACC_GROUP]++;
75453 		break;
75454 
75455 	case H_DON:
75456 		IDist[H_DON_GROUP][DistI[H_DON_GROUP]] = i;
75457 		DistI[H_DON_GROUP]++;
75458 		break;
75459 
75460 	case PHENYL_CENTER:
75461 		IDist[PHC_GROUP][DistI[PHC_GROUP]] = i;
75462 		DistI[PHC_GROUP]++;
75463 		break;
75464 
75465 	case AMIDE:
75466 	case PHE_CH3:
75467 	case PHENYL_RING:
75468 		IDist[PHR_GROUP][DistI[PHR_GROUP]] = i;
75469 		DistI[PHR_GROUP]++;
75470 		break;
75471 
75472 	case CH:
75473 	case CH2:
75474 	case CH3:
75475 	case SULFUR:
75476 	case ARO:
75477 		IDist[ARO_GROUP][DistI[ARO_GROUP]] = i;
75478 		DistI[ARO_GROUP]++;
75479 		break;
75480 
75481 	case METAL:
75482 		IDist[MET_GROUP][DistI[MET_GROUP]] = i;
75483 		DistI[MET_GROUP]++;
75484 		break;
75485 
75486 	case METAL_ACC:
75487 		IDist[MACC_GROUP][DistI[MACC_GROUP]] = i;
75488 		DistI[MACC_GROUP]++;
75489 		break;
75490 	}
75491     }
75492 
75493     for (l=0; l < N_GROUPS; l++) {
75494 	for (k=l; k < N_GROUPS; k++) {
75495 	   if (l < 4 && k < 4) {
75496 	      XGRP[l][k].n = GetCrossGroup(l,k,0);
75497 
75498 	      XGRP[l][k].XDist = NULL;
75499 	      XGRP[l][k].XHash = NULL;
75500 
75501 	      if (XGRP[l][k].n != 0) {
75502 		XGRP[l][k].XDist =
75503 			(CROSSSTRU *) malloc(sizeof(CROSSSTRU)*XGRP[l][k].n);
75504 
75505 		if (XGRP[l][k].XDist == NULL)
75506 			fprintf(stderr,"Failed to allocate memory !\n");
75507 
75508 		XGRP[l][k].n = GetCrossGroup(l,k,1);
75509 
75510 		qsort((CROSSSTRU *) XGRP[l][k].XDist,
75511 		    XGRP[l][k].n, sizeof(CROSSSTRU), cmpcrs);
75512 
75513 		XGRP[l][k].l =
75514 			(int) rndf(XGRP[l][k].XDist[XGRP[l][k].n-1].d*10.0);
75515 
75516 		XGRP[l][k].XHash =
75517 			(HASHSTRU *) malloc(sizeof(HASHSTRU)*(XGRP[l][k].l+1));
75518 
75519 		for (i=0; i<XGRP[l][k].l; i++) {
75520 		    XGRP[l][k].XHash[i].n = 0;
75521 		    XGRP[l][k].XHash[i].ind = 0;
75522 		}
75523 
75524 		jnew = -1;
75525 		ll = 0;
75526 
75527 		for (i=0; i<XGRP[l][k].n; i++) {
75528 		   j = (int) rndf(XGRP[l][k].XDist[i].d*10.0);
75529 		   if (j != jnew) {
75530 			if (jnew != -1) XGRP[l][k].XHash[jnew].n = ll;
75531 			XGRP[l][k].XHash[j].ind = i;
75532 			ll = 0;
75533 			jnew = j;
75534 	   	   }
75535 	   	   ll++;
75536 		}
75537 
75538 	      }
75539 	   } else {
75540 	      XGRP[l][k].n = 0;
75541 
75542 	      XGRP[l][k].XDist = NULL;
75543 	      XGRP[l][k].XHash = NULL;
75544 	   }
75545 	}
75546     }
75547 
75548 //    ScanCrossGroup(0,0,61,227);
75549 //    ScanCrossGroupDist(0,0,51,235,12.896);
75550 //    PrtInt(51,235,144,38,54,42);
75551 }
75552 
Find_Group(grp)75553 int Find_Group(grp)
75554 int grp;
75555 {
75556    switch (grp) {
75557    case H_ACC:
75558 	return H_ACC_GROUP;
75559 	break;
75560 
75561    case H_DON:
75562 	return H_DON_GROUP;
75563 	break;
75564 
75565    case PHENYL_CENTER:
75566 	return PHC_GROUP;
75567 	break;
75568 
75569    case AMIDE:
75570    case PHE_CH3:
75571    case PHENYL_RING:
75572 	return PHR_GROUP;
75573 	break;
75574 
75575    case CH:
75576    case CH2:
75577    case CH3:
75578    case SULFUR:
75579    case ARO:
75580 	return ARO_GROUP;
75581 	break;
75582 
75583    case METAL:
75584 	return MET_GROUP;
75585 	break;
75586 
75587    case METAL_ACC:
75588 	return MACC_GROUP;
75589 	break;
75590    }
75591 }
75592 
Find_Matching_Group(grp)75593 int Find_Matching_Group(grp)
75594 int grp;
75595 {
75596    switch (grp) {
75597    case H_ACC_GROUP:
75598 	return H_DON_GROUP;
75599 	break;
75600    case H_DON_GROUP:
75601 	return H_ACC_GROUP;
75602 	break;
75603    case PHC_GROUP:
75604 	return PHR_GROUP;
75605 	break;
75606    case PHR_GROUP:
75607 	return PHC_GROUP;
75608 	break;
75609    case ARO_GROUP:
75610 	return ARO_GROUP;
75611 	break;
75612    case MET_GROUP:
75613 	return MACC_GROUP;
75614 	break;
75615    case MACC_GROUP:
75616 	return MET_GROUP;
75617 	break;
75618    }
75619 }
75620 
Calc_Centroid(Tri)75621 void Calc_Centroid(Tri)
75622 TRISTRU *Tri;
75623 {
75624 
75625 /* calculates centroid of a triangle */
75626 /* should also fill in l,k,m */
75627 
75628    int i,j,k,l;
75629    float v1[3],v2[3],v3[3],dd;
75630 
75631    for (i = 0; i<3; i++ ) {
75632       Tri->Cen[i] = (Tri->p1[i] + Tri->p2[i] + Tri->p3[i]) / 3.0;
75633       v1[i] = Tri->p2[i] - Tri->p1[i];
75634       v2[i] = Tri->p3[i] - Tri->p1[i];
75635       v3[i] = Tri->p3[i] - Tri->p2[i];
75636    }
75637    Tri->d12 = veclen(v1)*toangs;
75638    Tri->d13 = veclen(v2)*toangs;
75639    Tri->d23 = veclen(v3)*toangs;
75640 
75641    cross(v1,v2,Tri->Out);
75642    dd = veclen(Tri->Out);
75643    if (dd > 0.0) {
75644       for (i = 0; i<3; i++ ) Tri->Out[i] = Tri->Out[i] / dd;
75645    }
75646 
75647 /* to tranform one triangle onto another:
75648    1 Translate Tri1.Cen[] to Tri2.Cen[]
75649    2 Take the two outvectors Tri1.Out[] and Tri2.Out[],
75650      calculate out vector from these vecs. This will be the axis of
75651      rotation,
75652      Take outvector of Out(Rot) x Tri2.out = OutF
75653      Now Out(Rot),Tri2.out and OutF form the basis on which will be rotatied
75654          z       ,x            y
75655    3 Now rotate Tri1 around Tri2.out, such that Tri1.p1[] == Tri2.p1[]
75656 */
75657 }
75658 
alntw_(isel1,isel2,iscst,nscnd)75659 void alntw_(isel1,isel2,iscst,nscnd)
75660 int *isel1;
75661 int *isel2;
75662 int *iscst;
75663 int *nscnd;
75664 {
75665 
75666 /* fill Tri1 and Tri2 structures with coordinates of two sets of
75667    three coordinates of two separate structure and find the transformation
75668    that moves stuct1 onto struct2 (trans_tri)
75669 */
75670 
75671    int i,j;
75672 
75673    for (j=0; j<3; j++) {
75674 	Tri1.p1[j] = (float) xyzp->coo[(isel1[0]-1)*3+j];
75675 	Tri1.p2[j] = (float) xyzp->coo[(isel1[1]-1)*3+j];
75676 	Tri1.p3[j] = (float) xyzp->coo[(isel1[2]-1)*3+j];
75677 
75678 	Tri2.p1[j] = (float) xyzp->coo[(*iscst+isel2[0]-1)*3+j];
75679 	Tri2.p2[j] = (float) xyzp->coo[(*iscst+isel2[1]-1)*3+j];
75680 	Tri2.p3[j] = (float) xyzp->coo[(*iscst+isel2[2]-1)*3+j];
75681    }
75682 
75683    Calc_Centroid(&Tri1);
75684    Calc_Centroid(&Tri2);
75685 
75686    Trans_Tri(&Tri1,&Tri2);
75687 }
75688 
Frst_Rot(cc,uu,sina,cosa,R)75689 void Frst_Rot(cc,uu,sina,cosa,R)
75690 float *cc;
75691 float *uu;
75692 double sina;
75693 double cosa;
75694 double R[4][4];
75695 {
75696 
75697     int i,j;
75698     double ca,sa,c[3],u[3];
75699 
75700     ca = cosa;
75701     sa = sina;
75702 
75703     for (i = 0; i<3; i++ ) {
75704 	c[i] = (double) cc[i];
75705 	u[i] = (double) uu[i];
75706     }
75707 
75708     R[0][0] = u[0]*u[0] + (u[1]*u[1] + u[2]*u[2])*ca;
75709     R[0][1] = u[0]*u[1]*(1.0 - ca) - u[2]*sa;
75710     R[0][2] = u[0]*u[2]*(1.0 - ca) + u[1]*sa;
75711     R[0][3] = (c[0]*(u[1]*u[1]+u[2]*u[2])-u[0]*(c[1]*u[1]+c[2]*u[2]))*(1.0 - ca) + (c[1]*u[2] - c[2]*u[1])*sa;
75712 
75713     R[1][0] = u[0]*u[1]*(1.0 - ca) + u[2]*sa;
75714     R[1][1] = u[1]*u[1] + (u[0]*u[0] + u[2]*u[2])*ca;
75715     R[1][2] = u[1]*u[2]*(1.0 - ca) - u[0]*sa;
75716     R[1][3] = (c[1]*(u[0]*u[0]+u[2]*u[2])-u[1]*(c[0]*u[0]+c[2]*u[2]))*(1.0 - ca) + (c[2]*u[0] - c[0]*u[2])*sa;
75717 
75718     R[2][0] = u[0]*u[2]*(1.0 - ca) - u[1]*sa;
75719     R[2][1] = u[1]*u[2]*(1.0 - ca) + u[0]*sa;
75720     R[2][2] = u[2]*u[2] + (u[0]*u[0] + u[1]*u[1])*ca;
75721     R[2][3] = (c[2]*(u[0]*u[0]+u[1]*u[1])-u[2]*(c[0]*u[0]+c[1]*u[1]))*(1.0 - ca) + (c[0]*u[1] - c[1]*u[0])*sa;
75722 
75723     R[3][0] = 0.0;
75724     R[3][1] = 0.0;
75725     R[3][2] = 0.0;
75726     R[3][3] = 1.0;
75727 }
75728 
vecnrm(float * v)75729 void vecnrm(float *v)
75730 {
75731    float vl;
75732    int j;
75733 
75734    vl = veclen(v);
75735    for (j=0; j<3; j++) {
75736 	v[j] = v[j] / vl;
75737    }
75738 }
75739 
xyzROT3(R,vt)75740 void xyzROT3(R,vt)
75741 double R[4][4];
75742 float *vt;
75743 {
75744    int j,k;
75745    double p[3],pp[3];
75746 
75747    for (j=0; j<3; j++) {
75748 	p[j] = vt[j];
75749 	pp[j] = 0.0;
75750    }
75751 
75752    for (j=0; j<3; j++) {
75753 	for (k=0; k<3; k++) {
75754 	   pp[j] = pp[j] + R[j][k]*p[k];
75755 	}
75756    }
75757 
75758    for (j=0; j<3; j++) {
75759 	vt[j] = (float) pp[j];
75760    }
75761 }
75762 
xyzROT4(R,vt)75763 void xyzROT4(R,vt)
75764 double R[4][4];
75765 float *vt;
75766 {
75767    int j,k;
75768    double p[4],pp[4];
75769 
75770    for (j=0; j<3; j++) {
75771 	p[j] = vt[j];
75772 	pp[j] = 0.0;
75773    }
75774 
75775    p[3] = 1.0;
75776    for (j=0; j<3; j++) {
75777 	for (k=0; k<4; k++) {
75778 	   pp[j] = pp[j] + R[j][k]*p[k];
75779 	}
75780    }
75781 
75782    for (j=0; j<3; j++) {
75783 	vt[j] = (float) pp[j];
75784    }
75785 }
75786 
Trans_Coo(Tri2,coo)75787 void Trans_Coo(Tri2,coo)
75788 TRISTRU *Tri2;
75789 double *coo;
75790 {
75791    int i,j;
75792    float pt[3];
75793    double R1[4][4],R2[4][4],t[3];
75794 
75795    if (!allConf(&Tri2->coo,ndocka)) exit(-1);
75796 
75797    for (j = 0; j<3; j++ ) {
75798 	t[j] = Tri2->t[j];
75799    }
75800 
75801    for (i=0; i<ndocka; i++) {
75802      for (j=0; j<3; j++) {
75803 	Tri2->coo[i*3+j] = t[j] + coo[i*3+j];
75804      }
75805    }
75806 
75807    for (i=0; i<4; i++)
75808      for (j=0; j<4; j++) R1[i][j] = Tri2->R1[i][j];
75809 
75810    for (i=0; i<ndocka; i++) {
75811      for (j=0; j<3; j++) {
75812 	pt[j] = Tri2->coo[i*3+j];
75813      }
75814 
75815      xyzROT4(R1,pt);
75816 
75817      for (j=0; j<3; j++) {
75818 	Tri2->coo[i*3+j] = pt[j];
75819      }
75820    }
75821 
75822    for (i=0; i<4; i++)
75823      for (j=0; j<4; j++) R2[i][j] = Tri2->R2[i][j];
75824 
75825 
75826    for (i=0; i<ndocka; i++) {
75827      for (j=0; j<3; j++) {
75828 
75829 	pt[j] = (float) Tri2->coo[i*3+j];
75830      }
75831 
75832      xyzROT4(R2,pt);
75833 
75834      for (j=0; j<3; j++) {
75835 	Tri2->coo[i*3+j] = (double) pt[j];
75836      }
75837    }
75838 
75839    for (j=0; j<3; j++) {
75840      if (Tri2->ohlig[j] == 1) {
75841 	i = Tri2->lig[j];
75842 	OHRot(Tri2,ligtyp[i]->atom[1],ligtyp[i]->atom[0],ligtyp[i]->atom[2],j);
75843 	OHFnd(Tri2,inttyp[Tri2->prot[j]]->ORI,j);
75844      }
75845    }
75846 
75847 }
75848 
PrtTrp(int indx)75849 void PrtTrp(int indx)
75850 {
75851 fprintf(stderr,"Triplet %d lig %d %d %d prot %d %d %d\n",indx,
75852 		TriArr[indx]->lig[0],TriArr[indx]->lig[1],TriArr[indx]->lig[2],
75853 		TriArr[indx]->prot[0],TriArr[indx]->prot[1],TriArr[indx]->prot[2]);
75854 fprintf(stderr,"prot dist d12 %f d13 %f d23 %f\n",
75855 		TriArr[indx]->d12,TriArr[indx]->d13,TriArr[indx]->d23);
75856 
75857 fprintf(stderr,"grp %d %d %d\n",
75858 		TriArr[indx]->grp[0],TriArr[indx]->grp[1],TriArr[indx]->grp[2]);
75859 }
75860 
PrtTrip(int indx,int ligind1,int ligind2)75861 void PrtTrip(int indx,int ligind1,int ligind2)
75862 {
75863 fprintf(stderr,"No match Triplet %d lig %d %d %d prot %d %d %d\n",indx,
75864 		TriArr[indx]->lig[0],TriArr[indx]->lig[1],TriArr[indx]->lig[2],
75865 		TriArr[indx]->prot[0],TriArr[indx]->prot[1],TriArr[indx]->prot[2]);
75866 	if (TriArr[indx]->lig[0] == ligind1 ||
75867 		TriArr[indx]->lig[1] == ligind1 ||
75868 		TriArr[indx]->lig[2] == ligind1) {
75869 
75870 		fprintf(stderr,"Triplet %d lig %d %d %d prot %d %d %d\n",indx,
75871 		TriArr[indx]->lig[0],TriArr[indx]->lig[1],TriArr[indx]->lig[2],
75872 		TriArr[indx]->prot[0],TriArr[indx]->prot[1],TriArr[indx]->prot[2]);
75873 
75874 		fprintf(stderr,"prot dist d12 %f d13 %f d23 %f\n",
75875 		TriArr[indx]->d12,TriArr[indx]->d13,TriArr[indx]->d23);
75876 
75877 		fprintf(stderr,"grp %d %d %d\n",
75878 		TriArr[indx]->grp[0],TriArr[indx]->grp[1],TriArr[indx]->grp[2]);
75879 
75880 	}
75881 
75882 	if (TriArr[indx]->lig[0] == ligind2 ||
75883 		TriArr[indx]->lig[1] == ligind2 ||
75884 		TriArr[indx]->lig[2] == ligind2) {
75885 
75886 		fprintf(stderr,"Triplet %d lig %d %d %d prot %d %d %d\n",indx,
75887 		TriArr[indx]->lig[0],TriArr[indx]->lig[1],TriArr[indx]->lig[2],
75888 		TriArr[indx]->prot[0],TriArr[indx]->prot[1],TriArr[indx]->prot[2]);
75889 
75890 		fprintf(stderr,"prot dist d12 %f d13 %f d23 %f\n",
75891 		TriArr[indx]->d12,TriArr[indx]->d13,TriArr[indx]->d23);
75892 
75893 		fprintf(stderr,"grp %d %d %d\n",
75894 		TriArr[indx]->grp[0],TriArr[indx]->grp[1],TriArr[indx]->grp[2]);
75895 	}
75896 }
75897 
Compress_Tri_L()75898 void Compress_Tri_L()
75899 {
75900    int i,ntritmp,tut,n;
75901    double dd;
75902 
75903    ntritmp = -1;
75904 
75905    for (i = 0; i < ntris; i++) {
75906 	if (TriArr[i] != NULL) {
75907 	   ntritmp++;
75908 	   TriArrCopy[ntritmp] = TriArr[i];
75909 	}
75910    }
75911 
75912    ntritmp++;
75913    ntris = ntritmp;
75914 
75915    for (i = 0; i < ntris; i++) {
75916 	TriArr[i] = TriArrCopy[i];
75917    }
75918 }
75919 
Compress_Tri_List()75920 void Compress_Tri_List()
75921 {
75922    int i,ntritmp,tut,n;
75923    double dd;
75924 
75925    if (ntris < MAXSOL) return;
75926 
75927    ntritmp = -1;
75928 
75929    n = ntris+1;
75930    tut = (ntris+1) % 2;
75931    if (tut > 0) n--;
75932 
75933    for (i = 0; i < n; i = i + 2 ) {
75934 	if (TriArr[i] == NULL && TriArr[i+1] != NULL) {
75935 	   ntritmp++;
75936 	   TriArrCopy[ntritmp] = TriArr[i+1];
75937 	   continue;
75938 	}
75939 	if (TriArr[i] != NULL && TriArr[i+1] == NULL) {
75940 	   ntritmp++;
75941 	   TriArrCopy[ntritmp] = TriArr[i];
75942 	   continue;
75943 	}
75944 	if (TriArr[i] == NULL && TriArr[i+1] == NULL) continue;
75945 	if (TriArr[i]->coo == NULL || TriArr[i+1]->coo == NULL) continue;
75946 	dd = dst(TriArr[i],TriArr[i+1]);
75947 	if (dd <= 0.000001) {
75948 	    if (TriArr[i+1]->coo != NULL) free(TriArr[i+1]->coo);
75949 	    free(TriArr[i+1]);
75950 	    TriArr[i+1] = NULL;
75951 	    ntritmp++;
75952 	    TriArrCopy[ntritmp] = TriArr[i];
75953 	} else {
75954 	    ntritmp++;
75955 	    TriArrCopy[ntritmp] = TriArr[i];
75956 	    ntritmp++;
75957 	    TriArrCopy[ntritmp] = TriArr[i+1];
75958 	}
75959    }
75960 
75961    ntris = ntritmp;
75962 
75963    for (i = 0; i < ntris+1; i++) {
75964 	TriArr[i] = TriArrCopy[i];
75965    }
75966 }
75967 
Compress_Tri_List_e12_nocoo()75968 void Compress_Tri_List_e12_nocoo()
75969 {
75970    int i,ntritmp,n;
75971    double dd;
75972 
75973    ntritmp = -1;
75974 
75975    n = ntris;
75976    for (i = 0; i < n; i++) {
75977 	if (TriArr[i] != NULL) {
75978 		if (TriArr[i]->e12 < 0.0) {
75979 		   ntritmp++;
75980 		   TriArrCopy[ntritmp] = TriArr[i];
75981 		}
75982 	}
75983    }
75984 
75985    ntritmp++;
75986 
75987    ntris = ntritmp;
75988    for (i = 0; i < ntris; i++) {
75989 	TriArr[i] = TriArrCopy[i];
75990    }
75991 }
75992 
Compress_Tri_List_e12()75993 void Compress_Tri_List_e12()
75994 {
75995    int i,ntritmp,n;
75996    double dd;
75997 
75998    ntritmp = -1;
75999 
76000    n = ntris;
76001    for (i = 0; i < n; i++) {
76002 	if (TriArr[i] != NULL) {
76003 	   if (TriArr[i]->coo != NULL) {
76004 		if (TriArr[i]->e12 < 0.0) {
76005 		   ntritmp++;
76006 		   TriArrCopy[ntritmp] = TriArr[i];
76007 		}
76008 	   }
76009 	}
76010    }
76011 
76012    ntritmp++;
76013 
76014    ntris = ntritmp;
76015    for (i = 0; i < ntris; i++) {
76016 	TriArr[i] = TriArrCopy[i];
76017    }
76018 }
76019 
76020 #define E12WIN 2.0
76021 
76022 static float E12min = BIGD;
76023 
CalcOne(int itri)76024 int CalcOne(int itri)
76025 {
76026     int i,j,lj;
76027     float etot;
76028 
76029     if (TriArr[itri] != NULL) {
76030 
76031 	   etot = 0.0;
76032 
76033 	   for (j=0; j < 3; j++) {
76034 		lj = TriArr[itri]->lig[j];
76035  		etot = etot +
76036 			CalInt(TriArr[itri]->prot[j],lj,ligtyp[lj]->points,
76037 				TriArr[itri]->t,
76038 				TriArr[itri]->R1,TriArr[itri]->R2,
76039 				TriArr[itri]->OutO,TriArr[itri]->OutOrg,0);
76040 	   }
76041 
76042 	   TriArr[itri]->e12 = etot;
76043 
76044 	   if (etot < E12min) {
76045 		E12min = etot;
76046 //	        if (Match_tri(TriArr[itri],8,24,13,51,235,145)) return(0);
76047 	   } else {
76048 		if (etot > E12min + E12WIN) return(1);
76049 	   }
76050 
76051     }
76052 
76053     return(0);
76054 }
76055 
CalcSchInt()76056 int CalcSchInt()
76057 {
76058     int i,j,lj,lig[3],ido,idoc,frag,conf,ntriso,NtrisCut,ntrisc,first;
76059     float etot,emin;
76060 
76061     emin = 10000.0;
76062     frag = -1;
76063 
76064     for (i=0; i < ntris; i++) {
76065 	if (TriArr[i] != NULL) {
76066 
76067 	   etot = 0.0;
76068 
76069 	   for (j=0; j < 3; j++) {
76070 		lj = TriArr[i]->lig[j];
76071  		etot = etot +
76072 			CalInt(TriArr[i]->prot[j],lj,ligtyp[lj]->points,
76073 				TriArr[i]->t,
76074 				TriArr[i]->R1,TriArr[i]->R2,
76075 				TriArr[i]->OutO,TriArr[i]->OutOrg,0);
76076 	   }
76077 
76078 
76079 	   TriArr[i]->e12 = etot;
76080 
76081 	   if (etot < emin) {
76082 		emin = etot;
76083 		frag = TriArr[i]->frag;
76084 		lig[0] = TriArr[i]->lig[0];
76085 		lig[1] = TriArr[i]->lig[1];
76086 		lig[2] = TriArr[i]->lig[2];
76087 	   }
76088 
76089 	}
76090     }
76091 
76092     Compress_Tri_List_e12_nocoo();
76093 
76094     if (ntris > 0) {
76095 	qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmptri);
76096     }
76097 
76098     NtrisCut = -1;
76099     ntrisc = ntris;
76100 
76101     for (i=0; i < ntris; i++) {
76102       if (TriArr[i] != NULL) {
76103 
76104 	ido = 0; idoc = 0; conf = -1;
76105 	if (TriArr[i]->conf != -1) idoc = 1;
76106 	if (idoc) {
76107 	   conf = TriArr[i]->conf;
76108 	} else {
76109 	   if (TriArr[i]->frag == frag) ido = 1;
76110 	}
76111 
76112 	if (TriArr[i]->e12 > TriArr[0]->e12 + E12WIN) {
76113 	   if (NtrisCut == -1) NtrisCut = i;
76114 	   ido = 0; idoc = 0;
76115 	}
76116 
76117 	if (ido) {
76118 	    Trans_Coo(TriArr[i],DCKxyz.coo);
76119 	} else if (idoc) {
76120 	    if (TriArr[i]->nconf == 0) {
76121 		Trans_Coo(TriArr[i],TriFin[conf]->coo);
76122 		continue;
76123 	    }
76124 
76125 	    first = 1;
76126 	    for (j=0; j < ligtyp[TriArr[i]->lig[0]]->nconf; j++) {
76127 		conf = ligtyp[TriArr[i]->lig[0]]->ConfArr[j];
76128 
76129 		if (Find_Lig_Conf(conf,i)) {
76130 		   if (first) {
76131 			Trans_Coo(TriArr[i],TriFin[conf]->coo);
76132 			first = 0;
76133 		   } else {
76134 			TriArr[ntrisc] = (TRISTRU *) malloc(sizeof(TRISTRU));
76135 			memcpy(TriArr[ntrisc], &EmpTri, sizeof(TRISTRU));
76136 			TriArr[ntrisc]->coo =
76137 			(double *) malloc(sizeof(double)*ndocka*3);
76138 			memcpy(TriArr[ntrisc], TriArr[i], sizeof(TRISTRU));
76139 			Trans_Coo(TriArr[ntrisc],TriFin[conf]->coo);
76140 			ntrisc++;
76141 		   }
76142 		}
76143 	    }
76144 
76145 	} else {
76146 	    if (TriArr[i]->coo != NULL) free(TriArr[i]->coo);
76147 	    free(TriArr[i]);
76148 	    TriArr[i] = NULL;
76149 	}
76150       }
76151     }
76152 
76153     ntris = ntrisc;
76154 
76155     ntriso = -1;
76156 
76157     for (i=0; i < 10; i++) {
76158 	Compress_Tri_List();
76159 	if ( ntris == ntriso || ntris < 50) break;
76160 	ntriso = ntris;
76161         fprintf(stderr,"compressed ntris %d\n",ntris);
76162     }
76163 
76164     return(frag);
76165 }
76166 
Trans_Tri(Tri1,Tri2)76167 void Trans_Tri(Tri1,Tri2)
76168 TRISTRU *Tri1;
76169 TRISTRU *Tri2;
76170 {
76171    int i,j,k,l;
76172    float v1[3],v2[3],v3[3],V1[4],V2[3],V3[3];
76173    float x,y,z,pt[3],pl,COSA,SINA,cosa,sina;
76174    double R1[4][4],R2[4][4],t[3];
76175 
76176 /* Tri1 is target, Tri2 to be transformed */
76177 
76178    for (j = 0; j<3; j++ ) {
76179 	t[j] = (double) (Tri1->Cen[j] - Tri2->Cen[j]);
76180 	v3[j] = Tri1->p1[j] - Tri1->Cen[j];
76181 	V1[j] = Tri2->p1[j] - Tri2->Cen[j];
76182 	V2[j] = Tri2->Out[j];
76183 	ORI2[j] = Tri2->Cen[j] + (float) t[j];
76184 	Tri2->Cen[j] = ORI2[j];
76185 	Tri2->p1c[j] = Tri2->p1[j] + t[j];
76186 	Tri2->p2c[j] = Tri2->p2[j] + t[j];
76187 	Tri2->p3c[j] = Tri2->p3[j] + t[j];
76188 	Tri2->P1[j] = Tri1->p1[j];
76189 	Tri2->P2[j] = Tri1->p2[j];
76190 	Tri2->P3[j] = Tri1->p3[j];
76191 	Tri2->t[j] = t[j];
76192 	Tri2->CenO[j] = Tri1->Cen[j];
76193 	Tri2->OutOrg[j] = Tri1->Out[j];
76194 	Tri2->prot[j] = Tri1->prot[j];
76195    }
76196 
76197    vecnrm(Tri2->Out);
76198    vecnrm(Tri1->Out);
76199 
76200    cross(Tri2->Out,Tri1->Out,v1);
76201    cross(Tri1->Out,Tri2->Out,v1);
76202    cross(Tri1->Out,v1,v2);
76203 
76204    vecnrm(v1);
76205    vecnrm(v2);
76206 
76207    IMPRD(Tri2->Out,Tri1->Out,&cosa,1);
76208    IMPRD(Tri2->Out,v2,&sina,1);
76209 
76210    Frst_Rot(Tri1->Cen,v1,sina,cosa,R1);
76211 
76212    vecnrm(V1);
76213    vecnrm(V2);
76214 
76215    xyzROT3(R1,V1);
76216    xyzROT3(R1,V2);
76217    xyzROT4(R1,ORI2);
76218 
76219    xyzROT4(R1,Tri2->p1c);
76220    xyzROT4(R1,Tri2->p2c);
76221    xyzROT4(R1,Tri2->p3c);
76222 
76223    for (j = 0; j<3; j++ ) {
76224 	Tri2->OutO[j] = V2[j];
76225    }
76226 
76227    for (i=0; i<4; i++)
76228      for (j=0; j<4; j++) Tri2->R1[i][j] = R1[i][j];
76229 
76230    cross(Tri1->Out,v3,v2);
76231 
76232 /* orthonormal basis Tri2.out=z,v2=x,v3=y */
76233 
76234    vecnrm(v2);
76235    vecnrm(v3);
76236    vecnrm(Tri1->Out);
76237    vecnrm(V1);
76238    cross(V2,V1,V3);
76239 
76240 
76241    for (i=0; i<3; i++) {
76242 	ORI[i] = Tri1->Cen[i];
76243 	B1[i] = Tri1->Out[i];
76244 	B2[i] = v2[i];
76245 	B3[i] = v3[i];
76246    }
76247 
76248    for (i=0; i<3; i++) {
76249 	Bt1[i] = V2[i];
76250 	Bt2[i] = V1[i];
76251 	Bt3[i] = V3[i];
76252    }
76253 
76254    IMPRD(v3,V1,&COSA,1);
76255    IMPRD(v3,V3,&SINA,1);
76256 
76257    Frst_Rot(ORI2,V2,SINA,COSA,R2);
76258 
76259    xyzROT4(R2,Tri2->p1c);
76260    xyzROT4(R2,Tri2->p2c);
76261    xyzROT4(R2,Tri2->p3c);
76262 
76263    for (i=0; i<4; i++)
76264      for (j=0; j<4; j++) Tri2->R2[i][j] = R2[i][j];
76265 
76266 }
76267 
Store_Tri(Tri1,Tri2)76268 void Store_Tri(Tri1,Tri2)
76269 TRISTRU *Tri1;
76270 TRISTRU *Tri2;
76271 {
76272    int j;
76273    double t[3];
76274 
76275 /* Tri1 is target, Tri2 to be transformed */
76276 
76277    for (j = 0; j<3; j++ ) {
76278 	t[j] = (double) (Tri1->Cen[j] - Tri2->Cen[j]);
76279 	Tri2->P1[j] = Tri1->p1[j];
76280 	Tri2->P2[j] = Tri1->p2[j];
76281 	Tri2->P3[j] = Tri1->p3[j];
76282 	Tri2->t[j] = t[j];
76283 	Tri2->CenO[j] = Tri1->Cen[j];
76284 	Tri2->OutOrg[j] = Tri1->Out[j];
76285    }
76286 
76287 
76288 }
76289 
Triangle_Same_Previous(Tri1,Tri2)76290 int Triangle_Same_Previous(Tri1,Tri2)
76291 TRISTRU *Tri1;
76292 TRISTRU *Tri2;
76293 {
76294    int i;
76295 
76296 
76297 /* Tri->d12,d13,d23 angs
76298    Tri->p1,p2,p3 au */
76299 
76300    if (Tri1 == NULL || Tri2 == NULL) return 0;
76301 
76302    if (Tri1->prot[0] != Tri2->prot[0] || Tri1->prot[1] != Tri2->prot[1] ||
76303 	Tri1->prot[2] != Tri2->prot[2]) return 0;
76304 
76305    if (ABS(Tri1->d12 - Tri2->d12) < 0.001 && ABS(Tri1->d13 - Tri2->d13) < 0.001 && ABS(Tri1->d23 - Tri2->d23) < 0.001) {
76306 
76307 	for (i=0; i < 3; i++) {
76308 	    if (ABS(Tri1->p1c[i] - Tri2->p1c[i]) > 0.001) return 0;
76309 	    if (ABS(Tri1->p2c[i] - Tri2->p2c[i]) > 0.001) return 0;
76310 	    if (ABS(Tri1->p3c[i] - Tri2->p3c[i]) > 0.001) return 0;
76311 	}
76312 	return 1;
76313    } else {
76314 	return 0;
76315    }
76316 }
76317 
FreeTri(int j)76318 void FreeTri(int j)
76319 {
76320    if (TriArr[j]->coo != NULL) free(TriArr[j]->coo);
76321    free(TriArr[j]);
76322    TriArr[j] = NULL;
76323 }
76324 
76325 #define MAXSOLLIGTRI 20
76326 
Find_Triangle_Match(Tri,idxs)76327 void Find_Triangle_Match(Tri,idxs)
76328 TRISTRU Tri;
76329 int idxs;
76330 {
76331    int grp[3],ogrp[3],i,j,k,l,ii,kk,idd,iee,n,m;
76332    int ind1,ind2,pnt1,pnt2,jind,jpnt,yesh;
76333    int AddTri,oo,idmin,idmax,iemin,iemax,iii,kkk,N,d100;
76334    float dd,ee,tt,ddd,ddt,eet,dckc;
76335    GRPSTRU *grp_p01, *grp_p12;
76336    CROSSSTRU *xrsii, *xrskk;
76337    TRISTRU TriA;
76338 
76339    d100 = (int) dckcoff*dckcoff;
76340    dckc = (float) dckcoff;
76341 
76342    if (Tri.d12 > dckc || Tri.d13 > dckc || Tri.d23 > dckc) return;
76343 
76344    TriA = Tri;
76345 
76346 /* convert specific group to general groups: eg H_ACC to H_ACC_GROUP */
76347 
76348    ogrp[0] = Find_Group(Tri.grp[0]);
76349    ogrp[1] = Find_Group(Tri.grp[1]);
76350    ogrp[2] = Find_Group(Tri.grp[2]);
76351 
76352 /* convert genreral groups to general matching groups */
76353 
76354    grp[0] = Find_Matching_Group(ogrp[0]);
76355    grp[1] = Find_Matching_Group(ogrp[1]);
76356    grp[2] = Find_Matching_Group(ogrp[2]);
76357 
76358    grp_p01 = &XGRP[grp[0]][grp[1]];
76359    grp_p12 = &XGRP[grp[1]][grp[2]];
76360 
76361    if (grp_p01->n == 0) return;
76362    if (grp_p12->n == 0) return;
76363 
76364    if (grp_p01->XDist == NULL)  return;
76365    if (grp_p01->XHash == NULL)  return;
76366    if (grp_p12->XDist == NULL)  return;
76367    if (grp_p12->XHash == NULL)  return;
76368 
76369    dd = ABS(Tri.d12 - DCKDEV);
76370    if (dd > dckc) {
76371 	idmin = d100;
76372    } else if (dd < DCKCMIN) {
76373 	idmin = 1;
76374    } else {
76375 	idmin = (int) rndf(dd*10.0);
76376 	if (idmin > d100) return;
76377    }
76378 
76379    dd = ABS(Tri.d12 + DCKDEV);
76380    if (dd > dckc) {
76381 	idmax = d100;
76382    } else if (dd < DCKCMIN) {
76383 	idmax = 1;
76384    } else {
76385 	idmax = (int) rndf(dd*10.0);
76386 	if (idmax > d100) idmax = d100;
76387    }
76388 
76389    ee = ABS(Tri.d23 - DCKDEV);
76390    if (ee > dckc) {
76391 	iemin = d100;
76392    } else if (ee < DCKCMIN) {
76393 	iemin = 1;
76394    } else {
76395 	iemin = (int) rndf(ee*10.0);
76396 	if (iemin > d100) return;
76397    }
76398 
76399    ee = ABS(Tri.d23 + DCKDEV);
76400    if (ee > dckc) {
76401 	iemax = d100;
76402    } else if (ee < DCKCMIN) {
76403 	iemax = 1;
76404    } else {
76405 	iemax = (int) rndf(ee*10.0);
76406 	if (iemax > d100) iemax = d100;
76407    }
76408 
76409    for (idd = idmin; idd < idmax+1; idd++ ) {
76410      N = 0;
76411      for (iee = iemin; iee < iemax+1; iee++ ) {
76412 
76413        n   = grp_p01->XHash[idd].n;
76414        ii  = grp_p01->XHash[idd].ind;
76415 
76416        if (ii+n >= grp_p01->n) break;
76417 
76418        m   = grp_p12->XHash[iee].n;
76419        kk  = grp_p12->XHash[iee].ind;
76420 
76421        if (kk+m >= grp_p12->n) break;
76422 
76423        for (i = 0; i < n; i++ ) {
76424 
76425 	iii = ii + i;
76426 	xrsii = &grp_p01->XDist[iii];
76427 
76428 	ddt  = xrsii->d;
76429 
76430 	for (k = 0; k < m; k++ ) {
76431 	   kkk = kk + k;
76432 	   xrskk = &grp_p12->XDist[kkk];
76433 
76434 	   eet  = xrskk->d;
76435 
76436 
76437 	   yesh = -1;
76438 
76439 	   if (xrsii->grp2 == grp[1]) {
76440 
76441 		if (xrskk->grp2 == grp[1]) {
76442 		   if (xrsii->ind2 == xrskk->ind2 &&
76443 		       xrsii->pnt2 == xrskk->pnt2) yesh = 1;
76444 
76445 		} else if (xrskk->grp1 == grp[1]) {
76446 		   if (xrsii->ind2 == xrskk->ind1 &&
76447 		       xrsii->pnt2 == xrskk->pnt1) yesh = 2;
76448 		}
76449 
76450 	   } else if (xrsii->grp1 == grp[1]) {
76451 
76452 		if (xrskk->grp1 == grp[1]) {
76453 		   if (xrsii->ind1 == xrskk->ind1 &&
76454 		       xrsii->pnt1 == xrskk->pnt1) yesh = 3;
76455 		} else if (xrskk->grp2 == grp[1]) {
76456 		   if (xrsii->ind1 == xrskk->ind2 &&
76457 		       xrsii->pnt1 == xrskk->pnt2) yesh = 4;
76458 		}
76459 	   }
76460 
76461 	   if (yesh != -1) {
76462 
76463 
76464 		switch (yesh) {
76465 		case 1:
76466 
76467 		   ind1 = xrsii->ind1;
76468 		   ind2 = xrskk->ind1;
76469 		   pnt1 = xrsii->pnt1;
76470 		   pnt2 = xrskk->pnt1;
76471 		   jind = xrsii->ind2;
76472 		   jpnt = xrsii->pnt2;
76473 		   break;
76474 
76475 		case 2:
76476 
76477 		   ind1 = xrsii->ind1;
76478 		   ind2 = xrskk->ind2;
76479 		   pnt1 = xrsii->pnt1;
76480 		   pnt2 = xrskk->pnt2;
76481 		   jind = xrsii->ind2;
76482 		   jpnt = xrsii->pnt2;
76483 		   break;
76484 
76485 		case 3:
76486 
76487 		   ind1 = xrsii->ind2;
76488 		   ind2 = xrskk->ind2;
76489 		   pnt1 = xrsii->pnt2;
76490 		   pnt2 = xrskk->pnt2;
76491 		   jind = xrsii->ind1;
76492 		   jpnt = xrsii->pnt1;
76493 		   break;
76494 
76495 		case 4:
76496 
76497 		   ind1 = xrsii->ind2;
76498 		   ind2 = xrskk->ind1;
76499 		   pnt1 = xrsii->pnt2;
76500 		   pnt2 = xrskk->pnt1;
76501 		   jind = xrsii->ind1;
76502 		   jpnt = xrsii->pnt1;
76503 		   break;
76504 
76505 		default:
76506 		   break;
76507 		}
76508 
76509 
76510 		ddd = 0.0;
76511 		for (l=0; l < 3; l++) {
76512 		   tt = inttyp[ind1]->points[pnt1*3+l] -
76513 		        inttyp[ind2]->points[pnt2*3+l];
76514 		   ddd = ddd + tt*tt;
76515 
76516 		}
76517 		ddd = sqrt(ddd)*TOANG;
76518 
76519 		if ((ABS(Tri.d13 - ddd) < DCKDEV) &&
76520 		    (ABS(Tri.d12 - ddt) < DCKDEV) &&
76521 		    (ABS(Tri.d23 - eet) < DCKDEV)) {
76522 
76523 			ntris++; N++;
76524 			if (ntris >= MAXTRI) {
76525 			   ntris = MAXTRI - 1;
76526 			   return;
76527 /*			fprintf(stderr,"ntris exceeded MAXTRI\n");*/
76528 			} else {
76529 
76530 			   if (N >= MAXSOLLIGTRI) goto IDD;
76531 
76532 			   TriArr[ntris] = (TRISTRU *) malloc(sizeof Tri);
76533 			   memcpy(TriArr[ntris], &EmpTri, sizeof(TRISTRU));
76534 			   TriArr[ntris]->coo = NULL;
76535 
76536 			   for (l=0; l < 3; l++) {
76537 				TriArr[ntris]->p1[l] = Tri.p1[l];
76538 				TriArr[ntris]->p2[l] = Tri.p2[l];
76539 				TriArr[ntris]->p3[l] = Tri.p3[l];
76540 				TriArr[ntris]->grp[l] = Tri.grp[l];
76541 				TriArr[ntris]->lig[l] = Tri.lig[l];
76542 			   }
76543 
76544 			   Calc_Centroid(TriArr[ntris]);
76545 
76546 			   for (l=0; l < 3; l++) {
76547 				TriA.p1[l] =
76548 				   inttyp[ind1]->points[pnt1*3+l];
76549 				TriA.p2[l] =
76550 				   inttyp[jind]->points[jpnt*3+l];
76551 				TriA.p3[l] =
76552 				   inttyp[ind2]->points[pnt2*3+l];
76553 				TriA.grp[l] = grp[l];
76554 			   }
76555 
76556 			   TriA.prot[0] = ind1;
76557 			   TriA.prot[1] = jind;
76558 			   TriA.prot[2] = ind2;
76559 
76560 			   TriArr[ntris]->prot[0] = ind1;
76561 			   TriArr[ntris]->prot[1] = jind;
76562 			   TriArr[ntris]->prot[2] = ind2;
76563 
76564 			   Calc_Centroid(&TriA);
76565 
76566 			   AddTri = 1;
76567  			   if (ntris > 1) {
76568  			      if (Triangle_Same_Previous(
76569 				    TriArr[ntris],TriArr[ntris-1])) AddTri = 0;
76570 			   }
76571 
76572 			   if (AddTri) {
76573 
76574 // TriA contains protein triangle. TriArr[ntris] contains ligand triangle
76575 
76576 				Trans_Tri(&TriA,TriArr[ntris]);
76577 				TriArr[ntris]->conf = Tri.conf;
76578 				TriArr[ntris]->nconf = Tri.nconf;
76579 				if (TriArr[ntris]->conf == -1) {
76580 				   TriArr[ntris]->frag = Tri.frag;
76581 				} else {
76582 				   TriArr[ntris]->frag = -1;
76583 				   TriArr[ntris]->frags[0] = Tri.frags[0];
76584 				   TriArr[ntris]->frags[1] = Tri.frags[1];
76585 				   TriArr[ntris]->frags[2] = Tri.frags[2];
76586 				}
76587 				TriArr[ntris]->triS = idxs;
76588 				if (CalcOne(ntris)) {
76589 				   FreeTri(ntris);
76590 				   ntris--;
76591 				}
76592 			   } else {
76593 				FreeTri(ntris);
76594 				ntris--;
76595 			   }
76596 			}
76597 
76598 		}
76599 	   }
76600 	} /* end for (k = 0; k < m; k++ ) */
76601        } /* end for (i = 0; i < n; i++ ) */
76602 
76603      }
76604 IDD:
76605      i = 0;
76606    }
76607 }
76608 
CalInt(ind1,ind2,lpoints,t,R1,R2,OutO,OutOrg,deb)76609 float CalInt(ind1,ind2,lpoints,t,R1,R2,OutO,OutOrg,deb)
76610 int ind1;
76611 int ind2;
76612 double *lpoints;
76613 double t[3];
76614 double R1[4][4];
76615 double R2[4][4];
76616 float OutO[3];
76617 float OutOrg[3];
76618 int deb;
76619 {
76620     int i,j,l,ipr;
76621     float e12,ddev,adev1,adev2,dd,aqmin,aq,at,todeg;
76622     float fq1,fq2,fd1,fa1,fa2;
76623     float O[3],T[3];
76624     double ctmp[3],v1[3],v2[3],cosa;
76625 
76626     ipr = 0;
76627 
76628     for (l=0; l < 3; l++) O[l] = t[l] + ligtyp[ind2]->ORI[l];
76629     xyzROT4(R1,O);
76630     xyzROT4(R2,O);
76631 
76632     todeg = 45.0e0/atan(1.0e0);
76633 
76634     e12 = inttyp[ind1]->area.ene + ligtyp[ind2]->area.ene;
76635 
76636     fq1 = 1.0;
76637 
76638     if (inttyp[ind1]->q0*ligtyp[ind2]->q0 < inttyp[ind1]->area.chgsc[1])
76639 	fq1 = inttyp[ind1]->area.chgsc[0];
76640 
76641     fq2 = 1.0;
76642 
76643     if (inttyp[ind1]->q0*ligtyp[ind2]->q0 < ligtyp[ind2]->area.chgsc[1])
76644 	fq2 = ligtyp[ind2]->area.chgsc[0];
76645 
76646     fd1 = 1.0;
76647 
76648     ddev = 0.0;
76649 
76650     for (i = 0; i < 3; i++ ) {
76651 	dd = (inttyp[ind1]->ORI[i] - O[i]);
76652 	ddev +=  dd*dd;
76653     }
76654 
76655     ddev = sqrt(ddev);
76656     ddev = ddev*toangs;
76657 
76658     ddev = ddev - 0.5*(inttyp[ind1]->area.radius + ligtyp[ind2]->area.radius);
76659     ddev = ABS(ddev);
76660 
76661     if (ddev <= inttyp[ind1]->area.dissc[0]) {
76662 	fd1 = 1.0;
76663     } else if (inttyp[ind1]->area.dissc[0] < ddev &&
76664 	ddev < inttyp[ind1]->area.dissc[1]) {
76665 	fd1 = 1.0 - (ddev - inttyp[ind1]->area.dissc[0])/
76666 		    (inttyp[ind1]->area.dissc[1]-inttyp[ind1]->area.dissc[0]);
76667     } else {
76668 	fd1 = 0.0;
76669 	return 0.0;
76670     }
76671 
76672     if (inttyp[ind1]->area.angsc[0] == 0 &&
76673 	inttyp[ind1]->area.angsc[1] == 360.0) {
76674 
76675 	fa1 = 1.0;
76676 
76677     } else {
76678 
76679 
76680 	adev1 = 0.0;
76681 	aqmin = 10000.0;
76682 
76683 	for (i = 0; i < inttyp[ind1]->npts; i++ ) {
76684 	   aq = 0.0;
76685 	   for (j = 0; j < 3; j++ ) {
76686 		at = inttyp[ind1]->points[i*3+j] - O[j];
76687 		aq = aq + at*at;
76688 	   }
76689 	   if (aq < aqmin) {
76690 		aqmin = aq;
76691 		for (j = 0; j < 3; j++ )
76692 		   ctmp[j] = inttyp[ind1]->points[i*3+j];
76693 	   }
76694 	}
76695 
76696 	for (j = 0; j < 3; j++ ) {
76697 	   v1[j] = O[j] - inttyp[ind1]->ORI[j];
76698 	   v2[j] = ctmp[j] - inttyp[ind1]->ORI[j];
76699 	}
76700 
76701 	dimprod(v1,v2,&cosa);
76702 
76703 	if (fabs(cosa) == 1.0) {
76704            adev1 = 0.0;
76705 	   if (cosa < 0) adev1 = 180.0;
76706 	} else {
76707            adev1 = (float) acos(cosa)*todeg;
76708 	}
76709 
76710 	fa1 = 1.0;
76711 
76712 	if (adev1 <= inttyp[ind1]->area.angsc[0]) {
76713 	   fa1 = 1.0;
76714 	} else if (inttyp[ind1]->area.angsc[0] < adev1 &&
76715 		   adev1 < inttyp[ind1]->area.angsc[1]) {
76716 	   fa1 = 1.0 - (adev1 - inttyp[ind1]->area.angsc[0])/
76717 		    (inttyp[ind1]->area.angsc[1]-inttyp[ind1]->area.angsc[0]);
76718 	} else {
76719 	   fa1 = 0.0;
76720 	   return 0.0;
76721 	}
76722     }
76723 
76724 
76725     if (ligtyp[ind2]->area.angsc[0] == 0 &&
76726 	ligtyp[ind2]->area.angsc[1] == 360.0) {
76727 
76728 	fa2 = 1.0;
76729 
76730     } else {
76731 
76732 	adev2 = 0.0;
76733 	aqmin = 10000.0;
76734 
76735 	for (i = 0; i < ligtyp[ind2]->npts; i++ ) {
76736 	   aq = 0.0;
76737 	   for (j = 0; j < 3; j++ ) T[j] = t[j] + lpoints[i*3+j];
76738 	   xyzROT4(R1,T);
76739 	   xyzROT4(R2,T);
76740 	   for (j = 0; j < 3; j++ ) {
76741 		at = T[j] - inttyp[ind1]->ORI[j];
76742 		aq = aq + at*at;
76743 	   }
76744 	   if (aq < aqmin) {
76745 		aqmin = aq;
76746 		for (j = 0; j < 3; j++ ) ctmp[j] = T[j];
76747 	   }
76748 	}
76749 
76750 	for (j = 0; j < 3; j++ ) {
76751 	   v1[j] = inttyp[ind1]->ORI[j] - O[j];
76752 	   v2[j] = ctmp[j] - O[j];
76753 	}
76754 
76755 	dimprod(v1,v2,&cosa);
76756 
76757 	if (fabs(cosa) == 1.0) {
76758            adev2 = 0.0;
76759 	   if (cosa < 0) adev2 = 180.0;
76760 	} else {
76761            adev2 = (float) acos(cosa)*todeg;
76762 	}
76763 
76764 	fa2 = 1.0;
76765 
76766 	if (adev2 <= ligtyp[ind2]->area.angsc[0]) {
76767 	   fa2 = 1.0;
76768 	} else if (ligtyp[ind2]->area.angsc[0] < adev2 &&
76769 		   adev2 < ligtyp[ind2]->area.angsc[1]) {
76770 	   fa2 = 1.0 - (adev2 - ligtyp[ind2]->area.angsc[0])/
76771 		    (ligtyp[ind2]->area.angsc[1]-ligtyp[ind2]->area.angsc[0]);
76772 	} else {
76773 	   fa2 = 0.0;
76774 	   return 0.0;
76775 	}
76776     }
76777 
76778 if (e12 > 0.0) fprintf(stderr,"CalInt: e12 %.3f\n",e12);
76779 if (fq1 < 0.0 || fq2 < 0.0 || fd1 < 0.0 || fa1 < 0.0 || fa2 < 0.0)
76780 	fprintf(stderr,"CalInt: fq1 %.3f fq2 %.3f fd1 %.3f fa1 %.3f fa2 %.3f\n",fq1,fq2,fd1,fa1,fa2);
76781     e12 = e12*fq1*fq2*fd1*fa1*fa2;
76782     return e12;
76783 }
76784 
Tris_NoLink()76785 void Tris_NoLink()
76786 {
76787     int i,j,n,ihacc1,ihacc2,ihdon1,ihdon2;
76788 
76789     for (i=0; i < ntriS; i++) {
76790 	if ((TriS[i].grp[0] == H_ACC || TriS[i].grp[1] == H_ACC ||
76791 		TriS[i].grp[2] == H_ACC) ||
76792 	    (TriS[i].grp[0] == H_DON || TriS[i].grp[1] == H_DON ||
76793 		TriS[i].grp[2] == H_DON)) {
76794 
76795 		   ihacc1 = -1; ihdon1 = -1;
76796 		   ihacc2 = -1; ihdon2 = -1;
76797 		   for (j=0; j < 3; j++) {
76798 			if (TriS[i].grp[j] == H_ACC) {
76799 			   if (ihacc1 == -1) {
76800 				ihacc1 = j;
76801 			   } else if (ihacc2 == -1) {
76802 				ihacc2 = j;
76803 			   }
76804 			}
76805 		   }
76806 		   for (j=0; j < 3; j++) {
76807 			if (TriS[i].grp[j] == H_DON) {
76808 			   if (ihdon1 == -1) {
76809 				ihdon1 = j;
76810 			   } else if (ihdon2 == -1) {
76811 				ihdon2 = j;
76812 			   }
76813 			}
76814 		   }
76815 		   if ((ihacc1 != -1 || ihacc2 != -1) &&
76816 		       (ihdon1 != -1 || ihdon2 != -1)) {
76817 
76818 		     if (ihdon1 != -1 && ihacc1 != -1) {
76819 			if (ligtyp[TriS[i].lig[ihdon1]]->link ==
76820 			    ligtyp[TriS[i].lig[ihacc1]]->link) {
76821 			   TriS[i].active = 0;
76822 			}
76823 		     }
76824 		     if (ihdon1 != -1 && ihacc2 != -1) {
76825 			if (ligtyp[TriS[i].lig[ihdon1]]->link ==
76826 			    ligtyp[TriS[i].lig[ihacc2]]->link) {
76827 			   TriS[i].active = 0;
76828 			}
76829 		     }
76830 		     if (ihdon2 != -1 && ihacc1 != -1) {
76831 			if (ligtyp[TriS[i].lig[ihdon2]]->link ==
76832 			    ligtyp[TriS[i].lig[ihacc1]]->link) {
76833 			   TriS[i].active = 0;
76834 			}
76835 		     }
76836 		     if (ihdon2 != -1 && ihacc2 != -1) {
76837 			if (ligtyp[TriS[i].lig[ihdon2]]->link ==
76838 			    ligtyp[TriS[i].lig[ihacc2]]->link) {
76839 			   TriS[i].active = 0;
76840 			}
76841 		     }
76842 		   }
76843 	}
76844     }
76845 
76846     n = 0;
76847     for (i=0; i < ntriS; i++) {
76848 	if (TriS[i].active) {
76849 	   TriS[n] = TriS[i];
76850 	   n++;
76851 	}
76852     }
76853     ntriS = n;
76854 
76855     if (debugdck) fprintf(stderr,"Tris_NoLink: ntris reduced %d \n",ntriS);
76856 }
76857 
Select_Tris(ifrag)76858 void Select_Tris(ifrag)
76859 int ifrag;
76860 {
76861     int i,j,n,nacd,nacdl,ihacc,ihdon;
76862 
76863     n = 0;
76864     nacd = 0; nacdl = 0;
76865 
76866     for (i=0; i < ntriS; i++) {
76867 	if (TriS[i].frag == ifrag) {
76868 	   n++;
76869 	   if ((TriS[i].grp[0] == H_ACC || TriS[i].grp[1] == H_ACC ||
76870 		TriS[i].grp[2] == H_ACC) ||
76871 		(TriS[i].grp[0] == H_DON || TriS[i].grp[1] == H_DON ||
76872 		TriS[i].grp[2] == H_DON)) {
76873 		   nacd++;
76874 		   ihacc = -1; ihdon = -1;
76875 		   for (j=0; j < 3; j++) {
76876 			if (TriS[i].grp[j] == H_ACC) ihacc = j;
76877 		   }
76878 		   for (j=0; j < 3; j++) {
76879 			if (TriS[i].grp[j] == H_DON) ihdon = j;
76880 		   }
76881 		   if (ihacc > -1 && ihdon > -1) {
76882 			if (ligtyp[TriS[i].lig[ihdon]]->link !=
76883 			    ligtyp[TriS[i].lig[ihacc]]->link)  nacdl++;
76884 		   }
76885 		}
76886  	}
76887     }
76888 
76889     fprintf(stderr,"Select_Tris: fragment %d ntris %d of which acc/don %d no linked %d\n",ifrag,n,nacd,nacdl);
76890 }
76891 
Sub_Selection_Tris()76892 void Sub_Selection_Tris()
76893 {
76894     int i,j,n,ispair,oh0,oh1,oh2;
76895 // The purpose of this function is to make a subslection of triplesin TriS[]
76896 // that have at least one pair of acceptors or donors:
76897 // acc-acc, acc-don or don-don
76898     n = 0;
76899 
76900     for (i=0; i < ntriS; i++) {
76901 	ispair = 0;
76902 	if ((TriS[i].grp[0] == H_ACC || TriS[i].grp[0] == H_DON)) ispair++;
76903 	if ((TriS[i].grp[1] == H_ACC || TriS[i].grp[1] == H_DON)) ispair++;
76904 	if ((TriS[i].grp[2] == H_ACC || TriS[i].grp[2] == H_DON)) ispair++;
76905 	if (ispair < 2) {
76906 	   TriS[i].active = 0;
76907 	} else {
76908 	   if (TriS[i].grp[0] == H_DON && TriS[i].grp[1] == H_DON) {
76909 		if (ligtyp[TriS[i].lig[0]]->ohlig &&
76910 		    ligtyp[TriS[i].lig[1]]->ohlig) {
76911 		    oh0 = ABS(ligtyp[TriS[i].lig[0]]->ohsame);
76912 		    oh1 = ABS(ligtyp[TriS[i].lig[1]]->ohsame);
76913 		    if (oh0 == oh1) TriS[i].active = 0;
76914 		}
76915 	   } else if (TriS[i].grp[0] == H_DON && TriS[i].grp[2] == H_DON) {
76916 		if (ligtyp[TriS[i].lig[0]]->ohlig &&
76917 		    ligtyp[TriS[i].lig[2]]->ohlig) {
76918 		    oh0 = ABS(ligtyp[TriS[i].lig[0]]->ohsame);
76919 		    oh2 = ABS(ligtyp[TriS[i].lig[2]]->ohsame);
76920 		    if (oh0 == oh2) TriS[i].active = 0;
76921 		}
76922 	   } else if (TriS[i].grp[1] == H_DON && TriS[i].grp[2] == H_DON) {
76923 		if (ligtyp[TriS[i].lig[1]]->ohlig &&
76924 		    ligtyp[TriS[i].lig[2]]->ohlig) {
76925 		    oh1 = ABS(ligtyp[TriS[i].lig[1]]->ohsame);
76926 		    oh2 = ABS(ligtyp[TriS[i].lig[2]]->ohsame);
76927 		    if (oh1 == oh2) TriS[i].active = 0;
76928 		}
76929 	   } else {
76930 		n++;
76931 	   }
76932 	}
76933     }
76934 
76935     n = 0;
76936     for (i=0; i < ntriS; i++) {
76937 	if (TriS[i].active) {
76938 	   TriS[n] = TriS[i];
76939 	   n++;
76940 	}
76941     }
76942     ntriS = n;
76943 
76944     fprintf(stderr,"Sub_Selection_Tris: ntris reduced %d \n",ntriS);
76945 }
76946 
76947 #define CHOSENCONF 8
76948 
Monitor_AccDon(n1,n2,p1,p2,npair,npairl)76949 int Monitor_AccDon(n1,n2,p1,p2,npair,npairl)
76950 int n1;
76951 int n2;
76952 int *p1;
76953 int *p2;
76954 int *npair;
76955 int *npairl;
76956 {
76957 
76958    int i,j,l,Conf;
76959    double r,tt,toangs2,DCKCOFF2,R2MIN;
76960 
76961    toangs2 = TOANG*TOANG;
76962    DCKCOFF2 = dckcoff*dckcoff;
76963 
76964    R2MIN = BIGD;
76965 
76966 
76967 // acc - don combination
76968 
76969    *npair = 0; *npairl = 0;
76970 
76971    for (i=0; i < n1; i++) {
76972 
76973      for (j=0; j < n2; j++) {
76974 
76975 	if (ligtyp[p2[j]]->ohlig && ligtyp[p2[j]]->ohsame < 0) {
76976 
76977 	   if (CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p2[j]]->ORI) &&
76978 		ligtyp[p1[i]]->frag[0] == ligtyp[p2[j]]->frag[0]) {
76979 
76980 	      r = 0.0;
76981 
76982 	      for (l=0; l < 3; l++) {
76983 	         tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p2[j]]->ORI[l];
76984 	         r = r + tt*tt;
76985 	      }
76986 
76987 	      if (r*toangs2 < R2MIN && r*toangs2 > DCKCMIN*DCKCMIN) {
76988  		R2MIN = r*toangs2;
76989 		*npair = *npair + 1;
76990 		if ((ligtyp[p1[i]]->link != ligtyp[p2[j]]->link) ||
76991 		    !ligtyp[p1[i]]->ohlig || !ligtyp[p2[j]]->ohlig)
76992 			*npairl = *npairl + 1;
76993 	      }
76994 
76995 	   }
76996 	}
76997      }
76998    }
76999 
77000 // acc - acc combination
77001 
77002    for (i=0; i < n1; i++) {
77003 
77004      for (j=0; j < n1; j++) {
77005 
77006 	if (i != j) {
77007 
77008 	   if (CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p1[j]]->ORI) &&
77009 		ligtyp[p1[i]]->frag[0] == ligtyp[p1[j]]->frag[0]) {
77010 
77011 	      r = 0.0;
77012 
77013 	      for (l=0; l < 3; l++) {
77014 	         tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p1[j]]->ORI[l];
77015 	         r = r + tt*tt;
77016 	      }
77017 
77018 	      if (r*toangs2 < R2MIN && r*toangs2 > DCKCMIN*DCKCMIN) {
77019  		R2MIN = r*toangs2;
77020 		*npair = *npair + 1;
77021 		*npairl = *npairl + 1;
77022 	      }
77023 
77024 	   }
77025 	}
77026      }
77027    }
77028 
77029 // don - don combination
77030 
77031    for (i=0; i < n2; i++) {
77032 
77033      for (j=0; j < n2; j++) {
77034 
77035 	if (i != j) {
77036 
77037 	 if ((ligtyp[p2[i]]->ohlig && ligtyp[p2[i]]->ohsame < 0) &&
77038 	     (ligtyp[p2[j]]->ohlig && ligtyp[p2[j]]->ohsame < 0)) {
77039 	   if (CmpORI(ligtyp[p2[i]]->ORI,ligtyp[p2[j]]->ORI) &&
77040 		ligtyp[p2[i]]->frag[0] == ligtyp[p2[j]]->frag[0]) {
77041 
77042 	      r = 0.0;
77043 
77044 	      for (l=0; l < 3; l++) {
77045 	         tt = ligtyp[p2[i]]->ORI[l] - ligtyp[p2[j]]->ORI[l];
77046 	         r = r + tt*tt;
77047 	      }
77048 
77049 	      if (r*toangs2 < R2MIN && r*toangs2 > DCKCMIN*DCKCMIN) {
77050  		R2MIN = r*toangs2;
77051 		*npair = *npair + 1;
77052 		*npairl = *npairl + 1;
77053 	      }
77054 
77055 	   }
77056 	 }
77057 	}
77058      }
77059    }
77060 
77061 fprintf(stderr,"MONITOR_ACCDON: R2MIN %.3f DCKCOFF %.3f\n",R2MIN,DCKCOFF2);
77062    if (R2MIN != BIGD) {
77063 	if (R2MIN > DCKCOFF2) {
77064 	   dckcoff = 15.0;
77065 fprintf(stderr,"NEW DCKCOFF %.3f\n",dckcoff);
77066 // there is a distance bigger  than DCKCOFF in the same fragment.
77067 // Increase dckcoff
77068 	   return(1);
77069 	} else {
77070 // there is a distance smaller than DCKCOFF in the same fragment
77071 	   return(0);
77072 	}
77073    } else {
77074 // there is a NO AAC/DON pair in the same fragment.
77075 	return(1);
77076    }
77077 }
77078 
Reduce_Pairs(int FiltAD,int * npairl)77079 void Reduce_Pairs(int FiltAD,int *npairl)
77080 {
77081    int i,j,n,np;
77082 
77083    n = *npairl; np = 0;
77084 
77085    for (i=0; i < n; i++) {
77086 	if (PAIRT[i] == FiltAD) {
77087 
77088 	   ADPAIR1[np] = ADPAIR1[i];
77089 	   ADPAIR2[np] = ADPAIR2[i];
77090 	   PAIRT[np] = PAIRT[i];
77091 	   np++;
77092 	}
77093    }
77094    *npairl = np;
77095 
77096 if (debugdck) fprintf(stderr,"Reduce_Pairs: New np %d\n\n",np);
77097 if (debugdck) fprintf(stderr,"Reduce_Pairs: ADPAIR1[0] %d ADPAIR2[0] %d\n\n",ADPAIR1[0],ADPAIR2[0]);
77098 
77099 }
77100 
Monitor_AccDon_Conformers(n1,n2,p1,p2,npair,npairl)77101 int Monitor_AccDon_Conformers(n1,n2,p1,p2,npair,npairl)
77102 int n1;
77103 int n2;
77104 int *p1;
77105 int *p2;
77106 int *npair;
77107 int *npairl;
77108 {
77109 
77110    int i,j,l,Conf;
77111    double r,tt,toangs2,DCKCOFF2,*R2MINAD,*R2MINAA,*R2MINDD;
77112    double R2MINEST,R2MINADEST,R2MINAAEST,R2MINDDEST;
77113 
77114    R2MINAD = (double *) malloc(sizeof(double)*ntrif);
77115    R2MINAA = (double *) malloc(sizeof(double)*ntrif);
77116    R2MINDD = (double *) malloc(sizeof(double)*ntrif);
77117 
77118    toangs2 = TOANG*TOANG;
77119    DCKCOFF2 = dckcoff*dckcoff;
77120 
77121    for (i=0; i < ntrif; i++) {
77122 	R2MINAD[i] = BIGD;
77123 	R2MINAA[i] = BIGD;
77124 	R2MINDD[i] = BIGD;
77125    }
77126 
77127 
77128 // acc - don combination
77129 
77130    *npair = 0; *npairl = 0;
77131 
77132    for (i=0; i < n1; i++) {
77133 
77134      for (j=0; j < n2; j++) {
77135 
77136 	if (ligtyp[p2[j]]->ohlig && ligtyp[p2[j]]->ohsame < 0) {
77137 
77138 	   if (CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p2[j]]->ORI) &&
77139 		ligtyp[p1[i]]->conf == ligtyp[p2[j]]->conf &&
77140 		ligtyp[p1[i]]->link != ligtyp[p2[j]]->link) {
77141 
77142 	      Conf = ligtyp[p1[i]]->conf;
77143 	      r = 0.0;
77144 
77145 	      for (l=0; l < 3; l++) {
77146 	         tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p2[j]]->ORI[l];
77147 	         r = r + tt*tt;
77148 	      }
77149 
77150 	      if (r*toangs2 < R2MINAD[Conf] && r*toangs2 > DCKCMIN*DCKCMIN) {
77151  		R2MINAD[Conf] = r*toangs2;
77152 		*npair = *npair + 1;
77153 		if ((ligtyp[p1[i]]->link != ligtyp[p2[j]]->link) ||
77154 		    !ligtyp[p1[i]]->ohlig || !ligtyp[p2[j]]->ohlig)
77155 			ADPAIR1[*npairl] =  ligtyp[p1[i]]->frag[0];
77156 			ADPAIR2[*npairl] =  ligtyp[p2[j]]->frag[0];
77157 			PAIRT[*npairl] =  1;
77158 			*npairl = *npairl + 1;
77159 	      }
77160 
77161 	   }
77162 	}
77163      }
77164    }
77165 
77166 // acc - acc combination
77167 
77168    for (i=0; i < n1; i++) {
77169 
77170      for (j=0; j < n1; j++) {
77171 
77172 	if (i != j) {
77173 
77174 	   if (CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p1[j]]->ORI) &&
77175 		ligtyp[p1[i]]->conf == ligtyp[p1[j]]->conf) {
77176 
77177 	      Conf = ligtyp[p1[i]]->conf;
77178 
77179 	      r = 0.0;
77180 
77181 	      for (l=0; l < 3; l++) {
77182 	         tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p1[j]]->ORI[l];
77183 	         r = r + tt*tt;
77184 	      }
77185 
77186 	      if (r*toangs2 < R2MINAA[Conf] && r*toangs2 > DCKCMIN*DCKCMIN) {
77187  		R2MINAA[Conf] = r*toangs2;
77188 		*npair = *npair + 1;
77189 		ADPAIR1[*npairl] =  ligtyp[p1[i]]->frag[0];
77190 		ADPAIR2[*npairl] =  ligtyp[p1[j]]->frag[0];
77191 		PAIRT[*npairl] =  2;
77192 		*npairl = *npairl + 1;
77193 	      }
77194 
77195 	   }
77196 	}
77197      }
77198    }
77199 
77200 // don - don combination
77201 
77202    for (i=0; i < n2; i++) {
77203 
77204      for (j=0; j < n2; j++) {
77205 
77206 	if (i != j) {
77207 
77208 	 if ((ligtyp[p2[i]]->ohlig && ligtyp[p2[i]]->ohsame < 0) &&
77209 	     (ligtyp[p2[j]]->ohlig && ligtyp[p2[j]]->ohsame < 0)) {
77210 	   if (CmpORI(ligtyp[p2[i]]->ORI,ligtyp[p2[j]]->ORI) &&
77211 		ligtyp[p2[i]]->conf == ligtyp[p2[j]]->conf) {
77212 
77213 	      Conf = ligtyp[p2[i]]->conf;
77214 	      r = 0.0;
77215 
77216 	      for (l=0; l < 3; l++) {
77217 	         tt = ligtyp[p2[i]]->ORI[l] - ligtyp[p2[j]]->ORI[l];
77218 	         r = r + tt*tt;
77219 	      }
77220 
77221 	      if (r*toangs2 < R2MINDD[Conf] && r*toangs2 > DCKCMIN*DCKCMIN) {
77222  		R2MINDD[Conf] = r*toangs2;
77223 		*npair = *npair + 1;
77224 		ADPAIR1[*npairl] =  ligtyp[p2[i]]->frag[0];
77225 		ADPAIR2[*npairl] =  ligtyp[p2[j]]->frag[0];
77226 		PAIRT[*npairl] =  3;
77227 		*npairl = *npairl + 1;
77228 	      }
77229 
77230 	   }
77231 	 }
77232 	}
77233      }
77234    }
77235 
77236    R2MINADEST = -BIGD;
77237    R2MINAAEST = -BIGD;
77238    R2MINDDEST = -BIGD;
77239 
77240    for (i=0; i < ntrif; i++) {
77241 	if (R2MINAD[i] != BIGD) {
77242 	   if (R2MINAD[i] > R2MINADEST) R2MINADEST = R2MINAD[i];
77243 	}
77244 	if (R2MINAA[i] != BIGD) {
77245 	   if (R2MINAA[i] > R2MINAAEST) R2MINAAEST = R2MINAA[i];
77246 	}
77247 	if (R2MINDD[i] != BIGD) {
77248 	   if (R2MINDD[i] > R2MINDDEST) R2MINDDEST = R2MINDD[i];
77249 	}
77250    }
77251 
77252    R2MINEST = R2MINADEST;
77253    if (R2MINEST < R2MINAAEST) R2MINEST = R2MINAAEST;
77254    if (R2MINEST < R2MINDDEST) R2MINEST = R2MINDDEST;
77255 
77256    free(R2MINAD);
77257    free(R2MINAA);
77258    free(R2MINDD);
77259 
77260    if (R2MINEST != -BIGD) {
77261 	if (R2MINEST > DCKCOFF2) {
77262 	   dckcoff = 15.0;
77263 	   FiltAD = 0;
77264 	   if (R2MINEST == R2MINADEST) FiltAD = 1;
77265 	   if (R2MINEST == R2MINAAEST) FiltAD = 2;
77266 	   if (R2MINEST == R2MINDDEST) FiltAD = 3;
77267 	   Reduce_Pairs(FiltAD,npairl);
77268 
77269 	   if (debugdck) fprintf(stderr,"NEW DCKCOFF %.3f\n\n",dckcoff);
77270 // there is a distance bigger  than DCKCOFF in the same fragment.
77271 // Increase dckcoff
77272 	   return(1);
77273 	} else {
77274 // there is a distance smaller than DCKCOFF in the same fragment
77275 	   return(0);
77276 	}
77277    } else {
77278 // there is a NO AAC/DON pair in the same fragment.
77279 	return(1);
77280    }
77281 }
77282 
Harvest_Triples(n1,n2,n3,p1,p2,p3)77283 void Harvest_Triples(n1,n2,n3,p1,p2,p3)
77284 int n1;
77285 int n2;
77286 int n3;
77287 int *p1;
77288 int *p2;
77289 int *p3;
77290 {
77291 // Harvest Triples creates triples of interaction points by sampling
77292 // three points from different or the same interaction arrays p1,p2,p3
77293 // where each distance between the three interaction points
77294 // must be smaller than DCKCOFF
77295 //
77296 // currently only triples belonging to ONE fragment are sampled !!!
77297 //
77298 
77299    int i,j,k,l,p1isp2,p1isp3,p2isp3,SingleFrag,SameFrag,Conf;
77300    int OHSAME12,OHSAME13,OHSAME23;
77301    double r,p,q,dd,tt,toangs2,DCKCOFF2;
77302    float rr,pp,qq;
77303 
77304    toangs2 = TOANG*TOANG;
77305    DCKCOFF2 = dckcoff*dckcoff;
77306 
77307    p1isp2 = 0; p1isp3 = 0; p2isp3 = 0;
77308 
77309    if (p1 == p2) p1isp2 = 1;
77310    if (p1 == p3) p1isp3 = 1;
77311    if (p2 == p3) p2isp3 = 1;
77312 
77313 
77314    for (i=0; i < n1; i++) {
77315 
77316      for (j=0; j < n2; j++) {
77317 
77318 	if (!p1isp2 || (p1isp2 && i != j)) {
77319 
77320 	   OHSAME12 = 0;
77321 	   if (ligtyp[p1[i]]->ohsame && ligtyp[p2[j]]->ohsame) {
77322 		if (ABS(ligtyp[p1[i]]->ohsame) == ABS(ligtyp[p2[j]]->ohsame))
77323 			OHSAME12 = 1;
77324 	   }
77325 	   if (CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p2[j]]->ORI) &&
77326 		ligtyp[p1[i]]->conf == ligtyp[p2[j]]->conf && !OHSAME12) {
77327 
77328 	      r = 0.0;
77329 
77330 	      for (l=0; l < 3; l++) {
77331 	         tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p2[j]]->ORI[l];
77332 	         r = r + tt*tt;
77333 	      }
77334 
77335 	      if (r*toangs2 > DCKCOFF2) continue;
77336 
77337 	      for (k=0; k < n3; k++) {
77338 
77339 		Conf = -1;
77340 
77341 		OHSAME13 = 0;
77342 		if (ligtyp[p1[i]]->ohsame && ligtyp[p3[k]]->ohsame) {
77343 		    if (ABS(ligtyp[p1[i]]->ohsame) ==
77344 			ABS(ligtyp[p3[k]]->ohsame))
77345 				OHSAME13 = 1;
77346 		}
77347 
77348 		OHSAME23 = 0;
77349 		if (ligtyp[p2[j]]->ohsame && ligtyp[p3[k]]->ohsame) {
77350 		    if (ABS(ligtyp[p2[j]]->ohsame) ==
77351 			ABS(ligtyp[p3[k]]->ohsame))
77352 				OHSAME23 = 1;
77353 		}
77354 
77355 		if ((!p1isp3 || (p1isp3 && i != k) &&
77356 		     !p2isp3 || (p2isp3 && j != k) ) &&
77357 		    CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p3[k]]->ORI) &&
77358 		    CmpORI(ligtyp[p2[j]]->ORI,ligtyp[p3[k]]->ORI) &&
77359 		    ligtyp[p2[j]]->conf == ligtyp[p3[k]]->conf &&
77360 		    !OHSAME13 && !OHSAME23
77361 		   ) {
77362 
77363 		   if ( ligtyp[p1[i]]->conf != -1 ||
77364 			ligtyp[p2[j]]->conf != -1 ||
77365 			ligtyp[p3[k]]->conf != -1) {
77366 			Conf = ligtyp[p1[i]]->conf;
77367 		   }
77368 
77369 		   SameFrag = 0;
77370 		   if (ligtyp[p1[i]]->frag[0] == ligtyp[p2[j]]->frag[0] &&
77371 			ligtyp[p1[i]]->frag[0] == ligtyp[p3[k]]->frag[0])
77372 			SameFrag = 1;
77373 
77374 		   SingleFrag = 0;
77375 		   if (ligtyp[p1[i]]->nfrag == 1 && ligtyp[p2[j]]->nfrag == 1 &&
77376 			ligtyp[p3[k]]->nfrag == 1) SingleFrag = 1;
77377 
77378 		   if ((SameFrag && SingleFrag) || Conf != -1) {
77379 
77380 			p = 0.0; q = 0.0;
77381 
77382 			for (l=0; l < 3; l++) {
77383 			   tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p3[k]]->ORI[l];
77384 			   p = p + tt*tt;
77385 			   tt = ligtyp[p2[j]]->ORI[l] - ligtyp[p3[k]]->ORI[l];
77386 			   q = q + tt*tt;
77387 			}
77388 
77389 			if (p*toangs2 > DCKCOFF2) continue;
77390 			if (q*toangs2 > DCKCOFF2) continue;
77391 
77392 			TriS[ntriS].grp[0] = ligtyp[p1[i]]->type;
77393 			TriS[ntriS].atindx[0] = ligtyp[p1[i]]->atom[0];
77394 			TriS[ntriS].lig[0] = p1[i];
77395 			TriS[ntriS].ohlig[0] = ligtyp[p1[i]]->ohlig;
77396 
77397 			TriS[ntriS].grp[1] = ligtyp[p2[j]]->type;
77398 			TriS[ntriS].atindx[1] = ligtyp[p2[j]]->atom[0];
77399 			TriS[ntriS].lig[1] = p2[j];
77400 			TriS[ntriS].ohlig[1] = ligtyp[p2[j]]->ohlig;
77401 
77402 			TriS[ntriS].grp[2] = ligtyp[p3[k]]->type;
77403 			TriS[ntriS].atindx[2] = ligtyp[p3[k]]->atom[0];
77404 			TriS[ntriS].lig[2] = p3[k];
77405 			TriS[ntriS].ohlig[2] = ligtyp[p3[k]]->ohlig;
77406 
77407 			for (l=0; l < 3; l++) {
77408 			   TriS[ntriS].p1[l] = (float) ligtyp[p1[i]]->ORI[l];
77409 	      		   TriS[ntriS].p2[l] = (float) ligtyp[p2[j]]->ORI[l];
77410 			   TriS[ntriS].p3[l] = (float) ligtyp[p3[k]]->ORI[l];
77411 			}
77412 
77413 			TriS[ntriS].frag = ligtyp[p2[j]]->frag[0];
77414 			TriS[ntriS].conf = Conf;
77415 			TriS[ntriS].nconf = 0;
77416 			TriS[ntriS].active = 1;
77417 
77418 			ntriS++;
77419 			if (ntriS == MAXSTRI - 1) return;
77420 		   }
77421 	        }
77422 	      }
77423 	   }
77424 	}
77425      }
77426    }
77427 }
77428 
DetAD(int i,int j)77429 int DetAD(int i, int j)
77430 {
77431    if (ligtyp[i]->type == H_DON && ligtyp[j]->type == H_ACC) return(1);
77432    if (ligtyp[i]->type == H_ACC && ligtyp[j]->type == H_DON) return(1);
77433    if (ligtyp[i]->type == H_ACC && ligtyp[j]->type == H_ACC) return(2);
77434    if (ligtyp[i]->type == H_DON && ligtyp[j]->type == H_DON) return(3);
77435    return(0);
77436 }
77437 
Harvest_Triples_NoFrag(n1,n2,n3,p1,p2,p3)77438 void Harvest_Triples_NoFrag(n1,n2,n3,p1,p2,p3)
77439 int n1;
77440 int n2;
77441 int n3;
77442 int *p1;
77443 int *p2;
77444 int *p3;
77445 {
77446 // Harvest Triples creates triples of interaction points by sampling
77447 // three points from different or the same interaction arrays p1,p2,p3
77448 // where each distance between the three interaction points
77449 // must be smaller than DCKCOFF
77450 //
77451 // currently only triples belonging to ONE fragment are sampled !!!
77452 //
77453 
77454    int i,j,k,l,p1isp2,p1isp3,p2isp3,SingleFrag,SameFrag,Conf;
77455    int OHSAME12,OHSAME13,OHSAME23;
77456    double r,p,q,dd,tt,toangs2,DCKCOFF2;
77457    float rr,pp,qq;
77458 
77459    toangs2 = TOANG*TOANG;
77460    DCKCOFF2 = dckcoff*dckcoff;
77461 
77462    p1isp2 = 0; p1isp3 = 0; p2isp3 = 0;
77463 
77464    if (p1 == p2) p1isp2 = 1;
77465    if (p1 == p3) p1isp3 = 1;
77466    if (p2 == p3) p2isp3 = 1;
77467 
77468 
77469    for (i=0; i < n1; i++) {
77470 
77471      for (j=0; j < n2; j++) {
77472 
77473 	if (!p1isp2 || (p1isp2 && i != j)) {
77474 
77475 	   OHSAME12 = 0;
77476 	   if (ligtyp[p1[i]]->ohsame && ligtyp[p2[j]]->ohsame) {
77477 		if (ABS(ligtyp[p1[i]]->ohsame) ==
77478 		    ABS(ligtyp[p2[j]]->ohsame))
77479 			OHSAME12 = 1;
77480 	   }
77481 
77482 	   if (CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p2[j]]->ORI) &&
77483 		ligtyp[p1[i]]->conf == ligtyp[p2[j]]->conf && !OHSAME12) {
77484 
77485 	      r = 0.0;
77486 
77487 	      for (l=0; l < 3; l++) {
77488 	         tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p2[j]]->ORI[l];
77489 	         r = r + tt*tt;
77490 	      }
77491 
77492 	      if (DetAD(p1[i],p2[j]) == FiltAD) {
77493 		 if (r*toangs2 > DCKCOFF2) continue;
77494 	      } else {
77495 		 if (r*toangs2 > 100.0) continue;
77496 	      }
77497 
77498 	      for (k=0; k < n3; k++) {
77499 
77500 		Conf = -1;
77501 
77502 		OHSAME13 = 0;
77503 		if (ligtyp[p1[i]]->ohsame && ligtyp[p3[k]]->ohsame) {
77504 		   if (ABS(ligtyp[p1[i]]->ohsame) ==
77505 		       ABS(ligtyp[p3[k]]->ohsame))
77506 			OHSAME13 = 1;
77507 		}
77508 
77509 		OHSAME23 = 0;
77510 		if (ligtyp[p2[j]]->ohsame && ligtyp[p3[k]]->ohsame) {
77511 		    if (ABS(ligtyp[p2[j]]->ohsame) ==
77512 			ABS(ligtyp[p3[k]]->ohsame))
77513 				OHSAME23 = 1;
77514 		}
77515 
77516 		if ((!p1isp3 || (p1isp3 && i != k) &&
77517 		     !p2isp3 || (p2isp3 && j != k) ) &&
77518 		    CmpORI(ligtyp[p1[i]]->ORI,ligtyp[p3[k]]->ORI) &&
77519 		    CmpORI(ligtyp[p2[j]]->ORI,ligtyp[p3[k]]->ORI) &&
77520 		    ligtyp[p1[i]]->conf == ligtyp[p3[k]]->conf &&
77521 		    ligtyp[p2[j]]->conf == ligtyp[p3[k]]->conf &&
77522 		    !OHSAME13 && !OHSAME23
77523 		   ) {
77524 
77525 		   Conf = ligtyp[p1[i]]->conf;
77526 
77527 		   if (Conf != -1) {
77528 
77529 			p = 0.0; q = 0.0;
77530 
77531 			for (l=0; l < 3; l++) {
77532 			   tt = ligtyp[p1[i]]->ORI[l] - ligtyp[p3[k]]->ORI[l];
77533 			   p = p + tt*tt;
77534 			   tt = ligtyp[p2[j]]->ORI[l] - ligtyp[p3[k]]->ORI[l];
77535 			   q = q + tt*tt;
77536 			}
77537 
77538 			if (DetAD(p1[i],p3[k]) == FiltAD) {
77539 	 		   if (p*toangs2 > DCKCOFF2) continue;
77540 			} else {
77541 			   if (p*toangs2 > 100.0) continue;
77542 			}
77543 
77544 			if (DetAD(p2[j],p3[k]) == FiltAD) {
77545 	 		   if (q*toangs2 > DCKCOFF2) continue;
77546 			} else {
77547 			   if (q*toangs2 > 100.0) continue;
77548 			}
77549 
77550 			TriS[ntriS].grp[0] = ligtyp[p1[i]]->type;
77551 			TriS[ntriS].atindx[0] = ligtyp[p1[i]]->atom[0];
77552 			TriS[ntriS].lig[0] = p1[i];
77553 			TriS[ntriS].ohlig[0] = ligtyp[p1[i]]->ohlig;
77554 
77555 			TriS[ntriS].grp[1] = ligtyp[p2[j]]->type;
77556 			TriS[ntriS].atindx[1] = ligtyp[p2[j]]->atom[0];
77557 			TriS[ntriS].lig[1] = p2[j];
77558 			TriS[ntriS].ohlig[1] = ligtyp[p2[j]]->ohlig;
77559 
77560 			TriS[ntriS].grp[2] = ligtyp[p3[k]]->type;
77561 			TriS[ntriS].atindx[2] = ligtyp[p3[k]]->atom[0];
77562 			TriS[ntriS].lig[2] = p3[k];
77563 			TriS[ntriS].ohlig[2] = ligtyp[p3[k]]->ohlig;
77564 
77565 			for (l=0; l < 3; l++) {
77566 			   TriS[ntriS].p1[l] = (float) ligtyp[p1[i]]->ORI[l];
77567 	      		   TriS[ntriS].p2[l] = (float) ligtyp[p2[j]]->ORI[l];
77568 			   TriS[ntriS].p3[l] = (float) ligtyp[p3[k]]->ORI[l];
77569 			}
77570 
77571 			TriS[ntriS].conf = Conf;
77572 //			TriS[ntriS].nconf = 0;
77573 			TriS[ntriS].nconf = 1;
77574 
77575 			if (TriS[ntriS].conf == -1) {
77576 			   TriS[ntriS].frag = ligtyp[p2[j]]->frag[0];
77577 			} else {
77578 			   TriS[ntriS].frag = -1;
77579 			   TriS[ntriS].frags[0] = ligtyp[p1[i]]->frag[0];
77580 			   TriS[ntriS].frags[1] = ligtyp[p2[j]]->frag[0];
77581 			   TriS[ntriS].frags[2] = ligtyp[p3[k]]->frag[0];
77582 			}
77583 			TriS[ntriS].active = 1;
77584 
77585 			ntriS++;
77586 			if (ntriS == MAXSTRI - 1) return;
77587 		   }
77588 	        }
77589 	      }
77590 	   }
77591 	}
77592      }
77593    }
77594 }
77595 
Gen_triples()77596 void Gen_triples()
77597 {
77598    int i,j,l;
77599 
77600    for (i=0; i < ntriS; i++) {
77601      if (TriS[i].active) {
77602 // these three lines may do nothing since TriS[i].d12 has not been set
77603 	Tri1.d12 = TriS[i].d12;
77604 	Tri1.d13 = TriS[i].d13;
77605 	Tri1.d23 = TriS[i].d23;
77606 	Tri1.grp[0] = TriS[i].grp[0];
77607 	Tri1.grp[1] = TriS[i].grp[1];
77608 	Tri1.grp[2] = TriS[i].grp[2];
77609 	Tri1.lig[0] = TriS[i].lig[0];
77610 	Tri1.lig[1] = TriS[i].lig[1];
77611 	Tri1.lig[2] = TriS[i].lig[2];
77612 	Tri1.ohlig[0] = TriS[i].ohlig[0];
77613 	Tri1.ohlig[1] = TriS[i].ohlig[1];
77614 	Tri1.ohlig[2] = TriS[i].ohlig[2];
77615 	for (l=0; l < 3; l++) {
77616 	   Tri1.p1[l] = TriS[i].p1[l];
77617 	   Tri1.p2[l] = TriS[i].p2[l];
77618 	   Tri1.p3[l] = TriS[i].p3[l];
77619 	}
77620 	Tri1.frag = TriS[i].frag;
77621 	Tri1.conf = TriS[i].conf;
77622 	Tri1.nconf = TriS[i].nconf;
77623 	if (TriS[i].conf != -1) {
77624 	   Tri1.frags[0] = TriS[i].frags[0];
77625 	   Tri1.frags[1] = TriS[i].frags[1];
77626 	   Tri1.frags[2] = TriS[i].frags[2];
77627 	}
77628 	Calc_Centroid(&Tri1);
77629 
77630 	Find_Triangle_Match(Tri1,i);
77631 	if (ntris == MAXTRI - 1) return;
77632      }
77633    }
77634 }
77635 
prtypes(ityp,n,iacc,nacc,idon,ndon,iphec,nphec,ipher,npher,iaro,naro)77636 void prtypes(ityp,n,iacc,nacc,idon,ndon,iphec,nphec,ipher,npher,iaro,naro)
77637 INCRSTRU **ityp;
77638 int n;
77639 int *iacc;
77640 int *nacc;
77641 int *idon;
77642 int *ndon;
77643 int *iphec;
77644 int *nphec;
77645 int *ipher;
77646 int *npher;
77647 int *iaro;
77648 int *naro;
77649 {
77650    int i;
77651 
77652    *nacc = 0; *ndon = 0; *nphec = 0; *npher = 0; *naro = 0;
77653 
77654    if (n == 0) return;
77655 
77656    for (i=0; i < n; i++) {
77657 	switch(ityp[i]->type) {
77658 	case H_ACC:
77659 	   fprintf(stderr,"%d H_ACC\n",i);
77660 	   iacc[*nacc] = i;
77661 	   (*nacc)++;
77662 	   break;
77663 	case H_DON:
77664 	   fprintf(stderr,"%d H_DON\n",i);
77665 	   idon[*ndon] = i;
77666 	   (*ndon)++;
77667 	   break;
77668 	case PHENYL_CENTER:
77669 	   fprintf(stderr,"%d PHENYL_CENTER\n",i);
77670 	   iphec[*nphec] = i;
77671 	   (*nphec)++;
77672 	   break;
77673 	case PHENYL_RING:
77674 	   fprintf(stderr,"%d PHENYL_RING\n",i);
77675 	   ipher[*npher] = i;
77676 	   (*npher)++;
77677 	   break;
77678 	case CH:
77679 	case CH2:
77680 	case CH3:
77681 	case SULFUR:
77682 	case ARO:
77683 	   fprintf(stderr,"%d ARO_GROUP\n",i);
77684 	   iaro[*naro] = i;
77685 	   (*naro)++;
77686 	   break;
77687 	default:
77688 	   fprintf(stderr,"%d Other\n",i);
77689 	}
77690    }
77691 
77692    fprintf(stderr,"\n");
77693 }
77694 
OrgLig()77695 void OrgLig()
77696 {
77697      int i,j,k;
77698      int grpj,grpk;
77699      double t0[3],R1[4][4];
77700      float etot,OutO[3];
77701 
77702      for (i=0; i < 3; i++) t0[i] = 0.0;
77703      for (i=0; i < 4; i++) {
77704         for (j=0; j < 4; j++) {
77705 	  if (i == j) {
77706 	   R1[i][j] = 1.0;
77707 	  } else {
77708 	   R1[i][j] = 0.0;
77709 	  }
77710         }
77711      }
77712 
77713      if (TriArr[0] == NULL) {
77714 	TriArr[0] = (TRISTRU *) malloc(sizeof(TRISTRU));
77715 	memcpy(TriArr[0], &EmpTri, sizeof(TRISTRU));
77716      }
77717 
77718      allConf(&TriArr[0]->coo,ndocka);
77719 
77720      if (TriArr[0]->coo == NULL) return;
77721 
77722      for (i=0; i<ndocka; i++) {
77723 	for (j=0; j<3; j++) {
77724 	   TriArr[0]->coo[i*3+j] = DCKxyz.coo[i*3+j];
77725 	}
77726      }
77727 
77728      prE = 1;
77729      etot = 0.0;
77730      for (j=0; j < lintp; j++) {
77731 	grpj = Find_Group(ligtyp[j]->type);
77732 	grpj = Find_Matching_Group(grpj);
77733 	for (k=0; k < nintp; k++) {
77734 	   grpk = Find_Group(inttyp[k]->type);
77735 	   if (grpj == grpk) {
77736 	      etot = etot +
77737 	      CalInt(k,j,ligtyp[j]->points,t0,R1,R1,OutO,OutO,1);
77738 	   }
77739 	}
77740      }
77741      TriArr[0]->e12 = etot;
77742      prE = 0;
77743      ntris++;
77744 }
77745 
RemCloseC()77746 void RemCloseC()
77747 {
77748    double dd[4],tt,CLOSED;
77749    int i,j,k,l,m,doit;
77750 
77751    CLOSED = CLOSEC/toangs;
77752 
77753    for (i = 0; i < ntris; i++ ) {
77754 	if (TriArr[i] != NULL) {
77755 	   for (j = 0; j < ndocka; j++ ) {
77756 		for (k = 0; k < nintp; k++ ) {
77757 		   doit = 0;
77758 		   for (m = 0; m < inttyp[k]->area.n; m++ ) {
77759 			dd[m] = 0.0;
77760 			for (l = 0; l < 3; l++ ) {
77761 			   tt = TriArr[i]->coo[j*3+l] - inttyp[k]->c[m][l];
77762 			   dd[m] = dd[m] + tt*tt;
77763 			}
77764 	 		dd[m] = sqrt(dd[m]);
77765 			if (dd[m] < CLOSED) {
77766 			   doit = 1;
77767 			   break;
77768 			}
77769 		   }
77770 		   if (doit) break;
77771 		}
77772 		if (doit) break;
77773 	   }
77774 	   if (doit) {
77775 		if (TriArr[i]->coo != NULL) free(TriArr[i]->coo);
77776 		free(TriArr[i]);
77777 	        TriArr[i] = NULL;
77778 	   }
77779 	}
77780    }
77781 
77782    Compress_Tri_L();
77783 
77784 }
77785 
RemCloseC_One(int L,int all)77786 void RemCloseC_One(int L,int all)
77787 {
77788 // Check triangle ligand coordinates TriArr[L]->coo for bunps against
77789 // all interaction points coordinates of the atoms that define the
77790 // interaction geometry.
77791 // If the triangle bumps remove it.
77792 //
77793 // all = 0 check the whole of ligand
77794 // all = 1 check only the the atoms belonging to the fragment the
77795 //         ligand triangle belong to
77796 //
77797 // RemCloseC_One is called once after adding a new triangle in
77798 // Find_Triangle_Match <== Gen_triple
77799 
77800    double dd[4],tt,CLOSED;
77801    int i,j,k,l,m,ido;
77802 
77803 fprintf(stderr,"Entering RemCloseC_One: \n");
77804    CLOSED = CLOSEC/toangs;
77805 
77806    if (TriArr[L] != NULL) {
77807 	for (k = 0; k < nintp; k++ ) {
77808 	    for (j = 0; j < ndocka; j++ ) {
77809 		ido = 0;
77810 		if (!all) {
77811 		   if (TriArr[L]->conf == -1) {
77812 			if (singleb.ifrg[k] == TriArr[L]->frag) ido = 1;
77813 		   } else {
77814 			if (singleb.ifrg[k] == TriArr[L]->frags[0] ||
77815 	    		    singleb.ifrg[k] == TriArr[L]->frags[1] ||
77816 	    		    singleb.ifrg[k] == TriArr[L]->frags[2]) ido = 1;
77817 		   }
77818 		} else {
77819 		   ido = 1;
77820 		}
77821 		if (ido) {
77822 		   for (m = 0; m < inttyp[k]->area.n; m++ ) {
77823 			dd[m] = 0.0;
77824 			for (l = 0; l < 3; l++ ) {
77825 			   tt = TriArr[L]->coo[j*3+l] - inttyp[k]->c[m][l];
77826 			   dd[m] = dd[m] + tt*tt;
77827 			}
77828 			dd[m] = sqrt(dd[m]);
77829 			if (dd[m] < CLOSED) {
77830 			   if (TriArr[L]->coo != NULL) free(TriArr[L]->coo);
77831 			   free(TriArr[L]);
77832 	        	   TriArr[L] = NULL;
77833 			   ntris--;
77834 			   return;
77835 			}
77836 		   }
77837 		}
77838 	    }
77839 	}
77840    }
77841 
77842 }
77843 
RemCC_One(L)77844 void RemCC_One(L)
77845 int L;
77846 {
77847 // Check triangle ligand coordinates TriArr[L]->coo for bumps against
77848 // all atoms of the proein
77849 // If the triangle bumps remove it.
77850 //
77851 // RemCC_One is called once after replacing the triangle with all
77852 // conformers in Map_Conformers
77853 //
77854 
77855     int i,j,k,l,ires;
77856     float tt,dd;
77857     double ddd,ttd,CLOSED;
77858 
77859     if (*ipdbon && calfptr->ncalf != 0) {
77860 	for (ires = 1; ires < calfptr->ncalf+1; ires++ ) {
77861 
77862 #if defined(VMS) || defined(UNDERSC)
77863 	   getpdb(&ires,ipdb,ihpdb);
77864 #else
77865 #ifdef CRAY
77866 	   GETPDB(&ires,ipdb,ihpdb);
77867 #else
77868    	   getpdb_(&ires,ipdb,ihpdb);
77869 #endif
77870 #endif
77871 	   CLOSED = CLOSEC/toangs;
77872 
77873 	   for (i=0; i<MXSYM; i++) {
77874 		if (ipdb[i] > 0) {
77875 		   if (TriArr[L] != NULL) {
77876 			for (k = 0; k < ndocka; k++ ) {
77877 			   ddd = 0.0;
77878 			   for (l = 0; l < 3; l++ ) {
77879 				ttd = xyzp->coo[(ipdb[i]-1)*3+l] -
77880 					TriArr[L]->coo[k*3+l];
77881 				ddd = ddd + ttd*ttd;
77882 			   }
77883 			   if (sqrt(ddd) < CLOSED) {
77884 				if (TriArr[L]->coo != NULL)
77885 				   free(TriArr[L]->coo);
77886 				free(TriArr[L]);
77887 				TriArr[L] = NULL;
77888 				ntris--;
77889 				break;
77890 			   }
77891 			}
77892 		   }
77893 		}
77894 	   }
77895 
77896 	   for (i=0; i<3*MXHSYM; i++) {
77897 		if (ihpdb[i] > 0) {
77898 		   if (TriArr[L] != NULL) {
77899 			for (k = 0; k < ndocka; k++ ) {
77900 			   ddd = 0.0;
77901 			   for (l = 0; l < 3; l++ ) {
77902 				ttd = xyzp->coo[(ihpdb[i]-1)*3+l] -
77903 					TriArr[L]->coo[k*3+l];
77904 				ddd = ddd + ttd*ttd;
77905 			   }
77906 			   if (sqrt(ddd) < CLOSED) {
77907 				if (TriArr[L]->coo != NULL)
77908 				   free(TriArr[L]->coo);
77909 				free(TriArr[L]);
77910 				TriArr[L] = NULL;
77911 				ntris--;
77912 				break;
77913 			   }
77914 			}
77915 		   }
77916 		}
77917 	   }
77918 
77919 
77920 	}
77921     }
77922 
77923 }
77924 
77925 
RemLoops(int j,int all,double CLOSED,int * ipdb,int * ihpdb)77926 int RemLoops(int j,int all,double CLOSED,int *ipdb,int *ihpdb)
77927 {
77928    int i,k,l,ido;
77929    float tt,dd;
77930    double ddd,ttd;
77931 
77932    for (i=0; i<MXSYM; i++) {
77933 	if (ipdb[i] > 0) {
77934 	    for (k = 0; k < ndocka; k++ ) {
77935 
77936 		ido = 0;
77937 		if (!all) {
77938 //		   if (TriArr[ntris]->conf == -1) {
77939 		   if (TriArr[j]->conf == -1) {
77940 			if (singleb.ifrg[k] == TriArr[j]->frag) ido = 1;
77941 		   } else {
77942 			if (singleb.ifrg[k] == TriArr[j]->frags[0] ||
77943 	    		    singleb.ifrg[k] == TriArr[j]->frags[1] ||
77944 	    		    singleb.ifrg[k] == TriArr[j]->frags[2]) ido = 1;
77945 		   }
77946 		} else {
77947 			ido = 1;
77948 		}
77949 
77950 		if (ido) {
77951 		      ddd = 0.0;
77952 		      for (l = 0; l < 3; l++ ) {
77953 			ttd = xyzp->coo[(ipdb[i]-1)*3+l] -
77954 				TriArr[j]->coo[k*3+l];
77955 			ddd = ddd + ttd*ttd;
77956 		      }
77957 		      if (sqrt(ddd) < CLOSED) return(1);
77958 		}
77959 
77960 	    } // end for k ndocka
77961 	} // ifend ipdb[i] > 0
77962    } // end for i MXSYM
77963 
77964    for (i=0; i<3*MXHSYM; i++) {
77965 	if (ihpdb[i] > 0) {
77966 	    for (k = 0; k < ndocka; k++ ) {
77967 		ido = 0;
77968 		if (!all) {
77969 		   if (TriArr[j]->conf == -1) {
77970 			if (singleb.ifrg[k] == TriArr[j]->frag) ido = 1;
77971 		   } else {
77972 			if (singleb.ifrg[k] == TriArr[j]->frags[0] ||
77973 	    		    singleb.ifrg[k] == TriArr[j]->frags[1] ||
77974 	    		    singleb.ifrg[k] == TriArr[j]->frags[2]) ido = 1;
77975 		   }
77976 		} else {
77977 		   ido = 1;
77978 		}
77979 
77980 		if (ido) {
77981 
77982 		      ddd = 0.0;
77983 		      for (l = 0; l < 3; l++ ) {
77984 			ttd = xyzp->coo[(ihpdb[i]-1)*3+l] -
77985 				TriArr[j]->coo[k*3+l];
77986 			ddd = ddd + ttd*ttd;
77987 		      }
77988 
77989 		      if (sqrt(ddd) < CLOSED) return(1);
77990 		}
77991 
77992 	    } // end for k ndocka
77993 	} // if end ihpdb[i] > 0
77994    } // end for i = MXHSYM
77995 
77996    return(0);
77997 }
77998 
RemCC_All(int all)77999 void RemCC_All(int all)
78000 {
78001     int j,ires;
78002     double CLOSED;
78003 
78004     CLOSED = CLOSEC/toangs;
78005 
78006     if (*ipdbon && calfptr->ncalf != 0) {
78007 	for (ires = 1; ires < calfptr->ncalf+1; ires++ ) {
78008 
78009 #if defined(VMS) || defined(UNDERSC)
78010 	   getpdb(&ires,ipdb,ihpdb);
78011 #else
78012 #ifdef CRAY
78013 	   GETPDB(&ires,ipdb,ihpdb);
78014 #else
78015    	   getpdb_(&ires,ipdb,ihpdb);
78016 #endif
78017 #endif
78018 
78019 	   for (j = 0; j < ntris; j++ ) {
78020 		if (TriArr[j] != NULL) {
78021 
78022 		   if (RemLoops(j,all,CLOSED,ipdb,ihpdb)) FreeTri(j);
78023 
78024 		} // if end TriArr[j] != NULL
78025 	   } // end for j ntris
78026 
78027 
78028 	}
78029     }
78030 
78031     Compress_Tri_L();
78032 
78033 }
78034 
ChkAro(ia1,ia2,xyz)78035 int ChkAro(ia1,ia2,xyz)
78036 int ia1;
78037 int ia2;
78038 COOSTRU *xyz;
78039 {
78040    int i,j,k,n1,n2,ian,ian1,ian2,ian3,ian12,ian13,ian23,itel;
78041    int ica1,ica2,icn[3];
78042 
78043    n1 = xyz->iconn[ia1*(MXCON+1)];
78044    n2 = xyz->iconn[ia2*(MXCON+1)];
78045 
78046    itel = 0;
78047 
78048    for (j=0; j < n1; j++) {
78049 	k = xyz->iconn[ia1*(MXCON+1)+j+1];
78050 	k = ABS(k) - 1;
78051 	if (k != ia2 && itel < 3) {
78052 	   icn[itel] = k;
78053 	   itel++;
78054 	}
78055    }
78056 
78057    ica1 = 0;
78058 
78059    if (itel == 2) {
78060 	if (singleb.irsd[icn[0]] == 4) ica1++;
78061 	if (singleb.irsd[icn[1]] == 4) ica1++;
78062 	if (singleb.irsd[ia1] == 4) ica1++;
78063    }
78064 
78065    itel = 0;
78066    for (j=0; j < n2; j++) {
78067 	k = xyz->iconn[ia2*(MXCON+1)+j+1];
78068 	k = ABS(k) - 1;
78069 	if (k != ia1 && itel < 3) {
78070 	   icn[itel] = k;
78071 	   itel++;
78072 	}
78073    }
78074 
78075    ica2 = 0;
78076 
78077    if (itel == 2) {
78078 	if (singleb.irsd[icn[0]] == 4) ica2++;
78079 	if (singleb.irsd[icn[1]] == 4) ica2++;
78080 	if (singleb.irsd[ia2] == 4) ica2++;
78081 	if ( (ica1 == 3 && ica2 == 2) || (ica1 == 2 && ica2 == 3) ) return(0);
78082 	if (ica1 == 3 && ica2 == 3) return(1);
78083    }
78084 
78085    return(0);
78086 }
78087 
IsPlanar(i1,i2,i3,i4,xyz)78088 int IsPlanar(i1,i2,i3,i4,xyz)
78089 int i1;
78090 int i2;
78091 int i3;
78092 int i4;
78093 COOSTRU *xyz;
78094 {
78095    int j;
78096    float v1[3],v2[3],v3[3],v4[3],v5[3];
78097    double cosa;
78098 
78099    for (j=0; j<3; j++) {
78100 	v1[j] = xyz->coo[i2*3+j] - xyz->coo[i1*3+j];
78101 	v2[j] = xyz->coo[i3*3+j] - xyz->coo[i1*3+j];
78102 	v3[j] = xyz->coo[i4*3+j] - xyz->coo[i1*3+j];
78103    }
78104 
78105    cross(v1,v2,v4);
78106    improd(v4,v3,&cosa);
78107 
78108    if (fabs(cosa) < 0.3) return(1);
78109 
78110    return(0);
78111 }
78112 
IsNPlanarH2(ia1,ia2,xyz)78113 int IsNPlanarH2(ia1,ia2,xyz)
78114 int ia1;
78115 int ia2;
78116 COOSTRU *xyz;
78117 {
78118    int j,k,n1,n2,ian1,ian2,itel;
78119    int ica1,ica2,icn[3],pl;
78120 
78121    n1 = xyz->iconn[ia1*(MXCON+1)];
78122 
78123    itel = 0;
78124    ian1 = 0;
78125    ian2 = 0;
78126 
78127    for (j=0; j < n1; j++) {
78128 	k = xyz->iconn[ia1*(MXCON+1)+j+1];
78129 	k = ABS(k) - 1;
78130 	if (k != ia2 && itel < 3) {
78131 	   icn[itel] = k;
78132 	   itel++;
78133 	}
78134    }
78135 
78136    pl = 0;
78137 
78138    if (itel == 2) {
78139 	ian1 = xyz->ianz[icn[0]];
78140 	ian2 = xyz->ianz[icn[1]];
78141 	pl = IsPlanar(ia1,icn[0],icn[1],ia2,xyz);
78142 
78143    }
78144 
78145    if (pl == 1 && ian1+ian2 == 2) return(0);
78146    return(1);
78147 }
78148 
IsSymFrg(isng,xyz)78149 int IsSymFrg(isng,xyz)
78150 int isng;
78151 COOSTRU *xyz;
78152 {
78153    int i,j,k,n1,n2,ia1,ia2,ian,ian1,ian2,ian3,ian12,ian13,ian23,itel;
78154    int ica1,ica2,icn[3],pl1,pl2;
78155 
78156    ia1 = singleb.sng[isng][0];
78157    ia2 = singleb.sng[isng][1];
78158 
78159    n1 = xyz->iconn[ia1*(MXCON+1)];
78160    n2 = xyz->iconn[ia2*(MXCON+1)];
78161 
78162    itel = 0;
78163 
78164    for (j=0; j < n1; j++) {
78165 	k = xyz->iconn[ia1*(MXCON+1)+j+1];
78166 	k = ABS(k) - 1;
78167 	if (k != ia2 && itel < 3) {
78168 	   icn[itel] = k;
78169 	   itel++;
78170 	}
78171    }
78172 
78173    pl1 = 0;
78174    ica1 = 0;
78175 
78176    switch(itel) {
78177    case 3:
78178 	ian1 = xyz->ianz[icn[0]];
78179 	ian2 = xyz->ianz[icn[1]];
78180 	ian3 = xyz->ianz[icn[2]];
78181 	break;
78182    case 2:
78183 	ian1 = xyz->ianz[icn[0]];
78184 	ian2 = xyz->ianz[icn[1]];
78185 	ian3 = 0;
78186 	if (singleb.irsd[icn[0]] == 5) ica1++;
78187 	if (singleb.irsd[icn[1]] == 5) ica1++;
78188 	if (singleb.irsd[ia1] == 5) ica1++;
78189 	pl1 = IsPlanar(ia1,icn[0],icn[1],ia2,xyz);
78190 	break;
78191    case 1:
78192 	ian1 = xyz->ianz[icn[0]];
78193 	ian2 = 0;
78194 	ian3 = 0;
78195 	break;
78196    case 0:
78197 	ian1 = 0;
78198 	ian2 = 0;
78199 	ian3 = 0;
78200 	break;
78201    default:
78202 	break;
78203    }
78204 
78205    ian12 = ian1 + ian2;
78206    ian13 = ian1 + ian3;
78207    ian23 = ian2 + ian3;
78208 
78209 
78210    if (itel == 3) {
78211 	if (ian1 == ian2 && ian1 == ian3) return(1);
78212 	if (ian12 == 2 || ian13 == 2 || ian23 == 2) return(2);
78213    }
78214 
78215    itel = 0;
78216    for (j=0; j < n2; j++) {
78217 	k = xyz->iconn[ia2*(MXCON+1)+j+1];
78218 	k = ABS(k) - 1;
78219 	if (k != ia1 && itel < 3) {
78220 	   icn[itel] = k;
78221 	   itel++;
78222 	}
78223    }
78224 
78225    pl2 = 0;
78226    ica2 = 0;
78227 
78228    switch(itel) {
78229    case 3:
78230 	ian1 = xyz->ianz[icn[0]];
78231 	ian2 = xyz->ianz[icn[1]];
78232 	ian3 = xyz->ianz[icn[2]];
78233 	break;
78234    case 2:
78235 	ian1 = xyz->ianz[icn[0]];
78236 	ian2 = xyz->ianz[icn[1]];
78237 	ian3 = 0;
78238 	if (singleb.irsd[icn[0]] == 5) ica2++;
78239 	if (singleb.irsd[icn[1]] == 5) ica2++;
78240 	if (singleb.irsd[ia2] == 5) ica2++;
78241 	pl2 = IsPlanar(ia2,icn[0],icn[1],ia1,xyz);
78242 	break;
78243    case 1:
78244 	ian1 = xyz->ianz[icn[0]];
78245 	ian2 = 0;
78246 	ian3 = 0;
78247 	break;
78248    case 0:
78249 	ian1 = 0;
78250 	ian2 = 0;
78251 	ian3 = 0;
78252 	break;
78253    default:
78254 	break;
78255    }
78256 
78257    ian12 = ian1 + ian2;
78258    ian13 = ian1 + ian3;
78259    ian23 = ian2 + ian3;
78260 
78261 
78262    if (itel == 3) {
78263 	if (ian1 == ian2 && ian1 == ian3) return(1);
78264 	if (ian12 == 2 || ian13 == 2 || ian23) return(2);
78265    } else if (itel == 2) {
78266 	if (ica1 == 3 && ica2 == 3) return(2);
78267 	if (pl1 == 1 && pl2 == 1) return(2);
78268    }
78269 
78270    return(3);
78271 }
78272 
ExtraFrag(C)78273 void ExtraFrag(C)
78274 COOSTRU *C;
78275 {
78276 
78277    int i,in,j,k[3],kn,ktot,krng,ir1,ir2,iflg;
78278 
78279    for (i=0; i < ndocka; i++) {
78280 
78281 	in = C->iconn[i*(MXCON+1)];
78282 	ir1 = singleb.jrng[i];
78283 	iflg = 0;
78284 	krng = -1;
78285 
78286 	if (in == 3 && ir1) {
78287 	   ktot = 0;
78288 	   for (j=0; j < 3; j++) {
78289 		k[j] = C->iconn[i*(MXCON+1)+j+1]-1;
78290 		if (singleb.jrng[k[j]] == ir1) {
78291 		   ktot++;
78292 		} else {
78293 		   krng = k[j];
78294 		}
78295 	   }
78296 
78297 	   if (ktot == 2) iflg = 1;
78298 	}
78299 
78300 	if (iflg && krng != -1 && krng > i) {
78301 
78302 	   kn = C->iconn[krng*(MXCON+1)];
78303 	   ir2 = singleb.jrng[krng];
78304 	   iflg = 0;
78305 
78306 	   if (kn == 3 && ir2) {
78307 
78308 		ktot = 0;
78309 		for (j=0; j < 3; j++) {
78310 		   k[j] = C->iconn[krng*(MXCON+1)+j+1]-1;
78311 		   if (singleb.jrng[k[j]] == ir2) ktot++;
78312 	   	}
78313 
78314 		if (ktot == 2) iflg = 1;
78315 	   }
78316 
78317 	   if (iflg) {
78318 		singleb.sng[singleb.N][0] = i;
78319 		singleb.sng[singleb.N][1] = krng;
78320 		singleb.N++;
78321 	   }
78322 
78323 	}
78324 
78325    }
78326 
78327 }
78328 
Fragmentise(xyz)78329 void Fragmentise(xyz)
78330 COOSTRU *xyz;
78331 {
78332    int i,j,k,l,n,m,itel,icn[4*MXCON],ICN[4*MXCON],N,iflg;
78333 
78334    singleb.NFRAG = 0;
78335 
78336    for (i=0; i < ndocka; i++) {
78337 	singleb.ifrg[i] = -1;
78338    }
78339 
78340    singleb.ifrg[0] = 0;
78341    N = 1;
78342    ICN[0] = 0;
78343    xyzp->iatclr[0] = singleb.NFRAG;
78344 
78345    while (1) {
78346 
78347       n = 0;
78348 
78349       for (m=0; m < N; m++) {
78350 
78351 	i = ICN[m];
78352 	singleb.ifrg[i] = singleb.NFRAG;
78353 	xyz->iatclr[i] = singleb.NFRAG;
78354 
78355 	for (j=0; j < xyz->iconn[i*(MXCON+1)]; j++) {
78356 
78357 	   k = xyz->iconn[i*(MXCON+1)+j+1];
78358 	   k = ABS(k) - 1;
78359 
78360 	   if (singleb.ifrg[k] == -1) {
78361 
78362 		iflg = 0;
78363 
78364 		for (l=0; l < singleb.N; l++) {
78365 		   if (singleb.sng[l][0] == i && singleb.sng[l][1] == k) {
78366 			iflg = 1;
78367 		   }
78368 		}
78369 
78370 		if (!iflg)  {
78371 		   singleb.ifrg[k] = singleb.NFRAG;
78372 		   xyz->iatclr[k] = singleb.NFRAG;
78373 		   icn[n] = k;
78374 		   n++;
78375 		}
78376 	   }
78377 	}
78378       }
78379 
78380       N = n;
78381 
78382       for (l=0; l < N; l++) {
78383 	ICN[l] = icn[l];
78384       }
78385 
78386       if (!N) {
78387 
78388 	iflg = 1;
78389 
78390         for (l=0; l < ndocka; l++) {
78391 	   if (singleb.ifrg[l] == -1) {
78392 		iflg = 0;
78393 		ICN[0] = l;
78394 		N = 1;
78395 		singleb.NFRAG++;
78396 		break;
78397 	   }
78398 	}
78399 	if (iflg) break;
78400       }
78401 
78402    }
78403 
78404    singleb.NFRAG++;
78405 
78406 
78407    for (i=0; i < singleb.N; i++) {
78408 	singleb.SngFrg[i][0] = singleb.ifrg[singleb.sng[i][0]];
78409 	singleb.SngFrg[i][1] = singleb.ifrg[singleb.sng[i][1]];
78410 	singleb.sngdone[i] = 0;
78411    }
78412 
78413    for (i=0; i < singleb.NFRAG; i++) {
78414 
78415 	itel = 0;
78416 
78417 	for (j=0; j < singleb.N; j++) {
78418 	   if (i == singleb.ifrg[singleb.sng[j][0]] ||
78419 	       i == singleb.ifrg[singleb.sng[j][1]]) {
78420 		singleb.FrgSng[i][itel] = j;
78421 		itel++;
78422 	   }
78423 
78424 	   singleb.FrgSngN[i] = itel;
78425 	}
78426    }
78427 
78428 }
78429 
78430 // Map_Conformers uses existing array of TriArr
78431 // to create new array elements with new conformers. However, these add
78432 // the original conformer, so we need to remove the original.
78433 
Map_Conformers()78434 void Map_Conformers()
78435 {
78436    int i,j,k,l,ntrism1,beg[MAXTRI],end[MAXTRI],at1,at2,at3;
78437 
78438    for (i=0; i < ntriS; i++) {
78439 	beg[i] = -1;
78440 	end[i] = -1;
78441    }
78442 
78443    for (i=0; i < ntris; i++) {
78444 	if (TriArr[i] != NULL) {
78445 	  if (TriArr[i]->coo != NULL) {
78446 	    if (TriArr[i]->triS < MAXTRI && TriArr[i]->triS >= 0) {
78447 	    if (beg[TriArr[i]->triS] == -1) {
78448 		beg[TriArr[i]->triS] = i;
78449 	    }
78450 	    end[TriArr[i]->triS] = i;
78451 	    }
78452 	  }
78453 	}
78454    }
78455 
78456 
78457    for (i=0; i < ntriS; i++) {
78458 
78459 	Tri1.grp[0] = TriS[i].grp[0];
78460 	Tri1.grp[1] = TriS[i].grp[1];
78461 	Tri1.grp[2] = TriS[i].grp[2];
78462 	Tri1.frag   = TriS[i].frag;
78463 
78464 	Tri2.grp[0] = TriS[i].grp[0];
78465 	Tri2.grp[1] = TriS[i].grp[1];
78466 	Tri2.grp[2] = TriS[i].grp[2];
78467 	Tri2.lig[0] = TriS[i].lig[0];
78468 	Tri2.lig[1] = TriS[i].lig[1];
78469 	Tri2.lig[2] = TriS[i].lig[2];
78470 	Tri2.frag   = TriS[i].frag;
78471 
78472 	at1 = TriS[i].atindx[0];
78473 	at2 = TriS[i].atindx[1];
78474 	at3 = TriS[i].atindx[2];
78475 
78476 	if (beg[i] != -1 && end[i] != -1) {
78477 
78478 	   for (j=beg[i]; j < end[i]+1; j++) {
78479 
78480 	    if (TriArr[j] != NULL) {
78481 		for (l=0; l < 3; l++) {
78482 		   Tri1.p1[l] = TriArr[j]->coo[at1*3+l];
78483 		   Tri1.p2[l] = TriArr[j]->coo[at2*3+l];
78484 		   Tri1.p3[l] = TriArr[j]->coo[at3*3+l];
78485 	   	}
78486 
78487 	   	Calc_Centroid(&Tri1);
78488 
78489 	   	for (k=0; k < ntrif; k++) {
78490 
78491 		   for (l=0; l < 3; l++) {
78492 			Tri2.p1[l] = TriFin[k]->coo[at1*3+l];
78493 			Tri2.p2[l] = TriFin[k]->coo[at2*3+l];
78494 			Tri2.p3[l] = TriFin[k]->coo[at3*3+l];
78495 		   }
78496 
78497 // allocate new triarr structure, set TriA to TriArr original coo
78498 
78499 		   ntris++;
78500 		   if (ntris >= MAXTRI) {
78501 			ntris = MAXTRI - 1;
78502 			return;
78503 		   }
78504 		   ntrism1 = ntris-1;
78505 
78506 		   TriArr[ntrism1] = (TRISTRU *) malloc(sizeof Tri1);
78507 		   memcpy(TriArr[ntrism1], &EmpTri, sizeof(TRISTRU));
78508 
78509 		   for (l=0; l < 3; l++) {
78510 			TriArr[ntrism1]->p1[l]  = Tri2.p1[l];
78511 			TriArr[ntrism1]->p2[l]  = Tri2.p2[l];
78512 			TriArr[ntrism1]->p3[l]  = Tri2.p3[l];
78513 			TriArr[ntrism1]->grp[l] = Tri2.grp[l];
78514 			TriArr[ntrism1]->lig[l] = Tri2.lig[l];
78515 		   }
78516 
78517 		   Calc_Centroid(TriArr[ntrism1]);
78518 
78519 		   Trans_Tri(&Tri1,TriArr[ntrism1]);
78520 		   Trans_Coo(TriArr[ntrism1],TriFin[k]->coo);
78521 
78522 		   TriArr[ntrism1]->frag = Tri2.frag;
78523 		   TriArr[ntrism1]->eint = TriArr[j]->eint + TriFin[k]->eint;
78524 		   TriArr[ntrism1]->e12  = TriArr[j]->e12;
78525 		   for (l=0; l < 3; l++) {
78526 			TriArr[ntrism1]->prot[l] = TriArr[j]->prot[l];
78527 		   }
78528 
78529 		}
78530 
78531 		if (TriArr[j] != NULL) {
78532 		   if (TriArr[j]->coo != NULL) {
78533 			free(TriArr[j]->coo);
78534 			TriArr[j]->coo = NULL;
78535 		   }
78536 
78537 		   free(TriArr[j]);
78538 		   TriArr[j] = NULL;
78539 		}
78540 	    }
78541 
78542 	   }
78543 	}
78544    }
78545 
78546    Compress_Tri_L();
78547 
78548 }
78549 
OriDist(double * coo1,double * coo2)78550 double OriDist(double *coo1, double *coo2)
78551 {
78552    int i,j;
78553    double tt,total;
78554 
78555    tt = 0.0;
78556    total = 0.0;
78557 
78558    for (i=0; i < 3; i++) {
78559 	tt = coo1[i]*toangs - coo2[i]*toangs;
78560 	tt = tt*tt;
78561 	total = total + tt;
78562    }
78563 
78564    total = sqrt(total);
78565 
78566    return(total);
78567 }
78568 
DispDist(int at1,int at2)78569 void DispDist(int at1,int at2)
78570 {
78571    double Ot1[3],Ot2[3];
78572 
78573    if (ntrif <= 1) return;
78574 
78575    Ot1[0] = TriFin[0]->coo[at1*3];
78576    Ot1[1] = TriFin[0]->coo[at1*3+1];
78577    Ot1[2] = TriFin[0]->coo[at1*3+2];
78578 
78579    Ot2[0] = TriFin[0]->coo[at2*3];
78580    Ot2[1] = TriFin[0]->coo[at2*3+1];
78581    Ot2[2] = TriFin[0]->coo[at2*3+2];
78582 
78583    fprintf(stderr,"Aft 0 Create_Conformers Dist: %.3f\n",OriDist(Ot1,Ot2));
78584 
78585    Ot1[0] = TriFin[1]->coo[at1*3];
78586    Ot1[1] = TriFin[1]->coo[at1*3+1];
78587    Ot1[2] = TriFin[1]->coo[at1*3+2];
78588 
78589    Ot2[0] = TriFin[1]->coo[at2*3];
78590    Ot2[1] = TriFin[1]->coo[at2*3+1];
78591    Ot2[2] = TriFin[1]->coo[at2*3+2];
78592 
78593    fprintf(stderr,"Aft 1 Create_Conformers Dist: %.3f\n",OriDist(Ot1,Ot2));
78594 }
78595 
Compress_Ligtyp_List()78596 void Compress_Ligtyp_List()
78597 {
78598    int i,j,k,lint;
78599 
78600    for (i=0; i < lintconf; i++) {
78601 	ligtyp[i]->nconf = 1;
78602 	ligtyp[i]->ConfArr[0] = i;
78603 	for (j=1; j < ntrif; j++) {
78604 	   k = i+j*lintconf;
78605 	   if ((ligtyp[i]->ORI[0] == ligtyp[k]->ORI[0]) &&
78606 		(ligtyp[i]->ORI[1] == ligtyp[k]->ORI[1]) &&
78607 		(ligtyp[i]->ORI[2] == ligtyp[k]->ORI[2]) ) {
78608 
78609 		ligtyp[i]->ConfArr[ligtyp[i]->nconf] = j;
78610 		ligtyp[i]->nconf++;
78611 		free(ligtyp[k]);
78612 		ligtyp[k] = NULL;
78613 	   }
78614 	}
78615    }
78616 
78617    lint = 0;
78618    for (i=0; i < lintp; i++) {
78619 	if (ligtyp[i] != NULL) {
78620 	   if (i != 0) {
78621 		ligtyp[lint] = ligtyp[i];
78622 	   }
78623 	   lint++;
78624 	}
78625    }
78626 
78627    lintp = lint;
78628 }
78629 
AssLig(C,coo,iconf)78630 void AssLig(C,coo,iconf)
78631 COOSTRU *C;
78632 double *coo;
78633 int iconf;
78634 {
78635 // AssLig creates interaction points from ligand OR
78636 // ligand conformers, through coo's generated for conformers
78637 
78638    int i,i1,in,iret,indx,indxm,it,j,k,kn,n,noh,nring,pl,kc1,kc2,jj;
78639    int jm1,jp1,io1,io2,io3;
78640    int aro,c2ar,n2ar,n2art,n2d,s2,ivalr,isetconf;
78641    int iring[6],oring[6],iele[4];
78642 
78643    ivalr = 0;
78644    isetconf = 0;
78645 
78646    if (lintp == 0) isetconf = 1;
78647 
78648    for (i=0; i < singleb.N; i++) {
78649 	singleb.sngdone[i] = 0;
78650    }
78651 
78652    for (i=0; i < ndocka; i++) {
78653 	singleb.irng[i] = 0;
78654 	singleb.jrng[i] = 0;
78655 	C->lring[i] = 0;
78656 	C->lwrit[i] = 0;
78657 	C->iaton[i] = 2;
78658    }
78659 
78660    for (i=0; i < ndocka; i++) {
78661 	i1 = i + 1;
78662 	nring = 0;
78663 #if defined(VMS) || defined(UNDERSC)
78664 	ringd(&i1,iring,&nring,&ZERO,
78665 #else
78666 #ifdef CRAY
78667 	RINGD(&i1,iring,&nring,&ZERO,
78668 #else
78669 	ringd_(&i1,iring,&nring,&ZERO,
78670 #endif
78671 #endif
78672 	C->ianz,C->iaton,C->iconn,C->lwrit,C->lring, &iret);
78673 	if (iret == 1) {
78674 	   if (nring == 6 || nring == 5) singleb.irng[i] = 1;
78675 	}
78676    }
78677 
78678    for (i=0; i < ndocka; i++) {
78679 	C->lring[i] = 0;
78680 	C->lwrit[i] = 0;
78681 	C->iaton[i] = 2;
78682    }
78683 
78684    for (i=0; i < ndocka; i++) {
78685 
78686 	i1 = i + 1;
78687 	in = C->iconn[i*(MXCON+1)];
78688 
78689 	for (j=0; j < in; j++) {
78690 	   k = C->iconn[i*(MXCON+1)+j+1]-1;
78691 	   kn = C->iconn[k*(MXCON+1)];
78692 	   if (k >= 0) {
78693 		if (k > i && (kn != 1 && in != 1)) {
78694 		   if (singleb.irsd[i] == 3 || singleb.irsd[k] == 3) {
78695 			pl = 1;
78696 			if (C->ianz[i] == 8 || C->ianz[k] == 8) {
78697 			   if (C->ianz[i] == 8 && C->ianz[k] == 1) pl = 0;
78698 			   if (C->ianz[k] == 8 && kn == 2) {
78699 				kc1 = C->iconn[k*(MXCON+1)+1]-1;
78700 				kc2 = C->iconn[k*(MXCON+1)+2]-1;
78701 				if (C->ianz[kc1] == 1 || C->ianz[kc2] == 1)
78702 					pl = 0;
78703 			   }
78704 			} if (C->ianz[i] == 7) {
78705 			   pl = IsNPlanarH2(i,k,C);
78706 			} else if (C->ianz[k] == 7) {
78707 			   pl = IsNPlanarH2(k,i,C);
78708 			}
78709 			if (pl && ((!singleb.irng[i] || !singleb.irng[k]) ||
78710 				(singleb.ityp[i]  == -50 || !singleb.irng[k]) )) {
78711 			   singleb.sng[singleb.N][0] = i;
78712 			   singleb.sng[singleb.N][1] = k;
78713 			   singleb.N++;
78714 			}
78715 		   }
78716 
78717 		   if ((singleb.ityp[i] == -2 && C->ianz[k] != 7) ||
78718 			(singleb.ityp[k] == -2 && C->ianz[i] != 7)) {
78719 			   singleb.sng[singleb.N][0] = i;
78720 			   singleb.sng[singleb.N][1] = k;
78721 			   singleb.N++;
78722 		   }
78723 
78724 		   if (singleb.irsd[i] == 4 && singleb.irsd[k] == 4) {
78725 			if (ChkAro(i,k,C)) {
78726 			   singleb.sng[singleb.N][0] = i;
78727 			   singleb.sng[singleb.N][1] = k;
78728 			   singleb.N++;
78729 			}
78730 		   }
78731 		}
78732 	   }
78733 	}
78734 
78735 	nring = 0;
78736 	ivalr++;
78737 #if defined(VMS) || defined(UNDERSC)
78738 	ringd(&i1,iring,&nring,&ZERO,
78739 #else
78740 #ifdef CRAY
78741 	RINGD(&i1,iring,&nring,&ZERO,
78742 #else
78743 	ringd_(&i1,iring,&nring,&ZERO,
78744 #endif
78745 #endif
78746 	C->ianz,C->iaton,C->iconn,C->lwrit,C->lring, &iret);
78747 
78748 	if (iret == 1) {
78749 	   if (nring == 6 || nring == 5) {
78750 	        singleb.irng[i] = 1;
78751 		RNGmin1(iring,nring);
78752 		ReORNG(C,iring,nring);
78753 		RNGput(iring,nring,ivalr);
78754                 isC3RNG(C,iring,oring,nring);
78755 		n2ar = 0;
78756 		n2art = -1;
78757 		c2ar = 0;
78758 		aro = 0;
78759 		n2d = 0;
78760 		s2  = 0;
78761 		for (j=0; j < nring; j++) {
78762 		   if (C->ityp[iring[j]] == 23) s2++;
78763 		   if (isANY(C->ityp[iring[j]],C2ar,2)) c2ar++;
78764 		   if (isANY(C->ityp[iring[j]],Aany,6)) aro++;
78765 		   if (isANY(C->ityp[iring[j]],N2ar,2)) {
78766 			if (n2art == -1) {
78767 			   n2art = j;
78768 			} else {
78769 			   n2d = j - n2art;
78770 			}
78771 			n2ar++;
78772 		   }
78773 		}
78774 /* address: ARO = C@AR + N2AR + S.2 */
78775 
78776 		if (c2ar == 6 || (c2ar == 5 && n2ar == 1) ||
78777 		   (n2ar == 2 && c2ar == 4) || (n2ar == 3 && c2ar == 3)) {
78778 /* phenyl_center */
78779 
78780 		   AllInt(C,&lintp,iring[0],iring[3],iring[1],0,
78781 			3,PHENYL_CENTER,PHC1,coo,iconf,0);
78782 		   AllInt(C,&lintp,iring[0],iring[3],iring[1],0,
78783 			3,PHENYL_CENTER,PHC2,coo,iconf,0);
78784 		   for (j=0; j < nring; j++) {
78785 			if (oring[j] == 1) {
78786 			   jm1 = j-1; if (jm1 < 0) jm1 = nring-1;
78787 			   jp1 = j+1; if (jp1 > nring-1) jp1 = 0;
78788 			   AllInt(C,&lintp,iring[j],iring[jm1],iring[jp1],
78789 				0,3,PHENYL_RING,PHR,coo,iconf,0);
78790 			}
78791 			C->lwrit[iring[j]] = 1;
78792 		   }
78793 		}
78794 
78795 		if ((n2ar == 1 && c2ar == 4) || (n2ar == 2 && c2ar == 3) ||
78796 		    (c2ar == 4 && s2 == 1) ) {
78797 /* phenyl_center */
78798 		   AllInt(C,&lintp,iring[0],iring[3],iring[1],0,
78799 			3,PHENYL_CENTER,PHC1,coo,iconf,0);
78800 		   AllInt(C,&lintp,iring[0],iring[3],iring[1],0,
78801 			3,PHENYL_CENTER,PHC2,coo,iconf,0);
78802 		   for (j=0; j < nring; j++) {
78803 			if (oring[j] == 1) {
78804 			   jm1 = j-1; if (jm1 < 0) jm1 = nring-1;
78805 			   jp1 = j+1; if (jp1 > nring-1) jp1 = 0;
78806 			   AllInt(C,&lintp,iring[j],iring[jm1],iring[jp1],
78807 				0,3,PHENYL_RING,PHR,coo,iconf,0);
78808 			}
78809 			C->lwrit[iring[j]] = 1;
78810 		   }
78811 		}
78812 
78813 		if (nring == 6) {
78814 		   if (c2ar == 1 && aro == 5) {
78815 		   fprintf(stderr,"adding phenyl ring\n");
78816 /* aro_ring6_H */
78817 		   }
78818 		}
78819 	   }
78820 	}
78821 
78822 	if (isANY(C->ityp[i],Nany,7) && Has_Con(C,i,1,iele) &&
78823 		C->qat[i] >= 0.3) {
78824 
78825 	   AllInt(C,&lintp,iele[0],i,0,0,2,H_DON,ONH,coo,iconf,0);
78826 
78827 	} else if (isDON(C->ityp[i]) && Has_Con(C,i,1,iele)) {
78828 
78829 	   if (isCOH(i,&io1,&io2,&it)) {
78830 	      double *GenOH = NULL;
78831 
78832 	      if (it == 5) {
78833 		noh = 3;
78834 	        OHGenRot(coo,&GenOH,io1,i,io2,noh,120);
78835 	      } else {
78836 		noh = 2;
78837 		OHGenRot(coo,&GenOH,io1,i,io2,noh,180);
78838 	      }
78839 	      for (jj=0; jj < noh; jj++) {
78840 		if (jj == 0) {
78841 		   OHAllInt(C,&lintp,io2,i,io1,coo,&GenOH[0],iconf,i,-i1,jj);
78842 		} else {
78843 		   OHAllInt(C,&lintp,io2,i,io1,coo,&GenOH[0],iconf,i,i1,jj);
78844 		}
78845 	      }
78846 	   } else {
78847 	      AllInt(C,&lintp,iele[0],i,0,0,2,H_DON,NHP,coo,iconf,0);
78848 	   }
78849 	   if (iele[1] != -1) {
78850 		AllInt(C,&lintp,iele[1],i,0,0,2,H_DON,NHP,coo,iconf,0);
78851 	   }
78852 
78853 	} else {
78854 /* todo: donors_cooh */
78855 	}
78856 
78857 	if (issCOO(i,&io1,&io2)) {
78858 
78859 	   AllInt(C,&lintp,io1,i,io2,0,3,H_ACC,COOmin,coo,iconf,0);
78860 
78861 	   ligtyp[lintp-1]->q0 = -0.5;
78862 	   ligtyp[lintp-1]->q1 =  0.0;
78863 	   ligtyp[lintp-1]->q2 = -0.5;
78864 
78865 	   AllInt(C,&lintp,io2,i,io1,0,3,H_ACC,COOmin,coo,iconf,0);
78866 	} else if (isCO(i,&io1)) {
78867 	   AllInt(C,&lintp,io1,i,0,0,2,H_ACC,CO,coo,iconf,0);
78868 	} else if (isCOmin(i,&io1)) {
78869 	   AllInt(C,&lintp,io1,i,0,0,2,H_ACC,CO,coo,iconf,0);
78870 	}
78871 	if (isSO(i,&io1,&io2)) {
78872 	   if (io1 != -1) AllInt(C,&lintp,io1,i,0,0,2,H_ACC,CO,coo,iconf,0);
78873 	   if (io2 != -1) AllInt(C,&lintp,io2,i,0,0,2,H_ACC,CO,coo,iconf,0);
78874 	}
78875 	if (isNO2(i,&io1,&io2)) {
78876 	   AllInt(C,&lintp,io1,i,io2,0,3,H_ACC,COOmin,coo,iconf,0);
78877 	   AllInt(C,&lintp,io2,i,io1,0,3,H_ACC,COOmin,coo,iconf,0);
78878 
78879 	} else if (isNO(i,&io1)) {
78880 	   AllInt(C,&lintp,io1,i,0,0,2,H_ACC,CO,coo,iconf,0);
78881 	}
78882 	if (isPO(i,&io1,&io2,&io3)) {
78883 	   if (io1 != -1) AllInt(C,&lintp,io1,i,0,0,2,H_ACC,CO,coo,iconf,0);
78884 	   if (io2 != -1) AllInt(C,&lintp,io2,i,0,0,2,H_ACC,CO,coo,iconf,0);
78885 	   if (io3 != -1) AllInt(C,&lintp,io3,i,0,0,2,H_ACC,CO,coo,iconf,0);
78886 	}
78887 	if (isC3OH(i,&io1,&io2)) {
78888 	   AllInt(C,&lintp,i,io1,io2,0,3,H_ACC,OSP3,coo,iconf,i);
78889 	}
78890 	if (isC2OH(i,&io1,&io2)) {
78891 	   AllInt(C,&lintp,i,io1,io2,0,3,H_ACC,OSP2,coo,iconf,i);
78892 	}
78893 	if (isCOC(i,&io1,&io2)) {
78894 	   AllInt(C,&lintp,i,io1,io2,0,3,H_ACC,COC,coo,iconf,0);
78895 	}
78896 	if (isRF(i,&io1)) {
78897 	   AllInt(C,&lintp,i,io1,0,0,2,H_ACC,CO,coo,iconf,0);
78898 	}
78899 	if (!isAZIDE(i)) {
78900 	   if (isNaryl(i,&io1,&io2)) {
78901 		AllInt(C,&lintp,i,io1,io2,0,3,H_ACC,NARYL,coo,iconf,0);
78902 	   }
78903 	}
78904 	if (isAMID(i,&io1,&io2)) {
78905 	   AllInt(C,&lintp,i,io2,io1,0,3,H_ACC,AMID1,coo,iconf,0);
78906 	   AllInt(C,&lintp,i,io2,io1,0,3,H_ACC,AMID2,coo,iconf,0);
78907 	}
78908 	if (isNamino(i,&io1,&io2,&io3)) {
78909 	   AllInt(C,&lintp,i,io1,io2,io3,4,H_ACC,NAMINO,coo,iconf,0);
78910 	}
78911 	if (isNT(i,&io1)) AllInt(C,&lintp,i,io1,0,0,2,H_ACC,CO,coo,iconf,0);
78912 
78913 	n = isCH3R(i);
78914 	if (n == 1) {
78915 	   AllInt(C,&lintp,i,0,0,0,1,CH3,SPH1,coo,iconf,0);
78916 	   indxm = lintp;
78917 	   AllInt(C,&lintp,i,0,0,0,1,PHE_CH3,CH3_PHE,coo,iconf,0);
78918 	   ligtyp[indxm]->area.radius = 4.0;
78919 	} else if (n == 2) {
78920 	   AllInt(C,&lintp,i,0,0,0,1,CH2,SPH1,coo,iconf,0);
78921 	} else if (n == 3) {
78922 	   AllInt(C,&lintp,i,0,0,0,1,CH,SPH1,coo,iconf,0);
78923 	}
78924 	n = isCarR(i);
78925 	if (n == 1 || n == 2) {
78926 	   AllInt(C,&lintp,i,0,0,0,1,ARO,SPH1,coo,iconf,0);
78927 	}
78928 	if (isS3(i)) AllInt(C,&lintp,i,0,0,0,1,SULFUR,SPH2,coo,iconf,0);
78929 	if (isSNH(i,&io1,&io2)) {
78930 	   AllInt(C,&lintp,i,io1,io2,0,3,H_ACC,COC,coo,iconf,0);
78931 	}
78932    }
78933 
78934    if (isetconf) lintconf = lintp;
78935 }
78936 
78937 #define MXINP 100
78938 
78939 #define CONFWIN 2.0
78940 
SortConf()78941 void SortConf()
78942 {
78943       int nt,i;
78944       float Emin;
78945 
78946       qsort((TRISTRU *) TriFin, ntrif, sizeof(TRISTRU *), cmpeint);
78947 
78948       Emin = TriFin[0]->eint + CONFWIN;
78949 
78950       nt = -1;
78951 
78952       for (i=0; i < ntrif; i++) {
78953 	if (TriFin[i] != NULL && nt == -1) {
78954 	   if (TriFin[i]->eint > Emin) nt = i;
78955 	}
78956       }
78957 
78958       if (nt != -1) {
78959 	for (i=nt; i < ntrif; i++) {
78960 	   if (TriFin[i]->coo != NULL) free(TriFin[i]->coo);
78961 	   if (TriFin[i] != NULL) free(TriFin[i]);
78962 	}
78963         ntrif = nt;
78964       }
78965 
78966 if (debugdck) {
78967       fprintf(stderr,"After sort conformations:\n\n");
78968       for (i=0; i < ntrif; i++) {
78969 	   if (TriFin[i] != NULL) {
78970 		fprintf(stderr,"i %d eint %.3f\n",i,TriFin[i]->eint);
78971 	   }
78972       }
78973 
78974       Write_Results("confchk.mol2",TriFin,ntrif,xyzp,1,0);
78975 }
78976 
78977 }
78978 
FindSameTriS(int ind)78979 void FindSameTriS(int ind)
78980 {
78981    int i,lig[3],act;
78982    float d12,d13,d23;
78983 
78984    for (i=0; i < 3; i++) {
78985       lig[i] = TriS[ind].lig[i];
78986    }
78987 
78988    d12 = TriS[ind].d12;
78989    d13 = TriS[ind].d13;
78990    d23 = TriS[ind].d23;
78991 
78992    TriS[ind].nconf = 1;
78993    TriS[ind].ConfArr[0] = TriS[ind].conf;
78994 
78995    for (i=0; i < ntriS; i++) {
78996 	if (TriS[i].active && i != ind) {
78997 	   if (TriS[i].lig[0] == lig[0] && TriS[i].lig[1] == lig[1] &&
78998 		TriS[i].lig[2] == lig[2] ) {
78999 	        if (TriS[i].d12 == d12 && TriS[i].d13 == d13 &&
79000 		    TriS[i].d23 == d23 ) {
79001 		   TriS[ind].ConfArr[TriS[ind].nconf] = TriS[i].conf;
79002 		   TriS[ind].nconf++;
79003 		   TriS[i].active = 0;
79004 		}
79005 	   }
79006 	}
79007    }
79008 }
79009 
Find_Lig_Conf(int k,int itri)79010 int Find_Lig_Conf(int k,int itri)
79011 {
79012      int i,iset1,iset2;
79013 
79014      iset1 = 0;
79015 
79016      for (i=0; i < ligtyp[TriArr[itri]->lig[1]]->nconf; i++) {
79017 	if (k == ligtyp[TriArr[itri]->lig[1]]->ConfArr[i]) {
79018 	   iset1 = 1;
79019 	}
79020      }
79021 
79022      iset2 = 0;
79023 
79024      for (i=0; i < ligtyp[TriArr[itri]->lig[2]]->nconf; i++) {
79025 	if (k == ligtyp[TriArr[itri]->lig[2]]->ConfArr[i]) {
79026 	   iset2 = 1;
79027 	}
79028      }
79029 
79030      if (iset1 && iset2) return(1);
79031      return(0);
79032 }
79033 
TrimTriS(int np)79034 void TrimTriS(int np)
79035 {
79036    int i,j,n,act,ntriso;
79037 
79038    for (i=0; i < ntriS; i++) {
79039 	for (j=0; j < np; j++) {
79040 	   if (!(ADPAIR1[j] == TriS[i].frags[0] ||
79041 		 ADPAIR2[j] == TriS[i].frags[0]))
79042 			TriS[i].active = 0;
79043 	   if (!(ADPAIR1[j] == TriS[i].frags[1] ||
79044 		 ADPAIR2[j] == TriS[i].frags[1]))
79045 			TriS[i].active = 0;
79046 	   if (!(ADPAIR1[j] == TriS[i].frags[2] ||
79047 		 ADPAIR2[j] == TriS[i].frags[2]))
79048 			TriS[i].active = 0;
79049 	}
79050    }
79051 
79052    for (i=0; i < ntriS; i++) {
79053 	act = TriS[i].active;
79054 	if (act) FindSameTriS(i);
79055    }
79056 
79057 
79058    n = 0;
79059    for (i=0; i < ntriS; i++) {
79060 	if (TriS[i].active) {
79061 	   TriS[n] = TriS[i];
79062 	   n++;
79063 	}
79064    }
79065    ntriS = n;
79066 }
79067 
79068 
ProcLig(imode)79069 void ProcLig(imode)
79070 int imode;
79071 {
79072    int i,i1,in,j,k,kn,l,m,indx,nring,iret,aro,c2ar,n2ar,n2art,n2d,iattmp,ipdbtmp;
79073    int jm1,jp1,io1,io2,io3,ierr,n,ninp[4],itel,maxsol,ic,pl,Ifrag,NoFrag;
79074    int *inpp[4],Score_Org_Ligand,indxm,irng,irs,iflg,iatomsd,mxnatd,ihaszmd;
79075    int nacc,ndon,nphec,npher,naro;
79076    int ncacc,ncdon,ncphec,ncpher,ncaro;
79077    int iacc[MAXLIGSTRU],idon[MAXLIGSTRU],iphec[MAXLIGSTRU],ipher[MAXLIGSTRU];
79078    int iaro[MAXLIGSTRU];
79079    int cacc[MAXLIGSTRU],cdon[MAXLIGSTRU],cphec[MAXLIGSTRU],cpher[MAXLIGSTRU];
79080    int caro[MAXLIGSTRU];
79081    int iring[6],oring[6],iele[4],ngrp,npair,npair_nolink;
79082    int *ianztmp,nt,tl0,tl1,tl2,l0,l1,l2;
79083    short int *ityptmp;
79084    time_t curtime;
79085    COOSTRU *pp;
79086 
79087    DCKLIGPROC = 1;
79088    Ifrag = -1;
79089    indx = 0;
79090    NoFrag = 0;
79091    MapConformers = 1;
79092 
79093    pp = xyzp;
79094 
79095    if (imode == 1) {
79096       iatomsd = *(xyzp->iatoms);
79097       mxnatd  = *(xyzp->mxnat);
79098       ihaszmd = *(zmptrp->ihaszm);
79099       xyzp = &DCKxyz;
79100       setiat(ndocka);
79101    } else {
79102       ndocka = *xyzp->iatoms;
79103    }
79104 
79105    for (i=0; i < ndocka; i++) {
79106 	xyzp->lring[i] = 0;
79107 	xyzp->lwrit[i] = 0;
79108 	xyzp->iaton[i] = 2;
79109    }
79110 
79111    for (i=0; i < ndocka; i++) {
79112 
79113 	i1 = i + 1;
79114 
79115 	xyzp->iaton[i] = 2;
79116 #if defined(VMS) || defined(UNDERSC)
79117 	ispnd(&irs,&i1,&irng,&ONE,&ZERO,
79118 #else
79119 #ifdef CRAY
79120 	ISPND(&irs,&i1,&irng,&ONE,&ZERO,
79121 #else
79122 	ispnd_(&irs,&i1,&irng,&ONE,&ZERO,
79123 #endif
79124 #endif
79125 	   xyzp->qat,xyzp->ianz,xyzp->iaton,xyzp->iconn,xyzp->lwrit,xyzp->lring);
79126 	singleb.irsd[i] = IHBT[irs-1];
79127 
79128    }
79129 
79130    singleb.N = 0;
79131 
79132    lintp = 0;
79133 
79134    AssLig(xyzp,xyzp->coo,-1);
79135    ExtraFrag(xyzp);
79136 
79137    Fragmentise(xyzp);
79138 
79139    for (j=0; j < lintp; j++) FrgInt(j);
79140 
79141    if (imode == 1) {
79142       xyzp = pp;
79143       setiat(iatomsd);
79144       *(xyzp->mxnat)  = mxnatd;
79145       *(zmptrp->ihaszm) = ihaszmd;
79146    }
79147 
79148    prtypes(ligtyp,lintp,iacc,&nacc,idon,&ndon,iphec,&nphec,ipher,&npher,iaro,&naro);
79149 
79150    if (imode == 0) {
79151       ndocka = *xyzp->iatoms;
79152       Create_Conformers(0,xyzp);
79153       if (ntrif == -1) CopyLig(xyzp);
79154 if (debugdck) Write_Results("conformers.mol2",TriFin,ntrif,xyzp,1,0);
79155       Loop_Opt_Dih(0,xyzp,1);
79156       return;
79157    }
79158 
79159 #if defined(VMS) || defined(UNDERSC)
79160    curs(&ONE);
79161 #else
79162 #ifdef CRAY
79163    CURS(&ONE);
79164 #else
79165    curs_(&ONE);
79166 #endif
79167 #endif
79168 
79169    ninp[0] = nacc; ninp[1] = ndon; ninp[2] = nphec; ninp[3] = npher;
79170    inpp[0] = iacc; inpp[1] = idon; inpp[2] = iphec; inpp[3] = ipher;
79171 
79172 if (debugdck) fprintf(stderr,"ndon %d nphec %d npher %d nacc %d\n",ndon,nphec,npher,nacc);
79173    ntriS = 0;
79174 
79175    ngrp = 2;
79176 
79177    if (Monitor_AccDon(nacc,ndon,iacc,idon,&npair,&npair_nolink)) {
79178 	ngrp = 3;
79179 if (debugdck) fprintf(stderr,"After Monitor_AccDon: ngrp %d\n",ngrp);
79180    } else {
79181 	npher = 0;
79182 	ninp[3] = 0;
79183    }
79184 
79185 if (debugdck) fprintf(stderr,"npair %d npairl %d\n",npair,npair_nolink);
79186 
79187 
79188    for (i=0; i < MAXTRI; i++) {
79189 	TriArr[i] = NULL;
79190 	TriArrCopy[i] = NULL;
79191    }
79192 
79193    if (npair_nolink == 0) {
79194 	Ifrag = 0;
79195 	MapConformers = 0;
79196    } else {
79197 
79198 	fprintf(stderr,"Start Setup_Distance_Tables\n");
79199 
79200 if (debugdck) {
79201   time(&curtime);
79202   fprintf(stderr,"Begin Time: %s\n",ctime(&curtime));
79203 }
79204 	Setup_Distance_Tables();
79205 
79206 if (debugdck) {
79207   time(&curtime);
79208   fprintf(stderr,"End Time: %s\n",ctime(&curtime));
79209 }
79210 
79211 	for (i=0; i < ngrp; i++) {
79212 	   for (j=0; j < ngrp; j++) {
79213 		for (k=0; k < ngrp; k++) {
79214 		   Harvest_Triples(ninp[i],ninp[j],ninp[k],
79215 			inpp[i],inpp[j],inpp[k]);
79216 		}
79217 	   }
79218 	}
79219 
79220 	Tris_NoLink();
79221 	if (npair && ntriS > 150) Sub_Selection_Tris();
79222 
79223 if (debugdck) fprintf(stderr,"Harvest_Triples: ntriS %d\n\n",ntriS);
79224 
79225 	Gen_triples();
79226 
79227 if (debugdck) {
79228 fprintf(stderr,"aft gen_triples:\n");
79229 for (i=0; i < ntris; i++) {
79230    if (TriArr[i] != NULL) PrtTrp(i);
79231 }
79232 }
79233 
79234 	Ifrag = CalcSchInt();
79235    }
79236 
79237 
79238    if (imode == 1) {
79239       iatomsd = *(xyzp->iatoms);
79240       mxnatd  = *(xyzp->mxnat);
79241       ihaszmd = *(zmptrp->ihaszm);
79242       xyzp = &DCKxyz;
79243       setiat(ndocka);
79244       Create_Conformers(Ifrag,xyzp);
79245       if (ntrif == -1) CopyLig(xyzp);
79246 
79247 if (debugdck) Write_Results("conformers.mol2",TriFin,ntrif,xyzp,1,0);
79248 
79249       if (!MapConformers) SortConf();
79250 
79251    }
79252 
79253    if (ntriS == 0 || npair_nolink == 0) {
79254 
79255 	ReleaseLig();
79256 	lintp = 0;
79257 
79258 // These two lines are here to test ONE conformer, that has smallest RMSD
79259 // with the crystal conformer
79260 
79261 
79262 	for (i=0; i < ntrif; i++) {
79263 	   AssLig(&DCKxyz,TriFin[i]->coo,i);
79264 	}
79265 
79266 	for (j=0; j < lintp; j++) FrgInt(j);
79267 
79268 	prtypes(ligtyp,lintp,iacc,&nacc,idon,&ndon,iphec,&nphec,
79269 		ipher,&npher,iaro,&naro);
79270 
79271 	Compress_Ligtyp_List();
79272 
79273 	prtypes(ligtyp,lintp,iacc,&nacc,idon,&ndon,iphec,&nphec,
79274 		ipher,&npher,iaro,&naro);
79275 
79276 // we need a routine that takes an array such as iacc and a conformer number
79277 // and create a specific subselection array
79278 
79279 	ninp[0] = nacc; ninp[1] = ndon; ninp[2] = nphec; ninp[3] = npher;
79280 	inpp[0] = iacc; inpp[1] = idon; inpp[2] = iphec; inpp[3] = ipher;
79281 
79282 	ntriS = 0;
79283 
79284 // This call is put in here to increase DCKCOFF to 15.0 if no ACC/DON pair
79285 // is found with DCKCOFF 10.0
79286 // as a side effect it also sets npair and npair_nolink
79287 
79288 //	if (Monitor_AccDon_Conformers(ncacc,ncdon,cacc,cdon,&npair,
79289 //		&npair_nolink)) {
79290 	if (Monitor_AccDon_Conformers(nacc,ndon,iacc,idon,&npair,
79291 		&npair_nolink)) {
79292 	   ngrp = 3;
79293 	   ngrp = 2;
79294 if (debugdck) fprintf(stderr,"After Monitor_AccDon_Conformers: ngrp %d\n",ngrp);
79295 	} else {
79296 	   npher = 0;
79297 	   ninp[3] = 0;
79298 	}
79299 
79300 	fprintf(stderr,"2nd: Start Setup_Distance_Tables\n");
79301 
79302 if (debugdck) {
79303    time(&curtime);
79304    fprintf(stderr,"Begin Time: %s nintp %d\n",ctime(&curtime),nintp);
79305 }
79306 
79307 	Setup_Distance_Tables();
79308 
79309 if (debugdck) {
79310    time(&curtime);
79311    fprintf(stderr,"End Time: %s npairl %d\n",ctime(&curtime),npair_nolink);
79312 }
79313 
79314 	if (npair_nolink == 0) {
79315 
79316 	   Harvest_Triples_NoFrag(ndon,nphec,naro,idon,iphec,iaro);
79317 	   Harvest_Triples_NoFrag(ndon,npher,naro,idon,ipher,iaro);
79318 	   Harvest_Triples_NoFrag(nacc,nphec,naro,iacc,iphec,iaro);
79319 	   Harvest_Triples_NoFrag(nacc,npher,naro,iacc,ipher,iaro);
79320 
79321 	} else {
79322 
79323 	   Harvest_Triples_NoFrag(ndon,ndon,nphec,idon,idon,iphec);
79324 	   Harvest_Triples_NoFrag(ndon,ndon,npher,idon,idon,ipher);
79325 	   Harvest_Triples_NoFrag(ndon,nacc,nphec,idon,iacc,iphec);
79326 	   Harvest_Triples_NoFrag(ndon,nacc,npher,idon,iacc,ipher);
79327 	   Harvest_Triples_NoFrag(nacc,nacc,nphec,iacc,iacc,iphec);
79328 	   Harvest_Triples_NoFrag(nacc,nacc,npher,iacc,iacc,ipher);
79329 
79330 fprintf(stderr,"Aft Harvest_Triples_NoFrag: ntriS %d\n",ntriS);
79331 //	   TrimTriS(npair_nolink);
79332 	   Tris_NoLink();
79333 	}
79334 
79335 	fprintf(stderr,"Harvest_Triples: ntriS %d\n",ntriS);
79336 
79337 	Gen_triples();
79338 
79339 	if (imode == 1) {
79340 	   xyzp = pp;
79341 	   setiat(iatomsd);
79342 	   *(xyzp->mxnat)  = mxnatd;
79343 	   *(zmptrp->ihaszm) = ihaszmd;
79344 	}
79345 	fprintf(stderr,"Gen_Triples: matched protein triples ntris %d\n",ntris);
79346 
79347 	CalcSchInt();
79348 
79349    }
79350 
79351    if (imode == 1) {
79352       xyzp = pp;
79353       setiat(iatomsd);
79354       *(xyzp->mxnat)  = mxnatd;
79355       *(zmptrp->ihaszm) = ihaszmd;
79356    }
79357 
79358 
79359 if (debugdck) fprintf(stderr,"bef CalcAllInt: ntris %d\n",ntris);
79360 
79361    CalcAllInt(0,0);
79362 
79363 if (debugdck) fprintf(stderr,"aft CalcAllInt: ntris %d\n",ntris);
79364 
79365 if (debugdck) {
79366    fprintf(stderr,"bef Write_Results befrem.mol2 ntris %d\n",ntris);
79367    Write_Results("befrem.mol2",TriArr,ntris,&DCKxyz,0,0);
79368 }
79369 
79370    RemCC_All(0);
79371 
79372 if (debugdck) {
79373 
79374    fprintf(stderr,"Bef aftrem.mol2 ntris %d\n",ntris);
79375 
79376    Write_Results("aftrem.mol2",TriArr,ntris,&DCKxyz,0,1);
79377 
79378    fprintf(stderr,"after RemCC_All:  ntris %d\n",ntris);
79379 }
79380 
79381    Compress_Tri_L();
79382 
79383 if (debugdck) fprintf(stderr,"Bef Linkage_List ntris %d\n",ntris);
79384 
79385 // If we leave this in we dont get the any solutions with negative energy
79386 // passing this point. So the good ones are taken out !!!!!
79387 // Perhaps we should consider doing the linkage with e12 !!!
79388    if (ntris > 10 && ntris < 1000) Linkage_List();
79389 
79390    Compress_Tri_L();
79391 
79392 if (debugdck) fprintf(stderr,"after Compress_Tri_L:  ntris %d\n",ntris);
79393 
79394 
79395    Compress_Tri_List_e12();
79396 
79397 if (debugdck) Write_Results("dockbef.mol2",TriArr,ntris,&DCKxyz,0,1);
79398 
79399    if (ntris > 0) OptTris();
79400 
79401    if (MapConformers) Map_Conformers();
79402 
79403 if (debugdck) fprintf(stderr,"after #MapConformers %d ntris %d\n",MapConformers,ntris);
79404 
79405    if (ntris > 0) {
79406 	if (MapConformers) {
79407 	   qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmptriF);
79408 	} else {
79409 	   qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmpeint);
79410 	}
79411    }
79412 
79413 if (debugdck) {
79414    if (MapConformers) {
79415 	if (1) Write_Results("mconformers.mol2",TriArr,ntris,&DCKxyz,1,1);
79416 
79417         fprintf(stderr,"after Map_Conformers:  ntris %d\n",ntris);
79418    }
79419 }
79420 
79421    Loop_Opt_Dih(Ifrag,&DCKxyz,0);
79422 
79423 if (debugdck) {
79424 
79425    fprintf(stderr,"bef dockdih write:\n");
79426 
79427    for (i=0; i < ntris; i++) {
79428 	if (TriArr[i] != NULL) PrtTrp(i);
79429    }
79430 
79431    Write_Results("dockdih.mol2",TriArr,ntris,&DCKxyz,1,1);
79432 }
79433 
79434 // CalcAllInt calculates e12 = interaction energy between protein and
79435 // ligand. perhaps at this point it should be calculating Etot:
79436 // Etot: Etot = e12 + eint
79437 // after this do an other sort this time on Etot
79438 
79439    CalcAllInt(debugdck,1);
79440 
79441    if (ntris > 0) {
79442 	qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmpeint);
79443    }
79444 
79445    Score_Org_Ligand = 0;
79446    if (Score_Org_Ligand) OrgLig();
79447 
79448 //   wrt_TriArr();
79449 
79450    RemCC_All(1);
79451    Linkage_List();
79452    Compress_Tri_L();
79453 
79454    Conformers_Energies(&DCKxyz);
79455 
79456    if (ntris > 0) {
79457 	if (MapConformers) {
79458 	   qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmptriF);
79459 	} else {
79460 	   qsort((TRISTRU *) TriArr, ntris, sizeof(TRISTRU *), cmpeint);
79461 	}
79462    }
79463 
79464 if (debugdck) fprintf(stderr,"ntris %d dckout %s\n",ntris,dckout);
79465 
79466    Write_Results(dckout,TriArr,ntris,&DCKxyz,1,1);
79467 
79468 #if defined(VMS) || defined(UNDERSC)
79469    curs(&ZERO);
79470 #else
79471 #ifdef CRAY
79472    CURS(&ZERO);
79473 #else
79474    curs_(&ZERO);
79475 #endif
79476 #endif
79477 
79478 }
79479 
79480 
GetLig()79481 int GetLig()
79482 {
79483 	int i,j,k,i1,it,idum,igttnk,idebug,iffset,ipdbon,iheat,irng,irs,n;
79484 	int iatomsd,mxnatd,ihaszmd,size,fftmp;
79485 	double rdum,heat;
79486 	FILEOP tmpfil;
79487 	FILEOP nfil = {NULL, NULL, 0, 0, 0, 0};
79488 	char *ss;
79489 	double *ppcoo;
79490 	int *ppanz,*ppatclr;
79491 	COOSTRU *pp;
79492 
79493 	size = MXLIGA;
79494 
79495 	alldck(&DCKxyz,&size);
79496 
79497 
79498 	tmpfil = COO[istruct]->memfil;
79499 	fileop = nfil;
79500 
79501 	nomemf = 0;
79502 	filmem(0,dcklig);
79503 
79504 	iffset = 0;
79505 
79506 	iatomsd = *(xyzp->iatoms);
79507 	mxnatd = *(xyzp->mxnat);
79508 	ihaszmd = *(zmptrp->ihaszm);
79509 
79510 /* get ambfor xyz file (gaff atom types */
79511 
79512 	fftmp = *fftyp;
79513 
79514 	ppcoo = xyzp->coo;
79515 	ppanz = xyzp->ianz;
79516 	ppatclr = xyzp->iatclr;
79517 
79518 	xyzp->coo = DCKxyz.coo;
79519 	xyzp->ianz = DCKxyz.ianz;
79520 	xyzp->iatclr = DCKxyz.iatclr;
79521 
79522 	gettnd_(&igttnk,&idebug,&ipdbon,&iffset,&iheat,&heat,
79523 	DCKxyz.ianz,DCKxyz.iconn,DCKxyz.iatclr,DCKxyz.ityp,DCKxyz.coo,
79524 	DCKxyz.qat,DCKxyz.isurf,
79525 	&idum,&idum,&idum,&idum,&idum,&idum,&idum,&idum,
79526 	&rdum,&rdum,&rdum,&rdum,&rdum,&rdum,
79527 	&rdum,&rdum,&rdum,&rdum,&rdum,&rdum);
79528 
79529 	xyzp->coo = ppcoo;
79530 	xyzp->ianz = ppanz;
79531 	xyzp->iatclr = ppatclr;
79532 
79533 	if (!igttnk) {
79534 	   sprintf(cmdstr,"File %s is NOT [AMBFOR] format\n",dcklig);
79535 	   if (DoCan(event.xbutton.x_root, event.xbutton.y_root,cmdstr,0)) {}
79536 	   return(0);
79537 	}
79538 
79539 	*fftyp = fftmp;
79540 	DCKxyz.iatoms = &ndocka;
79541 	*DCKxyz.iatoms = *(xyzp->iatoms);
79542 
79543 /* convert to au */
79544 
79545 	for (i=0; i < ndocka; i++) {
79546 	   singleb.ityp[i] = DCKxyz.ityp[i];
79547 	}
79548 
79549 /* retype to sybyl atom types */
79550 
79551 	pp = xyzp;
79552 	xyzp = &DCKxyz;
79553 
79554 	for (i=0; i < ndocka; i++) {
79555 
79556 	   i1 = i + 1;
79557 	   DCKxyz.iaton[i] = 2;
79558 #if defined(VMS) || defined(UNDERSC)
79559 	   ispnd(&irs,&i1,&irng,&ONE,&ZERO,
79560 #else
79561 #ifdef CRAY
79562 	   ISPND(&irs,&i1,&irng,&ONE,&ZERO,
79563 #else
79564 	   ispnd_(&irs,&i1,&irng,&ONE,&ONE,
79565 #endif
79566 #endif
79567 	   DCKxyz.qat,DCKxyz.ianz,DCKxyz.iaton,DCKxyz.iconn,DCKxyz.lwrit,DCKxyz.lring);
79568 
79569 	   strcpy(strname,elemts[DCKxyz.ianz[i]-1]);
79570 	   strcat(strname,ATYPE[irs-1]);
79571 	   singleb.irsd[i] = IHBT[irs-1];
79572 
79573 	   ss = strname;
79574 	   if (strname[0] == ' ') ss++;
79575 
79576 	   for (j=0; j < MXMOL2; j++) {
79577 		if (strncmp(ss,mol2[j],5) == 0) DCKxyz.ityp[i] = j+1;
79578 	   }
79579 	}
79580 
79581 	fileop = tmpfil;
79582 	COO[istruct]->memfil = fileop;
79583 
79584 	xyzp = pp;
79585 
79586 	*(xyzp->iatoms) = iatomsd;
79587 	*(xyzp->mxnat)  = mxnatd;
79588 	*(zmptrp->ihaszm) = ihaszmd;
79589 
79590 	return(1);
79591 }
79592 
ogDockSphere()79593 void ogDockSphere()
79594 {
79595     int i,j,k,l,ires;
79596 
79597 #ifdef DOGL
79598     glEnable(GL_BLEND);
79599     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
79600     ogsphere(1,CNTDCK,DCKRadius,1);
79601     glDisable(GL_BLEND);
79602 #endif
79603 
79604 }
79605 
ProcProt()79606 void ProcProt()
79607 {
79608     int i,j,k,l,ic,ires,indx,clss,doit;
79609     float tmp1[3],tmp3[3],C1[3],C2[3],C3[3],tt,dd;
79610     double colv[3];
79611     INCRSTRU tmptyp;
79612     double roddef;
79613 
79614     if (DCKRadius*((double) toangs) > 8.0)
79615 	DCKRadius = 8.0/((double) toangs);
79616 
79617     if (*ipdbon && calfptr->ncalf != 0) {
79618 	indx = 0;
79619 	for (ires = 1; ires < calfptr->ncalf+1; ires++ ) {
79620 
79621 	   doit = 0;
79622 
79623 #if defined(VMS) || defined(UNDERSC)
79624 	   getpdb(&ires,ipdb,ihpdb);
79625 #else
79626 #ifdef CRAY
79627 	   GETPDB(&ires,ipdb,ihpdb);
79628 #else
79629    	   getpdb_(&ires,ipdb,ihpdb);
79630 #endif
79631 #endif
79632 	   for (i=0; i<MXSYM; i++) {
79633 		dd = 0.0;
79634 		if (ipdb[i] > 0) {
79635 	   	   for (j=0; j<3; j++) {
79636 			tt = ((float) xyzp->coo[(ipdb[i]-1)*3+j] - CNTDCK[j]);
79637 			dd = dd + tt*tt;
79638 		   }
79639 		   if (sqrt(dd) < DCKRadius) doit = 1;
79640 		}
79641 	   }
79642 
79643 	   for (i=0; i<3*MXHSYM; i++) {
79644 		dd = 0.0;
79645 		if (ihpdb[i] > 0) {
79646 	   	   for (j=0; j<3; j++) {
79647 			tt = ((float) xyzp->coo[(ihpdb[i]-1)*3+j] - CNTDCK[j]);
79648 			dd = dd + tt*tt;
79649 		   }
79650 		   if (sqrt(dd) < DCKRadius) doit = 1;
79651 		}
79652 	   }
79653 
79654 	if (doit) {
79655 	   if (calfptr->icalf[ires][1] != 0) {
79656 
79657 	   /* amide */
79658 
79659 	   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79660 	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79661 
79662 	   for (j=0; j<3; j++) {
79663 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[2]-1)*3+j];
79664 		   inttyp[indx]->c[1][j] =
79665 			xyzp->coo[(calfptr->icalf[ires][1]-1)*3+j];
79666 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[3]-1)*3+j];
79667 	   }
79668 	   inttyp[indx]->type = AMIDE;
79669 	   inttyp[indx]->area = AMID1;
79670 	   inttyp[indx]->res  = calfptr->irsnr[ires-1];
79671 
79672 	   cal_area(inttyp[indx]);
79673 	   indx++;
79674 
79675 	   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79676 	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79677 
79678 	   for (j=0; j<3; j++) {
79679 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[2]-1)*3+j];
79680 		   inttyp[indx]->c[1][j] = xyzp->coo[(calfptr->icalf[ires][1]-1)*3+j];
79681 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[3]-1)*3+j];
79682 	   }
79683 	   inttyp[indx]->type = AMIDE;
79684 	   inttyp[indx]->area = AMID2;
79685 	   inttyp[indx]->res  = calfptr->irsnr[ires-1];
79686 
79687 	   cal_area(inttyp[indx]);
79688 	   indx++;
79689 	   }
79690 
79691 	   /* backbone C=O */
79692 
79693 	   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79694 	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79695 
79696 	   for (j=0; j<3; j++) {
79697 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[3]-1)*3+j];
79698 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[2]-1)*3+j];
79699 	   }
79700 	   inttyp[indx]->type = H_ACC;
79701 	   inttyp[indx]->area = CO;
79702 	   inttyp[indx]->res  = calfptr->irsnr[ires-1];
79703 
79704 	   cal_area(inttyp[indx]);
79705 
79706 	   indx++;
79707 
79708 	   /* backbone NH */
79709 
79710 	   if ((ipdb[0] != 0 && ihpdb[0] != 0) &&
79711 		calfptr->iamino[ires-1] != 15 ) {
79712 
79713 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79714 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79715 
79716 		for (j=0; j<3; j++) {
79717 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[0]-1)*3+j];
79718 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[0]-1)*3+j];
79719 		}
79720 		inttyp[indx]->atom[0] = ihpdb[0]-1;
79721 		inttyp[indx]->atom[1] = ipdb[0]-1;
79722 		inttyp[indx]->type = H_DON;
79723 		inttyp[indx]->area = ONH;
79724 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
79725 
79726 		cal_area(inttyp[indx]);
79727 	   	indx++;
79728 	   }
79729 
79730 	   switch (calfptr->iamino[ires-1]) {
79731 	   case 3:
79732 	   case 4:
79733 	   case 5:
79734 	   /* serine, threonine */
79735 	   /* serine, threonine OH */
79736 
79737 	        if (calfptr->iamino[ires-1] != 4) {
79738 
79739 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79740 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79741 
79742 		   for (j=0; j<3; j++) {
79743 	              if (calfptr->iamino[ires-1] == 3) {
79744 			inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[9]-1)*3+j];
79745 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[30]-1)*3+j];
79746 		      } else if (calfptr->iamino[ires-1] == 5) {
79747 			inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[12]-1)*3+j];
79748 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[31]-1)*3+j];
79749 		      }
79750 		   }
79751 	           if (calfptr->iamino[ires-1] == 3) {
79752 			inttyp[indx]->atom[0] = ihpdb[9]-1;
79753 			inttyp[indx]->atom[1] = ipdb[30]-1;
79754 		   } else if (calfptr->iamino[ires-1] == 5) {
79755 			inttyp[indx]->atom[0] = ihpdb[12]-1;
79756 			inttyp[indx]->atom[1] = ipdb[31]-1;
79757 		   }
79758 		   inttyp[indx]->type = H_DON;
79759 		   inttyp[indx]->area = ONH;
79760 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
79761 
79762 		   cal_area(inttyp[indx]);
79763 	   	   indx++;
79764 
79765 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79766 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79767 
79768 		   for (j=0; j<3; j++) {
79769 	              if (calfptr->iamino[ires-1] == 3) {
79770 			inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[30]-1)*3+j];
79771 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[4]-1)*3+j];
79772 			inttyp[indx]->c[2][j] = xyzp->coo[(ihpdb[9]-1)*3+j];
79773 		      } else {
79774 			inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[31]-1)*3+j];
79775 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[4]-1)*3+j];
79776 			inttyp[indx]->c[2][j] = xyzp->coo[(ihpdb[12]-1)*3+j];
79777 		      }
79778 		   }
79779 		   inttyp[indx]->type = H_ACC;
79780 		   inttyp[indx]->area = OSP3;
79781 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
79782 
79783 		   cal_area(inttyp[indx]);
79784 	   	   indx++;
79785 
79786 		} else {
79787 
79788 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79789 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79790 
79791 		   for (j=0; j<3; j++) {
79792 			inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[36]-1)*3+j];
79793 		   }
79794 		   inttyp[indx]->type = SULFUR;
79795 		   inttyp[indx]->area = SPH2;
79796 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
79797 
79798 		   cal_area(inttyp[indx]);
79799 	   	   indx++;
79800 
79801 		}
79802 
79803 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79804 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79805 
79806 		for (j=0; j<3; j++) {
79807 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
79808 		}
79809 		inttyp[indx]->type = CH;
79810 		inttyp[indx]->area = SPH1;
79811 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
79812 
79813 		cal_area(inttyp[indx]);
79814 	   	indx++;
79815 
79816 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79817 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79818 
79819 		for (j=0; j<3; j++) {
79820 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
79821 		}
79822 	        if (calfptr->iamino[ires-1] != 5) {
79823 		   inttyp[indx]->type = CH2;
79824 		} else {
79825 		   inttyp[indx]->type = CH;
79826 		}
79827 		inttyp[indx]->area = SPH1;
79828 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
79829 
79830 		cal_area(inttyp[indx]);
79831 	   	indx++;
79832 
79833 	        if (calfptr->iamino[ires-1] == 5) {
79834 
79835 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79836 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79837 
79838 		for (j=0; j<3; j++) {
79839 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[7]-1)*3+j];
79840 		}
79841 		inttyp[indx]->type = CH3;
79842 		inttyp[indx]->area = SPH1;
79843 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
79844 
79845 		cal_area(inttyp[indx]);
79846 	   	indx++;
79847 
79848 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79849 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79850 
79851 		for (j=0; j<3; j++) {
79852 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[7]-1)*3+j];
79853 		}
79854 		inttyp[indx]->type = PHE_CH3;
79855 		inttyp[indx]->area = CH3_PHE;
79856 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
79857 
79858 		cal_area(inttyp[indx]);
79859 	   	indx++;
79860 
79861 		}
79862 
79863 		break;
79864 	   case 1:
79865 	   case 2:
79866 	   case 6:
79867 	   case 7:
79868 	   case 11:
79869 	   /* glycine, alanine, isoleucine, leucine */
79870 
79871 	   /* Calpha */
79872 
79873 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79874 		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79875 
79876 		for (j=0; j<3; j++) {
79877 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
79878 		}
79879 	        if (calfptr->iamino[ires-1] != 1) {
79880 		   inttyp[indx]->type = CH;
79881 		} else {
79882 		   inttyp[indx]->type = CH2;
79883 		}
79884 		inttyp[indx]->area = SPH1;
79885 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
79886 
79887 		cal_area(inttyp[indx]);
79888 	   	indx++;
79889 
79890 	        if (calfptr->iamino[ires-1] >= 2) {
79891 	   /* Cbeta */
79892 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79893 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79894 
79895 		   for (j=0; j<3; j++) {
79896 			inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
79897 		   }
79898 	           if (calfptr->iamino[ires-1] == 9 ||
79899 			calfptr->iamino[ires-1] == 11) {
79900 			inttyp[indx]->type = CH2;
79901 	           } else if (calfptr->iamino[ires-1] > 2) {
79902 			inttyp[indx]->type = CH;
79903 		   } else {
79904 			inttyp[indx]->type = CH3;
79905 		   }
79906 		   inttyp[indx]->area = SPH1;
79907 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
79908 
79909 		   cal_area(inttyp[indx]);
79910 	   	   indx++;
79911 
79912 	           if (calfptr->iamino[ires-1] == 2) {
79913 			inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79914 	   		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79915 
79916 			for (j=0; j<3; j++) {
79917 			   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
79918 			}
79919 			inttyp[indx]->type = PHE_CH3;
79920 			inttyp[indx]->area = CH3_PHE;
79921 	        	inttyp[indx]->res  = calfptr->irsnr[ires-1];
79922 
79923 			cal_area(inttyp[indx]);
79924 	   		indx++;
79925 		   }
79926 		}
79927 
79928 	        if (calfptr->iamino[ires-1] >= 6) {
79929 	   /* Cgamma */
79930 
79931 		   if (calfptr->iamino[ires-1] != 7 && ipdb[6] != 0) {
79932 			inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79933 	   		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79934 
79935 			for (j=0; j<3; j++) {
79936 			   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[6]-1)*3+j];
79937 			}
79938 	        	if (calfptr->iamino[ires-1] > 6) {
79939 			   inttyp[indx]->type = CH;
79940 			} else {
79941 			   inttyp[indx]->type = CH2;
79942 			}
79943 			inttyp[indx]->area = SPH1;
79944 	        	inttyp[indx]->res  = calfptr->irsnr[ires-1];
79945 
79946 			cal_area(inttyp[indx]);
79947 	   		indx++;
79948 		   }
79949 
79950 	           if (calfptr->iamino[ires-1] == 6 ||
79951 			calfptr->iamino[ires-1] == 7 ||
79952 			calfptr->iamino[ires-1] == 11) {
79953 			/* isoleucine cg2,cd1 and leucine cd1,cd2 */
79954 			/* valine cg1,cg2 */
79955 
79956 			inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79957 	   		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79958 
79959 			for (j=0; j<3; j++) {
79960 			   if (calfptr->iamino[ires-1] == 6) {
79961 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[7]-1)*3+j];
79962 			   } else if (calfptr->iamino[ires-1] == 11) {
79963 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[9]-1)*3+j];
79964 			   } else {
79965 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[6]-1)*3+j];
79966 			   }
79967 			}
79968 			inttyp[indx]->type = PHE_CH3;
79969 			inttyp[indx]->area = CH3_PHE;
79970 	        	inttyp[indx]->res  = calfptr->irsnr[ires-1];
79971 
79972 			cal_area(inttyp[indx]);
79973 	   		indx++;
79974 
79975 			inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79976 	   		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79977 
79978 			for (j=0; j<3; j++) {
79979 			   if (calfptr->iamino[ires-1] == 6) {
79980 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[7]-1)*3+j];
79981 			   } else if (calfptr->iamino[ires-1] == 11) {
79982 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[9]-1)*3+j];
79983 			   } else {
79984 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[6]-1)*3+j];
79985 			   }
79986 			}
79987 			inttyp[indx]->type = CH3;
79988 			inttyp[indx]->area = SPH1;
79989 	        	inttyp[indx]->res  = calfptr->irsnr[ires-1];
79990 
79991 			cal_area(inttyp[indx]);
79992 	   		indx++;
79993 
79994 			inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
79995 	   		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
79996 
79997 			for (j=0; j<3; j++) {
79998 			   if (calfptr->iamino[ires-1] == 6) {
79999 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[9]-1)*3+j];
80000 			   } else if (calfptr->iamino[ires-1] == 11) {
80001 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[10]-1)*3+j];
80002 			   } else {
80003 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[7]-1)*3+j];
80004 			   }
80005 			}
80006 			inttyp[indx]->type = PHE_CH3;
80007 			inttyp[indx]->area = CH3_PHE;
80008 	        	inttyp[indx]->res  = calfptr->irsnr[ires-1];
80009 
80010 			cal_area(inttyp[indx]);
80011 	   		indx++;
80012 
80013 			inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80014 	   		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80015 
80016 			for (j=0; j<3; j++) {
80017 			   if (calfptr->iamino[ires-1] == 6) {
80018 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[9]-1)*3+j];
80019 			   } else if (calfptr->iamino[ires-1] == 11) {
80020 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[10]-1)*3+j];
80021 			   } else {
80022 			      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[7]-1)*3+j];
80023 			   }
80024 			}
80025 			inttyp[indx]->type = CH3;
80026 			inttyp[indx]->area = SPH1;
80027 	        	inttyp[indx]->res  = calfptr->irsnr[ires-1];
80028 
80029 			cal_area(inttyp[indx]);
80030 	   		indx++;
80031 		   }
80032 		}
80033 
80034 		break;
80035 	   case 8:
80036 	   /* methionine */
80037 
80038 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80039 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80040 
80041 		for (j=0; j<3; j++) {
80042 		    inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[35]-1)*3+j];
80043 		}
80044 		inttyp[indx]->type = SULFUR;
80045 		inttyp[indx]->area = SPH2;
80046 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80047 
80048 		cal_area(inttyp[indx]);
80049 	   	indx++;
80050 
80051 	   /* Calpha */
80052 
80053 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80054 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80055 
80056 		for (j=0; j<3; j++) {
80057 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80058 		}
80059 		inttyp[indx]->type = CH;
80060 		inttyp[indx]->area = SPH1;
80061 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80062 
80063 		cal_area(inttyp[indx]);
80064 	   	indx++;
80065 
80066 	   /* Cbeta */
80067 
80068 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80069 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80070 
80071 		for (j=0; j<3; j++) {
80072 			inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80073 		}
80074 		inttyp[indx]->type = CH2;
80075 		inttyp[indx]->area = SPH1;
80076 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80077 
80078 		cal_area(inttyp[indx]);
80079 	   	indx++;
80080 
80081 	   /* Cgamma */
80082 
80083 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80084 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80085 
80086 		for (j=0; j<3; j++) {
80087 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80088 		}
80089 		inttyp[indx]->type = CH2;
80090 		inttyp[indx]->area = SPH1;
80091 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80092 
80093 		cal_area(inttyp[indx]);
80094 	   	indx++;
80095 
80096 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80097 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80098 
80099 		for (j=0; j<3; j++) {
80100 		      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[11]-1)*3+j];
80101 		}
80102 		inttyp[indx]->type = PHE_CH3;
80103 		inttyp[indx]->area = CH3_PHE;
80104 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80105 
80106 		cal_area(inttyp[indx]);
80107 	   	indx++;
80108 
80109 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80110 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80111 
80112 		for (j=0; j<3; j++) {
80113 		      inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[11]-1)*3+j];
80114 		}
80115 		inttyp[indx]->type = CH3;
80116 		inttyp[indx]->area = SPH1;
80117 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80118 
80119 		cal_area(inttyp[indx]);
80120 	   	indx++;
80121 
80122 		break;
80123 	   case 9:
80124 	   /* asparate */
80125 	   /* OD1, CG, OD2 */
80126 
80127 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80128 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80129 
80130 		for (j=0; j<3; j++) {
80131 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[28]-1)*3+j];
80132 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80133 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[29]-1)*3+j];
80134 		}
80135 		inttyp[indx]->q0 = -0.5;
80136 		inttyp[indx]->q1 =  0.0;
80137 		inttyp[indx]->q2 = -0.5;
80138 		inttyp[indx]->type = H_ACC;
80139 		inttyp[indx]->area = COOmin;
80140 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80141 
80142 		cal_area(inttyp[indx]);
80143 
80144 	   	indx++;
80145 
80146 	   /* OD2, CG, OD1 */
80147 
80148 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80149 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80150 
80151 		for (j=0; j<3; j++) {
80152 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[29]-1)*3+j];
80153 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80154 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[28]-1)*3+j];
80155 		}
80156 		inttyp[indx]->type = H_ACC;
80157 		inttyp[indx]->area = COOmin;
80158 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80159 
80160 		cal_area(inttyp[indx]);
80161 
80162 	   	indx++;
80163 
80164 	   /* Calpha */
80165 
80166 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80167 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80168 
80169 		for (j=0; j<3; j++) {
80170 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80171 		}
80172 		inttyp[indx]->type = CH;
80173 		inttyp[indx]->area = SPH1;
80174 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80175 
80176 		cal_area(inttyp[indx]);
80177 	   	indx++;
80178 
80179 	   /* Cbeta */
80180 
80181 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80182 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80183 
80184 		for (j=0; j<3; j++) {
80185 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80186 		}
80187 		inttyp[indx]->type = CH2;
80188 		inttyp[indx]->area = SPH1;
80189 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80190 
80191 		cal_area(inttyp[indx]);
80192 	   	indx++;
80193 
80194 		break;
80195 	   case 10:
80196 	   /* asparagine */
80197 	   /* ND2 HD21/HD22 */
80198 
80199 
80200 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80201 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80202 
80203 		for (j=0; j<3; j++) {
80204 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[21]-1)*3+j];
80205 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[20]-1)*3+j];
80206 		}
80207 		inttyp[indx]->atom[0] = ihpdb[21]-1;
80208 		inttyp[indx]->atom[1] = ipdb[20]-1;
80209 		inttyp[indx]->type = H_DON;
80210 		inttyp[indx]->area = ONH;
80211 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80212 
80213 		cal_area(inttyp[indx]);
80214 		indx++;
80215 
80216 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80217 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80218 
80219 		for (j=0; j<3; j++) {
80220 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[24]-1)*3+j];
80221 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[20]-1)*3+j];
80222 		}
80223 		inttyp[indx]->atom[0] = ihpdb[24]-1;
80224 		inttyp[indx]->atom[1] = ipdb[20]-1;
80225 		inttyp[indx]->type = H_DON;
80226 		inttyp[indx]->area = ONH;
80227 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80228 
80229 		cal_area(inttyp[indx]);
80230 		indx++;
80231 
80232 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80233 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80234 
80235 		for (j=0; j<3; j++) {
80236 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[28]-1)*3+j];
80237 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80238 		}
80239 		inttyp[indx]->type = H_ACC;
80240 		inttyp[indx]->area = CO;
80241 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80242 
80243 		cal_area(inttyp[indx]);
80244 		indx++;
80245 
80246 	   /* Calpha */
80247 
80248 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80249 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80250 
80251 		for (j=0; j<3; j++) {
80252 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80253 		}
80254 		inttyp[indx]->type = CH;
80255 		inttyp[indx]->area = SPH1;
80256 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80257 
80258 		cal_area(inttyp[indx]);
80259 	   	indx++;
80260 
80261 	   /* Cbeta */
80262 
80263 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80264 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80265 
80266 		for (j=0; j<3; j++) {
80267 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80268 		}
80269 		inttyp[indx]->type = CH2;
80270 		inttyp[indx]->area = SPH1;
80271 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80272 
80273 		cal_area(inttyp[indx]);
80274 	   	indx++;
80275 
80276 		break;
80277 	   case 12:
80278 	   /* Lysine */
80279 
80280 		if (ihpdb[41] == 0) {
80281 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80282 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80283 
80284 		for (j=0; j<3; j++) {
80285 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[26]-1)*3+j];
80286 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[11]-1)*3+j];
80287 		   inttyp[indx]->c[2][j] = xyzp->coo[(ihpdb[39]-1)*3+j];
80288 		   inttyp[indx]->c[3][j] = xyzp->coo[(ihpdb[40]-1)*3+j];
80289 		}
80290 		inttyp[indx]->type = H_ACC;
80291 		inttyp[indx]->area = NAMINO;
80292 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80293 
80294 		cal_area(inttyp[indx]);
80295 	   	indx++;
80296 		}
80297 
80298 		/* hz_1 nz */
80299 
80300 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80301 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80302 
80303 		for (j=0; j<3; j++) {
80304 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[39]-1)*3+j];
80305 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[26]-1)*3+j];
80306 		}
80307 		inttyp[indx]->q0 = 0.0;
80308 		inttyp[indx]->q1 = 1.0;
80309 		inttyp[indx]->type = H_DON;
80310 		inttyp[indx]->area = NHP;
80311 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80312 
80313 		cal_area(inttyp[indx]);
80314 		indx++;
80315 
80316 		/* hz_2 nz */
80317 
80318 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80319 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80320 
80321 		for (j=0; j<3; j++) {
80322 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[40]-1)*3+j];
80323 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[26]-1)*3+j];
80324 		}
80325 		inttyp[indx]->q0 = 0.0;
80326 		inttyp[indx]->q1 = 1.0;
80327 		inttyp[indx]->type = H_DON;
80328 		inttyp[indx]->area = NHP;
80329 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80330 
80331 		cal_area(inttyp[indx]);
80332 		indx++;
80333 
80334 		/* hz_3 nz */
80335 
80336 		if (ihpdb[41] != 0) {
80337 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80338 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80339 
80340 		for (j=0; j<3; j++) {
80341 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[41]-1)*3+j];
80342 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[26]-1)*3+j];
80343 		}
80344 		inttyp[indx]->q0 = 0.0;
80345 		inttyp[indx]->q1 = 1.0;
80346 		inttyp[indx]->type = H_DON;
80347 		inttyp[indx]->area = NHP;
80348 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80349 
80350 		cal_area(inttyp[indx]);
80351 		indx++;
80352 		}
80353 
80354 	   /* Calpha */
80355 
80356 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80357 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80358 
80359 		for (j=0; j<3; j++) {
80360 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80361 		}
80362 		inttyp[indx]->type = CH;
80363 		inttyp[indx]->area = SPH1;
80364 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80365 
80366 		cal_area(inttyp[indx]);
80367 	   	indx++;
80368 
80369 	   /* Cbeta */
80370 
80371 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80372 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80373 
80374 		for (j=0; j<3; j++) {
80375 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80376 		}
80377 		inttyp[indx]->type = CH2;
80378 		inttyp[indx]->area = SPH1;
80379 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80380 
80381 		cal_area(inttyp[indx]);
80382 	   	indx++;
80383 
80384 	   /* Cgamma */
80385 
80386 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80387 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80388 
80389 		for (j=0; j<3; j++) {
80390 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80391 		}
80392 		inttyp[indx]->type = CH2;
80393 		inttyp[indx]->area = SPH1;
80394 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80395 
80396 		cal_area(inttyp[indx]);
80397 	   	indx++;
80398 
80399 	   /* Cdelta */
80400 
80401 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80402 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80403 
80404 		for (j=0; j<3; j++) {
80405 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[8]-1)*3+j];
80406 		}
80407 		inttyp[indx]->type = CH2;
80408 		inttyp[indx]->area = SPH1;
80409 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80410 
80411 		cal_area(inttyp[indx]);
80412 	   	indx++;
80413 
80414 	   /* Cepsilon */
80415 
80416 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80417 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80418 
80419 		for (j=0; j<3; j++) {
80420 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[11]-1)*3+j];
80421 		}
80422 		inttyp[indx]->type = CH2;
80423 		inttyp[indx]->area = SPH1;
80424 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80425 
80426 		cal_area(inttyp[indx]);
80427 	   	indx++;
80428 
80429 		break;
80430 	   case 13:
80431 	   /* glutamate */
80432 	   /* OE1, CD, OE2 */
80433 
80434 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80435 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80436 
80437 		for (j=0; j<3; j++) {
80438 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[33]-1)*3+j];
80439 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[8]-1)*3+j];
80440 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[34]-1)*3+j];
80441 		}
80442 		inttyp[indx]->q0 = -0.5;
80443 		inttyp[indx]->q1 =  0.0;
80444 		inttyp[indx]->q2 = -0.5;
80445 		inttyp[indx]->type = H_ACC;
80446 		inttyp[indx]->area = COOmin;
80447 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80448 
80449 		cal_area(inttyp[indx]);
80450 if (calfptr->irsnr[ires-1] == 353) MTXCOO1 = indx;
80451 	   	indx++;
80452 
80453 	   /* OE2, CD, OE1 */
80454 
80455 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80456 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80457 
80458 		for (j=0; j<3; j++) {
80459 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[34]-1)*3+j];
80460 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[8]-1)*3+j];
80461 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[33]-1)*3+j];
80462 		}
80463 		inttyp[indx]->type = H_ACC;
80464 		inttyp[indx]->area = COOmin;
80465 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80466 
80467 		cal_area(inttyp[indx]);
80468 if (calfptr->irsnr[ires-1] == 353) MTXCOO2 = indx;
80469 	   	indx++;
80470 
80471 	   /* Calpha */
80472 
80473 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80474 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80475 
80476 		for (j=0; j<3; j++) {
80477 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80478 		}
80479 		inttyp[indx]->type = CH;
80480 		inttyp[indx]->area = SPH1;
80481 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80482 
80483 		cal_area(inttyp[indx]);
80484 	   	indx++;
80485 
80486 	   /* Cbeta */
80487 
80488 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80489 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80490 
80491 		for (j=0; j<3; j++) {
80492 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80493 		}
80494 		inttyp[indx]->type = CH2;
80495 		inttyp[indx]->area = SPH1;
80496 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80497 
80498 		cal_area(inttyp[indx]);
80499 	   	indx++;
80500 
80501 	   /* Cgamma */
80502 
80503 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80504 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80505 
80506 		for (j=0; j<3; j++) {
80507 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80508 		}
80509 		inttyp[indx]->type = CH2;
80510 		inttyp[indx]->area = SPH1;
80511 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80512 
80513 		cal_area(inttyp[indx]);
80514 	   	indx++;
80515 
80516 		break;
80517 	   case 14:
80518 	   /* glutamine */
80519 	   /* NE2 HE21/HE22 */
80520 
80521 
80522 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80523 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80524 
80525 		for (j=0; j<3; j++) {
80526 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[33]-1)*3+j];
80527 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[23]-1)*3+j];
80528 		}
80529 		inttyp[indx]->atom[0] = ihpdb[33]-1;
80530 		inttyp[indx]->atom[1] = ipdb[23]-1;
80531 		inttyp[indx]->type = H_DON;
80532 		inttyp[indx]->area = ONH;
80533 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80534 
80535 		cal_area(inttyp[indx]);
80536 		indx++;
80537 
80538 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80539 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80540 
80541 		for (j=0; j<3; j++) {
80542 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[34]-1)*3+j];
80543 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[23]-1)*3+j];
80544 		}
80545 		inttyp[indx]->atom[0] = ihpdb[34]-1;
80546 		inttyp[indx]->atom[1] = ipdb[23]-1;
80547 		inttyp[indx]->type = H_DON;
80548 		inttyp[indx]->area = ONH;
80549 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80550 
80551 		cal_area(inttyp[indx]);
80552 		indx++;
80553 
80554 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80555 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80556 
80557 		for (j=0; j<3; j++) {
80558 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[33]-1)*3+j];
80559 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[8]-1)*3+j];
80560 		}
80561 		inttyp[indx]->type = H_ACC;
80562 		inttyp[indx]->area = CO;
80563 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80564 
80565 		cal_area(inttyp[indx]);
80566 		indx++;
80567 
80568 	   /* Calpha */
80569 
80570 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80571 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80572 
80573 		for (j=0; j<3; j++) {
80574 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80575 		}
80576 		inttyp[indx]->type = CH;
80577 		inttyp[indx]->area = SPH1;
80578 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80579 
80580 		cal_area(inttyp[indx]);
80581 	   	indx++;
80582 
80583 	   /* Cbeta */
80584 
80585 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80586 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80587 
80588 		for (j=0; j<3; j++) {
80589 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80590 		}
80591 		inttyp[indx]->type = CH2;
80592 		inttyp[indx]->area = SPH1;
80593 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80594 
80595 		cal_area(inttyp[indx]);
80596 	   	indx++;
80597 
80598 	   /* Cgamma */
80599 
80600 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80601 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80602 
80603 		for (j=0; j<3; j++) {
80604 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80605 		}
80606 		inttyp[indx]->type = CH2;
80607 		inttyp[indx]->area = SPH1;
80608 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80609 
80610 		cal_area(inttyp[indx]);
80611 	   	indx++;
80612 
80613 		break;
80614 	   case 15:
80615 	   /* Proline */
80616 	   /* Calpha */
80617 
80618 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80619 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80620 
80621 		for (j=0; j<3; j++) {
80622 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80623 		}
80624 		inttyp[indx]->type = CH;
80625 		inttyp[indx]->area = SPH1;
80626 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80627 
80628 		cal_area(inttyp[indx]);
80629 	   	indx++;
80630 
80631 	   /* Cbeta */
80632 
80633 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80634 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80635 
80636 		for (j=0; j<3; j++) {
80637 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80638 		}
80639 		inttyp[indx]->type = CH2;
80640 		inttyp[indx]->area = SPH1;
80641 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80642 
80643 		cal_area(inttyp[indx]);
80644 	   	indx++;
80645 
80646 	   /* Cgamma */
80647 
80648 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80649 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80650 
80651 		for (j=0; j<3; j++) {
80652 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80653 		}
80654 		inttyp[indx]->type = CH2;
80655 		inttyp[indx]->area = SPH1;
80656 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80657 
80658 		cal_area(inttyp[indx]);
80659 	   	indx++;
80660 
80661 	   /* Cdelta */
80662 
80663 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80664 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80665 
80666 		for (j=0; j<3; j++) {
80667 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[8]-1)*3+j];
80668 		}
80669 		inttyp[indx]->type = CH2;
80670 		inttyp[indx]->area = SPH1;
80671 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80672 
80673 		cal_area(inttyp[indx]);
80674 	   	indx++;
80675 
80676 		break;
80677 	   case 16:
80678 	   /* Arginine */
80679 	   /* ne-he */
80680 
80681 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80682 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80683 
80684 		for (j=0; j<3; j++) {
80685 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[27]-1)*3+j];
80686 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[21]-1)*3+j];
80687 		}
80688 		inttyp[indx]->q0 = 0.0;
80689 		inttyp[indx]->q1 = 0.333;
80690 		inttyp[indx]->atom[0] = ihpdb[27]-1;
80691 		inttyp[indx]->atom[1] = ipdb[21]-1;
80692 		inttyp[indx]->type = H_DON;
80693 		inttyp[indx]->area = ONH;
80694 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80695 
80696 		cal_area(inttyp[indx]);
80697 	   	indx++;
80698 
80699 	   /* nh1-hh11 */
80700 
80701 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80702 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80703 
80704 		for (j=0; j<3; j++) {
80705 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[54]-1)*3+j];
80706 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[24]-1)*3+j];
80707 		}
80708 		inttyp[indx]->q0 = 0.0;
80709 		inttyp[indx]->q1 = 0.333;
80710 		inttyp[indx]->atom[0] = ihpdb[54]-1;
80711 		inttyp[indx]->atom[1] = ipdb[24]-1;
80712 		inttyp[indx]->type = H_DON;
80713 		inttyp[indx]->area = ONH;
80714 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80715 
80716 		cal_area(inttyp[indx]);
80717 	   	indx++;
80718 
80719 	   /* nh1-hh12 */
80720 
80721 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80722 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80723 
80724 		for (j=0; j<3; j++) {
80725 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[55]-1)*3+j];
80726 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[24]-1)*3+j];
80727 		}
80728 		inttyp[indx]->q0 = 0.0;
80729 		inttyp[indx]->q1 = 0.333;
80730 		inttyp[indx]->atom[0] = ihpdb[55]-1;
80731 		inttyp[indx]->atom[1] = ipdb[24]-1;
80732 		inttyp[indx]->type = H_DON;
80733 		inttyp[indx]->area = ONH;
80734 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80735 
80736 		cal_area(inttyp[indx]);
80737 	   	indx++;
80738 
80739 	   /* nh2-hh21 */
80740 
80741 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80742 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80743 
80744 		for (j=0; j<3; j++) {
80745 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[57]-1)*3+j];
80746 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[25]-1)*3+j];
80747 		}
80748 		inttyp[indx]->q0 = 0.0;
80749 		inttyp[indx]->q1 = 0.333;
80750 		inttyp[indx]->atom[0] = ihpdb[57]-1;
80751 		inttyp[indx]->atom[1] = ipdb[25]-1;
80752 		inttyp[indx]->type = H_DON;
80753 		inttyp[indx]->area = ONH;
80754 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80755 
80756 		cal_area(inttyp[indx]);
80757 	   	indx++;
80758 
80759 	   /* nh2-hh22 */
80760 
80761 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80762 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80763 
80764 		for (j=0; j<3; j++) {
80765 		   inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[58]-1)*3+j];
80766 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[25]-1)*3+j];
80767 		}
80768 		inttyp[indx]->q0 = 0.0;
80769 		inttyp[indx]->q1 = 0.333;
80770 		inttyp[indx]->atom[0] = ihpdb[58]-1;
80771 		inttyp[indx]->atom[1] = ipdb[25]-1;
80772 		inttyp[indx]->type = H_DON;
80773 		inttyp[indx]->area = ONH;
80774 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80775 
80776 		cal_area(inttyp[indx]);
80777 	   	indx++;
80778 
80779 	   /* Calpha */
80780 
80781 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80782 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80783 
80784 		for (j=0; j<3; j++) {
80785 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80786 		}
80787 		inttyp[indx]->type = CH;
80788 		inttyp[indx]->area = SPH1;
80789 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80790 
80791 		cal_area(inttyp[indx]);
80792 	   	indx++;
80793 
80794 	   /* Cbeta */
80795 
80796 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80797 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80798 
80799 		for (j=0; j<3; j++) {
80800 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80801 		}
80802 		inttyp[indx]->type = CH2;
80803 		inttyp[indx]->area = SPH1;
80804 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80805 
80806 		cal_area(inttyp[indx]);
80807 	   	indx++;
80808 
80809 	   /* Cgamma */
80810 
80811 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80812 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80813 
80814 		for (j=0; j<3; j++) {
80815 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80816 		}
80817 		inttyp[indx]->type = CH2;
80818 		inttyp[indx]->area = SPH1;
80819 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80820 
80821 		cal_area(inttyp[indx]);
80822 	   	indx++;
80823 
80824 		break;
80825 	   case 17:
80826 	   /* Histidine */
80827 
80828 		if ((ihpdb[21] != 0 && ihpdb[33] != 0) ||
80829 			(ihpdb[21] != 0 && ihpdb[33] == 0)) {
80830 
80831 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80832 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80833 
80834 		   for (j=0; j<3; j++) {
80835 			inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[21]-1)*3+j];
80836 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[19]-1)*3+j];
80837 		   }
80838 		   if (ihpdb[21] != 0 && ihpdb[33] != 0) {
80839 			inttyp[indx]->type = H_DON;
80840 			inttyp[indx]->area = NHP;
80841 		   } else {
80842 			inttyp[indx]->atom[0] = ihpdb[21]-1;
80843 			inttyp[indx]->atom[1] = ipdb[19]-1;
80844 			inttyp[indx]->type = H_DON;
80845 			inttyp[indx]->area = ONH;
80846 		   }
80847 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
80848 
80849 		   cal_area(inttyp[indx]);
80850 		   indx++;
80851 
80852 		}
80853 
80854 		if ((ihpdb[21] != 0 && ihpdb[33] != 0) ||
80855 			(ihpdb[33] != 0 && ihpdb[21] == 0)) {
80856 
80857 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80858 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80859 
80860 		   for (j=0; j<3; j++) {
80861 			inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[33]-1)*3+j];
80862 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[23]-1)*3+j];
80863 		   }
80864 		   if (ihpdb[21] != 0 && ihpdb[33] != 0) {
80865 			inttyp[indx]->type = H_DON;
80866 			inttyp[indx]->area = NHP;
80867 		   } else {
80868 			inttyp[indx]->atom[0] = ihpdb[33]-1;
80869 			inttyp[indx]->atom[1] = ipdb[33]-1;
80870 			inttyp[indx]->type = H_DON;
80871 			inttyp[indx]->area = ONH;
80872 		   }
80873 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
80874 
80875 		   cal_area(inttyp[indx]);
80876 		   indx++;
80877 		}
80878 
80879 		if (ihpdb[21] == 0 || ihpdb[33] == 0) {
80880 
80881 
80882 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80883 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80884 
80885 		   for (j=0; j<3; j++) {
80886 		     if (ihpdb[21] == 0) {
80887 			/* HIE */
80888 			inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[19]-1)*3+j];
80889 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[12]-1)*3+j];
80890 			inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80891 		     } else {
80892 			/* HID */
80893 			inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[23]-1)*3+j];
80894 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[12]-1)*3+j];
80895 			inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[10]-1)*3+j];
80896 		     }
80897 		   }
80898 
80899 		   inttyp[indx]->type = H_ACC;
80900 		   inttyp[indx]->area = NARYL;
80901 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
80902 
80903 		   cal_area(inttyp[indx]);
80904 if (calfptr->irsnr[ires-1] == 524)  MTXCO1 = indx;
80905 
80906 		   indx++;
80907 		}
80908 
80909 	   /* Calpha */
80910 
80911 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80912 		memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80913 
80914 		for (j=0; j<3; j++) {
80915 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
80916 		}
80917 		inttyp[indx]->type = CH;
80918 		inttyp[indx]->area = SPH1;
80919 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80920 
80921 		cal_area(inttyp[indx]);
80922 	   	indx++;
80923 
80924 	   /* Cbeta */
80925 
80926 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80927 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80928 
80929 		for (j=0; j<3; j++) {
80930 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
80931 		}
80932 		inttyp[indx]->type = CH2;
80933 		inttyp[indx]->area = SPH1;
80934 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80935 
80936 		cal_area(inttyp[indx]);
80937 	   	indx++;
80938 
80939 	   /* Cgamma */
80940 
80941 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80942 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80943 
80944 		for (j=0; j<3; j++) {
80945 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
80946 		}
80947 		inttyp[indx]->type = ARO;
80948 		inttyp[indx]->area = SPH1;
80949 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80950 
80951 		cal_area(inttyp[indx]);
80952 	   	indx++;
80953 
80954 	   /* CE1 */
80955 
80956 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80957 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80958 
80959 		for (j=0; j<3; j++) {
80960 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[12]-1)*3+j];
80961 		}
80962 		inttyp[indx]->type = ARO;
80963 		inttyp[indx]->area = SPH1;
80964 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80965 
80966 		cal_area(inttyp[indx]);
80967 	   	indx++;
80968 
80969 	   /* CD2 */
80970 
80971 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80972 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80973 
80974 		for (j=0; j<3; j++) {
80975 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[10]-1)*3+j];
80976 		}
80977 		inttyp[indx]->type = ARO;
80978 		inttyp[indx]->area = SPH1;
80979 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
80980 
80981 		cal_area(inttyp[indx]);
80982 	   	indx++;
80983 
80984 		break;
80985 	   case 18:
80986 	   case 19:
80987 	   /* phenylalanine, tyrosine */
80988 
80989 	        if (calfptr->iamino[ires-1] == 19) {
80990 
80991 		   /* OH */
80992 
80993 		   inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
80994 	   	   memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
80995 
80996 		   for (j=0; j<3; j++) {
80997 			inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[51]-1)*3+j];
80998 			inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[32]-1)*3+j];
80999 		   }
81000 		   inttyp[indx]->atom[0] = ihpdb[51]-1;
81001 		   inttyp[indx]->atom[1] = ipdb[32]-1;
81002 		   inttyp[indx]->type = H_DON;
81003 		   inttyp[indx]->area = ONH;
81004 	           inttyp[indx]->res  = calfptr->irsnr[ires-1];
81005 
81006 		   cal_area(inttyp[indx]);
81007 	   	   indx++;
81008 
81009 		}
81010 
81011 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81012 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81013 
81014 		for (j=0; j<3; j++) {
81015 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
81016 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[16]-1)*3+j];
81017 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[9]-1)*3+j];
81018 		}
81019 		inttyp[indx]->type = PHENYL_CENTER;
81020 		inttyp[indx]->area = PHC1;
81021 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81022 
81023 		cal_area(inttyp[indx]);
81024 	   	indx++;
81025 
81026 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81027 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81028 
81029 		for (j=0; j<3; j++) {
81030 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
81031 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[16]-1)*3+j];
81032 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[9]-1)*3+j];
81033 		}
81034 		inttyp[indx]->type = PHENYL_CENTER;
81035 		inttyp[indx]->area = PHC2;
81036 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81037 
81038 		cal_area(inttyp[indx]);
81039 	   	indx++;
81040 
81041 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81042 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81043 
81044 		for (j=0; j<3; j++) {
81045 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[9]-1)*3+j];
81046 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[5]-1)*3+j];
81047 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[12]-1)*3+j];
81048 		}
81049 		inttyp[indx]->type = PHENYL_RING;
81050 		inttyp[indx]->area = PHR;
81051 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81052 
81053 		cal_area(inttyp[indx]);
81054 if (calfptr->irsnr[ires-1] == 404)  {
81055  MTXCO2 = indx;
81056 }
81057 	   	indx++;
81058 
81059 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81060 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81061 
81062 		for (j=0; j<3; j++) {
81063 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[12]-1)*3+j];
81064 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[9]-1)*3+j];
81065 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[16]-1)*3+j];
81066 		}
81067 		inttyp[indx]->type = PHENYL_RING;
81068 		inttyp[indx]->area = PHR;
81069 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81070 
81071 		cal_area(inttyp[indx]);
81072 if (calfptr->irsnr[ires-1] == 404)  {
81073  MTXCO3 = indx;
81074 }
81075 	   	indx++;
81076 
81077 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81078 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81079 
81080 		for (j=0; j<3; j++) {
81081 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[10]-1)*3+j];
81082 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[5]-1)*3+j];
81083 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[13]-1)*3+j];
81084 		}
81085 		inttyp[indx]->type = PHENYL_RING;
81086 		inttyp[indx]->area = PHR;
81087 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81088 
81089 		cal_area(inttyp[indx]);
81090 	   	indx++;
81091 
81092 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81093 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81094 
81095 		for (j=0; j<3; j++) {
81096 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[13]-1)*3+j];
81097 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[10]-1)*3+j];
81098 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[16]-1)*3+j];
81099 		}
81100 		inttyp[indx]->type = PHENYL_RING;
81101 		inttyp[indx]->area = PHR;
81102 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81103 
81104 		cal_area(inttyp[indx]);
81105 	   	indx++;
81106 
81107 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81108 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81109 
81110 		for (j=0; j<3; j++) {
81111 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[16]-1)*3+j];
81112 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[12]-1)*3+j];
81113 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[13]-1)*3+j];
81114 		}
81115 		inttyp[indx]->type = PHENYL_RING;
81116 		inttyp[indx]->area = PHR;
81117 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81118 
81119 		cal_area(inttyp[indx]);
81120 	   	indx++;
81121 
81122 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81123 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81124 
81125 		for (j=0; j<3; j++) {
81126 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
81127 		}
81128 		inttyp[indx]->type = CH;
81129 		inttyp[indx]->area = SPH1;
81130 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81131 
81132 		cal_area(inttyp[indx]);
81133 	   	indx++;
81134 
81135 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81136 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81137 
81138 		for (j=0; j<3; j++) {
81139 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
81140 		}
81141 		inttyp[indx]->type = CH2;
81142 		inttyp[indx]->area = SPH1;
81143 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81144 
81145 		cal_area(inttyp[indx]);
81146 	   	indx++;
81147 
81148 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81149 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81150 
81151 		for (j=0; j<3; j++) {
81152 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
81153 		}
81154 		inttyp[indx]->type = ARO;
81155 		inttyp[indx]->area = SPH1;
81156 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81157 
81158 		cal_area(inttyp[indx]);
81159 	   	indx++;
81160 
81161 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81162 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81163 
81164 		for (j=0; j<3; j++) {
81165 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[9]-1)*3+j];
81166 		}
81167 		inttyp[indx]->type = ARO;
81168 		inttyp[indx]->area = SPH1;
81169 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81170 
81171 		cal_area(inttyp[indx]);
81172 	   	indx++;
81173 
81174 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81175 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81176 
81177 		for (j=0; j<3; j++) {
81178 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[10]-1)*3+j];
81179 		}
81180 		inttyp[indx]->type = ARO;
81181 		inttyp[indx]->area = SPH1;
81182 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81183 
81184 		cal_area(inttyp[indx]);
81185 	   	indx++;
81186 
81187 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81188 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81189 
81190 		for (j=0; j<3; j++) {
81191 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[12]-1)*3+j];
81192 		}
81193 		inttyp[indx]->type = ARO;
81194 		inttyp[indx]->area = SPH1;
81195 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81196 
81197 		cal_area(inttyp[indx]);
81198 	   	indx++;
81199 
81200 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81201 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81202 
81203 		for (j=0; j<3; j++) {
81204 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[13]-1)*3+j];
81205 		}
81206 		inttyp[indx]->type = ARO;
81207 		inttyp[indx]->area = SPH1;
81208 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81209 
81210 		cal_area(inttyp[indx]);
81211 	   	indx++;
81212 
81213 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81214 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81215 
81216 		for (j=0; j<3; j++) {
81217 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[16]-1)*3+j];
81218 		}
81219 		inttyp[indx]->type = ARO;
81220 		inttyp[indx]->area = SPH1;
81221 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81222 
81223 		cal_area(inttyp[indx]);
81224 	   	indx++;
81225 
81226 		break;
81227 	   case 20:
81228 	   /* tryptofan */
81229 
81230 
81231 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81232 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81233 
81234 		for (j=0; j<3; j++) {
81235 		   if (ihpdb[29] > 0) {
81236 		      inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[29]-1)*3+j];
81237 		   } else if (ihpdb[31] > 0) {
81238 		      inttyp[indx]->c[0][j] = xyzp->coo[(ihpdb[31]-1)*3+j];
81239 		   }
81240 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[22]-1)*3+j];
81241 		}
81242 		if (ihpdb[29] > 0) {
81243 		   inttyp[indx]->atom[0] = ihpdb[29]-1;
81244 		} else if (ihpdb[31] > 0) {
81245 		   inttyp[indx]->atom[0] = ihpdb[31]-1;
81246 		}
81247 		inttyp[indx]->atom[1] = ipdb[22]-1;
81248 		inttyp[indx]->type = H_DON;
81249 		inttyp[indx]->area = ONH;
81250 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81251 
81252 		cal_area(inttyp[indx]);
81253 	   	indx++;
81254 
81255 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81256 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81257 
81258 		for (j=0; j<3; j++) {
81259 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[14]-1)*3+j];
81260 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[17]-1)*3+j];
81261 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[10]-1)*3+j];
81262 		}
81263 		inttyp[indx]->type = PHENYL_CENTER;
81264 		inttyp[indx]->area = PHC1;
81265 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81266 
81267 		cal_area(inttyp[indx]);
81268 	   	indx++;
81269 
81270 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81271 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81272 
81273 		for (j=0; j<3; j++) {
81274 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[14]-1)*3+j];
81275 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[10]-1)*3+j];
81276 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[18]-1)*3+j];
81277 		}
81278 		inttyp[indx]->type = PHENYL_CENTER;
81279 		inttyp[indx]->area = PHC2;
81280 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81281 
81282 		cal_area(inttyp[indx]);
81283 	   	indx++;
81284 
81285 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81286 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81287 
81288 		for (j=0; j<3; j++) {
81289 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[18]-1)*3+j];
81290 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[14]-1)*3+j];
81291 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[15]-1)*3+j];
81292 		}
81293 		inttyp[indx]->type = PHENYL_RING;
81294 		inttyp[indx]->area = PHR;
81295 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81296 
81297 		cal_area(inttyp[indx]);
81298 	   	indx++;
81299 
81300 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81301 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81302 
81303 		for (j=0; j<3; j++) {
81304 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[15]-1)*3+j];
81305 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[18]-1)*3+j];
81306 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[17]-1)*3+j];
81307 		}
81308 		inttyp[indx]->type = PHENYL_RING;
81309 		inttyp[indx]->area = PHR;
81310 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81311 
81312 		cal_area(inttyp[indx]);
81313 	   	indx++;
81314 
81315 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81316 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81317 
81318 		for (j=0; j<3; j++) {
81319 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[17]-1)*3+j];
81320 		   inttyp[indx]->c[1][j] = xyzp->coo[(ipdb[15]-1)*3+j];
81321 		   inttyp[indx]->c[2][j] = xyzp->coo[(ipdb[13]-1)*3+j];
81322 		}
81323 		inttyp[indx]->type = PHENYL_RING;
81324 		inttyp[indx]->area = PHR;
81325 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81326 
81327 		cal_area(inttyp[indx]);
81328 	   	indx++;
81329 
81330 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81331 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81332 
81333 		for (j=0; j<3; j++) {
81334 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[1]-1)*3+j];
81335 		}
81336 		inttyp[indx]->type = CH;
81337 		inttyp[indx]->area = SPH1;
81338 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81339 
81340 		cal_area(inttyp[indx]);
81341 	   	indx++;
81342 
81343 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81344 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81345 
81346 		for (j=0; j<3; j++) {
81347 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[4]-1)*3+j];
81348 		}
81349 		inttyp[indx]->type = CH2;
81350 		inttyp[indx]->area = SPH1;
81351 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81352 
81353 		cal_area(inttyp[indx]);
81354 	   	indx++;
81355 
81356 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81357 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81358 
81359 		for (j=0; j<3; j++) {
81360 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[5]-1)*3+j];
81361 		}
81362 		inttyp[indx]->type = ARO;
81363 		inttyp[indx]->area = SPH1;
81364 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81365 
81366 		cal_area(inttyp[indx]);
81367 	   	indx++;
81368 
81369 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81370 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81371 
81372 		for (j=0; j<3; j++) {
81373 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[9]-1)*3+j];
81374 		}
81375 		inttyp[indx]->type = ARO;
81376 		inttyp[indx]->area = SPH1;
81377 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81378 
81379 		cal_area(inttyp[indx]);
81380 	   	indx++;
81381 
81382 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81383 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81384 
81385 		for (j=0; j<3; j++) {
81386 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[10]-1)*3+j];
81387 		}
81388 		inttyp[indx]->type = ARO;
81389 		inttyp[indx]->area = SPH1;
81390 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81391 
81392 		cal_area(inttyp[indx]);
81393 	   	indx++;
81394 
81395 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81396 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81397 
81398 		for (j=0; j<3; j++) {
81399 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[13]-1)*3+j];
81400 		}
81401 		inttyp[indx]->type = ARO;
81402 		inttyp[indx]->area = SPH1;
81403 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81404 
81405 		cal_area(inttyp[indx]);
81406 	   	indx++;
81407 
81408 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81409 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81410 
81411 		for (j=0; j<3; j++) {
81412 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[14]-1)*3+j];
81413 		}
81414 		inttyp[indx]->type = ARO;
81415 		inttyp[indx]->area = SPH1;
81416 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81417 
81418 		cal_area(inttyp[indx]);
81419 	   	indx++;
81420 
81421 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81422 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81423 
81424 		for (j=0; j<3; j++) {
81425 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[17]-1)*3+j];
81426 		}
81427 		inttyp[indx]->type = ARO;
81428 		inttyp[indx]->area = SPH1;
81429 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81430 
81431 		cal_area(inttyp[indx]);
81432 	   	indx++;
81433 
81434 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81435 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81436 
81437 		for (j=0; j<3; j++) {
81438 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[18]-1)*3+j];
81439 		}
81440 		inttyp[indx]->type = ARO;
81441 		inttyp[indx]->area = SPH1;
81442 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81443 
81444 		cal_area(inttyp[indx]);
81445 	   	indx++;
81446 
81447 		inttyp[indx] =  (INCRSTRU *) malloc((sizeof tmptyp));
81448 	   	memcpy(inttyp[indx], &modtyp, sizeof(INCRSTRU));
81449 
81450 		for (j=0; j<3; j++) {
81451 		   inttyp[indx]->c[0][j] = xyzp->coo[(ipdb[15]-1)*3+j];
81452 		}
81453 		inttyp[indx]->type = ARO;
81454 		inttyp[indx]->area = SPH1;
81455 	        inttyp[indx]->res  = calfptr->irsnr[ires-1];
81456 
81457 		cal_area(inttyp[indx]);
81458 	   	indx++;
81459 
81460 		break;
81461 	   }
81462 	  }
81463 	}
81464     }
81465 
81466     nintp = indx;
81467     DCKPROTPROC = 1;
81468 }
81469 
TrnsTria(Tri,Cen,O,t,R1,R2)81470 void TrnsTria(Tri,Cen,O,t,R1,R2)
81471 TRISTRU *Tri;
81472 float Cen[3];
81473 float O[3];
81474 double t[3];
81475 double R1[4][4];
81476 double R2[4][4];
81477 {
81478     int i,l;
81479     float O1[3],O2[3],O3[3],C[3],Out[3];
81480     double ctmp[3],v1[3],v2[3];
81481     double colv[3];
81482     float tmp1[3],tmp3[3];
81483 
81484 #ifdef DOGL
81485     for (l=0; l < 3; l++) {
81486 
81487 	O1[l] = Tri->p1c[l];
81488 	O2[l] = Tri->p2c[l];
81489 	O3[l] = Tri->p3c[l];
81490 
81491 	C[l]  = ((float) t[l]) + Cen[l];
81492 	Out[l]= O[l];
81493     }
81494 
81495 
81496     for (l=0; l < 3; l++) {
81497 	Out[l]= C[l] + Tri->OutO[l];
81498     }
81499     glLineWidth(20.0);
81500 
81501     colv[0] = ((GLdouble) colorr[10]) / 65535.0 ;
81502     colv[1] = ((GLdouble) colorg[10]) / 65535.0 ;
81503     colv[2] = ((GLdouble) colorb[10]) / 65535.0 ;
81504 
81505     for (l=0; l<3; l++) {
81506 	tmp1[l] = O1[l];
81507     }
81508 
81509     glBegin(GL_LINES);
81510     glColor4d(colv[0],colv[1],colv[2],tr_val);
81511 
81512     glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81513 
81514     for (l=0; l<3; l++) {
81515 	tmp3[l] = O2[l];
81516     }
81517 
81518     glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81519 
81520     colv[0] = ((GLdouble) colorr[11]) / 65535.0 ;
81521     colv[1] = ((GLdouble) colorg[11]) / 65535.0 ;
81522     colv[2] = ((GLdouble) colorb[11]) / 65535.0 ;
81523 
81524     glColor4d(colv[0],colv[1],colv[2],tr_val);
81525 
81526     glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81527 
81528     for (l=0; l<3; l++) {
81529 	tmp3[l] = O3[l];
81530     }
81531 
81532     glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81533 
81534     for (l=0; l<3; l++) {
81535 	tmp1[l] = O2[l];
81536     }
81537 
81538     colv[0] = ((GLdouble) colorr[12]) / 65535.0 ;
81539     colv[1] = ((GLdouble) colorg[12]) / 65535.0 ;
81540     colv[2] = ((GLdouble) colorb[12]) / 65535.0 ;
81541 
81542     glColor4d(colv[0],colv[1],colv[2],tr_val);
81543 
81544     glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81545 
81546     for (l=0; l<3; l++) {
81547 	tmp3[l] = O3[l];
81548     }
81549 
81550     glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81551 
81552     for (l=0; l<3; l++) {
81553 	tmp1[l] = C[l];
81554     }
81555 
81556     colv[0] = ((GLdouble) colorr[15]) / 65535.0 ;
81557     colv[1] = ((GLdouble) colorg[15]) / 65535.0 ;
81558     colv[2] = ((GLdouble) colorb[15]) / 65535.0 ;
81559 
81560     glColor4f(colv[0],colv[1],colv[2],tr_val);
81561 
81562     glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
81563 
81564     for (l=0; l<3; l++) {
81565 	tmp3[l] = Out[l];
81566     }
81567 
81568     glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81569     glEnd();
81570 #endif
81571 
81572 }
81573 
plcoo(Tri)81574 void plcoo(Tri)
81575 TRISTRU *Tri;
81576 {
81577     int i,l,k,j,ia,ja,ic,m,ido;
81578     double colv[3];
81579     float tmp1[3],tmp2[3],tmp3[3];
81580 
81581     if (Tri->coo == NULL) return;
81582 
81583 #ifdef DOGL
81584     for (i=0; i<ndocka; i++) {
81585 
81586         ia = DCKxyz.ianz[i];
81587         ic = DCKxyz.iatclr[i]-1;
81588 	ic = 1;
81589 
81590         for (l=0; l<3; l++)
81591                tmp1[l] = (float) Tri->coo[i*3+l];
81592 
81593         for (k=0; k<DCKxyz.iconn[i*(MXCON+1)]; k++) {
81594 
81595 
81596             m = DCKxyz.iconn[i*(MXCON+1)+k+1];
81597             j = ABS(m) - 1;
81598             ja = DCKxyz.ianz[j];
81599 
81600             for (l=0; l<3; l++)
81601 	       tmp2[l] = (float) Tri->coo[j*3+l];
81602 
81603             ido = 1;
81604 
81605             if (ja == ia) {
81606 
81607                if (j > i) {
81608                   for (l=0; l<3; l++) tmp3[l] = tmp2[l];
81609                } else {
81610                   ido = 0;
81611                }
81612 
81613             } else {
81614 
81615                for (l=0; l<3; l++)
81616                   tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
81617             }
81618 
81619             if (ido) {
81620 
81621 	       colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
81622 	       colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
81623 	       colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
81624 
81625 	       glColor4d(colv[0],colv[1],colv[2],tr_val);
81626 	       glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81627 	       glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81628 
81629 	    }
81630 
81631 
81632 	}
81633     }
81634 #endif
81635 
81636 }
81637 
pltris(Tri)81638 void pltris(Tri)
81639 TRISTRU *Tri;
81640 {
81641     float tmp1[3],tmp3[3],C0[3],C1[3],C2[3],C3[3];
81642     double colv[3];
81643     int i,l;
81644 
81645 #ifdef DOGL
81646     glLineWidth(2.0);
81647 
81648     colv[0] = ((GLdouble) colorr[2]) / 65535.0 ;
81649     colv[1] = ((GLdouble) colorg[2]) / 65535.0 ;
81650     colv[2] = ((GLdouble) colorb[2]) / 65535.0 ;
81651 
81652     for (l=0; l<3; l++) {
81653 	tmp1[l] = Tri->P1[l];
81654     }
81655 
81656     glBegin(GL_LINES);
81657     glColor4d(colv[0],colv[1],colv[2],tr_val);
81658 
81659     glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81660 
81661     for (l=0; l<3; l++) {
81662 	tmp3[l] = Tri->P3[l];
81663     }
81664 
81665     glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81666 
81667 /* end vertex0 p1-p3 */
81668 
81669     colv[0] = ((GLdouble) colorr[3]) / 65535.0 ;
81670     colv[1] = ((GLdouble) colorg[3]) / 65535.0 ;
81671     colv[2] = ((GLdouble) colorb[3]) / 65535.0 ;
81672 
81673     glColor4d(colv[0],colv[1],colv[2],tr_val);
81674 
81675     glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81676 
81677     for (l=0; l<3; l++) {
81678 	tmp3[l] = Tri->P2[l];
81679     }
81680 
81681     glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81682 
81683 /* end vertex1 p1-p2 */
81684 
81685     for (l=0; l<3; l++) {
81686 	tmp1[l] = Tri->P3[l];
81687     }
81688 
81689     colv[0] = ((GLdouble) colorr[4]) / 65535.0 ;
81690     colv[1] = ((GLdouble) colorg[4]) / 65535.0 ;
81691     colv[2] = ((GLdouble) colorb[4]) / 65535.0 ;
81692 
81693     glColor4d(colv[0],colv[1],colv[2],tr_val);
81694 
81695     glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81696 
81697     for (l=0; l<3; l++) {
81698 	tmp3[l] = Tri->P2[l];
81699     }
81700 
81701     glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
81702 
81703 /* end vertex1 p3-p2 */
81704 
81705     for (l=0; l<3; l++) {
81706 	tmp1[l] = Tri->CenO[l];
81707     }
81708 
81709     colv[0] = ((GLdouble) colorr[0]) / 65535.0 ;
81710     colv[1] = ((GLdouble) colorg[0]) / 65535.0 ;
81711     colv[2] = ((GLdouble) colorb[0]) / 65535.0 ;
81712 
81713     glColor4d(colv[0],colv[1],colv[2],tr_val);
81714 
81715     glVertex3f(tmp1[0],tmp1[1],tmp1[2]);
81716 
81717     for (l=0; l<3; l++) {
81718 	tmp3[l] = Tri->CenO[l] + Tri->OutOrg[l];
81719     }
81720 
81721     glVertex3f(tmp3[0],tmp3[1],tmp3[2]);
81722 
81723     if (Tri->coo != NULL) plcoo(Tri);
81724 
81725     glEnd();
81726 
81727     TrnsTria(Tri,Tri->Cen,Tri->Out,Tri->t,Tri->R1,Tri->R2);
81728 
81729 #endif
81730 }
81731 
ogTris()81732 void ogTris()
81733 {
81734     int j,k,l,ic;
81735     float C0[3],C1[3],C2[3],C3[3];
81736     double colv[3];
81737     double roddef;
81738 
81739 #ifdef DOGL
81740     glBegin(GL_LINES);
81741 
81742     for (k=0; k < ntris; k++) {
81743 	if (TriArr[k] != NULL) {
81744 	   pltris(TriArr[k]);
81745 	}
81746     }
81747 
81748     glEnd();
81749 
81750     for (j=0; j<3; j++) {
81751 	   C1[j] = ORI[j] + B1[j];
81752 	   C2[j] = ORI[j] + B2[j];
81753 	   C3[j] = ORI[j] + B3[j];
81754     }
81755 
81756     ic = -1;
81757 
81758     roddef = (0.13/0.52917706);
81759     ogsphere(1,ORI,0.5*roddef,0);
81760 
81761     ic = 2;
81762 
81763     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
81764     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
81765     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
81766     glColor4d(colv[0],colv[1],colv[2],tr_val);
81767 
81768     ogarrow(1,ORI,C1,roddef);
81769 
81770     ic = 3;
81771 
81772     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
81773     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
81774     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
81775 
81776     glColor4d(colv[0],colv[1],colv[2],tr_val);
81777 
81778     ogarrow(2,ORI,C2,roddef);
81779 
81780     ic = 5;
81781 
81782     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
81783     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
81784     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
81785 
81786     glColor4d(colv[0],colv[1],colv[2],tr_val);
81787     ogarrow(3,ORI,C3,roddef);
81788 #endif
81789 
81790 }
81791 
ogORI(int k,int opt)81792 void ogORI(int k,int opt)
81793 {
81794     int i,ic;
81795     double roddef;
81796     float ori[3];
81797 
81798 #ifdef DOGL
81799     ic = -1;
81800 
81801     roddef = (0.13/0.52917706);
81802 
81803     for (i=0; i<3; i++) {
81804 	if (opt) {
81805 	   ori[i] = (float) ligtyp[k]->ORI[i];
81806 	} else {
81807 	   ori[i] = (float) inttyp[k]->ORI[i];
81808 	}
81809     }
81810     ogsphere(1,ori,0.5*roddef,0);
81811 #endif
81812 }
81813 
IntSurfGetlig()81814 void IntSurfGetlig()
81815 {
81816     ProcProt();
81817     GetLig();
81818 }
81819 
ogIntSurf()81820 void ogIntSurf()
81821 {
81822     int i,j,k,l,ic,clss;
81823     float tmp1[3],tmp3[3],C1[3],C2[3],C3[3];
81824     double colv[3];
81825     double roddef;
81826 
81827     if (!DCKPROTPROC) ProcProt();
81828 
81829 #ifdef DOGL
81830 
81831     if (DCKINVOKE) {
81832 	if (!GetLig()) {
81833 	   IntSurfDone = 1;
81834 	   return;
81835 	}
81836     }
81837 
81838     if (theIntSurf[istruct] > 0) glDeleteLists(theIntSurf[istruct],1);
81839     theIntSurf[istruct] = -1;
81840     theIntSurf[istruct] = glGenLists(1);
81841 
81842     glNewList(theIntSurf[istruct], GL_COMPILE);
81843     glDisable(GL_LIGHTING);
81844     glLineWidth(2.0);
81845     glEnable(GL_LINE_SMOOTH);
81846     glEnable(GL_COLOR_MATERIAL);
81847     glBegin(GL_LINES);
81848 
81849     for (k=0; k<nintp; k++) {
81850 
81851 	ic = 1;
81852 	clss = 0;
81853 
81854 	switch (inttyp[k]->type) {
81855 	case H_ACC:
81856 		ic = 0;
81857 		clss = 1;
81858 		break;
81859 	case H_DON:
81860 		ic = 12;
81861 		clss = -1;
81862 		break;
81863 	case CH:
81864 	case CH2:
81865 	case CH3:
81866 	case PHE_CH3:
81867 	case ARO:
81868 	case AMIDE:
81869 	case SULFUR:
81870 	case PHENYL_RING:
81871 		ic = 2;
81872 		clss = -2;
81873 		break;
81874 	case PHENYL_CENTER:
81875 		ic = 3;
81876 		clss = 2;
81877 		break;
81878 	case METAL:
81879 		ic = 4;
81880 		clss = 3;
81881 		break;
81882 	case METAL_ACC:
81883 		ic = 5;
81884 		clss = -3;
81885 		break;
81886 	}
81887 
81888 if (k == ATMselp) {
81889 //fprintf(stderr,"inttyp[%d]->res %d\n",k,inttyp[k]->res);
81890 	for (i=0; i<inttyp[k]->npts; i++) {
81891 
81892 	    colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
81893 	    colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
81894 	    colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
81895 
81896             for (l=0; l<3; l++) {
81897                tmp1[l] = (float) inttyp[k]->points[i*3+l];
81898 	    }
81899 
81900             glBegin(GL_LINES);
81901 	    glColor4d(colv[0],colv[1],colv[2],tr_val);
81902 	    for (j=0; j<6; j++) {
81903 		glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
81904            	for (l=0; l<3; l++) {
81905 		   tmp3[l] = (float)(tmp1[l] + CV[j][l]);
81906 		}
81907 		glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
81908 	    }
81909             glEnd();
81910 
81911 	}
81912 }
81913     }
81914 
81915     glEnd();
81916 
81917     for (k=0; k<nintp; k++) {
81918 	if (k == ATMselp) {
81919 	   ogORI(k,0);
81920 	}
81921     }
81922 
81923 
81924     ogTris();
81925 
81926     glEnable(GL_LIGHTING);
81927     glDisable(GL_COLOR_MATERIAL);
81928     glEndList();
81929 #endif
81930 
81931     if (!DCKBYPASS) ogLigSurf();
81932 
81933     IntSurfDone = 1;
81934 
81935 }
81936 
plpnts(int ic,int k)81937 void plpnts(int ic,int k)
81938 {
81939     float tmp1[3],tmp3[3];
81940     double colv[3];
81941     int i,j,l;
81942 
81943 #ifdef DOGL
81944     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
81945     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
81946     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
81947 
81948     for (i=0; i<ligtyp[k]->npts; i++) {
81949 	for (l=0; l<3; l++) {
81950 		tmp1[l] = (float) ligtyp[k]->points[i*3+l];
81951 	}
81952 	glBegin(GL_LINES);
81953 	glColor4d(colv[0],colv[1],colv[2],tr_val);
81954 	for (j=0; j<6; j++) {
81955 	   glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
81956       	   for (l=0; l<3; l++) {
81957 		tmp3[l] = (float)(tmp1[l] + CV[j][l]);
81958 	   }
81959 	   glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
81960 	}
81961 	glEnd();
81962     }
81963 #endif
81964 }
81965 
plpropnts(int ic,int k)81966 void plpropnts(int ic,int k)
81967 {
81968     float tmp1[3],tmp3[3];
81969     double colv[3];
81970     int i,j,l;
81971 
81972 #ifdef DOGL
81973     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
81974     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
81975     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
81976 
81977     if (inttyp[k] == NULL) return;
81978 
81979     for (i=0; i<inttyp[k]->npts; i++) {
81980 	for (l=0; l<3; l++) {
81981 		tmp1[l] = (float) inttyp[k]->points[i*3+l];
81982 	}
81983 	glBegin(GL_LINES);
81984 	glColor4d(colv[0],colv[1],colv[2],tr_val);
81985 	for (j=0; j<6; j++) {
81986 	   glVertex3d(tmp1[0],tmp1[1],tmp1[2]);
81987       	   for (l=0; l<3; l++) {
81988 		tmp3[l] = (float)(tmp1[l] + CV[j][l]);
81989 	   }
81990 	   glVertex3d(tmp3[0],tmp3[1],tmp3[2]);
81991 	}
81992 	glEnd();
81993     }
81994 #endif
81995 }
81996 
ogLigSurf()81997 void ogLigSurf()
81998 {
81999     int i,j,k,l,ic,clss;
82000     float tmp1[3],tmp3[3],C0[3],C1[3],C2[3],C3[3];
82001     double colv[3];
82002     double roddef;
82003 
82004     if (!DCKLIGPROC) {
82005 
82006 	if (!(*ipdbon)) {
82007 	   for (i=0; i < *xyzp->iatoms; i++) {
82008 		singleb.ityp[i] = xyzp->ityp[i];
82009 	   }
82010 	}
82011 
82012 	if (*fftyp != 5) typit(5,1);
82013 	if (!(*ipdbon)) ProcLig(0);
82014     }
82015 
82016 #ifdef DOGL
82017 
82018     if (theLigSurf[istruct] > 0) glDeleteLists(theLigSurf[istruct],1);
82019     theLigSurf[istruct] = -1;
82020     theLigSurf[istruct] = glGenLists(1);
82021 
82022     glNewList(theLigSurf[istruct], GL_COMPILE);
82023     glDisable(GL_LIGHTING);
82024     glLineWidth(2.0);
82025     glEnable(GL_LINE_SMOOTH);
82026     glEnable(GL_COLOR_MATERIAL);
82027     glBegin(GL_LINES);
82028 
82029     for (k=0; k<lintp; k++) {
82030 
82031 	ic = 1;
82032 	clss = 0;
82033 
82034 	switch (ligtyp[k]->type) {
82035 	case H_ACC:
82036 		ic = 0;
82037 		clss = 1;
82038 		break;
82039 	case H_DON:
82040 		ic = 12;
82041 		clss = -1;
82042 		break;
82043 	case CH:
82044 	case CH2:
82045 	case CH3:
82046 	case PHE_CH3:
82047 	case ARO:
82048 	case AMIDE:
82049 	case SULFUR:
82050 	case PHENYL_RING:
82051 		ic = 2;
82052 		clss = -2;
82053 		break;
82054 	case PHENYL_CENTER:
82055 		ic = 3;
82056 		clss = 2;
82057 		break;
82058 	case METAL:
82059 		ic = 4;
82060 		clss = 3;
82061 		break;
82062 	case METAL_ACC:
82063 		ic = 5;
82064 		clss = -3;
82065 		break;
82066 	}
82067 
82068 //	if (clss == 1 || clss == -1) {
82069 //	if (k == 8 || k == 22 || k == 12 || k == ATMsel) {
82070 	if (k == ATMselp) {
82071 	   plpnts(ic,k);
82072 	}
82073 
82074     }
82075 
82076 //    plpropnts(0,227);
82077 
82078     for (k=0; k<lintp; k++) {
82079 	if (k == ATMselp) {
82080 	   ogORI(k,1);
82081 	}
82082     }
82083 
82084     ogTris();
82085 
82086 
82087     glEnable(GL_LIGHTING);
82088     glDisable(GL_COLOR_MATERIAL);
82089     glEndList();
82090 #endif
82091 
82092     IntSurfDone = 1;
82093 
82094 
82095 }
82096 
ogAxs()82097 void ogAxs()
82098 {
82099     int i,j,k,l,ic,doit;
82100     float tmp1[3],tmp3[3],C0[3],C1[3],C2[3],C3[3];
82101     double colv[3];
82102     double roddef;
82103 
82104 #ifdef DOGL
82105     if (theIntSurf[istruct] > 0) glDeleteLists(theIntSurf[istruct],1);
82106     theIntSurf[istruct] = -1;
82107     theIntSurf[istruct] = glGenLists(1);
82108 
82109     glNewList(theIntSurf[istruct], GL_COMPILE);
82110     glDisable(GL_LIGHTING);
82111     glLineWidth(2.0);
82112     glEnable(GL_LINE_SMOOTH);
82113     glEnable(GL_COLOR_MATERIAL);
82114 
82115     for (j=0; j<3; j++) {
82116 	   C1[j] = ORI[j] + B1[j];
82117 	   C2[j] = ORI[j] + B2[j];
82118 	   C3[j] = ORI[j] + B3[j];
82119     }
82120 
82121     ic = -1;
82122 
82123     roddef = (0.13/0.52917706);
82124     ogsphere(1,ORI,0.5*roddef,0);
82125 
82126     ic = 2;
82127 
82128     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
82129     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
82130     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
82131     glColor4d(colv[0],colv[1],colv[2],tr_val);
82132 
82133     ogarrow(1,ORI,C1,roddef);
82134 
82135 /* orange */
82136 
82137     ic = 1;
82138 
82139     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
82140     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
82141     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
82142 
82143     glColor4d(colv[0],colv[1],colv[2],tr_val);
82144 
82145     ogarrow(2,ORI,C2,roddef);
82146 
82147     ic = 5;
82148 
82149     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
82150     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
82151     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
82152 
82153     glColor4d(colv[0],colv[1],colv[2],tr_val);
82154     ogarrow(3,ORI,C3,roddef);
82155 
82156     glEnable(GL_LIGHTING);
82157     glDisable(GL_COLOR_MATERIAL);
82158     glEndList();
82159 #endif
82160     IntSurfDone = 1;
82161 
82162 }
82163 
ogAxs2()82164 void ogAxs2()
82165 {
82166     int i,j,k,l,ic,doit;
82167     float tmp1[3],tmp3[3],C0[3],C1[3],C2[3],C3[3];
82168     double colv[3];
82169     double roddef;
82170 
82171 #ifdef DOGL
82172     if (theIntSurf2[istruct] > 0) glDeleteLists(theIntSurf2[istruct],1);
82173     theIntSurf2[istruct] = -1;
82174     theIntSurf2[istruct] = glGenLists(1);
82175 
82176     glNewList(theIntSurf2[istruct], GL_COMPILE);
82177     glDisable(GL_LIGHTING);
82178     glLineWidth(2.0);
82179     glEnable(GL_LINE_SMOOTH);
82180     glEnable(GL_COLOR_MATERIAL);
82181 
82182     for (j=0; j<3; j++) {
82183 	   C1[j] = ORI2[j] + Bt1[j];
82184 	   C2[j] = ORI2[j] + Bt2[j];
82185 	   C3[j] = ORI2[j] + Bt3[j];
82186     }
82187 
82188     ic = -1;
82189 
82190     roddef = (0.13/0.52917706);
82191     ogsphere(1,ORI2,0.5*roddef,0);
82192 
82193     ic = 6;
82194 
82195     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
82196     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
82197     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
82198     glColor4d(colv[0],colv[1],colv[2],tr_val);
82199 
82200     ogarrow(1,ORI2,C1,roddef);
82201 
82202 /* grey */
82203 
82204     ic = 7;
82205 
82206     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
82207     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
82208     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
82209 
82210     glColor4d(colv[0],colv[1],colv[2],tr_val);
82211 
82212     ogarrow(2,ORI2,C2,roddef);
82213 
82214 /* purple */
82215 
82216     ic = 8;
82217 
82218     colv[0] = ((GLdouble) colorr[ic+1]) / 65535.0 ;
82219     colv[1] = ((GLdouble) colorg[ic+1]) / 65535.0 ;
82220     colv[2] = ((GLdouble) colorb[ic+1]) / 65535.0 ;
82221 
82222     glColor4d(colv[0],colv[1],colv[2],tr_val);
82223     ogarrow(3,ORI2,C3,roddef);
82224 
82225     glEnable(GL_LIGHTING);
82226     glDisable(GL_COLOR_MATERIAL);
82227     glEndList();
82228 #endif
82229     IntSurfDone = 1;
82230 
82231 }
82232