Convert query result directly to ase Atoms objects?

If you are working with plain requests to use the NOMAD API, this would be an example retrieving a single system and turning it into ASE:

import requests
from ase import Atoms

base_url = 'http://nomad-lab.eu/prod/v1/api/v1'
response = requests.post(
    f'{base_url}/entries/archive/query',
    json={
        'pagination': {
            'page_size': 1
        },
        'required': {
            'run': {
                'system[-1]': {
                    'atoms': '*'
                }
            }
        }
    })
response_json = response.json()
nomad_atoms = response_json['data'][0]['archive']['run'][0]['system'][-1]['atoms']
atoms = Atoms(
    symbols=nomad_atoms['labels'],
    positions=nomad_atoms['positions'],
    cell=nomad_atoms['lattice_vectors'],
    pbc=nomad_atoms['periodic']
)

print(atoms)

If you want to work with the nomad-lab Python package, this could work for you:

from ase import Atoms
from nomad.client import ArchiveQuery

query = ArchiveQuery(
    required={
        'run': {
            'system[-1]': {
                'atoms': '*'
            }
        }
    })

result = query.download(1)[0]
nomad_atoms = result.run[0].system[-1].atoms
atoms = Atoms(
    symbols=nomad_atoms.labels,
    positions=nomad_atoms.positions.m,
    cell=nomad_atoms.lattice_vectors.m,
    pbc=nomad_atoms.periodic
)

print(atoms)

Tested this with the 1.1.x preview version, see here for install instructions.

Once someone gets to it, we can add a to_atoms function the class behind result.run[0].system[-1].atoms.