Architecture

Layout

unleap/
  __init__.py   version, UnleapError, lazy re-exports of the public API
  api.py        extract_ligand / extract_ligand_from_structure, LigandParams, base picking
  cli.py        argparse wrapper around api.extract_ligand; writes the files and report.txt
  amber.py      AMBERHOME helpers, base force-field presets, tleap / sander runners
  selection.py  --mask / --resname / auto-detect (standard residue name sets)
  extract.py    coordinate reading, ligand strip, sanity checks, PBC unwrap, HMR undo,
                atom-type consistency
  frcmod.py     full parameter set, tleap-style base lookup, diff, base scoring, frcmod writer
  lib.py        OFF library via ParmEd ResidueTemplate
  mol2.py       Tripos mol2 + SDF writers, RDKit bond-order inference
  validate.py   tleap rebuilds, term-by-term comparison, sander energy comparison
tests/
  conftest.py   builds fixtures on the fly (RDKit -> antechamber -c gas -> parmchk2 -> tleap)
  test_unleap.py  CLI behaviour
  test_api.py     Python API: strings, to_dict, workdir, no printing, structure input
scripts/
  vcm_sweep.py  real-data regression sweep over ABFE vcm_* jobs
docs/           this documentation (Sphinx, Read the Docs theme)

Data flow

unleap.extract_ligand() loads the files, then unleap.extract_ligand_from_structure() runs the steps below. Both return a LigandParams. The CLI (unleap.cli.run()) only calls extract_ligand, writes the result with write() and prints its report.

  1. unleap.extract.load() loads the topology with ParmEd and reads coordinates with read_coordinates() (see Amber and ParmEd behaviors, item 8).

  2. unleap.selection.ligand_mask(), then unleap.extract.strip(). This checks the selection (exactly one whole residue, not covalent), warns about NBFIX/12-6-4/CMAP, then strip("!(mask)")s a copy.copy of the topology (AmberParm rebuilds the copy from parm_data, so strip can rebuild the LJ tables), then unwraps the ligand across PBC.

  3. unleap.frcmod.full_params() builds the parameter set with AmberParameterSet.from_structure, then applies the masses, improper dedupe and order, and the leap angle correction.

  4. unleap.api.pick_base() scores each preset (or uses --base) and returns the BaseFF and its loaded .dat.

  5. unleap.extract.undo_hmr() (needs the base for reference H masses), then check_type_consistency(), then full_params again so the masses are final.

  6. unleap.frcmod.diff_params() compares each term with the base using tleap’s lookup rules (Diff frcmod matching rules).

  7. The frcmods, lib, mol2/sdf are rendered to strings (frcmod.render, lib.render, mol2.render); nothing touches the output directory.

  8. unleap.validate.run() writes those strings and LIG.orig.parm7 into the scratch workdir (a temporary directory unless one is given), does the three tleap rebuilds, then runs compare_terms() and compare_energies().

The library reports progress through logging.getLogger("unleap") and never prints or exits; the report text is returned as LigandParams.report.

State between steps

unleap.extract.Ligand carries the state between steps. ligand.masses is the per-atom mass list to write. It differs from lig.atoms[i].mass only when HMR was undone.

Warning

Never mutate parameter types attached to ligand.lig. unleap.validate.save_stripped() writes that structure as the reference everything is compared against. That’s why unleap.frcmod.full_params() replaces angle and dihedral types with corrected copies.