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

_from_pymatgen() #227

Closed
XinYu73 opened this issue Aug 23, 2023 · 2 comments
Closed

_from_pymatgen() #227

XinYu73 opened this issue Aug 23, 2023 · 2 comments

Comments

@XinYu73
Copy link

XinYu73 commented Aug 23, 2023

def _from_pymatgen(self, struc, tol=1e-3, a_tol=5.0, style='pyxtal', hn=None):
"""
Load structure from Pymatgen
should not be used directly

    Args:
        struc: input pymatgen structure
        tol: symmetry tolerance
        a_tol: angle tolerance
        style: 'pyxtal' or spglib, differing in the choice of origin
        hn: hall_number
    """
    from pyxtal.util import get_symmetrized_pmg
    #import pymatgen.analysis.structure_matcher as sm

    self.valid = True
    try:
        sym_struc, number = get_symmetrized_pmg(struc, tol, a_tol, style, hn)
        #print(sym_struc)
        #import sys; sys.exit()
    except TypeError:
        print("Failed to load the Pymatgen structure")
    #    print(struc)
    #    self.valid = False

    if self.valid:
        d = sym_struc.composition.as_dict()
        species = [key for key in d.keys()]
        numIons = []
        for ele in species:
            numIons.append(int(d[ele]))
        self.numIons = numIons
        self.species = species
        if hn is None:
            self.group = Group(number, style=style)
        else:
            self.group = Group(hn, use_hall=True)
        #print(self.group[0]); import sys; sys.exit()
        matrix, ltype = sym_struc.lattice.matrix, self.group.lattice_type
        self.lattice = Lattice.from_matrix(matrix, ltype=ltype)
        atom_sites = []
        for i, site in enumerate(sym_struc.equivalent_sites):
            pos = site[0].frac_coords
            letter = sym_struc.wyckoff_symbols[i]
            wp = Wyckoff_position.from_group_and_letter(number, letter, style=style, hn=hn)
            specie = site[0].specie.number
            #if wp.index>0: print(wp)
            pos1 = wp.search_generator(pos, self.group[0])
            if pos1 is not None:
                atom_sites.append(atom_site(wp, pos1, specie))
            else:
                break

the default tol for search_generator is 1e-2, if tol used to find equivalent atoms is large like 0.1, the default 1e-2 may be too small

@qzhu2017
Copy link
Owner

@XinYu73 Just fixed

@XinYu73
Copy link
Author

XinYu73 commented Aug 24, 2023

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants