int main(int argc, char *argv[]) { Options opt = setupOptions(argc, argv); cout << "READING: "<<opt.pdblist<<endl; vector<string> lines; MslTools::readTextFile(lines,opt.pdblist); map<string,bool> residueCombinations; PhiPsiStatistics pps; for (uint i = 0; i < lines.size();i++){ System sys; sys.readPdb(lines[i]); bool brokenChain = false; // Each chain int loopCount = 1; for (uint c = 0; c < sys.chainSize();c++){ // Walk through residues Chain &ch = sys.getChain(c); int startIndex = 0; int endIndex = ch.positionSize(); for (uint r = startIndex; r < endIndex;r++){ // Skip first and last residues if (r == 0 || r == ch.positionSize()-1) {continue;} Residue &resm1 = ch.getResidue(r-1); Residue &res = ch.getResidue(r); Residue &resp1 = ch.getResidue(r+1); // Skip if no backbone atoms if (!(resm1.atomExists("N") && res.atomExists("N") && resp1.atomExists("N"))) {continue;} if (!(resm1.atomExists("CA") && res.atomExists("CA") && resp1.atomExists("CA"))) {continue;} if (!(resm1.atomExists("C") && res.atomExists("C") && resp1.atomExists("C"))) {continue;} // Only look for loop residues if (!(res("CA").getSegID() == "LLLL" || res("CA").getSegID() == "TTTT")) {continue;} double psi1 = PhiPsiStatistics::getPsi(resm1,res); double phi2 = PhiPsiStatistics::getPhi(resm1,res); double psi2 = PhiPsiStatistics::getPsi(res,resp1); double phi3 = PhiPsiStatistics::getPhi(res,resp1); stringstream ss1; ss1 << resm1.getResidueName()<<"-"<<res.getResidueName(); double psi1round = MslTools::smartRound(psi1,20); if (abs(psi1round) > 180){ cerr << "ERROR psi1 = "<<psi1<<" rounded: "<<psi1round<<endl; cerr << "\t"<<res.toString()<<endl; exit(0); } stringstream psi1ss; psi1ss << psi1round; double phi2round = MslTools::smartRound(phi2,20); if (abs(phi2round) > 180){ cerr << "ERROR phi2 = "<<phi2<<" rounded: "<<phi2round<<endl; cerr << "\t"<<res.toString()<<endl; exit(0); } stringstream phi2ss; phi2ss << phi2round; //cout << "ADDING "<<ss1.str()<<" "<<psi1ss.str()<<" "<<phi2ss.str()<<endl; pps.addStatisitics(ss1.str(),psi1ss.str(),phi2ss.str(),1); residueCombinations[ss1.str()] = true; } } }//lines[i] map<string,int> counts = pps.getPhiPsiCounts(); RandomNumberGenerator rng; rng.setTimeBasedSeed(); ofstream fout; fout.open("shiftedRamaStats.txt"); stringstream ss; map<string,bool>::iterator it; for (it = residueCombinations.begin();it != residueCombinations.end();it++){ vector<string> toks = MslTools::tokenize(it->first,"-"); cout << "PAIR: "<<it->first<<" has "<<counts[it->first]<<" counts."<<endl; for (uint i = 0; i < opt.numSamples;i++){ // Get a random pair of Phi/Psi values std::pair<double,double> angles = pps.getRandomPhiPsi(it->first); // Add some noise into the angles.. (random angle 1/2 the width of a bin) angles.first += (rng.getRandomDouble() * (20/2) * (rng.getRandomDouble() < 0.5 ? -1 : 1)); angles.second += (rng.getRandomDouble() * (20/2) * (rng.getRandomDouble() < 0.5 ? -1 : 1)); while (abs(angles.first) > 180){ angles.first = pps.getRandomPhiPsi(it->first).first + (rng.getRandomDouble() * (20/2) * (rng.getRandomDouble() < 0.5 ? -1 : 1)); } while (abs(angles.second) > 180){ angles.second = pps.getRandomPhiPsi(it->first).second + (rng.getRandomDouble() * (20/2) * (rng.getRandomDouble() < 0.5 ? -1 : 1)); } char tmp[300]; sprintf(tmp, "%3s %8.3f %3s %8.3f\n", toks[0].c_str(), angles.first, toks[1].c_str(), angles.second); fout << tmp; } } fout.close(); //cout << ss.str()<<endl; }
void runSaltBridgeMC( subSeq &_exposedPositions, map<string,map<string,map<int, map<string,map<string, double> > > > > &_sbScoreTable, System &_sys, Options &_opt, std::priority_queue< std::pair<saltBridgeResult,subSeq>, std::vector< std::pair<saltBridgeResult,subSeq> >, compareScores> &_mcData){ // WT score saltBridgeResult wt_sbresult = scoreSaltBridgePositions(_exposedPositions,_sbScoreTable,_sys); // Map to insure we don't fill priority queue with duplicates map<string,bool> mcDataMap; string possibleMutations = "KREDH"; RandomNumberGenerator rng; rng.setTimeBasedSeed(); MSLOUT.stream() << "RNG SEED: "<<rng.getSeed()<<endl; //MonteCarloManager MCMngr(_startingTemperature, _endingTemperature,_scheduleCycles, _scheduleShape, _maxRejectionsNumber, _convergedSteps, _convergedE); MonteCarloManager MCMngr(_opt.startMCtemp,_opt.endMCtemp,_opt.numMCcycles, MonteCarloManager::EXPONENTIAL,100,0,0.0); MCMngr.setRandomNumberGenerator(&rng); MCMngr.setEner(wt_sbresult.score); subSeq current = _exposedPositions; string wtSeq = _exposedPositions.seq; // TODO add options to Options opt; to take care of MC-related options..... get rid of hard-coded values. while (!MCMngr.getComplete()) { // Make change int mutIndex = rng.getRandomInt(0,possibleMutations.size()-1); int seqPosIndex = rng.getRandomInt(0,_exposedPositions.seq.size()-1); string mutAA = possibleMutations.substr(mutIndex,1); string previousAA = current.seq.substr(seqPosIndex,1); current.seq.replace(seqPosIndex,1,mutAA); // Eval saltBridgeResult sbResult = scoreSaltBridgePositions(current,_sbScoreTable,_sys); //MSLOUT.stream() << "SCORE: "<<score<<" wt: "<<wt_score<<endl; // MC test for Acceptance: if (MCMngr.accept(sbResult.score)){ //cout << "New SEQ: "<<current.seq<<" score: "<<score<<endl; //cout << "WT SEQ: "<<wtSeq<<" score: "<<wt_score<<endl; bool keepIt = false; map<string, bool>::iterator it; it = mcDataMap.find(sbResult.sbId); if (it == mcDataMap.end()){ mcDataMap[sbResult.sbId] = true; if (_mcData.size() >= _opt.numSequenceModels){ if (sbResult.score < _mcData.top().first.score){ // Remove highest score, then add _mcData.pop(); _mcData.push(pair<saltBridgeResult,subSeq>(sbResult,current)); keepIt = true; } } else { _mcData.push(pair<saltBridgeResult,subSeq>(sbResult,current)); keepIt = true; } } if (!keepIt){ current.seq.replace(seqPosIndex,1,previousAA); } } else { current.seq.replace(seqPosIndex,1,previousAA); } } MSLOUT.stream() << "MC Completed -> "<<MCMngr.getReasonCompleted()<<endl; }