Simple Optimization#
Introduction#
The workflow of optimization is built on top of the SCF calculation. Basically, you adjust the structure based on the energy and forces calculated in the SCF calculation.
The tutorial files associated in this example can by found here: link to files
Input files#
Similar to the SCF calculation, the input files for optimization are the same. The only difference is that you need to provide additional information about the optimization.
File |
Description |
|---|---|
SLURM script |
Submits the job to the cluster with required resources and environment |
Python script |
Controls the workflow |
Structure file |
Contains the atomic positions and lattice vectors of your system |
Python file#
In the python file you need to provide the additional following information:
from ase.optimize import LBFGS
"... (other parts of the script)"
# Set the Maximum force threshold (fmax) parameter
fmax = 1e-4 * Rydberg / Bohr # ~0.0025 eV/Angstrom
# Initialize the optimizer
opt = LBFGS(atm, logfile="opt.log", trajectory="opt.traj", restart="opt.pckl")
# Run the optimization
opt.run(fmax=fmax)
# Save the final structure
write("relaxed.vasp", atm)
Note
LBFGS/BFGS optimizer parameters As you would have noticed, there are parameters set in the initialization of the optimizer. Here are some explanation:
logfile: The file where the optimizer will write the optimization process per iteration.trajectory: The file where the optimizer will write the trajectory or structure of each iteration.restart: The file where the optimizer will save the state of the optimization. This is useful when you want to continue the optimization from a certain point.
I’ll show a safe restart method in the next section.
Structure file#
For this tutorial, we try to optimize HB sheet. The structure provided is already in a relaxed form and won’t proceed with optimization if we use it. So, we artificially add small random displacements (rattle) to the atomic positions to make the structure not relaxed.
# Implemented already in the python file
# 1. INPUT STRUCTURE FILE
# 1.a - Read the input structure file
atm = read("pristine_vdw.vasp") # Read the input structure file
# 1.b - Apply artificial distortions
atm.rattle(stdev=0.0004, seed=0) # -- Apply a small random displacement to the atoms
Here is a quick look on the unaltered structure and the rattled structure:
As you can see, the Rattled structure (stdev=0.0004) that we use in the calculation is just slightly distored that it is hard to see the difference. For clarity, a highly rattled structure (stdev=0.1) is shown to better see the difference. We still use the rattle structure with stdev=0.0004 in the calculation because the highly rattled structure takes too much time to converge.
Output file#
We need 3 files to analyze the relaxation carefully.
opt.log- Contains the optimization process per iteration. We need to check if the computed force is below the threshold.opt.traj- Contains the trajectory of the optimization. We need to visualize the trajectory to see the final structure and the “path” travelled.relaxed.vasp- Contains the final structure of the optimization. For easy checking in the future, we save the final structure.