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