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

add POSCAR.lobster support in featurizer #186

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
129 changes: 94 additions & 35 deletions lobsterpy/featurize/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,23 @@ def _featurizecoxx(self, path_to_lobster_calc) -> pd.DataFrame:
"icoxxlist_path": "ICOHPLIST.lobster",
}
for file, default_value in req_files.items():
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
# Check if "POSCAR" exists, and if not, check for "POSCAR.lobster"
if file == "structure_path":
for filename in [default_value, "POSCAR.lobster"]:
poscar_path = dir_name / filename
req_files[file] = poscar_path # type: ignore
if not poscar_path.exists():
gz_file_path = Path(zpath(poscar_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
break
else:
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore

coxxcar_path = req_files.get("coxxcar_path")
structure_path = req_files.get("structure_path")
Expand Down Expand Up @@ -262,12 +273,22 @@ def _featurizecharges(self, path_to_lobster_calc) -> pd.DataFrame:
"structure_path": "POSCAR",
}
for file, default_value in req_files.items():
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
if file == "structure_path":
for filename in [default_value, "POSCAR.lobster"]:
poscar_path = dir_name / filename
req_files[file] = poscar_path # type: ignore
if not poscar_path.exists():
gz_file_path = Path(zpath(poscar_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
break
else:
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore

charge_path = req_files.get("charge_path")
structure_path = req_files.get("structure_path")
Expand Down Expand Up @@ -633,11 +654,19 @@ def _fingerprint_df(self, path_to_lobster_calc) -> pd.DataFrame:
are_cobis = False
are_coops = False

structure_path = dir_name / "POSCAR"
if not structure_path.exists():
gz_file_path = Path(zpath(structure_path))
if gz_file_path.exists():
structure_path = gz_file_path
for filename in ["POSCAR", "POSCAR.lobster"]:
structure_path = dir_name / filename
if not structure_path.exists():
gz_file_path = Path(zpath(structure_path))
if gz_file_path.exists():
structure_path = gz_file_path # type: ignore
break

# structure_path = dir_name / "POSCAR"
# if not structure_path.exists():
# gz_file_path = Path(zpath(structure_path))
# if gz_file_path.exists():
# structure_path = gz_file_path

coxx = FeaturizeCOXX(
path_to_coxxcar=str(coxxcar_path),
Expand Down Expand Up @@ -750,12 +779,22 @@ def _get_sg_df(self, path_to_lobster_calc) -> pd.DataFrame:
}

for file, default_value in req_files.items():
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
if file == "structure_path":
for filename in [default_value, "POSCAR.lobster"]:
poscar_path = dir_name / filename
req_files[file] = poscar_path # type: ignore
if not poscar_path.exists():
gz_file_path = Path(zpath(poscar_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
break
else:
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore

charge_path = str(req_files.get("charge_path"))
cohpcar_path = str(req_files.get("cohpcar_path"))
Expand Down Expand Up @@ -887,12 +926,22 @@ def _get_dos_moments_df(self, path_to_lobster_calc) -> pd.DataFrame:
"structure_path": "POSCAR",
}
for file, default_value in req_files.items():
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
if file == "structure_path":
for filename in [default_value, "POSCAR.lobster"]:
poscar_path = dir_name / filename
req_files[file] = poscar_path # type: ignore
if not poscar_path.exists():
gz_file_path = Path(zpath(poscar_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
break
else:
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore

doscar_path = req_files.get("doscar_path")
structure_path = req_files.get("structure_path")
Expand Down Expand Up @@ -928,12 +977,22 @@ def _get_dos_fingerprints_df(self, path_to_lobster_calc) -> pd.DataFrame:
"structure_path": "POSCAR",
}
for file, default_value in req_files.items():
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
if file == "structure_path":
for filename in [default_value, "POSCAR.lobster"]:
poscar_path = dir_name / filename
req_files[file] = poscar_path # type: ignore
if not poscar_path.exists():
gz_file_path = Path(zpath(poscar_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore
break
else:
file_path = dir_name / default_value
req_files[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files[file] = gz_file_path # type: ignore

doscar_path = req_files.get("doscar_path")
structure_path = req_files.get("structure_path")
Expand Down
34 changes: 22 additions & 12 deletions lobsterpy/featurize/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,28 @@ def get_lobsterpy_cba_dict(
}

for file, default_value in req_files_lobsterpy.items():
file_path = dir_name / default_value
req_files_lobsterpy[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files_lobsterpy[file] = gz_file_path # type: ignore
else:
raise Exception(
"Path provided for Lobster calc directory seems incorrect."
"It does not contain COHPCAR.lobster, ICOHPLIST.lobster, POSCAR and "
"CHARGE.lobster files needed for automatic analysis using LobsterPy"
)
if file == "structure_path":
for filename in [default_value, "POSCAR.lobster"]:
poscar_path = dir_name / filename
req_files_lobsterpy[file] = poscar_path # type: ignore
if not poscar_path.exists():
gz_file_path = Path(zpath(poscar_path))
if gz_file_path.exists():
req_files_lobsterpy[file] = gz_file_path # type: ignore
break
else:
file_path = dir_name / default_value
req_files_lobsterpy[file] = file_path # type: ignore
if not file_path.exists():
gz_file_path = Path(zpath(file_path))
if gz_file_path.exists():
req_files_lobsterpy[file] = gz_file_path # type: ignore
else:
raise Exception(
"Path provided for Lobster calc directory seems incorrect."
"It does not contain COHPCAR.lobster, ICOHPLIST.lobster, POSCAR and "
"CHARGE.lobster files needed for automatic analysis using LobsterPy"
)

cohpcar_path = req_files_lobsterpy.get("cohpcar_path")
charge_path = req_files_lobsterpy.get("charge_path")
Expand Down