1. add_cyclic_bond_loss
Register a JAX-differentiable harmonic loss on the cyclic closing amide bond geometry. This callback is appended to af_model._callbacks["model"]["loss"] during binder_hallucination and is called on every AF2 forward pass.
Signature
def add_cyclic_bond_loss( self, weight: float = 0.5, target_N_C: float = 1.33, target_CA_CA: float = 3.80, target_omega: float = 180.0, ) -> None
Parameters
| Name | Type | Default | Meaning |
|---|---|---|---|
self | AF2 model | — | ColabDesign AF2 model (method via monkey-patch in colabdesign_utils.py) |
weight | float | 0.5 | Loss weight on af_model.opt["weights"]["cyclic_bond"]. Raise to 1.0–2.0 if the ring fails to close |
target_N_C | float | 1.33 | Target N(1)–C(L) atom distance in Å |
target_CA_CA | float | 3.80 | Target Cα(1)–Cα(L) distance in Å |
target_omega | float | 180.0 | Target ω dihedral in degrees (180 = trans; 0 = cis) |
Returns
None. Side effects: appends a loss_fn to self._callbacks["model"]["loss"] and sets self.opt["weights"]["cyclic_bond"] = weight.
Example
from functions.colabdesign_utils import binder_hallucination # patched
from functions.cyclic_utils import add_cyclic_bond_loss
af_model = mk_afdesign_model(protocol="binder", use_multimer=True,
best_metric='loss')
af_model.prep_inputs(pdb_filename='target.pdb', chain='A',
binder_len=33, hotspot='A48,A53,A66')
# After prep_inputs, the cyclic_reses mask is attached automatically
add_cyclic_bond_loss(af_model, weight=1.0, target_N_C=1.33,
target_CA_CA=3.80, target_omega=180.0)
af_model.design_logits() # AF2 forward pass now includes cyclic_bond loss term
af_model.design_soft()
af_model.design_pssm_semigreedy()
See also
cyclize_relpos — the encoding side of the same trick. Stock add_termini_distance_loss (functions/colabdesign_utils.py:430-454) — the soft precursor this function replaces.