# AlphaFold2

AlphaFold2 is a deep learning framework that predicts protein 3D structures from amino acid sequences with high accuracy. It integrates multiple sequence alignments and structural templates, providing an efficient tool for structural biology and protein design.

## 基础信息

| 项目 | 值 |
|------|-----|
| 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. Alphafold2 Predict

**Tool Name:** `alphafold2_predict_alphafold2_predict_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `model_type` | `select` | ✗ | Model type. 'auto' selects alphafold2_ptm for monomer and alphafold2_multimer_v3 for complex. | `auto`, `alphafold2_ptm`, `alphafold2_multimer_v3`, `alphafold2_multimer_v2`, `alphafold2_multimer_v1`, `deepfold_v1` |
| `msa_mode` | `select` | ✗ | MSA mode: 'mmseqs2_uniref_env' (default), 'mmseqs2_uniref', or 'single_sequence' (no MSA, for testing). | `mmseqs2_uniref_env`, `mmseqs2_uniref`, `single_sequence` |
| `pair_mode` | `select` | ✗ | MSA pairing (complexes only): 'unpaired_paired' (pair same species + unpaired), 'paired' (only paired), 'unpaired' (separate per chain). | `unpaired_paired`, `paired`, `unpaired` |
| `pairing_strategy` | `select` | ✗ | Pairing strategy (complexes only): 'greedy' (fast) or 'complete' (accurate but slower). | `greedy`, `complete` |
| `sequences` | `array` | ✓ | Protein amino acid sequence(s) as chain list. Single chain for monomer, multiple for complex. The platform submits this field as one form item containing a list literal (e.g. ["ACDEGA", "EKSSG"]); a plain one-chain-per-item list is also accepted. |  |
| `num_models` | `number` | ✗ | Number of models to run (1-5). More models increase reliability but require more time. |  |
| `num_recycles` | `number` | ✗ | Recycling iterations (0-3). More iterations improve structure quality but require more time. |  |
| `use_templates` | `boolean` | ✗ | Whether to use template structures from the PDB template database. |  |
| `num_results` | `number` | ✗ | Number of prediction results to return (1-20). Each result uses a different random seed. |  |

### 示例代码

#### 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": "AlphaFold2",
    "tool_name": "alphafold2_predict_alphafold2_predict_post",
    "parameters": {
    "model_type": "<MODEL_TYPE>",
    "msa_mode": "<MSA_MODE>",
    "pair_mode": "<PAIR_MODE>",
    "pairing_strategy": "<PAIRING_STRATEGY>",
    "sequences": [],
    "num_models": 3,
    "num_recycles": 3,
    "use_templates": false,
    "num_results": 1
},
    # 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.")
```


---

## 2. Alphafold2 Predict Batch

**Tool Name:** `alphafold2_predict_batch_alphafold2_predict_batch_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `model_type` | `select` | ✗ | Model type. 'auto' selects alphafold2_ptm for monomer and alphafold2_multimer_v3 for complex. | `auto`, `alphafold2_ptm`, `alphafold2_multimer_v3`, `alphafold2_multimer_v2`, `alphafold2_multimer_v1`, `deepfold_v1` |
| `msa_mode` | `select` | ✗ | MSA mode: 'mmseqs2_uniref_env' (default), 'mmseqs2_uniref', or 'single_sequence' (no MSA, for testing). | `mmseqs2_uniref_env`, `mmseqs2_uniref`, `single_sequence` |
| `pair_mode` | `select` | ✗ | MSA pairing (complexes only): 'unpaired_paired' (pair same species + unpaired), 'paired' (only paired), 'unpaired' (separate per chain). | `unpaired_paired`, `paired`, `unpaired` |
| `pairing_strategy` | `select` | ✗ | Pairing strategy (complexes only): 'greedy' (fast) or 'complete' (accurate but slower). | `greedy`, `complete` |
| `input_file` | `file` | ✓ | One JSON batch file (.json). A JSON array with one object per prediction: {"name": "optional-unique-label", "sequences": ["CHAIN1", "CHAIN2", ...]} — all chains in one object are predicted together as a single multi-chain input; sequence items may also be objects like {"sequence": "ACDE"}. 'name' is optional (defaults to group_1, group_2, ...).<br/>file suffix: `json` |  |
| `num_models` | `number` | ✗ | Number of models to run per prediction (1-5). More models increase reliability but require more time. |  |
| `num_recycles` | `number` | ✗ | Recycling iterations (0-3). More iterations improve structure quality but require more time. |  |
| `use_templates` | `boolean` | ✗ | Whether to use template structures from the PDB template database. |  |
| `num_results` | `number` | ✗ | Number of prediction results to return PER prediction group (1-20). Each result uses a different random seed. |  |

### 示例代码

#### 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": "AlphaFold2",
    "tool_name": "alphafold2_predict_batch_alphafold2_predict_batch_post",
    "parameters": {
    "model_type": "<MODEL_TYPE>",
    "msa_mode": "<MSA_MODE>",
    "pair_mode": "<PAIR_MODE>",
    "pairing_strategy": "<PAIRING_STRATEGY>",
    "input_file": "<INPUT_FILE_FILE_ID>",
    "num_models": 3,
    "num_recycles": 3,
    "use_templates": false,
    "num_results": 1
},
    # 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/AlphaFold2>
