Simpatico  v1.10
McSystem.h
1 #ifndef MCMD_MC_SYSTEM_H
2 #define MCMD_MC_SYSTEM_H
3 
4 /*
5 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <mcMd/simulation/System.h> // base class
12 #include <mcMd/neighbor/CellList.h> // member
13 #include <util/signal/Signal.h> // members
14 #include <util/global.h>
15 
16 namespace McMd
17 {
18 
19  using namespace Util;
20 
21  class Atom;
22  #ifndef SIMP_NOPAIR
23  class McPairPotential;
24  #endif
25  #ifdef SIMP_BOND
26  class BondPotential;
27  #endif
28  #ifdef SIMP_ANGLE
29  class AnglePotential;
30  #endif
31  #ifdef SIMP_DIHEDRAL
32  class DihedralPotential;
33  #endif
34  #ifdef SIMP_COULOMB
35  class CoulombPotential;
36  #endif
37  #ifdef SIMP_EXTERNAL
38  class ExternalPotential;
39  #endif
40  #ifdef SIMP_TETHER
41  class TetherPotential;
42  #endif
43 
52  class McSystem : public System
53  {
54 
55  public:
56 
58  McSystem();
59 
61  virtual ~McSystem();
62 
64 
65 
78  virtual void readParameters(std::istream &in);
79 
85  virtual void loadParameters(Serializable::IArchive &ar);
86 
92  virtual void saveParameters(Serializable::OArchive &ar);
93 
95 
97 
98  using System::readConfig;
99 
107  virtual void readConfig(std::istream& in);
108 
114  virtual void loadConfig(Serializable::IArchive& ar);
115 
130  virtual
131  void generateMolecules(Array<int> const & capacities,
132  Array<double> const & diameters);
133 
135 
137 
144  double atomPotentialEnergy(const Atom& atom) const;
145 
149  double potentialEnergy() const;
150 
161  template <typename T>
162  void computeVirialStress(T& stress) const;
163 
179  template <typename T>
180  void computeStress(T& stress) const;
181 
185  void unsetPotentialEnergies();
186 
190  void unsetVirialStress();
191 
193 
195 
196  #ifndef SIMP_NOPAIR
197 
200  McPairPotential& pairPotential() const;
201  #endif
202 
203  #ifdef SIMP_BOND
204 
207  bool hasBondPotential() const;
208 
212  BondPotential& bondPotential() const;
213  #endif
214 
215  #ifdef SIMP_ANGLE
216 
219  bool hasAnglePotential() const;
220 
224  AnglePotential& anglePotential() const;
225  #endif
226 
227  #ifdef SIMP_DIHEDRAL
228 
231  bool hasDihedralPotential() const;
232 
236  DihedralPotential& dihedralPotential() const;
237  #endif
238 
239  #ifdef SIMP_COULOMB
240 
243  bool hasCoulombPotential() const;
244 
248  CoulombPotential& coulombPotential() const;
249  #endif
250 
251  #ifdef SIMP_EXTERNAL
252 
255  bool hasExternalPotential() const;
256 
260  ExternalPotential& externalPotential() const;
261  #endif
262 
263  #ifdef MCMD_LINK
264 
267  bool hasLinkPotential() const;
268 
272  BondPotential& linkPotential() const;
273  #endif
274 
275  #ifdef SIMP_TETHER
276 
279  TetherPotential& tetherPotential() const;
280  #endif
281 
283 
285 
289  Signal<>& positionSignal();
290 
294  virtual bool isValid() const;
295 
297 
298  protected:
299 
300  #ifdef MCMD_PERTURB
301 
304  virtual Factory<Perturbation>* newDefaultPerturbationFactory();
305  #endif
306 
307  #ifndef SIMP_NOPAIR
308 
313  void setPairPotential(McPairPotential* pairPotentialPtr);
314  #endif
315 
316  private:
317 
318  #ifndef SIMP_NOPAIR
319  mutable CellList::NeighborArray neighbors_;
321 
322  McPairPotential* pairPotentialPtr_;
323  #endif
324 
325  #ifdef SIMP_BOND
326  BondPotential* bondPotentialPtr_;
327  #endif
328 
329  #ifdef SIMP_ANGLE
330  AnglePotential* anglePotentialPtr_;
332  #endif
333 
334  #ifdef SIMP_DIHEDRAL
335  DihedralPotential* dihedralPotentialPtr_;
337  #endif
338 
339  #ifdef SIMP_COULOMB
340  CoulombPotential* coulombPotentialPtr_;
342  #endif
343 
344  #ifdef SIMP_EXTERNAL
345  ExternalPotential* externalPotentialPtr_;
347  #endif
348 
349  #ifdef MCMD_LINK
350  BondPotential* linkPotentialPtr_;
352  #endif
353 
354  #ifdef SIMP_TETHER
355  TetherPotential* tetherPotentialPtr_;
357  #endif
358 
360  Signal<> positionSignal_;
361 
362  /*
363  * Implementations of the explicit specializations of the public
364  * stress calculators computeStress(T& ) etc. for T = double,
365  * Util::Vector and Util::Tensor simply call these private method
366  * templates. This allows a single template method to be used to
367  * compile the 3 relevant explicit specializations of each stress
368  * calculator, while keeping the template implementations out of
369  * this header file.
370  */
371 
372  template <typename T>
373  void computeVirialStressImpl(T& stress) const;
374 
375  #ifdef MCMD_LINK
376  template <typename T>
377  void computeLinkStressImpl(T& stress) const;
378  #endif
379 
380  };
381 
382  // Inline methods
383 
384  #ifndef SIMP_NOPAIR
385  /*
386  * Return the McPairPotential by reference.
387  */
389  {
390  assert(pairPotentialPtr_);
391  return *pairPotentialPtr_;
392  }
393  #endif
394 
395  #ifdef SIMP_BOND
396  /*
397  * Does a bond potential exist?
398  */
399  inline bool McSystem::hasBondPotential() const
400  { return bool(bondPotentialPtr_); }
401 
402  /*
403  * Return the BondPotential by const reference.
404  */
406  {
407  assert(bondPotentialPtr_);
408  return *bondPotentialPtr_;
409  }
410  #endif
411 
412  #ifdef SIMP_ANGLE
413  /*
414  * Does an angle potential exist?
415  */
416  inline bool McSystem::hasAnglePotential() const
417  { return bool(anglePotentialPtr_); }
418 
419  /*
420  * Return angle potential by reference.
421  */
423  {
424  assert(anglePotentialPtr_);
425  return *anglePotentialPtr_;
426  }
427  #endif
428 
429  #ifdef SIMP_DIHEDRAL
430  /*
431  * Does a dihedral potential exist?
432  */
433  inline bool McSystem::hasDihedralPotential() const
434  { return bool(dihedralPotentialPtr_); }
435 
436  /*
437  * Return dihedral potential by reference.
438  */
440  {
441  assert(dihedralPotentialPtr_);
442  return *dihedralPotentialPtr_;
443  }
444  #endif
445 
446  #ifdef SIMP_COULOMB
447  /*
448  * Does a Coulomb potential exist?
449  */
450  inline bool McSystem::hasCoulombPotential() const
451  { return bool(coulombPotentialPtr_); }
452 
453  /*
454  * Return Coulomb potential by reference.
455  */
456  inline CoulombPotential& McSystem::coulombPotential() const
457  {
458  assert(coulombPotentialPtr_);
459  return *coulombPotentialPtr_;
460  }
461  #endif
462 
463  #ifdef SIMP_EXTERNAL
464  /*
465  * Does an external potential exist?
466  */
467  inline bool McSystem::hasExternalPotential() const
468  { return bool(externalPotentialPtr_); }
469 
470  /*
471  * Return external potential by reference.
472  */
474  {
475  assert(externalPotentialPtr_);
476  return *externalPotentialPtr_;
477  }
478  #endif
479 
480  #ifdef MCMD_LINK
481  /*
482  * Does a link potential exist?
483  */
484  inline bool McSystem::hasLinkPotential() const
485  {
486  assert(linkPotentialPtr_);
487  return bool(linkPotentialPtr_);
488  }
489 
490  /*
491  * Return link potential by reference.
492  */
494  { return *linkPotentialPtr_; }
495  #endif
496 
497  #ifdef SIMP_TETHER
498  /*
499  * Return tether potential by reference.
500  */
501  inline TetherPotential& McSystem::tetherPotential() const
502  {
503  assert(tetherPotentialPtr_);
504  return *tetherPotentialPtr_;
505  }
506  #endif
507 
508  #ifndef SIMP_NOPAIR
509  /*
510  * Set the pair potential
511  */
512  inline void McSystem::setPairPotential(McPairPotential* pairPotentialPtr)
513  { pairPotentialPtr_ = pairPotentialPtr; }
514  #endif
515 
516  /*
517  * Signal to indicate change in atomic positions.
518  */
520  { return positionSignal_; }
521 
522 }
523 #endif
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
Interface for a Angle Interaction.
Signal & positionSignal()
Signal to indicate change in atomic positions.
Definition: McSystem.h:519
BondPotential & bondPotential() const
Return the BondPotential by reference.
Definition: McSystem.h:405
bool hasDihedralPotential() const
Does a dihedral potential exist?.
Definition: McSystem.h:433
bool hasLinkPotential() const
Does a link potential exist?.
Definition: McSystem.h:484
A PairPotential for MC simulations (abstract).
bool hasAnglePotential() const
Does angle potential exist?.
Definition: McSystem.h:416
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
File containing preprocessor macros for error handling.
Interface for a Dihedral Potential.
Saving / output archive for binary ostream.
Abstract External Potential class.
bool hasBondPotential() const
Does a bond potential exist?.
Definition: McSystem.h:399
ExternalPotential & externalPotential() const
Return ExternalPotential by reference.
Definition: McSystem.h:473
A point particle within a Molecule.
Utility classes for scientific computation.
Definition: accumulators.mod:1
CoulombPotential & coulombPotential() const
Return CoulombPotential by reference.
Definition: McSystem.h:456
McPairPotential & pairPotential() const
Return the McPairPotential by reference.
Definition: McSystem.h:388
virtual void readConfig(std::istream &in)
Read system configuration from file.
Definition: System.cpp:808
BondPotential & linkPotential() const
Return the McLinkPotential by reference.
Definition: McSystem.h:493
Saving archive for binary istream.
bool hasCoulombPotential() const
Does a Coulomb potential exist?.
Definition: McSystem.h:450
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
bool hasExternalPotential() const
Does an external potential exist?.
Definition: McSystem.h:467
Abstract Bond Potential class.
Notifier (or subject) in the Observer design pattern.
Definition: Signal.h:38
AnglePotential & anglePotential() const
Return AnglePotential by reference.
Definition: McSystem.h:422
void setPairPotential(McPairPotential *pairPotentialPtr)
Set the PairPotential.
Definition: McSystem.h:512
DihedralPotential & dihedralPotential() const
Return the DihedralPotential by reference.
Definition: McSystem.h:439