All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TargetDist.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 "TargetDist.h"
23 #include "tools/PDB.h"
24 #include "ActionWithValue.h"
25 #include "Value.h"
26 
27 
28 namespace PLMD {
29 
30 void TargetDist::read( const PDB& pdb, std::vector<Value*> ar ){
31  // Clear values in target actions
32  for(unsigned i=0;i<ar.size();++i){
33  (ar[i]->getPntrToAction())->clearInputForces();
34  (ar[i]->getPntrToAction())->clearDerivatives();
35  }
36 
37  // Caclulate target actions from input in PDB file
38  std::vector<double> targ( ar.size() );
39  for(unsigned i=0;i<ar.size();++i){
40  if( ar[i]->valueHasBeenSet() ){
41  targ[i]=ar[i]->get();
42  } else {
43  (ar[i]->getPntrToAction())->calculateFromPDB( pdb );
44  targ[i]=ar[i]->get();
45  }
46  }
47  read( targ, ar );
48 }
49 
50 void TargetDist::read( const std::vector<double>& targ, std::vector<Value*> ar ){
51  plumed_assert( targ.size()==ar.size() );
52 
53  target.resize( ar.size() ); args.resize( ar.size() );
54  log.printf(" distance from this point in cv space : ");
55  for(unsigned i=0;i<target.size();++i){ log.printf("%f ", targ[i]); target[i]=targ[i]; args[i]=ar[i]; }
56  log.printf("\n");
57 }
58 
59 double TargetDist::calculate( std::vector<double>& derivs ){
60  plumed_assert( derivs.size()==args.size() );
61  double dist=0, tmp;
62  for(unsigned i=0;i<args.size();++i){
63  tmp=args[i]->difference( target[i], args[i]->get() );
64  derivs[i]=tmp; dist+=tmp*tmp;
65  }
66  dist=sqrt(dist);
67  for(unsigned i=0;i<args.size();++i) derivs[i]/=dist;
68  return dist;
69 }
70 
71 }
void read(const PDB &pdb, std::vector< Value * > args)
Definition: TargetDist.cpp:30
std::vector< double > target
Definition: TargetDist.h:37
double calculate(std::vector< double > &derivs)
Definition: TargetDist.cpp:59
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
std::vector< Value * > args
Definition: TargetDist.h:36
Minimalistic pdb parser.
Definition: PDB.h:38