# Read in initial configuration n, bond, r = read_cnf_atoms(cnf_prefix + inp_tag) print("{:40}{:15d} ".format('Number of particles', n)) print("{:40}{:15.6f}".format('Bond length (in sigma units)', bond)) # Initialize arrays for averaging and write column headings m_ratio = 0.0 run_begin(calc_variables()) for blk in range(1, nblock + 1): # Loop over blocks blk_begin() for stp in range(nstep): # Loop over steps r, accepted = regrow(temperature, m_max, k_max, bond, k_spring, r) m_ratio = 1.0 if accepted else 0.0 blk_add(calc_variables()) blk_end(blk) # Output block averages sav_tag = str(blk).zfill( 3) if blk < 1000 else 'sav' # Number configuration by block write_cnf_atoms(cnf_prefix + sav_tag, n, bond, r) # Save configuration run_end(calc_variables()) write_cnf_atoms(cnf_prefix + out_tag, n, bond, r) # Save configuration conclusion()
xi = x[i] pot_cl_old = 0.5 * xi**2 / p pot_qu_old = 0.5 * k_spring * ((xi - x[im1])**2 + (xi - x[ip1])**2) xi = xi + zeta * dx_max # Trial move to new position pot_cl_new = 0.5 * xi**2 / p pot_qu_new = 0.5 * k_spring * ((xi - x[im1])**2 + (xi - x[ip1])**2) delta = (pot_cl_new + pot_qu_new - pot_cl_old - pot_qu_old) / temperature if metropolis(delta): # Accept Metropolis test pot_cl = pot_cl + pot_cl_new - pot_cl_old # Update classical potential energy pot_qu = pot_qu + pot_qu_new - pot_qu_old # Update quantum potential energy x[i] = xi # Update position moves = moves + 1 # Increment move counter m_ratio = moves / p if blk >= 0: blk_add(calc_variables()) if blk >= 0: blk_end(blk) run_end(calc_variables()) e_qu = e_pi_sho(p, beta) print("{:8}{:8d}{:7}{:15.6f}".format('Exact P=', p, ' energy', e_qu)) e_qu = 0.5 / math.tanh(0.5 * beta) print("{:23}{:15.6f}".format('Exact P=infinity energy', e_qu))