From b857237fef0f093c64b088d818e748c0c149de97 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Thu, 19 Nov 2015 15:34:38 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@14269 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- tools/moltemplate/src/bonds_by_type.py | 43 +++++++++++++------------- tools/moltemplate/src/ltemplify.py | 18 +++++++---- tools/moltemplate/src/lttree.py | 1 - tools/moltemplate/src/moltemplate.sh | 24 ++++++++++---- tools/moltemplate/src/ttree.py | 16 +++++++--- 5 files changed, 64 insertions(+), 38 deletions(-) diff --git a/tools/moltemplate/src/bonds_by_type.py b/tools/moltemplate/src/bonds_by_type.py index b19335c943..ae915e724c 100755 --- a/tools/moltemplate/src/bonds_by_type.py +++ b/tools/moltemplate/src/bonds_by_type.py @@ -185,28 +185,28 @@ def LookupBondTypes(bond_types, bondid = bond_ids[ie] (atomid1, atomid2) = bond_pairs[ie] + if atomid1 not in atomids2types: + raise ttree_lex.InputError('Error: atom \"'+atomid1+'\" not defined in \"Data Atoms\".\n' + ' This usually happens when the user mistypes one of the names of the\n' + ' $atoms in either a \"Data Atoms\" or \"Data Bond List\" section.\n' + ' To find out where the mistake occured, search the \n' + ' \"ttree_assignments.txt\" file for:\n' + ' \"'+atomid1+'\"\n') + + if atomid2 not in atomids2types: + raise ttree_lex.InputError('Error: atom \"'+atomid2+'\" not defined in \"Data Atoms\".\n' + ' This usually happens when the user mistypes one of the names of the\n' + ' $atoms in either a \"Data Atoms\" or \"Data Bond List\" section.\n' + ' To find out where the mistake occured, search the \n' + ' \"ttree_assignments.txt\" file for:\n' + ' \"'+atomid2+'\"\n') + + atomtype1 = atomids2types[atomid1] + atomtype2 = atomids2types[atomid2] + #for n in range(0, len(typepattern_to_coefftypes)): for typepattern, coefftype in typepattern_to_coefftypes: - if atomid1 not in atomids2types: - raise ttree_lex.InputError('Error: atom \"'+atomid1+'\" not defined in \"Data Atoms\".\n' - ' This usually happens when the user mistypes one of the names of the\n' - ' $atoms in either a \"Data Atoms\" or \"Data Bond List\" section.\n' - ' To find out where the mistake occured, search the \n' - ' \"ttree_assignments.txt\" file for:\n' - ' \"'+atomid1+'\"\n') - - if atomid2 not in atomids2types: - raise ttree_lex.InputError('Error: atom \"'+atomid2+'\" not defined in \"Data Atoms\".\n' - ' This usually happens when the user mistypes one of the names of the\n' - ' $atoms in either a \"Data Atoms\" or \"Data Bond List\" section.\n' - ' To find out where the mistake occured, search the \n' - ' \"ttree_assignments.txt\" file for:\n' - ' \"'+atomid2+'\"\n') - - atomtype1 = atomids2types[atomid1] - atomtype2 = atomids2types[atomid2] - # use string comparisons to check if atom types match the pattern if (ttree_lex.MatchesAll((atomtype1, atomtype2), typepattern) or ttree_lex.MatchesAll((atomtype2, atomtype1), typepattern)): @@ -216,6 +216,7 @@ def LookupBondTypes(bond_types, for ie in range(0, len(bond_ids)): if not bond_types[ie]: + (atomid1, atomid2) = bond_pairs[ie] atomtype1 = atomids2types[atomid1] atomtype2 = atomids2types[atomid2] raise ttree_lex.InputError('Error: No bond types defined for the bond between\n' @@ -228,8 +229,8 @@ def LookupBondTypes(bond_types, if __name__ == "__main__": g_program_name = __file__.split('/')[-1] # = 'nbody_by_type.py' - g_date_str = '2013-8-06' - g_version_str = '0.1' + g_date_str = '2015-11-09' + g_version_str = '0.11' ####### Main Code Below: ####### sys.stderr.write(g_program_name+' v'+g_version_str+' '+g_date_str+' ') diff --git a/tools/moltemplate/src/ltemplify.py b/tools/moltemplate/src/ltemplify.py index 83987956ea..2909456d2d 100755 --- a/tools/moltemplate/src/ltemplify.py +++ b/tools/moltemplate/src/ltemplify.py @@ -217,8 +217,8 @@ def BelongsToSel(i, sel): try: g_program_name = __file__.split('/')[-1] # = 'ltemplify.py' - g_version_str = '0.49' - g_date_str = '2015-8-11' + g_version_str = '0.51' + g_date_str = '2015-10-27' sys.stderr.write(g_program_name+' v'+g_version_str+' '+g_date_str+'\n') non_empty_output = False @@ -674,9 +674,12 @@ try: (boundary_ylo==None) or (boundary_yhi==None) or (boundary_zlo==None) or (boundary_zhi==None)): - raise InputError('Error: The DATA file lacks a boundary-box header. You must specify:\n' + raise InputError('Error: Either DATA file lacks a boundary-box header, or it is in the wrong\n' + ' place. At the beginning of the file, you need to specify the box size:\n' ' xlo xhi ylo yhi zlo zhi (and xy xz yz if triclinic)\n' - ' These numbers should appear before the \"Atoms\" section.\n' + ' These numbers should appear BEFORE the other sections in the data file\n' + ' (such as the \"Atoms\", \"Masses\", \"Bonds\", \"Pair Coeffs\" sections)\n' + '\n' ' Use this format (example):\n' ' -100.0 100.0 xhi xlo\n' ' 0.0 200.0 yhi ylo\n' @@ -788,8 +791,12 @@ try: tokens[i_molid] = '$mol:id'+tokens[i_molid] l_data_atoms.append((' '*indent)+(' '.join(tokens)+'\n')) needed_atomids.add(atomid) + needed_atomtypes.add(atomtype) - needed_molids.add(molid) + # Not all atom_styles have molids. + # Check for this before adding. + if molid != None: + needed_molids.add(molid) for atomtype in needed_atomtypes: assert(type(atomtype) is int) @@ -808,7 +815,6 @@ try: if ((max_needed_atomid == None) or (max_needed_atomid < atomid)): max_needed_atomid = atomid - for molid in needed_molids: assert(type(molid) is int) if ((min_needed_molid == None) or diff --git a/tools/moltemplate/src/lttree.py b/tools/moltemplate/src/lttree.py index 46a752ba29..c77d820434 100755 --- a/tools/moltemplate/src/lttree.py +++ b/tools/moltemplate/src/lttree.py @@ -731,7 +731,6 @@ if __name__ == "__main__": WriteFiles(files_content) sys.stderr.write(' done\n') - # Step 11: Now write the variable bindings/assignments table. # Now write the variable bindings/assignments table. sys.stderr.write('writing \"ttree_assignments.txt\" file...') open('ttree_assignments.txt', 'w').close() # <-- erase previous version. diff --git a/tools/moltemplate/src/moltemplate.sh b/tools/moltemplate/src/moltemplate.sh index bb459f003a..ed1506fde3 100755 --- a/tools/moltemplate/src/moltemplate.sh +++ b/tools/moltemplate/src/moltemplate.sh @@ -9,8 +9,8 @@ # All rights reserved. G_PROGRAM_NAME="moltemplate.sh" -G_VERSION="1.33" -G_DATE="2015-9-22" +G_VERSION="1.34" +G_DATE="2015-11-18" echo "${G_PROGRAM_NAME} v${G_VERSION} ${G_DATE}" >&2 echo "" >&2 @@ -27,7 +27,7 @@ else echo "Error: $G_PROGRAM_NAME requires python or python3" >&2 exit 1 fi - + # First, determine the directory in which this shell script is located. # (The python script files should also be located here as well.) @@ -218,7 +218,7 @@ $data_ellipsoids $data_lines $data_triangles $data_boundary -$data_bonds_by_type +$data_bonds_by_type* ${data_angles_by_type}* ${data_dihedrals_by_type}* ${data_impropers_by_type}* @@ -599,6 +599,16 @@ done +if [ -z "$ATOM_STYLE" ]; then + #echo '########################################################\n' >&2 + #echo '## WARNING: atom_style unspecified ##\n' >&2 + #echo '## Assuming atom_style = \"full\" ##\n' >&2 + #echo '########################################################\n' >&2 + ATOM_STYLE="full" +fi + + + OUT_FILE_INPUT_SCRIPT="${OUT_FILE_BASE}.in" OUT_FILE_INIT="${OUT_FILE_BASE}.in.init" OUT_FILE_SETTINGS="${OUT_FILE_BASE}.in.settings" @@ -736,13 +746,12 @@ if [ -s "${data_bond_list}.template" ]; then echo "Looking up bond types according to atom type" >&2 #-- Generate a file containing bondid bondtype atomid1 atomid2 -- if ! $PYTHON_COMMAND "${SCRIPT_DIR}/bonds_by_type.py" \ + -atom-style "$ATOM_STYLE" \ -atoms "${data_atoms}.template" \ -bond-list "${data_bond_list}.template" \ -bondsbytype "${data_bonds_by_type}.template" \ -prefix '$/bond:bytype' > gen_bonds.template.tmp; then exit 4 - #WARNING: DO NOT REPLACE THIS WITH - #if ! $NBODY_COMMAND ...<-this sometimes causes a shell quotes-related error fi # ---- cleanup: ---- @@ -836,6 +845,7 @@ for FILE in "$data_angles_by_type"*.template; do -subgraph "${SUBGRAPH_SCRIPT}" \ -section "Angles" \ -sectionbytype "Angles By Type" \ + -atom-style "$ATOM_STYLE" \ -atoms "${data_atoms}.template" \ -bonds "${data_bonds}.template" \ -nbodybytype "${FILE}" \ @@ -931,6 +941,7 @@ for FILE in "$data_dihedrals_by_type"*.template; do -subgraph "${SUBGRAPH_SCRIPT}" \ -section "Dihedrals" \ -sectionbytype "Dihedrals By Type" \ + -atom-style "$ATOM_STYLE" \ -atoms "${data_atoms}.template" \ -bonds "${data_bonds}.template" \ -nbodybytype "${FILE}" \ @@ -1025,6 +1036,7 @@ for FILE in "$data_impropers_by_type"*.template; do -subgraph "${SUBGRAPH_SCRIPT}" \ -section "Impropers" \ -sectionbytype "Impropers By Type" \ + -atom-style "$ATOM_STYLE" \ -atoms "${data_atoms}.template" \ -bonds "${data_bonds}.template" \ -nbodybytype "${FILE}" \ diff --git a/tools/moltemplate/src/ttree.py b/tools/moltemplate/src/ttree.py index 611a616840..cc4aa20115 100755 --- a/tools/moltemplate/src/ttree.py +++ b/tools/moltemplate/src/ttree.py @@ -94,8 +94,8 @@ g_filename = __file__.split('/')[-1] g_module_name = g_filename if g_filename.rfind('.py') != -1: g_module_name = g_filename[:g_filename.rfind('.py')] -g_date_str = '2015-8-17' -g_version_str = '0.80' +g_date_str = '2015-10-14' +g_version_str = '0.81' @@ -1676,7 +1676,15 @@ def LookupNode(obj_name, starting_node, dbg_loc): class SimpleCounter(object): __slots__=["n","nincr"] - def __init__(self, n0 = 1, nincr = 1): + # static data attributes: + default_n0 = 1 + default_nincr = 1 + + def __init__(self, n0 = None, nincr = None): + if n0 == None: + n0 = SimpleCounter.default_n0 + if nincr == None: + nincr = SimpleCounter.default_nincr self.n = n0 - nincr self.nincr = nincr @@ -1729,7 +1737,7 @@ class Category(object): self.bindings = bindings if counter is None: - self.counter = SimpleCounter(1,1) + self.counter = SimpleCounter() else: self.counter = counter