aton.api.castep

Description

Functions to work with CASTEP calculation files.

Index

read_castep() Output reading

 1"""
 2# Description
 3
 4Functions to work with [CASTEP](https://castep-docs.github.io/castep-docs/) calculation files.
 5
 6# Index
 7
 8| | |
 9| --- | --- |
10| `read_castep()` | Output reading |
11
12---
13"""
14
15
16import aton.file as file
17import aton.txt.find as find
18import aton.txt.extract as extract
19
20
21def read_castep(filename) -> dict:
22    """
23    Reads a CASTEP output file, specified in `filename`.
24    Returns a dictionary with the following keys:
25    `'Enthalpy'` (LBFGS: Final Enthalpy, in kJ/mol),
26    `'Energy'` (Total energy corrected for finite basis set, in eV),
27    `'Space group'`, `'Volume'` (Angstrom^3), `'Density'` (amu/Angstrom^3), `'Density_g'` (g/cm^3),
28    `'A'`, `'B'`, `'C'` (Angstroms), `'Alpha'`, `'Beta'`, `'Gamma'` (Degrees).\n
29    Note that these output keys start with a **C**apital letter.
30    """
31    file_castep = file.get(filename)
32    # Initial definitions
33    enthalpy    = None
34    energy      = None
35    space_group = None
36    volume      = None
37    density     = None
38    density_g   = None
39    a           = None
40    b           = None
41    c           = None
42    alpha       = None
43    beta        = None
44    gamma       = None
45    # Find the output values in the file
46    enthalpy_str    = find.lines(file_castep, 'LBFGS: Final Enthalpy     =', -1)
47    energy_str      = find.lines(file_castep, 'Total energy corrected for finite basis set =', -1)
48    space_group_str = find.lines(file_castep, 'Space group of crystal =', -1)
49    volume_str      = find.lines(file_castep, 'Current cell volume =', -1)
50    density_str     = find.lines(file_castep, 'density =', -1, 1)
51    a_str           = find.lines(file_castep, 'a =', -1)
52    b_str           = find.lines(file_castep, 'b =', -1)
53    c_str           = find.lines(file_castep, 'c =', -1)
54    
55    if enthalpy_str:
56        enthalpy = extract.number(enthalpy_str[0], 'LBFGS: Final Enthalpy')
57    if energy_str:
58        energy = extract.number(energy_str[0], 'Total energy corrected for finite basis set')
59    if space_group_str:
60        # Avoid little stupid errors
61        space_group_str = space_group_str.replace(',','.')
62        space_group = extract.string(space_group_str[0], 'Space group of crystal')
63    if volume_str:
64        volume = extract.number(volume_str[0], 'Current cell volume')
65    if density_str:
66        density = extract.number(density_str[0], 'density')
67        density_g = extract.number(density_str[1], '')
68    if a:
69        a = extract.number(a_str, 'a')
70        alpha = extract.number(a_str, 'alpha')
71    if b:
72        b = extract.number(b_str, 'b')
73        beta = extract.number(b_str, 'beta')
74    if c:
75        c = extract.number(c_str, 'c')
76        gamma = extract.number(c_str, 'gamma')
77    # Return as a dict
78    dictionary = {
79        'Enthalpy'    : enthalpy,
80        'Energy'      : energy,
81        'Space group' : space_group,
82        'Volume'      : volume,
83        'Density'     : density,
84        'Density_g'   : density_g,
85        'A'           : a,
86        'B'           : b,
87        'C'           : c,
88        'Alpha'       : alpha,
89        'Beta'        : beta,
90        'Gamma'       : gamma,
91    }
92    return dictionary
def read_castep(filename) -> dict:
22def read_castep(filename) -> dict:
23    """
24    Reads a CASTEP output file, specified in `filename`.
25    Returns a dictionary with the following keys:
26    `'Enthalpy'` (LBFGS: Final Enthalpy, in kJ/mol),
27    `'Energy'` (Total energy corrected for finite basis set, in eV),
28    `'Space group'`, `'Volume'` (Angstrom^3), `'Density'` (amu/Angstrom^3), `'Density_g'` (g/cm^3),
29    `'A'`, `'B'`, `'C'` (Angstroms), `'Alpha'`, `'Beta'`, `'Gamma'` (Degrees).\n
30    Note that these output keys start with a **C**apital letter.
31    """
32    file_castep = file.get(filename)
33    # Initial definitions
34    enthalpy    = None
35    energy      = None
36    space_group = None
37    volume      = None
38    density     = None
39    density_g   = None
40    a           = None
41    b           = None
42    c           = None
43    alpha       = None
44    beta        = None
45    gamma       = None
46    # Find the output values in the file
47    enthalpy_str    = find.lines(file_castep, 'LBFGS: Final Enthalpy     =', -1)
48    energy_str      = find.lines(file_castep, 'Total energy corrected for finite basis set =', -1)
49    space_group_str = find.lines(file_castep, 'Space group of crystal =', -1)
50    volume_str      = find.lines(file_castep, 'Current cell volume =', -1)
51    density_str     = find.lines(file_castep, 'density =', -1, 1)
52    a_str           = find.lines(file_castep, 'a =', -1)
53    b_str           = find.lines(file_castep, 'b =', -1)
54    c_str           = find.lines(file_castep, 'c =', -1)
55    
56    if enthalpy_str:
57        enthalpy = extract.number(enthalpy_str[0], 'LBFGS: Final Enthalpy')
58    if energy_str:
59        energy = extract.number(energy_str[0], 'Total energy corrected for finite basis set')
60    if space_group_str:
61        # Avoid little stupid errors
62        space_group_str = space_group_str.replace(',','.')
63        space_group = extract.string(space_group_str[0], 'Space group of crystal')
64    if volume_str:
65        volume = extract.number(volume_str[0], 'Current cell volume')
66    if density_str:
67        density = extract.number(density_str[0], 'density')
68        density_g = extract.number(density_str[1], '')
69    if a:
70        a = extract.number(a_str, 'a')
71        alpha = extract.number(a_str, 'alpha')
72    if b:
73        b = extract.number(b_str, 'b')
74        beta = extract.number(b_str, 'beta')
75    if c:
76        c = extract.number(c_str, 'c')
77        gamma = extract.number(c_str, 'gamma')
78    # Return as a dict
79    dictionary = {
80        'Enthalpy'    : enthalpy,
81        'Energy'      : energy,
82        'Space group' : space_group,
83        'Volume'      : volume,
84        'Density'     : density,
85        'Density_g'   : density_g,
86        'A'           : a,
87        'B'           : b,
88        'C'           : c,
89        'Alpha'       : alpha,
90        'Beta'        : beta,
91        'Gamma'       : gamma,
92    }
93    return dictionary

Reads a CASTEP output file, specified in filename. Returns a dictionary with the following keys: 'Enthalpy' (LBFGS: Final Enthalpy, in kJ/mol), 'Energy' (Total energy corrected for finite basis set, in eV), 'Space group', 'Volume' (Angstrom^3), 'Density' (amu/Angstrom^3), 'Density_g' (g/cm^3), 'A', 'B', 'C' (Angstroms), 'Alpha', 'Beta', 'Gamma' (Degrees).

Note that these output keys start with a Capital letter.