| 1 | tim | 1994 | /* | 
| 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. Acknowledgement of the program authors must be made in any | 
| 10 |  |  | *    publication of scientific results based in part on use of the | 
| 11 |  |  | *    program.  An acceptable form of acknowledgement is citation of | 
| 12 |  |  | *    the article in which the program was described (Matthew | 
| 13 |  |  | *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher | 
| 14 |  |  | *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented | 
| 15 |  |  | *    Parallel Simulation Engine for Molecular Dynamics," | 
| 16 |  |  | *    J. Comput. Chem. 26, pp. 252-271 (2005)) | 
| 17 |  |  | * | 
| 18 |  |  | * 2. Redistributions of source code must retain the above copyright | 
| 19 |  |  | *    notice, this list of conditions and the following disclaimer. | 
| 20 |  |  | * | 
| 21 |  |  | * 3. Redistributions in binary form must reproduce the above copyright | 
| 22 |  |  | *    notice, this list of conditions and the following disclaimer in the | 
| 23 |  |  | *    documentation and/or other materials provided with the | 
| 24 |  |  | *    distribution. | 
| 25 |  |  | * | 
| 26 |  |  | * This software is provided "AS IS," without a warranty of any | 
| 27 |  |  | * kind. All express or implied conditions, representations and | 
| 28 |  |  | * warranties, including any implied warranty of merchantability, | 
| 29 |  |  | * fitness for a particular purpose or non-infringement, are hereby | 
| 30 |  |  | * excluded.  The University of Notre Dame and its licensors shall not | 
| 31 |  |  | * be liable for any damages suffered by licensee as a result of | 
| 32 |  |  | * using, modifying or distributing the software or its | 
| 33 |  |  | * derivatives. In no event will the University of Notre Dame or its | 
| 34 |  |  | * licensors be liable for any lost revenue, profit or data, or for | 
| 35 |  |  | * direct, indirect, special, consequential, incidental or punitive | 
| 36 |  |  | * damages, however caused and regardless of the theory of liability, | 
| 37 |  |  | * arising out of the use of or inability to use software, even if the | 
| 38 |  |  | * University of Notre Dame has been advised of the possibility of | 
| 39 |  |  | * such damages. | 
| 40 |  |  | */ | 
| 41 |  |  |  | 
| 42 |  |  | #include <algorithm> | 
| 43 |  |  | #include <fstream> | 
| 44 |  |  | #include "applications/staticProps/GofXyz.hpp" | 
| 45 |  |  | #include "utils/simError.h" | 
| 46 | tim | 2045 | #include "primitives/Molecule.hpp" | 
| 47 | tim | 1994 | namespace oopse { | 
| 48 |  |  |  | 
| 49 | tim | 2038 | GofXyz::GofXyz(SimInfo* info, const std::string& filename, const std::string& sele1, const std::string& sele2, double len, int nrbins) | 
| 50 |  |  | : RadialDistrFunc(info, filename, sele1, sele2), len_(len), nRBins_(nrbins) { | 
| 51 | tim | 1995 | setOutputName(getPrefix(filename) + ".gxyz"); | 
| 52 | tim | 1994 |  | 
| 53 | tim | 2038 | deltaR_ = len_ / nRBins_; | 
| 54 |  |  |  | 
| 55 |  |  | histogram_.resize(nRBins_); | 
| 56 |  |  | for (int i = 0 ; i < nRBins_; ++i) { | 
| 57 |  |  | histogram_[i].resize(nRBins_); | 
| 58 |  |  | for(int j = 0; j < nRBins_; ++j) { | 
| 59 |  |  | histogram_[i][j].resize(nRBins_); | 
| 60 |  |  | } | 
| 61 |  |  | } | 
| 62 | tim | 2045 |  | 
| 63 |  |  | //create atom2Mol mapping (should be other class' responsibility) | 
| 64 |  |  | atom2Mol_.insert(atom2Mol_.begin(), info_->getNGlobalAtoms() + info_->getNGlobalRigidBodies(), static_cast<Molecule*>(NULL)); | 
| 65 |  |  |  | 
| 66 |  |  | SimInfo::MoleculeIterator mi; | 
| 67 |  |  | Molecule* mol; | 
| 68 |  |  | Molecule::AtomIterator ai; | 
| 69 |  |  | Atom* atom; | 
| 70 |  |  | Molecule::RigidBodyIterator rbIter; | 
| 71 |  |  | RigidBody* rb; | 
| 72 |  |  |  | 
| 73 |  |  | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 74 |  |  |  | 
| 75 |  |  | for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { | 
| 76 |  |  | atom2Mol_[atom->getGlobalIndex()] = mol; | 
| 77 |  |  | } | 
| 78 |  |  |  | 
| 79 |  |  | for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { | 
| 80 |  |  | atom2Mol_[rb->getGlobalIndex()] = mol; | 
| 81 |  |  | } | 
| 82 |  |  |  | 
| 83 |  |  | } | 
| 84 | tim | 1994 | } | 
| 85 |  |  |  | 
| 86 |  |  |  | 
| 87 |  |  | void GofXyz::preProcess() { | 
| 88 | tim | 2045 | for (int i = 0 ; i < nRBins_; ++i) { | 
| 89 |  |  | histogram_[i].resize(nRBins_); | 
| 90 |  |  | for(int j = 0; j < nRBins_; ++j) { | 
| 91 |  |  | std::fill(histogram_[i][j].begin(), histogram_[i][j].end(), 0); | 
| 92 |  |  | } | 
| 93 |  |  | } | 
| 94 | tim | 1994 | } | 
| 95 |  |  |  | 
| 96 | tim | 2045 |  | 
| 97 | tim | 1994 | void GofXyz::initalizeHistogram() { | 
| 98 | tim | 2045 | //calculate the center of mass of the molecule of selected stuntdouble in selection1 | 
| 99 | tim | 1994 |  | 
| 100 | tim | 2045 | //determine the new coordinate set of selection1 | 
| 101 |  |  | //v1 = Rs1 -Rcom, | 
| 102 |  |  | //z = Rs1.dipole | 
| 103 |  |  | //x = v1 X z | 
| 104 |  |  | //y = z X x | 
| 105 |  |  | coorSets_.clear(); | 
| 106 | tim | 1994 |  | 
| 107 | tim | 2045 | int i; | 
| 108 |  |  | StuntDouble* sd; | 
| 109 |  |  | for (sd = seleMan1_.beginSelected(i); sd != NULL; sd = seleMan1_.nextSelected(i)) { | 
| 110 |  |  | Vector3d rcom = getMolCom(sd); | 
| 111 |  |  | Vector3d rs1 = sd->getPos(); | 
| 112 |  |  | Vector3d v1 =  rcom - rs1; | 
| 113 |  |  | CoorSet currCoorSet; | 
| 114 |  |  | currCoorSet.zaxis = sd->getElectroFrame().getColumn(2); | 
| 115 |  |  | v1.normalize(); | 
| 116 |  |  | currCoorSet.zaxis.normalize(); | 
| 117 |  |  | currCoorSet.xaxis = cross(v1, currCoorSet.zaxis); | 
| 118 |  |  | currCoorSet.yaxis = cross(currCoorSet.zaxis, currCoorSet.xaxis); | 
| 119 |  |  | coorSets_.insert(std::map<int, CoorSet>::value_type(sd->getGlobalIndex(), currCoorSet)); | 
| 120 |  |  | } | 
| 121 | tim | 1994 |  | 
| 122 |  |  | } | 
| 123 |  |  |  | 
| 124 |  |  | void GofXyz::collectHistogram(StuntDouble* sd1, StuntDouble* sd2) { | 
| 125 |  |  |  | 
| 126 |  |  | Vector3d pos1 = sd1->getPos(); | 
| 127 |  |  | Vector3d pos2 = sd2->getPos(); | 
| 128 | tim | 2045 | Vector3d r12 = pos2 - pos1; | 
| 129 | tim | 1994 | currentSnapshot_->wrapVector(r12); | 
| 130 |  |  |  | 
| 131 | tim | 2045 | std::map<int, CoorSet>::iterator i = coorSets_.find(sd1->getGlobalIndex()); | 
| 132 |  |  | assert(i != coorSets_.end()); | 
| 133 |  |  |  | 
| 134 |  |  | double x = dot(r12, i->second.xaxis); | 
| 135 |  |  | double y = dot(r12, i->second.yaxis); | 
| 136 |  |  | double z = dot(r12, i->second.zaxis); | 
| 137 | tim | 1994 |  | 
| 138 | tim | 2045 | int xbin = x / deltaR_; | 
| 139 |  |  | int ybin = y / deltaR_; | 
| 140 |  |  | int zbin = z / deltaR_; | 
| 141 |  |  |  | 
| 142 |  |  | if (xbin < nRBins_ && ybin < nRBins_ && zbin < nRBins_) { | 
| 143 |  |  | ++histogram_[x][y][z]; | 
| 144 |  |  | } | 
| 145 | tim | 1994 |  | 
| 146 |  |  | } | 
| 147 |  |  |  | 
| 148 |  |  | void GofXyz::writeRdf() { | 
| 149 | tim | 2046 | std::ofstream rdfStream(outputFilename_.c_str(), std::ios::binary); | 
| 150 | tim | 1994 | if (rdfStream.is_open()) { | 
| 151 | tim | 2046 | //rdfStream << "#g(x, y, z)\n"; | 
| 152 |  |  | //rdfStream << "#selection1: (" << selectionScript1_ << ")\t"; | 
| 153 |  |  | //rdfStream << "selection2: (" << selectionScript2_ << ")\n"; | 
| 154 |  |  | //rdfStream << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n"; | 
| 155 | tim | 1994 | for (int i = 0; i < histogram_.size(); ++i) { | 
| 156 | tim | 2045 |  | 
| 157 | tim | 1994 | for(int j = 0; j < histogram_[i].size(); ++j) { | 
| 158 | tim | 2045 |  | 
| 159 | tim | 1994 | for(int k = 0;k < histogram_[i].size(); ++k) { | 
| 160 | tim | 2046 | rdfStream.write(reinterpret_cast<char *>(&histogram_[i][j][k] ), sizeof(histogram_[i][j][k] )); | 
| 161 | tim | 1995 | } | 
| 162 | tim | 1994 | } | 
| 163 |  |  | } | 
| 164 |  |  |  | 
| 165 |  |  | } else { | 
| 166 |  |  |  | 
| 167 | tim | 2044 | sprintf(painCave.errMsg, "GofXyz: unable to open %s\n", outputFilename_.c_str()); | 
| 168 |  |  | painCave.isFatal = 1; | 
| 169 |  |  | simError(); | 
| 170 | tim | 1994 | } | 
| 171 |  |  |  | 
| 172 |  |  | rdfStream.close(); | 
| 173 |  |  | } | 
| 174 |  |  |  | 
| 175 | tim | 2045 | Vector3d GofXyz::getMolCom(StuntDouble* sd){ | 
| 176 |  |  | Molecule* mol = atom2Mol_[sd->getGlobalIndex()]; | 
| 177 |  |  | assert(mol); | 
| 178 |  |  | return mol->getCom(); | 
| 179 | tim | 1994 | } | 
| 180 |  |  |  | 
| 181 | tim | 2045 | } |