1 /*  -*- c++ -*-  */
2 #ifndef OUTPUTCACHE_H
3 #define OUTPUTCACHE_H
4 
5 #include "Real.h"
6 #include "PDB.h"
7 #include "PAR.h"
8 #include "iSGPAR.h"
9 #include "PSF.h"
10 #include "Vector3D.h"
11 
12 namespace ProtoMol {
13   class Output;
14   class Configuration;
15   class GenericTopology;
16   class ScalarStructure;
17   class Vector3DBlock;
18   class OutputFactoryDetails;
19   class Integrator;
20   struct PDB;
21   struct PDBAtom;
22   /**
23      OutputCache caches all kind of values, which may be needed
24      by Output objects and simplifies the access to values of interest.
25      Add new cached values, if needed ..
26      There are some (feature) values, which will only change when the
27      Topology changes
28   */
29   //________________________________________________________ OutputCache
30   class OutputCache  {
31     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32     // Constructors, destructors, assignment
33     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34   public:
35     OutputCache();
36     ~OutputCache();
37     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38     // New methods of class OutputCache
39     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40   public:
41     void initialize(const Configuration* config, const Integrator* integrator, const GenericTopology* topo,
42     		    const Vector3DBlock* pos, const Vector3DBlock*  vel, const ScalarStructure* energies);
43 
44     // Methods to add additional data for output objects
add(const std::vector<PDB::PDBAtom> & pdbAtoms)45     void add(const std::vector<PDB::PDBAtom>& pdbAtoms){myPDBAtoms = pdbAtoms;}
add(const PSF & psf)46     void add(const PSF& psf){myPSF = psf;}
add(const PAR & par)47     void add(const PAR& par){myPAR = par;}
add(const iSGPAR & par)48     void add(const iSGPAR& par){myiSGPAR = par;}
49 
50     Real     totalEnergy() const;
51     Real     potentialEnergy() const;
52     Real     kineticEnergy() const;
53     Real     temperature() const;
54     Real     temperatureForWater() const;
55     Real     temperatureForNonWater() const;
56     Real     volume() const;
57     Real     time() const;
58     Real     pressure() const;
59     Real     molecularPressure() const;
60     Real     molecularTemperature() const;
61     Real     molecularKineticEnergy() const;
62     Vector3D linearMomentum() const;
63     Vector3D angularMomentum() const;
64     Vector3D centerOfMass() const;
65     Real     diffusion() const;
66     Real     density() const;
67     Real     mass() const;
68     Real     dihedralPhi(int index) const;
69     Real     brent(Real ax, Real bx, Real cx, Real tol, Real &xmin, int dihindex, bool max) const;
70     std::vector<Real>                 dihedralPhis(std::vector<int>) const;
71     std::vector<std::vector< Real > > brentMaxima(std::vector<int>, bool) const;
72 
pdb()73     const std::vector<PDB::PDBAtom>& pdb() const {return myPDBAtoms;}
psf()74     const PSF&                       psf() const {return myPSF;}
par()75     const PAR&                       par() const {return myPAR;}
iSGpar()76     const iSGPAR&                    iSGpar() const {return myiSGPAR;}
77 
78     void uncache() const;
79     ///< To be called before every run() or finialize()
80     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81     // My data members
82     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83   private:
84     const Configuration*   myConfig;
85     const GenericTopology* myTopology;
86     const Integrator*      myIntegrator;
87     const ScalarStructure* myEnergies;
88     const Vector3DBlock*   myPositions;
89     const Vector3DBlock*   myVelocities;
90     Vector3DBlock*   myInitialPositions;
91 
92     // Additional data
93     std::vector<PDB::PDBAtom> myPDBAtoms;
94     PSF myPSF;
95     PAR myPAR;
96     iSGPAR myiSGPAR;
97 
98     mutable bool myCachedKE;
99     mutable Real myKE;
100     mutable Real myT;
101 
102     mutable bool myCachedPE;
103     mutable Real myPE;
104 
105     mutable bool myCachedV;
106     mutable Real myV;
107 
108     mutable bool myCachedP;
109     mutable Real myP;
110     mutable bool myCachedMolP;
111     mutable Real myMolP;
112 
113     mutable bool myCachedLinearMomentum;
114     mutable Vector3D myLinearMomentum;
115 
116     mutable bool myCachedAngularMomentum;
117     mutable Vector3D myAngularMomentum;
118 
119     mutable bool myCachedCenterOfMass;
120     mutable Vector3D myCenterOfMass;
121 
122     mutable bool myCachedDiffusion;
123     mutable Real myDiffusion;
124 
125     mutable bool myCachedDensity;
126     mutable Real myDensity;
127 
128     mutable bool myCachedMass;
129     mutable Real myMass;
130 
131     mutable int myCachedDihedralPhi;
132     mutable Real myDihedralPhi;
133 
134     mutable bool myCachedDihedralPhis;
135     mutable std::vector<Real>* myDihedralPhis;
136 
137     mutable bool myCachedBrentMaxima;
138     mutable std::vector< std::vector< Real > >* myBrentMaxima;
139 
140     mutable bool myCachedMolT;
141     mutable Real myMolT;
142 
143     mutable bool myCachedMolKE;
144     mutable Real myMolKE;
145 
146     mutable bool myCachedWaterT;
147     mutable Real myWaterT;
148 
149     mutable bool myCachedNonWaterT;
150     mutable Real myNonWaterT;
151 
152   };
153 }
154 #endif
155