Convert query result directly to ase Atoms objects?

Is it possible to convert the a nomad query result directly to an ase.Atoms object or do I have to build it myself? Are there examples?

Edit: I mean one structure of one run. (And looping through them.)

There is not build in function that would give you an ase atoms object at the moment. I can see that this would be useful: see System links and ASE atoms for results section (#1074) · Issues · nomad-lab / nomad-FAIR · GitLab

It should not be too hard to produce an ase.Atoms object as you typically need a list of atom label or order numbers, positions, lattice vectors, and periodicity. You’ll find these information in the various structure flavours found in results.properties.structure (recommended). Or if you are more interested in the original system produced by the simulation run.system.atoms. Both these sections give you all the 4 parameters needed to construct an ase.Atoms object.

1 Like

Thanks, that was my backup plan. Just wanted to check that I didn’t miss a feature.

I run into similar issue also recently when I was looking how to easily convert NOMAD entries into ase. It looks like ase claims it can read the nomad json Format Specific Options — ASE documentation. Unfortunately, it seems this was not updated to some metainfo syntax updates and is still limited to some old 0.10.x version

I wasn’t even aware the ASE contained something like this. We can try and look into it and contribute to the ASE project here. Thanks for the hint.

Hi, Did anyone every figure out or write a solution for this?

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.