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_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/PointWiseMapping.h"
30 : #include <vector>
31 :
32 : namespace PLMD {
33 :
34 : class PDB;
35 :
36 : namespace mapping {
37 :
38 : class Mapping :
39 : public ActionAtomistic,
40 : public ActionWithArguments,
41 : public ActionWithValue,
42 : public vesselbase::ActionWithVessel
43 : {
44 : friend class TrigonometricPathVessel;
45 : private:
46 : // The derivative wrt to the distance from the frame
47 : std::vector<double> dfframes;
48 : /// This holds all the reference information
49 : PointWiseMapping* mymap;
50 : /// The forces on each of the derivatives (used in apply)
51 : std::vector<double> forcesToApply;
52 : protected:
53 : /// The (transformed) distance from each frame
54 : std::vector<double> fframes;
55 : /// Get the number of frames in the path
56 : unsigned getNumberOfReferencePoints() const ;
57 : /// Finish the setup of the referenceValuePack by transfering atoms and args
58 : void finishPackSetup( const unsigned& ifunc, ReferenceValuePack& mypack ) const ;
59 : /// Calculate the value of the distance from the ith frame
60 : double calculateDistanceFunction( const unsigned& ifunc, ReferenceValuePack& myder, const bool& squared ) const ;
61 : /// Store the distance function
62 : void storeDistanceFunction( const unsigned& ifunc );
63 : /// Get the value of the weight
64 : double getWeight( const unsigned& weight ) const ;
65 : /// Return the vector of refernece configurations
66 : std::vector<ReferenceConfiguration*>& getAllReferenceConfigurations();
67 : /// Return a pointer to one of the reference configurations
68 : ReferenceConfiguration* getReferenceConfiguration( const unsigned& ifunc );
69 : public:
70 : static void registerKeywords( Keywords& keys );
71 : explicit Mapping(const ActionOptions&);
72 : ~Mapping();
73 : /// Overload the virtual functions that appear in both ActionAtomistic and ActionWithArguments
74 : void turnOnDerivatives();
75 : void calculateNumericalDerivatives( ActionWithValue* a=NULL );
76 : void lockRequests();
77 : void unlockRequests();
78 : /// Distance from a point is never periodic
79 0 : bool isPeriodic() { return false; }
80 : /// Get the number of derivatives for this action
81 : unsigned getNumberOfDerivatives(); // N.B. This is replacing the virtual function in ActionWithValue
82 : /// Get the value of lambda for paths and property maps
83 : virtual double getLambda();
84 : /// This does the transformation of the distance by whatever function is required
85 : virtual double transformHD( const double& dist, double& df ) const=0;
86 : /// Get the number of properties we are projecting onto
87 : unsigned getNumberOfProperties() const ;
88 : /// Get the name of the ith property we are projecting
89 : std::string getPropertyName( const unsigned& iprop ) const ;
90 : /// Get the index of a particular named property
91 : unsigned getPropertyIndex( const std::string& name ) const ;
92 : /// Set the value of one of the projection coordinates
93 : void setPropertyValue( const unsigned& iframe, const unsigned& iprop, const double& property );
94 : /// Get the name of the ith argument
95 : std::string getArgumentName( unsigned& iarg );
96 : /// Get the value of the ith property for the current frame
97 : double getPropertyValue( const unsigned& current, const unsigned& iprop ) const ;
98 : /// Apply the forces
99 : void apply();
100 : };
101 :
102 : inline
103 : unsigned Mapping::getNumberOfReferencePoints() const {
104 469 : return mymap->getNumberOfMappedPoints();
105 : }
106 :
107 : inline
108 20192 : unsigned Mapping::getNumberOfDerivatives() {
109 : unsigned nat=getNumberOfAtoms();
110 20192 : if(nat>0) return 3*nat + 9 + getNumberOfArguments();
111 2612 : return getNumberOfArguments();
112 : }
113 :
114 : inline
115 5015 : void Mapping::lockRequests() {
116 : ActionWithArguments::lockRequests();
117 : ActionAtomistic::lockRequests();
118 5015 : }
119 :
120 : inline
121 5015 : void Mapping::unlockRequests() {
122 : ActionWithArguments::unlockRequests();
123 : ActionAtomistic::unlockRequests();
124 5015 : }
125 :
126 : inline
127 : unsigned Mapping::getNumberOfProperties() const {
128 16 : return mymap->getNumberOfProperties();
129 : }
130 :
131 : inline
132 6 : std::string Mapping::getPropertyName( const unsigned& iprop ) const {
133 12 : return mymap->getPropertyName(iprop);
134 : }
135 :
136 : inline
137 : double Mapping::getPropertyValue( const unsigned& cur, const unsigned& iprop ) const {
138 : plumed_dbg_assert( iprop<getNumberOfProperties() );
139 29777 : return mymap->getPropertyValue( cur, iprop );
140 : }
141 :
142 : inline
143 : double Mapping::getWeight( const unsigned& current ) const {
144 : return mymap->getWeight( current );
145 : }
146 :
147 : inline
148 : void Mapping::storeDistanceFunction( const unsigned& ifunc ) {
149 : plumed_dbg_assert( ifunc<getNumberOfReferencePoints() );
150 : unsigned storef=getNumberOfReferencePoints()+ifunc;
151 : fframes[storef]=fframes[ifunc]; dfframes[storef]=dfframes[ifunc];
152 : mymap->copyFrameDerivatives( ifunc, storef );
153 : }
154 :
155 : inline
156 : std::vector<ReferenceConfiguration*>& Mapping::getAllReferenceConfigurations() {
157 2 : return mymap->getReferenceConfigurations();
158 : }
159 :
160 : }
161 : }
162 : #endif
|