How to exclude the certain elements

I am considering to extract the Li-containing materials from materialsproject database, by using the
.get_dataframe(criteria={“nelements”: {"$gt": 2},“nelements”: {"$lt": 5},“elements”:{"$in":[“Li”]},

How could I exclude the transition metal-containing materials?

Best Wishes
Bo Xiao

Hey Bo,

You can use MongoDB $nin https://docs.mongodb.com/manual/reference/operator/query/nin/

You’d place this inside the elements query as you have done for $in. You can get the list of transition metal elements in pymatgen by iterating over elements and passing this into your query:

transition_metals = [pmgel for pmgel in element_strs if Element(pmgel).is_transition_metal]
# then use $nin: [transition_metals]

See the pymatgen element documentation https://pymatgen.org/_modules/pymatgen/core/periodic_table.html for more details on using attributes like .is_transition_metal etc.

Alternatively, you can get all the Li materials from the data retrieval and then filter them by whether there is a transition metal element present.

If you run into problems doing either of these please let us know and post your code here, and we can help troubleshoot!

Thanks,
Alex

1 Like