大数跨境
0
0

RFdiffusion 教程(1):无条件生成与基序骨架设计

RFdiffusion 教程(1):无条件生成与基序骨架设计 Tina讲出海
2025-06-05
2
导读:RFdiffusion 是一个开源的结构生成方法,既可以在有条件信息(如功能基序、目标蛋白等)的情况下使用,也可以在无条件的情况下使用。它能够处理多种蛋白质设计任务,具体内容在 RFdiffusion

星标,再也不怕错过更新!方法见文末动图。



原文链接 

https://www.nature.com/articles/s41586-023-06415-8


代码链接 

https://github.com/RosettaCommons/RFdiffusion


RFdiffusion 是一个开源的结构生成方法,既可以在有条件信息(如功能基序、目标蛋白等)的情况下使用,也可以在无条件的情况下使用。它能够处理多种蛋白质设计任务,具体内容在 RFdiffusion 的论文中已有详细阐述。


1

Diffusion 可以完成的任务包括:

• 无条件蛋白生成(Unconditional protein generation)

• 基序支架设计(Motif Scaffolding)

 设计多样化(“部分扩散”机制,可在已有设计周围采样变体)

• 结合蛋白设计(Binder design)

• 对称性下的无条件生成(目前已支持循环对称、二面体对称和四面体对称,未来还将支持更多类型)

• 对称性的基序支架设计(Symmetric motif scaffolding)


接下来,本文将针对上述每一类任务,分别通过具体的代码示例,展示如何使用 RFdiffusion 实现这些功能,帮助读者快速上手并应用于自己的蛋白设计问题中。


2

安装

要开始使用 RFdiffusion,首先克隆该代码仓库:

Shellgit clone https://github.com/RosettaCommons/RFdiffusion.git

然后你需要将模型权重下载到 RFDiffusion 目录中:

Bashcd RFdiffusionmkdir models && cd modelswgethttp://files.ipd.uw.edu/pub/RFdiffusion/6f5902ac237024bdd0c176cb93063dc4/Base_ckpt.ptwgethttp://files.ipd.uw.edu/pub/RFdiffusion/e29311f6f1bf1af907f9ef9f44b8328b/Complex_base_ckpt.ptwgethttp://files.ipd.uw.edu/pub/RFdiffusion/60f09a193fb5e5ccdc4980417708dbab/Complex_Fold_base_ckpt.ptwgethttp://files.ipd.uw.edu/pub/RFdiffusion/74f51cfb8b440f50d70878e05361d8f0/InpaintSeq_ckpt.ptwgethttp://files.ipd.uw.edu/pub/RFdiffusion/76d00716416567174cdb7ca96e208296/InpaintSeq_Fold_ckpt.ptwget http://files.ipd.uw.edu/pub/RFdiffusion/5532d2e1f3a4738decd58b19d633b3c3/ActiveSite_ckpt.ptwgethttp://files.ipd.uw.edu/pub/RFdiffusion/12fc204edeae5b57713c5ad7dcb97d39/Base_epoch8_ckpt.pt
Optional:wgethttp://files.ipd.uw.edu/pub/RFdiffusion/f572d396fae9206628714fb2ce00f72e/Complex_beta_ckpt.pt
# original structure prediction weightswgethttp://files.ipd.uw.edu/pub/RFdiffusion/1befcb9b28e2f778f53d47f18b7597fa/RF_structure_prediction_weights.pt


请确保你已安装 Anaconda 或 Miniconda。


你还需要安装 NVIDIA 的 SE(3)-Transformer 实现。以下是安装该代码的方法:

Bashconda env create -f env/SE3nv.yml
conda activate SE3nvcd env/SE3Transformerpip install --no-cache-dir -r requirements.txtpython setup.py installcd ../.. # change into the root directory of the repositorypip install -e . # install the rfdiffusion module from the root of therepository

每次运行 RFdiffusion 之前,请确保通过以下命令激活对应的 conda 环境:

Shellconda activate SE3nv

3

使用


4

Unconditional design

我们首先来看一下如何进行一个长度为 150 个氨基酸的无条件蛋白设计。为此,我们只需要指定以下三项内容:

• 蛋白质的长度(The length of the protein)

• 我们希望保存输出文件的位置(The location where we want to write files to)

• 我们想要生成的设计数量 (The number of designs we want)

Shell./scripts/run_inference.py'contigmap.contigs=[150-150]' \inference.output_prefix=test_outputs/test \inference.num_designs=10


让我们详细来看一下。首先,什么是 contigmap.contigs?


Hydra 配置用于告诉推理脚本应如何运行。为了更好地组织配置内容,配置文件被划分为多个子配置块,其中之一就是 contigmap,它包含了与 contig 字符串 相关的所有内容(即定义将要构建的蛋白结构的部分)。


如果这一点还不清楚,你可以查看配置文件 configs/inference/base.yml 来了解更多细节。


那么,contigmap.contigs=[150-150] 是什么意思呢?


对于使用过 RFjoint inpainting 的人来说,这个格式可能看起来很熟悉,但略有不同。实际上,Diffusion 使用的“contig mapper”与 inpainting 完全相同,不同之处在于:由于我们使用的是 Hydra 配置系统,所以需要以不同的方式将 contig 信息传递给模型。


出于 Hydra 的语法要求,contig 字符串必须作为列表中的一个元素传递,而不能直接作为字符串。并且,整个参数必须用单引号包裹,以防命令行错误地解析其中的特殊字符。


contig 字符串可以用来指定一个长度范围,但在这个例子中,我们只是想要生成一个长度为 150 个氨基酸的蛋白质,因此直接写 [150-150] 即可。


这段配置将运行 10 次 diffusion 轨迹,并将生成的结构保存到你指定的输出文件夹中。

5

design_unconditional

在本节中,我们将介绍如何使用 RFdiffusion 执行最基础的蛋白质设计任务:无条件蛋白生成(unconditional design)。这一模式下,模型不依赖任何输入结构、基序片段或目标信息,完全从零开始生成具备合理折叠的蛋白质结构。

Bash#!/bin/bash# Here, we're making some unconditional designs# We specify the path for the outputs# We tell RFdiffusion that designs should be 100-200 residues in length(randomly sampled each design)# We generate 10 such designs../scripts/run_inference.py \   inference.output_prefix=example_outputs/unconditional/design_unconditional\    'contigmap.contigs=[100-200]' \    inference.num_designs=10
Shell'contigmap.contigs=[100-200]' 


这行是关键配置,表示:

• 模型每次设计时都将生成一个长度在 100 到 200 个残基之间的蛋白质;

• contigmap.contigs 是 RFdiffusion 的标准格式,用于指定目标序列的组成方式;

• 在无条件设计中,它代表一个单段连续的序列,没有固定结构、功能或分段要求。

6

design_unconditional_w_contact_potential

在本节中,我们基于无条件蛋白质设计,进一步引入辅助势能函数(contact potential),以引导模型生成更加紧凑、结构合理的蛋白折叠。


默认的无条件设计虽然能生成多样的蛋白结构,但有时会出现不够紧凑或内部接触不足的构象。通过加入 monomer_contacts 势能项,我们可以鼓励模型在设计过程中形成更多的链内残基接触,从而提升设计结构的可折叠性与稳定性。

Bash#!/bin/bash# Here, we're making some unconditional designs, and also using the'monomer_contacts' auxillary potential function# We specify the path for the outputs# We tell RFdiffusion that designs should be 100-200 residues in length(randomly sampled each design)# We generate 10 such designs../scripts/run_inference.py \   inference.output_prefix=example_outputs/design_unconditional_w_contact_potential\    'contigmap.contigs=[100-200]' \    inference.num_designs=10 \
        'potentials.guiding_potentials=["type:monomer_contacts,weight:0.05"]'

7

什么是 “with contact potential”?

“with contact potential” 的意思是:

在蛋白质设计过程中,引入了一个额外的能量函数项(即引导势函数,guiding potential),它鼓励生成的蛋白质结构中某些残基之间发生接触(即靠近形成非共价相互作用,如疏水、氢键等)。

8

monomer_contacts的具体含义

• type:monomer_contacts:

• 表示这个 potential 的类型是单体接触势,它鼓励设计出的蛋白质内部有合理的残基-残基接触模式(也就是结构更紧凑、自然)。

• weight:0.05:

• 指这个接触势函数在总优化目标中的权重是 0.05,是一个相对较小的软约束(soft constraint)。它不会强制影响结果,但会倾向于引导设计向具有内部接触的结构靠拢。

9

为什么要加 contact potential?

无条件设计(unconditional design)中,模型没有提供任何结构模板或binding目标,仅凭 diffusion 自己从头生成结构。

• 如果不加任何约束,可能生成一些不自然的蛋白质(比如疏松、无内部结构);

• monomer_contacts 会鼓励生成的结构中残基靠得更近,有利于形成稳定的折叠

10

design_unconditional_w_monomer_ROG

在本节中,我们在无条件蛋白设计的基础上,引入了一种新的引导势能——单体回转半径(monomer_ROG)势能,以进一步控制生成蛋白质的整体紧凑程度


“回转半径”(Radius of Gyration, ROG)是衡量蛋白结构是否紧密折叠的一个重要指标。通过设置 monomer_ROG 势能项,我们可以鼓励 RFdiffusion 生成的蛋白结构保持在预期的紧凑度范围内,避免出现不自然的松散构象。

Bash#!/bin/bash# Here, we're making some unconditional designs, and also using the'monomer_contacts' auxillary potential function# We specify the path for the outputs# We tell RFdiffusion that designs should be 100-200 residues in length(randomly sampled each design)# We generate 10 such designs../scripts/run_inference.py \   inference.output_prefix=example_outputs/design_unconditional_w_contact_potential\    'contigmap.contigs=[100-200]' \    inference.num_designs=10 \    'potentials.guiding_potentials=["type:monomer_contacts,weight:0.05"]'

这一段 Bash 脚本是调用 RFdiffusion 进行无条件蛋白质设计(unconditional design),但加上了一个特殊的引导势能项:monomer_ROG(单体回转半径势),用于鼓励生成的蛋白质结构更紧凑。


一句总结:

这段脚本使用了 回转半径 (Radius of Gyration, ROG) 引导势能,引导 RFdiffusion 在不提供模板的情况下生成结构更紧凑、更天然的蛋白质。

11

Radius of Gyration 是什么?

• 回转半径 (ROG) 衡量结构的紧凑程度

• 值越小,表示结构越紧密折叠;

• 大的 ROG 值意味着结构比较“松散”或拉伸。

12

适用场景

适合你想:

• 控制结构的紧凑性;

• 避免生成“线性”或“非自然折叠”结构;

• 或者你准备设计结构稳定的 scaffolds 或酶核心结构。


如需进一步添加 接触势 (monomer_contacts)、二级结构约束 或其他 guiding potential,可以并列添加多个,例如:

Shell'potentials.guiding_potentials=["type:monomer_ROG,weight:1,min_dist:5","type:monomer_contacts,weight:0.1"]'

13

Motif Scaffolding

RFdiffusion 可用于基序支架设计,其方式类似于 Constrained Hallucination 和 RFjoint Inpainting。总体而言,RFdiffusion 在性能上明显优于 Constrained Hallucination 和 RFjoint Inpainting。



在进行蛋白基序支架设计时,我们需要一种方式来指定:希望在哪些特定的蛋白结构片段上进行支架构建(即来自 .pdb 文件的一个或多个片段),以及希望它们之间如何连接、通过多少个残基连接到新生成的支架蛋白中。此外,我们通常并不预先知道连接基序所需的确切残基数,因此我们希望能够在设计过程中采样不同长度的连接片段。


这个输入指定的工作是通过 contigs 实现的,它受 Hydra 配置文件中的 contigmap 配置项控制。对于熟悉 Constrained Hallucination 或 RFjoint Inpainting 的用户来说,其逻辑非常相似。简要说明如下:


• 以字母开头的片段表示这是一个基序片段,字母对应于输入 .pdb 文件中的链名。例如 A10-25 表示输入结构中 A 链的第 10 到 25 个残基,即 (‘A’,10)、(‘A’,11)…(‘A’,25)。

• 没有字母前缀的片段表示是需要新设计生成的结构部分。这些部分可以用一个长度区间表示,RFdiffusion 在每次推理时都会从中随机采样长度。

• 如果需要指定链的断开位置(即生成的链不与原有片段连成一条链),使用 /0 来表示链断裂。

14

design_unconditional

在本节中,我们介绍如何使用 RFdiffusion 进行基序支架设计,即在保留一个已知的功能片段(motif)的基础上,为其构建稳定的结构支架(scaffold)

Bash#!/bin/bash# Here, we're running one of the motif-scaffolding benchmark examples# Specifically, we're scaffolding site 5 from RSV-F protein# We specify the output path and input pdb (the RSV-F protein)# We specify the protein we want to build, with the contig input:#   - 10-40 residues (randomly sampled)#   - residues 163-181 (inclusive) on theA chain of the input#   - 10-40 residues (randomly sampled)# We generate 10 designs
../scripts/run_inference.py \
    inference.output_prefix=example_outputs/design_motifscaffolding/design_motifscaffolding\   inference.input_pdb=input_pdbs/5TPN.pdb \   'contigmap.contigs=[10-40/A163-181/10-40]' \    inference.num_designs=10
Shell    'contigmap.contigs=[10-40/A163-181/10-40]'


这行是核心,指定构建的新蛋白应包含一个特定结构片段:

• 10-40:前导片段,随机生成长度在 10–40 个残基之间;

• A163-181:目标结构中的 motif,即 A链的残基 163 到 181,是你要保留并 scaffold 的功能区;

• 10-40:尾部片段,也是随机生成长度为 10–40 的残基。


整个结构最终是:新生成的前段 + motif + 新生成的后段

15

motif scaffolding 是什么?

Motif scaffolding 是结构设计中一种常见任务:

保留一个已知的功能性片段(motif),并为其设计稳定的两侧支撑结构(scaffold),以便在新蛋白中保留该功能。


在生物医学中,motif 通常是:

• 表位(epitope)

• 结合位点(binding site)

• 酶活性位点(catalytic site)

16

design_motifscaffolding_with_target

在本节中,我们展示如何使用 RFdiffusion 进行带结合目标的基序支架设计,即在设计支架的同时,考虑目标蛋白的空间限制,使所生成的结构具备特定的结合能力


与普通的 motif scaffolding 不同,此任务中不仅需要保留功能基序,还需要保证其在设计后能与一个已知目标蛋白(如受体、抗原)形成稳定的相互作用。这在设计结合肽段、疫苗抗原、受体识别位点等场景中尤为关键。

Bash#!/bin/bash# Here, we're running one of the motif-scaffolding benchmark examples, in the presenceof a target# Specifically, we're scaffolding the Mdm2-interacting peptide from p53# We specify the output path and input pdb (the p53-Mdm2 complex)# We specify the protein we want to build, with the contig input:#   - the Mdm2 target protein (residuesA25-109), with a chain break.#   - 0-70 residues (randomly sampled)#   - residues 17-29 (inclusive) on the Bchain of the input (the p53 helix)#   - 0-70 residues (randomly sampled)# We also constrain the total length of the diffused chain to be within 70 and120 residues# We generate 10 designs# As in the paper (at least for some of the designs we tested), we use thecomplex-finetuned modelpython ../scripts/run_inference.py \   inference.output_prefix=example_outputs/design_motifscaffolding_with_target/design_motifscaffolding_with_target\   inference.input_pdb=input_pdbs/1YCR.pdb \    'contigmap.contigs=[A25-109/00-70/B17-29/0-70]' \    contigmap.length=70-120 \    inference.num_designs=10 \    inference.ckpt_override_path=../models/Complex_base_ckpt.pt

这段脚本运行的是 RFdiffusion 的 motif-scaffolding 设计任务,但和你之前提供的相比,它是一个更高级的版本:


→ 在保留功能片段(motif)的同时,还需要考虑目标蛋白(target)的结合要求。


也就是说,这不是简单的 scaffold 结构,而是设计一个蛋白质片段,让它能嵌入 motif 并与目标蛋白相互作用

17

总体目标

设计一个新的蛋白质结构,它:

• 包含 p53 的功能性螺旋(B17–29)

• 能够结合 Mdm2 的结构区域(A25–109);

• 满足整体长度限制(70–120 个残基);

• 使用了为复合物优化的 RFdiffusion 模型(Complex_base_ckpt.pt);

Shellinference.input_pdb=input_pdbs/1YCR.pdb 

输入结构是 p53–Mdm2 蛋白复合物,PDB 编号 1YCR。其中:

• 链 A 是 Mdm2;

• 链 B 是 p53。

Shell'contigmap.contigs=[A25-109/0 0-70/B17-29/0-70]'

这段是核心的结构指定,解释如下:

➤ A25-109

• 保留目标蛋白 Mdm2 的结构,链 A 的残基 25–109。

➤ / :表示断开结构链

• Mdm2 是目标蛋白,不是你要设计的链,因此与新设计之间有断点。

➤ 0 0-70

• 中间插入一段设计片段,长度在 0–70 个残基之间;

• 0 0-70 是 RFdiffusion 中的一个容错写法,有时第一个 0 用作 placeholder。

➤ B17-29

• 这是要嵌入的 motif 片段,是 p53 的 α-螺旋区,也是与 Mdm2 结合的关键片段。

➤ /0-70

• 在 motif 的后面再设计一段 0–70 个残基的片段。

Shellcontigmap.length=70-120 

限制设计的新链长度在 70–120 个残基之间。

这通常用于约束生成结果在合理大小范围,避免过长或过短。

Shellinference.ckpt_override_path=../models/Complex_base_ckpt.pt

指定使用一个为复合物设计微调过的模型 checkpoint。这个模型特别适合用来设计结合目标蛋白的结构,比默认的 RFdiffusion 模型更适合这类任务。

18

design_motifscaffolding_inpaintseq

在本节中,我们介绍如何使用 RFdiffusion 实现序列可变的基序支架设计(inpaint sequence)。该任务在传统 motif scaffolding 的基础上,进一步允许基序中某些残基的氨基酸序列发生变化,从而获得更好的空间适配性与结构紧凑度。

Bash#!/bin/bash# Here, we're running one of the motif-scaffolding benchmark examples# Specifically, we're scaffolding site 5 from RSV-F protein# This is equivalent to the example in design_motifscaffolding.sh, except thatwe're adding the contigmap.inpaint_seq flag# The logic here is that only some of the amino acids are important for thefunction of the motif, and others can be redesigned.# This can promote better packing, as RFdiffusion is not forced to pack againstspecific (but unimportant) residues on the back-side of the motif  # We specify the output path and input pdb (the RSV-F protein)# We specify the protein we want to build, with the contig input:#   - 10-40 residues (randomly sampled)#   - residues 163-181 (inclusive) on theA chain of the input#   - 10-40 residues (randomly sampled)# We generate 10 designs# We then specify that residues 163-168 (inclusive), 170-171 (inclusive) and179 (inclusive) on the A chain of the input, should be masked in the input../scripts/run_inference.py \   inference.output_prefix=example_outputs/design_motifscaffolding_inpaintseq/design_motifscaffolding_inpaintseq\   inference.input_pdb=input_pdbs/5TPN.pdb \   'contigmap.contigs=[10-40/A163-181/10-40]' \    inference.num_designs=10 \   'contigmap.inpaint_seq=[A163-168/A170-171/A179]'

这段脚本是在运行 RFdiffusion 的 motif scaffolding 任务,其目标是:

• 保留 RSV-F 蛋白中的一个功能性结构片段(A163–181)

• 在其两侧构建新结构(scaffold)

• 并且特别指出:motif 内的部分残基不重要,可以重新设计,以获得更好的结构紧凑性或折叠质量。

Shellinference.input_pdb=input_pdbs/5TPN.pdb 

输入结构是 RSV-F 蛋白,PDB 编号为 5TPN,其中:

• A 链包含目标 motif 区(site 5),残基范围 163–181。

Shell'contigmap.contigs=[10-40/A163-181/10-40]' 

这是指定要构建的目标结构:

• 10-40:前导随机结构片段,长度 10–40 个残基;

• A163-181:motif 片段,RSV-F 的关键功能区;

• 10-40:尾部随机结构片段,长度 10–40。

即:

Shell随机结构 + 功能片段 + 随机结构
Shell'contigmap.inpaint_seq=[A163-168/A170-171/A179]'

这是该示例的关键创新点

contigmap.inpaint_seq

这个参数告诉 RFdiffusion:

motif 片段中某些残基可以“遮罩”掉(即不固定其序列),在设计过程中可以自由更改其氨基酸类型。

作用:

• 默认情况下,RFdiffusion 会保留输入结构中 motif 的序列和结构

• 但有时,motif 中的一部分残基对功能不重要,仅提供支撑结构;

• 这些残基可以重新设计(inpaint),从而让周围 scaffold 更容易 pack 得更好、整体折叠更合理。

这里遮罩掉的残基:

• A链的 163–168

• A链的 170–171

• A链的 179

这些位置的氨基酸可以被重新设计


19

背后逻辑

• motif 片段不是每个残基都同等重要;

• 保留关键位点的氨基酸,而重新设计非关键区域,可以提高整体折叠质量和多样性

• 这在 binder 设计、疫苗设计、或enzyme engineering 中非常常见。

20

总结

RFdiffusion 是一个开源的蛋白质结构设计工具,基于扩散模型,支持多种设计任务。本文重点介绍了其安装方式、无条件设计和 motif scaffolding 的使用方法。

· 安装:通过克隆仓库、下载模型权重,配置 Conda 环境及依赖,即可完成安装。

·  无条件蛋白生成:

o   可生成指定长度的全新蛋白结构(如 [100-200] 残基);

o  可加入辅助势能如 monomer_contacts(鼓励内部接触)或 monomer_ROG(控制结构紧凑性),提升设计质量。

· Motif scaffolding(基序支架设计):

o   在已知功能片段(motif)两侧生成支撑结构;

o   支持与目标蛋白结合的设计(如 p53–Mdm2);

o   可选择性重新设计 motif 内不重要的残基(inpaint_seq),提高适配性与结构紧凑度。


精彩回顾


图片
图片

供稿 | 刘安吉

责编 | 囡囡

设计 / 排版 | 可洲 


特别提示

微信公众号又双叒叕更改推送机制了,不是星标的订阅号,收到推送内容的时间会有延迟,甚至根本无法收到最新推送!不想错过FRCBS最新资讯,快来设为星标吧!

方法超简单,只需3秒钟!


点击上方卡片

关注我们吧


THE END

我知道你“在看”

【声明】内容源于网络
0
0
Tina讲出海
跨境分享间 | 每日提供跨境资讯
内容 47317
粉丝 0
Tina讲出海 跨境分享间 | 每日提供跨境资讯
总阅读181.9k
粉丝0
内容47.3k