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

Comparing trunk/src/primitives/Molecule.cpp (file contents):
Revision 3 by tim, Fri Sep 24 16:27:58 2004 UTC vs.
Revision 1908 by gezelter, Fri Jul 19 21:25:45 2013 UTC

# Line 1 | Line 1
1 < #include <stdlib.h>
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.cpp
45 > * @author    tlin
46 > * @date  10/28/2004
47 > * @version 1.0
48 > */
49  
50 + #include <algorithm>
51 + #include <set>
52  
53   #include "primitives/Molecule.hpp"
54 + #include "utils/MemoryUtils.hpp"
55   #include "utils/simError.h"
56  
57 + namespace OpenMD {
58 +  Molecule::Molecule(int stampId, int globalIndex, const std::string& molName,
59 +                     int region) : stampId_(stampId),
60 +                                   globalIndex_(globalIndex),
61 +                                   moleculeName_(molName),
62 +                                   region_(region),
63 +                                   constrainTotalCharge_(false) {
64 +  }
65 +  
66 +  Molecule::~Molecule() {
67 +    
68 +    MemoryUtils::deletePointers(atoms_);
69 +    MemoryUtils::deletePointers(bonds_);
70 +    MemoryUtils::deletePointers(bends_);
71 +    MemoryUtils::deletePointers(torsions_);
72 +    MemoryUtils::deletePointers(inversions_);
73 +    MemoryUtils::deletePointers(rigidBodies_);
74 +    MemoryUtils::deletePointers(cutoffGroups_);
75 +    MemoryUtils::deletePointers(constraintPairs_);
76 +    MemoryUtils::deletePointers(constraintElems_);
77  
78 <
79 < Molecule::Molecule( void ){
80 <
81 <  myAtoms = NULL;
82 <  myBonds = NULL;
13 <  myBends = NULL;
14 <  myTorsions = NULL;
15 < }
16 <
17 < Molecule::~Molecule( void ){
18 <  int i;
19 <  CutoffGroup* cg;
20 <  vector<CutoffGroup*>::iterator iter;
78 >    // integrableObjects_ don't own the objects
79 >    integrableObjects_.clear();
80 >    fluctuatingCharges_.clear();
81 >    
82 >  }
83    
84 <  if( myAtoms != NULL ){
85 <    for(i=0; i<nAtoms; i++) if(myAtoms[i] != NULL ) delete myAtoms[i];
86 <    delete[] myAtoms;
84 >  void Molecule::addAtom(Atom* atom) {
85 >    if (std::find(atoms_.begin(), atoms_.end(), atom) == atoms_.end()) {
86 >      atoms_.push_back(atom);
87 >    }
88    }
89 <
90 <  if( myBonds != NULL ){
91 <    for(i=0; i<nBonds; i++) if(myBonds[i] != NULL ) delete myBonds[i];
92 <    delete[] myBonds;
89 >  
90 >  void Molecule::addBond(Bond* bond) {
91 >    if (std::find(bonds_.begin(), bonds_.end(), bond) == bonds_.end()) {
92 >      bonds_.push_back(bond);
93 >    }
94    }
95 <
96 <  if( myBends != NULL ){
97 <    for(i=0; i<nBends; i++) if(myBends[i] != NULL ) delete myBends[i];
98 <    delete[] myBends;
95 >  
96 >  void Molecule::addBend(Bend* bend) {
97 >    if (std::find(bends_.begin(), bends_.end(), bend) == bends_.end()) {
98 >      bends_.push_back(bend);
99 >    }
100    }
101 <
102 <  if( myTorsions != NULL ){
103 <    for(i=0; i<nTorsions; i++) if(myTorsions[i] != NULL ) delete myTorsions[i];
104 <    delete[] myTorsions;
101 >  
102 >  void Molecule::addTorsion(Torsion* torsion) {
103 >    if (std::find(torsions_.begin(), torsions_.end(), torsion) ==
104 >        torsions_.end()) {
105 >      torsions_.push_back(torsion);
106 >    }
107    }
108  
109 <  for(cg = beginCutoffGroup(iter);  cg != NULL; cg = nextCutoffGroup(iter))
110 <    delete cg;
111 <  myCutoffGroups.clear();
109 >  void Molecule::addInversion(Inversion* inversion) {
110 >    if (std::find(inversions_.begin(), inversions_.end(), inversion) ==
111 >        inversions_.end()) {
112 >      inversions_.push_back(inversion);
113 >    }
114 >  }
115    
116 < }
117 <
118 <
119 < void Molecule::initialize( molInit &theInit ){
120 <
121 <  CutoffGroup* curCutoffGroup;
52 <  vector<CutoffGroup*>::iterator iterCutoff;
53 <  Atom* cutoffAtom;
54 <  vector<Atom*>::iterator iterAtom;
55 <  int atomIndex;
116 >  void Molecule::addRigidBody(RigidBody *rb) {
117 >    if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) ==
118 >        rigidBodies_.end()) {
119 >      rigidBodies_.push_back(rb);
120 >    }
121 >  }
122    
123 <  nAtoms = theInit.nAtoms;
124 <  nMembers = nAtoms;
125 <  nBonds = theInit.nBonds;
126 <  nBends = theInit.nBends;
127 <  nTorsions = theInit.nTorsions;
128 <  nRigidBodies = theInit.nRigidBodies;
63 <  nOriented = theInit.nOriented;
64 <
65 <  myAtoms = theInit.myAtoms;
66 <  myBonds = theInit.myBonds;
67 <  myBends = theInit.myBends;
68 <  myTorsions = theInit.myTorsions;
69 <  myRigidBodies = theInit.myRigidBodies;
70 <
71 <  myIntegrableObjects = theInit.myIntegrableObjects;
72 <
73 <  for (int i = 0; i < myRigidBodies.size(); i++)
74 <      myRigidBodies[i]->calcRefCoords();
75 <
76 <  myCutoffGroups = theInit.myCutoffGroups;
77 <  nCutoffGroups = myCutoffGroups.size();
78 <
79 < }
80 <
81 < void Molecule::calcForces( void ){
123 >  void Molecule::addCutoffGroup(CutoffGroup* cp) {
124 >    if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) ==
125 >        cutoffGroups_.end()) {
126 >      cutoffGroups_.push_back(cp);
127 >    }    
128 >  }
129    
130 <  int i;
131 <  double com[3];
132 <
133 <  for(i=0; i<myRigidBodies.size(); i++) {
134 <    myRigidBodies[i]->updateAtoms();
130 >  void Molecule::addConstraintPair(ConstraintPair* cp) {
131 >    if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) ==
132 >        constraintPairs_.end()) {
133 >      constraintPairs_.push_back(cp);
134 >    }    
135    }
136 <
137 <  for(i=0; i<nBonds; i++){
138 <    myBonds[i]->calc_forces();
136 >  
137 >  void Molecule::addConstraintElem(ConstraintElem* cp) {
138 >    if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) ==
139 >        constraintElems_.end()) {
140 >      constraintElems_.push_back(cp);
141 >    }
142    }
143 +  
144 +  void Molecule::complete() {
145 +    
146 +    std::set<Atom*> rigidAtoms;
147 +    Atom* atom;
148 +    AtomIterator ai;
149 +    RigidBody* rb;
150 +    RigidBodyIterator rbIter;
151  
152 <  for(i=0; i<nBends; i++){
95 <    myBends[i]->calc_forces();
96 <  }
152 >    // Get list of all the atoms that are part of rigid bodies
153  
154 <  for(i=0; i<nTorsions; i++){
155 <    myTorsions[i]->calc_forces();
156 <  }
154 >    for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
155 >      rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter());
156 >    }
157 >    
158 >    // add any atom that wasn't part of a rigid body to the list of integrableObjects
159  
160 <  // Rigid Body forces and torques are done after the fortran force loop
160 >    for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
161 >      
162 >      if (rigidAtoms.find(atom) == rigidAtoms.end()) {
163  
164 < }
164 >        // If an atom does not belong to a rigid body, it is an
165 >        // integrable object
166  
167 +        integrableObjects_.push_back(atom);
168 +      }
169 +    }
170 +    
171 +    // then add the rigid bodies themselves to the integrableObjects
172  
173 < double Molecule::getPotential( void ){
174 <  
175 <  int i;
110 <  double myPot = 0.0;
173 >    for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
174 >      integrableObjects_.push_back(rb);
175 >    }
176  
177 <  for(i=0; i<myRigidBodies.size(); i++) {
178 <    myRigidBodies[i]->updateAtoms();
114 <  }
115 <  
116 <  for(i=0; i<nBonds; i++){
117 <    myPot += myBonds[i]->get_potential();
118 <  }
177 >    // find the atoms that are fluctuating charges and add them to the
178 >    // fluctuatingCharges_ vector
179  
180 <  for(i=0; i<nBends; i++){
181 <    myPot += myBends[i]->get_potential();
180 >    for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
181 >      if ( atom->isFluctuatingCharge() )
182 >        fluctuatingCharges_.push_back( atom );      
183 >    }
184 >
185    }
186  
187 <  for(i=0; i<nTorsions; i++){
188 <    myPot += myTorsions[i]->get_potential();
187 >  RealType Molecule::getMass() {
188 >    StuntDouble* sd;
189 >    std::vector<StuntDouble*>::iterator i;
190 >    RealType mass = 0.0;
191 >    
192 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
193 >           nextIntegrableObject(i)){
194 >      mass += sd->getMass();
195 >    }
196 >    
197 >    return mass;    
198    }
199  
200 <  return myPot;
201 < }
200 >  Vector3d Molecule::getCom() {
201 >    StuntDouble* sd;
202 >    std::vector<StuntDouble*>::iterator i;
203 >    Vector3d com;
204 >    RealType totalMass = 0;
205 >    RealType mass;
206 >    
207 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
208 >           nextIntegrableObject(i)){
209 >      mass = sd->getMass();
210 >      totalMass += mass;
211 >      com += sd->getPos() * mass;    
212 >    }
213 >    
214 >    com /= totalMass;
215  
216 < void Molecule::printMe( void ){
132 <  
133 <  int i;
134 <
135 <  for(i=0; i<nBonds; i++){
136 <    myBonds[i]->printMe();
216 >    return com;
217    }
218  
219 <  for(i=0; i<nBends; i++){
220 <    myBends[i]->printMe();
219 >  void Molecule::moveCom(const Vector3d& delta) {
220 >    StuntDouble* sd;
221 >    std::vector<StuntDouble*>::iterator i;
222 >    
223 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
224 >           nextIntegrableObject(i)){
225 >      sd->setPos(sd->getPos() + delta);
226 >    }    
227    }
228  
229 <  for(i=0; i<nTorsions; i++){
230 <    myTorsions[i]->printMe();
229 >  Vector3d Molecule::getComVel() {
230 >    StuntDouble* sd;
231 >    std::vector<StuntDouble*>::iterator i;
232 >    Vector3d velCom;
233 >    RealType totalMass = 0;
234 >    RealType mass;
235 >    
236 >    for (sd = beginIntegrableObject(i); sd != NULL; sd =
237 >           nextIntegrableObject(i)){
238 >      mass = sd->getMass();
239 >      totalMass += mass;
240 >      velCom += sd->getVel() * mass;    
241 >    }
242 >    
243 >    velCom /= totalMass;
244 >    
245 >    return velCom;
246    }
247  
248 < }
248 >  RealType Molecule::getPotential() {
249  
250 < void Molecule::moveCOM(double delta[3]){
251 <  double aPos[3];
252 <  int i, j;
250 >    Bond* bond;
251 >    Bend* bend;
252 >    Torsion* torsion;
253 >    Inversion* inversion;
254 >    Molecule::BondIterator bondIter;;
255 >    Molecule::BendIterator  bendIter;
256 >    Molecule::TorsionIterator  torsionIter;
257 >    Molecule::InversionIterator  inversionIter;
258  
259 <  for(i=0; i<myIntegrableObjects.size(); i++) {
154 <    if(myIntegrableObjects[i] != NULL ) {
155 <      
156 <      myIntegrableObjects[i]->getPos( aPos );
157 <      
158 <      for (j=0; j< 3; j++)
159 <        aPos[j] += delta[j];
259 >    RealType potential = 0.0;
260  
261 <      myIntegrableObjects[i]->setPos( aPos );
261 >    for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) {
262 >      potential += bond->getPotential();
263      }
163  }
264  
265 <  for(i=0; i<myRigidBodies.size(); i++) {
265 >    for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) {
266 >      potential += bend->getPotential();
267 >    }
268  
269 <      myRigidBodies[i]->getPos( aPos );
270 <
271 <      for (j=0; j< 3; j++)
170 <        aPos[j] += delta[j];
171 <      
172 <      myRigidBodies[i]->setPos( aPos );
269 >    for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion =
270 >           nextTorsion(torsionIter)) {
271 >      potential += torsion->getPotential();
272      }
273 < }
273 >    
274 >    for (inversion = beginInversion(inversionIter); torsion != NULL;
275 >         inversion =  nextInversion(inversionIter)) {
276 >      potential += inversion->getPotential();
277 >    }
278 >    
279 >    return potential;
280 >    
281 >  }
282 >  
283 >  void Molecule::addProperty(GenericData* genData) {
284 >    properties_.addProperty(genData);  
285 >  }
286  
287 < void Molecule::atoms2rigidBodies( void ) {
288 <  int i;
178 <  for (i = 0; i < myRigidBodies.size(); i++) {
179 <    myRigidBodies[i]->calcForcesAndTorques();  
287 >  void Molecule::removeProperty(const std::string& propName) {
288 >    properties_.removeProperty(propName);  
289    }
181 }
290  
291 < void Molecule::getCOM( double COM[3] ) {
291 >  void Molecule::clearProperties() {
292 >    properties_.clearProperties();
293 >  }
294  
295 <  double mass, mtot;
296 <  double aPos[3];
297 <  int i, j;
188 <
189 <  for (j=0; j<3; j++)
190 <    COM[j] = 0.0;
191 <
192 <  mtot   = 0.0;
193 <
194 <  for (i=0; i < myIntegrableObjects.size(); i++) {
195 <    if (myIntegrableObjects[i] != NULL) {
196 <
197 <      mass = myIntegrableObjects[i]->getMass();
198 <      mtot   += mass;
295 >  std::vector<std::string> Molecule::getPropertyNames() {
296 >    return properties_.getPropertyNames();  
297 >  }
298        
299 <      myIntegrableObjects[i]->getPos( aPos );
300 <
202 <      for( j = 0; j < 3; j++)
203 <        COM[j] += aPos[j] * mass;
204 <
205 <    }
299 >  std::vector<GenericData*> Molecule::getProperties() {
300 >    return properties_.getProperties();
301    }
302  
303 <  for (j = 0; j < 3; j++)
304 <    COM[j] /= mtot;
210 < }
211 <
212 < double Molecule::getCOMvel( double COMvel[3] ) {
213 <
214 <  double mass, mtot;
215 <  double aVel[3];
216 <  int i, j;
217 <
218 <
219 <  for (j=0; j<3; j++)
220 <    COMvel[j] = 0.0;
221 <
222 <  mtot   = 0.0;
223 <
224 <  for (i=0; i < myIntegrableObjects.size(); i++) {
225 <    if (myIntegrableObjects[i] != NULL) {
226 <
227 <      mass = myIntegrableObjects[i]->getMass();
228 <      mtot   += mass;
229 <
230 <      myIntegrableObjects[i]->getVel(aVel);
231 <
232 <      for (j=0; j<3; j++)
233 <        COMvel[j] += aVel[j]*mass;
234 <
235 <    }
303 >  GenericData* Molecule::getPropertyByName(const std::string& propName) {
304 >    return properties_.getPropertyByName(propName);
305    }
306  
307 <  for (j=0; j<3; j++)
308 <    COMvel[j] /= mtot;
309 <
310 <  return mtot;
311 <
312 < }
313 <
314 < double Molecule::getTotalMass()
315 < {
316 <
317 <  double totalMass;
318 <  
319 <  totalMass = 0;
320 <  for(int i =0; i < myIntegrableObjects.size(); i++){
252 <    totalMass += myIntegrableObjects[i]->getMass();
307 >  std::ostream& operator <<(std::ostream& o, Molecule& mol) {
308 >    o << std::endl;
309 >    o << "Molecule " << mol.getGlobalIndex() << "has: " << std::endl;
310 >    o << mol.getNAtoms() << " atoms" << std::endl;
311 >    o << mol.getNBonds() << " bonds" << std::endl;
312 >    o << mol.getNBends() << " bends" << std::endl;
313 >    o << mol.getNTorsions() << " torsions" << std::endl;
314 >    o << mol.getNInversions() << " inversions" << std::endl;
315 >    o << mol.getNRigidBodies() << " rigid bodies" << std::endl;
316 >    o << mol.getNIntegrableObjects() << " integrable objects" << std::endl;
317 >    o << mol.getNCutoffGroups() << " cutoff groups" << std::endl;
318 >    o << mol.getNConstraintPairs() << " constraint pairs" << std::endl;
319 >    o << mol.getNFluctuatingCharges() << " fluctuating charges" << std::endl;
320 >    return o;
321    }
322 <
323 <  return totalMass;
256 < }
322 >  
323 > }//end namespace OpenMD

Comparing trunk/src/primitives/Molecule.cpp (property svn:keywords):
Revision 3 by tim, Fri Sep 24 16:27:58 2004 UTC vs.
Revision 1908 by gezelter, Fri Jul 19 21:25:45 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines