# Partial Diffusion

Protein redesign on an uploaded structure: RFdiffusion partially re-diffuses the backbone at selected residues to generate multiple designs. For each backbone, ProteinMPNN samples candidate sequences and AlphaFold2 evaluates them, with the lowest-RMSD candidate selected as the final sequence. Each final sequence is then independently folded with Chai-1. When a ligand is selected, it is docked to the predicted structure and scored by Gnina using affinity and CNN scores.

## 基础信息

| 项目 | 值 |
|------|-----|
| Base URL | `https://sciminer.tech/console/api` |
| API Endpoint | `/v1/internal/tools/invoke` |
| Content-Type | `application/json` |
| Authentication | `X-Auth-Token: <YOUR_API_KEY>` |

## 1. Predict Gpu

**Tool Name:** `predict_gpu_predict_gpu_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `docking_use_MSA_search` | `select` | ✗ | Whether Chai-1 docking uses MSA and template search | `True`, `False` |
| `input_pdb` | `file` | ✓ | Input protein structure file (PDB or mmCIF) used as the design scaffold; multi-chain structures are supported (required)<br/>file suffix: `pdb`, `cif` |  |
| `diffused_residues` | `string` | ✗ | Residues whose backbone structure will be redesigned by diffusion, using the residue numbering of the input structure, in the format 'ChainID: start-end; ...' (e.g. 'A: 1-172; B: 1-18,30-34'). Chain IDs must exist in the input structure; missing (gap) residues are ignored. Empty keeps the input backbone |  |
| `design_residues` | `string` | ✗ | Residues whose sequence will be redesigned by ProteinMPNN, same numbering and format as diffused_residues (e.g. 'A: 1-172; B: 1-18,30-34'). Empty redesigns all sequences |  |
| `partial_T` | `number` | ✗ | Number of partial-diffusion steps; smaller values stay closer to the input structure, larger values allow more structural change |  |
| `num_designs` | `number` | ✗ | Number of backbone designs to generate; runtime and points scale linearly with this value |  |
| `ligand_smiles` | `array` | ✗ | List of ligand SMILES. Chai-1 docking + Gnina scoring is enabled only when score_smiles_idx is also provided; only the selected ligand is docked and scored |  |
| `docking_diffn_samples_num` | `number` | ✗ | Number of Chai-1 complex samples generated per design for docking (only used when docking is enabled) |  |
| `score_smiles_idx` | `string` | ✗ | Selects the ligand to dock and score as 'L1', 'L2', ... referring to items of ligand_smiles; providing it together with ligand_smiles enables docking and scoring |  |

### 示例代码

#### Python

```python
import requests

BASE_URL = "https://sciminer.tech/console/api"
API_KEY = "<YOUR_API_KEY>"
endpoint = "/v1/internal/tools/invoke"

# If the invoked API includes FILE-type parameters, upload the file first to obtain a `file_id`,
# then fill the corresponding field in `parameters` with the returned `file_id`.
# File upload example (form-data, parameter name is `file`):

# files = {'file': open('path/to/your_file.ext', 'rb')}
# upload_url = f"{BASE_URL}/v1/internal/tools/file"
# resp_upload = requests.post(upload_url, files=files, headers={"X-Auth-Token": f"{API_KEY}"}, timeout=60)
# resp_upload.raise_for_status()
# file_id = resp_upload.json().get("file_id")
# print(f"File uploaded successfully, file_id: {file_id}")
# # Then set the `file_id` in the corresponding field of `payload['parameters']`, for example: payload['parameters']["your_file_param_name"] = file_id

headers = {
    "X-Auth-Token": f"{API_KEY}",
    "Content-Type": "application/json",
}

payload = {
    "provider_name": "Partial Diffusion",
    "tool_name": "predict_gpu_predict_gpu_post",
    "parameters": {
    "docking_use_MSA_search": "<DOCKING_USE_MSA_SEARCH>",
    "input_pdb": "<INPUT_PDB_FILE_ID>",
    "diffused_residues": "<DIFFUSED_RESIDUES>",
    "design_residues": "<DESIGN_RESIDUES>",
    "partial_T": 10,
    "num_designs": 10,
    "ligand_smiles": [],
    "docking_diffn_samples_num": 5,
    "score_smiles_idx": "<SCORE_SMILES_IDX>"
},
    # The job name is an optional parameter.
    #"job_name": "xxx",
}

# Step 1: Submit the task.
# Call the /invoke endpoint to start the task and obtain a task_id.
print("1. Submitting task...")
resp_submit = requests.post(f"{BASE_URL}{endpoint}", json=payload, headers=headers, timeout=30)
resp_submit.raise_for_status()
task_id = resp_submit.json().get("task_id")
print(f"Task ID: {task_id}")

# Step 2: Poll for the result.
# Use the task_id obtained above to call the /result endpoint to check status and fetch the result.
# If this tool takes a long time, you can increase the max_retries parameter or after exceeding the maximum number of times, you can use the task_id to re-request.
status_url = f"https://sciminer.tech/console/api/v1/internal/tools/result"
max_retries = 300
status = "PENDING"
for i in range(max_retries):
    print(f"Polling status (attempt {i+1}/{max_retries})...")
    resp_status = requests.get(
        status_url,
        params={"task_id": task_id},
        headers=headers,
        timeout=10
    )
    resp_status.raise_for_status()
    
    result = resp_status.json()
    status = result.get("status")
    print(f"Status: {status}")
    
    if status == "SUCCESS":
        print("✅ Task completed successfully！")
        print(f"Result: {result.get('result')}")
        break
    elif status == "FAILURE":
        print(f"❌ Task failed: {result.get('result')}")
        break
    else:
        # Wait 2 seconds before retrying
        import time
        time.sleep(2)
else:
    print("⏱️  Maximum retry attempts reached. The task is still running.")
```


---

## User Interface URL

> When the user needs a tool recommendation, output the URL.

**URL:** <https://sciminer.tech/utility/tool/Partial-Diffusion>
