| 1 | #!/usr/bin/env perl | 
| 2 |  | 
| 3 | # program that builds water boxes | 
| 4 |  | 
| 5 | # author    = "Chris Fennell | 
| 6 | # version   = "$Revision: 1.5 $" | 
| 7 | # date      = "$Date: 2008-01-23 21:22:18 $" | 
| 8 | # copyright = "Copyright (c) 2006 by the University of Notre Dame" | 
| 9 | # license   = "OOPSE" | 
| 10 |  | 
| 11 | use Getopt::Std; | 
| 12 |  | 
| 13 | $tolerance = 1.0E-8; | 
| 14 | $mass = 2.99151E-23; # mass of H2O in grams | 
| 15 | $cm3ToAng3 = 1E24;   # convert cm^3 to angstroms^3 | 
| 16 | $densityConvert = $mass*$cm3ToAng3; | 
| 17 | $lattice = 0; | 
| 18 | $nMol = 500; | 
| 19 | $density = 1.0; | 
| 20 | $doRandomize = 0; | 
| 21 | $cutoff = 12; | 
| 22 | $alpha = 0.2125; | 
| 23 | $alphaInt = 0.5125; | 
| 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:x:y:z:'); | 
| 31 |  | 
| 32 | # just to test opt_h | 
| 33 | $opt_h = "true" if $#ARGV >= 0; | 
| 34 |  | 
| 35 | # our option output | 
| 36 | if ($opt_h){ | 
| 37 | print "waterBoxer: builds water boxes\n\n"; | 
| 38 | print "usage: waterBoxer [-hmrv] [-d density] [-l lattice] [-n # waters]\n"; | 
| 39 | print "\t[-o file name] [-w water name] \n\n"; | 
| 40 | print "  -h : show this message\n"; | 
| 41 | print "  -m : print out a water.md file (file with all water models)\n"; | 
| 42 | print "  -r : randomize orientations\n"; | 
| 43 | print "  -v : verbose output\n\n"; | 
| 44 | print "  -d real    : density in g/cm^3\n"; | 
| 45 | print "                 (default: 1)\n"; | 
| 46 | print "  -l integer : 0 - face centered cubic, 1 - simple cubic\n"; | 
| 47 | print "                 (default: 0)\n"; | 
| 48 | print "  -n integer : # of water molecules\n"; | 
| 49 | print "                 (default: 500)\n"; | 
| 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"; | 
| 54 | print "  -x real    : dimension of the box along the x direction\n"; | 
| 55 | print "  -y real    : dimension of the box along the y direction\n"; | 
| 56 | print "  -z real    : dimension of the box along the z direction\n\n"; | 
| 57 | print "Note: you can only use values of x, y, or z that are smaller\n"; | 
| 58 | print "      than the derived box length for a given density and\n"; | 
| 59 | print "      number of molecules.\n\n"; | 
| 60 | print "Example:\n"; | 
| 61 | die   "   waterBoxer -d 0.997 -n 864 -w SSD_RF -o ssdrfWater.md\n"; | 
| 62 | } | 
| 63 |  | 
| 64 | # set some variables to be used in the code | 
| 65 | if (defined($opt_o)){ | 
| 66 | $fileName = $opt_o; | 
| 67 | $nothingSelected = 0; | 
| 68 | } else { | 
| 69 | $fileName = 'freshWater.md'; | 
| 70 | } | 
| 71 | if ($opt_m){ | 
| 72 | die "Error: $fileName cannot be \"water.md\"\n       Please choose a different name\n" if $fileName eq 'water.md'; | 
| 73 | $waterFileHandle = 'WATERMD'; | 
| 74 | $nothingSelected = 0; | 
| 75 | } else { | 
| 76 | $waterFileHandle = 'OUTFILE'; | 
| 77 | } | 
| 78 | if ($opt_r){ | 
| 79 | $doRandomize = $opt_r; | 
| 80 | $nothingSelected = 0; | 
| 81 | } | 
| 82 |  | 
| 83 | if (defined($opt_d)){ | 
| 84 | $nothingSelected = 0; | 
| 85 | if ($opt_d =~ /^[0-9]/) { | 
| 86 | $density = $opt_d; | 
| 87 | } else { | 
| 88 | die "Error: the value for '-d' ($opt_d) is not a valid number\n       Please choose a positive real # value\n"; | 
| 89 | } | 
| 90 | } | 
| 91 | if (defined($opt_w)){ | 
| 92 | $waterName = $opt_w; | 
| 93 | $nothingSelected = 0; | 
| 94 | } else { | 
| 95 | $waterName = 'SPCE'; | 
| 96 | } | 
| 97 | validateWater(); | 
| 98 | if ($invalidWater == 1){ | 
| 99 | print "Warning: \'$waterName\' is not a recognized water model name.\n"; | 
| 100 | print "         Use the \'-m\' option to generate a \'water.md\' with the\n"; | 
| 101 | print "         recognized water model geometries.\n\n"; | 
| 102 | } | 
| 103 | if ($waterName eq 'DPD') { | 
| 104 | # DPD waters are stand-ins for 4 water molecules | 
| 105 | $density = $density * 0.25; | 
| 106 | } | 
| 107 | if ($waterName eq 'CG2') { | 
| 108 | # CG2 waters are stand-ins for 2 water molecules | 
| 109 | $density = $density * 0.5; | 
| 110 | } | 
| 111 |  | 
| 112 | if (defined($opt_l)){ | 
| 113 | $nothingSelected = 0; | 
| 114 | if ($opt_l =~ /^[0-9]/) { | 
| 115 | $lattice = $opt_l; | 
| 116 | if ($lattice != 0 && $lattice != 1){ | 
| 117 | die "Error: the '-l' value ($opt_l) is not a valid number\n       Please choose 0 or 1\n"; | 
| 118 | } | 
| 119 | } else { | 
| 120 | die "Error: the '-l' value ($opt_l) is not a valid number\n       Please choose 0 or 1\n"; | 
| 121 | } | 
| 122 | } | 
| 123 | if (defined($opt_n)){ | 
| 124 | $nothingSelected = 0; | 
| 125 | if ($opt_n =~ /^[0-9]/) { | 
| 126 | $nMol = $opt_n; | 
| 127 | } else { | 
| 128 | die "Error: the '-n' value ($opt_n) is not a valid number\n       Please choose a non-negative integer\n"; | 
| 129 | } | 
| 130 | } | 
| 131 | if (defined($opt_x)){ | 
| 132 | $nothingSelected = 0; | 
| 133 | if ($opt_x =~ /^[0-9]/) { | 
| 134 | $boxx = $opt_x; | 
| 135 | } else { | 
| 136 | die "Error: the value for '-x' ($opt_x) is not a valid number\n       Please choose a positive real # value\n"; | 
| 137 | } | 
| 138 | } | 
| 139 | if (defined($opt_y)){ | 
| 140 | $nothingSelected = 0; | 
| 141 | if ($opt_y =~ /^[0-9]/) { | 
| 142 | $boxy = $opt_y; | 
| 143 | } else { | 
| 144 | die "Error: the value for '-y' ($opt_y) is not a valid number\n       Please choose a positive real # value\n"; | 
| 145 | } | 
| 146 | } | 
| 147 | if (defined($opt_z)){ | 
| 148 | $nothingSelected = 0; | 
| 149 | if ($opt_z =~ /^[0-9]/) { | 
| 150 | $boxz = $opt_z; | 
| 151 | } else { | 
| 152 | die "Error: the value for '-z' ($opt_z) is not a valid number\n       Please choose a positive real # value\n"; | 
| 153 | } | 
| 154 | } | 
| 155 |  | 
| 156 |  | 
| 157 | # open the file writer | 
| 158 | open(OUTFILE, ">./$fileName") || die "Error: can't open file $fileName\n"; | 
| 159 |  | 
| 160 | # check to set magic lattice numbers | 
| 161 | if ($lattice == 0){ | 
| 162 | $crystalNumReal = ($nMol/4.0)**(1.0/3.0); | 
| 163 | $crystalNum = int($crystalNumReal + $tolerance); | 
| 164 | $remainder = $crystalNumReal - $crystalNum; | 
| 165 |  | 
| 166 | # if crystalNumReal wasn't an integer, we bump the crystal to the next | 
| 167 | # magic number | 
| 168 | if ($remainder > $tolerance){ | 
| 169 | $crystalNum = $crystalNum + 1; | 
| 170 | $newMol = 4 * $crystalNum**3; | 
| 171 | print "Warning: The number chosen ($nMol) failed to build a clean fcc lattice.\n"; | 
| 172 | print "         The number of molecules has been increased to the next magic number ($newMol).\n\n"; | 
| 173 | $nMol = $newMol; | 
| 174 | } | 
| 175 | } elsif ($lattice == 1){ | 
| 176 | $crystalNumReal = ($nMol/1.0)**(1.0/3.0); | 
| 177 | $crystalNum = int($crystalNumReal + $tolerance); | 
| 178 | $remainder = $crystalNumReal - $crystalNum; | 
| 179 |  | 
| 180 | # again, if crystalNumReal wasn't an integer, we bump the crystal to the next | 
| 181 | # magic number | 
| 182 | if ($remainder > $tolerance){ | 
| 183 | $crystalNum = $crystalNum + 1; | 
| 184 | $newMol = $crystalNum**3; | 
| 185 | print "Warning: The number chosen ($nMol) failed to build a clean simple cubic lattice.\n"; | 
| 186 | print "         The number of molecules has been increased to the next magic number ($newMol).\n\n"; | 
| 187 | $nMol = $newMol; | 
| 188 | } | 
| 189 | } | 
| 190 |  | 
| 191 | # now we can start building the crystals | 
| 192 | $boxLength = ($nMol*$densityConvert/$density)**(1.0/3.0); | 
| 193 | $cellLength = $boxLength / $crystalNum; | 
| 194 |  | 
| 195 | if ($boxx != 0) { | 
| 196 | if ($boxLength < $boxx) { | 
| 197 | print "Computed box length is smaller than requested x axis.  Use more\n"; | 
| 198 | die "molecules."; | 
| 199 | } | 
| 200 | } else { | 
| 201 | $boxx = $boxLength; | 
| 202 | } | 
| 203 | if ($boxy != 0) { | 
| 204 | if ($boxLength < $boxy) { | 
| 205 | print "Computed box length is smaller than requested y axis.  Use more\n"; | 
| 206 | die "molecules."; | 
| 207 | } | 
| 208 | } else { | 
| 209 | $boxy = $boxLength; | 
| 210 | } | 
| 211 | if ($boxz != 0) { | 
| 212 | if ($boxLength < $boxz) { | 
| 213 | print "Computed box length is smaller than requested z axis.  Use more\n"; | 
| 214 | die "molecules."; | 
| 215 | } | 
| 216 | } else { | 
| 217 | $boxz = $boxLength; | 
| 218 | } | 
| 219 |  | 
| 220 | $nx = int($boxx / $cellLength); | 
| 221 | $ny = int($boxy / $cellLength); | 
| 222 | $nz = int($boxz / $cellLength); | 
| 223 |  | 
| 224 | if ($lattice == 0) { | 
| 225 | $nMol = 4 * $nx * $ny * $nz; | 
| 226 | } else { | 
| 227 | $nMol = $nx * $ny * $nz; | 
| 228 | } | 
| 229 |  | 
| 230 | $newDensity = $nMol * $densityConvert / ($boxx*$boxy*$boxz); | 
| 231 |  | 
| 232 | if (abs($newDensity-$density) > $tolerance) { | 
| 233 | print "Resetting density to $newDensity to make chosen box sides work out\n"; | 
| 234 | } | 
| 235 | $cellLengthX = $boxx/$nx; | 
| 236 | $cellLengthY = $boxy/$ny; | 
| 237 | $cellLengthZ = $boxz/$nz; | 
| 238 |  | 
| 239 | $cell2X = $cellLengthX*0.5; | 
| 240 | $cell2Y = $cellLengthY*0.5; | 
| 241 | $cell2Z = $cellLengthZ*0.5; | 
| 242 |  | 
| 243 | if ($lattice == 0) { | 
| 244 | # build the unit cell | 
| 245 | # molecule 0 | 
| 246 | $xCorr[0] = 0.0; | 
| 247 | $yCorr[0] = 0.0; | 
| 248 | $zCorr[0] = 0.0; | 
| 249 | # molecule 1 | 
| 250 | $xCorr[1] = 0.0; | 
| 251 | $yCorr[1] = $cell2Y; | 
| 252 | $zCorr[1] = $cell2Z; | 
| 253 | # molecule 2 | 
| 254 | $xCorr[2] = $cell2X; | 
| 255 | $yCorr[2] = $cell2Y; | 
| 256 | $zCorr[2] = 0.0; | 
| 257 | # molecule 3 | 
| 258 | $xCorr[3] = $cell2X; | 
| 259 | $yCorr[3] = 0.0; | 
| 260 | $zCorr[3] = $cell2Z; | 
| 261 | # assemble the lattice | 
| 262 | $counter = 0; | 
| 263 | for ($z = 0; $z < $nz; $z++) { | 
| 264 | for ($y = 0; $y < $ny; $y++) { | 
| 265 | for ($x = 0; $x < $nx; $x++) { | 
| 266 | for ($uc = 0; $uc < 4; $uc++) { | 
| 267 | $xCorr[$uc+$counter] = $xCorr[$uc] + $cellLengthX*$x; | 
| 268 | $yCorr[$uc+$counter] = $yCorr[$uc] + $cellLengthY*$y; | 
| 269 | $zCorr[$uc+$counter] = $zCorr[$uc] + $cellLengthZ*$z; | 
| 270 | } | 
| 271 | $counter = $counter + 4; | 
| 272 | } | 
| 273 | } | 
| 274 | } | 
| 275 |  | 
| 276 | } elsif ($lattice == 1) { | 
| 277 | # build the unit cell | 
| 278 | # molecule 0 | 
| 279 | $xCorr[0] = $cell2X; | 
| 280 | $yCorr[0] = $cell2Y; | 
| 281 | $zCorr[0] = $cell2Z; | 
| 282 | #assemble the lattice | 
| 283 | $counter = 0; | 
| 284 | for ($z = 0; $z < $nz; $z++) { | 
| 285 | for ($y = 0; $y < $ny; $y++) { | 
| 286 | for ($x = 0; $x < $nx; $x++) { | 
| 287 | $xCorr[$counter] = $xCorr[0] + $cellLengthX*$x; | 
| 288 | $yCorr[$counter] = $yCorr[0] + $cellLengthY*$y; | 
| 289 | $zCorr[$counter] = $zCorr[0] + $cellLengthZ*$z; | 
| 290 |  | 
| 291 | $counter++; | 
| 292 | } | 
| 293 | } | 
| 294 | } | 
| 295 | } | 
| 296 |  | 
| 297 | writeOutFile(); | 
| 298 | print "The water box \"$fileName\" was generated.\n"; | 
| 299 |  | 
| 300 | if ($opt_m){ | 
| 301 | printWaterMD(); | 
| 302 | print "The file \"water.md\" was generated for inclusion in \"$fileName\"\n"; | 
| 303 | } | 
| 304 |  | 
| 305 | if ($nothingSelected == 1) { | 
| 306 | print "(For help, use the \'-h\' option.)\n"; | 
| 307 | } | 
| 308 |  | 
| 309 |  | 
| 310 | # this marks the end of the main program, below is subroutines | 
| 311 |  | 
| 312 | sub acos { | 
| 313 | my ($rad) = @_; | 
| 314 | my $ret = atan2(sqrt(1 - $rad*$rad), $rad); | 
| 315 | return $ret; | 
| 316 | } | 
| 317 |  | 
| 318 | sub writeOutFile { | 
| 319 | # write out the header | 
| 320 | print OUTFILE "<OOPSE version=4>\n"; | 
| 321 | findCutoff(); | 
| 322 | findAlpha(); | 
| 323 | printMetaData(); | 
| 324 | printFrameData(); | 
| 325 | print OUTFILE "    <StuntDoubles>\n"; | 
| 326 |  | 
| 327 | # shift the box center to the origin and write out the coordinates | 
| 328 | for ($i = 0; $i < $nMol; $i++) { | 
| 329 | $xCorr[$i] -= 0.5*$boxx; | 
| 330 | $yCorr[$i] -= 0.5*$boxy; | 
| 331 | $zCorr[$i] -= 0.5*$boxz; | 
| 332 |  | 
| 333 | $q0 = 1.0; | 
| 334 | $q1 = 0.0; | 
| 335 | $q2 = 0.0; | 
| 336 | $q3 = 0.0; | 
| 337 |  | 
| 338 | if ($doRandomize == 1){ | 
| 339 | $cosTheta = 2.0*rand() - 1.0; | 
| 340 | $theta = acos($cosTheta); | 
| 341 | $phi = 2.0*3.14159265359*rand(); | 
| 342 | $psi = 2.0*3.14159265359*rand(); | 
| 343 |  | 
| 344 | $q0 = cos(0.5*$theta)*cos(0.5*($phi + $psi)); | 
| 345 | $q1 = sin(0.5*$theta)*cos(0.5*($phi - $psi)); | 
| 346 | $q2 = sin(0.5*$theta)*sin(0.5*($phi - $psi)); | 
| 347 | $q3 = cos(0.5*$theta)*sin(0.5*($phi + $psi)); | 
| 348 | } | 
| 349 |  | 
| 350 | print OUTFILE "$i\tpq\t$xCorr[$i] $yCorr[$i] $zCorr[$i] "; | 
| 351 | print OUTFILE "$q0 $q1 $q2 $q3\n"; | 
| 352 | } | 
| 353 |  | 
| 354 | print OUTFILE "    </StuntDoubles>\n  </Snapshot>\n</OOPSE>\n"; | 
| 355 | } | 
| 356 |  | 
| 357 | sub printMetaData { | 
| 358 | print OUTFILE "  <MetaData>\n"; | 
| 359 |  | 
| 360 | # print the water model or includes | 
| 361 | if ($opt_m){ | 
| 362 | print OUTFILE "#include \"water.md\""; | 
| 363 | } else { | 
| 364 | printWaterModel(); | 
| 365 | } | 
| 366 | printFakeWater() if $invalidWater == 1; | 
| 367 |  | 
| 368 | # now back to the metaData output | 
| 369 | print OUTFILE "\n\ncomponent{ | 
| 370 | type = \"$waterName\"; | 
| 371 | nMol = $nMol; | 
| 372 | } | 
| 373 |  | 
| 374 | ensemble = NVE; | 
| 375 | forceField = \"DUFF\"; | 
| 376 | electrostaticSummationMethod = \"shifted_force\"; | 
| 377 | electrostaticScreeningMethod = \"damped\"; | 
| 378 | cutoffRadius = $cutoff; | 
| 379 |  | 
| 380 | targetTemp = 300; | 
| 381 | targetPressure = 1.0; | 
| 382 |  | 
| 383 | tauThermostat = 1e3; | 
| 384 | tauBarostat = 1e4; | 
| 385 |  | 
| 386 | dt = 2.0; | 
| 387 | runTime = 1e3; | 
| 388 |  | 
| 389 | tempSet = \"true\"; | 
| 390 | thermalTime = 10; | 
| 391 | sampleTime = 100; | 
| 392 | statusTime = 2; | 
| 393 | </MetaData>\n"; | 
| 394 | } | 
| 395 |  | 
| 396 | sub findCutoff { | 
| 397 | if ($boxy < $boxx) { | 
| 398 | $bm = $boxy; | 
| 399 | } else { | 
| 400 | $bm = $boxx; | 
| 401 | } | 
| 402 | if ($boxz < $bm) { | 
| 403 | $bm = $boxz; | 
| 404 | } | 
| 405 | $boxLength2 = 0.5*$bm; | 
| 406 | if ($boxLength2 > $cutoff){ | 
| 407 | # the default is good | 
| 408 | } else { | 
| 409 | $cutoff = int($boxLength2); | 
| 410 | } | 
| 411 | } | 
| 412 |  | 
| 413 | sub findAlpha { | 
| 414 | $alpha = $alphaInt - $cutoff*$alphaSlope; | 
| 415 | } | 
| 416 |  | 
| 417 | sub printFrameData { | 
| 418 | print OUTFILE | 
| 419 | "  <Snapshot> | 
| 420 | <FrameData> | 
| 421 | Time: 0 | 
| 422 | Hmat: {{ $boxx, 0, 0 }, { 0, $boxy, 0 }, { 0, 0, $boxz }} | 
| 423 | </FrameData>\n"; | 
| 424 | } | 
| 425 |  | 
| 426 | sub printWaterMD { | 
| 427 | open(WATERMD, ">./water.md") || die "Error: can't open file water.md\n"; | 
| 428 | $waterFileHandle = 'WATERMD'; | 
| 429 |  | 
| 430 | print WATERMD "#ifndef _WATER_MD_\n#define _WATER_MD_\n"; | 
| 431 | printCl(); | 
| 432 | printNa(); | 
| 433 | printSSD_E(); | 
| 434 | printSSD_RF(); | 
| 435 | printSSD(); | 
| 436 | printSSD1(); | 
| 437 | printTRED(); | 
| 438 | printTIP3P(); | 
| 439 | printTIP4P(); | 
| 440 | printTIP4PEw(); | 
| 441 | printTIP5P(); | 
| 442 | printTIP5PE(); | 
| 443 | printSPCE(); | 
| 444 | printSPC(); | 
| 445 | printDPD(); | 
| 446 | printCG2(); | 
| 447 | print WATERMD "\n\n#endif"; | 
| 448 | } | 
| 449 |  | 
| 450 | sub printCl { | 
| 451 | print $waterFileHandle "\n\nmolecule{ | 
| 452 | name = \"Cl-\"; | 
| 453 |  | 
| 454 | atom[0]{ | 
| 455 | type = \"Cl-\"; | 
| 456 | position(0.0, 0.0, 0.0); | 
| 457 | } | 
| 458 | }" | 
| 459 | } | 
| 460 |  | 
| 461 | sub printNa { | 
| 462 | print $waterFileHandle "\n\nmolecule{ | 
| 463 | name = \"Na+\"; | 
| 464 |  | 
| 465 | atom[0]{ | 
| 466 | type = \"Na+\"; | 
| 467 | position(0.0, 0.0, 0.0); | 
| 468 | } | 
| 469 | }" | 
| 470 | } | 
| 471 |  | 
| 472 | sub printSSD_E { | 
| 473 | print $waterFileHandle "\n\nmolecule{ | 
| 474 | name = \"SSD_E\"; | 
| 475 |  | 
| 476 | atom[0]{ | 
| 477 | type = \"SSD_E\"; | 
| 478 | position( 0.0, 0.0, 0.0 ); | 
| 479 | orientation( 0.0, 0.0, 0.0 ); | 
| 480 | } | 
| 481 | }" | 
| 482 | } | 
| 483 |  | 
| 484 | sub printSSD_RF { | 
| 485 | print $waterFileHandle "\n\nmolecule{ | 
| 486 | name = \"SSD_RF\"; | 
| 487 |  | 
| 488 | atom[0]{ | 
| 489 | type = \"SSD_RF\"; | 
| 490 | position( 0.0, 0.0, 0.0 ); | 
| 491 | orientation( 0.0, 0.0, 0.0 ); | 
| 492 | } | 
| 493 | }" | 
| 494 | } | 
| 495 |  | 
| 496 | sub printSSD { | 
| 497 | print $waterFileHandle "\n\nmolecule{ | 
| 498 | name = \"SSD\"; | 
| 499 |  | 
| 500 | atom[0]{ | 
| 501 | type = \"SSD\"; | 
| 502 | position( 0.0, 0.0, 0.0 ); | 
| 503 | orientation( 0.0, 0.0, 0.0 ); | 
| 504 | } | 
| 505 | }" | 
| 506 | } | 
| 507 |  | 
| 508 | sub printSSD1 { | 
| 509 | print $waterFileHandle "\n\nmolecule{ | 
| 510 | name = \"SSD1\"; | 
| 511 |  | 
| 512 | atom[0]{ | 
| 513 | type = \"SSD1\"; | 
| 514 | position( 0.0, 0.0, 0.0 ); | 
| 515 | orientation( 0.0, 0.0, 0.0 ); | 
| 516 | } | 
| 517 | }" | 
| 518 | } | 
| 519 |  | 
| 520 | sub printTRED { | 
| 521 | print $waterFileHandle "\n\nmolecule{ | 
| 522 | name = \"TRED\"; | 
| 523 |  | 
| 524 | atom[0]{ | 
| 525 | type = \"TRED\"; | 
| 526 | position( 0.0, 0.0, 0.0 ); | 
| 527 | orientation( 0.0, 0.0, 0.0 ); | 
| 528 | } | 
| 529 | atom[1]{ | 
| 530 | type = \"EP_TRED\"; | 
| 531 | position( 0.0, 0.0, 0.5 ); | 
| 532 | } | 
| 533 |  | 
| 534 | rigidBody[0]{ | 
| 535 | members(0, 1); | 
| 536 | } | 
| 537 |  | 
| 538 | cutoffGroup{ | 
| 539 | members(0, 1); | 
| 540 | } | 
| 541 | }" | 
| 542 | } | 
| 543 |  | 
| 544 | sub printTIP3P { | 
| 545 | print $waterFileHandle "\n\nmolecule{ | 
| 546 | name = \"TIP3P\"; | 
| 547 |  | 
| 548 | atom[0]{ | 
| 549 | type = \"O_TIP3P\"; | 
| 550 | position( 0.0, 0.0, -0.06556 ); | 
| 551 | } | 
| 552 | atom[1]{ | 
| 553 | type = \"H_TIP3P\"; | 
| 554 | position( 0.0, 0.75695, 0.52032 ); | 
| 555 | } | 
| 556 | atom[2]{ | 
| 557 | type = \"H_TIP3P\"; | 
| 558 | position( 0.0, -0.75695, 0.52032 ); | 
| 559 | } | 
| 560 |  | 
| 561 | rigidBody[0]{ | 
| 562 | members(0, 1, 2); | 
| 563 | } | 
| 564 |  | 
| 565 | cutoffGroup{ | 
| 566 | members(0, 1, 2); | 
| 567 | } | 
| 568 | }" | 
| 569 | } | 
| 570 |  | 
| 571 | sub printTIP4P { | 
| 572 | print $waterFileHandle "\n\nmolecule{ | 
| 573 | name = \"TIP4P\"; | 
| 574 |  | 
| 575 | atom[0]{ | 
| 576 | type = \"O_TIP4P\"; | 
| 577 | position( 0.0, 0.0, -0.06556 ); | 
| 578 | } | 
| 579 | atom[1]{ | 
| 580 | type = \"H_TIP4P\"; | 
| 581 | position( 0.0, 0.75695, 0.52032 ); | 
| 582 | } | 
| 583 | atom[2]{ | 
| 584 | type = \"H_TIP4P\"; | 
| 585 | position( 0.0, -0.75695, 0.52032 ); | 
| 586 | } | 
| 587 | atom[3]{ | 
| 588 | type = \"EP_TIP4P\"; | 
| 589 | position( 0.0, 0.0, 0.08444 ); | 
| 590 | } | 
| 591 |  | 
| 592 | rigidBody[0]{ | 
| 593 | members(0, 1, 2, 3); | 
| 594 | } | 
| 595 |  | 
| 596 | cutoffGroup{ | 
| 597 | members(0, 1, 2, 3); | 
| 598 | } | 
| 599 | }" | 
| 600 | } | 
| 601 |  | 
| 602 | sub printTIP4PEw { | 
| 603 | print $waterFileHandle "\n\nmolecule{ | 
| 604 | name = \"TIP4P-Ew\"; | 
| 605 |  | 
| 606 | atom[0]{ | 
| 607 | type = \"O_TIP4P-Ew\"; | 
| 608 | position( 0.0, 0.0, -0.06556 ); | 
| 609 | } | 
| 610 | atom[1]{ | 
| 611 | type = \"H_TIP4P-Ew\"; | 
| 612 | position( 0.0, 0.75695, 0.52032 ); | 
| 613 | } | 
| 614 | atom[2]{ | 
| 615 | type = \"H_TIP4P-Ew\"; | 
| 616 | position( 0.0, -0.75695, 0.52032 ); | 
| 617 | } | 
| 618 | atom[3]{ | 
| 619 | type = \"EP_TIP4P-Ew\"; | 
| 620 | position( 0.0, 0.0, 0.05944 ); | 
| 621 | } | 
| 622 |  | 
| 623 | rigidBody[0]{ | 
| 624 | members(0, 1, 2, 3); | 
| 625 | } | 
| 626 |  | 
| 627 | cutoffGroup{ | 
| 628 | members(0, 1, 2, 3); | 
| 629 | } | 
| 630 | }" | 
| 631 | } | 
| 632 |  | 
| 633 | sub printTIP5P { | 
| 634 | print $waterFileHandle "\n\nmolecule{ | 
| 635 | name = \"TIP5P\"; | 
| 636 |  | 
| 637 | atom[0]{ | 
| 638 | type = \"O_TIP5P\"; | 
| 639 | position( 0.0, 0.0, -0.06556 ); | 
| 640 | } | 
| 641 | atom[1]{ | 
| 642 | type = \"H_TIP5P\"; | 
| 643 | position( 0.0, 0.75695, 0.52032 ); | 
| 644 | } | 
| 645 | atom[2]{ | 
| 646 | type = \"H_TIP5P\"; | 
| 647 | position( 0.0, -0.75695, 0.52032 ); | 
| 648 | } | 
| 649 | atom[3]{ | 
| 650 | type = \"EP_TIP5P\"; | 
| 651 | position( 0.57154, 0.0, -0.46971 ); | 
| 652 | } | 
| 653 | atom[4]{ | 
| 654 | type = \"EP_TIP5P\"; | 
| 655 | position( -0.57154, 0.0, -0.46971 ); | 
| 656 | } | 
| 657 |  | 
| 658 | rigidBody[0]{ | 
| 659 | members(0, 1, 2, 3, 4); | 
| 660 | } | 
| 661 |  | 
| 662 | cutoffGroup{ | 
| 663 | members(0, 1, 2, 3, 4); | 
| 664 | } | 
| 665 | }" | 
| 666 | } | 
| 667 |  | 
| 668 | sub printTIP5PE { | 
| 669 | print $waterFileHandle "\n\nmolecule{ | 
| 670 | name = \"TIP5P-E\"; | 
| 671 |  | 
| 672 | atom[0]{ | 
| 673 | type = \"O_TIP5P-E\"; | 
| 674 | position( 0.0, 0.0, -0.06556 ); | 
| 675 | } | 
| 676 | atom[1]{ | 
| 677 | type = \"H_TIP5P\"; | 
| 678 | position( 0.0, 0.75695, 0.52032 ); | 
| 679 | } | 
| 680 | atom[2]{ | 
| 681 | type = \"H_TIP5P\"; | 
| 682 | position( 0.0, -0.75695, 0.52032 ); | 
| 683 | } | 
| 684 | atom[3]{ | 
| 685 | type = \"EP_TIP5P\"; | 
| 686 | position( 0.57154, 0.0, -0.46971 ); | 
| 687 | } | 
| 688 | atom[4]{ | 
| 689 | type = \"EP_TIP5P\"; | 
| 690 | position( -0.57154, 0.0, -0.46971 ); | 
| 691 | } | 
| 692 |  | 
| 693 | rigidBody[0]{ | 
| 694 | members(0, 1, 2, 3, 4); | 
| 695 | } | 
| 696 |  | 
| 697 | cutoffGroup{ | 
| 698 | members(0, 1, 2, 3, 4); | 
| 699 | } | 
| 700 | }" | 
| 701 | } | 
| 702 |  | 
| 703 | sub printSPCE { | 
| 704 | print $waterFileHandle "\n\nmolecule{ | 
| 705 | name = \"SPCE\"; | 
| 706 |  | 
| 707 | atom[0]{ | 
| 708 | type = \"O_SPCE\"; | 
| 709 | position( 0.0, 0.0, -0.06461 ); | 
| 710 | } | 
| 711 | atom[1]{ | 
| 712 | type = \"H_SPCE\"; | 
| 713 | position( 0.0, 0.81649, 0.51275 ); | 
| 714 | } | 
| 715 | atom[2]{ | 
| 716 | type = \"H_SPCE\"; | 
| 717 | position( 0.0, -0.81649, 0.51275 ); | 
| 718 | } | 
| 719 |  | 
| 720 | rigidBody[0]{ | 
| 721 | members(0, 1, 2); | 
| 722 | } | 
| 723 |  | 
| 724 | cutoffGroup{ | 
| 725 | members(0, 1, 2); | 
| 726 | } | 
| 727 | }" | 
| 728 | } | 
| 729 |  | 
| 730 | sub printSPC { | 
| 731 | print $waterFileHandle "\n\nmolecule{ | 
| 732 | name = \"SPC\"; | 
| 733 |  | 
| 734 | atom[0]{ | 
| 735 | type = \"O_SPC\"; | 
| 736 | position( 0.0, 0.0, -0.06461 ); | 
| 737 | } | 
| 738 | atom[1]{ | 
| 739 | type = \"H_SPC\"; | 
| 740 | position( 0.0, 0.81649, 0.51275 ); | 
| 741 | } | 
| 742 | atom[2]{ | 
| 743 | type = \"H_SPC\"; | 
| 744 | position( 0.0, -0.81649, 0.51275 ); | 
| 745 | } | 
| 746 |  | 
| 747 | rigidBody[0]{ | 
| 748 | members(0, 1, 2); | 
| 749 | } | 
| 750 |  | 
| 751 | cutoffGroup{ | 
| 752 | members(0, 1, 2); | 
| 753 | } | 
| 754 | }" | 
| 755 | } | 
| 756 |  | 
| 757 | sub printDPD { | 
| 758 | print $waterFileHandle "\n\nmolecule{ | 
| 759 | name = \"DPD\"; | 
| 760 |  | 
| 761 | atom[0]{ | 
| 762 | type = \"DPD\"; | 
| 763 | position(0.0, 0.0, 0.0); | 
| 764 | } | 
| 765 | }" | 
| 766 | } | 
| 767 |  | 
| 768 | sub printCG2 { | 
| 769 | print $waterFileHandle "\n\nmolecule{ | 
| 770 | name = \"CG2\"; | 
| 771 |  | 
| 772 | atom[0]{ | 
| 773 | type = \"CG2\"; | 
| 774 | position(0.0, 0.0, 0.0); | 
| 775 | } | 
| 776 | }" | 
| 777 | } | 
| 778 |  | 
| 779 | sub printFakeWater { | 
| 780 | print $waterFileHandle "\n\nmolecule{ | 
| 781 | name = \"$waterName\"; | 
| 782 |  | 
| 783 | atom[0]{ | 
| 784 | type = \"$waterName\"; | 
| 785 | position(0.0, 0.0, 0.0); | 
| 786 | } | 
| 787 | }" | 
| 788 | } | 
| 789 |  | 
| 790 |  | 
| 791 | sub validateWater { | 
| 792 | if    ($waterName eq 'Cl-')      { $waterCase = 0;    } | 
| 793 | elsif ($waterName eq 'Na+')      { $waterCase = 1;    } | 
| 794 | elsif ($waterName eq 'SSD_E')    { $waterCase = 2;    } | 
| 795 | elsif ($waterName eq 'SSD_RF')   { $waterCase = 3;    } | 
| 796 | elsif ($waterName eq 'SSD')      { $waterCase = 4;    } | 
| 797 | elsif ($waterName eq 'SSD1')     { $waterCase = 5;    } | 
| 798 | elsif ($waterName eq 'TIP3P')    { $waterCase = 6;    } | 
| 799 | elsif ($waterName eq 'TIP4P')    { $waterCase = 7;    } | 
| 800 | elsif ($waterName eq 'TIP4P-Ew') { $waterCase = 8;    } | 
| 801 | elsif ($waterName eq 'TIP5P')    { $waterCase = 9;    } | 
| 802 | elsif ($waterName eq 'TIP5P-E')  { $waterCase = 10;   } | 
| 803 | elsif ($waterName eq 'SPCE')     { $waterCase = 11;   } | 
| 804 | elsif ($waterName eq 'SPC')      { $waterCase = 12;   } | 
| 805 | elsif ($waterName eq 'DPD')      { $waterCase = 13;   } | 
| 806 | elsif ($waterName eq 'CG2')      { $waterCase = 14;   } | 
| 807 | else                             { $invalidWater = 1; } | 
| 808 | } | 
| 809 |  | 
| 810 | sub printWaterModel { | 
| 811 | if    ($waterCase == 0)  { printCl();      } | 
| 812 | elsif ($waterCase == 1)  { printNa();      } | 
| 813 | elsif ($waterCase == 2)  { printSSD_E();   } | 
| 814 | elsif ($waterCase == 3)  { printSSD_RF();  } | 
| 815 | elsif ($waterCase == 4)  { printSSD();     } | 
| 816 | elsif ($waterCase == 5)  { printSSD1();    } | 
| 817 | elsif ($waterCase == 6)  { printTIP3P();   } | 
| 818 | elsif ($waterCase == 7)  { printTIP4P();   } | 
| 819 | elsif ($waterCase == 8)  { printTIP4PEw(); } | 
| 820 | elsif ($waterCase == 9)  { printTIP5P();   } | 
| 821 | elsif ($waterCase == 10) { printTIP5PE();  } | 
| 822 | elsif ($waterCase == 11) { printSPCE();    } | 
| 823 | elsif ($waterCase == 12) { printSPC();     } | 
| 824 | elsif ($waterCase == 13) { printDPD();     } | 
| 825 | elsif ($waterCase == 14) { printCG2();     } | 
| 826 | } |