dn6 HF Staff commited on
Commit
23854f9
·
verified ·
1 Parent(s): 4900749

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +78 -162
README.md CHANGED
@@ -9,10 +9,7 @@ All three models — RFD3, ProteinMPNN, and LigandMPNN — rely on [Foundry](htt
9
  ### Installation
10
 
11
  ```bash
12
- # Install foundry (provides model implementations + AtomWorks)
13
  pip install rc-foundry[all]
14
-
15
- # Install diffusers with modular pipeline support
16
  pip install diffusers
17
  ```
18
 
@@ -22,72 +19,114 @@ pip install diffusers
22
  import torch
23
  from diffusers import ModularPipeline
24
 
25
- # Load the pipeline
26
- pipe = ModularPipeline.from_pretrained(
27
- "dn6/RFDiffusion-3",
28
- trust_remote_code=True,
29
- )
30
- pipe.load_components(
31
- device_map="cuda",
32
- torch_dtype=torch.bfloat16,
33
- trust_remote_code=True,
34
- )
35
 
36
- # Generate a 100-residue protein backbone
37
  state = pipe(contigs="100")
38
-
39
- # Access coordinates
40
- print(state.output.xyz.shape) # [B, L, 3]
41
  ```
42
 
43
- ## Why Diffusers?
44
 
45
- Wrapping RFdiffusion3 as a diffusers `ModularPipeline` gives you access to the full diffusers ecosystem out of the box:
46
 
47
- ### CPU Offloading
 
 
 
 
48
 
49
- Run large models on limited VRAM by offloading components to CPU when not in use:
50
 
51
  ```python
52
- pipe.enable_model_cpu_offload()
53
  state = pipe(contigs="100")
 
54
  ```
55
 
56
- ### Hub Integration
57
 
58
- All models are hosted on the Hugging Face Hub. Load by repo ID, share fine-tuned variants, and version your checkpoints:
59
 
60
  ```python
61
- pipe = ModularPipeline.from_pretrained("dn6/RFDiffusion-3", trust_remote_code=True)
 
 
 
 
 
 
62
  ```
63
 
64
- ### LoRA Fine-Tuning
65
 
66
- Fine-tune RFdiffusion3 on custom datasets with LoRA supported natively by `ModelMixin`:
 
 
 
 
 
 
 
 
67
 
68
  ```python
69
- from peft import LoraConfig
70
 
71
- lora_config = LoraConfig(r=16, lora_alpha=16, target_modules=["to_q", "to_k", "to_v"])
72
- pipe.transformer.add_adapter(lora_config)
 
 
 
 
 
 
 
 
 
73
 
74
- # After training
75
- pipe.transformer.save_pretrained("my-rfd3-lora")
76
  ```
 
 
 
 
 
 
77
 
78
- ### Composable Workflows
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  Inspect, swap, and extend pipeline blocks at runtime:
81
 
82
  ```python
83
- # Inspect the pipeline
84
  print(pipe.blocks)
85
 
86
  # Swap ProteinMPNN for LigandMPNN
87
  mpnn = AutoModel.from_pretrained("dn6/RFDiffusion-3", subfolder="mpnn_ligand", trust_remote_code=True)
88
  pipe.update_components(mpnn=mpnn)
89
 
90
- # Add a custom post-processing block
 
 
 
91
  from diffusers.modular_pipelines import ModularPipelineBlocks, PipelineState
92
  from diffusers.modular_pipelines.modular_pipeline_utils import InputParam, OutputParam
93
 
@@ -108,14 +147,11 @@ class ScoreDesignStep(ModularPipelineBlocks):
108
  self.set_block_state(state, block_state)
109
  return components, state
110
 
111
- # Insert after the decoder
112
  pipe._blocks.sub_blocks.insert("score", ScoreDesignStep(), index=3)
113
  ```
114
 
115
  ## Output Types
116
 
117
- All output types return the base tensors (`xyz`, `sequence_indices`, `sequence_logits`). The `output_type` parameter controls what additional format is produced:
118
-
119
  | `output_type` | Additional output | Writes to disk |
120
  |---|---|---|
121
  | `"tensor"` | — | — |
@@ -126,142 +162,22 @@ All output types return the base tensors (`xyz`, `sequence_indices`, `sequence_l
126
  CIF outputs use [AtomWorks](https://github.com/RosettaCommons/atomworks) `to_cif_file` and return [biotite](https://www.biotite-python.org/) `AtomArray` / `AtomArrayStack` objects, matching the foundry output format.
127
 
128
  ```python
129
- # Save as compressed CIF (matches foundry output format)
130
  state = pipe(contigs="100", output_type="cif.gz", output_path="design_0")
131
 
132
- # AtomArray is available directly
133
  atom_array = state.output.atom_array
134
- print(atom_array) # biotite AtomArray with CA coords + residue names
135
 
136
- # Denoising trajectory as AtomArrayStack (one model per step)
137
  trajectory = state.output.trajectory_stack
138
 
139
- # PDB string output
140
  state = pipe(contigs="100", output_type="pdb", output_path="design_0.pdb")
141
  print(state.output.pdb_string[:200])
142
  ```
143
 
144
- ## Models
145
-
146
- By default, `load_components` loads the RFdiffusion3 transformer and scheduler. MPNN models are optional — load them separately when you need sequence design.
147
-
148
- ### RFdiffusion3 (RFD3)
149
-
150
- [RFdiffusion3](https://www.biorxiv.org/content/10.1101/2025.09.18.676967v2) is an all-atom generative model that designs protein structures via iterative denoising. Uses an EDM noise schedule with 200 steps. Loaded automatically by `load_components`.
151
-
152
- | Component | Subfolder | Description |
153
- |-----------|-----------|-------------|
154
- | `transformer` | `transformer/` | `RFDiffusionTransformerModel` (168M params) |
155
- | `scheduler` | `scheduler/` | `RFDiffusionScheduler` (EDM noise schedule + Euler stepping) |
156
-
157
- ### ProteinMPNN / LigandMPNN
158
-
159
- [ProteinMPNN](https://www.science.org/doi/10.1126/science.add2187) and [LigandMPNN](https://www.nature.com/articles/s41592-025-02626-1) are inverse-folding models that design amino acid sequences for a given protein backbone. These are **not** loaded by default — load them with `AutoModel` and register via `update_components`:
160
-
161
- ```python
162
- from diffusers import AutoModel
163
-
164
- mpnn = AutoModel.from_pretrained("dn6/RFDiffusion-3", subfolder="mpnn", trust_remote_code=True)
165
- pipe.update_components(mpnn=mpnn)
166
- ```
167
-
168
- Three variants are available:
169
-
170
- | Subfolder | Variant | Params | Description |
171
- |-----------|---------|--------|-------------|
172
- | `mpnn/` | ProteinMPNN | 1.66M | Standard protein sequence design |
173
- | `mpnn_ligand/` | LigandMPNN | 2.62M | Ligand-aware sequence design |
174
- | `mpnn_soluble/` | SolubleMPNN | 1.66M | Optimized for soluble proteins |
175
-
176
- ## Workflows
177
-
178
- The active workflow is selected automatically based on which inputs you provide. Passing `temperature` triggers the MPNN sequence design step; passing `input_xyz` enables motif conditioning.
179
-
180
- | Workflow | Trigger inputs | What runs |
181
- |----------|---------------|-----------|
182
- | `structure_only` | `contigs` | RFdiffusion3 |
183
- | `structure_and_sequence` | `contigs`, `temperature` | RFdiffusion3 → MPNN |
184
- | `motif_structure_and_sequence` | `contigs`, `input_xyz`, `temperature` | Motif-conditioned RFdiffusion3 → MPNN |
185
-
186
- > Workflows that include MPNN require loading an MPNN variant first (see above).
187
-
188
- You can also select a workflow explicitly:
189
-
190
- ```python
191
- workflow = pipe.get_workflow("structure_and_sequence")
192
- ```
193
-
194
- ### Structure Only
195
-
196
- ```python
197
- state = pipe(contigs="100")
198
- print(state.output.xyz.shape) # [1, 100, 3]
199
- ```
200
-
201
- ### Structure + Sequence Design
202
-
203
- ```python
204
- from diffusers import AutoModel
205
-
206
- # Load an MPNN variant and register it
207
- mpnn = AutoModel.from_pretrained("dn6/RFDiffusion-3", subfolder="mpnn", trust_remote_code=True)
208
- pipe.update_components(mpnn=mpnn)
209
-
210
- # Passing temperature triggers the MPNN step
211
- state = pipe(contigs="100", temperature=0.1)
212
- print(state.mpnn_output.designed_sequence) # e.g. "MKVLSEG..."
213
- ```
214
-
215
- ### Motif-Conditioned Design
216
-
217
- ```python
218
- import torch
219
-
220
- motif_coords = torch.randn(16, 3) # [N_motif, 3]
221
- state = pipe(
222
- contigs="A10-25/50",
223
- input_xyz=motif_coords,
224
- temperature=0.1,
225
- )
226
- ```
227
-
228
- ## Full Design Pipeline
229
-
230
- The three pipelines can be composed into a complete protein design workflow:
231
-
232
- ```
233
- RFD3 (design backbone) → MPNN (design sequence) → RF3 (validate fold)
234
- ```
235
-
236
- Each is a standalone `ModularPipeline` that can run independently. Here's the full end-to-end flow:
237
-
238
- ```python
239
- import torch
240
- from diffusers import AutoModel, ModularPipeline
241
-
242
- # 1. Design a backbone with RFdiffusion3
243
- design_pipe = ModularPipeline.from_pretrained("dn6/RFDiffusion-3", trust_remote_code=True)
244
- design_pipe.load_components(device_map="cuda", torch_dtype=torch.bfloat16, trust_remote_code=True)
245
-
246
- mpnn = AutoModel.from_pretrained("dn6/RFDiffusion-3", subfolder="mpnn", trust_remote_code=True)
247
- design_pipe.update_components(mpnn=mpnn)
248
-
249
- state = design_pipe(contigs="100", temperature=0.1, output_type="cif.gz", output_path="design")
250
- designed_sequence = state.mpnn_output.designed_sequence
251
-
252
- # 2. Validate the design with RF3 (structure prediction)
253
- fold_pipe = ModularPipeline.from_pretrained("dn6/RosettaFold-3", trust_remote_code=True)
254
- fold_pipe.load_components(device_map="cuda", torch_dtype=torch.bfloat16, trust_remote_code=True)
255
-
256
- state = fold_pipe(sequence=designed_sequence, output_type="cif.gz", output_path="prediction")
257
- ```
258
-
259
- > [RF3](https://www.biorxiv.org/content/10.1101/2025.08.14.670328) (RosettaFold3) is available as a separate pipeline at [`dn6/RosettaFold-3`](https://huggingface.co/dn6/RosettaFold-3).
260
-
261
  ## Citation
262
 
263
- If you use this code, please cite the relevant work:
264
-
265
  ```bibtex
266
  @article{butcher2025_rfdiffusion3,
267
  author = {Butcher, Jasper and Krishna, Rohith and Mitra, Raktim and Brent, Rafael Isaac and Li, Yanjing and Corley, Nathaniel and Kim, Paul T and Funk, Jonathan and Mathis, Simon Valentin and Salike, Saman and Muraishi, Aiko and Eisenach, Helen and Thompson, Tuscan Rock and Chen, Jie and Politanska, Yuliya and Sehgal, Enisha and Coventry, Brian and Zhang, Odin and Qiang, Bo and Didi, Kieran and Kazman, Maxwell and DiMaio, Frank and Baker, David},
 
9
  ### Installation
10
 
11
  ```bash
 
12
  pip install rc-foundry[all]
 
 
13
  pip install diffusers
14
  ```
15
 
 
19
  import torch
20
  from diffusers import ModularPipeline
21
 
22
+ pipe = ModularPipeline.from_pretrained("dn6/RFDiffusion-3", trust_remote_code=True)
23
+ pipe.load_components(device_map="cuda", torch_dtype=torch.bfloat16, trust_remote_code=True)
 
 
 
 
 
 
 
 
24
 
 
25
  state = pipe(contigs="100")
26
+ print(state.output.xyz.shape) # [1, 100, 3]
 
 
27
  ```
28
 
29
+ ## Workflows
30
 
31
+ The active workflow is selected automatically based on which inputs you provide:
32
 
33
+ | Workflow | Trigger inputs | What runs |
34
+ |----------|---------------|-----------|
35
+ | `structure_only` | `contigs` | RFdiffusion3 |
36
+ | `structure_and_sequence` | `contigs`, `temperature` | RFdiffusion3 → MPNN |
37
+ | `motif_structure_and_sequence` | `contigs`, `input_xyz`, `temperature` | Motif-conditioned RFdiffusion3 → MPNN |
38
 
39
+ ### Structure Only
40
 
41
  ```python
 
42
  state = pipe(contigs="100")
43
+ print(state.output.xyz.shape) # [1, 100, 3]
44
  ```
45
 
46
+ ### Structure + Sequence Design
47
 
48
+ Passing `temperature` triggers the MPNN sequence design step. Load an MPNN variant first:
49
 
50
  ```python
51
+ from diffusers import AutoModel
52
+
53
+ mpnn = AutoModel.from_pretrained("dn6/RFDiffusion-3", subfolder="mpnn", trust_remote_code=True)
54
+ pipe.update_components(mpnn=mpnn)
55
+
56
+ state = pipe(contigs="100", temperature=0.1)
57
+ print(state.mpnn_output.designed_sequence) # e.g. "MKVLSEG..."
58
  ```
59
 
60
+ Three MPNN variants are available:
61
 
62
+ | Subfolder | Variant | Params | Description |
63
+ |-----------|---------|--------|-------------|
64
+ | `mpnn/` | ProteinMPNN | 1.66M | Standard protein sequence design |
65
+ | `mpnn_ligand/` | LigandMPNN | 2.62M | Ligand-aware sequence design |
66
+ | `mpnn_soluble/` | SolubleMPNN | 1.66M | Optimized for soluble proteins |
67
+
68
+ ### Motif-Conditioned Design
69
+
70
+ Passing `input_xyz` enables motif conditioning — fix specific residues in place while designing the rest:
71
 
72
  ```python
73
+ import torch
74
 
75
+ motif_coords = torch.randn(16, 3) # [N_motif, 3]
76
+ state = pipe(
77
+ contigs="A10-25/50",
78
+ input_xyz=motif_coords,
79
+ temperature=0.1,
80
+ )
81
+ ```
82
+
83
+ ### Full Design Pipeline
84
+
85
+ The three pipelines can be composed into a complete protein design workflow:
86
 
 
 
87
  ```
88
+ RFD3 (design backbone) → MPNN (design sequence) → RF3 (validate fold)
89
+ ```
90
+
91
+ ```python
92
+ import torch
93
+ from diffusers import AutoModel, ModularPipeline
94
 
95
+ # 1. Design a backbone + sequence
96
+ design_pipe = ModularPipeline.from_pretrained("dn6/RFDiffusion-3", trust_remote_code=True)
97
+ design_pipe.load_components(device_map="cuda", torch_dtype=torch.bfloat16, trust_remote_code=True)
98
+
99
+ mpnn = AutoModel.from_pretrained("dn6/RFDiffusion-3", subfolder="mpnn", trust_remote_code=True)
100
+ design_pipe.update_components(mpnn=mpnn)
101
+
102
+ state = design_pipe(contigs="100", temperature=0.1, output_type="cif.gz", output_path="design")
103
+ designed_sequence = state.mpnn_output.designed_sequence
104
+
105
+ # 2. Validate the fold with RF3
106
+ fold_pipe = ModularPipeline.from_pretrained("dn6/RosettaFold-3", trust_remote_code=True)
107
+ fold_pipe.load_components(device_map="cuda", torch_dtype=torch.bfloat16, trust_remote_code=True)
108
+
109
+ state = fold_pipe(sequence=designed_sequence, output_type="cif.gz", output_path="prediction")
110
+ ```
111
+
112
+ > [RF3](https://www.biorxiv.org/content/10.1101/2025.08.14.670328) (RosettaFold3) is available as a separate pipeline at [`dn6/RosettaFold-3`](https://huggingface.co/dn6/RosettaFold-3).
113
+
114
+ ## Customizing Workflows
115
 
116
  Inspect, swap, and extend pipeline blocks at runtime:
117
 
118
  ```python
119
+ # Inspect the pipeline structure
120
  print(pipe.blocks)
121
 
122
  # Swap ProteinMPNN for LigandMPNN
123
  mpnn = AutoModel.from_pretrained("dn6/RFDiffusion-3", subfolder="mpnn_ligand", trust_remote_code=True)
124
  pipe.update_components(mpnn=mpnn)
125
 
126
+ # Select a workflow explicitly
127
+ workflow = pipe.get_workflow("structure_and_sequence")
128
+
129
+ # Add a custom block
130
  from diffusers.modular_pipelines import ModularPipelineBlocks, PipelineState
131
  from diffusers.modular_pipelines.modular_pipeline_utils import InputParam, OutputParam
132
 
 
147
  self.set_block_state(state, block_state)
148
  return components, state
149
 
 
150
  pipe._blocks.sub_blocks.insert("score", ScoreDesignStep(), index=3)
151
  ```
152
 
153
  ## Output Types
154
 
 
 
155
  | `output_type` | Additional output | Writes to disk |
156
  |---|---|---|
157
  | `"tensor"` | — | — |
 
162
  CIF outputs use [AtomWorks](https://github.com/RosettaCommons/atomworks) `to_cif_file` and return [biotite](https://www.biotite-python.org/) `AtomArray` / `AtomArrayStack` objects, matching the foundry output format.
163
 
164
  ```python
165
+ # Save as compressed CIF
166
  state = pipe(contigs="100", output_type="cif.gz", output_path="design_0")
167
 
168
+ # Access AtomArray directly
169
  atom_array = state.output.atom_array
 
170
 
171
+ # Denoising trajectory
172
  trajectory = state.output.trajectory_stack
173
 
174
+ # PDB output
175
  state = pipe(contigs="100", output_type="pdb", output_path="design_0.pdb")
176
  print(state.output.pdb_string[:200])
177
  ```
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  ## Citation
180
 
 
 
181
  ```bibtex
182
  @article{butcher2025_rfdiffusion3,
183
  author = {Butcher, Jasper and Krishna, Rohith and Mitra, Raktim and Brent, Rafael Isaac and Li, Yanjing and Corley, Nathaniel and Kim, Paul T and Funk, Jonathan and Mathis, Simon Valentin and Salike, Saman and Muraishi, Aiko and Eisenach, Helen and Thompson, Tuscan Rock and Chen, Jie and Politanska, Yuliya and Sehgal, Enisha and Coventry, Brian and Zhang, Odin and Qiang, Bo and Didi, Kieran and Kazman, Maxwell and DiMaio, Frank and Baker, David},