1 /* DeMonBasis.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 
23 #include "../../Config.h"
24 #include "../Common/Global.h"
25 #include "../DeMon/DeMonTypes.h"
26 #include "../DeMon/DeMonGlobal.h"
27 #include "../Geometry/GeomGlobal.h"
28 #include "../Geometry/GeomConversion.h"
29 #include "../Geometry/GeomXYZ.h"
30 #include "../Geometry/Fragments.h"
31 #include "../Geometry/DrawGeom.h"
32 #include "../Utils/Utils.h"
33 #include "../Utils/UtilsInterface.h"
34 #include "../Utils/Constants.h"
35 #include "../Geometry/InterfaceGeom.h"
36 #include "../Common/Windows.h"
37 #include "../Utils/Constants.h"
38 #include "../Utils/AtomsProp.h"
39 #include "../Utils/GabeditTextEdit.h"
40 #include "../Symmetry/MoleculeSymmetry.h"
41 #include "../Symmetry/MoleculeSymmetryInterface.h"
42 
43 static gchar selectedTypeBasis[BSIZE]="";
44 static gchar** listBasisReal = NULL;
45 static gchar** listBasisView = NULL;
46 static gint numberOfBasis = 0;
47 /*************************************************************************************************************/
48 static gchar* listTypeBasisView[] =
49 {
50 	"Pople Style basis sets",
51 	"Pople with one diffuse function",
52 	"Dunning basis sets",
53 	"Miscellenous and Specialized Basis Sets",
54 };
55 static gchar* listTypeBasisReal[] =
56 {
57 	"Pople",
58 	"PopleDiffuseAllAtoms",
59 	"Dunning",
60 	"Miscellenous",
61 };
62 static guint numberOfTypeBasis = G_N_ELEMENTS (listTypeBasisView);
63 /*************************************************************************************************************/
64 static gchar* listPopleBasisView[] =
65 {
66 	"DZVP 	   H-Xe LDA double zeta polarizationa basis set",
67 	"DZVP-GGA  H-Xe GGA double zeta polarizationa basis set",
68 	"DZVP2 	   Be-F, Al-Ar, Sc-Zn   Modified DZVP basis set.",
69 	"TZVP 	   H, Li, C-F, Si-Cl  LDA triple zeta polarization basis set.",
70 	"TZVP-GGA  Sc-Cu              GGA triple zeta polarization basis set. ",
71 	"TZVP-FIP1 H, C-F, Na, S, Cl, Cu TZVP with field-induced polarization",
72 	"TZVP-FIP2 H, C-F, Na, S, Cl, Cu for  alpha, beta (FIP1) and gamma (FIP2) calculations",
73 	"DZV      H,C 	LDA double zeta basis set.",
74 	"DZV-GGA  H,C 	GGA double zeta basis set.",
75 };
76 static gchar* listPopleBasisReal[] =
77 {
78 	"(DZVP)",
79 	"(DZVP-GGA)",
80 	"(DZVP2)",
81 	"(TZVP)",
82 	"(TZVP-GGA)",
83 	"(TZVP-FIP1)",
84 	"(TZVP-FIP2)",
85 	"(DZV)",
86 	"(DZV-GGA)",
87 };
88 static guint numberOfPopleBasis = G_N_ELEMENTS (listPopleBasisView);
89 /*************************************************************************************************************/
90 /*************************************************************************************************************/
91 static gchar* listDunningBasisView[] =
92 {
93 	"cc-pVDZ Dunning correlation concisistent polarized double zeta",
94 	"Aug-cc-pVDZ Same but including diffuse functions",
95 	"cc-pVTZ Dunning correlation concisistent polarized triple zeta",
96 	"Aug-cc-pVTZ Same but including diffuse functions(g-functions deleted!)",
97 	"cc-pVQZ Dunning correlation concisistent polarized quadruple zeta",
98 	"Aug-cc-pVQZ with diffuse functions",
99 	"cc-pV5Z Dunning correlation concisistent polarized quintuple zeta",
100 	"Aug-cc-pV5Z with diffuse functions",
101 	"cc-pV6Z Dunning correlation concisistent polarized sextuple zeta",
102 	"Aug-cc-pV6Z ... with diffuse functions",
103 };
104 static gchar* listDunningBasisReal[] =
105 {
106 	"(cc-pVDZ)",
107 	"(Aug-cc-pVDZ)",
108 	"(cc-pVTZ)",
109 	"(Aug-cc-pVTZ)",
110 	"(cc-pVQZ)",
111 	"(Aug-cc-pVQZ)",
112 	"(cc-pV5Z)",
113 	"(Aug-cc-pV5Z)",
114 	"(cc-pV6Z)",
115 	"(Aug-cc-pV6Z)",
116 };
117 static guint numberOfDunningBasis = G_N_ELEMENTS (listDunningBasisView);
118 /*************************************************************************************************************/
119 static gchar* listMiscellenousBasisView[] =
120 {
121 	"EPR-III 	H-F 	EPR basis set",
122 	"IGLO-II 	H, Li, B-F, Si 	NMR basis set",
123 	"IGLO-III 	H, B-F, Si, Cr, Fe 	NMR basis set",
124 	"STO-3G 	H-Ar 	STO-3G basis set for testing only",
125 	"SAD 	H, C-F 	Sadlej FIP basis set",
126 	"LIC 	H-Ne 	Lie-Clementi basis set",
127 	"WACHTERS 	Sc-Cu 	Wachters basis set without f functions",
128 	"DZ-ANO 	H-Zn 	Double zeta ANO basis set from Roos",
129 	"ECP|SD 	Valence basis for SD ECPs",
130 	"RECP|SD 	Valence basis for SD RECPs",
131 	"QECP|SD 	Valence basis for SD QECPs",
132 	"ECP|LANL2DZ 	Valence basis for LANL ECPs",
133 	"QECP|LANL2DZ 	Valence basis for LANL QECPs",
134 	"ECP|HW 	K-Cu 	Hay-Wadt basis for LANL ECPs",
135 	"QECP|HW 	Rb-Ag, Cs-La, Hf-Au 	Hay-Wadt basis for LANL QECPs",
136 	"MCP|LK 	Valence basis for LK MCPs",
137 	"RMCP|LK 	Valence basis for LK RMCPs",
138 	"XAS-I 	Li-F 	XAS augmentation basis for first row",
139 	"XAS-II 	Na-Cl 	XAS augmentation basis for second row"
140 };
141 static gchar* listMiscellenousBasisReal[] =
142 {
143 	"(EPR-III)",
144 	"(IGLO-II)",
145 	"(IGLO-III)",
146 	"(STO-3G)",
147 	"(SAD)",
148 	"(LIC)",
149 	"(WACHTERS)",
150 	"(DZ-ANO)",
151 	"(ECP|SD)",
152 	"(RECP|SD)",
153 	"(QECP|SD)",
154 	"(ECP|LANL2DZ)",
155 	"(QECP|LANL2DZ)",
156 	"(ECP|HW)",
157 	"(QECP|HW)",
158 	"(MCP|LK)",
159 	"(RMCP|LK)",
160 	"(XAS-I)",
161 	"(XAS-II)",
162 };
163 static guint numberOfMiscellenousBasis = G_N_ELEMENTS (listMiscellenousBasisView);
164 /*************************************************************************************************************/
165 static gchar* listAuxBasisView[] =
166 {
167 	"GEN-A2*",
168 	"A2 auxiliary function",
169         "GEN-A2",
170 	"GEN-A2**",
171 	"GEN-A3",
172 	"GEN-A3*",
173 	"GEN-A3**",
174 	"GEN-A4",
175 	"GEN-A4*",
176 	"GEN-A4**"
177 };
178 static gchar* listAuxBasisReal[] =
179 {
180 	"(GEN-A2*)",
181 	"(A2)",
182 	"(GEN-A2)",
183 	"(GEN-A2**)",
184 	"(GEN-A3)",
185 	"(GEN-A3*)",
186 	"(GEN-A3**)",
187 	"(GEN-A4)",
188 	"(GEN-A4*)",
189 	"(GEN-A4**)",
190 };
191 static guint numberOfAuxBasis = G_N_ELEMENTS (listAuxBasisView);
192 /*************************************************************************************************************/
setDeMonBasis(GtkWidget * comboBasis)193 static void setDeMonBasis(GtkWidget* comboBasis)
194 {
195 	gint i;
196 
197 	if(strcmp(selectedTypeBasis, "Pople")==0)
198 	{
199 		listBasisView = listPopleBasisView;
200 		listBasisReal = listPopleBasisReal;
201 		numberOfBasis = numberOfPopleBasis;
202 	}
203 	else if(strcmp(selectedTypeBasis, "Dunning")==0)
204 	{
205 		listBasisView = listDunningBasisView;
206 		listBasisReal = listDunningBasisReal;
207 		numberOfBasis = numberOfDunningBasis;
208 	}
209 	else
210 	{
211 		listBasisView = listMiscellenousBasisView;
212 		listBasisReal = listMiscellenousBasisReal;
213 		numberOfBasis = numberOfMiscellenousBasis;
214 	}
215 
216 	if (comboBasis && GTK_IS_COMBO_BOX(comboBasis))
217 	{
218 		GtkTreeModel * model = NULL;
219 		model = gtk_combo_box_get_model(GTK_COMBO_BOX(comboBasis));
220 		gtk_list_store_clear(GTK_LIST_STORE(model));
221 
222 		for(i=0;i<numberOfBasis;i++)
223   			gtk_combo_box_append_text (GTK_COMBO_BOX (comboBasis), listBasisView[i]);
224   		gtk_combo_box_set_active(GTK_COMBO_BOX (comboBasis), 0);
225 	}
226 
227 }
228 /************************************************************************************************************/
traitementTypeBasis(GtkComboBox * combobox,gpointer d)229 static void traitementTypeBasis (GtkComboBox *combobox, gpointer d)
230 {
231 	GtkTreeIter iter;
232 	gchar* data = NULL;
233 	gchar* res = NULL;
234 	gint i;
235 	GtkWidget* comboBasis = NULL;
236 	/* gchar* s;*/
237 	if (gtk_combo_box_get_active_iter (combobox, &iter))
238 	{
239 		GtkTreeModel* model = gtk_combo_box_get_model(combobox);
240 		gtk_tree_model_get (model, &iter, 0, &data, -1);
241 	}
242 	else return;
243 	for(i=0;i<numberOfTypeBasis;i++)
244 	{
245 		if(strcmp((gchar*)data,listTypeBasisView[i])==0) res = listTypeBasisReal[i];
246 	}
247 	if(res) sprintf(selectedTypeBasis,"%s",res);
248 	comboBasis = g_object_get_data(G_OBJECT (combobox), "ComboBasis");
249 
250 	if(comboBasis) setDeMonBasis(comboBasis);
251 }
252 /********************************************************************************************************/
create_list_type_basis(GtkWidget * comboBasis)253 static GtkWidget *create_list_type_basis(GtkWidget *comboBasis)
254 {
255         GtkTreeIter iter;
256         GtkTreeStore *store;
257 	GtkTreeModel *model;
258 	GtkWidget *combobox;
259 	GtkCellRenderer *renderer;
260 	gint i;
261         GtkTreeIter iter0;
262 
263 	store = gtk_tree_store_new (1,G_TYPE_STRING);
264 
265 	for(i=0;i<numberOfTypeBasis;i++)
266 	{
267         	gtk_tree_store_append (store, &iter, NULL);
268 		if(i==0) iter0 = iter;
269         	gtk_tree_store_set (store, &iter, 0, listTypeBasisView[i], -1);
270 	}
271 
272         model = GTK_TREE_MODEL (store);
273 	combobox = gtk_combo_box_new_with_model (model);
274 	g_object_set_data(G_OBJECT (combobox), "ComboBasis",comboBasis);
275 	/*
276 	gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (combobox), TRUE);
277 	*/
278 	g_object_unref (model);
279 	g_signal_connect (G_OBJECT(combobox), "changed", G_CALLBACK(traitementTypeBasis), NULL);
280 	renderer = gtk_cell_renderer_text_new ();
281 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
282 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
283 
284 	gtk_combo_box_set_active_iter(GTK_COMBO_BOX (combobox), &iter0);
285 
286 	return combobox;
287 }
288 /************************************************************************************************************/
initDeMonBasis()289 void initDeMonBasis()
290 {
291 	demonBasis.name = g_strdup("3-21G");
292 	demonBasis.molecule = g_strdup("$:molecule");
293 	demonBasis.numberOfBasisTypes=0;
294 	demonBasis.basisNames = NULL;
295 }
296 /************************************************************************************************************/
freeDeMonBasis()297 void freeDeMonBasis()
298 {
299 	if(demonBasis.name ) g_free(demonBasis.name);
300 	demonBasis.name = NULL;
301 	if(demonBasis.molecule ) g_free(demonBasis.molecule);
302 	demonBasis.molecule = NULL;
303 	if(demonBasis.basisNames)
304 	{
305 		gint i;
306 		for(i=0;i<demonBasis.numberOfBasisTypes;i++)
307 			if(demonBasis.basisNames[i])g_free(demonBasis.basisNames[i]);
308 
309 		if(demonBasis.basisNames)g_free(demonBasis.basisNames);
310 	}
311 	demonBasis.numberOfBasisTypes=0;
312 	demonBasis.basisNames = NULL;
313 }
314 /************************************************************************************************************/
changedEntryBasis(GtkWidget * entry,gpointer data)315 static void changedEntryBasis(GtkWidget *entry, gpointer data)
316 {
317 	G_CONST_RETURN gchar* entryText = NULL;
318 	gchar* res = NULL;
319 	gint i;
320 
321 	if(!GTK_IS_WIDGET(entry)) return;
322 
323 	entryText = gtk_entry_get_text(GTK_ENTRY(entry));
324 	if(strlen(entryText)<1)return;
325 
326 	if(demonBasis.name) g_free(demonBasis.name);
327 	for(i=0;i<numberOfBasis;i++)
328 	{
329 		if(strcmp((gchar*)entryText,listBasisView[i])==0) res = listBasisReal[i];
330 	}
331 	if(res) demonBasis.name=g_strdup(res);
332 }
333 /************************************************************************************************************/
changedEntryAuxBasis(GtkWidget * entry,gpointer data)334 static void changedEntryAuxBasis(GtkWidget *entry, gpointer data)
335 {
336 	G_CONST_RETURN gchar* entryText = NULL;
337 	gint i;
338 	gchar* res = NULL;
339 
340 	if(!GTK_IS_WIDGET(entry)) return;
341 
342 	entryText = gtk_entry_get_text(GTK_ENTRY(entry));
343 	if(strlen(entryText)<1)return;
344 
345 	if(demonMolecule.auxBasisName) g_free(demonMolecule.auxBasisName);
346 	for(i=0;i<numberOfAuxBasis;i++)
347 	{
348 		if(strcmp((gchar*)entryText,listAuxBasisView[i])==0) res = listAuxBasisReal[i];
349 	}
350 	if(res) demonMolecule.auxBasisName=g_strdup(res);
351 }
352 /***********************************************************************************************/
addComboListToATable(GtkWidget * table,gchar ** list,gint nlist,gint i,gint j,gint k)353 static GtkWidget* addComboListToATable(GtkWidget* table,
354 		gchar** list, gint nlist, gint i, gint j, gint k)
355 {
356 	GtkWidget *entry = NULL;
357 	GtkWidget *combo = NULL;
358 
359 	combo = create_combo_box_entry(list, nlist, TRUE, -1, -1);
360 
361 	gtk_table_attach(GTK_TABLE(table),combo,j,j+k,i,i+1,
362 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
363 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
364                   3,3);
365 	entry = GTK_BIN (combo)->child;
366 	g_object_set_data(G_OBJECT (entry), "Combo",combo);
367 
368 	return entry;
369 }
370 /***********************************************************************************************/
addDeMonTypeBasisToTable(GtkWidget * table,gint i,GtkWidget * comboBasis)371 void addDeMonTypeBasisToTable(GtkWidget *table, gint i, GtkWidget* comboBasis)
372 {
373 	GtkWidget* combo = NULL;
374 
375 	add_label_table(table,_("Type"),(gushort)i,0);
376 	add_label_table(table,":",(gushort)i,1);
377 	combo  = create_list_type_basis(comboBasis);
378 	gtk_table_attach(GTK_TABLE(table),combo,2,2+1,i,i+1,
379 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
380 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
381                   3,3);
382 }
383 /***********************************************************************************************/
addDeMonBasisToTable(GtkWidget * table,gint i)384 GtkWidget* addDeMonBasisToTable(GtkWidget *table, gint i)
385 {
386 	GtkWidget* entryBasis = NULL;
387 	GtkWidget* comboBasis = NULL;
388 	gint nlistBasis = 1;
389 	gchar* listBasis[] = {" "};
390 
391 
392 	add_label_table(table,_("Basis"),(gushort)i,0);
393 	add_label_table(table,":",(gushort)i,1);
394 	entryBasis = addComboListToATable(table, listBasis, nlistBasis, i, 2, 1);
395 	comboBasis  = g_object_get_data(G_OBJECT (entryBasis), "Combo");
396 	gtk_widget_set_sensitive(entryBasis, TRUE);
397 	gtk_editable_set_editable(GTK_EDITABLE(entryBasis),FALSE);
398 
399 	g_signal_connect(G_OBJECT(entryBasis),"changed", G_CALLBACK(changedEntryBasis),NULL);
400 	return comboBasis;
401 }
402 /***********************************************************************************************/
addDeMonAuxBasisToTable(GtkWidget * table,gint i,GtkWidget * comboMethod,GtkWidget * comboExcited)403 void addDeMonAuxBasisToTable(GtkWidget *table, gint i, GtkWidget* comboMethod, GtkWidget* comboExcited)
404 {
405 	GtkWidget* entryAuxBasis = NULL;
406 	GtkWidget* comboAuxBasis = NULL;
407 	GtkWidget* label = NULL;
408 
409 	label = add_label_table(table,_("Auxiliary basis"),(gushort)i,0);
410 	if(comboMethod) g_object_set_data(G_OBJECT (comboMethod), "LabelAuxBasis1", label);
411 	if(comboExcited) g_object_set_data(G_OBJECT (comboExcited), "LabelAuxBasis1", label);
412 	label = add_label_table(table,":",(gushort)i,1);
413 	if(comboMethod) g_object_set_data(G_OBJECT (comboMethod), "LabelAuxBasis2", label);
414 	if(comboExcited) g_object_set_data(G_OBJECT (comboExcited), "LabelAuxBasis2", label);
415 	entryAuxBasis = addComboListToATable(table, listAuxBasisView, numberOfAuxBasis, i, 2, 1);
416 	comboAuxBasis  = g_object_get_data(G_OBJECT (entryAuxBasis), "Combo");
417 	gtk_widget_set_sensitive(entryAuxBasis, TRUE);
418 	gtk_editable_set_editable(GTK_EDITABLE(entryAuxBasis),FALSE);
419 	if(comboMethod) g_object_set_data(G_OBJECT (comboMethod), "ComboAuxBasis", comboAuxBasis);
420 	if(comboExcited) g_object_set_data(G_OBJECT (comboExcited), "ComboAuxBasis", comboAuxBasis);
421 
422 	g_signal_connect(G_OBJECT(entryAuxBasis),"changed", G_CALLBACK(changedEntryAuxBasis),NULL);
423 	demonMolecule.auxBasisName=g_strdup(listAuxBasisReal[0]);
424 }
425 /***********************************************************************************************/
putDeMonBasisInTextEditor()426 static void putDeMonBasisInTextEditor()
427 {
428         gchar buffer[BSIZE];
429 
430 	gabedit_text_insert (GABEDIT_TEXT(text), NULL, &demonColorFore.keyWord, &demonColorBack.keyWord, "Basis ",-1);
431 	sprintf(buffer,"%s\n",demonBasis.name);
432         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer, -1);
433 
434 }
435 /***********************************************************************************************/
putDeMonAuxBasisInTextEditor()436 void putDeMonAuxBasisInTextEditor()
437 {
438         gchar buffer[BSIZE];
439 
440 	if(!demonMolecule.auxBasisName) return;
441         if(strcmp(demonMolecule.auxBasisName, "None") != 0)
442         {
443         gabedit_text_insert (GABEDIT_TEXT(text), NULL, &demonColorFore.keyWord, &demonColorBack.keyWord, "Auxis ",-1);
444         sprintf(buffer,"%s\n",demonMolecule.auxBasisName);
445         gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer, -1);
446         }
447 }
448 /***********************************************************************************************/
putDeMonBasisInfoInTextEditor()449 void putDeMonBasisInfoInTextEditor()
450 {
451 	putDeMonBasisInTextEditor();
452 }
453