Skip to content
Open
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
33 changes: 21 additions & 12 deletions src/material_hasher/hasher/bawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ def __init__(
bonding_kwargs: dict = {"tol": 0.2, "cutoff": 10, "use_fictive_radius": True},
include_composition: bool = True,
symmetry_labeling: str = "moyo",
primitive_reduction: bool = False,
shorten_hash: bool = False,
):
self.graphing_algorithm = graphing_algorithm
self.bonding_algorithm = bonding_algorithm
self.bonding_kwargs = bonding_kwargs
self.include_composition = include_composition
self.symmetry_labeling = symmetry_labeling
self.primitive_reduction = primitive_reduction
self.shorten_hash = shorten_hash

def get_bawl_materials_data(
Expand Down Expand Up @@ -90,26 +92,33 @@ def get_bawl_materials_data(
structure,
bonding_kwargs=self.bonding_kwargs,
bonding_algorithm=self.bonding_algorithm,
primitive_reduction=self.primitive_reduction,
)
data["bonding_graph_hash"] = get_weisfeiler_lehman_hash(graph)
else:
raise ValueError(
"Graphing algorithm {} not implemented".format(self.graphing_algorithm)
)
if not self.shorten_hash:
match (self.symmetry_labeling, symmetry_label):
case (_, label) if label is not None:
data["symmetry_label"] = label
case ("AFLOW", _):
data["symmetry_label"] = AFLOWSymmetry().get_symmetry_label(structure)
case ("SPGLib", _):
data["symmetry_label"] = SPGLibSymmetry().get_symmetry_label(structure)
case ("moyo", _):
data["symmetry_label"] = MoyoSymmetry().get_symmetry_label(structure)
case (unknown, _):
raise ValueError(f"Symmetry algorithm {unknown} not implemented")
match (self.symmetry_labeling, symmetry_label):
case (_, label) if label is not None:
data["symmetry_label"] = label
case ("AFLOW", _):
data["symmetry_label"] = AFLOWSymmetry().get_symmetry_label(
structure
)
case ("SPGLib", _):
data["symmetry_label"] = SPGLibSymmetry().get_symmetry_label(
structure
)
case ("moyo", _):
data["symmetry_label"] = MoyoSymmetry().get_symmetry_label(
structure
)
case (unknown, _):
raise ValueError(f"Symmetry algorithm {unknown} not implemented")
if self.include_composition:
data["composition"] = structure.composition.formula.replace(" ", "")
data["composition"] = structure.composition.reduced_formula.replace(" ", "")
return data

def get_material_hash(self, structure: Structure) -> str:
Expand Down
15 changes: 13 additions & 2 deletions src/material_hasher/hasher/utils/graph_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
from pymatgen.analysis.local_env import EconNN, NearNeighbors
from pymatgen.core import Structure
from networkx import Graph
from moyopy import MoyoDataset
from moyopy.interface import MoyoAdapter
import warnings


def get_structure_graph(
structure: Structure,
bonding_kwargs: dict = {},
bonding_algorithm: NearNeighbors = EconNN,
primitive_reduction: bool = False,
) -> Graph:
"""Method to build networkx graph object based on
bonding algorithm from Pymatgen Structure
Expand All @@ -23,11 +27,18 @@ class to build bonded structure. Defaults to EconNN.
Returns:
Graph: networkx Graph object
"""
assess_structure = (
MoyoAdapter.get_structure(
MoyoDataset(MoyoAdapter.from_structure(structure)).prim_std_cell
)
if primitive_reduction
else structure.copy()
)
structure_graph = StructureGraph.with_local_env_strategy(
structure=structure,
structure=assess_structure,
strategy=bonding_algorithm(**bonding_kwargs),
)
for n, site in zip(range(len(structure)), structure):
for n, site in zip(range(len(assess_structure)), assess_structure):
structure_graph.graph.nodes[n]["specie"] = site.specie.name
for edge in structure_graph.graph.edges:
structure_graph.graph.edges[edge]["voltage"] = structure_graph.graph.edges[
Expand Down