LOOS  v2.3.2
rsv-coscon.cpp
1 /*
2  Matrix cosine content. Calculates the cosine content
3  of a matrix. Expected input is the RSVs of a PCA...
4 
5  based on:
6  Hess, B. "Convergence of sampling in protein simulations."
7  Phys Rev E (2002) 65(3):031910
8 
9 */
10 
11 
12 
13 /*
14 
15  This file is part of LOOS.
16 
17  LOOS (Lightweight Object-Oriented Structure library)
18  Copyright (c) 2011, Tod D. Romo
19  Department of Biochemistry and Biophysics
20  School of Medicine & Dentistry, University of Rochester
21 
22  This package (LOOS) is free software: you can redistribute it and/or modify
23  it under the terms of the GNU General Public License as published by
24  the Free Software Foundation under version 3 of the License.
25 
26  This package is distributed in the hope that it will be useful,
27  but WITHOUT ANY WARRANTY; without even the implied warranty of
28  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  GNU General Public License for more details.
30 
31  You should have received a copy of the GNU General Public License
32  along with this program. If not, see <http://www.gnu.org/licenses/>.
33 */
34 
35 
36 #include <loos.hpp>
37 #include "bcomlib.hpp"
38 
39 using namespace std;
40 using namespace loos;
41 using namespace Convergence;
42 
43 
44 namespace opts = loos::OptionsFramework;
45 namespace po = loos::OptionsFramework::po;
46 
47 
48 typedef vector<AtomicGroup> vGroup;
49 
50 
51 uint nmodes;
52 string rsv;
53 
54 
55 string fullHelpMessage() {
56 
57  string s =
58  "\n"
59  "SYNOPSIS\n"
60  "\n"
61  "Calculate the cosine constent of a right singular vector matrix\n"
62  "\n"
63  "DESCRIPTION\n"
64  "\n"
65  "This tool calculates the cosine content of a matrix.\n"
66  "It is intended to be used on the right sinular vectors\n"
67  "from an SVD. These are projections onto to principal\n"
68  "components of the simulation.\n"
69  "\n"
70  "See: Hess, B. \"Convergence of sampling in protein \n"
71  " simulations.\" Phys Rev E (2002) 65(3):031910\n"
72  //Matrix cosine content. Calculates the cosine content
73  //of a matrix. Expected input is the RSVs of a PCA...
74  "\n"
75  "\n"
76  "EXAMPLES\n"
77  "\n"
78  "rsv-coscon pca_V.asc\n"
79  "\tCompute the cos content of the first 10 (default)\n"
80  "\tright singular vectors from a simulation PCA. If\n"
81  "\tthe PCA was computed with the LOOS SVD tool, the \n"
82  "\tRSVs are stored in _V.asc\n"
83  "\n"
84  "rsv-coscon --modes=5 pca_V.asc\n"
85  "\tCompute the cos content of the first 5 RSVs only.\n"
86  "\n"
87  "SEE ALSO\n"
88  "Packages/Convergence/coscon - \n"
89  "\tCompute the cosine content of a matrix. This tool\n"
90  "\tperforms a similar analysis, but it uses a block\n"
91  "\taveraging approach where the cosine content is\n"
92  "\tcalculated for increasingly long trajectory blocks\n"
93  "\n"
94  "Packages/Convergence/qcoscon - \n"
95  "\tPerform a quick cos content analysis on a simulation.\n"
96  "\tSimilar to coscon, but only performs the analysis on\n"
97  "\tthe full length simulation.\n"
98  "\n"
99  "Tools/svd - \n"
100  "\tCompute the principal components via the SVD.\n"
101  "\tThis results in several matrix files including\n"
102  "\tthe RSVs used as input to the current tool. \n"
103  "\tThe file [prefix]_V.asc contains the RSV matrix.\n"
104  "\n"
105  "\n";
106 
107  return(s);
108 }
109 
110 
111 //@cond TOOLS_INTERNAL
112 class ToolOptions : public opts::OptionsPackage {
113 public:
114  void addGeneric(po::options_description& o) {
115  o.add_options()
116  ("modes", po::value<uint>(&nmodes)->default_value(10), "Compute cosine content for first N modes");
117  }
118 
119  string print() const {
120  ostringstream oss;
121  oss << boost::format("modes=%d") % nmodes;
122  return(oss.str());
123  }
124 
125 };
126 
127 // @endcond TOOLS_INTERNAL
128 
129 int main(int argc, char *argv[]) {
130 
131  string hdr = invocationHeader(argc, argv);
132  opts::BasicOptions* bopts = new opts::BasicOptions(fullHelpMessage());
133  // opts::BasicOptions* bopts = new opts::BasicOptions;
134  ToolOptions* topts = new ToolOptions;
135  opts::RequiredArguments* ropts = new opts::RequiredArguments("rsv", "right-singular-vectors");
136 
137  opts::AggregateOptions options;
138  options.add(bopts).add(topts).add(ropts);
139  if (!options.parse(argc, argv))
140  exit(-1);
141 
142  cout << "# " << hdr << endl;
143  cout << "# " << vectorAsStringWithCommas<string>(options.print()) << endl;
144 
145  RealMatrix V;
146  readAsciiMatrix(ropts->value("rsv"), V);
147 
148  cout << "# n\tcoscon\n";
149  for (uint i=0; i<nmodes; ++i)
150  cout << i << "\t" << cosineContent(V, i) << endl;
151 
152 }
Provides simple way to add command-line arguments (required options)
Simple matrix template class using policy classes to determine behavior.
Definition: MatrixImpl.hpp:53
Namespace for encapsulating options processing.
STL namespace.
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
std::string value(const std::string &s) const
Retrieve the value for an argument.
std::vector< std::string > print() const
Math::Matrix< T, P, S > readAsciiMatrix(std::istream &is)
Read in a matrix from a stream returning a newly created matrix.
Definition: MatrixRead.hpp:72
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.