LCOV - code coverage report
Current view: top level - mapping - Mapping.h (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 13 15 86.7 %
Date: 2026-03-30 13:16:06 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2023 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             : #ifndef __PLUMED_mapping_Mapping_h
      23             : #define __PLUMED_mapping_Mapping_h
      24             : 
      25             : #include "core/ActionAtomistic.h"
      26             : #include "core/ActionWithValue.h"
      27             : #include "core/ActionWithArguments.h"
      28             : #include "vesselbase/ActionWithVessel.h"
      29             : #include "reference/ReferenceConfiguration.h"
      30             : #include <vector>
      31             : #include <map>
      32             : #include <memory>
      33             : 
      34             : namespace PLMD {
      35             : 
      36             : class PDB;
      37             : 
      38             : namespace mapping {
      39             : 
      40             : class Mapping :
      41             :   public ActionAtomistic,
      42             :   public ActionWithArguments,
      43             :   public ActionWithValue,
      44             :   public vesselbase::ActionWithVessel {
      45             :   friend class PropertyMap;
      46             :   friend class TrigonometricPathVessel;
      47             :   friend class AdaptivePath;
      48             : private:
      49             : //  The derivative wrt to the distance from the frame
      50             :   std::vector<double> dfframes;
      51             : /// This holds all the reference information
      52             :   std::vector<std::unique_ptr<ReferenceConfiguration> > myframes;
      53             : /// The forces on each of the derivatives (used in apply)
      54             :   std::vector<double> forcesToApply;
      55             : /// The weights of the various configurations
      56             :   std::vector<double> weights;
      57             : /// The list of properties in the property map
      58             :   std::map<std::string,std::vector<double> > property;
      59             : protected:
      60             : /// The (transformed) distance from each frame
      61             :   std::vector<double> fframes;
      62             : /// Get the number of frames in the path
      63             :   unsigned getNumberOfReferencePoints() const;
      64             : /// Finish the setup of the referenceValuePack by transferring atoms and args
      65             :   void finishPackSetup( const unsigned& ifunc, ReferenceValuePack& mypack ) const ;
      66             : /// Calculate the value of the distance from the ith frame
      67             :   double calculateDistanceFunction( const unsigned& ifunc, ReferenceValuePack& myder, const bool& squared ) const ;
      68             : /// Get the value of the weight
      69             :   double getWeight( const unsigned& weight ) const ;
      70             : /// Return the vector of refernece configurations
      71             :   std::vector<std::unique_ptr<ReferenceConfiguration>>& getAllReferenceConfigurations();
      72             : /// Return a pointer to one of the reference configurations
      73             :   ReferenceConfiguration* getReferenceConfiguration( const unsigned& ifunc );
      74             : public:
      75             :   static void registerKeywords( Keywords& keys );
      76             :   explicit Mapping(const ActionOptions&);
      77             : /// Overload the virtual functions that appear in both ActionAtomistic and ActionWithArguments
      78             :   void turnOnDerivatives() override;
      79             :   void calculateNumericalDerivatives( ActionWithValue* a=NULL ) override;
      80             :   void lockRequests() override;
      81             :   void unlockRequests() override;
      82             : /// Distance from a point is never periodic
      83           0 :   bool isPeriodic() override {
      84           0 :     return false;
      85             :   }
      86             : /// Get the number of derivatives for this action
      87             :   unsigned getNumberOfDerivatives() override;  // N.B. This is replacing the virtual function in ActionWithValue
      88             : /// Get the value of lambda for paths and property maps
      89             :   virtual double getLambda();
      90             : /// This does the transformation of the distance by whatever function is required
      91             :   virtual double transformHD( const double& dist, double& df ) const=0;
      92             : /// Get the number of properties we are projecting onto
      93             :   unsigned getNumberOfProperties() const ;
      94             : /// Get the name of the ith argument
      95             :   std::string getArgumentName( unsigned& iarg );
      96             : /// Get the value of the ith property for the current frame
      97             :   double getPropertyValue( const unsigned& current, const std::string& name ) const ;
      98             : /// Apply the forces
      99             :   void apply() override;
     100             : };
     101             : 
     102             : inline
     103             : unsigned Mapping::getNumberOfReferencePoints() const {
     104         469 :   return myframes.size();
     105             : }
     106             : 
     107             : inline
     108       20192 : unsigned Mapping::getNumberOfDerivatives() {
     109             :   unsigned nat=getNumberOfAtoms();
     110       20192 :   if(nat>0) {
     111       17580 :     return 3*nat + 9 + getNumberOfArguments();
     112             :   }
     113        2612 :   return getNumberOfArguments();
     114             : }
     115             : 
     116             : inline
     117        5015 : void Mapping::lockRequests() {
     118             :   ActionWithArguments::lockRequests();
     119             :   ActionAtomistic::lockRequests();
     120        5015 : }
     121             : 
     122             : inline
     123        5015 : void Mapping::unlockRequests() {
     124             :   ActionWithArguments::unlockRequests();
     125             :   ActionAtomistic::unlockRequests();
     126        5015 : }
     127             : 
     128             : inline
     129       30972 : double Mapping::getPropertyValue( const unsigned& cur, const std::string& name ) const {
     130       30972 :   return property.find(name)->second[cur];
     131             : }
     132             : 
     133             : inline
     134             : double Mapping::getWeight( const unsigned& current ) const {
     135             :   return weights[current];
     136             : }
     137             : 
     138             : inline
     139             : std::vector<std::unique_ptr<ReferenceConfiguration>>& Mapping::getAllReferenceConfigurations() {
     140           2 :   return myframes;
     141             : }
     142             : 
     143             : inline
     144             : unsigned Mapping::getNumberOfProperties() const {
     145           3 :   return property.size();
     146             : }
     147             : 
     148             : }
     149             : }
     150             : #endif

Generated by: LCOV version 1.16