def relaxGPAW(structure, label, forcemax=0.1, niter_max=1, steps=10): # Set calculator # loop a number of times to capture if minimization stops with high force # due to the VariansBreak calls niter = 0 # If the structure is already fully relaxed just return it traj = Trajectory(label + '_lcao.traj', 'w', structure) while (structure.get_forces()** 2).sum(axis=1).max()**0.5 > forcemax and niter < niter_max: dyn = BFGS(structure, logfile=label + '.log') vb = VariansBreak(structure, dyn, min_stdev=0.01, N=15) dyn.attach(traj) dyn.attach(vb) dyn.run(fmax=forcemax, steps=steps) niter += 1 #print('relaxgpaw over',flush=True) return structure
def relax_VarianceBreak(structure, calc, label='', slab=None, niter_max=3, forcemax=0.1, zlim=None): # Set calculator structure.set_calculator(calc) if slab is not None: # Make temporary constraint Natoms_slab = slab.get_number_of_atoms() c_temp = FixAtoms(indices=[i for i in range(Natoms_slab)]) # Save old constraint c0 = structure.constraints # Apply temporary constraint structure.set_constraint(c_temp) # loop a number of times to capture if minimization stops with high force # due to the VariansBreak calls niter = 0 # If the structure is already fully relaxed just return it if (structure.get_forces()**2).sum(axis=1).max()**0.5 < forcemax: return structure while (structure.get_forces()** 2).sum(axis=1).max()**0.5 > forcemax and niter < niter_max: dyn = BFGSLineSearch_zlim(structure, zlim=zlim, logfile=label + '.log') vb = VariansBreak(structure, dyn, min_stdev=0.01, N=15) dyn.attach(vb) dyn.run(fmax=forcemax, steps=200) niter += 1 if slab is not None: # set constraint back to old one structure.set_constraint(c0) # relax a little with old constraints dyn = BFGSLineSearch_zlim(structure, zlim=zlim, logfile=label + '.log') dyn.run(fmax=forcemax, steps=20) return structure else: return structure
def relaxGPAW(structure, label, calc=None, forcemax=0.1, niter_max=1, steps=10): # Create calculator if calc is None: calc=GPAW(poissonsolver = PoissonSolver(relax = 'GS',eps = 1.0e-7), # C mode = 'lcao', basis = 'dzp', xc='PBE', gpts = h2gpts(0.2, structure.get_cell(), idiv = 8), # C occupations=FermiDirac(0.1), maxiter=99, # C #maxiter=49, # Sn3O3 mixer=Mixer(nmaxold=5, beta=0.05, weight=75), nbands=-50, #kpts=(1,1,1), # C kpts=(2,2,1), # Sn3O3 txt = label+ '_lcao.txt') else: calc.set(txt=label+'_true.txt') # Set calculator structure.set_calculator(calc) # loop a number of times to capture if minimization stops with high force # due to the VariansBreak calls niter = 0 # If the structure is already fully relaxed just return it if (structure.get_forces()**2).sum(axis = 1).max()**0.5 < forcemax: return structure traj = Trajectory(label+'_lcao.traj','w', structure) while (structure.get_forces()**2).sum(axis = 1).max()**0.5 > forcemax and niter < niter_max: dyn = BFGS(structure, logfile=label+'.log') vb = VariansBreak(structure, dyn, min_stdev = 0.01, N = 15) dyn.attach(traj) dyn.attach(vb) dyn.run(fmax = forcemax, steps = steps) niter += 1 return structure
from ase.optimize import BFGS from ase.io import read, write from ase.calculators.emt import EMT from ase.ga.relax_attaches import VariansBreak import sys fname = sys.argv[1] print('Now relaxing {0}'.format(fname)) a = read(fname) a.calc = EMT() dyn = BFGS(a, trajectory=None, logfile=None) vb = VariansBreak(a, dyn) dyn.attach(vb.write) dyn.run(fmax=0.05) a.info['key_value_pairs']['raw_score'] = -a.get_potential_energy() write(fname[:-5] + '_done.traj', a) print('Done relaxing {0}'.format(fname))