Skip to content

Commit

Permalink
Update core.py
Browse files Browse the repository at this point in the history
  • Loading branch information
r3zu authored Feb 12, 2024
1 parent 2042ec8 commit c497723
Showing 1 changed file with 1 addition and 119 deletions.
120 changes: 1 addition & 119 deletions src/xtal2txt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,126 +229,8 @@ def get_robocrys_rep(self):
condensed_structure = condenser.condense_structure(self.structure)
return describer.describe(condensed_structure)


def get_space_group(self):
"""
Getting the space group symbol and number of the crystal structure.
Returns:
symbol: str
Symbol of the space group.
number: int
The integer number between 0 and 230 for the specified crystal structure.
"""

symbol = self.structure.get_space_group_info()[0]
number = self.structure.get_space_group_info()[1]

return symbol, number


def get_wyckoff_positions(self):
"""
Getting wyckoff positions of the elements in the unit cell as the combination of...
number and letter.
Returns:
ouput: str
A multi-line string that contain elements of the unit cell along with their...
wyckoff position in each line.
Hint: At the end of the string, there is an additional newline character.
"""

spacegroup_analyzer = SpacegroupAnalyzer(self.structure)
wyckoff_sites = spacegroup_analyzer.get_symmetry_dataset()
element_symbols = [site.specie.element.symbol for site in self.structure.sites]

data = []

for i in range(len(wyckoff_sites["wyckoffs"])):
sub_data = element_symbols[i], wyckoff_sites["wyckoffs"][i], wyckoff_sites["equivalent_atoms"][i]
data.append(sub_data)

a = dict(Counter(data))

output = ""
for i, j in a.items():
output += str(i[0]) + " " + str(j) + str(i[1]) + "\n"

return output

def get_wycryst():
"""
Obtaining the wyckoff representation for crystal structures that include:
chemcial formula
space group number
elements of the unit cell with their wyckoff positions.
Returns:
output: str
A multi-line string, which contain mentioned properties of the crystal...
structure in each separate line.
"""
output = ""
chemical_formula = self.structure.composition.formula
output += chemical_formula
output += "\n" + str(self.get_space_group()[1])
output += "\n" + self.get_wyckoff_positions()

return output

def wyckoff_decoder(self):
"""
Generating a pymatgen object from the output of the get_wyckoff_rep() method by using...
pyxtal package. In this method, all data are extracted from the multi-line string of the...
mentioned method.
In pyxtal package, a 3D crystal is produced by specifying the dimensions, elements,...
composition of elements, space group, and sites as wyckoff positions of the elements.
Returns:
pmg_struc: pymatgen.core.structure.Structure
"""

# Always dimensions is 3.
dimensions = 3

a, b, c, alpha, beta, gamma = self.get_parameters()

wyckoff_str = self.get_wyckoff_rep()
entities = wyckoff_str.split("\n")[:-1]
elements = entities[0]
spg = int(entities[1])
wyckoff_sites = entities[2:]
elements = elements.split(" ")

atoms = []
composition = []
for el in elements:
atom = el.rstrip('0123456789')
number = el[len(atom):]
atoms.append(atom)
composition.append(int(number))

sites = []
for atom in atoms:
sub_site = []
for site in wyckoff_sites:
if atom in site:
sub_site.append(site.split()[1])

sites.append(sub_site)

xtal_struc = pyxtal()
xtal_struc.from_random(dimensions,
spg,
atoms,
composition,
sites=sites,
)

pmg_struc = xtal_struc.to_pymatgen()

return pmg_struc
pass

def get_all_text_reps():
pass

0 comments on commit c497723

Please sign in to comment.