00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "chain_threading_all.h"
00019
00020 #include <cpsp/HCoreDatabaseFILE.hh>
00021 #include <biu/LatticeDescriptor.hh>
00022 #include <biu/LatticeDescriptorCUB.hh>
00023 #include <biu/LatticeDescriptorFCC.hh>
00024 #include <cpsp/HCoreDatabase.hh>
00025 #include <biu/Point.hh>
00026 #include <stdlib.h>
00027 #include <iomanip>
00028
00029 using namespace cpsp;
00030 using namespace std;
00031 namespace cpsp{
00032
00033 namespace scth{
00034
00035
00036
00037 int SideChainThreadingHandler::calculateCoreSize(std::string* seq){
00038 int coreSize=0;
00039 for(size_t i=0;i<seq->size();i++){
00040 if((*seq)[i]=='H'){
00041 coreSize++;
00042 }
00043 }
00044 return coreSize;
00045 }
00046
00047
00048 pair<int,int> SideChainThreadingHandler::checkParity(const std::string* seq){
00049 int odd=0;
00050 int even=0;
00051 for(size_t i=0;i<seq->size();i++){
00052 if((*seq)[i]=='H'){
00053 if((i % 2) == 0)
00054 even+=1;
00055 else odd+=1;
00056 }
00057 }
00058 return pair<int,int>(odd,even);
00059 }
00060
00061 pair<int,int> SideChainThreadingHandler::checkHCoreParity(const HCore* hCore){
00062 assert(hCore!=NULL);
00063 biu::IPointSet points=hCore->getPoints();
00064 int odd=0;
00065 int even=0;
00066 for (biu::IPointSet::const_iterator t=points.begin(); t!= points.end();t++){
00067 biu::IntPoint point=*t;
00068 int sum=point.getX()+point.getY()+point.getZ();
00069 if( (sum %2) == 0)
00070 even+=1;
00071 else odd+=1;
00072 }
00073 return pair<int,int>(odd,even);
00074 }
00075
00076
00077 bool SideChainThreadingHandler::checkSequenceHCoreParity(const std::string *seq, const HCore* hCore){
00078 pair<int,int> parity=checkParity(seq);
00079 pair<int,int> coreParity=checkHCoreParity(hCore);
00080 if(parity.first==coreParity.first || parity.second==coreParity.first)
00081 return true;
00082 else return false;
00083 }
00084
00085
00086
00087
00088
00089
00090 SideChainThreadingHandler::SideChainThreadingHandler(const SideChainOptions& option){
00091 solutionsNum=0;
00092
00093 cpsp::HCoreDatabase* db = option.coreDB;
00094 assert(db!=NULL);
00095 assert(db->isConnected());
00096 std::string* seq = option.Sequence;
00097 assert(seq!=NULL);
00098
00099 if (option.withOutput)
00100 std::cout <<"==> HP-sequence = " <<*seq <<std::endl;
00101
00102
00103
00104 biu::LatticeDescriptor* latDescr;
00105 bool useParity=false;
00106 if(*(option.Description)=="CUB"){
00107 latDescr=new biu::LatticeDescriptorCUB();
00108 useParity=true;
00109 }
00110 else{
00111 latDescr=new biu::LatticeDescriptorFCC();
00112 }
00113
00114 int size=this->calculateCoreSize(seq);
00115 biu::LatticeFrame* latFrame= new biu::LatticeFrame(latDescr,2*(seq->size()+2));
00116 db->initCoreAccess(*latFrame->getDescriptor() ,size);
00117 biu::IndexVec* neighVecs=new biu::IndexVec(latFrame->getIndexedNeighborhood ());
00118 HCore* hCore=new HCore();
00119 int allSolutions=0;
00120 int curSolutions=0;
00121
00122 int oldContacts=0;
00123 int coreNumber=0;
00124 while(db->getNextCore(*hCore)){
00125
00126 int newContacts=hCore->getContacts();
00127
00128
00129 if (newContacts!=oldContacts) {
00130 coreNumber=0;
00131 if (allSolutions >= option.SolutionsNum) {
00132 break;
00133 }
00134 if (oldContacts!=0) {
00135 if(option.verbose) {
00136 std::cout<<"No solutions found for HCore with "<< oldContacts<<" number of contacts"<<std::endl;
00137 }
00138 if (option.withOutput)
00139 std::cout <<"\n ==> number generated structures = "
00140 <<(curSolutions)
00141 <<std::endl;
00142 }
00143 curSolutions = 0;
00144 if (option.withOutput) {
00145 std::cout <<"\n==> energy = -"
00146 <<newContacts
00147 <<std::endl;
00148 }
00149 oldContacts=newContacts;
00150 } else {
00151 coreNumber++;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161 if(useParity && !checkSequenceHCoreParity(seq,hCore)) {
00162 if(option.verbose) {
00163 std::cout<<"No solution found for HCore number: "<<coreNumber<<" with "<<oldContacts<<" number of contacts"<<std::endl;
00164 }
00165 continue;
00166 }
00167 int sol=scth::RunSideChainThreading::run<DFS>(seq,latFrame,neighVecs,hCore,option, option.SolutionsNum-allSolutions);
00168 if(sol==0 && option.verbose) {
00169 std::cout<<"No solution found for HCore number: "<<coreNumber<<" with "<<oldContacts<<" number of contacts"<<std::endl;
00170 }
00171
00172 curSolutions += sol;
00173 allSolutions += sol;
00174
00175
00176 }
00177 if (option.withOutput) {
00178 std::cout <<"\n ==> number generated structures = "
00179 <<(curSolutions)
00180 <<"\n\n- total number of generated structures = "
00181 <<std::setw(15) <<allSolutions
00182 <<"\n- maximal contacts reachable = "
00183 <<std::setw(15) << oldContacts
00184 <<std::endl;
00185 }
00186 solutionsNum=allSolutions;
00187 delete(neighVecs);
00188 delete(latFrame);
00189 delete(latDescr);
00190
00191
00192 delete(hCore);
00193
00194 }
00195
00196
00197 int SideChainThreadingHandler::getSolutionsNum(){
00198 return solutionsNum;
00199 }
00200
00201
00202 }
00203 }
00204