All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DRMSD.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #include "DRMSD.h"
23 #include "PDB.h"
24 #include "Pbc.h"
25 #include <cmath>
26 
27 using namespace std;
28 namespace PLMD{
29 
30 void DRMSD::setFromPDB(const PDB&pdb, double lbound, double ubound){
31  setReference(pdb.getPositions(), lbound, ubound);
32 }
33 
34 void DRMSD::clear(){
35  targets.clear();
36 }
37 
38 void DRMSD::setReference(const vector<Vector> & reference, double lbound, double ubound)
39 {
40  natoms = reference.size();
41  for(unsigned i=0;i<natoms-1;++i){
42  for(unsigned j=i+1;j<natoms;++j){
43  double distance = delta(reference[i],reference[j]).modulo();
44  if(distance > lbound && distance < ubound){
45  targets[make_pair(i,j)] = distance;
46  }
47  }
48  }
49 }
50 
51 double DRMSD::calculate(const std::vector<Vector> & positions,
52  std::vector<Vector> &derivatives, Tensor& virial) const {
53 
54  Pbc fake_pbc;
55  return DRMSD::calculate(positions,fake_pbc,derivatives,virial,false);
56 }
57 
58 double DRMSD::calculate(const std::vector<Vector> & positions, const Pbc& pbc,
59  std::vector<Vector> &derivatives, Tensor& virial, bool do_pbc) const {
60 
61  plumed_assert(positions.size()==natoms && derivatives.size()==natoms );
62 
63  Vector distance;
64  double drmsd=0.; virial.zero();
65  for(unsigned i=0;i<derivatives.size();++i) derivatives[i].zero();
66  for(map< pair <unsigned,unsigned> , double>::const_iterator it=targets.begin();it!=targets.end();++it){
67  unsigned i=it->first.first;
68  unsigned j=it->first.second;
69  if(do_pbc){distance=pbc.distance( positions[i] , positions[j] );}
70  else{distance=delta( positions[i] , positions[j] );}
71  double len = distance.modulo();
72  double diff = len - it->second;
73  drmsd += diff * diff;
74  derivatives[i] += -( diff / len ) * distance;
75  derivatives[j] += ( diff / len ) * distance;
76  virial -= ( diff / len ) * Tensor(distance,distance);
77  }
78 
79  double npairs = static_cast<double>(targets.size());
80 
81  drmsd=sqrt( drmsd / npairs );
82 
83  double idrmsd=1.0/( drmsd * npairs );
84 
85  virial *= idrmsd;
86 
87  for(unsigned i=0;i<natoms;++i){derivatives[i] *= idrmsd;}
88 
89  return drmsd;
90 }
91 
92 
93 }
void zero()
set it to zero
Definition: Tensor.h:198
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
STL namespace.
Definition: Pbc.h:38
Vector distance(const Vector &, const Vector &, int *nshifts) const
internal version of distance, also returns the number of attempted shifts (used in Pbc::test())...
Definition: Pbc.cpp:158
const std::vector< Vector > & getPositions() const
Access to the position array.
Definition: PDB.cpp:31
VectorGeneric< n > delta(const VectorGeneric< n > &v1, const VectorGeneric< n > &v2)
Definition: Vector.h:262
Minimalistic pdb parser.
Definition: PDB.h:38
Tensor3d Tensor
Definition: Tensor.h:425