aiida_castep.parsers package#

Submodules#

aiida_castep.parsers.castep module#

Parsers for CASTEP

class aiida_castep.parsers.castep.CastepParser(node)[source]#

Bases: Parser

This is the class for Parsing results from a CASTEP calculation Supported calculations types: singlepoint geom

__abstractmethods__ = frozenset({})#
__module__ = 'aiida_castep.parsers.castep'#
_abc_impl = <_abc_data object>#
_has_empty_bands(bands_data: BandsData, thresh=0.005)[source]#

Check for the occupation of the BandsData

There should be some empty bands if the calculation is a not a fixed occupation one. Otherwise, the final energy and forces are not reliable.

_setting_key = 'parser_options'#
property castep_input_parameters#

Access the original castep input parameters

property castep_task#

Task of the calculation

parse(**kwargs)[source]#

Receives a dictionary of retrieved nodes.retrieved. Top level logic of operation

class aiida_castep.parsers.castep.RetrievedFileManager(retrieved_node, retrieved_temporary_folder=None)[source]#

Bases: object

Wrapper for supplying an unified file-handler interface for the retrieved content

__dict__ = mappingproxy({'__module__': 'aiida_castep.parsers.castep', '__doc__': '\n    Wrapper for supplying an unified file-handler interface for the retrieved content\n    ', '__init__': <function RetrievedFileManager.__init__>, 'open': <function RetrievedFileManager.open>, 'has_file': <function RetrievedFileManager.has_file>, 'list_object_names': <function RetrievedFileManager.list_object_names>, 'get_object_content': <function RetrievedFileManager.get_object_content>, '__dict__': <attribute '__dict__' of 'RetrievedFileManager' objects>, '__weakref__': <attribute '__weakref__' of 'RetrievedFileManager' objects>, '__annotations__': {}})#
__init__(retrieved_node, retrieved_temporary_folder=None)[source]#

Instantiate the manager object

__module__ = 'aiida_castep.parsers.castep'#
__weakref__#

list of weak references to the object (if defined)

get_object_content(name, mode='r') Union[str, bytes][source]#
has_file(name) bool[source]#

Return if we have this file

list_object_names() List[str][source]#

Return all object names avalaible

open(name, mode='r')[source]#

Open a file from either the retrieved node or the temporary folder

aiida_castep.parsers.castep.bands_from_castepbin(seedname, fmanager)[source]#

Acquire and prepare bands data from the castep_bin file instead

aiida_castep.parsers.castep.bands_to_bandsdata(bands_info, kpoints, bands)[source]#

Convert the result of parser_dot_bands into a BandsData object

Parameters:
  • bands_info – A dictionary of the informations of the bands file. contains field such as eferemi, units, cell

  • kpoints – An array of the kpoints of the bands, rows are (kindex, kx, ky, kz, weight)

  • bands – The actual bands array

Returns:

A BandsData object

Return type:

aiida.orm.bands.data.array.bands.BandsData

aiida_castep.parsers.castep_bin module#

Parser interface for CASTEP bin file

A few quantities are only avaliable from the CASTEP bin file

class aiida_castep.parsers.castep_bin.CastepbinFile(fileobj=None, filename=None)[source]#

Bases: object

Parser for the castep_bin file.

The heavy lifting is done by the castepxbin package, but here we need to do unit conversion and reorganisation.

__dict__ = mappingproxy({'__module__': 'aiida_castep.parsers.castep_bin', '__doc__': '\n    Parser for the `castep_bin` file.\n\n    The heavy lifting is done by the `castepxbin` package, but here we need to do unit\n    conversion and reorganisation.\n    ', '__init__': <function CastepbinFile.__init__>, 'eigenvalues': <property object>, 'total_energy': <property object>, 'occupancies': <property object>, 'kpoints': <property object>, 'kpoints_current_cell': <property object>, 'kpoint_weights': <property object>, 'kpoints_indices': <property object>, 'forces': <property object>, 'scaled_positions': <property object>, 'fermi_energy': <property object>, 'cell': <property object>, '_reindex3': <function CastepbinFile._reindex3>, '_reindex2': <function CastepbinFile._reindex2>, '__dict__': <attribute '__dict__' of 'CastepbinFile' objects>, '__weakref__': <attribute '__weakref__' of 'CastepbinFile' objects>, '__annotations__': {}})#
__init__(fileobj=None, filename=None)[source]#

Instantiate from an file object

__module__ = 'aiida_castep.parsers.castep_bin'#
__weakref__#

list of weak references to the object (if defined)

_reindex2(array)[source]#

Reshape the array (N, i_ion, i_species) into the common (NION, N) shape

_reindex3(array)[source]#

Reshape the array (N, i_ion, i_species) into the common (NION, N) shape

property cell#

Cell matrix (of row vectors)

property eigenvalues#

Return the eigenvalues array with shape (ns, nk, nb)

property fermi_energy#

Return the feremi energies

property forces#

Return the force array in unit eV/A

property kpoint_weights#

Return the weights of the kpoints in the internal order

property kpoints#

Return the kpoints array with shape (nk, 3)

property kpoints_current_cell#

Return the ordered kpoints array of the current cell with shape (nk, 3) The order of these kpoints may not be consistent with the eigenvalues.

property kpoints_indices#

Return the indices of the kpoints

The kpoints, eigenvalues, and occupations may not be in the original order as defined by the cell file, if the calculations is parallelised over the kpoints.

This property gives the index of the kpoints so that the original order can be recovered.

Note that most properties are in the “internal” order of kpoints, the original order is mostly useful for band structure calculations where the list of kpoints is explicitly given.

property occupancies#

Return the occupation array with shape (ns, nk, nb)

property scaled_positions#

Return the scaled positions

property total_energy#

Total energy in eV

aiida_castep.parsers.constants module#

Constants for unit conversion

aiida_castep.parsers.raw_parser module#

Module for parsing .castep file This module should not rely on any of AiiDA modules

class aiida_castep.parsers.raw_parser.LineParser(conditions)[source]#

Bases: object

Parser for a line

__dict__ = mappingproxy({'__module__': 'aiida_castep.parsers.raw_parser', '__doc__': '\n    Parser for a line\n    ', '__init__': <function LineParser.__init__>, 'parse': <function LineParser.parse>, '__dict__': <attribute '__dict__' of 'LineParser' objects>, '__weakref__': <attribute '__weakref__' of 'LineParser' objects>, '__annotations__': {}})#
__init__(conditions)[source]#

initialize the Parser by passing the conditions

__module__ = 'aiida_castep.parsers.raw_parser'#
__weakref__#

list of weak references to the object (if defined)

parse(line)[source]#

Return parsing results

Returns:

Result of the first matched Matcher object or None if no match is found

class aiida_castep.parsers.raw_parser.Matcher(regex, name, convfunc=None)[source]#

Bases: object

Class of the condition to match the line

__dict__ = mappingproxy({'__module__': 'aiida_castep.parsers.raw_parser', '__doc__': '\n    Class of the condition to match the line\n    ', '__init__': <function Matcher.__init__>, 'match_pattern': <function Matcher.match_pattern>, '__dict__': <attribute '__dict__' of 'Matcher' objects>, '__weakref__': <attribute '__weakref__' of 'Matcher' objects>, '__annotations__': {}})#
__init__(regex, name, convfunc=None)[source]#

Initialize a Matcher object.

Parameters:
  • regex (string) – Pattern to be matched

  • name (string) – Name of the results

__module__ = 'aiida_castep.parsers.raw_parser'#
__weakref__#

list of weak references to the object (if defined)

match_pattern(line)[source]#

Match pattern

Returns:

(out, match) Out is a dicationary of {self.name: <matched_value>}. and match is a re.MatchObject or None

class aiida_castep.parsers.raw_parser.RawParser(out_lines, input_dict, md_geom_info, bands_lines, **parser_opts)[source]#

Bases: object

An raw parser object to parse the output of CASTEP

__dict__ = mappingproxy({'__module__': 'aiida_castep.parsers.raw_parser', '__doc__': 'An raw parser object to parse the output of CASTEP', '__init__': <function RawParser.__init__>, 'parse': <function RawParser.parse>, 'parse_dot_bands': <function RawParser.parse_dot_bands>, 'parse_geom': <function RawParser.parse_geom>, 'parse_dot_castep': <function RawParser.parse_dot_castep>, '__dict__': <attribute '__dict__' of 'RawParser' objects>, '__weakref__': <attribute '__weakref__' of 'RawParser' objects>, '__annotations__': {}})#
__init__(out_lines, input_dict, md_geom_info, bands_lines, **parser_opts)[source]#

Instantiate the parser by passing list of the lines

__module__ = 'aiida_castep.parsers.raw_parser'#
__weakref__#

list of weak references to the object (if defined)

parse()[source]#
Returns:

A list of:

  • out_dict: a dictionary with parsed data.

  • trajectory_data: dictionary of trajectory data.

  • structure data: dictionary of cell, positions and symbols.

  • exit_code: exit code indicating potential problems of the run 2 different keys to check in out_dict: parser_warning and warnings.

parse_dot_bands()[source]#

Parse the dot_bands

parse_dot_castep()[source]#

Parse the dot-castep file

parse_geom(glines=None)[source]#

Parse the geom lines

class aiida_castep.parsers.raw_parser.UnitMatcher(regex, name, convfunc=None)[source]#

Bases: Matcher

The pattern of a UnitMatcher should have two groups with second group being the unit. The first group will be converted to float

__module__ = 'aiida_castep.parsers.raw_parser'#
match_pattern(line)[source]#

Match the pattern

aiida_castep.parsers.raw_parser.get_iter_parser()[source]#

Generate a LineParser object to parse repeating outputs

aiida_castep.parsers.raw_parser.parse_castep_text_output(out_lines, input_dict)[source]#

Parse ouput of .castep :param out_lines: a list of lines from readlines function

Parameters:

input_dict – Control some variables. Currently support ‘n_warning_lines’- number of the lines to include for a general warning.

Returns:

A list of parsed_data, trajectory_data and critical_messages:

  • parsed_data: dictionary with key values, referring to the last occurring quantities

  • trajectory_data: key, values of the intermediate scf steps, such as during geometryoptimization

  • critical_messages: a list with critical messages.

If any is found in parsed_data[“warnings”] the calculation should be considered as failed.

aiida_castep.parsers.raw_parser.parse_dot_bands(bands_lines)[source]#

Parse an CASTEP bands file Extract Kpoints and each bands for each kpoints. This is a generic parsing function. Return python builtin types.

The problems is the order of the kpoints written is parallelisation dependent and may not be the same as that specified in kpoints_list. However, CASTEP does write the index of the kpoints. We reorder the kpoints and the bands to match the original order in the input file.

Note that many other quantities indexed by kpoints, such as the optical matrix elements, follows the order of appearance in the bands file.

Parameters:

bands_lines – A list of lines to be parsed parse

Returns:

A list of bands_info, kpoints and bands:

  • bands_info: A dictionary for information of bands.

  • kpoints: A list of kpoints. In the format [kpoint index,

    coordinats x 3 kpoint weight]

  • bands: A list of bands. Each band has a list of actual eigenvalues for each spin components. E.g nkpoints, nspins, neigns.

Note that the atomic units are used in the bands file

aiida_castep.parsers.raw_parser.parse_force_box(lines)[source]#

Parse a box of the forces :param lines: a list of upcoming lines

Returns:

A list of number of lines read and the forces

aiida_castep.parsers.raw_parser.parse_geom_text_output(out_lines, input_dict) dict[source]#

Parse output of .geom file

Parameters:
  • out_lines – a list of lines from the readline function.

  • input_dict (dict) – not in use at the moment.

Returns:

key, value of the trajectories of cell, atoms, force etc

aiida_castep.parsers.raw_parser.parse_popn_box(lines)[source]#

Parse the Mulliken population box :param lines: a list of upcoming lines

:return a list of [number of lines read, charges, spins]

aiida_castep.parsers.raw_parser.parse_stress_box(lines)[source]#

Parse a box of the stress :param lines: a list of upcoming lines

Returns:

a list of [number of lines read, stress_tensor, pressure]

aiida_castep.parsers.test_marcher module#

aiida_castep.parsers.utils module#

Utility functions

exception aiida_castep.parsers.utils.CASTEPOutputParsingError[source]#

Bases: OutputParsingError

__module__ = 'aiida_castep.parsers.utils'#
aiida_castep.parsers.utils.add_last_if_exists(dict_of_sequence, key, dict_to_be_added)[source]#

Added the last term of a sequence to a dictionary. This is used for collecting final values in a dictionary of ‘trajectory’

aiida_castep.parsers.utils.desort_structure(structure, original_structure)[source]#

Recover the order of structure. CASTEP will sort the input structure according to the atomic numbers

aiida_castep.parsers.utils.get_desort_args(original_structure)[source]#

Return an index array for desorting the structure

Returns:

An array used to recovery the original order

aiida_castep.parsers.utils.structure_from_input(cell, positions, symbols)[source]#

Receives the dictionary cell parsed from CASTEP Convert it into an AiiDA structure object

Module contents#