26 #include "tools/Pbc.h"
43 energyHasBeenSet(false),
44 positionsHaveBeenSet(0),
45 massesHaveBeenSet(false),
46 chargesHaveBeenSet(false),
49 virialHasBeenSet(false),
60 std::cerr<<
"WARNING: there is some inconsistency in action added to atoms, as some of them were not properly destroyed. This might indicate an internal bug!!\n";
78 plumed_massert(
dataCanBeSet ,
"setPositions must be called after setStep in MD code interface");
79 plumed_massert( p ||
gatindex.size()==0,
"NULL position pointer with non-zero local atoms");
84 plumed_massert(
dataCanBeSet ,
"setMasses must be called after setStep in MD code interface");
85 plumed_massert( p ||
gatindex.size()==0,
"NULL mass pointer with non-zero local atoms");
91 plumed_massert(
dataCanBeSet,
"setCharges must be called after setStep in MD code interface");
92 plumed_massert( p ||
gatindex.size()==0,
"NULL charges pointer with non-zero local atoms");
97 plumed_massert(
dataCanBeSet ,
"setVirial must be called after setStep in MD code interface");
103 plumed_massert(
dataCanBeSet ,
"setEnergy must be called after setStep in MD code interface");
110 plumed_massert(
dataCanBeSet ,
"setForces must be called after setStep in MD code interface");
111 plumed_massert( p ||
gatindex.size()==0,
"NULL force pointer with non-zero local atoms");
117 plumed_massert(
dataCanBeSet ,
"setPositions must be called after setStep in MD code interface");
118 plumed_massert( p ||
gatindex.size()==0,
"NULL positions pointer with non-zero local atoms");
123 plumed_massert(
dataCanBeSet ,
"setForces must be called after setStep in MD code interface");
124 plumed_massert( p ||
gatindex.size()==0,
"NULL force pointer with non-zero local atoms");
129 std::set<AtomNumber> unique;
131 for(
unsigned i=0;i<
actions.size();i++)
if(
actions[i]->isActive()) {
132 unique.insert(
actions[i]->getUnique().begin(),
actions[i]->getUnique().end());
139 std::set<AtomNumber> unique;
157 for(std::set<AtomNumber>::const_iterator p=unique.begin();p!=unique.end();++p){
158 if(
dd.
g2l[p->index()]>=0){
177 vector<int> counts(n);
178 vector<int> displ(n);
179 vector<int> counts5(n);
180 vector<int> displ5(n);
183 for(
int i=1;i<
n;++i) displ[i]=displ[i-1]+counts[i-1];
184 for(
int i=0;i<
n;++i) counts5[i]=counts[i]*5;
185 for(
int i=0;i<
n;++i) displ5[i]=displ[i]*5;
188 int tot=displ[n-1]+counts[n-1];
189 for(
int i=0;i<tot;i++){
225 for(
int i=0;i<count;i++){
266 vector<const ActionAtomistic*>::iterator f=find(
actions.begin(),
actions.end(),
a);
267 plumed_massert(f!=
actions.end(),
"cannot remove an action registered to atoms");
290 plumed_massert( g ||
gatindex.size()==0,
"NULL gatindex pointer with non-zero local atoms");
292 for(
unsigned i=0;i<
dd.
g2l.size();i++)
dd.
g2l[i]=-1;
298 for(
unsigned i=0;i<
dd.
g2l.size();i++)
dd.
g2l[i]=-1;
331 vector<AtomNumber> fullListTmp;
333 fullListTmp.insert(fullListTmp.end(),
actions[i]->getUnique().begin(),
actions[i]->getUnique().end());
334 std::sort(fullListTmp.begin(),fullListTmp.end());
335 int nn=std::unique(fullListTmp.begin(),fullListTmp.end())-fullListTmp.begin();
337 for(
unsigned i=0;i<nn;++i)
fullList[i]=fullListTmp[i].index();
385 plumed_massert(
groups.count(name)==0,
"group named "+name+
" already exists");
390 plumed_massert(
groups.count(name)==1,
"cannot remove group named "+name);
395 o.write(reinterpret_cast<const char*>(&
positions[0][0]),
natoms*3*
sizeof(
double));
396 o.write(reinterpret_cast<const char*>(&
box(0,0)),9*
sizeof(
double));
397 o.write(reinterpret_cast<const char*>(&
energy),
sizeof(
double));
401 i.read(reinterpret_cast<char*>(&
positions[0][0]),
natoms*3*
sizeof(
double));
402 i.read(reinterpret_cast<char*>(&
box(0,0)),9*
sizeof(
double));
403 i.read(reinterpret_cast<char*>(&
energy),
sizeof(
double));
std::vector< const ActionAtomistic * > actions
void zero()
set it to zero
Simple class to store the index of an atom.
const int & getNatoms() const
virtual void setf(void *f)=0
Set a pointer to the forces array in the MD code.
void removeVirtualAtom(ActionWithVirtualAtom *)
AtomNumber addVirtualAtom(ActionWithVirtualAtom *)
std::vector< Vector > forces
std::vector< double > charges
virtual unsigned getRealPrecision() const =0
Get the size of MD-real.
double getMDKBoltzmann() const
void removeGroup(const std::string &name)
void setAtomsContiguous(int)
Class implementing fixed size matrices of doubles.
void add(const ActionAtomistic *)
virtual void getMasses(const std::vector< int > &index, std::vector< double > &m) const =0
Retrieve selected masses.
void enable(Communicator &c)
int getRealPrecision() const
void Bcast(T *, int, int)
std::vector< double > masses
MPI_Comm & Get_comm()
Reference to MPI communicator.
void writeBinary(std::ostream &) const
virtual void MD2double(const void *, double &) const =0
Convert a pointer to an MD-real to a double.
std::vector< int > indexToBeSent
Class containing wrappers to MPI.
virtual void setm(void *m)=0
Set a pointer to the mass array in the MD code.
std::vector< Communicator::Request > mpi_request_index
std::vector< Vector > positions
std::vector< ActionWithVirtualAtom * > virtualAtomsActions
void remove(const ActionAtomistic *)
void Allgather(const T *, int, T *, int)
void double2MD(const double &d, void *m) const
std::vector< Communicator::Request > mpi_request_positions
double getKBoltzmann() const
virtual void setUnits(const Units &units, const Units &MDUnits)=0
Set internal and MD units.
int Get_rank() const
Obtain the rank of the present process.
void readBinary(std::istream &)
std::vector< int > indexToBeReceived
void createFullList(int *)
Action used to create objects that access the positions of the atoms from the MD code.
const double & getEnergy() const
Get energy units as double.
const double & getTime() const
Get time units as double.
const double kBoltzmann(0.0083144621)
Boltzman constant in kj/K.
std::vector< double > positionsToBeReceived
Inherit from here if you are calculating the position of a virtual atom (eg a center of mass) ...
void resizeVectors(unsigned)
void setAtomsGatindex(int *)
virtual void setc(void *m)=0
Set a pointer to the charge array in the MD code.
virtual void rescaleForces(const std::vector< int > &index, double factor)=0
Rescale all the forces, including the virial.
void Recv(T *, int, int, int, Status &)
unsigned index() const
Returns the index number.
virtual void double2MD(const double &, void *) const =0
Convert a double to a pointer to an MD-real.
virtual void setBox(void *)=0
Set a pointer to the box array (3x3) in the MD code.
virtual void updateVirial(const Tensor &v) const =0
Increment the virial by an amount v.
virtual void getPositions(const std::vector< int > &index, std::vector< Vector > &p) const =0
Retrieve selected positions.
virtual void setVirial(void *)=0
Set a pointer to the virial array (3x3) in the MD code.
void setDomainDecomposition(Communicator &)
virtual void getBox(Tensor &) const =0
Retrieve box as a plumed Tensor.
virtual void setp(void *p)=0
Set a pointer to the positions array in the MD code.
unsigned forcesHaveBeenSet
void insertGroup(const std::string &name, const std::vector< AtomNumber > &a)
void setRealPrecision(int)
unsigned positionsHaveBeenSet
std::vector< int > gatindex
virtual void updateForces(const std::vector< int > &index, const std::vector< Vector > &f)=0
Increment the force on selected atoms.
void Set_comm(MPI_Comm)
Set from a real MPI communicator.
double getTimeStep() const
int Get_size() const
Obtain the number of processes.
std::vector< double > positionsToBeSent
void Allgatherv(const T *, int, T *, const int *, const int *)
Wrapper for MPI_Allgatherv.
void Sum(T *, int)
Wrapper for MPI_Allreduce with MPI_SUM.
Request Isend(const T *, int, int, int)
void setBox(const Tensor &b)
Set the lattice vectors.
std::vector< int > fullList
void MD2double(const void *m, double &d) const
void setPositions(void *)
virtual void getCharges(const std::vector< int > &index, std::vector< double > &c) const =0
Retrieve selected charges.
std::map< std::string, std::vector< AtomNumber > > groups
static MDAtomsBase * create(unsigned n)
Creates an MDAtomsTyped object such that sizeof(T)==n.