Suppress printing of elasticity data using MPRester.query from pymatgen

I would like to obtain all of the available elasticity data from Materials Project. When I run the code below as a script, all of the data prints to the terminal. How can I suppress it from printing?

import pymatgen as pmg

mpr = pmg.MPRester("MY_API_KEY")
elastic_data = mpr.query({"elasticity":{"$exists": True}},
						 properties=["task_id", "pretty_formula", "elasticity"]

I’m sure someone else will be able to tell you what the root cause of this is, however I have found that setting mp_decode = False in the query function (the default is True) suppresses this and is fine as long as you are happy with a raw Python dict as the output.


Hi @sally008, I can’t reproduce your issue. The following produces no output for me:

import pymatgen as pmg
mpr = pmg.MPRester()
elastic_data = mpr.query(
    {"elasticity":{"$exists": True}},
    properties=["task_id", "pretty_formula", "elasticity"])
# no output

Perhaps check your pymatgen version (print(pmg.__version__))? The latest is 4.7.4.

1 Like

That worked. Thank you!

1 Like

I just checked - I have version 4.7.2. I’ll update and see if that fixes my problem also!

I think the issue may be related to this other post on the forum. See my comment there. It sounds like the printing of data for you was part of an error raised.

1 Like