# AbNativ

AbNatiV: VQ-VAE-based assessment of antibody & nanobody nativeness for scoring and humanisation. Two task interfaces: /score (nativeness scoring) and /humanise (Fv humanisation).

## 基础信息

| 项目 | 值 |
|------|-----|
| 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. Antibody nativeness scoring (unpaired single-chain AbNatiV / AbNatiV2, or paired p-AbNatiV2).

Scoring modes:
    - unpaired: score a single chain with the model selected by `model_type`.
    - paired:   score a paired VH + VL with p-AbNatiV2 (model_type is ignored).

model_type values (used only for unpaired scoring):
    v1 (AbNatiV, default training sets):
        VH      - human immune-system-derived heavy chain
        VKappa  - human kappa light chain
        VLambda - human lambda light chain
        VHH     - camelid immune-system-derived single-domain antibody (nanobody)
    v2 (AbNatiV2, unpaired, improved):
        VH2     - human heavy chain
        VL2     - human light chain (kappa + lambda unified)
        VHH2    - camelid single-domain antibody (nanobody)

**Tool Name:** `score_score_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `scoring_mode` | `select` | ✗ | Scoring task: 'unpaired' = single-chain AbNatiV score (VH/VKappa/VLambda/VHH or v2 variants); 'paired' = p-AbNatiV2 paired VH/VL score (default: unpaired) | `unpaired`, `paired` |
| `model_type` | `select` | ✗ | AbNatiV model for unpaired scoring. Only used when scoring_mode=unpaired (ignored for paired). Pick by chain type and model generation. v1 (AbNatiV, default training sets): VH = human immune-system-derived heavy chain; VKappa = human kappa light chain; VLambda = human lambda light chain; VHH = camelid (nanobody) heavy chain. v2 (AbNatiV2, unpaired, improved): VH2 = human heavy chain; VL2 = human light chain (kappa+lambda unified); VHH2 = camelid (nanobody) heavy chain. Defaults to VH2. | `VH`, `VKappa`, `VLambda`, `VHH`, `VH2`, `VL2`, `VHH2` |
| `sequence` | `string` | ✗ | Raw antibody sequence, or multiline/FASTA text for batch unpaired scoring (used when no input file is provided) |  |
| `fasta_file` | `file` | ✗ | Optional batch input. FASTA (.fa/.fasta) of single chains, or a CSV (.csv). CSV columns are auto-detected by header prefix: an 'id'/'name' column is the row id; a column starting with 'vh' is the heavy chain; starting with 'vl' is the light chain; starting with 'seq' is the single-chain sequence. Unpaired scoring needs id + seq (or a FASTA); paired scoring needs id + vh + vl.<br/>file suffix: `fa`, `fasta`, `csv` |  |
| `vh_sequence` | `string` | ✗ | VH (heavy chain) sequence for paired scoring (single sequence), used when scoring_mode=paired |  |
| `vl_sequence` | `string` | ✗ | VL (light chain) sequence for paired scoring (single sequence), used when scoring_mode=paired |  |
| `mean_score_only` | `boolean` | ✗ | If true, output only one score per sequence; otherwise also emit per-residue profiles (default: false) |  |

### 示例代码

#### 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": "AbNativ",
    "tool_name": "score_score_post",
    "parameters": {
    "scoring_mode": "<SCORING_MODE>",
    "model_type": "<MODEL_TYPE>",
    "sequence": "<SEQUENCE>",
    "fasta_file": "<FASTA_FILE_FILE_ID>",
    "vh_sequence": "<VH_SEQUENCE>",
    "vl_sequence": "<VL_SEQUENCE>",
    "mean_score_only": false
},
    # 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. Humanise

**Tool Name:** `humanise_humanise_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `humanisation_mode` | `select` | ✗ | Humanisation task: 'nanobody' = dual-control VHH humanisation (hum_vhh); 'vh_vl_unpaired' = parallel VH/VL humanisation with unpaired models (hum_vh_vl); 'vh_vl_paired' = paired-model humanisation improving humanness + pairing (hum_vh_vl_paired) (default: nanobody) | `nanobody`, `vh_vl_unpaired`, `vh_vl_paired` |
| `sequence` | `string` | ✗ | Nanobody (VHH) sequence, or multiline/FASTA text for batch nanobody humanisation (used when humanisation_mode=nanobody) |  |
| `fasta_file` | `file` | ✗ | Optional FASTA of nanobody sequences (humanisation_mode=nanobody only)<br/>file suffix: `fa`, `fasta`, `csv` |  |
| `vh_sequence` | `string` | ✗ | VH sequence (required for humanisation_mode=vh_vl_unpaired or vh_vl_paired) |  |
| `vl_sequence` | `string` | ✗ | VL sequence (required for humanisation_mode=vh_vl_unpaired or vh_vl_paired) |  |
| `pdb_file` | `file` | ✗ | Optional crystal structure (.pdb/.cif) to assess solvent exposure (RASA); does NOT replace the sequence input. Must be cleaned (no waters/hetero atoms) and chains must be named 'H' (heavy) and 'L' (light) — chain ids are not configurable. If omitted, the structure is predicted (NbForge for nanobodies, ABodyBuilder3 for VH/VL)<br/>file suffix: `pdb`, `cif` |  |

### 示例代码

#### 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": "AbNativ",
    "tool_name": "humanise_humanise_post",
    "parameters": {
    "humanisation_mode": "<HUMANISATION_MODE>",
    "sequence": "<SEQUENCE>",
    "fasta_file": "<FASTA_FILE_FILE_ID>",
    "vh_sequence": "<VH_SEQUENCE>",
    "vl_sequence": "<VL_SEQUENCE>",
    "pdb_file": "<PDB_FILE_FILE_ID>"
},
    # 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/AbNativ>
