Skip to content

Commit

Permalink
moltemplate.sh now checks for missing masses
Browse files Browse the repository at this point in the history
  • Loading branch information
jewettaij committed Oct 16, 2020
1 parent 658d4cb commit a0b841f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
66 changes: 59 additions & 7 deletions moltemplate/lttree_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
from ttree_lex import ExtractCatName

g_program_name = __file__.split('/')[-1] # = 'lttree_postprocess.py'
g_version_str = '0.5.1'
g_date_str = '2017-8-23'
g_version_str = '0.6.1'
g_date_str = '2020-10-15'

def main():
atom_style = 'full'
ttree_assignments_fname = 'ttree_assignments.txt'

defined_mols = set([])
defined_atoms = set([])
defined_masses = set([])
defined_bonds = set([])
defined_angles = set([])
defined_dihedrals = set([])
Expand Down Expand Up @@ -115,7 +116,7 @@ def main():
raise InputError('Error(' + g_program_name + '): The following line from\n'
' "\"' + data_atoms + '.template\" has bad format:\n\n'
+ line_orig + '\n'
' This my probably an internal error. (Feel free to contact the developer.)\n'
' This might be an internal error. (Feel free to contact the developer.)\n'
+ g_no_check_msg + '\n')
else:
defined_atoms.add(tokens[i_atomid])
Expand All @@ -142,7 +143,7 @@ def main():
raise InputError('Error(' + g_program_name + '): The following line from\n'
' "\"' + data_bonds + '.template\" has bad format:\n\n'
+ line_orig + '\n'
' This my probably an internal error. (Feel free to contact the developer.)\n'
' This might be an internal error. (Feel free to contact the developer.)\n'
+ g_no_check_msg + '\n')
else:
defined_bonds.add(tokens[0])
Expand All @@ -167,7 +168,7 @@ def main():
raise InputError('Error(' + g_program_name + '): The following line from\n'
' "\"' + data_angles + '.template\" has bad format:\n\n'
+ line_orig + '\n'
' This my probably an internal error. (Feel free to contact the developer.)\n'
' This might be an internal error. (Feel free to contact the developer.)\n'
+ g_no_check_msg + '\n')
else:
defined_angles.add(tokens[0])
Expand All @@ -192,7 +193,7 @@ def main():
raise InputError('Error(' + g_program_name + '): The following line from\n'
' "\"' + data_dihedrals + '.template\" has bad format:\n\n'
+ line_orig + '\n'
' This my probably an internal error. (Feel free to contact the developer.)\n'
' This might be an internal error. (Feel free to contact the developer.)\n'
+ g_no_check_msg + '\n')
else:
defined_dihedrals.add(tokens[0])
Expand All @@ -219,7 +220,7 @@ def main():
raise InputError('Error(' + g_program_name + '): The following line from\n'
' "\"' + data_impropers + '.template\" has bad format:\n\n'
+ line_orig + '\n'
' This my probably an internal error. (Feel free to contact the developer.)\n'
' This might be an internal error. (Feel free to contact the developer.)\n'
+ g_no_check_msg + '\n')
else:
defined_impropers.add(tokens[0])
Expand All @@ -228,6 +229,32 @@ def main():
# Defining impropers (stored in the data_impropers file) is optional
pass

# ------------ defined_bonds ------------
try:
f = open(data_masses + '.template', 'r')

for line_orig in f:
ic = line_orig.find('#')
if ic != -1:
line = line_orig[:ic]
else:
line = line_orig.rstrip('\n')

tokens = line.strip().split()
if len(tokens) == 0:
pass
elif len(tokens) != 2:
raise InputError('Error(' + g_program_name + '): The following line from\n'
' "\"' + data_masses + '.template\" has bad format:\n\n'
+ line_orig + '\n'
' This might be an internal error. (Feel free to contact the developer.)\n'
+ g_no_check_msg + '\n')
else:
defined_masses.add(tokens[0])
f.close()
except:
pass # Defining mass (stored in the data_masses file) is optional

# ---- Check ttree_assignments to make sure variables are defined ----

try:
Expand Down Expand Up @@ -267,6 +294,8 @@ def main():
# We only care about instance variables (which use the '$' prefix)
# Lines corresponding to static variables (which use the '@' prefix)
# are ignored during this pass.


i_prefix = tokens[0].find('$')
if i_prefix != -1:
descr_str = tokens[0][i_prefix + 1:]
Expand Down Expand Up @@ -333,6 +362,29 @@ def main():
# ' you specified the correct path which leads to it (using / and ..))\n\n'+
# g_no_check_msg)




# Now check for @ (type) counter variables (such as @atom):
i_prefix = tokens[0].find('@')
if i_prefix != -1:
descr_str = tokens[0][i_prefix + 1:]
cat_name = ExtractCatName(descr_str)

if ((cat_name == 'atom') and (len(defined_masses) > 0) and
(tokens[0] not in defined_masses)):
raise InputError('Error(' + g_program_name + '): ' + usage_location_str + '\n' +
' A reference to an @atom: of type:\n'
' ' + tokens[0] + ' (<--full type name)\n\n' +
' ...was found, however its mass was never defined.\n'
' (Make sure that there is a "write_once("Data Masses"){" section in one\n'
' of your LT files which defines the mass of this atom type. If the\n'
' atom type name contains "/", then make sure the path is correct.)\n\n' +
g_no_check_msg)




f.close()

sys.stderr.write(g_program_name + ': -- No errors detected. --\n')
Expand Down
2 changes: 1 addition & 1 deletion moltemplate/nbody_by_type_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def GenInteractions_int(G_system,
# If in the future, different interactions (type_patterns) have
# different symmetries, and canonical_order() varies from
# interaction to interaction, then DONT loop over type_pattern:
# for type_pattern, coefftype in typepattern_to_coefftypes)
# for type_pattern, coefftype in typepattern_to_coefftypes:
# abids = canonical_order(abids, type_pattern)
# Why: When checking for undefined interactions,
# we just want to make sure that SOME kind of interaction
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.18.8"
G_DATE="2020-10-12"
G_VERSION="2.18.9"
G_DATE="2020-10-15"

echo "${G_PROGRAM_NAME} v${G_VERSION} ${G_DATE}" >&2
echo "" >&2
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.18.8.zip',
download_url='https://github.com/jewettaij/moltemplate/archive/v2.18.9.zip',

version='2.18.8',
version='2.18.9',

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

0 comments on commit a0b841f

Please sign in to comment.