Skip to content

Commit

Permalink
Issue #86
Browse files Browse the repository at this point in the history
Fix for files provided in LAMMPS input files when they appear as part of
more complex input parameters. Bug and example code provided by Anders
Johansson which was worked into the original LAMMPS plugin.
  • Loading branch information
jimboid committed Apr 23, 2018
1 parent 22b9e12 commit e96bce2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
4 changes: 3 additions & 1 deletion AUTHORS.rst
Expand Up @@ -12,4 +12,6 @@ Prof Charles A. Laughton (University of Nottingham)
Contributors:
#############

Developers with accepted contributions should include their name below.
Developers with accepted contributions should include their name below.

Anders Johansson - The University of Oslo - Contributed code to the LAMMPS plugin.
37 changes: 23 additions & 14 deletions longbow/apps/lammps.py
Expand Up @@ -93,8 +93,15 @@ def file_parser(filename, path, files, substitutions=None):

files.append(addfile)

# Create a dict for any variable substitutions and define keywords.
keywords = ['read_data', 'read_restart', 'read_dump', 'include']
# List of LAMMPS output commands, these will be used to mask against
# keywords that shouldn't used to detect files for transfer.
output_commands = ["print", "dump", "log", "restart", "write_dump",
"write_restart", "pair_write", "write_coeff",
"ave/time", "ave/chunk", "bond_write",
"ave/histo/weight", "saed/vtk", "ave/histo",
"write_data"]

# Setup variables to be substituted.
variables = {} if not substitutions else substitutions

fil = _fileopen(path, addfile)
Expand All @@ -114,28 +121,30 @@ def file_parser(filename, path, files, substitutions=None):

else:

words = line[:len(line)].split()
words = line.split()

if len(words) > 0:

_internalsubstitutions(variables, words)

# If this line is reading in an input file.
if words[0].lower() in keywords:
# Does this line contain an output command?
if set(words).isdisjoint(output_commands):

newfile = words[-1]
for word in words:

# Do variable substitutons
newfile = _variablesubstitutions(newfile, variables)
if os.path.isfile(os.path.join(path, word)):

# Deduce the location of newfile.
newpath = path
newfile = word

# Check newfile.
newfile = _newfilechecks(addfile, newfile, path)
# Do variable substitutons
newfile = _variablesubstitutions(newfile,
variables)

# Recursive function.
file_parser(newfile, newpath, files, substitutions)
# Check newfile.
newfile = _newfilechecks(addfile, newfile, path)

# Recursive function.
file_parser(newfile, path, files, substitutions)

fil.close()

Expand Down

0 comments on commit e96bce2

Please sign in to comment.