static TrajErr TRADESBenchmark(void) { /* protein is 1CDZ, same as beta protein - mixed alpha/beta protein 96 AA */ static Char sequence[]="ELPDFFQGKHFFLYGEFPGDERRKLIRYVTAFNGELEDYMSDRVQFVITAQEWDPSFEEALMDNPSLAFVRPRWIYSCNEKQKLLPHQLYGVVPQA"; CharPtr pc; FILE *f; Char fnamseq[PATH_MAX]; Char fnam[PATH_MAX]; Char fnamtrj[PATH_MAX]; Char fnuturndb[PATH_MAX]; Int2 err,numAA,cnt; Int4 randseed,dbsize; pMakeTrjParamBlock mkdata; pFoldTrajParamBlock foldtrajprm; CPUTimePtr pTime1,pTime2,pTime3,pTime4; BiostrucPtr bspBiostruc; PDNMS pdnmsModelstruc; PMSD pmsdHead; PDNML pdnmlModel; PMLD pmldThis; BiostrucIdPtr pbi=NULL; BiostrucDescrPtr pbd=NULL; printf("%d is the CODEBASE version here.\n6502:UNIX x86_32, 6503003:UNIX x86_64, 6500:Win32, 6401:UNIX PPC_32\n\n", S4VERSION); sprintf(fnuturndb,"UTURNDB"); /* to clean up errant U-Turn files CWVH 2010 */ if (!OPENMMDBAPI(0,NULL)) { ErrPostEx(SEV_ERROR,2,1,"Unable to open MMDBAPI"); return ERR_FAIL; } printf("One moment, opening rotamer library...\n"); if (LoadRotLib()!=ERR_SUCCESS) { ErrPostEx(SEV_ERROR,1,8,"Cannot open rotamer library (%s%s) - if the file is missing, please re-install the software",CFG_local_datafilepath,NEWSCWRL_FNAM); return ERR_FAIL; } pc=DFPTmpNam(FALSE,FALSE); if ((f=FileOpen(pc,"w"))==NULL) { CLOSEMMDBAPI(); FreeRotLib(); ErrPostEx(SEV_ERROR,errno,1,"Failed to open %s file",pc); return ERR_FAIL; } fprintf(f,"%s\n",sequence); /* Make sure disk space was sufficient to write to file */ if (fflush(f)==EOF) { FileClose(f); CLOSEMMDBAPI(); FreeRotLib(); ErrPostEx(SEV_ERROR,errno,1,"Failed to write to %s file",pc); return ERR_FAIL; } FileClose(f); StringCpy(fnamseq,pc); sprintf(fnam,"%s%s",CFG_local_datafilepath,BENCH_TRAJ); sprintf(fnamtrj,"%s%s%s",CFG_local_datafilepath,BENCH_TRAJ,ASN_EXT); mkdata = (pMakeTrjParamBlock)MemNew(sizeof(MakeTrjParamBlock)); mkdata->TrajMethod = 2; /* from sequence */ mkdata->valfnamin = NULL; mkdata->pcChain = NULL; mkdata->modelnum = 1; mkdata->startres = 1; mkdata->endres = 0; mkdata->peakheight = 100; mkdata->noise = 0; mkdata->savechi = 0; mkdata->sigma_x = 0.0; mkdata->sigma_y = 0.0; mkdata->temperature = 0; mkdata->timestep = 0.0; mkdata->seqfnamin = fnamseq; mkdata->tgtype = 4; mkdata->sstrufname = NULL; mkdata->DoRPS = FALSE; mkdata->uturn = FALSE; mkdata->SStruinput = FALSE; mkdata->trjfnamout = fnam; mkdata->comprtype = USE_RLE; mkdata->constrfnamin = NULL; mkdata->units=UNITS_ARBITRARY; mkdata->templat=NULL; mkdata->zhangwindsize = 0; mkdata->alignfile=NULL; mkdata->ssmask=NULL; mkdata->dumpcsv=0; mkdata->benchmark=1; mkdata->all_coil = (Boolean)(FALSE); mkdata->all_beta = (Boolean)(FALSE); /* ensure config file is set right, even if user may have fudged it */ if (SetConfigFileValues(WALK_PHIPSI,50.0/*errtol*/, 0.25/*abbb*/, 0.50/*absc*/, 0.0/*tunnelprob*/)!=ERR_SUCCESS) { CLOSEMMDBAPI(); FreeRotLib(); mkdata=MemFree(mkdata); FileRemove(pc); #ifdef OS_UNIX ErrPostEx(SEV_ERROR,0,0,"Unable to write config file .foldtrajrc, cannot continue"); #else ErrPostEx(SEV_FATAL,0,0,"Unable to write config file foldtraj.ini, cannot continue"); #endif return ERR_FAIL; } printf("Predicting secondary structure and generating trajectory distribution...\n"); pTime1=CPUTimeMeasure(); MakeTrj((VoidPtr)mkdata); printf("MadeTrj complete, unpacking ASN.1 Trajectory Graph\n"); pTime2=CPUTimeMeasure(); mkdata=MemFree(mkdata); FileRemove(fnamseq); if (UnPackAsnTrajGraph(fnam,&numAA,sequence,NULL,&pbi,&pbd,NULL)==NULL) { CLOSEMMDBAPI(); FreeRotLib(); FileRemove(fnamtrj); ErrPostEx(SEV_ERROR,2,3,"Unable to read trajectory distribution %s, please create a new one",fnam); return ERR_FAIL; } randseed=54374; RandomSeed(randseed); StringCpy(tmpskelfname,DFPTmpNam(FALSE,FALSE)); /* make the ASN.1 file for this protein's chemical graph */ BuildSkelASN(sequence,tmpskelfname); InitBSPLog(randseed,sequence,totalstruc); TGInit(tmpdbasename,DB_READ,&dbsize); printf("Folding protein...\n"); pTime3=CPUTimeMeasure(); for (cnt=0;cnt<100;cnt++) { bspBiostruc=NULL; bspBiostruc=MIMEBiostrucAsnGet(tmpskelfname,"r",NULL); if (bspBiostruc==NULL) { CLOSEMMDBAPI(); FreeRotLib(); FileRemove(fnamtrj); BSFree(bspTempLog); FileRemove(tmpskelfname); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); ErrPostEx(SEV_ERROR,3,1,"Unable to fetch Biostruc"); return ERR_FAIL; } if (pbi!=NULL) { if (bspBiostruc->id!=NULL) AsnGenericChoiceSeqOfFree(bspBiostruc->id,(AsnOptFreeFunc)BiostrucIdFree); bspBiostruc->id=pbi; pbi=NULL; } if (pbd!=NULL) { if (bspBiostruc->descr!=NULL) AsnGenericChoiceSeqOfFree(bspBiostruc->descr,(AsnOptFreeFunc)BiostrucDescrFree); bspBiostruc->descr=pbd; pbd=NULL; } /* now the chemical graph is correctly in memory as a modelstruc, with co-ordinates (and hence PALDs) assigned only to a-carbons */ pdnmsModelstruc=MakeAModelstruc(bspBiostruc); if (pdnmsModelstruc==NULL) { CLOSEMMDBAPI(); FreeRotLib(); FileRemove(fnamtrj); BSFree(bspTempLog); FileRemove(tmpskelfname); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); ErrPostEx(SEV_ERROR,4,1,"Unable to convert Biostruc to Modelstruc. Please ensure your protein only contains the 20 standard amino acids."); return ERR_FAIL; } pmsdHead=(PMSD)(pdnmsModelstruc->data.ptrvalue); /* remove ppAsnOrder for all models so it will be rebuilt in WriteAsnAllModel */ pdnmlModel=pmsdHead->pdnmlModels; while (pdnmlModel) { pmldThis=(PMLD)(pdnmlModel->data.ptrvalue); if (pmldThis->ppAsnOrder) { PTRVectorFree(pmldThis->ppAsnOrder,0); pmldThis->ppAsnOrder=NULL; } pdnmlModel=pdnmlModel->next; } if (dbsize!=((PMMD)((pmsdHead->pdnmmHead)->data.ptrvalue))->iResCount) { CLOSEMMDBAPI(); FreeRotLib(); FreeAModelstruc(pdnmsModelstruc); BSFree(bspTempLog); FileRemove(fnamtrj); FileRemove(tmpskelfname); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); ErrPostEx(SEV_ERROR,1,1,"protein length inconsistency error, expect: %d actual: %d, possibly due to corrupt trajectory file; aborting",((PMMD)((pmsdHead->pdnmmHead)->data.ptrvalue))->iResCount,dbsize); return ERR_FAIL; } foldtrajprm=(pFoldTrajParamBlock)MemNew(sizeof(FoldTrajParamBlock)); foldtrajprm->pmsdRoot=pmsdHead; foldtrajprm->Model=1; foldtrajprm->err=0; foldtrajprm->gen=0; foldtrajprm->errorfile=NULL; /* do the folding here */ TRADEProtein((VoidPtr)foldtrajprm,1); err=foldtrajprm->err; foldtrajprm=MemFree(foldtrajprm); FreeAModelstruc(pdnmsModelstruc); if (err!=ERR_SUCCESS && err!=ERR_INCOMPLETE) { FileRemove(fnamtrj); FileRemove(tmpskelfname); BSFree(bspTempLog); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); CLOSEMMDBAPI(); FreeRotLib(); ErrPostEx(SEV_ERROR,1,1,"Benchtraj returned a folding error %d",err); return ERR_FAIL; } } pTime4=CPUTimeMeasure(); FileRemove(fnamtrj); FileRemove(tmpskelfname); BSFree(bspTempLog); TGClose(); CleanUpDB(tmpdbasename); CleanUpDB(fnuturndb); CLOSEMMDBAPI(); FreeRotLib(); printf("Benchmark complete.\n\nSummary\n-------\n Usr time Sys time\n -------- --------\n"); printf("Maketrj %9.3f %9.3f\nFoldtraj %9.3f %9.3f\n\n",CPUTimeGetUser(pTime2)-CPUTimeGetUser(pTime1),CPUTimeGetSys(pTime2)-CPUTimeGetSys(pTime1),CPUTimeGetUser(pTime4)-CPUTimeGetUser(pTime3),CPUTimeGetSys(pTime4)-CPUTimeGetSys(pTime3)); printf("Benchtraj successful\n"); return ERR_SUCCESS; }
PCSAN CSANStructMask(Int4 iMMDBid, Int4 iGiStruc) { Int4 iNumSeq = 0; BiostrucPtr pbsThis = NULL; Int4 iStrucLen = 0; PDNMS pdnmsStructure = NULL; PMSD pmsdThis = NULL; PMMD pmmdMol = NULL; PCSAN pcsanStruc = NULL; PCSAN pcsanMask = NULL; Char pcName[31]; if (iGiStruc == 0) return NULL; /* get a pdnms to the structure MMDBid, then a pdnmm to the embedded Gi */ if((pbsThis = SHoundGet3D(iMMDBid))!= NULL) pdnmsStructure = MakeAModelstruc(pbsThis); if (!pdnmsStructure) { ErrPostEx(SEV_ERROR, 0, 0,"Fatal Error during MMDB structure retrieval %ld\n", (long) iMMDBid); return NULL; } pmmdMol = MMDBGetMoleculeByGI(pdnmsStructure, iGiStruc); pmsdThis = (PMSD) pdnmsStructure->data.ptrvalue; pcsanMask = NewCSAN(); pcsanMask->iGi = iGiStruc; pcsanMask->next = NewCSAN(); pcsanStruc= pcsanMask->next; pcsanMask->iLen = pmmdMol->iResCount; pcsanStruc->iGi = iGiStruc; pcsanStruc->iLen = pmmdMol->iResCount; /* name of stru = "%s" */ /* name of SS = "!SS_%s" */ pcName[0] = '\0'; sprintf(pcName,"!SS_gi|%ld|pdb|%4s|%1s",(long) iGiStruc, pmsdThis->pcPDBName, pmmdMol->pcMolName); pcsanMask->pcSeqName = StringSave(pcName); if (StringLen(pcName) > 23) pcsanMask->pcSeqName[23] = '\0'; sprintf(pcName,"gi|%ld|pdb|%4s|%1s",(long) iGiStruc, IsNullStr(pmsdThis->pcPDBName), IsNullStr(pmmdMol->pcMolName)); pcsanStruc->pcSeqName = StringSave(pcName); if (StringLen(pcName) > 23) pcsanMask->pcSeqName[23] = '\0'; /* fill the sec-structure mask with the structure, pad the remainder */ FillCSANWithMask(pcsanMask, pmmdMol, pmmdMol->iResCount); /* fill the CSAN node with the structure, pad the remainder if shorter */ FillCSANWithStru(pcsanStruc, pmmdMol, pmmdMol->iResCount); ClearStructures(); return pcsanMask; }
Int2 Main() { PMSD pmsdRoot = NULL; static char valfilein[PATH_MAX]; Int2 iDotLen = 0; AsnIoPtr aip=NULL; NcbiMimeAsn1Ptr nmap=NULL; BiostrucPtr bsp=NULL; BiostrucSeqPtr bssp=NULL; PDNMS pdnmsModelstruc = NULL; ErrSev esMsg,esLog,esFatal; PDNML pdnmlModel; PMLD pmldThis; Boolean isMime = FALSE; Int4 iModels = 0, iNCBImodel = 0, iPDBmodel = 0, iAscii = 0; /* Initialize MMDB-API */ ErrSetLogfile("error_strSummary.log", ELOG_APPEND|ELOG_BANNER); ErrSetOptFlags(EO_SHOW_SEVERITY|EO_SHOW_CODES|EO_LOG_FILELINE|EO_SHOW_USERSTR|EO_SHOW_ERRTEXT|EO_BEEP|EO_WAIT_KEY|EO_LOGTO_USRFILE); if (!GetArgs("strSummary reports on what is inside .val or .cn3 or .prt file to stdout.\nCaution - will not work on Biounits downloaded from NCBI, use Asymmetric Units\n",3,Rargs)) return 1; /* we use exact filenames and extensions to avoid confusion */ StringCpy(valfilein, Rargs[0].strvalue); if (FileLength(valfilein) == 0) { ErrPostEx(SEV_FATAL,13,1,"Unable to find input file %s",Rargs[0].strvalue); return 13; } if (!OpenMMDBAPI(0,NULL)) { ErrPostEx(SEV_FATAL,12,1,"Unable to open MMDBAPI, check for missing bstdt.val dictionary file."); return 12; } /* load an ASN.1 file *.val or *.c3d or *.prt write out Biostruc only */ aip=AsnIoOpen(valfilein,"rb"); if (aip==NULL) { ErrPostEx(SEV_FATAL,11,1,"Unable open ASN.1 stream in file %s",valfilein); return 11; } /* first try biostruc load */ /* printf("try biostruc\n"); */ esMsg=ErrGetMessageLevel(); esLog=ErrGetLogLevel(); esFatal=ErrGetFatalLevel(); ErrSetMessageLevel(SEV_MAX); ErrSetLogLevel(SEV_MAX); ErrSetFatalLevel(SEV_MAX); bsp=BiostrucAsnRead(aip,NULL); AsnIoClose(aip); ErrSetMessageLevel(esMsg); ErrSetLogLevel(esLog); ErrSetFatalLevel(esFatal); if (bsp == NULL) { /* try ascii */ aip = AsnIoOpen(valfilein,"r"); if (aip==NULL) { ErrPostEx(SEV_FATAL,10,1,"Unable open binary or ascii ASN.1 from file %s",valfilein); return 10; } esMsg=ErrGetMessageLevel(); esLog=ErrGetLogLevel(); esFatal=ErrGetFatalLevel(); ErrSetMessageLevel(SEV_MAX); ErrSetLogLevel(SEV_MAX); ErrSetFatalLevel(SEV_MAX); bsp=BiostrucAsnRead(aip,NULL); AsnIoClose(aip); ErrSetMessageLevel(esMsg); ErrSetLogLevel(esLog); ErrSetFatalLevel(esFatal); if (bsp) iAscii = 1; } if (bsp==NULL) { /* printf("try mime binary\n"); */ /* then try NCBIMime load */ aip=NULL; aip=AsnIoOpen(valfilein,"rb"); ErrSetMessageLevel(SEV_MAX); ErrSetLogLevel(SEV_MAX); ErrSetFatalLevel(SEV_MAX); nmap=NcbiMimeAsn1AsnRead(aip,NULL); ErrSetMessageLevel(esMsg); ErrSetLogLevel(esLog); ErrSetFatalLevel(esFatal); AsnIoClose(aip); if (nmap == NULL) { /* printf("try mime ascii\n"); */ aip=AsnIoOpen(valfilein,"r"); ErrSetMessageLevel(SEV_MAX); ErrSetLogLevel(SEV_MAX); ErrSetFatalLevel(SEV_MAX); nmap=NcbiMimeAsn1AsnRead(aip,NULL); ErrSetMessageLevel(esMsg); ErrSetLogLevel(esLog); ErrSetFatalLevel(esFatal); AsnIoClose(aip); if (nmap) iAscii = 1; } if (nmap!=NULL) { /* got an NCBI mime */ if (nmap->choice!=NcbiMimeAsn1_strucseq && nmap->choice!=NcbiMimeAsn1_strucseqs) { /* wrong MIME type */ nmap=NcbiMimeAsn1Free(nmap); ErrPostEx(SEV_ERROR,9,1,"MIME-type wrapper is not a strucseq or strucseqs - no Biostruc to report in: %s",valfilein); return 9; } isMime = TRUE; /* unwrap the mime and leave the bsp for PDB conversion */ bssp=(BiostrucSeqPtr)(nmap->data.ptrvalue); bsp=bssp->structure; bssp->structure = NULL; /* may want to report on contents of wrapper ... */ nmap=NcbiMimeAsn1Free(nmap); /* discard the wrapper */ nmap = NULL; bssp = NULL; } } if (bsp == NULL) { ErrPostEx(SEV_ERROR,8,1,"No Biostruc in files to report in: %s",valfilein); return 8; } pdnmsModelstruc=MakeAModelstruc(bsp); if (pdnmsModelstruc==NULL) { ErrPostEx(SEV_ERROR,7,1,"Unable to convert Biostruc to Modelstruc"); return 7; } pmsdRoot=(PMSD)(pdnmsModelstruc->data.ptrvalue); if (pmsdRoot==NULL) { ErrPostEx(SEV_ERROR,6,1,"Internal error."); return 6; } /* OK, Ready to Start Reporting */ printf("Filename: %s\n", valfilein); if (Rargs[1].intvalue == FALSE) { if (iAscii) printf("ASCII Asn.1 (.prt) "); else printf("Binary Asn.1 (.val) "); if (isMime) printf("Entry Point: NCBIMime\n"); else printf("Entry Point: Biostruc\n"); if (pmsdRoot->pcPDBName != NULL) printf("PDB code: %s\n",pmsdRoot->pcPDBName); printf("MMDB Id: %d\n", (int) pmsdRoot->iMMDBid); printf("Name: %s\n",GetStrucStrings(pdnmsModelstruc, LONG_NAME)); printf("PDB Class: %s\n",GetStrucStrings(pdnmsModelstruc, PDB_CLASS)); printf("PDB Source: %s\n",GetStrucStrings(pdnmsModelstruc, PDB_SOURCE)); pdnmlModel=pmsdRoot->pdnmlModels; while (pdnmlModel) { iModels++; pmldThis=(PMLD)(pdnmlModel->data.ptrvalue); if (pmldThis->iType==Model_type_ncbi_all_atom) { iNCBImodel = pdnmlModel->choice; } if (pmldThis->iType==Model_type_pdb_model) { iPDBmodel = pdnmlModel->choice; } pdnmlModel=pdnmlModel->next; } printf("Number of Models: %d\n",iModels); if(iNCBImodel) printf("NCBI All Atom Model: %d\n",iNCBImodel); if (iPDBmodel) printf("PDB All Atom Model: %d\n",iPDBmodel); if (pmsdRoot->pDictLocal) printf("Has Local Chemical Graph Dictionary\n"); printf("Number of Molecules: %d\n", (int) pmsdRoot->iMolCount); /* number of molecules */ printf("Number of Objects: %d\n",(int) pmsdRoot->iObjCount); /* number of objects */ printf("Number of Density Sets: %d\n",(int) pmsdRoot->iDensCount); /* number of densities */ printf("Number of Inter-Molecule Bonds: %d\n", (int) pmsdRoot->iIMBCount); if (Rargs[2].intvalue == TRUE) { printf("\n\nRAMACHANDRAN Angles for all Proteins:\n"); if (iNCBImodel) { printf("NCBI All Atom Coordinate Model Number %d\n\nChain, AA, Num, Phi, Psi\n",iNCBImodel); WriteStdoutRamaOneModel(pmsdRoot, iNCBImodel ); } else if (iPDBmodel) { printf("PDB All Atom Coordinate Model Number %d:\n\nChain, AA, Num, Phi, Psi\n",iPDBmodel); WriteStdoutRamaOneModel(pmsdRoot, iPDBmodel ); } } } printf("\n\n"); /* Output FASTA for each chain and dump het list - oldie but goodie code ! */ WriteFASTASeqHet(pdnmsModelstruc, stdout); /* Shut Down MMDB-API */ /* All Modelstrucs remaining are freed in CloseMMDB-API() */ CloseMMDBAPI(); return 0; }
Nlm_Int2 Main () { Int2 iTest; Byte bRender; Int2 iColor; PDNMS pdnmsModelstruc; BiostrucPtr pbsBiostruc; Char cOut[254]; FILE *pFile; ErrSetFatalLevel(SEV_MAX); if (! GetArgs("GetMMDB",NUMARGS,myargs)) return 1; /* Initialize MMDBAPI */ if (! OpenMMDBAPI(0, NULL)) { printf("Have not opened mmdbapi"); return 2; } /* load an ASN.1 Biostruc */ /* Any other method of obtaining a Biostruc is fine... */ /* This one does a built-in lookup of PDB accesion numbers */ /* then fetches the file using the Entrez clinet-server interface */ pbsBiostruc = FetchBiostrucPDB(myargs[0].strvalue, myargs[3].intvalue, 100); if (pbsBiostruc == NULL) { printf("Have not fetched Biostruc"); return 3; } /* convert it into a Modelstruc pointed to by pdnmsModelstruc */ pdnmsModelstruc= MakeAModelstruc(pbsBiostruc); if ( pdnmsModelstruc == NULL ) { printf("Have not converted Biostruc"); return 4; } if (myargs[1].intvalue == 0) /* Summary */ { if (!myargs[2].strvalue) { sprintf(cOut,"%s.sum", myargs[0].strvalue); pFile = fopen(cOut, "w"); } else pFile = fopen(myargs[2].strvalue,"w"); iTest = WriteStructSummary(pdnmsModelstruc,pFile); } if (myargs[1].intvalue == 2) /* Kinemage */ { bRender = (Byte) myargs[5].intvalue; iColor = (Int2) myargs[4].intvalue; if (!myargs[2].strvalue) { sprintf(cOut,"%s.kin", myargs[0].strvalue); pFile = fopen(cOut, "w"); } else pFile = fopen(myargs[2].strvalue,"w"); iTest = WriteKinAllModel(pdnmsModelstruc,pFile, iColor,bRender); } if (myargs[1].intvalue == 1) /* PDB */ { if (!myargs[2].strvalue) { sprintf(cOut,"%s.pdb", myargs[0].strvalue); pFile = fopen(cOut, "w"); } else pFile = fopen(myargs[2].strvalue,"w"); iTest = WritePDBAllModel(pdnmsModelstruc,pFile); } /* Free the Modelstruc (and its enclosed Biostruc) */ /* FreeAModelstruc(PDNMS pdnmsThis); not necessary */ /* This can be done individually - but all Modelstrucs */ /* remaining are freed in CloseMMDBAPI() */ /* Shut Down MMDBAPI */ CloseMMDBAPI(); return TRUE; }