Simpatico  v1.10
Homopolymer.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 "Homopolymer.h"
9 
10 namespace Simp
11 {
12 
13  using namespace Util;
14 
15  /*
16  * Default constructor.
17  */
18  Homopolymer::Homopolymer()
19  : Linear(),
20  atomType_(NullIndex),
21  bondType_(NullIndex)
22  #ifdef SIMP_ANGLE
23  , angleType_(NullIndex)
24  #endif
25  #ifdef SIMP_DIHEDRAL
26  , dihedralType_(NullIndex)
27  #endif
28  { setClassName("Homopolymer"); }
29 
30  /*
31  * Read nAtom and type.
32  */
33  void Homopolymer::readSpeciesParam(std::istream &in)
34  {
35  read<int>(in,"nAtom", nAtom_);
36  read<int>(in,"atomType", atomType_);
37  nBond_ = nAtom_ - 1;
38  read<int>(in,"bondType", bondType_);
39 
40  #ifdef SIMP_ANGLE
41  hasAngles_ = 0; // default value
42  readOptional<int>(in, "hasAngles", hasAngles_);
43  if (hasAngles_) {
44  if (nAtom_ < 3) {
45  UTIL_THROW("Error: Cannot have angles with nAtom < 3");
46  }
47  nAngle_ = nAtom_ - 2;
48  read<int>(in, "angleType", angleType_);
49  } else {
50  nAngle_ = 0;
51  }
52  #endif
53 
54  #ifdef SIMP_DIHEDRAL
55  hasDihedrals_ = 0; // default value
56  readOptional<int>(in, "hasDihedrals", hasDihedrals_);
57  if (hasDihedrals_) {
58  if (nAtom_ < 4) {
59  UTIL_THROW("Error: Cannot have dihedrals with nAtom < 4");
60  }
61  nDihedral_ = nAtom_ - 3;
62  read<int>(in, "dihedralType", dihedralType_);
63  } else {
64  nDihedral_ = 0;
65  }
66  #endif
67 
68  buildLinear();
69  }
70 
71  /*
72  * Load from Serializable::IArchive.
73  */
75  {
76  loadParameter<int>(ar,"nAtom", nAtom_);
77  loadParameter<int>(ar,"atomType", atomType_);
78  nBond_ = nAtom_ - 1;
79  loadParameter<int>(ar,"bondType", bondType_);
80  #ifdef SIMP_ANGLE
81  hasAngles_ = 0;
82  loadParameter<int>(ar,"hasAngles", hasAngles_, false);
83  if (hasAngles_) {
84  nAngle_ = nBond_ - 1;
85  if (nAngle_ > 0) {
86  loadParameter<int>(ar,"angleType", angleType_);
87  }
88  } else {
89  nAngle_ = 0;
90  }
91  #endif
92  #ifdef SIMP_DIHEDRAL
93  hasDihedrals_ = 0;
94  loadParameter<int>(ar,"hasDihedrals", hasDihedrals_, false);
95  if (hasDihedrals_) {
96  if (nAtom_ > 3) {
97  nDihedral_ = nAtom_ - 3;
98  } else {
99  nDihedral_ = 0;
100  }
101  if (nDihedral_ > 0) {
102  loadParameter<int>(ar, "dihedralType", dihedralType_);
103  }
104  } else {
105  nDihedral_ = 0;
106  }
107  #endif
108 
109  buildLinear();
110  }
111 
112  /*
113  * Save internal state to an archive.
114  */
116  {
117  ar << moleculeCapacity_;
118  ar << nAtom_;
119  ar << atomType_;
120  ar << bondType_;
121  #ifdef SIMP_ANGLE
122  Parameter::saveOptional(ar, hasAngles_, hasAngles_);
123  if (hasAngles_ && nAngle_ > 0) {
124  ar << angleType_;
125  }
126  #endif
127  #ifdef SIMP_DIHEDRAL
128  Parameter::saveOptional(ar, hasDihedrals_, hasDihedrals_);
129  if (hasDihedrals_ && nDihedral_ > 0) {
130  ar << dihedralType_;
131  }
132  #endif
133  }
134 
135  /*
136  * Return atomType_ for every atom.
137  */
138  int Homopolymer::calculateAtomTypeId(int index) const
139  { return atomType_; }
140 
141  /*
142  * Return bondType_ for every bond.
143  */
144  int Homopolymer::calculateBondTypeId(int index) const
145  { return bondType_; }
146 
147  #ifdef SIMP_ANGLE
148  /*
149  * Return angleType_ for every angle.
150  */
152  { return angleType_; }
153  #endif
154 
155  #ifdef SIMP_DIHEDRAL
156  /*
157  * Return dihedralType_ for every dihedral.
158  */
160  { return dihedralType_; }
161  #endif
162 
163 }
virtual void loadSpeciesParam(Serializable::IArchive &ar)
Load species structure from an Archive.
Definition: Homopolymer.cpp:74
virtual int calculateBondTypeId(int index) const
Return same bond type for any bond in any chain.
Classes used by all simpatico molecular simulations.
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
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
virtual int calculateDihedralTypeId(int index) const
Return same dihedral type for any dihedral in any chain.
virtual void readSpeciesParam(std::istream &in)
Read nAtom_ and the chain type.
Definition: Homopolymer.cpp:33
Utility classes for scientific computation.
Definition: accumulators.mod:1
virtual int calculateAtomTypeId(int index) const
Return the same type for any particle in any chain.
Saving archive for binary istream.
void setClassName(const char *className)
Set class name string.
virtual int calculateAngleTypeId(int index) const
Return same angle type for any angle in any chain.
static void saveOptional(Serializable::OArchive &ar, Type &value, bool isActive)
Save an optional parameter value to an output archive.
Definition: Parameter.h:224