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