def init_one_atom_normal(num_walkers, prop_range, num_molecules, filename): # Read the xyz file generated by Webmo (used to calculate Ground State energy) # Return the file in the shape of a ndarray walk = out.read_xyz(filename, num_molecules)['w'] # Broadcasts xyz file output to inputted size given by num_walkers # Propagate walkers by a prop_range and then return walkers = np.broadcast_to(walk[0], (num_walkers, num_molecules, 3, 3)) + \ np.random.normal(-prop_range, prop_range, (num_walkers, num_molecules, 3, 3)) return walkers
# Filename (string) # Used to initialize system. Should be a .xyz filename with the xyz positions of # one walker in the system. filename = 'm_tetramer.xyz' # If using WebMO intitialization, uncomment this line below # Reads in a .xyz file of a 1 walker system and broadcasts to n_walker array with # some amount of propagation simulate some randomness but not so much that the system # cannot equilibrate # Propagation amount prop_amount = .5 #walkers = np.random.uniform(-prop_amount, prop_amount, (n_walkers, num_molecules, 3, 3)) #walkers = np.load('r_tetramer.npy', allow_pickle = True) walkers, num_molecules = out.gen_walker_array(filename, n_walkers, prop_amount, num_molecules) # Uncomment the code below if doing an initialization within a random range # Initial 4D walker array # Returns a uniform distribution cenetered at the given bond length # Array axes are walkers, molecules, atoms, coordinates #walkers = (np.random.rand(n_walkers, num_molecules, lib.atomic_masses.shape[0],lib.coord_const) - .5) # Uncomment this line if loading in an already equliibrated walker array #walkers = np.load('5000_walker.npy') ####################################################################################### # Simulation start = time.time() # Equilibriate Walkers
[lib.sim_loop(snapshots[i],prop_steps,dt,do_dw=True)['a'] \ for j in range(prop_reps)],axis=-1),axis=1) # print(ancestor_weights.shape) # Calculate the distance between one of the OH vectors # Used in the histogram and wave function plot CO_lengths = np.linalg.norm(walkers[:, 0, 0] - walkers[:, 0, 1], axis=1) plt.figure(i) # Get the range to graph the wave function in # Step is .001, which is usually a good smooth value x = np.arange(CO_lengths.min(), CO_lengths.max(), step=.001) plt.hist(CO_lengths, weights=ancestor_weights, bins=n_bins, density=True) #TODO maybe square this function? plt.plot(x, lib.norm_constant * np.exp(-((x - lib.eq_bond_length)**2) * np.sqrt(lib.kCO * lib.reduced_mass) / 2), label='Wave Function') plt.xlabel('CO Bond Length') plt.ylabel('Density') plt.title(f'Density of CO Bond Length at Snapshot {i*prop_interval}') np.save('CO_DW_snap_' + str(i) + '.npy', walkers) out.write_array('CO_DW_snap_' + str(i), ancestors=ancestor_weights, atoms=['C', 'O']) plt.show()