Skip to content

CASTEP

The most recent CASTEP documentation is the best resource for up-to-date advice on CASTEP calculations. The Theory of Condensed Matter group in Cambridge also provides a comprehensive manual.

A CASTEP calculation requires two primary input files:

  1. .param: Contains control parameters and calculation flags.
  2. .cell: Contains the crystal structure and unit cell information.

Input files

.param

cut_off_energy      : 900 eV
xc_functional       : PBESOL
fix_occupancy       : true
grid_scale          : 2
elec_energy_tol     : 1.0e-8 eV
task                : MagRes   
MAGRES_TASK         : NMR      
IPRINT              : 2  
opt_strategy        : speed
num_dump_cycles     : 0
fine_grid_scale     : 2.8
MAX_SCF_CYCLES      : 256
MAGRES_MAX_CG_STEPS : 512
CONTINUATION        : default
BACKUP_INTERVAL     : 1

Since we primarily use CASTEP for NMR calculations, the example above demonstrates an NMR setup. Key settings include:

  • task: MagRes: Specifies that a Magnetic Resonance calculation should be performed.
  • MAGRES_TASK: Defines the specific properties to calculate. Options include:
    • shielding: Magnetic shielding tensors.
    • efg: Electric field gradient tensors.
    • NMR: Calculates both shielding and EFG.

For other types of calculations see the official docs for the .param file.

Restarting Long Calculations

NMR calculations can be computationally expensive and may exceed HPC walltime limits. To ensure restart files are written specifically for the NMR part of the calculation, add the following block to your .param file:

%BLOCK devel_code
    MAGRES_RESTART_QPT
%ENDBLOCK devel_code

Note: CASTEP writes one restart file per CPU. Therefore, when restarting a job, you must use the exact same number of cores as the original run.

.cell

%BLOCK LATTICE_CART
13.675000  0.000000  0.000000
-6.837500 11.842897  0.000000
 0.000000  0.000000 14.767000
%ENDBLOCK LATTICE_CART

%BLOCK POSITIONS_ABS
O 11.664775  1.160604  1.811911
O  4.827275  5.108236  6.734244
O -2.010225  9.055869 11.656578
O  6.837500  9.521690  1.811911
O  6.837500  1.626425  6.734244
O  0.000000  5.574057 11.656578
O  2.010225  1.160604  1.811911
O  8.847725  5.108236  6.734244
O  2.010225  9.055869 11.656578
O -4.827275 10.682293 12.955089
O  8.847725  2.787029  3.110422
O  2.010225  6.734661  8.032756
O  0.000000  2.321208 12.955089
O  6.837500  6.268840  3.110422
O  0.000000 10.216473  8.032756
O  4.827275 10.682293 12.955089
O  4.827275  2.787029  3.110422
O -2.010225  6.734661  8.032756
O 11.236064  3.672482  2.461659
O  4.398564  7.620115  7.383992
O -2.438936 11.567747 12.306326
O  4.876505  7.894475  2.461659
O -1.960995 11.842108  7.383992
O -1.960995  3.946843 12.306326
O  4.399931  0.275940  2.461659
O -2.437569  4.223572  7.383992
O  4.399931  8.171204 12.306326
O  9.275069  0.275940  2.461659
O  2.437569  4.223572  7.383992
O -4.399931  8.171204 12.306326
O  2.438936  3.672482  2.461659
O -4.398564  7.620115  7.383992
O  2.438936 11.567747 12.306326
O  8.798495  7.894475  2.461659
O  1.960995 11.842108  7.383992
O  1.960995  3.946843 12.306326
O  0.000684  2.848217  1.941860
O  6.838184  6.795849  6.864194
O  0.000684 10.743482 11.786527
O  4.370530 10.419381  1.941860
O  4.370530  2.524116  6.864194
O -2.466970  6.471749 11.786527
O -4.371214 10.418197  1.941860
O  9.303786  2.522932  6.864194
O  2.466286  6.470564 11.786527
O  6.836816  8.994681 12.825140
O  6.836816  1.099416  2.980473
O -0.000684  5.047048  7.902806
O  2.466970  1.423516 12.825140
O  9.304470  5.371149  2.980473
O  2.466970  9.318781  7.902806
O 11.208714  1.424701 12.825140
O  4.371214  5.372333  2.980473
O -2.466286  9.319965  7.902806
O 11.912976  3.051915  0.000000
O  5.075476  6.999547  4.922333
O -1.762024 10.947180  9.844667
O  5.075476  8.790983  0.000000
O  5.075476  0.895718  4.922333
O -1.762024  4.843350  9.844667
O  3.524047  0.000000  0.000000
O 10.361548  3.947632  4.922333
O  3.524048  7.895265  9.844667
O 10.150953  0.000000  0.000000
O  3.313453  3.947632  4.922333
O -3.524047  7.895265  9.844667
O  1.762024  3.051915  0.000000
O  8.599524  6.999547  4.922333
O  1.762024 10.947180  9.844667
O  8.599524  8.790983  0.000000
O  8.599524  0.895718  4.922333
O  1.762024  4.843350  9.844667
Si 12.122888  2.681232  1.552012
Si  5.285388  6.628864  6.474345
Si -1.552112 10.576497 11.396678
Si  5.291541  9.158113  1.552012
Si  5.291541  1.262848  6.474345
Si -1.545959  5.210480 11.396678
Si  3.098071  0.003553  1.552012
Si  9.935571  3.951185  6.474345
Si  3.098071  7.898818 11.396678
Si 10.576929  0.003553  1.552012
Si  3.739429  3.951185  6.474345
Si -3.098071  7.898818 11.396678
Si  1.552112  2.681232  1.552012
Si  8.389613  6.628864  6.474345
Si  1.552113 10.576497 11.396678
Si  8.383459  9.158113  1.552012
Si  8.383459  1.262848  6.474345
Si  1.545959  5.210480 11.396678
Si -5.285387  9.161665 13.214988
Si  8.389612  1.266400  3.370322
Si  1.552112  5.214033  8.292655
Si  1.545959  2.684785 13.214988
Si  8.383459  6.632417  3.370322
Si  1.545959 10.580050  8.292655
Si  3.739429 11.839345 13.214988
Si  3.739429  3.944080  3.370322
Si -3.098071  7.891712  8.292655
Si -3.739429 11.839345 13.214988
Si  9.935571  3.944080  3.370322
Si  3.098071  7.891712  8.292655
Si  5.285388  9.161665 13.214988
Si  5.285388  1.266400  3.370322
Si -1.552112  5.214033  8.292655
Si -1.545959  2.684785 13.214988
Si  5.291541  6.632417  3.370322
Si -1.545959 10.580050  8.292655
%ENDBLOCK POSITIONS_ABS

KPOINT_MP_SPACING 0.05

The .cell file can be easily prepared using ASE. A critical aspect is setting up the K-points. A robust method is to define the spacing between K-points using KPOINT_MP_SPACING (as shown above). For more information, refer to the official documentation on K-points.

Output files

.magres

The .magres file format is used for NMR calculations in both CASTEP and Quantum Espresso. It is compatible with post-processing NMR software such as Soprano and general-purpose tools like ASE.

In a typical workflow, you can extract NMR observables using the following Python code:

from ase.io import read
from soprano.properties.nmr import *

# Load the magres file
mfi = read('MFI.magres')

# Extract properties
iso = MSIsotropy.get(mfi)
aniso = MSAnisotropy.get(mfi)
asym = MSAsymmetry.get(mfi)
cq = EFGQuadrupolarConstant.get(mfi)
etaq = EFGAsymmetry.get(mfi)

print(f'Atom type: {mfi.symbols[0]}, iso: {iso[0]:.2f}, aniso: {aniso[0]:.2f}, asym: {asym[0]:.2f}, Cq: {cq[0]/1e6:.2f}, eta: {etaq[0]:.2f}')

Example Output:

Atom type: O,Atom type: O, iso: 225.98, aniso: 88.76, asym: 0.09, Cq: -5.14, eta: 0.12