def main(): tomlfile = sys.argv[1] if len(sys.argv) > 1 else "input.toml" rxparams = RXParams.from_toml(tomlfile) nreplicas = rxparams.nreplicas nprocs_per_replica = rxparams.nprocs_per_replica kB = 8.6173e-5 comm = RX_MPI_init(rxparams) # RXMC parameters # specify temperatures for each replica, number of steps, etc. kTstart = rxparams.kTstart kTend = rxparams.kTend kTs = kB * np.linspace(kTstart, kTend, nreplicas) # Set Lreload to True when restarting Lreload = rxparams.reload nsteps = rxparams.nsteps RXtrial_frequency = rxparams.RXtrial_frequency sample_frequency = rxparams.sample_frequency print_frequency = rxparams.print_frequency dftparams = DFTParams.from_toml(tomlfile) if dftparams.solver == 'vasp': solver = VASPSolver(dftparams.path) elif dftparams.solver == 'qe': solver = QESolver(dftparams.path) else: print('unknown solver: {}'.format(dftparams.solver)) sys.exit(1) # model setup # we first choose a "model" defining how to perform energy calculations and trial steps # on the "configuration" defined below energy_calculator = runner(base_input_dir=dftparams.base_input_dir, Solver=solver, nprocs_per_solver=nprocs_per_replica, comm=MPI.COMM_SELF, perturb=dftparams.perturb, solver_run_scheme=dftparams.solver_run_scheme) model = dft_latgas(energy_calculator, save_history=False) # defect sublattice setup configparams = DFTConfigParams.from_toml(tomlfile) spinel_config = defect_config(configparams) configs = [] for i in range(nreplicas): configs.append(copy.deepcopy(spinel_config)) obsparams = ObserverParams.from_toml(tomlfile) # RXMC calculation RXcalc = TemperatureRX_MPI(comm, CanonicalMonteCarlo, model, configs, kTs) if Lreload: RXcalc.reload() obs = RXcalc.run( nsteps, RXtrial_frequency, sample_frequency, print_frequency, observer=default_observer(comm, Lreload), subdirs=True, ) if comm.Get_rank() == 0: print(obs)
grid = grid_1D(0.02, 0.02, 5.0) g_r_OY = g_r(MCcalc.config.structure, "O", "Y", grid) g_r_OZr = g_r(MCcalc.config.structure, "O", "Zr", grid) g_r_YY = g_r(MCcalc.config.structure, "Y", "Y", grid) # energy2 = energy**2.0 # xparam = MCcalc.model.xparam(MCcalc.config) outputfi.write( "\t".join([str(observable) for observable in [MCcalc.kT, energy]]) + "\n") outputfi.flush() scalar_obs = [MCcalc.kT, energy] return obs_encode(scalar_obs, g_r_OY, g_r_OZr, g_r_YY) kB = 8.6173e-5 comm, nreplicas, nprocs_per_replica = RX_MPI_init() # defect sublattice setup ################################################################ cation_sites = [[0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]] anion_sites = [ [0.2500000000000000, 0.2500000000000000, 0.2500000000000000], [0.7500000000000000, 0.7500000000000000, 0.7500000000000000], [0.7500000000000000, 0.7500000000000000, 0.2500000000000000], [0.2500000000000000, 0.2500000000000000, 0.7500000000000000], [0.7500000000000000, 0.2500000000000000, 0.7500000000000000], [0.2500000000000000, 0.7500000000000000, 0.2500000000000000], [0.2500000000000000, 0.7500000000000000, 0.7500000000000000], [0.7500000000000000, 0.2500000000000000, 0.2500000000000000], ]
def main(): # Input parser parser = argparse.ArgumentParser( description="Reorganize abICS RXMC results by temperature") parser.add_argument("inputfi", help="toml input file used for abICS run") parser.add_argument( "skipsteps", nargs="?", type=int, default=0, help="number of thermalization steps to skip in energy averaging." + " Default: 0", ) args = parser.parse_args() inputfi = args.inputfi nskip = args.skipsteps rxparams = RXParams.from_toml(inputfi) nreplicas = rxparams.nreplicas comm = RX_MPI_init(rxparams) myreplica = comm.Get_rank() if myreplica == 0: if os.path.exists("Tseparate"): shutil.move("Tseparate", "Tseparate.bak.{}".format(datetime.datetime.now())) os.mkdir("Tseparate") comm.Barrier() # Separate structure files os.mkdir(os.path.join("Tseparate", str(myreplica))) Trank_hist = np.load(os.path.join(str(myreplica), "Trank_hist.npy")) os.chdir(str(myreplica)) for j in range(len(Trank_hist)): shutil.copy( "structure.{}.vasp".format(j), os.path.join(os.pardir, "Tseparate", str(Trank_hist[j])), ) # Separate energies myreplica_energies = np.load("obs_save.npy")[:, 0] for Tid in range(nreplicas): T_energies = np.where(Trank_hist == Tid, myreplica_energies, 0) T_energies_rcvbuf = np.zeros(T_energies.shape[0], "d") comm.Reduce( [T_energies, MPI.DOUBLE], [T_energies_rcvbuf, MPI.DOUBLE], op=MPI.SUM, root=Tid, ) if myreplica == Tid: np.savetxt( os.path.join(os.pardir, "Tseparate", str(Tid), "energies.dat"), T_energies_rcvbuf, ) comm.Barrier() if myreplica == 0: os.chdir(os.path.join(os.pardir, "Tseparate")) with open("energies_T.dat", "w") as fi: kTs = np.load(os.path.join(os.pardir, "kTs.npy")) Ts = kTs / constants.value(u"Boltzmann constant in eV/K") for Tid in range(nreplicas): energy_mean = np.mean( np.loadtxt(os.path.join(str(Tid), "energies.dat"))[nskip:]) fi.write("{}\t{}\n".format(Ts[Tid], energy_mean))