castep_outputs.utilities.castep_res#

Module containing all regexes.

Module Attributes

Pattern

Valid input where patterns are wanted.

FNUMBER_RE

Floating point number.

INTNUMBER_RE

Integer number.

EXPNUMBER_RE

Float or int with exponent.

EXPFNUMBER_RE

Exponent or bare floating point.

RATIONAL_RE

Integer ratio.

NUMBER_RE

Generalised number.

FLOAT_RAT_RE

Floating point, integer or ratio.

THREEVEC_RE

Three vector.

SPECIES_RE

Element name.

ATOM_NAME_RE

CASTEP atom name with optional tag and label.

ATOM_NAME_GRP_RE

Labelled CASTEP atom name.

SHELL_RE

RegEx for atomic shell labels.

TAG_RE

RegEx for CASTEP table tags as in e.g. .md/.geom.

EMPTY

Empty line RegEx

ATOM_RE

CASTEP Atom RegEx with optional index.

ATOMIC_DATA_3VEC

CASTEP atom followed by 3D vector.

Functions

gen_table_re(content[, border, pre, post, ...])

Construct a regex for matching table headers with given borders.

get_atom_parts(spec)

Get components of an atom name (species, tag, label) from a spec string.

get_numbers(line)

Get all numbers in a string as a list.

labelled_floats(labels[, counts, sep, suffix])

Construct a regex for extracting floats with assigned labels.

castep_outputs.utilities.castep_res.ATOMIC_DATA_3VEC#

CASTEP atom followed by 3D vector.

castep_outputs.utilities.castep_res.ATOM_NAME_GRP_RE#

Labelled CASTEP atom name.

castep_outputs.utilities.castep_res.ATOM_NAME_RE#

CASTEP atom name with optional tag and label.

castep_outputs.utilities.castep_res.ATOM_RE#

CASTEP Atom RegEx with optional index.

castep_outputs.utilities.castep_res.EMPTY#

Empty line RegEx

castep_outputs.utilities.castep_res.EXPFNUMBER_RE#

Exponent or bare floating point.

castep_outputs.utilities.castep_res.EXPNUMBER_RE#

Float or int with exponent.

castep_outputs.utilities.castep_res.FLOAT_RAT_RE#

Floating point, integer or ratio.

castep_outputs.utilities.castep_res.FNUMBER_RE#

Floating point number.

castep_outputs.utilities.castep_res.INTNUMBER_RE#

Integer number.

castep_outputs.utilities.castep_res.NUMBER_RE#

Generalised number.

castep_outputs.utilities.castep_res.Pattern#

Valid input where patterns are wanted.

alias of str | Pattern

castep_outputs.utilities.castep_res.RATIONAL_RE#

Integer ratio.

castep_outputs.utilities.castep_res.SHELL_RE#

RegEx for atomic shell labels. E.g. 4d4.

castep_outputs.utilities.castep_res.SPECIES_RE#

Element name.

castep_outputs.utilities.castep_res.TAG_RE#

RegEx for CASTEP table tags as in e.g. .md/.geom.

castep_outputs.utilities.castep_res.THREEVEC_RE#

Three vector.

castep_outputs.utilities.castep_res.gen_table_re(content, border='\\\\s*', *, pre='', post='', whole_line=True)[source]#

Construct a regex for matching table headers with given borders.

Parameters:
  • content (str) – RegEx capturing the content of the table.

  • border (str) – RegEx capturing the characters the make up the border.

  • pre (str) – RegEx matching content outside and before the table.

  • post (str) – RegEx matching content outside and after the table.

  • whole_line (bool) – Whether the RegExes are an exact match for the whole line.

Returns:

RegEx pattern to match line(s).

Return type:

str

Examples

RegEx for a line of “?”s

# No content, with any number of questionmarks.
gen_table_re("", r"\?+")

RegEx for a separator line in a table which resembles:

+-----------------------------------+
gen_table_re("-+", "\+")
castep_outputs.utilities.castep_res.get_atom_parts(spec)[source]#

Get components of an atom name (species, tag, label) from a spec string.

Parameters:

spec (str) – String to split up.

Returns:

Dictionary detailing separate parts of atom name.

Return type:

dict[str, str]

Examples

>>> get_atom_parts("Ar")
{'species': 'Ar'}
>>> get_atom_parts("Ar:tag")
{'species': 'Ar', 'tag': 'tag'}
>>> get_atom_parts("Ar [label]")
{'species': 'Ar', 'label': 'label'}
>>> get_atom_parts("Ar:tag[label]")
{'species': 'Ar', 'tag': 'tag', 'label': 'label'}
castep_outputs.utilities.castep_res.get_numbers(line)[source]#

Get all numbers in a string as a list.

Parameters:

line (str) – String to search for valid numbers.

Returns:

All numbers found in line.

Return type:

list[str]

Examples

>>> get_numbers("Hello 13, my name is 3.142")
['13', '3.142']

See also

NUMBER_RE

RegEx matching numbers.

castep_outputs.utilities.castep_res.labelled_floats(labels, counts=(None,), sep='\\\\s+?', suffix='')[source]#

Construct a regex for extracting floats with assigned labels.

Parameters:
  • labels (Sequence[str]) – Iterable of labels to label each group.

  • counts (Sequence[int | str | None]) – Iterable of counts to group into each label (count must not exceed that of labels).

  • sep (str) – Separator between floats.

  • suffix (str) – Suffix following each float.

Returns:

Regular expression to match floats with given labels.

Return type:

str

Raises:

NotImplementedError – If suffix and counts provided.

Examples

# Capture 3 space-separated floats with labels "x", "y", "z"
labelled_floats(("x", "y", "z"))
# Capture 2 colon-separated floats with labels "u", "v"
labelled_floats(("u", "v"), sep=":")
# Capture 3 space-separated floats under the label "val"
labelled_floats(("val",), counts=(3,))