Simpatico  v1.10
MdSystem.h
1 #ifndef MCMD_MD_SYSTEM_H
2 #define MCMD_MD_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 <util/signal/Signal.h> // members
13 
14 #include <util/global.h>
15 
16 namespace Util {
17  template <typename T> class Factory;
18 }
19 
20 namespace McMd
21 {
22 
23  using namespace Util;
24 
25  // Forward declarations
26 
27  #ifndef SIMP_NOPAIR
28  class MdPairPotential;
29  #endif
30  #ifdef SIMP_BOND
31  class BondPotential;
32  #endif
33  #ifdef SIMP_ANGLE
34  class AnglePotential;
35  #endif
36  #ifdef SIMP_DIHEDRAL
37  class DihedralPotential;
38  #endif
39  #ifdef SIMP_COULOMB
40  class MdCoulombPotential;
41  #endif
42  #ifdef SIMP_EXTERNAL
43  class ExternalPotential;
44  #endif
45  #ifdef SIMP_SPECIAL
46  class SpecialPotential;
47  #endif
48  #ifdef SIMP_TETHER
49  class TetherPotential;
50  #endif
51 
52  class MdIntegrator;
53  class McSystem;
54 
68  class MdSystem : public System
69  {
70 
71  public:
72 
79  MdSystem();
80 
97  MdSystem(McSystem& system);
98 
102  virtual ~MdSystem();
103 
105 
106 
115  virtual void readParameters(std::istream &in);
116 
122  virtual void loadParameters(Serializable::IArchive &ar);
123 
129  virtual void saveParameters(Serializable::OArchive &ar);
130 
132 
134 
143  virtual void readConfig(std::istream& in);
144 
145  using System::readConfig;
146 
155  virtual void loadConfig(Serializable::IArchive& ar);
156 
171  void generateMolecules(Array<int> const & capacities,
172  Array<double> const & diameters);
173 
175 
177 
188  void calculateForces();
189 
193  double kineticEnergy() const;
194 
198  double potentialEnergy();
199 
203  void unsetPotentialEnergy();
204 
221  template <typename T>
222  void computeStress(T& stress) const;
223 
234  template <typename T>
235  void computeVirialStress(T& stress) const;
236 
240  void unsetVirialStress();
241 
249  template <typename T>
250  void computeKineticStress(T& stress) const;
251 
253 
255 
256  #ifndef SIMP_NOPAIR
257 
260  MdPairPotential& pairPotential() const;
261  #endif
262 
266  bool hasBondPotential() const;
267 
268  #ifdef SIMP_BOND
269 
272  BondPotential& bondPotential() const;
273  #endif
274 
275  #ifdef SIMP_ANGLE
276 
279  bool hasAnglePotential() const;
280 
284  AnglePotential& anglePotential() const;
285  #endif
286 
287  #ifdef SIMP_DIHEDRAL
288 
291  bool hasDihedralPotential() const;
292 
296  DihedralPotential& dihedralPotential() const;
297  #endif
298 
299  #ifdef SIMP_COULOMB
300 
303  bool hasCoulombPotential() const;
304 
308  MdCoulombPotential& coulombPotential() const;
309  #endif
310 
311  #ifdef SIMP_EXTERNAL
312 
315  bool hasExternalPotential() const;
316 
320  ExternalPotential& externalPotential() const;
321  #endif
322 
323  #ifdef SIMP_SPECIAL
324 
327  bool hasSpecialPotential() const;
328 
332  SpecialPotential& specialPotential() const;
333  #endif
334 
335  #ifdef MCMD_LINK
336 
339  bool hasLinkPotential() const;
340 
344  BondPotential& linkPotential() const;
345  #endif
346 
347  #ifdef SIMP_TETHER
348 
351  TetherPotential& tetherPotential() const;
352  #endif
353 
355 
357 
361  void setZeroForces();
362 
366  void setZeroVelocities();
367 
373  void setBoltzmannVelocities(double temperature);
374 
382  Vector removeDriftVelocity();
383 
390  void shiftAtoms();
391 
393 
395 
399  Signal<>& positionSignal();
400 
404  Signal<>& velocitySignal();
405 
407 
409 
413  MdIntegrator& mdIntegrator();
414 
418  Factory<MdIntegrator>& mdIntegratorFactory();
419 
423  virtual bool isValid() const;
424 
426 
427  protected:
428 
432  virtual ConfigIo* newDefaultConfigIo();
433 
434  private:
435 
437  Signal<> positionSignal_;
438 
440  Signal<> velocitySignal_;
441 
442  #ifndef SIMP_NOPAIR
443  MdPairPotential* pairPotentialPtr_;
445  #endif
446 
447  #ifdef SIMP_BOND
448  BondPotential* bondPotentialPtr_;
450  #endif
451 
452  #ifdef SIMP_ANGLE
453  AnglePotential* anglePotentialPtr_;
455  #endif
456 
457  #ifdef SIMP_DIHEDRAL
458  DihedralPotential* dihedralPotentialPtr_;
460  #endif
461 
462  #ifdef SIMP_COULOMB
463  MdCoulombPotential* coulombPotentialPtr_;
465  #endif
466 
467  #ifdef SIMP_EXTERNAL
468  ExternalPotential* externalPotentialPtr_;
470  #endif
471 
472  #ifdef SIMP_SPECIAL
473  SpecialPotential* specialPotentialPtr_;
475  #endif
476 
477  #ifdef MCMD_LINK
478  BondPotential* linkPotentialPtr_;
480  #endif
481 
482  #ifdef SIMP_TETHER
483  TetherPotential* tetherPotentialPtr_;
485  #endif
486 
488  MdIntegrator *mdIntegratorPtr_;
489 
491  Factory<MdIntegrator> *mdIntegratorFactoryPtr_;
492 
494  bool createdMdIntegratorFactory_;
495 
496  /*
497  * Implementations of the explicit specializations of the public
498  * stress calculators computeVirialStress(T& ) etc. for T = double,
499  * Util::Vector and Util::Tensor simply call these private method
500  * templates. This allows a single private template method to be
501  * used to compile the 3 relevant explicit specializations of each
502  * stress calculator, while allowing the template implementations
503  * to be defined in MdSystem.cpp, rather than in this header file.
504  */
505 
506  template <typename T>
507  void computeKineticStressImpl(T& stress) const;
508 
509  template <typename T>
510  void computeVirialStressImpl(T& stress) const;
511 
512  };
513 
514  // Inline functions
515 
516  #ifndef SIMP_NOPAIR
517  /*
518  * Return PairPotential by reference.
519  */
520  inline MdPairPotential& MdSystem::pairPotential() const
521  {
522  assert(pairPotentialPtr_);
523  return *pairPotentialPtr_;
524  }
525  #endif
526 
527  #ifdef SIMP_BOND
528  /*
529  * Does a bond potential exist?
530  */
531  inline bool MdSystem::hasBondPotential() const
532  { return bool(bondPotentialPtr_); }
533 
534  /*
535  * Return bond potential by reference.
536  */
537  inline BondPotential& MdSystem::bondPotential() const
538  {
539  assert(bondPotentialPtr_);
540  return *bondPotentialPtr_;
541  }
542  #endif
543 
544  #ifdef SIMP_ANGLE
545  /*
546  * Does an angle potential exist?
547  */
548  inline bool MdSystem::hasAnglePotential() const
549  { return bool(anglePotentialPtr_); }
550 
551  /*
552  * Return angle potential by reference.
553  */
554  inline AnglePotential& MdSystem::anglePotential() const
555  {
556  assert(anglePotentialPtr_);
557  return *anglePotentialPtr_;
558  }
559  #endif
560 
561  #ifdef SIMP_DIHEDRAL
562  /*
563  * Does a dihedral potential exist?
564  */
565  inline bool MdSystem::hasDihedralPotential() const
566  { return bool(dihedralPotentialPtr_); }
567 
568  /*
569  * Return dihedral potential by reference.
570  */
571  inline DihedralPotential& MdSystem::dihedralPotential() const
572  {
573  assert(dihedralPotentialPtr_);
574  return *dihedralPotentialPtr_;
575  }
576  #endif
577 
578  #ifdef SIMP_COULOMB
579  /*
580  * Does a Coulomb potential exist?
581  */
582  inline bool MdSystem::hasCoulombPotential() const
583  { return bool(coulombPotentialPtr_); }
584 
585  /*
586  * Return Coulomb potential by reference.
587  */
588  inline MdCoulombPotential& MdSystem::coulombPotential() const
589  {
590  assert(coulombPotentialPtr_);
591  return *coulombPotentialPtr_;
592  }
593  #endif
594 
595  #ifdef SIMP_EXTERNAL
596  /*
597  * Does an external potential exist?
598  */
599  inline bool MdSystem::hasExternalPotential() const
600  { return bool(externalPotentialPtr_); }
601 
602  /*
603  * Return external potential by reference.
604  */
605  inline ExternalPotential& MdSystem::externalPotential() const
606  {
607  assert(externalPotentialPtr_);
608  return *externalPotentialPtr_;
609  }
610  #endif
611 
612  #ifdef SIMP_SPECIAL
613  /*
614  * Does a special potential exist?
615  */
616  inline bool MdSystem::hasSpecialPotential() const
617  { return bool(specialPotentialPtr_); }
618 
619  /*
620  * Return special potential by reference.
621  */
622  inline SpecialPotential& MdSystem::specialPotential() const
623  {
624  assert(specialPotentialPtr_);
625  return *specialPotentialPtr_;
626  }
627  #endif
628 
629  #ifdef MCMD_LINK
630  /*
631  * Does a link potential exist?
632  */
633  inline bool MdSystem::hasLinkPotential() const
634  { return bool(linkPotentialPtr_); }
635 
636  /*
637  * Return link potential by reference.
638  */
639  inline BondPotential& MdSystem::linkPotential() const
640  {
641  assert(linkPotentialPtr_);
642  return *linkPotentialPtr_;
643  }
644  #endif
645 
646  #ifdef SIMP_TETHER
647  /*
648  * Return tether potential by reference.
649  */
650  inline TetherPotential& MdSystem::tetherPotential() const
651  {
652  assert(tetherPotentialPtr_);
653  return *tetherPotentialPtr_;
654  }
655  #endif
656 
657  /*
658  * Return the MdIntegrator by reference.
659  */
660  inline MdIntegrator& MdSystem::mdIntegrator()
661  {
662  assert(mdIntegratorPtr_);
663  return *mdIntegratorPtr_;
664  }
665 
666  /*
667  * Signal to indicate change in atomic positions.
668  */
669  inline Signal<>& MdSystem::positionSignal()
670  { return positionSignal_; }
671 
672  /*
673  * Signal to indicate change in atomic velocities.
674  */
675  inline Signal<>& MdSystem::velocitySignal()
676  { return velocitySignal_; }
677 
678 }
679 #endif
Coulomb potential for an Md simulation.
A System for use in a Markov chain Monte Carlo simulation.
Definition: McSystem.h:52
A Vector is a Cartesian vector.
Definition: Vector.h:75
Interface for a Angle Interaction.
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
File containing preprocessor macros for error handling.
Specialized potential for an MD simulation.
Abstract base for molecular dynamics integrators.
Definition: MdIntegrator.h:30
Interface for a Dihedral Potential.
Saving / output archive for binary ostream.
Abstract External Potential class.
Utility classes for scientific computation.
Definition: accumulators.mod:1
An PairPotential for MD simulation.
Saving archive for binary istream.
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
Abstract Bond Potential class.
Notifier (or subject) in the Observer design pattern.
Definition: Signal.h:38
A System for Molecular Dynamics simulation.
Definition: MdSystem.h:68
System configuration file reader and writer.