From cad3ce5ea13f646a079109643f644c1f0544d5de Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Tue, 18 Feb 2025 07:30:18 +0000 Subject: [PATCH 1/2] Added functionality to add DOIs to syntax file and then cite them using plumed.cite command --- json/doi_manager.py | 37 ++++++++++++++++++++++++++++++ src/adjmat/AdjacencyMatrixBase.cpp | 3 ++- src/cltools/GenJson.cpp | 9 ++++++++ src/clusters/ClusteringBase.cpp | 2 ++ src/tools/.gitignore | 1 + src/tools/CitationMap.inc | 1 + src/tools/Citations.cpp | 13 +++++++++-- src/tools/Keywords.cpp | 8 +++++++ src/tools/Keywords.h | 6 +++++ 9 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 json/doi_manager.py create mode 100644 src/tools/CitationMap.inc diff --git a/json/doi_manager.py b/json/doi_manager.py new file mode 100644 index 0000000000..5425395adf --- /dev/null +++ b/json/doi_manager.py @@ -0,0 +1,37 @@ +import subprocess +import json + +def get_dois_from_syntax() : + with open("syntax.json") as f : + try: + plumed_syntax = json.load(f) + except ValueError as ve: + raise InvalidJSONError(ve) + + doilist = [] + for key, value in plumed_syntax.items() : + if not isinstance(value,dict) or "dois" not in value.keys() : continue + for doi in value["dois"] : + if doi not in doilist : doilist.append(doi) + return doilist + +def get_reference(doi): + # initialize strings + ref="" + # retrieve citation from doi + if(len(doi)>0): + # get citation + cit = subprocess.check_output('curl -LH "Accept: text/bibliography; style=science" \'http://dx.doi.org/'+doi+'\'', shell=True).decode('utf-8').strip() + if("DOI Not Found" in cit) : ref="DOI not found" + else: ref=cit[3:cit.find(", doi")] + return ref + +if __name__ == "__main__" : + # Get all the dois that are listed in the syntax file + doilist = get_dois_from_syntax() + # Now get all the references using Max's magic script and create the map + of = open("../src/tools/CitationMap.inc","w+") + for doi in doilist : + if doi==doilist[-1] : of.write("{\"" + doi + "\",\"" + get_reference(doi) + "\"}") + else : of.write("{\"" + doi + "\",\"" + get_reference(doi) + "\"}") + of.close() diff --git a/src/adjmat/AdjacencyMatrixBase.cpp b/src/adjmat/AdjacencyMatrixBase.cpp index c75bf31e1d..a9ca438bd2 100644 --- a/src/adjmat/AdjacencyMatrixBase.cpp +++ b/src/adjmat/AdjacencyMatrixBase.cpp @@ -43,6 +43,7 @@ void AdjacencyMatrixBase::registerKeywords( Keywords& keys ) { keys.addOutputComponent("y","COMPONENTS","matrix","the projection of the bond on the y axis"); keys.addOutputComponent("z","COMPONENTS","matrix","the projection of the bond on the z axis"); keys.setValueDescription("matrix","a matrix containing the weights for the bonds between each pair of atoms"); + keys.addDOI("10.1021/acs.jctc.6b01073"); } AdjacencyMatrixBase::AdjacencyMatrixBase(const ActionOptions& ao): @@ -174,7 +175,7 @@ AdjacencyMatrixBase::AdjacencyMatrixBase(const ActionOptions& ao): addComponent( "z", shape ); componentIsNotPeriodic("z"); } - log<<" Bibliography "<0 ) { + std::cout<<"\"" + keys.getDOIList()[0] + "\""; + for(unsigned j=1; jgetShape()[0] ); cluster_sizes.resize( getPntrToArgument(0)->getShape()[0] ); + log<<" Bibliography "<& nneigh, Matrix& adj_list ) { diff --git a/src/tools/.gitignore b/src/tools/.gitignore index 4888552338..ad4adf6152 100644 --- a/src/tools/.gitignore +++ b/src/tools/.gitignore @@ -7,3 +7,4 @@ !/Makefile !/README !/module.type +!/CitationMap.inc diff --git a/src/tools/CitationMap.inc b/src/tools/CitationMap.inc new file mode 100644 index 0000000000..8b2d9f5554 --- /dev/null +++ b/src/tools/CitationMap.inc @@ -0,0 +1 @@ +{"10.1021/acs.jctc.6b01073","G. A. Tribello, F. Giberti, G. C. Sosso, M. Salvalaglio, M. Parrinello, Analyzing and Driving Cluster Formation in Atomistic Simulations. Journal of Chemical Theory and Computation. 13, 1317–1327 (2017)"} \ No newline at end of file diff --git a/src/tools/Citations.cpp b/src/tools/Citations.cpp index 2f4a06ca00..ef23a2d1ec 100644 --- a/src/tools/Citations.cpp +++ b/src/tools/Citations.cpp @@ -26,14 +26,23 @@ namespace PLMD { +const static Tools::FastStringUnorderedMap doi_map = { +#include "CitationMap.inc" +}; + std::string Citations::cite(const std::string & item) { + std::string myref=item; + if( doi_map.find(item)!=doi_map.end() ) { + myref=doi_map.find(item)->second; + } + unsigned i; for(i=0; i& Keywords::getDOIList() const { + return doilist; +} + }// namespace PLMD diff --git a/src/tools/Keywords.h b/src/tools/Keywords.h index 9a02e1e5cb..3b846caaa2 100644 --- a/src/tools/Keywords.h +++ b/src/tools/Keywords.h @@ -152,6 +152,8 @@ class Keywords { std::vector neededActions; /// List of suffixes that can be used with this action std::vector actionNameSuffixes; +/// List of doi's that should appear in the manual + std::vector doilist; /// Print the documentation for the named keyword in html void print_html_item( const std::string& ) const; public: @@ -314,6 +316,10 @@ class Keywords { std::string getReplacementAction() const ; /// Note that this action has been deprecated void setDeprecated( const std::string& name ); +/// Add a DOI to the list in the manual page for this action + void addDOI( const std::string& doi ); +/// Get the list of DOI + const std::vector& getDOIList() const ; }; //the following templates specializations make the bitmask enum work with the From f3bb1e92214e25e766f25f647adeefe0503d7cc9 Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Mon, 24 Feb 2025 09:09:26 +0000 Subject: [PATCH 2/2] Fixed python issue that github points out --- json/doi_manager.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/json/doi_manager.py b/json/doi_manager.py index 5425395adf..37f58952f7 100644 --- a/json/doi_manager.py +++ b/json/doi_manager.py @@ -30,8 +30,7 @@ def get_reference(doi): # Get all the dois that are listed in the syntax file doilist = get_dois_from_syntax() # Now get all the references using Max's magic script and create the map - of = open("../src/tools/CitationMap.inc","w+") - for doi in doilist : - if doi==doilist[-1] : of.write("{\"" + doi + "\",\"" + get_reference(doi) + "\"}") - else : of.write("{\"" + doi + "\",\"" + get_reference(doi) + "\"}") - of.close() + with open("../src/tools/CitationMap.inc","w+") as of : + for doi in doilist : + if doi==doilist[-1] : of.write("{\"" + doi + "\",\"" + get_reference(doi) + "\"}") + else : of.write("{\"" + doi + "\",\"" + get_reference(doi) + "\"}")