1 /* Gamess.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 "../Gamess/GamessTypes.h"
24 #include "../Gamess/GamessGlobal.h"
25 #include "../Gamess/GamessMolecule.h"
26 #include "../Gamess/GamessControl.h"
27 #include "../Gamess/GamessBasis.h"
28 #include "../Gamess/GamessGuess.h"
29 #include "../Gamess/GamessSCF.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 	gamessColorFore.keyWord.red = 65535;
49 	gamessColorFore.keyWord.green = 0;
50 	gamessColorFore.keyWord.blue = 0;
51 
52 	gamessColorBack.keyWord.red = (gushort)(65535/1.2);
53 	gamessColorBack.keyWord.green = (gushort)(65535/1.2);
54 	gamessColorBack.keyWord.blue = (gushort)(65535/1.2);
55 
56 	gamessColorFore.description.red = 0;
57 	gamessColorFore.description.green = 65535;
58 	gamessColorFore.description.blue = 65535;
59 
60 	gamessColorBack.description.red = (gushort)(65535/2.0);
61 	gamessColorBack.description.green = (gushort)(65535/2.0);
62 	gamessColorBack.description.blue = (gushort)(65535/2.0);
63 
64 }
65 /************************************************************************************************************/
destroyWinsGamess(GtkWidget * win)66 void destroyWinsGamess(GtkWidget *win)
67 {
68 	destroy(Wins,NULL);
69 	Wins = NULL;
70 	initGamessMoleculeButtons();
71 	/*
72 	freeGamessFunctionals();
73 	freeGamessStdFunctionals();
74 	freeGamessMole();
75 	freeGamessGuessWaveFunction();
76 	freeGamessMolecule();
77 	freeGamessMpqc();
78 	freeGamessBasis();
79 	freeGamessOptimization();
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 This file was generated by Gabedit\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 	putGamessControlInfoInTextEditor();
120 	putGamessChargeAndSpinInfoInTextEditor();
121 
122 	if(!gamessSemiEmperical()) putGamessBasisInfoInTextEditor();
123 	putGamessGuessInfoInTextEditor();
124 	putGamessSCFInfoInTextEditor();
125 	putGamessGeometryInfoInTextEditor();
126 
127 	iprogram = PROG_IS_GAMESS;
128 	fileopen.command=g_strdup(NameCommandGamess);
129 	gtk_notebook_set_current_page((GtkNotebook*)NoteBookText,0);
130 }
131 /*********************************************************************************************/
addHboxToTable(GtkWidget * table,gint i,gint j,gint ki,gint kj)132 static GtkWidget* addHboxToTable(GtkWidget* table, gint i, gint j, gint ki, gint kj)
133 {
134 	GtkWidget *hbox = gtk_hbox_new(TRUE, 5);
135 
136 	gtk_table_attach(GTK_TABLE(table),hbox,j,j+kj,i,i+ki,
137 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
138 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
139                   3,3);
140 
141 	return hbox;
142 }
143 /************************************************************************************************************/
gamessInputFileWindow(gboolean newInputFile)144 static void gamessInputFileWindow(gboolean newInputFile)
145 {
146 	GtkWidget *button;
147 	GtkWidget *hbox = NULL;
148 	GtkWidget *hboxSymmetryChargeMultiplicity = NULL;
149 
150 	GtkWidget *table = gtk_table_new(6,2,FALSE);
151 
152 	newFile = newInputFile;
153 
154 	initGamessMolecule();
155 	setGamessMolecule();
156 
157 	if(gamessMolecule.numberOfAtoms <1)
158 	{
159 		Message(
160 			_(
161 			"You must initially define your geometry.\n\n"
162 			"From the principal Menu select : Geometry/Draw\n"
163 			"and draw (or read) your molecule."),
164 			_("Error"),TRUE);
165 		return;
166 	}
167 
168 	if(Wins) destroy_children(Wins);
169 
170 	Wins= gtk_dialog_new ();
171 	gtk_window_set_position(GTK_WINDOW(Wins),GTK_WIN_POS_NONE);
172 	gtk_window_set_transient_for(GTK_WINDOW(Wins),GTK_WINDOW(Fenetre));
173 	gtk_window_set_title(&GTK_DIALOG(Wins)->window,_("Gamess input"));
174     	gtk_window_set_modal (GTK_WINDOW (Wins), TRUE);
175 
176 	init_child(Wins, destroyWinsGamess,_(" Gamess input "));
177 	g_signal_connect(G_OBJECT(Wins),"delete_event",(GCallback)destroy_children,NULL);
178 
179 	gtk_widget_realize(Wins);
180 
181 	button = create_button(Wins,_("Cancel"));
182 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
183 	g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK( toCancelWin),GTK_OBJECT(Wins));
184 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
185 	gtk_widget_show (button);
186 
187 	button = create_button(Wins,_("OK"));
188 
189 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->vbox), table, FALSE, TRUE, 5);
190 
191 	hbox =addHboxToTable(table, 0, 0, 1, 1);
192 	hboxSymmetryChargeMultiplicity = hbox;
193 	createGamessSymmetryFrame(Wins, hbox);
194 
195 	hbox =addHboxToTable(table, 1, 0, 1, 2);
196 	initGamessBasisFrame();
197 	initGamessGuessFrame();
198 	initGamessSCFFrame();
199 	createGamessControlFrame(Wins, hbox);
200 	createGamessBasisFrame(Wins, hbox);
201 	createGamessChargeMultiplicityFrame(hboxSymmetryChargeMultiplicity);
202 
203 	hbox =addHboxToTable(table, 2, 0, 1, 2);
204 	createGamessGuessFrame(Wins, hbox);
205 	createGamessSCFFrame(Wins, hbox);
206 
207 
208 	gtk_box_pack_start (GTK_BOX( GTK_DIALOG(Wins)->action_area), button, FALSE, TRUE, 5);
209 	GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
210 	gtk_widget_grab_default(button);
211 	gtk_widget_show (button);
212 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(putInfoInTextEditor),GTK_OBJECT(Wins));
213 	g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(destroy_children),GTK_OBJECT(Wins));
214 
215 
216 	gtk_widget_show_all(Wins);
217 	gamessWin = Wins;
218 }
219 /************************************************************************************************************/
newGamess()220 void newGamess()
221 {
222 	gamessInputFileWindow(TRUE);
223 }
224 /************************************************************************************************************/
insertGamess()225 void insertGamess()
226 {
227 	gamessInputFileWindow(FALSE);
228 }
229