RDiffusion is a diffusion-based framework for RNA sequence design and generation. It combines diffusion generation with task-specific guidance models, and supports both single-task and multi-task constraints during inference. Typical applications include functional family targeting, disease association, protein-RNA binding, secondary structure constraints, 3D structure conditions, UTR optimization, and Cas13 guide design.
-
πͺ Unified Inference Entry Use inference.py as the single entry point for uncon, text, rfam, disease, prot_rna_bind, ss, ts, utr, and cas13.
-
π§ Multi-task Guidance Support joint multi-task guidance with per-task guidance scale control.
-
π§ͺ Rich Conditioning Inputs Support diverse condition types, including family/label, text functional conditions, secondary structure, icshape, PDB structure, and Cas13 target context.
-
π¨ Flexible Generation Modes Support template masking generation, partial seed preservation, and position-specific design via design_pos.
-
π Batch Inference by JSON Load a JSON list through data_path for large-scale batch inference.
-
π€ Ready-to-Export Results Export outputs directly as JSON files under infer_results for downstream evaluation and visualization.
It is recommended to create the environment from install.sh in the project root.
conda create -n RDiffusion python=3.8.11conda activate RDiffusionbash install.shpython inference.py --helpIf this command prints the argument help message correctly, the inference entry and required dependencies are ready.
RDiffusion pretrained models can be downloaded from:
https://modelscope.cn/models/wj1006/RDiffusion/files
After downloading, place all model files into the checkpoints folder.
The following checkpoints are used by this repository:
-
pretrained_gen.pt - Base diffusion generator checkpoint. Recommended default for uncon and text tasks.
-
rfam_gen.pt - Diffusion generator checkpoint specialized for RFAM family-conditioned generation.
-
rfam_guidance.pt - Guidance classifier checkpoint for RFAM label guidance during sampling.
-
disease_gen.pt - Diffusion generator checkpoint for disease-related RNA generation.
-
disease_guidance.pt - Guidance classifier checkpoint for disease target guidance.
-
prot_rna_bind_gen.pt - Diffusion generator checkpoint for protein-RNA binding related generation.
-
prot_rna_bind_guidance.pt - Multi-label guidance checkpoint for protein binding targets.
-
ss_gen.pt - Diffusion generator checkpoint for secondary structure (SS) task.
-
ts_gen.pt - Diffusion generator checkpoint for tertiary structure (TS) conditioned task.
-
utr_gen.pt - Diffusion generator checkpoint for UTR task.
-
utr_guidance.pt - Guidance checkpoint for UTR optimization/regression objective.
-
cas13_gen.pt - Diffusion generator checkpoint for Cas13 guide design.
-
cas13_guidance.pt - Guidance checkpoint for Cas13 activity-aware generation.
RDiffusion test data can be downloaded from:
https://modelscope.cn/models/wj1006/RDiffusion_test_data
After downloading, place the files into the corresponding project data directories as needed (for example under test_data/).
All examples below should be run from the project root.
Detailed tutorials for all supported tasks are provided in the tutorials/ folder.
Run diffusion sampling without any task guidance.
python inference.py \
--tasks uncon \
--lens 120 \
--diffusion_model_path checkpoints/pretrained_gen.pt \
--num_samples 5 \
--output_path results/infer_results/uncon_infer.jsonGenerate RNA sequences conditioned only by a text prompt (func_cond).
This task does not load any guidance model, and by default uses checkpoints/pretrained_gen.pt.
python inference.py \
--tasks text \
--diffusion_model_path checkpoints/pretrained_gen.pt \
--func_cond "RNA aptamer with high stability" \
--lens 120 \
--num_samples 5 \
--output_path results/infer_results/text_infer.jsonApply class-level constraints using RFAM family targets.
python inference.py \
--tasks rfam \
--rfam_target RF00001 \
--diffusion_model_path checkpoints/rfam_gen.pt \
--guidance_scale 1.0 \
--num_samples 5 \
--lens 120 \
--update_by_guide \
--update_all \
--output_path results/infer_results/rfam_infer.jsonGuide generation using disease labels.
python inference.py \
--tasks disease \
--disease_target Osteoarthritis \
--diffusion_model_path checkpoints/disease_gen.pt \
--guidance_scale 1.0 \
--lens 20 \
--num_samples 10 \
--update_by_guide \
--update_all \
--output_path results/infer_results/disease_infer.jsonGuide generation using a list of protein names (multi-label).
Use -ProteinName to indicate a negative target (reduce binding probability to that protein).
python inference.py \
--tasks prot_rna_bind \
--protein_targets EIF4G2,TRA2A \
--diffusion_model_path checkpoints/prot_rna_bind_gen.pt \
--guidance_scale 1.0 \
--lens 101 \
--num_samples 5 \
--update_by_guide \
--update_all \
--output_path results/infer_results/prot_rna_bind_infer.json
# Mixed positive/negative targets: increase CAPRIN1 binding and suppress AARS binding.
python inference.py \
--tasks prot_rna_bind \
--protein_targets CAPRIN1,-AARS \
--diffusion_model_path checkpoints/prot_rna_bind_gen.pt \
--guidance_scale 1.0 \
--lens 101 \
--num_samples 5 \
--update_by_guide \
--update_all \
--output_path results/infer_results/prot_rna_bind_infer_mixed.jsonUse dot-bracket secondary structure conditions for guided design.
python inference.py \
--tasks ss \
--diffusion_model_path checkpoints/ss_gen.pt \
--secondary_structure "(((...)))..." \
--lens 12 \
--num_samples 3 \
--update_by_guide \
--update_all \
--output_path results/infer_results/ss_infer.jsonπ‘ Note: The ss task depends on ERNIE-RNA related model checkpoints/arguments (defaults are already provided in the script).
Use encoded PDB structure features as condition input.
python inference.py \
--tasks ts \
--diffusion_model_path checkpoints/ts_gen.pt \
--pdb_path /path/to/example.pdb \
--num_samples 3 \
--argmax \
--output_path results/infer_results/ts_infer.jsonRun generation with UTR guidance.
python inference.py \
--tasks utr \
--diffusion_model_path checkpoints/utr_gen.pt \
--num_samples 5 \
--output_path results/infer_results/utr_infer.jsonBuild full context from target_before, target_at_guide, and target_after, then output guide_seq.
python inference.py \
--tasks cas13 \
--diffusion_model_path checkpoints/cas13_gen.pt \
--target_before GAAGGAGCTTGAGCTCAAAA \
--target_at_guide GCTCTGAAAACAAGCGCATCTCTAGAGA \
--target_after CAAATAATCTCCATGACTAG \
--num_samples 5 \
--output_path results/infer_results/cas13_infer.jsonFor example, RFAM + protein binding joint guidance:
python inference.py \
--tasks rfam,prot_rna_bind \
--rfam_target RF00001 \
--diffusion_model_path checkpoints/prot_rna_bind_gen.pt(pretrained_gen.pt/rfam_gen.pt) \
--protein_targets CAPRIN1 \
--guidance_scales '{"rfam":1.4,"prot_rna_bind":1.1}' \
--num_samples 5 \
--output_path results/infer_results/multi_task_infer.jsondata_path should point to a JSON list, where each item defines one sample input (for example template, targets, and other fields).
python inference.py \
--tasks rfam \
--diffusion_model_path checkpoints/prot_rna_bind_gen.pt \
--data_path results/infer_results/test_rfam.json \
--output_path results/infer_results/rfam_batch_infer.jsonThe following are the most commonly used and important parameters.
-
π― tasks Task type. Supports a single task or comma-separated multi-task input. Available values: uncon, text, rfam, disease, prot_rna_bind, ss, ts, utr, cas13.
-
𧬠template Initial template sequence. If provided, generation/design is performed on top of this template according to mask_ratio or design_pos.
-
π lens Target generation length. Especially important when template is not provided.
-
π num_samples Number of samples to generate per input.
-
π§ guidance_scale Global guidance strength.
-
π update_by_guide Whether to enable gradient-based guidance updates from guidance models during sampling. For tasks without guidance model (
uncon,text,ts), this flag has no effect. -
π update_all Whether each guidance update modifies logits at all masked positions (
True) or only the current sampled position (False). In practice,Trueusually gives stronger guidance but can be less diverse. -
π func_cond Plain text condition string. This is required for task
text, and should be natural language text (not a label ID). -
π mask_ratio Ratio of positions to mask in template-based generation. Larger values increase novelty, smaller values preserve more from template.
-
π§ guidance_scales Task-level guidance strengths in JSON format, for example {"rfam":1.5,"ss":2.0}.
-
βοΈ design_pos Specify design position ranges, for example 88-115 or (5-9,10-17,19-25).
-
ποΈ data_path Path to batch input JSON. When set, each record is sampled once, which is suitable for batch processing.
-
π protein_targets Comma-separated protein names for
prot_rna_bind. Prefix with-to suppress binding to that protein (for exampleCAPRIN1,-AARS). -
π€ output_path Path to output JSON results.
-
π§© secondary_structure / icshape / pdb_path Inputs for ss conditioning, icshape conditioning, and ts 3D structure conditioning, respectively.
The following is the core inference-related structure (non-essential details omitted).
RDiffusion/
βββ inference.py
βββ install.sh
βββ checkpoints/
βββ figures/
β βββ RDiffusion_workflow.pdf
βββ results/
β βββ infer_results/
βββ docs/
βββ src/
βββ design/
βββ guidance_models/
βββ models/
βββ data/
βββ utils/
βββ ERNIE-RNA/
βββ structure_encoder/
βββ evaluation/
βββ visualization/
- π§ͺ For first-time validation, start with a single task (for example ss or rfam) to confirm checkpoints and environment are working correctly.
- π For multi-task runs, start with smaller guidance_scales and increase them gradually.
- π If using data_path for batch processing, begin with a small smoke test of 2-3 samples.
To extend with new tasks, start from inference.py and the inference_* modules under src/utils.
This source code is released under the MIT License. See the LICENSE file in the root directory for details.
Our framework and model training were inspired by the following outstanding open-source projects:
We sincerely thank the authors of these works for providing excellent foundations for RDiffusion.

