23 #include "tools/Tools.h"
31 #include "config/Config.h"
35 #include "tools/Exception.h"
38 #include "tools/Log.h"
39 #include "tools/DLLoader.h"
40 #include "tools/Communicator.h"
42 #include "tools/Stopwatch.h"
43 #include "tools/Citations.h"
45 #include "tools/IFile.h"
51 PlumedMain::PlumedMain():
63 atoms(*new
Atoms(*this)),
100 #define CHECK_INIT(ini,word) plumed_massert(ini,"cmd(\"" + word +"\") should be only used after plumed initialization")
101 #define CHECK_NOTINIT(ini,word) plumed_massert(!(ini),"cmd(\"" + word +"\") should be only used before plumed initialization")
102 #define CHECK_NULL(val,word) plumed_massert(val,"NULL pointer received in cmd(\"" + word + "\")");
112 }
else if(word==
"setBox") {
116 }
else if(word==
"setPositions") {
119 }
else if(word==
"setMasses") {
122 }
else if(word==
"setCharges") {
125 }
else if(word==
"setPositionsX") {
128 }
else if(word==
"setPositionsY") {
131 }
else if(word==
"setPositionsZ") {
134 }
else if(word==
"setVirial") {
138 }
else if(word==
"setEnergy") {
142 }
else if(word==
"setForces") {
145 }
else if(word==
"setForcesX") {
148 }
else if(word==
"setForcesY") {
151 }
else if(word==
"setForcesZ") {
154 }
else if(word==
"calc") {
157 }
else if(word==
"prepareDependencies") {
160 }
else if(word==
"shareData") {
163 }
else if(word==
"prepareCalc") {
166 }
else if(word==
"performCalc") {
169 }
else if(word==
"setStep") {
172 step=(*
static_cast<int*
>(val));
174 }
else if(word==
"setStepLong") {
177 step=(*
static_cast<long int*
>(val));
180 }
else if(word==
"setAtomsNlocal"){
184 }
else if(word==
"setAtomsGatindex"){
187 }
else if(word==
"setAtomsContiguous"){
191 }
else if(word==
"createFullList"){
195 }
else if(word==
"getFullList"){
199 }
else if(word==
"clearFullList"){
202 }
else if(word==
"read"){
206 }
else if(word==
"clear"){
209 }
else if(word==
"getApiVersion"){
211 *(
static_cast<int*
>(val))=1;
213 }
else if(word==
"init"){
216 }
else if(word==
"setRealPrecision"){
220 }
else if(word==
"setMDLengthUnits"){
226 }
else if(word==
"setMDEnergyUnits"){
232 }
else if(word==
"setMDTimeUnits"){
238 }
else if(word==
"setNaturalUnits"){
244 }
else if(word==
"setNoVirial"){
247 }
else if(word==
"setPlumedDat"){
251 }
else if(word==
"setMPIComm"){
255 }
else if(word==
"setMPIFComm"){
259 }
else if(word==
"setMPImultiSimComm"){
262 }
else if(word==
"setNatoms"){
266 }
else if(word==
"setTimestep"){
270 }
else if(word==
"setMDEngine"){
274 }
else if(word==
"setLog"){
276 log.
link(static_cast<FILE*>(val));
277 }
else if(word==
"setLogFile"){
280 log.
open(static_cast<char*>(val),
"w");
282 }
else if(word==
"setStopFlag"){
286 }
else if(word==
"getExchangesFlag"){
290 }
else if(word==
"setExchangesSeed"){
294 }
else if(word==
"setNumberOfReplicas"){
298 }
else if(word==
"getExchangesList"){
302 }
else if(word==
"runFinalJobs"){
305 }
else if(word==
"isEnergyNeeded"){
309 else *(
static_cast<int*
>(val))=0;
310 }
else if(word==
"getBias"){
322 }
else if(nw==2 && words[0]==
"checkAction"){
325 *(
static_cast<int*
>(val))=check;
326 }
else if(nw>1 && words[0]==
"GREX"){
328 plumed_massert(
grex,
"error allocating grex");
329 std::string kk=words[1];
330 for(
unsigned i=2;i<words.size();i++) kk+=
" "+words[i];
332 }
else if(nw>1 && words[0]==
"CLTool"){
335 std::string kk=words[1];
336 for(
unsigned i=2;i<words.size();i++) kk+=
" "+words[i];
339 plumed_merror(
"cannot interpret cmd(\"" + word +
"\"). check plumed developers manual to see the available commands.");
354 log<<
"PLUMED is starting\n";
356 log<<
"Please cite this paper when using PLUMED ";
357 log<<
cite(
"Tribello, Bonomi, Branduardi, Camilloni, and Bussi, Comput. Phys. Commun. 185, 604 (2014)");
359 log<<
"For further information see the PLUMED web page at http://www.plumed-code.org\n";
364 if(
grex)
log.
printf(
"GROMACS-like replica exchange is on\n");
372 log<<
"Relevant bibliography:\n";
374 log<<
"Please read and cite where appropriate!\n";
375 log<<
"Finished setup\n";
384 std::vector<std::string> words;
387 log.
printf(
"END FILE: %s\n",str.c_str());
395 if(words.empty())
return;
396 else if(words[0]==
"ENDPLUMED")
return;
397 else if(words[0]==
"_SET_SUFFIX"){
398 plumed_assert(words.size()==2);
401 std::vector<std::string> interpreted(words);
406 log<<
"I cannot understand line:";
407 for(
unsigned i=0;i<interpreted.size();++i)
log<<
" "<<interpreted[i];
463 (*p)->clearOptions();
468 for(
unsigned i=0;i<
pilots.size();++i){
477 if((*p)->isActive()){
478 if((*p)->checkNeedsGradients()) (*p)->setOption(
"GRADIENTS");
516 std::string actionNumberLabel;
519 actionNumberLabel=
"4A "+actionNumberLabel+
" "+(*p)->getLabel();
532 if((*p)->isActive()){
533 if((*p)->checkNumericalDerivatives()) (*p)->calculateNumericalDerivatives();
534 else (*p)->calculate();
555 if((*p)->isActive()){
557 std::string actionNumberLabel;
560 actionNumberLabel=
"5A "+actionNumberLabel+
" "+(*p)->getLabel();
582 if((*p)->isActive()) (*p)->update();
588 else plumed_merror(
"your md code cannot handle plumed stop events - add a call to plumed.comm(stopFlag,stopCondition)");
597 for(ActionSet::const_iterator p=
actionSet.begin();p!=
actionSet.end();++p) (*p)->fflush();
604 size_t n=s.find_last_of(
".");
607 if(n!=std::string::npos && n<s.length()-1) extension=s.substr(n+1);
608 if(n!=std::string::npos && n<s.length()) base=s.substr(0,n);
609 if(extension==
"cpp"){
610 string cmd=
"plumed mklib "+s;
622 log<<
"I cannot load library "<<ss<<
"\n";
627 log<<
"Loading shared library "<<s.c_str()<<
"\n";
628 log<<
"Here is the new list of available actions\n";
630 }
else plumed_merror(
"loading not enabled, please recompile with -D__PLUMED_HAS_DLOPEN");
638 std::string mmode(mode);
639 std::string ppath(path);
641 std::string ppathsuf=ppath+
suffix;
642 FILE*fp=std::fopen(const_cast<char*>(ppathsuf.c_str()),const_cast<char*>(mmode.c_str()));
643 if(!fp) fp=std::fopen(const_cast<char*>(ppath.c_str()),const_cast<char*>(mmode.c_str()));
644 plumed_massert(fp,
"file " + ppath +
" cannot be found");
649 return std::fclose(fp);
676 (*p)->runFinalJobs();
const int & getNatoms() const
long int step
Present step number.
bool isActive() const
Check if action is active.
void init()
Initialize the object.
ActionRegister & actionRegister()
std::string plumedDat
Name of the input file.
bool isEnergyNeeded() const
Class taking care of dynamic loading.
std::vector containing the sequence of Action to be done.
bool novirial
Flag to switch off virial calculation (for debug and MD codes with no barostat)
This is used to create PLMD::Action objects that are run with some set frequency. ...
void setAtomsContiguous(int)
std::vector< ActionPilot * > pilots
Set of Pilot actions.
#define CHECK_NULL(val, word)
int getRealPrecision() const
void waitData()
Scatters the needed atoms.
Communicator & multi_sim_comm
void load(const std::string &)
Load a shared library.
FileBase & link(FILE *)
Link to an already open filed.
Class containing wrappers to MPI.
void stop()
Stop the calculation cleanly (both the MD code and plumed)
void checkRead()
Check if Action was properly read.
Class containing atom related quantities from the MD code.
double bias
The total bias (=total energy of the restraints)
std::string getVersionLong()
int * stopFlag
Stuff to make plumed stop the MD code cleanly.
Class containing the log stream.
void justCalculate()
Perform the forward loop on active actions.
void justApply()
Perform the backward loop on active actions.
void setGradientsIfNeeded()
Calculate the gradients and store them for all the values (need for projections)
std::vector< T > select() const
Extract pointers to all Action's of type T To extract all Colvar , use select();.
void double2MD(const double &d, void *m) const
void setMDEnergyUnits(double d)
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
void runJobsAtEndOfCalculation()
If there are calculations that need to be done at the very end of the calculations this makes sures t...
void share(const std::set< AtomNumber > &)
FileBase & flush()
Flushes the file to disk.
int Get_rank() const
Obtain the rank of the present process.
const std::string & error()
Returns the last error in dynamic loader.
void eraseFile(FileBase &)
Erase a file.
void createFullList(int *)
void prepareDependencies()
Prepare the list of active Actions and needed atoms.
IFile & open(const std::string &name)
Opens the file.
void readInputWords(const std::vector< std::string > &str)
Read an input string.
This class is used to bring the relevant information to the Action constructor.
void exit(int c=0)
Stop the run.
Action used to create objects that access the positions of the atoms from the MD code.
void fflush()
Flush all files.
void clearInputForces()
Clear the forces on the values.
OFile & link(OFile &)
Allows linking this OFile to another one.
bool initialized
Flag to avoid double initialization.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
const double & getEnergy() const
Get energy units as double.
Base class for all the input Actions.
void cmd(const std::string &key, const void *val)
Const val version, which indeed just overrides the const and call the virtual method.
bool isOpen()
Check if a file is open.
void setSuffix(const std::string &)
Set the suffix string.
Citations & citations
tools/Citations.holder
Atoms & atoms
Object containing information about atoms (such as positions,...).
void setMDLengthUnits(double d)
Inherit from here if you are calculating the position of a virtual atom (eg a center of mass) ...
std::string cite(const std::string &)
Add a citation.
void insertFile(FileBase &)
Insert a file.
Class taking care of bibliography.
void setMDTimeUnits(double d)
std::set< FileBase * >::iterator files_iterator
void calc()
Complete PLUMED calculation.
bool active
Condition for plumed to be active.
void prepareCalc()
Prepare the calculation.
Communicator & comm
Communicator for plumed.
void readInputFile(std::string str)
Read an input file.
void setAtomsGatindex(int *)
FILE * fopen(const char *path, const char *mode)
Opens a file.
void pause(const std::string &name)
Pause timer named "name".
static bool installed()
Returns true if the dynamic loader is available (on some systems it may not).
ActionSet & actionSet
Set of actions found in plumed.dat file.
double getOutputQuantity(const unsigned j) const
Get the value of one of the components of the PLMD::Action.
double getBias() const
get the value of the bias
std::string getVersionGit()
void stop(const std::string &name)
Stop timer named "name".
const Units & getMDUnits()
std::set< FileBase * > files
const std::string & getSuffix() const
Get the suffix string.
void cmd(const std::string &key, void *val=NULL)
cmd method, accessible with standard Plumed.h interface.
int fclose(FILE *fp)
Closes a file opened with PlumedMain::fopen()
void * load(const std::string &)
Load a library, returning its handle.
void setDomainDecomposition(Communicator &)
virtual void clearDerivatives()
Clear the derivatives of values wrt parameters.
bool detailedTimers
Flag to switch on detailed timers.
std::string suffix
Suffix string for file opening, useful for multiple simulations in the same directory.
void Barrier() const
Wrapper to MPI_Barrier.
void setRealPrecision(int)
void setMDNaturalUnits(bool n)
Class implementing stopwatch to time execution.
void shareData()
Share the needed atoms.
void performCalc()
Perform the calculation.
void Set_comm(MPI_Comm)
Set from a real MPI communicator.
Base class for dealing with files.
Class providing cmd() access to command line tools.
#define CHECK_NOTINIT(ini, word)
double getTimeStep() const
int Get_size() const
Obtain the number of processes.
std::string cite(const std::string &)
Add a citation, returning a string containing the reference number, something like "[10]"...
Action * create(const ActionOptions &ao)
Create an Action of the type indicated in the options.
void Set_fcomm(void *comm)
Set from a pointer to a real MPI communicator (FORTRAN)
#define CHECK_INIT(ini, word)
OFile & setLinePrefix(const std::string &)
Set the prefix for output.
OFile & open(const std::string &name)
Opens the file using automatic append/backup.
ExchangePatterns & exchangePatterns
Class of possible exchange patterns, used for BIASEXCHANGE but also for future parallel tempering...
Log & getLog()
Referenge to the log stream.
std::string MDEngine
Name of MD engine.
void setGradientsIfNeeded()
void MD2double(const void *m, double &d) const
void start(const std::string &name)
Start timer named "name".
void setPositions(void *)
void Abort(int)
Wrapper to MPI_Abort.
void clearDelete()
Clear and deletes all the included pointers.