1 /* GInterfaceGeom.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 <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include "../Common/Global.h"
27 #include "../Utils/UtilsInterface.h"
28 #include "../Utils/Utils.h"
29 #include "../Geometry/GeomGlobal.h"
30 #include "../Geometry/GeomXYZ.h"
31 #include "../Geometry/GeomZmatrix.h"
32 #include "../Geometry/InterfaceGeom.h"
33 #include "GaussGlobal.h"
34 
35 /************************************************************************************************************/
get_number_of_model_connections()36 static gint get_number_of_model_connections()
37 {
38 	gint i;
39 	gint j;
40 	gint nc = 0;
41 	gint NC = NcentersXYZ;
42 	if(MethodeGeom == GEOM_IS_ZMAT) NC = NcentersZmat;
43     	for(i=0;i<NC;i++)
44 	{
45 		if( MethodeGeom == GEOM_IS_XYZ)
46 			if(strstr(GeomXYZ[i].Layer,"Me") || strstr(GeomXYZ[i].Layer,"Lo")) continue;
47 		if( MethodeGeom == GEOM_IS_ZMAT)
48 			if(strstr(Geom[i].Layer,"Me") || strstr(Geom[i].Layer,"Lo")) continue;
49     		for(j=0;j<NC;j++)
50 		{
51 			if(i==j) continue;
52 			if( MethodeGeom == GEOM_IS_XYZ)
53 				if(!strstr(GeomXYZ[j].Layer,"Me") && !strstr(GeomXYZ[j].Layer,"Lo")) continue;
54 			if( MethodeGeom == GEOM_IS_ZMAT)
55 				if(!strstr(Geom[j].Layer,"Me") && !strstr(Geom[j].Layer,"Lo")) continue;
56 			if(connecteds(i,j)) nc++;
57 		}
58 	}
59 	return nc;
60 }
61 /************************************************************************************************************/
get_number_of_inter_connections()62 static gint get_number_of_inter_connections()
63 {
64 	gint i;
65 	gint j;
66 	gint nc = 0;
67 	gint NC = NcentersXYZ;
68 	if(MethodeGeom == GEOM_IS_ZMAT) NC = NcentersZmat;
69     	for(i=0;i<NC;i++)
70 	{
71 
72 		if( MethodeGeom == GEOM_IS_XYZ)
73 			if(strstr(GeomXYZ[i].Layer," ") || strstr(GeomXYZ[i].Layer,"Lo") || strstr(GeomXYZ[i].Layer,"Hi")) continue;
74 		if( MethodeGeom == GEOM_IS_ZMAT)
75 			if(strstr(Geom[i].Layer," ") || strstr(Geom[i].Layer,"Lo") || strstr(Geom[i].Layer,"Hi")) continue;
76 
77     		for(j=0;j<NC;j++)
78 		{
79 			if(i==j) continue;
80 			if( MethodeGeom == GEOM_IS_XYZ)
81 				if(!strstr(GeomXYZ[j].Layer," ") && !strstr(GeomXYZ[j].Layer,"Lo") && !strstr(GeomXYZ[j].Layer,"Hi")) continue;
82 			if( MethodeGeom == GEOM_IS_ZMAT)
83 				if(!strstr(Geom[j].Layer," ") && !strstr(Geom[j].Layer,"Lo") && !strstr(Geom[j].Layer,"Hi")) continue;
84 			if(connecteds(i,j)) nc++;
85 		}
86 	}
87 	return nc;
88 }
89 /************************************************************************************************************/
set_spin_of_electrons()90 void set_spin_of_electrons()
91 {
92         gint i;
93         guint NumberElectrons[3];
94         guint SpinElectrons[3];
95         gchar* chaine;
96 
97         if(EntryCS[0] == NULL ) return;
98         NumberElectrons[2]= get_number_electrons(2);
99         NumberElectrons[1]= get_number_electrons(1);
100         NumberElectrons[0]= get_number_electrons(0);
101 
102         for(i=0;i<3;i++)
103 		SpinElectrons[i]=0;
104         if(NMethodes==3)
105 	{
106         	NumberElectrons[2] += get_number_of_model_connections();
107         	NumberElectrons[1] += get_number_of_inter_connections();
108 	}
109         if(NMethodes==2)
110 	{
111         	NumberElectrons[1] += get_number_of_model_connections();
112 	}
113 
114         for(i=0;(guint)i<NMethodes;i++)
115         	if((NumberElectrons[i]-TotalCharges[i])%2==0)
116 			SpinElectrons[i]=1;
117                 else
118 			SpinElectrons[i]=2;
119 
120         for(i=0;(guint)i<NMethodes;i++)
121         {
122 		if(SpinMultiplicities[i]%2 != SpinElectrons[i]%2)
123 			SpinMultiplicities[i] = SpinElectrons[i];
124          	chaine = g_strdup_printf("%d",SpinMultiplicities[i]);
125 	 	if(EntryCS[2*i+1] && GTK_IS_ENTRY(EntryCS[2*i+1]))
126 		{
127          		gtk_entry_set_text(GTK_ENTRY(EntryCS[2*i+1]),chaine);
128 		}
129         }
130 }
131 /************************************************************************************************************/
change_of_charge(GtkWidget * entry,gpointer d)132 static void change_of_charge(GtkWidget *entry,gpointer d)
133 {
134         G_CONST_RETURN gchar *entry_text;
135         gint *Number;
136 
137         Number = (gint*)d;
138         entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
139         TotalCharges[*Number] = atoi(entry_text);
140 	set_spin_of_electrons();
141 
142 }
143 /************************************************************************************************************/
create_combo_charge(GtkWidget * hbox,gint Num,gchar * tlabel)144 static void create_combo_charge(GtkWidget *hbox,gint Num,gchar *tlabel)
145 {
146   gchar *tlist[]={"0","1","-1","2","-2","3","-3","4","-4"};
147   gint *Number;
148   Number = g_malloc(sizeof(gint));
149   *Number = Num/2;
150   EntryCS[Num] = create_label_combo(hbox,tlabel,tlist,9,TRUE,-1,(gint)(ScreenHeight*0.1));
151   g_signal_connect(G_OBJECT(EntryCS[Num]), "changed", G_CALLBACK(change_of_charge), Number);
152   TotalCharges[*Number] = 0;
153 }
154 /************************************************************************************************************/
create_combo_spin(GtkWidget * hbox,gint Num,gchar * tlabel)155 static void create_combo_spin(GtkWidget *hbox,gint Num,gchar *tlabel)
156 {
157   gchar *tlist[]={"1","2","3","4","5","6","7","8","9"};
158  EntryCS[Num] = create_label_combo(hbox,tlabel,tlist,9,TRUE,-1,(gint)(ScreenHeight*0.1));
159 }
160 /************************************************************************************************************/
GAjoutePageGeom(GtkWidget * NoteBook)161 void GAjoutePageGeom(GtkWidget *NoteBook)
162 {
163   GtkWidget *window1;
164   GtkWidget *Frame;
165   GtkWidget *LabelOnglet;
166   GtkWidget *LabelMenu;
167   GtkWidget *vbox;
168   GtkWidget *hbox;
169   GtkWidget *hbox2;
170   GtkWidget *FrameType;
171   GtkWidget *combobox = NULL;
172   gint i;
173 
174   geom_is_open();
175   geominter=g_malloc(sizeof(GeomInter));
176   geominter->window= gtk_frame_new(NULL);
177   HboxGeom = NULL;
178   for(i=0;i<6;i++)
179 	EntryCS[i]=NULL;
180 
181   Frame = geominter->window;
182   gtk_container_set_border_width(GTK_CONTAINER(Frame), 10);
183 
184   LabelOnglet = gtk_label_new(_("Molecular Specifications"));
185   LabelMenu = gtk_label_new(_("Molecular Specifications"));
186   gtk_notebook_append_page_menu(GTK_NOTEBOOK(NoteBook),
187                                 Frame,
188                                 LabelOnglet, LabelMenu);
189 
190   window1 = Frame;
191   g_object_set_data(G_OBJECT (window1), "window1", window1);
192 
193   vbox =create_vbox(window1);
194 
195   hbox =create_hbox_false(vbox);
196   hbox2 =create_hbox_false(vbox);
197   NMethodes = 0;
198 
199   if(Methodes[1]!=NULL || Methodes[2]!=NULL )
200   {
201   	create_label_hbox(hbox,_("Charge of    "),-1);
202   	create_combo_charge(hbox,0,_("Real system : "));
203   	create_label_hbox(hbox2,_("2*Spin+1 of "),-1);
204   	create_combo_spin(hbox2,1,_("Real system : "));
205         NMethodes++;
206   }
207   else
208   {
209   	create_label_hbox(hbox,_("Charge of   "),-1);
210   	create_combo_charge(hbox,0,_("system : "));
211   	create_label_hbox(hbox,_("2*Spin+1 of "),-1);
212   	create_combo_spin(hbox,1,_("system : "));
213         NMethodes++;
214   }
215   if(Methodes[1]!=NULL && Methodes[2]!=NULL )
216   {
217   	create_combo_charge(hbox,2,_("Intermediate system : "));
218   	create_combo_spin(hbox2,3,_("Intermediate system : "));
219   	NMethodes++;
220   	create_combo_charge(hbox,4,_("Model system : "));
221   	create_combo_spin(hbox2,5,_("Model system : "));
222   	NMethodes++;
223   }
224   else
225   if(Methodes[1]!=NULL || Methodes[2]!=NULL )
226   {
227   	create_combo_charge(hbox,2,_("Model system : "));
228   	create_combo_spin(hbox2,3,_("Model system : "));
229   	NMethodes++;
230   }
231 
232   if(!GeomFromCheck )
233   {
234   create_hseparator(vbox);
235   hbox =create_hbox_false(vbox);
236   FrameType = create_frame(window1,hbox,_("TYPE"));
237   combobox = create_geom(window1,FrameType);
238 
239   geominter->vbox=vbox;
240   geominter->frametitle=g_strdup(_("GEOMETRY"));
241 
242  if(GeomXYZ != NULL && MethodeGeom == GEOM_IS_XYZ )
243      create_geomXYZ_interface (GABEDIT_TYPEFILEGEOM_UNKNOWN);
244  if(Geom != NULL && MethodeGeom == GEOM_IS_ZMAT)
245      create_geom_interface (GABEDIT_TYPEFILEGEOM_UNKNOWN);
246 
247   }
248   set_spin_of_electrons();
249   if(combobox) gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0);
250 
251 }
252 
253