LCOV - code coverage report
Current view: top level - core - TargetDist.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 0 27 0.0 %
Date: 2020-11-18 11:20:57 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2019 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.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       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           0 : void TargetDist::read( const PDB& pdb, std::vector<Value*> ar ) {
      31             :   // Clear values in target actions
      32           0 :   for(unsigned i=0; i<ar.size(); ++i) {
      33           0 :     (ar[i]->getPntrToAction())->clearInputForces();
      34           0 :     (ar[i]->getPntrToAction())->clearDerivatives();
      35             :   }
      36             : 
      37             :   // Caclulate target actions from input in PDB file
      38           0 :   std::vector<double> targ( ar.size() );
      39           0 :   for(unsigned i=0; i<ar.size(); ++i) {
      40           0 :     if( ar[i]->valueHasBeenSet() ) {
      41           0 :       targ[i]=ar[i]->get();
      42             :     } else {
      43           0 :       (ar[i]->getPntrToAction())->calculateFromPDB( pdb );
      44           0 :       targ[i]=ar[i]->get();
      45             :     }
      46             :   }
      47           0 :   read( targ, ar );
      48           0 : }
      49             : 
      50           0 : void TargetDist::read( const std::vector<double>& targ, std::vector<Value*> ar ) {
      51           0 :   plumed_assert( targ.size()==ar.size() );
      52             : 
      53           0 :   target.resize( ar.size() ); args.resize( ar.size() );
      54           0 :   log.printf("  distance from this point in cv space : ");
      55           0 :   for(unsigned i=0; i<target.size(); ++i) { log.printf("%f ", targ[i]); target[i]=targ[i]; args[i]=ar[i]; }
      56           0 :   log.printf("\n");
      57           0 : }
      58             : 
      59           0 : double TargetDist::calculate( std::vector<double>& derivs ) {
      60           0 :   plumed_assert( derivs.size()==args.size() );
      61             :   double dist=0;
      62           0 :   for(unsigned i=0; i<args.size(); ++i) {
      63           0 :     double tmp=args[i]->difference( target[i], args[i]->get() );
      64           0 :     derivs[i]=tmp; dist+=tmp*tmp;
      65             :   }
      66           0 :   dist=sqrt(dist);
      67           0 :   for(unsigned i=0; i<args.size(); ++i) derivs[i]/=dist;
      68           0 :   return dist;
      69             : }
      70             : 
      71             : }

Generated by: LCOV version 1.13