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.
unleap.extract.load()loads the topology with ParmEd and reads coordinates withread_coordinates()(see Amber and ParmEd behaviors, item 8).unleap.selection.ligand_mask(), thenunleap.extract.strip(). This checks the selection (exactly one whole residue, not covalent), warns about NBFIX/12-6-4/CMAP, thenstrip("!(mask)")s acopy.copyof the topology (AmberParm rebuilds the copy fromparm_data, sostripcan rebuild the LJ tables), then unwraps the ligand across PBC.unleap.frcmod.full_params()builds the parameter set withAmberParameterSet.from_structure, then applies the masses, improper dedupe and order, and the leap angle correction.unleap.api.pick_base()scores each preset (or uses--base) and returns theBaseFFand its loaded.dat.unleap.extract.undo_hmr()(needs the base for reference H masses), thencheck_type_consistency(), thenfull_paramsagain so the masses are final.unleap.frcmod.diff_params()compares each term with the base using tleap’s lookup rules (Diff frcmod matching rules).The frcmods, lib, mol2/sdf are rendered to strings (
frcmod.render,lib.render,mol2.render); nothing touches the output directory.unleap.validate.run()writes those strings andLIG.orig.parm7into the scratchworkdir(a temporary directory unless one is given), does the three tleap rebuilds, then runscompare_terms()andcompare_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.