API reference
Recover a ligand’s mol2 / frcmod / OFF lib from an Amber parm7 + rst7 pair.
- exception unleap.UnleapError[source]
Bases:
RuntimeErrorRaised for user-facing failures (bad selection, unsupported topology, …).
- unleap.extract_ligand(parm7, crd, *, mask=None, resname=None, frame=0, name=None, base='auto', undo_hmr=True, validate=True, workdir=None)[source]
Recover the mol2 / frcmod / OFF lib of one ligand residue in a built Amber system.
- Parameters:
parm7 (str or path) – Amber topology.
crd (str or path) – Coordinates: ASCII rst7/inpcrd, NetCDF restart, or NetCDF trajectory (see
frame).mask (str, optional) – Amber mask or residue name selecting the ligand (at most one). If both are None, the single non-standard residue is auto-detected.
resname (str, optional) – Amber mask or residue name selecting the ligand (at most one). If both are None, the single non-standard residue is auto-detected.
frame (int) – Trajectory frame, 0-based; negative counts from the end.
name (str, optional) – Unit/residue name for the outputs (default: the original residue name).
base (str) – Base force field for the diff frcmod: “auto”, “gaff”, “gaff2”, “gaff211” or a .dat path.
undo_hmr (bool) – Detect and reverse hydrogen mass repartitioning.
validate (bool) – Rebuild the ligand with tleap and compare terms and sander energies to the original.
workdir (str or path, optional) – Scratch directory for the validation (kept). A temporary one is used if None.
- Return type:
- Raises:
UnleapError – For any user-facing failure (bad selection, unsupported topology, missing AmberTools).
- unleap.extract_ligand_from_structure(struct, *, mask=None, resname=None, name=None, base='auto', undo_hmr=True, validate=True, workdir=None)[source]
Like
extract_ligand(), for an already-loadedparmed.amber.AmberParmwith coordinates (and box, if periodic).structis not modified, so it can be reused, e.g. once per resname in a dual-topology system. After editing it through ParmEd’s object model, callstruct.remake_parm()first.
- class unleap.LigandParams(name: str, resname: str, mask: str, n_atoms: int, net_charge: float, frcmod: str, full_frcmod: str, lib: str, mol2: str, sdf: object, tleap_in: str, base: BaseFF, base_scores: dict, hmr_undone: bool, diff_counts: dict, checks: list = <factory>, validated: bool = False, warnings: list = <factory>, report: str = '', structure: object = None)[source]
Bases:
objectEverything unleap recovers for one ligand. File bodies are strings;
write()puts them on disk.- property ok
True when every validation check passed (vacuously True when not validated).
- class unleap.CheckResult(name: str, ok: bool, details: list = <factory>)[source]
Bases:
objectOne rebuild-and-compare check:
detailslists each mismatch (empty whenok).
- class unleap.BaseFF(name: str, dat: str, leap_preamble: str)[source]
Bases:
objectA base force field the diff frcmod is written against.
- name: str
- dat: str
- leap_preamble: str
- load()[source]
Python API internals
Python API: extract a ligand’s parameters from a built system and get them back as data.
- class unleap.api.LigandParams(name: str, resname: str, mask: str, n_atoms: int, net_charge: float, frcmod: str, full_frcmod: str, lib: str, mol2: str, sdf: object, tleap_in: str, base: BaseFF, base_scores: dict, hmr_undone: bool, diff_counts: dict, checks: list = <factory>, validated: bool = False, warnings: list = <factory>, report: str = '', structure: object = None)[source]
Bases:
objectEverything unleap recovers for one ligand. File bodies are strings;
write()puts them on disk.- property ok
True when every validation check passed (vacuously True when not validated).
- unleap.api.extract_ligand(parm7, crd, *, mask=None, resname=None, frame=0, name=None, base='auto', undo_hmr=True, validate=True, workdir=None)[source]
Recover the mol2 / frcmod / OFF lib of one ligand residue in a built Amber system.
- Parameters:
parm7 (str or path) – Amber topology.
crd (str or path) – Coordinates: ASCII rst7/inpcrd, NetCDF restart, or NetCDF trajectory (see
frame).mask (str, optional) – Amber mask or residue name selecting the ligand (at most one). If both are None, the single non-standard residue is auto-detected.
resname (str, optional) – Amber mask or residue name selecting the ligand (at most one). If both are None, the single non-standard residue is auto-detected.
frame (int) – Trajectory frame, 0-based; negative counts from the end.
name (str, optional) – Unit/residue name for the outputs (default: the original residue name).
base (str) – Base force field for the diff frcmod: “auto”, “gaff”, “gaff2”, “gaff211” or a .dat path.
undo_hmr (bool) – Detect and reverse hydrogen mass repartitioning.
validate (bool) – Rebuild the ligand with tleap and compare terms and sander energies to the original.
workdir (str or path, optional) – Scratch directory for the validation (kept). A temporary one is used if None.
- Return type:
- Raises:
UnleapError – For any user-facing failure (bad selection, unsupported topology, missing AmberTools).
- unleap.api.extract_ligand_from_structure(struct, *, mask=None, resname=None, name=None, base='auto', undo_hmr=True, validate=True, workdir=None)[source]
Like
extract_ligand(), for an already-loadedparmed.amber.AmberParmwith coordinates (and box, if periodic).structis not modified, so it can be reused, e.g. once per resname in a dual-topology system. After editing it through ParmEd’s object model, callstruct.remake_parm()first.
Command line
unleap: strip a ligand out of a parm7/rst7 pair and regenerate its mol2, frcmod and lib.
Selection
Choose the ligand residue: explicit mask, residue name, or auto-detect.
Extraction
Load the system, strip out the ligand, and check it can be expressed as mol2/frcmod/lib.
- class unleap.extract.Ligand(struct: object, lig: object, mask: str, hmr: bool = False, masses: list = <factory>, warnings: list = <factory>)[source]
Bases:
object- property resname
- unleap.extract.read_coordinates(path, frame=0)[source]
(xyz, box) from an ASCII rst7/inpcrd or one frame of a NetCDF restart/trajectory.
Reads the file directly: ParmEd’s format sniffing rejects rst7 headers that carry a temperature (pmemd/REMD restarts), and loading a whole trajectory just for one frame is wasteful.
- unleap.extract.strip(struct, mask)[source]
Extract the ligand and run the topology sanity checks.
structis not modified.The ligand is stripped from
copy.copy(struct), which AmberParm rebuilds fromparm_data; after editing a structure through the object model, callstruct.remake_parm()first.
- unleap.extract.undo_hmr(ligand, base_params=None)[source]
Detect hydrogen mass repartitioning and restore the original masses in ligand.masses.
Each H gets its type’s mass from the base force field (or 1.008); the mass it carried beyond that is returned to the heavy atom it is bonded to, which reverses HMR exactly.
frcmod
Build the full (self-contained) and diff-vs-base frcmod parameter sets.
- unleap.frcmod.improper_atoms(d)[source]
Improper atoms ordered with the central atom third (frcmod convention).
tleap may store an improper reversed in the prmtop (central atom second); a reversed torsion is the same angle, so reverse it back. The central atom is the one bonded to the other three.
- unleap.frcmod.full_params(ligand)[source]
Every parameter the ligand uses, with masses taken from ligand.masses (HMR undone).
- unleap.frcmod.lookup_dihedral(base, key)[source]
tleap order: explicit types (either direction), then X-b-c-X.
- unleap.frcmod.lookup_improper(base, key)[source]
Central atom is third; outer atoms may be permuted; most specific match wins.
- unleap.frcmod.compare_to_base(full, base)[source]
Return {section: [(key, value), …]} of ligand terms that the base does not reproduce.
- unleap.frcmod.score_base(full, base)[source]
Fraction of the ligand’s bonded terms the base reproduces (masses ignored: HMR may alter them).
- unleap.frcmod.diff_params(full, base)[source]
Parameter set holding only the terms missing from, or different in, the base.
- unleap.frcmod.render(pset, title)[source]
frcmod text, modeled on ParmEd’s writer but keeping prmtop precision (ParmEd rounds req/theteq to 3 decimals, which breaks GAFF2’s 4-decimal bond lengths) and the prmtop improper order.
- unleap.frcmod.LEAP_DEG_CORRECTION
Convert a string or number to a floating-point number, if possible.
OFF library
Write the ligand as an Amber OFF library unit.
mol2 / SDF
TRIPOS mol2 writer: Amber atom types, exact charges, RDKit-inferred bond orders.
- unleap.mol2.bond_orders(lig)[source]
Return ({(i, j): order} with i < j, kekulized, RDKit mol); (None, None) if RDKit cannot assign them.
- unleap.mol2.render_sdf(mol, ligand, name)[source]
SDF with bond orders and formal charges: the RDKit/viewer-friendly copy (RDKit’s mol2 reader only understands SYBYL types, not GAFF).
Validation
Round-trip check: rebuild the ligand with tleap from the outputs and compare to the original.
- class unleap.validate.CheckResult(name: str, ok: bool, details: list = <factory>)[source]
Bases:
objectOne rebuild-and-compare check:
detailslists each mismatch (empty whenok).
- unleap.validate.save_stripped(struct, prefix)[source]
Write the stripped original ligand (non-periodic) for comparison.
AmberTools helpers
AmberTools environment helpers: base force fields, tleap and sander runners.
- class unleap.amber.BaseFF(name: str, dat: str, leap_preamble: str)[source]
Bases:
objectA base force field the diff frcmod is written against.
- unleap.amber.resolve_base(spec)[source]
Resolve a –base value (preset name or .dat path); ‘auto’ returns None.