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 "tools/Units.h"
31 :
32 : namespace PLMD {
33 :
34 : /**
35 : Class containing interface to MDAtomsTyped
36 :
37 : This class is used to translate from reals of the type used in MD to
38 : plumed (doubles), and also to rearrange atoms list according to specific
39 : ordering indexes (to deal with domain decomposition codes) and layout
40 : (to allow passing xx[] yy[] zz[] arrays from the MD code).
41 :
42 : The class is abstract, but it is possible to allocate a new pointer with
43 : create(n), where n is the actual size of MD-reals e.g.
44 : \verbatim
45 : MDAtomsBase mdatoms=MDAtomsBase::create(sizeof(float));
46 : // ...
47 : delete mdatoms;
48 : \endverbatim
49 : */
50 2778 : class MDAtomsBase
51 : {
52 : public:
53 : /// Creates an MDAtomsTyped<T> object such that sizeof(T)==n
54 : static MDAtomsBase* create(unsigned n);
55 : /// Virtual destructor, just to allow inheritance.
56 2778 : 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 :
113 : }
114 :
115 :
116 : #endif
|