| 3 |
|
# program that builds water boxes |
| 4 |
|
|
| 5 |
|
# author = "Chris Fennell |
| 6 |
< |
# version = "$Revision: 1.4 $" |
| 7 |
< |
# date = "$Date: 2006-10-02 23:54:30 $" |
| 6 |
> |
# version = "$Revision: 1.5 $" |
| 7 |
> |
# date = "$Date: 2006-10-03 22:38:50 $" |
| 8 |
|
# copyright = "Copyright (c) 2006 by the University of Notre Dame" |
| 9 |
|
# license = "OOPSE" |
| 10 |
|
|
| 24 |
|
$alphaSlope = 0.025; |
| 25 |
|
$invalidWater = 0; |
| 26 |
|
$waterCase = -1; |
| 27 |
+ |
$nothingSelected = 1; |
| 28 |
|
|
| 29 |
|
# get our options |
| 30 |
|
getopts('hmrvd:l:n:o:w:'); |
| 31 |
|
|
| 32 |
< |
# if we don't have a filename, drop to -h |
| 33 |
< |
$opt_h = 'true' if $#ARGV != -1; |
| 32 |
> |
# just to test opt_h |
| 33 |
> |
$opt_h = "true" if $#ARGV >= 0; |
| 34 |
|
|
| 35 |
|
# our option output |
| 36 |
|
if ($opt_h){ |
| 50 |
|
print " -o char : output file name\n"; |
| 51 |
|
print " (default: freshWater.md)\n"; |
| 52 |
|
print " -w char : name of the water stunt double\n"; |
| 53 |
< |
print " (default: SPCE)\n"; |
| 53 |
> |
print " (default: SPCE)\n\n"; |
| 54 |
|
print "Example:\n"; |
| 55 |
|
die " waterBoxer -d 0.997 -n 864 -w SSD_RF -o ssdrfWater.md\n"; |
| 56 |
|
} |
| 58 |
|
# set some variables to be used in the code |
| 59 |
|
if (defined($opt_o)){ |
| 60 |
|
$fileName = $opt_o; |
| 61 |
+ |
$nothingSelected = 0; |
| 62 |
|
} else { |
| 63 |
|
$fileName = 'freshWater.md'; |
| 64 |
|
} |
| 65 |
|
if ($opt_m){ |
| 66 |
< |
die "$fileName cannot be \"water.md\"\n\tPlease choose a different name\n" if $fileName eq 'water.md'; |
| 66 |
> |
die "Error: $fileName cannot be \"water.md\"\n Please choose a different name\n" if $fileName eq 'water.md'; |
| 67 |
|
$waterFileHandle = 'WATERMD'; |
| 68 |
+ |
$nothingSelected = 0; |
| 69 |
|
} else { |
| 70 |
|
$waterFileHandle = 'OUTFILE'; |
| 71 |
|
} |
| 72 |
|
if ($opt_r){ |
| 73 |
|
$doRandomize = $opt_r; |
| 74 |
+ |
$nothingSelected = 0; |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
if (defined($opt_w)){ |
| 78 |
|
$waterName = $opt_w; |
| 79 |
+ |
$nothingSelected = 0; |
| 80 |
|
} else { |
| 81 |
|
$waterName = 'SPCE'; |
| 82 |
|
} |
| 84 |
|
if ($invalidWater == 1){ |
| 85 |
|
print "Warning: \'$waterName\' is not a recognized water model name.\n"; |
| 86 |
|
print " Use the \'-m\' option to generate a \'water.md\' with the\n"; |
| 87 |
< |
print " recognized water model geometries.\n"; |
| 87 |
> |
print " recognized water model geometries.\n\n"; |
| 88 |
|
} |
| 89 |
|
if (defined($opt_d)){ |
| 90 |
+ |
$nothingSelected = 0; |
| 91 |
|
if ($opt_d =~ /^[0-9]/) { |
| 92 |
|
$density = $opt_d; |
| 93 |
|
} else { |
| 94 |
< |
die "\t-d value ($opt_d) is not a valid number\n\tPlease choose a positive real # value\n"; |
| 94 |
> |
die "Error: the value for '-d' ($opt_d) is not a valid number\n Please choose a positive real # value\n"; |
| 95 |
|
} |
| 96 |
|
} |
| 97 |
|
if (defined($opt_l)){ |
| 98 |
+ |
$nothingSelected = 0; |
| 99 |
|
if ($opt_l =~ /^[0-9]/) { |
| 100 |
|
$lattice = $opt_l; |
| 101 |
|
if ($lattice != 0 && $lattice != 1){ |
| 102 |
< |
die "\t-l value ($opt_l) is not a valid number\n\tPlease choose 0 or 1\n"; |
| 102 |
> |
die "Error: the '-l' value ($opt_l) is not a valid number\n Please choose 0 or 1\n"; |
| 103 |
|
} |
| 104 |
|
} else { |
| 105 |
< |
die "\t-l value ($opt_l) is not a valid number\n\tPlease choose 0 or 1\n"; |
| 105 |
> |
die "Error: the '-l' value ($opt_l) is not a valid number\n Please choose 0 or 1\n"; |
| 106 |
|
} |
| 107 |
|
} |
| 108 |
|
if (defined($opt_n)){ |
| 109 |
+ |
$nothingSelected = 0; |
| 110 |
|
if ($opt_n =~ /^[0-9]/) { |
| 111 |
|
$nMol = $opt_n; |
| 112 |
|
} else { |
| 113 |
< |
die "\t-n value ($opt_n) is not a valid number\n\tPlease choose a non-negative integer\n"; |
| 113 |
> |
die "Error: the '-n' value ($opt_n) is not a valid number\n Please choose a non-negative integer\n"; |
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
# open the file writer |
| 118 |
< |
open(OUTFILE, ">./$fileName") || die "\tError: can't open file $fileName\n"; |
| 118 |
> |
open(OUTFILE, ">./$fileName") || die "Error: can't open file $fileName\n"; |
| 119 |
|
|
| 120 |
|
# check to set magic lattice numbers |
| 121 |
|
if ($lattice == 0){ |
| 128 |
|
if ($remainder > $tolerance){ |
| 129 |
|
$crystalNum = $crystalNum + 1; |
| 130 |
|
$newMol = 4 * $crystalNum**3; |
| 131 |
< |
print "WARNING: The number chosen ($nMol) failed to build a clean\n"; |
| 132 |
< |
print "fcc lattice. The number of molecules has been increased to\n"; |
| 125 |
< |
print "the next magic number ($newMol).\n"; |
| 131 |
> |
print "Warning: The number chosen ($nMol) failed to build a clean fcc lattice.\n"; |
| 132 |
> |
print " The number of molecules has been increased to the next magic number ($newMol).\n\n"; |
| 133 |
|
$nMol = $newMol; |
| 134 |
|
} |
| 135 |
|
} elsif ($lattice == 1){ |
| 142 |
|
if ($remainder > $tolerance){ |
| 143 |
|
$crystalNum = $crystalNum + 1; |
| 144 |
|
$newMol = $crystalNum**3; |
| 145 |
< |
print "WARNING: The number chosen ($nMol) failed to build a clean\n"; |
| 146 |
< |
print "simple cubic lattice. The number of molecules has been\n"; |
| 140 |
< |
print "increased to the next magic number ($newMol).\n"; |
| 145 |
> |
print "Warning: The number chosen ($nMol) failed to build a clean simple cubic lattice.\n"; |
| 146 |
> |
print " The number of molecules has been increased to the next magic number ($newMol).\n\n"; |
| 147 |
|
$nMol = $newMol; |
| 148 |
|
} |
| 149 |
|
} |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
writeOutFile(); |
| 211 |
< |
print "Water box \"$fileName\" generated.\n"; |
| 211 |
> |
print "The water box \"$fileName\" was generated.\n"; |
| 212 |
|
|
| 213 |
|
if ($opt_m){ |
| 214 |
|
printWaterMD(); |
| 215 |
< |
print "File \"water.md\" generated for inclusion in \"$fileName\"\n"; |
| 215 |
> |
print "The file \"water.md\" was generated for inclusion in \"$fileName\"\n"; |
| 216 |
|
} |
| 217 |
|
|
| 218 |
+ |
if ($nothingSelected == 1) { |
| 219 |
+ |
print "(For help, use the \'-h\' option.)\n"; |
| 220 |
+ |
} |
| 221 |
+ |
|
| 222 |
+ |
|
| 223 |
|
# this marks the end of the main program, below is subroutines |
| 224 |
|
|
| 225 |
|
sub acos { |
| 329 |
|
} |
| 330 |
|
|
| 331 |
|
sub printWaterMD { |
| 332 |
< |
open(WATERMD, ">./water.md") || die "\tError: can't open file water.md\n"; |
| 332 |
> |
open(WATERMD, ">./water.md") || die "Error: can't open file water.md\n"; |
| 333 |
|
$waterFileHandle = 'WATERMD'; |
| 334 |
|
|
| 335 |
|
print WATERMD "#ifndef _WATER_MD_\n#define _WATER_MD_\n"; |