Retrieve Data from Lists of Specific Elements

I’d like to retrieve data for all binary, ternary, etc. compounds whose elements belong to specific lists (i.e., excluding all other elements). For example, how do I retrieve data for a binary compound made of elements from groups 1 and 2 in the Periodic Table? That is, one element has to belong to group 1 and the other from group 2, and they can’t belong to any group other than 1 and 2. Other examples:

  • A binary compound with both elements from group 3.
  • A ternary compound with elements from groups 1, 3, and 4.
  • A ternary compound with elements from groups 2, 2, and 5 (i.e., two different elements must be from the same group 2).

The Python script looks something like this:

criteria = {"nelements": {"$eq": 2}, "elasticity": {"$exists": True}, "spacegroup.number": {"$exists": True}, "band_gap": {"$exists": True}, "elements": {"$in": ???, "$nin": ???}}

results = m.query(criteria=criteria, properties=properties)

The ??? indicate lists, but that I’m not sure if it’s correct. I tried a few things, but I’m not able to include/exclude elements as needed.

Thank you.

P.S.: The number of elements does need to be a strict criterion. For example, I could use "nelements": {"$lte": 4} and specify that the elements must belong to groups 1 and 4 only.


The most flexible way to do this is to use the chemsys field for querying. You would include an entry of the form

{"chemsys": {"$in": ["Be-Li", "Be-Na", ...]}}

to your criteria mapping (note that nelements becomes unnecessary). It is up to you to generate the list of chemical systems and be sure the elements of each are alphabetically sorted. The sorting is necessary because we index all materials by chemsys value for efficient querying by exact string matching.

You can use the pymatgen.core.periodic_table module to help generate such lists because a pymatgen Element knows its group, etc. I’ve posted some example code here to demonstrate this.


That’s great! Thanks a lot! My somewhat naïve solution was to query all compounds with a given number of elements (and other criteria), and then filter the results only using the ones I was interested in (e.g., only metals and metalloids, and from selected groups).