rendered paste body# Perform a geomtry optimizationfrom ase import Atoms, PickleTrajectory, readfrom ase.optimize.lbfgs import LBFGS, LBFGSLineSearchfrom gpaw import GPAW, Mixer, MixerSum, ConvergenceError, PoissonSolverfrom gpaw.poisson import PoissonSolverfrom gpaw.eigensolvers.rmm_diis import RMM_DIISps = PoissonSolver(nn='M', relax='GS', eps=1e-9)es = RMM_DIIS(keep_htpsit=False)# Makes Python traceback appear only on the root processorimport sysfrom gpaw.mpi import worldfrom ase.utils import devnullif world.rank != 0: sys.stderr = devnullepsilon = 0.01 # small perturbationa = 4.08bulk = Atoms('Au4', positions=((0, 0 ,0), (0.5, 0.5, 0), (0.5, epsilon, 0.5), (0, 0.5, 0.5)), pbc=True)bulk.set_cell((a,a,a), scale_atoms=True)bulk = bulk.repeat((1, 1, 1))calc = GPAW(h=0.16, maxiter=200, mode = 'fd', poissonsolver = ps, nbands = 30, spinpol = False, xc = 'LDA', width = 0.01, mixer = Mixer(0.10, 5, 100.0), # mixer = MixerSum(0.10, 5, 100.0), # spinpol = True eigensolver = es, parallel = {'buffer_size':2048}, txt = 'Au_bulk.out')bulk.set_calculator(calc)# spinpol = True# magmom = 2.0# mms = [magmom for i in range(len(bulk))]# bulk.set_initial_magnetic_memonts(mms)mode = 'w'traj = PickleTrajectory('qn.traj', mode, bulk)relax = LBFGS(bulk, logfile = 'qn.log', trajectory = traj, restart= 'qn.pckl')# Check if there is enough time left, if not shutdown the calculation# Need to do this for the SCF and structural optimization seperatelwallclocktime = 2 # wallclock time limit in minutesfrom time import timeclass MaxTime: def __init__(self, nminutes): self.starttime = time() self.maxtime = nminutes * 60 def checkSCF(self): decision = 0 if world.rank == 0: now = time() if now - self.starttime > self.maxtime: decision = 1 decision = world.sum(decision) if decision: calc.scf.converged = True def checkOpt(self): decision = 0 if world.rank == 0: now = time() if now - self.starttime > self.maxtime: decision = 1 decision = world.sum(decision) if decision: relax.fmax = float('inf')StopCalculation = MaxTime(wallclocktime)calc.attach(StopCalculation.checkSCF)relax.attach(StopCalculation.checkOpt)relax.attach(lambda: calc.write('Au_bulk.%d.hdf5' % relax.nsteps))relax.run(fmax=0.05, steps=5) # This should stop in the middle of the 4 relaxation step