<jupyter_start><jupyter_text>Materials API - Exercise 2: Using the MPRester and Pymatgen to Find Materials With Exotic Mechanical PropertiesThe tetragonal SiO$_2$ polymorph $\alpha$-cristobalite is one of the very few crystalline materials known to have a negative average Poisson's ratio, which means that its cross-section expands under tensile strain rather than contracting. This property can be extremely useful in a variety of applications such as scratch-resistant coatings and high-toughness ceramics. Why does $\alpha$-cristobalite exhibit this property while other materials do not? The prevailing hypothesis is that $\alpha$-cristobalite's negative Poisson's ratio is a result of its crystal structure. If that's the case, then perhaps we can find other materials with this exotic property by looking for materials with similar structures and then calculating their Poisson's ratios.  Step 1: Retrieve the structure of $\alpha$-cristobaliteFirst, we should find the ground state structure for $\alpha$-cristobalite, which has the spacegroup $P4_12_12$ [92]. Remember, stable materials have *low* energy above hull (`energy_above_hull`)._Hint: Query using `chemsys_formula` and `spacegroup_number` for the desired compound and then select the one with the lowest `energy_above_hull` if there are multiple results. Consider using the `sort_field` and `ascending` input parameters of the query method._<jupyter_code># Your code here
from mp_api.matproj import MPRester

with MPRester("<your API key>") as mpr:
    ac = mpr.query(____)

ac_structure = ____
ac_mpid = ____<jupyter_output><empty_output><jupyter_text>Step 2: Build a structure comparison engine and test it outThe code below creates a structure matcher object that can be used to compare if two structures are simlar (loose tolerances = similar, tight tolerances = identical). Please verify that the structure matcher works for identical structure by comparing the structure of AC with itself. _Hint: Replace  with the two structures you want to compare, separated by a comma._<jupyter_code>##### Don't edit code below #####

from pymatgen.analysis.structure_matcher import StructureMatcher
from pymatgen.analysis.structure_matcher import FrameworkComparator
# This line initializes our comparator. Please don't play with its tolerances until after you are done
comparison_engine = StructureMatcher(ltol=.2, stol=.5, angle_tol=10, primitive_cell=True, 
                                     scale=True, attempt_supercell=True, 
                                     comparator=FrameworkComparator())
##### Don't edit code above #####
print(comparison_engine.fit(ac_structure, ac_structure))<jupyter_output><empty_output><jupyter_text>We know that the high-temperature phase of cristobalite, $\beta$-cristobalite [(mp-546794)](https://materialsproject.org/materials/mp-546794/), has a very similar structure to $\alpha$-cristobalite. Let's see if the structure matcher agrees. Please retreive the structure for `mp-546794` and then compare it with our prototype structure. _Hint: Use the `get_structure_by_material_id` method of the `MPRester`. Also, no need to re-initialize the structure matcher, just call it's `fit` method again._<jupyter_code># Your code here
with MPRester("<your API key>") as mpr:
    bc_structure = ____
    
print(comparison_engine.fit(bc_structure, ac_structure))<jupyter_output><empty_output><jupyter_text>Just to make sure we haven't increased the tolerances too much, please try it against a random compound to make sure it's not matching dissimilar structures._Hint: "mp-4991" is a good random MPID you can use_<jupyter_code># Your code here
with MPRester("<your API key>") as mpr:
    bc_structure = ____
    
print(comparison_engine.fit(bc_structure, ac_structure))<jupyter_output><empty_output><jupyter_text>Step 3: Get a set of candidate structures to compareNow that we have our comparator, we need some candidates to screen! Imagine that we have an experimental colleague, <NAME>, who is an expert at synthesizing vanadate compounds. We have a hunch that some of the vanadates coming out of Dr. Tsarpinski's lab might have similar structures to $\alpha$-cristobalite and therefore might have negative Poisson's ratios. Let's see if we're right:For our search, we want to start with a set of structures that are:* Computationally tractable, so not too many sites (i.e `nsites = (0, 50)` is a good range)* Not too unlikely to be synthesizable (energy above hull <=100 meV/atom, i.e. `energy_above_hull = (0.0, 0.1)`)* Have a "vanadate" composition, i.e. `chemsys_formula = "*V3O8"`Construct and execute a query to get the `structure`, `material_id`, and `formula_pretty` for all materials that match these criteria:<jupyter_code># Your code here
with MPRester("<your API key>") as mpr:
    
    vanadate_ids = [entry.material_id for entry in mpr.query(____)]
    
    vanadates = mpr.query(____)<jupyter_output><empty_output><jupyter_text>Step 4: Screen the vanadates for similar structures to $\alpha$-cristobalite and then check if our hypothesis is valid by querying for their Poisson's ratios. Now that we have a list of vanadates, let's screen it for similar structures. After we have the similar structures, make one final query to the Materials API to retrieve the `formula_pretty` and `homogeneous_possion` property for each one. _Hint: Create an empty list for matches and then iterate through the vanadate entries with a for loop. If its structure is similar to $\alpha$-cristobalite, append its `material_id` to a list of matches. After you have a match list, query the Materials API for entries with a `material_id` that is in your matches._<jupyter_code># Your code here
matches = []
for entry in vanadates:
    if comparison_engine.fit(ac_structure, entry.structure):
        ____

with MPRester("<your API key>") as mpr:
    elastic_data = mpr.query(____)

for e in elastic_data:
    print(e.material_id, e.formula_pretty, e.homogeneous_poisson)<jupyter_output><empty_output>