Skip to content

Commit

Permalink
Added classmethod decorators to Wyckoff_Position from_(...) type cons…
Browse files Browse the repository at this point in the history
…tructor methods
  • Loading branch information
Somerandomguy10111 committed May 5, 2024
1 parent c385b35 commit 5b622ab
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions pyxtal/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,11 +1352,12 @@ class Wyckoff_position:
"""

#=============================Initialization===========================
def from_dict(dictionary):
@classmethod
def from_dict(cls, dictionary):
"""
Constructs a Wyckoff_position object using a dictionary.
"""
wp = Wyckoff_position()
wp = cls()
for key in dictionary:
setattr(wp, key, dictionary[key])
#wp.get_site_symmetry()
Expand All @@ -1367,8 +1368,8 @@ def from_dict(dictionary):
wp.set_ops()
return wp


def from_group_and_letter(group, letter, dim=3, style='pyxtal', hn=None):
@classmethod
def from_group_and_letter(cls, group, letter, dim=3, style='pyxtal', hn=None):
"""
Creates a Wyckoff_position using the space group number and index
Expand All @@ -1387,12 +1388,13 @@ def from_group_and_letter(group, letter, dim=3, style='pyxtal', hn=None):
ops_all = get_wyckoffs(group, dim=dim)
index = index_from_letter(letter, ops_all, dim=dim)
if hn is not None:
wp = Wyckoff_position.from_group_and_index(hn, index, dim, use_hall=True, wyckoffs=ops_all)
wp = cls.from_group_and_index(hn, index, dim, use_hall=True, wyckoffs=ops_all)
else:
wp = Wyckoff_position.from_group_and_index(group, index, dim, style=style, wyckoffs=ops_all)
wp = cls.from_group_and_index(group, index, dim, style=style, wyckoffs=ops_all)
return wp

def from_group_and_index(group, index, dim=3, use_hall=False, style='pyxtal', wyckoffs=None):
@classmethod
def from_group_and_index(cls, group, index, dim=3, use_hall=False, style='pyxtal', wyckoffs=None):
"""
Creates a Wyckoff_position using the space group number and index
Expand Down Expand Up @@ -1454,9 +1456,10 @@ def from_group_and_index(group, index, dim=3, use_hall=False, style='pyxtal', wy
"lattice_type": lattice_type,
}

return Wyckoff_position.from_dict(wpdict)
return cls.from_dict(wpdict)

def from_symops_wo_group(ops):
@classmethod
def from_symops_wo_group(cls, ops):
"""
search Wyckoff Position by symmetry operations
Now only supports space group symmetry
Expand All @@ -1469,16 +1472,16 @@ def from_symops_wo_group(ops):
`Wyckoff_position`
"""
_, spg_num = get_symmetry_from_ops(ops)
wp = Wyckoff_position.from_group_and_index(spg_num, 0)
wp = cls.from_group_and_index(spg_num, 0)
if isinstance(ops[0], str):
ops = [SymmOp.from_xyz_str(op) for op in ops]
wp.ops = ops
match_spg, match_hm = wp.update()
#print("match_spg", match_spg, "match_hall", match_hm)
return wp


def from_symops(ops, G):
@classmethod
def from_symops(cls,ops, G):
"""
search Wyckoff Position by symmetry operations
Expand Down

0 comments on commit 5b622ab

Please sign in to comment.