LOOS  v2.3.2
hessian.hpp
1 /*
2  hessian matrix construction code
3 
4 */
5 
6 
7 /*
8  This file is part of LOOS.
9 
10  LOOS (Lightweight Object-Oriented Structure library)
11  Copyright (c) 2009 Tod D. Romo
12  Department of Biochemistry and Biophysics
13  School of Medicine & Dentistry, University of Rochester
14 
15  This package (LOOS) is free software: you can redistribute it and/or modify
16  it under the terms of the GNU General Public License as published by
17  the Free Software Foundation under version 3 of the License.
18 
19  This package is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <http://www.gnu.org/licenses/>.
26 
27 */
28 
29 
36 #if !defined(LOOS_HESSIAN_HPP)
37 #define LOOS_HESSIAN_HPP
38 
39 
40 #include <loos.hpp>
41 
42 #include "spring_functions.hpp"
43 
44 namespace ENM {
45 
47 
52  class SuperBlock {
53  public:
54  SuperBlock() : springs(0) { }
55 
57 
68  SuperBlock(SpringFunction* func, const loos::AtomicGroup& nodelist) : springs(func), nodes(nodelist) { }
69  SuperBlock(const SuperBlock& b) : springs(b.springs), nodes(b.nodes) { }
70  virtual ~SuperBlock() { }
71 
72  uint size() const { return(static_cast<uint>(nodes.size())); }
73 
74  // ------------------------------------------------------
76  virtual SpringFunction::Params setParams(const SpringFunction::Params& v) {
77  return(springs->setParams(v));
78  }
79 
81  virtual bool validParams() const { return(springs->validParams()); }
82 
84  virtual uint paramSize() const { return(springs->paramSize()); }
85  // ------------------------------------------------------
86 
88  virtual loos::DoubleMatrix block(const uint j, const uint i) {
89  return(blockImpl(j, i, springs));
90  }
91 
92 
93  protected:
94 
96 
101  loos::DoubleMatrix blockImpl(const uint j, const uint i, SpringFunction* fptr) {
102  if (i >= size() || j >= size())
103  throw(std::runtime_error("Invalid index in Hessian SuperBlock"));
104 
105  if (fptr == 0)
106  throw(std::runtime_error("No spring function defined for hessian!"));
107 
108  loos::GCoord u = nodes[j]->coords();
109  loos::GCoord v = nodes[i]->coords();
110  loos::GCoord d = v - u;
111 
112  loos::DoubleMatrix K = fptr->constant(u, v, d);
113  loos::DoubleMatrix B(3, 3);
114  for (uint y=0; y<3; ++y)
115  for (uint x=0; x<3; ++x)
116  B(x, y) = d[x]*d[y] * K(x,y);
117 
118  return(B);
119  }
120 
121 
122  SpringFunction* springs;
123  loos::AtomicGroup nodes;
124  };
125 
126 
127 
129 
136  public:
137 
139  SuperBlockDecorator(SuperBlock* b) : SuperBlock(*b), decorated(b) { }
140 
141  protected:
142  SuperBlock *decorated;
143  };
144 
145 
146 
148 
187  public:
190  bound_spring(bs),
191  connectivity(cm)
192  {
193  if (connectivity.rows() != connectivity.cols() && connectivity.cols() != size())
194  throw(std::runtime_error("Connectivity matrix and Nodelist have differing sizes"));
195  }
196 
197 
198  // Block now checks to see if nodes i and j are connected and, if
199  // so, uses our alternative spring function.
200  loos::DoubleMatrix block(const uint j, const uint i) {
201  if (connectivity(j, i))
202  return(blockImpl(j, i, bound_spring));
203  else
204  return(decorated->block(j, i));
205  }
206 
208  SpringFunction::Params setParams(const SpringFunction::Params& v) {
209  SpringFunction::Params u = bound_spring->setParams(v);
210  if (! u.empty())
211  u = decorated->setParams(u);
212  return(u);
213  }
214 
216  bool validParams() const { return(bound_spring->validParams() && decorated->validParams()); }
217 
219  uint paramSize() const { return(bound_spring->paramSize() + decorated->paramSize()); }
220 
221  private:
222  SpringFunction* bound_spring;
223  loos::Math::Matrix<int> connectivity;
224  };
225 
226 };
227 
228 #endif
229 
230 
231 
virtual Params setParams(const Params &konst)=0
Sets the internal constants, returning the unused ones.
virtual loos::DoubleMatrix block(const uint j, const uint i)
Returns a 3x3 matrix representing a superblock in the Hessian for the two nodes.
Definition: hessian.hpp:88
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
loos::DoubleMatrix block(const uint j, const uint i)
Returns a 3x3 matrix representing a superblock in the Hessian for the two nodes.
Definition: hessian.hpp:200
SuperBlock(SpringFunction *func, const loos::AtomicGroup &nodelist)
Constructor taking a spring function and a list of nodes.
Definition: hessian.hpp:68
uint paramSize() const
Returns the aggregate parameter size.
Definition: hessian.hpp:219
Decorator for switching spring functions based on a matrix of flags.
Definition: hessian.hpp:186
Interface for ENM spring functions.
virtual SpringFunction::Params setParams(const SpringFunction::Params &v)
Forwards to the contained SpringFunction...
Definition: hessian.hpp:76
Namespace to encapsulate Elastic Network Model routines.
Definition: anm-lib.hpp:32
virtual loos::DoubleMatrix constant(const loos::GCoord &u, const loos::GCoord &v, const loos::GCoord &d)=0
Actually compute the spring constant as a 3x3 matrix.
SuperBlock decorator base class.
Definition: hessian.hpp:135
loos::DoubleMatrix blockImpl(const uint j, const uint i, SpringFunction *fptr)
Implementation of the superblock calculation.
Definition: hessian.hpp:101
virtual uint paramSize() const
Forwards to the contained SpringFunction...
Definition: hessian.hpp:84
virtual uint paramSize() const =0
How many internal constants there are.
virtual bool validParams() const
Forwards to the contained SpringFunction...
Definition: hessian.hpp:81
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
SpringFunction::Params setParams(const SpringFunction::Params &v)
Assign parameters and propagate to the decorated superblock.
Definition: hessian.hpp:208
virtual bool validParams() const =0
Determines if the internal constants are "valid".
SuperBlockDecorator(SuperBlock *b)
Constructor that takes a SuperBlock to decorate.
Definition: hessian.hpp:139
bool validParams() const
Both the alternate and all decorated parameters are valid.
Definition: hessian.hpp:216