Exemple #1
0
def get_tote(structure_type, form_e, species, oxides_table_path, debug=False):
    # formula = spe2form(structure_type, species)
    # composition = Composition(formula)
    spe_dict = Counter({})
    for site in SITE_INFO[structure_type]:
        spe_dict += Counter({spe.__str__(): round(SITE_INFO[structure_type][site]['num_atoms'] \
                                                  * species[site][spe]) \
                             for spe in sorted(species[site], key=lambda x: species[site][x])})
    composition = Composition(spe_dict)
    tote = form_e

    for el, amt in composition.items():
        if debug:
            print(el)
        stable_ox_entry = None
        if el.symbol == 'O':
            continue
        if el.symbol in BINARY_OXDIES_ENTRIES:
            stable_ox_entry = BINARY_OXDIES_ENTRIES[el.symbol]

        if not stable_ox_entry:
            stable_ox_table = loadfn(oxides_table_path)
            stable_ox_id = stable_ox_table[el.__str__()]['mpid']
            stable_ox_entry = m.get_entry_by_material_id(
                stable_ox_id,
                property_data=['e_above_hull', 'formation_energy_per_atom'])
        min_e = stable_ox_entry.uncorrected_energy
        amt_ox = stable_ox_entry.composition[el.name]
        tote += (amt / amt_ox) * min_e
    return tote
Exemple #2
0
def parse_formula(formula, max_len=9):
    f = Composition(formula).fractional_composition.as_dict()

    matrix = np.zeros((max_len, len(elements)))
    for i, ent in enumerate(f.items()):
        el, num = ent
        el = elements.index(el)
        matrix[i, el] = num
        # matrix[i, -1] = num / total

    return matrix
def get_tote(structure_type, form_e, species, debug=False):

    spe_dict = Counter({})
    for site in SITE_INFO[structure_type]:
        spe_dict += Counter({spe.__str__(): round(SITE_INFO[structure_type][site]['num_atoms'] \
                                                  * species[site][spe]) \
                             for spe in sorted(species[site], key=lambda x: species[site][x])})
    composition = Composition(spe_dict)
    tote = form_e

    for el, amt in composition.items():
        if debug:
            print(el)
        if el.symbol == 'O':
            continue
        if BINARY_OXDIES_ENTRIES.get(el.__str__()):
            stable_ox_entry = BINARY_OXDIES_ENTRIES[el.__str__()]
        else:
            raise ValueError("No binary oxide entry for %s" % el.__str__())
        min_e = stable_ox_entry.uncorrected_energy
        amt_ox = stable_ox_entry.composition[el.name]
        tote += (amt / amt_ox) * min_e
    return tote
Exemple #4
0
def parse_composition(structure_type, s, ctype):
    toks = s.strip().split()
    if len(toks) == 1:
        c = Composition({toks[0].split(":")[0]: 1})
    else:
        c = Composition(
            {t.split(":")[0]: float(t.split(":")[1])
             for t in toks})
        c = Composition({k2: v2 / sum(c.values()) for k2, v2 in c.items()})
        if len(c) != 2:
            raise ValueError("Bad composition on %s." % ctype)
        frac = [c.get_atomic_fraction(k) for k in c.keys()]

        if structure_type == 'garnet':
            if ctype == "A":
                if abs(frac[0] - 0.5) > 0.01:
                    raise ValueError("Bad composition on %s. "
                                     "Only 1:1 mixing allowed!" % ctype)
            elif ctype in ["C", "D"]:
                if not (abs(frac[0] - 1.0 / 3) < 0.01
                        or abs(frac[1] - 1.0 / 3) < 0.01):
                    raise ValueError("Bad composition on %s. "
                                     "Only 2:1 mixing allowed!" % ctype)
        elif structure_type == 'perovskite':
            if abs(frac[0] - 0.5) > 0.01:
                raise ValueError("Bad composition on %s. "
                                 "Only 1:1 mixing allowed!" % ctype)
    try:
        for k in c.keys():
            k.oxi_state
            if k not in ELS[structure_type][ctype]:
                raise ValueError("%s is not a valid species for %s site." %
                                 (k, ctype))
    except AttributeError:
        raise ValueError("Oxidation states must be specified for all species!")

    return c
Exemple #5
0
    def formula_to_periodic_table(self):
        def channel(x, y):
            '''                 
            x: horizontal
            y: vertical
            '''

            # f 14, d 10, p 6
            x, y = x + 1, y + 1  # changing to start from 1. 1 is the origin
            if y == 1 or x <= 2:
                channel = 0  # s
            elif 27 <= x:
                channel = 1  # p
            elif x == 3 or (3 + 14 + 1 <= x and x <= 17 + 9):
                channel = 2  # d
            elif 4 <= x and x <= 17:
                channel = 3  # f
            else:
                print("error in making channel in period_table_as_img")
            return channel

        dict_formula = Composition(self.formula).as_dict()
        coordinate = np.zeros([4, 7, 18 + 14], dtype=np.float32)
        for key, value in dict_formula.items():
            i = self.allowed_elements_list.index(key)
            # print(key)
            num = i + 1  # which is element number as H of num is 1
            # 18+14=32 # channel mens s,p,d, and f
            if num == 1:  # H
                coordinate[channel(0, 0), 0, 0] = value
            elif num == 2:  # He
                coordinate[channel(0, 32 - 1), 0, 32 - 1] = value

            elif num <= 18:
                # if q, mod=divmod(10,3) then q=3, mod=1
                y, x = divmod(num - 2, 8)
                if x == 1 or x == 2:
                    coordinate[channel(y + 1, x - 1), y + 1, x - 1] = value
                else:
                    if x == 0:
                        x = 8
                        y -= 1
                    x = x + 10 + 14
                    coordinate[channel(y + 1, x - 1), y + 1, x - 1] = value

            elif num <= 54:  # from K to Xe, which are from 4th and 5th period
                y, x = divmod(num - 18, 18)
                if x == 0:
                    x = 18
                    y -= 1
                if x == 1 or x == 2 or x == 3:
                    coordinate[channel(y + 3, x - 1), y + 3, x - 1] = value
                else:
                    x = x + 14
                    coordinate[channel(y + 3, x - 1), y + 3, x - 1] = value

            elif num <= 118:
                y, x = divmod(num - 54, 32)
                if x == 0:
                    x = 32
                    y -= 1
                coordinate[channel(y + 5, x - 1), y + 5, x - 1] = value
            else:
                raise ValueError('error in period to image-like')

        #     dict[key] = coordinate
        # if 'Tl' in dict.keys():
        #     dict['TI'] = dict['Tl']
        # if 'Li' in dict.keys():
        #     dict['LI'] = dict['Li']
        return coordinate