--- branches/development/src/perturbations/ElectricField.cpp 2012/08/20 18:28:22 1780 +++ branches/development/src/perturbations/ElectricField.cpp 2013/01/30 14:43:08 1844 @@ -72,13 +72,14 @@ namespace OpenMD { Molecule::AtomIterator j; Molecule* mol; Atom* atom; + AtomType* atype; potVec longRangePotential(0.0); Vector3d dip; Vector3d trq; Vector3d EFfrc; Vector3d pos; RealType chrg; - RealType pot, fieldPot, moment; + RealType pot, fieldPot; RealType chrgToKcal = 23.0609; RealType debyeToKcal = 4.8018969509; bool isCharge; @@ -86,19 +87,28 @@ namespace OpenMD { if (doElectricField) { fieldPot = 0.0; - for (mol = info_->beginMolecule(i); mol != NULL; mol = info_->nextMolecule(i)) { + for (mol = info_->beginMolecule(i); mol != NULL; + mol = info_->nextMolecule(i)) { + for (atom = mol->beginAtom(j); atom != NULL; atom = mol->nextAtom(j)) { + isCharge = false; chrg = 0.0; - - FixedChargeAdapter fca = FixedChargeAdapter(atom->getAtomType()); + + atype = atom->getAtomType(); + + if (atype->isElectrostatic()) { + atom->addElectricField(EF * chrgToKcal); + } + + FixedChargeAdapter fca = FixedChargeAdapter(atype); if ( fca.isFixedCharge() ) { isCharge = true; chrg = fca.getCharge(); } - FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atom->getAtomType()); + FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atype); if ( fqa.isFluctuatingCharge() ) { isCharge = true; chrg += atom->getFlucQPos(); @@ -108,7 +118,7 @@ namespace OpenMD { EFfrc = EF*chrg; EFfrc *= chrgToKcal; atom->addFrc(EFfrc); - // totally ad-hoc choice of the origin for potential calculation + // ad-hoc choice of the origin for potential calculation pos = atom->getPos(); pot = -dot(pos, EFfrc); if (doParticlePot) { @@ -117,18 +127,15 @@ namespace OpenMD { fieldPot += pot; } - MultipoleAdapter ma = MultipoleAdapter(atom->getAtomType()); + MultipoleAdapter ma = MultipoleAdapter(atype); if (ma.isDipole() ) { - Vector3d u_i = atom->getElectroFrame().getColumn(2); - moment = ma.getDipoleMoment(); - moment *= debyeToKcal; - dip = u_i * moment; - trq = cross(dip, EF); - //cerr << "dip = " << dip << "\n"; - // cerr << "trq = " << trq << "\n"; + Vector3d dipole = atom->getDipole(); + dipole *= debyeToKcal; + + trq = cross(dipole, EF); atom->addTrq(trq); - pot = -dot(dip, EF); - //cerr << "pot = " << pot << "\n"; + + pot = -dot(dipole, EF); if (doParticlePot) { atom->addParticlePot(pot); } @@ -142,11 +149,8 @@ namespace OpenMD { #endif Snapshot* snap = info_->getSnapshotManager()->getCurrentSnapshot(); longRangePotential = snap->getLongRangePotentials(); - // << "longRangePotential = " << longRangePotential << "\n"; longRangePotential[ELECTROSTATIC_FAMILY] += fieldPot; - //cerr << "longRangePotential[ELECTROSTATIC_FAMILY] = " << longRangePotential[ELECTROSTATIC_FAMILY] << "\n"; snap->setLongRangePotential(longRangePotential); } } - }