60#include "io/AtomTypesSectionParser.hpp"
61#include "io/BaseAtomTypesSectionParser.hpp"
62#include "io/BendTypesSectionParser.hpp"
63#include "io/BondTypesSectionParser.hpp"
64#include "io/ChargeAtomTypesSectionParser.hpp"
65#include "io/DirectionalAtomTypesSectionParser.hpp"
66#include "io/EAMAtomTypesSectionParser.hpp"
67#include "io/FluctuatingChargeAtomTypesSectionParser.hpp"
68#include "io/GayBerneAtomTypesSectionParser.hpp"
69#include "io/InversionTypesSectionParser.hpp"
70#include "io/LennardJonesAtomTypesSectionParser.hpp"
71#include "io/MultipoleAtomTypesSectionParser.hpp"
72#include "io/NonBondedInteractionsSectionParser.hpp"
73#include "io/OptionSectionParser.hpp"
74#include "io/PolarizableAtomTypesSectionParser.hpp"
75#include "io/SCAtomTypesSectionParser.hpp"
76#include "io/ShapeAtomTypesSectionParser.hpp"
77#include "io/StickyAtomTypesSectionParser.hpp"
78#include "io/StickyPowerAtomTypesSectionParser.hpp"
79#include "io/TorsionTypesSectionParser.hpp"
80#include "io/UFFAtomTypesSectionParser.hpp"
81#include "types/EAMAdapter.hpp"
82#include "types/GayBerneAdapter.hpp"
83#include "types/LennardJonesAdapter.hpp"
84#include "types/StickyAdapter.hpp"
85#include "types/SuttonChenAdapter.hpp"
86#include "utils/simError.h"
92 tempPath = getenv(
"FORCE_PARAM_PATH");
94 if (tempPath == NULL) {
96 STR_DEFINE(ffPath_, FRC_PATH);
101 setForceFieldFileName(ffName +
".frc");
154 void ForceField::parse(
const std::string& filename) {
157 ffStream = openForceFieldFile(filename);
159 spMan_.parse(*ffStream, *
this);
161 ForceField::AtomTypeContainer::MapTypeIterator i;
164 for (at = atomTypeCont_.beginType(i); at != NULL;
165 at = atomTypeCont_.nextType(i)) {
169 std::vector<AtomType*> ayb = at->allYourBase();
170 if (ayb.size() > 1) {
171 for (
int j = ayb.size() - 1; j > 0; j--) {
172 ayb[j - 1]->useBase(ayb[j]);
187 std::vector<std::string> keys;
189 return atomTypeCont_.find(keys);
199 std::string at = atypeIdentToName.find(ident)->second;
203 BondType* ForceField::getBondType(
const std::string& at1,
204 const std::string& at2) {
205 std::vector<std::string> keys;
216 std::vector<std::string> at1key;
217 at1key.push_back(at1);
218 atype1 = atomTypeCont_.
find(at1key);
220 std::vector<std::string> at2key;
221 at2key.push_back(at2);
222 atype2 = atomTypeCont_.
find(at2key);
225 std::vector<AtomType*> at1Chain = atype1->allYourBase();
226 std::vector<AtomType*> at2Chain = atype2->allYourBase();
228 std::vector<AtomType*>::iterator i;
229 std::vector<AtomType*>::iterator j;
235 std::vector<std::pair<int, std::vector<std::string>>> foundBonds;
237 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
239 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
240 bondTypeScore = ii + jj;
242 std::vector<std::string> myKeys;
243 myKeys.push_back((*i)->getName());
244 myKeys.push_back((*j)->getName());
246 BondType* bondType = bondTypeCont_.
find(myKeys);
248 foundBonds.push_back(std::make_pair(bondTypeScore, myKeys));
255 if (!foundBonds.empty()) {
257 std::sort(foundBonds.begin(), foundBonds.end());
259 std::vector<std::string> theKeys = foundBonds[0].second;
261 BondType* bestType = bondTypeCont_.find(theKeys);
266 return bondTypeCont_.find(keys, wildCardAtomTypeName_);
271 BendType* ForceField::getBendType(
const std::string& at1,
272 const std::string& at2,
273 const std::string& at3) {
274 std::vector<std::string> keys;
280 BendType* bendType = bendTypeCont_.find(keys);
287 std::vector<std::string> at1key;
288 at1key.push_back(at1);
289 atype1 = atomTypeCont_.find(at1key);
291 std::vector<std::string> at2key;
292 at2key.push_back(at2);
293 atype2 = atomTypeCont_.find(at2key);
295 std::vector<std::string> at3key;
296 at3key.push_back(at3);
297 atype3 = atomTypeCont_.find(at3key);
300 std::vector<AtomType*> at1Chain = atype1->allYourBase();
301 std::vector<AtomType*> at2Chain = atype2->allYourBase();
302 std::vector<AtomType*> at3Chain = atype3->allYourBase();
304 std::vector<AtomType*>::iterator i;
305 std::vector<AtomType*>::iterator j;
306 std::vector<AtomType*>::iterator k;
313 std::vector<std::tuple<int, int, std::vector<std::string>>> foundBends;
315 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
317 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
319 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
322 std::vector<std::string> myKeys;
323 myKeys.push_back((*i)->getName());
324 myKeys.push_back((*j)->getName());
325 myKeys.push_back((*k)->getName());
327 BendType* bendType = bendTypeCont_.find(myKeys);
329 foundBends.push_back(std::make_tuple(jj, IKscore, myKeys));
338 if (!foundBends.empty()) {
339 std::sort(foundBends.begin(), foundBends.end());
340 std::vector<std::string> theKeys = std::get<2>(foundBends[0]);
342 BendType* bestType = bendTypeCont_.find(theKeys);
346 return bendTypeCont_.find(keys, wildCardAtomTypeName_);
351 TorsionType* ForceField::getTorsionType(
const std::string& at1,
352 const std::string& at2,
353 const std::string& at3,
354 const std::string& at4) {
355 std::vector<std::string> keys;
362 TorsionType* torsionType = torsionTypeCont_.find(keys);
370 std::vector<std::string> at1key;
371 at1key.push_back(at1);
372 atype1 = atomTypeCont_.find(at1key);
374 std::vector<std::string> at2key;
375 at2key.push_back(at2);
376 atype2 = atomTypeCont_.find(at2key);
378 std::vector<std::string> at3key;
379 at3key.push_back(at3);
380 atype3 = atomTypeCont_.find(at3key);
382 std::vector<std::string> at4key;
383 at4key.push_back(at4);
384 atype4 = atomTypeCont_.find(at4key);
387 std::vector<AtomType*> at1Chain = atype1->allYourBase();
388 std::vector<AtomType*> at2Chain = atype2->allYourBase();
389 std::vector<AtomType*> at3Chain = atype3->allYourBase();
390 std::vector<AtomType*> at4Chain = atype4->allYourBase();
392 std::vector<AtomType*>::iterator i;
393 std::vector<AtomType*>::iterator j;
394 std::vector<AtomType*>::iterator k;
395 std::vector<AtomType*>::iterator l;
404 std::vector<std::tuple<int, int, std::vector<std::string>>> foundTorsions;
406 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
408 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
410 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
412 for (l = at4Chain.begin(); l != at4Chain.end(); ++l) {
416 std::vector<std::string> myKeys;
417 myKeys.push_back((*i)->getName());
418 myKeys.push_back((*j)->getName());
419 myKeys.push_back((*k)->getName());
420 myKeys.push_back((*l)->getName());
422 TorsionType* torsionType = torsionTypeCont_.find(myKeys);
424 foundTorsions.push_back(
425 std::make_tuple(JKscore, ILscore, myKeys));
436 if (!foundTorsions.empty()) {
437 std::sort(foundTorsions.begin(), foundTorsions.end());
438 std::vector<std::string> theKeys = std::get<2>(foundTorsions[0]);
440 TorsionType* bestType = torsionTypeCont_.find(theKeys);
445 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
447 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
449 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
451 for (l = at4Chain.begin(); l != at4Chain.end(); ++l) {
455 std::vector<std::string> myKeys;
456 myKeys.push_back((*i)->getName());
457 myKeys.push_back((*j)->getName());
458 myKeys.push_back((*k)->getName());
459 myKeys.push_back((*l)->getName());
461 TorsionType* torsionType =
462 torsionTypeCont_.find(myKeys, wildCardAtomTypeName_);
464 foundTorsions.push_back(
465 std::make_tuple(JKscore, ILscore, myKeys));
476 if (!foundTorsions.empty()) {
477 std::sort(foundTorsions.begin(), foundTorsions.end());
478 std::vector<std::string> theKeys = std::get<2>(foundTorsions[0]);
479 TorsionType* bestType =
480 torsionTypeCont_.find(theKeys, wildCardAtomTypeName_);
490 InversionType* ForceField::getInversionType(
const std::string& at1,
491 const std::string& at2,
492 const std::string& at3,
493 const std::string& at4) {
494 std::vector<std::string> keys;
501 InversionType* inversionType =
502 inversionTypeCont_.permutedFindSkippingFirstElement(keys);
504 return inversionType;
510 std::vector<std::string> at1key;
511 at1key.push_back(at1);
512 atype1 = atomTypeCont_.find(at1key);
514 std::vector<std::string> at2key;
515 at2key.push_back(at2);
516 atype2 = atomTypeCont_.find(at2key);
518 std::vector<std::string> at3key;
519 at3key.push_back(at3);
520 atype3 = atomTypeCont_.find(at3key);
522 std::vector<std::string> at4key;
523 at4key.push_back(at4);
524 atype4 = atomTypeCont_.find(at4key);
527 std::vector<AtomType*> at1Chain = atype1->allYourBase();
528 std::vector<AtomType*> at2Chain = atype2->allYourBase();
529 std::vector<AtomType*> at3Chain = atype3->allYourBase();
530 std::vector<AtomType*> at4Chain = atype4->allYourBase();
532 std::vector<AtomType*>::iterator i;
533 std::vector<AtomType*>::iterator j;
534 std::vector<AtomType*>::iterator k;
535 std::vector<AtomType*>::iterator l;
544 std::vector<std::tuple<int, int, std::vector<std::string>>>
547 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
549 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
551 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
553 for (l = at4Chain.begin(); l != at4Chain.end(); ++l) {
555 JKLscore = jj + kk + ll;
557 std::vector<std::string> myKeys;
558 myKeys.push_back((*i)->getName());
559 myKeys.push_back((*j)->getName());
560 myKeys.push_back((*k)->getName());
561 myKeys.push_back((*l)->getName());
563 InversionType* inversionType =
564 inversionTypeCont_.permutedFindSkippingFirstElement(myKeys);
566 foundInversions.push_back(
567 std::make_tuple(Iscore, JKLscore, myKeys));
578 if (!foundInversions.empty()) {
579 std::sort(foundInversions.begin(), foundInversions.end());
580 std::vector<std::string> theKeys = std::get<2>(foundInversions[0]);
582 InversionType* bestType =
583 inversionTypeCont_.permutedFindSkippingFirstElement(theKeys);
588 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
590 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
592 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
594 for (l = at4Chain.begin(); l != at4Chain.end(); ++l) {
596 JKLscore = jj + kk + ll;
598 std::vector<std::string> myKeys;
599 myKeys.push_back((*i)->getName());
600 myKeys.push_back((*j)->getName());
601 myKeys.push_back((*k)->getName());
602 myKeys.push_back((*l)->getName());
603 InversionType* inversionType =
604 inversionTypeCont_.permutedFindSkippingFirstElement(
605 myKeys, wildCardAtomTypeName_);
607 foundInversions.push_back(
608 std::make_tuple(Iscore, JKLscore, myKeys));
618 if (!foundInversions.empty()) {
619 std::sort(foundInversions.begin(), foundInversions.end());
620 std::vector<std::string> theKeys = std::get<2>(foundInversions[0]);
621 InversionType* bestType =
622 inversionTypeCont_.permutedFindSkippingFirstElement(
623 theKeys, wildCardAtomTypeName_);
633 const std::string& at1,
const std::string& at2) {
634 std::vector<std::string> keys;
639 NonBondedInteractionType* nbiType =
640 nonBondedInteractionTypeCont_.find(keys);
646 std::vector<std::string> at1key;
647 at1key.push_back(at1);
648 atype1 = atomTypeCont_.find(at1key);
650 std::vector<std::string> at2key;
651 at2key.push_back(at2);
652 atype2 = atomTypeCont_.find(at2key);
655 std::vector<AtomType*> at1Chain = atype1->allYourBase();
656 std::vector<AtomType*> at2Chain = atype2->allYourBase();
658 std::vector<AtomType*>::iterator i;
659 std::vector<AtomType*>::iterator j;
665 std::vector<std::pair<int, std::vector<std::string>>> foundNBI;
667 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
669 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
670 nbiTypeScore = ii + jj;
672 std::vector<std::string> myKeys;
673 myKeys.push_back((*i)->getName());
674 myKeys.push_back((*j)->getName());
676 NonBondedInteractionType* nbiType =
677 nonBondedInteractionTypeCont_.find(myKeys);
679 foundNBI.push_back(std::make_pair(nbiTypeScore, myKeys));
686 if (!foundNBI.empty()) {
688 std::sort(foundNBI.begin(), foundNBI.end());
689 std::vector<std::string> theKeys = foundNBI[0].second;
691 NonBondedInteractionType* bestType =
692 nonBondedInteractionTypeCont_.find(theKeys);
696 return nonBondedInteractionTypeCont_.find(keys, wildCardAtomTypeName_);
701 BondType* ForceField::getExactBondType(
const std::string& at1,
702 const std::string& at2) {
703 std::vector<std::string> keys;
706 return bondTypeCont_.find(keys);
709 BendType* ForceField::getExactBendType(
const std::string& at1,
710 const std::string& at2,
711 const std::string& at3) {
712 std::vector<std::string> keys;
716 return bendTypeCont_.find(keys);
719 TorsionType* ForceField::getExactTorsionType(
const std::string& at1,
720 const std::string& at2,
721 const std::string& at3,
722 const std::string& at4) {
723 std::vector<std::string> keys;
728 return torsionTypeCont_.find(keys);
731 InversionType* ForceField::getExactInversionType(
const std::string& at1,
732 const std::string& at2,
733 const std::string& at3,
734 const std::string& at4) {
735 std::vector<std::string> keys;
740 return inversionTypeCont_.find(keys);
744 const std::string& at1,
const std::string& at2) {
745 std::vector<std::string> keys;
748 return nonBondedInteractionTypeCont_.find(keys);
751 bool ForceField::addAtomType(
const std::string& at,
AtomType* atomType) {
752 std::vector<std::string> keys;
754 atypeIdentToName[atomType->getIdent()] = at;
755 return atomTypeCont_.add(keys, atomType);
758 bool ForceField::replaceAtomType(
const std::string& at,
AtomType* atomType) {
759 std::vector<std::string> keys;
761 atypeIdentToName[atomType->getIdent()] = at;
762 return atomTypeCont_.replace(keys, atomType);
765 bool ForceField::addBondType(
const std::string& at1,
const std::string& at2,
767 std::vector<std::string> keys;
770 return bondTypeCont_.add(keys, bondType);
773 bool ForceField::addBendType(
const std::string& at1,
const std::string& at2,
774 const std::string& at3,
BendType* bendType) {
775 std::vector<std::string> keys;
779 return bendTypeCont_.add(keys, bendType);
782 bool ForceField::addTorsionType(
const std::string& at1,
783 const std::string& at2,
784 const std::string& at3,
785 const std::string& at4,
787 std::vector<std::string> keys;
792 return torsionTypeCont_.add(keys, torsionType);
795 bool ForceField::addInversionType(
const std::string& at1,
796 const std::string& at2,
797 const std::string& at3,
798 const std::string& at4,
800 std::vector<std::string> keys;
805 return inversionTypeCont_.add(keys, inversionType);
808 bool ForceField::addNonBondedInteractionType(
809 const std::string& at1,
const std::string& at2,
811 std::vector<std::string> keys;
814 return nonBondedInteractionTypeCont_.add(keys, nbiType);
817 RealType ForceField::getRcutFromAtomType(
AtomType* at) {
820 LennardJonesAdapter lja = LennardJonesAdapter(at);
821 if (lja.isLennardJones()) { rcut = 2.5 * lja.getSigma(); }
822 EAMAdapter ea = EAMAdapter(at);
824 switch (ea.getEAMType()) {
826 rcut = max(rcut, ea.getRcut());
830 rcut = max(rcut, ea.getLatticeConstant() * sqrt(10.0) / 2.0);
836 SuttonChenAdapter sca = SuttonChenAdapter(at);
837 if (sca.isSuttonChen()) { rcut = max(rcut, 2.0 * sca.getAlpha()); }
838 GayBerneAdapter gba = GayBerneAdapter(at);
839 if (gba.isGayBerne()) {
840 rcut = max(rcut, 2.5 * sqrt(2.0) * max(gba.getD(), gba.getL()));
842 StickyAdapter sa = StickyAdapter(at);
843 if (sa.isSticky()) { rcut = max(rcut, max(sa.getRu(), sa.getRup())); }
848 ifstrstream* ForceField::openForceFieldFile(
const std::string& filename) {
849 std::string forceFieldFilename(filename);
851 ifstrstream* ffStream =
new ifstrstream();
854 ffStream->open(forceFieldFilename.c_str());
856 if (!ffStream->is_open()) {
859 forceFieldFilename = ffPath_ +
"/" + forceFieldFilename;
860 ffStream->open(forceFieldFilename.c_str());
862 if (!ffStream->is_open()) {
863 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
864 "Error opening the force field parameter file:\n"
866 "\tHave you tried setting the FORCE_PARAM_PATH environment "
868 forceFieldFilename.c_str());
869 painCave.severity = OPENMD_ERROR;
870 painCave.isFatal = 1;
AtomType is what OpenMD looks to for unchanging data about an atom.
"io/AtomTypesSectionParser.hpp"
"io/BaseAtomTypesSectionParser.hpp"
"io/BendTypesSectionParser.hpp"
BondType class is responsible for calculating the force and energy of the bond.
"io/BondTypesSectionParser.hpp"
"io/EAMAtomTypesSectionParser.hpp"
ForceField(std::string ffName)
AtomType * getAtomType(const std::string &at)
getAtomType by string
"io/InversionTypesSectionParser.hpp"
NonBondedInteractionType class is responsible for keeping track of static (unchanging) parameters for...
"io/OptionSectionParser.hpp"
"io/SCAtomTypesSectionParser.hpp"
"io/StickyAtomTypesSectionParser.hpp"
StickyPowerAtomTypesSectionParser.hpp "io/StickyAtomTypesSectionParser.hpp".
"io/TorsionTypesSectionParser.hpp"
ElemPtr find(KeyType &keys)
Exact Match.
ifstrstream class provides a stream interface to read data from files.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.