| 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 | /** | 
| 44 | * @file Molecule.hpp | 
| 45 | * @author    tlin | 
| 46 | * @date  10/25/2004 | 
| 47 | * @version 1.0 | 
| 48 | */ | 
| 49 |  | 
| 50 | #ifndef PRIMITIVES_MOLECULE_HPP | 
| 51 | #define PRIMITIVES_MOLECULE_HPP | 
| 52 | #include <vector> | 
| 53 | #include <iostream> | 
| 54 |  | 
| 55 | #include "constraints/ConstraintPair.hpp" | 
| 56 | #include "math/Vector3.hpp" | 
| 57 | #include "primitives/Atom.hpp" | 
| 58 | #include "primitives/RigidBody.hpp" | 
| 59 | #include "primitives/Bond.hpp" | 
| 60 | #include "primitives/Bend.hpp" | 
| 61 | #include "primitives/Torsion.hpp" | 
| 62 | #include "primitives/Inversion.hpp" | 
| 63 | #include "primitives/CutoffGroup.hpp" | 
| 64 | #include "utils/PropertyMap.hpp" | 
| 65 |  | 
| 66 | namespace OpenMD{ | 
| 67 |  | 
| 68 | class Constraint; | 
| 69 |  | 
| 70 | /** | 
| 71 | * @class Molecule Molecule.hpp "primitives/Molecule.hpp" | 
| 72 | * @brief | 
| 73 | */ | 
| 74 | class Molecule { | 
| 75 | public: | 
| 76 |  | 
| 77 | typedef std::vector<Atom*>::iterator AtomIterator; | 
| 78 | typedef std::vector<Bond*>::iterator BondIterator; | 
| 79 | typedef std::vector<Bend*>::iterator BendIterator; | 
| 80 | typedef std::vector<Torsion*>::iterator TorsionIterator; | 
| 81 | typedef std::vector<Inversion*>::iterator InversionIterator; | 
| 82 | typedef std::vector<RigidBody*>::iterator RigidBodyIterator; | 
| 83 | typedef std::vector<CutoffGroup*>::iterator CutoffGroupIterator; | 
| 84 | typedef std::vector<StuntDouble*>::iterator IntegrableObjectIterator; | 
| 85 | typedef std::vector<ConstraintPair*>::iterator ConstraintPairIterator; | 
| 86 | typedef std::vector<ConstraintElem*>::iterator ConstraintElemIterator; | 
| 87 | typedef std::vector<Atom*>::iterator FluctuatingChargeIterator; | 
| 88 |  | 
| 89 | Molecule(int stampId, int globalIndex, const std::string& molName, int region); | 
| 90 | virtual ~Molecule(); | 
| 91 |  | 
| 92 | /** | 
| 93 | * Returns the global index of this molecule. | 
| 94 | * @return  the global index of this molecule | 
| 95 | */ | 
| 96 | int getGlobalIndex() { | 
| 97 | return globalIndex_; | 
| 98 | } | 
| 99 |  | 
| 100 | /** | 
| 101 | * Returns the stamp id of this molecule | 
| 102 | * @note Ideally, every molecule should keep a pointer of its | 
| 103 | * molecule stamp instead of its stamp id. However, the pointer | 
| 104 | * will become invalid, if the molecule migrate to other | 
| 105 | * processor. | 
| 106 | */ | 
| 107 | int getStampId() { | 
| 108 | return stampId_; | 
| 109 | } | 
| 110 | int getRegion() { | 
| 111 | return region_; | 
| 112 | } | 
| 113 |  | 
| 114 | /** Returns the name of the molecule */ | 
| 115 | std::string getType() { | 
| 116 | return moleculeName_; | 
| 117 | } | 
| 118 |  | 
| 119 | /** | 
| 120 | * Sets the global index of this molecule. | 
| 121 | * @param index new global index to be set | 
| 122 | */ | 
| 123 | void setGlobalIndex(int index) { | 
| 124 | globalIndex_ = index; | 
| 125 | } | 
| 126 |  | 
| 127 | void setConstrainTotalCharge(bool ctc) { | 
| 128 | constrainTotalCharge_ = ctc; | 
| 129 | } | 
| 130 |  | 
| 131 | bool constrainTotalCharge() { | 
| 132 | return constrainTotalCharge_; | 
| 133 | } | 
| 134 |  | 
| 135 | /** add an atom into this molecule */ | 
| 136 | void addAtom(Atom* atom); | 
| 137 |  | 
| 138 | /** add a bond into this molecule */ | 
| 139 | void addBond(Bond* bond); | 
| 140 |  | 
| 141 | /** add a bend into this molecule */ | 
| 142 | void addBend(Bend* bend); | 
| 143 |  | 
| 144 | /** add a torsion into this molecule*/ | 
| 145 | void addTorsion(Torsion* torsion); | 
| 146 |  | 
| 147 | /** add an improper torsion into this molecule*/ | 
| 148 | void addInversion(Inversion* inversion); | 
| 149 |  | 
| 150 | /** add a rigidbody into this molecule */ | 
| 151 | void addRigidBody(RigidBody *rb); | 
| 152 |  | 
| 153 | /** add a cutoff group into this molecule */ | 
| 154 | void addCutoffGroup(CutoffGroup* cp); | 
| 155 |  | 
| 156 | void addConstraintPair(ConstraintPair* consPair); | 
| 157 |  | 
| 158 | void addConstraintElem(ConstraintElem* consElem); | 
| 159 |  | 
| 160 | /** */ | 
| 161 | void complete(); | 
| 162 |  | 
| 163 | /** Returns the total number of atoms in this molecule */ | 
| 164 | unsigned int getNAtoms() { | 
| 165 | return atoms_.size(); | 
| 166 | } | 
| 167 |  | 
| 168 | /** Returns the total number of bonds in this molecule */ | 
| 169 | unsigned int getNBonds(){ | 
| 170 | return bonds_.size(); | 
| 171 | } | 
| 172 |  | 
| 173 | /** Returns the total number of bends in this molecule */ | 
| 174 | unsigned int getNBends() { | 
| 175 | return bends_.size(); | 
| 176 | } | 
| 177 |  | 
| 178 | /** Returns the total number of torsions in this molecule */ | 
| 179 | unsigned int getNTorsions() { | 
| 180 | return torsions_.size(); | 
| 181 | } | 
| 182 |  | 
| 183 | /** Returns the total number of improper torsions in this molecule */ | 
| 184 | unsigned int getNInversions() { | 
| 185 | return inversions_.size(); | 
| 186 | } | 
| 187 |  | 
| 188 | /** Returns the total number of rigid bodies in this molecule */ | 
| 189 | unsigned int getNRigidBodies() { | 
| 190 | return rigidBodies_.size(); | 
| 191 | } | 
| 192 |  | 
| 193 | /** Returns the total number of integrable objects in this molecule */ | 
| 194 | unsigned int getNIntegrableObjects() { | 
| 195 | return integrableObjects_.size(); | 
| 196 | } | 
| 197 |  | 
| 198 | /** Returns the total number of cutoff groups in this molecule */ | 
| 199 | unsigned int getNCutoffGroups() { | 
| 200 | return cutoffGroups_.size(); | 
| 201 | } | 
| 202 |  | 
| 203 | /** Returns the total number of constraints in this molecule */ | 
| 204 | unsigned int getNConstraintPairs() { | 
| 205 | return constraintPairs_.size(); | 
| 206 | } | 
| 207 |  | 
| 208 | /** Returns the total number of fluctuating charges in this molecule */ | 
| 209 | unsigned int getNFluctuatingCharges() { | 
| 210 | return fluctuatingCharges_.size(); | 
| 211 | } | 
| 212 |  | 
| 213 | Atom* getAtomAt(unsigned int i) { | 
| 214 | assert(i < atoms_.size()); | 
| 215 | return atoms_[i]; | 
| 216 | } | 
| 217 |  | 
| 218 | RigidBody* getRigidBodyAt(unsigned int i) { | 
| 219 | assert(i < rigidBodies_.size()); | 
| 220 | return rigidBodies_[i]; | 
| 221 | } | 
| 222 |  | 
| 223 | Atom* beginAtom(std::vector<Atom*>::iterator& i) { | 
| 224 | i = atoms_.begin(); | 
| 225 | return (i == atoms_.end()) ? NULL : *i; | 
| 226 | } | 
| 227 |  | 
| 228 | Atom* nextAtom(std::vector<Atom*>::iterator& i) { | 
| 229 | ++i; | 
| 230 | return (i == atoms_.end()) ? NULL : *i; | 
| 231 | } | 
| 232 |  | 
| 233 | Bond* beginBond(std::vector<Bond*>::iterator& i) { | 
| 234 | i = bonds_.begin(); | 
| 235 | return (i == bonds_.end()) ? NULL : *i; | 
| 236 | } | 
| 237 |  | 
| 238 | Bond* nextBond(std::vector<Bond*>::iterator& i) { | 
| 239 | ++i; | 
| 240 | return (i == bonds_.end()) ? NULL : *i; | 
| 241 |  | 
| 242 | } | 
| 243 |  | 
| 244 | Bend* beginBend(std::vector<Bend*>::iterator& i) { | 
| 245 | i = bends_.begin(); | 
| 246 | return (i == bends_.end()) ? NULL : *i; | 
| 247 | } | 
| 248 |  | 
| 249 | Bend* nextBend(std::vector<Bend*>::iterator& i) { | 
| 250 | ++i; | 
| 251 | return (i == bends_.end()) ? NULL : *i; | 
| 252 | } | 
| 253 |  | 
| 254 | Torsion* beginTorsion(std::vector<Torsion*>::iterator& i) { | 
| 255 | i = torsions_.begin(); | 
| 256 | return (i == torsions_.end()) ? NULL : *i; | 
| 257 | } | 
| 258 |  | 
| 259 | Torsion* nextTorsion(std::vector<Torsion*>::iterator& i) { | 
| 260 | ++i; | 
| 261 | return (i == torsions_.end()) ? NULL : *i; | 
| 262 | } | 
| 263 |  | 
| 264 | Inversion* beginInversion(std::vector<Inversion*>::iterator& i) { | 
| 265 | i = inversions_.begin(); | 
| 266 | return (i == inversions_.end()) ? NULL : *i; | 
| 267 | } | 
| 268 |  | 
| 269 | Inversion* nextInversion(std::vector<Inversion*>::iterator& i) { | 
| 270 | ++i; | 
| 271 | return (i == inversions_.end()) ? NULL : *i; | 
| 272 | } | 
| 273 |  | 
| 274 | RigidBody* beginRigidBody(std::vector<RigidBody*>::iterator& i) { | 
| 275 | i = rigidBodies_.begin(); | 
| 276 | return (i == rigidBodies_.end()) ? NULL : *i; | 
| 277 | } | 
| 278 |  | 
| 279 | RigidBody* nextRigidBody(std::vector<RigidBody*>::iterator& i) { | 
| 280 | ++i; | 
| 281 | return (i == rigidBodies_.end()) ? NULL : *i; | 
| 282 | } | 
| 283 |  | 
| 284 | StuntDouble* beginIntegrableObject(std::vector<StuntDouble*>::iterator& i) { | 
| 285 | i = integrableObjects_.begin(); | 
| 286 | return (i == integrableObjects_.end()) ? NULL : *i; | 
| 287 | } | 
| 288 |  | 
| 289 | StuntDouble* nextIntegrableObject(std::vector<StuntDouble*>::iterator& i) { | 
| 290 | ++i; | 
| 291 | return (i == integrableObjects_.end()) ? NULL : *i; | 
| 292 | } | 
| 293 |  | 
| 294 | CutoffGroup* beginCutoffGroup(std::vector<CutoffGroup*>::iterator& i) { | 
| 295 | i = cutoffGroups_.begin(); | 
| 296 | return (i == cutoffGroups_.end()) ? NULL : *i; | 
| 297 | } | 
| 298 |  | 
| 299 | CutoffGroup* nextCutoffGroup(std::vector<CutoffGroup*>::iterator& i) { | 
| 300 | ++i; | 
| 301 | return (i == cutoffGroups_.end()) ? NULL : *i; | 
| 302 | } | 
| 303 |  | 
| 304 | ConstraintPair* beginConstraintPair(std::vector<ConstraintPair*>::iterator& i) { | 
| 305 | i = constraintPairs_.begin(); | 
| 306 | return (i == constraintPairs_.end()) ? NULL : *i; | 
| 307 | } | 
| 308 |  | 
| 309 | ConstraintPair* nextConstraintPair(std::vector<ConstraintPair*>::iterator& i) { | 
| 310 | ++i; | 
| 311 | return (i == constraintPairs_.end()) ? NULL : *i; | 
| 312 | } | 
| 313 |  | 
| 314 | ConstraintElem* beginConstraintElem(std::vector<ConstraintElem*>::iterator& i) { | 
| 315 | i = constraintElems_.begin(); | 
| 316 | return (i == constraintElems_.end()) ? NULL : *i; | 
| 317 | } | 
| 318 |  | 
| 319 | ConstraintElem* nextConstraintElem(std::vector<ConstraintElem*>::iterator& i) { | 
| 320 | ++i; | 
| 321 | return (i == constraintElems_.end()) ? NULL : *i; | 
| 322 | } | 
| 323 |  | 
| 324 | Atom* beginFluctuatingCharge(std::vector<Atom*>::iterator& i) { | 
| 325 | i = fluctuatingCharges_.begin(); | 
| 326 | return (i == fluctuatingCharges_.end()) ? NULL : *i; | 
| 327 | } | 
| 328 |  | 
| 329 | Atom* nextFluctuatingCharge(std::vector<Atom*>::iterator& i) { | 
| 330 | ++i; | 
| 331 | return (i == fluctuatingCharges_.end()) ? NULL : *i; | 
| 332 | } | 
| 333 |  | 
| 334 |  | 
| 335 | /** | 
| 336 | * Returns the total potential energy of short range interaction | 
| 337 | * of this molecule | 
| 338 | */ | 
| 339 | RealType getPotential(); | 
| 340 |  | 
| 341 | /** get total mass of this molecule */ | 
| 342 | RealType getMass(); | 
| 343 |  | 
| 344 | /** return the center of mass of this molecule */ | 
| 345 | Vector3d getCom(); | 
| 346 |  | 
| 347 | /** Moves the center of this molecule */ | 
| 348 | void moveCom(const Vector3d& delta); | 
| 349 |  | 
| 350 | /** Returns the velocity of center of mass of this molecule */ | 
| 351 | Vector3d getComVel(); | 
| 352 |  | 
| 353 | std::string getMoleculeName() { | 
| 354 | return moleculeName_; | 
| 355 | } | 
| 356 |  | 
| 357 | friend std::ostream& operator <<(std::ostream& o, Molecule& mol); | 
| 358 |  | 
| 359 | //below functions are just forward functions | 
| 360 | /** | 
| 361 | * Adds property into property map | 
| 362 | * @param genData GenericData to be added into PropertyMap | 
| 363 | */ | 
| 364 | void addProperty(GenericData* genData); | 
| 365 |  | 
| 366 | /** | 
| 367 | * Removes property from PropertyMap by name | 
| 368 | * @param propName the name of property to be removed | 
| 369 | */ | 
| 370 | void removeProperty(const std::string& propName); | 
| 371 |  | 
| 372 | /** | 
| 373 | * clear all of the properties | 
| 374 | */ | 
| 375 | void clearProperties(); | 
| 376 |  | 
| 377 | /** | 
| 378 | * Returns all names of properties | 
| 379 | * @return all names of properties | 
| 380 | */ | 
| 381 | std::vector<std::string> getPropertyNames(); | 
| 382 |  | 
| 383 | /** | 
| 384 | * Returns all of the properties in PropertyMap | 
| 385 | * @return all of the properties in PropertyMap | 
| 386 | */ | 
| 387 | std::vector<GenericData*> getProperties(); | 
| 388 |  | 
| 389 | /** | 
| 390 | * Returns property | 
| 391 | * @param propName name of property | 
| 392 | * @return a pointer point to property with propName. If no property named propName | 
| 393 | * exists, return NULL | 
| 394 | */ | 
| 395 | GenericData* getPropertyByName(const std::string& propName); | 
| 396 |  | 
| 397 | private: | 
| 398 |  | 
| 399 | int globalIndex_; | 
| 400 |  | 
| 401 | std::vector<Atom*> atoms_; | 
| 402 | std::vector<Bond*> bonds_; | 
| 403 | std::vector<Bend*> bends_; | 
| 404 | std::vector<Torsion*> torsions_; | 
| 405 | std::vector<Inversion*> inversions_; | 
| 406 | std::vector<RigidBody*> rigidBodies_; | 
| 407 | std::vector<StuntDouble*> integrableObjects_; | 
| 408 | std::vector<CutoffGroup*> cutoffGroups_; | 
| 409 | std::vector<ConstraintPair*> constraintPairs_; | 
| 410 | std::vector<ConstraintElem*> constraintElems_; | 
| 411 | std::vector<Atom*> fluctuatingCharges_; | 
| 412 | int stampId_; | 
| 413 | int region_; | 
| 414 | std::string moleculeName_; | 
| 415 | PropertyMap properties_; | 
| 416 | bool constrainTotalCharge_; | 
| 417 |  | 
| 418 | }; | 
| 419 |  | 
| 420 | } //namespace OpenMD | 
| 421 | #endif // |