Skip to content

Commit

Permalink
Added functionality to add DOIs to syntax file and then cite them usi…
Browse files Browse the repository at this point in the history
…ng plumed.cite command (#1202)

* Added functionality to add DOIs to syntax file and then cite them using plumed.cite command

* Fixed python issue that github points out

---------

Co-authored-by: Gareth Aneurin Tribello <[email protected]>
  • Loading branch information
gtribello and Gareth Aneurin Tribello authored Mar 10, 2025
1 parent 05b18f4 commit d382710
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 3 deletions.
36 changes: 36 additions & 0 deletions json/doi_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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
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) + "\"}")
3 changes: 2 additions & 1 deletion src/adjmat/AdjacencyMatrixBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -174,7 +175,7 @@ AdjacencyMatrixBase::AdjacencyMatrixBase(const ActionOptions& ao):
addComponent( "z", shape );
componentIsNotPeriodic("z");
}
log<<" Bibliography "<<plumed.cite("Tribello, Giberti, Sosso, Salvalaglio and Parrinello, J. Chem. Theory Comput. 13, 1317 (2017)")<<"\n";
log<<" Bibliography "<<plumed.cite("10.1021/acs.jctc.6b01073")<<"\n";
}

unsigned AdjacencyMatrixBase::getNumberOfDerivatives() {
Expand Down
9 changes: 9 additions & 0 deletions src/cltools/GenJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ int GenJson::main(FILE* in, FILE*out,Communicator& pc) {
}
std::cout<<" \"replacement\" : \""<<replacement<<"\",\n";
}
std::cout<<" \"dois\" : [";
unsigned ndoi = keys.getDOIList().size();
if( ndoi>0 ) {
std::cout<<"\"" + keys.getDOIList()[0] + "\"";
for(unsigned j=1; j<ndoi; ++j) {
std::cout<<", \"" + keys.getDOIList()[j] + "\"";
}
}
std::cout<<"],\n";
std::cout<<" \"syntax\" : {"<<std::endl;
for(unsigned j=0; j<keys.size(); ++j) {
std::string defa = "", desc = keys.getKeywordDescription( keys.getKeyword(j) );
Expand Down
2 changes: 2 additions & 0 deletions src/clusters/ClusteringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace clusters {
void ClusteringBase::registerKeywords( Keywords& keys ) {
matrixtools::MatrixOperationBase::registerKeywords( keys );
keys.setValueDescription("vector","vector with length that is equal to the number of rows in the input matrix. Elements of this vector are equal to the cluster that each node is a part of");
keys.addDOI("10.1021/acs.jctc.6b01073");
}

ClusteringBase::ClusteringBase(const ActionOptions&ao):
Expand All @@ -49,6 +50,7 @@ ClusteringBase::ClusteringBase(const ActionOptions&ao):
// Resize local variables
which_cluster.resize( getPntrToArgument(0)->getShape()[0] );
cluster_sizes.resize( getPntrToArgument(0)->getShape()[0] );
log<<" Bibliography "<<plumed.cite("10.1021/acs.jctc.6b01073")<<"\n";
}

void ClusteringBase::retrieveAdjacencyLists( std::vector<unsigned>& nneigh, Matrix<unsigned>& adj_list ) {
Expand Down
1 change: 1 addition & 0 deletions src/tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
!/Makefile
!/README
!/module.type
!/CitationMap.inc
1 change: 1 addition & 0 deletions src/tools/CitationMap.inc
Original file line number Diff line number Diff line change
@@ -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)"}
13 changes: 11 additions & 2 deletions src/tools/Citations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@

namespace PLMD {

const static Tools::FastStringUnorderedMap<std::string> 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<items.size(); ++i)
if(items[i]==item) {
if(items[i]==myref) {
break;
}
if(i==items.size()) {
items.push_back(item);
items.push_back(myref);
}
plumed_assert(i<items.size());
std::string ret;
Expand Down
8 changes: 8 additions & 0 deletions src/tools/Keywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,14 @@ std::string Keywords::getReplacementAction() const {
return replaceaction;
}

void Keywords::addDOI( const std::string& doi ) {
doilist.push_back( doi );
}

const std::vector<std::string>& Keywords::getDOIList() const {
return doilist;
}

void Keywords::linkActionInDocs( const std::string& k, const std::string& action ) {
plumed_massert( exists(k), "no " + k + " keyword" );
keywords.at(k).setLinkedAction(action);
Expand Down
6 changes: 6 additions & 0 deletions src/tools/Keywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class Keywords {
std::vector<std::string> neededActions;
/// List of suffixes that can be used with this action
std::vector<std::string> actionNameSuffixes;
/// List of doi's that should appear in the manual
std::vector<std::string> doilist;
/// Print the documentation for the named keyword in html
void print_html_item( const std::string& ) const;
public:
Expand Down Expand Up @@ -312,6 +314,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<std::string>& getDOIList() const ;
/// Create a link to this action in the documentation for it
void linkActionInDocs( const std::string& k, const std::string& action );
/// Get any actions that are linked to this keyword
Expand Down

1 comment on commit d382710

@PlumedBot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found broken examples in automatic/ANGLES.tmp
Found broken examples in automatic/ANN.tmp
Found broken examples in automatic/CAVITY.tmp
Found broken examples in automatic/CLASSICAL_MDS.tmp
Found broken examples in automatic/CLUSTER_DIAMETER.tmp
Found broken examples in automatic/CLUSTER_DISTRIBUTION.tmp
Found broken examples in automatic/CLUSTER_PROPERTIES.tmp
Found broken examples in automatic/CONSTANT.tmp
Found broken examples in automatic/CONTACT_MATRIX.tmp
Found broken examples in automatic/CONTACT_MATRIX_PROPER.tmp
Found broken examples in automatic/CONVERT_TO_FES.tmp
Found broken examples in automatic/COORDINATIONNUMBER.tmp
Found broken examples in automatic/DFSCLUSTERING.tmp
Found broken examples in automatic/DISTANCE_FROM_CONTOUR.tmp
Found broken examples in automatic/DUMPCUBE.tmp
Found broken examples in automatic/DUMPGRID.tmp
Found broken examples in automatic/EDS.tmp
Found broken examples in automatic/EMMI.tmp
Found broken examples in automatic/ENVIRONMENTSIMILARITY.tmp
Found broken examples in automatic/FIND_CONTOUR.tmp
Found broken examples in automatic/FIND_CONTOUR_SURFACE.tmp
Found broken examples in automatic/FIND_SPHERICAL_CONTOUR.tmp
Found broken examples in automatic/FOURIER_TRANSFORM.tmp
Found broken examples in automatic/FUNCPATHGENERAL.tmp
Found broken examples in automatic/FUNCPATHMSD.tmp
Found broken examples in automatic/FUNNEL.tmp
Found broken examples in automatic/FUNNEL_PS.tmp
Found broken examples in automatic/GHBFIX.tmp
Found broken examples in automatic/GPROPERTYMAP.tmp
Found broken examples in automatic/HBOND_MATRIX.tmp
Found broken examples in automatic/HISTOGRAM.tmp
Found broken examples in automatic/INCLUDE.tmp
Found broken examples in automatic/INCYLINDER.tmp
Found broken examples in automatic/INENVELOPE.tmp
Found broken examples in automatic/INTERPOLATE_GRID.tmp
Found broken examples in automatic/LOCAL_AVERAGE.tmp
Found broken examples in automatic/MAZE_OPTIMIZER_BIAS.tmp
Found broken examples in automatic/MAZE_RANDOM_ACCELERATION_MD.tmp
Found broken examples in automatic/MAZE_SIMULATED_ANNEALING.tmp
Found broken examples in automatic/MAZE_STEERED_MD.tmp
Found broken examples in automatic/METATENSOR.tmp
Found broken examples in automatic/MULTICOLVARDENS.tmp
Found broken examples in automatic/OUTPUT_CLUSTER.tmp
Found broken examples in automatic/PAMM.tmp
Found broken examples in automatic/PCA.tmp
Found broken examples in automatic/PCAVARS.tmp
Found broken examples in automatic/PIV.tmp
Found broken examples in automatic/PLUMED.tmp
Found broken examples in automatic/Q3.tmp
Found broken examples in automatic/Q4.tmp
Found broken examples in automatic/Q6.tmp
Found broken examples in automatic/QUATERNION.tmp
Found broken examples in automatic/REWEIGHT_BIAS.tmp
Found broken examples in automatic/REWEIGHT_METAD.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_LINEAR_PROJ.tmp
Found broken examples in automatic/SIZESHAPE_POSITION_MAHA_DIST.tmp
Found broken examples in automatic/SPRINT.tmp
Found broken examples in automatic/TETRAHEDRALPORE.tmp
Found broken examples in automatic/TORSIONS.tmp
Found broken examples in automatic/WHAM_HISTOGRAM.tmp
Found broken examples in automatic/WHAM_WEIGHTS.tmp
Found broken examples in AnalysisPP.md
Found broken examples in CollectiveVariablesPP.md
Found broken examples in MiscelaneousPP.md

Please sign in to comment.