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 1908 by gezelter, Fri Jul 19 21:25:45 2013 UTC vs.
Revision 2054 by gezelter, Tue Jan 13 20:14:57 2015 UTC

# Line 53 | 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,
# Line 145 | Line 146 | namespace OpenMD {
146      
147      std::set<Atom*> rigidAtoms;
148      Atom* atom;
149 <    AtomIterator ai;
149 >    Atom* atom1;
150 >    Atom* atom2;
151 >    AtomIterator ai, aj;
152      RigidBody* rb;
153      RigidBodyIterator rbIter;
154 +    Bond* bond;
155 +    BondIterator bi;
156  
157      // Get list of all the atoms that are part of rigid bodies
158  
# Line 182 | Line 187 | namespace OpenMD {
187          fluctuatingCharges_.push_back( atom );      
188      }
189  
185  }
190  
191 +    // find the electronegative atoms and add them to the
192 +    // hBondAcceptors_ vector:
193 +    
194 +    for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
195 +      AtomType* at = atom->getAtomType();
196 +      // get the chain of base types for this atom type:
197 +      std::vector<AtomType*> ayb = at->allYourBase();
198 +      // use the last type in the chain of base types for the name:
199 +      std::string bn = UpperCase(ayb[ayb.size()-1]->getName());
200 +
201 +        if (bn.compare("O")==0 || bn.compare("N")==0
202 +            || bn.compare("F")==0)
203 +          hBondAcceptors_.push_back( atom );
204 +      
205 +    }
206 +    
207 +    // find electronegative atoms that are either bonded to
208 +    // hydrogens or are present in the same rigid bodies:
209 +    
210 +    for (bond = beginBond(bi); bond != NULL; bond = nextBond(bi)) {
211 +      Atom* atom1 = bond->getAtomA();
212 +      Atom* atom2 = bond->getAtomB();
213 +      AtomType* at1 = atom1->getAtomType();
214 +      AtomType* at2 = atom1->getAtomType();
215 +      // get the chain of base types for this atom type:
216 +      std::vector<AtomType*> ayb1 = at1->allYourBase();
217 +      std::vector<AtomType*> ayb2 = at2->allYourBase();
218 +      // use the last type in the chain of base types for the name:
219 +      std::string bn1 = UpperCase(ayb1[ayb1.size()-1]->getName());
220 +      std::string bn2 = UpperCase(ayb2[ayb2.size()-1]->getName());
221 +      
222 +      if (bn1.compare("H")==0) {
223 +        if (bn2.compare("O")==0 || bn2.compare("N")==0
224 +            || bn2.compare("F")==0) {
225 +          HBondDonor* donor = new HBondDonor();
226 +          donor->donorAtom = atom2;
227 +          donor->donatedHydrogen = atom1;
228 +          hBondDonors_.push_back( donor );
229 +        }
230 +      }
231 +      if (bn2.compare("H")==0) {
232 +        if (bn1.compare("O")==0 || bn1.compare("N")==0
233 +            || bn1.compare("F")==0) {
234 +          HBondDonor* donor = new HBondDonor();
235 +          donor->donorAtom = atom1;
236 +          donor->donatedHydrogen = atom2;
237 +            hBondDonors_.push_back( donor );
238 +        }
239 +      }
240 +    }
241 +    
242 +    for (rb = beginRigidBody(rbIter); rb != NULL;
243 +         rb = nextRigidBody(rbIter)) {
244 +      for(atom1 = rb->beginAtom(ai); atom1 != NULL;
245 +          atom1 = rb->nextAtom(ai)) {
246 +        AtomType* at1 = atom1->getAtomType();
247 +        // get the chain of base types for this atom type:
248 +        std::vector<AtomType*> ayb1 = at1->allYourBase();
249 +        // use the last type in the chain of base types for the name:
250 +        std::string bn1 = UpperCase(ayb1[ayb1.size()-1]->getName());
251 +        
252 +        if (bn1.compare("O")==0 || bn1.compare("N")==0
253 +            || bn1.compare("F")==0) {
254 +          for(atom2 = rb->beginAtom(aj); atom2 != NULL;
255 +              atom2 = rb->nextAtom(aj)) {
256 +            AtomType* at2 = atom2->getAtomType();
257 +            // get the chain of base types for this atom type:              
258 +            std::vector<AtomType*> ayb2 = at2->allYourBase();
259 +            // use the last type in the chain of base types for the name:
260 +            std::string bn2 = UpperCase(ayb2[ayb2.size()-1]->getName());
261 +            if (bn2.compare("H")==0) {              
262 +              HBondDonor* donor = new HBondDonor();
263 +              donor->donorAtom = atom1;
264 +              donor->donatedHydrogen = atom2;
265 +              hBondDonors_.push_back( donor );
266 +            }
267 +          }
268 +        }
269 +      }
270 +    }
271 +  }
272 +  
273    RealType Molecule::getMass() {
274      StuntDouble* sd;
275      std::vector<StuntDouble*>::iterator i;
# Line 215 | Line 301 | namespace OpenMD {
301  
302      return com;
303    }
304 +  
305 +  Vector3d Molecule::getCom(int snapshotNo) {
306 +    StuntDouble* sd;
307 +    std::vector<StuntDouble*>::iterator i;
308 +    Vector3d com;
309 +    RealType totalMass = 0;
310 +    RealType mass;
311 +    
312 +    for (sd = beginIntegrableObject(i); sd != NULL; sd =
313 +           nextIntegrableObject(i)){
314 +      mass = sd->getMass();
315 +      totalMass += mass;
316 +      com += sd->getPos(snapshotNo) * mass;    
317 +    }
318 +    
319 +    com /= totalMass;
320  
321 +    return com;
322 +  }
323 +
324    void Molecule::moveCom(const Vector3d& delta) {
325      StuntDouble* sd;
326      std::vector<StuntDouble*>::iterator i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines