Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-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 "MultiColvarBase.h"
23 : #include "AtomValuePack.h"
24 : #include "core/ActionRegister.h"
25 :
26 : #include <string>
27 : #include <cmath>
28 :
29 : using namespace std;
30 :
31 : namespace PLMD {
32 : namespace multicolvar {
33 :
34 : //+PLUMEDOC MCOLVAR DENSITY
35 : /*
36 : Calculate functions of the density of atoms as a function of the box. This allows one to calculate
37 : the number of atoms in half the box.
38 :
39 : \par Examples
40 :
41 : The following example calculates the number of atoms in one half of the simulation box.
42 :
43 : \plumedfile
44 : DENSITY SPECIES=1-100 LABEL=d
45 : AROUND ARG=d XLOWER=0.0 XUPPER=0.5 LABEL=d1
46 : PRINT ARG=d1.* FILE=colvar1 FMT=%8.4f
47 : \endplumedfile
48 :
49 : */
50 : //+ENDPLUMEDOC
51 :
52 :
53 22 : class Density : public MultiColvarBase {
54 : public:
55 : static void registerKeywords( Keywords& keys );
56 : explicit Density(const ActionOptions&);
57 : // active methods:
58 : virtual double compute( const unsigned& tindex, AtomValuePack& myatoms ) const ;
59 : /// Returns the number of coordinates of the field
60 4 : bool isPeriodic() { return false; }
61 200687 : bool isDensity() const { return true; }
62 0 : bool hasDifferentiableOrientation() const { return true; }
63 : // void addOrientationDerivativesToBase( const unsigned& iatom, const unsigned& jstore, const unsigned& base_cv_no,
64 : // const std::vector<double>& weight, MultiColvarFunction* func ){}
65 : void getIndexList( const unsigned& ntotal, const unsigned& jstore, const unsigned& maxder, std::vector<unsigned>& indices );
66 : // unsigned getNumberOfQuantities();
67 : void getValueForTask( const unsigned& iatom, std::vector<double>& vals );
68 : };
69 :
70 6463 : PLUMED_REGISTER_ACTION(Density,"DENSITY")
71 :
72 12 : void Density::registerKeywords( Keywords& keys ) {
73 12 : MultiColvarBase::registerKeywords( keys );
74 24 : keys.use("SPECIES");
75 12 : }
76 :
77 11 : Density::Density(const ActionOptions&ao):
78 : Action(ao),
79 11 : MultiColvarBase(ao)
80 : {
81 22 : std::vector<AtomNumber> all_atoms; parseMultiColvarAtomList("SPECIES", -1, all_atoms);
82 22 : ablocks.resize(1); ablocks[0].resize( atom_lab.size() );
83 978 : for(unsigned i=0; i<atom_lab.size(); ++i) { addTaskToList(i); ablocks[0][i]=i; }
84 11 : setupMultiColvarBase( all_atoms );
85 : // And check everything has been read in correctly
86 11 : checkRead();
87 11 : }
88 :
89 15950 : double Density::compute( const unsigned& tindex, AtomValuePack& myvals ) const {
90 15950 : return 1.0;
91 : }
92 :
93 0 : void Density::getIndexList( const unsigned& ntotal, const unsigned& jstore, const unsigned& maxder, std::vector<unsigned>& indices ) {
94 0 : indices[jstore]=0;
95 0 : }
96 :
97 : // unsigned Density::getNumberOfQuantities(){
98 : // return 2;
99 : // }
100 :
101 0 : void Density::getValueForTask( const unsigned& iatom, std::vector<double>& vals ) {
102 0 : plumed_dbg_assert( vals.size()==2 ); vals[0]=vals[1]=1.0;
103 0 : }
104 :
105 : }
106 4839 : }
107 :
|