Fragment Detection

Fragment Detection

Usage

To analyze molecular fragments using the geometric method, useful for standard organic molecules, the way ase visualizations work:

# Single file analysis
python -m rgpycrumbs.cli geom detect-fragments geometric molecule.xyz --multiplier 1.2

# Batch processing a directory
python -m rgpycrumbs.cli geom detect-fragments batch ./structures/ --output summary.csv

For systems with ambiguous bonding, like transition states or loosely bound complexes, use the Wiberg Bond Order method which requires tblite, described here:

python -m rgpycrumbs.cli geom detect-fragments bond-order complex.xyz --threshold 0.6

Python Example

You can also use the detection logic directly within Python scripts. This example demonstrates creating a water dimer in ASE and verifying it separates into two fragments.

from ase import Atoms
from ase.build import molecule
from rgpycrumbs.geom.detect_fragments import find_fragments_geometric

# 1. Construct a water dimer
# One water at the origin, another separated by 3.5 Angstroms
water_a = molecule("H2O")
water_b = molecule("H2O")
water_b.translate([3.5, 0, 0])

dimer = water_a + water_b

# 2. Detect fragments using geometric criteria (Cordero radii)
# A standard covalent bond check would treat these as separate.
n_frags, labels = find_fragments_geometric(dimer, bond_multiplier=1.2)

print(f"System contains {n_frags} fragments.")
print(f"Atom labels: {labels}")

# Expected Output:
# System contains 2 fragments.
# Atom labels: [0 0 0 1 1 1]

API Reference

For developer details and source code see rgpycrumbs.geom.detect_fragments.