votca 2024.1-dev
Loading...
Searching...
No Matches
potentialfunction.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#include <votca/tools/table.h>
20
21#include <boost/lexical_cast.hpp>
22
23using namespace std;
24using namespace votca::tools;
25
26namespace votca {
27namespace csg {
28
29PotentialFunction::PotentialFunction(const string &name, Index nlam, double min,
30 double max) {
31
32 name_ = name;
33 lam_ = Eigen::VectorXd::Zero(nlam);
34 min_ = min;
35 cut_off_ = max;
36}
37
38void PotentialFunction::setParam(string filename) {
39
40 Table param;
41 param.Load(filename);
42
43 if (param.size() != lam_.size()) {
44
45 throw std::runtime_error("In potential " + name_ +
46 ": parameters size mismatch!\n"
47 "Check input parameter file \"" +
48 filename + "\" \nThere should be " +
49 boost::lexical_cast<string>(lam_.size()) +
50 " parameters");
51 } else {
52 for (Index i = 0; i < lam_.size(); i++) {
53 lam_(i) = param.y(i);
54 }
55 }
56}
57
58void PotentialFunction::SaveParam(const string &filename) {
59
60 Table param;
61 param.SetHasYErr(false);
62 param.resize(lam_.size());
63
64 for (Index i = 0; i < lam_.size(); i++) {
65 param.set(i, double(i), lam_(i), 'i');
66 }
67
68 param.Save(filename);
69}
70
71void PotentialFunction::SavePotTab(const string &filename, double step) {
72 Index ngrid = (Index)((cut_off_ - min_) / step + 1.00000001);
73 Table pot_tab;
74 pot_tab.SetHasYErr(false);
75 pot_tab.resize(ngrid);
76 double r_init;
77 Index i;
78
79 for (r_init = min_, i = 0; i < ngrid - 1; r_init += step) {
80 pot_tab.set(i++, r_init, CalculateF(r_init), 'i');
81 }
82
83 pot_tab.set(i, cut_off_, CalculateF(cut_off_), 'i');
84 pot_tab.Save(filename);
85}
86
87void PotentialFunction::SavePotTab(const string &filename, double step,
88 double rmin, double rcut) {
89 Index ngrid = (Index)((rcut - rmin) / step + 1.00000001);
90 Table pot_tab;
91 pot_tab.SetHasYErr(false);
92 pot_tab.resize(ngrid);
93 double r_init;
94 Index i;
95 char flag = 'i';
96
97 for (r_init = rmin, i = 0; i < ngrid - 1; r_init += step) {
98 pot_tab.set(i++, r_init, CalculateF(r_init), flag);
99 }
100
101 pot_tab.set(i, rcut, CalculateF(rcut), flag);
102 pot_tab.Save(filename);
103}
104} // namespace csg
105} // namespace votca
virtual void SaveParam(const std::string &filename)
virtual void SavePotTab(const std::string &filename, double step)
PotentialFunction(const std::string &name, Index nlam, double min, double max)
virtual double CalculateF(double r) const =0
virtual void setParam(std::string filename)
class to store tables like rdfs, tabulated potentials, etc
Definition table.h:36
Index size() const
Definition table.h:42
void SetHasYErr(bool has_yerr)
Definition table.h:81
void set(const Index &i, const double &x, const double &y)
Definition table.h:52
void Load(std::string filename)
Definition table.cc:47
void resize(Index N)
Definition table.cc:38
double & y(Index i)
Definition table.h:45
void Save(std::string filename) const
Definition table.cc:59
STL namespace.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26