oILAB
Loading...
Searching...
No Matches
CanonicalTPImplementation.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 8/14/24.
3//
4#ifndef OILAB_CANONICALTPIMPLEMENTATION_H
5#define OILAB_CANONICALTPIMPLEMENTATION_H
6
7#include <algorithm>
8#include <OrderedTuplet.h>
9
10namespace gbLAB {
11
12 template<typename StateType, typename SystemType>
14 const std::string& lmpLocation,
15 const std::string& potentialName,
16 const double& temperature,
17 const std::string& filename) :
18 lmpLocation(lmpLocation),
19 potentialName(potentialName),
20 temperature(temperature),
21 countTP(0)
22 {
23 if (!filename.empty())
24 output.open(filename);
25 }
26
27 template<typename StateType, typename SystemType>
28 double CanonicalTP<StateType,SystemType>::probability(const std::pair<StateType,SystemType>& proposedStateSystem,
29 const std::pair<StateType,SystemType>& currentStateSystem)
30 {
31 // calculate energies here
32 const auto& currentState= currentStateSystem.first;
33 const auto& currentSystem= currentStateSystem.second;
34 const auto& proposedState= proposedStateSystem.first;
35 const auto& proposedSystem= proposedStateSystem.second;
36
37 if(countTP==0) {
38 const auto &temp = currentSystem.densityEnergy(lmpLocation, potentialName, false);
39 currentDensity = std::get<0>(temp);
40 currentEnergy = std::get<1>(temp);
41 stateEnergyMap[currentState] = currentEnergy;
42 //std::cout << "density = " << currentDensity << ", energy = " << currentEnergy << std::endl;
43 }
44 else {
45 assert(stateEnergyMap.find(currentState) != stateEnergyMap.end());
46 currentEnergy= stateEnergyMap[currentState];
47 }
48
49 double proposedEnergy, proposedDensity;
50
51 //StateType proposedState(proposedStateSystemPair.first);
52 //SystemType proposedSystem(proposedStateSystemPair.second);
53 if (stateEnergyMap.find(proposedState) != stateEnergyMap.end()) {
54 proposedEnergy = stateEnergyMap.at(proposedState);
55 }
56 else {
57 const auto& temp= proposedSystem.densityEnergy(lmpLocation, potentialName, false);
58 proposedDensity= std::get<0>(temp);
59 proposedEnergy= std::get<1>(temp);
60 //proposedEnergy = proposedSystem.energy();
61 //std::cout << "density = " << proposedDensity << ", energy = " << proposedEnergy << std::endl;
62 stateEnergyMap[proposedState] = proposedEnergy;
63 }
64
65 countTP++;
66 double delta = proposedEnergy - currentEnergy;
67
68 if(output.is_open())
69 output << currentState << " " << currentState.density() << " " << currentEnergy << std::endl;
70 return std::min(1.0, exp(-delta / temperature));
71 }
72
73}
74#endif
std::ofstream output
Definition CanonicalTP.h:19
CanonicalTP(const std::string &lmpLocation, const std::string &potentialName, const double &temperature, const std::string &filename="")
double probability(const std::pair< StateType, SystemType > &proposedState, const std::pair< StateType, SystemType > &currentState)