Simpatico  v1.10
Activate.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 "Activate.h"
9 #include <mcMd/chemistry/Atom.h>
10 #include <mcMd/chemistry/Molecule.h>
11 #include <simp/species/Species.h>
12 #ifdef SIMP_BOND
13 #include <mcMd/chemistry/Bond.h>
14 #endif
15 #ifdef SIMP_ANGLE
16 #include <mcMd/chemistry/Angle.h>
17 #endif
18 #ifdef SIMP_DIHEDRAL
19 #include <mcMd/chemistry/Dihedral.h>
20 #endif
21 
22 namespace McMd
23 {
24 
25  using namespace Util;
26  using namespace Simp;
27 
28  /*
29  * De-activate an atom and update associated groups.
30  */
32  {
33  // Precondition: Atom must be active
34  if (!atom.isActive()) {
35  UTIL_THROW("Atom is not active");
36  }
37 
38  // De-activate atom
39  atom.setIsActive(false);
40 
41  #ifdef SIMP_BOND
42  // Update associated groups
43  Molecule& molecule = atom.molecule();
44  const Species& species = molecule.species();
45  const int atomId = int( &atom - &molecule.atom(0) );
46  if (species.nBond()) {
47  const Species::AtomBondIdArray groupIds = species.atomBondIds(atomId);
48  for (int i = 0; i < groupIds.size(); ++i) {
49  molecule.bond(groupIds[i]).incrementInactive();
50  assert(molecule.bond(groupIds[i]).checkInactive());
51  }
52  }
53  #ifdef SIMP_ANGLE
54  if (species.nAngle()) {
55  const Species::AtomAngleIdArray groupIds = species.atomAngleIds(atomId);
56  for (int i = 0; i < groupIds.size(); ++i) {
57  molecule.angle(groupIds[i]).incrementInactive();
58  assert(molecule.angle(groupIds[i]).checkInactive());
59  }
60  }
61  #endif
62  #ifdef SIMP_DIHEDRAL
63  if (species.nDihedral()) {
64  const Species::AtomDihedralIdArray groupIds = species.atomDihedralIds(atomId);
65  for (int i = 0; i < groupIds.size(); ++i) {
66  molecule.dihedral(groupIds[i]).incrementInactive();
67  assert(molecule.dihedral(groupIds[i]).checkInactive());
68  }
69  }
70  #endif
71  #endif // ifdef SIMP_BOND
72  }
73 
74  /*
75  * Re-activate a temporarily de-activated atom and update associated groups.
76  */
78  {
79  // Precondition: Atom must be inactive
80  if (atom.isActive()) {
81  UTIL_THROW("Atom already active");
82  }
83 
84  // Re-activate atom
85  atom.setIsActive(true);
86 
87  #ifdef SIMP_BOND
88  // Update associated groups
89  Molecule& molecule = atom.molecule();
90  const Species& species = molecule.species();
91  const int atomId = int( &atom - &molecule.atom(0) );
92  assert(atomId >= 0);
93  assert(atomId < molecule.nAtom());
94  if (species.nBond()) {
95  const Species::AtomBondIdArray groupIds = species.atomBondIds(atomId);
96  for (int i = 0; i < groupIds.size(); ++i) {
97  molecule.bond(groupIds[i]).decrementInactive();
98  assert(molecule.bond(groupIds[i]).checkInactive());
99  }
100  }
101  #ifdef SIMP_ANGLE
102  if (species.nAngle()) {
103  const Species::AtomAngleIdArray groupIds = species.atomAngleIds(atomId);
104  for (int i = 0; i < groupIds.size(); ++i) {
105  molecule.angle(groupIds[i]).decrementInactive();
106  assert(molecule.angle(groupIds[i]).checkInactive());
107  }
108  }
109  #endif
110  #ifdef SIMP_DIHEDRAL
111  if (species.nDihedral()) {
112  const Species::AtomDihedralIdArray groupIds = species.atomDihedralIds(atomId);
113  for (int i = 0; i < groupIds.size(); ++i) {
114  molecule.dihedral(groupIds[i]).decrementInactive();
115  assert(molecule.dihedral(groupIds[i]).checkInactive());
116  }
117  }
118  #endif
119  #endif // ifdef SIMP_BOND
120 
121  }
122 
123  /*
124  * Activate all atoms and groups in this molecule.
125  */
126  void Activate::activate(Molecule& molecule)
127  {
128  int i;
129  for (i = 0; i < molecule.nAtom(); ++i) {
130  molecule.atom(i).setIsActive(true);
131  }
132  #ifdef SIMP_BOND
133  for (i = 0; i < molecule.nBond(); ++i) {
134  molecule.bond(i).activate();
135  }
136  #endif
137  #ifdef SIMP_ANGLE
138  for (i = 0; i < molecule.nAngle(); ++i) {
139  molecule.angle(i).activate();
140  }
141  #endif
142  #ifdef SIMP_DIHEDRAL
143  for (i = 0; i < molecule.nDihedral(); ++i) {
144  molecule.dihedral(i).activate();
145  }
146  #endif
147  }
148 
149 }
Bond & bond(int localId)
Get a specific Bond in this Molecule by non-const reference.
Molecule & molecule() const
Get the parent Molecule by reference.
const AtomDihedralIdArray & atomDihedralIds(int atomId) const
Get array of ids for dihedrals that contain one Atom.
int nDihedral() const
Get the number of Dihedrals in this Molecule.
int nAngle() const
Get the number of Angles in this Molecule.
Dihedral & dihedral(int localId)
Get a specific Dihedral in this Molecule by reference.
bool checkInactive() const
Check consistency of number of inactive atoms.
Species & species() const
Get the molecular Species by reference.
static void activate(Molecule &molecule)
Activate all atoms and groups in one molecule.
Definition: Activate.cpp:126
Classes used by all simpatico molecular simulations.
A fixed capacity (static) contiguous array with a variable logical size.
Definition: FSArray.h:37
int nDihedral() const
Get number of dihedrals per molecule for this Species.
static void reactivate(Atom &atom)
Re-activate a temporarily de-activated atom and update groups.
Definition: Activate.cpp:77
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
bool isActive() const
Get the isActive flag.
int nBond() const
Get the number of Bonds in this Molecule.
const AtomAngleIdArray & atomAngleIds(int atomId) const
Get array of ids for angles that contain one Atom.
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
const AtomBondIdArray & atomBondIds(int atomId) const
Get array of ids for Bonds that contain one Atom.
const Atom & atom(int localId) const
Get a specific Atom in this Molecule.
A physical molecule (a set of covalently bonded Atoms).
A Species represents a set of chemically similar molecules.
int nBond() const
Get number of bonds per molecule for this Species.
int nAngle() const
Get number of angles per molecule for this Species.
Angle & angle(int localId)
Get a specific Angle in this Molecule by non-const reference.
int size() const
Return logical size of this array (i.e., number of elements).
Definition: FSArray.h:207
int nAtom() const
Get the number of Atoms in this Molecule.
static void deactivate(Atom &atom)
Temporarily de-activate one atom and update associated groups.
Definition: Activate.cpp:31