Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-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_core_MDAtoms_h 23 : #define __PLUMED_core_MDAtoms_h 24 : 25 : #include "tools/Tensor.h" 26 : #include "tools/Vector.h" 27 : #include "tools/AtomNumber.h" 28 : #include <vector> 29 : #include <set> 30 : #include <memory> 31 : 32 : namespace PLMD { 33 : 34 : class Units; 35 : 36 : /** 37 : Class containing interface to MDAtomsTyped 38 : 39 : This class is used to translate from reals of the type used in MD to 40 : plumed (doubles), and also to rearrange atoms list according to specific 41 : ordering indexes (to deal with domain decomposition codes) and layout 42 : (to allow passing xx[] yy[] zz[] arrays from the MD code). 43 : 44 : The class is abstract, but it is possible to allocate a new pointer with 45 : create(n), where n is the actual size of MD-reals e.g. 46 : \verbatim 47 : std::unique_ptr<MDAtomsBase> mdatoms=MDAtomsBase::create(sizeof(float)); 48 : \endverbatim 49 : */ 50 3389 : class MDAtomsBase 51 : { 52 : public: 53 : /// Creates an MDAtomsTyped<T> object such that sizeof(T)==n 54 : static std::unique_ptr<MDAtomsBase> create(unsigned n); 55 : /// Virtual destructor, just to allow inheritance. 56 3389 : virtual ~MDAtomsBase() {} 57 : /// Get the size of MD-real 58 : virtual unsigned getRealPrecision()const=0; 59 : /// Set a pointer to the mass array in the MD code 60 : virtual void setm(void*m)=0; 61 : /// Set a pointer to the charge array in the MD code 62 : virtual void setc(void*m)=0; 63 : /// Set a pointer to the box array (3x3) in the MD code 64 : virtual void setBox(void*)=0; 65 : /// Set a pointer to the positions array in the MD code 66 : virtual void setp(void*p)=0; 67 : /// Set a pointer to the virial array (3x3) in the MD code 68 : virtual void setVirial(void*)=0; 69 : /// Set a pointer to the forces array in the MD code 70 : virtual void setf(void*f)=0; 71 : /// Set a pointer to the position array in the MD code 72 : virtual void setp(void*p,int i)=0; 73 : /// Set a pointer to the force array in the MD code 74 : virtual void setf(void*f,int i)=0; 75 : /// Set internal and MD units 76 : virtual void setUnits(const Units& units,const Units& MDUnits)=0; 77 : /// Convert a pointer to an MD-real to a double 78 : virtual void MD2double(const void*,double&)const=0; 79 : /// Convert a double to a pointer to an MD-real 80 : virtual void double2MD(const double&,void*)const=0; 81 : 82 : virtual Vector getMDforces(const unsigned index)const=0; 83 : /// Retrieve box as a plumed Tensor 84 : virtual void getBox(Tensor &)const=0; 85 : /// Retrieve selected positions. 86 : /// The operation is done in such a way that p[index[i]] is equal to the coordinates of atom i 87 : virtual void getPositions(const std::vector<int>&index,std::vector<Vector>&p)const=0; 88 : /// Retrieve all atom positions from index i to index j. 89 : virtual void getPositions(unsigned i,unsigned j,std::vector<Vector>&p)const=0; 90 : /// Retrieve all atom positions from atom indices and local indices. 91 : virtual void getPositions(const std::set<AtomNumber>&index,const std::vector<unsigned>&i,std::vector<Vector>&p)const=0; 92 : /// Retrieve selected masses. 93 : /// The operation is done in such a way that m[index[i]] is equal to the mass of atom i 94 : virtual void getMasses(const std::vector<int>&index,std::vector<double>&m)const=0; 95 : /// Retrieve selected charges. 96 : /// The operation is done in such a way that c[index[i]] is equal to the charge of atom i 97 : virtual void getCharges(const std::vector<int>&index,std::vector<double>&c)const=0; 98 : /// Retrieve local positions. 99 : virtual void getLocalPositions(std::vector<Vector>&p)const=0; 100 : /// Increment the virial by an amount v 101 : virtual void updateVirial(const Tensor&v)const=0; 102 : /// Increment the force on selected atoms. 103 : /// The operation is done in such a way that f[index[i]] is added to the force on atom i 104 : virtual void updateForces(const std::vector<int>&index,const std::vector<Vector>&f)=0; 105 : /// Increment the force on selected atoms. 106 : /// The operation is done only for local atoms used in an action 107 : virtual void updateForces(const std::set<AtomNumber>&index,const std::vector<unsigned>&i,const std::vector<Vector>&forces)=0; 108 : /// Rescale all the forces, including the virial. 109 : /// It is applied to all atoms with local index going from 0 to index.size()-1 110 : virtual void rescaleForces(const std::vector<int>&index,double factor)=0; 111 : 112 : /// Set a pointer to an extra CV. 113 : virtual void setExtraCV(const std::string &name,void*p)=0; 114 : /// Set a pointer to an extra CV force. 115 : virtual void setExtraCVForce(const std::string &name,void*p)=0; 116 : /// Retrieve the value of an extra CV. 117 : virtual double getExtraCV(const std::string &name)=0; 118 : /// Update the value of an extra CV force. 119 : /// \todo check if this should also be scaled when acting on total energy 120 : virtual void updateExtraCVForce(const std::string &name,double f)=0; 121 : }; 122 : 123 : } 124 : 125 : 126 : #endif