In [1]:
from pycalphad import Database, variables as v
from pycalphad.variables import Species

dbf = Database('AlCoCrNi-2016Liu-minified.TDB')

In [2]:
import itertools
import string
import sympy
import numpy as np

def genericize(mapping, const_array):
    new_array = []
    for subl in const_array:
        new_array.append(tuple(mapping[x] for x in subl))
    return tuple(new_array)
def sigfigs(x, n):
    """Round x to n significant digits"""
    if x != 0:
        return np.around(x, -(np.floor(np.log10(np.abs(x)))).astype(np.int) + (n - 1))
    else:
        return x
def average_piecewise(pw):
    return sum(x.expr for x in pw.args)/len(pw.args)

def categorize_phase(phase_name, constituents, site_ratios):
    if phase_name == 'LIQUID' and len(constituents) == 1:
        return 'liquid'
    elif phase_name == 'GAS' and len(constituents) == 1:
        return 'gas'
    elif len(constituents) == 1 or \
        (len(constituents) == 2 and len(constituents[1]) == 1 and list(constituents[1])[0] == Species('VA')):
        return 'solid'
    elif all(len(x) == 1 for x in constituents):
        return 'stoichiometric'
    else:
        return 'complex'

def extract_coefficients(expr, polys):
    result = {}
    for poly in polys:
        if poly == 1:
            continue
        else:
            coef = float(expr.coeff(poly))
        result[poly] = coef
        expr = expr - poly*coef
    expr = expr.n()
    if isinstance(expr, (sympy.Float, sympy.Integer)):
        result[1] = float(expr)
        expr = sympy.S.Zero
    if expr is not sympy.S.Zero:
        raise ValueError(expr)
    return tuple(result[p] for p in polys)

total_results = []

for combo in itertools.combinations(dbf.elements - {'VA', '/-'}, 2):
    combo_str = sorted(set(combo) | {'VA'})
    combo = [Species(x) for x in combo_str]
    combo_dict = dict(zip([c for c in combo if c.number_of_atoms > 0], string.ascii_uppercase))
    combo_dict[Species('VA')] = 'VA'
    allowed_phases = set()
    # TODO: Categorize each phase? solid solution, intermetallic, complex intermetallic, liquid, etc.
    for phase_name, phase_obj in dbf.phases.items():
        include_phase = True
        for sublattice in phase_obj.constituents:
            if len(set(sublattice).intersection(combo)) == 0:
                # None of the components in a sublattice are active
                # We cannot build a model of this phase
                include_phase = False
                break
        if include_phase:
            allowed_phases |= {phase_name}
    for param in dbf._parameters.all():
        if param['phase_name'] in allowed_phases and param['parameter_type'] in ['G', 'L']:
            active_pure_elements = [list(x.constituents.keys()) for subl in param['constituent_array'] for x in subl]
            active_pure_elements = [el.upper() for constituents in active_pure_elements for el in constituents]
            active_pure_elements = set(active_pure_elements)
            if not active_pure_elements.issubset(combo_str):
                continue
            generic_combo = [Species(x) for x in sorted(active_pure_elements)]
            gen_combo_dict = dict(zip([c for c in generic_combo if c.number_of_atoms > 0], string.ascii_uppercase))
            gen_combo_dict[Species('VA')] = 'VA'
            gen_combo_dict[Species('*')] = '*'
            ratio_sum = sum(dbf.phases[param['phase_name']].sublattices)
            reduced_ratios = tuple(sigfigs(c, 3) for c in dbf.phases[param['phase_name']].sublattices)
            param_val = param['parameter'].subs(dbf.symbols).subs(dbf.symbols).subs(dbf.symbols).subs(dbf.symbols)
            # If parameter is Piecewise, average it (for now)
            param_val = sympy.piecewise_fold(param_val)
            pw_atoms = param_val.atoms(sympy.Piecewise)
            pw_dict = {key: average_piecewise(key) for key in pw_atoms}
            param_val = param_val.subs(pw_dict)
            # Cross terms must be listed first
            polys = [v.T*sympy.log(1.0e-5*v.P)] + [v.T*sympy.log(v.T), sympy.log(v.T)] + [v.T**n for n in range(-30,0)] + [v.T**n for n in range(1,30)] + [1]
            columns = ['system', 'phase_name', 'phase_type', 'site_ratios',
                       'parameter_order', 'constituent_array', 'parameter_value'] + \
                        [str(x) for x in polys]
            try:
                id_tuple = (tuple(c for c in combo_str if c != 'VA'), param['phase_name'],
                            categorize_phase(param['phase_name'], dbf.phases[param['phase_name']].constituents, reduced_ratios),
                            reduced_ratios, param['parameter_order'],
                            genericize(gen_combo_dict, param['constituent_array']),
                            param_val) + extract_coefficients(param_val, polys)
                total_results.append(id_tuple)
            except ValueError as e:
                print(e)


102862.903225806*((4.65e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 1115.9095
172788.461538462*((2.6e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 3645.714
172788.461538462*((2.6e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 7287.714
102862.903225806*((4.65e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 1115.9095
172788.461538462*((2.6e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 3645.714
172788.461538462*((2.6e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 7287.714
102862.903225806*((4.65e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 1115.9095
172788.461538462*((2.6e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 3645.714
172788.461538462*((2.6e-11*P + 1.0)**0.8 - 1.0)*exp(9.2e-9*T**2 + 1.7e-5*T) - 7287.714

In [3]:
import pandas as pd
from IPython.display import display

df = pd.DataFrame(total_results, columns=columns)
for p in polys:
    df[str(p)] = pd.to_numeric(df[str(p)])
multi_df = df.set_index(['phase_type', 'site_ratios', 'constituent_array', 'parameter_order'])
display(multi_df)


system phase_name parameter_value T*log(1.0e-5*P) T*log(T) log(T) T**(-30) T**(-29) T**(-28) T**(-27) ... T**21 T**22 T**23 T**24 T**25 T**26 T**27 T**28 T**29 1
phase_type site_ratios constituent_array parameter_order
solid (1.0, 3.0) ((VA,), (VA,)) 0 (CO, NI) BCC_A2 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
liquid (1.0,) ((A,),) 0 (CO, NI) LIQUID -7.3267e-22*T**7 - 5.78266666666667e-8*T**3 - ... 0.0 -21.862033 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 4849.556000
solid (1.0, 1.0) ((A,), (VA,)) 0 (CO, NI) FCC_A1 -2.89133333333333e-8*T**3 - 0.0004424565*T**2 ... 0.0 -10.931017 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -2600.775833
(1.0, 3.0) ((A,), (VA,)) 0 (CO, NI) BCC_A2 -2.89133333333333e-8*T**3 - 0.0004424565*T**2 ... 0.0 -10.931017 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1345.570833
((A, VA), (VA,)) 0 (CO, NI) BCC_A2 -35.045*T + 96765 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 96765.000000
(1.0, 0.5) ((A,), (VA,)) 0 (CO, NI) HCP_A3 -2.89133333333333e-8*T**3 - 0.0004424565*T**2 ... 0.0 -10.931017 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -2814.570833
complex (0.5, 0.5, 3.0) ((A,), (VA,), (VA,)) 0 (CO, NI) BCC_B2 -0.2875*T + 25867.5 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 25867.500000
((VA,), (A,), (VA,)) 0 (CO, NI) BCC_B2 -0.2875*T + 25867.5 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 25867.500000
liquid (1.0,) ((A,),) 0 (CO, NI) LIQUID -1.27439333333333e-21*T**7 - 0.000537855555555... 0.0 -21.610667 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1380.564556
solid (1.0, 1.0) ((A,), (VA,)) 0 (CO, NI) FCC_A1 -0.000806783333333333*T**2 - 10.866*T*log(T) +... 0.0 -10.866000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -5503.302333
(1.0, 3.0) ((A,), (VA,)) 0 (CO, NI) BCC_A2 -0.000806783333333333*T**2 - 10.866*T*log(T) +... 0.0 -10.866000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1145.760333
((A, VA), (VA,)) 0 (CO, NI) BCC_A2 -0.22789*T + 24593.23 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 24593.230000
(1.0, 0.5) ((A,), (VA,)) 0 (CO, NI) HCP_A3 -0.000806783333333333*T**2 - 10.866*T*log(T) +... 0.0 -10.866000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -4980.302333
complex (0.5, 0.5, 3.0) ((VA,), (A,), (VA,)) 0 (CO, NI) BCC_B2 -6.7374925*T + 28302.71 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 28302.710000
((A,), (VA,), (VA,)) 0 (CO, NI) BCC_B2 -6.7374925*T + 28302.71 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 28302.710000
liquid (1.0,) ((A, B),) 0 (CO, NI) LIQUID 1331/2 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 665.500000
solid (1.0, 1.0) ((A, B), (VA,)) 0 (CO, NI) FCC_A1 0.63145*T - 400 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -400.000000
(1.0, 3.0) ((A, B), (VA,)) 0 (CO, NI) BCC_A2 1000 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1000.000000
(1.0, 0.5) ((A, B), (VA,)) 0 (CO, NI) HCP_A3 -0.1925*T - 810 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -810.000000
complex (0.5, 0.5, 3.0) ((A,), (B,), (VA,)) 0 (CO, NI) BCC_B2 -0.832*T + 1932.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1932.000000
((B,), (A,), (VA,)) 0 (CO, NI) BCC_B2 -0.832*T + 1932.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1932.000000
(0.75, 0.25, 1.0) ((B,), (A,), (VA,)) 0 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A,), (B,), (VA,)) 0 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A, B), (A,), (VA,)) 0 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A, B), (B,), (VA,)) 0 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A, B), (A,), (VA,)) 1 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A, B), (B,), (VA,)) 1 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((*,), (A, B), (VA,)) 0 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
1 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A, B), (*,), (VA,)) 0 (CO, NI) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
solid (1.0, 0.5) ((A,), (VA,)) 0 (AL, CR) HCP_A3 -2.46201666666667e-7*T**3 + 0.000315725*T**2 -... 0.0 -12.818000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -5068.714000
complex (0.5, 0.5, 3.0) ((A,), (VA,), (VA,)) 0 (AL, CR) BCC_B2 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((VA,), (A,), (VA,)) 0 (AL, CR) BCC_B2 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
liquid (1.0,) ((A, B),) 0 (AL, CR) LIQUID -14500 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -14500.000000
1 (AL, CR) LIQUID -5500 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -5500.000000
solid (1.0, 1.0) ((A, B), (VA,)) 0 (AL, CR) FCC_A1 3*T - 22950 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -22950.000000
(1.0, 3.0) ((A, B), (VA,)) 0 (AL, CR) BCC_A2 5*T - 27450 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -27450.000000
complex (0.5, 0.5, 3.0) ((A,), (B,), (VA,)) 0 (AL, CR) BCC_B2 -1000 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1000.000000
((B,), (A,), (VA,)) 0 (AL, CR) BCC_B2 -1000 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1000.000000
(0.75, 0.25, 1.0) ((B,), (A,), (VA,)) 0 (AL, CR) L12_FCC -1245 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1245.000000
((A,), (B,), (VA,)) 0 (AL, CR) L12_FCC -1245 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -1245.000000
((A, B), (A,), (VA,)) 0 (AL, CR) L12_FCC -2490.00000000000 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -2490.000000
((A, B), (B,), (VA,)) 0 (AL, CR) L12_FCC -2490.00000000000 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -2490.000000
((A, B), (A,), (VA,)) 1 (AL, CR) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A, B), (B,), (VA,)) 1 (AL, CR) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((*,), (A, B), (VA,)) 0 (AL, CR) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
1 (AL, CR) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
((A, B), (*,), (VA,)) 0 (AL, CR) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
1 (AL, CR) L12_FCC 0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000
stoichiometric (10.0, 1.0, 2.0) ((A,), (A,), (B,)) 0 (AL, CR) AL11CR2 -9.62500345833333e-6*T**3 + 0.023521515*T**2 -... 0.0 -155.848251 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -144305.234000
(13.0, 2.0) ((A,), (B,)) 0 (AL, CR) AL13CR2 -1.12854762083333e-5*T**3 + 0.027683345*T**2 -... 0.0 -179.523206 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -151390.426000
(4.0, 1.0) ((A,), (B,)) 0 (AL, CR) AL4CR -3.56714716666667e-6*T**3 + 0.008639385*T**2 -... 0.0 -60.167910 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -67065.598000
(8.0, 5.0) ((A,), (B,)) 0 (AL, CR) AL8CR5_H -7.87289933333333e-6*T**3 + 0.018225945*T**2 -... 0.0 -158.789819 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -140835.338000
0 (AL, CR) AL8CR5_L -7.87289933333333e-6*T**3 + 0.018225945*T**2 -... 0.0 -158.789819 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -181726.838000
(9.0, 4.0) ((A,), (B,)) 0 (AL, CR) AL9CR4_H -8.45693404166667e-6*T**3 + 0.019991135*T**2 -... 0.0 -157.809297 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -130714.470000
0 (AL, CR) AL9CR4_L -8.45693404166667e-6*T**3 + 0.019991135*T**2 -... 0.0 -157.809297 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -178872.970000
(1.0, 2.0) ((A,), (B,)) 0 (AL, CR) ALCR2 -1.32263970833333e-6*T**3 + 0.002712365*T**2 -... 0.0 -37.473477 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -34741.774000
complex (8.0, 18.0, 4.0) ((A,), (A,), (B,)) 0 (AL, CR) SIGMA_SGTE -1.50988250416667e-5*T**3 + 0.036638455*T**2 -... 0.0 -252.509116 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 31918.762000
((A,), (B,), (B,)) 0 (AL, CR) SIGMA_SGTE -1.20583276666667e-5*T**3 + 0.02359327*T**2 - ... 0.0 -376.695819 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -166917.476000
(3.0, 2.0, 1.0) ((A,), (A,), (VA,)) 0 (AL, CR) AL3NI2 -4.151181875e-6*T**3 + 0.010404575*T**2 - 59.1... 0.0 -59.187387 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 21125.770000

218 rows × 66 columns


In [4]:
for system_name, system_df in df.groupby('system'):
    system_df = system_df.drop_duplicates(subset='phase_name')
    print('-')
    print('-'.join(system_name))
    print(system_df['phase_type'].value_counts().to_string())


-
AL-CO
stoichiometric    4
solid             3
complex           3
liquid            1
-
AL-CR
stoichiometric    8
complex           4
solid             3
liquid            1
-
AL-NI
solid             3
complex           3
stoichiometric    2
liquid            1
-
CO-CR
complex    3
solid      3
liquid     1
-
CO-NI
solid      3
complex    2
liquid     1
-
CR-NI
complex    3
solid      3
liquid     1

In [54]:
import numpy as np

def frac_nonzero(x):
    return np.count_nonzero(x)/np.size(x)
def fnz_var(x):
    fnz = frac_nonzero(x)
    return fnz*(1-fnz)

mdc = (multi_df.drop(columns=['system', 'phase_name', 'parameter_value'])
                .groupby(level=[0,1,2,3])
                .agg([frac_nonzero, fnz_var])
    )
#display(mdc)
mdl = (multi_df.drop(columns=['system', 'phase_name', 'parameter_value'])
                .groupby(level=[0,1,2,3])
                .apply(np.size, axis=0)
    )
display(mdl)


phase_type      site_ratios        constituent_array      parameter_order
complex         (0.5, 0.5, 3.0)    ((A,), (B,), (VA,))    0                   6
                                   ((A,), (VA,), (VA,))   0                  12
                                   ((B,), (A,), (VA,))    0                   6
                                   ((VA,), (A,), (VA,))   0                  12
                (0.75, 0.25, 1.0)  ((*,), (A, B), (VA,))  0                   6
                                                          1                   6
                                   ((A,), (B,), (VA,))    0                   6
                                   ((A, B), (*,), (VA,))  0                   6
                                                          1                   6
                                   ((A, B), (A,), (VA,))  0                   6
                                                          1                   6
                                   ((A, B), (B,), (VA,))  0                   6
                                                          1                   6
                                   ((B,), (A,), (VA,))    0                   6
                (3.0, 2.0, 1.0)    ((A,), (*,), (B, VA))  0                   1
                                   ((A,), (A,), (B,))     0                   1
                                   ((A,), (A,), (VA,))    0                   3
                                   ((A,), (A, B), (*,))   0                   1
                                   ((A,), (B,), (B,))     0                   1
                                   ((A,), (B,), (VA,))    0                   1
                (8.0, 18.0, 4.0)   ((A,), (A,), (B,))     0                   2
                                   ((A,), (B,), (B,))     0                   2
                                   ((B,), (A,), (A,))     0                   1
                                   ((B,), (B,), (A,))     0                   1
liquid          (1.0,)             ((A,),)                0                   9
                                   ((A, B),)              0                   6
                                                          1                   5
                                                          2                   2
                                                          3                   2
                                                          4                   1
solid           (1.0, 0.5)         ((A,), (VA,))          0                  12
                                   ((A, B), (VA,))        0                   2
                (1.0, 1.0)         ((A,), (VA,))          0                   9
                                   ((A, B), (VA,))        0                   6
                                                          1                   2
                                                          2                   2
                                                          3                   1
                (1.0, 3.0)         ((A,), (VA,))          0                   9
                                   ((A, B), (VA,))        0                   6
                                                          1                   2
                                   ((A, VA), (VA,))       0                  12
                                   ((VA,), (VA,))         0                   6
stoichiometric  (0.375, 0.625)     ((A,), (B,))           0                   1
                (0.75, 0.25)       ((A,), (B,))           0                   1
                (1.0, 2.0)         ((A,), (B,))           0                   1
                (3.0, 1.0)         ((A,), (B,))           0                   1
                (4.0, 1.0)         ((A,), (B,))           0                   1
                (5.0, 2.0)         ((A,), (B,))           0                   1
                (8.0, 5.0)         ((A,), (B,))           0                   2
                (9.0, 2.0)         ((A,), (B,))           0                   1
                (9.0, 4.0)         ((A,), (B,))           0                   2
                (10.0, 1.0, 2.0)   ((A,), (A,), (B,))     0                   1
                (13.0, 2.0)        ((A,), (B,))           0                   1
                (13.0, 4.0)        ((A,), (B,))           0                   1
dtype: int64

In [50]:
df.drop_duplicates(subset=['phase_name', 'system'])['phase_type'].value_counts()


Out[50]:
complex           18
solid             18
stoichiometric    14
liquid             6
Name: phase_type, dtype: int64

In [ ]: