Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2016-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 : #include "ActionWithGrid.h"
23 : #include "core/PlumedMain.h"
24 : #include "core/ActionSet.h"
25 :
26 : namespace PLMD {
27 : namespace gridtools {
28 :
29 61 : void ActionWithGrid::registerKeywords( Keywords& keys ) {
30 61 : vesselbase::ActionWithAveraging::registerKeywords( keys );
31 244 : keys.add("compulsory","BANDWIDTH","the bandwidths for kernel density esimtation");
32 305 : keys.add("compulsory","KERNEL","gaussian","the kernel function you are using. More details on the kernels available "
33 : "in plumed plumed can be found in \\ref kernelfunctions.");
34 244 : keys.add("optional","CONCENTRATION","the concentration parameter for Von Mises-Fisher distributions");
35 61 : }
36 :
37 52 : ActionWithGrid::ActionWithGrid( const ActionOptions& ao):
38 : Action(ao),
39 : ActionWithAveraging(ao),
40 104 : mygrid(NULL)
41 : {
42 52 : }
43 :
44 47 : void ActionWithGrid::createGrid( const std::string& type, const std::string& inputstr ) {
45 : // Start creating the input for the grid
46 : std::string vstring = inputstr;
47 94 : if( keywords.exists("KERNEL") ) {
48 72 : std::string vconc; parse("CONCENTRATION",vconc);
49 36 : if( vconc.length()>0 ) {
50 4 : vstring += " TYPE=fibonacci CONCENTRATION=" + vconc;
51 : } else {
52 68 : std::string kstring; parse("KERNEL",kstring);
53 38 : if( kstring=="DISCRETE" ) vstring += " KERNEL=" + kstring;
54 180 : else vstring += " KERNEL=" + kstring + " " + getKeyword("BANDWIDTH");
55 : }
56 : }
57 188 : vesselbase::VesselOptions da("mygrid","",-1,vstring,this);
58 94 : Keywords keys; gridtools::AverageOnGrid::registerKeywords( keys );
59 94 : vesselbase::VesselOptions dar( da, keys );
60 47 : if( type=="histogram" ) {
61 28 : mygrid = new HistogramOnGrid(dar);
62 19 : } else if( type=="average" ) {
63 8 : mygrid = new AverageOnGrid(dar);
64 11 : } else if( type=="grid" ) {
65 11 : mygrid = new GridVessel(dar);
66 : } else {
67 0 : plumed_merror("no way to create grid of type " + type );
68 : }
69 47 : }
70 :
71 16 : void ActionWithGrid::turnOnDerivatives() {
72 16 : needsDerivatives(); ActionWithValue::turnOnDerivatives();
73 16 : if( getStride()==1 ) setStride(0);
74 8 : else if( getStride()!=0 ) error("conflicting instructions for grid - stride was set but must be evaluated on every step for derivatives - remove STRIDE keyword");
75 16 : if( clearstride>1 ) error("conflicting instructions for grid - CLEAR was set but grid must be reset on every step for derivatives - remove CLEAR keyword" );
76 16 : if( weights.size()>0 ) error("conflicting instructions for grid - LOGWEIGHTS was set but weights are not considered when derivatives of grid are evaluated - remove LOGWEIGHTS keyword");
77 16 : }
78 :
79 202 : void ActionWithGrid::calculate() {
80 : // Do nothing if derivatives are not required
81 202 : if( doNotCalculateDerivatives() ) return;
82 : // Clear on every step
83 40 : if( mygrid ) clearAverage();
84 : // Should not be any reweighting so just set these accordingly
85 40 : lweight=0; cweight=1.0;
86 : // Prepare to do the averaging
87 40 : prepareForAveraging();
88 : // Run all the tasks (if required
89 40 : if( useRunAllTasks ) runAllTasks();
90 : // This the averaging if it is not done using task list
91 20 : else performOperations( true );
92 : // Update the norm
93 40 : if( mygrid ) mygrid->setNorm( cweight );
94 : // Finish the averaging
95 40 : finishAveraging();
96 : // And reset for next step
97 40 : if( mygrid ) mygrid->reset();
98 : }
99 :
100 54761 : void ActionWithGrid::performTask( const unsigned& task_index, const unsigned& current, MultiValue& myvals ) const {
101 : // Set the weight of this point
102 54761 : myvals.setValue( 0, cweight ); compute( current, myvals );
103 54761 : }
104 :
105 : }
106 4839 : }
|