Simpatico  v1.10
CosineDihedral.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "CosineDihedral.h"
9 
10 namespace Simp
11 {
12 
13  using namespace Util;
14 
15  /*
16  * Constructor.
17  */
19  : nDihedralType_(0)
20  {
21  setClassName("CosineDihedral");
22  for (int i = 0; i < MaxNDihedralType; ++i) {
23  kappa_[i] = 0.0;
24  }
25  }
26 
27  /*
28  * Copy constructor.
29  */
31  : nDihedralType_(other.nDihedralType_)
32  { for (int i = 0; i < nDihedralType_; ++i) kappa_[i] = other.kappa_[i]; }
33 
34  /*
35  * Assignment.
36  */
38  {
39  nDihedralType_ = other.nDihedralType_;
40  for (int i = 0; i < nDihedralType_; ++i) kappa_[i] = other.kappa_[i];
41  return *this;
42  }
43 
44  /*
45  * Set the nDihedralType_ member.
46  */
47  void CosineDihedral::setNDihedralType(int nDihedralType)
48  {
49  if (nDihedralType > MaxNDihedralType) {
50  UTIL_THROW("nDihedralType > CosineDihedral::MaxNDihedralType");
51  }
52  nDihedralType_ = nDihedralType;
53  }
54 
55  /*
56  * Read bend interaction parameters kappa from file.
57  */
58  void CosineDihedral::readParameters(std::istream &in)
59  {
60  if (nDihedralType_ <= 0) {
61  UTIL_THROW("nDihedralType must be set before readParam");
62  }
63  readCArray<double>(in, "kappa", kappa_, nDihedralType_);
64  }
65 
66  /*
67  * Load internal state from an archive.
68  */
70  {
71  ar >> nDihedralType_;
72  if (nDihedralType_ <= 0) {
73  UTIL_THROW( "nDihedralType must be positive");
74  }
75  loadCArray<double> (ar, "kappa", kappa_, nDihedralType_);
76  }
77 
78  /*
79  * Save internal state to an archive.
80  */
82  {
83  ar << nDihedralType_;
84  ar.pack(kappa_, nDihedralType_);
85  }
86 
87  /*
88  * Modify a parameter, identified by a string.
89  */
90  void CosineDihedral::set(std::string name, int type, double value)
91  {
92  if (name == "kappa") {
93  kappa_[type] = value;
94  } else {
95  UTIL_THROW("Unrecognized parameter name");
96  }
97  }
98 
99  /*
100  * Get a parameter value, identified by a string.
101  */
102  double CosineDihedral::get(std::string name, int type) const
103  {
104  double value = 0.0;
105  if (name == "kappa") {
106  value = kappa_[type];
107  } else {
108  UTIL_THROW("Unrecognized parameter name");
109  }
110  return value;
111  }
112 
113  /*
114  * Return name string "CosineDihedral" for this evaluator class.
115  */
116  std::string CosineDihedral::className() const
117  { return std::string("CosineDihedral"); }
118 
119 }
std::string className() const
Return name string "CosineDihedral" for this evaluator class.
void setNDihedralType(int nDihedralType)
Set the number of dihedral types.
void set(std::string name, int type, double value)
Modify a parameter, identified by a string.
Classes used by all simpatico molecular simulations.
CosineDihedral()
Default constructor.
Saving / output archive for binary ostream.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
void pack(const T &data)
Pack one object of type T.
CosineDihedral & operator=(const CosineDihedral &other)
Assignment.
Utility classes for scientific computation.
Definition: accumulators.mod:1
double get(std::string name, int type) const
Get a parameter value, identified by a string.
virtual void loadParameters(Serializable::IArchive &ar)
Load internal state from an archive.
Saving archive for binary istream.
void setClassName(const char *className)
Set class name string.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
A dihedral potential proportional to cos(phi).
void readParameters(std::istream &in)
Read dihedral interaction parameters from input stream.