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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines