diff --git a/tools/README b/tools/README index f0729b4e2b..15018d90cf 100644 --- a/tools/README +++ b/tools/README @@ -20,7 +20,8 @@ createatoms generate lattices of atoms within a geometry data2xmovie convert a data file to a snapshot that xmovie can viz eam_database one tool to generate EAM alloy potential files eam_generate 2nd tool to generate EAM alloy potential files -eff scripts for working with the EFF (electron force field) +eff scripts for working with the eFF (electron force field) +ipp input pre-processor Perl tool for creating input scripts lmp2arc convert LAMMPS output to Accelrys Insight format lmp2cfg convert LAMMPS output to CFG files for AtomEye viz lmp2traj convert LAMMPS output to contour, density profiles diff --git a/tools/createatoms/README.txt b/tools/createatoms/README similarity index 78% rename from tools/createatoms/README.txt rename to tools/createatoms/README index 0da2cc2f09..2648172487 100644 --- a/tools/createatoms/README.txt +++ b/tools/createatoms/README @@ -11,5 +11,8 @@ The tool is authored by Xiaowang Zhou (Sandia) who can be contacted at xzhou at sandia.gov for questions. Sample build of program: - gfortran createAtoms.f which produces a.out + +This tool can be used in conjunction with the ipp tool for creating +its input commands. See tools/ipp/README.txt for an example. + diff --git a/tools/ipp/README b/tools/ipp/README new file mode 100644 index 0000000000..d2cca9d9c6 --- /dev/null +++ b/tools/ipp/README @@ -0,0 +1,29 @@ +Ipp is a Perl script for facilitating the creation of a complicated +file (say, a lammps input file or tools/createatoms input file) using +a template file. + +ipp was created and is maintained by Reese Jones (Sandia), rjones at +sandia.gov. + +Example 1: + +If one has a template for a long lammps input file called +"template_lammps.input" where a few parameters need to be changed. One +can define these parameters in a short file called +"fill_parameters_lammps.input" and execute "ipp -p +fill_parameters_lammps.input template_lammps.input > +lammps.input". The file "lammps.input" file will be the final lammps +input file. + +Example 2: + +If one has a template for a long createAtoms input file called +"template_createAtoms.input" that creates double elpasolite +crystals. One wants to change the lattice constants and tilting angle +of the octahedrons. One can define these parameters in a short file +called "fill_parameters_createAtoms.input" and execute "ipp -p +fill_parameters_createAtoms.input template_createAtoms.input > +createAtoms.input". The "createAtoms.input" file will be the final +createAtoms input file. If one has an excetable for createAtoms called +"create", one can simply execute "create a=2) +# also order precedence: a=10 -p p.file b=12 +# nested if/else/endif blocks + +# Regular expressions for numeric fields +$e = "-?(?:\\d+\\.?\\d*|\\.\\d+)[eEdD](?:\\+|-)?\\d+"; # exponential notation +$f = "-?\\d+\\.\\d*|-?\\.\\d+"; # floating point +$i = "-?\\d+"; # integer +$ui = "\\d+"; # unsigned integer +$n = "$e|$f|$i"; # numeric field + +# Read command line arguments +while (scalar(@ARGV)) { + $arg = shift(@ARGV); + if ($arg =~ /-p/) { $parameter_file = shift(@ARGV); + parse_parameter_file($parameter_file); + } + elsif ($arg =~ /-o/) { $new_file = shift(@ARGV); } + elsif ($arg =~ /=/) { ($tag,$value) = split(/=/,$arg); + $values_p1{$tag} = $value; + } + else { $template_file = $arg; } +} + +# Check for correct command line arguments +if( ! defined($template_file) ) { + print STDERR "Usage: ipp <-p parameters_file> template_file <-o new_file>\n"; + print STDERR " note: \"value\" must be numeric (not a character string)\n"; + print STDERR " parameter file format : name = value\n"; + print STDERR " or : value name\n"; + print STDERR " template file example: modulus is {10.0*name +3.2}\n"; + exit(-1); +} + + +# output +$output_fh = \*STDOUT; +if( defined($new_file) ) { + open(NEW,">$new_file"); + $output_fh = \*NEW; +} +output($template_file,$output_fh); +if( defined($new_file) ) { close(NEW); } + +# debug : print key--> value +#foreach $key (sort keys %values_p1) { +# print "# $key ---> ",$values_p1{$key},"\n"; +#} + + +########################################################################### +# parse parameter file +########################################################################### +# Read parameters file, extract tags and corresponding values in either aprepro +# "{ tag = value }" format or standard "value tag" format, and store the +# tag/value pairs in %values_p1. +# NOTE : compound expressions are not currently allowed. + +sub parse_parameter_file { +my $pfile = shift(@_); +# (1) parse numerical values +open (PARAMETERS, "<$pfile") || die "Can't open parameters file: $pfile: $!"; +while () { # read each line of file, one at a time + # extract tag/value fields allowing multiple matches per line in either format + foreach $field (m/(?:$n)\s+\w+|\s*\w+\s*=\s*(?:$n)\s*/go) { + # extract tag/value pair from each field NOTE () are memory + if ( ( ($value, $tag) = ($field =~ m/^($n)\s+(\w+)$/o) ) || # Standard + ( ($tag, $value) = ($field =~ m/^\s*(\w+)\s*=\s*($n)\s*$/o))){# Apr + $value =~ s/[dD]/e/o; # convert any F77 dbl prec exponents + $values_p1{$tag} = $value; # store in hash + } + } +} +close (PARAMETERS); + +# (2) parse string values in dbl quotes +open (PARAMETERS, "<$pfile") || die "Can't open parameters file: $pfile: $!"; +while () { # read each line of file, one at a time + # extract tag/value fields allowing multiple matches per line in either format + #if ( m/=/ && m/\"/ ){ + if ( ($tag, $value) = ($_ =~ m/^\s*(\w+)\s*=\s*\"(.*)\"\s*$/o)){ + $values_p1{$tag} = $value; # store in hash + } +} +close (PARAMETERS); +} + +################################################################# +# Process template simulation file and create new simulation file +################################################################# +# Read each line of template_file, find the {} fields, process any +# assignments or expressions, and substitute the corresponding values. +# Print each line with substitution to new_file. The parameters +# file assignments (%values_p1 = precedence 1) take precedence over any +# duplicate template file assignments (%values_p2 = precedence 2) in +# order to allow the flexibility to define defaults in the template +# file which can then be overridden by a particular parameters file. + +sub output{ +my $tfile = shift (@_); +# Open the template simulation file for input. +open (TEMPLATE, "<$tfile") || die "Can't open template file $tfile: $!"; +# Open the new simulation file for output. +#$print_to_file = 0; +#if (defined($new_file)) { +#open (NEW, ">$new_file") || die "Can't create instance file $new_file: $!"; +#$print_to_file = 1; +#} +$print_to_file = 1; +$fh = shift (@_); + +$print = 1; # print line flag +while (