From 07e03ff09b0fce6133995ca70b7c6920d312022d Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Wed, 4 Jul 2012 13:55:54 +0200 Subject: [PATCH] Added class to manage bibliography --- src/BiasMetaD.cpp | 6 ++++++ src/Citations.cpp | 26 ++++++++++++++++++++++++++ src/Citations.h | 30 ++++++++++++++++++++++++++++++ src/PlumedMain.cpp | 11 +++++++++++ src/PlumedMain.h | 7 ++++++- 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/Citations.cpp create mode 100644 src/Citations.h diff --git a/src/BiasMetaD.cpp b/src/BiasMetaD.cpp index d0669c44b..80c1b897f 100644 --- a/src/BiasMetaD.cpp +++ b/src/BiasMetaD.cpp @@ -251,6 +251,12 @@ grid_(false) }else{ hillsfile_=fopen(hillsfname.c_str(),"w"); } + + log<<" Bibliography "<<plumed.cite("Laio and Parrinello, PNAS 99, 12562 (2002)"); + if(welltemp_) log<<plumed.cite( + "Barducci, Bussi, and Parrinello, Phys. Rev. Lett. 100, 020603 (2008)"); + log<<"\n"; + } void BiasMetaD::readGaussians(FILE* file) diff --git a/src/Citations.cpp b/src/Citations.cpp new file mode 100644 index 000000000..bb976d19c --- /dev/null +++ b/src/Citations.cpp @@ -0,0 +1,26 @@ +#include "Citations.h" +#include "PlumedException.h" +#include "Tools.h" +#include <iostream> + +using namespace std; +using namespace PLMD; + +std::string Citations::cite(const std::string & item){ + unsigned i; + for(i=0;i<items.size();++i) if(items[i]==item) break; + if(i==items.size()) items.push_back(item); + plumed_assert(i<items.size()); + string ret; + Tools::convert(i,ret); + ret="["+ret+"]"; + return ret; +} + +std::ostream & PLMD::operator<<(std::ostream &log,const Citations&cit){ + for(unsigned i=0;i<cit.items.size();++i) + log<<" ["<<i<<"] "<<cit.items[i]<<"\n"; + return log; +} + + diff --git a/src/Citations.h b/src/Citations.h new file mode 100644 index 000000000..2012e6b62 --- /dev/null +++ b/src/Citations.h @@ -0,0 +1,30 @@ +#ifndef __PLUMED_Citations_h +#define __PLUMED_Citations_h + +#include <vector> +#include <string> +#include <iosfwd> + +namespace PLMD{ + +/** +Class taking care of bibliography. +*/ + +class Citations{ + std::vector<std::string> items; +public: +/// Add a citation. +/// It returns a string containing the reference number, something like "[10]" + std::string cite(const std::string &); +/// Dumps the bibliography. +/// It writes on the ostream the list of all the bibliographic itemrs +/// prefixed with their reference number + friend std::ostream &operator<<(std::ostream &,const Citations&); +}; + +std::ostream & operator<<(std::ostream &,const Citations&); + +} + +#endif diff --git a/src/PlumedMain.cpp b/src/PlumedMain.cpp index fd2a42dfc..f5f9a653d 100644 --- a/src/PlumedMain.cpp +++ b/src/PlumedMain.cpp @@ -20,6 +20,7 @@ #include "PlumedCommunicator.h" #include "CLToolMain.h" #include "Stopwatch.h" +#include "Citations.h" using namespace PLMD; using namespace std; @@ -32,6 +33,7 @@ PlumedMain::PlumedMain(): grex(NULL), initialized(false), log(*new Log(comm)), + citations(*new Citations), step(0), active(false), atoms(*new Atoms(*this)), @@ -48,6 +50,7 @@ PlumedMain::~PlumedMain(){ stopwatch.stop(); if(initialized) log<<stopwatch; delete &actionSet; + delete &citations; delete &atoms; delete &log; if(grex) delete grex; @@ -302,6 +305,10 @@ void PlumedMain::init(){ } atoms.updateUnits(); log.printf("Timestep: %f\n",atoms.getTimeStep()); + log<<"Relevant bibliography:\n"; + log<<citations; + log<<"Please read and cite where appropriate!\n"; + log<<"Finished setupt\n"; } void PlumedMain::readInputFile(std::string str){ @@ -537,6 +544,10 @@ int PlumedMain::fclose(FILE*fp){ return std::fclose(fp); } +std::string PlumedMain::cite(const std::string&item){ + return citations.cite(item); +} + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/PlumedMain.h b/src/PlumedMain.h index 902c34127..416f6beb3 100644 --- a/src/PlumedMain.h +++ b/src/PlumedMain.h @@ -35,6 +35,7 @@ class ActionSet; class DLLoader; class PlumedCommunicator; class Stopwatch; +class Citations; /// Main plumed object. /// In MD engines this object is not manipulated directly but it is wrapped in @@ -61,7 +62,8 @@ private: std::string MDEngine; /// Log stream Log& log; - +/// Citations holder + Citations& citations; /// Present step number. int step; @@ -94,6 +96,9 @@ 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&); + public: PlumedMain(); // this is to access to WithCmd versions of cmd (allowing overloading of a virtual method) -- GitLab