1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
|
/* mmdbapi.c
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information (NCBI)
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government do not place any restriction on its use or reproduction.
* We would, however, appreciate having the NCBI and the author cited in
* any work or product based on this material
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* ===========================================================================
*
* File Name: mmdbapi1.c
*
* Author: Christopher Hogue
*
* Version Creation Date: 08/19/95
*
* $Revision: 6.12 $
*
* File Description: MMDBAPI wrappers.
*
* Modifications:
* --------------------------------------------------------------------------
* Date Name Description of modification
* ------- ---------- -----------------------------------------------------
*
*
*
* $Log: mmdbapi.c,v $
* Revision 6.12 1999/08/04 21:21:25 lewisg
* made ClearStructure turn off neighbor mode in non-cn3d mode
*
* Revision 6.11 1999/03/05 22:43:59 vakatov
* Made ClearStructures() function be NLM_EXTERN -- for the DLL build on PC
*
* Revision 6.10 1999/03/05 20:22:31 kans
* ClearStructures clears neighbor bit
*
* Revision 6.9 1998/08/26 18:02:38 kans
* fixed -v -fd warnings
*
* Revision 6.8 1998/08/12 21:54:37 lewisg
* pick correct master in SetNeighborOn
*
* Revision 6.7 1998/05/06 16:25:27 lewisg
* get rid of clear all structures bug
*
* Revision 6.6 1998/04/16 00:30:00 lewisg
* get rid of dead code
*
* Revision 6.5 1998/04/05 04:29:01 lewisg
* make SetNeighborOn set the right slaves in cn3d mode
*
* Revision 6.4 1998/04/04 00:57:52 lewisg
* corrected several functions to behave properly in neighbor mode
*
* Revision 6.3 1998/03/13 22:34:18 lewisg
* fix neighbor mode
*
* Revision 6.2 1998/03/06 01:16:00 lewisg
* merge
*
* Revision 6.0 1997/08/25 18:10:48 madden
* Revision changed to 6.0
*
* Revision 5.0 1996/05/28 14:02:09 ostell
* Set to revision 5.0
*
* Revision 1.6 1996/05/15 17:01:35 hogue
* Fixed compiler warnings.
*
* Revision 1.5 1996/04/18 17:05:49 hogue
* Added neighbor mode functionality, setting Master & Slave structures. GetFirstModelstruc gets first slave now when in neighbor mode. Backing out of neighbor mode resets pdnmsSelected to the Master.
*
* Revision 1.4 1996/01/31 21:30:49 hogue
* Major changes to accomodate multiple structures, added mmdbAPI
* data structure, list pointers for traversing structures,
* list pointers for PFB selection holders, etc.
*
* Revision 1.3 1995/10/07 15:24:19 hogue
* Counting biostrucs from 0 to n.
*
* Revision 1.2 1995/10/05 20:22:42 hogue
* Fixed some structure tracking bugs, added ClearStructures()
*
* Revision 1.1 1995/09/20 13:45:47 kans
* Initial revision
*
*
* ==========================================================================
*/
/*
WARNING! The way some of these functions work is dependent on the setting of
pmmdbapi->fCn3D, which is set to TRUE when being run by Cn3D. This is to
eliminate the modality of those functions when running in Neighbor mode.
*/
#include <mmdbapi.h>
static pmmdbAPI pmmdbapi = NULL;
Boolean LIBCALL IsMMDBAPIOpen(void)
{
return (Boolean) (pmmdbapi != NULL);
}
void LIBCALL fnMMDBCn3Dmode (void) /* may I never live this down */
{
pmmdbapi->fCn3D = TRUE;
}
pmmdbAPI LIBCALL NewMMDBAPI(void)
{
pmmdbAPI papi = NULL;
papi = (pmmdbAPI)MemNew((size_t)(sizeof(mmdbAPI)));
return papi;
}
Int2 LIBCALL OpenMMDBAPI(Byte bExtent, CharPtr pcDictName)
{
if (pmmdbapi != NULL) return 1;
else pmmdbapi = NewMMDBAPI();
if (bExtent == 0)
pmmdbapi->bExtent = (Byte) POWER_VIEW;
else
pmmdbapi->bExtent = (Byte) bExtent;
if (pcDictName == NULL)
pmmdbapi->prgdDict = LoadDict(DICT_DEFAULT);
else
pmmdbapi->prgdDict = LoadDict(pcDictName);
if (!pmmdbapi->prgdDict)
{
ErrClear();
ErrPostEx(SEV_FATAL,0,0, "Unable to Load Residue Dictionary");
ErrShow();
return 0;
}
if (! (objmmdb1AsnLoad() && objmmdb2AsnLoad() && objmmdb3AsnLoad() ))
{
ErrClear();
ErrPostEx(SEV_FATAL,0,0, "Internal objmmdbNAsnLoad() Failure");
ErrShow();
return 0;
}
pmmdbapi->iLocalCount = 0;
pmmdbapi->iFeatureSet = 0;
pmmdbapi->iFeatureId = 0;
pmmdbapi->pvnsffHead = NULL;
pmmdbapi->pColorFunc = NULL;
pmmdbapi->Neighbor = FALSE;
pmmdbapi->fCn3D = FALSE;
return 1;
}
BiostrucPtr LIBCALL FetchBiostrucPDB(CharPtr pcAcession, Int4 iModelLevel, Int4 iMaxModels)
{
BiostrucPtr pbsTemp;
pbsTemp = FetchBS(pcAcession, INP_PDB_ACCESSION, iModelLevel,
iMaxModels, pmmdbapi->bExtent);
return pbsTemp;
}
PDNMS LIBCALL MakeAModelstruc(BiostrucPtr pbsThis)
{
PDNMS pdnmsTemp = NULL;
PDNMS pdnmsCount = NULL;
PMSD pmsdThis = NULL;
PMSD pmsdMaster = NULL;
Int4 iCount = 0;
if (!pmmdbapi)
{
ErrClear();
ErrPostEx(SEV_FATAL,0,0, "MMDBAPI Not Initialized\n Use InitMMDBAPI() \n");
ErrShow();
return pdnmsTemp;
}
if (!pbsThis) return pdnmsTemp;
if (pmmdbapi->Neighbor && pmmdbapi->pdnmsMaster)
{
pmsdMaster = (PMSD) pmmdbapi->pdnmsMaster->data.ptrvalue;
pmmdbapi->iLocalCount++;
pdnmsTemp = Biostruc2Modelstruc(&pmsdMaster->pdnmsSlaves, pbsThis, pmmdbapi->prgdDict,
pmmdbapi->bExtent, pmmdbapi->iLocalCount, NULL, (Int2)0);
}
else
{
pmmdbapi->iLocalCount++;
pdnmsTemp = Biostruc2Modelstruc(&pmmdbapi->pdnmsMain, pbsThis, pmmdbapi->prgdDict,
pmmdbapi->bExtent, pmmdbapi->iLocalCount, NULL, (Int2)0);
}
if (!pdnmsTemp)
{
pmmdbapi->iLocalCount--; /* back it off the counter */
return pdnmsTemp; /* NOTE THE BIOSTRUC pbsThis is FREED if this fails!!*/
}
if (pmmdbapi->Neighbor)
{
pmmdbapi->pdnmsSlave = pdnmsTemp;
pmmdbapi->pdnmsSelected = pmmdbapi->pdnmsMaster;
}
else pmmdbapi->pdnmsSelected = pdnmsTemp;
pmsdThis = (PMSD) pdnmsTemp->data.ptrvalue;
pmsdThis->iHashChange = MakeHashChange(pdnmsTemp);
AssignBackBone(pdnmsTemp);
AssignVirtual(pdnmsTemp);
AssignIons(pdnmsTemp);
return pdnmsTemp;
}
PDNMS LIBCALL GetPDNMSMain(void)
{
return pmmdbapi->pdnmsMain;
}
PRGD LIBCALL GetPRGDDictionary(void)
{
return pmmdbapi->prgdDict;
}
void LIBCALL ChangeMMDBAPIbExtent(Byte bExtent)
{
pmmdbapi->bExtent = bExtent;
}
Byte LIBCALL GetMMDBAPIbExtent(void)
{
return pmmdbapi->bExtent;
}
Int4 LIBCALL MakeHashChange(PDNMS pdnmsThis)
{
PMSD pmsdThis = NULL;
Int4 iHashCalc = 0;
Int4 iAtomLocs = 0;
if (!pdnmsThis) return iHashCalc;
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
iAtomLocs = AssignAtomLocId(pdnmsThis);
if (!(pmsdThis->bUpdate & (Byte) AM_CHANGED))
return pmsdThis->iMMDBid;
/* only changed if dirty bit set ... */
iHashCalc = pmsdThis->iMMDBid + pmsdThis->iModels + pmsdThis->iFeatures +
pmsdThis->iObjCount + pmsdThis->iDensCount + 100000 + iAtomLocs;
iHashCalc++; /* inc by one... for incremental changes (eg transform'ns) */
return iHashCalc;
}
Int4 LIBCALL CountModelstrucs(void)
{
Int4 iCount = 0;
PDNMS pdnmsCount = NULL;
if (!pmmdbapi) return iCount;
pdnmsCount = pmmdbapi->pdnmsMain;
while (pdnmsCount)
{
iCount++;
pdnmsCount = pdnmsCount->next;
}
return iCount;
}
void LIBCALL FreeAModelstruc(PDNMS pdnmsThis)
{
Int2 iLocalId;
ValNodePtr pvnKillSelectList = NULL;
iLocalId = (Int2) pdnmsThis->choice;
pvnKillSelectList = ValNodeExtractList(&pmmdbapi->pvnPFBSelect, iLocalId);
ValNodeFree(pvnKillSelectList); /* selection list purged for this Modelstruc */
if (pdnmsThis == pmmdbapi->pdnmsSelected)
pmmdbapi->pdnmsSelected = NULL;
if (pdnmsThis == pmmdbapi->pdnmsPrevious)
pmmdbapi->pdnmsPrevious = NULL;
if (pdnmsThis == pmmdbapi->pdnmsSlave)
pmmdbapi->pdnmsSlave = NULL;
if (pdnmsThis == pmmdbapi->pdnmsHolder)
pmmdbapi->pdnmsHolder = pdnmsThis->last;
if(AreNeighborsOn() && pdnmsThis != pmmdbapi->pdnmsMaster)
FreeDNMS(((PMSD)(pmmdbapi->pdnmsMaster->data.ptrvalue))->pdnmsSlaves, pdnmsThis);
else
{
if (pdnmsThis == pmmdbapi->pdnmsMaster) pmmdbapi->pdnmsMaster = NULL;
pmmdbapi->pdnmsMain = FreeDNMS(pmmdbapi->pdnmsMain, pdnmsThis);
}
}
NLM_EXTERN void LIBCALL ClearStructures(void)
{
PDNMS pdnmsThis = NULL;
if (!pmmdbapi) return;
pdnmsThis = GetFirstModelstruc();
if (!pdnmsThis) return;
FreeListDNMS(pdnmsThis);
if (!pmmdbapi->Neighbor || pmmdbapi->fCn3D)
{
pmmdbapi->pdnmsMain = NULL;
pmmdbapi->pdnmsMaster = NULL;
}
pmmdbapi->Neighbor = 0;
pmmdbapi->pdnmsSlave = NULL;
pmmdbapi->pdnmsHolder = NULL;
pmmdbapi->pdnmsSelected = NULL;
pmmdbapi->pdnmsPrevious = NULL;
ValNodeFree(pmmdbapi->pvnPFBSelect);
pmmdbapi->pvnPFBSelect = NULL;
pmmdbapi->pvnUndoMark = NULL;
/* lyg. no freeing of feature data in pmmdbapi. Is this a good idea? */
}
void LIBCALL CloseMMDBAPI(void)
{
if (!pmmdbapi) return;
if (pmmdbapi->pdnmsMain) FreeListDNMS(pmmdbapi->pdnmsMain);
if (pmmdbapi->pvnPFBSelect) ValNodeFree(pmmdbapi->pvnPFBSelect);
if (pmmdbapi->prgdDict) BiostrucResidueGraphSetFree(pmmdbapi->prgdDict);
if (pmmdbapi->pvnsffHead) FreeListVNSFF(pmmdbapi->pvnsffHead);
if (pmmdbapi) MemFree(pmmdbapi);
return;
}
CharPtr LIBCALL GetStrucStrings(PDNMS pdnmsThis, Int4 iPickType)
{
PMSD pmsdThis;
if (!pdnmsThis) pdnmsThis = pmmdbapi->pdnmsMain;
if (!pdnmsThis) return NULL;
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
if (pmsdThis->bMe != (Byte) AM_MSD) return NULL;
if (iPickType == LONG_NAME) return (pmsdThis->pcChemName);
if (iPickType == PDB_ACC) return (pmsdThis->pcPDBName);
if (iPickType == PDB_CLASS) return (pmsdThis->pcPdbClass);
if (iPickType == PDB_SOURCE) return (pmsdThis->pcPdbSource);
return NULL;
}
void LIBCALL SetSelectedModelstruc(PDNMS pdnmsThis)
{
/* doesn't check to see if structure is a really a slave if Neighbor mode on */
if (pmmdbapi->Neighbor == TRUE && !(pmmdbapi->fCn3D))
{
pmmdbapi->pdnmsSlave = pdnmsThis;
pmmdbapi->pdnmsSelected = pdnmsThis;
}
else
pmmdbapi->pdnmsSelected = pdnmsThis;
}
void LIBCALL SetNeighborOn(void)
{
if (!pmmdbapi->pdnmsMaster)
pmmdbapi->pdnmsMaster = GetSelectedModelstruc();
if ( pmmdbapi->pdnmsMaster && !(pmmdbapi->fCn3D))
{
pmmdbapi->Neighbor = TRUE;
if (!pmmdbapi->pdnmsSlave)
{
pmmdbapi->pdnmsSlave = GetFirstModelstruc(); /* NULL if none loaded */
}
else pmmdbapi->Neighbor = FALSE;
}
else
{
pmmdbapi->pdnmsMaster = GetSelectedModelstruc();
if (pmmdbapi->pdnmsMaster)
{
pmmdbapi->pdnmsSlave = ((PMSD)(pmmdbapi->pdnmsMaster->data.ptrvalue))->pdnmsSlaves;
pmmdbapi->Neighbor = TRUE;
}
}
}
Boolean LIBCALL AreNeighborsOn(void)
{
return pmmdbapi->Neighbor;
}
void LIBCALL SetNeighborOff(void)
{
pmmdbapi->pdnmsSelected = pmmdbapi->pdnmsMaster;
pmmdbapi->Neighbor = FALSE;
pmmdbapi->pdnmsSlave = NULL;
}
PDNMS LIBCALL GetSelectedModelstruc(void)
{
if (pmmdbapi->Neighbor == TRUE && !(pmmdbapi->fCn3D))
return pmmdbapi->pdnmsSlave;
else
return pmmdbapi->pdnmsSelected;
}
PDNMS LIBCALL SwapModelstruc(void)
{
PDNMS pdnmsTemp;
pdnmsTemp = pmmdbapi->pdnmsSelected;
pmmdbapi->pdnmsSelected = pmmdbapi->pdnmsPrevious;
pmmdbapi->pdnmsPrevious = pdnmsTemp;
return pmmdbapi->pdnmsSelected;
}
void LIBCALL SetMasterModelstruc(PDNMS pdnmsThis)
{
pmmdbapi->pdnmsMaster = pdnmsThis;
}
PDNMS LIBCALL GetMasterModelstruc(void)
{
return pmmdbapi->pdnmsMaster;
}
void LIBCALL SetSlaveModelstruc(PDNMS pdnmsThis)
{
pmmdbapi->pdnmsSlave = pdnmsThis;
}
PDNMS LIBCALL GetSlaveModelstruc(void)
{
return pmmdbapi->pdnmsSlave;
}
/**************************************************/
/* GetFirstModelstruc, GetNextModelstruc and */
/* GetPreviousModelstruc are provided to walk */
/* the doubly-linked list of structures that */
/* MMDBAPI has in memory... */
/* SetHolderModelstruc allows one to set the */
/* pointer to any of the structures */
/**************************************************/
PDNMS LIBCALL GetFirstModelstruc(void)
{
PMSD pmsdThis = NULL;
PDNMS pdnmsThis = NULL;
if (pmmdbapi->Neighbor && !(pmmdbapi->fCn3D))
{
pdnmsThis = GetMasterModelstruc();
if (pdnmsThis)
{
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
pmmdbapi->pdnmsHolder = pmsdThis->pdnmsSlaves;
return pmsdThis->pdnmsSlaves;
}
else return NULL;
}
pmmdbapi->pdnmsHolder = pmmdbapi->pdnmsMain;
return pmmdbapi->pdnmsMain;
}
void LIBCALL SetHolderModelstruc(PDNMS pdnmsThis)
{
pmmdbapi->pdnmsHolder = pdnmsThis;
}
PDNMS LIBCALL GetNextModelstruc(void)
{
if (pmmdbapi->pdnmsHolder)
{
pmmdbapi->pdnmsHolder = pmmdbapi->pdnmsHolder->next;
return pmmdbapi->pdnmsHolder;
}
return NULL;
}
PDNMS LIBCALL GetPreviousModelstruc(void)
{ /* node which came before this one */
if (pmmdbapi->pdnmsHolder)
{
pmmdbapi->pdnmsHolder = pmmdbapi->pdnmsHolder->last;
return pmmdbapi->pdnmsHolder;
}
return NULL;
}
ValNodePtr LIBCALL AddPFBSelect(PFB pfbThis)
{
PDNMS pdnmsStruc = NULL;
PMSD pmsdStruc = NULL;
if (!pfbThis) return NULL;
pdnmsStruc = DNFromPFB((PFB)ToMSDParent(pfbThis));
pmmdbapi->pvnUndoMark = ValNodeAddPointer(&pmmdbapi->pvnPFBSelect,
pdnmsStruc->choice, (VoidPtr) pfbThis);
/* the choice field allows us to extract pointers
* to different structures from the list, esp. when freeing
* specific structures.
*/
return pmmdbapi->pvnUndoMark;
}
void LIBCALL ClearPFBSelectList(void)
{
ValNodeFree(pmmdbapi->pvnPFBSelect);
pmmdbapi->pvnPFBSelect = NULL;
return;
}
void LIBCALL UndoPFBSelectList(void)
{
ValNodeFree(pmmdbapi->pvnUndoMark);
return;
}
PSFF LIBCALL DoesFeatureTypeHaveFuncs(Uint1 iCode)
{
ValNodePtr pvn = NULL;
PSFF psffThis = NULL;
ValNodeFindNext(pmmdbapi->pvnsffHead, NULL, iCode);
if (pvn)
{
psffThis = (PSFF) pvn->data.ptrvalue;
return psffThis;
}
return NULL;
}
Uint1 LIBCALL Call3DColorProc(ColorPropPtr pcpThis)
{
Uint1 i = 0;
if (pmmdbapi->pColorFunc)
(*(pmmdbapi->pColorFunc)) (pcpThis, &i);
return i;
}
|