Examples
Use the Quickstart Guide to launch the NIM before running the following examples.
For the request format and required atomic data fields, refer to API Reference.
Install the Python libraries needed for the examples on this page:
Using ASE for Structure I/O
Use the NIM for BGR to process a chemistry dataset by combining it with the I/O
capabilities from the Atomic Simulation Environment (ASE). With a file
structures.extxyz containing multiple structures in ASE
extended XYZ format,
and NIM for BGR running at http://localhost:8000/v1/infer, the
following script runs batched optimization. Refer to the example
structures.extxyz file.
The container-wide ALCHEMI_NIM_PBC setting determines the accepted request
form. In the default periodic mode, each ASE Atoms object must define a cell,
and the request must include cell. To process isolated molecules, first
launch a separate container with a compatible model and
ALCHEMI_NIM_PBC=false, then ensure that each request omits cell. Setting
Atoms.pbc to false does not switch the running container to non-periodic
mode. Refer to the AIMNet2 launch example.
The following Python script reads structures from structures.extxyz,
performs batched optimization, and produces a structures_opt.extxyz file with
optimized structures.
Concurrent Requests
The inference API accepts multiple concurrent requests; the server processes them and returns responses in order. There is no dedicated async/polling API. Achieve concurrent behavior by issuing multiple requests and waiting on the responses.
Concurrent behavior example (Python)
Asynchronous example (Python)
Use asyncio with an async HTTP client to
send multiple inference requests without blocking. Install aiohttp
(for example, pip install aiohttp) and run the following:
Partial Optimization With Active Masks
Freeze specific atoms during optimization by using the active_mask field: