ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/primitives/Molecule.cpp
(Generate patch)

Comparing:
trunk/src/primitives/Molecule.cpp (file contents), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/primitives/Molecule.cpp (file contents), Revision 1715 by gezelter, Tue May 22 21:55:31 2012 UTC

# Line 6 | Line 6
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
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
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.
# Line 37 | Line 28
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, 24107 (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   /**
# Line 53 | Line 54
54   #include "utils/MemoryUtils.hpp"
55   #include "utils/simError.h"
56  
57 < namespace oopse {
57 > namespace OpenMD {
58    Molecule::Molecule(int stampId, int globalIndex, const std::string& molName)
59      : stampId_(stampId), globalIndex_(globalIndex), moleculeName_(molName) {
60 <
61 <    }
61 <
60 >  }
61 >  
62    Molecule::~Molecule() {
63 <
63 >    
64      MemoryUtils::deletePointers(atoms_);
65      MemoryUtils::deletePointers(bonds_);
66      MemoryUtils::deletePointers(bends_);
67      MemoryUtils::deletePointers(torsions_);
68 +    MemoryUtils::deletePointers(inversions_);
69      MemoryUtils::deletePointers(rigidBodies_);
70      MemoryUtils::deletePointers(cutoffGroups_);
71      MemoryUtils::deletePointers(constraintPairs_);
72      MemoryUtils::deletePointers(constraintElems_);
73 <    //integrableObjects_ don't own the objects
73 >
74 >    // integrableObjects_ don't own the objects
75      integrableObjects_.clear();
76 +    fluctuatingCharges_.clear();
77      
78    }
79 <
79 >  
80    void Molecule::addAtom(Atom* atom) {
81      if (std::find(atoms_.begin(), atoms_.end(), atom) == atoms_.end()) {
82        atoms_.push_back(atom);
83      }
84    }
85 <
85 >  
86    void Molecule::addBond(Bond* bond) {
87      if (std::find(bonds_.begin(), bonds_.end(), bond) == bonds_.end()) {
88        bonds_.push_back(bond);
89      }
90    }
91 <
91 >  
92    void Molecule::addBend(Bend* bend) {
93      if (std::find(bends_.begin(), bends_.end(), bend) == bends_.end()) {
94        bends_.push_back(bend);
95      }
96    }
97 <
97 >  
98    void Molecule::addTorsion(Torsion* torsion) {
99 <    if (std::find(torsions_.begin(), torsions_.end(), torsion) == torsions_.end()) {
99 >    if (std::find(torsions_.begin(), torsions_.end(), torsion) ==
100 >        torsions_.end()) {
101        torsions_.push_back(torsion);
102      }
103    }
104  
105 +  void Molecule::addInversion(Inversion* inversion) {
106 +    if (std::find(inversions_.begin(), inversions_.end(), inversion) ==
107 +        inversions_.end()) {
108 +      inversions_.push_back(inversion);
109 +    }
110 +  }
111 +  
112    void Molecule::addRigidBody(RigidBody *rb) {
113 <    if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) == rigidBodies_.end()) {
113 >    if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) ==
114 >        rigidBodies_.end()) {
115        rigidBodies_.push_back(rb);
116      }
117    }
118 <
118 >  
119    void Molecule::addCutoffGroup(CutoffGroup* cp) {
120 <    if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) == cutoffGroups_.end()) {
120 >    if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) ==
121 >        cutoffGroups_.end()) {
122        cutoffGroups_.push_back(cp);
123 <    }
111 <
123 >    }    
124    }
125 <
125 >  
126    void Molecule::addConstraintPair(ConstraintPair* cp) {
127 <    if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) == constraintPairs_.end()) {
127 >    if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) ==
128 >        constraintPairs_.end()) {
129        constraintPairs_.push_back(cp);
130 <    }
118 <
130 >    }    
131    }
132 <
132 >  
133    void Molecule::addConstraintElem(ConstraintElem* cp) {
134 <    if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) == constraintElems_.end()) {
134 >    if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) ==
135 >        constraintElems_.end()) {
136        constraintElems_.push_back(cp);
137      }
125
138    }
139 <
139 >  
140    void Molecule::complete() {
141      
142      std::set<Atom*> rigidAtoms;
143 +    Atom* atom;
144 +    AtomIterator ai;
145      RigidBody* rb;
146 <    std::vector<RigidBody*>::iterator rbIter;
146 >    RigidBodyIterator rbIter;
147  
148 <    
148 >    // Get list of all the atoms that are part of rigid bodies
149 >
150      for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
151        rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter());
152      }
153 +    
154 +    // add any atom that wasn't part of a rigid body to the list of integrableObjects
155  
139    Atom* atom;
140    AtomIterator ai;
156      for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
157 <  
158 <      if (rigidAtoms.find(*ai) == rigidAtoms.end()) {
159 <        //if an atom does not belong to a rigid body, it is an integrable object
160 <        integrableObjects_.push_back(*ai);
157 >      
158 >      if (rigidAtoms.find(atom) == rigidAtoms.end()) {
159 >
160 >        // If an atom does not belong to a rigid body, it is an
161 >        // integrable object
162 >
163 >        integrableObjects_.push_back(atom);
164        }
165      }
166 +    
167 +    // then add the rigid bodies themselves to the integrableObjects
168  
149    //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
156    //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    //}
169      for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
170        integrableObjects_.push_back(rb);
171      }
172 <    //integrableObjects_.insert(integrableObjects_.end(), rigidBodies_.begin(), rigidBodies_.end());
172 >
173 >    // find the atoms that are fluctuating charges and add them to the
174 >    // fluctuatingCharges_ vector
175 >
176 >    for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
177 >      if ( atom->isFluctuatingCharge() )
178 >        fluctuatingCharges_.push_back( atom );      
179 >    }
180 >
181    }
182  
183 <  double Molecule::getMass() {
183 >  RealType Molecule::getMass() {
184      StuntDouble* sd;
185      std::vector<StuntDouble*>::iterator i;
186 <    double mass = 0.0;
187 <
188 <    for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){
186 >    RealType mass = 0.0;
187 >    
188 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
189 >           nextIntegrableObject(i)){
190        mass += sd->getMass();
191      }
192 <
193 <    return mass;
179 <
192 >    
193 >    return mass;    
194    }
195  
196    Vector3d Molecule::getCom() {
197      StuntDouble* sd;
198      std::vector<StuntDouble*>::iterator i;
199      Vector3d com;
200 <    double totalMass = 0;
201 <    double mass;
200 >    RealType totalMass = 0;
201 >    RealType mass;
202      
203 <    for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){
203 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
204 >           nextIntegrableObject(i)){
205        mass = sd->getMass();
206        totalMass += mass;
207        com += sd->getPos() * mass;    
208      }
209 <
209 >    
210      com /= totalMass;
211  
212      return com;
# Line 201 | Line 216 | namespace oopse {
216      StuntDouble* sd;
217      std::vector<StuntDouble*>::iterator i;
218      
219 <    for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){
219 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
220 >           nextIntegrableObject(i)){
221        sd->setPos(sd->getPos() + delta);
222 <    }
207 <
222 >    }    
223    }
224  
225    Vector3d Molecule::getComVel() {
226      StuntDouble* sd;
227      std::vector<StuntDouble*>::iterator i;
228      Vector3d velCom;
229 <    double totalMass = 0;
230 <    double mass;
229 >    RealType totalMass = 0;
230 >    RealType mass;
231      
232 <    for (sd = beginIntegrableObject(i); sd != NULL; sd = nextIntegrableObject(i)){
232 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
233 >           nextIntegrableObject(i)){
234        mass = sd->getMass();
235        totalMass += mass;
236        velCom += sd->getVel() * mass;    
237      }
238 <
238 >    
239      velCom /= totalMass;
240 <
240 >    
241      return velCom;
242    }
243  
244 <  double Molecule::getPotential() {
244 >  RealType Molecule::getPotential() {
245  
246      Bond* bond;
247      Bend* bend;
248      Torsion* torsion;
249 +    Inversion* inversion;
250      Molecule::BondIterator bondIter;;
251      Molecule::BendIterator  bendIter;
252      Molecule::TorsionIterator  torsionIter;
253 +    Molecule::InversionIterator  inversionIter;
254  
255 <    double potential = 0.0;
255 >    RealType potential = 0.0;
256  
257      for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) {
258        potential += bond->getPotential();
# Line 244 | Line 262 | namespace oopse {
262        potential += bend->getPotential();
263      }
264  
265 <    for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) {
265 >    for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion =
266 >           nextTorsion(torsionIter)) {
267        potential += torsion->getPotential();
268      }
269 <
269 >    
270 >    for (inversion = beginInversion(inversionIter); torsion != NULL;
271 >         inversion =  nextInversion(inversionIter)) {
272 >      potential += inversion->getPotential();
273 >    }
274 >    
275      return potential;
276 +    
277 +  }
278 +  
279 +  void Molecule::addProperty(GenericData* genData) {
280 +    properties_.addProperty(genData);  
281 +  }
282  
283 +  void Molecule::removeProperty(const std::string& propName) {
284 +    properties_.removeProperty(propName);  
285    }
286  
287 +  void Molecule::clearProperties() {
288 +    properties_.clearProperties();
289 +  }
290 +
291 +  std::vector<std::string> Molecule::getPropertyNames() {
292 +    return properties_.getPropertyNames();  
293 +  }
294 +      
295 +  std::vector<GenericData*> Molecule::getProperties() {
296 +    return properties_.getProperties();
297 +  }
298 +
299 +  GenericData* Molecule::getPropertyByName(const std::string& propName) {
300 +    return properties_.getPropertyByName(propName);
301 +  }
302 +
303    std::ostream& operator <<(std::ostream& o, Molecule& mol) {
304      o << std::endl;
305      o << "Molecule " << mol.getGlobalIndex() << "has: " << std::endl;
# Line 259 | Line 307 | namespace oopse {
307      o << mol.getNBonds() << " bonds" << std::endl;
308      o << mol.getNBends() << " bends" << std::endl;
309      o << mol.getNTorsions() << " torsions" << std::endl;
310 +    o << mol.getNInversions() << " inversions" << std::endl;
311      o << mol.getNRigidBodies() << " rigid bodies" << std::endl;
312 <    o << mol.getNIntegrableObjects() << "integrable objects" << std::endl;
313 <    o << mol.getNCutoffGroups() << "cutoff groups" << std::endl;
314 <    o << mol.getNConstraintPairs() << "constraint pairs" << std::endl;
312 >    o << mol.getNIntegrableObjects() << " integrable objects" << std::endl;
313 >    o << mol.getNCutoffGroups() << " cutoff groups" << std::endl;
314 >    o << mol.getNConstraintPairs() << " constraint pairs" << std::endl;
315 >    o << mol.getNFluctuatingCharges() << " fluctuating charges" << std::endl;
316      return o;
317    }
318 <
319 < }//end namespace oopse
318 >  
319 > }//end namespace OpenMD

Comparing:
trunk/src/primitives/Molecule.cpp (property svn:keywords), Revision 507 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
branches/development/src/primitives/Molecule.cpp (property svn:keywords), Revision 1715 by gezelter, Tue May 22 21:55:31 2012 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines