delta = delta / temperature if metropolis(delta): # Accept Metropolis test total = total + partial_new - partial_old # Update total values total_spr = total_spr + partial_new_spr - partial_old_spr # Update quantum system potential r[k, i, :] = rki # Update position r_moves = r_moves + 1 # Increment move counter r_ratio = r_moves / (n * p) c_ratio = c_moves / n 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 for k in range(p): write_cnf_atoms(cnf_prefix + str(k).zfill(2) + '.' + sav_tag, n, box, r[k, :, :] * box) # Save configuration run_end(calc_variables()) total = potential(box, r_cut, r) # Double check book-keeping assert not total.ovr, 'Overlap in final configuration' total_spr = spring(box, k_spring, r) for k in range(p): write_cnf_atoms(cnf_prefix + str(k).zfill(2) + '.' + out_tag, n, box, r[k, :, :] * box) # Save configuration conclusion()
kin = 0.5*np.sum(v**2) / n print("{:40}{:15.6f}".format('Kinetic energy',kin) ) if np.fabs(delta_rho) < tol and np.fabs(delta_kin) < tol: print('No changes requested') else: if np.fabs(delta_rho) > tol: assert rho+delta_rho > 0.0, 'New requested density would be negative' scale = ( rho / (rho+delta_rho) )**(1.0/3.0) box = box * scale r = r * scale rho = n / box**3 print("{:40}{:15.6f}".format('Density',rho) ) if np.fabs(delta_kin) > tol: assert kin+delta_kin > 0.0, 'New requested kinetic energy would be negative' scale = np.sqrt ( (kin+delta_kin) / kin ) v = v * scale kin = 0.5*np.sum(v**2) / n print("{:40}{:15.6f}".format('New kinetic energy',kin) ) if atomic: if velocities: write_cnf_atoms ( filename, n, box, r, v ) else: write_cnf_atoms ( filename, n, box, r ) else: if velocities: write_cnf_mols ( filename, n, box, r, e, v, w ) else: write_cnf_mols ( filename, n, box, r, e )
if accepted: n_acc = n_acc + 1 q_min, q_max = update_histogram(q, q_min, q_max) c_ratio = n_acc / n_crank blk_add(calc_variables()) blk_end(blk) # Output block averages flat = histogram_flat(flatness, q_min, q_max, h) # Check for flatness if flat: # End of this stage print("{:63}".format('-' * 63)) print("{:5}{:3d}{:22}{:3d}{:3d}{:3d}".format( 'stage', stage, ' q_min q_max q_count =', q_min, q_max, np.count_nonzero(h[q_min:q_max + 1] > 0.5))) print("{:63}".format('-' * 63)) sav_tag = str(stage).zfill( 3) if stage < 1000 else 'sav' # Number configuration by stage write_cnf_atoms(cnf_prefix + sav_tag, n, bond, r) # Save configuration write_histogram(his_prefix + sav_tag) # Save histogram stage = stage + 1 # Ready for next stage ds = ds / 2.0 # Entropy change reduction run_end(calc_variables() ) # Output run averages, although these are really not relevant write_results() # Specimen results at selected temperatures write_cnf_atoms(cnf_prefix + out_tag, n, bond, r) # Save configuration conclusion()
if k == i or k == j or partner[k] == i or partner[k] == j: coltime[k], partner[k] = update(k, box, r[k:, :], v[k:, :]) # Search for partners <i if i > 0: coltime[:i], partner[:i] = dndate(i, box, r[:i + 1, :], v[:i + 1, :], coltime[:i], partner[:i]) if j > 0: coltime[:j], partner[:j] = dndate(j, box, r[:j + 1, :], v[:j + 1, :], coltime[:j], partner[:j]) ncoll = ncoll + col_sum # Calculate and accumulate variables for this step 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, box, r * box, v) # Save configuration run_end(calc_variables()) print("{:40}{:15d} ".format('Total collisions', ncoll)) assert not overlap(box, r), 'Particle overlap in final configuration' write_cnf_atoms(cnf_prefix + out_tag, n, box, r * box, v) # Save configuration conclusion()
total2 = total2_new # Update total values box1 = box1_new # Update box lengths box2 = box2_new # Update box lengths v_ratio = 1.0 # Set move counter blk_add(calc_variables()) rho_vals[stp, :] = [n1 / box1**3, n2 / box2**3] eng_vals[stp, :] = [ 1.5 * temperature + total1.pot / n1, 1.5 * temperature + total2.pot / n2 ] blk_end(blk) # Output block averages sav_tag = str(blk).zfill( 3) if blk < 1000 else 'sav' # Number configuration by block write_cnf_atoms(cnf1_prefix + sav_tag, n1, box1, r1 * box1) # Save configuration write_cnf_atoms(cnf2_prefix + sav_tag, n2, box2, r2 * box2) # Save configuration # Increment histograms rho_h, rho_bins = np.histogram(rho_vals, bins=nh, range=(rho_min, rho_max)) eng_h, eng_bins = np.histogram(eng_vals, bins=nh, range=(eng_min, eng_max)) rho_hist = rho_hist + rho_h eng_hist = eng_hist + eng_h run_end(calc_variables()) # Write out histograms norm = 2 * nstep * nblock * (rho_bins[1] - rho_bins[0]) rho_hist = rho_hist / norm norm = 2 * nstep * nblock * (eng_bins[1] - eng_bins[0])