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 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 35 | Line 35
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]  Vardeman & Gezelter, in progress (2009).                        
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   /**
# Line 52 | Line 53
53   #include "primitives/Molecule.hpp"
54   #include "utils/MemoryUtils.hpp"
55   #include "utils/simError.h"
56 + #include "utils/StringUtils.hpp"
57  
58   namespace OpenMD {
59 <  Molecule::Molecule(int stampId, int globalIndex, const std::string& molName)
60 <    : stampId_(stampId), globalIndex_(globalIndex), moleculeName_(molName) {
59 >  Molecule::Molecule(int stampId, int globalIndex, const std::string& molName,
60 >                     int region) :
61 >                                   globalIndex_(globalIndex),
62 >                                   stampId_(stampId),
63 >                                   region_(region),
64 >                                   moleculeName_(molName),
65 >                                   constrainTotalCharge_(false) {
66    }
67    
68    Molecule::~Molecule() {
# Line 69 | Line 76 | namespace OpenMD {
76      MemoryUtils::deletePointers(cutoffGroups_);
77      MemoryUtils::deletePointers(constraintPairs_);
78      MemoryUtils::deletePointers(constraintElems_);
79 +
80      // integrableObjects_ don't own the objects
81      integrableObjects_.clear();
82 +    fluctuatingCharges_.clear();
83      
84    }
85    
# Line 137 | Line 146 | namespace OpenMD {
146    void Molecule::complete() {
147      
148      std::set<Atom*> rigidAtoms;
149 +    Atom* atom;
150 +    Atom* atom1;
151 +    Atom* atom2;
152 +    AtomIterator ai, aj;
153      RigidBody* rb;
154 <    std::vector<RigidBody*>::iterator rbIter;
154 >    RigidBodyIterator rbIter;
155 >    Bond* bond;
156 >    BondIterator bi;
157  
158 <    
158 >    // Get list of all the atoms that are part of rigid bodies
159 >
160      for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
161        rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter());
162      }
163      
164 <    Atom* atom;
165 <    AtomIterator ai;
164 >    // add any atom that wasn't part of a rigid body to the list of integrableObjects
165 >
166      for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
167        
168 <      if (rigidAtoms.find(*ai) == rigidAtoms.end()) {
168 >      if (rigidAtoms.find(atom) == rigidAtoms.end()) {
169  
170          // If an atom does not belong to a rigid body, it is an
171          // integrable object
172  
173 <        integrableObjects_.push_back(*ai);
173 >        integrableObjects_.push_back(atom);
174        }
175      }
176      
177 <    //find all free atoms (which do not belong to rigid bodies)  
162 <    // performs the "difference" operation from set theory, the output
163 <    // range contains a copy of every element that is contained in
164 <    // [allAtoms.begin(), allAtoms.end()) and not contained in
165 <    // [rigidAtoms.begin(), rigidAtoms.end()).
166 <    //std::set_difference(allAtoms.begin(), allAtoms.end(), rigidAtoms.begin(), rigidAtoms.end(),
167 <    //                        std::back_inserter(integrableObjects_));
177 >    // then add the rigid bodies themselves to the integrableObjects
178  
169    //if (integrableObjects_.size() != allAtoms.size() - rigidAtoms.size()) {
170    //    //Some atoms in rigidAtoms are not in allAtoms, something must be wrong
171    //    sprintf(painCave.errMsg, "Atoms in rigidbody are not in the atom list of the same molecule");
172    //
173    //    painCave.isFatal = 1;
174    //    simError();        
175    //}
179      for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
180        integrableObjects_.push_back(rb);
181      }
179    //integrableObjects_.insert(integrableObjects_.end(), rigidBodies_.begin(), rigidBodies_.end());
180  }
182  
183 +    // find the atoms that are fluctuating charges and add them to the
184 +    // fluctuatingCharges_ vector
185 +
186 +    for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
187 +      if ( atom->isFluctuatingCharge() )
188 +        fluctuatingCharges_.push_back( atom );      
189 +    }
190 +
191 +
192 +    // find the electronegative atoms and add them to the
193 +    // hBondAcceptors_ vector:
194 +    
195 +    for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
196 +      AtomType* at = atom->getAtomType();
197 +      // get the chain of base types for this atom type:
198 +      std::vector<AtomType*> ayb = at->allYourBase();
199 +      // use the last type in the chain of base types for the name:
200 +      std::string bn = UpperCase(ayb[ayb.size()-1]->getName());
201 +
202 +        if (bn.compare("O")==0 || bn.compare("N")==0
203 +            || bn.compare("F")==0)
204 +          hBondAcceptors_.push_back( atom );
205 +      
206 +    }
207 +    
208 +    // find electronegative atoms that are either bonded to
209 +    // hydrogens or are present in the same rigid bodies:
210 +    
211 +    for (bond = beginBond(bi); bond != NULL; bond = nextBond(bi)) {
212 +      Atom* atom1 = bond->getAtomA();
213 +      Atom* atom2 = bond->getAtomB();
214 +      AtomType* at1 = atom1->getAtomType();
215 +      AtomType* at2 = atom1->getAtomType();
216 +      // get the chain of base types for this atom type:
217 +      std::vector<AtomType*> ayb1 = at1->allYourBase();
218 +      std::vector<AtomType*> ayb2 = at2->allYourBase();
219 +      // use the last type in the chain of base types for the name:
220 +      std::string bn1 = UpperCase(ayb1[ayb1.size()-1]->getName());
221 +      std::string bn2 = UpperCase(ayb2[ayb2.size()-1]->getName());
222 +      
223 +      if (bn1.compare("H")==0) {
224 +        if (bn2.compare("O")==0 || bn2.compare("N")==0
225 +            || bn2.compare("F")==0) {
226 +          HBondDonor* donor = new HBondDonor();
227 +          donor->donorAtom = atom2;
228 +          donor->donatedHydrogen = atom1;
229 +          hBondDonors_.push_back( donor );
230 +        }
231 +      }
232 +      if (bn2.compare("H")==0) {
233 +        if (bn1.compare("O")==0 || bn1.compare("N")==0
234 +            || bn1.compare("F")==0) {
235 +          HBondDonor* donor = new HBondDonor();
236 +          donor->donorAtom = atom1;
237 +          donor->donatedHydrogen = atom2;
238 +            hBondDonors_.push_back( donor );
239 +        }
240 +      }
241 +    }
242 +    
243 +    for (rb = beginRigidBody(rbIter); rb != NULL;
244 +         rb = nextRigidBody(rbIter)) {
245 +      for(atom1 = rb->beginAtom(ai); atom1 != NULL;
246 +          atom1 = rb->nextAtom(ai)) {
247 +        AtomType* at1 = atom1->getAtomType();
248 +        // get the chain of base types for this atom type:
249 +        std::vector<AtomType*> ayb1 = at1->allYourBase();
250 +        // use the last type in the chain of base types for the name:
251 +        std::string bn1 = UpperCase(ayb1[ayb1.size()-1]->getName());
252 +        
253 +        if (bn1.compare("O")==0 || bn1.compare("N")==0
254 +            || bn1.compare("F")==0) {
255 +          for(atom2 = rb->beginAtom(aj); atom2 != NULL;
256 +              atom2 = rb->nextAtom(aj)) {
257 +            AtomType* at2 = atom2->getAtomType();
258 +            // get the chain of base types for this atom type:              
259 +            std::vector<AtomType*> ayb2 = at2->allYourBase();
260 +            // use the last type in the chain of base types for the name:
261 +            std::string bn2 = UpperCase(ayb2[ayb2.size()-1]->getName());
262 +            if (bn2.compare("H")==0) {              
263 +              HBondDonor* donor = new HBondDonor();
264 +              donor->donorAtom = atom1;
265 +              donor->donatedHydrogen = atom2;
266 +              hBondDonors_.push_back( donor );
267 +            }
268 +          }
269 +        }
270 +      }
271 +    }
272 +  }
273 +  
274    RealType Molecule::getMass() {
275      StuntDouble* sd;
276      std::vector<StuntDouble*>::iterator i;
# Line 210 | Line 302 | namespace OpenMD {
302  
303      return com;
304    }
305 +  
306 +  Vector3d Molecule::getCom(int snapshotNo) {
307 +    StuntDouble* sd;
308 +    std::vector<StuntDouble*>::iterator i;
309 +    Vector3d com;
310 +    RealType totalMass = 0;
311 +    RealType mass;
312 +    
313 +    for (sd = beginIntegrableObject(i); sd != NULL; sd =
314 +           nextIntegrableObject(i)){
315 +      mass = sd->getMass();
316 +      totalMass += mass;
317 +      com += sd->getPos(snapshotNo) * mass;    
318 +    }
319 +    
320 +    com /= totalMass;
321  
322 +    return com;
323 +  }
324 +
325    void Molecule::moveCom(const Vector3d& delta) {
326      StuntDouble* sd;
327      std::vector<StuntDouble*>::iterator i;
# Line 299 | Line 410 | namespace OpenMD {
410      return properties_.getPropertyByName(propName);
411    }
412  
302
303
304
413    std::ostream& operator <<(std::ostream& o, Molecule& mol) {
414      o << std::endl;
415      o << "Molecule " << mol.getGlobalIndex() << "has: " << std::endl;
# Line 311 | Line 419 | namespace OpenMD {
419      o << mol.getNTorsions() << " torsions" << std::endl;
420      o << mol.getNInversions() << " inversions" << std::endl;
421      o << mol.getNRigidBodies() << " rigid bodies" << std::endl;
422 <    o << mol.getNIntegrableObjects() << "integrable objects" << std::endl;
423 <    o << mol.getNCutoffGroups() << "cutoff groups" << std::endl;
424 <    o << mol.getNConstraintPairs() << "constraint pairs" << std::endl;
422 >    o << mol.getNIntegrableObjects() << " integrable objects" << std::endl;
423 >    o << mol.getNCutoffGroups() << " cutoff groups" << std::endl;
424 >    o << mol.getNConstraintPairs() << " constraint pairs" << std::endl;
425 >    o << mol.getNFluctuatingCharges() << " fluctuating charges" << std::endl;
426      return o;
427    }
428    

Comparing trunk/src/primitives/Molecule.cpp (property svn:keywords):
Revision 1390 by gezelter, Wed Nov 25 20:02:06 2009 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines