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_reference_ReferenceArguments_h 23 : #define __PLUMED_reference_ReferenceArguments_h 24 : 25 : #include "ReferenceConfiguration.h" 26 : #include "tools/Matrix.h" 27 : 28 : namespace PLMD { 29 : 30 : /// \ingroup TOOLBOX 31 : /// In many applications (e.g. paths, fields, property maps) it is necessary to calculate 32 : /// the distance between two configurations. These distances can be calculated in a variety of 33 : /// different ways. For instance, one can assert that the distance between the two configuration 34 : /// is the distance one would have to move all the atoms to transform configuration 1 into configuration 35 : /// 2. Alternatively, one could calculate the values of a large set of collective coordinates in the two 36 : /// configurations and then calculate the Euclidean distances between these two points in the resulting 37 : /// high-dimensional vector space. Lastly, one can combine these two forms of distance calculation to calculate 38 : /// a hybrid distance. Plumed allows one to use all these forms of distance calculations and also to implement 39 : /// new forms of distance. You should inherit from this class if your distance involves reference colvar values. 40 : /// This class and \ref PLMD::ReferenceAtoms mirror the functionalities in \ref PLMD::ActionWithArguments and 41 : /// \ref PLMD::ActionAtomistic respectively but for distances. 42 : 43 : class ReferenceArguments : 44 : virtual public ReferenceConfiguration 45 : { 46 : friend class Direction; 47 : friend class ReferenceConfiguration; 48 : private: 49 : /// The weights for normed euclidean distance 50 : std::vector<double> weights, sqrtweight; 51 : /// The N X N matrix we are using to calculate our Malanobius distance 52 : Matrix<double> metric; 53 : std::vector<double> trig_metric; 54 : /// The values of the colvars in the reference configuration 55 : std::vector<double> reference_args; 56 : /// The names of the arguments 57 : std::vector<std::string> arg_names; 58 : /// The indices for setting derivatives 59 : std::vector<unsigned> arg_der_index; 60 : protected: 61 : /// Are we reading weights from input 62 : bool hasweights; 63 : /// Are we calculating a Malanobius distance 64 : bool hasmetric; 65 : /// Read in the atoms from the pdb file 66 : void readArgumentsFromPDB( const PDB& pdb ); 67 : /// Set the values of the colvars based on their current instantanous values (used in Analysis) 68 : void setReferenceArguments(); 69 : public: 70 : explicit ReferenceArguments( const ReferenceConfigurationOptions& ro ); 71 : /// Get the number of reference arguments 72 : unsigned getNumberOfReferenceArguments() const override; 73 : /// Get the arguments required 74 : void getArgumentRequests( std::vector<std::string>&, bool disable_checks=false ) override; 75 : /// Set the positions of the reference arguments 76 : void setReferenceArguments( const std::vector<double>& arg_vals, const std::vector<double>& sigma ); 77 : /// Set the positions of the reference arguments 78 : void moveReferenceArguments( const std::vector<double>& arg_vals ); 79 : /// Get the value of the ith reference argument 80 : double getReferenceArgument( const unsigned& i ) const override; 81 : /// Return all the reference arguments 82 : const std::vector<double>& getReferenceArguments() const override; 83 : const std::vector<double>& getReferenceMetric() override; 84 : /// Return names 85 : const std::vector<std::string>& getArgumentNames() override; 86 : /// Calculate the euclidean/malanobius distance the atoms have moved from the reference 87 : /// configuration in CV space 88 : virtual double calculateArgumentDistance( const std::vector<Value*> & vals, const std::vector<double>& arg, ReferenceValuePack& myder, const bool& squared ) const ; 89 : /// Displace the positions of the reference atoms 90 : void displaceReferenceArguments( const double& weight, const std::vector<double>& displace ); 91 : /// Extract the displacement from a position in a space 92 : virtual void extractArgumentDisplacement( const std::vector<Value*>& vals, const std::vector<double>& arg, std::vector<double>& dirout ) const ; 93 : /// Project the displacement of the arguments on a vector 94 : double projectArgDisplacementOnVector( const std::vector<double>& eigv, const std::vector<Value*>& vals, const std::vector<double>& arg, ReferenceValuePack& mypack ) const ; 95 : }; 96 : 97 : inline 98 1020 : double ReferenceArguments::getReferenceArgument( const unsigned& i ) const { 99 : plumed_dbg_assert( i<reference_args.size() ); 100 1040 : return reference_args[i]; 101 : } 102 : 103 : inline 104 790964 : const std::vector<double>& ReferenceArguments::getReferenceArguments() const { 105 790964 : return reference_args; 106 : } 107 : 108 : inline 109 962 : const std::vector<std::string>& ReferenceArguments::getArgumentNames() { 110 962 : return arg_names; 111 : } 112 : 113 : inline 114 39585 : unsigned ReferenceArguments::getNumberOfReferenceArguments() const { 115 39585 : return reference_args.size(); 116 : } 117 : 118 : } 119 : #endif 120 :