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 : friend class Direction; 46 : friend class ReferenceConfiguration; 47 : private: 48 : /// The weights for normed euclidean distance 49 : std::vector<double> weights, sqrtweight; 50 : /// The N X N matrix we are using to calculate our Malanobius distance 51 : Matrix<double> metric; 52 : std::vector<double> trig_metric; 53 : /// The values of the colvars in the reference configuration 54 : std::vector<double> reference_args; 55 : /// The names of the arguments 56 : std::vector<std::string> arg_names; 57 : /// The indices for setting derivatives 58 : std::vector<unsigned> arg_der_index; 59 : protected: 60 : /// Are we reading weights from input 61 : bool hasweights; 62 : /// Are we calculating a Malanobius distance 63 : bool hasmetric; 64 : /// Read in the atoms from the pdb file 65 : void readArgumentsFromPDB( const PDB& pdb ); 66 : /// Set the values of the colvars based on their current instantanous values (used in Analysis) 67 : void setReferenceArguments(); 68 : public: 69 : explicit ReferenceArguments( const ReferenceConfigurationOptions& ro ); 70 : /// Get the number of reference arguments 71 : unsigned getNumberOfReferenceArguments() const override; 72 : /// Get the arguments required 73 : void getArgumentRequests( std::vector<std::string>&, bool disable_checks=false ) override; 74 : /// Set the positions of the reference arguments 75 : void setReferenceArguments( const std::vector<double>& arg_vals, const std::vector<double>& sigma ); 76 : /// Set the positions of the reference arguments 77 : void moveReferenceArguments( const std::vector<double>& arg_vals ); 78 : /// Get the value of the ith reference argument 79 : double getReferenceArgument( const unsigned& i ) const override; 80 : /// Return all the reference arguments 81 : const std::vector<double>& getReferenceArguments() const override; 82 : const std::vector<double>& getReferenceMetric() override; 83 : /// Return names 84 : const std::vector<std::string>& getArgumentNames() override; 85 : /// Calculate the euclidean/malanobius distance the atoms have moved from the reference 86 : /// configuration in CV space 87 : virtual double calculateArgumentDistance( const std::vector<Value*> & vals, const std::vector<double>& arg, ReferenceValuePack& myder, const bool& squared ) const ; 88 : /// Displace the positions of the reference atoms 89 : void displaceReferenceArguments( const double& weight, const std::vector<double>& displace ); 90 : /// Extract the displacement from a position in a space 91 : virtual void extractArgumentDisplacement( const std::vector<Value*>& vals, const std::vector<double>& arg, std::vector<double>& dirout ) const ; 92 : /// Project the displacement of the arguments on a vector 93 : double projectArgDisplacementOnVector( const std::vector<double>& eigv, const std::vector<Value*>& vals, const std::vector<double>& arg, ReferenceValuePack& mypack ) const ; 94 : }; 95 : 96 : inline 97 1020 : double ReferenceArguments::getReferenceArgument( const unsigned& i ) const { 98 : plumed_dbg_assert( i<reference_args.size() ); 99 1040 : return reference_args[i]; 100 : } 101 : 102 : inline 103 790964 : const std::vector<double>& ReferenceArguments::getReferenceArguments() const { 104 790964 : return reference_args; 105 : } 106 : 107 : inline 108 962 : const std::vector<std::string>& ReferenceArguments::getArgumentNames() { 109 962 : return arg_names; 110 : } 111 : 112 : inline 113 39585 : unsigned ReferenceArguments::getNumberOfReferenceArguments() const { 114 39585 : return reference_args.size(); 115 : } 116 : 117 : } 118 : #endif 119 :