def _callback(fn, it, **kwargs): if it % interval == 0: kset.ctx().create_storage_file() store_density_potential(E.density, E.potential) mag_mom = E.density.compute_atomic_mag_mom() save_state({ 'f': fn, 'ek': kset.e, 'mag_mom': mag_mom }, kset=kset, prefix='fn_%05d_' % it)
def _callback(fn, it, **kwargs): if it % interval == 0: save_state({'f': fn}, kset=kset, prefix='fn_%05d_' % it)
kset = res['kpointset'] potential = res['potential'] density = res['density'] hamiltonian = res['hamiltonian'] H = ApplyHamiltonian(hamiltonian, kset) E = Energy(kset, potential, density, H) T = args.T kT = kb*T nel = ctx.unit_cell().num_valence_electrons() smearing = GaussianSplineSmearing(T=T, nel=nel, nspin=2, kw=kset.w) # smearing = RegularizedFermiDiracSmearing(T=T, nel=nel, nspin=2, kw=kset.w) fn = kset.fn X = kset.C M = FreeEnergy(H=H, E=E, T=T, smearing=smearing) cg = CG(M, fd_slope_check=args.check_slope) tstart = time.time() FE, X, fn, success = cg.run(X, fn, maxiter=args.maxiter, ninner=args.ni, prec_type=args.precond, tol=args.tol, callback=callback(kset)) tstop = time.time() logger('cg.run took: ', tstop-tstart, ' seconds') if not success: logger('!!! CG DID NOT CONVERGE !!!') logger('final energy:', M(X, fn)) save_state({'X': X, 'f': fn}, kset=kset, prefix='marzari_final')
smearing = make_gaussian_spline_smearing(T, ctx, kset) M = FreeEnergy(E=E, T=T, smearing=smearing) cg = CG(M) tstart = time.time() def callback(kset, interval=50, **kwargs): def _callback(fn, it, **kwargs): if it % interval == 0: save_state({'f': fn}, kset=kset, prefix='fn_%05d_' % it) return _callback X, fn = cg.run(X, fn, tol=args.tol, prec=use_prec, prec_type=args.precond, maxiter=args.maxiter, kappa=args.kappa, eps=args.eps, restart=args.restart, cgtype=args.cg_type, tau=args.tau, callback=callback(kset)) tstop = time.time() logger('cg.run took: ', tstop - tstart, ' seconds') logger('final energy:', M(X, fn)) save_state({'X': X, 'f': fn}, kset=kset, prefix='neuge_final')