CASTEP¶
Introduction¶
CASTEP [1] W is a software package which uses density functional theory to provide a good atomic-level description of all manner of materials and molecules. CASTEP can give information about total energies, forces and stresses on an atomic system, as well as calculating optimum geometries, band structures, optical spectra, phonon spectra and much more. It can also perform molecular dynamics simulations.
The CASTEP calculator interface class offers intuitive access to all CASTEP
settings and most results. All CASTEP specific settings are accessible via
attribute access (i.e. calc.param.keyword = ...
or
calc.cell.keyword = ...
)
Getting Started:¶
Set the environment variables appropriately for your system:
export CASTEP_COMMAND=' ... '
export CASTEP_PP_PATH=' ... '
Note: alternatively to CASTEP_PP_PATH one can set PSPOT_DIR as CASTEP consults this by default, i.e.:
export PSPOT_DIR=' ... '
Running the Calculator¶
The default initialization command for the CASTEP calculator is
To do a minimal run one only needs to set atoms, this will use all default settings of CASTEP, meaning LDA, singlepoint, etc..
With a generated castep_keywords.json in place all options are accessible
by inspection, i.e. tab-completion. This works best when using ipython
.
All options can be accessed via calc.param.<TAB>
or calc.cell.<TAB>
and documentation is printed with calc.param.<keyword> ?
or
calc.cell.<keyword> ?
. All options can also be set directly
using calc.keyword = ...
or calc.KEYWORD = ...
or even
ialc.KeYwOrD
or directly as named arguments in the call to the constructor
(e.g. Castep(task='GeometryOptimization')
).
If using this calculator on a machine without CASTEP, one might choose to copy
a castep_keywords.json file generated elsewhere in order to access this
feature: the file will be used if located in the working directory,
$HOME/.ase/ or ase/ase/calculators/ within the ASE library. The file should
be generated the first time it is needed, but you can generate a new keywords
file in the currect directory with python -m ase.calculators.castep
.
All options that go into the .param
file are held in an CastepParam
instance, while all options that go into the .cell
file and don’t belong
to the atoms object are held in an CastepCell
instance. Each instance can
be created individually and can be added to calculators by attribute
assignment, i.e. calc.param = param
or calc.cell = cell
.
All internal variables of the calculator start with an underscore (_).
All cell attributes that clearly belong into the atoms object are blocked.
Setting calc.atoms_attribute
(e.g. = positions
) is sent directly to
the atoms object.
Arguments:¶
Keyword |
Description |
---|---|
|
The relative path where all input and output files will be placed. If this does not exist, it will be created. Existing directories will be moved to directory-TIMESTAMP unless self._rename_existing_dir is set to false. |
|
The prefix of .param, .cell, .castep, etc. files. |
|
Command to run castep. Can also be set via the bash
environment variable |
|
Boolean whether to check if the installed castep
version matches the version from which the available
options were deduced. Defaults to |
|
The path where the pseudopotentials are stored. Can
also be set via the bash environment variables
|
|
Boolean whether to search for pseudopotentials in
|
|
Integer to indicate the level of tolerance to apply validation of any parameters set in the CastepCell or CastepParam objects against the ones found in castep_keywords. Levels are as following: 0 = no tolerance, keywords not found in castep_keywords will raise an exception 1 = keywords not found will be accepted but produce a warning (default) 2 = keywords not found will be accepted silently 3 = no attempt is made to look for castep_keywords.json at all |
|
Can be used to pass a CastepKeywords object that is then used with no attempt to actually load a castep_keywords.json file. Most useful for debugging and testing purposes. |
Additional Settings¶
Internal Setting |
Description |
---|---|
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( |
|
( Since this behavior may not always be desirable for
single-point calculations. Regular reuse for e.g.
a geometry-optimization can be achieved by setting
|
|
( |
Special features:¶
.dryrun_ok()
Runs
castep_command seed -dryrun
in a temporary directory return True if all variables initialized ok. This is a fast way to catch errors in the input. Afterwards _kpoints_used is set..merge_param()
Takes a filename or filehandler of a .param file or CastepParam instance and merges it into the current calculator instance, overwriting current settings
.keyword.clear()
Can be used on any option like
calc.param.keyword.clear()
orcalc.cell.keyword.clear()
to return to the CASTEP default..initialize()
Creates all needed input in the
_directory
. This can then copied to and run in a place without ASE or even python..set_pspot('<library>')
This automatically sets the pseudo-potential for all present species to
<Species>_<library>.usp
. Make sure that_castep_pp_path
is set correctly. Note that there is no check, if the file actually exists. If it doesn’t castep will crash! You may want to usefind_pspots()
instead..find_pspots(pspot=<library>, suffix=<suffix>)
This automatically searches for pseudopotentials of type
<Species>_<library>.<suffix>
or<Species>-<library>.<suffix>
incastep_pp_path` (make sure this is set correctly). Note that ``<Species>
will be searched for case insensitive. Regular expressions are accepted, and arguments'*'
will be regarded as bash-like wildcards. Defaults are any<library>
and any<suffix>
from['usp', 'UPF', 'recpot']
. If you have well-organized folders with pseudopotentials of one kind, this should work with the defaults.print(calc)
Prints a short summary of the calculator settings and atoms.
ase.io.castep.read_seed('path-to/seed')
Given you have a combination of seed.{param,cell,castep} this will return an atoms object with the last ionic positions in the .castep file and all other settings parsed from the .cell and .param file. If no .castep file is found the positions are taken from the .cell file. The output directory will be set to the same directory, only the label is preceded by ‘copy_of_’ to avoid overwriting.
.set_kpts(kpoints)
This is equivalent to initialising the calculator with
calc = Castep(kpts=kpoints)
.kpoints
can be specified in many convenient forms: simple Monkhorst-Pack grids can be specified e.g.(2, 2, 3)
or'2 2 3'
; lists of specific weighted k-points can be given in reciprocal lattice coordinates e.g.[[0, 0, 0, 0.25], [0.25, 0.25, 0.25, 0.75]]
; a dictionary syntax is available for more complex requirements e.g.{'size': (2, 2, 2), 'gamma': True}
will give a Gamma-centered 2x2x2 M-P grid,{'density': 10, 'gamma': False, 'even': False}
will give a mesh with density of at least 10 Ang (based on the unit cell of currently-attached atoms) with an odd number of points in each direction and avoiding the Gamma point..set_bandpath(bandpath)
This is equivalent to initialialising the calculator with
calc=Castep(bandpath=bandpath)
and may be set simultaneously with kpts. It allows an electronic band structure path to be set up using ASE BandPath objects. This enables a band structure calculation to be set up conveniently using e.g. calc.set_bandpath(atoms.cell.bandpath().interpolate(npoints=200)).band_structure(bandfile=None)
Read a band structure from _seedname.bands_ file. This returns an ase BandStructure object which may be plotted with e.g.
calc.band_structure().plot()
Notes/Issues:¶
Currently only the FixAtoms constraint is fully supported for reading and writing. There is some experimental support for the FixCartesian constraint.
There is no support for the CASTEP unit system. Units of eV and Angstrom are used throughout. In particular when converting total energies from different calculators, one should check that the same CODATA version is used for constants and conversion factors, respectively.
Example:¶
"""This simple demo calculates the total energy of CO molecules
using once LDA and once PBE as xc-functional. Obviously
some parts in this scripts are longer than necessary, but are shown
to demonstrate some more features."""
import ase
import ase.calculators.castep
import ase.io.castep
calc = ase.calculators.castep.Castep()
directory = 'CASTEP_ASE_DEMO'
# include interface settings in .param file
calc._export_settings = True
# reuse the same directory
calc._directory = directory
calc._rename_existing_dir = False
calc._label = 'CO_LDA'
# necessary for tasks with changing positions
# such as GeometryOptimization or MolecularDynamics
calc._set_atoms = True
# Param settings
calc.param.xc_functional = 'LDA'
calc.param.cut_off_energy = 400
# Prevent CASTEP from writing *wvfn* files
calc.param.num_dump_cycles = 0
# Cell settings
calc.cell.kpoint_mp_grid = '1 1 1'
calc.cell.fix_com = False
calc.cell.fix_all_cell = True
# Set and clear and reset settings (just for shows)
calc.param.task = 'SinglePoint'
# Reset to CASTEP default
calc.param.task.clear()
# all of the following are identical
calc.param.task = 'GeometryOptimization'
calc.task = 'GeometryOptimization'
calc.TASK = 'GeometryOptimization'
calc.Task = 'GeometryOptimization'
# Prepare atoms
mol = ase.atoms.Atoms('CO', [[0, 0, 0], [0, 0, 1.2]], cell=[10, 10, 10])
mol.calc = calc
# Check for correct input
if calc.dryrun_ok():
print(f'{mol.calc._label} : {mol.get_potential_energy()} ')
else:
print("Found error in input")
print(calc._error)
# Read all settings from previous calculation
mol = ase.io.castep.read_seed('%s/CO_LDA' % directory)
# Use the OTF pseudo-potential we have just generated
mol.calc.set_pspot('OTF')
# Change some settings
mol.calc.param.xc_functional = 'PBE'
# don't forget to set an appropriate label
mol.calc._label = 'CO_PBE'
# Recalculate the potential energy
print(f'{mol.calc._label} : {mol.get_potential_energy()} ')