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

Bandstructure path name changes and Kpoint from_dict #2144

Merged
merged 5 commits into from
May 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions pymatgen/electronic_structure/bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ def as_dict(self):
"@class": self.__class__.__name__,
}

@classmethod
def from_dict(cls, d):
"""
Create from dict.

Args:
A dict with all data for a kpoint object.

Returns:
A Kpoint object
"""

return cls(
coords=d["fcoords"],
lattice=Lattice.from_dict(d["lattice"]),
coords_are_cartesian=False,
label=d["label"],
)


class BandStructure:
"""
Expand Down
18 changes: 18 additions & 0 deletions pymatgen/electronic_structure/tests/test_bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ def test_as_dict(self):
self.assertListEqual(self.kpoint.as_dict()["fcoords"], [0.1, 0.4, -0.5])
self.assertListEqual(self.kpoint.as_dict()["ccoords"], [1.0, 4.0, -5.0])

def test_from_dict(self):

d = self.kpoint.as_dict()

kpoint = Kpoint.from_dict(d)

self.assertEqual(kpoint.frac_coords[0], 0.1)
self.assertEqual(kpoint.frac_coords[1], 0.4)
self.assertEqual(kpoint.frac_coords[2], -0.5)
self.assertEqual(kpoint.a, 0.1)
self.assertEqual(kpoint.b, 0.4)
self.assertEqual(kpoint.c, -0.5)
self.assertEqual(kpoint.lattice, Lattice.cubic(10.0))
self.assertEqual(kpoint.cart_coords[0], 1.0)
self.assertEqual(kpoint.cart_coords[1], 4.0)
self.assertEqual(kpoint.cart_coords[2], -5.0)
self.assertEqual(kpoint.label, "X")


class BandStructureSymmLine_test(PymatgenTest):
def setUp(self):
Expand Down
30 changes: 16 additions & 14 deletions pymatgen/symmetry/bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
structure,
has_magmoms=False,
magmom_axis=None,
path_type="sc",
path_type="setyawan_curtarolo",
symprec=0.01,
angle_tolerance=5,
atol=1e-5,
Expand All @@ -71,14 +71,14 @@ def __init__(
should point. If all magnetic moments are provided as
vectors then this argument is not used.
path_type (string): Chooses which convention to use to generate
the high symmetry path. Options are: 'sc', 'hin', 'lm' for the
Setyawan & Curtarolo, Hinuma et al., and Latimer & Munro conventions.
Choosing 'all' will generate one path with points from all three
conventions. Equivalent labels between each will also be generated.
Order will always be Latimer & Munro, Setyawan & Curtarolo, and Hinuma et al.
Lengths for each of the paths will also be generated and output
as a list. Note for 'all' the user will have to alter the labels on
their own for plotting.
the high symmetry path. Options are: 'setyawan_curtarolo', 'hinuma',
'latimer_munro' for the Setyawan & Curtarolo, Hinuma et al., and
Latimer & Munro conventions. Choosing 'all' will generate one path
with points from all three conventions. Equivalent labels between
each will also be generated. Order will always be Latimer & Munro,
Setyawan & Curtarolo, and Hinuma et al. Lengths for each of the paths
will also be generated and output as a list. Note for 'all' the user
will have to alter the labels on their own for plotting.
symprec (float): Tolerance for symmetry finding
angle_tolerance (float): Angle tolerance for symmetry finding.
atol (float): Absolute tolerance used to determine symmetric
Expand All @@ -95,11 +95,11 @@ def __init__(

if path_type != "all":

if path_type == "lm":
if path_type == "latimer_munro":
self._kpath = self._get_lm_kpath(has_magmoms, magmom_axis, symprec, angle_tolerance, atol).kpath
elif path_type == "sc":
elif path_type == "setyawan_curtarolo":
self._kpath = self._get_sc_kpath(symprec, angle_tolerance, atol).kpath
elif path_type == "hin":
elif path_type == "hinuma":
hin_dat = self._get_hin_kpath(symprec, angle_tolerance, atol, not has_magmoms)
self._kpath = hin_dat.kpath
self._hin_tmat = hin_dat._tmat
Expand Down Expand Up @@ -248,8 +248,10 @@ def _get_klabels(self, lm_bs, sc_bs, hin_bs, rpg):

n_op = len(rpg)

pairs = itertools.permutations([{"sc": sc_path}, {"lm": lm_path}, {"hin": hin_path}], r=2)
labels = {"sc": {}, "lm": {}, "hin": {}}
pairs = itertools.permutations(
[{"setyawan_curtarolo": sc_path}, {"latimer_munro": lm_path}, {"hinuma": hin_path}], r=2
)
labels = {"setyawan_curtarolo": {}, "latimer_munro": {}, "hinuma": {}}

for (a, b) in pairs:
[(a_type, a_path)] = list(a.items())
Expand Down