1 /* FireFly.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 "../Common/Global.h"
23 #include "../FireFly/FireFlyTypes.h"
24 #include "../FireFly/FireFlyGlobal.h"
25 #include "../FireFly/FireFlyMolecule.h"
26 #include "../FireFly/FireFlyControl.h"
27 #include "../FireFly/FireFlyBasis.h"
28 #include "../FireFly/FireFlyGuess.h"
29 #include "../FireFly/FireFlySCF.h"
30 #include "../Utils/UtilsInterface.h"
31 #include "../Geometry/GeomGlobal.h"
32 #include "../Geometry/InterfaceGeom.h"
33 #include "../Utils/Utils.h"
34 #include "../Utils/AtomsProp.h"
35 #include "../Utils/Constants.h"
36 #include "../Utils/GabeditTextEdit.h"
37 
38 static GtkWidget *Wins=NULL;
39 static gboolean newFile = FALSE;
40 /************************************************************************************************************/
setColors()41 static void setColors()
42 {
43 	static gboolean first = TRUE;
44 
45 	if(!first) return;
46 	first = FALSE;
47 
48 	fireflyColorFore.keyWord.red = 65535;
49 	fireflyColorFore.keyWord.green = 0;
50 	fireflyColorFore.keyWord.blue = 0;
51 
52 	fireflyColorBack.keyWord.red = (gushort)(65535/1.2);
53 	fireflyColorBack.keyWord.green = (gushort)(65535/1.2);
54 	fireflyColorBack.keyWord.blue = (gushort)(65535/1.2);
55 
56 	fireflyColorFore.description.red = 0;
57 	fireflyColorFore.description.green = 65535;
58 	fireflyColorFore.description.blue = 65535;
59 
60 	fireflyColorBack.description.red = (gushort)(65535/2.0);
61 	fireflyColorBack.description.green = (gushort)(65535/2.0);
62 	fireflyColorBack.description.blue = (gushort)(65535/2.0);
63 
64 }
65 /************************************************************************************************************/
destroyWinsFireFly(GtkWidget * win)66 void destroyWinsFireFly(GtkWidget *win)
67 {
68 	destroy(Wins,NULL);
69 	Wins = NULL;
70 	initFireFlyMoleculeButtons();
71 	/*
72 	freeFireFlyFunctionals();
73 	freeFireFlyStdFunctionals();
74 	freeFireFlyMole();
75 	freeFireFlyGuessWaveFunction();
76 	freeFireFlyMolecule();
77 	freeFireFlyMpqc();
78 	freeFireFlyBasis();
79 	freeFireFlyOptimization();
80 	*/
81 }
82 /************************************************************************************************************/
toCancelWin(GtkWidget * win,gpointer data)83 static void toCancelWin(GtkWidget* win,gpointer data)
84 {
85 	Cancel_YesNo(win, data, destroy_children);
86 }
87 /************************************************************************************************************/
putTitleInTextEditor()88 static void putTitleInTextEditor()
89 {
90         gchar buffer[BSIZE];
91 
92 	sprintf(buffer,"%c ================================================================\n",'!');
93         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
94 
95 	sprintf(buffer,"%c Input file for FireFly\n",'!');
96         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
97 
98 	sprintf(buffer,"%c ================================================================\n",'!');
99         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer,-1);
100 }
101 /************************************************************************************************************/
putInfoInTextEditor(GtkWidget * button,gpointer data)102 static void putInfoInTextEditor(GtkWidget *button, gpointer data)
103 {
104 	setColors();
105 	if(newFile)
106 	{
107 		reset_name_files();
108 		ClearText(text);
109 	}
110 	else
111 	{
112         	gint nchar;
113         	nchar=gabedit_text_get_length(GABEDIT_TEXT(text));
114         	gabedit_text_set_point(GABEDIT_TEXT(text),nchar);
115 	}
116 	data_modify(TRUE);
117 
118 	putTitleInTextEditor();
119 	putFireFlyControlInfoInTextEditor();
120 	putFireFlyChargeAndSpinInfoInTextEditor();
121 
122 	if(!fireflySemiEmperical()) putFireFlyBasisInfoInTextEditor();
123 	putFireFlyGuessInfoInTextEditor();
124 	putFireFlySCFInfoInTextEditor();
125 	putFireFlyGeometryInfoInTextEditor();
126 	/*
127 	putFireFlyBasisInfoInTextEditor();
128 	putFireFlyGuessWaveFunctionInfoInTextEditor();
129 	putFireFlyMoleInfoInTextEditor();
130 	if(fireflyMpqc.optimize) putFireFlyOptimizationInfoInTextEditor();
131 	putFireFlyMpqcInfoInTextEditor();
132 	*/
133 
134 	iprogram = PROG_IS_FIREFLY;
135 	fileopen.command=g_strdup(NameCommandFireFly);
136 	gtk_notebook_set_current_page((GtkNotebook*)NoteBookText,0);
137 }
138 /*********************************************************************************************/
addHboxToTable(GtkWidget * table,gint i,gint j,gint ki,gint kj)139 static GtkWidget* addHboxToTable(GtkWidget* table, gint i, gint j, gint ki, gint kj)
140 {
141 	GtkWidget *hbox = gtk_hbox_new(TRUE, 5);
142 
143 	gtk_table_attach(GTK_TABLE(table),hbox,j,j+kj,i,i+ki,
144 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
145 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
146                   3,3);
147 
148 	return hbox;
149 }
150 /************************************************************************************************************/
fireflyInputFileWindow(gboolean newInputFile)151 static void fireflyInputFileWindow(gboolean newInputFile)
152 {
153 	GtkWidget *button;
154 	GtkWidget *hbox = NULL;
155 	GtkWidget *hboxSymmetryChargeMultiplicity = NULL;
156 
157 	GtkWidget *table = gtk_table_new(6,2,FALSE);
158 
159 	newFile = newInputFile;
160 
161 	initFireFlyMolecule();
162 	setFireFlyMolecule();
163 	/*
164 	initFireFlyMpqc();
165 	initFireFlyMole();
166 	initFireFlyFunctionals();
167 	initFireFlyStdFunctionals();
168 	initFireFlyGuessWaveFunction();
169 	initFireFlyBasis();
170 	initFireFlyOptimization();
171 	*/
172 
173 
174 	if(fireflyMolecule.numberOfAtoms <1)
175 	{
176 		Message(
177 			_(
178 			"You must initially define your geometry.\n\n"
179 			"From the principal Menu select : Geometry/Draw\n"
180 			"and draw (or read) your molecule."),
181 			_("Error"),TRUE);
182 		return;
183 	}
184 
185 	if(Wins) destroy_children(Wins);
186 
187 	Wins= gtk_dialog_new ();
188 	gtk_window_set_position(GTK_WINDOW(Wins),GTK_WIN_POS_NONE);
189 	gtk_window_set_transient_for(GTK_WINDOW(Wins),GTK_WINDOW(Fenetre));
190 	gtk_window_set_title(&GTK_DIALOG(Wins)->window,_("FireFly input"));
191     	gtk_window_set_modal (GTK_WINDOW (Wins), TRUE);
192 
193 	init_child(Wins, destroyWinsFireFly,_(" FireFly input "));
194 	g_signal_connect(G_OBJECT(Wins),"delete_event",(GCallback)destroy_children,NULL);
195 
196 	gtk_widget_realize(Wins);
197 
198 	button = create_button(Wins,_("Cancel"));
199 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
200 	g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK( toCancelWin),GTK_OBJECT(Wins));
201 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
202 	gtk_widget_show (button);
203 
204 	button = create_button(Wins,_("OK"));
205 
206 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->vbox), table, FALSE, TRUE, 5);
207 
208 	hbox =addHboxToTable(table, 0, 0, 1, 1);
209 	hboxSymmetryChargeMultiplicity = hbox;
210 	createFireFlySymmetryFrame(Wins, hbox);
211 
212 	hbox =addHboxToTable(table, 1, 0, 1, 2);
213 	initFireFlyBasisFrame();
214 	initFireFlyGuessFrame();
215 	initFireFlySCFFrame();
216 	createFireFlyControlFrame(Wins, hbox);
217 	createFireFlyBasisFrame(Wins, hbox);
218 	createFireFlyChargeMultiplicityFrame(hboxSymmetryChargeMultiplicity);
219 
220 	hbox =addHboxToTable(table, 2, 0, 1, 2);
221 	createFireFlyGuessFrame(Wins, hbox);
222 	createFireFlySCFFrame(Wins, hbox);
223 
224 
225 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
226 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
227 	gtk_widget_grab_default(button);
228 	gtk_widget_show (button);
229 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(putInfoInTextEditor),GTK_OBJECT(Wins));
230 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(destroy_children),GTK_OBJECT(Wins));
231 
232 
233 	gtk_widget_show_all(Wins);
234 	fireflyWin = Wins;
235 }
236 /************************************************************************************************************/
newFireFly()237 void newFireFly()
238 {
239 	fireflyInputFileWindow(TRUE);
240 }
241 /************************************************************************************************************/
insertFireFly()242 void insertFireFly()
243 {
244 	fireflyInputFileWindow(FALSE);
245 }
246