MemoryError caused by entering a large number of elements (more than 40) in get_entries_in_chemsys()

Hi, I’m trying to create entries with about 40–50 elements from the MP database.

Hence I used get_entries_in_chemsys with 43 elements like this:

from mp_api.client import MPRester
with MPRester('My api code') as mpr:  
    entries = mpr.get_entries_in_chemsys("Ag-Al-B-Ba-Be-Bi-Br-C-Ca-Cd-Ce-Cl-Co-Cr-Cs-Cu-F-Fe-I-K-La-Li-Mg-Mn-Mo-N-Na-Ni-O-P-Pb-Rb-S-Sc-Se-Si-Sr-Te-Ti-V-Y-Zn-Zr")

However, after running the code for about 30 minutes, it stopped with a memory error like this:

I found that it worked well with small elements (20 or less), but when I applied a lot of elements (40 or more), I got a memory error.

If you have a good solution, could you please suggest it?
Best regards

I partially resolved the MemoryError in ‘get_entries_in_chemsys()’ by systematically extracting chemical systems that can be formed from combinations of elements, such as [A], [A-B], [A-B-C], one at a time, and then utilizing them in conjunction with ‘get_entries()’.

Here’s the code:

from mp_api.client import MPRester
import itertools

ele_combi = "Ag-Al-B-Ba-Be-Bi-Br-C-Ca-Cd-Ce-Cl-Co-Cr-Cs-Cu-F-Fe-I-K-La-Li-Mg-Mn-Mo-N-Na-Ni-O-P-Pb-Rb-S-Sc-Se-Si-Sr-Te-Ti-V-Y-Zn-Zr"


def get_entries_in_chemsys(elements):
    # create a generator that yields combinations of elements
    elements_set = set(elements.split("-"))
    for i in range(len(elements_set)):
        for els in itertools.combinations(elements_set, i + 1):
            a = "-".join(sorted(els))
            b = a.split("-")
            if len(b) <= 4:
                c = '-'.join(b)
                yield c

all_entries=[]
with MPRester('My API code') as mpr:
    # loop over the generator and get entries for each combination
    for chemsys in get_entries_in_chemsys(ele_combi):
        print(chemsys)
        entries = mpr.get_entries(chemsys,additional_criteria={"thermo_types": ["GGA_GGA+U"]})
        all_entries.extend(entries)
        print(len(all_entries))

However, this method is quite slow and time-consuming.
(This seems quite computationally inefficient.)

If you have any other good ideas, please help!

I finally resolved the issue by extracting all MP data into individual entries and subsequently filtering out only those entries relevant to the specific elemental combinations I intended to analyze.