votca 2024.2-dev
Loading...
Searching...
No Matches
potentialfunctionljg.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2019 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
19
20using namespace std;
21
22namespace votca {
23namespace csg {
24
25PotentialFunctionLJG::PotentialFunctionLJG(const string &name, double min,
26 double max)
27 : PotentialFunction(name, 5, min, max) {}
28
29double PotentialFunctionLJG::CalculateF(double r) const {
30
31 // lj 12-6 part + gaussian
32 if (r >= min_ && r <= cut_off_) {
33 return lam_(0) / pow(r, 12) - lam_(1) / pow(r, 6) +
34 lam_(2) * exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
35 } else {
36 return 0.0;
37 }
38}
39
40// calculate first derivative w.r.t. ith parameter
41double PotentialFunctionLJG::CalculateDF(Index i, double r) const {
42
43 if (r >= min_ && r <= cut_off_) {
44
45 switch (i) {
46 case 0:
47 return 1.0 / pow(r, 12);
48 case 1:
49 return -1.0 / pow(r, 6);
50 case 2:
51 return exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
52 case 3:
53 return -1.0 * lam_(2) * (r - lam_(4)) * (r - lam_(4)) *
54 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
55 case 4:
56 return 2.0 * lam_(2) * lam_(3) * (r - lam_(4)) *
57 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
58 }
59 }
60 return 0.0;
61}
62
63// calculate second derivative w.r.t. ith parameter
64double PotentialFunctionLJG::CalculateD2F(Index i, Index j, double r) const {
65
66 if (r >= min_ && r <= cut_off_) {
67
68 switch (i) {
69 case 0:
70 // all second derivatives w.r.t. c12 are zero
71 return 0.0;
72 case 1:
73 return 0.0;
74 case 2:
75 switch (j) {
76 case 0:
77 return 0.0;
78 case 1:
79 return 0.0;
80 case 2:
81 return 0.0;
82 case 3:
83 return -1.0 * (r - lam_(4)) * (r - lam_(4)) *
84 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
85 case 4:
86 return 2.0 * lam_(3) * (r - lam_(4)) *
87 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
88 default:
89 return 0.0;
90 }
91 case 3:
92 switch (j) {
93 case 0:
94 return 0.0;
95 case 1:
96 return 0.0;
97 case 2:
98 return -1.0 * (r - lam_(4)) * (r - lam_(4)) *
99 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
100 case 3:
101 return lam_(2) * pow((r - lam_(4)), 4) *
102 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
103 case 4:
104 return 2.0 * lam_(2) * (r - lam_(4)) *
105 (1.0 - lam_(3) * pow((r - lam_(4)), 2)) *
106 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
107 default:
108 return 0.0;
109 }
110 case 4:
111 switch (j) {
112 case 0:
113 return 0.0;
114 case 1:
115 return 0.0;
116 case 2:
117 return 2.0 * lam_(3) * (r - lam_(4)) *
118 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
119 case 3:
120 return 2.0 * lam_(2) * (r - lam_(4)) *
121 (1.0 - lam_(3) * pow((r - lam_(4)), 2)) *
122 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
123 case 4:
124 return 2.0 * lam_(2) * lam_(3) *
125 (2.0 * lam_(3) * pow((r - lam_(4)), 2) - 1.0) *
126 exp(-1.0 * lam_(3) * (r - lam_(4)) * (r - lam_(4)));
127 }
128 }
129 }
130 return 0.0;
131}
132} // namespace csg
133} // namespace votca
double CalculateF(double r) const override
PotentialFunctionLJG(const std::string &name, double min=0.0, double max=10.0)
double CalculateD2F(Index i, Index j, double r) const override
double CalculateDF(Index i, double r) const override
STL namespace.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26