# 1. Solvated Pt surface with 0V SHE bias

Let's repeat the calculation from Session 2, Exercise 3, but through python.
Specifically, we will use the `sub_JDFTx.py` script from the GCNEB package to submit JDFTx calculations
(this will already be in your `PATH` after loading the beast tutorial module).

Notice the differences here:

1. There is a `POSCAR` file (VASP format) containing the geometry, allowing to interface with calculations started from other codes.

2. The `inputs` file contains familiar JDFTx commands, but does not specify the lattice and ionic geometry (now specified in POSCAR).

3. The `inputs` file contains additional parameters for the ASE-based GCNEB wrapper code in the "ASE Params" section.
   The important parameters to tune are 'restart', 'fmax' and 'econv'.
   Setting 'restart True' will tell the calculation to read the structure 
   from the CONTCAR file instead of the POSCAR file (VASP nomenclature).
   
4. The 'fmax' and 'econv' tags indicate the ASE force and energy convergence
   thresholds, in eV/A and eV, respectively. 
   Note that ionic minimization is now controlled by ASE, while electronic minimization occurs in JDFTx.


## Run the calculation

To display a list of script options, run:

    sub_JDFTx.py -h
  
To show a list of all parameters to control the ASE wrapper in `inputs`:  

    sub_JDFTx.py -i True
  

We can launch the calculation with:

    sub_JDFTx.py -o Pt-surf -test True -g True

which will write outputs to files prefixed by `Pt-surf` and use GPUs in the test queue.

This submits a batch job, and returns to the terminal.
Once the calculation starts (monitor using `squeue -u trainXXX`),
watch the files produced by the job using `ls`.

After a while, the job will create a JDFTx input file `in`, and start piping output to `out`.
Notice that this input file now has commands we added to `inputs`, spliced in with geometry
and a few other control commands added by the ASE wrapper interface.

The output file should be very familiar, and quite similar to the case where we ran the same system by hand.
The only difference would be that there would be an entire JDFTx run for each ionic step,
each with only a single IonicMinimize step, because geometry optimization is now handled by ASE.
(In the present example, the script quits after a single ionic step.)


## Analysis

The `out` file will still be present with the same information as running native JDFTx.
New files include the CONTCAR file with the converged structure and the opt.log file.
`opt.log` contains the time, energy (in eV) and force (eV/A) of each ionic step.

This calculation should reach the same energy as the native JDFTx Pt surface 
(Session 2, Calc 3)

    -258.6783 Hartree   (Ecomponents)
    -7038.994 eV        (opt.log)

Also note that this is a grand-canonical run, with the number of electrons
changing automatically from 48 (neutral) to about 48.2 at OV SHE,
which also matches what we did directly using JDFTx before.

## Visualization

Open `Visualize.ipynb` to compare the starting and converged structures
(identical in this case).
