Skip to content

Commit

Permalink
Merge pull request JaGeo#331 from naik-aakash/update_calc_quality
Browse files Browse the repository at this point in the history
Update calc quality and fingerprints usage
  • Loading branch information
JaGeo authored Sep 11, 2024
2 parents b722b16 + bc11fcc commit a98d1be
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 185 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "3.10"
cache: pip
cache-dependency-path: pyproject.toml

- uses: pre-commit/[email protected].0
- uses: pre-commit/[email protected].1

test:
runs-on: ubuntu-latest
Expand All @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
split: [1, 2, 3, 4, 5, 6]


Expand Down Expand Up @@ -63,10 +63,12 @@ jobs:
pytest --cov=lobsterpy --cov-report term-missing --cov-append --splits 6 --group ${{ matrix.split }} -vv --durations-path ./tests/test_data/.pytest-split-durations
- name: Upload coverage
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.split }}
path: .coverage
name: coverage-${{ matrix.split }}-${{ matrix.python-version }}
include-hidden-files: true
overwrite: false
path: ./.coverage

coverage:
needs: test
Expand All @@ -84,12 +86,12 @@ jobs:
- name: Download coverage artifacts
continue-on-error: true
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Run coverage
continue-on-error: true
run: |
coverage combine coverage*/.coverage*
coverage combine coverage*/.coverage-*-3.10
coverage report --show-missing
- name: Upload coverage reports to Codecov
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ authors = [{ name = "Janine George", email = "[email protected]" }]
version = "0.4.7"
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
]
requires-python = ">=3.9,<3.13"
requires-python = ">=3.10,<3.13"
dependencies = [
"pymatgen>=2024.5.1",
"pymatgen>=2024.9.10",
"numpy<3.0.0",
"typing",
]
Expand Down
12 changes: 6 additions & 6 deletions src/lobsterpy/cohp/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,18 +1693,18 @@ def get_lobster_calc_quality_summary(
max_e=max_e,
n_bins=n_bins,
normalize=True,
type=orb.name,
fp_type=orb.name,
)
fp_vasp_orb = dos_vasp.get_dos_fp(
min_e=min_e,
max_e=max_e,
n_bins=n_bins,
normalize=True,
type=orb.name,
fp_type=orb.name,
)

tani_orb = round(
dos_vasp.get_dos_fp_similarity(fp_lobster_orb, fp_vasp_orb, tanimoto=True),
dos_vasp.get_dos_fp_similarity(fp_lobster_orb, fp_vasp_orb, metric="tanimoto"),
4,
)
quality_dict["dos_comparisons"][f"tanimoto_orb_{orb.name}"] = tani_orb # type: ignore
Expand All @@ -1714,17 +1714,17 @@ def get_lobster_calc_quality_summary(
max_e=max_e,
n_bins=n_bins,
normalize=True,
type="summed_pdos",
fp_type="summed_pdos",
)
fp_vasp = dos_vasp.get_dos_fp(
min_e=min_e,
max_e=max_e,
n_bins=n_bins,
normalize=True,
type="summed_pdos",
fp_type="summed_pdos",
)

tanimoto_summed = round(dos_vasp.get_dos_fp_similarity(fp_lobster, fp_vasp, tanimoto=True), 4)
tanimoto_summed = round(dos_vasp.get_dos_fp_similarity(fp_lobster, fp_vasp, metric="tanimoto"), 4)
quality_dict["dos_comparisons"]["tanimoto_summed"] = tanimoto_summed # type: ignore
quality_dict["dos_comparisons"]["e_range"] = [min_e, max_e] # type: ignore
quality_dict["dos_comparisons"]["n_bins"] = n_bins # type: ignore
Expand Down
29 changes: 4 additions & 25 deletions src/lobsterpy/featurize/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,27 +1009,6 @@ def get_df(self, ids: str | None = None) -> pd.DataFrame:
return df


class DosFingerprint(NamedTuple):
"""
Represents a Density of States (DOS) fingerprint.
This named tuple is used to store information related to the Density of States (DOS)
in a material. It includes the energies, densities, type, number of bins, and bin width.
:param energies: The energy values associated with the DOS.
:param densities: The corresponding density values for each energy.
:param type: The type of DOS fingerprint.
:param n_bins: The number of bins used in the fingerprint.
:param bin_width: The width of each bin in the DOS fingerprint.
"""

energies: np.ndarray
densities: np.ndarray
type: str
n_bins: int
bin_width: float


class FeaturizeDoscar:
"""
Class to compute DOS moments and fingerprints from DOSCAR.lobster / DOSCAR.LSO.lobster.
Expand Down Expand Up @@ -1155,15 +1134,15 @@ def get_fingerprint_df(
ids = Path(self.path_to_doscar).parent.name
df = pd.DataFrame(index=[ids], columns=["DOS_FP"])

fp = self.dos.get_dos_fp(
type=fp_type,
dos_fp = self.dos.get_dos_fp(
fp_type=fp_type,
normalize=normalize,
n_bins=n_bins,
binning=binning,
max_e=self.e_range[-1] if self.e_range is not None else None,
min_e=self.e_range[0] if self.e_range is not None else None,
)._asdict()
)

df.loc[ids, "DOS_FP"] = DosFingerprint(**fp)
df.loc[ids, "DOS_FP"] = dos_fp

return df
7 changes: 4 additions & 3 deletions tests/featurize/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
BatchStructureGraphs,
BatchSummaryFeaturizer,
)
from lobsterpy.featurize.core import CoxxFingerprint, DosFingerprint
from lobsterpy.featurize.core import CoxxFingerprint
from pymatgen.analysis.graphs import StructureGraph
from pymatgen.electronic_structure.dos import DosFingerprint

CurrentDir = Path(__file__).absolute().parent
TestDir = CurrentDir / "../"
Expand Down Expand Up @@ -576,7 +577,7 @@ def test_batch_dos_featurizer_non_lso(self):

for dos_fp in df_fp["DOS_FP"]:
assert isinstance(dos_fp, DosFingerprint)
assert dos_fp.type == "p"
assert dos_fp.fp_type == "p"
assert dos_fp.n_bins == 100

def test_batch_dos_featurizer_lso(self):
Expand Down Expand Up @@ -668,7 +669,7 @@ def test_batch_dos_featurizer_lso(self):

for dos_fp in df_fp_lso["DOS_FP"]:
assert isinstance(dos_fp, DosFingerprint)
assert dos_fp.type == "summed_pdos"
assert dos_fp.fp_type == "summed_pdos"
assert dos_fp.n_bins == 256


Expand Down
2 changes: 1 addition & 1 deletion tests/featurize/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import pandas as pd
import pytest
from lobsterpy.featurize.core import (
DosFingerprint,
FeaturizeCharges,
FeaturizeCOXX,
FeaturizeDoscar,
FeaturizeLobsterpy,
)
from pymatgen.electronic_structure.dos import DosFingerprint

CurrentDir = Path(__file__).absolute().parent
TestDir = CurrentDir / "../"
Expand Down
Loading

0 comments on commit a98d1be

Please sign in to comment.