Simpatico  v1.10
HomopolymerSG.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 "HomopolymerSG.h"
9 #ifdef UTIL_MPI
10 #include <mcMd/simulation/McMd_mpi.h>
11 #endif
12 
13 namespace McMd
14 {
15 
16  using namespace Util;
17  using namespace Simp;
18 
19  /*
20  * Constructor.
21  */
23  : Linear(),
25  bondType_(NullIndex)
26  #ifdef SIMP_ANGLE
27  , angleType_(NullIndex)
28  #endif
29  #ifdef SIMP_DIHEDRAL
30  , dihedralType_(NullIndex)
31  #endif
32  {
33  setMutatorPtr(this);
34  setClassName("HomopolymerSG");
35  }
36 
37  /*
38  * Destructor.
39  */
41  {}
42 
43  /*
44  * Read a pair of monomer types and exchange chemical potential.
45  */
46  void HomopolymerSG::readParameters(std::istream& in)
47  {
49  }
50 
51  /*
52  * Read a pair of monomer types and exchange chemical potential.
53  */
54  void HomopolymerSG::readSpeciesParam(std::istream& in)
55  {
56  read<int>(in, "nAtom", nAtom_);
57  read<int>(in, "bondType", bondType_);
58  nBond_ = nAtom_ - 1;
59 
60  #ifdef SIMP_ANGLE
61  hasAngles_ = 0; // Default value
62  nAngle_ = 0;
63  readOptional<int>(in, "hasAngles", hasAngles_);
64  if (hasAngles_) {
65  if (nAtom_ < 3) {
66  UTIL_THROW("Error: Cannot have angles with nAtom < 3");
67  }
68  nAngle_ = nAtom_ - 2;
69  read<int>(in, "angleType", angleType_);
70  }
71  #endif
72 
73  #ifdef SIMP_DIHEDRAL
74  hasAngles_ = 0; // Default value
75  nDihedral_ = 0; // Default value
76  readOptional<int>(in, "hasDihedrals", hasDihedrals_);
77  if (hasDihedrals_) {
78  if (nAtom_ < 4) {
79  UTIL_THROW("Error: Cannot have angles with nAtom < 4");
80  }
81  nDihedral_ = nAtom_ - 3;
82  read<int>(in, "angleType", angleType_);
83  }
84  #endif
85 
86  buildLinear();
87 
88  read<Pair <int> >(in, "typeIds", typeIds_);
89  read<double>(in, "weightRatio", weightRatio_);
90 
92 
93  // Set statistical weights
94  double sum = weightRatio_ + 1.0;
95  mutator().setWeight(0, weightRatio_/sum);
96  mutator().setWeight(1, 1.0/sum);
97  }
98 
99  /*
100  * Load from Serializable::IArchive.
101  */
103  {
104  loadParameter<int>(ar,"nAtom", nAtom_);
105  nBond_ = nAtom_ - 1;
106  loadParameter<int>(ar,"bondType", bondType_);
107 
108  #ifdef SIMP_ANGLE
109  hasAngles_ = 0;
110  loadParameter<int>(ar,"hasAngles", hasAngles_, false);
111  if (hasAngles_) {
112  nAngle_ = nBond_ - 1;
113  if (nAngle_ > 0) {
114  loadParameter<int>(ar,"angleType", angleType_);
115  }
116  } else {
117  nAngle_ = 0;
118  }
119  #endif
120 
121  #ifdef SIMP_DIHEDRAL
122  hasDihedrals_ = 0;
123  loadParameter<int>(ar,"hasDihedrals", hasDihedrals_, false);
124  if (hasDihedrals_) {
125  if (nAtom_ > 3) {
126  nDihedral_ = nAtom_ - 3;
127  } else {
128  nDihedral_ = 0;
129  }
130  if (nDihedral_ > 0) {
131  loadParameter<int>(ar, "dihedralType", dihedralType_);
132  }
133  } else {
134  nDihedral_ = 0;
135  }
136  #endif
137 
138  buildLinear();
139 
141 
142  loadParameter<Pair <int> >(ar, "typeIds", typeIds_);
143  loadParameter<double>(ar, "weightRatio", weightRatio_);
144 
145  // Set statistical weights
146  double sum = weightRatio_ + 1.0;
147  mutator().setWeight(0, weightRatio_/sum);
148  mutator().setWeight(1, 1.0/sum);
149  }
150 
151  /*
152  * Save internal state to an archive.
153  */
155  {
156  ar << moleculeCapacity_;
157  ar << nAtom_;
158  ar << bondType_;
159  #ifdef SIMP_ANGLE
161  if (hasAngles_ && nAngle_ > 0) {
162  ar << angleType_;
163  }
164  #endif
165  #ifdef SIMP_DIHEDRAL
167  if (hasDihedrals_ && nDihedral_ > 0) {
168  ar << dihedralType_;
169  }
170  #endif
171  ar << typeIds_;
172  ar << weightRatio_;
173  }
174 
175  /*
176  * Return NullIndex for every atom.
177  *
178  * Used by Linear::buildLinear().
179  */
181  { return NullIndex; }
182 
183  /*
184  * Return 0 for every bond.
185  *
186  * Used by Linear::buildLinear().
187  */
189  { return bondType_; }
190 
191  #ifdef SIMP_ANGLE
192  /*
193  * Return 0 for every angle.
194  *
195  * Used by Linear::buildLinear().
196  */
198  { return angleType_; }
199  #endif
200 
201  #ifdef SIMP_DIHEDRAL
202  /*
203  * Return 0 for every dihedral.
204  *
205  * Used by Linear::buildLinear().
206  */
208  { return dihedralType_; }
209  #endif
210 
211  /*
212  * Change the type of a specific molecule.
213  */
214  void HomopolymerSG::setMoleculeState(Molecule& molecule, int stateId)
215  {
216  int nAtom = molecule.nAtom();
217  for (int i = 0; i < nAtom; ++i) {
218  molecule.atom(i).setTypeId(typeIds_[stateId]);
219  }
220  setMoleculeStateId(molecule, stateId);
221  }
222 
223 }
virtual void loadSpeciesParam(Serializable::IArchive &ar)
Load species structure from an Archive.
virtual int calculateDihedralTypeId(int index) const
Return same dihedral type for any dihedral in any chain.
int nAtom() const
Get number of atoms per molecule for this Species.
int moleculeCapacity_
Number of molecules associated with the species.
void setMutatorPtr(McMd::SpeciesMutator *mutatorPtr)
Set pointer to associated McMd::SpeciesMutator for a mutable species.
void allocateSpeciesMutator(int nMolecule, int nState)
Allocate arrays of molecule state ids and statistical weights.
void setMoleculeStateId(const Molecule &molecule, int stateId)
Set the state id of a specific molecule.
virtual void setMoleculeState(Molecule &molecule, int stateId)
Set the type of all atoms in the molecule.
void setWeight(int stateId, double weight)
Set the statistical weight associated with a specific state.
HomopolymerSG()
Constructor.
Classes used by all simpatico molecular simulations.
virtual int calculateAtomTypeId(int index) const
Return the same type for any particle in any chain.
Mix-in class for mutable subclasses of Species.
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 int calculateAngleTypeId(int index) const
Return same angle type for any angle in any chain.
Utility classes for scientific computation.
Definition: accumulators.mod:1
int nDihedral_
Number of dihedrals per molecule.
virtual void readParameters(std::istream &in)
Read parameters and initialize.
int nAngle_
Number of angles per molecule.
virtual int calculateBondTypeId(int index) const
Return same bond type for any bond in any chain.
virtual void readParameters(std::istream &in)
Read parameters and initialize structure for this species.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
void setTypeId(int typeId)
Set the atomic type index.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int hasDihedrals_
Does this chain have dihedral potentials (0 = false, 1 = true).
Definition: Linear.h:64
virtual void readSpeciesParam(std::istream &in)
Read nAtom, a pair of atom type ids and weightRatio.
void buildLinear()
Build the chemical structure for a linear molecule.
Definition: Linear.cpp:39
void setClassName(const char *className)
Set class name string.
virtual ~HomopolymerSG()
Destructor.
const Atom & atom(int localId) const
Get a specific Atom in this Molecule.
int capacity() const
Maximum allowed number of molecules for this Species.
A physical molecule (a set of covalently bonded Atoms).
McMd::SpeciesMutator & mutator()
Return the species mutator object by reference.
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
int nAtom() const
Get the number of Atoms in this Molecule.