|
| 1 | +import re |
| 2 | + |
| 3 | +from nomad.parsing.file_parser.text_parser import Quantity, TextParser |
| 4 | + |
| 5 | + |
| 6 | +RE_N = r'[\n\r]' |
| 7 | + |
| 8 | + |
| 9 | +class WInParser(TextParser): |
| 10 | + def init_quantities(self): |
| 11 | + def str_proj_to_list(val_in: str) -> list[str]: |
| 12 | + # To avoid inconsistent regex that can contain or not spaces |
| 13 | + val_n = [re.sub(r'\s.*', '', x) for x in val_in.split('\n') if x] |
| 14 | + return [v.strip('[]').replace(' ', '').split(':') for v in val_n] |
| 15 | + |
| 16 | + self._quantities = [ |
| 17 | + Quantity( |
| 18 | + 'energy_fermi', r'\n\rfermi_energy\s*=\s*([\d\.\-]+)', repeats=False |
| 19 | + ), |
| 20 | + Quantity( |
| 21 | + 'projections', |
| 22 | + r'[bB]egin [pP]rojections([\s\S]+?)(?:[eE]nd [pP]rojections)', |
| 23 | + repeats=False, |
| 24 | + str_operation=str_proj_to_list, |
| 25 | + ), |
| 26 | + ] |
| 27 | + |
| 28 | + |
| 29 | +class HrParser(TextParser): |
| 30 | + def init_quantities(self): |
| 31 | + self._quantities = [ |
| 32 | + Quantity('degeneracy_factors', r'\s*written on[\s\w]*:\d*:\d*\s*([\d\s]+)'), |
| 33 | + Quantity('hoppings', r'\s*([-\d\s.]+)', repeats=False), |
| 34 | + ] |
| 35 | + |
| 36 | + |
| 37 | +class WOutParser(TextParser): |
| 38 | + def __init__(self): |
| 39 | + super().__init__(None) |
| 40 | + |
| 41 | + def init_quantities(self): |
| 42 | + kmesh_quantities = [ |
| 43 | + Quantity('n_points', r'Total points[\s=]*(\d+)', dtype=int, repeats=False), |
| 44 | + Quantity( |
| 45 | + 'grid', r'Grid size *\= *(\d+) *x *(\d+) *x *(\d+)', repeats=False |
| 46 | + ), |
| 47 | + Quantity('k_points', r'\|[\s\d]*(-*\d.[^\|]+)', repeats=True, dtype=float), |
| 48 | + ] |
| 49 | + |
| 50 | + klinepath_quantities = [ |
| 51 | + Quantity( |
| 52 | + 'high_symm_name', |
| 53 | + r'\| *From\: *([a-zA-Z]+) [\d\.\-\s]*To\: *([a-zA-Z]+)', |
| 54 | + repeats=True, |
| 55 | + ), |
| 56 | + Quantity( |
| 57 | + 'high_symm_value', |
| 58 | + r'\| *From\: *[a-zA-Z]* *([\d\.\-\s]+)To\: *[a-zA-Z]* *([\d\.\-\s]+)\|', |
| 59 | + repeats=True, |
| 60 | + ), |
| 61 | + ] |
| 62 | + |
| 63 | + disentangle_quantities = [ |
| 64 | + Quantity( |
| 65 | + 'outer', |
| 66 | + r'\|\s*Outer:\s*([-\d.]+)\s*\w*\s*([-\d.]+)\s*\((?P<__unit>\w+)\)', |
| 67 | + dtype=float, |
| 68 | + repeats=False, |
| 69 | + ), |
| 70 | + Quantity( |
| 71 | + 'inner', |
| 72 | + r'\|\s*Inner:\s*([-\d.]+)\s*\w*\s*([-\d.]+)\s*\((?P<__unit>\w+)\)', |
| 73 | + dtype=float, |
| 74 | + repeats=False, |
| 75 | + ), |
| 76 | + ] |
| 77 | + |
| 78 | + structure_quantities = [ |
| 79 | + Quantity('labels', r'\|\s*([A-Z][a-z]*)', repeats=True), |
| 80 | + Quantity( |
| 81 | + 'positions', |
| 82 | + r'\|\s*([\-\d\.]+)\s*([\-\d\.]+)\s*([\-\d\.]+)', |
| 83 | + repeats=True, |
| 84 | + dtype=float, |
| 85 | + ), |
| 86 | + ] |
| 87 | + |
| 88 | + self._quantities = [ |
| 89 | + # Program quantities |
| 90 | + Quantity( |
| 91 | + 'version', r'\s*\|\s*Release\:\s*([\d\.]+)\s*', repeats=False |
| 92 | + ), |
| 93 | + # System quantities |
| 94 | + Quantity('lattice_vectors', r'\s*a_\d\s*([\d\-\s\.]+)', repeats=True), |
| 95 | + Quantity( |
| 96 | + 'reciprocal_lattice_vectors', r'\s*b_\d\s*([\d\-\s\.]+)', repeats=True |
| 97 | + ), |
| 98 | + Quantity( |
| 99 | + 'structure', |
| 100 | + rf'(\s*Fractional Coordinate[\s\S]+?)(?:{RE_N}\s*(PROJECTIONS|K-POINT GRID))', |
| 101 | + repeats=False, |
| 102 | + sub_parser=TextParser(quantities=structure_quantities), |
| 103 | + ), |
| 104 | + # Method quantities |
| 105 | + Quantity( |
| 106 | + 'k_mesh', |
| 107 | + r'\s*(K-POINT GRID[\s\S]+?)(?:-\s*MAIN)', |
| 108 | + repeats=False, |
| 109 | + sub_parser=TextParser(quantities=kmesh_quantities), |
| 110 | + ), |
| 111 | + Quantity( |
| 112 | + 'k_line_path', |
| 113 | + r'\s*(K-space path sections\:[\s\S]+?)(?:\*-------)', |
| 114 | + repeats=False, |
| 115 | + sub_parser=TextParser(quantities=klinepath_quantities), |
| 116 | + ), |
| 117 | + Quantity( |
| 118 | + 'Nwannier', |
| 119 | + r'\|\s*Number of Wannier Functions\s*\:\s*(\d+)', |
| 120 | + repeats=False, |
| 121 | + ), |
| 122 | + Quantity( |
| 123 | + 'Nband', |
| 124 | + r'\|\s*Number of input Bloch states\s*\:\s*(\d+)', |
| 125 | + repeats=False, |
| 126 | + ), |
| 127 | + Quantity( |
| 128 | + 'Niter', r'\|\s*Total number of iterations\s*\:\s*(\d+)', repeats=False |
| 129 | + ), |
| 130 | + Quantity( |
| 131 | + 'conv_tol', |
| 132 | + r'\|\s*Convergence tolerence\s*\:\s*([\d.eE-]+)', |
| 133 | + repeats=False, |
| 134 | + ), |
| 135 | + Quantity( |
| 136 | + 'energy_windows', |
| 137 | + r'(\|\s*Energy\s*Windows\s*\|[\s\S]+?)(?:Number of target bands to extract:)', |
| 138 | + repeats=False, |
| 139 | + sub_parser=TextParser(quantities=disentangle_quantities), |
| 140 | + ), |
| 141 | + # Band related quantities |
| 142 | + Quantity( |
| 143 | + 'n_k_segments', |
| 144 | + r'\|\s*Number of K-path sections\s*\:\s*(\d+)', |
| 145 | + repeats=False, |
| 146 | + ), |
| 147 | + Quantity( |
| 148 | + 'div_first_k_segment', |
| 149 | + r'\|\s*Divisions along first K-path section\s*\:\s*(\d+)', |
| 150 | + repeats=False, |
| 151 | + ), |
| 152 | + Quantity( |
| 153 | + 'band_segments_points', |
| 154 | + r'\|\s*From\:\s*\w+([\d\s\-\.]+)To\:\s*\w+([\d\s\-\.]+)', |
| 155 | + repeats=True, |
| 156 | + ), |
| 157 | + ] |
| 158 | + |
0 commit comments