50#include "brains/ForceModifier.hpp"
51#include "nonbonded/NonBondedInteraction.hpp"
53#include "types/FixedChargeAdapter.hpp"
54#include "types/MultipoleAdapter.hpp"
55#include "utils/Constants.hpp"
59 MagneticField::MagneticField(
SimInfo* info) :
60 ForceModifier {info}, initialized {false}, doMagneticField {false} {
61 simParams = info_->getSimParams();
64 void MagneticField::initialize() {
65 std::vector<RealType> mf;
67 if (simParams->haveMagneticField()) {
68 doMagneticField =
true;
69 mf = simParams->getMagneticField();
72 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
73 "MagneticField: Incorrect number of parameters specified.\n"
74 "\tthere should be 3 parameters, but %zu were specified.\n",
86 void MagneticField::modifyForces() {
87 if (!initialized) initialize();
89 SimInfo::MoleculeIterator i;
90 Molecule::AtomIterator j;
102 Vector3d AngMomentum;
107 if (doMagneticField) {
108 for (mol = info_->beginMolecule(i); mol != NULL;
109 mol = info_->nextMolecule(i)) {
110 for (atom = mol->beginAtom(j); atom != NULL; atom = mol->nextAtom(j)) {
114 atype = atom->getAtomType();
118 FixedChargeAdapter fca = FixedChargeAdapter(atype);
119 if (fca.isFixedCharge()) {
124 C *= Constants::chargeFieldConvert;
127 f =
cross(v, MF) * C * Constants::magneticFieldConvert;
131 MultipoleAdapter ma = MultipoleAdapter(atype);
133 D = atom->getDipole() * Constants::dipoleFieldConvert;
138 AngMomentum = atom->getJ();
140 if (atom->isLinear()) {
141 l = atom->linearAxis();
145 omega[m] = AngMomentum[m] / I(m, m);
146 omega[n] = AngMomentum[n] / I(n, n);
148 omega = I.inverse() * AngMomentum;
Uniform Magnetic Field perturbation.
Abstract class for external ForceModifier classes.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.