Skip to content

FragSelector

Fragment selector with a 2D diagram and the 3D structure side by side. Pick atoms in either panel; both views, the index lists and the copy buttons stay in sync.

See the Fragment Selector example for a walkthrough.

CLI

aseview molecule.xyz -v frag
aseview molecule.xyz -v frag --bond-threshold 1.4
aseview molecule.xyz -v frag -o selector.html

frag is never chosen automatically; pass -v frag. With a multi-frame file only the first frame is used.

Constructor

FragSelector(data, *, selected=None, theme=None, **settings)
Parameter Type Description Default
data Atoms, str, ... One structure (anything MolecularViewer accepts; only the first frame is used) Required
selected list[int] Atom indices selected initially None
theme str Viewer theme; None uses get_theme() None
**settings Viewer settings, e.g. bond_threshold, style, hide_hydrogens, copy_format

copy_format (xyz, extxyz, cif, vasp-poscar) is the format of the copy buttons. extxyz and POSCAR keep the cell and fixed/move-mask constraints; cif keeps the cell but has no constraint field.

Methods

show(), get_html(), save_html() and save_png() work as in MolecularViewer.

In the viewer

Tools

Tool Key 2D panel 3D panel
Navigate N Drag pans, wheel zooms, double-click refits Drag rotates, right-drag pans, wheel zooms
Click C Click an atom to toggle it Click an atom to toggle it (drag still rotates)
Rect R Drag a rectangle Drag a rectangle over the projected atoms
Lasso L Draw a free-form region Draw a free-form region

Hold Shift while releasing to add to the selection instead of replacing it. In the grid layout, rectangle and lasso use the panel you drag in.

2D diagram

The layout is computed from the 3D coordinates: bonds from covalent radii, connected components separated, each projected with PCA and refined with a force-directed pass, bond lengths normalised, and fragments placed left to right, largest first. Bond halves take their atom's color.

Selection panel

Control Description
Selected / Unselected Live [i, j, ...] index lists with counts and copy buttons
All / Clear / Invert Change the whole selection
Expand H Add hydrogens bonded to selected atoms
Copy by fragment Selected and unselected atoms as separate frames in copy_format
Copy reindexed One structure with the selected atoms first

Examples

from ase.build import molecule
from aseview import FragSelector

FragSelector(molecule("CH3CH2OH"), selected=[0, 1, 2]).show()
FragSelector("complex.xyz", bond_threshold=1.3, copy_format="extxyz").save_html("selector.html")