Iteratively run a scf job

Import Driver from QEpy

[1]:
from qepy.driver import Driver

Try to initialize the parallel

[2]:
try:
    from mpi4py import MPI
    comm=MPI.COMM_WORLD
except:
    comm=None

Initialize a QEpy driver

[3]:
driver=Driver('qe_in.in', comm=comm, iterative=True, logfile=True)
driver.get_output();

Diagoalize the hamiltonian

[4]:
driver.diagonalize()

Get the output from QE

[5]:
print(''.join(driver.get_output()))

     total cpu time spent up to now is        0.1 secs

     Self-consistent Calculation

     iteration #  1     ecut=    40.00 Ry     beta= 0.70
     Davidson diagonalization with overlap
     ethr =  1.00E-02,  avg # of iterations =  6.0

     Threshold (ethr) on eigenvalues was too large:
     Diagonalizing with lowered threshold

     Davidson diagonalization with overlap
     ethr =  4.15E-04,  avg # of iterations =  6.0

Mixing the density

[6]:
driver.mix()
print(''.join(driver.get_output()))

     total energy              =    -547.87228845 Ry
     Harris-Foulkes estimate   =    -552.98395983 Ry
     estimated scf accuracy    <       0.18384145 Ry

Repeat the diagonalize and mix

[7]:
driver.diagonalize()
driver.mix()
print(''.join(driver.get_output()))

     iteration #  2     ecut=    40.00 Ry     beta= 0.70
     Davidson diagonalization with overlap
     ethr =  4.18E-04,  avg # of iterations =  2.0

     total energy              =    -552.21322908 Ry
     Harris-Foulkes estimate   =    -553.01029870 Ry
     estimated scf accuracy    <       0.26179117 Ry

Repeat the diagonalize and mix, until converge

[8]:
for i in range(40):
    driver.diagonalize()
    driver.mix()
    converged = driver.check_convergence()
    if converged : break
[9]:
driver.get_scf_error()
[9]:
2.568830612113917e-09
[10]:
driver.get_scf_steps()
[10]:
27
[11]:
driver.get_energy() # Ry
[11]:
-552.934773888642
[12]:
driver.get_forces() # Ry/au
[12]:
array([[-8.35134989e-03,  3.16389540e-08,  1.39021403e-07],
       [ 7.84463365e-03, -1.17617196e-07,  3.65640857e-08],
       [ 7.84832955e-03,  2.96114229e-08, -1.83683268e-07],
       [-7.34161332e-03,  5.63668194e-08,  8.09777957e-09]])
[13]:
driver.get_stress() # Ry/bohr**3
[13]:
array([[ 6.13985689e-07, -6.33397323e-12,  8.53309208e-11],
       [-6.33397323e-12, -2.56059016e-03, -1.62509654e-10],
       [ 8.53309208e-11, -1.62509654e-10, -2.56118400e-03]])

Stop the driver before you run another different job

[14]:
driver.stop()