Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2013-2019 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_ReferenceConfiguration_h
23 : #define __PLUMED_reference_ReferenceConfiguration_h
24 :
25 : #include <vector>
26 : #include <string>
27 : #include "tools/Vector.h"
28 : #include "tools/Tensor.h"
29 : #include "tools/Tools.h"
30 : #include "tools/Exception.h"
31 : #include "ReferenceValuePack.h"
32 : #include "tools/Matrix.h"
33 :
34 : namespace PLMD {
35 :
36 : class Value;
37 : class Pbc;
38 : class OFile;
39 : class PDB;
40 : class Direction;
41 :
42 2006 : class ReferenceConfigurationOptions {
43 : friend class ReferenceConfiguration;
44 : private:
45 : std::string tt;
46 : public:
47 : explicit ReferenceConfigurationOptions( const std::string& type );
48 : bool usingFastOption() const ;
49 : std::string getMultiRMSDType() const ;
50 : };
51 :
52 : /// \ingroup INHERIT
53 : /// Abstract base class for calculating the distance from a reference configuration.
54 : /// A reference configuration can either have a particular set of atoms in a particular
55 : /// given configuration or it can be that a particular set of colvars have a particular
56 : /// set of values. It could also be a combination of both. To allow all the posible
57 : /// permutations and in order make it easy to add new ways of calculating the distance
58 : /// we have implemented this using polymorphism and multiple inheritance. The following
59 : /// provides \ref AddingAMetric "information" on how to implement a new method for
60 : /// calculating the distance between a pair of configurations
61 :
62 938 : class ReferenceConfiguration {
63 : friend class SingleDomainRMSD;
64 : friend double distance( const Pbc& pbc, const std::vector<Value*> & vals, ReferenceConfiguration*, ReferenceConfiguration*, const bool& squared );
65 : private:
66 : /// The name of this particular config
67 : std::string name;
68 : /// A weight assigned to this particular frame
69 : double weight;
70 : /// A vector containing all the remarks from the pdb input
71 : std::vector<std::string> line;
72 : /// This is used to store the values of arguments
73 : // std::vector<double> tmparg;
74 : /// These are used to do fake things when we copy frames
75 : std::vector<AtomNumber> fake_atom_numbers;
76 : std::vector<std::string> fake_arg_names;
77 : /// These are use by the distance function above
78 : std::vector<Vector> fake_refatoms;
79 : std::vector<double> fake_refargs;
80 : std::vector<double> fake_metric;
81 : protected:
82 : /// Derivatives wrt to the arguments
83 : // std::vector<double> arg_ders;
84 : /// The virial contribution has to be stored
85 : // bool virialWasSet;
86 : // Tensor virial;
87 : /// Derivatives wrt to the atoms
88 : // std::vector<Vector> atom_ders;
89 : /// Crash with an error
90 : void error(const std::string& msg);
91 : /// Clear the derivatives
92 : // void clearDerivatives();
93 : public:
94 : explicit ReferenceConfiguration( const ReferenceConfigurationOptions& ro );
95 : /// Destructor
96 : virtual ~ReferenceConfiguration();
97 : /// Return the name of this metric
98 : std::string getName() const ;
99 : ///
100 : virtual unsigned getNumberOfReferencePositions() const ;
101 : virtual unsigned getNumberOfReferenceArguments() const ;
102 : /// Retrieve the atoms that are required for this guy
103 92 : virtual void getAtomRequests( std::vector<AtomNumber>&, bool disable_checks=false ) {}
104 : /// Retrieve the arguments that are required for this guy
105 352 : virtual void getArgumentRequests( std::vector<std::string>&, bool disable_checks=false ) {}
106 : /// Set the final number of arguments
107 : // virtual void setNumberOfArguments( const unsigned& );
108 : /// Set the final number of atoms
109 : // virtual void setNumberOfAtoms( const unsigned& );
110 : /// Set the reference configuration using a PDB
111 : virtual void set( const PDB& );
112 : /// Do all local business for setting the configuration
113 : virtual void read( const PDB& )=0;
114 : /// Set the weight for this frame
115 : void setWeight( const double& ww );
116 : /// Return the weight for this frame
117 : double getWeight() const ;
118 : /// Calculate the distance from the reference configuration
119 : double calculate( const std::vector<Vector>& pos, const Pbc& pbc, const std::vector<Value*>& vals, ReferenceValuePack& myder, const bool& squared=false ) const ;
120 : /// Calculate the distance from the reference configuration
121 : virtual double calc( const std::vector<Vector>& pos, const Pbc& pbc, const std::vector<Value*>& vals, const std::vector<double>& args,
122 : ReferenceValuePack& myder, const bool& squared ) const=0;
123 : // /// Return the derivative wrt to the ith atom
124 : // Vector getAtomDerivative( const unsigned& ) const ;
125 : // /// Return the derivative wrt to the ith argument
126 : // double getArgumentDerivative( const unsigned& ) const ;
127 : /// Return the derivatives of the distance wrt the cell vectors. This returns false
128 : /// for everything other than DRMSD as these sort of calculations have to be done
129 : /// separately when you use RMSD
130 : // bool getVirial( Tensor& virout ) const ;
131 : /// Parse something from the pdb remarks
132 : template<class T>
133 : bool parse( const std::string&key, T&t, bool ignore_missing=false );
134 : /// Parse vector from the pdb remarks
135 : template<class T>
136 : bool parseVector( const std::string&key, std::vector<T>&t, bool ignore_missing=false );
137 : /// Parse a flag
138 : void parseFlag(const std::string&key,bool&t);
139 : /// Check that all the remarks in the pdb have been read in
140 : void checkRead();
141 : /// Copy derivatives from one frame to this frame
142 : void copyDerivatives( const ReferenceConfiguration* );
143 : /// Set the atom numbers and the argument names
144 : void setNamesAndAtomNumbers( const std::vector<AtomNumber>& numbers, const std::vector<std::string>& arg );
145 : /// Set the reference structure (perhaps should also pass the pbc and align and displace )
146 : void setReferenceConfig( const std::vector<Vector>& pos, const std::vector<double>& arg, const std::vector<double>& metric );
147 : /// Print a pdb file containing the reference configuration
148 : void print( OFile& ofile, const double& time, const double& weight, const double& lunits, const double& old_norm );
149 : void print( OFile& ofile, const std::string& fmt, const double& lunits );
150 : /// Get one of the referene arguments
151 0 : virtual double getReferenceArgument( const unsigned& i ) const { plumed_error(); return 0.0; }
152 : /// These are overwritten in ReferenceArguments and ReferenceAtoms but are required here
153 : /// to make PLMD::distance work
154 : virtual const std::vector<Vector>& getReferencePositions() const ;
155 : virtual const std::vector<double>& getReferenceArguments() const ;
156 : virtual const std::vector<double>& getReferenceMetric();
157 : /// These are overwritten in ReferenceArguments and ReferenceAtoms to make frame copying work
158 : virtual const std::vector<AtomNumber>& getAbsoluteIndexes();
159 : virtual const std::vector<std::string>& getArgumentNames();
160 : /// Extract a Direction giving you the displacement from some position
161 : void extractDisplacementVector( const std::vector<Vector>& pos, const std::vector<Value*>& vals,
162 : const std::vector<double>& arg, const bool& nflag,
163 : Direction& mydir ) const ;
164 : /// Stuff for pca
165 0 : virtual bool pcaIsEnabledForThisReference() { return false; }
166 : double projectDisplacementOnVector( const Direction& mydir, const std::vector<Value*>& vals,
167 : const std::vector<double>& arg, ReferenceValuePack& mypack ) const ;
168 : /// Stuff to setup pca
169 0 : virtual void setupPCAStorage( ReferenceValuePack& mypack ) { plumed_error(); }
170 : /// Move the reference configuration by an ammount specified using a Direction
171 : void displaceReferenceConfiguration( const double& weight, Direction& dir );
172 : };
173 :
174 : // inline
175 : // Vector ReferenceConfiguration::getAtomDerivative( const unsigned& ider ) const {
176 : // plumed_dbg_assert( ider<atom_ders.size() );
177 : // return atom_ders[ider];
178 : // }
179 :
180 : // inline
181 : // double ReferenceConfiguration::getArgumentDerivative( const unsigned& ider ) const {
182 : // plumed_dbg_assert( ider<arg_ders.size() );
183 : // return arg_ders[ider];
184 : // }
185 :
186 : inline
187 : void ReferenceConfiguration::setWeight( const double& ww ) {
188 1908 : weight=ww;
189 : }
190 :
191 : inline
192 : double ReferenceConfiguration::getWeight() const {
193 2395548 : return weight;
194 : }
195 :
196 : template<class T>
197 1576 : bool ReferenceConfiguration::parse(const std::string&key, T&t, bool ignore_missing ) {
198 1576 : bool found=Tools::parse(line,key,t);
199 1576 : if(!ignore_missing && !found) error(key + " is missing");
200 1576 : return found;
201 : }
202 :
203 : template<class T>
204 100 : bool ReferenceConfiguration::parseVector(const std::string&key,std::vector<T>&t, bool ignore_missing) {
205 100 : bool found=Tools::parseVector(line,key,t);
206 100 : if(!ignore_missing && !found) error(key + " is missing");
207 100 : return found;
208 : }
209 :
210 : inline
211 35206 : const std::vector<Vector>& ReferenceConfiguration::getReferencePositions() const {
212 35206 : return fake_refatoms;
213 : }
214 :
215 : inline
216 3351 : const std::vector<double>& ReferenceConfiguration::getReferenceArguments() const {
217 3351 : return fake_refargs;
218 : }
219 :
220 : inline
221 17 : const std::vector<double>& ReferenceConfiguration::getReferenceMetric() {
222 17 : return fake_metric;
223 : }
224 :
225 : inline
226 345 : const std::vector<AtomNumber>& ReferenceConfiguration::getAbsoluteIndexes() {
227 345 : return fake_atom_numbers;
228 : }
229 :
230 : inline
231 36 : const std::vector<std::string>& ReferenceConfiguration::getArgumentNames() {
232 36 : return fake_arg_names;
233 : }
234 :
235 : inline
236 34870 : unsigned ReferenceConfiguration::getNumberOfReferencePositions() const {
237 34870 : return 0;
238 : }
239 :
240 : inline
241 137642 : unsigned ReferenceConfiguration::getNumberOfReferenceArguments() const {
242 137642 : return 0;
243 : }
244 :
245 :
246 :
247 : }
248 : #endif
|