ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/flucq/FluctuatingChargeForces.cpp
Revision: 1970
Committed: Wed Feb 26 19:45:34 2014 UTC (11 years, 2 months ago) by gezelter
File size: 5384 byte(s)
Log Message:
Adding a fluctuating charge forces block

File Contents

# Content
1 /*
2 * Copyright (c) 2012 The University of Notre Dame. All Rights Reserved.
3 *
4 * The University of Notre Dame grants you ("Licensee") a
5 * non-exclusive, royalty free, license to use, modify and
6 * redistribute this software in source and binary code form, provided
7 * that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
15 * distribution.
16 *
17 * This software is provided "AS IS," without a warranty of any
18 * kind. All express or implied conditions, representations and
19 * warranties, including any implied warranty of merchantability,
20 * fitness for a particular purpose or non-infringement, are hereby
21 * excluded. The University of Notre Dame and its licensors shall not
22 * be liable for any damages suffered by licensee as a result of
23 * using, modifying or distributing the software or its
24 * derivatives. In no event will the University of Notre Dame or its
25 * licensors be liable for any lost revenue, profit or data, or for
26 * direct, indirect, special, consequential, incidental or punitive
27 * damages, however caused and regardless of the theory of liability,
28 * arising out of the use of or inability to use software, even if the
29 * University of Notre Dame has been advised of the possibility of
30 * such damages.
31 *
32 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
33 * research, please cite the appropriate papers when you publish your
34 * work. Good starting points are:
35 *
36 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
37 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
38 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
39 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
40 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41 */
42
43 #ifdef IS_MPI
44 #include <mpi.h>
45 #endif
46
47 #include "flucq/FluctuatingChargeForces.hpp"
48 #include "types/FluctuatingChargeAdapter.hpp"
49
50 namespace OpenMD {
51
52 FluctuatingChargeForces::FluctuatingChargeForces(SimInfo* info) :
53 info_(info), initialized_(false) {
54 }
55
56 void FluctuatingChargeForces::initialize(){
57 FQtypes.clear();
58 FQtids.clear();
59 FQtids.resize( forceField_->getNAtomType(), -1);
60
61 set<AtomType*>::iterator at;
62 for (at = simTypes_.begin(); at != simTypes_.end(); ++at)
63 if ((*at)->isFluctuatingCharge()) addType(*at);
64
65 initialized_ = true;
66 }
67
68 void FluctuatingChargeForces::getSelfInteraction(int atid, RealType charge,
69 RealType &potential,
70 RealType &force) {
71 if (!initialized_) initialize();
72
73 data = FQMap[FQtids[atid]];
74
75 if (data.hasMultipleMinima) {
76 int nDiabats = data.diabaticStates.size();
77 if (nDiabats == 2){
78 RealType q1 = data.diabaticStates[0].first;
79 RealType e1 = data.diabaticStates[0].second;
80 RealType q2 = data.diabaticStates[1].first;
81 RealType e2 = data.diabaticStates[1].second;
82 RealType k = data.curvature;
83 RealType c = data.coupling;
84
85 RealType v1 = e1 + 0.5 * k * (charge-q1)*(charge-q1);
86 RealType v1p = k*(charge-q1);
87 RealType v2 = e2 + 0.5 * k * (charge-q2)*(charge-q2);
88 RealType v2p = k*(charge-q2);
89 potential += (v1 + v2 - sqrt(4*c*c+ v1*v1 - 2.0*v1*v2 + v2*v2))/2.0;
90 force -= (v1p + v2p - ((v1 - v2) * (v1p - v2p)) /
91 sqrt(4*c*c + v1*v1 - 2*v1*v2 + v2*v2))/2.0;
92 } else {
93 std::cerr << "too many diabatic states\n";
94 }
95 } else {
96 RealType Jii = data.hardness;
97 RealType chi = data.electronegativity;
98 force -= charge * Jii + chi;
99 potential += charge * (charge * Jii * 0.5 + chi);
100 }
101 return;
102 }
103
104 void FluctuatingChargeForces::addType(AtomType* atomType) {
105 FluctuatingChargeAtomData data;
106 FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
107 if (fqa.isFluctuatingCharge()) {
108 if (fqa.hasMultipleMinima()) {
109 data.hasMultipleMinima = true;
110 data.curvature = fqa.getCurvature();
111 data.coupling = fqa.getCoupling();
112 data.diabaticStates = fqa.getDiabaticStates();
113 } else {
114 data.hasMultipleMinima = false;
115 data.electronegativity = fqa.getElectronegativity();
116 data.hardness = fqa.getHardness();
117 data.slaterN = fqa.getSlaterN();
118 data.slaterZeta = fqa.getSlaterZeta();
119 }
120 int atid = atomType->getIdent();
121 int fqtid = FQtypes.size();
122
123 pair<set<int>::iterator,bool> ret;
124 ret = FQtypes.insert( atid );
125 if (ret.second == false) {
126 sprintf( painCave.errMsg,
127 "FluctuatingChargeForces already had a previous fluctuating "
128 "charge entry with ident %d\n",
129 atid );
130 painCave.severity = OPENMD_INFO;
131 painCave.isFatal = 0;
132 simError();
133 }
134 FQtids[atid] = fqtid;
135 FQMap.push_back(data);
136 }
137 }
138 }

Properties

Name Value
svn:eol-style native
svn:executable *