Skip to content

Commit 78c35ce

Browse files
Gareth Aneurin TribelloGareth Aneurin Tribello
authored andcommitted
Bug fix for testing for keywords.
This fixes a problem when numbered keyword detection was done wrongly if you are checking the keywords for the last action in the input file.
1 parent f775584 commit 78c35ce

File tree

3 files changed

+50
-13
lines changed

3 files changed

+50
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "PlumedToHTML"
8-
version = "0.121"
8+
version = "0.122"
99
description = "A package for creating prettified HTML for PLUMED files"
1010
authors = [{ name = "Gareth Tribello", email = "[email protected]" }]
1111
maintainers = [{ name = "Daniele Rapetti", email = "[email protected]" }]

src/PlumedToHTML/PlumedFormatter.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,8 @@ def format(self, tokensource, outfile):
3838
for ttype, value in tokensource :
3939
# This checks if we are at the start of a new action. If we are we should be reading a value or an action and the label and action for the previous one should be set
4040
if len(action)>0 and (ttype==String or ttype==Keyword or ttype==Comment.Preproc) :
41-
if action==self.checkaction :
42-
for key in keywords :
43-
if key in self.keyword_dict[action]["syntax"] :
44-
self.checkaction_keywords.add( key )
45-
else :
46-
# This makes sure we find numbered keywords
47-
for kkkk in self.keyword_dict[action]["syntax"] :
48-
if kkkk=="output" or self.keyword_dict[action]["syntax"][kkkk]["multiple"]==0 : continue
49-
if kkkk in key : self.checkaction_keywords.add( kkkk )
41+
if action==self.checkaction :
42+
self.storeKeywordsForCheckAction( keywords )
5043
if notooltips :
5144
# Reset everything for the new action
5245
action, label, keywords, notooltips = "", "", [], False
@@ -302,9 +295,8 @@ def format(self, tokensource, outfile):
302295
else :
303296
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">'+ self.keyword_dict[action]["description"] + ' <a href="' + self.keyword_dict[action]["hyperlink"] + '" style="color:green">More details</a><i></i></span></span>')
304297
# Check if there is stuff to output for the last action in the file
305-
if action==self.checkaction :
306-
for key in keywords :
307-
self.checkaction_keywords.add( key )
298+
if action==self.checkaction :
299+
self.storeKeywordsForCheckAction( keywords )
308300
if len(label)>0 and label not in all_labels and label not in self.valuedict.keys() :
309301
all_labels.add( label )
310302
if action in self.keyword_dict and "output" in self.keyword_dict[action]["syntax"] : self.writeValuesData( outfile, action, label, keywords, self.keyword_dict[action]["syntax"]["output"] )
@@ -354,4 +346,14 @@ def writeValueInfo( self, outfile, label, span_label, valinfo ) :
354346

355347
def getCheckActionKeywords( self ) :
356348
return self.checkaction_keywords
349+
350+
def storeKeywordsForCheckAction( self, keywords ) :
351+
for key in keywords :
352+
if key in self.keyword_dict[self.checkaction]["syntax"] :
353+
self.checkaction_keywords.add( key )
354+
else :
355+
# This makes sure we find numbered keywords
356+
for kkkk in self.keyword_dict[self.checkaction]["syntax"] :
357+
if kkkk=="output" or self.keyword_dict[self.checkaction]["syntax"][kkkk]["multiple"]==0 : continue
358+
if kkkk in key : self.checkaction_keywords.add( kkkk )
357359

tests/test_keyword_list.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,38 @@ def testReadKeywords(self) :
3434
with open("check_keywords_file", "w") as ofile :
3535
PlumedToHTML.processMarkdownString( inpt, "check_keyword", ("plumed",), ("master",), actions, ofile, checkaction="DISTANCE", checkactionkeywords=keyset )
3636
self.assertTrue( keyset==set({"COMPONENTS"}) )
37+
38+
inpt = """
39+
```plumed
40+
# Define two groups of atoms
41+
g: GROUP ATOMS=1-5
42+
h: GROUP ATOMS=6-20
43+
44+
# Calculate the CONTACT_MATRIX for the atoms in group g
45+
cg: CONTACT_MATRIX GROUP=g SWITCH={RATIONAL R_0=0.1}
46+
47+
# Calculate the CONTACT_MATRIX for the atoms in group h
48+
ch: CONTACT_MATRIX GROUP=h SWITCH={RATIONAL R_0=0.2}
49+
50+
# Calculate the CONTACT_MATRIX between the atoms in group g and group h
51+
cgh: CONTACT_MATRIX GROUPA=g GROUPB=h SWITCH={RATIONAL R_0=0.15}
52+
53+
# Now calculate the contact matrix between the atoms in group h and group h
54+
# Notice this is just the transpose of cgh
55+
cghT: TRANSPOSE ARG=cgh
56+
57+
# And concatenate the matrices together to construct the adjacency matrix between the
58+
# adjacency matrices
59+
m: CONCATENATE ...
60+
MATRIX11=cg MATRIX12=cgh
61+
MATRIX21=cghT MATRIX22=ch
62+
...
63+
```
64+
"""
65+
66+
actions = set({})
67+
keyset = set({"MATRIX"})
68+
with open("check_keywords_file", "w") as ofile :
69+
PlumedToHTML.processMarkdownString( inpt, "check_keyword", ("plumed",), ("master",), actions, ofile, checkaction="CONCATENATE", checkactionkeywords=keyset )
70+
print( "final keyset", keyset )
71+
self.assertTrue( keyset==set({}) )

0 commit comments

Comments
 (0)