<jupyter_start><jupyter_text>Find the best substrate for BiFeO3Let's find the best substrate for a Bismuth Ferrate.<jupyter_code>from pymatgen.matproj.rest import MPRester
mpr = MPRester()
film = mpr.get_structure_by_material_id("mp-645159")<jupyter_output><empty_output><jupyter_text>Next, we need to get the elastic tensor<jupyter_code>from pymatgen.analysis.elasticity.elastic import ElasticTensor
elac = mpr.query({"material_id": "mp-645159"},['elasticity'])[0]
tensor = ElasticTensor.from_voigt(elac['elasticity']['elastic_tensor'])
tensor<jupyter_output><empty_output><jupyter_text>Let's get a list of substrates to consider. Materials Project has collected a set of the most accessible substrates and their corresponding MPids<jupyter_code>mpr.get_all_substrates()
pot_substrates = [mpr.get_structure_by_material_id(s) for s in mpr.get_all_substrates()]
print(pot_substrates[1])<jupyter_output>Full Formula (Al2 N2)
Reduced Formula: AlN
abc   :   3.128588   3.128588   5.016955
angles:  90.000000  90.000000 120.000000
Sites (4)
  #  SP           a         b         c    coordination_no  forces
---  ----  --------  --------  --------  -----------------  ----------------------
  0  N     0.666667  0.333333  0.880713                  4  [0.0, 0.0, 0.0007832]
  1  N     0.333333  0.666667  0.380713                  4  [0.0, 0.0, 0.0007832]
  2  Al    0.666667  0.333333  0.499287                  4  [0.0, 0.0, -0.0007832]
  3  Al    0.333333  0.666667  0.999287                  4  [0.0, 0.0, -0.0007832]<jupyter_text>Next we need to initialize the substrate analyzer<jupyter_code>from pymatgen.analysis.substrate_analyzer import SubstrateAnalyzer
sa = SubstrateAnalyzer()<jupyter_output><empty_output><jupyter_text>The analyzer can be used to calculate matches between a substrates and films<jupyter_code>all_matches = []
for substrate in pot_substrates[:10]:
    matches = list(sa.calculate(substrate,film,tensor,lowest=True))
    for m in matches:
        m['composition'] = str(substrate.composition.reduced_formula)
    all_matches.extend(matches)
len(all_matches)<jupyter_output><empty_output><jupyter_text>Let's plot the matches<jupyter_code>%matplotlib inline
from matplotlib import pyplot as plt

for i in all_matches:
    plt.scatter(i['elastic_energy'],i['match_area'])
plt.xlabel("Elastic Energy (eV)")
plt.ylabel(r"Matching Area ($\AA^2$)")
plt.xlim(0,0.005)
plt.show()<jupyter_output><empty_output><jupyter_text>Our previous analysis shows that the lower left corner is preferred. So let's look at matches with matching area <<jupyter_code>for m in all_matches:
    if m['match_area'] < 50.0 and m['elastic_energy'] < 0.002:
        print("Material: {} Substrate Face: {}  Film Direction: {}  Strain: {}".format(m['composition'],
                                                                                      m['sub_miller'],
                                                                                      m['film_miller'],
                                                                                      m['strain']))<jupyter_output>Material: CeO2 Substrate Face: [0, 1, 0]  Film Direction: [1, 0, -1]  Strain: 0.012856399831028797
Material: GaAs Substrate Face: [1, 0, 0]  Film Direction: [1, 0, -1]  Strain: 0.018005629745282737
Material: DyScO3 Substrate Face: [0, 0, 1]  Film Direction: [0, 0, 1]  Strain: 0.006456864634338208
Material: DyScO3 Substrate Face: [0, 1, 0]  Film Direction: [0, 1, 0]  Strain: 0.011114725727691326
Material: DyScO3 Substrate Face: [1, 0, 0]  Film Direction: [1, 0, 0]  Strain: 0.006888529056243525
Material: GaP Substrate Face: [0, 1, 0]  Film Direction: [1, 0, -1]  Strain: 0.010095340220019764
{'fraction_non_alphanumeric': 0.1255446623093682, 'fraction_numerical': 0.10157952069716776, 'mean_word_length': 2.919957310565635, 'pattern_counts': {'":': 1, '<': 30, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '554072', 'license': 'BSD-3-Clause-LBNL', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1251, 'n_words': 306, 'path': 'pymatgen/Epitaxial Analysis.ipynb', 'repo_name': 'materialsproject/workshop-2017', 'size': '3672'}