Simpatico  v1.10
LinearGenerator.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 "LinearGenerator.h"
9 #include <mcMd/simulation/Simulation.h>
10 #include <mcMd/simulation/System.h>
11 #include <mcMd/potentials/bond/BondPotential.h>
12 #include <mcMd/neighbor/CellList.h>
13 #include <simp/species/Species.h>
14 #include <simp/boundary/Boundary.h>
15 
16 namespace McMd
17 {
18 
19  class CellList;
20 
21  using namespace Util;
22  using namespace Simp;
23 
25  : Generator(species, system)
26  {}
27 
28  /*
29  * Recursive function to try to place an atom.
30  */
31  bool
33  Array<double> const & diameters,
34  CellList& cellList)
35  {
36  Random& random = simulation().random();
37 
38  // Attempt to place first atom at random
39  Atom* atomPtr = &molecule.atom(0);
40  int maxAttempt = 500;
41  int iAttempt = 0;
42  bool success = false;
43  while (!success && iAttempt < maxAttempt) {
44  boundary().randomPosition(random, atomPtr->position());
45  success = attemptPlaceAtom(*atomPtr, diameters, cellList);
46  }
47  if (!success) {
48  return false;
49  }
50 
51  Vector v;
52  //double temperature = system().energyEnsemble().temperature();
53  //double beta = 1.0/temperature;
54  double beta = 1.0;
55  Atom* prevPtr = 0;
56  int bondType = 0;
57  maxAttempt = 100;
58  int nAtom = species().nAtom();
59  for (int iAtom = 1; iAtom < nAtom; ++iAtom) {
60  atomPtr = &molecule.atom(iAtom);
61  prevPtr = &molecule.atom(iAtom-1);
62  iAttempt = 0;
63  success = false;
64  while (!success && iAttempt < maxAttempt) {
65  atomPtr->position() = prevPtr->position();
66  random.unitVector(v);
67  v *= bondPotential().randomBondLength(&random, beta,
68  bondType);
69  atomPtr->position() += v;
70  success = attemptPlaceAtom(*atomPtr, diameters, cellList);
71  ++iAttempt;
72  }
73  if (!success) {
74  for (int j = 0; j < iAtom; ++j) {
75  cellList.deleteAtom(molecule.atom(j));
76  }
77  return false; // Failure to insert an atom
78  }
79  }
80 
81  // Normal termination implies successful molecule insertion.
82  return true;
83  }
84 
85 }
A Vector is a Cartesian vector.
Definition: Vector.h:75
int nAtom() const
Get number of atoms per molecule for this Species.
const BondPotential & bondPotential()
Get the associated BondPotential by reference.
Definition: Generator.h:209
void randomPosition(Random &random, Vector &r) const
Generate random position within the primary unit cell.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
Classes used by all simpatico molecular simulations.
LinearGenerator(Species &species, System &system)
Constructor.
const Species & species()
Get the associated Species by reference.
Definition: Generator.h:184
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
const Boundary & boundary() const
Get the associated Boundary by reference.
Definition: Generator.h:202
Generates initial configurations for molecules of one species.
Definition: Generator.h:38
Simulation & simulation()
Get the associated Simulation by reference.
Definition: Generator.h:190
void deleteAtom(Atom &atom)
Delete a Atom object from its cell.
A cell list for Atom objects in a periodic system boundary.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
const Atom & atom(int localId) const
Get a specific Atom in this Molecule.
Random number generator.
Definition: Random.h:46
bool attemptPlaceMolecule(Molecule &molecule, Array< double > const &diameters, CellList &cellList)
Attempt to place an entire linear chain.
A physical molecule (a set of covalently bonded Atoms).
const Vector & position() const
Get the position Vector by const reference.
virtual double randomBondLength(Util::Random *random, double beta, int type) const =0
Return bond length chosen from equilibrium distribution.
A Species represents a set of chemically similar molecules.
bool attemptPlaceAtom(Atom &atom, const Array< double > &diameters, CellList &cellList)
Attempt to place an atom.
Definition: Generator.cpp:52
void unitVector(Vector &v)
Generate unit vector with uniform probability over the unit sphere.
Definition: Random.cpp:122
Random & random()
Get the random number generator by reference.