def compare(self, A, B, nnodes=10, nedges=20, weights=None, x=1): print("") maker = _MakeRandomGraph(nnodes=nnodes, nedges=nedges, node_set=A + B + [x]) graph = maker.run() graph_backup = graph.copy() reducer = GraphReduction(maker.rates, A, B, weights=weights) kmc = KineticMonteCarlo(graph_backup, debug=False) # test compute_committor_probability() PxB = reducer.compute_committor_probability(x) PxB_kmc = kmc.committor_probability(x, A, B, niter=1000) print("committor probability ", x, "->", B, "=", PxB) print("committor probability kmc", x, "->", B, "=", PxB_kmc) self.assertAlmostEqual(PxB, PxB_kmc, delta=.1) reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() rAB_SS = reducer.get_rate_AB_SS() # compute rate via linalg lin = TwoStateRates(maker.rates, A, B, weights=weights) lin.compute_rates() rAB_LA = lin.get_rate_AB() lin.compute_committors() rAB_SS_LA = lin.get_rate_AB_SS() self.assertAlmostEqual(rAB_SS, rAB_SS_LA, 5) PxB_LA = lin.get_committor(x) if x not in A and x not in B: self.assertAlmostEqual(PxB, PxB_LA, 5) rAB_KMC = kmc.mean_rate(A, B, niter=1000, weights=weights) print("NGT rate A->B", rAB) print("KMC rate A->B", rAB_KMC) print("normalized difference", old_div((rAB - rAB_KMC), rAB)) print("normalized difference to linalg", old_div((rAB - rAB_LA), rAB)) self.assertLess(old_div(abs(rAB - rAB_KMC), rAB), .1) self.assertLess(old_div(abs(rAB - rAB_LA), rAB), .00001) rBA_KMC = kmc.mean_rate(B, A, niter=1000, weights=weights) print("NGT rate B->A", rBA) print("KMC rate B->A", rBA_KMC) print("normalized difference", old_div((rBA - rBA_KMC), rBA)) self.assertLess(old_div(abs(rBA - rBA_KMC), rBA), .1) paB = kmc.committor_probability(A[0], [A[0]], B, niter=1000) print("the committor probability a->B", paB) print("graph reduction committor prob", reducer.get_committor_probabilityAB(A[0])) self.assertAlmostEqual(paB, reducer.get_committor_probabilityAB(A[0]), delta=.1)
def compare_linalg(self, A, B, nnodes=20, nedges=20): from pele.rates._rates_linalg import TwoStateRates maker = _MakeRandomGraph(nnodes=20, nedges=20, node_set=A + B) maker.run() reducer = NGT(maker.rates, A, B) reducer.compute_rates_and_committors() committors = reducer.get_committors() la = TwoStateRates(maker.rates, A, B) # la.compute_rates() la.compute_committors() qla = la.committor_dict for n, qla in la.committor_dict.items(): self.assertAlmostEqual(qla, committors[n], 7)
def compare_linalg(self, A, B, nnodes=20, nedges=20): from pele.rates._rates_linalg import TwoStateRates maker = _MakeRandomGraph(nnodes=20, nedges=20, node_set=A+B) maker.run() reducer = NGT(maker.rates, A, B) reducer.compute_rates_and_committors() committors = reducer.get_committors() la = TwoStateRates(maker.rates, A, B) # la.compute_rates() la.compute_committors() qla = la.committor_dict for n, qla in la.committor_dict.iteritems(): self.assertAlmostEqual(qla, committors[n], 7)
def initialize(self): self.minima2rates.run() self.two_state_rates = TwoStateRates( self.minima2rates.rate_constants, self.minima2rates.A, self.minima2rates.B, weights=self.minima2rates.weights, )
def _test_rate(self, i, j): reducer = TwoStateRates(self.rates, [i], [j]) reducer.compute_rates() rAB = reducer.get_rate_AB() self.assertAlmostEqual(rAB, self.final_rate, 7) reducer.compute_committors() rAB_ss = reducer.get_rate_AB_SS() print "kSS", rAB_ss self.assertAlmostEqual(rAB_ss, 1.5, 7)
def _test_rate(self, A, B): reducer = TwoStateRates(self.rates, A, B) reducer.compute_rates() reducer.compute_committors() kAB = reducer.get_rate_AB() self.assertAlmostEqual(kAB, self.true_kAB, 7) # kBA = reducer.get_rate_BA() # self.assertAlmostEqual(kBA, self.true_kBA, 7) rAB_SS = reducer.get_rate_AB_SS() self.assertAlmostEqual(rAB_SS, self.true_kAB_SS, 7)
def compare(self, A, B, nnodes=10, nedges=20, weights=None, x=1): print("") maker = _MakeRandomGraph(nnodes=nnodes, nedges=nedges, node_set=A+B+[x]) graph = maker.run() graph_backup = graph.copy() reducer = GraphReduction(maker.rates, A, B, weights=weights) kmc = KineticMonteCarlo(graph_backup, debug=False) # test compute_committor_probability() PxB = reducer.compute_committor_probability(x) PxB_kmc = kmc.committor_probability(x, A, B, niter=1000) print("committor probability ", x, "->", B, "=", PxB) print("committor probability kmc", x, "->", B, "=", PxB_kmc) self.assertAlmostEqual(PxB, PxB_kmc, delta=.1) reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() rAB_SS = reducer.get_rate_AB_SS() # compute rate via linalg lin = TwoStateRates(maker.rates, A, B, weights=weights) lin.compute_rates() rAB_LA = lin.get_rate_AB() lin.compute_committors() rAB_SS_LA = lin.get_rate_AB_SS() self.assertAlmostEqual(rAB_SS, rAB_SS_LA, 5) PxB_LA = lin.get_committor(x) if x not in A and x not in B: self.assertAlmostEqual(PxB, PxB_LA, 5) rAB_KMC = kmc.mean_rate(A, B, niter=1000, weights=weights) print("NGT rate A->B", rAB) print("KMC rate A->B", rAB_KMC) print("normalized difference", (rAB - rAB_KMC)/rAB) print("normalized difference to linalg", (rAB - rAB_LA)/rAB) self.assertLess(abs(rAB - rAB_KMC)/rAB, .1) self.assertLess(abs(rAB - rAB_LA)/rAB, .00001) rBA_KMC = kmc.mean_rate(B, A, niter=1000, weights=weights) print("NGT rate B->A", rBA) print("KMC rate B->A", rBA_KMC) print("normalized difference", (rBA - rBA_KMC)/rBA) self.assertLess(abs(rBA - rBA_KMC)/rBA, .1) paB = kmc.committor_probability(A[0], [A[0]], B, niter=1000) print("the committor probability a->B", paB) print("graph reduction committor prob", reducer.get_committor_probabilityAB(A[0])) self.assertAlmostEqual(paB, reducer.get_committor_probabilityAB(A[0]), delta=.1)
def _test_rate(self, i, j): reducer = TwoStateRates(self.rates, [i], [j]) reducer.compute_rates() rAB = reducer.get_rate_AB() self.assertAlmostEqual(rAB, self.final_rate, 7) reducer.compute_committors() rAB_ss = reducer.get_rate_AB_SS() print("kSS", rAB_ss) self.assertAlmostEqual(rAB_ss, 1.5, 7)
def do_check(self, A, B, nnodes=20, nedges=20): maker = _MakeRandomGraph(nnodes=20, nedges=20, node_set=A + B) rates = maker.make_rates() reducer = TwoStateRates(rates, A, B) reducer.compute_rates() reducer.compute_committors() from pele.rates._ngt_cpp import NGT ngt = NGT(rates, A, B) ngt.compute_rates() self.assertAlmostEqual(reducer.get_rate_AB(), ngt.get_rate_AB(), 7) self.assertAlmostEqual(reducer.get_rate_AB_SS(), ngt.get_rate_AB_SS(), 7)
class RatesLinalg(object): """this class duplicates the behavior in RateCalculation, but with the linalg solver""" _initialized = False _times_computed = False def __init__(self, transition_states, A, B, T=1., use_fvib=True): self.minima2rates = _Minima2Rates(transition_states, A, B, T=T, use_fvib=use_fvib) def initialize(self): self.minima2rates.run() self.two_state_rates = TwoStateRates(self.minima2rates.rate_constants, self.minima2rates.A, self.minima2rates.B, weights=self.minima2rates.weights) def compute_rates(self): if not self._initialized: self.initialize() if not self._times_computed: self.two_state_rates.compute_rates() self._times_computed = True return old_div(self.two_state_rates.get_rate_AB(), self.minima2rates.rate_norm) def get_mfptimes(self): if not self._initialized: self.initialize() if not self._times_computed: self.two_state_rates.compute_rates() times = self.two_state_rates.mfpt_computer.mfpt_dict self.mfpt_dict = dict( ((m, t * self.minima2rates.rate_norm) for m, t in times.items())) for m in self.minima2rates.B: self.mfpt_dict[m] = 0. return self.mfpt_dict def compute_committors(self): if not self._initialized: self.initialize() self.two_state_rates.compute_committors() self.committors = self.two_state_rates.committor_dict for m in self.minima2rates.A: self.committors[m] = 0. for m in self.minima2rates.B: self.committors[m] = 1. return self.committors def get_committors(self): return self.committors
def do_check(self, A, B, nnodes=20, nedges=20): maker = _MakeRandomGraph(nnodes=20, nedges=20, node_set=A+B) rates = maker.make_rates() reducer = TwoStateRates(rates, A, B) reducer.compute_rates() reducer.compute_committors() from pele.rates._ngt_cpp import NGT ngt = NGT(rates, A, B) ngt.compute_rates() self.assertAlmostEqual(reducer.get_rate_AB(), ngt.get_rate_AB(), 7) self.assertAlmostEqual(reducer.get_rate_AB_SS(), ngt.get_rate_AB_SS(), 7)
class RatesLinalg(object): """this class duplicates the behavior in RateCalculation, but with the linalg solver""" _initialized = False _times_computed = False def __init__(self, transition_states, A, B, T=1.0, use_fvib=True): self.minima2rates = _Minima2Rates(transition_states, A, B, T=T, use_fvib=use_fvib) def initialize(self): self.minima2rates.run() self.two_state_rates = TwoStateRates( self.minima2rates.rate_constants, self.minima2rates.A, self.minima2rates.B, weights=self.minima2rates.weights, ) def compute_rates(self): if not self._initialized: self.initialize() if not self._times_computed: self.two_state_rates.compute_rates() self._times_computed = True return self.two_state_rates.get_rate_AB() / self.minima2rates.rate_norm def get_mfptimes(self): if not self._initialized: self.initialize() if not self._times_computed: self.two_state_rates.compute_rates() times = self.two_state_rates.mfpt_computer.mfpt_dict self.mfpt_dict = dict(((m, t * self.minima2rates.rate_norm) for m, t in times.iteritems())) for m in self.minima2rates.B: self.mfpt_dict[m] = 0.0 return self.mfpt_dict def compute_committors(self): if not self._initialized: self.initialize() self.two_state_rates.compute_committors() self.committors = self.two_state_rates.committor_dict for m in self.minima2rates.A: self.committors[m] = 0.0 for m in self.minima2rates.B: self.committors[m] = 1.0 return self.committors def get_committors(self): return self.committors
def initialize(self): self.minima2rates.run() self.two_state_rates = TwoStateRates(self.minima2rates.rate_constants, self.minima2rates.A, self.minima2rates.B, weights=self.minima2rates.weights)