Metadata-Version: 2.4
Name: atomeye
Version: 3.1.0
Summary: AtomEye, the atomistic configuration viewer by Ju Li, with a Python interface that works with ASE
Keywords: atomistic,visualisation,molecular dynamics,ASE,extxyz
Author: Ju Li, Futoshi Shimizu, James Kermode
Maintainer: James Kermode
License-Expression: MIT
License-File: LICENSE
License-File: extxyz/LICENSE
License-File: extxyz/libcleri/LICENSE.md
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Programming Language :: C
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Chemistry
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Topic :: Scientific/Engineering :: Visualization
Project-URL: Homepage, https://github.com/jameskermode/AtomEye
Project-URL: Issues, https://github.com/jameskermode/AtomEye/issues
Project-URL: Demo, https://jameskermode.github.io/AtomEye/
Requires-Python: >=3.9
Requires-Dist: numpy
Provides-Extra: ase
Requires-Dist: ase; extra == "ase"
Description-Content-Type: text/markdown

# AtomEye

AtomEye is a fast viewer for atomistic configurations and trajectories,
written by [Ju Li](http://li.mit.edu/Archive/Graphics/A/), with the
scripting interface and parallel rendering of AtomEye 3 by Futoshi
Shimizu. It draws large configurations as shaded spheres with its own
software renderer, and is driven by the mouse, the keyboard, typed
commands or scripts. If you use it in published work, please cite
J. Li, [Modelling Simul. Mater. Sci. Eng. 11 (2003) 173](https://doi.org/10.1088/0965-0393/11/2/305).

This fork brings it up to date. It adds Extended XYZ files, a Python
interface that works with [ASE](https://ase-lib.org), native windows on
Linux (X11 or Wayland), macOS and Windows, and a WebAssembly build that
runs in a web browser and in marimo and Jupyter notebooks.

- **Try it in your browser:** <https://jameskermode.github.io/AtomEye/>
  (a marimo notebook, with Python and ASE running in the browser too) or
  <https://jameskermode.github.io/AtomEye/app/> (the viewer alone, full
  screen; it opens your own `.xyz` files and can be installed on a tablet)
- **Download:** <https://github.com/jameskermode/AtomEye/releases>

## Download

The viewer with its Python module is on [PyPI](https://pypi.org/project/atomeye/),
for Linux and macOS (Apple silicon), and so is the notebook widget, for
any platform:

    pip install atomeye
    pip install atomeye-widget

The same wheels, and the viewer for use without Python, are on the
[releases page](https://github.com/jameskermode/AtomEye/releases).

| You want | Download | Then |
| --- | --- | --- |
| The viewer on Linux (X11) | `atomeye-linux-x86_64.tar.gz` or `-aarch64` | unpack; `./A example.xyz` |
| The viewer on Linux, Wayland without X11 | `atomeye-linux-sdl3-x86_64.tar.gz` or `-aarch64` | unpack; `./A example.xyz` |
| The viewer on Windows | `atomeye-windows-x86_64.zip` | unpack; `A.exe example.xyz` in a terminal. `atomeye-register.cmd` adds AtomEye to "Open with" for `.xyz`, `.extxyz`, `.cfg` and `.pdb` files |
| The viewer on macOS (Apple silicon) as an application | `AtomEye-macos-arm64.zip` | unpack; double-click a configuration and choose AtomEye, or drop one on the icon or the window |
| The viewer and Python module, Linux or macOS (Apple silicon) | nothing: `pip install atomeye` (or the `atomeye-…whl` for your Python and platform) | `atomeye example.xyz` |
| The notebook widget, any platform | nothing: `pip install atomeye-widget` | `from atomeye_widget import AtomEyeWidget` |

The Linux bundles need glibc 2.28 or later and carry their other
libraries with them (the X11 one uses the system's libX11 and libXext).
The macOS wheels and application are built for the macOS version of the
build machine (currently 26) and later; on older systems, build from
source. The application is not notarised by Apple: the first time, open
it with a right-click and "Open", or allow it under Privacy & Security
in System Settings. Started that way it has no terminal: use the keys
(`?` lists them); what it prints is in `~/Library/Logs/AtomEye.log`. For
the prompt, run `AtomEye.app/Contents/MacOS/A file.xyz` in a terminal.

## Using the viewer

    A config.xyz            # or .cfg, .pdb
    A traj.xyz:last         # the last frame of a trajectory
    A traj.xyz:340          # frame 340
    A cluster:run/traj.xyz  # a file on another computer, through ssh
    A https://example.org/config.xyz

(`atomeye` instead of `A` if you installed a wheel.) Start it from a
terminal: that is where commands are typed and where information is
printed.

- **Mouse:** drag to rotate, Shift- or Ctrl-drag to translate, right-drag
  or the wheel to move in and out, right-click an atom or bond for
  information about it.
- **Keyboard:** press `?` or F1 in the window for the list of shortcuts.
  A few to start with: `b` bonds, `k` colour by coordination,
  PgUp/PgDn atom size, Tab parallel or perspective projection,
  Delete/Insert next and previous frame, Alt+0…9 colour by a per-atom
  property.
- **Commands:** anything a key does can be typed at the prompt in the
  terminal, with arguments, e.g. `aux_property_coloring force0`,
  `rotate 0 0.1`, `capture_png shot.png 2000`, `resize 800 600`. Tab
  completes command names (when built with a line editor). `doc/A3.html` and `doc/atomeye.html` are Ju
  Li's manuals for AtomEye 3 and the original AtomEye.
- **Scripts:** `A -f=script.txt config.xyz` runs a file of commands, and
  `~/.A` is run at startup if it exists. For example, to start with a
  larger window, smaller atoms and bonds, and to have BackSpace go back a
  frame on keyboards without an Insert key:

      resize 800 600
      change_atom_r_ratio -2
      toggle_bond_mode
      set key->BackSpace load_config_backward
      set key->BackSpace+C load_config_first

- **Files elsewhere:** `host:path` (or `user@host:path`, with `:frame`
  after an Extended XYZ name as usual) is fetched with your own `ssh`,
  so whatever your `~/.ssh/config` sets up - keys, an agent, jump hosts -
  applies; a path is relative to your home directory there. `http://`
  and `https://` addresses are fetched with `curl`. Both work at startup
  and in `load_config`. The viewer shows a temporary copy, which
  `reload_config` (F10) fetches again. Log in with a key or an agent: a
  password can only be asked for before the viewer has started.
- **Watching a running simulation:** the command `watch` keeps showing the
  newest there is - the last frame of an Extended XYZ file, or the last
  of a numbered sequence of files - looking every second (every 10 s for
  a file elsewhere; `watch 30` for another interval, `watch off` to
  stop).
- **Drag and drop:** in the SDL3 build (the wheels, and the Windows and
  Wayland downloads), a file dropped on the window is opened.
- **Without a display:** `A -nowindow -f=script.txt config.xyz` renders
  offscreen, with any build.

## Python and ASE

The `atomeye` package (`pip install atomeye`, or `pip install .` from the source)
contains the viewer, an `atomeye` command that runs it, and a Python
module. It registers itself as an ASE viewer:

    from ase.build import bulk
    from ase.visualize import view

    atoms = bulk("Si", cubic=True) * (4, 4, 4)
    view(atoms, viewer="atomeye")

A list of `Atoms` is shown as a trajectory. Every real, integer or logical
per-atom array in `atoms.arrays` can be used for colouring and arrows.
The window stays open after Python exits.

There are two ways to drive the viewer yourself:

- `atomeye.AtomEyeProcess(atoms)` runs the viewer as a separate process,
  driven through a pipe. This is what the ASE plugin uses. It works on
  every platform, allows any number of viewers, and reports errors from
  the viewer as exceptions.
- `atomeye.AtomEyeViewer(atoms)`, or `atomeye.view(atoms)`, runs the
  viewer inside the Python process on its own thread. It adds callbacks
  when atoms are clicked and `get_visible()`, and `display()` to put a
  snapshot in a Jupyter notebook. It is not available on Windows, and
  see the platform notes below for macOS and SDL.

Both have the same command methods (`capture`, `resize`,
`aux_property_coloring`, `draw_arrows`, ...) and take `nowindow=True` to
render offscreen:

    import atomeye
    v = atomeye.AtomEyeProcess(atoms, nowindow=True)
    v.aux_property_coloring("force0")
    v.capture("forces.png")
    v.close()

### Notebook widget

`atomeye-widget` is a separate, pure-Python package in which the viewer
runs in the browser as WebAssembly, so it needs no display and no
compiled extension. It works in [marimo](https://marimo.io) (including
WASM notebooks) and Jupyter:

    from atomeye_widget import AtomEyeWidget

    w = AtomEyeWidget(atoms)          # in marimo: mo.ui.anywidget(w)
    w.frame = 5
    w.run_command("aux_property_coloring 0")

Install it with `pip install atomeye-widget`; in a notebook that runs
in the browser itself (marimo WASM, JupyterLite), with
`micropip.install("atomeye-widget")`. It is also an ASE viewer:
`view(atoms, viewer="atomeye_widget")`. See
[`wasm/python/README.md`](wasm/python/README.md), and
[`wasm/README.md`](wasm/README.md) for the WebAssembly build and for
using the viewer in a web page of your own.

### On a tablet, or as a web application

<https://jameskermode.github.io/AtomEye/app/> is the viewer filling the
screen, made for touch: drag to rotate, two fingers to translate, pinch
to move in and out, hold a finger on an atom for information about it.
The **?** button lists the keyboard shortcuts, and tapping a key there
presses it, so nothing needs a keyboard. **Image** saves or shares a
picture of the view.

- *Install it:* on an iPad choose Share, then "Add to Home Screen"; in
  Chrome or Edge (Android, desktop) choose "Install app". It then starts
  like any other application, full screen, and works offline.
- *Open a file* from the device with **Open**, or by dropping it on the
  page: Extended XYZ, CFG or PDB, gzipped or not. Several files chosen
  together are shown as a sequence, a frame each. Installed on Android,
  AtomEye is also offered when a file is shared from another application.
- *Frames:* a slider and **Play** appear when there is more than one.
- The view is drawn at the full resolution of the screen, and at a lower
  one if that proves too slow for a large configuration.
- *Open a file from the web* with **URL**, or by putting its address in
  the link: `.../app/?url=https://.../file.xyz&frame=3&commands=toggle_bond_mode`.
  Such a link can be shared; whoever follows it sees the same
  configuration. The server holding the file has to allow other sites to
  read it (CORS): files on GitHub and in gists work, and the address of a
  file's page on GitHub is understood.

#### Files on a computer you reach with ssh: `atomeye-serve`

A tablet has no `ssh host:file`, but the web application can be served
from the computer that has the files, and brought to the tablet through
an ssh tunnel. On that computer (Python 3.8 or later is all it needs):

    curl -fsSLO https://raw.githubusercontent.com/jameskermode/AtomEye/master/tools/atomeye-serve
    python3 atomeye-serve ~/runs

It fetches the application once, serves it together with the files under
that directory on a port of that computer only, and prints the ssh
command that forwards the port and the links to open: `…/files` lists
the configurations to choose from (the **Files** button in the viewer
goes back to it), and `…/?url=data/run1/traj.xyz` opens one. The address
contains a random word, so that other users of that computer cannot read
the files by guessing it.

iPadOS stops a tunnel soon after its ssh application goes to the
background, so run the ssh command on a computer that is always on and
reachable from the tablet instead, and publish the port from there; with
Tailscale, `tailscale serve --bg 8000` gives an `https://` address, at
which the application can also be added to the Home Screen.

## Building from source

AtomEye builds with [Meson](https://mesonbuild.com). Clone with
submodules, for the [extxyz](https://github.com/libAtoms/extxyz) reader:

    git clone --recursive https://github.com/jameskermode/AtomEye.git

Choose a window system with `-Dwindow_system=...`:

- `x11` (the default): Xlib, as in the original AtomEye. On macOS this
  needs [XQuartz](https://www.xquartz.org).
- `sdl3`: [SDL3](https://libsdl.org), for native windows on macOS,
  Wayland or X11 on Linux, and Windows.
- `none`: no window system; offscreen rendering only.
- `wasm`: WebAssembly, with Emscripten; see `wasm/README.md`.

It needs libpng and libjpeg, plus for Extended XYZ support PCRE2 and
Python with the `pyleri` package (at build time only). Optional: a line
editor for the command prompt (libedit or GNU readline), and LAPACK and
GSL, which the viewer itself does not need.

On Debian or Ubuntu:

    sudo apt install build-essential pkg-config libpng-dev libjpeg-dev \
        libedit-dev libpcre2-dev
    sudo apt install libx11-dev libxext-dev libxpm-dev   # for x11
    sudo apt install libsdl3-dev                         # for sdl3
    pip install meson ninja pyleri

On macOS with [Homebrew](https://brew.sh):

    brew install pkgconf libpng jpeg-turbo pcre2
    brew install sdl3                  # for sdl3: native windows
    brew install --cask xquartz        # for x11
    pip install meson ninja pyleri
    export PKG_CONFIG_PATH="$(brew --prefix jpeg-turbo)/lib/pkgconfig:/opt/X11/lib/pkgconfig"

On Windows, in an [MSYS2](https://www.msys2.org) UCRT64 shell (the result
is a native program that does not need MSYS2 to run):

    pacman -S mingw-w64-ucrt-x86_64-{gcc,meson,ninja,pkgconf,libpng,libjpeg-turbo,pcre2,sdl3,python,python-pip}
    pip install --break-system-packages pyleri

Then:

    meson setup build -Dwindow_system=sdl3    # or x11, or none
    meson compile -C build                    # gives build/A
    meson test -C build
    meson install -C build                    # optional

Options (`meson setup build -Dname=value`):

- `window_system`: `x11`, `sdl3`, `none` or `wasm`, as above.
- `line_editor`: `auto`, `libedit`, `readline` or `none`. `auto` prefers
  libedit, which is BSD licensed; GNU readline is GPL, which matters if
  you redistribute binaries. Without a line editor, lines are read as
  they are (the default on Windows).
- `extxyz`: `auto`, `enabled` or `disabled`. With `auto`, Extended XYZ
  support is left out if the submodule, PCRE2 or pyleri is missing.
- `python`: `enabled` or `disabled` (the default). Also builds the Python
  module, which needs numpy.
- `lapack`, `gsl`: `auto`, `enabled` or `disabled`.

`pip install .` builds and installs the Python package with the viewer
inside it; add `-Csetup-args=-Dwindow_system=sdl3` to choose the window
system.

The tests render offscreen, so they need no display. GitHub Actions
builds and tests every combination on Linux, macOS and Windows, builds
the wheels and bundles, and publishes the browser demo.

## What this fork adds

### Extended XYZ

[Extended XYZ](https://github.com/libAtoms/extxyz) files (`.xyz`) are
read with the C library of libAtoms/extxyz. The species come from the
`species` property, or from atomic numbers in `Z`. Real, integer and
logical properties become auxiliary properties for colouring; a vector
such as `force` becomes `force0`, `force1` and `force2`. Without a
`Lattice`, a bounding box with a 10 Å margin is used.

Frames of a trajectory are stepped through as usual (Delete and Insert,
with Ctrl for the last and first), or chosen by adding `:frame` to the
file name:

    load_config traj.xyz:first
    load_config traj.xyz:last
    load_config traj.xyz:45          # frame 45
    load_config traj.xyz:forward:10  # ten frames on
    set n->glob_advance 100          # the step of Delete and Insert

`reload_config` (F10) reads the file again, so frames written by a
running simulation since it was opened become available. NetCDF
trajectories are no longer read; convert them, for example with ASE.

### Arrows: `draw_arrows`

Draws a vector field, such as forces or displacements:

    draw_arrows off | number|name [scale factor] [head height] [head width] [up vector]

- `number|name`: the first of three consecutive auxiliary properties.
  For properties from an XYZ file the trailing number can be left out:
  `draw_arrows force`.
- `scale factor`: multiplies the arrow length; 0, the default, scales
  automatically.
- `head height`, `head width`: as fractions of the arrow length
  (defaults 0.1 and 0.05).
- `up vector`: arrow heads are drawn in the plane of the arrow and this
  vector (default 0 1 0).

`set n->arrow_overlay 1` keeps earlier arrows when more are drawn, to
show several fields at once.

### Colouring by a named property

`aux_property_coloring` takes the name of a property as well as its
number: `aux_property_coloring velocities0`.

### Colour patch files and user-defined bonds

`load_atom_color [file]` (F12) reads a colour patch file, by default
`<configuration>.usr` (for `traj.xyz:3` and every other frame of it,
`traj.usr`). A patch with that name is also applied whenever the
configuration is loaded. Each line is one of

    radius                      next atom: new radius
    r g b                       next atom: new colour
    r g b radius                next atom: both
    index r g b radius          the atom with this index (from 0)
    i j r g b radius            a bond between atoms i and j

Colours are 0-1 (or 0-255) and radii are in the units of the standard
atomic radii. If the file has rows for only the first *m* atoms, without
indices, and *m* divides the number of atoms, the pattern is repeated.

As soon as a patch defines bonds, they replace the bonds AtomEye works
out from the neighbour list, until a patch without bonds is loaded or
the cutoffs are changed with `rcut_patch`. They follow the atoms from
frame to frame. `change_atom_r_ratio` and `change_bond_radius` scale the
radii that are there, so radii set by a patch keep their proportions.

### Typing in colour thresholds

`typein_auxiliary_threshold [lower upper]` (Shift-T when colouring by a
property) sets both thresholds of the colour scale at once, asking for
them if they are not given. Thresholds set by hand stay fixed when other
configurations are loaded, until they are reset (Ctrl-R) or another
property is chosen.

(Patch files with bonds and typed-in thresholds come from the later
version of AtomEye 3 preserved in
[ray-shan/atomeye3-mac-m1](https://github.com/ray-shan/atomeye3-mac-m1).)

### Remote files and `watch`

`A host:path`, `A https://...`, the `watch` command and drag and drop
(see [Using the viewer](#using-the-viewer)). Nothing is linked in for
the first two: they run the `ssh` and `curl` programs of the computer.

### Smaller additions

- `xtal_origin_half` (Shift-Z) centres the cell on fractional coordinates
  (0.5, 0.5, 0.5), for cells with coordinates in 0 to 1 rather than the
  -0.5 to 0.5 that AtomEye expects.
- Cells smaller than twice the bond cutoff: `n->small_cell_err_handler`
  chooses between quitting (0), replicating the cell (1) and carrying on
  without some bonds (2, the default) when a configuration is loaded.
  `toggle_small_cell_mode` switches between the last two and reloads;
  `A -small-cell=quit|multiply|nocheck` sets it from the command line.
- `rcut_patch 2.4 absolute` sets a bond cutoff to a value instead of
  changing it by an amount:

      rcut_patch start Si Si
      rcut_patch 2.4 absolute
      rcut_patch finish

- `toggle_help` (`?` or F1) shows the keyboard shortcuts.
- Captures (`capture_png`, `capture_jpg`, `capture_eps`) work offscreen,
  at any size.

## Platform notes

- **Terminal:** commands and messages use the terminal the viewer was
  started from. The X11 build may open an xterm for them, as the
  original did, when it cannot tell which terminal it was started from.
- **SDL3:** one window per viewer, so `clone` and `new` are not
  available; start another viewer. Windows are not scaled for HiDPI
  displays.
- **macOS:** in-process `AtomEyeViewer` windows cannot be opened with
  SDL (use `AtomEyeProcess`, the ASE plugin or `nowindow=True`), and
  only one in-process viewer per Python session works.
- **Windows:** no Python extension module or wheels (the subprocess
  viewer works with the standalone `A.exe`), no line editing at the
  prompt, and no commands over a network port (`-listen`, `-c`).
- **Browser:** one view per widget; `close`, `quit`, `clone` and `new`
  are refused.

## Credits and licence

AtomEye was designed and written by Ju Li: the viewer, its software
renderer (the AX library) and the libraries under them. Please cite

> J. Li, "AtomEye: an efficient atomistic configuration viewer",
> Modelling Simul. Mater. Sci. Eng. 11 (2003) 173,
> [doi:10.1088/0965-0393/11/2/305](https://doi.org/10.1088/0965-0393/11/2/305)

if you use AtomEye in published work. The scripting interface (typed
commands, scripts, key bindings) and the parallel rendering of AtomEye 3
are by Futoshi Shimizu (2004-2005). Their manuals are in `doc/`, and the
original distribution is at <http://li.mit.edu/Archive/Graphics/A/>.

The Extended XYZ and Python support and the ports to current systems
and to the browser are by James Kermode, with contributions from
others; see the commit history.

AtomEye is distributed under the MIT licence, with the permission of
Ju Li, given also on behalf of Futoshi Shimizu:
see [`LICENSE`](LICENSE), which also lists the parts with terms of their
own. The bundled [extxyz](https://github.com/libAtoms/extxyz) library is
MIT licensed too, and the font of the keyboard shortcuts list is the
public domain X11 "fixed" font. The `Notes` and `Bugs` directories are
reference material from the original source, not part of the program and
not covered by the licence.
