First Principles: CASTEP Introduction¶
Basic Instructions¶
On scarf you need to tell the system where to find CASTEP and it’s associated tools. If you just type
which castep.mpi
you will get a no castep in ... message. To fix this, you just need to type the command
module load CASTEP
to get the current default version of CASTEP, or
module load CASTEP/25.1.2-iomkl-2024
to get a specific version of CASTEP. After this, castep.mpi (and lots of other CASTEP utilities) will be added to your PATH. Unfortunately you will
need to do this every time you log in, unless you add this command to
the end of your ~/.bashrc file.
This practical now starts with a basic CASTEP run and then moves onto understanding the accuracy of the results. We will start with pure silicon to learn the basics of running CASTEP and electronic structure. We will then move on to a more interesting crystal - quartz - and examine questions about the crystal structures at ambient and high pressures.
A. Silicon¶
Get the files required for this exercise
mkdir ~/silicon
cp /work4/training/ccp5/abinitio/castep/silicon/* ~/silicon/
cd ~/silicon
Examine the CASTEP input files Si2.cell and Si2.param using your
favourite text editor (e.g. nano). The Si_00.usp file is a pseudopotential
file, you do not need to understand it at the moment.
nano Si2.cell
nano Si2.param
There is information on this website: https://www.castep.org/help_and_support and there are some useful support websites too, such as https://www.ccpnc.ac.uk/docs/castep-for-nmr-calculations
I also have a full CASTEP course with lecture notes, videos and exercises at https://www-users.york.ac.uk/~mijp1/teaching/grad_FPMM if you want more.
NB If you want to understand what is happening with the Si2.cell and Si2.param file, you can also use the built-in CASTEP help system.
Information on using CASTEP can be seen by using:
castep --help
To get more information on a particular input file keyword (e.g. task)
use:
castep --help task
If you don’t know the keyword you need to use, then you can search on a particular keyword. This returns a list of keywords that you might be interested in, e.g. to look at all keywords which contain a reference to symmetry.
castep --search symmetry
Finally, to list all keywords, use:
castep --search all
Note that the long-form arguments --help and --search can
optionally be replaced with -h and -s, respectively.
This system is very small and quick to run, so we can see what happens if we just type:
castep.mpi Si2
This will read the input files and run the calculation. The main output will be written to Si2.castep which is a “human readable” file.
We will now go through this file to understand what is happening …
An important question you should always ask: is the answer correct? Is it converged? Have I used an appropriate level of theory?
B. Quartz¶
Quartz has a more complex crystal structure, with a hexagonal unit cell:
%BLOCK lattice_abc
4.9158 4.9158 5.4091
90.0 90.0 120.0
%ENDBLOCK lattice_abc
%BLOCK positions_frac
Si 0.5303000000000000 0.0000000000000000 0.3333333333333333
Si 0.0000000000000000 0.5303000000000000 0.6666666666666667
Si 0.4697000000000000 0.4697000000000000 0.0000000000000000
O 0.1462000000000000 0.4142000000000000 0.8810000000000000
O 0.7320000000000000 0.5858000000000000 0.7856700000000000
O 0.5858000000000000 0.7320000000000000 0.2143300000000000
O 0.2680000000000000 0.8538000000000000 0.5476700000000000
O 0.4142000000000000 0.1462000000000000 0.1190000000000000
O 0.8538000000000000 0.2680000000000000 0.4523300000000000
%ENDBLOCK positions_frac
This gives the hexagonal unit cell with lattice parameters a=b=4.9158 Å and c=5.4091 Å and
the corresponding hexagonal unit cell angles in the data block lattice_abc. The fractional
coordinates of the atoms are then given in the next data block positions_frac.
Copy the files
cd
mkdir ~/quartz
cp /work4/training/ccp5/abinitio/castep/quartz/* ~/quartz/
cp /work4/training/ccp5/abinitio/castep/castep.slurm ~/quartz/
cd ~/quartz
Examine the cell input file to see where symmetry optimisations are turned on.
In the param file task is set as GeometryOptimisation.
We can run in parallel on 24 compute cores with, edit castep.slurm to contain the following line
mpirun -n 24 castep.mpi quartz-geom
submit the job
sbatch castep.slurm
After that, your task is to determine the atomic positions and lattice parameters of quartz in the local-density approximation with lattice parameters accurate to 0.5% and internal coordinates accurate to 0.25%.
First, you will need to change keyword values in the cell and param files, for example k-point convergence and plane wave cutoff. Use the websites or the CASTEP built-in help to find the best keywords to use. This should be done with the fixed geometry and using the “single point energy” task.
Once you have found good values for the cut-off energy and kpoints, you should
then edit the provided quartz-geom files with these values. This has a
different value of task and so will now run a geometry-optimisation calculation. You
should also edit the castep.slurm file to run this new job. You may need to
also increase the time allowed …
To find all the CASTEP keywords associated with a geometry optimisation you can search with:
castep.mpi -s geom
This will list all keywords containing “geom”. You can then get help/syntax for specific keywords, for example to find options and defaults for geom_max_iter:
castep.mpi -h geom_max_iter
When running a geom-opt, you should be aware of the different possible stopping conditions - it might be because of convergence, or it might be that CASTEP has run out of iterations! You should always check. One nice website that helps to visualize your geom-opt convergence is https://jkshenton.github.io/marimo_notebooks/apps/castep_geomopt_summary.html
More ambitious task¶
Compute the transition pressure from quartz to the high-pressure phase stishovite. A useful keyword in
the .cell file will be external_pressure. You will need to think carefully about how to structure
the calculation and the accuracy and convergence.
An example .cell and .param file for stishovite is given in
cd
mkdir ~/stishovite
cp /work4/training/ccp5/abinitio/castep/quartz/stishovite.* ~/stishovite/
cp /work4/training/ccp5/abinitio/castep/castep.slurm ~/stishovite/
cd ~/stishovite/
edit castep.slurm and run the job.
N.B. You may need to set up a series of calculations to run overnight and finish the analysis in the morning. Does your answer make sense?
Final task¶
Repeat the transition pressure calculation using the “PBE” generalised gradient approximation.