Skip to content

Commit

Permalink
add precommit config and fix problem (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinzyb authored Dec 29, 2023
1 parent 39b268f commit 2968cdf
Show file tree
Hide file tree
Showing 26 changed files with 269 additions and 259 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
pip install .
pip install sphinx
pip install jupyter-book
- name: Sphinx APIDoc
run: |
sphinx-apidoc -f -o jupyter-book/_api/ cp2kdata/ --separate
Expand Down
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
exclude: "^tests/.*$"
# - id: end-of-file-fixer
- id: check-yaml
# - id: check-added-large-files
2 changes: 1 addition & 1 deletion cp2kdata/block_parser/atomic_kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def parse_atomic_kinds(output_file):
for match in ATOMIC_KINDS_RE.finditer(output_file):
atomic_kinds.append(match["atomic_kind"])
if atomic_kinds:
# only return the last atomic kinds
# only return the last atomic kinds
return np.array(atomic_kinds[-num_atomic_kinds_list[-1]:], dtype=str)
else:
return None
20 changes: 10 additions & 10 deletions cp2kdata/block_parser/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
ALL_CELL_RE = re.compile(
r"""
\s+CELL\|\sVector\sa\s\[angstrom\]:
\s+(?P<xx>[\s-]\d+\.\d+)
\s+(?P<xy>[\s-]\d+\.\d+)
\s+(?P<xx>[\s-]\d+\.\d+)
\s+(?P<xy>[\s-]\d+\.\d+)
\s+(?P<xz>[\s-]\d+\.\d+)
\s+\|a\|\s+=\s+\S+
\n
\s+CELL\|\sVector\sb\s\[angstrom\]:
\s+(?P<yx>[\s-]\d+\.\d+)
\s+(?P<yy>[\s-]\d+\.\d+)
\s+(?P<yx>[\s-]\d+\.\d+)
\s+(?P<yy>[\s-]\d+\.\d+)
\s+(?P<yz>[\s-]\d+\.\d+)
\s+\|b\|\s+=\s+\S+
\n
\s+CELL\|\sVector\sc\s\[angstrom\]:
\s+(?P<zx>[\s-]\d+\.\d+)
\s+(?P<zy>[\s-]\d+\.\d+)
\s+(?P<zx>[\s-]\d+\.\d+)
\s+(?P<zy>[\s-]\d+\.\d+)
\s+(?P<zz>[\s-]\d+\.\d+)
\s+\|c\|\s+=\s+\S+
\n
Expand All @@ -45,7 +45,7 @@ def parse_all_cells(output_file):
return np.array(all_cells, dtype=float)
else:
return None

ALL_MD_CELL_RE_V7 = re.compile(
r"""
\sCELL\sLNTHS\[bohr\]\s{13}=\s
Expand Down Expand Up @@ -75,22 +75,22 @@ def parse_all_cells(output_file):
#skip three lines
(.{80}\n){3}
#parse angles
(\sMD\|\sCell\sangles\s\[deg\]\s{10}
(\sMD\|\sCell\sangles\s\[deg\]\s{10}
\s{2}(?P<alpha>\d\.\d{8}E(\+|\-)\d{2})
\s{2}(?P<beta>\d\.\d{8}E(\+|\-)\d{2})
\s{2}(?P<gamma>\d\.\d{8}E(\+|\-)\d{2}))?
""",
re.VERBOSE
)

def parse_all_md_cells(output_file: List[str],
def parse_all_md_cells(output_file: List[str],
cp2k_info: Cp2kInfo,
init_cell_info=None):
# init_cell_info are used for npt_I parse.
# because npt_I doesn't include angle info in MD| block

# notice that the cell of step 0 is excluded from MD| block

# choose parser according to cp2k_info.version
if cp2k_info.version in ['2023.1']:
ALL_MD_CELL_RE = ALL_MD_CELL_RE_V2023
Expand Down
4 changes: 2 additions & 2 deletions cp2kdata/block_parser/converge.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def parse_e_f_converge(filename) -> ConvergeInfo:
info_dict = regrep(
filename=filename,
reverse=True,
patterns={"converge": CONVERGE_PATTERN},
patterns={"converge": CONVERGE_PATTERN},
terminate_on_match=True
)

Expand All @@ -32,7 +32,7 @@ def parse_md_converge(filename):
info_dict = regrep(
filename=filename,
reverse=True,
patterns={"converge": CONVERGE_PATTERN},
patterns={"converge": CONVERGE_PATTERN},
terminate_on_match=False
)
#print(info_dict['converge'])
Expand Down
14 changes: 7 additions & 7 deletions cp2kdata/block_parser/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def parse_dipole_list(output_file):

"""
Reference Point [Bohr] 0.00000000 0.00000000 0.00000000
Charges
Charges
Electronic= 864.00000000 Core= -864.00000000 Total= 0.00000000
Dipole vectors are based on the periodic (Berry phase) operator.
They are defined modulo integer multiples of the cell matrix [Debye].
[X] [ 46.55265580 0.00000000 0.00000000 ] [i]
[Y]=[ 0.00000000 54.46353324 0.00000000 ]*[j]
[Z] [ 0.00000000 0.00000000 54.47313965 ] [k]
Dipole moment [Debye]
Dipole vectors are based on the periodic (Berry phase) operator.
They are defined modulo integer multiples of the cell matrix [Debye].
[X] [ 46.55265580 0.00000000 0.00000000 ] [i]
[Y]=[ 0.00000000 54.46353324 0.00000000 ]*[j]
[Z] [ 0.00000000 0.00000000 54.47313965 ] [k]
Dipole moment [Debye]
X= -0.07183634 Y= -0.07690441 Z= 1.13302571 Total= 1.13790246
"""
2 changes: 1 addition & 1 deletion cp2kdata/block_parser/errors_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def parse_errors(output_file):
errors_info = {}

for match in EXCEED_WALL_TIME_RE.finditer(output_file):
#print(match)
if match:
Expand Down
22 changes: 11 additions & 11 deletions cp2kdata/block_parser/header_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Cp2kInfo:
def parse_cp2k_info(filename) -> Cp2kInfo:

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

Expand All @@ -42,10 +42,10 @@ class GlobalInfo:

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

global_info = regrep(
filename=filename,
patterns={"run_type": GLOBAL_INFO_RUN_TYPE_PATTERN,
filename=filename,
patterns={"run_type": GLOBAL_INFO_RUN_TYPE_PATTERN,
"print_level": GLOBAL_INFO_PRINT_LEVEL_PATTERN
},
terminate_on_match=True
Expand Down Expand Up @@ -78,16 +78,16 @@ class DFTInfo:

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

dft_info = regrep(
filename=filename,
filename=filename,
patterns={
"ks_type": DFT_INFO_KS_TYPE_PATTERN,
"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:
Expand All @@ -108,12 +108,12 @@ class MDInfo:

def parse_md_info(filename):
md_info = {}

md_info = regrep(
filename=filename,
filename=filename,
patterns={
"ensemble_type": MD_INFO_ENSEMBLE_TYPE_PATTERN
},
},
terminate_on_match=True
)

Expand Down
10 changes: 5 additions & 5 deletions cp2kdata/block_parser/md_xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ def parse_pos_xyz_from_wannier(wannier_xyz_fiel):
def parse_md_stress(stress_file):
print(f"Parsing Stresses from {stress_file}")
stresses_list = np.loadtxt(
stress_file,
usecols=(2, 3, 4, 5, 6, 7, 8, 9, 10),
stress_file,
usecols=(2, 3, 4, 5, 6, 7, 8, 9, 10),
ndmin=2,
dtype=np.float64
)

numb_frames = stresses_list.shape[0]

return stresses_list.reshape(numb_frames, 3, 3)

def parse_md_cell(cell_file):
print(f"Parsing Cells from {cell_file}")
cells_list = np.loadtxt(
cell_file,
usecols=(2, 3, 4, 5, 6, 7, 8, 9, 10),
cell_file,
usecols=(2, 3, 4, 5, 6, 7, 8, 9, 10),
ndmin=2,
dtype=np.float64
)
Expand Down
4 changes: 2 additions & 2 deletions cp2kdata/block_parser/mulliken.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
\s+(?P<kind>\d+)
\s+(?P<alpha>[\s-]\d+\.\d+)
\s+(?P<net_charge>[\s-]\d+\.\d+)
)+
""",
re.VERBOSE
Expand Down Expand Up @@ -67,7 +67,7 @@ def parse_mulliken_pop_list(output_file, DFTInfo):
"net_charge": float(net_charge),
}
)
mulliken_pop_list.append(mulliken_pop)
mulliken_pop_list.append(mulliken_pop)

if mulliken_pop_list:
return mulliken_pop_list
Expand Down
16 changes: 8 additions & 8 deletions cp2kdata/block_parser/stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
(\sSTRESS\sTENSOR\s\[GPa\]
\n
\s+X\s+Y\s+Z\s*\n
\s+X
\s+(?P<xx>[\s-]\d+\.\d+)
\s+(?P<xy>[\s-]\d+\.\d+)
\s+X
\s+(?P<xx>[\s-]\d+\.\d+)
\s+(?P<xy>[\s-]\d+\.\d+)
\s+(?P<xz>[\s-]\d+\.\d+)\n
\s+Y
\s+(?P<yx>[\s-]\d+\.\d+)
\s+(?P<yy>[\s-]\d+\.\d+)
\s+(?P<yx>[\s-]\d+\.\d+)
\s+(?P<yy>[\s-]\d+\.\d+)
\s+(?P<yz>[\s-]\d+\.\d+)\n
\s+Z
\s+(?P<zx>[\s-]\d+\.\d+)
\s+(?P<zy>[\s-]\d+\.\d+)
\s+Z
\s+(?P<zx>[\s-]\d+\.\d+)
\s+(?P<zy>[\s-]\d+\.\d+)
\s+(?P<zz>[\s-]\d+\.\d+)\n
|# or another pattern used in v8.1
\s+STRESS\|\sAnalytical\sstress\stensor\s\[GPa\]\s*\n
Expand Down
31 changes: 15 additions & 16 deletions cp2kdata/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

class Cp2kCell:
def __init__(
self,
cell_param: npt.NDArray[np.float64],
grid_point: npt.NDArray[np.int_] = None,
self,
cell_param: npt.NDArray[np.float64],
grid_point: npt.NDArray[np.int_] = None,
grid_spacing_matrix: npt.NDArray[np.float64] = None
):
"""
Expand All @@ -32,21 +32,21 @@ def __init__(
if isinstance(cell_param, float):
self.cell_matrix = np.array(
[
[cell_param, 0, 0],
[0, cell_param, 0],
[cell_param, 0, 0],
[0, cell_param, 0],
[0, 0, cell_param]
]
)
print("input cell_param is a float, the cell is assumed to be cubic")
elif cell_param.shape == (3,):
self.cell_matrix = np.array(
[
[cell_param[0], 0, 0],
[0, cell_param[1], 0],
[cell_param[0], 0, 0],
[0, cell_param[1], 0],
[0, 0, cell_param[2]]
]
)
print("the length of input cell_param is 3, "
print("the length of input cell_param is 3, "
"the cell is assumed to be orthorhombic")
elif cell_param.shape == (6,):
self.cell_matrix = cellpar_to_cell(cell_param)
Expand All @@ -55,12 +55,12 @@ def __init__(
"which will be converted to cell matrix")
elif cell_param.shape == (3, 3):
self.cell_matrix = cell_param
print("input cell_param is a matrix with shape of (3,3), "
print("input cell_param is a matrix with shape of (3,3), "
"the cell is read as is")
else:
raise ValueError("The input cell_param is not supported")


if (grid_point is None) and (grid_spacing_matrix is None):
self.grid_point = None
self.grid_spacing_matrix = None
Expand All @@ -74,7 +74,7 @@ def __init__(
elif (grid_point is not None) and (grid_spacing_matrix is not None):
self.grid_point = np.array(grid_point)
self.grid_spacing_matrix = np.array(grid_spacing_matrix)

if grid_point is not None:
self.grid_point = self.grid_point.astype(int)

Expand All @@ -83,7 +83,7 @@ def __init__(

def copy(self):
return deepcopy(self)

def get_volume(self):
return np.linalg.det(self.cell_matrix)

Expand All @@ -92,14 +92,13 @@ def get_dv(self):
return np.linalg.det(self.grid_spacing_matrix)
except LinAlgError as ae:
print("No grid point information is available")

def get_cell_param(self):
return self.cell_param

def get_cell_angles(self):
return self.cell_param[3:]

def get_cell_lengths(self):
return self.cell_param[:3]


Loading

0 comments on commit 2968cdf

Please sign in to comment.