aiida-castep
is a plugin to interface CASTEP with AiiDA (Automated Interactive Infrastructure and Database for Computational Science).
It is quite complicated to explain what AiiDA is, but here are some key benefits:
In this example, we go through how to setup a CastepCalculation
. A CastepCalculation
is essentially a "transaction" with the underlying CASTEP executable,
and is the basis for more complex workflows.
In reality, you will seldom have the need to setup such calculation explicitly like in this notebook, since it is more convenient to setup higher level workflows directly (through WorkChain
s).
Nevertheless, it can be useful to know how each elementary calculation operates.
This example does not require any installation of the actual CASTEP code. The output file is generated by a mock code that matches the input with existing repository of completed calculations, and generate the output files accordingly.
%load_ext aiida
from aiida import load_profile, engine, orm, plugins
from aiida.storage.sqlite_temp import SqliteTempBackend
profile = load_profile(
SqliteTempBackend.create_profile(
'myprofile',
sandbox_path='_sandbox',
options={
'warnings.development_version': False,
'runner.poll.interval': 1
},
debug=False
),
allow_switch=True
)
profile
Profile<uuid='835822e76755476d9826ed697be0e2b7' name='myprofile'>
AiiDA stores everything as Node
and connect them by link (i.e a graph database).
There are two type of nodes Calculation
and Data
.
CasteplCalculation
¶The red-square represents the CastepCalculation
node, and the rounded nodes going in and out to it are the input and output nodes.
# A exmaple of the provenance graph of a CastepCalculation
from __future__ import print_function
from IPython.display import Image
Image("./Si_bs_example.png")
The calculations (square) take data nodes (circle) as the input and create output data nodes.
There is also a Code
node which represents the code that is used to conduct the calculation, i.e the CASTEP executable on the remote cluster.
Here are the essential parts of a CASTEP calculations and their representation in AiiDA:
StructureData
KpointsData
OTFGData
or UspData
or even UpfData
param
and cell
files - Dict
Below is a walk-through of the steps to create a single point calculation using the basic CastepCalculation
class.
import numpy as np
import aiida.orm as orm
from pprint import pprint
This is taken from the online tutorial.
The cell
file contain the crystal structure and related setting.
!cat 'bandstructure/silicon/Si2.cell' | grep -v -e "^!"
%block lattice_cart 2.6954645 2.6954645 0.0 2.6954645 0.0 2.6954645 0.0 2.6954645 2.6954645 %endblock lattice_cart %block positions_frac Si 0.00 0.00 0.00 Si 0.25 0.25 0.25 %endblock positions_frac symmetry_generate %block species_pot Si Si_00.usp %endblock species_pot kpoint_mp_grid 4 4 4 %block bs_kpoint_path 0.5 0.25 0.75 ! W 0.5 0.5 0.5 ! L 0.0 0.0 0.0 ! Gamma 0.5 0.0 0.5 ! X 0.5 0.25 0.75 ! W 0.375 0.375 0.75 ! K %endblock bs_kpoint_path
The param
file contains a list of key-value pairs
!cat 'bandstructure/silicon/Si2.param' | grep -v -e "^!"
task bandstructure ! The TASK keyword instructs CASTEP what to do xc_functional LDA ! Which exchange-correlation functional to use. basis_precision MEDIUM ! Choose high cut-off COARSE/MEDIUM/FINE/PRECISE fix_occupancy true ! Treat the system as an insulator opt_strategy speed ! Choose algorithms for best speed at expense of memory. num_dump_cycles 0 ! Don't write unwanted ".wvfn" files. write_formatted_density TRUE ! Write out a density file that we can view using (e.g.) Jmol.
We setup a similar calculation with Si here. Instead of going for the band structure, we just do a single point run.
StructureData
node¶# Define the structure
from aiida.plugins import DataFactory
StructureData = DataFactory('structure')
silicon = StructureData()
r_unit = 2.6954645
silicon.set_cell(np.array([[1, 1, 0], [1, 0, 1], [0, 1, 1]]) * r_unit)
silicon.append_atom(symbols=["Si"], position=[0, 0, 0])
silicon.append_atom(symbols=["Si"], position=[r_unit * 0.5] * 3)
silicon.label = "Si"
silicon.description = "A silicon structure"
Atomic Simulation Environment (ASE) has a rich set of tools for handling structures, center around the ase.Atoms
class.
They can be converted to StructureData
that AiiDA understands and saves to the provenance graph.
# You can also use ase.Atoms object to create the StructureData
from ase import Atoms
silicon_atoms = Atoms('Si2', cell=silicon.cell, scaled_positions=((0, 0, 0), (0.25, 0.25, 0.25)))
silicon_from_atoms = StructureData(ase=silicon_atoms)
StructureData
can be converted back to Atoms
for complex operation using ase
.
# You can also convent the StructureData back to ase.Atoms
silicon_atoms_2 = silicon_from_atoms.get_ase()
silicon_atoms_2 == silicon_atoms
True
Note that a similar interface also exists to work with pymatgen
.
Dict
node¶We use a nested dictionary to represent the input key-value pairs for CASTEP.
The keys for param
file goes under PARAM
and that for cell
file goes under CELL
.
Finally, we convert the dictionary to Dict
, allowing AiiDA to store it in the database.
# Define a dictionary to store the parameters of the calculations
Dict = DataFactory('dict')
param_dict = {
# Notice that the keywords are group into two sub-dictionaries
# just like you would do when preparing the inputs by hand
"CELL":{
"symmetry_generate": True,
"snap_to_symmetry": True,
# Pass a list of string to set a BLOCK inputs
#"cell_constraints":
#["0 0 0", "0 0 0"]
},
"PARAM":{
"task": "singlepoint",
"basis_precision": "medium",
"fix_occupancy": True, # Use bool type to make it easy for querying
"opt_strategy": "speed",
"num_dump_cycles": 0,
"write_formatted_density": True
}}
# We need to create a Dict node that holds the dictionary
param = Dict(dict=param_dict)
Dict
type can be converted back to python dictionary.
# You can acceess the stored data
pprint(param.get_dict())
# You can also reset the data in the Dict node
param_dict["PARAM"].update(opt_strategy="memory")
param.set_dict(param_dict)
print(param.get_dict())
# Get it back
param_dict["PARAM"].update(opt_strategy="memory")
{'CELL': {'snap_to_symmetry': True, 'symmetry_generate': True}, 'PARAM': {'basis_precision': 'medium', 'fix_occupancy': True, 'num_dump_cycles': 0, 'opt_strategy': 'speed', 'task': 'singlepoint', 'write_formatted_density': True}} {'CELL': {'symmetry_generate': True, 'snap_to_symmetry': True}, 'PARAM': {'task': 'singlepoint', 'basis_precision': 'medium', 'fix_occupancy': True, 'opt_strategy': 'memory', 'num_dump_cycles': 0, 'write_formatted_density': True}}
KpointsData
node¶Plane-wave DFT calculations require a k-point grid. We need to define it and store the database. The KpointData
is used for this purpose.
KpointsData = DataFactory('array.kpoints')
# You can define kpoints explicitly
kpoints = KpointsData()
# Use gamma and 0.25, 0.25, 0.25
kpoints.set_kpoints(((0., 0., 0), (0.25, 0.25, 0.25)), weights=[0.5, 0.5])
pprint(kpoints.get_kpoints(also_weights=True))
(array([[0. , 0. , 0. ], [0.25, 0.25, 0.25]]), array([0.5, 0.5]))
Very often the a grid is used, the actual kpoints are computed by CASTEP taking symmetry into account.
The KpointsData
can also represent the grid instead of explicit points.
# More commonly, we want to use a grid (mesh) of the kpoints
kpoints = KpointsData()
kpoints.set_kpoints_mesh((4, 4, 4), offset=(0,0,0))
print(kpoints.get_kpoints_mesh())
([4, 4, 4], [0.0, 0.0, 0.0])
Pseuodpotentials are also stored as Node
in AiiDA and we have to define them. For CASTEP, they can be library names, on-the-fly generation strings or files.
Define an OTFG string for Si
from aiida_castep.data.otfg import OTFGData
from aiida_castep.data.usp import UspData
# Explicitly define the OTFG string
si_c18 = OTFGData(otfg_entry="Si 3|1.8|5|6|7|30:31:32")
# Alternatively you can define explicitly the file to be used
#si_usp = UspData(file="/home/max/MS61_00/Si_00.usp")
Alternatively, we can define a string as the name of the library.
c9 = OTFGData(otfg_entry="C9")
A calculation has a bunch of inputs which have been define above.
It also requires other settings such as which code to use, what resources are need and for how long e.t.c.
from aiida.plugins import CalculationFactory
#Load up the CASTEP calculation
CastepCalculation = CalculationFactory('castep.castep')
It is most convenient to use a ProcessBuilder
to build calculation. It provides a namespace for all the inputs and allows interactive tab completion.
builder = CastepCalculation.get_builder()
# Uncomment the below line to create a localhost Computer if you have not done so
comp = orm.Computer('localhost', 'localhost', transport_type='core.local', scheduler_type='core.direct')
comp.store()
# Some configuration may be needed for first-time user
comp.set_workdir('/tmp/aiida_run/')
comp.configure()
<aiida.orm.authinfos.AuthInfo at 0x7f1bc0ebd430>
It is essential that we tell AiiDA which CASTEP executable on the remote compute that we want to run.
Hence, a Code
is required for the builder.
import os
# Define a mock code on the localhost computer
code_path = !which castep.mock
castep_mock = orm.Code((comp, code_path[0]), input_plugin_name='castep.castep')
Now, we put everything together in the builder
builder.structure = silicon
builder.parameters = param
builder.kpoints = kpoints
builder.code = castep_mock
builder.pseudos = {'Si': c9}
builder.metadata.options.withmpi = False
builder.metadata.options.resources = {'num_machines': 1, 'tot_num_mpiprocs': 2}
builder.metadata.options.max_wallclock_seconds = 600
builder.metadata.label = "Si SINGLEPOINT"
builder.metadata.description = 'A Example CASTEP calculation for silicon'
def d2attr(d, b):
for k, v in d.items():
b.__setattr__(k, v)
from aiida.engine import run_get_node
from aiida.engine import Process
results, calcjob = run_get_node(builder)
results['retrieved'].base.repository.list_object_names()
['_scheduler-stderr.txt', '_scheduler-stdout.txt', 'aiida.bands', 'aiida.castep', 'aiida.den_fmt']
calcjob.base.repository.list_object_names()
['.aiida', '_aiidasubmit.sh', 'aiida.cell', 'aiida.param']
calcjob.inputs.structure.cell
[[2.6954645, 2.6954645, 0.0], [2.6954645, 0.0, 2.6954645], [0.0, 2.6954645, 2.6954645]]
calcjob.inputs.code.attributes
{'is_local': False, 'remote_exec_path': '/home/bonan/miniconda3/envs/aiida-2.0-dev/bin/castep.mock', 'input_plugin': 'castep.castep'}
print(calcjob.base.repository.get_object_content('aiida.param'))
##### Generated by aiida_castep 22:25:36 26/05/2022 BST ##### # author: Bonan Zhu (zhubonan@outlook.com) # # AiiDA User: user@email.com # AiiDA profile: myprofile # Information of the calculation node # label: Si SINGLEPOINT # description: # A Example CASTEP calculation for silicon # ## Information of input nodes used: # # type: uuid: 16b540c5-e510-4d8f-8f8f-c789b109a71e (pk: 3) # pk: 3 # linkname: parameters # uuid: 16b540c5-e510-4d8f-8f8f-c789b109a71e # label: # description: # # END OF HEADER task : singlepoint basis_precision : medium fix_occupancy : True opt_strategy : memory num_dump_cycles : 0 write_formatted_density: True iprint : 1 run_time : 540 comment : Si SINGLEPOINT
We demostrate how to follow the links to get the input and output of a calculation
lns = calcjob.get_incoming() # This is an link manager
# A link triple is a object contains the link label, vertex of the link
link = lns.first()
print(f"Link label: {link.link_label}")
print(f"Link node: {link.node}")
print(f"Link type: {link.link_type}")
Link label: pseudos__Si Link node: uuid: e9cb672c-a8a5-4233-af2d-858f4d2ee3f1 (pk: 1) Link type: LinkType.INPUT_CALC
# Get the node by the link label
print(lns.get_node_by_label('structure').__repr__())
print(lns.get_node_by_label('parameters').__repr__())
<StructureData: uuid: 2a534b89-3f0c-481b-957b-24e338f627ad (pk: 2)> <Dict: uuid: 16b540c5-e510-4d8f-8f8f-c789b109a71e (pk: 3)>
# Link pair includes link type and link label
lns.all_link_pairs()
[LinkPair(link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='pseudos__Si'), LinkPair(link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='structure'), LinkPair(link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='parameters'), LinkPair(link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='kpoints'), LinkPair(link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='code')]
# Link triples also include nodes
lns.link_triples
[LinkTriple(node=<OTFGData: uuid: e9cb672c-a8a5-4233-af2d-858f4d2ee3f1 (pk: 1)>, link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='pseudos__Si'), LinkTriple(node=<StructureData: uuid: 2a534b89-3f0c-481b-957b-24e338f627ad (pk: 2)>, link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='structure'), LinkTriple(node=<Dict: uuid: 16b540c5-e510-4d8f-8f8f-c789b109a71e (pk: 3)>, link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='parameters'), LinkTriple(node=<KpointsData: uuid: 301e225b-980c-4d98-bb32-4fcb64c13b55 (pk: 4)>, link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='kpoints'), LinkTriple(node=<Code: Remote code '' on localhost, pk: 5, uuid: 73b511f7-a5f4-4396-97c5-8c248466f170>, link_type=<LinkType.INPUT_CALC: 'input_calc'>, link_label='code')]
The raw output is stored in the retrieved
output node.
# The to access the output
print(calcjob.outputs.retrieved.base.repository.get_object_content("aiida.castep"))
+-------------------------------------------------+ | | | CCC AA SSS TTTTT EEEEE PPPP | | C A A S T E P P | | C AAAA SS T EEE PPPP | | C A A S T E P | | CCC A A SSS T EEEEE P | | | +-------------------------------------------------+ | | | Welcome to Academic Release CASTEP version 19.1 | | Ab Initio Total Energy Program | | | | Authors: | | M. Segall, M. Probert, C. Pickard, P. Hasnip, | | S. Clark, K. Refson, J. R. Yates, M. Payne | | | | Contributors: | | P. Lindan, P. Haynes, J. White, V. Milman, | | N. Govind, M. Gibson, P. Tulip, V. Cocula, | | B. Montanari, D. Quigley, M. Glover, | | L. Bernasconi, A. Perlov, M. Plummer, | | E. McNellis, J. Meyer, J. Gale, D. Jochym | | J. Aarons, B. Walker, R. Gillen, D. Jones | | T. Green, I. J. Bush, C. J. Armstrong, | | E. J. Higgins, E. L. Brown, M. S. McFly, | | J. Wilkins, B-C. Shih, P. J. P. Byrne | | | | Copyright (c) 2000 - 2018 | | | | Distributed under the terms of an | | Agreement between the United Kingdom | | Car-Parrinello (UKCP) Consortium, | | Daresbury Laboratory and Accelrys, Inc. | | | | Please cite | | | | "First principles methods using CASTEP" | | | | Zeitschrift fuer Kristallographie | | 220(5-6) pp. 567-570 (2005) | | | | S. J. Clark, M. D. Segall, C. J. Pickard, | | P. J. Hasnip, M. J. Probert, K. Refson, | | M. C. Payne | | | | in all publications arising from | | your use of CASTEP | | | +-------------------------------------------------+ | | | http://www.castep.org | | | +-------------------------------------------------+ Compiled for linux_x86_64_gfortran7.0 on Sat, 23 Mar 2019 17:55:25 +0000 from code version 669252f55895+ Tue, 15 Jan 2019 17:23:14 +0000 Compiler: GNU Fortran 7.3.0; Optimisation: fast MATHLIBS: Intel MKL(2018.0.4) (LAPACK version 3.7.0) FFT Lib : mkl Fundamental constants values: CODATA 2014 Run started: Mon, 02 Dec 2019 12:59:04 +0000 Atomic calculation performed for Si: 1s2 2s2 2p6 3s2 3p2 Converged in 55 iterations to an ae energy of -7859.183 eV ============================================================ | Pseudopotential Report - Date of generation 2-12-2019 | ------------------------------------------------------------ | Element: Si Ionic charge: 4.00 Level of theory: LDA | | Atomic Solver: Koelling-Harmon | | | | Reference Electronic Structure | | Orbital Occupation Energy | | 3s 2.000 -0.400 | | 3p 2.000 -0.153 | | | | Pseudopotential Definition | | Beta l e Rc scheme norm | | 1 0 -0.400 1.797 qc 0 | | 2 0 0.250 1.797 qc 0 | | 3 1 -0.153 1.797 qc 0 | | 4 1 0.250 1.797 qc 0 | | 5 2 0.000 1.797 qc 0 | | 6 2 0.250 1.797 qc 0 | | loc 3 0.000 1.797 pn 0 | | | | Augmentation charge Rinner = 1.255 | | Partial core correction Rc = 1.255 | ------------------------------------------------------------ | "3|1.8|5|6|7|30:31:32" | ------------------------------------------------------------ | Author: Chris J. Pickard, Cambridge University | ============================================================ Pseudo atomic calculation performed for Si 3s2 3p2 Converged in 16 iterations to a total energy of -162.9815 eV Calculation not parallelised. ************************************ Title ************************************ Si SINGLEPOINT ***************************** General Parameters ****************************** output verbosity : normal (1) write checkpoint data to : aiida.check type of calculation : single point energy stress calculation : off density difference calculation : off electron localisation func (ELF) calculation : off Hirshfeld analysis : off calculation limited to maximum : 540 seconds timing information : on memory usage estimate : on write extra output files : on write final potential to formatted file : off write final density to formatted file : on write BibTeX reference list : on write OTFG pseudopotential files : on write electrostatic potential file : on write bands file : on checkpoint writing : both castep_bin and check files output length unit : A output mass unit : amu output time unit : ps output charge unit : e output spin unit : hbar/2 output energy unit : eV output force unit : eV/A output velocity unit : A/ps output pressure unit : GPa output inv_length unit : 1/A output frequency unit : cm-1 output force constant unit : eV/A**2 output volume unit : A**3 output IR intensity unit : (D/A)**2/amu output dipole unit : D output efield unit : eV/A/e output entropy unit : J/mol/K wavefunctions paging : none random number generator seed : randomised (125904847) data distribution : optimal for this architecture optimization strategy : minimize memory(---) *********************** Exchange-Correlation Parameters *********************** using functional : Local Density Approximation relativistic treatment : Koelling-Harmon DFT+D: Semi-empirical dispersion correction : off ************************* Pseudopotential Parameters ************************** pseudopotential representation : reciprocal space <beta|phi> representation : reciprocal space spin-orbit coupling : off **************************** Basis Set Parameters ***************************** basis set accuracy : MEDIUM plane wave basis set cut-off : 163.2683 eV size of standard grid : 1.7500 size of fine gmax : 11.4559 1/A finite basis set correction : none **************************** Electronic Parameters **************************** number of electrons : 8.000 net charge of system : 0.000 treating system as non-spin-polarized number of bands : 4 ********************* Electronic Minimization Parameters ********************** Method: Treating system as non-metallic, and number of SD steps : 1 and number of CG steps : 4 total energy / atom convergence tol. : 0.1000E-04 eV max force / atom convergence tol. : ignored convergence tolerance window : 3 cycles max. number of SCF cycles : 30 periodic dipole correction : NONE *********************** Population Analysis Parameters ************************ Population analysis with cutoff : 3.000 A Population analysis output : summary and pdos components ******************************************************************************* ------------------------------- Unit Cell ------------------------------- Real Lattice(A) Reciprocal Lattice(1/A) 2.6954645 2.6954645 0.0000000 1.165510677 1.165510677 -1.165510677 2.6954645 0.0000000 2.6954645 1.165510677 -1.165510677 1.165510677 0.0000000 2.6954645 2.6954645 -1.165510677 1.165510677 1.165510677 Lattice parameters(A) Cell Angles a = 3.811962 alpha = 60.000000 b = 3.811962 beta = 60.000000 c = 3.811962 gamma = 60.000000 Current cell volume = 39.167950 A**3 density = 1.434106 AMU/A**3 = 2.381389 g/cm^3 ------------------------------- Cell Contents ------------------------------- Total number of ions in cell = 2 Total number of species in cell = 1 Max number of any one species = 2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x Element Atom Fractional coordinates of atoms x x Number u v w x x----------------------------------------------------------x x Si 1 -0.000000 -0.000000 -0.000000 x x Si 2 0.250000 0.250000 0.250000 x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx No user defined ionic velocities ------------------------------- Details of Species ------------------------------- Mass of species in AMU Si 28.0855000 Electric Quadrupole Moment (Barn) Si 1.0000000 No Isotope Defined Files used for pseudopotentials: Si 3|1.8|5|6|7|30:31:32 ------------------------------- k-Points For BZ Sampling ------------------------------- MP grid size for SCF calculation is 4 4 4 with an offset of 0.000 0.000 0.000 Number of kpoints used = 10 ------------------------------- Symmetry and Constraints ------------------------------- Maximum deviation from symmetry = 0.748142E-16 ANG Number of symmetry operations = 48 Number of ionic constraints = 3 Point group of crystal = 32: Oh, m-3m, 4/m -3 2/m Space group of crystal = 227: Fd-3m, F 4d 2 3 -1d Set iprint > 1 for details on symmetry rotations/translations Centre of mass is constrained Set iprint > 1 for details of linear ionic constraints Number of cell constraints= 5 Cell constraints are: 1 1 1 0 0 0 External pressure/stress (GPa) 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 +---------------- MEMORY AND SCRATCH DISK ESTIMATES PER PROCESS --------------+ | Memory Disk | | Baseline code, static data and system overhead 33.0 MB 0.0 MB | | BLAS internal memory storage 0.0 MB 0.0 MB | | Model and support data 15.5 MB 4.4 MB | | Electronic energy minimisation requirements 0.4 MB 0.6 MB | | Force calculation requirements 0.4 MB 0.0 MB | | ----------------------------- | | Approx. total storage required per process 48.9 MB 5.0 MB | | | | Requirements will fluctuate during execution and may exceed these estimates | +-----------------------------------------------------------------------------+ Calculating total energy with cut-off of 163.268 eV. ------------------------------------------------------------------------ <-- SCF SCF loop Energy Energy gain Timer <-- SCF per atom (sec) <-- SCF ------------------------------------------------------------------------ <-- SCF Initial 5.38885016E+001 3.73 <-- SCF 1 -3.23029209E+002 1.88458855E+002 4.07 <-- SCF 2 -3.36680788E+002 6.82578942E+000 4.39 <-- SCF 3 -3.37655316E+002 4.87264051E-001 4.72 <-- SCF 4 -3.37909301E+002 1.26992416E-001 5.07 <-- SCF 5 -3.37909560E+002 1.29231306E-004 5.40 <-- SCF 6 -3.37909560E+002 2.51802717E-007 5.79 <-- SCF 7 -3.37909560E+002 7.15553895E-009 6.14 <-- SCF ------------------------------------------------------------------------ <-- SCF Final energy = -337.9095600892 eV (energy not corrected for finite basis set) Writing analysis data to aiida.castep_bin Writing model to aiida.check ******************** Symmetrised Forces ******************** * * * Cartesian components (eV/A) * * -------------------------------------------------------- * * x y z * * * * Si 1 0.00000 0.00000 0.00000 * * Si 2 0.00000 0.00000 0.00000 * * * ************************************************************ Pseudo atomic calculation performed for Si 3s2 3p2 Converged in 16 iterations to a total energy of -162.9815 eV Charge spilling parameter for spin component 1 = 0.84% Orbital Populations Ion Atom Orbital Charge ------------------------------------------- Si 1 S 1.357 Si 1 Px 0.924 Si 1 Py 0.884 Si 1 Pz 0.834 Si 2 S 1.357 Si 2 Px 0.924 Si 2 Py 0.884 Si 2 Pz 0.835 ------------------------------------------- Total: 8.000 ------------------------------------------- Atomic Populations (Mulliken) ----------------------------- Species Ion s p d f Total Charge (e) ===================================================================== Si 1 1.36 2.64 0.00 0.00 4.00 0.00 Si 2 1.36 2.64 0.00 0.00 4.00 0.00 ===================================================================== Bond Population Length (A) ====================================================================== Si 1 -- Si 2 2.98 2.33434 ====================================================================== Writing analysis data to aiida.castep_bin Writing model to aiida.check A BibTeX formatted list of references used in this run has been written to aiida.bib Initialisation time = 3.44 s Calculation time = 2.92 s Finalisation time = 0.02 s Total time = 6.38 s Peak Memory Use = 77736 kB
An result of calculation is reflected by the exit status. Like processes, zero return code means it completed without error.
calcjob.exit_status
0
To can the list of possible exit_status
and they meanings, we can use verdi plugin list
. This also shows list of inputs of which the required ones are in bold.
!verdi plugin list aiida.calculations castep.castep
Description: Class representing a generic CASTEP calculation - This class should work for all types of calculations. Inputs: parameters: required Dict A node that defines the input parameters pseudos: required Use nodes for the pseudopotentails of one ofthe element in the structure. Y ... structure: required StructureData The input structure bs_kpoints: optional KpointsData Extra kpoints input for task: bandstructure code: optional Code The `Code` to use for this job. This input is required, unless the `remote_ ... elnes_kpoints: optional KpointsData Extra kpoints input for task: elnes kpoints: optional KpointsData Use a node defining the kpoints for the calculation magres_kpoints: optional KpointsData Extra kpoints input for task: magres metadata: optional optics_kpoints: optional KpointsData Extra kpoints input for task: optics parent_calc_folder: optional RemoteData Use a remote folder as the parent folder. Useful for restarts. phonon_fine_kpoints: optional KpointsData Extra kpoints input for task: phonon, phonon+efield phonon_kpoints: optional KpointsData Extra kpoints input for task: phonon, phonon+efield remote_folder: optional RemoteData Remote directory containing the results of an already completed calculation ... settings: optional Dict A node for additional settings spectral_kpoints: optional KpointsData Extra kpoints input for task: spectral supercell_kpoints: optional KpointsData Extra kpoints input for task: phonon Outputs: output_parameters: required Dict Parsed results in a dictionary format. remote_folder: required RemoteData Input files necessary to run the process will be stored in this folder node ... retrieved: required FolderData Files that are retrieved by the daemon will be stored in this node. By defa ... remote_stash: optional RemoteStashData Contents of the `stash.source_list` option are stored in this remote folder ... Exit codes: 0: Calculation terminated gracefully, end found 1: The process has failed with an unspecified error. 2: The process failed with legacy failure mode. 10: The process returned an invalid output. 11: The process did not register a required output. 100: The process did not have the required `retrieved` output. 101: SCF Cycles failed to reach convergence 103: Stopped execuation due to detection of 'stop ' keyword in param file. 104: CASTEP generate error files. Check them for details 105: Cannot find the end of calculation 106: No output .castep files found 107: Calculation self-terminated due to time limit 108: No retrieve folder is found 110: The job ran out of memory. 120: The job ran out of walltime. 200: UNKOWN ERROR 501: At least one kpoints/spin has no empty bands - please rerun with increased nextra_bands.
Results of calculation can be access in python
# A Dict node is created containing some of the parsed results
calcjob.outputs.output_parameters.get_dict()
{'warnings': [], 'castep_version': '19.1', 'unit_length': 'A', 'unit_time': 'ps', 'unit_energy': 'eV', 'unit_force': 'eV/A', 'num_ions': 2, 'n_kpoints': '10', 'point_group': '32: Oh, m-3m, 4/m -3 2/m', 'space_group': '227: Fd-3m, F 4d 2 3 -1d', 'cell_constraints': '1 1 1 0 0 0', 'pseudo_pots': {'Si': '3|1.8|5|6|7|30:31:32'}, 'initialisation_time': 3.44, 'calculation_time': 2.92, 'finalisation_time': 0.02, 'total_time': 6.38, 'geom_unconverged': None, 'parser_warnings': [], 'parser_info': 'AiiDA CASTEP basic Parser v1.1.1', 'total_energy': -337.9095600892, 'error_messages': []}
# Alternatively, you can access the parsed results using
calcjob.res.castep_version # hit tab for completion after `res`
'19.1'
# To get all the outgoing links and nodes
calcjob.get_outgoing().all()
[LinkTriple(node=<RemoteData: uuid: 36167374-0f02-467e-9ccb-25a6c62f27a0 (pk: 7)>, link_type=<LinkType.CREATE: 'create'>, link_label='remote_folder'), LinkTriple(node=<FolderData: uuid: d610ec30-f095-4018-b403-5c4ddb5aa4cb (pk: 8)>, link_type=<LinkType.CREATE: 'create'>, link_label='retrieved'), LinkTriple(node=<BandsData: uuid: c05a309e-706d-499c-8558-3cbe958f61da (pk: 9)>, link_type=<LinkType.CREATE: 'create'>, link_label='output_bands'), LinkTriple(node=<ArrayData: uuid: bae83129-6fee-44df-a8a4-d895406e6c0b (pk: 10)>, link_type=<LinkType.CREATE: 'create'>, link_label='output_array'), LinkTriple(node=<Dict: uuid: 2adc9560-6b1e-47d4-817a-7d6ba740b84d (pk: 11)>, link_type=<LinkType.CREATE: 'create'>, link_label='output_parameters')]
# Or just the nodes
calcjob.get_outgoing().all_nodes()
[<RemoteData: uuid: 36167374-0f02-467e-9ccb-25a6c62f27a0 (pk: 7)>, <FolderData: uuid: d610ec30-f095-4018-b403-5c4ddb5aa4cb (pk: 8)>, <BandsData: uuid: c05a309e-706d-499c-8558-3cbe958f61da (pk: 9)>, <ArrayData: uuid: bae83129-6fee-44df-a8a4-d895406e6c0b (pk: 10)>, <Dict: uuid: 2adc9560-6b1e-47d4-817a-7d6ba740b84d (pk: 11)>]
The actual files retrived from remote computer is stored in a FolderData
node.
# The output .castep files and others are stored in the repository
calcjob.outputs.retrieved.base.repository.list_object_names()
['_scheduler-stderr.txt', '_scheduler-stdout.txt', 'aiida.bands', 'aiida.castep', 'aiida.den_fmt']
We check if the correct energy was parsed from the output .castep
file
# To quickly check the output file
!echo '{calcjob.outputs.retrieved.base.repository.get_object_content('aiida.castep')}' | grep 'Final energy'
# The parsed the total energy
print(calcjob.res.total_energy)
Final energy = -337.9095600892 eV -337.9095600892
So the energy matches 👏!