Skip to content

Commit

Permalink
Simplification for getting the files that are used for shortcuts and …
Browse files Browse the repository at this point in the history
…valuedictionary
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed May 21, 2024
1 parent 8369007 commit 2fe5b14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions PlumedToHTML/PlumedToHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
"""

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='PlumedToHTML',
version='0.70',
version='0.71',
author="Gareth Tribello",
author_email="[email protected]",
description="A package for creating pretified HTML for PLUMED files",
Expand Down

0 comments on commit 2fe5b14

Please sign in to comment.