1 /* GamessGuess.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 #include <stdlib.h>
21 #include <ctype.h>
22 #include <math.h>
23 #include <string.h>
24 
25 #include "../../Config.h"
26 #include "../Common/Global.h"
27 #include "../Gamess/GamessTypes.h"
28 #include "../Gamess/GamessGlobal.h"
29 #include "../Utils/Utils.h"
30 #include "../Utils/UtilsInterface.h"
31 #include "../Utils/GabeditTextEdit.h"
32 #include "../Common/Windows.h"
33 #include "../Utils/Constants.h"
34 
35 static GtkWidget *buttonPrintGuess = NULL;
36 static GtkWidget *buttonRotate = NULL;
37 static GtkWidget *guessFrame = NULL;
38 /*************************************************************************************************************/
39 static gchar* listGuessMethodView[] = { "Huckel", "Core" };
40 static gchar* listGuessMethodReal[] = { "NONE", "GUESS=HCORE" };
41 static guint numberOfGuessMethods = G_N_ELEMENTS (listGuessMethodView);
42 static gchar selectedGuessMethod[BSIZE]="NONE";
43 /*************************************************************************************************************/
initGamessGuessFrame()44 void initGamessGuessFrame()
45 {
46 	guessFrame = NULL;
47 }
48 /*************************************************************************************************************/
setSensitiveGamessGuessFrame(gboolean sensitive)49 void setSensitiveGamessGuessFrame(gboolean sensitive)
50 {
51 	if(!guessFrame) return;
52 	gtk_widget_set_sensitive(guessFrame, sensitive);
53 }
54 /*************************************************************************************************************/
putGamessGuessOptionsInfoInTextEditor()55 static void putGamessGuessOptionsInfoInTextEditor()
56 {
57 	if(!GTK_TOGGLE_BUTTON (buttonPrintGuess)->active
58 	   && !GTK_TOGGLE_BUTTON (buttonRotate)->active) return;
59         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, " ",-1);
60         gabedit_text_insert (GABEDIT_TEXT(text), NULL, &gamessColorFore.keyWord, &gamessColorBack.keyWord, "$GUESS",-1);
61 	if(GTK_TOGGLE_BUTTON (buttonPrintGuess)->active)
62         	gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, " PRTMO=.TRUE.",-1);
63 	if(GTK_TOGGLE_BUTTON (buttonRotate)->active)
64         	gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, " MIX=.TRUE.",-1);
65 
66         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, " ",-1);
67         gabedit_text_insert (GABEDIT_TEXT(text), NULL, &gamessColorFore.keyWord, &gamessColorBack.keyWord, "$END\n",-1);
68 }
69 /************************************************************************************************************/
putGamessGuessMethodInfoInTextEditor()70 static void putGamessGuessMethodInfoInTextEditor()
71 {
72 	if( strcmp(selectedGuessMethod,"NONE")==0 ) return;
73         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, " ",-1);
74         gabedit_text_insert (GABEDIT_TEXT(text), NULL, &gamessColorFore.keyWord, &gamessColorBack.keyWord, "$GUESS",-1);
75         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, " ",-1);
76         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, selectedGuessMethod,-1);
77         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, " ",-1);
78         gabedit_text_insert (GABEDIT_TEXT(text), NULL, &gamessColorFore.keyWord, &gamessColorBack.keyWord, "$END\n",-1);
79 }
80 /*************************************************************************************************************/
putGamessGuessInfoInTextEditor()81 void putGamessGuessInfoInTextEditor()
82 {
83 	putGamessGuessMethodInfoInTextEditor();
84 	putGamessGuessOptionsInfoInTextEditor();
85 
86 }
87 /************************************************************************************************************/
traitementGuessMethod(GtkComboBox * combobox,gpointer d)88 static void traitementGuessMethod (GtkComboBox *combobox, gpointer d)
89 {
90 	GtkTreeIter iter;
91 	gchar* data = NULL;
92 	gchar* res = NULL;
93 	gint i;
94 	/* gchar* s;*/
95 	if (gtk_combo_box_get_active_iter (combobox, &iter))
96 	{
97 		GtkTreeModel* model = gtk_combo_box_get_model(combobox);
98 		gtk_tree_model_get (model, &iter, 0, &data, -1);
99 	}
100 	for(i=0;i<numberOfGuessMethods;i++)
101 	{
102 		if(strcmp((gchar*)data,listGuessMethodView[i])==0) res = listGuessMethodReal[i];
103 	}
104 	if(res) sprintf(selectedGuessMethod,"%s",res);
105 	else  sprintf(selectedGuessMethod,"MINI");
106 
107 	/* for(s=selectedGuessMethod;*s != 0;s++) *s = toupper(*s);*/
108 }
109 /********************************************************************************************************/
create_list_guessmethods()110 static GtkWidget *create_list_guessmethods()
111 {
112         GtkTreeIter iter;
113         GtkTreeStore *store;
114 	GtkTreeModel *model;
115 	GtkWidget *combobox;
116 	GtkCellRenderer *renderer;
117 	gint i;
118         GtkTreeIter iter0;
119 
120 	store = gtk_tree_store_new (1,G_TYPE_STRING);
121 
122 	for(i=0;i<numberOfGuessMethods;i++)
123 	{
124         	gtk_tree_store_append (store, &iter, NULL);
125 		if(i==0) iter0 = iter;
126         	gtk_tree_store_set (store, &iter, 0, listGuessMethodView[i], -1);
127 	}
128 
129         model = GTK_TREE_MODEL (store);
130 	combobox = gtk_combo_box_new_with_model (model);
131 	/*
132 	gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (combobox), TRUE);
133 	*/
134 	g_object_unref (model);
135 	g_signal_connect (G_OBJECT(combobox), "changed", G_CALLBACK(traitementGuessMethod), NULL);
136 	renderer = gtk_cell_renderer_text_new ();
137 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
138 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
139 
140 	gtk_combo_box_set_active_iter(GTK_COMBO_BOX (combobox), &iter0);
141 
142 	return combobox;
143 }
144 /************************************************************************************************************/
createGamessGuessFrame(GtkWidget * win,GtkWidget * box)145 void createGamessGuessFrame(GtkWidget *win, GtkWidget *box)
146 {
147 	GtkWidget* frame;
148 	GtkWidget* vboxFrame;
149 	GtkWidget* sep;
150 	GtkWidget* combo = NULL;
151 	gint l=0;
152 	gint c=0;
153 	gint ncases=1;
154 	GtkWidget *table = gtk_table_new(4,3,FALSE);
155 
156 	buttonPrintGuess = NULL;
157 	buttonRotate = NULL;
158 
159 	frame = gtk_frame_new (_("Mo Guess"));
160 	guessFrame = frame;
161 	gtk_widget_show (frame);
162 	gtk_box_pack_start (GTK_BOX (box), frame, TRUE, TRUE, 3);
163 	gtk_frame_set_label_align (GTK_FRAME (frame), 0.5, 0.5);
164 
165 	vboxFrame = gtk_vbox_new (FALSE, 3);
166 	gtk_widget_show (vboxFrame);
167 	gtk_container_add (GTK_CONTAINER (frame), vboxFrame);
168 	gtk_box_pack_start (GTK_BOX (vboxFrame), table, TRUE, TRUE, 0);
169 
170 	/*------------------ Guess Method -----------------------------------------*/
171 	l=0;
172 	c = 0; ncases=1;
173 	add_label_table(table,_("Initial Guess"),l,c);
174 	c = 1; ncases=1;
175 	add_label_table(table,":",l,c);
176 	combo = create_list_guessmethods();
177 	c = 2; ncases=1;
178 	gtk_table_attach(GTK_TABLE(table),combo,c,c+ncases,l,l+1,
179 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
180 		(GtkAttachOptions)	(GTK_FILL | GTK_SHRINK),
181                   2,2);
182 	/*------------------ separator -----------------------------------------*/
183 	l++;
184 	sep = gtk_hseparator_new ();;
185 	c = 0; ncases=3;
186 	gtk_table_attach(GTK_TABLE(table),sep,c,c+ncases,l,l+1,
187 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
188 		(GtkAttachOptions)	(GTK_FILL | GTK_SHRINK),
189                   2,2);
190 	/*------------------ Print Orbs L ------------*/
191 	l++;
192 	c = 0; ncases=3;
193 	buttonPrintGuess = gtk_check_button_new_with_label (_("Print the initial Guess"));
194 	gtk_table_attach(GTK_TABLE(table),buttonPrintGuess,c,c+ncases,l,l+1,
195 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
196 		(GtkAttachOptions)	(GTK_FILL | GTK_SHRINK),
197                   2,2);
198 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buttonPrintGuess), FALSE);
199 	/*------------------ Mix ------------*/
200 	l++;
201 	c = 0; ncases=3;
202 	buttonRotate = gtk_check_button_new_with_label (_("Rotate alpha and beta orbitals"));
203 	gtk_table_attach(GTK_TABLE(table),buttonRotate,c,c+ncases,l,l+1,
204 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
205 		(GtkAttachOptions)	(GTK_FILL | GTK_SHRINK),
206                   2,2);
207 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buttonRotate), FALSE);
208 }
209