Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyright fixes for ext/io/phonon/symmetry/transformations/util/vis/dev_scripts and improve io.lobster #3757

Merged
merged 72 commits into from
Apr 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
418f3e2
Add a CI run that only tests non-optional deps (optimistically)
ml-evs Feb 22, 2024
b0b16a6
Install dev deps at least
ml-evs Feb 22, 2024
a9cf9cd
Try out pyright config for unbound vars only
ml-evs Feb 22, 2024
93e9afe
Add pyright to CI
ml-evs Feb 22, 2024
fc09e78
Merge branch 'master' into ml-evs/ci-with-mandatory-deps
ml-evs Mar 29, 2024
f63b806
pyright fix
DanielYang59 Apr 13, 2024
20d318e
pyright fix in vis.structure_vtk
DanielYang59 Apr 13, 2024
974a8b9
fix `utils`
DanielYang59 Apr 13, 2024
081db43
fix `transformations`
DanielYang59 Apr 13, 2024
28b9380
Merge branch 'master' into pyright
DanielYang59 Apr 13, 2024
fa0e173
Merge branch 'master' into pyright
DanielYang59 Apr 13, 2024
d388c23
fix `symmetry.kpath`
DanielYang59 Apr 13, 2024
895f2c1
finish fixing `symmetry`
DanielYang59 Apr 13, 2024
2d7f701
update `pyright`
DanielYang59 Apr 13, 2024
a6a5714
suppress `pyright` reportMissingModuleSource warning
DanielYang59 Apr 13, 2024
2063f09
fix `phonon`
DanielYang59 Apr 13, 2024
4ac354f
some fixes in `io`
DanielYang59 Apr 13, 2024
a9c8c78
Merge branch 'master' into pyright
DanielYang59 Apr 13, 2024
e3d2d54
format tweaks of `io.vasp.outputs`
DanielYang59 Apr 13, 2024
afac73e
fix unit test for `symmetry.kpath`
DanielYang59 Apr 13, 2024
147cb85
fix io.vasp
DanielYang59 Apr 13, 2024
962e4ee
fix unit test for io.vasp.inputs
DanielYang59 Apr 13, 2024
2f4c6fc
fix io.qchem
DanielYang59 Apr 13, 2024
87a588b
fix io.pwscf, need input
DanielYang59 Apr 13, 2024
c3f290b
replace `match.group(i)` with `match[i]`
DanielYang59 Apr 13, 2024
8ee0655
fix missing )
DanielYang59 Apr 13, 2024
45b59b9
fix typo
DanielYang59 Apr 13, 2024
eddf08f
suppress `reportInvalidTypeForm`
DanielYang59 Apr 13, 2024
d9cfcff
fix io.nwchem and packmol
DanielYang59 Apr 13, 2024
ac96441
fix io.lobster.inputs and use snake_case
DanielYang59 Apr 13, 2024
5b031a5
fix lobsterenv
DanielYang59 Apr 13, 2024
92d8a91
fix io.icet
DanielYang59 Apr 13, 2024
0acf807
fix io.lammps
DanielYang59 Apr 13, 2024
69ea14e
revert to try/except for speed
DanielYang59 Apr 14, 2024
da84ebc
set default coords_are_cartesian for pwscf
DanielYang59 Apr 14, 2024
4d6426b
fix io.gaussian
DanielYang59 Apr 14, 2024
6778493
fix io.fiesta
DanielYang59 Apr 14, 2024
4a0a125
fix io.cif
DanielYang59 Apr 14, 2024
626ba66
fix io.babel
DanielYang59 Apr 14, 2024
a44a97d
fix io.ase
DanielYang59 Apr 14, 2024
641e9aa
fix io.cif tests
DanielYang59 Apr 14, 2024
5fed53a
fix io.feff
DanielYang59 Apr 14, 2024
5732564
fix io.exciting
DanielYang59 Apr 14, 2024
6066330
fix io.abinit
DanielYang59 Apr 14, 2024
17b8e4a
fix io.cp2k
DanielYang59 Apr 14, 2024
3b41635
fix io.lobster.outputs
DanielYang59 Apr 14, 2024
46987fd
take some (not all) code rabbit suggestion
DanielYang59 Apr 14, 2024
7335314
fix ext
DanielYang59 Apr 14, 2024
6580fb5
fix dev_scripts
DanielYang59 Apr 14, 2024
58050bb
fix logic error
DanielYang59 Apr 14, 2024
aab8e22
simplify checking
DanielYang59 Apr 14, 2024
6f9d344
remove some weird constructions in lobster io
JaGeo Apr 14, 2024
247a08c
pre-commit auto-fixes
pre-commit-ci[bot] Apr 14, 2024
b8d03f1
resolve code rabbit suggestions
JaGeo Apr 14, 2024
befe350
Merge branch 'pyright' of github.com:DanielYang59/pymatgen into pyright
DanielYang59 Apr 14, 2024
136a0e4
fix more new key issues
JaGeo Apr 14, 2024
9ec8141
fix new_key problems with code simplification
JaGeo Apr 14, 2024
b3a3180
make same logic for del
JaGeo Apr 14, 2024
0ba73d8
remove unnecessary `int` before `math.floor/ceil`
DanielYang59 Apr 14, 2024
f9db258
Fix lower vs other
JaGeo Apr 14, 2024
1b0d6fe
Merge branch 'pyright' of github.com:DanielYang59/pymatgen into pyright
JaGeo Apr 14, 2024
72981f1
tweak error type in io.lobster
DanielYang59 Apr 15, 2024
aee9bc4
fix error type in lobster test
DanielYang59 Apr 15, 2024
d1aec0f
fix nested if
DanielYang59 Apr 15, 2024
abaebb5
pre-commit auto-fixes
pre-commit-ci[bot] Apr 15, 2024
801a98f
remove DEBUG tag
DanielYang59 Apr 15, 2024
4b1c8d0
comment out pyright until all chunks finished
DanielYang59 Apr 15, 2024
6cc78ce
replace runtime error with value error
DanielYang59 Apr 15, 2024
afc4f6d
use walrus op for if match := re.match(...)
janosh Apr 15, 2024
80aa33f
remove unused pyright code until ready to enable
janosh Apr 15, 2024
1dffaff
rename single-letter m->match
janosh Apr 15, 2024
2ce0368
remove unused raw
DanielYang59 Apr 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix io.lobster.outputs
  • Loading branch information
DanielYang59 committed Apr 14, 2024
commit 3b4163504ec11fec1c6afb25c10be946e87d1688
114 changes: 56 additions & 58 deletions pymatgen/io/lobster/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import collections
import fnmatch
import itertools
import os
import re
import warnings
Expand Down Expand Up @@ -124,7 +125,6 @@ def __init__(
if not self.are_multi_center_cobis:
# The COHP data start in row num_bonds + 3
data = np.array([np.array(row.split(), dtype=float) for row in contents[num_bonds + 3 :]]).transpose()
self.energies = data[0]
cohp_data = {
"average": {
"COHP": {spin: data[1 + 2 * s * (num_bonds + 1)] for s, spin in enumerate(spins)},
Expand All @@ -134,7 +134,8 @@ def __init__(
else:
# The COBI data start in row num_bonds + 3 if multi-center cobis exist
data = np.array([np.array(row.split(), dtype=float) for row in contents[num_bonds + 3 :]]).transpose()
self.energies = data[0]

self.energies = data[0]

orb_cohp: dict[str, Any] = {}
# present for Lobster versions older than Lobster 2.2.0
Expand Down Expand Up @@ -964,11 +965,11 @@ def __init__(self, filename: str | None, **kwargs) -> None:
self.basis_functions = basisfunctions

wall_time, user_time, sys_time = self._get_timing(data=data)
timing = {}
timing["wall_time"] = wall_time
timing["user_time"] = user_time
timing["sys_time"] = sys_time
self.timing = timing
self.timing = {
"wall_time": wall_time,
"user_time": user_time,
"sys_time": sys_time,
}

warninglines = self._get_all_warning_lines(data=data)
self.warning_lines = warninglines
Expand Down Expand Up @@ -1084,15 +1085,13 @@ def _get_dft_program(data):

@staticmethod
def _get_number_of_spins(data):
if "spillings for spin channel 2" in data:
return 2
return 1
return 2 if "spillings for spin channel 2" in data else 1

@staticmethod
def _get_threads(data):
for row in data:
splitrow = row.split()
if len(splitrow) > 11 and ((splitrow[11]) == "threads" or (splitrow[11] == "thread")):
if len(splitrow) > 11 and splitrow[11] in {"threads", "thread"}:
return splitrow[10]
raise ValueError("Threads not found.")

Expand Down Expand Up @@ -1157,9 +1156,9 @@ def _get_timing(data):
if "wall" in splitrow:
wall_time = splitrow[2:10]
if "user" in splitrow:
user_time = splitrow[0:8]
user_time = splitrow[:8]
if "sys" in splitrow:
sys_time = splitrow[0:8]
sys_time = splitrow[:8]

wall_time_dict = {"h": wall_time[0], "min": wall_time[2], "s": wall_time[4], "ms": wall_time[6]}
user_time_dict = {"h": user_time[0], "min": user_time[2], "s": user_time[4], "ms": user_time[6]}
Expand Down Expand Up @@ -1267,6 +1266,7 @@ def __init__(
atom_type = []
atom_names = []
orbital_names = []
parameters = []

if not isinstance(filenames, list) or filenames is None:
filenames_new = []
Expand Down Expand Up @@ -1308,7 +1308,9 @@ def __init__(
"present"
)

kpoints_array = []
kpoints_array: list = []
eigenvals: dict = {}
p_eigenvals: dict = {}
for ifilename, filename in enumerate(filenames):
with zopen(filename, mode="rt") as file:
contents = file.read().split("\n")
Expand All @@ -1331,7 +1333,7 @@ def __init__(
self.is_spinpolarized = len(linenumbers) == 2

if ifilename == 0:
eigenvals = {} # type: dict
eigenvals = {}
eigenvals[Spin.up] = [
[collections.defaultdict(float) for _ in range(self.number_kpts)] for _ in range(self.nbands)
]
Expand All @@ -1340,7 +1342,7 @@ def __init__(
[collections.defaultdict(float) for _ in range(self.number_kpts)] for _ in range(self.nbands)
]

p_eigenvals = {} # type: dict
p_eigenvals = {}
p_eigenvals[Spin.up] = [
[
{
Expand All @@ -1366,6 +1368,7 @@ def __init__(

idx_kpt = -1
linenumber = 0
iband = 0
for line in contents[1:-1]:
if line.split()[0] == "#":
KPOINT = np.array(
Expand Down Expand Up @@ -1486,7 +1489,7 @@ def _read(self, contents: list, spin_numbers: list):
kpoint = line.split(" ")
kpoint_array = []
for kpointel in kpoint:
if kpointel not in ["at", "k-point", ""]:
if kpointel not in {"at", "k-point", ""}:
kpoint_array += [float(kpointel)]

elif "maxDeviation" in line:
Expand Down Expand Up @@ -1559,15 +1562,16 @@ def has_good_quality_check_occupied_bands(
for matrix in self.band_overlaps_dict[Spin.down]["matrices"]:
for iband1, band1 in enumerate(matrix):
for iband2, band2 in enumerate(band1):
if number_occ_bands_spin_down is not None:
if iband1 < number_occ_bands_spin_down and iband2 < number_occ_bands_spin_down:
if iband1 == iband2:
if abs(band2 - 1.0).all() > limit_deviation:
return False
elif band2.all() > limit_deviation:
return False
else:
if number_occ_bands_spin_down is None:
raise ValueError("number_occ_bands_spin_down has to be specified")

if iband1 < number_occ_bands_spin_down and iband2 < number_occ_bands_spin_down:
if iband1 == iband2:
if abs(band2 - 1.0).all() > limit_deviation:
return False
elif band2.all() > limit_deviation:
return False

return True

@property
Expand Down Expand Up @@ -1686,10 +1690,9 @@ def _parse_file(filename):
real += [float(splitline[4])]
imaginary += [float(splitline[5])]

if not len(real) == grid[0] * grid[1] * grid[2]:
raise ValueError("Something went wrong while reading the file")
if not len(imaginary) == grid[0] * grid[1] * grid[2]:
if len(real) != grid[0] * grid[1] * grid[2] or len(imaginary) != grid[0] * grid[1] * grid[2]:
raise ValueError("Something went wrong while reading the file")

return grid, points, real, imaginary, distance

def set_volumetric_data(self, grid, structure):
Expand All @@ -1713,36 +1716,31 @@ def set_volumetric_data(self, grid, structure):
new_imaginary = []
new_density = []

runner = 0
for x in range(Nx + 1):
for y in range(Ny + 1):
for z in range(Nz + 1):
x_here = x / float(Nx) * a[0] + y / float(Ny) * b[0] + z / float(Nz) * c[0]
y_here = x / float(Nx) * a[1] + y / float(Ny) * b[1] + z / float(Nz) * c[1]
z_here = x / float(Nx) * a[2] + y / float(Ny) * b[2] + z / float(Nz) * c[2]

if x != Nx and y != Ny and z != Nz:
if (
not np.isclose(self.points[runner][0], x_here, 1e-3)
and not np.isclose(self.points[runner][1], y_here, 1e-3)
and not np.isclose(self.points[runner][2], z_here, 1e-3)
):
raise ValueError(
"The provided wavefunction from Lobster does not contain all relevant"
" points. "
"Please use a line similar to: printLCAORealSpaceWavefunction kpoint 1 "
"coordinates 0.0 0.0 0.0 coordinates 1.0 1.0 1.0 box bandlist 1 "
)

new_x += [x_here]
new_y += [y_here]
new_z += [z_here]

new_real += [self.real[runner]]
new_imaginary += [self.imaginary[runner]]
new_density += [self.real[runner] ** 2 + self.imaginary[runner] ** 2]

runner += 1
for runner, (x, y, z) in enumerate(itertools.product(range(Nx + 1), range(Ny + 1), range(Nz + 1))):
x_here = x / float(Nx) * a[0] + y / float(Ny) * b[0] + z / float(Nz) * c[0]
y_here = x / float(Nx) * a[1] + y / float(Ny) * b[1] + z / float(Nz) * c[1]
z_here = x / float(Nx) * a[2] + y / float(Ny) * b[2] + z / float(Nz) * c[2]

if x != Nx and y != Ny and z != Nz:
if (
not np.isclose(self.points[runner][0], x_here, 1e-3)
and not np.isclose(self.points[runner][1], y_here, 1e-3)
and not np.isclose(self.points[runner][2], z_here, 1e-3)
):
raise ValueError(
"The provided wavefunction from Lobster does not contain all relevant"
" points. "
"Please use a line similar to: printLCAORealSpaceWavefunction kpoint 1 "
"coordinates 0.0 0.0 0.0 coordinates 1.0 1.0 1.0 box bandlist 1 "
)

new_x += [x_here]
new_y += [y_here]
new_z += [z_here]

new_real += [self.real[runner]]
new_imaginary += [self.imaginary[runner]]
new_density += [self.real[runner] ** 2 + self.imaginary[runner] ** 2]

self.final_real = np.reshape(new_real, [Nx, Ny, Nz])
self.final_imaginary = np.reshape(new_imaginary, [Nx, Ny, Nz])
Expand Down
Loading