def compile_crystal(datarow, flavor='pmg'):
        """
        Helper method for representing the MPDS crystal structures in two flavors:
        either as a Pymatgen Structure object, or as an ASE Atoms object.

        Attention #1. Disordered structures (e.g. fractional indices in the chemical formulae)
        are not supported by this method, and hence the occupancies are not retrieved.
        Currently it's up to the user to take care of that (see e.g.
        https://doi.org/10.1186/s13321-016-0129-3 etc.).

        Attention #2. Pymatgen and ASE flavors are generally not compatible, e.g.
        primitive vs. crystallographic cell is defaulted,
        atoms wrapped or non-wrapped into the unit cell etc.

        Note, that the crystal structures are not retrieved by default,
        so for them one needs to specify the following fields:
            - cell_abc
            - sg_n
            - basis_noneq
            - els_noneq
        e.g. like this: {'S':['cell_abc', 'sg_n', 'basis_noneq', 'els_noneq']}

        Args:
            datarow: (list) Required data to construct crystal structure:
                [cell_abc, sg_n, basis_noneq, els_noneq]
            flavor: (str) Either "pmg", or "ase"

        Returns:
            - if flavor is pmg, returns Pymatgen Structure object
            - if flavor is ase, returns ASE Atoms object
        """
        if not datarow or not datarow[-1]:
            # this is either a P-entry with the cell data, which meets the search criterion,
            # or a 'low quality' structure with no basis (just unit cell parameters)
            return None

        if len(datarow) < 4:
            raise ValueError(
                "Must supply a data row that ends with the entries "
                "'cell_abc', 'sg_n', 'basis_noneq', 'els_noneq'")

        cell_abc, sg_n, basis_noneq, els_noneq = \
            datarow[-4], int(datarow[-3]), datarow[-2], _massage_atsymb(datarow[-1])

        if flavor == 'pmg' and use_pmg:
            return Structure.from_spacegroup(
                sg_n,
                Lattice.from_parameters(*cell_abc),
                els_noneq,
                basis_noneq
            )

        elif flavor == 'ase' and use_ase:
            atom_data = []

            for num, i in enumerate(basis_noneq):
                atom_data.append(Atom(els_noneq[num], tuple(i)))

            return crystal(
                atom_data,
                spacegroup=sg_n,
                cellpar=cell_abc,
                primitive_cell=True,
                onduplicates='replace'
            )

        else: raise APIError("Crystal structure treatment unavailable")
def compile_crystal ( datarow , flavor = 'pmg' ) : if not datarow or not datarow [ - 1 ] : return None if len ( datarow ) < 4 : raise ValueError ( "Must supply a data row that ends with the entries " "'cell_abc', 'sg_n', 'basis_noneq', 'els_noneq'" ) cell_abc , sg_n , basis_noneq , els_noneq = datarow [ - 4 ] , int ( datarow [ - 3 ] ) , datarow [ - 2 ] , _massage_atsymb ( datarow [ - 1 ] ) if flavor == 'pmg' and use_pmg : return Structure . from_spacegroup ( sg_n , Lattice . from_parameters ( * cell_abc ) , els_noneq , basis_noneq ) elif flavor == 'ase' and use_ase : atom_data = [ ] for num , i in enumerate ( basis_noneq ) : atom_data . append ( Atom ( els_noneq [ num ] , tuple ( i ) ) ) return crystal ( atom_data , spacegroup = sg_n , cellpar = cell_abc , primitive_cell = True , onduplicates = 'replace' ) else : raise APIError ( "Crystal structure treatment unavailable" )
Helper method for representing the MPDS crystal structures in two flavors:
        either as a Pymatgen Structure object, or as an ASE Atoms object.

        Attention #1. Disordered structures (e.g. fractional indices in the chemical formulae)
        are not supported by this method, and hence the occupancies are not retrieved.
        Currently it's up to the user to take care of that (see e.g.
        https://doi.org/10.1186/s13321-016-0129-3 etc.).

        Attention #2. Pymatgen and ASE flavors are generally not compatible, e.g.
        primitive vs. crystallographic cell is defaulted,
        atoms wrapped or non-wrapped into the unit cell etc.

        Note, that the crystal structures are not retrieved by default,
        so for them one needs to specify the following fields:
            - cell_abc
            - sg_n
            - basis_noneq
            - els_noneq
        e.g. like this: {'S':['cell_abc', 'sg_n', 'basis_noneq', 'els_noneq']}

        Args:
            datarow: (list) Required data to construct crystal structure:
                [cell_abc, sg_n, basis_noneq, els_noneq]
            flavor: (str) Either "pmg", or "ase"

        Returns:
            - if flavor is pmg, returns Pymatgen Structure object
            - if flavor is ase, returns ASE Atoms object