60#include "utils/simError.h"
63 Molecule::Molecule(
int stampId,
int globalIndex,
const std::string& molName,
65 globalIndex_(globalIndex),
66 stampId_(stampId), region_(region), moleculeName_(molName),
67 constrainTotalCharge_(false) {}
69 Molecule::~Molecule() {
70 Utils::deletePointers(atoms_);
71 Utils::deletePointers(bonds_);
72 Utils::deletePointers(bends_);
73 Utils::deletePointers(torsions_);
74 Utils::deletePointers(inversions_);
75 Utils::deletePointers(rigidBodies_);
76 Utils::deletePointers(cutoffGroups_);
77 Utils::deletePointers(constraintPairs_);
78 Utils::deletePointers(constraintElems_);
79 Utils::deletePointers(hBondDonors_);
82 integrableObjects_.clear();
83 fluctuatingCharges_.clear();
86 void Molecule::addAtom(
Atom* atom) {
87 if (std::find(atoms_.begin(), atoms_.end(), atom) == atoms_.end()) {
88 atoms_.push_back(atom);
92 void Molecule::addBond(
Bond* bond) {
93 if (std::find(bonds_.begin(), bonds_.end(), bond) == bonds_.end()) {
94 bonds_.push_back(bond);
98 void Molecule::addBend(
Bend* bend) {
99 if (std::find(bends_.begin(), bends_.end(), bend) == bends_.end()) {
100 bends_.push_back(bend);
105 if (std::find(torsions_.begin(), torsions_.end(), torsion) ==
107 torsions_.push_back(torsion);
112 if (std::find(inversions_.begin(), inversions_.end(), inversion) ==
114 inversions_.push_back(inversion);
119 if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) ==
120 rigidBodies_.end()) {
121 rigidBodies_.push_back(rb);
126 if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) ==
127 cutoffGroups_.end()) {
128 cutoffGroups_.push_back(cp);
133 if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) ==
134 constraintPairs_.end()) {
135 constraintPairs_.push_back(cp);
139 void Molecule::addConstraintElem(ConstraintElem* cp) {
140 if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) ==
141 constraintElems_.end()) {
142 constraintElems_.push_back(cp);
146 void Molecule::complete() {
147 std::set<Atom*> rigidAtoms;
153 RigidBodyIterator rbIter;
159 for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
160 rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter());
166 for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
167 if (rigidAtoms.find(atom) == rigidAtoms.end()) {
171 integrableObjects_.push_back(atom);
177 for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
178 integrableObjects_.push_back(rb);
184 for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
185 if (atom->isFluctuatingCharge()) fluctuatingCharges_.push_back(atom);
191 for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
192 AtomType* at = atom->getAtomType();
194 std::vector<AtomType*> ayb = at->allYourBase();
196 std::string bn =
UpperCase(ayb[ayb.size() - 1]->getName());
198 if (bn.compare(
"O") == 0 || bn.compare(
"N") == 0 || bn.compare(
"F") == 0)
199 hBondAcceptors_.push_back(atom);
205 for (bond = beginBond(bi); bond != NULL; bond = nextBond(bi)) {
206 Atom* atom1 = bond->getAtomA();
207 Atom* atom2 = bond->getAtomB();
208 AtomType* at1 = atom1->getAtomType();
209 AtomType* at2 = atom2->getAtomType();
211 std::vector<AtomType*> ayb1 = at1->allYourBase();
212 std::vector<AtomType*> ayb2 = at2->allYourBase();
214 std::string bn1 =
UpperCase(ayb1[ayb1.size() - 1]->getName());
215 std::string bn2 =
UpperCase(ayb2[ayb2.size() - 1]->getName());
217 if (bn1.compare(
"H") == 0) {
218 if (bn2.compare(
"O") == 0 || bn2.compare(
"N") == 0 ||
219 bn2.compare(
"F") == 0) {
220 HBondDonor* donor =
new HBondDonor();
221 donor->donorAtom = atom2;
222 donor->donatedHydrogen = atom1;
223 hBondDonors_.push_back(donor);
226 if (bn2.compare(
"H") == 0) {
227 if (bn1.compare(
"O") == 0 || bn1.compare(
"N") == 0 ||
228 bn1.compare(
"F") == 0) {
229 HBondDonor* donor =
new HBondDonor();
230 donor->donorAtom = atom1;
231 donor->donatedHydrogen = atom2;
232 hBondDonors_.push_back(donor);
237 for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
238 for (atom1 = rb->beginAtom(ai); atom1 != NULL; atom1 = rb->nextAtom(ai)) {
239 AtomType* at1 = atom1->getAtomType();
241 std::vector<AtomType*> ayb1 = at1->allYourBase();
243 std::string bn1 =
UpperCase(ayb1[ayb1.size() - 1]->getName());
245 if (bn1.compare(
"O") == 0 || bn1.compare(
"N") == 0 ||
246 bn1.compare(
"F") == 0) {
247 for (atom2 = rb->beginAtom(aj); atom2 != NULL;
248 atom2 = rb->nextAtom(aj)) {
249 AtomType* at2 = atom2->getAtomType();
251 std::vector<AtomType*> ayb2 = at2->allYourBase();
253 std::string bn2 =
UpperCase(ayb2[ayb2.size() - 1]->getName());
254 if (bn2.compare(
"H") == 0) {
255 HBondDonor* donor =
new HBondDonor();
256 donor->donorAtom = atom1;
257 donor->donatedHydrogen = atom2;
258 hBondDonors_.push_back(donor);
266 RealType Molecule::getMass() {
268 std::vector<StuntDouble*>::iterator i;
271 for (sd = beginIntegrableObject(i); sd != NULL;
272 sd = nextIntegrableObject(i)) {
281 std::vector<StuntDouble*>::iterator i;
283 RealType totalMass {};
286 for (sd = beginIntegrableObject(i); sd != NULL;
287 sd = nextIntegrableObject(i)) {
300 std::vector<StuntDouble*>::iterator i;
302 RealType totalMass {};
305 for (sd = beginIntegrableObject(i); sd != NULL;
306 sd = nextIntegrableObject(i)) {
309 com += sd->
getPos() * mass;
319 std::vector<StuntDouble*>::iterator i;
321 RealType totalMass {};
324 for (sd = beginIntegrableObject(i); sd != NULL;
325 sd = nextIntegrableObject(i)) {
328 com += sd->
getPos(snapshotNo) * mass;
343 std::vector<StuntDouble*>::iterator i;
345 for (sd = beginIntegrableObject(i); sd != NULL;
346 sd = nextIntegrableObject(i)) {
353 std::vector<StuntDouble*>::iterator i;
355 RealType totalMass = 0;
358 for (sd = beginIntegrableObject(i); sd != NULL;
359 sd = nextIntegrableObject(i)) {
362 velCom += sd->
getVel() * mass;
370 RealType Molecule::getPotential() {
375 Molecule::BondIterator bondIter;
377 Molecule::BendIterator bendIter;
378 Molecule::TorsionIterator torsionIter;
379 Molecule::InversionIterator inversionIter;
381 RealType potential = 0.0;
383 for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) {
384 potential += bond->getPotential();
387 for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) {
388 potential += bend->getPotential();
391 for (torsion = beginTorsion(torsionIter); torsion != NULL;
392 torsion = nextTorsion(torsionIter)) {
393 potential += torsion->getPotential();
396 for (inversion = beginInversion(inversionIter); inversion != NULL;
397 inversion = nextInversion(inversionIter)) {
398 potential += inversion->getPotential();
404 void Molecule::addProperty(std::shared_ptr<GenericData> genData) {
405 properties_.addProperty(genData);
408 void Molecule::removeProperty(
const std::string& propName) {
409 properties_.removeProperty(propName);
412 std::vector<std::string> Molecule::getPropertyNames() {
413 return properties_.getPropertyNames();
416 std::vector<std::shared_ptr<GenericData>> Molecule::getProperties() {
417 return properties_.getProperties();
420 std::shared_ptr<GenericData> Molecule::getPropertyByName(
421 const std::string& propName) {
422 return properties_.getPropertyByName(propName);
425 std::ostream& operator<<(std::ostream& o,
Molecule& mol) {
428 o << mol.
getNAtoms() <<
" atoms" << std::endl;
429 o << mol.
getNBonds() <<
" bonds" << std::endl;
430 o << mol.
getNBends() <<
" bends" << std::endl;
size_t getNIntegrableObjects()
Returns the total number of integrable objects in this molecule.
size_t getNFluctuatingCharges()
Returns the total number of fluctuating charges in this molecule.
size_t getNInversions()
Returns the total number of improper torsions in this molecule.
int getGlobalIndex()
Returns the global index of this molecule.
size_t getNBends()
Returns the total number of bends in this molecule.
size_t getNConstraintPairs()
Returns the total number of constraints in this molecule.
size_t getNAtoms()
Returns the total number of atoms in this molecule.
size_t getNRigidBodies()
Returns the total number of rigid bodies in this molecule.
size_t getNBonds()
Returns the total number of bonds in this molecule.
size_t getNCutoffGroups()
Returns the total number of cutoff groups in this molecule.
size_t getNTorsions()
Returns the total number of torsions in this molecule.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Vector3d getVel()
Returns the current velocity of this stuntDouble.
RealType getMass()
Returns the mass of this stuntDouble.
Vector3d getPos()
Returns the current position of this stuntDouble.
void setPos(const Vector3d &pos)
Sets the current position of this stuntDouble.
Vector3d getPrevPos()
Returns the previous position of this stuntDouble.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string UpperCase(const std::string &S)
Converts a string to UPPER CASE.