8 #include "CosineSqAngle.h" 9 #include <util/math/Constants.h> 10 #include <util/random/Random.h> 12 #include <util/mpi/MpiLoader.h> 27 for (
int i = 0; i < MaxNAngleType; ++i) {
38 : nAngleType_(other.nAngleType_)
40 for (
int i = 0; i < MaxNAngleType; ++i) {
41 kappa_[i] = other.kappa_[i];
42 theta0_[i] = other.theta0_[i];
43 cosTheta0_[i] = other.cosTheta0_[i];
52 nAngleType_ = other.nAngleType_;
53 for (
int i = 0; i < MaxNAngleType; ++i) {
54 kappa_[i] = other.kappa_[i];
55 theta0_[i] = other.theta0_[i];
56 cosTheta0_[i] = other.cosTheta0_[i];
66 if (nAngleType > MaxNAngleType) {
67 UTIL_THROW(
"nAngleType > CosineSqAngle::MaxNAngleType");
69 nAngleType_ = nAngleType;
81 readCArray<double>(in,
"kappa", kappa_, nAngleType_);
82 readCArray<double>(in,
"theta0", theta0_, nAngleType_);
85 for (
int i = 0; i < nAngleType_; ++i) {
96 loadCArray<double> (ar,
"kappa", kappa_, nAngleType_);
97 loadCArray<double>(ar,
"theta0", theta0_, nAngleType_);
100 loader.load(cosTheta0_, nAngleType_);
102 ar.unpack(cosTheta0_, nAngleType_);
112 ar.
pack(kappa_, nAngleType_);
113 ar.
pack(theta0_, nAngleType_);
114 ar.
pack(cosTheta0_, nAngleType_);
124 Random *random,
double beta,
int type)
const 126 double Theta, Theta_min;
130 Theta_min = acos(cosTheta0_[type]);
131 U_min =
energy(cos(Theta_min), type);
133 while (chosen ==
false) {
135 U =
energy(cos(Theta), type);
136 if (random->
uniform() < exp(-beta*(U-U_min))*cos(Theta)/cos(Theta_min))
150 Random *random,
double beta,
int type)
const 152 double CosineTheta, CosineTheta_min;
156 CosineTheta_min = cosTheta0_[type];
157 U_min =
energy(CosineTheta_min, type);
159 while (chosen ==
false) {
160 CosineTheta = random->
uniform(-1, 1);
161 U =
energy(CosineTheta, type);
162 if (random->
uniform() < exp(-beta*(U-U_min)))
174 if (name ==
"kappa") {
175 kappa_[type] = value;
177 if (name ==
"theta0") {
178 theta0_[type] = value;
190 if (name ==
"kappa") {
191 value = kappa_[type];
193 if (name ==
"theta0") {
194 value = theta0_[type];
205 {
return std::string(
"CosineSqAngle"); }
double energy(double cosTheta, int type) const
Returns potential energy for one angle.
std::string className() const
Return name string "CosineSqAngle" for this evaluator class.
CosineSqAngle()
Default constructor.
Classes used by all simpatico molecular simulations.
double uniform()
Return a random floating point number x, uniformly distributed in the range 0 <= x < 1...
void set(std::string name, int type, double value)
Modify a parameter, identified by a string.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void pack(const T &data)
Pack one object of type T.
A three body angle potential, as a function of angle cosine.
Utility classes for scientific computation.
double randomCosineAngle(Random *random, double beta, int type) const
Return bond angle cosine chosen from equilibrium distribution.
void setNAngleType(int nAngleType)
Set the number of angle types.
void readParameters(std::istream &in)
Read angle interaction parameters from input stream.
CosineSqAngle & operator=(const CosineSqAngle &other)
Assignment.
Saving archive for binary istream.
Provides methods for MPI-aware loading of data from input archive.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
static const double Pi
Trigonometric constant Pi.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
void setClassName(const char *className)
Set class name string.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
double get(std::string name, int type) const
Get a parameter value, identified by a string.
double randomAngle(Random *random, double beta, int type) const
Return bond angle chosen from equilibrium distribution.