Skip to content

Commit

Permalink
Merge pull request #487 from esoteric-ephemera/main
Browse files Browse the repository at this point in the history
Updating spglib attr access / improvements for MP building
  • Loading branch information
janosh authored Sep 3, 2024
2 parents 7359a3f + e690b7f commit e13cad8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion robocrys/condense/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_sym_inequiv_components(
components = deepcopy(components)

sym_inequiv_components = {}
equivalent_atoms = spg_analyzer.get_symmetry_dataset()["equivalent_atoms"]
equivalent_atoms = spg_analyzer.get_symmetry_dataset().equivalent_atoms

for component in components:
sym_indices = frozenset(equivalent_atoms[x] for x in component["site_ids"])
Expand Down
25 changes: 18 additions & 7 deletions robocrys/condense/mineral.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
"""This module provides tools for matching structures to known mineral class."""

from __future__ import annotations

from importlib.resources import files as import_resource_file
from itertools import islice
from typing import Any
from pathlib import Path
from typing import TYPE_CHECKING, Any

import numpy as np
from matminer.utils.io import load_dataframe_from_json
from importlib.resources import files as import_resource_file
from pymatgen.analysis.prototypes import AflowPrototypeMatcher
from pymatgen.core.structure import IStructure

from robocrys.condense.fingerprint import (
get_fingerprint_distance,
get_structure_fingerprint,
)


if TYPE_CHECKING:
import pandas as pd

_mineral_db_file = import_resource_file("robocrys.condense") / "mineral_db.json.gz"


class MineralMatcher:
"""Class to match a structure to a mineral name.
Expand All @@ -40,6 +47,8 @@ class MineralMatcher:
fingerprint_distance_cutoff: Cutoff to determine how similar a match
must be to be returned. The distance is measured between the
structural fingerprints in euclidean space.
mineral_db : Optional path or pandas .DataFrame object containing the
mineral fingerprint database.
"""

def __init__(
Expand All @@ -49,9 +58,12 @@ def __init__(
initial_angle_tol: float = 5.0,
use_fingerprint_matching: bool = True,
fingerprint_distance_cutoff: float = 0.4,
mineral_db: str | Path | pd.DataFrame | None = None,
):
db_file = import_resource_file("robocrys.condense") / "mineral_db.json.gz"
self.mineral_db = load_dataframe_from_json(db_file)
self.mineral_db = mineral_db if mineral_db is not None else _mineral_db_file
if isinstance(self.mineral_db, (str, Path)):
self.mineral_db = load_dataframe_from_json(self.mineral_db)

self.initial_ltol = initial_ltol
self.initial_stol = initial_stol
self.initial_angle_tol = initial_angle_tol
Expand Down Expand Up @@ -214,8 +226,7 @@ def get_fingerprint_matches(
]

if match_n_sp:
n_elems = structure.n_elems
mineral_db = mineral_db[mineral_db["n_elems"] == n_elems]
mineral_db = mineral_db[mineral_db["n_elems"] == structure.n_elems]

num_rows = mineral_db.shape[0]
max_n_matches = max_n_matches or num_rows
Expand Down
3 changes: 2 additions & 1 deletion robocrys/condense/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __init__(
self.site_fingerprints = get_site_fingerprints(bonded_structure.structure)

sga = SpacegroupAnalyzer(bonded_structure.structure, symprec=symprec)
equivalent_sites = sga.get_symmetry_dataset()["equivalent_atoms"]
equivalent_sites = sga.get_symmetry_dataset().equivalent_atoms

if use_symmetry_equivalent_sites:
self.equivalent_sites = list(equivalent_sites)
else:
Expand Down
1 change: 0 additions & 1 deletion robocrys/describe/describer.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ def get_component_makeup_summary(self) -> str:
formula = latexify(formula)
elif self.fmt == "unicode":
formula = unicodeify(formula)
print(formula)
elif self.fmt == "html":
formula = htmlify(formula)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
test_suite="nose.collector",
packages=find_packages(),
install_requires=[
"spglib",
"spglib>=2.5.0",
"numpy",
"scipy",
"pymatgen",
"pymatgen>=2024.1.26",
"inflect",
"networkx",
"matminer>=0.9.2",
Expand Down

0 comments on commit e13cad8

Please sign in to comment.