Skip to content

Fragment Selector

FragSelector shows a 2D diagram and the 3D structure side by side. Pick atoms in either panel; the Selected and Unselected index lists update live and can be copied straight into your code.

from ase.build import molecule
from aseview import FragSelector

FragSelector(molecule("CH3OH")).show()
aseview molecule.xyz -v frag
aseview molecule.xyz -v frag -o selector.html   # save instead of serving

Selecting

Switch tools in the toolbar or with the keyboard: Navigate (N), Click (C), Rect (R) and Lasso (L). Rectangles and lassos work in both panels; hold Shift when releasing to add to the selection. Expand H adds the hydrogens bonded to the selection, and All / Clear / Invert change it as a whole.

Disconnected molecules become separate islands in the 2D panel, so a whole molecule is one lasso away — here two water molecules:

A larger case with two iodo-benzimidazole units (50 atoms):

If bonds are missing or spurious, change bond_threshold (CLI -bt); the 2D layout and 3D bonds rebuild with it.

Using the selection

Paste the copied lists into Python:

from ase.build import molecule

ethanol = molecule("CH3CH2OH")
selected = [2, 3]                   # copied from "Selected": the OH group
unselected = [0, 1, 4, 5, 6, 7, 8]  # copied from "Unselected"

ethanol[selected].get_chemical_formula()    # 'HO'
ethanol[unselected].get_chemical_formula()  # 'C2H5'

The same lists fit common workflows:

from ase.constraints import FixAtoms

atoms.set_constraint(FixAtoms(indices=selected))   # freeze the picked atoms
qm_region, mm_region = atoms[selected], atoms[unselected]  # QM/MM partition

Copy by fragment copies the selected and unselected atoms as two frames, and Copy reindexed copies one structure with the selected atoms first, in copy_format (xyz, extxyz, cif or vasp-poscar).

selected=[...] preselects atoms when the viewer opens:

FragSelector(atoms, selected=[0, 1, 2], copy_format="extxyz")