Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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