LOOS  v2.3.2
qcoscon.cpp
1 /*
2 
3  "Quick" Cosine content. Calculates the cosine content for the
4  entire trajectory for the first N modes.
5 
6  based on:
7  Hess, B. "Convergence of sampling in protein simulations."
8  Phys Rev E (2002) 65(3):031910
9 
10 */
11 
12 
13 
14 /*
15 
16  This file is part of LOOS.
17 
18  LOOS (Lightweight Object-Oriented Structure library)
19  Copyright (c) 2011, Tod D. Romo
20  Department of Biochemistry and Biophysics
21  School of Medicine & Dentistry, University of Rochester
22 
23  This package (LOOS) is free software: you can redistribute it and/or modify
24  it under the terms of the GNU General Public License as published by
25  the Free Software Foundation under version 3 of the License.
26 
27  This package is distributed in the hope that it will be useful,
28  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  GNU General Public License for more details.
31 
32  You should have received a copy of the GNU General Public License
33  along with this program. If not, see <http://www.gnu.org/licenses/>.
34 */
35 
36 
37 #include <loos.hpp>
38 #include "bcomlib.hpp"
39 
40 using namespace std;
41 using namespace loos;
42 using namespace Convergence;
43 
44 
45 namespace opts = loos::OptionsFramework;
46 namespace po = loos::OptionsFramework::po;
47 
48 
49 typedef vector<AtomicGroup> vGroup;
50 
51 
52 uint nmodes;
53 
54 string fullHelpMessage() {
55 
56  string s =
57  "\n"
58  "SYNOPSIS\n"
59  "\n"
60  "Calculate the cosine constent of a whole simulation\n"
61  "\n"
62  "DESCRIPTION\n"
63  "\n"
64  "Quick version of the cosine content calculation.\n"
65  "This tool performs the same calculation as coscon, \n"
66  "but instead of varying the trajectory in a block\n"
67  "averaging approach only the full trajectory is used.\n"
68  "The results are printed for the first 10 modes.\n"
69  "\n"
70  //
71  "EXAMPLES\n"
72  "\n"
73  "qcoscon -s 'name==\"CA\"' model.pdb traj.dcd\n"
74  "\tCalculate the cos content of the first 10 modes\n"
75  "\tof traj.dcd using the PCA of the CA atoms.\n"
76  "\n"
77  "SEE ALSO\n"
78  "Packages/Convergence/coscon - \n"
79  "\tCompute the cosine content of a matrix. This tool\n"
80  "\tperforms a similar analysis, but it uses a block\n"
81  "\taveraging approach where the cosine content is\n"
82  "\tcalculated for increasingly long trajectory blocks\n"
83  "\n"
84  "Packages/Convergence/rsv-coscon - \n"
85  "\tCalculate the cos content of the RSVs from a simulation\n"
86  "\tPCA.\n"
87  "\n"
88  "Tools/svd - \n"
89  "\tCompute the principal components via the SVD.\n"
90  "\tThis results in several matrix files including\n"
91  "\tthe RSVs used as input to the current tool. \n"
92  "\tThe file [prefix]_V.asc contains the RSV matrix.\n"
93  "\n"
94  "\n";
95 
96  return(s);
97 }
98 
99 
100 //@cond TOOLS_INTERNAL
101 class ToolOptions : public opts::OptionsPackage {
102 public:
103  void addGeneric(po::options_description& o) {
104  o.add_options()
105  ("modes", po::value<uint>(&nmodes)->default_value(10), "Compute cosine content for first N modes");
106  }
107 
108  string print() const {
109  ostringstream oss;
110  oss << boost::format("modes=%d") % nmodes;
111  return(oss.str());
112  }
113 
114 };
115 
116 
117 // @endcond TOOLS_INTERNAL
118 
119 int main(int argc, char *argv[]) {
120 
121  string hdr = invocationHeader(argc, argv);
122  opts::BasicOptions* bopts = new opts::BasicOptions(fullHelpMessage());
125  ToolOptions* topts = new ToolOptions;
126 
127  opts::AggregateOptions options;
128  options.add(bopts).add(sopts).add(tropts).add(topts);
129  if (!options.parse(argc, argv))
130  exit(-1);
131 
132  cout << "# " << hdr << endl;
133  cout << "# " << vectorAsStringWithCommas<string>(options.print()) << endl;
134 
135  AtomicGroup model = tropts->model;
136  pTraj traj = tropts->trajectory;
137  if (tropts->skip)
138  cerr << "Warning: --skip option ignored\n";
139 
140  AtomicGroup subset = selectAtoms(model, sopts->selection);
141  vector<AtomicGroup> ensemble;
142  readTrajectory(ensemble, subset, traj);
143 
144  // Read in and align...
145  boost::tuple<std::vector<XForm>, greal, int> ares = iterativeAlignment(ensemble);
146  AtomicGroup avg = averageStructure(ensemble);
147 
148  NoAlignPolicy policy(avg, true);
149  RealMatrix V = rsv(ensemble, policy);
150  cout << "# n\tcoscon\n";
151  for (uint i=0; i<nmodes; ++i)
152  cout << i << "\t" << cosineContent(V, i) << endl;
153 
154 }
pTraj trajectory
The trajectory, primed by the –skip value (if specified)
def averageStructure(traj)
Python version of averageStructure (using loos.pyloos.Trajectory-like objects) The subset defined in ...
Definition: ensembles.py:14
Simple matrix template class using policy classes to determine behavior.
Definition: MatrixImpl.hpp:53
Namespace for encapsulating options processing.
Provides a single LOOS selection (–selection)
def iterativeAlignment(ensemble, threshold=1e-8, maxiter=1000)
Iteratively align a loos.pyloos.Trajectory object (or a list of AtomicGroups)
Definition: alignment.py:12
STL namespace.
AtomicGroup model
Model that describes the trajectory.
bool parse(int argc, char *argv[])
Parses a command line, returning true if parsing was ok.
Options common to all tools (including –fullhelp)
std::string invocationHeader(int argc, char *argv[])
Create an invocation header.
Definition: utils.cpp:124
Basic trajectory with a –skip option.
std::vector< std::string > print() const
AtomicGroup selectAtoms(const AtomicGroup &source, const std::string selection)
Applies a string-based selection to an atomic group...
Definition: utils.cpp:195
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.
Combines a set of OptionsPackages.
AggregateOptions & add(OptionsPackage *pack)
Add a pointer to an OptionsPackage that will be used for options.