materialsproject / MPContribs

Platform for materials scientists to contribute and disseminate their materials data through Materials Project
https://mpcontribs.org
MIT License
35 stars 20 forks source link

`tables.get_entries()` is returning tables from a different project #1223

Closed Andrew-S-Rosen closed 2 years ago

Andrew-S-Rosen commented 2 years ago
from mpcontribs.client import Client
project = "qmof"
apikey = "MyAPIKey"
client = Client(apikey=apikey, host="contribs-api.materialsproject.org")
data = client.tables.get_entries().response().result['data']
print(data[0])

The above will print data from an entirely different project. Am I setting this up wrong?

Andrew-S-Rosen commented 2 years ago

Ooops! I never actually specify the project anywhere. Trying to figure that out now...

tschaume commented 2 years ago

You can use the project argument to the client to initialize it only for your project.

On Sat, Aug 6, 2022, 9:26 AM Andrew S. Rosen @.***> wrote:

Ooops! I never actually specify the project anywhere. Trying to figure that out now...

— Reply to this email directly, view it on GitHub https://github.com/materialsproject/MPContribs/issues/1223#issuecomment-1207242742, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKW5FALYMW2XXXS3Z24U33VX2G35ANCNFSM55Y7QVBA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

tschaume commented 2 years ago

PS I might have to double check this for the tables endpoint. The sure way to only get your tables is to first query the contributions and get a list of table IDs.

On Sat, Aug 6, 2022, 9:30 AM Patrick Huck @.***> wrote:

You can use the project argument to the client to initialize it only for your project.

On Sat, Aug 6, 2022, 9:26 AM Andrew S. Rosen @.***> wrote:

Ooops! I never actually specify the project anywhere. Trying to figure that out now...

— Reply to this email directly, view it on GitHub https://github.com/materialsproject/MPContribs/issues/1223#issuecomment-1207242742, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKW5FALYMW2XXXS3Z24U33VX2G35ANCNFSM55Y7QVBA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Andrew-S-Rosen commented 2 years ago

Thanks! That makes sense. My only follow-up question is: do I just iterate through client.get_structure() or client.get_table() for each ID? I don't want to stress our servers out if I loop through 20k of these, but I'm not sure how to pass a list of IDs rather than a single ID.

Andrew-S-Rosen commented 2 years ago

I got it I think. I am doing as follows. Not sure if it's the most efficient.

from mpcontribs.client import Client
from pymatgen.core import Structure

apikey = "MyAPIKey"
client = Client(apikey=apikey,host="contribs-api.materialsproject.org")

qmof_entries = client.contributions.get_entries(
    project="qmof", _fields=["identifier", "data", "structures"]
).result()["data"]

structure_ids = [entry['structures'][0]['id'] for entry in qmof_entries]
structure_data = client.structures.get_entries(
    id__in=structure_ids, _fields=["name", "cif"]
).result()["data"]

structures = [Structure.from_str(entry['cif'],fmt='cif') for entry in structure_data]