| 1 |
gezelter |
246 |
/* |
| 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 |
|
|
/** |
| 43 |
|
|
* @file Molecule.cpp |
| 44 |
|
|
* @author tlin |
| 45 |
|
|
* @date 10/28/2004 |
| 46 |
|
|
* @version 1.0 |
| 47 |
|
|
*/ |
| 48 |
gezelter |
2 |
|
| 49 |
gezelter |
246 |
#include <algorithm> |
| 50 |
|
|
#include <set> |
| 51 |
gezelter |
2 |
|
| 52 |
tim |
3 |
#include "primitives/Molecule.hpp" |
| 53 |
gezelter |
246 |
#include "utils/MemoryUtils.hpp" |
| 54 |
tim |
3 |
#include "utils/simError.h" |
| 55 |
gezelter |
2 |
|
| 56 |
gezelter |
246 |
namespace oopse { |
| 57 |
|
|
Molecule::Molecule(int stampId, int globalIndex, const std::string& molName) |
| 58 |
|
|
: stampId_(stampId), globalIndex_(globalIndex), moleculeName_(molName) { |
| 59 |
gezelter |
2 |
|
| 60 |
gezelter |
246 |
} |
| 61 |
gezelter |
2 |
|
| 62 |
gezelter |
246 |
Molecule::~Molecule() { |
| 63 |
gezelter |
2 |
|
| 64 |
gezelter |
246 |
MemoryUtils::deleteVectorOfPointer(atoms_); |
| 65 |
|
|
MemoryUtils::deleteVectorOfPointer(bonds_); |
| 66 |
|
|
MemoryUtils::deleteVectorOfPointer(bends_); |
| 67 |
|
|
MemoryUtils::deleteVectorOfPointer(torsions_); |
| 68 |
|
|
MemoryUtils::deleteVectorOfPointer(rigidBodies_); |
| 69 |
|
|
MemoryUtils::deleteVectorOfPointer(cutoffGroups_); |
| 70 |
|
|
MemoryUtils::deleteVectorOfPointer(constraintPairs_); |
| 71 |
|
|
MemoryUtils::deleteVectorOfPointer(constraintElems_); |
| 72 |
|
|
//integrableObjects_ don't own the objects |
| 73 |
|
|
integrableObjects_.clear(); |
| 74 |
|
|
|
| 75 |
gezelter |
2 |
} |
| 76 |
|
|
|
| 77 |
gezelter |
246 |
void Molecule::addAtom(Atom* atom) { |
| 78 |
|
|
if (std::find(atoms_.begin(), atoms_.end(), atom) == atoms_.end()) { |
| 79 |
|
|
atoms_.push_back(atom); |
| 80 |
|
|
} |
| 81 |
|
|
} |
| 82 |
gezelter |
2 |
|
| 83 |
gezelter |
246 |
void Molecule::addBond(Bond* bond) { |
| 84 |
|
|
if (std::find(bonds_.begin(), bonds_.end(), bond) == bonds_.end()) { |
| 85 |
|
|
bonds_.push_back(bond); |
| 86 |
|
|
} |
| 87 |
|
|
} |
| 88 |
gezelter |
2 |
|
| 89 |
gezelter |
246 |
void Molecule::addBend(Bend* bend) { |
| 90 |
|
|
if (std::find(bends_.begin(), bends_.end(), bend) == bends_.end()) { |
| 91 |
|
|
bends_.push_back(bend); |
| 92 |
|
|
} |
| 93 |
|
|
} |
| 94 |
gezelter |
2 |
|
| 95 |
gezelter |
246 |
void Molecule::addTorsion(Torsion* torsion) { |
| 96 |
|
|
if (std::find(torsions_.begin(), torsions_.end(), torsion) == torsions_.end()) { |
| 97 |
|
|
torsions_.push_back(torsion); |
| 98 |
|
|
} |
| 99 |
|
|
} |
| 100 |
gezelter |
2 |
|
| 101 |
gezelter |
246 |
void Molecule::addRigidBody(RigidBody *rb) { |
| 102 |
|
|
if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) == rigidBodies_.end()) { |
| 103 |
|
|
rigidBodies_.push_back(rb); |
| 104 |
|
|
} |
| 105 |
gezelter |
2 |
} |
| 106 |
|
|
|
| 107 |
gezelter |
246 |
void Molecule::addCutoffGroup(CutoffGroup* cp) { |
| 108 |
|
|
if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) == cutoffGroups_.end()) { |
| 109 |
|
|
cutoffGroups_.push_back(cp); |
| 110 |
|
|
} |
| 111 |
gezelter |
2 |
|
| 112 |
gezelter |
246 |
} |
| 113 |
gezelter |
2 |
|
| 114 |
gezelter |
246 |
void Molecule::addConstraintPair(ConstraintPair* cp) { |
| 115 |
|
|
if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) == constraintPairs_.end()) { |
| 116 |
|
|
constraintPairs_.push_back(cp); |
| 117 |
|
|
} |
| 118 |
gezelter |
2 |
|
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
gezelter |
246 |
void Molecule::addConstraintElem(ConstraintElem* cp) { |
| 122 |
|
|
if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) == constraintElems_.end()) { |
| 123 |
|
|
constraintElems_.push_back(cp); |
| 124 |
|
|
} |
| 125 |
gezelter |
2 |
|
| 126 |
|
|
} |
| 127 |
|
|
|
| 128 |
gezelter |
246 |
void Molecule::complete() { |
| 129 |
|
|
|
| 130 |
|
|
std::set<Atom*> rigidAtoms; |
| 131 |
|
|
RigidBody* rb; |
| 132 |
|
|
std::vector<RigidBody*>::iterator rbIter; |
| 133 |
gezelter |
2 |
|
| 134 |
gezelter |
246 |
|
| 135 |
|
|
for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) { |
| 136 |
|
|
rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter()); |
| 137 |
|
|
} |
| 138 |
gezelter |
2 |
|
| 139 |
gezelter |
246 |
Atom* atom; |
| 140 |
|
|
AtomIterator ai; |
| 141 |
|
|
for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) { |
| 142 |
gezelter |
2 |
|
| 143 |
gezelter |
246 |
if (rigidAtoms.find(*ai) == rigidAtoms.end()) { |
| 144 |
|
|
//if an atom does not belong to a rigid body, it is an integrable object |
| 145 |
|
|
integrableObjects_.push_back(*ai); |
| 146 |
|
|
} |
| 147 |
|
|
} |
| 148 |
gezelter |
2 |
|
| 149 |
gezelter |
246 |
//find all free atoms (which do not belong to rigid bodies) |
| 150 |
|
|
//performs the "difference" operation from set theory, the output range contains a copy of every |
| 151 |
|
|
//element that is contained in [allAtoms.begin(), allAtoms.end()) and not contained in |
| 152 |
|
|
//[rigidAtoms.begin(), rigidAtoms.end()). |
| 153 |
|
|
//std::set_difference(allAtoms.begin(), allAtoms.end(), rigidAtoms.begin(), rigidAtoms.end(), |
| 154 |
|
|
// std::back_inserter(integrableObjects_)); |
| 155 |
gezelter |
2 |
|
| 156 |
gezelter |
246 |
//if (integrableObjects_.size() != allAtoms.size() - rigidAtoms.size()) { |
| 157 |
|
|
// //Some atoms in rigidAtoms are not in allAtoms, something must be wrong |
| 158 |
|
|
// sprintf(painCave.errMsg, "Atoms in rigidbody are not in the atom list of the same molecule"); |
| 159 |
|
|
// |
| 160 |
|
|
// painCave.isFatal = 1; |
| 161 |
|
|
// simError(); |
| 162 |
|
|
//} |
| 163 |
gezelter |
2 |
|
| 164 |
gezelter |
246 |
integrableObjects_.insert(integrableObjects_.end(), rigidBodies_.begin(), rigidBodies_.end()); |
| 165 |
gezelter |
2 |
} |
| 166 |
|
|
|
| 167 |
gezelter |
246 |
double Molecule::getMass() { |
| 168 |
|
|
StuntDouble* sd; |
| 169 |
|
|
std::vector<StuntDouble*>::iterator i; |
| 170 |
|
|
double mass = 0.0; |
| 171 |
gezelter |
2 |
|
| 172 |
gezelter |
246 |
for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
| 173 |
|
|
mass += sd->getMass(); |
| 174 |
|
|
} |
| 175 |
gezelter |
2 |
|
| 176 |
gezelter |
246 |
return mass; |
| 177 |
gezelter |
2 |
|
| 178 |
|
|
} |
| 179 |
|
|
|
| 180 |
gezelter |
246 |
Vector3d Molecule::getCom() { |
| 181 |
|
|
StuntDouble* sd; |
| 182 |
|
|
std::vector<StuntDouble*>::iterator i; |
| 183 |
|
|
Vector3d com; |
| 184 |
|
|
double totalMass = 0; |
| 185 |
|
|
double mass; |
| 186 |
|
|
|
| 187 |
|
|
for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
| 188 |
|
|
mass = sd->getMass(); |
| 189 |
|
|
totalMass += mass; |
| 190 |
|
|
com += sd->getPos() * mass; |
| 191 |
gezelter |
2 |
} |
| 192 |
|
|
|
| 193 |
gezelter |
246 |
com /= totalMass; |
| 194 |
gezelter |
2 |
|
| 195 |
gezelter |
246 |
return com; |
| 196 |
|
|
} |
| 197 |
gezelter |
2 |
|
| 198 |
gezelter |
246 |
void Molecule::moveCom(const Vector3d& delta) { |
| 199 |
|
|
StuntDouble* sd; |
| 200 |
|
|
std::vector<StuntDouble*>::iterator i; |
| 201 |
|
|
|
| 202 |
|
|
for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
| 203 |
|
|
sd->setPos(sd->getPos() + delta); |
| 204 |
gezelter |
2 |
} |
| 205 |
|
|
|
| 206 |
|
|
} |
| 207 |
|
|
|
| 208 |
gezelter |
246 |
Vector3d Molecule::getComVel() { |
| 209 |
|
|
StuntDouble* sd; |
| 210 |
|
|
std::vector<StuntDouble*>::iterator i; |
| 211 |
|
|
Vector3d velCom; |
| 212 |
|
|
double totalMass = 0; |
| 213 |
|
|
double mass; |
| 214 |
|
|
|
| 215 |
|
|
for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){ |
| 216 |
|
|
mass = sd->getMass(); |
| 217 |
|
|
totalMass += mass; |
| 218 |
|
|
velCom += sd->getVel() * mass; |
| 219 |
|
|
} |
| 220 |
gezelter |
2 |
|
| 221 |
gezelter |
246 |
velCom /= totalMass; |
| 222 |
gezelter |
2 |
|
| 223 |
gezelter |
246 |
return velCom; |
| 224 |
|
|
} |
| 225 |
gezelter |
2 |
|
| 226 |
gezelter |
246 |
double Molecule::getPotential() { |
| 227 |
gezelter |
2 |
|
| 228 |
gezelter |
246 |
Bond* bond; |
| 229 |
|
|
Bend* bend; |
| 230 |
|
|
Torsion* torsion; |
| 231 |
|
|
Molecule::BondIterator bondIter;; |
| 232 |
|
|
Molecule::BendIterator bendIter; |
| 233 |
|
|
Molecule::TorsionIterator torsionIter; |
| 234 |
gezelter |
2 |
|
| 235 |
gezelter |
246 |
double potential = 0.0; |
| 236 |
gezelter |
2 |
|
| 237 |
gezelter |
246 |
for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) { |
| 238 |
|
|
potential += bond->getPotential(); |
| 239 |
|
|
} |
| 240 |
gezelter |
2 |
|
| 241 |
gezelter |
246 |
for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) { |
| 242 |
|
|
potential += bend->getPotential(); |
| 243 |
gezelter |
2 |
} |
| 244 |
|
|
|
| 245 |
gezelter |
246 |
for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) { |
| 246 |
|
|
potential += torsion->getPotential(); |
| 247 |
gezelter |
2 |
} |
| 248 |
|
|
|
| 249 |
gezelter |
246 |
return potential; |
| 250 |
gezelter |
2 |
|
| 251 |
|
|
} |
| 252 |
|
|
|
| 253 |
gezelter |
246 |
std::ostream& operator <<(std::ostream& o, Molecule& mol) { |
| 254 |
|
|
o << std::endl; |
| 255 |
|
|
o << "Molecule " << mol.getGlobalIndex() << "has: " << std::endl; |
| 256 |
|
|
o << mol.getNAtoms() << " atoms" << std::endl; |
| 257 |
|
|
o << mol.getNBonds() << " bonds" << std::endl; |
| 258 |
|
|
o << mol.getNBends() << " bends" << std::endl; |
| 259 |
|
|
o << mol.getNTorsions() << " torsions" << std::endl; |
| 260 |
|
|
o << mol.getNRigidBodies() << " rigid bodies" << std::endl; |
| 261 |
|
|
o << mol.getNIntegrableObjects() << "integrable objects" << std::endl; |
| 262 |
|
|
o << mol.getNCutoffGroups() << "cutoff groups" << std::endl; |
| 263 |
|
|
o << mol.getNConstraintPairs() << "constraint pairs" << std::endl; |
| 264 |
|
|
return o; |
| 265 |
|
|
} |
| 266 |
gezelter |
2 |
|
| 267 |
gezelter |
246 |
}//end namespace oopse |