LOOS  v2.3.2
enm-lib.cpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2010 Tod D. Romo
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 */
22 
23 
24 #include "enm-lib.hpp"
25 
26 
27 using namespace std;
28 using namespace loos;
29 
30 
31 namespace ENM {
32 
33  // Map masses from one group onto another... Minimal error checking...
34  void copyMasses(AtomicGroup& target, const AtomicGroup& source) {
35  if (target.size() != source.size()) {
36  cerr << "ERROR- groups have different sizes in copyMasses... (maybe your PSF doesn't match the model?)\n";
37  exit(-1);
38  }
39 
40  for (uint i=0; i<target.size(); ++i) {
41  if (source[i]->name() != target[i]->name()) {
42  cerr << "ERROR- atom mismatch at position " << i << endl;
43  exit(-1);
44  }
45  target[i]->mass(source[i]->mass());
46  }
47  }
48 
49 
50  // Copy the masses from a PSF onto a group
51  void massFromPSF(AtomicGroup& grp, const string& name) {
52  AtomicGroup psf = createSystem(name);
53  copyMasses(grp, psf);
54  }
55 
56 
57  // The masses are stored in the occupancy field of a PDB...
59  for (AtomicGroup::iterator i = grp.begin(); i != grp.end(); ++i)
60  (*i)->mass((*i)->occupancy());
61  }
62 
63 
64  // Build the 3n x 3n diagonal mass matrix for a group
66  uint n = grp.size();
67 
68  DoubleMatrix M(3*n,3*n);
69  for (uint i=0, k=0; i<n; ++i, k += 3) {
70  M(k,k) = grp[i]->mass();
71  M(k+1,k+1) = grp[i]->mass();
72  M(k+2,k+2) = grp[i]->mass();
73  }
74 
75  return(M);
76  }
77 
78 
79 
80 
81 
82 
83 
84  void ElasticNetworkModel::buildHessian() {
85  uint n = blocker_->size();
86  loos::DoubleMatrix H(3*n,3*n);
87 
88  for (uint i=1; i<n; ++i) {
89  for (uint j=0; j<i; ++j) {
90  loos::DoubleMatrix B = blocker_->block(j, i);
91  for (uint x = 0; x<3; ++x)
92  for (uint y = 0; y<3; ++y) {
93  H(i*3 + y, j*3 + x) = -B(y, x);
94  H(j*3 + x, i*3 + y) = -B(x ,y);
95  }
96  }
97  }
98 
99  // Now handle the diagonal...
100  for (uint i=0; i<n; ++i) {
101  loos::DoubleMatrix B(3,3);
102  for (uint j=0; j<n; ++j) {
103  if (j == i)
104  continue;
105 
106  for (uint x=0; x<3; ++x)
107  for (uint y=0; y<3; ++y)
108  B(y,x) += H(j*3 + y, i*3 + x);
109  }
110 
111  for (uint x=0; x<3; ++x)
112  for (uint y=0; y<3; ++y)
113  H(i*3 + y, i*3 + x) = -B(y,x);
114  }
115 
116  hessian_ = H;
117  }
118 
119 
120 
121 };
void copyMasses(AtomicGroup &target, const AtomicGroup &source)
Map masses from one group onto another... Minimal error checking...
Definition: enm-lib.cpp:34
Simple matrix template class using policy classes to determine behavior.
Definition: MatrixImpl.hpp:53
STL namespace.
DoubleMatrix getMasses(const AtomicGroup &grp)
Build the 3n x 3n diagonal mass matrix for a group.
Definition: enm-lib.cpp:65
AtomicGroup createSystem(const std::string &filename)
Factory function for reading in structure files.
Definition: sfactories.cpp:115
void massFromOccupancy(AtomicGroup &grp)
The masses are stored in the occupancy field of a PDB...
Definition: enm-lib.cpp:58
Namespace to encapsulate Elastic Network Model routines.
Definition: anm-lib.hpp:32
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.
void massFromPSF(AtomicGroup &grp, const string &name)
Copy the masses from a PSF onto a group.
Definition: enm-lib.cpp:51