pycalphad phase filter

Some sample code that removes phases that have sublattices with only inactive components from the phase list

The database loaded is a Al-Co-Cr-Ni database. We have defined components that are only Al-Ni-Co (excluding Cr). The goal is to filter out phases that are invalid because they have sublattices that contain Cr


In [13]:
from pycalphad import Database
from pycalphad.tests.datasets import ALCOCRNI_TDB

dbf = Database.from_string(ALCOCRNI_TDB, fmt='tdb')

In [14]:
comps = ['AL', 'NI', 'CO', 'VA'] # missing CR
phases = [phase for phase in dbf.phases.keys() if all(
         len(set(comps).intersection(subl)) > 0 for subl in dbf.phases[phase].constituents)]

In [15]:
print('Phases included: {}\n'.format(phases))
print('Phases excluded: {}'.format(dbf.phases.keys()-set(phases)))


Phases included: ['BCC_B2', 'AL13CO4', 'AL3NI2', 'L12_FCC', 'AL9CO2', 'AL3CO', 'HCP_A3', 'AL3NI5', 'AL5CO2', 'LIQUID', 'AL3NI1', 'FCC_A1', 'BCC_A2']

Phases excluded: {'AL8CR5_L', 'SIGMA_SGTE', 'AL9CR4_H', 'AL11CR2', 'ALCR2', 'AL8CR5_H', 'AL9CR4_L', 'AL4CR', 'AL13CR2'}

In [16]:
print('Constituents of excluded phases:')
for ph in dbf.phases.keys()-set(phases):
    print('{:10}: {}'.format(ph, dbf.phases[ph].constituents))


Constituents of excluded phases:
AL8CR5_L  : (frozenset({'AL'}), frozenset({'CR'}))
SIGMA_SGTE: (frozenset({'NI', 'AL', 'CO'}), frozenset({'NI', 'AL', 'CO', 'CR'}), frozenset({'CR'}))
AL9CR4_H  : (frozenset({'AL'}), frozenset({'CR'}))
AL11CR2   : (frozenset({'AL'}), frozenset({'AL'}), frozenset({'CR'}))
ALCR2     : (frozenset({'AL'}), frozenset({'CR'}))
AL8CR5_H  : (frozenset({'AL'}), frozenset({'CR'}))
AL9CR4_L  : (frozenset({'AL'}), frozenset({'CR'}))
AL4CR     : (frozenset({'AL'}), frozenset({'CR'}))
AL13CR2   : (frozenset({'AL'}), frozenset({'CR'}))