Skip to content

Commit

Permalink
infrastructure changes + COMPASS bug fixes. Infrastructure: Counter v…
Browse files Browse the repository at this point in the history
…ariables ($ and @) can no longer contain , or () characters. (In the future, this will make it much easier to create source code for programming languages. Note to self: The +-=/. characters are still allowed. The / and . characters are used for path resolution and should never be forbidden.) COMPASS: The "msifrc2lt.py" script has been (hopefully) fixed and is now able to convert the COMPASS force field files again. This made it possible to fix 2 bugs in the "compass_published.lt" force field file: 1) wildcards are now given low priority instead of high priority, and 2) non-hybrid bond, angle, dihedral, improper, and pair styles are used by default (for KOKKOS compatibility). Also: Commas were removed from the atom type names (and replaced with ~ characters).
  • Loading branch information
jewettaij committed Jul 13, 2020
1 parent b1ba71f commit acc86c6
Show file tree
Hide file tree
Showing 14 changed files with 4,032 additions and 3,927 deletions.
13 changes: 7 additions & 6 deletions doc/moltemplate_manual_src/moltemplate_manual.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ \subsubsection*{Boundary Conditions:}
``animate write psf system.psf'',
``pbc wrap -compound res -all'', and
``pbc box''.
See sections \ref{sec:vmd_topotools}, and \ref{sec:vmd_advanced}
See sections \ref{sec:vmd_topotools}, and appendix \ref{sec:vmd_advanced}
for details.
}
\end{figure}
Expand Down Expand Up @@ -4417,16 +4417,17 @@ \section{Bonded interactions ``By Type''}

\subsection*{Regular expressions}
Regular-expressions can also be used to match potential atom and bond types.
(To use regular expressions, surround the atom and
bond types on either side by slashes.
For example: \mbox{/@atom:C[1-5]/}, should match
\mbox{@atom:C1} through \mbox{@atom:C6}.)
\textit{Note: This feature has not been tested as of 2019-9-03.}
To use regular expressions, the first 3 characters following ``:'' should be
``re.'', and the variable name should be enclosed in curly brackets, \{\}.
For example: \mbox{@\{atom:re.C[1-5]\}}, should match
\mbox{@atom:C1} through \mbox{@atom:C6}.
\textit{Note: This feature has not been tested as of 2020-7-09.}

In a similar way, one can define ``Dihedrals By Type'' and
``Impropers By Type''.



% I THINK I FIXED THIS LIMITATION
% SO I COMMENTED OUT THIS NEXT SECTION:
% IGNORE ALL COMMENTED OUT TEXT IN THE PARAGRAPHS BELOW
Expand Down
6 changes: 3 additions & 3 deletions moltemplate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from .ttree_lex import TtreeShlex, split, LineLex, SplitQuotedString, \
EscCharStrToChar, SafelyEncodeString, RemoveOuterQuotes, MaxLenStr, \
HasWildcard, InputError, ErrorLeader, SrcLoc, OSrcLoc, TextBlock, VarRef, \
VarNPtr, VarBinding, SplitTemplate, SplitTemplateMulti, TableFromTemplate, \
ExtractCatName, DeleteLinesWithBadVars, TemplateLexer
HasWildcard, HasRE, InputError, ErrorLeader, SrcLoc, OSrcLoc, TextBlock, \
VarRef, VarNPtr, VarBinding, SplitTemplate, SplitTemplateMulti, \
TableFromTemplate, ExtractCatName, DeleteLinesWithBadVars, TemplateLexer

from .nbody_graph_search import Disconnected, NotUndirected, Edge, Vertex, \
Dgraph, Ugraph, SortVertsByDegree, DFS, GraphMatcher
Expand Down
5 changes: 2 additions & 3 deletions moltemplate/bonds_by_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ def LookupBondTypes(bond_types,
typepattern = []

for typestr in tokens[1:]:
if ((len(typestr) >= 2) and
(typestr[0] == '/') and (typestr[-1] == '/')):
regex_str = typestr[1:-1]
if ttree_lex.HasRE(typestr):
regex_str = typestr[3:]
typepattern.append(re.compile(regex_str))
else:
typepattern.append(ttree_lex.EscCharStrToChar(typestr))
Expand Down
5 changes: 2 additions & 3 deletions moltemplate/charge_by_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,8 @@ def LookupChargePairs(chargebyatomid,
typepattern = []

for typestr in tokens[:2]:
if ((len(typestr) >= 2) and
(typestr[0] == '/') and (typestr[-1] == '/')):
regex_str = typestr[1:-1]
if ttree_lex.HasRE(typestr):
regex_str = typestr[3:]
typepattern.append(re.compile(regex_str))
else:
typepattern.append(ttree_lex.EscCharStrToChar(typestr))
Expand Down
7,014 changes: 3,507 additions & 3,507 deletions moltemplate/force_fields/compass_published.lt

Large diffs are not rendered by default.

821 changes: 458 additions & 363 deletions moltemplate/force_fields/convert_MSI_files_to_LT_files/msifrc2lt.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ def main():
use_hybrid = True
del argv[i:i + 1]

elif argv[i] == '-no-hybrid':
use_hybrid = False
del argv[i:i + 1]

elif (argv[i] == '-zeropad' or argv[i] == '-zero-pad'):
if (i + 1 >= len(argv)) or (argv[i+1][1:] == '-'):
raise Exception(
Expand Down
6 changes: 4 additions & 2 deletions moltemplate/genpoly_modify_lt.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

g_program_name = __file__.split('/')[-1]
g_version_str = '0.3.4'
g_date_str = '2020-6-12'
g_version_str = '0.3.5'
g_date_str = '2020-7-10'

g_usage_msg = """
Expand Down Expand Up @@ -185,6 +185,8 @@ def _DistributeRandom(widths, # width of each object (>0)
"""

Nm = len(widths)
if Nm == 0:
return []
N = len(occupancy)
locations = [-1 for im in range(0, Nm)]

Expand Down
6 changes: 3 additions & 3 deletions moltemplate/nbody_by_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def GenInteractions_lines(lines_atoms,
'Offending line:\n' +
'\"' + line + '\"\n'
'Expected either ' +
str(1 + g_bond_pattern.GetNumVerts()) + ' or ' +
str(1 + g_bond_pattern.GetNumVerts()) + ' or '+
str(1 + g_bond_pattern.GetNumVerts() +
g_bond_pattern.GetNumEdges())
+ ' colunms.'))
Expand All @@ -254,8 +254,8 @@ def GenInteractions_lines(lines_atoms,

for typestr in tokens[1:]:
if ((len(typestr) >= 2) and
(typestr[0] == '/') and (typestr[-1] == '/')):
regex_str = typestr[1:-1]
HasRE(typestr)):
regex_str = typestr[3:]
typepattern.append(re.compile(regex_str))
else:
typepattern.append(EscCharStrToChar(typestr))
Expand Down
23 changes: 9 additions & 14 deletions moltemplate/postprocess_coeffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ def main():
# If the second token is surrounded by '/' characters, interpret
# it as a regular expression.
token1_is_re = ((len(tokens) >= 2) and
(len(tokens[1]) >= 2) and
(tokens[1][0] == '/') and (tokens[1][-1] == '/'))
HasRE(tokens[1]))
# If the second token contains wildcard characters, interpret
# it as a wildcard (ie. glob) expression.
token1_is_wild = ((len(tokens) >= 2) and
Expand All @@ -173,7 +172,7 @@ def main():
(tokens[0].find('bond_coeff') == 0) and
(token1_is_re or token1_is_wild)):
if token1_is_re:
regex_str = typestr[1:-1]
regex_str = tokens[1][3:] #*#
left_paren = text_after = ''
typepattern = re.compile(regex_str)
else:
Expand All @@ -188,7 +187,7 @@ def main():
(tokens[0].find('angle_coeff') == 0) and
(token1_is_re or token1_is_wild)):
if token1_is_re:
regex_str = typestr[1:-1]
regex_str = tokens[1][3:] #*#
left_paren = text_after = ''
typepattern = re.compile(regex_str)
else:
Expand All @@ -203,7 +202,7 @@ def main():
(tokens[0].find('dihedral_coeff') == 0) and
(token1_is_re or token1_is_wild)):
if token1_is_re:
regex_str = typestr[1:-1]
regex_str = tokens[1][3:] #*#
left_paren = text_after = ''
typepattern = re.compile(regex_str)
else:
Expand All @@ -218,7 +217,7 @@ def main():
(tokens[0].find('improper_coeff') == 0) and
(token1_is_re or token1_is_wild)):
if token1_is_re:
regex_str = typestr[1:-1]
regex_str = tokens[1][3:] #*#
left_paren = text_after = ''
typepattern = re.compile(regex_str)
else:
Expand Down Expand Up @@ -286,12 +285,8 @@ def main():
################
# If surrounded by '/' characters, the token is meant to be
# interpreted as a regular expression.
token1_is_re = ((len(tokens[1]) >= 2) and
(tokens[1][0] == '/') and
(tokens[1][-1] == '/'))
token2_is_re = ((len(tokens[2]) >= 2) and
(tokens[2][0] == '/') and
(tokens[2][-1] == '/'))
token1_is_re = HasRE(tokens[1])
token2_is_re = HasRE(tokens[2])
# If the token contains wildcard characters, interpret
# it as a wildcard (ie. glob) expression.
token1_is_wild = (HasWildcard(tokens[1]) #contain '*' or '?'
Expand All @@ -303,7 +298,7 @@ def main():

if token1_is_re:
atom_types1 = atom_types
regex_str = tokens[1][1:-1]
regex_str = tokens[1][3:]
typepattern1 = re.compile(regex_str)
elif token1_is_wild:
atom_types1 = atom_types
Expand All @@ -312,7 +307,7 @@ def main():

if token2_is_re:
atom_types2 = atom_types
regex_str = tokens[2][1:-1]
regex_str = tokens[2][3:]
typepattern2 = re.compile(regex_str)
elif token2_is_wild:
atom_types2 = atom_types
Expand Down
4 changes: 2 additions & 2 deletions moltemplate/scripts/moltemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# Copyright (c) 2013

G_PROGRAM_NAME="moltemplate.sh"
G_VERSION="2.17.10"
G_DATE="2020-6-12"
G_VERSION="2.18.0"
G_DATE="2020-7-12"

echo "${G_PROGRAM_NAME} v${G_VERSION} ${G_DATE}" >&2
echo "" >&2
Expand Down
23 changes: 13 additions & 10 deletions moltemplate/ttree.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
# in words or tokens parsed by TtreeShlex. Otherwise it is identical to shlex.
try:
from .ttree_lex import TtreeShlex, SplitQuotedString, EscCharStrToChar, \
SafelyEncodeString, RemoveOuterQuotes, MaxLenStr, HasWildcard, \
SafelyEncodeString, RemoveOuterQuotes, MaxLenStr, HasWildcard, HasRE, \
InputError, ErrorLeader, OSrcLoc, TextBlock, VarRef, VarBinding, \
TemplateLexer
except (ImportError, SystemError, ValueError):
Expand Down Expand Up @@ -102,8 +102,8 @@
g_module_name = g_filename
if g_filename.rfind('.py') != -1:
g_module_name = g_filename[:g_filename.rfind('.py')]
g_date_str = '2019-11-19'
g_version_str = '0.86.3'
g_date_str = '2020-7-09'
g_version_str = '0.86.4'


class ClassReference(object):
Expand Down Expand Up @@ -4451,12 +4451,14 @@ def AutoAssignVals(cat_node,
# category counter without incrementing it.
var_binding.value = str(cat.counter.query())

elif HasWildcard(var_binding.full_name):
elif (HasWildcard(var_binding.full_name) or
HasRE(var_binding.full_name)):
# -- The wildcard hack ---
# Variables containing * or ? characters in their names
# are not allowed. These are not variables, but patterns
# to match with other variables. Represent them by the
# (full-path-expanded) string containing the * or ?.
# are not allowed. This is also true of regular
# expressions. These are not variables, but patterns to
# match with other variables. Represent them by the (full-
# path-expanded) string containing the * or ? or regex.
var_binding.value = var_binding.full_name

else:
Expand Down Expand Up @@ -4824,9 +4826,10 @@ def WriteVarBindingsFile(node):
or
(isinstance(node, StaticObj) and isinstance(nd, StaticObj))):

# Now omit variables whos names contain "*" or "?"
# (these are actually not variables, but wildcard patterns)
if not HasWildcard(var_binding.full_name):
# Now omit variables whos names contain "*" or "?" or regex
# (these are not variables, but pattern matching strings)
if not (HasWildcard(var_binding.full_name) or
HasRE(var_binding.full_name)):
if len(var_binding.refs) > 0:
usage_example = ' #' +\
ErrorLeader(var_binding.refs[0].srcloc.infile,
Expand Down
25 changes: 16 additions & 9 deletions moltemplate/ttree_lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"RemoveOuterQuotes",
"MaxLenStr",
"HasWildcard",
"HasRE",
"MatchesPattern",
#"IsRegex",
"InputError",
Expand Down Expand Up @@ -115,7 +116,7 @@ def __init__(self,
self.quotes = '\'"'
self.escape = '\\'
self.escapedquotes = '"'
self.operators = '='
self.operators = '=' #binary numeric operators like +-*/ might be added
self.state = ' '
self.pushback = deque()
self.lineno = 1
Expand Down Expand Up @@ -557,7 +558,6 @@ def SplitQuotedString(string,
if token != '':
# if this is not the first character in the token
include_endquote = True

token += c
reading_token = True
else:
Expand Down Expand Up @@ -671,12 +671,13 @@ def MaxLenStr(s1, s2):
return s1


# def IsRegex(pat):
# """
# Check to see if string (pat) is bracketed by slashes.
#
# """
# return (len(pat)>=2) and (pat[0]=='/') and (pat[-1] == '/')
def HasRE(pat):
"""
Returns true if a string (pat) begins with 're.'
"""
return pat.find('re.') == 0


def HasWildcard(pat):
"""
Expand Down Expand Up @@ -1552,6 +1553,7 @@ def __init__(self,
self.operators + \
self.escape + \
self.commenters

# Note:
# self.whitespace = ' \t\r\f\n'
# self.quotes = '\'"'
Expand All @@ -1572,6 +1574,7 @@ def ReadTemplate(self,
simplify_output=False,
terminators='}',
other_esc_chars='{',
var_terminators='{}(),', #(var_delim, spaces also included) CONTINUEHERE COMMA BREAKS compass_published.lt
keep_terminal_char=True):
"""
ReadTemplate() reads a block of text (between terminators)
Expand Down Expand Up @@ -1658,7 +1661,7 @@ def ReadTemplate(self,
commented_state = False
var_paren_depth = 0 # This is non-zero iff we are inside a
# bracketed variable's name for example: "${var}"
var_terminators = self.whitespace + self.newline + self.var_delim + '{}'
var_terminators += self.whitespace + self.newline + self.var_delim

tmpl_list = [] # List of alternating tuples of text_blocks and
# variable names (see format comment above)
Expand Down Expand Up @@ -1754,6 +1757,7 @@ def ReadTemplate(self,
# immediately follow the '$' character (as in "${var}")
elif var_paren_depth > 0:
var_paren_depth += 1
var_descr_plist.append(nextchar)

elif nextchar in self.var_close_paren:
#sys.stdout.write(' ReadTemplate() readmode found }.\n')
Expand All @@ -1770,6 +1774,9 @@ def ReadTemplate(self,
if var_paren_depth == 0:
var_suffix = nextchar
terminate_var = True
else:
var_descr_plist.append(nextchar)


elif nextchar in var_terminators:
#sys.stdout.write(' ReadTemplate() readmode found var_terminator \"'+nextchar+'\"\n')
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@

url='https://github.com/jewettaij/moltemplate',

download_url='https://github.com/jewettaij/moltemplate/archive/v2.17.10.zip',
download_url='https://github.com/jewettaij/moltemplate/archive/v2.18.0.zip',

version='2.17.10',
version='2.18.0',

keywords=['simulation', 'LAMMPS', 'molecule editor', 'molecule builder',
'ESPResSo'],
Expand Down

0 comments on commit acc86c6

Please sign in to comment.