1 /* BuildPolySaccharide.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 <gtk/gtk.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ctype.h>
27 #include <math.h>
28
29 #include "../Common/Global.h"
30 #include "../Utils/Utils.h"
31 #include "../Utils/UtilsInterface.h"
32 #include "../Utils/AtomsProp.h"
33 #include "../Geometry/GeomGlobal.h"
34 #include "../Geometry/Fragments.h"
35 #include "../Geometry/DrawGeom.h"
36 #include "../Geometry/GeomXYZ.h"
37 #include "../Geometry/InterfaceGeom.h"
38 #include "../Geometry/FragmentsPSC.h"
39 #include "../Geometry/RotFragments.h"
40 #include "../Geometry/MenuToolBarGeom.h"
41
42 void define_good_factor();
43 void create_GeomXYZ_from_draw_grometry();
44
45 #define LigneT 7
46 #define ColonneT 2
47
48 static GtkWidget* Entrys[3];
49 static GtkWidget* ButtonAlpha = NULL;
50 static GtkWidget* ButtonBeta = NULL;
51 static GtkWidget* ButtonL = NULL;
52 static GtkWidget* ButtonD = NULL;
53
54 static char *Symb[ColonneT][LigneT]={
55 {"Allose","Altrose","Arabinose","Fructose","Galactose","Glucose","Gulose"},
56 {"Idose","Lyxose","Mannose","Ribose","Talose","Xylose","00"}
57 };
58 static GtkWidget* SButtons[ColonneT][LigneT];
59
60 static gchar conf[30];
61 static gint lastFragNumber = -1;
62 static gint O = -1;
63 static gint O1 = -1;
64 static gint O2 = -1;
65 static gint O3 = -1;
66 static gint O4 = -1;
67 static gint O5 = -1;
68 static gint O6 = -1;
69 static gint HO1 = -1;
70 static gint HO2 = -1;
71 static gint HO3 = -1;
72 static gint HO4 = -1;
73 static gint HO6 = -1;
74 static gint C1 = -1;
75 static gint C2 = -1;
76 static gint C3 = -1;
77 static gint C4 = -1;
78 static gint C5 = -1;
79 static gint C6 = -1;
80 static gint H1 = -1;
81 static gint H2 = -1;
82 static gint H3 = -1;
83 static gint H4 = -1;
84 static gint H5 = -1;
85 static gint H6 = -1;
86 static gint H61 = -1;
87 static gint H62 = -1;
88
89 static gint lastO = -1;
90 static gint lastO1 = -1;
91 static gint lastC1 = -1;
92 static gint lastHO1 = -1;
93 static gint connectTo = -1;
94 static gint connect2 = -1;
95 static gint become = -1;
96 static gint removeH = -1;
97
98 static gdouble phi = -57;
99 static gdouble psi = 47;
100 static gdouble omega = 180;
101
102 static gdouble lastOmega = 180;
103 static gdouble lastPsi = 180;
104 static gdouble lastPhi = 180;
105 gchar fragName[30] = "L";
106 gchar fullFragName[30] = "L";
107 static Fragment Frag = {0,NULL};
108 static GeomDef* G=NULL;
109 static gint Nb = 0;
110 static gboolean capped = FALSE;
111
112 /********************************************************************************/
init_variables()113 static void init_variables()
114 {
115 lastFragNumber = -1;
116 capped = FALSE;
117
118 lastOmega = 180;
119 lastPsi = 180;
120 lastPhi = 180;
121 if(Nb!=0)
122 {
123 gint i;
124 for (i=0;i<Nb;i++)
125 {
126 g_free(G[i].Prop.symbol);
127 g_free(G[i].Prop.name);
128 g_free(G[i].mmType);
129 g_free(G[i].pdbType);
130 g_free(G[i].Residue);
131 if(G[i].typeConnections) g_free(G[i].typeConnections);
132 }
133
134 if(G)
135 g_free(G);
136 }
137 Nb=0;
138 G = NULL;
139 lastO = -1;
140 lastO1 = -1;
141 lastC1 = -1;
142 lastHO1 = -1;
143
144 }
145 /*****************************************************************************/
destroy_dlg(GtkWidget * Dlg,gpointer data)146 static void destroy_dlg(GtkWidget* Dlg,gpointer data)
147 {
148 delete_child(Dlg);
149 if(Nb!=0)
150 {
151 gint i;
152 for (i=0;i<Nb;i++)
153 {
154 g_free(G[i].Prop.symbol);
155 g_free(G[i].Prop.name);
156 g_free(G[i].mmType);
157 g_free(G[i].pdbType);
158 g_free(G[i].Residue);
159 if(G[i].typeConnections) g_free(G[i].typeConnections);
160 }
161
162 if(G) g_free(G);
163 }
164 Nb=0;
165 G = NULL;
166
167 activate_rotation();
168 }
169 /*****************************************************************************/
test_connection(gint i,gint j)170 static gboolean test_connection(gint i,gint j)
171 {
172 gdouble distance;
173 gdouble rcut;
174 gdouble x,y,z;
175 if(G[i].N == 0 || G[j].N == 0) return FALSE;
176 x = G[i].X-G[j].X;
177 y = G[i].Y-G[j].Y;
178 z = G[i].Z-G[j].Z;
179 distance = x*x+y*y+z*z;
180 rcut = G[i].Prop.covalentRadii+G[j].Prop.covalentRadii;
181 rcut = rcut* rcut;
182
183 if(distance<rcut) return TRUE;
184 else return FALSE;
185 }
186 /*****************************************************************************/
set_connections(gint iBegin,gint lastF,gint newF)187 static void set_connections(gint iBegin, gint lastF, gint newF)
188 {
189 gint i;
190 gint j;
191
192 if(Nb<1) return;
193 if(!G) return;
194 if(iBegin<0) iBegin = 0;
195 for(i=0;i<iBegin;i++)
196 {
197 if(!G[i].typeConnections) continue;
198 G[i].typeConnections = g_realloc(G[i].typeConnections,Nb*sizeof(gint));
199 for(j=iBegin;j<Nb;j++) G[i].typeConnections[j] = 0;
200 }
201 for(i=iBegin;i<Nb;i++)
202 {
203 G[i].typeConnections = g_malloc(Nb*sizeof(gint));
204 for(j=0;j<Nb;j++) G[i].typeConnections[j] = 0;
205 }
206 for(i=iBegin;i<Nb;i++)
207 {
208 for(j=i+1;j<Nb;j++)
209 {
210 if(test_connection(i,j)) G[i].typeConnections[j]= 1;
211 G[j].typeConnections[i] = G[i].typeConnections[j];
212 }
213 }
214 if(lastF>-1 && newF>-1)
215 {
216 G[lastF].typeConnections[newF] = G[newF].typeConnections[lastF]=1;
217 }
218 }
219 /*****************************************************************************/
define_geometry_to_draw()220 static void define_geometry_to_draw()
221 {
222 gint i;
223 gint j;
224 gdouble C[3]={0.0,0.0,0.0};
225
226 Free_One_Geom(geometry0,Natoms);
227 Free_One_Geom(geometry ,Natoms);
228 Natoms = 0;
229 geometry0 = NULL;
230 geometry = NULL;
231 reset_origine_molecule_drawgeom();
232
233 geometry0 = g_malloc((Nb)*sizeof(GeomDef));
234 geometry = g_malloc((Nb)*sizeof(GeomDef));
235 Natoms = 0;
236 for(i=0;i<Nb;i++)
237 {
238 if(G[i].N != 0)
239 {
240 geometry0[Natoms].X = G[i].X;
241 geometry0[Natoms].Y = G[i].Y;
242 geometry0[Natoms].Z = G[i].Z;
243 geometry0[Natoms].Charge = G[i].Charge;
244 geometry0[Natoms].Prop = prop_atom_get(G[i].Prop.symbol);
245 geometry0[Natoms].mmType = g_strdup(G[i].mmType);
246 geometry0[Natoms].pdbType = g_strdup(G[i].pdbType);
247 geometry0[Natoms].Residue = g_strdup(G[i].Residue);
248 geometry0[Natoms].ResidueNumber = G[i].ResidueNumber;
249 geometry0[Natoms].show = TRUE;
250 geometry0[Natoms].N = i+1;
251 geometry0[Natoms].typeConnections = NULL;
252 geometry0[Natoms].Layer = HIGH_LAYER;
253 geometry0[Natoms].Variable = TRUE;
254
255 geometry[Natoms].X = G[i].X;
256 geometry[Natoms].Y = G[i].Y;
257 geometry[Natoms].Z = G[i].Z;
258 geometry[Natoms].Charge = G[i].Charge;
259 geometry[Natoms].Prop = prop_atom_get(G[i].Prop.symbol);
260 geometry[Natoms].mmType = g_strdup(G[i].mmType);
261 geometry[Natoms].pdbType = g_strdup(G[i].pdbType);
262 geometry[Natoms].Residue = g_strdup(G[i].Residue);
263 geometry[Natoms].ResidueNumber = G[i].ResidueNumber;
264 geometry[Natoms].show = TRUE;
265 geometry[Natoms].N = i+1;
266 geometry[Natoms].typeConnections = NULL;
267 geometry[Natoms].Layer = HIGH_LAYER;
268 geometry[Natoms].Variable = TRUE;
269 Natoms++;
270 C[0] += G[i].X;
271 C[1] += G[i].Y;
272 C[2] += G[i].Z;
273 }
274
275
276 }
277
278 for(i=0;i<3;i++)
279 C[i] /= Natoms;
280 /* center */
281 for(i=0;i<(gint)Natoms;i++)
282 {
283 geometry0[i].X -= C[0];
284 geometry0[i].Y -= C[1];
285 geometry0[i].Z -= C[2];
286
287 geometry[i].X -= C[0];
288 geometry[i].Y -= C[1];
289 geometry[i].Z -= C[2];
290 }
291 if(Natoms>0)
292 {
293 geometry0 = g_realloc(geometry0,(Natoms)*sizeof(GeomDef));
294 geometry = g_realloc(geometry,(Natoms)*sizeof(GeomDef));
295 }
296 for(i=0;i<(gint)Natoms;i++)
297 {
298 geometry[i].typeConnections = g_malloc(Natoms*sizeof(gint));
299 for(j=0;j<(gint)Natoms;j++) geometry[i].typeConnections[j] = 0;
300 geometry0[i].typeConnections = g_malloc(Natoms*sizeof(gint));
301 for(j=0;j<(gint)Natoms;j++) geometry0[i].typeConnections[j] = 0;
302 }
303 for(i=0;i<(gint)Natoms;i++)
304 {
305 gint iG = geometry[i].N-1;
306 for(j=i+1;j<(gint)Natoms;j++)
307 {
308 gint jG = geometry[j].N-1;
309 geometry[i].typeConnections[j] = G[iG].typeConnections[jG];
310 geometry[j].typeConnections[i] = G[jG].typeConnections[iG];
311 }
312 }
313 for(i=0;i<(gint)Natoms;i++)
314 geometry[i].N = geometry0[i].N = i+1;
315
316 copy_connections(geometry0,geometry,Natoms);
317 RebuildGeom = TRUE;
318
319 }
320 /********************************************************************************/
fixH6BondAngles(gint previousFragNumber,gint currentFragNumber)321 static void fixH6BondAngles( gint previousFragNumber, gint currentFragNumber )
322 {
323 gint H61 = -1, H62 = -1, LastO1 = -1, C6 = -1, C5 = -1;
324 gdouble pseudo[] = {0.0, 0.0, 0.0};
325 gint i;
326 for( i = 0; i < Nb; i++ )
327 {
328 if(G[i].ResidueNumber != previousFragNumber)
329 continue;
330 if ( !strcmp(G[i].pdbType ,"O1" ) )
331 LastO1 = i;
332 }
333 for( i = 0; i < Nb; i++ )
334 {
335 if(G[i].ResidueNumber != currentFragNumber)
336 continue;
337
338 if ( !strcmp(G[i].pdbType ,"H61" ) )
339 H61 = i;
340 else if ( !strcmp(G[i].pdbType ,"H62" ) )
341 H62 = i;
342 else if ( !strcmp(G[i].pdbType ,"H62" ) )
343 H62 = i;
344 else if ( !strcmp(G[i].pdbType ,"C6" ) )
345 C6 = i;
346 else if ( !strcmp(G[i].pdbType ,"C5" ) )
347 C5 = i;
348 }
349 if ( ( LastO1 == -1 ) || ( H61 == -1 ) ||
350 ( H62 == -1 ) || ( C6 == -1 ) ||
351 ( C5 == -1 )
352 )
353 return;
354 pseudo[ 0 ] =( ( G[LastO1].X + G[C5].X ) / 2.0 );
355 pseudo[ 1 ] =( ( G[LastO1].Y + G[C5].Y ) / 2.0 );
356 pseudo[ 2 ] =( ( G[LastO1].Z + G[C5].Z ) / 2.0 );
357
358 if(Nb>0)
359 G = g_realloc(G,(Nb+1)*sizeof(GeomDef));
360 else
361 G = g_malloc((1)*sizeof(GeomDef));
362 G[Nb].X = pseudo[0];
363 G[Nb].Y = pseudo[1];
364 G[Nb].Z = pseudo[2];
365
366 SetAngle (Nb+1, G, Nb, C6, H61, 125.25 , NULL, 0);
367 SetTorsion(Nb+1, G, lastO1, Nb, C6, H61, 90.0, NULL, 0);
368
369 SetAngle (Nb+1, G, Nb, C6, H62, 125.25 , NULL, 0);
370 SetTorsion(Nb+1, G, lastO1, Nb, C6, H62, -90.0, NULL, 0);
371
372 if(Nb>0)
373 G = g_realloc(G,(Nb)*sizeof(GeomDef));
374 }
375 /********************************************************************************/
add_fragment(GtkWidget * button)376 void add_fragment(GtkWidget* button)
377 {
378 gint i;
379 gint j;
380 G_CONST_RETURN gchar* t;
381 gint omegaArrayCounter=0;
382 gint* omegaArray=NULL;
383
384
385 t = gtk_entry_get_text(GTK_ENTRY(Entrys[0]));
386 phi = atof(t);
387 t = gtk_entry_get_text(GTK_ENTRY(Entrys[1]));
388 psi = atof(t);
389 t = gtk_entry_get_text(GTK_ENTRY(Entrys[2]));
390 omega = atof(t);
391
392 if(Nb>0)
393 G = g_realloc(G,(Nb+Frag.NAtoms+1)*sizeof(GeomDef));
394 else
395 G = g_malloc((Frag.NAtoms+1)*sizeof(GeomDef));
396
397 omegaArray = g_malloc(Frag.NAtoms*sizeof(gint));
398
399 Ddef = FALSE;
400
401 j=Nb-1;
402 for(i=0;i<Frag.NAtoms;i++)
403 {
404 j++;
405 G[j].X=Frag.Atoms[i].Coord[0];
406 G[j].Y=Frag.Atoms[i].Coord[1];
407 G[j].Z=Frag.Atoms[i].Coord[2];
408 G[j].Charge=Frag.Atoms[i].Charge;
409 G[j].mmType=g_strdup(Frag.Atoms[i].mmType);
410 G[j].pdbType=g_strdup(Frag.Atoms[i].pdbType);
411 G[j].Residue=g_strdup(Frag.Atoms[i].Residue);
412 G[j].ResidueNumber=lastFragNumber+1;
413 G[j].typeConnections = NULL;
414
415 G[j].Prop = prop_atom_get(Frag.Atoms[i].Symb);
416 G[j].N = j+1;
417
418 if (!strcmp(Frag.Atoms[i].pdbType, "O1" ) ){
419 O1 = j;
420 }
421 else if (!strcmp(Frag.Atoms[i].pdbType, "O2" ) ){
422 O2 = j;
423 }
424 else if (!strcmp(Frag.Atoms[i].pdbType, "O3" ) ){
425 O3 = j;
426 }
427 else if (!strcmp(Frag.Atoms[i].pdbType, "O4" ) ){
428 O4 = j;
429 }
430 else if (!strcmp(Frag.Atoms[i].pdbType, "O5" ) ){
431 O5 = j;
432 }
433 else if (!strcmp(Frag.Atoms[i].pdbType, "O" ) ){
434 O = j;
435 }
436 else if (!strcmp(Frag.Atoms[i].pdbType, "O6" ) ){
437 O6 = j;
438 }
439 else if (!strcmp(Frag.Atoms[i].pdbType, "HO1" ) ){
440 HO1 = j;
441 }
442 else if (!strcmp(Frag.Atoms[i].pdbType, "HO2" ) ){
443 HO2 = j;
444 }
445 else if (!strcmp(Frag.Atoms[i].pdbType, "HO3" ) ){
446 HO3 = j;
447 }
448 else if (!strcmp(Frag.Atoms[i].pdbType, "HO4" ) ){
449 HO4 = j;
450 }
451 else if (!strcmp(Frag.Atoms[i].pdbType, "HO6" ) ){
452 HO6 = j;
453 }
454 else if (!strcmp(Frag.Atoms[i].pdbType, "C1" ) ){
455 C1 = j;
456 }
457 else if (!strcmp(Frag.Atoms[i].pdbType, "C2" ) ){
458 C2 = j;
459 }
460 else if (!strcmp(Frag.Atoms[i].pdbType, "C3" ) ){
461 C3 = j;
462 }
463 else if (!strcmp(Frag.Atoms[i].pdbType, "C4" ) ){
464 C4 = j;
465 }
466 else if (!strcmp(Frag.Atoms[i].pdbType, "C5" ) ){
467 C5 = j;
468 }
469 else if (!strcmp(Frag.Atoms[i].pdbType, "C6" ) ){
470 C6 = j;
471 }
472 else if (!strcmp(Frag.Atoms[i].pdbType, "H1" ) ){
473 H1 = j;
474 }
475 else if (!strcmp(Frag.Atoms[i].pdbType, "H2" ) ){
476 H2 = j;
477 }
478 else if (!strcmp(Frag.Atoms[i].pdbType, "H3" ) ){
479 H3 = j;
480 }
481 else if (!strcmp(Frag.Atoms[i].pdbType, "H4" ) ){
482 H4 = j;
483 }
484 else if (!strcmp(Frag.Atoms[i].pdbType, "H6" ) ){
485 H6 = j;
486 }
487 else if (!strcmp(Frag.Atoms[i].pdbType, "H5" ) ){
488 H5 = j;
489 }
490 else if (!strcmp(Frag.Atoms[i].pdbType, "H61" ) ){
491 H61 = j;
492 }
493 else if (!strcmp(Frag.Atoms[i].pdbType, "H61" ) ){
494 H62 = j;
495 }
496 omegaArray[ omegaArrayCounter++ ] = j;
497 }
498 Nb += Frag.NAtoms;
499
500 connectTo = C4;
501 connect2 = C3;
502 become = O3;
503 removeH = HO3;
504
505 if(!strcmp(conf,"O1 - C1"))
506 {
507 connectTo = C1;
508 connect2 = O;
509 become = O1;
510 removeH = HO1;
511 capped = TRUE;
512 }
513 else
514 if(!strcmp(conf,"O1 - C2"))
515 {
516 connectTo = C2;
517 connect2 = C1;
518 become = O2;
519 removeH = HO2;
520 }
521 else
522 if(!strcmp(conf,"O1 - C3"))
523 {
524
525 connectTo = C3;
526 connect2 = C2;
527 become = O3;
528 removeH = HO3;
529 }
530 else
531 if(!strcmp(conf,"O1 - C4"))
532 {
533 connectTo = C4;
534 connect2 = C3;
535 become = O4;
536 removeH = HO4;
537 }
538 else
539 if(!strcmp(conf,"O1 - C5"))
540 {
541 connectTo = C5;
542 connect2 = C4;
543 become = O5;
544 removeH = H5;
545 }
546 else
547 {
548 connectTo = C6;
549 connect2 = C5;
550 become = O6;
551 removeH = H6;
552 }
553 if(lastFragNumber !=-1)
554 {
555 SetBondDistance(G, lastO1, become, 0.0, omegaArray, omegaArrayCounter);
556 SetAngle( Nb, G, lastC1, lastO1, connectTo, 109.5, omegaArray, omegaArrayCounter );
557 SetTorsion(Nb, G, lastO, lastC1, lastO1, connectTo, lastPhi, omegaArray, omegaArrayCounter );
558 SetTorsion(Nb, G, lastC1, lastO1, connectTo, connect2, psi, omegaArray, omegaArrayCounter );
559 if ( connectTo == C6 )
560 {
561 SetTorsion(Nb, G, lastO1, connectTo, connect2, C4, omega, omegaArray, omegaArrayCounter );
562 fixH6BondAngles( lastFragNumber, lastFragNumber + 1 );
563 }
564 /* printf("removeH=%d bec = %d lastHO1 = %d\n ",removeH,become,lastHO1);*/
565 G[removeH].N = 0;
566 G[become].N = 0;
567 G[lastHO1].N = 0;
568 }
569
570 set_connections(Nb-Frag.NAtoms,lastO1,connectTo);
571 define_geometry_to_draw();
572 define_good_factor();
573 create_GeomXYZ_from_draw_grometry();
574 unselect_all_atoms();
575 reset_multiple_bonds();
576 reset_hydrogen_bonds();
577 reset_charges_multiplicities();
578 drawGeom();
579
580 lastO1 = O1;
581 lastC1 = C1;
582 lastO = O;
583 lastHO1 = HO1;
584
585 lastOmega = omega;
586 lastPhi = phi;
587 lastPsi = psi;
588 lastFragNumber++;
589 if(capped)
590 {
591 GtkWidget* Dlg = g_object_get_data(G_OBJECT (button),"Dlg");
592 GtkWidget* w;
593 destroy_dlg(Dlg,NULL);
594 w = Message(_("The O1-C1 bond acts as a cap to the chain.\nSuggestion: Use O1-C1 only for disaccharides or to cap a chain."),_("Info"),TRUE);
595 gtk_window_set_modal(GTK_WINDOW(w),TRUE);
596 gtk_window_set_transient_for(GTK_WINDOW(w),GTK_WINDOW(GeomDlg));
597 }
598
599 }
600 /********************************************************************************/
build_polysaccharide(GtkWidget * w,gpointer data)601 static void build_polysaccharide(GtkWidget *w,gpointer data)
602 {
603 gboolean alpha = TRUE;
604 sprintf(fragName,"%s",(gchar*)data);
605 /* lowercase(fragName);*/
606
607
608 if (GTK_TOGGLE_BUTTON (ButtonBeta)->active)
609 alpha = FALSE;
610
611 sprintf(fullFragName,"%s",fragName);
612 Frag = GetFragmentPSC(fullFragName,alpha);
613 add_fragment(w);
614 }
615 /********************************************************************************************************/
traite_conformation(GtkComboBox * combobox,gpointer d)616 static void traite_conformation(GtkComboBox *combobox, gpointer d)
617 {
618 gint i;
619 gint j;
620 GtkTreeIter iter;
621 gchar* option = NULL;
622 if (gtk_combo_box_get_active_iter (combobox, &iter))
623 {
624 GtkTreeModel* model = gtk_combo_box_get_model(combobox);
625 gtk_tree_model_get (model, &iter, 0, &option, -1);
626 }
627
628 sprintf(conf,"%s",option);
629 if(!strcmp(option,"O1 - C5") || !strcmp(option,"O1 - C6")) gtk_editable_set_editable((GtkEditable*) Entrys[2],TRUE);
630 else gtk_editable_set_editable((GtkEditable*) Entrys[2],FALSE);
631 if(!strcmp(option,"O1 - C5"))
632 {
633 for(i=0;i<LigneT;i++)
634 for(j=0;j<ColonneT;j++)
635 {
636 if(SButtons[j][i])
637 {
638 if( !strcmp(Symb[j][i],"Arabinose") ||
639 !strcmp(Symb[j][i],"Lyxose") ||
640 !strcmp(Symb[j][i],"Ribose") ||
641 !strcmp(Symb[j][i],"Xylose")
642 )
643 gtk_widget_set_sensitive(SButtons[j][i], TRUE);
644 else
645 gtk_widget_set_sensitive(SButtons[j][i], FALSE);
646 }
647 }
648 }
649 else
650 if(!strcmp(option,"O1 - C4") || !strcmp(option,"O1 - C6"))
651 {
652 for(i=0;i<LigneT;i++)
653 for(j=0;j<ColonneT;j++)
654 {
655 if(SButtons[j][i])
656 {
657 if( !strcmp(Symb[j][i],"Arabinose") ||
658 !strcmp(Symb[j][i],"Lyxose") ||
659 !strcmp(Symb[j][i],"Ribose") ||
660 !strcmp(Symb[j][i],"Xylose")
661 )
662 gtk_widget_set_sensitive(SButtons[j][i], FALSE);
663 else
664 gtk_widget_set_sensitive(SButtons[j][i], TRUE);
665 }
666 }
667
668 }
669 else
670 {
671 for(i=0;i<LigneT;i++)
672 for(j=0;j<ColonneT;j++)
673 if(SButtons[j][i])
674 gtk_widget_set_sensitive(SButtons[j][i], TRUE);
675 }
676
677 }
678 /********************************************************************************************************/
get_button_connectivity()679 static GtkWidget *get_button_connectivity()
680 {
681 GtkTreeIter iter;
682 GtkTreeStore *store;
683 GtkTreeModel *model;
684 GtkWidget *combobox;
685 GtkCellRenderer *renderer;
686
687 store = gtk_tree_store_new (1,G_TYPE_STRING);
688 gtk_tree_store_append (store, &iter, NULL);
689 gtk_tree_store_set (store, &iter, 0, "O1 - C1", -1);
690 gtk_tree_store_append (store, &iter, NULL);
691 gtk_tree_store_set (store, &iter, 0, "O1 - C2", -1);
692 gtk_tree_store_append (store, &iter, NULL);
693 gtk_tree_store_set (store, &iter, 0, "O1 - C3", -1);
694 gtk_tree_store_append (store, &iter, NULL);
695 gtk_tree_store_set (store, &iter, 0, "O1 - C4", -1);
696 gtk_tree_store_append (store, &iter, NULL);
697 gtk_tree_store_set (store, &iter, 0, "O1 - C5", -1);
698 gtk_tree_store_append (store, &iter, NULL);
699 gtk_tree_store_set (store, &iter, 0, "O1 - C6", -1);
700 sprintf(conf,"O1 - C4");
701
702 model = GTK_TREE_MODEL (store);
703 combobox = gtk_combo_box_new_with_model (model);
704 g_object_unref (model);
705 g_signal_connect (G_OBJECT(combobox), "changed", G_CALLBACK(traite_conformation), NULL);
706 renderer = gtk_cell_renderer_text_new ();
707 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
708 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer, "text", 0, NULL);
709
710 return combobox;
711 }
712 /********************************************************************************/
add_connectivity(GtkWidget * Dlg,GtkWidget * box)713 static GtkWidget* add_connectivity(GtkWidget* Dlg,GtkWidget *box)
714 {
715 GtkWidget* frame;
716 GtkWidget* combobox;
717
718 frame = gtk_frame_new (_("Connectivity"));
719 gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
720 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
721
722 gtk_container_add(GTK_CONTAINER(box),frame);
723 gtk_widget_show (frame);
724
725
726 combobox =get_button_connectivity();
727 gtk_container_add(GTK_CONTAINER(frame), combobox);
728 return combobox;
729 }
730 /********************************************************************************/
add_anomer(GtkWidget * Dlg,GtkWidget * box)731 static void add_anomer(GtkWidget* Dlg,GtkWidget *box)
732 {
733 GtkWidget* Table;
734 GtkWidget* frame;
735
736 frame = gtk_frame_new ("Anomer");
737 gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
738 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
739
740 gtk_container_add(GTK_CONTAINER(box),frame);
741 gtk_widget_show (frame);
742
743 Table = gtk_table_new(1,2,TRUE);
744 gtk_container_add(GTK_CONTAINER(frame),Table);
745
746 ButtonAlpha = gtk_radio_button_new_with_label( NULL," Alpha " );
747 gtk_table_attach(GTK_TABLE(Table),ButtonAlpha,0,1,0,1,
748 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
749 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
750 1,1);
751 ButtonBeta = gtk_radio_button_new_with_label( gtk_radio_button_get_group (GTK_RADIO_BUTTON (ButtonAlpha)),
752 " Beta ");
753 gtk_table_attach(GTK_TABLE(Table),ButtonBeta,1,2,0,1,
754 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
755 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
756 1,1);
757 g_object_set_data(G_OBJECT (Dlg), "ButtonAlpha",ButtonAlpha);
758 g_object_set_data(G_OBJECT (Dlg), "ButtonBeta",ButtonBeta);
759 }
760 /********************************************************************************/
add_isomer(GtkWidget * Dlg,GtkWidget * box)761 static void add_isomer(GtkWidget* Dlg,GtkWidget *box)
762 {
763 GtkWidget* Table;
764 GtkWidget* frame;
765
766 frame = gtk_frame_new (_("Isomer"));
767 gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
768 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
769
770 gtk_container_add(GTK_CONTAINER(box),frame);
771 gtk_widget_show (frame);
772
773 Table = gtk_table_new(1,2,TRUE);
774 gtk_container_add(GTK_CONTAINER(frame),Table);
775
776 ButtonL = gtk_radio_button_new_with_label( NULL," L " );
777 gtk_table_attach(GTK_TABLE(Table),ButtonL,0,1,0,1,
778 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
779 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
780 1,1);
781 ButtonD = gtk_radio_button_new_with_label( gtk_radio_button_get_group (GTK_RADIO_BUTTON (ButtonL)),
782 " D ");
783 gtk_table_attach(GTK_TABLE(Table),ButtonD,1,2,0,1,
784 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
785 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
786 1,1);
787 g_object_set_data(G_OBJECT (Dlg), "ButtonL",ButtonL);
788 g_object_set_data(G_OBJECT (Dlg), "ButtonD",ButtonD);
789 }
790 /********************************************************************************/
add_conformation(GtkWidget * Dlg,GtkWidget * box)791 static void add_conformation(GtkWidget* Dlg,GtkWidget *box)
792 {
793 GtkWidget* Table;
794 GtkWidget* frame;
795 GtkWidget* Label;
796 gchar* tlabel[] = {"Phi","Psi","Omega"};
797 gchar* elabel[] = {"180.0","180.0","180.0"};
798 gint i;
799
800 frame = gtk_frame_new (_("Conformation"));
801 gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
802 gtk_container_set_border_width (GTK_CONTAINER (frame), 5);
803
804 gtk_container_add(GTK_CONTAINER(box),frame);
805 gtk_widget_show (frame);
806
807 Table = gtk_table_new(3,2,TRUE);
808 gtk_container_add(GTK_CONTAINER(frame),Table);
809
810 for(i=0;i<3;i++)
811 {
812 Label = gtk_label_new(tlabel[i]);
813 gtk_table_attach(GTK_TABLE(Table),Label,0,1,i,i+1,
814 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
815 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
816 1,1);
817 Entrys[i] = gtk_entry_new();
818 gtk_table_attach(GTK_TABLE(Table),Entrys[i],1,2,i,i+1,
819 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
820 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
821 1,1);
822
823 if(i==2)
824 gtk_editable_set_editable((GtkEditable*) Entrys[i],FALSE);
825 else
826 gtk_editable_set_editable((GtkEditable*) Entrys[i],TRUE);
827 gtk_entry_set_text(GTK_ENTRY(Entrys[i]),elabel[i]);
828 }
829 }
830 /******************************************************************************/
add_buttons(GtkWidget * Dlg,GtkWidget * box)831 static void add_buttons(GtkWidget *Dlg,GtkWidget* box)
832 {
833 GtkWidget* Table;
834 GtkWidget* button;
835 GtkWidget* frame;
836 guint i;
837 guint j;
838 GtkStyle *button_style;
839 GtkStyle *style;
840
841
842 frame = gtk_frame_new (NULL);
843 gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
844 gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
845
846 gtk_container_add(GTK_CONTAINER(box),frame);
847 gtk_widget_show (frame);
848
849 Table = gtk_table_new(LigneT,ColonneT,TRUE);
850 gtk_container_add(GTK_CONTAINER(frame),Table);
851 button_style = gtk_widget_get_style(Dlg);
852
853 for ( i = 0;i<LigneT;i++)
854 for ( j = 0;j<ColonneT;j++)
855 {
856 SButtons[j][i] = NULL;
857 if(strcmp(Symb[j][i],"00"))
858 {
859 button = gtk_button_new_with_label(Symb[j][i]);
860 g_object_set_data(G_OBJECT (button), "Dlg",Dlg);
861 style=set_button_style(button_style,button,"H");
862 g_signal_connect(G_OBJECT(button), "clicked",
863 (GCallback)build_polysaccharide,(gpointer )Symb[j][i]);
864 /*
865 gtk_widget_set_size_request (GTK_WIDGET(button), (ScreenWidth)*0.05, (ScreenHeight)*0.05);
866 */
867 gtk_table_attach(GTK_TABLE(Table),button,j,j+1,i,i+1,
868 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND) ,
869 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND),
870 1,1);
871 SButtons[j][i] = button;
872 }
873
874 }
875
876 }
877 /**********************************************************************/
build_polysaccharide_dlg()878 void build_polysaccharide_dlg()
879 {
880 GtkWidget *Dlg;
881 GtkWidget *Button;
882 GtkWidget *hbox;
883 GtkWidget *vbox;
884 GtkWidget *frame;
885 GtkWidget *vboxframe;
886 GtkWidget *combobox;
887
888 init_variables();
889 Dlg = gtk_dialog_new();
890 gtk_window_set_title(GTK_WINDOW(Dlg),_("Build PolySaccharide molecule"));
891 gtk_window_set_position(GTK_WINDOW(Dlg),GTK_WIN_POS_CENTER);
892 gtk_window_set_modal (GTK_WINDOW (Dlg), TRUE);
893 gtk_window_set_transient_for(GTK_WINDOW(Dlg),GTK_WINDOW(GeomDlg));
894
895
896 add_child(GeomDlg,Dlg,gtk_widget_destroy,_(" Build PolySacc. mol. "));
897
898
899 g_signal_connect(G_OBJECT(Dlg),"delete_event",(GCallback)destroy_dlg,NULL);
900
901 frame = gtk_frame_new (NULL);
902 gtk_frame_set_shadow_type( GTK_FRAME(frame),GTK_SHADOW_ETCHED_OUT);
903 gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
904 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dlg)->vbox), frame,TRUE,TRUE,0);
905 gtk_widget_show (frame);
906
907 vboxframe = create_vbox(frame);
908
909 hbox = create_hbox_false(vboxframe);
910
911 add_buttons(Dlg,hbox);
912 vbox = gtk_vbox_new (FALSE, 0);
913 gtk_box_pack_end (GTK_BOX(hbox), vbox, FALSE, FALSE, 5);
914 gtk_widget_show (vbox);
915 combobox = add_connectivity(Dlg,vbox);
916 add_conformation(Dlg,vbox);
917
918 hbox = gtk_hbox_new (FALSE, 0);
919 gtk_box_pack_end (GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
920 gtk_widget_show (hbox);
921 add_anomer(Dlg,hbox);
922 add_isomer(Dlg,hbox);
923
924
925 /* The "Close" button */
926 gtk_box_set_homogeneous (GTK_BOX( GTK_DIALOG(Dlg)->action_area), FALSE);
927 gtk_widget_realize(Dlg);
928 Button = create_button(Dlg,_("Close"));
929 gtk_box_pack_end (GTK_BOX( GTK_DIALOG(Dlg)->action_area), Button, FALSE, TRUE, 5);
930 g_signal_connect_swapped(G_OBJECT(Button), "clicked",(GCallback)destroy_dlg,GTK_OBJECT(Dlg));
931
932 GTK_WIDGET_SET_FLAGS(Button, GTK_CAN_DEFAULT);
933 gtk_widget_grab_default(Button);
934 gtk_widget_show_all(GTK_DIALOG(Dlg)->vbox);
935 gtk_widget_show_all(GTK_DIALOG(Dlg)->action_area);
936 gtk_widget_show_now(Dlg);
937
938 /*fit_windows_position(GeomDlg, Dlg);*/
939
940 gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 3);
941 }
942
943