MJR's Castep Notes

This page contains some random information about the use of Castep. It is incomplete, but contributions are welcome. It is provided mostly so that I can remember what I have done, and in the hope that it might be of some use to someone else. Also a link to the official online Castep documentation.

Some of the background theory to Castep and DFT can be found in chapter IV of my thesis. A rather more modern and complete approach can be found in Prof Probert's lecture course from York. (Prof Probert is one of the Castep developers.)

(I also have unmaintained notes on the ancient, Fortran77, pre-commercial version of Castep. In the unlikely event that someone wants these, they can still be found here.)

Utilities

The Castep distribution provides many useful utilities. From the 20.11 academic distribution it includes c2x, a converter for Castep's check files, which can extract charge and spin density, wavefuctions, or simply atomic positions. It can also convert between .cell and .pdb files, and other similar tricks. It also can be built with the spglib crystal symmetry finder for symmetry analysis. C2x also supports other DFT codes, such as Abinit, Elk, Quantum Espresso, Siesta and VASP.

C2x 2.34d (July 2020) is included in the Castep 20.11 academic distribution. To see what functionality more recent versions of c2x would include, view c2x's changelog.

Theory

These notes should mostly apply to plane-wave codes in general, not just Castep, but I make no promises.

Practice

A simple test of Castep on an ethene molecule.

Over-riding FFT grid selection

I often find myself wanting to do this, for various strange reasons. It seems to be undocumented and unsupported, but, in a .param file, a block such as the following seems to work.

%block devel_code 
STD_GRID=50 50 45 FINE_GRID=60 60 50
%endblock devel_code

Such devel_code blocks tend to have little error-checking, and are not intended to be used saved for by developers, so you have no right to blame anyone should they not behave as expected. For my own convenience, I record here the syntax for changing the Ewald converge tolerance from its default of 100 (should never be necessary). The value below should give wrong answers most of the time. Replacing the "2" with "1000" might give one confidence that the Ewald sum was correctly converged.

%block devel_code
EWALD: PREC = 2 :ENDEWALD
%endblock devel_code

Norm-conserving potentials

For on-the-fly norm-conserving pseudopotentials, add to the cell file:

%block species_pot
  NCP
%endblock species_pot

Also some anonymous notes on the pseudopotential string.

Compiling

SYS V IPC

The main use of this is that it magically merges MPI messages when run on a machine with multiple shared-memory nodes, and thus improves scaling. In other circumstances it is of little use, but adds C code to what is otherwise a pure Fortran project.

The source file for this which is part of Castep 17.21 (and earlier) is incompatible with ifort 17.0 (and later) when used with most versions of OpenMPI. This can be fixed by removing the
include "mpif.h"
line and uncommenting the
Use mpi
line a couple of lines earlier in Source/Utility/FreeIPC.f90.

MKL FFTs

Depending on how one's compiler is set up, adding
include 'mkl_dfti.f90'
before the first line of Source/Utility/fft.mkl.F90 may make it easier to compile this file.

Optimisation

When using the Intel compilers, Castep will use the option -xHost, unless TARGETCPU=portable, in which case it is compiled with -msse3. If the executable is to be used only on the architecture which generated it, then -xHost is a good option. However, if one wishes to have a portable executable, -msse3 will make no use of AVX instructions. Something like -msse3 -axavx might be better, at the expense of taking longer to compile and producing a larger executable. See further notes on ifort and CPU selection.

Avoiding make

The Castep build system is flexible, but, for bears of little brain, verging on the incomprehensible. I tend to use a simpler shell script for compilation, an example of which is below. The script will be tied to a particular version of Castep, due to the addition of extra source files as functionality is extended. It is offered with no guarantee of functionality or correctness!

compile-17.2

compile-18.1

compile-19.1

compile-20.1

compile-21.1

compile-22.1

compile-23.1

Testing

Castep's test suite by default says things like "461 out of 462 tests passed." This is fine if all tests passed, but unhelpful if one wishes to know what failed. A find-and-replace of " -q " by " -v " on Test/Makefile improves things.

Useful Links

Castep in TCM

The c2x utility is centrally installed.

Further information about Castep itself in TCM can be found on TCM's internal Castep page.