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