1 /* PsicodeBasis.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 "../Psicode/PsicodeTypes.h"
26 #include "../Psicode/PsicodeGlobal.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 on non-hydrogen atoms",
52 	"Pople with one diffuse function on all atoms",
53 	"Dunning basis sets",
54 	"Jensen Basis Sets",
55 	"Miscellenous and Specialized Basis Sets",
56 };
57 static gchar* listTypeBasisReal[] =
58 {
59 	"Pople",
60 	"PopleDiffuseNonHydrogen",
61 	"PopleDiffuseAllAtoms",
62 	"Dunning",
63 	"Jensen",
64 	"Miscellenous",
65 };
66 static guint numberOfTypeBasis = G_N_ELEMENTS (listTypeBasisView);
67 /*************************************************************************************************************/
68 static gchar* listPopleBasisView[] =
69 {
70 	"6-31G Pople 6-31G and its modifications",
71 	"6-311G Pople 6-311G and its modifications",
72 
73 	"3-21G*  3-21G plus one polarisation function all non-hydrogens atoms",
74 	"6-31G* 6-31G plus one polarisation function all non-hydrogens atoms",
75 	"6-311G* 6-311G plus one polarisation function all non-hydrogens atoms",
76 
77 	"3-21G**  3-21G plus one polarisation function all atoms",
78 	"6-31G** 6-31G plus one polarisation function all atoms",
79 	"6-311G** 6-311G plus one polarisation function all atoms",
80 
81 	"3-21G(2d)  3-21G plus two polarisation functions all non-hydrogens atoms",
82 	"6-31G(2d) 6-31G plus two polarisation functions all non-hydrogens atoms",
83 	"6-311G(2d) 6-311G plus two polarisation functions all non-hydrogens atoms",
84 
85 	"3-21G(2d,2p)  3-21G plus two polarisation functions all atoms",
86 	"6-31G(2d,2p) 6-31G plus two polarisation functions all atoms",
87 	"6-311G(2d,2p) 6-311G plus two polarisation functions all atoms",
88 
89 	"3-21G(2df)  3-21G plus three polarisation functions all non-hydrogens atoms",
90 	"6-31G(2df) 6-31G plus three polarisation functions all non-hydrogens atoms",
91 	"6-311G(2df) 6-311G plus three polarisation functions all non-hydrogens atoms",
92 
93 	"3-21G(2df,2pd)  3-21G plus three polarisation functions all atoms",
94 	"6-31G(2df,2pd) 6-31G plus three polarisation functions all atoms",
95 	"6-311G(2df,2pd) 6-311G plus three polarisation functions all atoms",
96 
97 	"3-21G(3df)  3-21G plus four polarisation functions all non-hydrogens atoms",
98 	"6-31G(3df) 6-31G plus four polarisation functions all non-hydrogens atoms",
99 	"6-311G(3df) 6-311G plus four polarisation functions all non-hydrogens atoms",
100 
101 	"3-21G(3df,3pd)  3-21G plus four polarisation functions all atoms",
102 	"6-31G(3df,3pd) 6-31G plus four polarisation functions all atoms",
103 	"6-311G(3df,3pd) 6-311G plus four polarisation functions all atoms",
104 };
105 static gchar* listPopleBasisReal[] =
106 {
107 	"6-31G",
108 	"6-311G",
109 
110 	"3-21G*",
111 	"6-31G*",
112 	"6-311G*",
113 
114 	"3-21G**",
115 	"6-31G**",
116 	"6-311G**",
117 
118 	"3-21G(2d)",
119 	"6-31G(2d)",
120 	"6-311G(2d)",
121 
122 	"3-21G(2d,2p)",
123 	"6-31G(2d,2p)",
124 	"6-311G(2d,2p)",
125 
126 	"3-21G(2df)",
127 	"6-31G(2df)",
128 	"6-311G(2df)",
129 
130 	"3-21G(2df,2pd)",
131 	"6-31G(2df,2pd)",
132 	"6-311G(2df,2pd)",
133 
134 	"3-21G(3df)",
135 	"6-31G(3df)",
136 	"6-311G(3df)",
137 
138 	"3-21G(3df,3pd)",
139 	"6-31G(3df,3pd)",
140 	"6-311G(3df,3pd)",
141 };
142 static guint numberOfPopleBasis = G_N_ELEMENTS (listPopleBasisView);
143 /*************************************************************************************************************/
144 static gchar* listPopleDiffuseNonHydrogenBasisView[] =
145 {
146 	"3-21+G  3-21G plus diffuse functions on all non-hydrogens atoms",
147 	"6-31+G 6-31G plus diffuse functions on all non-hydrogens atoms",
148 	"6-311+G 6-311G plus diffuse functions on all non-hydrogens atoms",
149 
150 	"3-21+G*  3-21G + diff. non-hydrogens + 1 pol. non-hydrogens",
151 	"6-31+G* 6-31G + diff. non-hydrogens + 1 pol. non-hydrogens",
152 	"6-311+G* 6-311G + diff. non-hydrogens + 1 pol. non-hydrogens",
153 
154 	"3-21+G**  3-21G + diff. non-hydrogens + 1 pol. ",
155 	"6-31+G** 6-31G + diff. non-hydrogens + 1 pol. ",
156 	"6-311+G** 6-311G + diff. non-hydrogens + 1 pol. ",
157 
158 	"3-21+G(2d)  3-21G + diff. non-hydrogens + 2 pol. non-hydrogens",
159 	"6-31+G(2d) 6-31G + diff. non-hydrogens + 2 pol. non-hydrogens",
160 	"6-311+G(2d) 6-311G + diff. non-hydrogens + 2 pol. non-hydrogens",
161 
162 	"3-21+G(2d,2p)  3-21G + diff. non-hydrogens + 2 pol.",
163 	"6-31+G(2d,2p) 6-31G + diff. non-hydrogens + 2 pol.",
164 	"6-311+G(2d,2p) 6-311G + diff. non-hydrogens + 2 pol.",
165 
166 	"3-21+G(2df)  3-21G + diff. non-hydrogens + 3 pol. non-hydrogens",
167 	"6-31+G(2df) 6-31G + diff. non-hydrogens + 3 pol. non-hydrogens",
168 	"6-311+G(2df) 6-311G + diff. non-hydrogens + 3 pol. non-hydrogens",
169 
170 	"3-21+G(2df,2pd)  3-21G + diff. non-hydrogens + 3 pol.",
171 	"6-31+G(2df,2pd) 6-31G + diff. non-hydrogens + 3 pol.",
172 	"6-311+G(2df,2pd) 6-311G + diff. non-hydrogens + 3 pol.",
173 
174 	"3-21+G(3df)  3-21G + diff. non-hydrogens + 4 pol. non-hydrogens",
175 	"6-31+G(3df) 6-31G + diff. non-hydrogens + 4 pol. non-hydrogens",
176 	"6-311+G(3df) 6-311G + diff. non-hydrogens + 4 pol. non-hydrogens",
177 
178 	"3-21+G(3df,3pd)  3-21G + diff. non-hydrogens + 4 pol.",
179 	"6-31+G(3df,3pd) 6-31G + diff. non-hydrogens + 4 pol.",
180 	"6-311+G(3df,3pd) 6-311G + diff. non-hydrogens + 4 pol.",
181 };
182 static gchar* listPopleDiffuseNonHydrogenBasisReal[] =
183 {
184 	"3-21+G",
185 	"6-31+G",
186 	"6-311+G",
187 
188 	"3-21+G*",
189 	"6-31+G*",
190 	"6-311+G*",
191 
192 	"3-21+G**",
193 	"6-31+G**",
194 	"6-311+G**",
195 
196 	"3-21+G(2d)",
197 	"6-31+G(2d)",
198 	"6-311+G(2d)",
199 
200 	"3-21+G(2d,2p)",
201 	"6-31+G(2d,2p)",
202 	"6-311+G(2d,2p)",
203 
204 	"3-21+G(2df)",
205 	"6-31+G(2df)",
206 	"6-311+G(2df)",
207 
208 	"3-21+G(2df,2pd)",
209 	"6-31+G(2df,2pd)",
210 	"6-311+G(2df,2pd)",
211 
212 	"3-21+G(3df)",
213 	"6-31+G(3df)",
214 	"6-311+G(3df)",
215 
216 	"3-21+G(3df,3pd)",
217 	"6-31+G(3df,3pd)",
218 	"6-311+G(3df,3pd)",
219 };
220 static guint numberOfPopleDiffuseNonHydrogenBasis = G_N_ELEMENTS (listPopleDiffuseNonHydrogenBasisView);
221 /*************************************************************************************************************/
222 static gchar* listPopleDiffuseAllAtomsBasisView[] =
223 {
224 	"3-21++G  3-21G plus diffuse functions on all atoms",
225 	"6-31++G 6-31G plus diffuse functions on all atoms",
226 	"6-311++G 6-311G plus diffuse functions on all atoms",
227 
228 	"3-21++G*  3-21G + diff. + 1 pol. non-hydrogens",
229 	"6-31++G* 6-31G + diff. + 1 pol. non-hydrogens",
230 	"6-311++G* 6-311G + diff. + 1 pol. non-hydrogens",
231 
232 	"3-21++G**  3-21G + diff. + 1 pol. ",
233 	"6-31++G** 6-31G + diff. + 1 pol. ",
234 	"6-311++G** 6-311G + diff. + 1 pol. ",
235 
236 	"3-21++G(2d)  3-21G + diff. + 2 pol. non-hydrogens",
237 	"6-31++G(2d) 6-31G + diff. + 2 pol. non-hydrogens",
238 	"6-311++G(2d) 6-311G + diff. + 2 pol. non-hydrogens",
239 
240 	"3-21++G(2d,2p)  3-21G + diff. + 2 pol.",
241 	"6-31++G(2d,2p) 6-31G + diff. + 2 pol.",
242 	"6-311++G(2d,2p) 6-311G + diff. + 2 pol.",
243 
244 	"3-21++G(2df)  3-21G + diff. + 3 pol. non-hydrogens",
245 	"6-31++G(2df) 6-31G + diff. + 3 pol. non-hydrogens",
246 	"6-311++G(2df) 6-311G + diff. + 3 pol. non-hydrogens",
247 
248 	"3-21++G(2df,2pd)  3-21G + diff. + 3 pol.",
249 	"6-31++G(2df,2pd) 6-31G + diff. + 3 pol.",
250 	"6-311++G(2df,2pd) 6-311G + diff. + 3 pol.",
251 
252 	"3-21++G(3df)  3-21G + diff. + 4 pol. non-hydrogens",
253 	"6-31++G(3df) 6-31G + diff. + 4 pol. non-hydrogens",
254 	"6-311++G(3df) 6-311G + diff. + 4 pol. non-hydrogens",
255 
256 	"3-21++G(3df,3pd)  3-21G + diff. + 4 pol.",
257 	"6-31++G(3df,3pd) 6-31G + diff. + 4 pol.",
258 	"6-311++G(3df,3pd) 6-311G + diff. + 4 pol.",
259 
260 };
261 static gchar* listPopleDiffuseAllAtomsBasisReal[] =
262 {
263 	"3-21++G",
264 	"6-31++G",
265 	"6-311++G",
266 
267 	"3-21++G*",
268 	"6-31++G*",
269 	"6-311++G*",
270 
271 	"3-21++G**",
272 	"6-31++G**",
273 	"6-311++G**",
274 
275 	"3-21++G(2d)",
276 	"6-31++G(2d)",
277 	"6-311++G(2d)",
278 
279 	"3-21++G(2d,2p)",
280 	"6-31++G(2d,2p)",
281 	"6-311++G(2d,2p)",
282 
283 	"3-21++G(2df)",
284 	"6-31++G(2df)",
285 	"6-311++G(2df)",
286 
287 	"3-21++G(2df,2pd)",
288 	"6-31++G(2df,2pd)",
289 	"6-311++G(2df,2pd)",
290 
291 	"3-21++G(3df)",
292 	"6-31++G(3df)",
293 	"6-311++G(3df)",
294 
295 	"3-21++G(3df,3pd)",
296 	"6-31++G(3df,3pd)",
297 	"6-311++G(3df,3pd)",
298 };
299 static guint numberOfPopleDiffuseAllAtomsBasis = G_N_ELEMENTS (listPopleDiffuseAllAtomsBasisView);
300 /*************************************************************************************************************/
301 static gchar* listDunningBasisView[] =
302 {
303 	"cc-pVDZ Dunning correlation concisistent polarized double zeta",
304 	"Aug-cc-pVDZ Same but including diffuse functions",
305 	"cc-pVTZ Dunning correlation concisistent polarized triple zeta",
306 	"Aug-cc-pVTZ Same but including diffuse functions(g-functions deleted!)",
307 	"cc-pVQZ Dunning correlation concisistent polarized quadruple zeta",
308 	"Aug-cc-pVQZ with diffuse functions",
309 	"cc-pV5Z Dunning correlation concisistent polarized quintuple zeta",
310 	"Aug-cc-pV5Z with diffuse functions",
311 	"cc-pV6Z Dunning correlation concisistent polarized sextuple zeta",
312 	"Aug-cc-pV6Z ... with diffuse functions",
313 };
314 static gchar* listDunningBasisReal[] =
315 {
316 	"cc-pVDZ",
317 	"Aug-cc-pVDZ",
318 	"cc-pVTZ",
319 	"Aug-cc-pVTZ",
320 	"cc-pVQZ",
321 	"Aug-cc-pVQZ",
322 	"cc-pV5Z",
323 	"Aug-cc-pV5Z",
324 	"cc-pV6Z",
325 	"Aug-cc-pV6Z",
326 };
327 static guint numberOfDunningBasis = G_N_ELEMENTS (listDunningBasisView);
328 /*************************************************************************************************************/
329 static gchar* listJensenBasisView[] =
330 {
331 	"PC-1 Polarization consistent basis sets (H-Ar) optimized for DFT",
332 	"PC-2 double zeta polarization consistent basis sets (H-Ar) optimized for DFT",
333 	"PC-3 triple zeta polarization consistent basis sets (H-Ar) optimized for DFT",
334 	"PC-4 quadruple zeta polarization consistent basis sets (H-Ar) optimized for DFT",
335 	"Aug-PC-1 PC-1 with augmentations by diffuse functions",
336 	"Aug-PC-2 PC-2 with augmentations by diffuse functions",
337 	"Aug-PC-3 PC-3 with augmentations by diffuse functions",
338 	"Aug-PC-4 PC-4 with augmentations by diffuse functions",
339 };
340 static gchar* listJensenBasisReal[] =
341 {
342 	"PC-1",
343 	"PC-2",
344 	"PC-3",
345 	"PC-4",
346 	"Aug-PC-1",
347 	"Aug-PC-2",
348 	"Aug-PC-3",
349 	"Aug-PC-4",
350 };
351 static guint numberOfJensenBasis = G_N_ELEMENTS (listJensenBasisView);
352 /*************************************************************************************************************/
353 static gchar* listMiscellenousBasisView[] =
354 {
355 	"IGLO-II Kutzelniggs basis set for NMR and EPR calculations",
356 	"IGLO-III Kutzelniggs basis set for NMR and EPR calculations (accurate)",
357 
358 };
359 static gchar* listMiscellenousBasisReal[] =
360 {
361 	"IGLO-II",
362 	"IGLO-III",
363 };
364 static guint numberOfMiscellenousBasis = G_N_ELEMENTS (listMiscellenousBasisView);
365 /*************************************************************************************************************/
366 static gchar* listAuxBasisView[] =
367 {
368 	"cc-pVDZ-RI",
369 	"cc-pVTZ-RI",
370 	"cc-pVQZ-RI",
371 	"cc-pV5Z-RI",
372 	"cc-pV6Z-RI",
373 	"pCVDZ-RI",
374 };
375 static gchar* listAuxBasisReal[] =
376 {
377 	"cc-pVDZ-RI",
378 	"cc-pVTZ-RI",
379 	"cc-pVQZ-RI",
380 	"cc-pV5Z-RI",
381 	"cc-pV6Z-RI",
382 	"pCVDZ-RI",
383 };
384 static guint numberOfAuxBasis = G_N_ELEMENTS (listAuxBasisView);
385 /*************************************************************************************************************/
setPsicodeBasis(GtkWidget * comboBasis)386 static void setPsicodeBasis(GtkWidget* comboBasis)
387 {
388 	gint i;
389 
390 	if(strcmp(selectedTypeBasis, "Pople")==0)
391 	{
392 		listBasisView = listPopleBasisView;
393 		listBasisReal = listPopleBasisReal;
394 		numberOfBasis = numberOfPopleBasis;
395 	}
396 	else if(strcmp(selectedTypeBasis, "PopleDiffuseNonHydrogen")==0)
397 	{
398 		listBasisView = listPopleDiffuseNonHydrogenBasisView;
399 		listBasisReal = listPopleDiffuseNonHydrogenBasisReal;
400 		numberOfBasis = numberOfPopleDiffuseNonHydrogenBasis;
401 	}
402 	else if(strcmp(selectedTypeBasis, "PopleDiffuseAllAtoms")==0)
403 	{
404 		listBasisView = listPopleDiffuseAllAtomsBasisView;
405 		listBasisReal = listPopleDiffuseAllAtomsBasisReal;
406 		numberOfBasis = numberOfPopleDiffuseAllAtomsBasis;
407 	}
408 	else if(strcmp(selectedTypeBasis, "Dunning")==0)
409 	{
410 		listBasisView = listDunningBasisView;
411 		listBasisReal = listDunningBasisReal;
412 		numberOfBasis = numberOfDunningBasis;
413 	}
414 	else if(strcmp(selectedTypeBasis, "Jensen")==0)
415 	{
416 		listBasisView = listJensenBasisView;
417 		listBasisReal = listJensenBasisReal;
418 		numberOfBasis = numberOfJensenBasis;
419 	}
420 	else
421 	{
422 		listBasisView = listMiscellenousBasisView;
423 		listBasisReal = listMiscellenousBasisReal;
424 		numberOfBasis = numberOfMiscellenousBasis;
425 	}
426 
427 	if (comboBasis && GTK_IS_COMBO_BOX(comboBasis))
428 	{
429 		GtkTreeModel * model = NULL;
430 		model = gtk_combo_box_get_model(GTK_COMBO_BOX(comboBasis));
431 		gtk_list_store_clear(GTK_LIST_STORE(model));
432 
433 		for(i=0;i<numberOfBasis;i++)
434   			gtk_combo_box_append_text (GTK_COMBO_BOX (comboBasis), listBasisView[i]);
435   		gtk_combo_box_set_active(GTK_COMBO_BOX (comboBasis), 0);
436 	}
437 
438 }
439 /************************************************************************************************************/
traitementTypeBasis(GtkComboBox * combobox,gpointer d)440 static void traitementTypeBasis (GtkComboBox *combobox, gpointer d)
441 {
442 	GtkTreeIter iter;
443 	gchar* data = NULL;
444 	gchar* res = NULL;
445 	gint i;
446 	GtkWidget* comboBasis = NULL;
447 	/* gchar* s;*/
448 	if (gtk_combo_box_get_active_iter (combobox, &iter))
449 	{
450 		GtkTreeModel* model = gtk_combo_box_get_model(combobox);
451 		gtk_tree_model_get (model, &iter, 0, &data, -1);
452 	}
453 	else return;
454 	for(i=0;i<numberOfTypeBasis;i++)
455 	{
456 		if(strcmp((gchar*)data,listTypeBasisView[i])==0) res = listTypeBasisReal[i];
457 	}
458 	if(res) sprintf(selectedTypeBasis,"%s",res);
459 	comboBasis = g_object_get_data(G_OBJECT (combobox), "ComboBasis");
460 
461 	if(comboBasis) setPsicodeBasis(comboBasis);
462 }
463 /********************************************************************************************************/
create_list_type_basis(GtkWidget * comboBasis)464 static GtkWidget *create_list_type_basis(GtkWidget *comboBasis)
465 {
466         GtkTreeIter iter;
467         GtkTreeStore *store;
468 	GtkTreeModel *model;
469 	GtkWidget *combobox;
470 	GtkCellRenderer *renderer;
471 	gint i;
472         GtkTreeIter iter0;
473 
474 	store = gtk_tree_store_new (1,G_TYPE_STRING);
475 
476 	for(i=0;i<numberOfTypeBasis;i++)
477 	{
478         	gtk_tree_store_append (store, &iter, NULL);
479 		if(i==0) iter0 = iter;
480 		if(i==3) iter0 = iter;
481         	gtk_tree_store_set (store, &iter, 0, listTypeBasisView[i], -1);
482 	}
483 
484         model = GTK_TREE_MODEL (store);
485 	combobox = gtk_combo_box_new_with_model (model);
486 	g_object_set_data(G_OBJECT (combobox), "ComboBasis",comboBasis);
487 	/*
488 	gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (combobox), TRUE);
489 	*/
490 	g_object_unref (model);
491 	g_signal_connect (G_OBJECT(combobox), "changed", G_CALLBACK(traitementTypeBasis), NULL);
492 	renderer = gtk_cell_renderer_text_new ();
493 	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
494 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
495 
496 	gtk_combo_box_set_active_iter(GTK_COMBO_BOX (combobox), &iter0);
497 
498 	return combobox;
499 }
500 /************************************************************************************************************/
initPsicodeBasis()501 void initPsicodeBasis()
502 {
503 	psicodeBasis.name = g_strdup("3-21G");
504 	psicodeBasis.molecule = g_strdup("$:molecule");
505 	psicodeBasis.numberOfBasisTypes=0;
506 	psicodeBasis.basisNames = NULL;
507 }
508 /************************************************************************************************************/
freePsicodeBasis()509 void freePsicodeBasis()
510 {
511 	if(psicodeBasis.name ) g_free(psicodeBasis.name);
512 	psicodeBasis.name = NULL;
513 	if(psicodeBasis.molecule ) g_free(psicodeBasis.molecule);
514 	psicodeBasis.molecule = NULL;
515 	if(psicodeBasis.basisNames)
516 	{
517 		gint i;
518 		for(i=0;i<psicodeBasis.numberOfBasisTypes;i++)
519 			if(psicodeBasis.basisNames[i])g_free(psicodeBasis.basisNames[i]);
520 
521 		if(psicodeBasis.basisNames)g_free(psicodeBasis.basisNames);
522 	}
523 	psicodeBasis.numberOfBasisTypes=0;
524 	psicodeBasis.basisNames = NULL;
525 }
526 /************************************************************************************************************/
changedEntryBasis(GtkWidget * entry,gpointer data)527 static void changedEntryBasis(GtkWidget *entry, gpointer data)
528 {
529 	G_CONST_RETURN gchar* entryText = NULL;
530 	gchar* res = NULL;
531 	gint i;
532 
533 	if(!GTK_IS_WIDGET(entry)) return;
534 
535 	entryText = gtk_entry_get_text(GTK_ENTRY(entry));
536 	if(strlen(entryText)<1)return;
537 
538 	if(psicodeBasis.name) g_free(psicodeBasis.name);
539 	for(i=0;i<numberOfBasis;i++)
540 	{
541 		if(strcmp((gchar*)entryText,listBasisView[i])==0) res = listBasisReal[i];
542 	}
543 	if(res) psicodeBasis.name=g_strdup(res);
544 }
545 /************************************************************************************************************/
changedEntryAuxBasis(GtkWidget * entry,gpointer data)546 static void changedEntryAuxBasis(GtkWidget *entry, gpointer data)
547 {
548 	G_CONST_RETURN gchar* entryText = NULL;
549 	gint i;
550 	gchar* res = NULL;
551 
552 	if(!GTK_IS_WIDGET(entry)) return;
553 
554 	entryText = gtk_entry_get_text(GTK_ENTRY(entry));
555 	if(strlen(entryText)<1)return;
556 
557 	if(psicodeMolecule.auxBasisName) g_free(psicodeMolecule.auxBasisName);
558 	for(i=0;i<numberOfAuxBasis;i++)
559 	{
560 		if(strcmp((gchar*)entryText,listAuxBasisView[i])==0) res = listAuxBasisReal[i];
561 	}
562 	if(res) psicodeMolecule.auxBasisName=g_strdup(res);
563 }
564 /***********************************************************************************************/
addComboListToATable(GtkWidget * table,gchar ** list,gint nlist,gint i,gint j,gint k)565 static GtkWidget* addComboListToATable(GtkWidget* table,
566 		gchar** list, gint nlist, gint i, gint j, gint k)
567 {
568 	GtkWidget *entry = NULL;
569 	GtkWidget *combo = NULL;
570 
571 	combo = create_combo_box_entry(list, nlist, TRUE, -1, -1);
572 
573 	gtk_table_attach(GTK_TABLE(table),combo,j,j+k,i,i+1,
574 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
575 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
576                   3,3);
577 	entry = GTK_BIN (combo)->child;
578 	g_object_set_data(G_OBJECT (entry), "Combo",combo);
579 
580 	return entry;
581 }
582 /***********************************************************************************************/
addPsicodeTypeBasisToTable(GtkWidget * table,gint i,GtkWidget * comboBasis)583 void addPsicodeTypeBasisToTable(GtkWidget *table, gint i, GtkWidget* comboBasis)
584 {
585 	GtkWidget* combo = NULL;
586 
587 	add_label_table(table,_("Type"),(gushort)i,0);
588 	add_label_table(table,":",(gushort)i,1);
589 	combo  = create_list_type_basis(comboBasis);
590 	gtk_table_attach(GTK_TABLE(table),combo,2,2+1,i,i+1,
591 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
592 		(GtkAttachOptions)	(GTK_FILL | GTK_EXPAND),
593                   3,3);
594 }
595 /***********************************************************************************************/
addPsicodeBasisToTable(GtkWidget * table,gint i)596 GtkWidget* addPsicodeBasisToTable(GtkWidget *table, gint i)
597 {
598 	GtkWidget* entryBasis = NULL;
599 	GtkWidget* comboBasis = NULL;
600 	gint nlistBasis = 1;
601 	gchar* listBasis[] = {" "};
602 
603 
604 	add_label_table(table,_("Basis"),(gushort)i,0);
605 	add_label_table(table,":",(gushort)i,1);
606 	entryBasis = addComboListToATable(table, listBasis, nlistBasis, i, 2, 1);
607 	comboBasis  = g_object_get_data(G_OBJECT (entryBasis), "Combo");
608 	gtk_widget_set_sensitive(entryBasis, FALSE);
609 
610 	g_signal_connect(G_OBJECT(entryBasis),"changed", G_CALLBACK(changedEntryBasis),NULL);
611 	return comboBasis;
612 }
613 /***********************************************************************************************/
addPsicodeAuxBasisToTable(GtkWidget * table,gint i,GtkWidget * comboMethod,GtkWidget * comboExcited)614 void addPsicodeAuxBasisToTable(GtkWidget *table, gint i, GtkWidget* comboMethod, GtkWidget* comboExcited)
615 {
616 	GtkWidget* entryAuxBasis = NULL;
617 	GtkWidget* comboAuxBasis = NULL;
618 	GtkWidget* label = NULL;
619 
620 	label = add_label_table(table,_("Auxiliary basis"),(gushort)i,0);
621 	if(comboMethod) g_object_set_data(G_OBJECT (comboMethod), "LabelAuxBasis1", label);
622 	if(comboExcited) g_object_set_data(G_OBJECT (comboExcited), "LabelAuxBasis1", label);
623 	label = add_label_table(table,":",(gushort)i,1);
624 	if(comboMethod) g_object_set_data(G_OBJECT (comboMethod), "LabelAuxBasis2", label);
625 	if(comboExcited) g_object_set_data(G_OBJECT (comboExcited), "LabelAuxBasis2", label);
626 	entryAuxBasis = addComboListToATable(table, listAuxBasisView, numberOfAuxBasis, i, 2, 1);
627 	comboAuxBasis  = g_object_get_data(G_OBJECT (entryAuxBasis), "Combo");
628 	gtk_widget_set_sensitive(entryAuxBasis, FALSE);
629 	if(comboMethod) g_object_set_data(G_OBJECT (comboMethod), "ComboAuxBasis", comboAuxBasis);
630 	if(comboExcited) g_object_set_data(G_OBJECT (comboExcited), "ComboAuxBasis", comboAuxBasis);
631 
632 	g_signal_connect(G_OBJECT(entryAuxBasis),"changed", G_CALLBACK(changedEntryAuxBasis),NULL);
633 	psicodeMolecule.auxBasisName=g_strdup(listAuxBasisReal[0]);
634 }
635 /***********************************************************************************************/
putPsicodeBasisInTextEditor()636 static void putPsicodeBasisInTextEditor()
637 {
638         gchar buffer[BSIZE];
639 
640 	sprintf(buffer,"set basis %s\n\n",psicodeBasis.name);
641        	gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer, -1);
642 
643 }
644 /***********************************************************************************************/
putPsicodeAuxBasisInTextEditor()645 void putPsicodeAuxBasisInTextEditor()
646 {
647         gchar buffer[BSIZE];
648 
649 	if(!psicodeMolecule.auxBasisName) return;
650        	gabedit_text_insert (GABEDIT_TEXT(text), NULL, &psicodeColorFore.keyWord, &psicodeColorBack.keyWord, "\nbasis  \"ri-mp2 basis\" spherical\n", -1);
651 	sprintf(buffer," * library %s",psicodeMolecule.auxBasisName);
652        	gabedit_text_insert (GABEDIT_TEXT(text), NULL, NULL, NULL, buffer, -1);
653        	gabedit_text_insert (GABEDIT_TEXT(text), NULL, &psicodeColorFore.keyWord, &psicodeColorBack.keyWord, "\nend\n", -1);
654 }
655 /***********************************************************************************************/
putPsicodeBasisInfoInTextEditor()656 void putPsicodeBasisInfoInTextEditor()
657 {
658 	putPsicodeBasisInTextEditor();
659 }
660