Skip to content

Commit

Permalink
Merge e8cd20d into 5bba75a
Browse files Browse the repository at this point in the history
  • Loading branch information
robinzyb authored Jan 11, 2024
2 parents 5bba75a + e8cd20d commit c8239b8
Show file tree
Hide file tree
Showing 28 changed files with 761 additions and 584 deletions.
4 changes: 3 additions & 1 deletion cp2kdata/block_parser/atomic_kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
re.VERBOSE
)


def parse_num_atomic_kinds(output_file):
num_atomic_kinds_list = []

for match in NUM_ATOMIC_KINDS_RE.finditer(output_file):
num_atomic_kinds_list.append(int(match["num_atomic_kind"]))
return num_atomic_kinds_list


def parse_atomic_kinds(output_file):
num_atomic_kinds_list = parse_num_atomic_kinds(output_file)
atomic_kinds = []
Expand All @@ -31,4 +33,4 @@ def parse_atomic_kinds(output_file):
# only return the last atomic kinds
return np.array(atomic_kinds[-num_atomic_kinds_list[-1]:], dtype=str)
else:
return None
return None
16 changes: 9 additions & 7 deletions cp2kdata/block_parser/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
re.VERBOSE
)


def parse_all_cells(output_file):
all_cells = []
for match in ALL_CELL_RE.finditer(output_file):
#print(match)
# print(match)
cell = [
[match["xx"], match["xy"], match["xz"]],
[match["yx"], match["yy"], match["yz"]],
Expand All @@ -46,6 +47,7 @@ def parse_all_cells(output_file):
else:
return None


ALL_MD_CELL_RE_V7 = re.compile(
r"""
\sCELL\sLNTHS\[bohr\]\s{13}=\s
Expand Down Expand Up @@ -83,6 +85,7 @@ def parse_all_cells(output_file):
re.VERBOSE
)


def parse_all_md_cells(output_file: List[str],
cp2k_info: Cp2kInfo,
init_cell_info=None):
Expand All @@ -105,9 +108,9 @@ def parse_all_md_cells(output_file: List[str],
if init_cell_info is None:
# for NPT_F parser, cell info is complete in MD| block
for match in ALL_MD_CELL_RE.finditer(output_file):
#print(match)
# print(match)
cell = [match["a"], match["b"], match["c"],
match["alpha"], match["beta"], match["gamma"]]
match["alpha"], match["beta"], match["gamma"]]
cell = np.array(cell, dtype=float)
# convert bohr to angstrom
cell[:3] = cell[:3] * au2A
Expand All @@ -119,16 +122,15 @@ def parse_all_md_cells(output_file: List[str],
init_cell_param = cell_to_cellpar(init_cell_info)
init_cell_angles = init_cell_param[3:]
for match in ALL_MD_CELL_RE.finditer(output_file):
#print(match)
# print(match)
cell = [match["a"], match["b"], match["c"],
match["alpha"], match["beta"], match["gamma"]]
match["alpha"], match["beta"], match["gamma"]]
cell = np.array(cell, dtype=float)
cell[3:] = init_cell_angles
cell = cellpar_to_cell(cell)
all_md_cells.append(cell)


if all_md_cells:
return np.array(all_md_cells, dtype=float)
else:
return None
return None
9 changes: 6 additions & 3 deletions cp2kdata/block_parser/converge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,38 @@
class ConvergeInfo:
converge: bool = False


CONVERGE_PATTERN = \
r"""(?xm)
^\s{1,2}\*\*\*\sSCF\srun\sconverged\sin
"""


def parse_e_f_converge(filename) -> ConvergeInfo:

info_dict = regrep(
filename=filename,
reverse=True,
patterns={"converge": CONVERGE_PATTERN},
terminate_on_match=True
)
)

if info_dict['converge']:
converge_info = ConvergeInfo(converge=True)
else:
converge_info = ConvergeInfo(converge=False)
return converge_info


def parse_md_converge(filename):

info_dict = regrep(
filename=filename,
reverse=True,
patterns={"converge": CONVERGE_PATTERN},
terminate_on_match=False
)
#print(info_dict['converge'])
)
# print(info_dict['converge'])

# if __name__ == "__main__":
# file_name = "e_f"
Expand Down
4 changes: 2 additions & 2 deletions cp2kdata/block_parser/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
def parse_init_atomic_coordinates(output_file):

match = INIT_ATOMIC_COORDINATES_RE.search(output_file)
# only get the first match
# only get the first match
init_atomic_coordinates = []
chemical_symbols = []
for x, y, z in zip(*match.captures("x", "y", "z")):
Expand All @@ -38,4 +38,4 @@ def parse_init_atomic_coordinates(output_file):
if init_atomic_coordinates:
return np.array(init_atomic_coordinates, dtype=float), np.array(atom_kind_list, dtype=int), chemical_symbols
else:
return None
return None
6 changes: 4 additions & 2 deletions cp2kdata/block_parser/dft_plus_u.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# \s+(?P<spin_moment>[\s-]\d+\.\d+)
# \n
# )+


def parse_dft_plus_u_occ(output_file):
dft_plus_u_occ = []
for match in PLUS_U_RE.finditer(output_file):
Expand All @@ -40,7 +42,7 @@ def parse_dft_plus_u_occ(output_file):
# "spin_moment": float(spin_moment)
# }
# )
if dft_plus_u_occ:
if dft_plus_u_occ:
return dft_plus_u_occ
else:
return None
return None
6 changes: 4 additions & 2 deletions cp2kdata/block_parser/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
re.VERBOSE
)

#TODO write a pytest for this
# TODO write a pytest for this


def parse_dipole_list(output_file):
dipole_list = []
Expand All @@ -26,6 +27,7 @@ def parse_dipole_list(output_file):
else:
return None


"""
Reference Point [Bohr] 0.00000000 0.00000000 0.00000000
Charges
Expand All @@ -37,4 +39,4 @@ def parse_dipole_list(output_file):
[Z] [ 0.00000000 0.00000000 54.47313965 ] [k]
Dipole moment [Debye]
X= -0.07183634 Y= -0.07690441 Z= 1.13302571 Total= 1.13790246
"""
"""
3 changes: 1 addition & 2 deletions cp2kdata/block_parser/energies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
re.VERBOSE
)


def parse_energies_list(output_file):

energies_list = []
Expand All @@ -17,5 +18,3 @@ def parse_energies_list(output_file):
return np.array(energies_list, dtype=float)
else:
return None


3 changes: 1 addition & 2 deletions cp2kdata/block_parser/errors_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
)



def parse_errors(output_file):
errors_info = {}

for match in EXCEED_WALL_TIME_RE.finditer(output_file):
#print(match)
# print(match)
if match:
errors_info = {
"exceed_wall_time": True
Expand Down
2 changes: 2 additions & 0 deletions cp2kdata/block_parser/fep.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import numpy as np


def parse_vertical_gap(mix_ener_file, r_col=3, p_col=4):
r_ener = np.loadtxt(mix_ener_file, usecols=r_col)
p_ener = np.loadtxt(mix_ener_file, usecols=p_col)
Expand Down
3 changes: 2 additions & 1 deletion cp2kdata/block_parser/forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
re.VERBOSE
)


def parse_atomic_forces_list(output_file):
atomic_forces_list = []
for match in ATOMIC_FORCES_RE.finditer(output_file):
Expand All @@ -29,4 +30,4 @@ def parse_atomic_forces_list(output_file):
if atomic_forces_list:
return np.array(atomic_forces_list, dtype=float)
else:
return None
return None
19 changes: 12 additions & 7 deletions cp2kdata/block_parser/header_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
class Cp2kInfo:
version: str = None


CP2K_INFO_VERSION_PATTERN = \
r"""(?xm)
^\sCP2K\|\sversion\sstring:\s{10,42}
CP2K\sversion\s(?P<version>\d{1,4}\.\d)(?:\s\(Development\sVersion\))?$
"""


def parse_cp2k_info(filename) -> Cp2kInfo:

cp2k_info = regrep(
filename=filename,
patterns={"version": CP2K_INFO_VERSION_PATTERN},
terminate_on_match=True
)
)

return Cp2kInfo(version=cp2k_info["version"][0][0][0])

Expand All @@ -30,6 +32,7 @@ class GlobalInfo:
run_type: str = None
print_level: str = None


# PATTERNS
GLOBAL_INFO_RUN_TYPE_PATTERN = \
r"""(?xm)
Expand All @@ -40,6 +43,7 @@ class GlobalInfo:
^\sGLOBAL\|\sGlobal\sprint\slevel\s{42,}(?P<print_level>\w+)\n
"""


def parse_global_info(filename) -> GlobalInfo:
global_info = {}

Expand All @@ -49,7 +53,7 @@ def parse_global_info(filename) -> GlobalInfo:
"print_level": GLOBAL_INFO_PRINT_LEVEL_PATTERN
},
terminate_on_match=True
)
)

return GlobalInfo(run_type=global_info["run_type"][0][0][0],
print_level=global_info["print_level"][0][0][0]
Expand All @@ -76,6 +80,7 @@ class DFTInfo:
^\sDFT\|\sMultiplicity\s{57,}(\d{1,4})$
"""


def parse_dft_info(filename) -> DFTInfo:
dft_info = {}

Expand All @@ -86,26 +91,26 @@ def parse_dft_info(filename) -> DFTInfo:
"multiplicity": DFT_INFO_MULTIPLICITY_PATTERN
},
terminate_on_match=True
)
)

if dft_info:
return DFTInfo(ks_type=dft_info["ks_type"][0][0][0], multiplicity=dft_info["multiplicity"][0][0][0])
else:
return None




@dataclass
class MDInfo:
ensemble_type: str = None


# PATTERNS
MD_INFO_ENSEMBLE_TYPE_PATTERN = \
r"""(?xm)
^\s(?:MD_PAR|MD)\|\sEnsemble\s(?:t|T)ype\s{39,60}(?P<ensemble_type>\w{3,16})
"""


def parse_md_info(filename):
md_info = {}

Expand All @@ -115,6 +120,6 @@ def parse_md_info(filename):
"ensemble_type": MD_INFO_ENSEMBLE_TYPE_PATTERN
},
terminate_on_match=True
)
)

return MDInfo(ensemble_type=md_info["ensemble_type"][0][0][0])
return MDInfo(ensemble_type=md_info["ensemble_type"][0][0][0])
5 changes: 3 additions & 2 deletions cp2kdata/block_parser/hirshfeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
re.VERBOSE
)


def parse_hirshfeld_pop_list(output_file):
hirshfeld_pop_list = []
for match in HIRSHFELD_RE.finditer(output_file):
Expand All @@ -36,7 +37,7 @@ def parse_hirshfeld_pop_list(output_file):
}
)
hirshfeld_pop_list.append(hirshfeld_pop)
if hirshfeld_pop_list:
return hirshfeld_pop_list[:-1]
if hirshfeld_pop_list:
return hirshfeld_pop_list[:-1]
else:
return None
Loading

0 comments on commit c8239b8

Please sign in to comment.