# Constraints OpenDDE supports two independent constraint mechanisms, both declared per job in the input JSON: | Mechanism | JSON key | Supported models | CLI flag | Constraint kinds | | --- | --- | --- | --- | --- | | `constraint_embedder` | `distance_constraint` | `opendde_v2` only (`opendde_v1` raises an error) | None | `site`, `pair` | | Training-Free Guidance (TFG) | `constraint` | `opendde_v2` and `opendde_v1` (`opendde_v1` supports TFG only) | `--use_tfg_guidance true` | `contact`, `movable_chains`, `epitope` | - `opendde_v2` supports both `constraint_embedder` conditioning and TFG guidance. - `opendde_v1` has no constraint embedder and supports **TFG (`constraint`) only**; passing `distance_constraint` to `opendde_v1` raises an error. - Neither mechanism creates covalent bonds; use `covalent_bonds` for those (see [infer_json_format.md](infer_json_format.md)). --- ## 1. `constraint_embedder` (`distance_constraint`, `opendde_v2` only) `distance_constraint` conditions the pair representation inside the trunk through the trained constraint embedder. It requires no extra CLI flag and applies only to `opendde_v2`. - **`site`**: asks that each residue in `site` lies within `max_distance` of its nearest residue in `source`. - **`pair`**: asks that every residue in `left` and every residue in `right` lies within `[min_distance, max_distance]` (`min_distance` defaults to `0.0`). - **Selectors**: `entity` is the 1-based index in `sequences` (required); optional `copy` (1-based) and `positions` (1-based residue numbers) narrow the selection. Omitting `positions` selects the entire entity. - **Distances**: measured in Å between representative atoms (`CA` for amino acids, `C1'` for nucleotides, each atom for ligands), up to 32 Å. Values of `max_distance` in `6–12` Å match the trained range. ### Case 1: Antibody–antigen epitope (`site`) constraint Tell `opendde_v2` that chain 2 (binder) should sit within `8.0` Å of antigen residue `69` on entity `1`, without naming any binder-side residue (from [`examples/constraint/example_constraint_msa.json`](https://github.com/aurekaresearch/OpenDDE/blob/main/examples/constraint/example_constraint_msa.json)): ```json [ { "name": "7st3_site_8", "modelSeeds": [101], "sequences": [ { "proteinChain": { "sequence": "YMLDLQPETTDLYCGGGGSGGGGSGGGGSIQRTPKIQVYSRHPAENGKSNFLNCYVSGFHPSDIEVDLLKNGERIEKVEHSDLSFSKDWSFYLLYYTEFTPTEKDEYACRVNHVTLSQPKIVKWDRDMGGGGSGGGGSGGGGSGGGGSGSHSMRYFFTSVSRPGRGEPRFIAVGYVDDTQFVRFDSDAASQRMEPRAPWIEQEGPEYWDGETRKVKAHSQTHRVDLGTLRGCYNQSEAGSHTVQRMYGCDVGSDWRFLRGYHQYAYDGKDYIALKEDLRSWTAADMCAQTTKHKWEAAHVAEQLRAYLEGTCVEWLRRYLENGKETLQRTDAPKTHMTHHAVSDHEATLRCWALSFYPAEITLTWQRDGEDQTQDTELVETRPAGDGTFQKWAAVVVPSGQEQRYTCHVQHEGLPKPLTLRWEHHHHHH", "count": 1, "id": ["A"], "msa": {"precomputed_msa_dir": "./examples/constraint/msa/7st3/1/", "pairing_db": "uniref100"} } }, { "proteinChain": { "sequence": "EVKLVESGGGLVQPGGSLRLSCAASGSIFSINTMGWYRQTPGKQRDLVADISSGGSTKYGDSVKGRFTISRDNTKNTVYLQMNSLKPEDTAVYYCYGLSYSNDDYWGQGTQVTVSS", "count": 1, "id": ["B"], "msa": {"precomputed_msa_dir": "./examples/constraint/msa/7st3/2/", "pairing_db": "uniref100"} } } ], "distance_constraint": { "site": [ { "source": [{"entity": 2}], "site": [{"entity": 1, "positions": [69]}], "max_distance": 8.0 } ] } } ] ``` ### Case 2: Residue–residue (`pair`) constraint Constrain residue `72` of entity `1` to be within `15.0` Å of residue `103` of entity `2`: ```json "distance_constraint": { "pair": [ { "left": [{"entity": 1, "positions": [72]}], "right": [{"entity": 2, "positions": [103]}], "max_distance": 15.0 } ] } ``` ### Case 3: Protein–ligand pocket (`pair`) constraint Place ligand `CCD_ZRY` (entity `2`) within `3.0–5.0` Å of residue `311` on protein entity `1` (from [`examples/constraint/example_constraint_msa.json`](https://github.com/aurekaresearch/OpenDDE/blob/main/examples/constraint/example_constraint_msa.json)): ```json [ { "name": "5sak_residue_ligand_pair_3_5", "modelSeeds": [101], "sequences": [ { "proteinChain": { "sequence": "MSSPLKNALVTAMLAGGALSSPTKQHVGIPVNASPEVGPGKYSFKQVRNPNYKFNGPLSVKKTYLKYGVPIPAWLEDAVQNSTSGLAERSTGSATTTPIDSLDDAYITPVQIGTPAQTLNLDFDTGSSDLWVFSSETTASEVDGQTIYTPSKSTTAKLLSGATWSISYGDGSSSSGDVYTDTVSVGGLTVTGQAVESAKKVSSSFTEDSTIDGLLGLAFSTLNTVSPTQQKTFFDNAKASLDSPVFTADLGYHAPGTYNFGFIDTTAYTGSITYTAVSTKQGFWEWTSTGYAVGSGTFKSTSIDGIADTGTTLLYLPATVVSAYWAQVSGAKSSSSVGGYVFPCSATLPSFTFGVGSARIVIPGDYIDFGPISTGSSSCFGGIQSSAGIGINIFGDVALKAAFVVFNGATTPTLGFASK", "count": 1, "id": ["A"], "msa": {"precomputed_msa_dir": "./examples/constraint/msa/5sak/1/", "pairing_db": "uniref100"} } }, { "ligand": { "ligand": "CCD_ZRY", "count": 1, "id": ["L"] } } ], "distance_constraint": { "pair": [ { "left": [{"entity": 1, "positions": [311]}], "right": [{"entity": 2}], "min_distance": 3.0, "max_distance": 5.0 } ] } } ] ``` Run all bundled `distance_constraint` examples (7ST3 site/pair and 5SAK residue–ligand, paired with unconstrained baselines): ```bash python runner/batch_inference.py pred \ -i examples/constraint/example_constraint_msa.json \ -o ./output_constraint \ -n opendde_v2 \ --use_msa true ``` --- ## 2. Training-Free Guidance (`constraint`, `opendde_v2` and `opendde_v1`) TFG steers the sampled coordinates during diffusion without modifying trunk representations or weights. It requires `--use_tfg_guidance true` and works with **both `opendde_v2` and `opendde_v1`** (for `opendde_v1`, TFG is the only supported constraint mode). ### Case 4: Rigid-body contact restraint (`movable_chains` + `contact`) Move antibody chains `["H", "L"]` as a rigid body to satisfy a contact between heavy-chain `CA` at position `102` and antigen `CA` at position `20`: ```json [ { "name": "abag_tfg_contact", "modelSeeds": [101], "sequences": [ {"proteinChain": {"sequence": "EVQLVESGGG...", "count": 1, "id": ["H"]}}, {"proteinChain": {"sequence": "DIQMTQSPSS...", "count": 1, "id": ["L"]}}, {"proteinChain": {"sequence": "MKTIIALSYI...", "count": 1, "id": ["A"]}} ], "constraint": { "movable_chains": ["H", "L"], "contact": [ { "entity1": "1", "copy1": 1, "position1": "102", "atom1": "CA", "entity2": "3", "copy2": 1, "position2": "20", "atom2": "CA", "min_distance": 3.5, "max_distance": 8.0 } ] } } ] ``` Run with `opendde_v2` or `opendde_v1`: ```bash # opendde_v2 python runner/batch_inference.py pred \ -i abag_tfg_contact.json \ -o ./output_tfg_v2 \ -n opendde_v2 \ --use_tfg_guidance true # opendde_v1 (supports TFG constraints only) python runner/batch_inference.py pred \ -i abag_tfg_contact.json \ -o ./output_tfg_v1 \ -n opendde_v1 \ --use_tfg_guidance true ``` ### Case 5: Epitope guidance (`movable_chains` + `epitope`) Guide antibody CDRs onto a set of antigen epitope residues without specifying antibody-side contacts: ```json [ { "name": "abag_tfg_epitope", "modelSeeds": [101], "sequences": [ {"proteinChain": {"sequence": "EVQLVESGGG...", "count": 1, "id": ["H"]}}, {"proteinChain": {"sequence": "DIQMTQSPSS...", "count": 1, "id": ["L"]}}, {"proteinChain": {"sequence": "MKTIIALSYI...", "count": 1, "id": ["A"]}} ], "constraint": { "movable_chains": ["H", "L"], "epitope": { "residues": [ {"entity": "3", "copy": 1, "position": "248", "residue": "P"}, {"entity": "3", "copy": 1, "position": "249", "residue": "N"}, {"entity": "3", "copy": 1, "position": "251", "residue": "D"} ], "paratope": "cdr", "min_fraction": 0.5 } } } ] ``` - `paratope` accepts `"all"` (default), `"cdr"` (positions 24–40, 50–66, 88–115 of each movable chain), or explicit windows such as `{"windows": {"H": [[95, 108]], "L": [[89, 97]]}}`. - `min_fraction` sets the minimum fraction of listed epitope residues within 5 Å (heavy-atom distance) of the paratope. Run with the tuned TFG settings (`--dtype bf16 --enable_tf32 false` at 200 diffusion steps): ```bash python runner/batch_inference.py pred \ -i abag_tfg_epitope.json \ -o ./output_tfg_epitope \ -n opendde_v2 \ --use_tfg_guidance true \ --dtype bf16 \ --enable_tf32 false ``` See [tfg_constraint_guidance.md](tfg_constraint_guidance.md) for the search algorithm, default schedules, and `--tfg_rigid KEY=VALUE` overrides.