/** Print the population fraction of the entire simulation for each state and * each residue */ void ProtTraj::PrintProtPop(string const& fname) { // Set up the table of populations, initializing everything to zero vector<StateCount> pop_counts; // Now loop through every state and every residue, building pop_counts for (Cpin::ResIterator rit = cpin_->begin(); rit != cpin_->end(); rit++) { StateCount newstate; newstate.nstates = 0; for (int i = 0; i < rit->numStates(); i++) { newstate.state_cnt.push_back(0ll); newstate.prot_cnt.push_back(rit->numProtons(i)); newstate.nstates++; } pop_counts.push_back(newstate); } // Now loop through the entire trajectory, building the population list for (int i = 1; i < nframes_ + 1; i++) { ProtVector curst = statelist_[i]; for (int j = 0; j < nres_; j++) pop_counts[j].state_cnt[ statelist_[i][j] ] += 1ll; } // Now print out the population counts ofstream fp(fname.c_str()); if (!fp.is_open()) throw FileIOError("Could not open " + fname + " for writing!"); // Get the max number of states int maxst = cpin_->getResidues()[0].numStates(); for (Cpin::ResIterator rit = cpin_->begin(); rit != cpin_->end(); rit++) maxst = MAX(maxst, rit->numStates()); // Write the header fp << right << fixed << setw(17) << "Residue Number" << " "; for (int i = 0; i < maxst; i++) fp << setw(9) << "State" << setw(3) << i << ' '; fp << endl << setfill('-') << setw(maxst*13+18) << '-' << endl; // Now loop through every residue and print out the populations for (int i = 0; i < nres_; i++) { stringstream iss; iss << "Residue: " << cpin_->getResidues()[i].getResname() << " " << cpin_->getResidues()[i].getResnum(); fp << setfill(' ') << left << setw(17) << iss.str() << " "; for (int j = 0; j < pop_counts[i].nstates; j++) { double pop = (double) pop_counts[i].state_cnt[j] / (double) nframes_; fp << setprecision(6) << setw(8) << pop << " (" << pop_counts[i].prot_cnt[j] << ") "; } fp << endl; } fp.close(); }
int main(int argc, char**argv) { // Set up the command-line options and parse them CLOptions clopt = CLOptions(argc, argv); if (clopt.Parse()) return 1; // Check the input if (clopt.CheckInput()) { cerr << "Error: Input errors detected! See messages above." << endl; return 1; } // test_clopt(clopt); /* Uncomment to test command-line parsing */ int nres = 0; // number of residues (for consistency tests) /* Set up the cpin and print some diagnostic information (only necessary if * we're not fixing REMD files */ Cpin my_cpin; if (clopt.REMDPrefix().empty()) { if ( clopt.Cpin().empty() ) { #ifdef REDOX cerr << "Error: No cein file provided!" << endl; #else cerr << "Error: No cpin file provided!" << endl; #endif return 1; } if ( my_cpin.Parse(clopt.Cpin()) ) return 1; nres = (int) my_cpin.getTrescnt(); if (nres <= 0) { cerr << "Error: Did not detect any residues in " << clopt.Cpin() << endl; return 1; } if (clopt.Debug()) { cout << "There are " << nres << " titratable residues defined in " << my_cpin.getFilename() << ":" << endl; cout << "They are:" << endl; for (Cpin::ResIterator it = my_cpin.begin(); it != my_cpin.end(); it++) { cout << "\t" << setw(3) << it->getResname() << left << " " << setw(3) << it->getResnum() << " (" << it->numStates() << " states) [ "; for (int j = 0; j < it->numStates(); j++) { #ifdef REDOX if (it->isProtonated(j)) cout << "R "; else cout << "O "; #else if (it->isProtonated(j)) cout << "P "; else cout << "D "; #endif } cout << "]" << endl; } } } // if clopt.REMDPrefix().empty() // Set up the cpouts CpoutList cpouts; for (CLOptions::cpout_iterator it = clopt.begin(); it != clopt.end(); it++) { CpoutFile c = CpoutFile(&my_cpin, *it); // Skip over invalid cpouts if (!c.Valid()) { #ifdef REDOX cerr << "Error: Ceout file " << *it << " is invalid! Skipping." << endl; #else cerr << "Error: Cpout file " << *it << " is invalid! Skipping." << endl; #endif continue; } // For REMD fixing where a cpin is unnecessary, make sure all cpouts have // the same number of residues, so set nres to the first cpout's Nres if (nres <= 0) nres = c.Nres(); // Skip over cpouts with a residue mismatch if (c.Nres() != nres) { #ifdef REDOX cerr << "Error: Ceout file " << *it << " has " << c.Nres() << #else cerr << "Error: Cpout file " << *it << " has " << c.Nres() << #endif " residues. I expected " << my_cpin.getTrescnt() << ". Skipping." << endl; continue; } if (clopt.Debug()) #ifdef REDOX cout << "Added [[ " << *it << " ]] to ceout list." << endl; #else cout << "Added [[ " << *it << " ]] to cpout list." << endl; #endif cpouts.push_back(c); } if (clopt.Debug()) #ifdef REDOX cout << "Analyzing " << clopt.Cpouts().size() << " ceouts." << endl; if (cpouts.size() != clopt.Cpouts().size()) { cerr << "Error: Number of Ceout files " << cpouts.size() << #else cout << "Analyzing " << clopt.Cpouts().size() << " cpouts." << endl; if (cpouts.size() != clopt.Cpouts().size()) { cerr << "Error: Number of Cpout files " << cpouts.size() << #endif " does not equal number specified: " << clopt.Cpouts().size() << endl; return 1; } // Special-case REMD re-ordering if (!clopt.REMDPrefix().empty()) return sort_remd_files(cpouts, clopt.REMDPrefix(), clopt.Overwrite()); #ifdef REDOX ProtTraj stats = ProtTraj(&my_cpin, cpouts[0].pH(), cpouts[0].GetRecord(), cpouts[0].Temperature()); #else ProtTraj stats = ProtTraj(&my_cpin, cpouts[0].pH(), cpouts[0].GetRecord()); #endif for (cpout_iterator it = cpouts.begin(); it != cpouts.end(); it++) { // If we are here, then warn if we are about to use a REMD file if (!clopt.Expert()) it->WarnRemd(); stats.LoadCpout(*it); } // Do the normal calcpka-style output if requested if (clopt.Calcpka()) { if (clopt.Output().empty()) stats.PrintCalcpka(cout); else { ofstream fd; fd.open(clopt.Output().c_str()); stats.PrintCalcpka(fd); fd.close(); } } // Do chunk analysis if (clopt.ChunkWindow() > 0) stats.PrintChunks(clopt.ChunkWindow(), clopt.ChunkOutput(), clopt.PrintProtonated() && !clopt.pKa(), clopt.pKa()); // Do cumulative analysis if (clopt.doCumulative()) stats.PrintCumulative(clopt.CumulativeOutput(), clopt.Interval(), clopt.PrintProtonated() && !clopt.pKa(), clopt.pKa()); // Do running averages if (clopt.RunningAvgWindow() > 0) stats.PrintRunningAvg(clopt.RunningAvgWindow(), clopt.Interval(), clopt.RunningAvgOutput(), clopt.PrintProtonated() && !clopt.pKa(), clopt.pKa()); // Do protonation fraction dump if (clopt.Population().size() > 0) stats.PrintProtPop(clopt.Population()); // Do conditional probabilities if (clopt.CondProbs().size() > 0) { for (CLOptions::prob_iterator it = clopt.condbegin(); it != clopt.condend(); it++) if (it->Set(my_cpin) == ConditionalProb::ERR) { cerr << "Quitting due to errors above." << endl; return 1; } stats.PrintCondProb(clopt.ConditionalOutput(), clopt.CondProbs()); } // Do conditional probability time series (we already set the conditional // probabilities above, so no need to do it again) if (clopt.CondProbs().size() > 0 && !clopt.ConditionalChunkOut().empty()) stats.PrintCondTimeseries(clopt.ConditionalChunkOut(), clopt.Interval(), clopt.CondProbs()); if (clopt.Debug()) cout << "All done!" << endl; return 0; }