LCOV - code coverage report
Current view: top level - isdb - MetainferenceBase.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 41 49 83.7 %
Date: 2026-11-05 10:19:04 Functions: 7 11 63.6 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2017-2026 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 "MetainferenceBase.h"
      23             : 
      24             : namespace PLMD {
      25             : namespace isdb {
      26             : 
      27         286 : void MetainferenceBase::registerKeywords( Keywords& keys ) {
      28         286 :   Action::registerKeywords(keys);
      29         286 :   ActionAtomistic::registerKeywords(keys);
      30         286 :   ActionWithValue::registerKeywords(keys);
      31         286 :   ActionWithArguments::registerKeywords(keys);
      32         572 :   keys.addInputKeyword("optional","ARG","scalar","the labels of the values from which the function is calculated");
      33         286 :   keys.addFlag("DOSCORE",false,"activate metainference");
      34         286 :   MetainferenceCore::registerKeywords(keys);
      35         572 :   keys.addOutputComponent("score",        "default",      "scalar","the Metainference score");
      36         286 : }
      37             : 
      38         254 : MetainferenceBase::MetainferenceBase(const ActionOptions&ao):
      39             :   Action(ao),
      40             :   ActionAtomistic(ao),
      41             :   ActionWithArguments(ao),
      42             :   ActionWithValue(ao),
      43         254 :   doscore_(false),
      44         254 :   narg(0),
      45         254 :   valueScore(nullptr),
      46         254 :   iselect(0) {
      47         254 :   parseFlag("DOSCORE", doscore_);
      48         508 :   core_=std::make_unique<MetainferenceCore>(*this,doscore_);
      49             :   // reweight implies a different number of arguments (the latest one must always be the bias)
      50         254 :   if(core_->doReweight()&&getNumberOfArguments()!=1) {
      51           0 :     error("To REWEIGHT one must provide one single bias as an argument");
      52             :   }
      53         254 : }
      54             : 
      55         254 : MetainferenceBase::~MetainferenceBase() {
      56         508 : }
      57             : 
      58          83 : void MetainferenceBase::Initialise(const unsigned input) {
      59             :   setNarg(input);
      60          83 :   if(narg!=parameters.size()) {
      61             :     std::string num1;
      62           0 :     Tools::convert(parameters.size(),num1);
      63             :     std::string num2;
      64           0 :     Tools::convert(narg,num2);
      65           0 :     std::string msg = "The number of experimental values " + num1 +" must be the same of the calculated values " + num2;
      66           0 :     error(msg);
      67             :   }
      68             : 
      69         166 :   addComponentWithDerivatives("score");
      70          83 :   componentIsNotPeriodic("score");
      71          83 :   valueScore=getPntrToComponent("score");
      72             : 
      73          83 :   core_->setup(parameters, *this, [this](const std::string& name) {
      74        5928 :     return getPntrToComponent(name);
      75             :   });
      76          83 : }
      77             : 
      78        2503 : void MetainferenceBase::Selector() {
      79        2503 :   iselect = core_->getSelector();
      80        2503 : }
      81             : 
      82        2503 : double MetainferenceBase::getScore() {
      83             :   // selector for REM-like simulations
      84        2503 :   Selector();
      85        2503 :   const double ene = core_->calculate(iselect, core_->doReweight() ? getArgument(0) : 0.);
      86        2503 :   if(core_->doReweight()) {
      87        1936 :     setArgDerivatives(valueScore, core_->getBiasDer());
      88             :   }
      89        2503 :   return ene;
      90             : }
      91             : 
      92           0 : void MetainferenceBase::writeStatus() {
      93           0 :   core_->writeStatus();
      94           0 : }
      95             : 
      96        1323 : void MetainferenceBase::update() {
      97             :   // write the status file
      98        1323 :   core_->update();
      99        1323 : }
     100             : 
     101             : }
     102             : }

Generated by: LCOV version 1.16