# 4. Bulk Platinum

We'll end this session with a bulk metal, so that we can put together solids and molecules in the next session.
Please see the input file in `in`.

The geometry is specified by a face-centered cubic lattice, and a single Pt ion within it (specified in lattice coordinates).

We now need to specify k-points to sample the Brillouin zone and smearing to sample the Fermi surface:

    kpoint-folding 8 8 8
    elec-smearing Fermi 0.01

The above commands create a 8 x 8 x 8 ($\Gamma$-centered by default) k-point mesh
to integrate over all possible Bloch wave vectors,
and select a Fermi smearing - effectively an elevated electron temperature - of 0.01 Eh.
This is roughly 10 times room temperature, but is needed to sample the sharp Fermi surface
reliably without Nyquist sampling issues at the practical k-point counts considered here.
(The code also supports Gauss, Cold and Methfessel-Paxton schemes
to minimize errors associated with the elevated temperature.)

There is no ionic geometry to optimize this time, but we specify `lattice-minimize`
to optimize the lattice vectors starting from the initial experimental geometry.
Finally, `dump Ionic Lattice` asks for lattice vectors to be output at every geometry optimization step.


## Run the calculation

As before, start an interactive session:

    beast-interactive

run:

    srun -n 4 --gpus 4 jdftx_gpu -i in | tee out

and end the interactive session (`Ctrl+D`).
Note that we now ask for four MPI processes with one GPU each to fully use one Perlmutter node.
JDFTx is MPI-parallelized over reduced k-points and spin, reported as `nStates` in the output file.
Previously, we always had nStates = 1 and could only use one process (with remaining parallelization using CPU threads or GPU cores using CUDA).
Now, we have 29 states (reduced from 8 x 8 x 8 = 512 by symmetries), which we can split among more processes.
Since we have 4 GPUs on one Perlmutter node, we used 4 processes here with each covering 7-8 states.
If we wanted to use the CPUs, we could have used 29 processes with 1 core each, `srun -n 29 -c 1 jdftx -i in`.

(In practice, use `srun -n 1 jdftx -ni in` to perform a quick dry-run (no actual calculation)
to find `nStates` in order to decide the optimal parallelization strategy.)

In the lattice minimization output, notice that each step reports the stress and strain additionally.
The final strain (relative to initial) at convergence is 1.3\%: the lattice expands from experiment because PBE GGA underbinds solids.

Whenever we do lattice optimization, we must repeat the calculation till the strain within a run is small.
This is because the PW basis is kept fixed when the lattice changes to enable a smooth energy landscape for minimization.
However, the PW basis at a given KE cutoff depends on the lattice, and so we need to re-check convergence
and should only stop when the lattice does not change appreciably in a given run.

To continue, uncomment the `include jdftx.lattice` line and comment out the `lattice` command in `in`.
Run the code again now, and it will start with the lattice optimized in the previous run.
When we run it the second time, the strain is -0.001\%, and we don't need to rerun lattice optimization again.

## Visualization

Open the `Visualize.ipynb` in this directory to visualize the bulk Pt lattice.

## Further exercises

1. Convergence checks

    We don't have box size to converge for a bulk solid, but we do need to converge Brillouin zone sampling with k-points.
    For a metal, we additionally need to pick appropriate smearing and a commensurate k-point sampling.
    Perform the following convergence checks:

    + Try various k-point samplings from 1x1x1 to 12x12x12, how many k-points do you need for 1 mEh accuracy?
    + Change the smearing width between 0.001 (room temperature) to 0.01: how does the electron entropy contribution TS change?
    + Compare the entropy vs width variation for MP1 and Cold smearing in addition to Fermi.
    + How does the k-point convergence depend on smearing width?
    + Check the convergence of our recommended planewave cutoff. You could try elec-cutoff: 10 50, 15 75, 25 125. 

2. Bandstructure & density of states

    Try to calculate the bandstructure and density of states. 
    
    + For the bandstructure, you can use the inputs from and follow the latter part of the [Metals Tutorial](https://jdftx.org/Metals.html). 
    + For the density of states you can add the following inputs to your input file and follow the [Density of States Tutorial](https://jdftx.org/DensityOfStates.html) for plotting.

            elec-n-bands 12  
            converge-empty-states yes  
            density-of-states Total
