Skip to content

Commit

Permalink
Merge branch 'master' into symmetrized_structure_as_dict_monsable
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 authored Mar 7, 2025
2 parents 331b8b7 + 9523e3c commit fe5e46b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
21 changes: 12 additions & 9 deletions src/pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3745,25 +3745,28 @@ def get_nn_info(self, structure: Structure, n: int):

if self.use_fictive_radius:
# calculate fictive ionic radii
fict_ionic_radii = [_get_fictive_ionic_radius(site, neighbor) for neighbor in neighbors]
fictive_ionic_radii = [_get_fictive_ionic_radius(site, neighbor) for neighbor in neighbors]
else:
# just use the bond distance
fict_ionic_radii = [neighbor.nn_distance for neighbor in neighbors]
fictive_ionic_radii = [neighbor.nn_distance for neighbor in neighbors]

# calculate mean fictive ionic radius
mefir = _get_mean_fictive_ionic_radius(fict_ionic_radii)
mean_fictive_ionic_radius = _get_mean_fictive_ionic_radius(fictive_ionic_radii)

# iteratively solve MEFIR; follows equation 4 in Hoppe's EconN paper
prev_mefir = float("inf")
while abs(prev_mefir - mefir) > 1e-4:
prev_mean_fictive_ionic_radius = float("inf")
while abs(prev_mean_fictive_ionic_radius - mean_fictive_ionic_radius) > 1e-4:
# this is guaranteed to converge
prev_mefir = mefir
mefir = _get_mean_fictive_ionic_radius(fict_ionic_radii, minimum_fir=mefir)
prev_mean_fictive_ionic_radius = mean_fictive_ionic_radius
mean_fictive_ionic_radius = _get_mean_fictive_ionic_radius(
fictive_ionic_radii,
minimum_fir=mean_fictive_ionic_radius,
)

siw = []
for nn, fir in zip(neighbors, fict_ionic_radii, strict=True):
for nn, fictive_ionic_radius in zip(neighbors, fictive_ionic_radii, strict=True):
if nn.nn_distance < self.cutoff:
w = math.exp(1 - (fir / mefir) ** 6)
w = math.exp(1 - (fictive_ionic_radius / mean_fictive_ionic_radius) ** 6)
if w > self.tol:
bonded_site = {
"site": nn,
Expand Down
23 changes: 23 additions & 0 deletions src/pymatgen/symmetry/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,29 @@ def get_lattice_type(self) -> LatticeType:
return "rhombohedral"
return "hexagonal" if system == "trigonal" else system

def get_pearson_symbol(self) -> str:
"""Get the Pearson symbol for the structure.
Returns:
str: Pearson symbol for structure.
"""
cry_sys = self.get_crystal_system()
spg_sym = self.get_space_group_symbol()
centering = "C" if spg_sym[0] in ("A", "B", "C", "S") else spg_sym[0]

CRYSTAL_FAMILY_SYMBOLS = {
"triclinic": "a",
"monoclinic": "m",
"orthorhombic": "o",
"tetragonal": "t",
"trigonal": "h",
"hexagonal": "h",
"cubic": "c",
}

num_sites_conventional = len(self._space_group_data.std_types)
return f"{CRYSTAL_FAMILY_SYMBOLS[cry_sys]}{centering}{num_sites_conventional}"

def get_symmetry_dataset(self) -> SpglibDataset:
"""Get the symmetry dataset as a SpglibDataset.
Expand Down
22 changes: 16 additions & 6 deletions tests/symmetry/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@

class TestSpacegroupAnalyzer(PymatgenTest):
def setUp(self):
# FePO4
self.structure = Structure.from_file(f"{VASP_IN_DIR}/POSCAR")
self.sg = SpacegroupAnalyzer(self.structure, 0.001)

# Li10GeP2S12
self.disordered_structure = self.get_structure("Li10GeP2S12")
self.disordered_sg = SpacegroupAnalyzer(self.disordered_structure, 0.001)

# FePO4 with order of sites changed so the atoms aren't grouped by element.
struct = self.structure.copy()
site = struct[0]
del struct[0]
struct.append(site.species, site.frac_coords)
self.sg3 = SpacegroupAnalyzer(struct, 0.001)
graphite = self.get_structure("Graphite")
graphite.add_site_property("magmom", [0.1] * len(graphite))
self.sg4 = SpacegroupAnalyzer(graphite, 0.001)
self.structure4 = graphite

# Graphite
self.structure4 = self.get_structure("Graphite")
self.structure4.add_site_property("magmom", [0.1] * len(self.structure4))
self.sg4 = SpacegroupAnalyzer(self.structure4, 0.001)

def test_primitive(self):
struct = Structure.from_spacegroup("Fm-3m", np.eye(3) * 3, ["Cu"], [[0, 0, 0]])
Expand All @@ -49,9 +55,7 @@ def test_primitive(self):
def test_is_laue(self):
struct = Structure.from_spacegroup("Fm-3m", np.eye(3) * 3, ["Cu"], [[0, 0, 0]])
assert SpacegroupAnalyzer(struct).is_laue()

assert self.sg.is_laue()

assert self.disordered_sg.is_laue()

def test_magnetic(self):
Expand Down Expand Up @@ -86,6 +90,12 @@ def test_get_pointgroup(self):
assert self.sg.get_point_group_symbol() == "mmm"
assert self.disordered_sg.get_point_group_symbol() == "4/mmm"

def test_get_pearson_symbol(self):
assert self.sg.get_pearson_symbol() == "oP24"
assert self.disordered_sg.get_pearson_symbol() == "tP58"
assert self.sg3.get_pearson_symbol() == "oP24"
assert self.sg4.get_pearson_symbol() == "hP4"

def test_get_point_group_operations(self):
sg: SpacegroupAnalyzer
rng = np.random.default_rng()
Expand Down

0 comments on commit fe5e46b

Please sign in to comment.