Download specific raw files from NOMAD repository with Python request/post

Good evening,

I’m having trouble understanding how to download specific raw files using the python API.
I’m aware of the previous threads on this topic:

Now, I did manage to download the entire, zipped, raw directory (example1 below) and get the path where the specific file I’m looking for is (example2 below). What I’m missing is how to combine the two things, i.e. how to get a specific raw file through the python api without downloading the whole zipped folder. The naive attempt I made (example3) does not work (404, file not found).

Many Thanks,

Gabriele

+++example1++++++++++++++++++++++++++++++++++
base_url = ‘NOMAD API - Swagger UI
for mat in response_json[‘data’]: #response from query on {base_url}/entries/query
string=base_url+“/entries/”+mat[‘entry_id’]+“/raw?compress=True”
resp2=requests.get(string,stream=True)
filename=mat[‘entry_id’][3:-1]+“.zip”
open(filename,“wb”).write(resp2.content)
+++++++++++++++++++++++++++++++++++++++++

+++example2+++++++++++++++++++++++++++++++
base_url = ‘NOMAD API - Swagger UI
for mat in response_json[‘data’]: #response from query on {base_url}/entries/rawdir/query
for ff in mat[‘files’]:
print(ff[‘path’])
++++++++++++++++++++++++++++++++++++++++++

+++example3+++++++++++++++++++++++++++++++++
base_url = ‘NOMAD API - Swagger UI
for mat in response_json[‘data’]:
for fil in mat[‘files’]:
if “CONTCAR” in fil[‘path’]: #resp. from {base_url}/entries/rawdir/query with “program_name’:‘VASP’”
#string=base_url+“/entries/”+mat[‘entry_id’]+‘/’+fil[‘path’] #this doesnt work, too
string=base_url+“/entries/”+fil[‘path’]
resp2=requests.get(string,stream=True)
filename=mat[‘entry_id’][3:-1]+“.vasp”
open(filename,“wb”).write(resp2.content)
++++++++++++++++++++++++++++++++++++++++++++

You can use this endpoint to download a file from an entry: /entries/{entry_id}/raw/{path}. Please not path here is relative to the entries directory. For examples

https://nomad-lab.eu/prod/v1/api/v1/entries/zlbgPUoF2Ll2jiZxwvldBdYSRaga/raw/INCAR.gz

You can also use this endpoint to download a file from an upload: /uploads/{upload_id}/raw/{path}. But now you need the full path to the file, i.e. the path relative to the root of the upload. Example:

https://nomad-lab.eu/prod/v1/api/v1/uploads/_yRtoH8rSim9du20z2XdmQ/raw/nomad_upload_thread_1/aflow_engines-mag_special/runs_2011-08-25-10-38-51/2011-6-3-19-10-16_7466_3019/relax1/INCAR.gz
1 Like