Simpatico  v1.10
Diblock.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 "Diblock.h"
9 #include <util/global.h>
10 
11 namespace Simp
12 {
13 
14  using namespace Util;
15 
16  /*
17  * Default constructor.
18  */
20  : Linear()
21  #ifdef SIMP_ANGLE
22  , angleType_(NullIndex)
23  #endif
24  #ifdef SIMP_DIHEDRAL
25  , dihedralType_(NullIndex)
26  #endif
27  {
28  setClassName("Diblock");
29  for (int i=0; i < 2; ++i) {
30  atomTypes_[i] = NullIndex;
31  blockLengths_[i] = 0;
32  }
33  }
34 
35  /*
36  * Read blockLengths_ and atomTypes_ for each block
37  */
38  void Diblock::readSpeciesParam(std::istream &in)
39  {
40  readCArray<int>(in,"blockLengths", blockLengths_, 2);
41  for (int i=0; i < 2; ++i) {
42  if (blockLengths_[i] < 1) {
43  UTIL_THROW("Invalid blockLength for diblock.");
44  }
45  }
46  nAtom_ = blockLengths_[0] + blockLengths_[1];
47  readCArray<int>(in,"atomTypes", atomTypes_, 2);
48 
49  nBond_ = nAtom_ - 1;
50  read<int>(in, "bondType", bondType_);
51 
52  #ifdef SIMP_ANGLE
53  hasAngles_ = 0; // default value
54  readOptional<int>(in, "hasAngles", hasAngles_);
55  if (hasAngles_) {
56  if (nAtom_ < 3) {
57  UTIL_THROW("Error: Cannot have angles with nAtom < 3");
58  }
59  nAngle_ = nAtom_ - 2;
60  read<int>(in, "angleType", angleType_);
61  } else {
62  nAngle_ = 0;
63  }
64  #endif
65 
66  #ifdef SIMP_DIHEDRAL
67  hasDihedrals_ = 0; // default value
68  readOptional<int>(in, "hasDihedrals", hasDihedrals_);
69  if (hasDihedrals_) {
70  if (nAtom_ < 4) {
71  UTIL_THROW("Error: Cannot have dihedrals with nAtom < 4");
72  }
73  nDihedral_ = nAtom_ - 3;
74  read<int>(in, "dihedralType", dihedralType_);
75  } else {
76  nDihedral_ = 0;
77  }
78  #endif
79 
80  buildLinear();
81  }
82 
83  /*
84  * Load from Serializable::IArchive.
85  */
87  {
88  loadCArray<int>(ar, "blockLengths", blockLengths_, 2);
89  for (int i=0; i < 2; ++i) {
90  if (blockLengths_[i] < 1) {
91  UTIL_THROW("Invalid blockLength for diblock.");
92  }
93  }
94  nAtom_ = blockLengths_[0] + blockLengths_[1];
95  loadCArray<int>(ar, "atomTypes", atomTypes_, 2);
96 
97  nBond_ = nAtom_ - 1;
98  loadParameter<int>(ar,"bondType", bondType_);
99  #ifdef SIMP_ANGLE
100  hasAngles_ = 0;
101  loadParameter<int>(ar,"hasAngles", hasAngles_, false); // optional
102  if (hasAngles_) {
103  if (nAtom_ < 3) {
104  UTIL_THROW("Error: Cannot have angles with nAtom < 3");
105  }
106  nAngle_ = nAtom_ - 2;
107  loadParameter<int>(ar,"angleType", angleType_);
108  } else {
109  nAngle_ = 0;
110  }
111  #endif
112  #ifdef SIMP_DIHEDRAL
113  hasDihedrals_ = 0;
114  loadParameter<int>(ar,"hasDihedrals", hasDihedrals_, false); // optional
115  if (hasDihedrals_) {
116  if (nAtom_ < 4) {
117  UTIL_THROW("Error: Cannot have dihedrals with nAtom < 4");
118  }
119  nDihedral_ = nAtom_ - 3;
120  loadParameter<int>(ar, "dihedralType", dihedralType_);
121  } else {
122  nDihedral_ = 0;
123  }
124  #endif
125 
126  buildLinear();
127  }
128 
129  /*
130  * Save internal state to an archive.
131  */
133  {
134  ar << moleculeCapacity_;
135  ar.pack(blockLengths_, 2);
136  ar.pack(atomTypes_, 2);
137  ar << bondType_;
138  #ifdef SIMP_ANGLE
140  if (hasAngles_ && nAngle_ > 0) {
141  ar << angleType_;
142  }
143  #endif
144  #ifdef SIMP_DIHEDRAL
146  if (hasDihedrals_ && nDihedral_ > 0) {
147  ar << dihedralType_;
148  }
149  #endif
150  }
151 
152  /*
153  * Return atomTypes_ for every atom.
154  */
155  int Diblock::calculateAtomTypeId(int index) const
156  {
157  if (index < blockLengths_[0]) {
158  return atomTypes_[0];
159  } else {
160  return atomTypes_[1];
161  }
162  }
163 
164  /*
165  * Return bondType_ for every bond.
166  */
167  int Diblock::calculateBondTypeId(int molBondId) const
168  { return bondType_; }
169 
170  #ifdef SIMP_ANGLE
171  /*
172  * Return angleType_ for every angle.
173  */
174  int Diblock::calculateAngleTypeId(int index) const
175  { return angleType_; }
176  #endif
177 
178  #ifdef SIMP_DIHEDRAL
179  /*
180  * Return dihedralType_ for every dihedral.
181  */
182  int Diblock::calculateDihedralTypeId(int index) const
183  { return dihedralType_; }
184  #endif
185 
186 }
int moleculeCapacity_
Number of molecules associated with the species.
virtual int calculateAtomTypeId(int index) const
Return the atom type for a specific atom.
Definition: Diblock.cpp:155
virtual int calculateDihedralTypeId(int index) const
Return same dihedral type for any dihedral in any chain.
Definition: Diblock.cpp:182
virtual int calculateBondTypeId(int index) const
Return same bond type for any bond in any chain.
Definition: Diblock.cpp:167
File containing preprocessor macros for error handling.
Classes used by all simpatico molecular simulations.
virtual void loadSpeciesParam(Serializable::IArchive &ar)
Load species structure from an Archive.
Definition: Diblock.cpp:86
int hasAngles_
Does this chain have angle potentials (0 = false, 1 = true).
Definition: Linear.h:57
static const int NullIndex
Null (unknown) value for any non-negative index.
int nAtom_
Number of atoms per molecule.
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 readSpeciesParam(std::istream &in)
Read block lengths length and and types.
Definition: Diblock.cpp:38
void pack(const T &data)
Pack one object of type T.
Diblock()
Default constructor.
Definition: Diblock.cpp:19
Utility classes for scientific computation.
Definition: accumulators.mod:1
int nDihedral_
Number of dihedrals per molecule.
int nAngle_
Number of angles per molecule.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
Definition: Diblock.cpp:132
Saving archive for binary istream.
int hasDihedrals_
Does this chain have dihedral potentials (0 = false, 1 = true).
Definition: Linear.h:64
void buildLinear()
Build the chemical structure for a linear molecule.
Definition: Linear.cpp:39
void setClassName(const char *className)
Set class name string.
int atomTypes_[2]
Particle type ids for each block.
Definition: Diblock.h:52
static void saveOptional(Serializable::OArchive &ar, Type &value, bool isActive)
Save an optional parameter value to an output archive.
Definition: Parameter.h:224
int nBond_
Number of bonds per molecule.
A Species of linear polymers (abstract).
Definition: Linear.h:36
virtual int calculateAngleTypeId(int index) const
Return same angle type for any angle in any chain.
Definition: Diblock.cpp:174
int blockLengths_[2]
Number of particles in each block.
Definition: Diblock.h:49