Metadata-Version: 2.4
Name: mintatlas
Version: 1.0.2
Summary: Read-only Python and command-line access to MINT-ATLAS magnetic interaction data
License-Expression: MIT
Project-URL: Homepage, https://mintatlas.org
Project-URL: Repository, https://github.com/mintatlas-org/mintatlas
Project-URL: Issues, https://github.com/mintatlas-org/mintatlas/issues
Project-URL: Changelog, https://github.com/mintatlas-org/mintatlas/blob/HEAD/CHANGELOG.md
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests<3,>=2.32.4
Provides-Extra: tables
Requires-Dist: pandas>=2.0; extra == "tables"
Provides-Extra: release
Requires-Dist: build>=1.2; extra == "release"
Requires-Dist: twine>=6; extra == "release"
Dynamic: license-file

# mintatlas

[Website](https://mintatlas.org) |
[PyPI](https://pypi.org/project/mintatlas/) |
[GitHub](https://github.com/mintatlas-org/mintatlas) |
[Issues](https://github.com/mintatlas-org/mintatlas/issues)

Python and command-line access to [MINT-ATLAS](https://mintatlas.org), a database
of atomistic magnetic interactions.

Search materials, retrieve structures and magnetic interaction parameters,
access precomputed AMS and Fourier-transformed exchange J(q), and download
scientific data for further analysis.
The client provides read-only access through OPTIMADE and MINT-ATLAS extensions.
No account or API token is required for the public service.

## Installation

Python 3.10 or later is required. Install from PyPI:

```sh
pip install mintatlas
```

To upgrade an existing installation and check the command:

```sh
python -m pip install --upgrade mintatlas
mintatlas --version
mintatlas --help
```

For a reproducible installation of version 1.0.2:

```sh
python -m pip install mintatlas==1.0.2
```

The package name, Python import and command are all `mintatlas`.
Requests is the only direct runtime dependency;
the database, web server and scientific solver are not installed with the client.

## Quick start

The default service is `https://mintatlas.org`:

```sh
mintatlas info
mintatlas search --elements Fe Te
mintatlas show mi-0
mintatlas show mi-0 --fields _mintatlas_mean_field_tc_kelvin
mintatlas downloads mi-0
mintatlas download mi-0 --output mi-0.h5
```

The examples use `mi-0` as a material ID; replace it with an ID returned by your
search. A formula can match several records, so use material IDs for retrieval
and downloads. Available interaction kinds, AMS/J(q) variants and export formats are
declared by the server and may differ between materials.

## Command-line interface

```sh
mintatlas capabilities
mintatlas search --elements Fe Te
mintatlas search --formula Fe3GeTe2
mintatlas search --filter 'elements HAS "Fe" AND nsites < 20' --page-size 5
mintatlas search --elements Fe --all --fields chemical_formula_reduced _mintatlas_method
mintatlas show mi-0
mintatlas show mi-0 --fields _mintatlas_mean_field_tc_kelvin
mintatlas show mi-0 --fields _mintatlas_formula _mintatlas_mean_field_tc_kelvin
mintatlas structure mi-0
mintatlas interactions mi-0 --kind jij_scalar --unit meV --distance angstrom
mintatlas ams mi-0
mintatlas jq mi-0
mintatlas downloads mi-0
mintatlas download mi-0 --output mi-0.h5
mintatlas download mi-0 --kind jij_scalar --format csv --output mi-0.jij.csv
mintatlas download mi-0 --kind structure --format mcif --output mi-0.mcif
```

- `search` returns one **OPTIMADE JSON envelope** with `meta` and `links.next`.
  `--all` explicitly traverses all matching pages and returns a JSON list.
- Element search requires all supplied elements and allows additional elements.
  `--formula` matches the original provider formula exactly, not the standardized
  full-cell formula. Formulas may identify multiple records. For the standard
  formula use `--filter 'chemical_formula_reduced="Fe"'`.
- `capabilities` returns server-declared defaults, limits, units and schemas.
- `show` returns metadata, available AMS/J(q) variant keys, resource URLs and downloads.
- `show --fields FIELD ...` instead returns a single OPTIMADE structure resource
  with `id`, `type` and selected `attributes` (not the full material summary).
  Names are checked against the server's `/info/structures`, then sent using
  `response_fields`. Unknown names and omitted requested fields are errors;
  a returned `null` is preserved. The server may also include mandatory fields.
  This option selects OPTIMADE properties, not nested material-summary keys.
- `interactions` fetches **all rows**, never just the first page. For a large table,
  `download --kind jij_scalar --format csv` is more efficient than many JSON pages.
- `ams --variant KEY` requests an existing key returned by `show`. It does not
  compute a new spectrum or change the reference state.
- `jq --variant KEY` requests a key from `show`'s `jq_variants` list. It returns
  all signed exchange eigenvalues and the full stored path, without AMS arrays.
  Omitting `--variant` uses the server default. Requires the J(q)-enabled server.
- `download` fetches exactly one available export. Select a shared AMS/J(q) H5 by using its
  variant key as `--kind`. Inspect `downloads` for actual available formats.
  A structure export may be CIF or MCIF; request the advertised format.
  With no kind/format, the server must mark one unique default; otherwise the
  command reports an error rather than choosing a file.
- JSON is written to stdout; diagnostics and retry notices go to stderr. Redirect
  JSON with `> result.json` when desired. Downloads never overwrite existing files
  unless `--force` is supplied. Shell `>` has the shell's normal overwrite behavior.
- Exit codes: 0 success, 1 request/data/file failure, 2 argument syntax error,
  3 exhausted rate limit, 130 interrupted.

### Show a material and query Tc

Retrieve the full material summary, including metadata, available spectrum
variants and download links:

```sh
mintatlas show mi-0
```

With version 1.0.2 or later, request only the mean-field temperature field:

```sh
mintatlas show mi-0 --fields _mintatlas_mean_field_tc_kelvin
```

Example response (the numerical value depends on the server's current data):

```json
{
  "id": "mi-0",
  "type": "structures",
  "attributes": {
    "_mintatlas_mean_field_tc_kelvin": 19.686420289902046
  }
}
```

Select multiple fields by separating their names with spaces:

```sh
mintatlas show mi-0 --fields _mintatlas_formula _mintatlas_mean_field_tc_kelvin
```

The temperature is in kelvin; see [Mean-field temperature](#mean-field-temperature)
for its physical meaning. A returned `null` is not 0 K. Field selection retrieves
JSON only, without downloading H5 or recalculating the temperature. Unsupported
field names produce an error rather than an invented value.

## Python interface

Use `Client` as a context manager to release connections when finished:

```python
from mintatlas import Client

with Client() as client:
    page = client.search(elements=["Fe", "Te"], page_limit=5)
    for entry in page["data"]:
        print(entry["id"], entry["attributes"]["chemical_formula_reduced"])

    material = client.get_material("mi-0")
    structure = client.get_structure("mi-0")
    selected = client.get_structure("mi-0", response_fields=["_mintatlas_mean_field_tc_kelvin"])
    print("Mean-field temperature (K):", selected["attributes"]["_mintatlas_mean_field_tc_kelvin"])
    jij = client.get_interactions("mi-0", "jij_scalar", unit="meV", distance="angstrom")
    print(jij["columns"], jij["column_units"])
    print("Interaction rows:", len(jij["rows"]))

    ams = client.get_ams("mi-0")
    jq = client.get_jq("mi-0")
    print(jq["unit"], jq["exchange_eigenvalues_meV"])
    client.download("mi-0", "mi-0.h5")
```

Use `client.iter_materials(elements=["Fe"])` to fetch all matching structures
sequentially. `client.iter_interaction_pages("mi-0")` yields pages for incremental
processing; `get_interactions` instead returns one complete combined table.
Metadata includes units, stored/reconstructed origin and pair coverage when
provided. Errors on a later page do not return a partial table as a complete one.
An iterator may already have yielded earlier valid pages when an error occurs.

Discovery, structure-property definitions and per-material metadata are cached for the lifetime of a client.
Call `client.refresh()` after a server deployment to fetch them again on next
use. Numeric paging defaults and unit/distance defaults are not sent unless
explicitly requested. The server applies its current defaults and limits.
There are no client-side lists of material IDs, interaction kinds or formats.

### Mean-field temperature

`_mintatlas_mean_field_tc_kelvin` is the MINT-ATLAS calculated classical
scalar-exchange mean-field temperature estimate at q=0, in kelvin. It is not
an experimental Curie temperature or a full-Brillouin-zone ordering search.
`null` means no positive q=0 instability or no available calculation, not 0 K.
The CLI retrieves the server's value without recalculating it or downloading H5.

### Fourier-transformed exchange J(q)

`get_jq()` returns **eigenvalues of the scalar-exchange Fourier matrix**, not the
matrix elements and not magnon energies. The `exchange_eigenvalues_meV` array has
shape `(q_points, modes)`. Each row is sorted in ascending order and retains
negative values. The last column is the largest eigenvalue at that q point;
it is not an additional branch or a maximum over the full Brillouin zone.

`q_reduced`, `q_cartesian`, `q_distance`, `q_distance_normalized`, `q_labels`,
control points and reciprocal geometry describe the same stored path. Read
`coordinate_units` for their units. No moment normalization, reference signs,
DMI, anisotropy or field enter J(q). At identical q coordinates its values are
independent of the selected AMS reference and Hamiltonian variant. The variant
key identifies the shared stored path/container. Branch indices are eigenvalue
ranks, not tracked eigenvectors or one-to-one AMS branch assignments.

Discover the available container before downloading:

```python
from mintatlas import Client

with Client() as client:
    material = client.get_material("mi-0")
    variants = material.get("jq_variants", [])
    if not variants:
        raise RuntimeError("This material has no advertised stored J(q).")
    key = variants[0]["key"]
    jq = client.get_jq("mi-0", variant=key)
    exports = [item for item in material["downloads"]
               if item["kind"] == key and item["format"] == "h5"
               and "jq" in item.get("quantities", [])]
    if not exports:
        raise RuntimeError("No H5 export is available for this J(q) variant.")
    client.download("mi-0", "mi-0.spectrum.h5", kind=key, format="h5")
```

The spectrum H5 contains `exchange_eigenvalues_meV` alongside the AMS and q-path
arrays. The default **material H5 is not this spectrum file**. No duplicate J(q)
H5 is created. JSON can also be saved with `mintatlas jq mi-0 > mi-0.jq.json`.

The client never computes missing J(q), changes signs, or falls back to AMS when
the J(q) resource is absent. An older server may support AMS without supporting
the separate J(q) endpoint; `get_jq()` then raises `CapabilityError`. Stored-data
or geometry failures returned by the server remain explicit API errors.

### pandas integration

Install the optional `tables` extra:

```sh
python -m pip install "mintatlas[tables]"
```

```python
from mintatlas import Client, to_dataframe

with Client() as client:
    jij = client.get_interactions("mi-0", "jij_scalar", unit="meV")

frame = to_dataframe(jij)
print(frame.head())
print(frame.attrs["column_units"])
```

Table metadata, including units, is retained in `DataFrame.attrs`.

## Service configuration

The client discovers compatible API versions, resource URLs, pagination links
and download locations from the server. Unspecified parameters use server
defaults; unsupported resources or parameters produce explicit errors.

| CLI option | Python argument | Purpose |
| --- | --- | --- |
| `--base-url` | `base_url` | Service root; defaults to `https://mintatlas.org` |
| `--api-url` | `api_url` | Alternative OPTIMADE entry URL, without `/info` |
| `--timeout` | `timeout` | Connect/read timeout in seconds; default `30` |
| `--max-retries` | `max_retries` | Retries for HTTP 429/503; default `2` |
| `--trust-origin` | `trusted_origins` | Explicitly permit an additional service or file origin |

Place global CLI options before the subcommand, for example
`mintatlas --timeout 60 info`. The CLI also reads `MINTATLAS_BASE_URL` and
`MINTATLAS_API_URL`. A base URL is a site root, not a versioned API path.
By default, discovery starts at `<base_url>/optimade/info`; use `api_url` for
an alternative entry. Magnetic extensions require a service that advertises
MINT-ATLAS capabilities. No alternate route is guessed if discovery fails.

TLS certificate verification is enabled. Redirects are not automatically
followed, and resource links must stay on the configured API origin unless you
explicitly trust another origin. Such trust applies to the entire origin.

## Scientific conventions

Standard structure searches use OPTIMADE. Magnetic data, AMS, J(q) and downloads are
MINT-ATLAS extensions, not standardized OPTIMADE magnetic fields. The client
discovers their URLs from server metadata rather than constructing extension
paths. The client does not infer missing data, validate a
magnetic ground state, recalculate energies or take absolute values of spectra.
AMS reference-state information, warnings and real/imaginary results are retained
as supplied. Mean-field ordering-temperature estimates are not experimental Tc.

Use `client.capabilities()["interaction_parameters"]` for accepted units and
distance modes. The current server offers mRy/meV and lattice/angstrom;
conversion is performed by the server. CSV downloads retain the server's export
convention, currently mRy/lattice. Site/moment columns have their
own units; consult `column_units`. A full embedded simulation structure and its
standardized chemical formula are not necessarily identical to a provider's
effective-medium or thin-film display formula.

Downloading H5 requires no HDF5 library; reading it locally may require `h5py` or
another compatible reader. The client returns data and never executes it.

## Rate limits and errors

There are no tokens or login. Requests are sequential, with a minimum 2.1-second
interval within one client instance. Server admission is shared with other users;
pacing does not guarantee acceptance or coordinate separate CLI processes.

HTTP 429/503 responses get at most two retries, respecting `Retry-After` (seconds
or HTTP date) and a total retry-sleep budget of 120 seconds. If the requested wait
exceeds the budget, the error is returned instead of retrying earlier. Connection,
TLS, mid-stream transfer failures and other HTTP errors are not automatically
retried. `timeout=30` is a connect/read timeout, not an entire-operation deadline.

```python
from mintatlas import Client, MintAtlasError, RateLimitError

try:
    with Client(max_retries=0) as client:
        page = client.search(formula="Fe")
except RateLimitError as error:
    print("Wait before retrying:", error.retry_after)
except MintAtlasError as error:
    print("Request failed:", error)
```

Use one client per sequential workflow; a Client is not designed for concurrent
thread sharing. No background downloads or bulk-file operations are provided.
Server limits cannot be bypassed by changing client settings. Page sizes are not
silently clamped; an excessive request returns the server's error (403 for the
current OPTIMADE page cap).

An unadvertised extension, unit, resource or AMS/J(q) variant raises `CapabilityError`;
missing/ambiguous downloads raise `DownloadError`. Unsupported versions and
schemas fail explicitly. Older servers without capability discovery can still
serve standard OPTIMADE searches, but the client will not guess their magnetic
extension routes. A supported table with no values is different from an
unprovided resource: it remains an explicit `empty: true` table. Standard
OPTIMADE filters retain the protocol's own error/unknown-field semantics.

Downloads use a temporary file in the destination directory, check size and
SHA-256 when advertised, then publish atomically. An incomplete download leaves
no final file, and failed replacement preserves an existing file. Automatic file
names are safe ID/kind/format components, not remote Content-Disposition.
Local safety limits remain configurable (`max_json_bytes`, download `max_bytes`,
timeouts and retry budget); server declarations cannot relax them automatically.
No-overwrite publication requires a filesystem supporting hard links.

## Source code and support

The source code is available on
[GitHub](https://github.com/mintatlas-org/mintatlas). Report bugs and request
features through [GitHub Issues](https://github.com/mintatlas-org/mintatlas/issues).
Include the client version, the command or Python example, and the error message
when reporting a problem. Do not include credentials or private data.

See [MINT-ATLAS](https://mintatlas.org) for dataset descriptions and scientific
definitions, and the
[changelog](https://github.com/mintatlas-org/mintatlas/blob/HEAD/CHANGELOG.md)
for client release notes.

## License

This client software is distributed under the
[MIT License](https://github.com/mintatlas-org/mintatlas/blob/HEAD/LICENSE).
Copyright (c) 2026 Qichen Xu.
