57#include "io/AtomTypesSectionParser.hpp"
58#include "io/BaseAtomTypesSectionParser.hpp"
59#include "io/BendTypesSectionParser.hpp"
60#include "io/BondTypesSectionParser.hpp"
61#include "io/ChargeAtomTypesSectionParser.hpp"
62#include "io/DirectionalAtomTypesSectionParser.hpp"
63#include "io/EAMAtomTypesSectionParser.hpp"
64#include "io/FluctuatingChargeAtomTypesSectionParser.hpp"
65#include "io/GayBerneAtomTypesSectionParser.hpp"
66#include "io/InversionTypesSectionParser.hpp"
67#include "io/LennardJonesAtomTypesSectionParser.hpp"
68#include "io/MultipoleAtomTypesSectionParser.hpp"
69#include "io/NonBondedInteractionsSectionParser.hpp"
70#include "io/OptionSectionParser.hpp"
71#include "io/PolarizableAtomTypesSectionParser.hpp"
72#include "io/SCAtomTypesSectionParser.hpp"
73#include "io/ShapeAtomTypesSectionParser.hpp"
74#include "io/StickyAtomTypesSectionParser.hpp"
75#include "io/StickyPowerAtomTypesSectionParser.hpp"
76#include "io/TorsionTypesSectionParser.hpp"
77#include "io/UFFAtomTypesSectionParser.hpp"
78#include "types/EAMAdapter.hpp"
79#include "types/GayBerneAdapter.hpp"
80#include "types/LennardJonesAdapter.hpp"
81#include "types/StickyAdapter.hpp"
82#include "types/SuttonChenAdapter.hpp"
83#include "utils/simError.h"
89 tempPath = getenv(
"FORCE_PARAM_PATH");
91 if (tempPath == NULL) {
93 STR_DEFINE(ffPath_, FRC_PATH);
98 setForceFieldFileName(ffName +
".frc");
151 void ForceField::parse(
const std::string& filename) {
154 ffStream = openForceFieldFile(filename);
156 spMan_.parse(*ffStream, *
this);
158 ForceField::AtomTypeContainer::MapTypeIterator i;
161 for (at = atomTypeCont_.beginType(i); at != NULL;
162 at = atomTypeCont_.nextType(i)) {
166 std::vector<AtomType*> ayb = at->allYourBase();
167 if (ayb.size() > 1) {
168 for (
int j = ayb.size() - 1; j > 0; j--) {
169 ayb[j - 1]->useBase(ayb[j]);
184 std::vector<std::string> keys;
186 return atomTypeCont_.
find(keys);
196 std::string at = atypeIdentToName.find(ident)->second;
200 BondType* ForceField::getBondType(
const std::string& at1,
201 const std::string& at2) {
202 std::vector<std::string> keys;
213 std::vector<std::string> at1key;
214 at1key.push_back(at1);
215 atype1 = atomTypeCont_.
find(at1key);
217 std::vector<std::string> at2key;
218 at2key.push_back(at2);
219 atype2 = atomTypeCont_.
find(at2key);
222 std::vector<AtomType*> at1Chain = atype1->allYourBase();
223 std::vector<AtomType*> at2Chain = atype2->allYourBase();
225 std::vector<AtomType*>::iterator i;
226 std::vector<AtomType*>::iterator j;
232 std::vector<std::pair<int, std::vector<std::string>>> foundBonds;
234 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
236 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
237 bondTypeScore = ii + jj;
239 std::vector<std::string> myKeys;
240 myKeys.push_back((*i)->getName());
241 myKeys.push_back((*j)->getName());
243 BondType* bondType = bondTypeCont_.
find(myKeys);
245 foundBonds.push_back(std::make_pair(bondTypeScore, myKeys));
252 if (!foundBonds.empty()) {
254 std::sort(foundBonds.begin(), foundBonds.end());
256 std::vector<std::string> theKeys = foundBonds[0].second;
258 BondType* bestType = bondTypeCont_.
find(theKeys);
263 return bondTypeCont_.
find(keys, wildCardAtomTypeName_);
268 BendType* ForceField::getBendType(
const std::string& at1,
269 const std::string& at2,
270 const std::string& at3) {
271 std::vector<std::string> keys;
277 BendType* bendType = bendTypeCont_.
find(keys);
284 std::vector<std::string> at1key;
285 at1key.push_back(at1);
286 atype1 = atomTypeCont_.
find(at1key);
288 std::vector<std::string> at2key;
289 at2key.push_back(at2);
290 atype2 = atomTypeCont_.
find(at2key);
292 std::vector<std::string> at3key;
293 at3key.push_back(at3);
294 atype3 = atomTypeCont_.
find(at3key);
297 std::vector<AtomType*> at1Chain = atype1->allYourBase();
298 std::vector<AtomType*> at2Chain = atype2->allYourBase();
299 std::vector<AtomType*> at3Chain = atype3->allYourBase();
301 std::vector<AtomType*>::iterator i;
302 std::vector<AtomType*>::iterator j;
303 std::vector<AtomType*>::iterator k;
310 std::vector<std::tuple<int, int, std::vector<std::string>>> foundBends;
312 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
314 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
316 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
319 std::vector<std::string> myKeys;
320 myKeys.push_back((*i)->getName());
321 myKeys.push_back((*j)->getName());
322 myKeys.push_back((*k)->getName());
324 BendType* bendType = bendTypeCont_.
find(myKeys);
326 foundBends.push_back(std::make_tuple(jj, IKscore, myKeys));
335 if (!foundBends.empty()) {
336 std::sort(foundBends.begin(), foundBends.end());
337 std::vector<std::string> theKeys = std::get<2>(foundBends[0]);
339 BendType* bestType = bendTypeCont_.
find(theKeys);
343 return bendTypeCont_.
find(keys, wildCardAtomTypeName_);
348 TorsionType* ForceField::getTorsionType(
const std::string& at1,
349 const std::string& at2,
350 const std::string& at3,
351 const std::string& at4) {
352 std::vector<std::string> keys;
359 TorsionType* torsionType = torsionTypeCont_.
find(keys);
367 std::vector<std::string> at1key;
368 at1key.push_back(at1);
369 atype1 = atomTypeCont_.
find(at1key);
371 std::vector<std::string> at2key;
372 at2key.push_back(at2);
373 atype2 = atomTypeCont_.
find(at2key);
375 std::vector<std::string> at3key;
376 at3key.push_back(at3);
377 atype3 = atomTypeCont_.
find(at3key);
379 std::vector<std::string> at4key;
380 at4key.push_back(at4);
381 atype4 = atomTypeCont_.
find(at4key);
384 std::vector<AtomType*> at1Chain = atype1->allYourBase();
385 std::vector<AtomType*> at2Chain = atype2->allYourBase();
386 std::vector<AtomType*> at3Chain = atype3->allYourBase();
387 std::vector<AtomType*> at4Chain = atype4->allYourBase();
389 std::vector<AtomType*>::iterator i;
390 std::vector<AtomType*>::iterator j;
391 std::vector<AtomType*>::iterator k;
392 std::vector<AtomType*>::iterator l;
401 std::vector<std::tuple<int, int, std::vector<std::string>>> foundTorsions;
403 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
405 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
407 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
409 for (l = at4Chain.begin(); l != at4Chain.end(); ++l) {
413 std::vector<std::string> myKeys;
414 myKeys.push_back((*i)->getName());
415 myKeys.push_back((*j)->getName());
416 myKeys.push_back((*k)->getName());
417 myKeys.push_back((*l)->getName());
419 TorsionType* torsionType = torsionTypeCont_.
find(myKeys);
421 foundTorsions.push_back(
422 std::make_tuple(JKscore, ILscore, myKeys));
433 if (!foundTorsions.empty()) {
434 std::sort(foundTorsions.begin(), foundTorsions.end());
435 std::vector<std::string> theKeys = std::get<2>(foundTorsions[0]);
437 TorsionType* bestType = torsionTypeCont_.
find(theKeys);
441 return torsionTypeCont_.
find(keys, wildCardAtomTypeName_);
446 InversionType* ForceField::getInversionType(
const std::string& at1,
447 const std::string& at2,
448 const std::string& at3,
449 const std::string& at4) {
450 std::vector<std::string> keys;
457 InversionType* inversionType =
458 inversionTypeCont_.permutedFindSkippingFirstElement(keys);
460 return inversionType;
466 std::vector<std::string> at1key;
467 at1key.push_back(at1);
468 atype1 = atomTypeCont_.
find(at1key);
470 std::vector<std::string> at2key;
471 at2key.push_back(at2);
472 atype2 = atomTypeCont_.
find(at2key);
474 std::vector<std::string> at3key;
475 at3key.push_back(at3);
476 atype3 = atomTypeCont_.
find(at3key);
478 std::vector<std::string> at4key;
479 at4key.push_back(at4);
480 atype4 = atomTypeCont_.
find(at4key);
483 std::vector<AtomType*> at1Chain = atype1->allYourBase();
484 std::vector<AtomType*> at2Chain = atype2->allYourBase();
485 std::vector<AtomType*> at3Chain = atype3->allYourBase();
486 std::vector<AtomType*> at4Chain = atype4->allYourBase();
488 std::vector<AtomType*>::iterator i;
489 std::vector<AtomType*>::iterator j;
490 std::vector<AtomType*>::iterator k;
491 std::vector<AtomType*>::iterator l;
500 std::vector<std::tuple<int, int, std::vector<std::string>>>
503 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
505 for (k = at3Chain.begin(); k != at3Chain.end(); ++k) {
507 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
509 for (l = at4Chain.begin(); l != at4Chain.end(); ++l) {
511 JKLscore = jj + kk + ll;
513 std::vector<std::string> myKeys;
514 myKeys.push_back((*i)->getName());
515 myKeys.push_back((*j)->getName());
516 myKeys.push_back((*k)->getName());
517 myKeys.push_back((*l)->getName());
519 InversionType* inversionType =
520 inversionTypeCont_.permutedFindSkippingFirstElement(myKeys);
522 foundInversions.push_back(
523 std::make_tuple(Iscore, JKLscore, myKeys));
534 if (!foundInversions.empty()) {
535 std::sort(foundInversions.begin(), foundInversions.end());
536 std::vector<std::string> theKeys = std::get<2>(foundInversions[0]);
538 InversionType* bestType =
539 inversionTypeCont_.permutedFindSkippingFirstElement(theKeys);
543 return inversionTypeCont_.
find(keys, wildCardAtomTypeName_);
548 NonBondedInteractionType* ForceField::getNonBondedInteractionType(
549 const std::string& at1,
const std::string& at2) {
550 std::vector<std::string> keys;
555 NonBondedInteractionType* nbiType =
556 nonBondedInteractionTypeCont_.
find(keys);
562 std::vector<std::string> at1key;
563 at1key.push_back(at1);
564 atype1 = atomTypeCont_.
find(at1key);
566 std::vector<std::string> at2key;
567 at2key.push_back(at2);
568 atype2 = atomTypeCont_.
find(at2key);
571 std::vector<AtomType*> at1Chain = atype1->allYourBase();
572 std::vector<AtomType*> at2Chain = atype2->allYourBase();
574 std::vector<AtomType*>::iterator i;
575 std::vector<AtomType*>::iterator j;
581 std::vector<std::pair<int, std::vector<std::string>>> foundNBI;
583 for (i = at1Chain.begin(); i != at1Chain.end(); ++i) {
585 for (j = at2Chain.begin(); j != at2Chain.end(); ++j) {
586 nbiTypeScore = ii + jj;
588 std::vector<std::string> myKeys;
589 myKeys.push_back((*i)->getName());
590 myKeys.push_back((*j)->getName());
592 NonBondedInteractionType* nbiType =
593 nonBondedInteractionTypeCont_.
find(myKeys);
595 foundNBI.push_back(std::make_pair(nbiTypeScore, myKeys));
602 if (!foundNBI.empty()) {
604 std::sort(foundNBI.begin(), foundNBI.end());
605 std::vector<std::string> theKeys = foundNBI[0].second;
607 NonBondedInteractionType* bestType =
608 nonBondedInteractionTypeCont_.
find(theKeys);
612 return nonBondedInteractionTypeCont_.
find(keys, wildCardAtomTypeName_);
617 BondType* ForceField::getExactBondType(
const std::string& at1,
618 const std::string& at2) {
619 std::vector<std::string> keys;
622 return bondTypeCont_.
find(keys);
625 BendType* ForceField::getExactBendType(
const std::string& at1,
626 const std::string& at2,
627 const std::string& at3) {
628 std::vector<std::string> keys;
632 return bendTypeCont_.
find(keys);
635 TorsionType* ForceField::getExactTorsionType(
const std::string& at1,
636 const std::string& at2,
637 const std::string& at3,
638 const std::string& at4) {
639 std::vector<std::string> keys;
644 return torsionTypeCont_.
find(keys);
647 InversionType* ForceField::getExactInversionType(
const std::string& at1,
648 const std::string& at2,
649 const std::string& at3,
650 const std::string& at4) {
651 std::vector<std::string> keys;
656 return inversionTypeCont_.
find(keys);
659 NonBondedInteractionType* ForceField::getExactNonBondedInteractionType(
660 const std::string& at1,
const std::string& at2) {
661 std::vector<std::string> keys;
664 return nonBondedInteractionTypeCont_.
find(keys);
667 bool ForceField::addAtomType(
const std::string& at, AtomType* atomType) {
668 std::vector<std::string> keys;
670 atypeIdentToName[atomType->getIdent()] = at;
671 return atomTypeCont_.add(keys, atomType);
674 bool ForceField::replaceAtomType(
const std::string& at, AtomType* atomType) {
675 std::vector<std::string> keys;
677 atypeIdentToName[atomType->getIdent()] = at;
678 return atomTypeCont_.replace(keys, atomType);
681 bool ForceField::addBondType(
const std::string& at1,
const std::string& at2,
682 BondType* bondType) {
683 std::vector<std::string> keys;
686 return bondTypeCont_.add(keys, bondType);
689 bool ForceField::addBendType(
const std::string& at1,
const std::string& at2,
690 const std::string& at3, BendType* bendType) {
691 std::vector<std::string> keys;
695 return bendTypeCont_.add(keys, bendType);
698 bool ForceField::addTorsionType(
const std::string& at1,
699 const std::string& at2,
700 const std::string& at3,
701 const std::string& at4,
702 TorsionType* torsionType) {
703 std::vector<std::string> keys;
708 return torsionTypeCont_.add(keys, torsionType);
711 bool ForceField::addInversionType(
const std::string& at1,
712 const std::string& at2,
713 const std::string& at3,
714 const std::string& at4,
715 InversionType* inversionType) {
716 std::vector<std::string> keys;
721 return inversionTypeCont_.add(keys, inversionType);
724 bool ForceField::addNonBondedInteractionType(
725 const std::string& at1,
const std::string& at2,
726 NonBondedInteractionType* nbiType) {
727 std::vector<std::string> keys;
730 return nonBondedInteractionTypeCont_.add(keys, nbiType);
733 RealType ForceField::getRcutFromAtomType(AtomType* at) {
736 LennardJonesAdapter lja = LennardJonesAdapter(at);
737 if (lja.isLennardJones()) { rcut = 2.5 * lja.getSigma(); }
738 EAMAdapter ea = EAMAdapter(at);
740 switch (ea.getEAMType()) {
742 rcut = max(rcut, ea.getRcut());
746 rcut = max(rcut, ea.getLatticeConstant() * sqrt(10.0) / 2.0);
752 SuttonChenAdapter sca = SuttonChenAdapter(at);
753 if (sca.isSuttonChen()) { rcut = max(rcut, 2.0 * sca.getAlpha()); }
754 GayBerneAdapter gba = GayBerneAdapter(at);
755 if (gba.isGayBerne()) {
756 rcut = max(rcut, 2.5 * sqrt(2.0) * max(gba.getD(), gba.getL()));
758 StickyAdapter sa = StickyAdapter(at);
759 if (sa.isSticky()) { rcut = max(rcut, max(sa.getRu(), sa.getRup())); }
764 ifstrstream* ForceField::openForceFieldFile(
const std::string& filename) {
765 std::string forceFieldFilename(filename);
767 ifstrstream* ffStream =
new ifstrstream();
770 ffStream->open(forceFieldFilename.c_str());
772 if (!ffStream->is_open()) {
775 forceFieldFilename = ffPath_ +
"/" + forceFieldFilename;
776 ffStream->open(forceFieldFilename.c_str());
778 if (!ffStream->is_open()) {
779 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
780 "Error opening the force field parameter file:\n"
782 "\tHave you tried setting the FORCE_PARAM_PATH environment "
784 forceFieldFilename.c_str());
785 painCave.severity = OPENMD_ERROR;
786 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"
"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.