def main(system_params=None): from boost.mpi import world, broadcast from pylada.vasp.extract import Extract, ExtractGW from pylada.vasp.specie import U, nlep from pylada.vasp import Vasp import os from os import path from .nlep import Objective from pylada.vasp.nlep.postprocessing import find_best, load_test, prepare_analog_fit print("mpi rank %d of %d" % (world.rank, world.size)) # Things which need to be put into dictionary of input script. # global_dict = { "Extract": Extract, "ExtractGW": ExtractGW, "Vasp": Vasp, "nlep": nlep, "U": U } # read file governing run. other input files should be generic run_input = load_run_input() run_control = RunControl(run_input) load_from_analogs = run_input.load_from_analogs # create systems from .systems import setup_systems systems = setup_systems(run_input, system_params) if (run_input.nbjobs == -1): run_control.nbjobs = world.size assert world.size >= run_control.nbjobs, "Too few procs granted, or too many jobs requested." job_comm = world vasp_comm = world color = world.rank % run_control.nbjobs job_comm = world.split(color) vasp_comm = job_comm if (job_comm.size > 1): vasp_comm = job_comm.split(job_comm.rank) create_directories(run_control, systems, job_comm, color) # barrier to be sure all necessary directories exist world.barrier() # creates objective functions from systems for s in systems.systems: print(s.outdir) s.objective = Objective(s.input.vasp, s.input.dft_in, s.input.gw_in, outdir=s.outdir, comm=vasp_comm, units=run_input.units) s.evals_file = file("%s/evals" % s.outdir, "w") systems.evals_file = file("%s/evals" % run_control.outdir, "w") # setup correspondence between vector "x" and list of species (ie at least # one subpart shared by > 1 systems): systems.setup_species() # barrier to be sure all necessary directories exist world.barrier() # only serial vasp so far, but lmmin is a parallel fitter if (job_comm.rank != 0 and run_input.optimizer != "lmmin"): print("rank %d superfluous, returning; beware barrier" % world.rank) return print("world rank %d job %d local rank %d working dir %s" % (world.rank, color, job_comm.rank, run_control.outdir)) job_main(job_comm, run_input, systems, vasp_comm)
def main(): from boost.mpi import world from scipy.optimize import fmin as scipy_simplex from pylada.vasp import Extract, ExtractGW, Vasp, Specie from pylada.vasp.specie import nlep as nlep_parameters, U as u_parameters from pylada.vasp.incar import Standard, NBands from sys import exit indir = "SnO2" dft_in = Extract(directory=indir, comm=world) dft_in.OUTCAR = "OUTCAR_pbe" dft_in.CONTCAR = "POSCAR" gw_in = ExtractGW(directory=indir, comm=world) gw_in.OUTCAR = "OUTCAR_gw" gw_in.CONTCAR = "POSCAR" # Creates species with nlep parameters to optimize species = Specie\ ( "Sn", path="pseudos/Sn", U=[nlep_parameters(type="Dudarev", l=i, U0=0e0) for i in ["s", "p", "d"]] ),\ Specie\ ( "O", path="pseudos/O", U=[nlep_parameters(type="Dudarev", l=i, U0=0e0) for i in ["s", "p"]] ) # add U to Sn atoms. species[0].U.append( u_parameters(type="Dudarev", U=2e0, l=2) ) # creates vasp launcher vasp = Vasp\ ( kpoints = lambda x: "Automatic generation\n0\ngamma\n6 6 10\n0 0 0", precision = "accurate", smearing = "bloechl", ediff = 1e-5, relaxation = "ionic", encut = 1, # uses ENMAX * 1, which is VASP default species = species ) # adds some extra parameters. vasp.nbands = Standard("NBANDS", 64) vasp.lorbit = Standard("LORBIT", 10) vasp.npar = Standard("NPAR", 2) vasp.lplane = Standard("LPLANE", ".TRUE.") vasp.addgrid = Standard("ADDGRID", ".TRUE.") del vasp.fftgrid # creates objective function. objective = Objective(vasp, dft_in, gw_in) x0, f0, iter, funcalls, warnflag = scipy_simplex(objective, objective.x, maxfun=150, full_output=1, xtol=0.2) world.barrier() if world.rank == 0: print "minimum value:", f0 print "for: ", x0 * units print "after %i iterations and %i function calls." % (iter, funcalls) print "with warning flag: ", warnflag print final(x0)