LOOS  v2.3.2
anm-lib.hpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2010, Tod D. Romo, Alan Grossfield
6  Department of Biochemistry and Biophysics
7  School of Medicine & Dentistry, University of Rochester
8 
9  This package (LOOS) is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation under version 3 of the License.
12 
13  This package is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
26 #if !defined(LOOS_ANM_LIB_HPP)
27 #define LOOS_ANM_LIB_HPP
28 
29 
30 #include "enm-lib.hpp"
31 
32 namespace ENM {
33 
35  class ANM : public ElasticNetworkModel {
36  public:
37  ANM(SuperBlock* b) : ElasticNetworkModel(b) { prefix_ = "anm"; }
38 
39  void solve() {
40 
41  if (verbosity_ > 2)
42  std::cerr << "Building hessian...\n";
43  buildHessian();
44  if (debugging_)
45  loos::writeAsciiMatrix(prefix_ + "_H.asc", hessian_, meta_, false);
46 
47  loos::Timer<> t;
48  if (verbosity_ > 1)
49  std::cerr << "Computing SVD of hessian...\n";
50  t.start();
51 
52  boost::tuple<loos::DoubleMatrix, loos::DoubleMatrix, loos::DoubleMatrix> result = svd(hessian_);
53 
54  t.stop();
55  if (verbosity_ > 1)
56  std::cerr << "SVD took " << loos::timeAsString(t.elapsed()) << std::endl;
57 
58 
59  eigenvecs_ = boost::get<0>(result);
60  eigenvals_ = boost::get<1>(result);
61  rsv_ = boost::get<2>(result);
62 
63  loos::Math::reverseRows(eigenvals_);
64  loos::Math::reverseColumns(eigenvecs_);
65  loos::Math::reverseRows(rsv_);
66  }
67 
68 
71 
72  if (rsv_.rows() == 0)
73  throw(std::logic_error("ANM::inverseHessian() called before ANM::solve()"));
74 
75  uint n = eigenvals_.rows();
76  for (uint i=6; i<n; ++i) {
77  double s = 1.0 / eigenvals_[i];
78  for (uint j=0; j<n; ++j)
79  rsv_(i, j) *= s;
80  }
81 
82  loos::DoubleMatrix Hi = loos::Math::MMMultiply(rsv_, eigenvecs_, true, true);
83  return(Hi);
84  }
85 
86 
87  private:
88  loos::DoubleMatrix rsv_;
89 
90  };
91 
92 };
93 
94 #endif
95 
96 
ElasticNetworkModel(SuperBlock *blocker)
Base constructor for all ENMs.
Definition: enm-lib.hpp:75
Simple matrix template class using policy classes to determine behavior.
Definition: MatrixImpl.hpp:53
This class creates superblocks in a hessian.
Definition: hessian.hpp:52
double elapsed(void) const
Return the elapsed time.
Definition: timer.hpp:109
void buildHessian()
Construct the hessian using the contained SuperBlock.
Definition: enm-lib.cpp:84
loos::DoubleMatrix inverseHessian()
Return the inverted hessian matrix.
Definition: anm-lib.hpp:70
void start(void)
Starts the timer.
Definition: timer.hpp:85
std::ostream & writeAsciiMatrix(std::ostream &os, const Math::Matrix< T, P, S > &M, const std::string &meta, const Math::Range &start, const Math::Range &end, const bool trans=false, F fmt=F())
Write a submatrix to a stream.
Namespace to encapsulate Elastic Network Model routines.
Definition: anm-lib.hpp:32
void solve()
Computes the hessian and solves for the eigenpairs.
Definition: anm-lib.hpp:39
std::string timeAsString(const double t, const uint precision)
Convert t (seconds) into a string, converting to hours and minutes as necessary.
Definition: utils.cpp:212
double stop(void)
Stops the timer.
Definition: timer.hpp:94
Class for tracking time.
Definition: timer.hpp:80
RealMatrix MMMultiply(const RealMatrix &A, const RealMatrix &B, const bool transa, const bool transb)
Matrix-matrix multiply (using BLAS)
Definition: MatrixOps.cpp:170
Anisotropic network model.
Definition: anm-lib.hpp:35
Interface for all ENMs.
Definition: enm-lib.hpp:67