def calculatePositionDistribution(hbar): print("calculating for hbar=%0.4f" % hbar) p = Potential(-mu, lambda_) k = Kinetic(mass, tau) de = deltaEnergy(k, p) m = Metropolis(de, init=initial, valWidth=1, initValWidth=initial_random, hbar=hbar, tau=tau, N=N) vals = next(islice(m, iterations, iterations + 1)) # get iterations th metropolis iteration return list(np.histogram(vals[0], bins)[0]), vals[1]
def calculateTunnelingRate(distance): print('Calculating transition rate for distance %0.2f' % distance) # calculate potential parameter lambda_ = distanceToParameter(distance) p = Potential(mu, lambda_) a = Action(tau, mass, p) m = Metropolis(N, a, borders=[-10, 10], hbar=hbar, tau=tau) tC = TransitionCounter() for value in m: tC.registerValue(value) return tC.getTransitions()
def calculateEnergy(hbar): print('calculating for hbar=%0.4f' % hbar) m = Metropolis(init=initial, valWidth=random_width, initValWidth=initial_random, hbar=hbar, tau=tau, N=N, m=mass, lambda_=0, mu=mu) k = Kinetic(mass, tau) p = Potential(mu, 0) e = Energy(k, p) accept_ratios = [] energies = [] for _ in range(iterations): d, a = m.__next__() accept_ratios.append(a) energies.append(e(d)) energies = np.array(energies) # calculate mean energy d = energies[:-1] - energies[1:] da = running_mean(d, 10) if da[0] > 0: start = np.argmax(da < 0) + 10 else: start = np.argmax(da > 0) + 10 energies_cut = energies[start:] energies_cut_ac = autoCorrelationNormalized(energies_cut, np.arange(len(energies_cut))) # calculate integrated autocorrelation time tint, dtint, w_max = getIntegratedCorrelationTime(energies_cut_ac, factor=10) step_size = int((tint + dtint) * 2 + 1) energies_blocked = block(energies_cut, step_size) energy, denergy = np.mean(energies_blocked), np.std(energies_blocked) return [energy, denergy], np.mean(accept_ratios)
parameters = [ 'iterations', 'N', 'mass', 'mu', 'tau', 'hbar', 'initial', 'initial_random', 'step', 'random_width', ] # generate objects related to metropolis p = Potential(mu, 0) # harmonic potential -> no x^4 contribution de = deltaEnergy(p, mass, tau) if step: initial = [0.0] * int(N * 0.4) + [5.0] * int(N * 0.2) + [0.0] * int( N * 0.4) m = Metropolis(init=initial, valWidth=random_width, initValWidth=initial_random, hbar=hbar, tau=tau, N=N, m=mass, lambda_=0,
from matplotlib import pyplot as plt from tools import Potential, distanceToParameter import numpy as np # number of distances evaluated min_distance = 1 max_distance = 16 step_distance = 1 params = [ (10, 0, 'harm', 0) ] distances = np.arange(min_distance, max_distance, step_distance) params += [ (-10, distanceToParameter(d), 'anharm: %0.2f' %d, d) for d in distances ] for mu, lambda_, name, d in params: xvalues = np.arange(-5-d / 2, 5+d / 2, 0.01) p = Potential(mu, lambda_) yvalues = p(xvalues) plt.figure() plt.errorbar(xvalues, yvalues) plt.xlabel('Distance') plt.ylabel('Tunneling rate') plt.savefig('imgs/d_%s.png' %name) plt.savefig('imgs/d_%s.pdf' %name) plt.close()
mass = args.mass mu = args.mu tau = args.tau hbar = args.hbar initial = args.initial initial_random = args.initial_random distance = args.distance lambda_ = distanceToParameter(distance) output = args.output parameters = [ 'iterations', 'N', 'mass', 'mu', 'tau', 'hbar', 'initial', 'initial_random', 'distance', 'lambda_', ] p = Potential(-mu, lambda_) k = Kinetic(mass, tau) de = deltaEnergy(k, p) m = Metropolis(de, init=initial, valWidth=1, initValWidth=initial_random, hbar=hbar, tau=tau, N=N) root_path = getRootDirectory() dir_ = root_path / 'data' / 'anharmonic_oscillator_track' dir_.mkdir(parents=True, exist_ok=True) file_ = dir_ / ('N%di%dinit%sm%0.4fl%0.4fd%0.4f.csv' % (N, iterations, 'rand' if initial == None else str(initial), mass, lambda_, distance)) if output != '': file_ = dir_ / output