Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

msdmmdb.cc

00001 //---------------------------------------------------
00002 // msdmmdb.cc
00003 // 
00004 // Project: PDBe API Framework 
00005 // Module:  Example program to use Proxy class methods to extend existing 
00006 // mmdb and ligand chemistry libraries for MSD-API chemistry layer.
00007 // These libraries have been developed by Eugene B. Krissinel and Adel Golovin.
00008 // Proxy classes uses MSD-API Data layer to load data from warehouse
00009 // and makes all the classes and methods in these class libraries available
00010 // through API calls.
00011 // 
00012 // Chemistry Layer
00013 // Last updated: 25 February 2004 10:17
00014 // (C) Siamak Sobhany
00015 //---------------------------------------------------
00016 // 
00017 #include <iostream>
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #include <ctype.h>
00022 
00023 
00024 #ifndef __MSD_USER_H__
00025 #include "msd_user.h"
00026 #endif
00027 
00028 
00029 
00030 
00031 int main(int argc, char* argv[]) {
00032  MSDManager* msdm;
00033   char select_stm[3072];
00034  
00035  int nDepId = 13156;
00036  int nMaxCells = 2;
00037  int nDepDepId = nDepId;
00038     char szExpType[255] = {0};
00039     short nExpTypeInd = 0;
00040  short nInd;
00041     int nContactType;
00042     int nContactType1;
00043     int nContactType2;
00044     int nValueType;
00045     double dblValue, dblAngle, dblDist1, dblDist2;
00046     int nActiveSiteType1, nActiveSiteType2;
00047     int nAtomId1, nAtomId2;
00048     char szAtomName1[12], szAtomName2[12];
00049     int nAtomSiteId1, nAtomSiteId2;
00050     int nComponentId1, nComponentId2;
00051     int nChainId1, nChainId2;
00052     int nActiveSiteId1, nActiveSiteId2, nActiveSiteId3;
00053     int nAssemblyId, nAssemblySerial;
00054     int nModelId;
00055     char szCode3letter1[4];
00056     char szCode3letter2[4];
00057     char szChainID1[4];
00058     char szChainID2[4];
00059     int nPdbSeq1, nPdbSeq2;
00060     int nCarbonIndex = getElementNo(" C");
00061     int nNeighbourTypeId;
00062     int nNeighbourTypeId1;
00063     int nNeighbourTypeId2;
00064     int nOrdering;
00065     char chLigandAcceptorDonor[2];
00066     char chNeighbourAcceptorDonor[2];
00067     char szSymbol1[3];
00068     char szSymbol2[3];
00069  
00070  
00071  char         S1[100];
00072  char         S2[100];
00073  double dblMinDist;
00074  int nSeqDist;
00075  PSContact vContact = NULL;
00076  int nContacts = 0;
00077  msdbConnect db;
00078  msdbConnect::msdbInit();
00079  try
00080  {
00081         db.rlogon("search/search55@msdsrchd");
00082         printf("\nLogin Seccessfull.");
00083  }
00084   catch(msdbException& p){ // intercept OTL exceptions
00085    cerr<<p.msg<<endl; // print out error message
00086    cerr<<p.stm_text<<endl; // print out SQL that caused the error
00087    cerr<<p.var_info<<endl; // print out the variable that caused the error
00088   
00089   }
00090  
00091  InitMatType();
00092  msdm=new MSDManager();
00093 
00094   SetMakersCAtom ( (void*)newCDBAtom,(void*)streamNewCDBAtom );
00095  
00096  
00097   connectivity_d* connect_d = new connectivity_d[1000];
00098   connectivity_a* connect_a = new connectivity_a[1000];  
00099   int nDCount = 0, nACount = 0;
00100   
00101 
00102  if (msdm->LoadWarehouse(db,38175) != S_OK)
00103  {   printf("\nData MSDManger not loaded.");
00104          exit(1);
00105  }
00106  printf("\nData MSDManger loaded successfully.");
00107  printf("\nNumber of Atoms for this entry:  = %d atoms.\n", msdm->GetNumberOfAtoms());
00108  printf("\nPDB Code for this entry:  = %s (PDB Code)\n", msdm->GetEntryID());
00109  
00110  sprintf(select_stm,"%s","select /*+ INDEX(ENTRY)*/ entry.SHORT_EXPERIMENT_TYPE " 
00111         " from entry where entry.entry_id = :nDepDepId <int> ");
00112   
00113   try{
00114   msdbStream imsd (50, select_stm, db);
00115   imsd << nDepDepId;
00116 
00117   while (!imsd.eof()){
00118    imsd >> szExpType;
00119    nExpTypeInd = imsd.is_null();
00120    if (!nExpTypeInd)
00121       trimRight(szExpType);
00122     else
00123       szExpType[0] = 0;
00124         
00125     ExpType::EExpType nType = ExpType::nUNKNOWN;
00126     if (!strcmp("XRAY", szExpType))
00127       nType = ExpType::nXRAY;
00128     else if (!strcmp("NMR", szExpType))
00129       nType = ExpType::nNMR;
00130     else if (!strcmp("SSNMR", szExpType))
00131       nType = ExpType::nNMR;
00132     int nCells   = nType == ExpType::nXRAY? nMaxCells : -1;
00133     if (nCells >= 0 && msdm->IsTheoretical() == S_OK)
00134       nCells = -1;
00135    
00136     dblMinDist  = 0.1;
00137     nSeqDist  = 1;
00138    
00139     if (nCells >= 0) 
00140       {
00141         if (!msdm->isCrystInfo()) 
00142                   {cerr << "Missing cell parameters (a,b,c,alpha,beta,gamma)" << endl;
00143                return (1);
00144                   }
00145         else if (!msdm->isSpaceGroup()) 
00146            {cerr << "Missing space group of symmetry"<< endl;
00147             return (2);
00148            }
00149         else if (!msdm->isTransfMatrix()) 
00150           {cerr << "Orthogonalization/fractionalization is impossible"<< endl;
00151            return (3);
00152       }
00153           }
00154   } // end while
00155  } // end try   
00156         catch(msdbException& p){ // intercept OTL exceptions
00157   cerr<<"get experiment type error"<<endl; 
00158   cerr<<p.msg<<endl; // print out error message
00159   cerr<<p.stm_text<<endl; // print out SQL that caused the error
00160   cerr<<p.var_info<<endl; // print out the variable that caused the error
00161  }
00162  
00163  db.logoff();
00164  
00165  CDBAssembly** vpAssembly = NULL;
00166     msdm->GetAssemblyArray(&vpAssembly);
00167     int nAssemblyCount = 0;
00168     msdm->GetAssemblyCount(&nAssemblyCount);
00169     CDBAtom** vpMacroMolAtom = new CDBAtom*[msdm->GetAtomArrayLength()];
00170     CDBAtom** vpLigandAtom = new CDBAtom*[msdm->GetAtomArrayLength()];
00171     CDBAtom** vpWaterAtom = new CDBAtom*[msdm->GetAtomArrayLength()];
00172     CAtom** vpMaxOccAtom = new CAtom*[msdm->GetAtomArrayLength()];
00173     CAtom** vpFirstReserveAtom = new CAtom*[msdm->GetAtomArrayLength()];
00174     CAtom** vpSecondReserveAtom = new CAtom*[msdm->GetAtomArrayLength()];
00175     int* vnActiveSiteId = new int[msdm->GetAtomArrayLength() + 1];
00176     for (int l = 0; l < nAssemblyCount; l++)
00177       {
00178         CDBAssembly* pAssembly = vpAssembly[l];
00179         pAssembly->GetId(&nAssemblyId);
00180         pAssembly->GetSerial(&nAssemblySerial);
00181         int nModelAssemblyCount = 0;
00182         pAssembly->GetModelAssemblyCount(&nModelAssemblyCount);
00183         for (int im = 0; im < nModelAssemblyCount; im++)
00184           {
00185             memset(vnActiveSiteId, 0, sizeof(int) * (msdm->GetAtomArrayLength() + 1));
00186             CDBModelAssembly* pModelAssembly = NULL;
00187             pAssembly->GetModelAssembly(&pModelAssembly, im);
00188             CDBModel* pModel = NULL;
00189             pModelAssembly->GetModel(&pModel);
00190             pModel->GetId(&nModelId);
00191             int nMacroMolAtoms = 0;
00192             int nLigandAtoms = 0;
00193             int nWaterAtoms = 0;
00194             int nMaxOccAtoms = 0;
00195             for (int nc = 0; nc < pModel->GetNumberOfChains(); nc++)
00196               {
00197                 CDBChain* pChain = (CDBChain*)pModel->GetChain(nc);
00198                 char szType[20];
00199                 pChain->GetType(szType);
00200                 bool bIsWater   = (szType[0] != 0 && szType[1] == 'W') || szType[0] == 'W';
00201                 bool bIsLigand  = (szType[0] != 0 && szType[1] == 'B') || szType[0] == 'B';
00202                 bool bIsMacromol = (szType[0] != 0 && szType[1] == 'C') || szType[0] == 'C';
00203                 bool bIsModRes = false;
00204                 if (bIsLigand || bIsMacromol || bIsWater) for (int nr = 0; nr < pChain->GetNumberOfResidues(); nr++)
00205                   {
00206                     CDBResidue* pResidue = (CDBResidue*)pChain->GetResidue(nr);
00207                     if (bIsMacromol && pChain->IsProtein() == S_OK)
00208                       bIsModRes = !isStdAminoAcid(pResidue->name);
00209                     int nResAssemblyId = 0;
00210                     if (pResidue->GetAssemblyId(&nResAssemblyId) != S_OK ||
00211                         nAssemblyId != nResAssemblyId)
00212                       continue;
00213                     rvector  occupancy = NULL;
00214                     int nAltLocs,alflag;
00215                     AltLoc   aLoc;
00216                     PAltLoc  aL = NULL;
00217                     pResidue->GetAltLocations ( nAltLocs, aL, occupancy, alflag );
00218                     PCAtom pPrevAtom = NULL;
00219                     double dx = -2.0;
00220                     aLoc[0] = char(0);
00221                     if (nAltLocs > 1)
00222                       {
00223                         for (int i=0;i<nAltLocs;i++)
00224                           if ((aL[i][0]) && (occupancy[i]>dx))  {
00225                             dx = occupancy[i];
00226                             strcpy ( aLoc,aL[i] );
00227                           }
00228                       }
00229                     else
00230                       {
00231                         if (strcmp(aLoc,aL[0])) 
00232                           strcpy ( aLoc,aL[0] );
00233                       }
00234                     for (int na = 0; na < pResidue->nAtoms; na++)
00235                       {
00236                         CDBAtom* pAtom = (CDBAtom*)pResidue->atom[na];
00237                         if (!pAtom || pAtom->Ter)
00238                           continue;
00239                         if (bIsLigand || bIsModRes)
00240                           vpLigandAtom[nLigandAtoms++] = pAtom;
00241                         else if (bIsMacromol && !bIsModRes)
00242                           vpMacroMolAtom[nMacroMolAtoms++] = pAtom;     
00243                         else if (bIsWater)
00244                           vpWaterAtom[nWaterAtoms++] = pAtom;
00245                         if (pAtom->element[0] == 0)
00246                           continue;
00247                         if (nAltLocs > 1)
00248                           {
00249                             bool B = !strcmp(aLoc, pAtom->altLoc);
00250                             if ((!B) && (!pAtom->altLoc[0]))  {
00251                               // We got a non-aLoc code that is an "empty-altcode".
00252                               // Check if this atom has the altcode that we need.
00253                               for (int ja=na+1;(ja<pResidue->nAtoms) && (!B);ja++)
00254                                 if (pResidue->atom[ja])  {
00255                                   if ((!pResidue->atom[ja]->Ter) && 
00256                                       (!strcmp(pResidue->atom[ja]->name, pAtom->name)))
00257                                     B = !strcmp(aLoc,pResidue->atom[ja]->altLoc);
00258                                 }
00259                               // if altcode=aLoc is not there for the atom (B is set False)
00260                               // then we take its "empty-code" location
00261                               B = !B;
00262                             }
00263                             if (B)
00264                               vpMaxOccAtom[nMaxOccAtoms++] = pAtom;
00265                           }
00266                         else
00267                           vpMaxOccAtom[nMaxOccAtoms++] = pAtom;
00268                       }
00269                   }
00270               }
00271             
00272                 if (!nMacroMolAtoms || !nLigandAtoms)
00273               continue;
00274           
00275             donor_out* d_out = new donor_out[nMaxOccAtoms];         
00276             next_d* nextd = new next_d[nMaxOccAtoms];
00277             int nDonorCount = 0;
00278             acceptor_out* a_out = new acceptor_out[nMaxOccAtoms];
00279             next_a* nexta = new next_a[nMaxOccAtoms];
00280             int nAcceptorCount = 0;
00281             std::map<CAtomKey*, int, ltatom> mapDonor;
00282             initDonorOut(vpMaxOccAtom, nMaxOccAtoms, 
00283                          connect_d,  nDCount, mapDonor,
00284                          d_out, nextd, &nDonorCount);
00285             std::map<CAtomKey*, int, ltatom> mapAcceptor;
00286             initAcceptorOut(vpMaxOccAtom, nMaxOccAtoms, 
00287                             connect_a, nACount, mapAcceptor,
00288                             a_out, nexta, &nAcceptorCount);
00289             vContact = NULL;
00290             nContacts = 0;
00291 
00292             msdm->CMMDBManager::SeekContacts((PPCAtom)vpLigandAtom, nLigandAtoms, 
00293                                            (PPCAtom)vpMacroMolAtom, nMacroMolAtoms,
00294                                            0, 5, 2,
00295                                            vContact, nContacts, 0, NULL, 1);
00296     
00298         printContacts(0, 0, vContact, nContacts, 
00299                           (CAtom**)vpLigandAtom, nLigandAtoms, (CAtom**)vpMacroMolAtom, nMacroMolAtoms, 
00300                           NULL);
00302          // print contacts
00303         if (nContacts>0)  {
00304     printf ( " Found %i contacts:\n",nContacts );
00305     for (int i=0;i<nContacts;i++)
00306       printf ( " %s <-> %s   %10.4f A\n",
00307                vpLigandAtom[vContact[i].id1]->GetAtomID(S1),
00308                vpMacroMolAtom[vContact[i].id2]->GetAtomID(S2),
00309                vContact[i].dist );
00310     } else
00311     printf ( " No contact found.\n" );
00312        vContact = NULL;
00313            nContacts = 0;
00314             msdm->CMMDBManager::SeekContacts((PPCAtom)vpLigandAtom, nLigandAtoms, 
00315                                            (PPCAtom)vpLigandAtom, nLigandAtoms,
00316                                            0, 5, 2,
00317                                            vContact, nContacts, 0, NULL, 2);
00318      // print contacts
00319         if (nContacts>0)  {
00320     printf ( " Found %i contacts:\n",nContacts );
00321     for (int i=0;i<nContacts;i++)
00322       printf ( " %s <-> %s   %10.4f A\n",
00323                vpLigandAtom[vContact[i].id1]->GetAtomID(S1),
00324                vpLigandAtom[vContact[i].id2]->GetAtomID(S2),
00325                vContact[i].dist );
00326     } else
00327     printf ( " No contact found.\n" );
00328         vContact = NULL;
00329         nContacts = 0;
00330             msdm->CMMDBManager::SeekContacts((PPCAtom)vpLigandAtom, nLigandAtoms, 
00331                                            (PPCAtom)vpWaterAtom, nWaterAtoms,
00332                                            0, 5, 2,
00333                                            vContact, nContacts, 0, NULL, 3);
00334     // print contacts
00335    if (nContacts>0)  {
00336     printf ( " Found %i contacts:\n",nContacts );
00337     for (int i=0;i<nContacts;i++)
00338       printf ( " %s <-> %s   %10.4f A\n",
00339                vpLigandAtom[vContact[i].id1]->GetAtomID(S1),
00340                vpWaterAtom[vContact[i].id2]->GetAtomID(S2),
00341                vContact[i].dist );
00342     } else
00343     printf ( " No contact found.\n" );
00344   
00345           }
00346           }
00347  
00348   // dispose array contact:
00349   if (vContact)  
00350   delete [] vContact;
00351   if (msdm)
00352   delete msdm;
00353   
00354 return (0);
00355 }
00356 

Generated on Fri Apr 16 13:47:44 2004 for MSDAPI by doxygen 1.3.4-20031005