| 1 | /* | 
| 2 | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. | 
| 3 | * | 
| 4 | * The University of Notre Dame grants you ("Licensee") a | 
| 5 | * non-exclusive, royalty free, license to use, modify and | 
| 6 | * redistribute this software in source and binary code form, provided | 
| 7 | * that the following conditions are met: | 
| 8 | * | 
| 9 | * 1. Redistributions of source code must retain the above copyright | 
| 10 | *    notice, this list of conditions and the following disclaimer. | 
| 11 | * | 
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | *    notice, this list of conditions and the following disclaimer in the | 
| 14 | *    documentation and/or other materials provided with the | 
| 15 | *    distribution. | 
| 16 | * | 
| 17 | * This software is provided "AS IS," without a warranty of any | 
| 18 | * kind. All express or implied conditions, representations and | 
| 19 | * warranties, including any implied warranty of merchantability, | 
| 20 | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 | * be liable for any damages suffered by licensee as a result of | 
| 23 | * using, modifying or distributing the software or its | 
| 24 | * derivatives. In no event will the University of Notre Dame or its | 
| 25 | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 | * direct, indirect, special, consequential, incidental or punitive | 
| 27 | * damages, however caused and regardless of the theory of liability, | 
| 28 | * arising out of the use of or inability to use software, even if the | 
| 29 | * University of Notre Dame has been advised of the possibility of | 
| 30 | * such damages. | 
| 31 | * | 
| 32 | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 | * research, please cite the appropriate papers when you publish your | 
| 34 | * work.  Good starting points are: | 
| 35 | * | 
| 36 | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | */ | 
| 42 |  | 
| 43 | #include <iostream> | 
| 44 | #include <fstream> | 
| 45 | #include <string> | 
| 46 |  | 
| 47 | #include "brains/SimCreator.hpp" | 
| 48 | #include "brains/SimInfo.hpp" | 
| 49 | #include "io/DumpReader.hpp" | 
| 50 | #include "utils/simError.h" | 
| 51 |  | 
| 52 | #include "applications/staticProps/StaticPropsCmd.h" | 
| 53 | #include "applications/staticProps/StaticAnalyser.hpp" | 
| 54 | #include "applications/staticProps/GofR.hpp" | 
| 55 | #include "applications/staticProps/GofZ.hpp" | 
| 56 | #include "applications/staticProps/GofRZ.hpp" | 
| 57 | #include "applications/staticProps/GofRAngle.hpp" | 
| 58 | #include "applications/staticProps/GofAngle2.hpp" | 
| 59 | #include "applications/staticProps/GofXyz.hpp" | 
| 60 | #include "applications/staticProps/TwoDGofR.hpp" | 
| 61 | #include "applications/staticProps/P2OrderParameter.hpp" | 
| 62 | #include "applications/staticProps/BondOrderParameter.hpp" | 
| 63 | #include "applications/staticProps/BOPofR.hpp" | 
| 64 | #include "applications/staticProps/RippleOP.hpp" | 
| 65 | #include "applications/staticProps/SCDOrderParameter.hpp" | 
| 66 | #include "applications/staticProps/DensityPlot.hpp" | 
| 67 | #include "applications/staticProps/ObjectCount.hpp" | 
| 68 | #include "applications/staticProps/RhoZ.hpp" | 
| 69 | #include "applications/staticProps/pAngle.hpp" | 
| 70 | #include "applications/staticProps/BondAngleDistribution.hpp" | 
| 71 | #include "applications/staticProps/NanoVolume.hpp" | 
| 72 | #include "applications/staticProps/NanoLength.hpp" | 
| 73 | #if defined(HAVE_FFTW_H) || defined(HAVE_DFFTW_H) || defined(HAVE_FFTW3_H) | 
| 74 | #include "applications/staticProps/Hxy.hpp" | 
| 75 | #endif | 
| 76 | #include "applications/staticProps/RhoR.hpp" | 
| 77 | #include "applications/staticProps/AngleR.hpp" | 
| 78 | #include "applications/staticProps/TetrahedralityParam.hpp" | 
| 79 | #include "applications/staticProps/TetrahedralityParamZ.hpp" | 
| 80 | #include "applications/staticProps/TetrahedralityParamXYZ.hpp" | 
| 81 | #include "applications/staticProps/RNEMDStats.hpp" | 
| 82 | #include "applications/staticProps/NitrileFrequencyMap.hpp" | 
| 83 | #include "applications/staticProps/MultipoleSum.hpp" | 
| 84 |  | 
| 85 | using namespace OpenMD; | 
| 86 |  | 
| 87 | int main(int argc, char* argv[]){ | 
| 88 |  | 
| 89 |  | 
| 90 | gengetopt_args_info args_info; | 
| 91 |  | 
| 92 | //parse the command line option | 
| 93 | if (cmdline_parser (argc, argv, &args_info) != 0) { | 
| 94 | exit(1) ; | 
| 95 | } | 
| 96 |  | 
| 97 | //get the dumpfile name | 
| 98 | std::string dumpFileName = args_info.input_arg; | 
| 99 | std::string sele1; | 
| 100 | std::string sele2; | 
| 101 | std::string sele3; | 
| 102 |  | 
| 103 | // check the first selection argument, or set it to the environment | 
| 104 | // variable, or failing that, set it to "select all" | 
| 105 |  | 
| 106 | if (args_info.sele1_given) { | 
| 107 | sele1 = args_info.sele1_arg; | 
| 108 | } else { | 
| 109 | char*  sele1Env= getenv("SELECTION1"); | 
| 110 | if (sele1Env) { | 
| 111 | sele1 = sele1Env; | 
| 112 | } else { | 
| 113 | sele1 = "select all"; | 
| 114 | } | 
| 115 | } | 
| 116 |  | 
| 117 | // check the second selection argument, or set it to the environment | 
| 118 | // variable, or failing that, set it to the first selection | 
| 119 |  | 
| 120 | if (args_info.sele2_given) { | 
| 121 | sele2 = args_info.sele2_arg; | 
| 122 | } else { | 
| 123 | char* sele2Env = getenv("SELECTION2"); | 
| 124 | if (sele2Env) { | 
| 125 | sele2 = sele2Env; | 
| 126 | } else { | 
| 127 | //If sele2 is not specified, then the default behavior | 
| 128 | //should be what is already intended for sele1 | 
| 129 | sele2 = sele1; | 
| 130 | } | 
| 131 | } | 
| 132 |  | 
| 133 | // check the third selection argument, which is only set if | 
| 134 | // requested by the user | 
| 135 |  | 
| 136 | if (args_info.sele3_given) sele3 = args_info.sele3_arg; | 
| 137 |  | 
| 138 | bool batchMode; | 
| 139 | if (args_info.scd_given){ | 
| 140 | if (args_info.sele1_given && | 
| 141 | args_info.sele2_given && args_info.sele3_given) { | 
| 142 | batchMode = false; | 
| 143 | } else if (args_info.molname_given && | 
| 144 | args_info.begin_given && args_info.end_given) { | 
| 145 | if (args_info.begin_arg < 0 || | 
| 146 | args_info.end_arg < 0 || args_info.begin_arg > args_info.end_arg-2) { | 
| 147 | sprintf( painCave.errMsg, | 
| 148 | "below conditions are not satisfied:\n" | 
| 149 | "0 <= begin && 0<= end && begin <= end-2\n"); | 
| 150 | painCave.severity = OPENMD_ERROR; | 
| 151 | painCave.isFatal = 1; | 
| 152 | simError(); | 
| 153 | } | 
| 154 | batchMode = true; | 
| 155 | } else{ | 
| 156 | sprintf( painCave.errMsg, | 
| 157 | "either --sele1, --sele2, --sele3 are specified," | 
| 158 | " or --molname, --begin, --end are specified\n"); | 
| 159 | painCave.severity = OPENMD_ERROR; | 
| 160 | painCave.isFatal = 1; | 
| 161 | simError(); | 
| 162 | } | 
| 163 | } | 
| 164 |  | 
| 165 | //parse md file and set up the system | 
| 166 | SimCreator creator; | 
| 167 | SimInfo* info = creator.createSim(dumpFileName); | 
| 168 |  | 
| 169 | RealType maxLen; | 
| 170 | RealType zmaxLen; | 
| 171 | if (args_info.length_given) { | 
| 172 | maxLen = args_info.length_arg; | 
| 173 | if (args_info.zlength_given){ | 
| 174 | zmaxLen = args_info.zlength_arg; | 
| 175 | } | 
| 176 | } else { | 
| 177 | Mat3x3d hmat = info->getSnapshotManager()->getCurrentSnapshot()->getHmat(); | 
| 178 | maxLen = std::min(std::min(hmat(0, 0), hmat(1, 1)), hmat(2, 2)) /2.0; | 
| 179 | zmaxLen = hmat(2,2); | 
| 180 | } | 
| 181 |  | 
| 182 | StaticAnalyser* analyser; | 
| 183 | if (args_info.gofr_given){ | 
| 184 | analyser= new GofR(info, dumpFileName, sele1, sele2, maxLen, | 
| 185 | args_info.nbins_arg); | 
| 186 | } else if (args_info.gofz_given) { | 
| 187 | analyser= new GofZ(info, dumpFileName, sele1, sele2, maxLen, | 
| 188 | args_info.nbins_arg); | 
| 189 | } else if (args_info.r_z_given) { | 
| 190 | analyser  = new GofRZ(info, dumpFileName, sele1, sele2, maxLen, zmaxLen, | 
| 191 | args_info.nbins_arg, args_info.nbins_z_arg); | 
| 192 | } else if (args_info.r_theta_given) { | 
| 193 | if (args_info.sele3_given) | 
| 194 | analyser  = new GofRTheta(info, dumpFileName, sele1, sele2, sele3, maxLen, | 
| 195 | args_info.nbins_arg, args_info.nanglebins_arg); | 
| 196 | else | 
| 197 | analyser  = new GofRTheta(info, dumpFileName, sele1, sele2, maxLen, | 
| 198 | args_info.nbins_arg, args_info.nanglebins_arg); | 
| 199 | } else if (args_info.r_omega_given) { | 
| 200 | if (args_info.sele3_given) | 
| 201 | analyser  = new GofROmega(info, dumpFileName, sele1, sele2, sele3, maxLen, | 
| 202 | args_info.nbins_arg, args_info.nanglebins_arg); | 
| 203 | else | 
| 204 | analyser  = new GofROmega(info, dumpFileName, sele1, sele2, maxLen, | 
| 205 | args_info.nbins_arg, args_info.nanglebins_arg); | 
| 206 |  | 
| 207 | } else if (args_info.theta_omega_given) { | 
| 208 | if (args_info.sele3_given) | 
| 209 | analyser  = new GofAngle2(info, dumpFileName, sele1, sele2, sele3, | 
| 210 | args_info.nanglebins_arg); | 
| 211 | else | 
| 212 | analyser  = new GofAngle2(info, dumpFileName, sele1, sele2, | 
| 213 | args_info.nanglebins_arg); | 
| 214 | } else if (args_info.gxyz_given) { | 
| 215 | if (args_info.refsele_given) { | 
| 216 | analyser= new GofXyz(info, dumpFileName, sele1, sele2, | 
| 217 | args_info.refsele_arg, maxLen, args_info.nbins_arg); | 
| 218 | } else { | 
| 219 | sprintf( painCave.errMsg, | 
| 220 | "--refsele must set when --gxyz is used"); | 
| 221 | painCave.severity = OPENMD_ERROR; | 
| 222 | painCave.isFatal = 1; | 
| 223 | simError(); | 
| 224 | } | 
| 225 | } else if (args_info.twodgofr_given){ | 
| 226 | if (args_info.dz_given) { | 
| 227 | analyser= new TwoDGofR(info, dumpFileName, sele1, sele2, maxLen, | 
| 228 | args_info.dz_arg, args_info.nbins_arg); | 
| 229 | } else { | 
| 230 | sprintf( painCave.errMsg, | 
| 231 | "A slab width (dz) must be specified when calculating TwoDGofR"); | 
| 232 | painCave.severity = OPENMD_ERROR; | 
| 233 | painCave.isFatal = 1; | 
| 234 | simError(); | 
| 235 | } | 
| 236 | } else if (args_info.p2_given) { | 
| 237 | if (args_info.sele1_given) { | 
| 238 | if (args_info.sele2_given) | 
| 239 | analyser  = new P2OrderParameter(info, dumpFileName, sele1, sele2); | 
| 240 | else | 
| 241 | if (args_info.seleoffset_given) | 
| 242 | analyser  = new P2OrderParameter(info, dumpFileName, sele1, | 
| 243 | args_info.seleoffset_arg); | 
| 244 | else | 
| 245 | analyser  = new P2OrderParameter(info, dumpFileName, sele1); | 
| 246 | } else { | 
| 247 | sprintf( painCave.errMsg, | 
| 248 | "At least one selection script (--sele1) must be specified when calculating P2 order parameters"); | 
| 249 | painCave.severity = OPENMD_ERROR; | 
| 250 | painCave.isFatal = 1; | 
| 251 | simError(); | 
| 252 | } | 
| 253 | } else if (args_info.rp2_given){ | 
| 254 | analyser = new RippleOP(info, dumpFileName, sele1, sele2); | 
| 255 | } else if (args_info.bo_given){ | 
| 256 | if (args_info.rcut_given) { | 
| 257 | analyser = new BondOrderParameter(info, dumpFileName, sele1, | 
| 258 | args_info.rcut_arg, | 
| 259 | args_info.nbins_arg); | 
| 260 | } else { | 
| 261 | sprintf( painCave.errMsg, | 
| 262 | "A cutoff radius (rcut) must be specified when calculating Bond Order Parameters"); | 
| 263 | painCave.severity = OPENMD_ERROR; | 
| 264 | painCave.isFatal = 1; | 
| 265 | simError(); | 
| 266 | } | 
| 267 | } else if (args_info.multipole_given){ | 
| 268 | analyser = new MultipoleSum(info, dumpFileName, sele1, | 
| 269 | maxLen, args_info.nbins_arg); | 
| 270 | } else if (args_info.tet_param_given) { | 
| 271 | if (args_info.rcut_given) { | 
| 272 | analyser = new TetrahedralityParam(info, dumpFileName, sele1, | 
| 273 | args_info.rcut_arg, | 
| 274 | args_info.nbins_arg); | 
| 275 | } else { | 
| 276 | sprintf( painCave.errMsg, | 
| 277 | "A cutoff radius (rcut) must be specified when calculating Tetrahedrality Parameters"); | 
| 278 | painCave.severity = OPENMD_ERROR; | 
| 279 | painCave.isFatal = 1; | 
| 280 | simError(); | 
| 281 | } | 
| 282 | } else if (args_info.tet_param_z_given) { | 
| 283 | if (args_info.rcut_given) { | 
| 284 | analyser = new TetrahedralityParamZ(info, dumpFileName, sele1, sele2, | 
| 285 | args_info.rcut_arg, | 
| 286 | args_info.nbins_arg); | 
| 287 | } else { | 
| 288 | sprintf( painCave.errMsg, | 
| 289 | "A cutoff radius (rcut) must be specified when calculating Tetrahedrality Parameters"); | 
| 290 | painCave.severity = OPENMD_ERROR; | 
| 291 | painCave.isFatal = 1; | 
| 292 | simError(); | 
| 293 | } | 
| 294 | } else if (args_info.tet_param_xyz_given) { | 
| 295 | if (!args_info.rcut_given) { | 
| 296 | sprintf( painCave.errMsg, | 
| 297 | "A cutoff radius (rcut) must be specified when calculating" | 
| 298 | " Tetrahedrality Parameters"); | 
| 299 | painCave.severity = OPENMD_ERROR; | 
| 300 | painCave.isFatal = 1; | 
| 301 | simError(); | 
| 302 | } | 
| 303 | if (!args_info.voxelSize_given) { | 
| 304 | sprintf( painCave.errMsg, | 
| 305 | "A voxel size must be specified when calculating" | 
| 306 | " volume-resolved Tetrahedrality Parameters"); | 
| 307 | painCave.severity = OPENMD_ERROR; | 
| 308 | painCave.isFatal = 1; | 
| 309 | simError(); | 
| 310 | } | 
| 311 | if (!args_info.gaussWidth_given) { | 
| 312 | sprintf( painCave.errMsg, | 
| 313 | "A gaussian width must be specified when calculating" | 
| 314 | " volume-resolved Tetrahedrality Parameters"); | 
| 315 | painCave.severity = OPENMD_ERROR; | 
| 316 | painCave.isFatal = 1; | 
| 317 | simError(); | 
| 318 | } | 
| 319 | analyser = new TetrahedralityParamXYZ(info, dumpFileName, sele1, sele2, | 
| 320 | args_info.rcut_arg, | 
| 321 | args_info.voxelSize_arg, | 
| 322 | args_info.gaussWidth_arg); | 
| 323 | } else if (args_info.ior_given){ | 
| 324 | if (args_info.rcut_given) { | 
| 325 | analyser = new IcosahedralOfR(info, dumpFileName, sele1, | 
| 326 | args_info.rcut_arg, | 
| 327 | args_info.nbins_arg, maxLen); | 
| 328 | } else { | 
| 329 | sprintf( painCave.errMsg, | 
| 330 | "A cutoff radius (rcut) must be specified when calculating Bond Order Parameters"); | 
| 331 | painCave.severity = OPENMD_ERROR; | 
| 332 | painCave.isFatal = 1; | 
| 333 | simError(); | 
| 334 | } | 
| 335 | } else if (args_info.for_given){ | 
| 336 | if (args_info.rcut_given) { | 
| 337 | analyser = new FCCOfR(info, dumpFileName, sele1, args_info.rcut_arg, | 
| 338 | args_info.nbins_arg, maxLen); | 
| 339 | } else { | 
| 340 | sprintf( painCave.errMsg, | 
| 341 | "A cutoff radius (rcut) must be specified when calculating Bond Order Parameters"); | 
| 342 | painCave.severity = OPENMD_ERROR; | 
| 343 | painCave.isFatal = 1; | 
| 344 | simError(); | 
| 345 | } | 
| 346 | } else if (args_info.bad_given){ | 
| 347 | if (args_info.rcut_given) { | 
| 348 | analyser = new BondAngleDistribution(info, dumpFileName, sele1, | 
| 349 | args_info.rcut_arg, | 
| 350 | args_info.nbins_arg); | 
| 351 | } else { | 
| 352 | sprintf( painCave.errMsg, | 
| 353 | "A cutoff radius (rcut) must be specified when calculating Bond Angle Distributions"); | 
| 354 | painCave.severity = OPENMD_ERROR; | 
| 355 | painCave.isFatal = 1; | 
| 356 | simError(); | 
| 357 | } | 
| 358 | } else if (args_info.scd_given) { | 
| 359 | if (batchMode) { | 
| 360 | analyser  = new SCDOrderParameter(info, dumpFileName, | 
| 361 | args_info.molname_arg, | 
| 362 | args_info.begin_arg, args_info.end_arg); | 
| 363 | } else{ | 
| 364 | analyser  = new SCDOrderParameter(info, dumpFileName, | 
| 365 | sele1, sele2, sele3); | 
| 366 | } | 
| 367 | }else if (args_info.density_given) { | 
| 368 | analyser= new DensityPlot(info, dumpFileName, sele1, sele2, maxLen, | 
| 369 | args_info.nbins_arg); | 
| 370 | } else if (args_info.count_given) { | 
| 371 | analyser = new ObjectCount(info, dumpFileName, sele1 ); | 
| 372 | } else if (args_info.slab_density_given) { | 
| 373 | analyser = new RhoZ(info, dumpFileName, sele1, args_info.nbins_arg); | 
| 374 | } else if (args_info.rnemdz_given) { | 
| 375 | analyser = new RNEMDZ(info, dumpFileName, sele1, args_info.nbins_arg); | 
| 376 | } else if (args_info.rnemdr_given) { | 
| 377 | analyser = new RNEMDR(info, dumpFileName, sele1, args_info.nbins_arg); | 
| 378 | } else if (args_info.rnemdrt_given) { | 
| 379 | analyser = new RNEMDRTheta(info, dumpFileName, sele1, | 
| 380 | args_info.nbins_arg, args_info.nanglebins_arg); | 
| 381 | } else if (args_info.nitrile_given) { | 
| 382 | analyser = new NitrileFrequencyMap(info, dumpFileName, sele1, | 
| 383 | args_info.nbins_arg); | 
| 384 | } else if (args_info.p_angle_given) { | 
| 385 | if (args_info.sele1_given) { | 
| 386 | if (args_info.sele2_given) | 
| 387 | analyser  = new pAngle(info, dumpFileName, sele1, sele2, | 
| 388 | args_info.nbins_arg); | 
| 389 | else | 
| 390 | if (args_info.seleoffset_given) { | 
| 391 | if (args_info.seleoffset2_given) { | 
| 392 | analyser  = new pAngle(info, dumpFileName, sele1, | 
| 393 | args_info.seleoffset_arg, | 
| 394 | args_info.seleoffset2_arg, | 
| 395 | args_info.nbins_arg); | 
| 396 | } else { | 
| 397 | analyser  = new pAngle(info, dumpFileName, sele1, | 
| 398 | args_info.seleoffset_arg, | 
| 399 | args_info.nbins_arg); | 
| 400 | } | 
| 401 | } else | 
| 402 | analyser  = new pAngle(info, dumpFileName, sele1, | 
| 403 | args_info.nbins_arg); | 
| 404 | } else { | 
| 405 | sprintf( painCave.errMsg, | 
| 406 | "At least one selection script (--sele1) must be specified when " | 
| 407 | "calculating P(angle) distributions"); | 
| 408 | painCave.severity = OPENMD_ERROR; | 
| 409 | painCave.isFatal = 1; | 
| 410 | simError(); | 
| 411 | } | 
| 412 | #if defined(HAVE_FFTW_H) || defined(HAVE_DFFTW_H) || defined(HAVE_FFTW3_H) | 
| 413 | }else if (args_info.hxy_given) { | 
| 414 | analyser = new Hxy(info, dumpFileName, sele1, args_info.nbins_x_arg, | 
| 415 | args_info.nbins_y_arg, args_info.nbins_arg); | 
| 416 | #endif | 
| 417 | }else if (args_info.rho_r_given) { | 
| 418 | if (args_info.radius_given){ | 
| 419 | analyser = new RhoR(info, dumpFileName, sele1, maxLen,args_info.nbins_arg,args_info.radius_arg); | 
| 420 | }else{ | 
| 421 | sprintf( painCave.errMsg, | 
| 422 | "A particle radius (radius) must be specified when calculating Rho(r)"); | 
| 423 | painCave.severity = OPENMD_ERROR; | 
| 424 | painCave.isFatal = 1; | 
| 425 | simError(); | 
| 426 | } | 
| 427 | } else if (args_info.hullvol_given) { | 
| 428 | analyser = new NanoVolume(info, dumpFileName, sele1); | 
| 429 | } else if (args_info.rodlength_given) { | 
| 430 | analyser = new NanoLength(info, dumpFileName, sele1); | 
| 431 | } else if (args_info.angle_r_given) { | 
| 432 | analyser = new AngleR(info, dumpFileName, sele1, maxLen,args_info.nbins_arg); | 
| 433 | } | 
| 434 |  | 
| 435 | if (args_info.output_given) { | 
| 436 | analyser->setOutputName(args_info.output_arg); | 
| 437 | } | 
| 438 | if (args_info.step_given) { | 
| 439 | analyser->setStep(args_info.step_arg); | 
| 440 | } | 
| 441 |  | 
| 442 | analyser->process(); | 
| 443 |  | 
| 444 | delete analyser; | 
| 445 | delete info; | 
| 446 |  | 
| 447 | return 0; | 
| 448 | } |