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_MultiReferenceBase_h
23 : #define __PLUMED_reference_MultiReferenceBase_h
24 :
25 : #include "ReferenceConfiguration.h"
26 : #include "tools/Matrix.h"
27 :
28 : namespace PLMD {
29 :
30 : class MultiReferenceBase {
31 : private:
32 : /// Everything has been set
33 : bool wasSet;
34 : /// Skip all checking allows users to do really dodgy stuff :-)
35 : bool skipchecks;
36 : /// The type of metric we are using
37 : std::string mtype;
38 : protected:
39 : /// These are the configurations that serve as references
40 : std::vector<ReferenceConfiguration*> frames;
41 : /// Read something from the last frame
42 : template <class T>
43 : void parse(const std::string& key, T& val );
44 : public:
45 : MultiReferenceBase( const std::string& type, const bool& checksoff );
46 : /// Destructor deletes all polymorphic pointers
47 : virtual ~MultiReferenceBase();
48 : /// Delete all the data in the reference object
49 : void clearFrames();
50 0 : virtual void clearRestOfData() {};
51 : /// Read a frame from the input
52 : void readFrame( PDB& pdb );
53 : /// Find what is required of us from the reference frames
54 : void getAtomAndArgumentRequirements( std::vector<AtomNumber>& atoms, std::vector<std::string>& args );
55 : /// Finish setup of frames
56 : // void setNumberOfAtomsAndArguments( const unsigned& natoms, const unsigned& nargs );
57 : /// Do additional reading required by derived class
58 12 : virtual void readRestOfFrame() {}
59 : /// Do additional resizing required by derived class
60 0 : virtual void resizeRestOfFrame() {}
61 : /// Return the size of the frames vector
62 : unsigned getNumberOfReferenceFrames() const ;
63 : /// Calculate the distance from one of the reference points
64 : double calcDistanceFromConfiguration( const unsigned& ifunc, const std::vector<Vector>& pos, const Pbc& pbc,
65 : const std::vector<Value*>& arg, ReferenceValuePack& myder, const bool& squared ) const ;
66 : /// Return the ith reference frame
67 : ReferenceConfiguration* getFrame( const unsigned& iframe );
68 : /// Return a reference to all the reference frames
69 : std::vector<ReferenceConfiguration*>& getReferenceConfigurations();
70 : /// Copy a reference configuration into the multi reference object
71 : void copyFrame( ReferenceConfiguration* frameToCopy );
72 : /// Set the weight of the ith frame
73 : void setWeights( const std::vector<double>& ww );
74 : /// Retrieve the weight of one of the frames
75 : double getWeight( const unsigned& ifram ) const ;
76 : /// Calculate the distances between all the frames and store in a matrix
77 : void calculateAllDistances( const Pbc& pbc, const std::vector<Value*> & vals, Communicator& comm, Matrix<double>& distances, const bool& squared );
78 : };
79 :
80 : template <class T>
81 252 : void MultiReferenceBase::parse(const std::string& key, T& val ) {
82 504 : frames[frames.size()-1]->parse(key,val);
83 252 : }
84 :
85 : inline
86 : double MultiReferenceBase::calcDistanceFromConfiguration( const unsigned& ifunc, const std::vector<Vector>& pos, const Pbc& pbc,
87 : const std::vector<Value*>& arg, ReferenceValuePack& myder, const bool& squared ) const {
88 344744 : return frames[ifunc]->calculate( pos, pbc, arg, myder, squared );
89 : }
90 :
91 : inline
92 : unsigned MultiReferenceBase::getNumberOfReferenceFrames() const {
93 820 : return frames.size();
94 : }
95 :
96 : inline
97 : double MultiReferenceBase::getWeight( const unsigned& ifram ) const {
98 : plumed_dbg_assert( ifram<frames.size() );
99 832 : return frames[ifram]->getWeight();
100 : }
101 :
102 : inline
103 : ReferenceConfiguration* MultiReferenceBase::getFrame( const unsigned& iframe ) {
104 : plumed_dbg_assert( iframe<frames.size() );
105 371946 : return frames[iframe];
106 : }
107 :
108 : inline
109 : std::vector<ReferenceConfiguration*>& MultiReferenceBase::getReferenceConfigurations() {
110 2 : return frames;
111 : }
112 :
113 : }
114 : #endif
|