From 5e6e6d6022c50624325b162bed67e4a59ff23d8a Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Wed, 12 Dec 2012 15:07:44 +0100 Subject: [PATCH] Moving setup actions in a separate dir Since the SetupMolInfo action is used by other ones, I left it in core/. It is however registered in setup/, so that it can be excluded disabling that module. Moreover, I added a method so as to remove a friend statement in PlumedMain --- src/core/PlumedMain.h | 5 ++- src/core/SetupMolInfo.cpp | 7 +++- src/setup/.gitignore | 9 +++++ src/setup/ActionSetup.h | 25 +++++++++++++ src/{core/SetupLoad.cpp => setup/Load.cpp} | 18 +++++---- src/setup/Makefile | 5 +++ src/setup/MolInfo.cpp | 37 +++++++++++++++++++ .../SetupRestart.cpp => setup/Restart.cpp} | 22 ++++++----- src/{core/SetupUnits.cpp => setup/Units.cpp} | 22 ++++++----- src/setup/module.type | 1 + 10 files changed, 120 insertions(+), 31 deletions(-) create mode 100644 src/setup/.gitignore create mode 100644 src/setup/ActionSetup.h rename src/{core/SetupLoad.cpp => setup/Load.cpp} (86%) create mode 100644 src/setup/Makefile create mode 100644 src/setup/MolInfo.cpp rename src/{core/SetupRestart.cpp => setup/Restart.cpp} (84%) rename src/{core/SetupUnits.cpp => setup/Units.cpp} (91%) create mode 100644 src/setup/module.type diff --git a/src/core/PlumedMain.h b/src/core/PlumedMain.h index a99ccdd7f..540a6e098 100644 --- a/src/core/PlumedMain.h +++ b/src/core/PlumedMain.h @@ -71,8 +71,6 @@ It does not contain any static data. class PlumedMain: public WithCmd { -/// I restrict access to this class so that other classes cannot mistakely change the restart flag. - friend class SetupRestart; public: /// Communicator for plumed. /// Includes all the processors used by plumed. @@ -137,6 +135,7 @@ public: /// Flag to switch off virial calculation (for debug) bool novirial; + /// Add a citation, returning a string containing the reference number, something like "[10]" std::string cite(const std::string&); @@ -246,6 +245,8 @@ public: void fflush(); /// Check if restarting bool getRestart()const; +/// Set restart flag + void setRestart(bool f){restart=f;} /// Stop the calculation cleanly (both the MD code and plumed) void stop(); }; diff --git a/src/core/SetupMolInfo.cpp b/src/core/SetupMolInfo.cpp index ee04b5cfd..9d4f4bc9d 100644 --- a/src/core/SetupMolInfo.cpp +++ b/src/core/SetupMolInfo.cpp @@ -61,7 +61,12 @@ ALPHARMSD BACKBONE=all TYPE=DRMSD LESS_THAN={RATIONAL R_0=0.08 NN=8 MM=12} LABEL //+ENDPLUMEDOC -PLUMED_REGISTER_ACTION(SetupMolInfo,"MOLINFO") +/* +This action is defined in core/ as it is used by other actions. +Anyway, it is registered in setup/, so that excluding that module from +compilation will exclude it from plumed. +*/ + void SetupMolInfo::registerKeywords( Keywords& keys ){ ActionSetup::registerKeywords(keys); diff --git a/src/setup/.gitignore b/src/setup/.gitignore new file mode 100644 index 000000000..488855233 --- /dev/null +++ b/src/setup/.gitignore @@ -0,0 +1,9 @@ +/* +# in this directory, only accept source, Makefile and README +!/.gitignore +!/*.c +!/*.cpp +!/*.h +!/Makefile +!/README +!/module.type diff --git a/src/setup/ActionSetup.h b/src/setup/ActionSetup.h new file mode 100644 index 000000000..25d050ed6 --- /dev/null +++ b/src/setup/ActionSetup.h @@ -0,0 +1,25 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2012 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed-code.org for more information. + + This file is part of plumed, version 2.0. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see <http://www.gnu.org/licenses/>. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#ifndef __PLUMED_setup_ActionSetup_h +#define __PLUMED_setup_ActionSetup_h +#include "core/ActionSetup.h" +#endif diff --git a/src/core/SetupLoad.cpp b/src/setup/Load.cpp similarity index 86% rename from src/core/SetupLoad.cpp rename to src/setup/Load.cpp index 28d160d7f..da4f2de98 100644 --- a/src/core/SetupLoad.cpp +++ b/src/setup/Load.cpp @@ -19,14 +19,15 @@ You should have received a copy of the GNU Lesser General Public License along with plumed. If not, see <http://www.gnu.org/licenses/>. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ -#include "ActionSetup.h" -#include "ActionRegister.h" -#include "PlumedMain.h" +#include "core/ActionSetup.h" +#include "core/ActionRegister.h" +#include "core/PlumedMain.h" #include "tools/PlumedException.h" using namespace std; namespace PLMD{ +namespace setup{ //+PLUMEDOC GENERIC LOAD /* @@ -45,22 +46,22 @@ LOAD FILE=extensions.so */ //+ENDPLUMEDOC -class SetupLoad : +class Load : public virtual ActionSetup { public: static void registerKeywords( Keywords& keys ); - SetupLoad(const ActionOptions&ao); + Load(const ActionOptions&ao); }; -PLUMED_REGISTER_ACTION(SetupLoad,"LOAD") +PLUMED_REGISTER_ACTION(Load,"LOAD") -void SetupLoad::registerKeywords( Keywords& keys ){ +void Load::registerKeywords( Keywords& keys ){ ActionSetup::registerKeywords(keys); keys.add("compulsory","FILE","-","file to be loaded"); } -SetupLoad::SetupLoad(const ActionOptions&ao): +Load::Load(const ActionOptions&ao): Action(ao), ActionSetup(ao) { @@ -72,4 +73,5 @@ ActionSetup(ao) } } +} diff --git a/src/setup/Makefile b/src/setup/Makefile new file mode 100644 index 000000000..43a7e5620 --- /dev/null +++ b/src/setup/Makefile @@ -0,0 +1,5 @@ +USE=core tools +BUILDAFTER=config + +#generic makefile +include ../maketools/make.module diff --git a/src/setup/MolInfo.cpp b/src/setup/MolInfo.cpp new file mode 100644 index 000000000..57a7e6de7 --- /dev/null +++ b/src/setup/MolInfo.cpp @@ -0,0 +1,37 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2012 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed-code.org for more information. + + This file is part of plumed, version 2.0. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see <http://www.gnu.org/licenses/>. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#include "core/ActionRegister.h" +#include "core/SetupMolInfo.h" + +namespace PLMD{ +namespace setup{ + +/* +This action is defined in core/ as it is used by other actions. +Anyway, it is registered here, so that excluding this module from +compilation will exclude it from plumed. +*/ + +PLUMED_REGISTER_ACTION(SetupMolInfo,"MOLINFO") + +} +} diff --git a/src/core/SetupRestart.cpp b/src/setup/Restart.cpp similarity index 84% rename from src/core/SetupRestart.cpp rename to src/setup/Restart.cpp index 6e2d65cab..7b8f4e426 100644 --- a/src/core/SetupRestart.cpp +++ b/src/setup/Restart.cpp @@ -19,15 +19,16 @@ You should have received a copy of the GNU Lesser General Public License along with plumed. If not, see <http://www.gnu.org/licenses/>. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ -#include "ActionSetup.h" -#include "ActionRegister.h" -#include "PlumedMain.h" -#include "Atoms.h" +#include "core/ActionSetup.h" +#include "core/ActionRegister.h" +#include "core/PlumedMain.h" +#include "core/Atoms.h" #include "tools/PlumedException.h" using namespace std; namespace PLMD{ +namespace setup{ //+PLUMEDOC GENERIC RESTART /* @@ -59,26 +60,27 @@ This directive can have also other side effects, e.g. on \ref METAD */ //+ENDPLUMEDOC -class SetupRestart : +class Restart : public virtual ActionSetup { public: static void registerKeywords( Keywords& keys ); - SetupRestart(const ActionOptions&ao); + Restart(const ActionOptions&ao); }; -PLUMED_REGISTER_ACTION(SetupRestart,"RESTART") +PLUMED_REGISTER_ACTION(Restart,"RESTART") -void SetupRestart::registerKeywords( Keywords& keys ){ +void Restart::registerKeywords( Keywords& keys ){ ActionSetup::registerKeywords(keys); } -SetupRestart::SetupRestart(const ActionOptions&ao): +Restart::Restart(const ActionOptions&ao): Action(ao), ActionSetup(ao) { - plumed.restart=true; + plumed.setRestart(true); log<<"Restarting simulation: files will be appended\n"; } } +} diff --git a/src/core/SetupUnits.cpp b/src/setup/Units.cpp similarity index 91% rename from src/core/SetupUnits.cpp rename to src/setup/Units.cpp index b834063eb..35683e339 100644 --- a/src/core/SetupUnits.cpp +++ b/src/setup/Units.cpp @@ -19,15 +19,16 @@ You should have received a copy of the GNU Lesser General Public License along with plumed. If not, see <http://www.gnu.org/licenses/>. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ -#include "ActionSetup.h" -#include "ActionRegister.h" -#include "PlumedMain.h" -#include "Atoms.h" +#include "core/ActionSetup.h" +#include "core/ActionRegister.h" +#include "core/PlumedMain.h" +#include "core/Atoms.h" #include "tools/PlumedException.h" using namespace std; namespace PLMD{ +namespace setup{ //+PLUMEDOC GENERIC UNITS /* @@ -51,17 +52,17 @@ UNITS LENGTH=nm TIME=0.001 */ //+ENDPLUMEDOC -class SetupUnits : +class Units : public virtual ActionSetup { public: static void registerKeywords( Keywords& keys ); - SetupUnits(const ActionOptions&ao); + Units(const ActionOptions&ao); }; -PLUMED_REGISTER_ACTION(SetupUnits,"UNITS") +PLUMED_REGISTER_ACTION(Units,"UNITS") -void SetupUnits::registerKeywords( Keywords& keys ){ +void Units::registerKeywords( Keywords& keys ){ ActionSetup::registerKeywords(keys); keys.add("optional","LENGTH","the units of lengths. Either specify a conversion factor from the default, nm, or A (for angstroms) or um"); keys.add("optional","ENERGY","the units of energy. Either specify a conversion factor from the default, kj/mol, or use j/mol or kcal/mol"); @@ -69,11 +70,11 @@ void SetupUnits::registerKeywords( Keywords& keys ){ keys.addFlag("NATURAL",false,"use natural units"); } -SetupUnits::SetupUnits(const ActionOptions&ao): +Units::Units(const ActionOptions&ao): Action(ao), ActionSetup(ao) { - Units u; + PLMD::Units u; std::string s; @@ -111,4 +112,5 @@ ActionSetup(ao) } } +} diff --git a/src/setup/module.type b/src/setup/module.type new file mode 100644 index 000000000..fc25731b6 --- /dev/null +++ b/src/setup/module.type @@ -0,0 +1 @@ +default-on -- GitLab