This tutorial can be downloaded link.

1.0 Getting started: Ground state density functional theory calculations

We are going to generate an input file for the Quantum ESPRESSO or Qbox code. Each code will compute the ground state electronic stucture for the methane molecule using density functional theory.

Step 1: Load WESTpy

[1]:
from westpy import *

 _    _ _____ _____ _____
| |  | |  ___/  ___|_   _|
| |  | | |__ \ `--.  | |_ __  _   _
| |/\| |  __| `--. \ | | '_ \| | | |
\  /\  / |___/\__/ / | | |_) | |_| |
 \/  \/\____/\____/  \_/ .__/ \__, |
                       | |     __/ |
                       |_|    |___/

WEST version     :  6.3.0
Today            :  2026-03-14 16:31:14.060486

Step 2: Define geometry

[2]:
geom = Geometry()

Let’s define a cubic cell of edge 25 Bohr.

[3]:
geom.setCell((25,0,0),(0,25,0),(0,0,25))

We load the atomic positions from a XYZ file, available online.

[4]:
geom.addAtomsFromOnlineXYZ( "https://west-code.org/doc/training/methane/CH4.xyz" )

We associate pseudopotential files to each species.

[5]:
geom.addSpecies( "C", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.2.upf")
geom.addSpecies( "H", "http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.2.upf")

Step 3.1: Generate input file for Quantum ESPRESSO

The ground state calculation is defined by the geometry, a choice of the exchange-correlation functional, and by setting an energy cutoff for the wavefunctions.

[6]:
gs = GroundState(geom,xc="PBE",ecut=40.0)

We are now able to generate the input file for Quantum ESPRESSO.

[7]:
gs.generateInputPW()

Generated file:  pw.in

We can inspect the file pw.in

[8]:
with open("pw.in","r") as file :
    data = file.read()
    print(data)
&CONTROL
calculation       = 'scf'
restart_mode      = 'from_scratch'
pseudo_dir        = './'
outdir            = './'
prefix            = 'calc'
wf_collect        = .TRUE.
/
&SYSTEM
ibrav             = 0
nat               = 5
ntyp              = 2
ecutwfc           = 40.0
nbnd              = 8
input_dft         = 'PBE'
nosym             = .TRUE.
noinv             = .TRUE.
/
&ELECTRONS
diago_full_acc = .TRUE.
conv_thr       = 1.d-8
/
ATOMIC_SPECIES
C 12.011 C_ONCV_PBE-1.2.upf
H 1.008 H_ONCV_PBE-1.2.upf
ATOMIC_POSITIONS {bohr}
C 0.0 0.0 0.0
H 1.1859921166189487 -1.1858031440063577 1.1859921166189487
H -1.1859921166189487 1.1859921166189487 1.1859921166189487
H -1.1859921166189487 -1.1859921166189487 -1.1859921166189487
H 1.1859921166189487 1.1859921166189487 -1.1859921166189487
K_POINTS {gamma}
CELL_PARAMETERS {bohr}
25.0 0.0 0.0
0.0 25.0 0.0
0.0 0.0 25.0

We can optionally also download the pseudopotentials files.

[9]:
gs.downloadPseudopotentials()
Downloaded file:  C_ONCV_PBE-1.2.upf , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/upf/C_ONCV_PBE-1.2.upf
Downloaded file:  H_ONCV_PBE-1.2.upf , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/upf/H_ONCV_PBE-1.2.upf

Step 3.2: Generate input file for Qbox

To generate the input for Qbox, we can simply update Species to use the XML format.

[10]:
gs.updateSpecies("C", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.2.xml")
gs.updateSpecies("H", "http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.2.xml")

We are now able to generate the input file for Qbox.

[11]:
gs.generateInputQbox()

Generated file:  qbox.in

We can inspect the file qbox.in

[12]:
with open("qbox.in","r") as file :
    data = file.read()
    print(data)
set cell 25.0 0.0 0.0 0.0 25.0 0.0 0.0 0.0 25.0
species Carbon http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.2.xml
species Hydrogen http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.2.xml
atom C1 Carbon 0.0 0.0 0.0
atom H2 Hydrogen 1.1859921166189487 -1.1858031440063577 1.1859921166189487
atom H3 Hydrogen -1.1859921166189487 1.1859921166189487 1.1859921166189487
atom H4 Hydrogen -1.1859921166189487 -1.1859921166189487 -1.1859921166189487
atom H5 Hydrogen 1.1859921166189487 1.1859921166189487 -1.1859921166189487
set ecut 40.0
set wf_dyn JD
set xc PBE
set scf_tol 1.e-8
randomize_wf
run -atomic_density 0 100 5
save gs.xml

We can optionally also download the pseudopotentials files.

[13]:
gs.downloadPseudopotentials()
Downloaded file:  C_ONCV_PBE-1.2.xml , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/xml/C_ONCV_PBE-1.2.xml
Downloaded file:  H_ONCV_PBE-1.2.xml , from url:  http://www.quantum-simulation.org/potentials/sg15_oncv/xml/H_ONCV_PBE-1.2.xml