23 #include "tools/NeighborList.h"
24 #include "tools/Communicator.h"
33 void CoordinationBase::registerKeywords(
Keywords& keys ){
34 Colvar::registerKeywords(keys);
35 keys.
addFlag(
"SERIAL",
false,
"Perform the calculation in serial - for debug purpose");
36 keys.
addFlag(
"PAIR",
false,
"Pair only 1st element of the 1st group with 1st element in the second, etc");
37 keys.
addFlag(
"NLIST",
false,
"Use a neighbour list to speed up the calculation");
38 keys.
add(
"optional",
"NL_CUTOFF",
"The cutoff for the neighbour list");
39 keys.
add(
"optional",
"NL_STRIDE",
"The frequency with which we are updating the atoms in the neighbour list");
40 keys.
add(
"atoms",
"GROUPA",
"First list of atoms");
41 keys.
add(
"atoms",
"GROUPB",
"Second list of atoms");
54 vector<AtomNumber> ga_lista,gb_lista;
72 parse(
"NL_CUTOFF",nl_cut);
73 if(nl_cut<=0.0)
error(
"NL_CUTOFF should be explicitly specified and positive");
74 parse(
"NL_STRIDE",nl_st);
75 if(nl_st<=0)
error(
"NL_STRIDE should be explicitly specified and positive");
84 log.
printf(
" between two groups of %d and %d atoms\n",ga_lista.size(),gb_lista.size());
86 for(
unsigned int i=0;i<ga_lista.size();++i){
91 for(
unsigned int i=0;i<gb_lista.size();++i){
96 if(
pbc)
log.
printf(
" using periodic boundary conditions\n");
97 else log.
printf(
" without periodic boundary conditions\n");
98 if(dopair)
log.
printf(
" with PAIR option\n");
100 log.
printf(
" using neighbor lists with\n");
101 log.
printf(
" update every %d steps and cutoff %lf\n",nl_st,nl_cut);
111 if(
getExchangeStep())
error(
"Neighbor lists for this collective variable are not compatible with replica exchange, sorry for that!");
119 if(
getExchangeStep())
error(
"Neighbor lists should be updated on exchange steps - choose a NL_STRIDE which divides the exchange stride!");
147 for(
unsigned int i=rank;i<
nl->
size();i+=stride) {
161 deriv[i0] = deriv[i0] + (-dfunc)*distance ;
162 deriv[i1] = deriv[i1] + dfunc*distance ;
163 virial=virial+(-dfunc)*
Tensor(distance,distance);
168 if(!deriv.empty())
comm.
Sum(&deriv[0][0],3*deriv.size());
const Vector & getPosition(int) const
Get position of i-th atom.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
void setNotPeriodic()
Set your default value to have no periodicity.
std::vector< PLMD::AtomNumber > & getFullAtomList()
Return the list of all atoms. These are needed to rebuild the neighbor list.
Log & log
Reference to the log stream.
double modulo() const
Compute the modulo.
Class implementing fixed size matrices of doubles.
virtual void prepare()
Prepare an Action for calculation This can be used by Action if they need some special preparation be...
Class implementing fixed size vectors of doubles.
void setAtomsDerivatives(int, const Vector &)
void error(const std::string &msg) const
Crash calculation and print documentation.
const std::vector< Vector > & getPositions() const
Get the array of all positions.
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
void add(const std::string &t, const std::string &k, const std::string &d)
Add a new keyword of type t with name k and description d.
void addValueWithDerivatives()
Add a value with the name label that has derivatives.
void requestAtoms(const std::vector< AtomNumber > &a)
void update(const std::vector< PLMD::Vector > &positions)
Update the neighbor list and prepare the new list of atoms that will be requested to the main code...
#define PLUMED_COLVAR_INIT(ao)
const Pbc & getPbc() const
Get reference to Pbc.
void setBoxDerivatives(const Tensor &)
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
This class holds the keywords and their documentation.
int Get_rank() const
Obtain the rank of the present process.
A class that implements neighbor lists from two lists or a single list of atoms.
This class is used to bring the relevant information to the Action constructor.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
std::pair< unsigned, unsigned > getClosePair(unsigned i) const
Get the i-th pair of the neighbor list.
bool getExchangeStep() const
Check if we are on an exchange step.
VectorGeneric< n > delta(const VectorGeneric< n > &v1, const VectorGeneric< n > &v2)
void setValue(const double &d)
Set the default value (the one without name)
virtual void calculate()
Calculate an Action.
long int getStep() const
Return the present timestep.
unsigned getStride() const
Get the update stride of the neighbor list.
std::vector< PLMD::AtomNumber > & getReducedAtomList()
Update the indexes in the neighbor list to match the ordering in the new positions array and return t...
Vector pbcDistance(const Vector &, const Vector &) const
Compute the pbc distance between two positions.
int Get_size() const
Obtain the number of processes.
virtual double pairing(double distance, double &dfunc, unsigned i, unsigned j) const =0
unsigned getNumberOfAtoms() const
Get number of available atoms.
void Sum(T *, int)
Wrapper for MPI_Allreduce with MPI_SUM.
void addFlag(const std::string &k, const bool def, const std::string &d)
Add a falg with name k that is by default on if def is true and off if def is false. d should provide a description of the flag.
unsigned size() const
Get the size of the neighbor list.