1 /* UtilsOrb.c */
2 /**********************************************************************************************************
3 Copyright (c) 2002-2013 Abdul-Rahman Allouche. All rights reserved
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 documentation files (the Gabedit), to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
8 and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9 
10   The above copyright notice and this permission notice shall be included in all copies or substantial portions
11   of the Software.
12 
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
14 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
16 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17 DEALINGS IN THE SOFTWARE.
18 ************************************************************************************************************/
19 
20 
21 #include "../../Config.h"
22 #include "../Display/GlobalOrb.h"
23 #include "../Utils/Vector3d.h"
24 #include "../Display/GLArea.h"
25 #include "../Display/Orbitals.h"
26 #include "../Display/OrbitalsMolpro.h"
27 #include "../Display/OrbitalsGamess.h"
28 #include "../Display/OrbitalsQChem.h"
29 #include "../Display/GeomOrbXYZ.h"
30 #include "../Display/BondsOrb.h"
31 #include "../Display/UtilsOrb.h"
32 #include "../Display/TriangleDraw.h"
33 #include "../Utils/Utils.h"
34 #include "../Utils/UtilsInterface.h"
35 #include "../Utils/Constants.h"
36 #include "../Common/Windows.h"
37 #include "../Display/Vibration.h"
38 #include "../Display/ContoursPov.h"
39 #include "../Display/PlanesMappedPov.h"
40 #include "../Display/GridCube.h"
41 #include "../Display/GridCP.h"
42 #include "../Display/ColorMap.h"
43 #include "../Display/LabelsGL.h"
44 
45 /**********************************************/
getOptimalN(gint nG)46 static gint getOptimalN(gint nG)
47 {
48 	/* 2^n = 16, 32, 64, 128, 256, 512, 1024 */
49 	/* 3*2^n = 24, 48, 96, 192, 384, 768 */
50 	static gint def[] = {17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769,1025};
51 	static gint nd = sizeof(def)/sizeof(gint);
52 	gint i;
53 	if(nG<17) nG = 17;
54 	for(i=0;i<nd-1;i++)
55 	{
56 		if(nG>def[i] && nG<def[i+1])
57 		{
58 			nG = def[i];
59 			break;
60 		}
61 	}
62 	if(nG%2==0) nG++;
63 	if(nG>65) nG = 65;
64 	return nG;
65 }
66 /**********************************************/
InitializeAll()67 void InitializeAll()
68 {
69  	CoefAlphaOrbitals = NULL;
70  	EnerAlphaOrbitals = NULL;
71 	TypeSelOrb = 1;
72 	NumSelOrb = -1;
73 	free_objects_all();
74 }
75 /**********************************************/
CreateTable2(gint N)76 gdouble** CreateTable2(gint N)
77 {
78 	gdouble** T;
79 	gint i;
80 	gint j;
81 
82 	T = g_malloc(N*sizeof(gdouble*)) ;
83 	for(i=0;i<N;i++)
84 	{
85 		T[i] = g_malloc(N*sizeof(gdouble));
86 		for(j=0;j<N;j++) T[i][j] = 0.0;
87 	}
88 
89 	return T;
90 }
91 /**********************************************/
FreeTable2(gdouble ** T,gint N)92 gdouble** FreeTable2(gdouble **T,gint N)
93 {
94 	gint i;
95 	for(i=0;i<N;i++) g_free(T[i]);
96 	g_free(T);
97 	return NULL;
98 }
99 /**********************************************/
GetTotalNelectrons()100 gint GetTotalNelectrons()
101 {
102   gint i;
103   gint N=0;
104  for(i=0;i<nCenters;i++)
105  {
106          if(Type[GeomOrb[i].NumType].N>0)
107               N +=Type[GeomOrb[i].NumType].N;
108  }
109  return N;
110 }
111 /**********************************************/
GetSumAbsCharges()112 gdouble GetSumAbsCharges()
113 {
114 	gdouble s = 0;
115 	gint i;
116 	for(i=0;i<nCenters;i++)
117 		s += fabs(GeomOrb[i].partialCharge);
118 	return s;
119 }
120 /**********************************************/
DefineNOccs()121 void DefineNOccs()
122 {
123   NTotOcc = GetTotalNelectrons();
124   NAlphaOcc =NTotOcc/2+1;
125   NBetaOcc =NTotOcc/2;
126   NTotOcc /=2;
127   TypeSelOrb = 1;
128   NumSelOrb = NAlphaOcc-1;
129 }
130 /**********************************************/
GetSymmetry(gint l)131 char GetSymmetry(gint l)
132 {
133         switch(l)
134         {
135         case 0 : return 'S';
136         case 1 : return 'P';
137         case 2 : return 'D';
138         case 3 : return 'F';
139         case 4 : return 'G';
140         case 5 : return 'H';
141         case 6 : return 'I';
142         }
143        return 'x';
144 }
145 /**********************************************/
GetNelectrons(char * symb)146 gint GetNelectrons(char *symb)
147 {
148   gint i;
149   gint  Z[NATOMS]={
150 	1,2,
151 	3,4,5,6,7,8,9,10,
152 	11,12,13,14,15,16,17,18,
153 	19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
154         37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,
155         55,56,57,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,
156         87,88,89,
157         58,59,60,61,62,63,64,65,66,67,68,69,70,71,
158         90,91,92,93,94,95,96,97,98,99,100,101,102,103,
159         0
160 	};
161   char *Symb[NATOMS]={
162 	"H","He",
163 	"Li","Be","B","C","N","O","F","Ne",
164 	"Na","Mg","Al","Si","P","S","Cl","Ar",
165 	"K","Ca","Sc","Ti","V","Cr","Mn","Fe",
166 	"Co","Ni","Cu","Zn","Ga","Ge","As","Se",
167 	"Br","Kr","Rb","Sr","Y","Zr","Nb","Mo",
168 	"Tc","Ru","Rh","Pd","Ag","Cd","In",
169 	"Sn","Sb","Te","I","Xe","Cs","Ba","La",
170 	"Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl",
171 	"Pb","Bi","Po","At","Rn","Fr","Ra","Ac",
172 	"Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb",
173 	"Dy","Ho","Er","Tm","Yb","Lu",
174 	"Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf",
175 	"Es","Fm","Md","No","Lr",
176         "X"
177 	};
178 
179    for(i=0;i<NATOMS;i++)
180     if( !strcmp(symb,Symb[i]) )
181       return Z[i];
182 
183    return -1;
184 }
185 /**********************************************/
printLineChar(char c,gint n)186 void printLineChar(char c,gint n)
187 {
188   gint i;
189   for(i=0;i<n;i++)
190   	printf("%c",c);
191   printf("\n");
192 }
193 /**********************************************/
get_type_file_orb(gchar * fileName)194 gint get_type_file_orb(gchar *fileName)
195 {
196  	gchar *t;
197  	FILE *fd;
198  	guint taille=BSIZE;
199 	gint ktype = GABEDIT_TYPEFILE_UNKNOWN;
200 
201  	t=g_malloc(taille);
202  	fd = FOpen(fileName, "rb");
203 
204  	if(fd ==NULL)
205  	{
206 		gchar buffer[BSIZE];
207 		sprintf(buffer,_("Sorry, I can not open '%s' file\n"),fileName);
208   		Message(buffer,_("Error"),TRUE);
209  		g_free(t);
210   		return ktype;
211  	}
212 	if(0<get_one_int_from_fchk_gaussian_file(fd,"Number of atoms "))
213 	{
214 		ktype = GABEDIT_TYPEFILE_GAUSSIAN_FCHK;
215  		g_free(t);
216 		fclose(fd);
217 		printf("GABEDIT_TYPEFILE_GAUSSIAN_FCHK\n");
218 		return ktype;
219 	}
220 	rewind(fd);
221     	{ char* e = fgets(t,taille,fd);}
222 	uppercase(t);
223         if(strstr(t, "ENTERING" ))
224 		ktype = GABEDIT_TYPEFILE_GAUSSIAN;
225 	else
226         if(strstr( t, "[MOLDEN FORMAT]" ))
227 			ktype = GABEDIT_TYPEFILE_MOLDEN;
228 	else
229 	if(mystrcasestr( t, "<Title>"))
230                         ktype = GABEDIT_TYPEFILE_WFX;
231 	else
232 	if(strstr( t, "[GABEDIT FORMAT]" ))
233 		ktype = GABEDIT_TYPEFILE_GABEDIT;
234 	else
235 	if(strstr( t, "GAMESS" ))
236 		ktype = GABEDIT_TYPEFILE_GAMESS;
237 	else
238 	if(atoi(t)>0 && !strstr(t,"**********"))
239 		ktype = GABEDIT_TYPEFILE_XYZ;
240 	if( ktype == GABEDIT_TYPEFILE_UNKNOWN)
241 	{
242 		while(!feof(fd))
243 		{
244     			{ char* e = fgets(t,taille,fd);}
245 			if(strstr(t,"PROGRAM SYSTEM MOLPRO"))
246 			{
247 				ktype = GABEDIT_TYPEFILE_MOLPRO;
248 				break;
249 			}
250 			if(mystrcasestr( t, "<Title>"))
251 			{
252                         	ktype = GABEDIT_TYPEFILE_WFX;
253 				break;
254 			}
255 			if(strstr(t,"GAMESS VERSION") || strstr(t,"PC GAMESS"))
256 			{
257 				ktype = GABEDIT_TYPEFILE_GAMESS;
258 				break;
259 			}
260 			if(strstr(t,"Welcome to Q-Chem"))
261 			{
262 				ktype = GABEDIT_TYPEFILE_QCHEM;
263 				break;
264 			}
265 			if(strstr(t,"Northwest Computational Chemistry Package"))
266 			{
267 				ktype = GABEDIT_TYPEFILE_NWCHEM;
268 				break;
269 			}
270 			uppercase(t);
271         		if(strstr(t, "ENTERING GAUSSIAN" ))
272 			{
273 				ktype = GABEDIT_TYPEFILE_GAUSSIAN;
274 				break;
275 			}
276 			if(strstr( t, "[MOLDEN FORMAT]" ))
277 			{
278 				ktype = GABEDIT_TYPEFILE_MOLDEN;
279 				break;
280 			}
281 		}
282 	}
283 	rewind(fd);
284 	if( ktype == GABEDIT_TYPEFILE_UNKNOWN)
285 	{
286 		while(!feof(fd))
287 		{
288     			{ char* e = fgets(t,taille,fd);}
289 			if(strstr(t,"* O   R   C   A *"))
290 			{
291 				ktype = GABEDIT_TYPEFILE_ORCA;
292 				break;
293 			}
294 		}
295 	}
296 	rewind(fd);
297 	if( ktype == GABEDIT_TYPEFILE_UNKNOWN)
298 	{
299 		while(!feof(fd))
300 		{
301     			{ char* e = fgets(t,taille,fd);}
302 			if(strstr(t,"GAMESS"))
303 			{
304     				{ char* e = fgets(t,taille,fd);}
305 				if(strstr(t,"FROM IOWA STATE UNIVERSITY"))
306 				ktype = GABEDIT_TYPEFILE_GAMESS;
307 				break;
308 			}
309 		}
310 	}
311 	rewind(fd);
312 	if( ktype == GABEDIT_TYPEFILE_UNKNOWN)
313 	{
314     		{ char* e = fgets(t,taille,fd);}
315 		if(strstr(t,"START OF MOPAC FILE"))
316 			ktype = GABEDIT_TYPEFILE_MOPAC_AUX;
317 	}
318 	rewind(fd);
319 	if( ktype == GABEDIT_TYPEFILE_UNKNOWN)
320 	{
321     		{ char* e = fgets(t,taille,fd);}
322 		if(strstr(t,"BEGIN IRC"))
323 			ktype = GABEDIT_TYPEFILE_GAMESSIRC;
324 	}
325 	rewind(fd);
326 	if( ktype == GABEDIT_TYPEFILE_UNKNOWN)
327 	{
328 		while(!feof(fd))
329 		{
330     			{ char* e = fgets(t,taille,fd);}
331 			if(strstr(t,"in the AO basis:"))
332 			{
333     				{ char* e = fgets(t,taille,fd);}
334 				if(strstr(t,"------------------"))
335 				ktype = GABEDIT_TYPEFILE_NBO;
336 				break;
337 			}
338 		}
339 	}
340  	fclose(fd);
341  	g_free(t);
342  	if(ktype==GABEDIT_TYPEFILE_UNKNOWN)
343  	{
344 		gchar buffer[BSIZE];
345 		sprintf(buffer,_("Sorry,  I can not determine the type of '%s' file\n"),fileName);
346   		Message(buffer,_("Error"),TRUE);
347  	}
348 	return ktype;
349 
350 }
351 /**********************************************************/
352 /* return
353    -1 : undefined
354     0 : cartezian
355     1 : Spherical
356 */
get_type_basis_in_gamess_file(gchar * fileName)357 gint get_type_basis_in_gamess_file(gchar *fileName)
358 {
359  	gchar *t;
360  	FILE *fd;
361  	guint taille=BSIZE;
362 	gint ktype = -1;
363 
364  	t=g_malloc(taille);
365  	fd = FOpen(fileName, "rb");
366 
367  	if(fd ==NULL)
368  	{
369 		gchar buffer[BSIZE];
370 		sprintf(buffer,_("Sorry, I can not open '%s' file\n"),fileName);
371   		Message(buffer,_("Error"),TRUE);
372 
373  		g_free(t);
374   		return ktype;
375  	}
376 	ktype = 0;
377 	while(!feof(fd))
378 	{
379     		{ char* e = fgets(t,taille,fd);}
380         	if(strstr( t, "ISPHER="))
381 		{
382 			gchar t1[50];
383 			gchar t2[50];
384 			sscanf(t,"%s %s",t1,t2);
385 			if(strstr(t2,"-")) ktype = 1;
386 			else if(atoi(t2)==0) ktype = -1;
387 			break;
388 		}
389 	}
390  	fclose(fd);
391  	g_free(t);
392 	return ktype;
393 
394 }
395 /**********************************************************/
396 /* return
397    -1 : undefined
398     0 : cartezian
399     1 : Spherical
400 */
get_type_basis_in_gaussian_file(gchar * fileName)401 gint get_type_basis_in_gaussian_file(gchar *fileName)
402 {
403  	gchar *t;
404  	FILE *fd;
405  	guint taille=BSIZE;
406 	gint ktype = -1;
407 
408  	t=g_malloc(taille);
409  	fd = FOpen(fileName, "rb");
410 
411  	if(fd ==NULL)
412  	{
413 		gchar buffer[BSIZE];
414 		sprintf(buffer,_("Sorry, I can not open '%s' file\n"),fileName);
415   		Message(buffer,_("Error"),TRUE);
416 
417  		g_free(t);
418   		return ktype;
419  	}
420 	ktype = 0;
421 	while(!feof(fd))
422 	{
423     		{ char* e = fgets(t,taille,fd);}
424         	if(strstr( t, "(5D, 7F)"))
425 		{
426 			ktype = 1;
427 			break;
428 		}
429         	if(strstr( t, "(6D, 7F)"))
430 		{
431 			ktype = 0;
432 			break;
433 		}
434         	if(strstr( t, "(6D, 10F)"))
435 		{
436 			ktype = 0;
437 			break;
438 		}
439 	}
440 
441  	fclose(fd);
442  	g_free(t);
443 	return ktype;
444 
445 }
446 /**********************************************************/
447 /* return
448    -1 : undefined
449     0 : cartezian
450     1 : Spherical
451 */
get_type_basis_in_nwchem_file(gchar * fileName)452 gint get_type_basis_in_nwchem_file(gchar *fileName)
453 {
454  	gchar *t;
455  	FILE *fd;
456  	guint taille=BSIZE;
457 	gint ktype = -1;
458 
459  	t=g_malloc(taille);
460  	fd = FOpen(fileName, "rb");
461 
462  	if(fd ==NULL)
463  	{
464 		gchar buffer[BSIZE];
465 		sprintf(buffer,_("Sorry, I can not open '%s' file\n"),fileName);
466   		Message(buffer,_("Error"),TRUE);
467 
468  		g_free(t);
469   		return ktype;
470  	}
471 	ktype = 0;
472 	while(!feof(fd))
473 	{
474     		{ char* e = fgets(t,taille,fd);}
475         	if(strstr( t, "ao basis") && strstr( t, "spherical")) {ktype=1;break;}
476         	if(strstr( t, "ao basis") && strstr( t, "cart")) {ktype=0;break;}
477 	}
478  	fclose(fd);
479  	g_free(t);
480 	return ktype;
481 
482 }
483 /**********************************************************/
484 /* return
485    -1 : undefined
486     0 : cartezian
487     1 : Spherical
488 */
get_type_basis_in_qchem_file(gchar * fileName)489 gint get_type_basis_in_qchem_file(gchar *fileName)
490 {
491  	gchar *t;
492  	FILE *fd;
493  	guint taille=BSIZE;
494 	gint ktype = -1;
495 	gint ks = 0;
496 	gint kc = 0;
497 
498  	t=g_malloc(taille);
499  	fd = FOpen(fileName, "rb");
500 
501  	if(fd ==NULL)
502  	{
503 		gchar buffer[BSIZE];
504 		sprintf(buffer,_("Sorry, I can not open '%s' file\n"),fileName);
505   		Message(buffer,_("Error"),TRUE);
506 
507  		g_free(t);
508   		return ktype;
509  	}
510 	ktype = 0;
511 	while(!feof(fd))
512 	{
513     		{ char* e = fgets(t,taille,fd);}
514         	if(strstr( t, "  d 1 ")) ks++;
515         	if(strstr( t, "  f 1 ")) ks++;
516         	if(strstr( t, "  g 1 ")) ks++;
517         	if(strstr( t, "  h 1 ")) ks++;
518         	if(strstr( t, "  i 1 ")) ks++;
519         	if(strstr( t, "  j 1 ")) ks++;
520         	if(strstr( t, " dxx ")) kc++;
521         	if(strstr( t, " fxyz ")) kc++;
522         	if(strstr( t, " gxxxx ")) kc++;
523         	if(strstr( t, " hxxxxx ")) kc++;
524         	if(strstr( t, " ixxxxx ")) kc++;
525         	if(strstr( t, " jxxxxx ")) kc++;
526 	}
527 	/* printf("ks = %d kc = %d\n",ks,kc);*/
528 	if(ks>0 && kc ==0) ktype = 1;
529 	else if(ks==0 && kc >0) ktype = 0;
530 	else if(ks==0 && kc==0) ktype = 0;
531 	else ktype= -1;
532 
533  	fclose(fd);
534  	g_free(t);
535 	return ktype;
536 
537 }
538 /**********************************************************/
539 /* return
540    -1 : undefined
541     0 : cartezian
542     1 : Spherical
543 */
get_type_basis_in_gabedit_file(gchar * fileName)544 gint get_type_basis_in_gabedit_file(gchar *fileName)
545 {
546  	gchar *t;
547  	FILE *fd;
548  	guint taille=BSIZE;
549 	gint ktype = -1;
550 
551  	t=g_malloc(taille);
552  	fd = FOpen(fileName, "rb");
553 
554  	if(fd ==NULL)
555  	{
556 		gchar buffer[BSIZE];
557 		sprintf(buffer,_("Sorry, I can not open '%s' file\n"),fileName);
558   		Message(buffer,_("Error"),TRUE);
559  		g_free(t);
560   		return ktype;
561  	}
562 	ktype = -1;
563     	{ char* e = fgets(t,taille,fd);}
564 	uppercase(t);
565 	if(strstr( t, "[GABEDIT FORMAT]"))
566 	{
567 		if(strstr( t, "SPHE"))
568 			ktype = 1;
569 		else
570 			ktype = 0;
571 	}
572 
573  	fclose(fd);
574  	g_free(t);
575 	return ktype;
576 
577 }
578 /**********************************************************/
579 /* return
580    -1 : undefined
581     0 : cartezian
582     1 : Spherical
583 */
get_type_basis_in_molden_file(gchar * fileName)584 gint get_type_basis_in_molden_file(gchar *fileName)
585 {
586  	gchar *t;
587  	FILE *fd;
588  	guint taille=BSIZE;
589 	gint ktype = -1;
590 
591  	t=g_malloc(taille);
592  	fd = FOpen(fileName, "rb");
593 
594  	if(fd ==NULL)
595  	{
596 		gchar buffer[BSIZE];
597 		sprintf(buffer,_("Sorry, I can not open '%s' file\n"),fileName);
598   		Message(buffer,_("Error"),TRUE);
599  		g_free(t);
600   		return ktype;
601  	}
602 	ktype = -1;
603     	{ char* e = fgets(t,taille,fd);}
604 	uppercase(t);
605 	//if(strstr( t, "[MOLDEN FORMAT]"))
606 	{
607 		ktype = 0;
608 		while(!feof(fd))
609 		{
610     			{ char* e = fgets(t,taille,fd);}
611 			uppercase(t);
612 			if(strstr( t, "[5D"))
613 			{
614 				ktype = 1;
615 				break;
616 			}
617 		}
618 	}
619 
620  	fclose(fd);
621  	g_free(t);
622 	return ktype;
623 }
624 /**********************************************************/
PrintAllOrb(gdouble ** M)625 void PrintAllOrb(gdouble** M)
626 {
627  gint i,j;
628 
629 
630  gint Nblock;
631  gint Nrest;
632  gint Nb;
633  gint Nbmax=5;
634  gint Nbj,Nej;
635  gint l;
636  char *XYZ[]={"x","y","z"};
637 
638  Nblock = NAOrb/Nbmax;
639  Nrest = NAOrb%Nbmax;
640  if(Nrest !=0) Nblock++;
641 
642 
643  for(Nb=0;Nb<Nblock;Nb++)
644  {
645  printf("\n");
646  printf("\t");
647  Nbj=Nbmax*Nb;
648  Nej=Nbmax*Nb+Nbmax;
649  if(Nb==Nblock-1 && Nrest !=0)
650  	Nej=Nbmax*Nb+Nrest;
651  for( j=Nbj;j<Nej;j++)
652  {
653      if(j<NTotOcc)
654 	printf("%9s ","Occuped");
655      else
656 	printf("%9s ","Virtual");
657  }
658  printf("\n");
659  printf("\t");
660  for( j=Nbj;j<Nej;j++)
661 	printf("%9s ","-------");
662  printf("\n");
663  i=-1;
664 
665  for( i=0;i<NAOrb;i++)
666  {
667 		 l=0;
668 		 for(j=0;j<3;j++)
669 		   l += AOrb[i].Gtf[0].l[j];
670 
671 		 printf("%c",GetSymmetry(l));
672 		 for(j=0;j<3;j++)
673 		 {
674 			 switch(AOrb[i].Gtf[0].l[j])
675 			 {
676 			 case 0:break;
677 			 case 1:printf("%s",XYZ[j]);break;
678 			 default :printf("%s%d",XYZ[j],AOrb[i].Gtf[0].l[j]);
679 			 }
680 		 }
681 		printf("\t");
682 
683  for( j=Nbj;j<Nej;j++)
684      printf("%9.6f ",M[j][i]);
685    printf("\n");
686  }
687 
688  }/*End Nb loop */
689    printf("\n");
690 }
691 /*************************************************************************************/
testascii(char c)692 static gboolean testascii(char c)
693 {
694 	switch ( c )
695 	{
696 	case	'0':
697 	case	'1':
698 	case	'2':
699 	case	'3':
700 	case	'4':
701 	case	'5':
702 	case	'6':
703 	case	'7':
704 	case	'8':
705 	case	'9':
706 	case	'.':
707 	case	'e':
708 	case	'E':
709 	case	'+':
710 	case	'-':return TRUE;
711 	}
712 	return FALSE;
713 }
714 /*************************************************************************************/
testi(char c)715 gboolean testi(char c)
716 {
717 	switch ( c )
718 	{
719 	case	'0':
720 	case	'1':
721 	case	'2':
722 	case	'3':
723 	case	'4':
724 	case	'5':
725 	case	'6':
726 	case	'7':
727 	case	'8':
728 	case	'9': return TRUE;
729 	}
730 	return FALSE;
731 }
732 /*************************************************************************************/
this_is_a_real(gchar * t)733 gboolean this_is_a_real(gchar *t)
734 {
735 	guint i;
736 	for(i=0;i<strlen(t);i++)
737 		if(!testascii(t[i]) ) return FALSE;
738 	if(t[0] =='e' || t[0] =='E' ) return FALSE;
739 	return TRUE;
740 
741 }
742 /*************************************************************************************/
this_is_a_integer(gchar * t)743 gboolean this_is_a_integer(gchar *t)
744 {
745 	guint i;
746 	if(!testi(t[0])&& t[0] != '-' ) return FALSE;
747 	for(i=1;i<strlen(t);i++)
748 		if(!testi(t[i]) ) return FALSE;
749 	return TRUE;
750 
751 }
752 /*************************************************************************************/
free_data_all()753 void free_data_all()
754 {
755         free_grid_all();
756         free_iso_all();
757         free_orbitals();
758         free_geometry();
759 	set_label_title("",0,0);
760 }
761 /********************************************************************************/
change_entry_value(GtkWidget * Entry,gpointer data)762 static void change_entry_value(GtkWidget *Entry, gpointer data)
763 {
764 	GtkWidget **entriestmp = NULL;
765 	gushort ii;
766 	gushort jj;
767 	gushort i;
768 	gushort j;
769 	gint k;
770 	gchar* temp;
771 	GtkWidget *entries[3][6];
772 	gchar tnG[100]="49";
773 	gint nG = (gint)fabs(limits.MinMax[1][1]-limits.MinMax[0][1])*6;
774 
775 	nG = getOptimalN(nG);
776 	sprintf(tnG,"%d",nG);
777 	if(GTK_IS_WIDGET(Entry))
778 	{
779 		entriestmp = (GtkWidget **)g_object_get_data (G_OBJECT (Entry), "Entries");
780 	}
781 	else return;
782 
783 	if(entriestmp==NULL) return;
784 
785 	for(i=0;i<3;i++)
786 	for(j=0;j<6;j++)
787 		entries[i][j] = entriestmp[i*6+j];
788 
789 	for(i=0;i<3;i++)
790 	for(j=0;j<6;j++)
791 		if(!GTK_IS_WIDGET(entries[i][j]))return;
792 	ii = 10;
793 	jj = 10;
794 	for(i=0;i<3;i++)
795 	for(j=0;j<6;j++)
796 	{
797 		if(Entry == entries[i][j])
798 		{
799 			ii = i;
800 			jj = j;
801 			break;
802 		}
803 	}
804 	if(ii==10 || jj == 10) return;
805 	/* reset second and third direction */
806 	if(ii==0 && jj <= 2)
807 	{
808 		gdouble C1[3];
809 		gdouble C2[3];
810 		gdouble C3[3];
811 		gdouble p = 0;
812 
813 		for(i=0;i<3;i++) C1[i] = atof(gtk_entry_get_text(GTK_ENTRY(entries[0][i])));
814 		for(i=0;i<3;i++) C2[i] = 0.0;
815 		for(i=0;i<3;i++)
816 			if(fabs(C1[i])<1e-6)
817 			{
818 				C2[i] = 1.0;
819 				break;
820 			}
821 		if(i==3) for(i=0;i<3;i++) C2[i] = 1.0;
822 
823 		k = 0;
824 		for(i=0;i<3;i++)
825 		{
826 			if(fabs(C1[i])>1e-6)
827 			{
828 				k = i;
829 				break;
830 			}
831 		}
832 		if(C1[k]!=0)
833 		{
834 			for(i=0;i<3;i++) if(k!=i) p += C1[i]*C2[i];
835 			C2[k] = -p/C1[k];
836 		}
837 		for(i=0;i<3;i++)
838 			C3[i] = C1[(i+1)%3]*C2[(i+2)%3] - C2[(i+1)%3]*C1[(i+2)%3];
839 
840 
841 		for(i=0;i<3;i++)
842 		{
843 			temp = g_strdup_printf("%lf",C2[i]);
844 		       	gtk_entry_set_text(GTK_ENTRY(entries[1][i]),temp);
845 			g_free(temp);
846 			temp = g_strdup_printf("%lf",C3[i]);
847 		       	gtk_entry_set_text(GTK_ENTRY(entries[2][i]),temp);
848 			g_free(temp);
849 		}
850 		return ;
851 	}
852 	/* reset z for second direction, reset third direction */
853 	if(ii==1 && jj <= 1)
854 	{
855 		gdouble C1[3];
856 		gdouble C2[3];
857 		gdouble C3[3];
858 		gdouble p = 0;
859 
860 		for(i=0;i<3;i++) C1[i] = atof(gtk_entry_get_text(GTK_ENTRY(entries[0][i])));
861 		for(i=0;i<3;i++) C2[i] = atof(gtk_entry_get_text(GTK_ENTRY(entries[1][i])));
862 
863 		k = 2;
864 		if(C1[k]!=0)
865 		{
866 			for(i=0;i<3;i++) if(k!=i) p += C1[i]*C2[i];
867 			C2[k] = -p/C1[k];
868 		}
869 		for(i=0;i<3;i++) C3[i] = C1[(i+1)%3]*C2[(i+2)%3] - C2[(i+1)%3]*C1[(i+2)%3];
870 
871 		temp = g_strdup_printf("%lf",C2[k]);
872 		gtk_entry_set_text(GTK_ENTRY(entries[1][k]),temp);
873 		g_free(temp);
874 
875 		for(i=0;i<3;i++)
876 		{
877 			temp = g_strdup_printf("%lf",C3[i]);
878 		       	gtk_entry_set_text(GTK_ENTRY(entries[2][i]),temp);
879 			g_free(temp);
880 		}
881 		return;
882 	}
883 	if(jj==3)
884 	{
885 		gdouble min = 0;
886 		gdouble max = 0;
887 
888 		min = atof(gtk_entry_get_text(GTK_ENTRY(entries[ii][jj])));
889 		max = -min;
890 
891 		nG = (gint)fabs(max-min)*6;
892 		nG = getOptimalN(nG);
893 		sprintf(tnG,"%d",nG);
894 
895 		temp = g_strdup_printf("%lf",max);
896 		gtk_entry_set_text(GTK_ENTRY(entries[ii][jj+1]),temp);
897 		g_free(temp);
898 		gtk_entry_set_text(GTK_ENTRY(entries[ii][jj+2]),tnG);
899 		if(ii<2)
900 		{
901 			temp = g_strdup_printf("%lf",min);
902 			gtk_entry_set_text(GTK_ENTRY(entries[ii+1][jj]),temp);
903 			g_free(temp);
904 		}
905 
906 		return;
907 	}
908 	if(jj==4&& ii<2)
909 	{
910 		gdouble max = 0;
911 
912 		max = atof(gtk_entry_get_text(GTK_ENTRY(entries[ii][jj])));
913 		temp = g_strdup_printf("%lf",max);
914 		gtk_entry_set_text(GTK_ENTRY(entries[ii+1][jj]),temp);
915 		g_free(temp);
916 		return;
917 	}
918 	if(jj==5 && ii<2)
919 	{
920 		gint nPoints = 10;
921 
922 		nPoints = atoi(gtk_entry_get_text(GTK_ENTRY(entries[ii][jj])));
923 		temp = g_strdup_printf("%d", nPoints);
924 		gtk_entry_set_text(GTK_ENTRY(entries[ii+1][jj]),temp);
925 		g_free(temp);
926 		return;
927 	}
928 }
929 /********************************************************************************/
create_grid_frame(GtkWidget * vboxall,gchar * title)930 GtkWidget *create_grid_frame( GtkWidget *vboxall,gchar* title)
931 {
932 	GtkWidget *frame;
933 	GtkWidget *vboxframe;
934 	gushort i;
935 	gushort j;
936 	GtkWidget *Table;
937 	gchar* temp = NULL;
938 	static GtkWidget* entries[3][6];
939 	gint nG = (gint)fabs(limits.MinMax[1][1]-limits.MinMax[0][1])*6;
940 	gchar tnG[100]="49";
941 
942 	nG = getOptimalN(nG);
943 	sprintf(tnG,"%d",nG);
944 
945 	frame = gtk_frame_new (title);
946 	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
947 	gtk_container_add (GTK_CONTAINER (vboxall), frame);
948 	gtk_widget_show (frame);
949 
950 	vboxframe = create_vbox(frame);
951 	Table = gtk_table_new(4,7,FALSE);
952 	gtk_container_add(GTK_CONTAINER(vboxframe),Table);
953 
954 	/* first line , titles */
955 	i = 0; j = 0;
956 	j++;
957 	add_label_at_table(Table, _("Vx"),(gushort)i,(gushort)j,GTK_JUSTIFY_CENTER);
958 	j++;
959 	add_label_at_table(Table, _("Vy"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
960 	j++;
961 	add_label_at_table(Table, _("Vz"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
962 	j++;
963 	add_label_at_table(Table, _("Minimum"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
964 	j++;
965 	add_label_at_table(Table, _("Maximum"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
966 	j++;
967 	add_label_at_table(Table, _("Number of points"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
968 
969 	/* First direction */
970 	j = 0;
971 	i++;
972 	add_label_at_table(Table, _("First direction "),(gushort)i,(gushort)j,GTK_JUSTIFY_LEFT);
973 
974 	j++;
975 	entries[i-1][j-1] = gtk_entry_new ();
976     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
977 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
978 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"1.0");
979 
980 	j++;
981 	entries[i-1][j-1] = gtk_entry_new ();
982     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
983 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
984 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
985 
986 	j++;
987 	entries[i-1][j-1] = gtk_entry_new ();
988     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
989 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
990 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
991 
992 	j++;
993 	entries[i-1][j-1] = gtk_entry_new ();
994     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
995 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
996 	temp = g_strdup_printf("%lf",limits.MinMax[0][0]);
997 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
998 	if(temp) g_free(temp);
999 
1000 	j++;
1001 	entries[i-1][j-1] = gtk_entry_new ();
1002     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1003 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1004 	temp = g_strdup_printf("%lf",limits.MinMax[1][0]);
1005 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1006 	if(temp) g_free(temp);
1007 
1008 	j++;
1009 	entries[i-1][j-1] = gtk_entry_new ();
1010     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1011 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1012 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),tnG);
1013 
1014 	/* Second direction */
1015 	j = 0;
1016 	i++;
1017 	add_label_at_table(Table, _("Second direction "),(gushort)i,(gushort)j,GTK_JUSTIFY_LEFT);
1018 
1019 	j++;
1020 	entries[i-1][j-1] = gtk_entry_new ();
1021     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1022 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1023 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1024 
1025 	j++;
1026 	entries[i-1][j-1] = gtk_entry_new ();
1027     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1028 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1029 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"1.0");
1030 
1031 	j++;
1032 	entries[i-1][j-1] = gtk_entry_new ();
1033     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1034 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1035 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1036 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1037 
1038 	j++;
1039 	entries[i-1][j-1] = gtk_entry_new ();
1040     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1041 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1042 	temp = g_strdup_printf("%lf",limits.MinMax[0][1]);
1043 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1044 	if(temp) g_free(temp);
1045 
1046 	j++;
1047 	entries[i-1][j-1] = gtk_entry_new ();
1048     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1049 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1050 	temp = g_strdup_printf("%lf",limits.MinMax[1][1]);
1051 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1052 	if(temp) g_free(temp);
1053 
1054 	j++;
1055 	entries[i-1][j-1] = gtk_entry_new ();
1056     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1057 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1058 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),tnG);
1059 
1060 	/* Third direction */
1061 	j = 0;
1062 	i++;
1063 	add_label_at_table(Table, _("Third direction "),(gushort)i,(gushort)j,GTK_JUSTIFY_LEFT);
1064 
1065 	j++;
1066 	entries[i-1][j-1] = gtk_entry_new ();
1067     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1068 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1069 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1070 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1071 
1072 	j++;
1073 	entries[i-1][j-1] = gtk_entry_new ();
1074     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1075 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1076 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1077 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1078 
1079 	j++;
1080 	entries[i-1][j-1] = gtk_entry_new ();
1081     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1082 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1083 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"1.0");
1084 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1085 
1086 	j++;
1087 	entries[i-1][j-1] = gtk_entry_new ();
1088     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1089 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1090 	temp = g_strdup_printf("%lf",limits.MinMax[0][2]);
1091 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1092 	if(temp) g_free(temp);
1093 
1094 	j++;
1095 	entries[i-1][j-1] = gtk_entry_new ();
1096     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1097 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1098 	temp = g_strdup_printf("%lf",limits.MinMax[1][2]);
1099 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1100 	if(temp) g_free(temp);
1101 
1102 	j++;
1103 	entries[i-1][j-1] = gtk_entry_new ();
1104     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1105 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1106 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),tnG);
1107 
1108 
1109 
1110 	for(i=0;i<3;i++)
1111 	for(j=0;j<6;j++)
1112 	{
1113 		g_object_set_data (G_OBJECT (entries[i][j]), "Entries", &entries);
1114 	}
1115 
1116 	for(i=0;i<3;i++)
1117 	for(j=0;j<6;j++)
1118   		g_signal_connect(G_OBJECT(entries[i][j]), "changed",G_CALLBACK(change_entry_value),entries[i][j]);
1119 
1120 	gtk_widget_show_all(frame);
1121 	g_object_set_data (G_OBJECT (frame), "Entries",&entries);
1122 
1123   	return frame;
1124 }
1125 /********************************************************************************/
create_grid(gchar * title)1126 void create_grid(gchar* title)
1127 {
1128 	GtkWidget *Win;
1129 	GtkWidget *frame;
1130 	GtkWidget *hbox;
1131 	GtkWidget *vboxall;
1132 	GtkWidget *vboxwin;
1133 	GtkWidget *button;
1134 	GtkWidget** entries;
1135 
1136 	if(!GeomOrb)
1137 	{
1138 		Message(_("Sorry, Please load a file before\n"),_("Error"),TRUE);
1139 		return;
1140 	}
1141 	if(!CoefAlphaOrbitals && TypeGrid != GABEDIT_TYPEGRID_MEP_CHARGES)
1142 	{
1143 		Message(_("Sorry, Please load the MO before\n"),_("Error"),TRUE);
1144 		return;
1145 	}
1146 	if(TypeGrid == GABEDIT_TYPEGRID_MEP_CHARGES)
1147 	{
1148 		gdouble s= GetSumAbsCharges();
1149 		if(s<1e-6) Message(_("Sorry, All partial charges are null\n"),_("Error"),TRUE);
1150 		return;
1151 	}
1152 
1153 	if(!AOAvailable &&(TypeGrid == GABEDIT_TYPEGRID_DDENSITY || TypeGrid == GABEDIT_TYPEGRID_ADENSITY))
1154 	{
1155 		Message(_("Sorry, No atomic orbitals available.\nPlease use a gabedit file for load : \n"
1156 		  "Geometry, Molecular and Atomic Orbitals\n"),_("Error"),TRUE);
1157 		return;
1158 	}
1159 
1160 	Win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1161 	gtk_window_set_title(GTK_WINDOW(Win),title);
1162 	gtk_window_set_position(GTK_WINDOW(Win),GTK_WIN_POS_CENTER);
1163 	gtk_container_set_border_width (GTK_CONTAINER (Win), 5);
1164 	gtk_window_set_transient_for(GTK_WINDOW(Win),GTK_WINDOW(PrincipalWindow));
1165 	gtk_window_set_modal (GTK_WINDOW (Win), TRUE);
1166 
1167 	add_glarea_child(Win,"Grid ");
1168 
1169 	vboxall = create_vbox(Win);
1170 	vboxwin = vboxall;
1171 	frame = create_grid_frame(vboxall,_("Box & Grid"));
1172 	entries = (GtkWidget**) g_object_get_data (G_OBJECT (frame), "Entries");
1173 	g_object_set_data (G_OBJECT (Win), "Entries",entries);
1174 
1175 
1176 	hbox = create_hbox_false(vboxwin);
1177 	gtk_widget_realize(Win);
1178 
1179 	button = create_button(Win,_("Cancel"));
1180 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1181 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
1182 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)delete_child, G_OBJECT(Win));
1183 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)gtk_widget_destroy,G_OBJECT(Win));
1184 	gtk_widget_show (button);
1185 
1186 	button = create_button(Win,_("OK"));
1187 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
1188 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1189 	gtk_widget_grab_default(button);
1190 	gtk_widget_show (button);
1191 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)applygrid,G_OBJECT(Win));
1192 
1193 
1194 	gtk_widget_show_all (Win);
1195 }
1196 /********************************************************************************/
applyelfdens(GtkWidget * Win,gpointer data)1197 void applyelfdens(GtkWidget *Win,gpointer data)
1198 {
1199 	GtkWidget** entriestmp = NULL;
1200 	G_CONST_RETURN gchar* temp;
1201 	gchar* dump;
1202 	gint i;
1203 	gint j;
1204 	GridLimits limitstmp;
1205 	gint NumPointstmp[3];
1206 	GtkWidget *entries[3][6];
1207 	gdouble V[3][3];
1208 	Grid* gridDens = NULL;
1209 	gboolean ongrid = TRUE;
1210 
1211 	if(GTK_IS_WIDGET(Win))
1212 	{
1213 		entriestmp = (GtkWidget **)g_object_get_data(G_OBJECT (Win), "Entries");
1214 		ongrid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT (Win), "OnGrid"));
1215 	}
1216 	else return;
1217 
1218 	if(entriestmp==NULL) return;
1219 
1220 	for(i=0;i<3;i++)
1221 	for(j=0;j<6;j++)
1222 		entries[i][j] = entriestmp[i*6+j];
1223 
1224 	for(i=0;i<3;i++)
1225 	{
1226 		for(j=3;j<5;j++)
1227 		{
1228         		temp	= gtk_entry_get_text(GTK_ENTRY(entries[i][j]));
1229 			dump = NULL;
1230 			if(temp && strlen(temp)>0)
1231 			{
1232 				dump = g_strdup(temp);
1233 				delete_first_spaces(dump);
1234 				delete_last_spaces(dump);
1235 			}
1236 
1237 			if(dump && strlen(dump)>0 && this_is_a_real(dump))
1238 			{
1239 				limitstmp.MinMax[j-3][i] = atof(dump);
1240 			}
1241 			else
1242 			{
1243 				GtkWidget* message = Message(_("Error : one entry is not a float "),_("Error"),TRUE);
1244   				gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1245 				return;
1246 			}
1247 			if(dump) g_free(dump);
1248 		}
1249         	temp	= gtk_entry_get_text(GTK_ENTRY(entries[i][5]));
1250 		NumPointstmp[i] = atoi(temp);
1251 		if(NumPointstmp[i] <=2)
1252 		{
1253 			GtkWidget* message = Message(_("Error : The number of points should be > 2. "),_("Error"),TRUE);
1254   			gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1255 			return;
1256 		}
1257 
1258 	}
1259 
1260 	for(i=0;i<3;i++)
1261 	{
1262 		if( limitstmp.MinMax[0][i]> limitstmp.MinMax[1][i])
1263 		{
1264 			GtkWidget* message = Message(_("Error :  The minimal value should be smaller than the maximal value "),_("Error"),TRUE);
1265   			gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1266 			return;
1267 		}
1268 	}
1269 	for(i=0;i<3;i++)
1270 	{
1271 		for(j=0;j<3;j++)
1272 		{
1273 			V[i][j] = 0;
1274         		temp	= gtk_entry_get_text(GTK_ENTRY(entries[i][j]));
1275 			dump = NULL;
1276 			if(temp && strlen(temp)>0)
1277 			{
1278 				dump = g_strdup(temp);
1279 				delete_first_spaces(dump);
1280 				delete_last_spaces(dump);
1281 			}
1282 
1283 			if(dump && strlen(dump)>0 && this_is_a_real(dump))
1284 			{
1285 				V[i][j] = atof(dump);
1286 			}
1287 			else
1288 			{
1289 				GtkWidget* message = Message(_("Error : one entry is not a float "),_("Error"),TRUE);
1290   				gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1291 				return;
1292 			}
1293 			if(dump) g_free(dump);
1294 		}
1295 	}
1296 
1297 	for(i=0;i<3;i++)
1298 	{
1299 		gdouble norm = 0.0;
1300 		for(j=0;j<3;j++)
1301 			norm += V[i][j]*V[i][j];
1302 		if(fabs(norm)<1e-8)
1303 		{
1304 			GtkWidget* message = Message(_("Error : the norm is equal to 0 "),_("Error"),TRUE);
1305   			gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1306 			return;
1307 		}
1308 		for(j=0;j<3;j++)
1309 			V[i][j] /= sqrt(norm);
1310 	}
1311 	for(j=0;j<3;j++) originOfCube[j] = 0;
1312 	for(j=0;j<3;j++) firstDirection[j] = V[0][j];
1313 	for(j=0;j<3;j++) secondDirection[j] = V[1][j];
1314 	for(j=0;j<3;j++) thirdDirection[j] = V[2][j];
1315 
1316 	for(i=0;i<3;i++)
1317 	{
1318 		NumPoints[i] =NumPointstmp[i] ;
1319 		for(j=0;j<2;j++)
1320 			limits.MinMax[j][i] =limitstmp.MinMax[j][i];
1321 	}
1322 
1323 
1324 	delete_child(Win);
1325 	free_grid_all();
1326 	grid = define_grid_ELFSAVIN(NumPoints,limits);
1327 	if(grid)
1328 	{
1329 		add_surface();
1330 		free_iso_all();
1331 		limits.MinMax[0][3] = grid->limits.MinMax[0][3];
1332 		limits.MinMax[1][3] = grid->limits.MinMax[1][3];
1333 	}
1334 	gridDens = define_grid_electronic_density(NumPoints,limits);
1335 	computeELFAttractors(grid, gridDens, ongrid);
1336 	Define_Iso(0.9);
1337 	glarea_rafresh(GLArea);
1338 }
1339 /********************************************************************************/
create_grid_ELF_Dens_analyze(gboolean ongrid)1340 void create_grid_ELF_Dens_analyze(gboolean ongrid)
1341 {
1342 	GtkWidget *Win;
1343 	GtkWidget *frame;
1344 	GtkWidget *hbox;
1345 	GtkWidget *vboxall;
1346 	GtkWidget *vboxwin;
1347 	GtkWidget *button;
1348 	GtkWidget** entries;
1349 
1350 	if(!GeomOrb)
1351 	{
1352 		Message(_("Sorry, Please load a file before\n"),_("Error"),TRUE);
1353 		return;
1354 	}
1355 	if(!CoefAlphaOrbitals && TypeGrid != GABEDIT_TYPEGRID_MEP_CHARGES)
1356 	{
1357 		Message(_("Sorry, Please load the MO before\n"),_("Error"),TRUE);
1358 		return;
1359 	}
1360 	if(TypeGrid == GABEDIT_TYPEGRID_MEP_CHARGES)
1361 	{
1362 		gdouble s= GetSumAbsCharges();
1363 		if(s<1e-6) Message(_("Sorry, All partial charges are null\n"),_("Error"),TRUE);
1364 		return;
1365 	}
1366 
1367 	if(!AOAvailable &&(TypeGrid == GABEDIT_TYPEGRID_DDENSITY || TypeGrid == GABEDIT_TYPEGRID_ADENSITY))
1368 	{
1369 		Message(_("Sorry, No atomic orbitals available.\nPlease use a gabedit file for load : \n"
1370 		  "Geometry, Molecular and Atomic Orbitals\n"),_("Error"),TRUE);
1371 		return;
1372 	}
1373 
1374 	Win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1375 	gtk_window_set_title(GTK_WINDOW(Win),_("ELF Attractors"));
1376 	gtk_window_set_position(GTK_WINDOW(Win),GTK_WIN_POS_CENTER);
1377 	gtk_container_set_border_width (GTK_CONTAINER (Win), 5);
1378 	gtk_window_set_transient_for(GTK_WINDOW(Win),GTK_WINDOW(PrincipalWindow));
1379 	gtk_window_set_modal (GTK_WINDOW (Win), TRUE);
1380 
1381 	add_glarea_child(Win,"Grid ");
1382 
1383 	vboxall = create_vbox(Win);
1384 	vboxwin = vboxall;
1385 	frame = create_grid_frame(vboxall,_("Box & Grid"));
1386 	entries = (GtkWidget**) g_object_get_data (G_OBJECT (frame), "Entries");
1387 	g_object_set_data (G_OBJECT (Win), "Entries",entries);
1388 	g_object_set_data (G_OBJECT (Win), "OnGrid",GINT_TO_POINTER(ongrid));
1389 
1390 
1391 	hbox = create_hbox_false(vboxwin);
1392 	gtk_widget_realize(Win);
1393 
1394 	button = create_button(Win,_("Cancel"));
1395 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1396 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
1397 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)delete_child, G_OBJECT(Win));
1398 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)gtk_widget_destroy,G_OBJECT(Win));
1399 	gtk_widget_show (button);
1400 
1401 	button = create_button(Win,_("OK"));
1402 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
1403 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
1404 	gtk_widget_grab_default(button);
1405 	gtk_widget_show (button);
1406 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)applyelfdens,G_OBJECT(Win));
1407 
1408 
1409 	gtk_widget_show_all (Win);
1410 }
1411 /********************************************************************************/
read_any_file(gchar * FileName)1412 void read_any_file(gchar* FileName)
1413 {
1414 	gint filetype = get_type_file_orb(FileName);
1415 	switch(filetype)
1416 	{
1417 		case GABEDIT_TYPEFILE_GAMESS : read_gamess_orbitals(FileName);break;
1418 		case GABEDIT_TYPEFILE_GAUSSIAN : read_gauss_orbitals(FileName);break;
1419 		case GABEDIT_TYPEFILE_MOLPRO : read_molpro_orbitals(FileName);break;
1420 		case GABEDIT_TYPEFILE_QCHEM : read_qchem_orbitals(FileName);break;
1421 		case GABEDIT_TYPEFILE_MOLDEN : read_molden_orbitals(FileName);break;
1422 		case GABEDIT_TYPEFILE_GABEDIT : read_gabedit_orbitals(FileName);break;
1423 		case GABEDIT_TYPEFILE_XYZ : gl_read_xyz_file(FileName);break;
1424 		case GABEDIT_TYPEFILE_GAUSSIANINPUT :
1425 		case GABEDIT_TYPEFILE_MOLCASINPUT :
1426 		case GABEDIT_TYPEFILE_MOLPROINPUT :
1427 		case GABEDIT_TYPEFILE_UNKNOWN : break;
1428 	}
1429 }
1430 /********************************************************************************/
get_number_of_point(GtkWidget * Entry)1431 gint get_number_of_point(GtkWidget* Entry)
1432 {
1433 	gchar* t = NULL;
1434 	gint N = -1;
1435         G_CONST_RETURN gchar* temp = gtk_entry_get_text(GTK_ENTRY(Entry));
1436 	if(temp)
1437 	{
1438 		t = g_strdup(temp);
1439 		delete_first_spaces(t);
1440 		delete_last_spaces(t);
1441 	}
1442 	if(t && !this_is_a_integer(t))
1443 	{
1444 		GtkWidget* win = Message(_("Error : The number of points should be integer. "),_("Error"),TRUE);
1445   		gtk_window_set_modal (GTK_WINDOW (win), TRUE);
1446 		g_free(t);
1447 		return -1;
1448 	}
1449 	if(t) g_free(t);
1450 	N = atoi(temp);
1451 	if(N<=0)
1452 	{
1453 		GtkWidget* win = Message(_("Error : The number of points should be positive. "),_("Error"),TRUE);
1454   		gtk_window_set_modal (GTK_WINDOW (win), TRUE);
1455 		return -1;
1456 	}
1457 	return N;
1458 }
1459 /********************************************************************************/
get_a_float(GtkWidget * Entry,gdouble * value,gchar * errorMessage)1460 gboolean get_a_float(GtkWidget* Entry,gdouble* value, gchar* errorMessage)
1461 {
1462 	G_CONST_RETURN gchar* temp;
1463 	gchar* t = NULL;
1464         temp	= gtk_entry_get_text(GTK_ENTRY(Entry));
1465 	if(temp&& strlen(temp)>0)
1466 	{
1467 		t = g_strdup(temp);
1468 		delete_first_spaces(t);
1469 		delete_last_spaces(t);
1470 	}
1471 	else
1472 	{
1473 		GtkWidget* win = Message(errorMessage,_("Error"),TRUE);
1474   		gtk_window_set_modal (GTK_WINDOW (win), TRUE);
1475 		return FALSE;
1476 	}
1477 	if(t && !this_is_a_real(t))
1478 	{
1479 		GtkWidget* win = Message(errorMessage,_("Error"),TRUE);
1480 		g_free(t);
1481   		gtk_window_set_modal (GTK_WINDOW (win), TRUE);
1482 		return FALSE;
1483 	}
1484 	if(t) g_free(t);
1485 	*value = atof(temp);
1486 	return TRUE;
1487 }
1488 /********************************************************************************/
initialise_global_orbitals_variables()1489 void initialise_global_orbitals_variables()
1490 {
1491 	gint i;
1492 	PopupMenuIsOpen = FALSE;
1493 	BondsOrb = NULL;
1494 	GeomOrb = NULL;
1495 	GLArea = NULL;
1496 	nCenters =0;
1497  	ShowDipoleOrb = TRUE;
1498  	ShowHBondOrb = FALSE;
1499  	ShowHAtomOrb = TRUE;
1500 	ShowMultiBondsOrb = TRUE;
1501  	ShowVibration = FALSE;
1502 	TypeGrid = GABEDIT_TYPEGRID_ORBITAL;
1503 	TypeGeom = GABEDIT_TYPEGEOM_STICK;
1504 	TypeBlend = GABEDIT_BLEND_NO;
1505 	TypePosWireFrame = GABEDIT_POS_WIREFRAME_NO;
1506 	TypeNegWireFrame = GABEDIT_NEG_WIREFRAME_NO;
1507 	SurfShow = GABEDIT_SURFSHOW_POSNEG;
1508 	TypeTexture = GABEDIT_TYPETEXTURE_NONE;
1509 	Title = NULL;
1510 	ScreenWidth = gdk_screen_width();
1511 	ScreenHeight = gdk_screen_height();
1512 	for(i=0;i<3;i++)
1513 		limits.MinMax[0][i] = -5;
1514 	for(i=0;i<3;i++)
1515 		limits.MinMax[1][i] = 5;
1516 	NumPoints[0] = 49;
1517 	NumPoints[1] = 49;
1518 	NumPoints[2] = 49;
1519 	CoefAlphaOrbitals = NULL;
1520 	EnerAlphaOrbitals = NULL;
1521 	OccAlphaOrbitals = NULL;
1522 	SymAlphaOrbitals = NULL;
1523 	CoefBetaOrbitals = NULL;
1524 	EnerBetaOrbitals = NULL;
1525 	OccBetaOrbitals = NULL;
1526 	SymBetaOrbitals = NULL;
1527 	isopositive = NULL;
1528 	isonegative = NULL;
1529 	isonull = NULL;
1530 	grid = NULL;
1531 	gridPlaneForContours = NULL;
1532 	gridPlaneForPlanesMapped = NULL;
1533 
1534 	reDrawContoursPlane = FALSE;
1535 	reDrawPlaneMappedPlane = FALSE;
1536 
1537 	AOAvailable = FALSE;
1538 	RebuildSurf = TRUE;
1539 	RebuildGeom = TRUE;
1540 	newContours = TRUE;
1541 	newSurface = FALSE;
1542 	DeleteContours = FALSE;
1543 	CancelCalcul = FALSE;
1544 	init_vibration();
1545 	createBMPFiles = FALSE;
1546 	numBMPFile = 0;
1547 	createPPMFiles = FALSE;
1548 	numPPMFile = 0;
1549 	createPOVFiles = FALSE;
1550 	numPOVFile = 0;
1551 	AOrb = NULL;
1552 	SAOrb = NULL;
1553 	SOverlaps = NULL;
1554 	solventRadius = 1.4;
1555 	alphaFED = 3.0; /* eV^-1 */
1556 }
1557 /********************************************************************************/
close_window_orb(GtkWidget * win,gpointer data)1558 void close_window_orb(GtkWidget*win, gpointer data)
1559 {
1560 	if(!GTK_IS_WIDGET(PrincipalWindow)) return;
1561 
1562 	CancelCalcul = TRUE;
1563 	while( gtk_events_pending() ) gtk_main_iteration();
1564 
1565 	free_data_all();
1566 	free_objects_all();
1567 
1568   	destroy_children(PrincipalWindow);
1569 
1570 	GLArea = NULL;
1571 	PrincipalWindow = NULL;
1572 }
1573 /********************************************************************************/
add_glarea_child(GtkWidget * winchild,gchar * title)1574 void add_glarea_child(GtkWidget* winchild,gchar* title)
1575 {
1576   if(GLArea)
1577   {
1578   	add_child(PrincipalWindow,winchild,gtk_widget_destroy,title);
1579   	g_signal_connect(G_OBJECT(winchild),"delete_event",(GCallback)delete_child,NULL);
1580   }
1581   else
1582   {
1583   	add_button_windows(title,winchild);
1584   	g_signal_connect(G_OBJECT(winchild), "delete_event",(GCallback)destroy_button_windows,NULL);
1585   	g_signal_connect(G_OBJECT(winchild), "delete_event",G_CALLBACK(gtk_widget_destroy),NULL);
1586   }
1587 }
1588 /*************************************************************************************/
create_color_surfaces_file()1589 void create_color_surfaces_file()
1590 {
1591 	gchar *colorsurface;
1592 	FILE *fd;
1593 	gdouble v[4];
1594 	gint i;
1595 	gint j;
1596 	gint n=3;
1597 
1598 	colorsurface = g_strdup_printf("%s/colorssurface",gabedit_directory());
1599 
1600 	fd = FOpen(colorsurface, "w");
1601 	if(fd)
1602 	{
1603 		fprintf(fd,"%d\n",n);
1604 		for(i=0;i<n;i++)
1605 		{
1606 			get_color_surface(i,v) ;
1607 			for(j=0;j<4;j++)
1608 				fprintf(fd,"%lf ",v[j]);
1609 			fprintf(fd,"\n");
1610 		}
1611 		fclose(fd);
1612 	}
1613 
1614 	g_free(colorsurface);
1615 }
1616 /*************************************************************************************/
read_color_surfaces_file()1617 void read_color_surfaces_file()
1618 {
1619 	gchar *colorsurface;
1620 	FILE *fd;
1621 	gint i;
1622 	gint n = 0;
1623 	gchar t[BSIZE];
1624 	gint len = BSIZE;
1625 	gdouble v[4];
1626 
1627 	colorsurface = g_strdup_printf("%s/colorssurface",gabedit_directory());
1628 
1629 	fd = fopen(colorsurface, "rb");
1630 	if(fd)
1631 	{
1632     		{ char* e = fgets(t,BSIZE,fd);}
1633 		n = atoi(t);
1634 		for(i=0;i<n;i++)
1635 		{
1636     			{ char* e = fgets(t,len,fd);}
1637 			sscanf(t,"%lf %lf %lf %lf",&v[0],&v[1],&v[2],&v[3]);
1638 			set_color_surface(i,v);
1639 		}
1640  		fclose(fd);
1641 	}
1642 	g_free(colorsurface);
1643 }
1644 /*************************************************************************************/
applygridsas(GtkWidget * Win,gpointer data)1645 static void applygridsas(GtkWidget *Win,gpointer data)
1646 {
1647 	GtkWidget** entriestmp = NULL;
1648 	G_CONST_RETURN gchar* temp;
1649 	gchar* dump;
1650 	gint i;
1651 	gint j;
1652 	GridLimits limitstmp;
1653 	gint NumPointstmp[3];
1654 	GtkWidget *entries[4][6];
1655 	gdouble V[3][3];
1656 
1657 
1658 	if(GTK_IS_WIDGET(Win))
1659 	{
1660 		entriestmp = (GtkWidget **)g_object_get_data(G_OBJECT (Win), "Entries");
1661 	}
1662 	else return;
1663 
1664 	if(entriestmp==NULL) return;
1665 
1666 	for(i=0;i<3;i++)
1667 	for(j=0;j<6;j++)
1668 		entries[i][j] = entriestmp[i*6+j];
1669 	entries[3][0] = entriestmp[18];
1670 
1671 	for(i=0;i<3;i++)
1672 	{
1673 		for(j=3;j<5;j++)
1674 		{
1675         		temp	= gtk_entry_get_text(GTK_ENTRY(entries[i][j]));
1676 			dump = NULL;
1677 			if(temp && strlen(temp)>0)
1678 			{
1679 				dump = g_strdup(temp);
1680 				delete_first_spaces(dump);
1681 				delete_last_spaces(dump);
1682 			}
1683 
1684 			if(dump && strlen(dump)>0 && this_is_a_real(dump))
1685 			{
1686 				limitstmp.MinMax[j-3][i] = atof(dump);
1687 			}
1688 			else
1689 			{
1690 				GtkWidget* message = Message(_("Error : one entry is not a float "),_("Error"),TRUE);
1691   				gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1692 				return;
1693 			}
1694 			if(dump) g_free(dump);
1695 		}
1696         	temp	= gtk_entry_get_text(GTK_ENTRY(entries[i][5]));
1697 		NumPointstmp[i] = atoi(temp);
1698 		if(NumPointstmp[i] <=2)
1699 		{
1700 			GtkWidget* message = Message(_("Error : The number of points should be > 2. "),_("Error"),TRUE);
1701   			gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1702 			return;
1703 		}
1704 
1705 	}
1706 	{
1707         	temp	= gtk_entry_get_text(GTK_ENTRY(entries[3][0]));
1708 		dump = NULL;
1709 		if(temp && strlen(temp)>0)
1710 		{
1711 			dump = g_strdup(temp);
1712 			delete_first_spaces(dump);
1713 			delete_last_spaces(dump);
1714 		}
1715 
1716 		if(dump && strlen(dump)>0 && this_is_a_real(dump))
1717 		{
1718 			solventRadius = atof(dump);
1719 		}
1720 		else
1721 		{
1722 			GtkWidget* message = Message(_("Error : The solvent radius should be a float "),_("Error"),TRUE);
1723   			gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1724 			return;
1725 		}
1726 		if(dump) g_free(dump);
1727 	}
1728 
1729 	for(i=0;i<3;i++)
1730 	{
1731 		if( limitstmp.MinMax[0][i]> limitstmp.MinMax[1][i])
1732 		{
1733 			GtkWidget* message = Message(_("Error :  The minimal value should be smaller than the maximal value "),_("Error"),TRUE);
1734   			gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1735 			return;
1736 		}
1737 	}
1738 	for(i=0;i<3;i++)
1739 	{
1740 		for(j=0;j<3;j++)
1741 		{
1742 			V[i][j] = 0;
1743         		temp	= gtk_entry_get_text(GTK_ENTRY(entries[i][j]));
1744 			dump = NULL;
1745 			if(temp && strlen(temp)>0)
1746 			{
1747 				dump = g_strdup(temp);
1748 				delete_first_spaces(dump);
1749 				delete_last_spaces(dump);
1750 			}
1751 
1752 			if(dump && strlen(dump)>0 && this_is_a_real(dump))
1753 			{
1754 				V[i][j] = atof(dump);
1755 			}
1756 			else
1757 			{
1758 				GtkWidget* message = Message(_("Error : one entry is not a float "),_("Error"),TRUE);
1759   				gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1760 				return;
1761 			}
1762 			if(dump) g_free(dump);
1763 		}
1764 	}
1765 
1766 	for(i=0;i<3;i++)
1767 	{
1768 		gdouble norm = 0.0;
1769 		for(j=0;j<3;j++)
1770 			norm += V[i][j]*V[i][j];
1771 		if(fabs(norm)<1e-8)
1772 		{
1773 			GtkWidget* message = Message(_("Error : the norm is equal to 0 "),_("Error"),TRUE);
1774   			gtk_window_set_modal (GTK_WINDOW (message), TRUE);
1775 			return;
1776 		}
1777 		for(j=0;j<3;j++)
1778 			V[i][j] /= sqrt(norm);
1779 	}
1780 	for(j=0;j<3;j++) originOfCube[j] = 0;
1781 	for(j=0;j<3;j++) firstDirection[j] = V[0][j];
1782 	for(j=0;j<3;j++) secondDirection[j] = V[1][j];
1783 	for(j=0;j<3;j++) thirdDirection[j] = V[2][j];
1784 
1785 	for(i=0;i<3;i++)
1786 	{
1787 		NumPoints[i] =NumPointstmp[i] ;
1788 		for(j=0;j<2;j++)
1789 			limits.MinMax[j][i] =limitstmp.MinMax[j][i];
1790 	}
1791 
1792 
1793 	delete_child(Win);
1794 	if(TypeGrid == GABEDIT_TYPEGRID_SAS)
1795 	{
1796 		TypeGrid = GABEDIT_TYPEGRID_SAS;
1797 		Define_Grid();
1798 		Define_Iso(0.0);
1799 	}
1800 	if(TypeGrid == GABEDIT_TYPEGRID_SASMAP)
1801 	{
1802 		TypeGrid = GABEDIT_TYPEGRID_SAS;
1803 		Define_Grid();
1804 		Define_Iso(0.0);
1805 		CancelCalcul = FALSE;
1806 		mapping_with_mep_from_charges();
1807 	}
1808 
1809 	glarea_rafresh(GLArea);
1810 }
1811 /*************************************************************************************/
create_grid_sas_frame(GtkWidget * vboxall,gchar * title)1812 static GtkWidget *create_grid_sas_frame( GtkWidget *vboxall,gchar* title)
1813 {
1814 	GtkWidget *frame;
1815 	GtkWidget *vboxframe;
1816 	gushort i;
1817 	gushort j;
1818 	GtkWidget *Table;
1819 	gchar* temp = NULL;
1820 	static GtkWidget* entries[4][6];
1821 	gint nG = (gint)fabs(limits.MinMax[1][1]-limits.MinMax[0][1])*6;
1822 	gchar tnG[100]="49";
1823 	gchar sr[100]="1.4";
1824 
1825 	nG = getOptimalN(nG);
1826 	sprintf(tnG,"%d",nG);
1827 
1828 	sprintf(sr,"%lf",solventRadius);
1829 
1830 	frame = gtk_frame_new (title);
1831 	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
1832 	gtk_container_add (GTK_CONTAINER (vboxall), frame);
1833 	gtk_widget_show (frame);
1834 
1835 	vboxframe = create_vbox(frame);
1836 	Table = gtk_table_new(4,7,FALSE);
1837 	gtk_container_add(GTK_CONTAINER(vboxframe),Table);
1838 
1839 	/* first line , titles */
1840 	i = 0; j = 0;
1841 	j++;
1842 	add_label_at_table(Table, _("Vx"),(gushort)i,(gushort)j,GTK_JUSTIFY_CENTER);
1843 	j++;
1844 	add_label_at_table(Table, _("Vy"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
1845 	j++;
1846 	add_label_at_table(Table, _("Vz"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
1847 	j++;
1848 	add_label_at_table(Table, _("Minimum"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
1849 	j++;
1850 	add_label_at_table(Table, _("Maximum"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
1851 	j++;
1852 	add_label_at_table(Table, _("Number of points"),(gushort)i, (gushort)j,GTK_JUSTIFY_CENTER);
1853 
1854 	/* First direction */
1855 	j = 0;
1856 	i++;
1857 	add_label_at_table(Table, _("First direction "),(gushort)i,(gushort)j,GTK_JUSTIFY_LEFT);
1858 
1859 	j++;
1860 	entries[i-1][j-1] = gtk_entry_new ();
1861     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1862 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1863 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"1.0");
1864 
1865 	j++;
1866 	entries[i-1][j-1] = gtk_entry_new ();
1867     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1868 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1869 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1870 
1871 	j++;
1872 	entries[i-1][j-1] = gtk_entry_new ();
1873     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1874 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1875 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1876 
1877 	j++;
1878 	entries[i-1][j-1] = gtk_entry_new ();
1879     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1880 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1881 	temp = g_strdup_printf("%lf",limits.MinMax[0][0]);
1882 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1883 	if(temp) g_free(temp);
1884 
1885 	j++;
1886 	entries[i-1][j-1] = gtk_entry_new ();
1887     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1888 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1889 	temp = g_strdup_printf("%lf",limits.MinMax[1][0]);
1890 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1891 	if(temp) g_free(temp);
1892 
1893 	j++;
1894 	entries[i-1][j-1] = gtk_entry_new ();
1895     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1896 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1897 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),tnG);
1898 
1899 	/* Second direction */
1900 	j = 0;
1901 	i++;
1902 	add_label_at_table(Table, _("Second direction "),(gushort)i,(gushort)j,GTK_JUSTIFY_LEFT);
1903 
1904 	j++;
1905 	entries[i-1][j-1] = gtk_entry_new ();
1906     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1907 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1908 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1909 
1910 	j++;
1911 	entries[i-1][j-1] = gtk_entry_new ();
1912     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1913 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1914 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"1.0");
1915 
1916 	j++;
1917 	entries[i-1][j-1] = gtk_entry_new ();
1918     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1919 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1920 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1921 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1922 
1923 	j++;
1924 	entries[i-1][j-1] = gtk_entry_new ();
1925     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1926 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1927 	temp = g_strdup_printf("%lf",limits.MinMax[0][1]);
1928 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1929 	if(temp) g_free(temp);
1930 
1931 	j++;
1932 	entries[i-1][j-1] = gtk_entry_new ();
1933     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1934 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1935 	temp = g_strdup_printf("%lf",limits.MinMax[1][1]);
1936 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1937 	if(temp) g_free(temp);
1938 
1939 	j++;
1940 	entries[i-1][j-1] = gtk_entry_new ();
1941     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1942 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1943 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),tnG);
1944 
1945 	/* Third direction */
1946 	j = 0;
1947 	i++;
1948 	add_label_at_table(Table, _("Third direction "),(gushort)i,(gushort)j,GTK_JUSTIFY_LEFT);
1949 
1950 	j++;
1951 	entries[i-1][j-1] = gtk_entry_new ();
1952     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1953 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1954 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1955 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1956 
1957 	j++;
1958 	entries[i-1][j-1] = gtk_entry_new ();
1959     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1960 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1961 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"0.0");
1962 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1963 
1964 	j++;
1965 	entries[i-1][j-1] = gtk_entry_new ();
1966     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),50,-1);
1967 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1968 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),"1.0");
1969 	gtk_widget_set_sensitive(entries[i-1][j-1], FALSE);
1970 
1971 	j++;
1972 	entries[i-1][j-1] = gtk_entry_new ();
1973     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1974 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1975 	temp = g_strdup_printf("%lf",limits.MinMax[0][2]);
1976 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1977 	if(temp) g_free(temp);
1978 
1979 	j++;
1980 	entries[i-1][j-1] = gtk_entry_new ();
1981     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1982 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1983 	temp = g_strdup_printf("%lf",limits.MinMax[1][2]);
1984 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),temp);
1985 	if(temp) g_free(temp);
1986 
1987 	j++;
1988 	entries[i-1][j-1] = gtk_entry_new ();
1989     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][j-1]),100,-1);
1990 	add_widget_table(Table,entries[i-1][j-1],(gushort)i,(gushort)j);
1991 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][j-1]),tnG);
1992 
1993 	/* Slovent radius */
1994 	j = 0;
1995 	i++;
1996 	{
1997 		GtkWidget *Label;
1998 		GtkWidget *hbox = gtk_hbox_new(0,FALSE);
1999 
2000 		Label = gtk_label_new ("Solvent radius (Angstrum) ");
2001    		gtk_label_set_justify(GTK_LABEL(Label),GTK_JUSTIFY_LEFT);
2002 		gtk_box_pack_start (GTK_BOX (hbox), Label, FALSE, FALSE, 0);
2003 		gtk_table_attach(GTK_TABLE(Table),hbox,j,j+2,i,i+1,
2004                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
2005                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
2006                   3,3);
2007 	}
2008 
2009 	j+=2;
2010 	entries[i-1][0] = gtk_entry_new ();
2011     	gtk_widget_set_size_request(GTK_WIDGET(entries[i-1][0]),50,-1);
2012 	gtk_table_attach(GTK_TABLE(Table),GTK_WIDGET(entries[i-1][0]),j,j+3,i,i+1,
2013                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
2014                   (GtkAttachOptions)(GTK_FILL | GTK_SHRINK),
2015                   3,3);
2016 	gtk_entry_set_text(GTK_ENTRY(entries[i-1][0]),sr);
2017 
2018 
2019 	for(i=0;i<3;i++)
2020 	for(j=0;j<6;j++)
2021 	{
2022 		g_object_set_data (G_OBJECT (entries[i][j]), "Entries", &entries);
2023 	}
2024 	g_object_set_data (G_OBJECT (entries[3][0]), "Entries", &entries);
2025 
2026 	for(i=0;i<3;i++)
2027 	for(j=0;j<6;j++)
2028   		g_signal_connect(G_OBJECT(entries[i][j]), "changed",G_CALLBACK(change_entry_value),entries[i][j]);
2029 
2030 	gtk_widget_show_all(frame);
2031 	g_object_set_data (G_OBJECT (frame), "Entries",&entries);
2032 
2033   	return frame;
2034 }
2035 /********************************************************************************/
create_grid_sas(gchar * title)2036 void create_grid_sas(gchar* title)
2037 {
2038 	GtkWidget *Win;
2039 	GtkWidget *frame;
2040 	GtkWidget *hbox;
2041 	GtkWidget *vboxall;
2042 	GtkWidget *vboxwin;
2043 	GtkWidget *button;
2044 	GtkWidget** entries;
2045 
2046 	if(!GeomOrb)
2047 	{
2048 		Message(_("Sorry, Please load a file before\n"),_("Error"),TRUE);
2049 		return;
2050 	}
2051 
2052 	Win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2053 	gtk_window_set_title(GTK_WINDOW(Win),title);
2054 	gtk_window_set_position(GTK_WINDOW(Win),GTK_WIN_POS_CENTER);
2055 	gtk_container_set_border_width (GTK_CONTAINER (Win), 5);
2056 	gtk_window_set_transient_for(GTK_WINDOW(Win),GTK_WINDOW(PrincipalWindow));
2057 	gtk_window_set_modal (GTK_WINDOW (Win), TRUE);
2058 
2059 	add_glarea_child(Win,"Grid ");
2060 
2061 	vboxall = create_vbox(Win);
2062 	vboxwin = vboxall;
2063 	frame = create_grid_sas_frame(vboxall,_("Box & Grid & Solvent radius"));
2064 	entries = (GtkWidget**) g_object_get_data (G_OBJECT (frame), "Entries");
2065 	g_object_set_data (G_OBJECT (Win), "Entries",entries);
2066 
2067 
2068 	hbox = create_hbox_false(vboxwin);
2069 	gtk_widget_realize(Win);
2070 
2071 	button = create_button(Win,_("Cancel"));
2072 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
2073 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
2074 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)delete_child, G_OBJECT(Win));
2075 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)gtk_widget_destroy,G_OBJECT(Win));
2076 	gtk_widget_show (button);
2077 
2078 	button = create_button(Win,_("OK"));
2079 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
2080 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
2081 	gtk_widget_grab_default(button);
2082 	gtk_widget_show (button);
2083 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)applygridsas,G_OBJECT(Win));
2084 
2085 
2086 	gtk_widget_show_all (Win);
2087 }
2088 /********************************************************************************/
apply_set_scale_ball_stick(GtkWidget * Win,gpointer data)2089 static void apply_set_scale_ball_stick(GtkWidget *Win,gpointer data)
2090 {
2091 	GtkWidget* entryBall = NULL;
2092 	GtkWidget* entryStick = NULL;
2093 	gdouble sBall = 1;
2094 	gdouble sStick = 1;
2095 
2096 	if(!GTK_IS_WIDGET(Win)) return;
2097 
2098 	entryBall = g_object_get_data (G_OBJECT (Win), "EntryBall");
2099 	entryStick = g_object_get_data (G_OBJECT (Win), "EntryStick");
2100 
2101 	if(entryBall) sBall = atof(gtk_entry_get_text(GTK_ENTRY(entryBall)));
2102 	if(entryStick) sStick = atof(gtk_entry_get_text(GTK_ENTRY(entryStick)));
2103 	RebuildGeom = TRUE;
2104 	setScaleBall(sBall);
2105 	setScaleStick(sStick);
2106 	glarea_rafresh(GLArea);
2107 }
2108 /********************************************************************************/
apply_set_scale_ball_stick_close(GtkWidget * Win,gpointer data)2109 static void apply_set_scale_ball_stick_close(GtkWidget *Win,gpointer data)
2110 {
2111 	apply_set_scale_ball_stick(Win,data);
2112 	delete_child(Win);
2113 }
2114 /********************************************************************************/
add_entry_scale(GtkWidget * table,gchar * strLabel,gint il,gdouble val)2115 static GtkWidget *add_entry_scale(GtkWidget *table, gchar* strLabel, gint il, gdouble val)
2116 {
2117 	gushort i;
2118 	gushort j;
2119 	GtkWidget *entry;
2120 	GtkWidget *label;
2121 
2122 /*----------------------------------------------------------------------------------*/
2123 	i = il;
2124 	j = 0;
2125 	label = gtk_label_new(strLabel);
2126 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
2127                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
2128                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
2129                   1,1);
2130 /*----------------------------------------------------------------------------------*/
2131 	i = il;
2132 	j = 1;
2133 	label = gtk_label_new(":");
2134 	gtk_table_attach(GTK_TABLE(table),label, j,j+1,i,i+1,
2135                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK) ,
2136                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
2137                   1,1);
2138 /*----------------------------------------------------------------------------------*/
2139 	i = il;
2140 	j = 2;
2141 	entry =  gtk_entry_new();
2142 	{
2143 		gchar* v = g_strdup_printf("%lf",val);
2144 		if(v)gtk_entry_set_text(GTK_ENTRY(entry),v);
2145 		else gtk_entry_set_text(GTK_ENTRY(entry),"1.0");
2146 		if(v) g_free(v);
2147 	}
2148 
2149 	gtk_table_attach(GTK_TABLE(table),entry,
2150 			j,j+4,i,i+1,
2151                   (GtkAttachOptions)(GTK_FILL|GTK_EXPAND) ,
2152                   (GtkAttachOptions)(GTK_FILL|GTK_SHRINK),
2153                   1,1);
2154 
2155   	return entry;
2156 }
2157 /********************************************************************************/
set_scale_ball_stick_dlg()2158 void set_scale_ball_stick_dlg()
2159 {
2160 	GtkWidget *Win;
2161 	GtkWidget *frame;
2162 	GtkWidget *vboxframe;
2163 	GtkWidget *hbox;
2164 	GtkWidget *table;
2165 	GtkWidget *vboxall;
2166 	GtkWidget *button;
2167 	GtkWidget *entryBall;
2168 	GtkWidget *entryStick;
2169 
2170 	Win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2171 	gtk_window_set_title(GTK_WINDOW(Win),_("Scale Ball&Stick"));
2172 	gtk_window_set_position(GTK_WINDOW(Win),GTK_WIN_POS_CENTER);
2173 	gtk_container_set_border_width (GTK_CONTAINER (Win), 5);
2174 	gtk_window_set_modal (GTK_WINDOW (Win), TRUE);
2175 
2176 	add_glarea_child(Win,"ScaleBallStick");
2177 
2178 	vboxall = create_vbox(Win);
2179 	frame = gtk_frame_new (NULL);
2180 	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
2181 	gtk_container_add (GTK_CONTAINER (vboxall), frame);
2182 	gtk_widget_show (frame);
2183 
2184 	vboxframe = create_vbox(frame);
2185 	table = gtk_table_new(2,3,FALSE);
2186 	gtk_container_add(GTK_CONTAINER(vboxframe),table);
2187 
2188 	entryBall = add_entry_scale(table, _("Scale Ball"), 0,getScaleBall());
2189 	g_object_set_data (G_OBJECT (Win), "EntryBall",entryBall);
2190 	entryStick = add_entry_scale(table, _("Scale Stick"), 1,getScaleStick());
2191 	g_object_set_data (G_OBJECT (Win), "EntryStick",entryStick);
2192 
2193 	hbox = create_hbox_false(vboxall);
2194 	gtk_widget_realize(Win);
2195 
2196 	button = create_button(Win,_("OK"));
2197 	gtk_box_pack_end (GTK_BOX( hbox), button, FALSE, TRUE, 3);
2198 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
2199 	gtk_widget_grab_default(button);
2200 	gtk_widget_show (button);
2201 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)apply_set_scale_ball_stick_close,G_OBJECT(Win));
2202 
2203 	button = create_button(Win,_("Apply"));
2204 	gtk_box_pack_end (GTK_BOX( hbox), button, FALSE, TRUE, 3);
2205 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
2206 	gtk_widget_show (button);
2207 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)apply_set_scale_ball_stick,G_OBJECT(Win));
2208 
2209 	button = create_button(Win,_("Cancel"));
2210 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
2211 	gtk_box_pack_end (GTK_BOX( hbox), button, FALSE, TRUE, 3);
2212 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)delete_child, G_OBJECT(Win));
2213 	g_signal_connect_swapped(G_OBJECT(button), "clicked",(GCallback)gtk_widget_destroy,G_OBJECT(Win));
2214 	gtk_widget_show (button);
2215 
2216 	gtk_widget_show_all (Win);
2217 }
2218 /*********************************************************************************************************/
resetGridColorMap()2219 static void resetGridColorMap()
2220 {
2221 	GtkWidget* handleBoxColorMapGrid = g_object_get_data(G_OBJECT(PrincipalWindow), "HandleboxColorMapGrid");
2222 
2223 	if(handleBoxColorMapGrid)
2224 	{
2225 		GtkWidget* entryLeft  = g_object_get_data(G_OBJECT(handleBoxColorMapGrid), "EntryLeft");
2226 		GtkWidget* entryRight = g_object_get_data(G_OBJECT(handleBoxColorMapGrid), "EntryRight");
2227 		GtkWidget* darea      = g_object_get_data(G_OBJECT(handleBoxColorMapGrid), "DrawingArea");
2228 		ColorMap* colorMap = g_object_get_data(G_OBJECT( handleBoxColorMapGrid),"ColorMap");
2229 		if(colorMap && entryLeft && entryRight && darea && colorMap->numberOfColors>0)
2230 		{
2231 			gdouble minValue = colorMap->colorValue[0].value;
2232 			gdouble maxValue = colorMap->colorValue[colorMap->numberOfColors-1].value;
2233 			ColorMap* newColorMap = new_colorMap_min_max(minValue, maxValue);
2234 			colormap_free(colorMap);
2235 			g_free(colorMap);
2236 			colorMap = newColorMap;
2237 			g_object_set_data(G_OBJECT(handleBoxColorMapGrid),"ColorMap", colorMap);
2238 			g_object_set_data(G_OBJECT(entryLeft),"ColorMap", colorMap);
2239 			g_object_set_data(G_OBJECT(entryRight),"ColorMap", colorMap);
2240 			g_object_set_data(G_OBJECT(darea),"ColorMap", colorMap);
2241 			color_map_refresh(handleBoxColorMapGrid);
2242 			if(GTK_WIDGET_VISIBLE(handleBoxColorMapGrid))
2243 			{
2244 				gtk_widget_hide(handleBoxColorMapGrid);
2245 				gtk_widget_show(handleBoxColorMapGrid);
2246 			}
2247 		}
2248 	}
2249 }
2250 /*********************************************************************************************************/
resetPlanesMappedColorMap()2251 static void resetPlanesMappedColorMap()
2252 {
2253 	GtkWidget* handleBoxColorMapPlanesMapped = g_object_get_data(G_OBJECT(PrincipalWindow), "HandleboxColorMapPlanesMapped");
2254 	if(handleBoxColorMapPlanesMapped)
2255 	{
2256 		GtkWidget* entryLeft  = g_object_get_data(G_OBJECT(handleBoxColorMapPlanesMapped), "EntryLeft");
2257 		GtkWidget* entryRight = g_object_get_data(G_OBJECT(handleBoxColorMapPlanesMapped), "EntryRight");
2258 		GtkWidget* darea      = g_object_get_data(G_OBJECT(handleBoxColorMapPlanesMapped), "DrawingArea");
2259 		ColorMap* colorMap = g_object_get_data(G_OBJECT( handleBoxColorMapPlanesMapped),"ColorMap");
2260 		if(colorMap && entryLeft && entryRight && darea && colorMap->numberOfColors>0)
2261 		{
2262 			gdouble minValue = colorMap->colorValue[0].value;
2263 			gdouble maxValue = colorMap->colorValue[colorMap->numberOfColors-1].value;
2264 			ColorMap* newColorMap = new_colorMap_min_max(minValue, maxValue);
2265 			colormap_free(colorMap);
2266 			g_free(colorMap);
2267 			colorMap = newColorMap;
2268 			g_object_set_data(G_OBJECT(handleBoxColorMapPlanesMapped),"ColorMap", colorMap);
2269 			g_object_set_data(G_OBJECT(entryLeft),"ColorMap", colorMap);
2270 			g_object_set_data(G_OBJECT(entryRight),"ColorMap", colorMap);
2271 			g_object_set_data(G_OBJECT(darea),"ColorMap", colorMap);
2272 			color_map_refresh(handleBoxColorMapPlanesMapped);
2273 			if(GTK_WIDGET_VISIBLE(handleBoxColorMapPlanesMapped))
2274 			{
2275 				gtk_widget_hide(handleBoxColorMapPlanesMapped);
2276 				gtk_widget_show(handleBoxColorMapPlanesMapped);
2277 			}
2278 
2279 		}
2280 	}
2281 }
2282 /*********************************************************************************************************/
resetContoursColorMap()2283 static void resetContoursColorMap()
2284 {
2285 	GtkWidget* handleBoxColorMapContours = g_object_get_data(G_OBJECT(PrincipalWindow), "HandleboxColorMapContours");
2286 
2287 	if(handleBoxColorMapContours)
2288 	{
2289 		GtkWidget* entryLeft  = g_object_get_data(G_OBJECT(handleBoxColorMapContours), "EntryLeft");
2290 		GtkWidget* entryRight = g_object_get_data(G_OBJECT(handleBoxColorMapContours), "EntryRight");
2291 		GtkWidget* darea      = g_object_get_data(G_OBJECT(handleBoxColorMapContours), "DrawingArea");
2292 		ColorMap* colorMap = g_object_get_data(G_OBJECT( handleBoxColorMapContours),"ColorMap");
2293 		if(colorMap && entryLeft && entryRight && darea && colorMap->numberOfColors>0)
2294 		{
2295 			gdouble minValue = colorMap->colorValue[0].value;
2296 			gdouble maxValue = colorMap->colorValue[colorMap->numberOfColors-1].value;
2297 			ColorMap* newColorMap = new_colorMap_min_max(minValue, maxValue);
2298 			colormap_free(colorMap);
2299 			g_free(colorMap);
2300 			colorMap = newColorMap;
2301 			g_object_set_data(G_OBJECT(handleBoxColorMapContours),"ColorMap", colorMap);
2302 			g_object_set_data(G_OBJECT(entryLeft),"ColorMap", colorMap);
2303 			g_object_set_data(G_OBJECT(entryRight),"ColorMap", colorMap);
2304 			g_object_set_data(G_OBJECT(darea),"ColorMap", colorMap);
2305 			color_map_refresh(handleBoxColorMapContours);
2306 			if(GTK_WIDGET_VISIBLE(handleBoxColorMapContours))
2307 			{
2308 				gtk_widget_hide(handleBoxColorMapContours);
2309 				gtk_widget_show(handleBoxColorMapContours);
2310 			}
2311 		}
2312 	}
2313 }
2314 /*********************************************************************************************************/
resetAllColorMapOrb()2315 void resetAllColorMapOrb()
2316 {
2317 	resetGridColorMap();
2318 	resetContoursColorMap();
2319 	resetPlanesMappedColorMap();
2320 	resetBeginNegative();
2321 	glarea_rafresh(GLArea);
2322 }
2323 /*********************************************************************************************************************/
set_alphaFED(GtkWidget * button,gpointer data)2324 static void set_alphaFED(GtkWidget *button,gpointer data)
2325 {
2326 	GtkWidget* entry = (GtkWidget*)data;
2327 	G_CONST_RETURN gchar* temp;
2328 	gchar* dump = NULL;
2329 	GtkWidget* Win = g_object_get_data (G_OBJECT (button), "Win");
2330 
2331 	if(!GTK_IS_WIDGET(data)) return;
2332 
2333        	temp	= gtk_entry_get_text(GTK_ENTRY(entry));
2334 	if(temp && strlen(temp)>0)
2335 	{
2336 		dump = g_strdup(temp);
2337 		delete_first_spaces(dump);
2338 		delete_last_spaces(dump);
2339 	}
2340 
2341 	if(dump && strlen(dump)>0 && this_is_a_real(dump) && atof(dump)>=0 && atof(dump)<=100)
2342 	{
2343 		alphaFED = atof(dump);
2344 		if(dump) g_free(dump);
2345 		gtk_widget_destroy(Win);
2346 	}
2347 	else
2348 	{
2349 		GtkWidget* message = Message(_("Error : alpha should be a real between 0 and 100 "),_("Error"),TRUE);
2350   		gtk_window_set_modal (GTK_WINDOW (message), TRUE);
2351 		if(dump) g_free(dump);
2352 		gtk_window_set_transient_for(GTK_WINDOW(message),GTK_WINDOW(Win));
2353 		return;
2354 	}
2355 }
2356 /*********************************************************************/
set_alphaFED_dialog()2357 GtkWidget* set_alphaFED_dialog ()
2358 {
2359 	GtkWidget *fp;
2360 	GtkWidget *frame;
2361 	GtkWidget *vboxall;
2362 	GtkWidget *vboxframe;
2363 	GtkWidget *hbox;
2364 	GtkWidget *button;
2365 	GtkWidget *label;
2366 	GtkWidget* entry;
2367 	GtkWidget *hseparator;
2368 	gchar* tlabel="Alpha(eV^-1) : ";
2369 	gchar* val = NULL;
2370 	gchar* info =
2371 		"f (x,y,z) = (2 - n)/2{\n"
2372 	      	"      [sum_j(1 to N) O_j  Phi_j (x,y,z)^2 e^(-alpha(e_HOMO -e_j ))]/\n"
2373 	        "     [sum_j(1 to N) O_j   e^(-alpha(e_HOMO -e_j ))]\n"
2374       		"}\n"
2375       		"+ n/2 {\n"
2376 	        "      [sum_j(1 to N) (2-O_j)  Phi_j (x,y,z)^2 e^(+alpha(e_LUMO -e_j ))]/\n"
2377 	        "      [sum_j(1 to N) (2-O_j)   e^(+alpha(e_LUMO -e_j ))]\n"
2378       		"}\n\n"
2379 		"n  = 0 for an electrophilic reaction,\n"
2380      		"     1 for a radical reaction, and\n"
2381      		"     2 for a nucleophilic reaction.\n"
2382 		"N is the number of orbitals.\n"
2383 		"O_j is the number of electrons in orbital j.\n"
2384 		"Phi_j(x,y,z) is the value of the orbital j at point (x,y,z).\n"
2385 		"e_j is the energy of orbital j.\n";
2386 
2387 	fp = gtk_window_new(GTK_WINDOW_TOPLEVEL);
2388 	gtk_window_set_modal(GTK_WINDOW(fp),TRUE);
2389 	gtk_window_set_title(GTK_WINDOW(fp),_("Set alpha for FED calculation"));
2390 	gtk_container_set_border_width (GTK_CONTAINER (fp), 5);
2391 
2392 	gtk_window_set_position(GTK_WINDOW(fp),GTK_WIN_POS_CENTER);
2393 	gtk_window_set_modal (GTK_WINDOW (fp), TRUE);
2394 
2395 	g_signal_connect(G_OBJECT(fp),"delete_event",(GCallback)gtk_widget_destroy,NULL);
2396 
2397 	vboxall = create_vbox(fp);
2398 	frame = gtk_frame_new (NULL);
2399 	gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
2400 	gtk_container_add (GTK_CONTAINER (vboxall), frame);
2401 	gtk_widget_show (frame);
2402 
2403 	vboxframe = create_vbox(frame);
2404 
2405 	hbox = create_hbox(vboxframe);
2406 	label = gtk_label_new (info);
2407 	gtk_widget_show (label);
2408 	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 0);
2409 
2410 	hseparator = gtk_hseparator_new ();
2411 	gtk_box_pack_start (GTK_BOX (vboxframe), hseparator, TRUE, FALSE, 0);
2412 
2413 	hbox = create_hbox(vboxframe);
2414 	label = gtk_label_new (tlabel);
2415 	gtk_widget_show (label);
2416 	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, FALSE, 0);
2417 
2418 	entry = gtk_entry_new ();
2419 	gtk_widget_show (entry);
2420 	gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, TRUE, 0);
2421 	val = g_strdup_printf("%f",alphaFED);
2422        	gtk_entry_set_text(GTK_ENTRY(entry),val);
2423 	if(val) g_free(val);
2424 
2425 	hbox = create_hbox(vboxall);
2426 
2427 	button = create_button(PrincipalWindow,_("OK"));
2428 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
2429 	g_signal_connect(G_OBJECT(button), "clicked",G_CALLBACK(set_alphaFED),(gpointer)entry);
2430 	g_object_set_data (G_OBJECT (button), "Win", fp);
2431 	gtk_widget_show (button);
2432 
2433 	button = create_button(PrincipalWindow,_("Cancel"));
2434 	gtk_box_pack_start (GTK_BOX( hbox), button, TRUE, TRUE, 3);
2435 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(gtk_widget_destroy),GTK_OBJECT(fp));
2436 
2437 	gtk_widget_show (button);
2438 
2439 	gtk_widget_show_all(fp);
2440 	return fp;
2441 }
2442