From 2fe5b1495230b2c1d4dd0efd8df429eacd92a63e Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Tue, 21 May 2024 08:54:27 +0100 Subject: [PATCH] Simplification for getting the files that are used for shortcuts and valuedictionary --- PlumedToHTML/PlumedToHTML.py | 28 ++++++++++++++++------------ setup.py | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PlumedToHTML/PlumedToHTML.py b/PlumedToHTML/PlumedToHTML.py index a134358..9b7b7cb 100644 --- a/PlumedToHTML/PlumedToHTML.py +++ b/PlumedToHTML/PlumedToHTML.py @@ -39,6 +39,7 @@ def test_and_get_html( inpt, name, actions=set({}) ) : Keyword arguments: inpt -- A string containing the PLUMED input name -- The name to use for this input in the html + actions -- Set that is filled with the actions that were used in this input """ # Check if this is to be included by another input filename, keepfile = name + ".dat", False @@ -53,15 +54,15 @@ def test_and_get_html( inpt, name, actions=set({}) ) : iff.write(test_inpt + "\n") iff.close() # Now do the test - broken = test_plumed( "plumed", filename, header="", shortcutfile=name + '.json', valuefile='values_' + name + '.json' ) + broken = test_plumed( "plumed", filename, header="", printjson=True ) # Retrieve the html that is output by plumed - html = get_html( inpt, name, name, ("master",), (broken,), ("plumed",), actions=actions ) + html = get_html( inpt, filename, filename, ("master",), (broken,), ("plumed",), actions=actions ) # Remove the tempory files that we created if not keepfile : os.remove(filename) return html -def test_plumed( executible, filename, header=[], shortcutfile=[], valuefile=[] ) : +def test_plumed( executible, filename, header=[], printjson=False, jsondir="./" ) : """ Test if plumed can parse this input file @@ -71,8 +72,8 @@ def test_plumed( executible, filename, header=[], shortcutfile=[], valuefile=[] executible -- A string that contains the command for running plumed filename -- A string that contains the name of the plumed input file to parse header -- A string to put at the top of the error page that is output - shortcutfile -- The file on which to output the json file containing the expansed shortcuts. If not present this is not output - valuefile -- The file on which to output the dictionary explaining what each value represents. If not present this is not output + printjson -- Set true if you want to used plumed to print the files containing the expansions of shortcuts and the value dictionary + jsondir -- The directory in which to output the files containing the expansions of the shortcuts and the value dictionaries """ # Get the information for running the code run_folder = str(pathlib.PurePosixPath(filename).parent) @@ -88,10 +89,12 @@ def test_plumed( executible, filename, header=[], shortcutfile=[], valuefile=[] cmd = [executible, 'driver', '--plumed', plumed_file, '--natoms', str(natoms), '--parse-only', '--kt', '2.49'] # Add everything to ensure we can run with replicas if needs be if int(nreplicas)>1 : cmd = ['mpirun', '-np', str(nreplicas)] + cmd + ['--multi', str(nreplicas)] - # Add the shortcutfile output if the user has asked for it - if len(shortcutfile)>0 : cmd = cmd + ['--shortcut-ofile', shortcutfile] - # Add the value dictionary if the user has asked for it - if len(valuefile)>0 : cmd = cmd + ['--valuedict-ofile', valuefile] + if printjson : + plumed_file = os.path.basename(filename) + # Add the shortcutfile output if the user has asked for it + cmd = cmd + ['--shortcut-ofile', jsondir + plumed_file + ".json"] + # Add the value dictionary if the user has asked for it + cmd = cmd + ['--valuedict-ofile', jsondir + plumed_file + "_values.json"] # raw std output - to be zipped outfile=filename + "." + executible + ".stdout.txt" # raw std error - to be zipped @@ -169,6 +172,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch broken -- The outcome of running test plumed on the input plumedexe -- The plumed executibles that were used. The first one is the one that should be used to create the input file annotations usejson -- Bool that tells you whether or not to look for json files that are generated by plumed driver + maxchecks -- Maximum number of checks to perform on plumed input. Set this to reduce computational expense actions -- Set to store all the actions that have been used in the input """ @@ -203,15 +207,15 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, usejson=None, maxch if os.path.exists( name + '.json' ) : os.remove( name + ".json") # Check for value dictionary to use to create labels - if os.path.exists( 'values_' + name + '.json') and searchjson : - with open('values_' + name + '.json') as f : + if os.path.exists( name + '_values.json') and searchjson : + with open( name + '_values.json') as f : try: valuedict = json.load(f) except json.JSONDecodeError as ve: raise Exception("invalid json for value dictionary", ve) else : valuedict = {} # Remove the tempory files that we created - if os.path.exists( 'values_' + name + '.json') : os.remove( 'values_' + name + ".json") + if os.path.exists( name + '_values.json') : os.remove( name + "_values.json") # Create the lexer that will generate the pretty plumed input lexerfile = os.path.join(os.path.dirname(__file__),"PlumedLexer.py") diff --git a/setup.py b/setup.py index 47fd487..5dd1123 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name='PlumedToHTML', - version='0.70', + version='0.71', author="Gareth Tribello", author_email="gareth.tribello@gmail.com", description="A package for creating pretified HTML for PLUMED files",