1 /* $Id: cn3dmodl.c,v 6.93 2006/07/13 17:08:36 bollin Exp $
2 * ===========================================================================
3 *
4 *                            PUBLIC DOMAIN NOTICE
5 *            National Center for Biotechnology Information (NCBI)
6 *
7 *  This software/database is a "United States Government Work" under the
8 *  terms of the United States Copyright Act.  It was written as part of
9 *  the author's official duties as a United States Government employee and
10 *  thus cannot be copyrighted.  This software/database is freely available
11 *  to the public for use. The National Library of Medicine and the U.S.
12 *  Government do not place any restriction on its use or reproduction.
13 *  We would, however, appreciate having the NCBI and the author cited in
14 *  any work or product based on this material
15 *
16 *  Although all reasonable efforts have been taken to ensure the accuracy
17 *  and reliability of the software and data, the NLM and the U.S.
18 *  Government do not and cannot warrant the performance or results that
19 *  may be obtained by using this software or data. The NLM and the U.S.
20 *  Government disclaim all warranties, express or implied, including
21 *  warranties of performance, merchantability or fitness for any particular
22 *  purpose.
23 * ===========================================================================
24 *
25 * File Name: $Id: cn3dmodl.c,v 6.93 2006/07/13 17:08:36 bollin Exp $
26 *
27 * Author: Yanli Wang
28 *
29 * Version Creation Date: 18/9/1998
30 *
31 * $Log: cn3dmodl.c,v $
32 * Revision 6.93  2006/07/13 17:08:36  bollin
33 * use Uint4 instead of Uint2 for itemID values
34 *
35 * Revision 6.92  2001/04/27 20:07:59  juran
36 * Heed warnings.
37 *
38 * Revision 6.91  2000/04/08 00:37:31  lewisg
39 * multiple seqentries, NEWSEQ message, etc.
40 *
41 * Revision 6.89  2000/03/23 18:27:25  thiessen
42 * show-by-selected now works for hets/ions/water
43 *
44 * Revision 6.88  2000/03/15 04:43:55  thiessen
45 * various minor fixes
46 *
47 * Revision 6.87  2000/03/14 18:03:13  thiessen
48 * add target row to MMD; remove rowmgr
49 *
50 * Revision 6.86  2000/03/10 18:46:59  lewisg
51 * add show/hide
52 *
53 * Revision 6.85  2000/02/28 14:47:59  thiessen
54 * fixed "show selected only" in show/hide
55 *
56 * Revision 6.84  2000/02/26 00:01:40  thiessen
57 * OpenGL improvements, progress on cleanup of Show/Hide
58 *
59 * Revision 6.83  2000/02/25 02:53:14  thiessen
60 * check AlignMgr rather than bAligned flag to see if a residue is aligned
61 *
62 * Revision 6.82  2000/02/19 21:25:56  thiessen
63 * split of cn3dmodl into cn3dmodl and cn3dstyl
64 *
65 * Revision 6.81  2000/02/14 12:32:31  thiessen
66 * fix solvent identification; progress on seqcons module
67 *
68 * Revision 6.80  2000/02/11 15:52:28  thiessen
69 * transparent solvent if partial occupancy; move alt conf behaviour checkbox to Show/Hide panel
70 *
71 * Revision 6.79  2000/02/10 15:51:59  lewisg
72 * cn3d responds and send correct update messages.  many coloring bug fixes
73 *
74 * Revision 6.78  2000/02/07 20:17:37  lewisg
75 * minor bug fixes, use gui font for win32
76 *
77 * Revision 6.77  1999/12/28 23:06:35  lewisg
78 * udv/cn3d communication
79 *
80 * Revision 6.76  1999/12/28 15:08:43  lewisg
81 * remove remaining mediainfo code
82 *
83 * Revision 6.75  1999/12/27 23:14:11  lewisg
84 * add colormgr show/hide in Cn3D
85 *
86 * Revision 6.74  1999/12/16 15:25:22  thiessen
87 * removed unused buttons/popups from OpenGL version
88 *
89 * Revision 6.73  1999/12/11 01:30:34  lewisg
90 * fix bugs with sharing colors between ddv and cn3d
91 *
92 * Revision 6.72  1999/11/22 14:46:43  thiessen
93 * moved _OPENGL code blocks to only vibrant and ncbicn3d libraries
94 *
95 * Revision 6.71  1999/11/15 18:30:08  lewisg
96 * get rid of extra redraws when selecting
97 *
98 * Revision 6.70  1999/11/10 23:19:41  lewisg
99 * rewrite of selection code for ddv
100 *
101 * Revision 6.69  1999/11/03 16:24:21  lewisg
102 * get rid of non-existing includes
103 *
104 * Revision 6.68  1999/11/02 23:06:07  lewisg
105 * fix cn3d to launch correctly if there is no seqentry associated with bioseq
106 *
107 * Revision 6.67  1999/10/29 14:15:28  thiessen
108 * ran all Cn3D source through GNU Indent to prettify
109 *
110 * Revision 6.66  1999/10/15 20:56:39  lewisg
111 * append DDV_ColorGlobal as userdata.  free memory when cn3d terminates.
112 *
113 * Revision 6.65  1999/10/05 23:18:20  lewisg
114 * add ddv and udv to cn3d with memory management
115 *
116 * Revision 6.64  1999/09/21 18:09:15  lewisg
117 * binary search added to color manager, various bug fixes, etc.
118 *
119 * Revision 6.63  1999/09/10 13:49:38  lewisg
120 * eliminate spaces before preprocessor directives
121 *
122 * Revision 6.62  1999/07/27 14:19:09  ywang
123 * fix previous in another way so that not to break any existant code
124 *
125 * Revision 6.61  1999/07/26 21:42:47  vakatov
126 * Fixed a multiple ValNode list deallocation in
127 * ClearSpecialFeature/SpecialFeatureFree
128 *
129 * Revision 6.60  1999/07/15 15:59:41  ywang
130 * improve feature control, call Cn3D_DeHighlightAll after ObjMgrDeSelectAll
131 *
132 * Revision 6.59  1999/07/12 14:15:37  ywang
133 * initialize ButtoN b for internal call Cn3D_ListDomainProc & Cn3D_ListStrucProc
134 *
135 * Revision 6.58  1999/07/07 20:45:35  ywang
136 * clear domaindata, mediadata, special feature before reading in new data in cn3d
137 *
138 * Revision 6.57  1999/07/01 16:01:08  ywang
139 * improve display control panel
140 *
141 * Revision 6.56  1999/06/16 15:13:29  ywang
142 * for feature editing: direct return for 'Cancel' 'Delete' 'Edit' 'Save' if no residues or no feature name selected
143 *
144 * Revision 6.55  1999/06/07 21:25:14  ywang
145 * add iUserDefinedFeatureOld, FeatureOnOld to protect saved features being overwritten by temporary feature
146 *
147 * Revision 6.54  1999/06/07 20:26:11  ywang
148 * change prompt for featue editing
149 *
150 * Revision 6.53  1999/06/07 19:39:50  ywang
151 * remove obsolete user defined features, an obsolete feature means a feature whose region has been completely overwirtten by a later defined feature
152 *
153 * Revision 6.52  1999/06/03 20:29:24  ywang
154 * fix bug in aligned domain display when they are from same structure
155 *
156 * Revision 6.51  1999/05/27 16:11:22  ywang
157 * initilize all local variables at defined
158 *
159 * Revision 6.50  1999/05/03 16:54:23  ywang
160 * fix bug for recording and matching mol-id for user defined features
161 *
162 * Revision 6.49  1999/04/22 21:10:44  ywang
163 * check NULL pointer on domain counting
164 *
165 * Revision 6.48  1999/04/21 21:15:09  ywang
166 * replace Cn3D_DeHighlightAll with ObjMgrDeSelectAll
167 *
168 * Revision 6.46  1999/04/16 22:21:23  ywang
169 * update residue aligned status on mediadata upon sequence SHOW/HIDE
170 *
171 * Revision 6.45  1999/04/15 21:37:35  ywang
172 * add AssignDomainAlignedStatusForStrucSeqs
173 *
174 * Revision 6.44  1999/04/14 17:43:26  ywang
175 * synchronize object show/hide upon action 'Show Selected Only' action
176 *
177 * Revision 6.43  1999/04/14 17:19:15  ywang
178 * synchronize object show/hide upon action 'Show Selected Only' action
179 *
180 * Revision 6.42  1999/04/13 23:06:14  ywang
181 * fix bug for coloring strucseqs data
182 *
183 * Revision 6.41  1999/04/06 20:11:02  lewisg
184 * more opengl
185 *
186 * Revision 6.40  1999/04/02 20:51:57  ywang
187 * fix warnings
188 *
189 * Revision 6.39  1999/03/22 22:41:52  ywang
190 * redesign feature page, fix bugs
191 *
192 * Revision 6.38  1999/03/18 23:13:03  ywang
193 * modify feature window
194 *
195 * Revision 6.37  1999/03/18 22:28:56  ywang
196 * add functions for saveout+readin+index user defined features
197 *
198 * Revision 6.36  1999/03/08 21:16:21  ywang
199 * initialize variables
200 *
201 * Revision 6.35  1999/03/08 19:34:35  ywang
202 * redesign Feature page
203 *
204 * Revision 6.34  1999/03/03 23:17:21  lewisg
205 * one master struct at a time, list slaves in structure info, bug fixes
206 *
207 * Revision 6.33  1999/03/01 20:21:30  ywang
208 * put in options for residue on/off control
209 *
210 * Revision 6.32  1999/02/24 23:00:02  ywang
211 * minor name change for user defined feature at MGD nodecn3dmodl.c
212 *
213 * Revision 6.31  1999/02/12 15:42:56  ywang
214 * change void static to static void for ClearSpecialFeaturewithMGD(void)
215 *
216 * Revision 6.30  1999/02/11 22:38:51  ywang
217 * fix bug on display highlight residues only--if no res are highlighted, cn3d sets that button status as FALSE and draw whole structurescn3dwin.c
218 *
219 * Revision 6.29  1999/02/08 18:42:25  ywang
220 * improve feature editing
221 *
222 * Revision 6.28  1999/02/04 16:14:44  ywang
223 * support delete added features
224 *
225 * Revision 6.27  1999/02/03 23:09:24  ywang
226 * add functions to allow editing 'added feature' in Model menu
227 *
228 * Revision 6.26  1999/02/02 22:25:27  ywang
229 * improve feature edit function
230 *
231 * Revision 6.25  1999/02/01 21:10:09  ywang
232 * correct mistake
233 *
234 * Revision 6.24  1999/02/01 20:43:25  ywang
235 * improve 'Model' menu
236 *
237 * Revision 6.23  1999/01/27 21:51:51  ywang
238 * add label to 'Model' menu
239 *
240 * Revision 6.22  1999/01/27 16:21:55  ywang
241 * redesign 'Model' menu
242 *
243 * Revision 6.21  1999/01/26 17:14:35  ywang
244 * redesign Display menu and add 'display highlight residues only' function
245 *
246 * Revision 6.20  1999/01/20 18:21:19  ywang
247 * include salmedia.h due to the move around of MediaInfo from cn3dmsg.h to the new created salmedia.h
248 *
249  * Revision 6.19  1998/12/16  22:49:37  ywang
250  * fix compiling warnings on Win32
251  *
252  * Revision 6.17  1998/11/09  22:03:31  ywang
253  * fix bugs for modeling
254  *
255  * Revision 6.16  1998/11/06  23:01:05  ywang
256  * fix bugs for modeling
257  *
258  * Revision 6.15  1998/11/04  13:03:30  kans
259  * fixed variable name
260  *
261 * Revision 6.14  1998/11/04 00:06:19  ywang
262 * add function for modeling: change render/color for special residue(s)
263 *
264  * Revision 6.13  1998/10/21  15:48:23  ywang
265  * rearrange View Control menu
266  *
267  * Revision 6.12  1998/10/20  17:50:37  ywang
268  * fix MMDB/VAST domain number inconsistency problem
269  *
270  * Revision 6.11  1998/10/20  16:54:39  ywang
271  * fix bug in AssignDomainAlignedStatus
272  *
273  * Revision 6.10  1998/10/13  14:44:17  ywang
274  * fix bugs for single struc case in AssignDomainAlignedStatus
275  *
276  * Revision 6.9  1998/10/08  21:39:15  ywang
277  * fix bug for assign domain aligned status
278  *
279  * Revision 6.8  1998/10/08  00:07:19  ywang
280  * fix domain aligned status bug
281  *
282  * Revision 6.6  1998/10/02  18:25:15  kans
283  * some functions did not have void as a return, which the Mac compiler detected
284  *
285 * Revision 6.5  1998/10/01 21:55:39  ywang
286 * put function for object display control
287 *
288  * Revision 6.4  1998/09/30  22:10:46  ywang
289  * control display on three levels: structure, chain, domain
290  *
291  * Revision 6.3  1998/09/23  22:04:02  ywang
292  * synchronize show/hide between cn3d and salsa when display complexity is changed
293  *
294  * Revision 6.2  1998/09/23  18:38:48  ywang
295  * add functions to control display on domain level
296  *
297  * Revision 6.1  1998/09/22  18:02:54  ywang
298  * panels and functions for display control
299  *
300 */
301 
302 #include <ncbi.h>
303 #ifdef _OPENGL
304 #include <shim3d.h>
305 #else
306 #include <viewer3d.h>
307 #endif
308 #include <cn3dmain.h>
309 #include <math.h>
310 #include <mmdbapi.h>
311 #include <mmdbapi1.h>
312 #include <mmdbapi2.h>
313 #include <mmdbapi3.h>
314 #include <mmdbapi4.h>
315 #include <algorend.h>
316 #include <cn3dmsg.h>
317 #include <salmedia.h>
318 #include <salutil.h>
319 #include <cn3dopen.h>
320 #include <cn3dmodl.h>
321 #include <objmime.h>
322 #include <cn3dshim.h>
323 #include <alignmgr.h>
324 
325 
326 static ButtoN Cn3D_bDisplayHighlight;
327 static Boolean Cn3D_NoSingleHL = FALSE;
328 static ButtoN Cn3D_bAlignOn, Cn3D_bUnalignOn;
329 static ButtoN Cn3D_bDisplayAlignedDomain;
330 static LisT Cn3D_lStruc;
331 static LisT Cn3D_lFeature;
332 
333 static DomainInfo **domaindata;
334 static Int4 iDomainCount = 0;
335 
336 Boolean Cn3D_fAlignOn, Cn3D_fUnalignOn; /* globals  for above buttons */
337 
338 static ButtoN Cn3D_altConfIdOverlay;
allowAltConfIdOverlay(void)339 Nlm_Boolean allowAltConfIdOverlay(void)
340 {
341     return GetStatus(Cn3D_altConfIdOverlay);
342 }
343 
344 static ButtoN Cn3D_bDisplayApply;
345 
346 
347 /*-------------------------------------------------------------------*/
348 
Cn3DCheckNoSingleHighlight(PFB pfbThis,Int4 iModel,Int4 iIndex,Pointer ptr)349 void LIBCALLBACK Cn3DCheckNoSingleHighlight(PFB pfbThis, Int4 iModel,
350                                             Int4 iIndex, Pointer ptr)
351 {
352     PMGD pmgdThis = NULL;
353     PDNMG pdnmgThis = NULL;
354 
355     pmgdThis = (PMGD) pfbThis;
356     if (pmgdThis->bHighlighted == 1)
357         Cn3D_NoSingleHL = FALSE;
358 }
359 
360 /*-----------------------------------------------*/
Cn3DCheckHighlighted(void)361 void Cn3DCheckHighlighted(void)
362 {
363     PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
364     PMSD pmsdMaster = NULL, pmsdSlave = NULL;
365 
366     /* replace old function which depends on ObjMgr */
367     /* by doing so, highlight for non ObjMgr registered residues will */
368     /* also be picked up when do Cn3D_Redraw */
369 
370     Cn3D_NoSingleHL = TRUE;
371 
372     pdnmsMaster = GetSelectedModelstruc();
373     if (pdnmsMaster != NULL) {
374         pmsdMaster = pdnmsMaster->data.ptrvalue;
375 
376         TraverseGraphs(pdnmsMaster, 0, 0, NULL,
377                        Cn3DCheckNoSingleHighlight);
378         pdnmsSlave = pmsdMaster->pdnmsSlaves;
379         while (pdnmsSlave && Cn3D_NoSingleHL) {
380             TraverseGraphs(pdnmsSlave, 0, 0, NULL,
381                            Cn3DCheckNoSingleHighlight);
382             pdnmsSlave = pdnmsSlave->next;
383         }
384     }
385 }
386 
387 /*---------------------------------------------------------*/
Cn3D_SelectDomainProc(LisT l)388 static void Cn3D_SelectDomainProc(LisT l)
389 {
390     SetStatus(Cn3D_bDisplayAlignedDomain, FALSE);
391 }
392 
393 /*---------------------------------------------------------*/
394 /* fill out domain list */
Cn3D_ListDomainProc(void)395 NLM_EXTERN void Cn3D_ListDomainProc(void)
396 {
397     Char MolName[20];
398     Int4 iCount = 0, iCountActive = 0;
399 
400     Reset(Cn3D_lFeature);
401 
402     for (iCount = 0; iCount < iDomainCount; iCount++) {
403         domaindata[iCount]->bVisibleParent =
404             GetItemStatus(Cn3D_lStruc,
405                           domaindata[iCount]->iStrucIndex + 1);
406     }
407 
408     for (iCount = 0; iCount < iDomainCount; iCount++) {
409         if (domaindata[iCount]->iDomain == 0)
410             sprintf(MolName, "%4s  %2s", domaindata[iCount]->pcPDBName,
411                     domaindata[iCount]->pcMolName);
412         else
413             sprintf(MolName, "%4s  %2s  %2d",
414                     domaindata[iCount]->pcPDBName,
415                     domaindata[iCount]->pcMolName,
416                     domaindata[iCount]->iDomain);
417         if (domaindata[iCount]->bVisibleParent) {
418             ListItem(Cn3D_lFeature, (CharPtr) MolName);
419             iCountActive++;
420             if (!GetStatus(Cn3D_bDisplayAlignedDomain))
421                 SetItemStatus(Cn3D_lFeature, iCountActive,
422                               domaindata[iCount]->bVisible);
423             else {
424                 if (domaindata[iCount]->bAligned) {
425                     SetItemStatus(Cn3D_lFeature, iCountActive, TRUE);
426                     domaindata[iCount]->bVisible = TRUE;
427                 } else if (!domaindata[iCount]->bAligned) {
428                     SetItemStatus(Cn3D_lFeature, iCountActive, FALSE);
429                     domaindata[iCount]->bVisible = FALSE;
430                 }
431             }
432         }
433 
434     }
435     return;
436 }
437 
438 /*---------------------------------------------------------*/
Cn3D_ListAlignedDomainProc(ButtoN b)439 static void Cn3D_ListAlignedDomainProc(ButtoN b)
440 {
441     Cn3D_ListDomainProc();
442 }
443 
444 /*---------------------------------------------------------*/
FillFeatureListProc(LisT l)445 static void FillFeatureListProc(LisT l)
446 {
447     Cn3D_ListDomainProc();
448 }
449 
450 /*---------------------------------------------------------*/
SetDomainParentStatus(Int4 Index,Byte bVisible)451 static void SetDomainParentStatus(Int4 Index, Byte bVisible)
452 {
453     Int4 iCount = 0;
454 
455     for (iCount = 0; iCount < iDomainCount; iCount++) {
456         if (domaindata[iCount]->iStrucIndex == Index)
457             domaindata[iCount]->bVisibleParent = bVisible;
458     }
459 
460 }
461 
462 /*---------------------------------------------------------*/
Cn3D_ReSetModVisibleStatus(PVNMO pvnmoThis,Byte bVisible)463 static void Cn3D_ReSetModVisibleStatus(PVNMO pvnmoThis, Byte bVisible)
464 {
465     PMOD pmodThis = NULL;
466 
467     while (pvnmoThis) {
468         pmodThis = (PMOD) pvnmoThis->data.ptrvalue;
469         pmodThis->bVisible = bVisible;
470         pvnmoThis = pvnmoThis->next;
471     }
472 }
473 
474 /*---------------------------------------------------------*/
Cn3D_ReSetMmVisibleStatus(PDNMM pdnmmHead,Byte bVisible)475 static void Cn3D_ReSetMmVisibleStatus(PDNMM pdnmmHead, Byte bVisible)
476 {
477     PMMD pmmdThis = NULL;
478     PDNMG pdnmg = NULL;
479     PMGD pmgd = NULL;
480 
481     for (; pdnmmHead; pdnmmHead = pdnmmHead->next) {
482         pmmdThis = pdnmmHead->data.ptrvalue;
483         if (pmmdThis) {
484             if (pmmdThis->bWhat != (Byte) AM_PROT
485                 && pmmdThis->bWhat != (Byte) AM_RNA
486                 && pmmdThis->bWhat != (Byte) AM_DNA)
487                 continue;
488 
489             Cn3D_SetVisible(Cn3D_ColorData.pDDVColorGlobal, pmmdThis, bVisible);
490 
491             for (pdnmg = pmmdThis->pdnmgHead; pdnmg != NULL;
492                  pdnmg = pdnmg->next) {
493                 pmgd = (PMGD) pdnmg->data.ptrvalue;
494                 pmgd->bVisible = bVisible;
495             }
496         }
497     }
498 }
499 
500 /*---------------------------------------------------------*/
Cn3D_ReSetVisibleStatus(void)501 static void Cn3D_ReSetVisibleStatus(void)
502 {
503     PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
504     PMSD pmsdMaster = NULL, pmsdSlave = NULL;
505     PDNMM pdnmmHead = NULL;
506     PMMD pmmdThis = NULL;
507     PDNMG pdnmg = NULL;
508     PMGD pmgd = NULL;
509 
510     PVNMO pvnmoThis = NULL;
511 
512     pdnmsMaster = GetSelectedModelstruc();
513     if (pdnmsMaster != NULL) {
514         pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
515 
516         pmsdMaster->bVisible = 1;
517 
518         pvnmoThis = pmsdMaster->pvnmoHead;
519         Cn3D_ReSetModVisibleStatus(pvnmoThis, 1);
520 
521         pdnmmHead = pmsdMaster->pdnmmHead;
522         Cn3D_ReSetMmVisibleStatus(pdnmmHead, 1);
523 
524         pdnmsSlave = pmsdMaster->pdnmsSlaves;
525         while (pdnmsSlave) {
526             pmsdSlave = (PMSD) pdnmsSlave->data.ptrvalue;
527 
528             pmsdSlave->bVisible = 1;
529 
530             pvnmoThis = pmsdSlave->pvnmoHead;
531             Cn3D_ReSetModVisibleStatus(pvnmoThis, 1);
532 
533             pdnmmHead = pmsdSlave->pdnmmHead;
534             Cn3D_ReSetMmVisibleStatus(pdnmmHead, 1);
535 
536             pdnmsSlave = pdnmsSlave->next;
537         }
538     }
539 
540 }
541 
542 /* sets values in the show/hide list for structures */
Cn3D_SetStrucList(void)543 NLM_EXTERN void Cn3D_SetStrucList(void)
544 {
545     PDNMS pdnmsMaster, pdnmsSlave;
546     PMSD pmsdMaster, pmsdSlave;
547     Int4 iCount = 0;
548 
549     Reset(Cn3D_lStruc);
550     pdnmsMaster = GetSelectedModelstruc();
551     if (pdnmsMaster != NULL) {
552         pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
553         ListItem(Cn3D_lStruc, pmsdMaster->pcPDBName);
554         SetItemStatus(Cn3D_lStruc, iCount + 1, pmsdMaster->bVisible);
555 
556         iCount++;
557 
558         pdnmsSlave = pmsdMaster->pdnmsSlaves;
559         while (pdnmsSlave) {
560             pmsdSlave = (PMSD) pdnmsSlave->data.ptrvalue;
561             ListItem(Cn3D_lStruc, pmsdSlave->pcPDBName);
562             SetItemStatus(Cn3D_lStruc, iCount + 1, pmsdSlave->bVisible);
563 
564             iCount++;
565 
566             pdnmsSlave = pdnmsSlave->next;
567         }
568     }
569 }
570 
571 /*---------------------------------------------------------*/
AssignDomainAlignedStatusForStrucSeqs(void)572 void AssignDomainAlignedStatusForStrucSeqs(void)
573 {
574     PDNMS pdnmsMaster = NULL;
575     PMSD pmsdMaster = NULL;
576     PDNMM pdnmmHead = NULL, pdnmmHead_temp = NULL;
577     PMMD pmmdThis = NULL;
578     PDNMG pdnmg = NULL;
579     PMGD pmgd = NULL;
580 
581     Int4 iCount = 0, iCountChain = 0;
582 
583     pdnmsMaster = GetSelectedModelstruc();
584     if (pdnmsMaster == NULL)
585         return;
586 
587     pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
588     pdnmmHead = pmsdMaster->pdnmmHead;
589 
590     for (iCount = 0; iCount < iDomainCount; iCount++) {
591         domaindata[iCount]->bAligned = FALSE;
592         pdnmmHead_temp = pdnmmHead;
593 
594         iCountChain = 0;
595 
596         while (pdnmmHead_temp) {
597             pmmdThis = pdnmmHead_temp->data.ptrvalue;
598             if (pmmdThis == NULL)
599                 break;
600             if (pmmdThis->bWhat != (Byte) AM_PROT
601                 && pmmdThis->bWhat != (Byte) AM_RNA
602                 && pmmdThis->bWhat != (Byte) AM_DNA)
603                 goto setout1;
604 
605             if (domaindata[iCount]->iChainIndex == iCountChain) {
606                 for (pdnmg = pmmdThis->pdnmgHead; pdnmg != NULL;
607                      pdnmg = pdnmg->next) {
608                     pmgd = (PMGD) pdnmg->data.ptrvalue;
609                     if (pmgd->iDomain == domaindata[iCount]->iDomain
610                         && pmgd->bReserved) {
611                         domaindata[iCount]->bAligned = TRUE;
612                         goto setout2;
613                     }
614                 }
615             }
616 
617           setout1:
618             pdnmmHead_temp = pdnmmHead_temp->next;
619             iCountChain++;
620         }
621       setout2:
622         continue;
623     }
624 
625 }
626 
627 /*---------------------------------------------------------*/
AssignDomainAlignedStatus(void)628 void AssignDomainAlignedStatus(void)
629 {
630     Int4 iCount = 0, iCountStruc = 0;
631     PDNMS pdnmsMaster = NULL;
632     PMSD pmsdMaster = NULL;
633     BiostrucAnnotSetPtr pbsaThis = NULL;
634     BiostrucFeatureSetPtr pbsfsThis = NULL;
635     BiostrucFeaturePtr pbsfThis = NULL;
636 
637     Int2 iDomainMaster = 0, iDomainSlave = 0;
638 
639     pdnmsMaster = GetSelectedModelstruc();
640     if (!pdnmsMaster)
641         return;
642     else
643         pmsdMaster = pdnmsMaster->data.ptrvalue;
644 
645     pbsaThis = pmsdMaster->psaStrucAlignment;
646     if (pbsaThis == NULL)
647         return;
648     pbsfsThis = pbsaThis->features;
649     iDomainMaster = (Int2) (pbsfsThis->id % 100);
650 
651     for (iCount = 0; iCount < iDomainCount; iCount++) {
652         pbsfThis = pbsfsThis->features;
653         iCountStruc = 0;
654         while (pbsfThis) {
655             iDomainSlave =
656                 (Int2) (((pbsfThis->id - pbsfThis->id % 10) / 10) % 100);
657             iCountStruc++;
658 
659             if (domaindata[iCount]->iStrucIndex == 0) {
660                 if (
661                     (StringNCmp
662                      (pbsfThis->name, domaindata[iCount]->pcPDBName,
663                       4) == 0)
664                     && (pbsfThis->name[4] ==
665                         domaindata[iCount]->pcMolName[0])) {
666 /*            if((Char) pbsfThis->name[5] == '0'){   */
667                     if (iDomainMaster == 0) {
668                         domaindata[iCount]->bAligned = TRUE;
669                     }
670                         else if (iDomainMaster ==
671                                  domaindata[iCount]->iDomain) {
672                         domaindata[iCount]->bAligned = TRUE;
673                     }
674                 }
675             } else if (domaindata[iCount]->iStrucIndex == iCountStruc) {
676                 if (
677                     (StringNCmp
678                      (pbsfThis->name + 7, domaindata[iCount]->pcPDBName,
679                       4) == 0)
680                     && (pbsfThis->name[11] ==
681                         domaindata[iCount]->pcMolName[0])) {
682                     if (iDomainSlave == 0) {
683                         domaindata[iCount]->bAligned = TRUE;
684                     } else if (iDomainSlave == domaindata[iCount]->iDomain) {
685                         domaindata[iCount]->bAligned = TRUE;
686                     }
687                 }
688             }
689 
690             pbsfThis = pbsfThis->next;
691         }
692     }
693 
694 }
695 
696 /*---------------------------------------------------------*/
Cn3D_CountDomainProc(void)697 void LIBCALL Cn3D_CountDomainProc(void)
698 {
699     Int4 iCount = 0;
700     Int4 idom = 0;
701     Int4 iCountStruc = 0, iCountChain = 0;
702 
703     PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
704     PMSD pmsdMaster = NULL, pmsdSlave = NULL;
705     PDNMM pdnmmHead = NULL;
706     PMMD pmmdThis = NULL;
707     PDNMG pdnmg = NULL;
708     PMGD pmgd = NULL;
709 
710     Boolean EncounterZeroDomain = FALSE;
711 
712     pdnmsMaster = GetSelectedModelstruc();
713 
714     if (pdnmsMaster == NULL)
715         return;
716 
717     if (pdnmsMaster != NULL) {
718         pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
719         pdnmmHead = pmsdMaster->pdnmmHead;
720 
721         while (pdnmmHead) {
722             pmmdThis = pdnmmHead->data.ptrvalue;
723             if (pmmdThis) {
724                 if (pmmdThis->bWhat != (Byte) AM_PROT
725                     && pmmdThis->bWhat != (Byte) AM_RNA
726                     && pmmdThis->bWhat != (Byte) AM_DNA)
727                     goto pre_setout1;
728 
729                 idom = 0;
730 
731                 EncounterZeroDomain = FALSE;
732                 for (pdnmg = pmmdThis->pdnmgHead; pdnmg != NULL;
733                      pdnmg = pdnmg->next) {
734                     pmgd = (PMGD) pdnmg->data.ptrvalue;
735                     if (!EncounterZeroDomain) {
736                         if (pmgd->iDomain == 0) {
737                             iCount++;
738                             EncounterZeroDomain = TRUE;
739                         }
740                     }
741                     if (pmgd->iDomain > idom) {
742                         idom = (Int4) pmgd->iDomain;
743                         iCount++;
744                     }
745                 }
746 
747             }
748           pre_setout1:
749             pdnmmHead = pdnmmHead->next;
750         }
751 
752         pdnmsSlave = pmsdMaster->pdnmsSlaves;
753         while (pdnmsSlave) {
754             pmsdSlave = (PMSD) pdnmsSlave->data.ptrvalue;
755             pdnmmHead = pmsdSlave->pdnmmHead;
756 
757             while (pdnmmHead) {
758                 pmmdThis = pdnmmHead->data.ptrvalue;
759                 if (pmmdThis) {
760                     if (pmmdThis->bWhat != (Byte) AM_PROT
761                         && pmmdThis->bWhat != (Byte) AM_RNA
762                         && pmmdThis->bWhat != (Byte) AM_DNA)
763                         goto pre_setout2;
764 
765                     idom = 0;
766 
767                     EncounterZeroDomain = FALSE;
768 
769                     for (pdnmg = pmmdThis->pdnmgHead; pdnmg != NULL;
770                          pdnmg = pdnmg->next) {
771                         pmgd = (PMGD) pdnmg->data.ptrvalue;
772                         if (!EncounterZeroDomain) {
773                             if (pmgd->iDomain == 0) {
774                                 iCount++;
775                                 EncounterZeroDomain = TRUE;
776                             }
777                         }
778                         pmgd = (PMGD) pdnmg->data.ptrvalue;
779                         if (pmgd->iDomain > idom) {
780                             idom = (Int4) pmgd->iDomain;
781                             iCount++;
782                         }
783                     }
784 
785                 }
786               pre_setout2:
787                 pdnmmHead = pdnmmHead->next;
788             }
789 
790             pdnmsSlave = pdnmsSlave->next;
791         }
792     }
793 
794     iDomainCount = iCount;
795 
796     /* to allocate memory for domaindata */
797 
798     domaindata =
799         (Pointer) MemNew((size_t) (iDomainCount * sizeof(Pointer)));
800     for (iCount = 0; iCount < iDomainCount; iCount++) {
801         domaindata[iCount] = (DomainInfoPtr) MemNew(sizeof(DomainInfo));
802     }
803 
804     /* to load pdbname, chain id, domain id into domaindata */
805 
806     iCount = 0;
807     iCountStruc = 0;
808     iCountChain = 0;
809 
810     pdnmsMaster = GetSelectedModelstruc();
811     if (pdnmsMaster != NULL) {
812         pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
813         pdnmmHead = pmsdMaster->pdnmmHead;
814 
815         while (pdnmmHead) {
816             pmmdThis = pdnmmHead->data.ptrvalue;
817             if (pmmdThis) {
818                 if (pmmdThis->bWhat != (Byte) AM_PROT
819                     && pmmdThis->bWhat != (Byte) AM_RNA
820                     && pmmdThis->bWhat != (Byte) AM_DNA)
821                     goto setout1;
822                 Cn3D_SetVisible(Cn3D_ColorData.pDDVColorGlobal, pmmdThis,
823                                 TRUE);
824 
825                 idom = 0;
826 
827                 EncounterZeroDomain = FALSE;
828 
829                 for (pdnmg = pmmdThis->pdnmgHead; pdnmg != NULL;
830                      pdnmg = pdnmg->next) {
831                     pmgd = (PMGD) pdnmg->data.ptrvalue;
832                     if (!EncounterZeroDomain) {
833                         if (pmgd->iDomain == 0) {
834                             StringCpy(domaindata[iCount]->pcPDBName,
835                                       pmsdMaster->pcPDBName);
836                             StringCpy(domaindata[iCount]->pcMolName,
837                                       pmmdThis->pcMolName);
838                             domaindata[iCount]->iDomain = 0;
839                             domaindata[iCount]->iStrucIndex = iCountStruc;
840                             domaindata[iCount]->iChainIndex = iCountChain;
841                             domaindata[iCount]->bVisible = TRUE;
842                             domaindata[iCount]->bVisibleParent = TRUE;
843                             iCount++;
844                             EncounterZeroDomain = TRUE;
845                         }
846                     }
847                     if (pmgd->iDomain > idom) {
848                         idom = (Int4) pmgd->iDomain;
849                         StringCpy(domaindata[iCount]->pcPDBName,
850                                   pmsdMaster->pcPDBName);
851                         StringCpy(domaindata[iCount]->pcMolName,
852                                   pmmdThis->pcMolName);
853                         domaindata[iCount]->iDomain = pmgd->iDomain;
854                         domaindata[iCount]->iStrucIndex = iCountStruc;
855                         domaindata[iCount]->iChainIndex = iCountChain;
856                         domaindata[iCount]->bVisible = TRUE;
857                         domaindata[iCount]->bVisibleParent = TRUE;
858 
859                         iCount++;
860                     }
861                 }
862                 iCountChain++;
863             }
864           setout1:
865             pdnmmHead = pdnmmHead->next;
866         }
867 
868         iCountStruc++;
869         pdnmsSlave = pmsdMaster->pdnmsSlaves;
870         while (pdnmsSlave) {
871             pmsdSlave = (PMSD) pdnmsSlave->data.ptrvalue;
872             pdnmmHead = pmsdSlave->pdnmmHead;
873 
874             while (pdnmmHead) {
875                 pmmdThis = pdnmmHead->data.ptrvalue;
876                 if (pmmdThis) {
877                     if (pmmdThis->bWhat != (Byte) AM_PROT
878                         && pmmdThis->bWhat != (Byte) AM_RNA
879                         && pmmdThis->bWhat != (Byte) AM_DNA)
880                         goto setout2;
881 
882                     idom = 0;
883 
884                     EncounterZeroDomain = FALSE;
885 
886                     for (pdnmg = pmmdThis->pdnmgHead; pdnmg != NULL;
887                          pdnmg = pdnmg->next) {
888                         pmgd = (PMGD) pdnmg->data.ptrvalue;
889                         if (!EncounterZeroDomain) {
890                             if (pmgd->iDomain == 0) {
891                                 StringCpy(domaindata[iCount]->pcPDBName,
892                                           pmsdSlave->pcPDBName);
893                                 StringCpy(domaindata[iCount]->pcMolName,
894                                           pmmdThis->pcMolName);
895                                 domaindata[iCount]->iDomain = 0;
896                                 domaindata[iCount]->iStrucIndex =
897                                     iCountStruc;
898                                 domaindata[iCount]->iChainIndex =
899                                     iCountChain;
900                                 domaindata[iCount]->bVisible = TRUE;
901                                 domaindata[iCount]->bVisibleParent = TRUE;
902                                 iCount++;
903                                 EncounterZeroDomain = TRUE;
904                             }
905                         }
906                         if (pmgd->iDomain > idom) {
907                             idom = (Int4) pmgd->iDomain;
908                             StringCpy(domaindata[iCount]->pcPDBName,
909                                       pmsdSlave->pcPDBName);
910                             StringCpy(domaindata[iCount]->pcMolName,
911                                       pmmdThis->pcMolName);
912                             domaindata[iCount]->iDomain = pmgd->iDomain;
913                             domaindata[iCount]->iStrucIndex = iCountStruc;
914                             domaindata[iCount]->iChainIndex = iCountChain;
915                             domaindata[iCount]->bVisible = TRUE;
916                             domaindata[iCount]->bVisibleParent = TRUE;
917 
918                             iCount++;
919                         }
920 /*             if(pmgd->bReserved && !domaindata[iCount - 1]->bAligned) domaindata[iCount - 1]->bAligned = TRUE;  */
921                     }
922                     iCountChain++;
923                 }
924               setout2:
925                 pdnmmHead = pdnmmHead->next;
926             }
927 
928             iCountStruc++;
929             pdnmsSlave = pdnmsSlave->next;
930         }
931     }
932 
933     if (pmsdMaster->iMimeType == NcbiMimeAsn1_strucseqs) {
934         AssignDomainAlignedStatusForStrucSeqs();
935     } else
936         AssignDomainAlignedStatus();
937 }
938 
939 /*---------------------------------------------------------*/
SetDomainDataItemStatus(LisT l)940 static void SetDomainDataItemStatus(LisT l)
941 {
942     Int4 iCount = 0, iCountActive = 0;
943 
944     for (iCount = 0; iCount < iDomainCount; iCount++) {
945         if (domaindata[iCount]->bVisibleParent) {
946             domaindata[iCount]->bVisible =
947                 GetItemStatus(Cn3D_lFeature, iCountActive + 1);
948             iCountActive++;
949         }
950     }
951 
952     return;
953 }
954 
955 /*---------------------------------------------------------*/
iCountItemGet(PMSD pmsdThis,PMMD pmmdThis,PMGD pmgdThis,Int4 iCountStruc)956 Int4 iCountItemGet(PMSD pmsdThis, PMMD pmmdThis, PMGD pmgdThis,
957                    Int4 iCountStruc)
958 {
959     Int4 iCount = 0, iCountLive = 0;
960     Int2 iDomain = 0;
961 
962     if (pmgdThis == NULL)
963         iDomain = 0;
964     else
965         iDomain = pmgdThis->iDomain;
966 
967     for (iCount = 0; iCount < iDomainCount; iCount++) {
968         if (!domaindata[iCount]->bVisibleParent)
969             continue;
970         if (StringCmp(pmsdThis->pcPDBName, domaindata[iCount]->pcPDBName)
971             == 0
972             && StringCmp(pmmdThis->pcMolName,
973                          domaindata[iCount]->pcMolName) == 0
974             && iDomain == domaindata[iCount]->iDomain
975             && iCountStruc == domaindata[iCount]->iStrucIndex)
976             return (iCountLive + 1);
977         iCountLive++;
978 
979     }
980 
981     return 0;
982 }
983 
984 /*---------------------------------------------------------*/
fnAlignList(LisT l)985 NLM_EXTERN void fnAlignList(LisT l)
986 /* set the values of the alignment pane */
987 {
988     Int4 iCount = 0;
989     PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
990     PMSD pmsdMaster = NULL, pmsdSlave = NULL;
991     BiostrucFeaturePtr pbsfThis = NULL;
992     PDNMM pdnmmHead = NULL;
993     PMMD pmmdThis = NULL;
994     Byte bVisible = 0;
995     SeqIdPtr sipThis = NULL;
996     Uint2 entityID = 0, itemtype = 0;
997 
998 #ifndef _OPENGL
999     Cn3D_SaveActiveCam();
1000 #endif
1001 
1002     iCount = 0;
1003     pdnmsMaster = GetSelectedModelstruc();
1004     if (pdnmsMaster != NULL) {
1005 
1006         pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
1007 
1008         bVisible = pmsdMaster->bVisible;
1009         pmsdMaster->bVisible = GetItemStatus(Cn3D_lStruc, iCount + 1);
1010         SetDomainParentStatus(iCount, pmsdMaster->bVisible);
1011 
1012         pdnmmHead = pmsdMaster->pdnmmHead;
1013         Cn3D_ReSetMmVisibleStatus(pdnmmHead, pmsdMaster->bVisible);
1014 
1015         if (pmsdMaster->iMimeType != NcbiMimeAsn1_strucseqs) {
1016             TraverseGraphs(pdnmsMaster, 0, 0, NULL, fnClearMarkedResidues);
1017             pmsdMaster->bAligned = 0;
1018         }
1019         pdnmsSlave = pmsdMaster->pdnmsSlaves;
1020 
1021         if (pmsdMaster->psaStrucAlignment != NULL) {
1022             pbsfThis = pmsdMaster->psaStrucAlignment->features->features;
1023             iCount++;
1024             while (pdnmsSlave) {
1025                 pmsdSlave = (PMSD) pdnmsSlave->data.ptrvalue;
1026 
1027                 bVisible = pmsdSlave->bVisible;
1028 
1029                 TraverseGraphs(pdnmsSlave, 0, 0, NULL,
1030                                fnClearMarkedResidues);
1031 
1032                 pmsdSlave->bVisible =
1033                     GetItemStatus(Cn3D_lStruc, iCount + 1);
1034                 SetDomainParentStatus(iCount, pmsdSlave->bVisible);
1035 
1036                 if (pmsdMaster->bVisible && pmsdSlave->bVisible) {
1037                     fnMarkAlignedResidues(pdnmsMaster, pdnmsSlave,
1038                                           pbsfThis);
1039                     pmsdMaster->bAligned++;
1040                 }
1041                 pbsfThis = pbsfThis->next;
1042 
1043                 if (bVisible != pmsdSlave->bVisible) {
1044                     pdnmmHead = pmsdSlave->pdnmmHead;
1045                     Cn3D_ReSetMmVisibleStatus(pdnmmHead,
1046                                               pmsdSlave->bVisible);
1047                 }
1048 
1049                 iCount++;
1050                 pdnmsSlave = pdnmsSlave->next;
1051             }
1052         }
1053     }
1054 #ifndef _OPENGL
1055     Cn3D_v3d->is_zoomed = TRUE; /* keep the proteins from moving */
1056 #endif
1057 }
1058 
1059 
1060 /*---------------------------------------------------------*/
SynchronizeModVisibleStatus(PFB pfbThis)1061 static void SynchronizeModVisibleStatus(PFB pfbThis)
1062 {
1063     PMSD pmsdThis = NULL;
1064     PMMD pmmdThis = NULL;
1065     PDNMG pdnmg = NULL;
1066     PMGD pmgdThis = NULL;
1067 
1068     PVNMO pvnmoThis = NULL;
1069     PMOD pmodThis = NULL;
1070 
1071     ValNodePtr pvnThis = NULL;
1072 
1073     pmsdThis = ToMSDParent(pfbThis);
1074     pvnmoThis = pmsdThis->pvnmoHead;
1075 
1076     if (pfbThis->bMe == AM_MGD) {
1077         while (pvnmoThis) {
1078             pmodThis = pvnmoThis->data.ptrvalue;
1079             pmodThis->bVisible = 0;
1080             pvnThis = pmodThis->pvnContains;
1081             while (pvnThis) {
1082                 pmgdThis = (PMGD) pvnThis->data.ptrvalue;
1083                 if (GetStatus(Cn3D_bDisplayHighlight))
1084                     pmodThis->bVisible = (pmgdThis->bVisible && pmgdThis->bHighlighted);
1085                 else
1086                     pmodThis->bVisible = pmgdThis->bVisible;
1087                 if (pmodThis->bVisible == 1) break;
1088                 pvnThis = pvnThis->next;
1089             }
1090             pvnmoThis = pvnmoThis->next;
1091         }
1092     }
1093 
1094 /* not currently used...
1095     else if (pfbThis->bMe == AM_MMD) {
1096         pmmdThis = (PMMD) pfbThis;
1097         while (pvnmoThis) {
1098             pmodThis = pvnmoThis->data.ptrvalue;
1099             if (IsGraphNode((PFB) pmodThis->pvnContains->data.ptrvalue)) {
1100                 if (pmmdThis ==
1101                     GetParentMol((PFB) pmodThis->pvnContains->data.ptrvalue)) {
1102                     pmodThis->bVisible =
1103                         Cn3D_IsVisible(Cn3D_ColorData.pDDVColorGlobal, pmmdThis);
1104                 }
1105             }
1106             pvnmoThis = pvnmoThis->next;
1107         }
1108     }
1109 */
1110 }
1111 
1112 /*---------------------------------------------------------*/
ResetDisplayCtrls(void)1113 void LIBCALL ResetDisplayCtrls(void)
1114 /* set the values of the alignment pane */
1115 {
1116     Cn3D_ReSetVisibleStatus();
1117     Cn3D_SetStrucList();
1118 
1119     Cn3D_ListDomainProc();
1120 
1121     SetStatus(Cn3D_bAlignOn, Cn3D_fAlignOn);
1122     SetStatus(Cn3D_bUnalignOn, Cn3D_fUnalignOn);
1123 
1124     return;
1125 }
1126 
1127 
1128 /*---------------------------------------------------------*/
DisplayControls(Nlm_GrouP prnt)1129 GrouP LIBCALL DisplayControls(Nlm_GrouP prnt)
1130 {
1131     GrouP g, h;
1132     PrompT ppt1, /*ppt2,*/ ppt3, ppt4;
1133 
1134     g = HiddenGroup(prnt, -1, 0, NULL);
1135     if (!g)
1136         return NULL;
1137     SetGroupSpacing(g, 3, 9);
1138 #ifdef WIN_MOTIF
1139     SetGroupMargins(g, 4, 1);
1140     SetGroupSpacing(g, 2, 1);
1141 #else
1142     SetGroupMargins(g, 1, 1);
1143     SetGroupSpacing(g, 0, 0);
1144 #endif
1145 
1146     StaticPrompt(g, "", 0, stdLineHeight, systemFont, 'l');
1147     StaticPrompt(g, "", 0, stdLineHeight, systemFont, 'l');
1148 
1149     h = HiddenGroup(g, 0, -4, NULL);
1150     SetGroupSpacing(h, 30, 10);
1151 
1152     ppt1 =
1153         StaticPrompt(h, "Molecule", 0, stdLineHeight + 5, systemFont, 'c');
1154     Cn3D_lStruc = MultiList(h, 6, 10, FillFeatureListProc);
1155     StaticPrompt(h, "", 0, stdLineHeight, systemFont, 'l');
1156     StaticPrompt(h, "", 0, stdLineHeight, systemFont, 'l');
1157     AlignObjects(ALIGN_LEFT, (HANDLE) ppt1, (HANDLE) Cn3D_lStruc, NULL);
1158 
1159     ppt3 =
1160         StaticPrompt(h, "Domain", 0, stdLineHeight + 5, systemFont, 'c');
1161     Cn3D_bDisplayAlignedDomain =
1162         CheckBox(h, "Aligned Domain Only", Cn3D_ListAlignedDomainProc);
1163     Cn3D_lFeature = MultiList(h, 6, 8, Cn3D_SelectDomainProc);
1164     StaticPrompt(h, "", 0, stdLineHeight, systemFont, 'l');
1165     AlignObjects(ALIGN_LEFT, (HANDLE) ppt3, (HANDLE) Cn3D_lFeature, NULL);
1166 
1167     ppt4 =
1168         StaticPrompt(h, "Residue", 0, stdLineHeight + 5, systemFont, 'c');
1169     Cn3D_bAlignOn = CheckBox(h, "Aligned", NULL);
1170     Cn3D_bUnalignOn = CheckBox(h, "Unaligned", NULL);
1171     Cn3D_bDisplayHighlight =
1172         CheckBox(h, "Show Selected Only", NULL);
1173     AlignObjects(ALIGN_LEFT, (HANDLE) ppt4,
1174                  (HANDLE) Cn3D_bDisplayHighlight, NULL);
1175     SetStatus(Cn3D_bDisplayHighlight, FALSE);
1176     SetStatus(Cn3D_bAlignOn, Cn3D_fAlignOn);
1177     SetStatus(Cn3D_bUnalignOn, Cn3D_fUnalignOn);
1178 
1179     Cn3D_altConfIdOverlay = CheckBox(g,
1180         "Overlay uncorrelated conformer ensembles", NULL);
1181     AlignObjects(ALIGN_CENTER, (HANDLE) Cn3D_altConfIdOverlay, (HANDLE) g, NULL);
1182     SetStatus(Cn3D_altConfIdOverlay, TRUE);
1183 
1184     StaticPrompt(g, "", 0, stdLineHeight + 5, systemFont, 'c');
1185     Cn3D_bDisplayApply = PushButton(g, "Apply!", Cn3D_DisplayProc);
1186     AlignObjects(ALIGN_CENTER, (HANDLE) Cn3D_bDisplayApply, (HANDLE) h,
1187                  NULL);
1188 
1189     ResetDisplayCtrls();
1190 
1191     return g;
1192 }
1193 
SetResidueVisibilities(PDNMS pdnmsThis,Int4 iCountStruc,SeqAlignPtr salp)1194 static void SetResidueVisibilities(PDNMS pdnmsThis, Int4 iCountStruc, SeqAlignPtr salp)
1195 {
1196     PMSD pmsdThis;
1197     PDNMM pdnmmHead;
1198     PMMD pmmdThis = NULL;
1199     PDNMG pdnmg = NULL;
1200     PMGD pmgd = NULL;
1201     PVNMO pvnmoThis = NULL;
1202     Int4 currentRow = -1, currentAlignLoc = -2;
1203     Boolean bIsPorNA;
1204 
1205     pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
1206     pdnmmHead = pmsdThis->pdnmmHead;
1207 
1208     while (pdnmmHead) {
1209         pmmdThis = pdnmmHead->data.ptrvalue;
1210         if (pmmdThis) {
1211             bIsPorNA = (pmmdThis->bWhat == (Byte) AM_PROT ||
1212                         pmmdThis->bWhat == (Byte) AM_RNA ||
1213                         pmmdThis->bWhat == (Byte) AM_DNA);
1214 
1215             if (bIsPorNA)
1216                 Cn3D_SetVisible(Cn3D_ColorData.pDDVColorGlobal, pmmdThis, TRUE);
1217             else
1218                 pmmdThis->bVisible = TRUE;
1219 
1220             if (bIsPorNA && salp && pmmdThis->pSeqId)
1221                 currentRow = ViewMgr_TRow2VRow(salp, pmmdThis->iTargetRow);
1222             else
1223                 currentRow = -1;
1224 
1225             for (pdnmg = pmmdThis->pdnmgHead; pdnmg != NULL;
1226                     pdnmg = pdnmg->next) {
1227                 pmgd = (PMGD) pdnmg->data.ptrvalue;
1228 
1229                 /* first check to see if whole structure is visible */
1230                 if (bIsPorNA)
1231                     pmgd->bVisible = GetItemStatus(Cn3D_lFeature,
1232                                                    iCountItemGet(pmsdThis,
1233                                                                  pmmdThis, pmgd,
1234                                                                  iCountStruc));
1235                 else
1236                     pmgd->bVisible = TRUE;
1237 
1238                 if (pmgd->bVisible && GetStatus(Cn3D_bDisplayHighlight))
1239                     pmgd->bVisible = pmgd->bHighlighted;
1240 
1241                 if (bIsPorNA) {
1242                     if (salp && currentRow > 0)
1243                         currentAlignLoc = AlnMgrMapBioseqToSeqAlign(salp,
1244                                                                     pdnmg->choice - 1,
1245                                                                     currentRow,
1246                                                                     NULL);
1247                     if ((currentAlignLoc >= 0 && !Cn3D_fAlignOn) ||
1248                         (currentAlignLoc < 0 && !Cn3D_fUnalignOn))
1249                         pmgd->bVisible = 0;
1250                 }
1251             }
1252         }
1253 
1254         SynchronizeModVisibleStatus((PFB) pmgd);
1255         pdnmmHead = pdnmmHead->next;
1256     }
1257 }
1258 
1259 /*---------------------------------------------------------*/
Cn3D_DisplayProc(ButtoN b)1260 NLM_EXTERN void Cn3D_DisplayProc(ButtoN b)
1261 {
1262     LisT l = NULL;
1263     SeqAlignPtr salp = NULL;
1264     SeqAnnotPtr sanp;
1265     PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
1266     Int4 iCountStruc = 0;
1267 
1268     Cn3D_fAlignOn = GetStatus(Cn3D_bAlignOn);
1269     Cn3D_fUnalignOn = GetStatus(Cn3D_bUnalignOn);
1270     fnAlignList(l);
1271     SetDomainDataItemStatus(l);
1272 
1273     if (GetStatus(Cn3D_bDisplayHighlight)) {
1274         Cn3DCheckHighlighted();
1275         if (Cn3D_NoSingleHL)
1276             SetStatus(Cn3D_bDisplayHighlight, FALSE);
1277     }
1278 
1279     /* get pointer to current SeqAlign */
1280     for (sanp = Cn3D_ColorData.sap; sanp != NULL; sanp = sanp->next) {
1281         if (sanp->data != NULL) {
1282             salp = sanp->data;
1283             break;
1284         }
1285     }
1286 
1287     pdnmsMaster = GetSelectedModelstruc();
1288     if (pdnmsMaster) {
1289         SetResidueVisibilities(pdnmsMaster, iCountStruc, salp);
1290         iCountStruc++;
1291 
1292         pdnmsSlave = ((PMSD) pdnmsMaster->data.ptrvalue)->pdnmsSlaves;
1293         while (pdnmsSlave) {
1294             SetResidueVisibilities(pdnmsSlave, iCountStruc, salp);
1295             iCountStruc++;
1296             pdnmsSlave = pdnmsSlave->next;
1297         }
1298     }
1299 
1300 #ifndef _OPENGL
1301     Cn3D_v3d->is_zoomed = TRUE; /* keep the proteins from moving */
1302 #endif
1303     Cn3dObjMgrGetSelected();
1304     fnCn3D_RedrawWrapper(FALSE);
1305 
1306     return;
1307 
1308 }
1309 
1310 /*-------------------------------------------*/
ClearDomainData(void)1311 void ClearDomainData(void)
1312 {
1313     Int4 iCount = 0;
1314 
1315     for (iCount = 0; iCount < iDomainCount; iCount++) {
1316         MemFree(domaindata[iCount]);
1317     }
1318 
1319     if (domaindata) MemFree(domaindata);
1320 
1321     domaindata = NULL;
1322     iDomainCount = 0;
1323     SetStatus(Cn3D_bDisplayHighlight, FALSE);
1324     Cn3D_NoSingleHL = FALSE;
1325 
1326     return;
1327 }
1328 
1329