61#include "types/FixedChargeAdapter.hpp"
64#include "utils/simError.h"
67 Molecule::Molecule(
int globalIndex,
MoleculeStamp* molStamp) :
68 globalIndex_(globalIndex), molStamp_ {molStamp},
69 constrainTotalCharge_(false) {}
71 Molecule::~Molecule() {
72 Utils::deletePointers(atoms_);
73 Utils::deletePointers(bonds_);
74 Utils::deletePointers(bends_);
75 Utils::deletePointers(torsions_);
76 Utils::deletePointers(inversions_);
77 Utils::deletePointers(rigidBodies_);
78 Utils::deletePointers(cutoffGroups_);
79 Utils::deletePointers(constraintPairs_);
80 Utils::deletePointers(constraintElems_);
81 Utils::deletePointers(hBondDonors_);
84 integrableObjects_.clear();
85 fluctuatingCharges_.clear();
89 if (std::find(atoms_.begin(), atoms_.end(), atom) == atoms_.end()) {
90 atoms_.push_back(atom);
95 if (std::find(bonds_.begin(), bonds_.end(), bond) == bonds_.end()) {
96 bonds_.push_back(bond);
101 if (std::find(bends_.begin(), bends_.end(), bend) == bends_.end()) {
102 bends_.push_back(bend);
107 if (std::find(torsions_.begin(), torsions_.end(), torsion) ==
109 torsions_.push_back(torsion);
114 if (std::find(inversions_.begin(), inversions_.end(), inversion) ==
116 inversions_.push_back(inversion);
121 if (std::find(rigidBodies_.begin(), rigidBodies_.end(), rb) ==
122 rigidBodies_.end()) {
123 rigidBodies_.push_back(rb);
128 if (std::find(cutoffGroups_.begin(), cutoffGroups_.end(), cp) ==
129 cutoffGroups_.end()) {
130 cutoffGroups_.push_back(cp);
135 if (std::find(constraintPairs_.begin(), constraintPairs_.end(), cp) ==
136 constraintPairs_.end()) {
137 constraintPairs_.push_back(cp);
141 void Molecule::addConstraintElem(ConstraintElem* cp) {
142 if (std::find(constraintElems_.begin(), constraintElems_.end(), cp) ==
143 constraintElems_.end()) {
144 constraintElems_.push_back(cp);
148 void Molecule::complete() {
149 std::set<Atom*> rigidAtoms;
155 RigidBodyIterator rbIter;
161 for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
162 rigidAtoms.insert(rb->getBeginAtomIter(), rb->getEndAtomIter());
168 for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
169 if (rigidAtoms.find(atom) == rigidAtoms.end()) {
173 integrableObjects_.push_back(atom);
179 for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
180 integrableObjects_.push_back(rb);
186 for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
187 if (atom->isFluctuatingCharge()) fluctuatingCharges_.push_back(atom);
193 for (atom = beginAtom(ai); atom != NULL; atom = nextAtom(ai)) {
194 AtomType* at = atom->getAtomType();
196 std::vector<AtomType*> ayb = at->allYourBase();
198 std::string bn =
UpperCase(ayb[ayb.size() - 1]->getName());
200 if (bn.compare(
"O") == 0 || bn.compare(
"N") == 0 || bn.compare(
"F") == 0)
201 hBondAcceptors_.push_back(atom);
207 for (bond = beginBond(bi); bond != NULL; bond = nextBond(bi)) {
208 Atom* atom1 = bond->getAtomA();
209 Atom* atom2 = bond->getAtomB();
210 AtomType* at1 = atom1->getAtomType();
211 AtomType* at2 = atom2->getAtomType();
213 std::vector<AtomType*> ayb1 = at1->allYourBase();
214 std::vector<AtomType*> ayb2 = at2->allYourBase();
216 std::string bn1 =
UpperCase(ayb1[ayb1.size() - 1]->getName());
217 std::string bn2 =
UpperCase(ayb2[ayb2.size() - 1]->getName());
219 if (bn1.compare(
"H") == 0) {
220 if (bn2.compare(
"O") == 0 || bn2.compare(
"N") == 0 ||
221 bn2.compare(
"F") == 0) {
222 HBondDonor* donor =
new HBondDonor();
223 donor->donorAtom = atom2;
224 donor->donatedHydrogen = atom1;
225 hBondDonors_.push_back(donor);
228 if (bn2.compare(
"H") == 0) {
229 if (bn1.compare(
"O") == 0 || bn1.compare(
"N") == 0 ||
230 bn1.compare(
"F") == 0) {
231 HBondDonor* donor =
new HBondDonor();
232 donor->donorAtom = atom1;
233 donor->donatedHydrogen = atom2;
234 hBondDonors_.push_back(donor);
239 for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) {
240 for (atom1 = rb->beginAtom(ai); atom1 != NULL; atom1 = rb->nextAtom(ai)) {
241 AtomType* at1 = atom1->getAtomType();
243 std::vector<AtomType*> ayb1 = at1->allYourBase();
245 std::string bn1 =
UpperCase(ayb1[ayb1.size() - 1]->getName());
247 if (bn1.compare(
"O") == 0 || bn1.compare(
"N") == 0 ||
248 bn1.compare(
"F") == 0) {
249 for (atom2 = rb->beginAtom(aj); atom2 != NULL;
250 atom2 = rb->nextAtom(aj)) {
251 AtomType* at2 = atom2->getAtomType();
253 std::vector<AtomType*> ayb2 = at2->allYourBase();
255 std::string bn2 =
UpperCase(ayb2[ayb2.size() - 1]->getName());
256 if (bn2.compare(
"H") == 0) {
257 HBondDonor* donor =
new HBondDonor();
258 donor->donorAtom = atom1;
259 donor->donatedHydrogen = atom2;
260 hBondDonors_.push_back(donor);
270 std::vector<StuntDouble*>::iterator i;
273 for (sd = beginIntegrableObject(i); sd != NULL;
274 sd = nextIntegrableObject(i)) {
283 std::vector<Atom*>::iterator i;
286 for (atom = beginAtom(i); atom != NULL; atom = nextAtom(i)) {
290 if (fca.isFixedCharge()) { q += fca.getCharge(); }
298 std::vector<StuntDouble*>::iterator i;
300 RealType totalMass {};
303 for (sd = beginIntegrableObject(i); sd != NULL;
304 sd = nextIntegrableObject(i)) {
317 std::vector<StuntDouble*>::iterator i;
319 RealType totalMass {};
322 for (sd = beginIntegrableObject(i); sd != NULL;
323 sd = nextIntegrableObject(i)) {
326 com += sd->
getPos() * mass;
336 std::vector<StuntDouble*>::iterator i;
338 RealType totalMass {};
341 for (sd = beginIntegrableObject(i); sd != NULL;
342 sd = nextIntegrableObject(i)) {
345 com += sd->
getPos(snapshotNo) * mass;
354 Vector3d delta = newCom -
getCom();
360 std::vector<StuntDouble*>::iterator i;
362 for (sd = beginIntegrableObject(i); sd != NULL;
363 sd = nextIntegrableObject(i)) {
370 std::vector<StuntDouble*>::iterator i;
371 Vector3d velCom(0.0);
372 RealType totalMass = 0;
375 for (sd = beginIntegrableObject(i); sd != NULL;
376 sd = nextIntegrableObject(i)) {
379 velCom += sd->
getVel() * mass;
392 Molecule::BondIterator bondIter;
394 Molecule::BendIterator bendIter;
395 Molecule::TorsionIterator torsionIter;
396 Molecule::InversionIterator inversionIter;
398 RealType potential = 0.0;
400 for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) {
401 potential += bond->getPotential();
404 for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) {
405 potential += bend->getPotential();
408 for (torsion = beginTorsion(torsionIter); torsion != NULL;
409 torsion = nextTorsion(torsionIter)) {
410 potential += torsion->getPotential();
413 for (inversion = beginInversion(inversionIter); inversion != NULL;
414 inversion = nextInversion(inversionIter)) {
415 potential += inversion->getPotential();
422 properties_.addProperty(genData);
426 properties_.removeProperty(propName);
430 return properties_.getPropertyNames();
434 return properties_.getProperties();
438 const std::string& propName) {
439 return properties_.getPropertyByName(propName);
442 std::ostream& operator<<(std::ostream& o,
Molecule& mol) {
445 o << mol.
getNAtoms() <<
" atoms" << std::endl;
446 o << mol.
getNBonds() <<
" bonds" << std::endl;
447 o << mol.
getNBends() <<
" bends" << std::endl;
AtomType * getAtomType()
Returns the AtomType of this Atom.
AtomType is what OpenMD looks to for unchanging data about an atom.
Vector3d getPrevCom()
Returns the center of mass position of this molecule in the previous snapshot.
void addAtom(Atom *atom)
add an atom into this molecule
void addInversion(Inversion *inversion)
add an improper torsion into this molecule
size_t getNIntegrableObjects()
Returns the total number of integrable objects in this molecule.
RealType getMass()
get total mass of this molecule
size_t getNFluctuatingCharges()
Returns the total number of fluctuating charges in this molecule.
std::vector< std::string > getPropertyNames()
Returns all names of properties.
size_t getNInversions()
Returns the total number of improper torsions in this molecule.
void removeProperty(const std::string &propName)
Removes property from PropertyMap by name.
void addBend(Bend *bend)
add a bend into this molecule
void addRigidBody(RigidBody *rb)
add a rigidbody into this molecule
int getGlobalIndex()
Returns the global index of this molecule.
std::vector< std::shared_ptr< GenericData > > getProperties()
Returns all of the properties in PropertyMap.
size_t getNBends()
Returns the total number of bends in this molecule.
std::shared_ptr< GenericData > getPropertyByName(const std::string &propName)
Returns property.
size_t getNConstraintPairs()
Returns the total number of constraints in this molecule.
void addCutoffGroup(CutoffGroup *cp)
add a cutoff group into this molecule
Vector3d getComVel()
Returns the velocity of center of mass of this molecule.
void addBond(Bond *bond)
add a bond into 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.
void addProperty(std::shared_ptr< GenericData > genData)
Adds property into property map.
RealType getPotential()
Returns the total potential energy of short range interaction of this molecule.
void moveCom(const Vector3d &delta)
Moves the center of this molecule.
size_t getNCutoffGroups()
Returns the total number of cutoff groups in this molecule.
void addTorsion(Torsion *torsion)
add a torsion into this molecule
size_t getNTorsions()
Returns the total number of torsions in this molecule.
RealType getFixedCharge()
get total fixed charge of this molecule
void setCom(const Vector3d &newCom)
Sets the center of this molecule.
Vector3d getCom()
Returns the current center of mass position of 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.