26 #include "core/PlumedMain.h"
27 #include "core/Atoms.h"
28 #include "tools/PDB.h"
29 #include "tools/RMSD.h"
30 #include "tools/Tools.h"
37 void PathMSDBase::registerKeywords(
Keywords& keys){
38 Colvar::registerKeywords(keys);
39 keys.
add(
"compulsory",
"LAMBDA",
"the lambda parameter is needed for smoothing, is in the units of plumed");
40 keys.
add(
"compulsory",
"REFERENCE",
"the pdb is needed to provide the various milestones");
41 keys.
add(
"optional",
"NEIGH_SIZE",
"size of the neighbor list");
42 keys.
add(
"optional",
"NEIGH_STRIDE",
"how often the neighbor list needs to be calculated in time units");
58 std::vector<AtomNumber> aaa;
70 if(mypdb.
getAtomNumbers().size()==0)
error(
"number of atoms in a frame should be more than zero");
72 if(nat!=mypdb.
getAtomNumbers().size())
error(
"frames should have the same number of atoms");
76 pdbv.push_back(mypdb);
80 mymsd.set(mypdb,
"OPTIMAL");
81 msdv.push_back(mymsd);
91 log.
printf(
" List size required ( %d ) is too large: resizing to the maximum number of frames required: %u \n",
neigh_size,
nframes);
98 log.
printf(
" Neighbor list NOT enabled \n");
105 if(
neigh_size>0 &&
getExchangeStep())
error(
"Neighbor lists for this collective variable are not compatible with replica exchange, sorry for that!");
113 for(
unsigned i=0;i<
nframes;i++){
122 unsigned nat=
pdbv[0].size();
123 plumed_assert(nat>0);
125 plumed_assert(
imgVec.size()>0);
127 std::vector<double> tmp_distances(
imgVec.size(),0.0);
128 std::vector<Vector> tmp_derivs;
130 std::vector<Vector> tmp_derivs2(
imgVec.size()*nat);
133 for(
unsigned i=rank;i<
imgVec.size();i+=stride){
136 plumed_assert(tmp_derivs.size()==nat);
137 for(
unsigned j=0;j<nat;j++) tmp_derivs2[i*nat+j]=tmp_derivs[j];
143 for(
unsigned i=0;i<
imgVec.size();i++){
144 imgVec[i].distance=tmp_distances[i];
145 imgVec[i].distder.assign(&tmp_derivs2[i*nat],nat+&tmp_derivs2[i*nat]);
150 vector<Value*> val_s_path;
158 vector<double> s_path(val_s_path.size());
for(
unsigned i=0;i<s_path.size();i++)s_path[i]=0.;
165 typedef vector< class ImagePath >::iterator imgiter;
167 (*it).similarity=exp(-
lambda*((*it).distance));
169 for(
unsigned i=0;i<s_path.size();i++){
170 s_path[i]+=((*it).property[i])*(*it).similarity;
172 partition+=(*it).similarity;
174 for(
unsigned i=0;i<s_path.size();i++){ s_path[i]/=partition; val_s_path[i]->set(s_path[i]) ;}
175 val_z_path->
set(-(1./
lambda)*std::log(partition));
176 for(
unsigned j=0;j<s_path.size();j++){
181 double expval=(*it).similarity;
182 tmp=
lambda*expval*(s_path[j]-(*it).property[j])/partition;
183 for(
unsigned i=0;i<
derivs_s.size();i++){
derivs_s[i]+=tmp*(*it).distder[i] ;}
184 if(j==0){
for(
unsigned i=0;i<
derivs_z.size();i++){
derivs_z[i]+=(*it).distder[i]*expval/partition;}}
186 for(
unsigned i=0;i<
derivs_s.size();i++){
Log & log
Reference to the log stream.
A class for holding the value of a function together with its derivatives.
void setAtomsDerivatives(int, const Vector &)
std::vector< Vector > derivs_s
std::vector< Vector > derivs_z
void error(const std::string &msg) const
Crash calculation and print documentation.
std::vector< ImagePath > imgVec
const std::vector< Vector > & getPositions() const
Get the array of all positions.
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.
#define PLUMED_COLVAR_INIT(ao)
void set(double)
Set the value of the function.
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
FILE * fopen(const char *path, const char *mode)
Opens a file.
This class holds the keywords and their documentation.
int Get_rank() const
Obtain the rank of the present process.
This class is used to bring the relevant information to the Action constructor.
virtual void calculate()
Calculate an Action.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
bool getExchangeStep() const
Check if we are on an exchange step.
int fclose(FILE *fp)
Closes a file opened with Action::fclose().
long int getStep() const
Return the present timestep.
void setBoxDerivativesNoPbc()
Set box derivatives automatically.
const double & getLength() const
Get length units as double.
Provides the keyword RMSD
bool readFromFilepointer(FILE *fp, bool naturalUnits, double scale)
Read from a file pointer.
Value * getPntrToComponent(int i)
Return a pointer to the component by index.
std::vector< std::string > labels
const std::vector< AtomNumber > & getAtomNumbers() const
Access to the indexes.
int Get_size() const
Obtain the number of processes.
std::vector< std::vector< double > > indexvec
void Sum(T *, int)
Wrapper for MPI_Allreduce with MPI_SUM.