# REINVENT4

AI-driven molecular design tool for de novo design, scaffold hopping, R-group replacement, linker design, and molecule optimization using reinforcement learning and transfer learning.

## 基础信息

| 项目 | 值 |
|------|-----|
| 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. Generate molecules using various model types (reinvent, libinvent, linkinvent, mol2mol, pepinvent).
Supports custom trained models from /learning endpoint.

**Tool Name:** `sampling_sampling_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `model_type` | `select` | ✗ | Type of model (options: reinvent, libinvent, linkinvent, mol2mol, pepinvent, default: reinvent) | `reinvent`, `libinvent`, `linkinvent`, `mol2mol`, `pepinvent` |
| `sample_strategy` | `select` | ✗ | Sampling strategy for Mol2Mol/PepInvent (options: multinomial, beamsearch) | `multinomial`, `beamsearch` |
| `num_smiles` | `number` | ✗ | Number of SMILES to sample (range: 1-10000, default: 100) |  |
| `unique_molecules` | `boolean` | ✗ | Remove duplicate molecules (options: true, false, default: true) |  |
| `randomize_smiles` | `boolean` | ✗ | Randomize SMILES atom order (options: true, false, default: true) |  |
| `smiles_file` | `file` | ✗ | Optional SMILES file for LibInvent/LinkInvent/Mol2Mol |  |
| `model_file` | `file` | ✗ | Optional trained model file (.pt) from /learning endpoint. If provided, overrides default prior model.<br/>file suffix: `pt` |  |
| `temperature` | `number` | ✗ | Temperature for multinomial sampling (range: 0.1-5.0, optional) |  |

### 示例代码

#### 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": "REINVENT4",
    "tool_name": "sampling_sampling_post",
    "parameters": {
    "model_type": "<MODEL_TYPE>",
    "sample_strategy": "<SAMPLE_STRATEGY>",
    "num_smiles": 100,
    "unique_molecules": false,
    "randomize_smiles": false,
    "smiles_file": "<SMILES_FILE_FILE_ID>",
    "model_file": "<MODEL_FILE_FILE_ID>",
    "temperature": 2
},
    # 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. Fine-tune a molecular generative model using transfer learning with custom SMILES data.

**Tool Name:** `transfer_learning_transfer_learning_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `model_type` | `select` | ✗ | Model type for transfer learning. Options: 'reinvent' (generates from scratch, learns molecular distributions), 'mol2mol' (transforms molecules, learns transformation patterns). (default: reinvent) | `reinvent`, `mol2mol` |
| `transfer_smiles_file` | `file` | ✓ | Training SMILES file for fine-tuning. Format varies by model type.<br/>file suffix: `smi`, `txt`, `csv` |  |
| `input_model_file` | `file` | ✗ | Optional trained model file (.pt) to use as starting point. If not provided, uses default prior model.<br/>file suffix: `pt` |  |
| `num_epochs` | `number` | ✗ | Training epochs (default: 10) |  |
| `batch_size` | `number` | ✗ | Batch size (default: 64) |  |
| `learning_rate` | `number` | ✗ | Learning rate (default: 0.0001) |  |

### 示例代码

#### 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": "REINVENT4",
    "tool_name": "transfer_learning_transfer_learning_post",
    "parameters": {
    "model_type": "<MODEL_TYPE>",
    "transfer_smiles_file": "<TRANSFER_SMILES_FILE_FILE_ID>",
    "input_model_file": "<INPUT_MODEL_FILE_FILE_ID>",
    "num_epochs": 10,
    "batch_size": 64,
    "learning_rate": 0.0001
},
    # 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.")
```


---

## 3. Optimize molecular generation using reinforcement learning with scoring components.
Supports Docking as an optimization target alongside other molecular property components.

**Tool Name:** `staged_learning_staged_learning_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `model_type` | `select` | ✗ | Model: 'reinvent' generates from scratch; 'mol2mol' transforms molecules; 'libinvent' adds R-groups; 'linkinvent' connects fragments. (default: reinvent) | `reinvent`, `libinvent`, `linkinvent`, `mol2mol`, `pepinvent` |
| `components` | `select_array` | ✗ | List of scoring components for optimization. Options: QED, MolecularWeight, TPSA, SlogP, Csp3, HBondAcceptors, HBondDonors, NumRotBond, NumHeavyAtoms, NumRings, NumAromaticRings, NumHeteroAtoms, SAScore, TanimotoSimilarity, CustomAlerts, Docking:vina, Docking:smina, Docking:gnina, Docking:vina_flex. When Docking is included, two-stage training is automatically enabled for efficiency. Weights are equally distributed. | `QED`, `MolecularWeight`, `TPSA`, `SlogP`, `Csp3`, `HBondAcceptors`, `HBondDonors`, `NumRotBond`, `NumHeavyAtoms`, `NumRings`, `NumAromaticRings`, `NumHeteroAtoms`, `SAScore`, `TanimotoSimilarity`, `CustomAlerts`, `Docking:gnina` |
| `seed_smiles_file` | `file` | ✗ | Seed molecules for reinforcement learning. REQUIRED for mol2mol/libinvent/linkinvent/pepinvent. NOT needed for reinvent (generates from scratch).<br/>file suffix: `smi`, `txt`, `csv` |  |
| `ref_smiles_file` | `file` | ✗ | Reference molecules for TanimotoSimilarity. Required when components includes 'TanimotoSimilarity'.<br/>file suffix: `smi`, `txt`, `csv` |  |
| `input_model_file` | `file` | ✗ | Optional trained model file (.pt) to use as starting point (e.g. from /transfer_learning). If not provided, uses default prior model.<br/>file suffix: `pt` |  |
| `smarts_filters` | `string` | ✗ | SMARTS patterns to filter molecules (newline-separated). Required when components includes 'CustomAlerts'. |  |
| `protein_file` | `file` | ✗ | [Docking] Protein structure file (PDB, CIF, or PDBQT). Required when components includes 'Docking'.<br/>file suffix: `pdb`, `cif`, `pdbqt` |  |
| `binding_site` | `string` | ✗ | [Docking] Binding site pocket center and grid box. Use pocket picker. Format: Center:X,Y,Z;Size:SX,SY,SZ. Required when components includes 'Docking'. |  |
| `flexible_residues` | `string` | ✗ | [Docking] Flexible receptor residues for vina_flex engine (format: Chain:ResNum comma-separated, e.g., 'A:85,A:98,A:152', optional). Use residue picker to select flexible sidechains in binding pocket. Only used when components includes 'Docking:vina_flex'. |  |
| `max_steps` | `number` | ✗ | Training steps (default: 100) |  |
| `batch_size` | `number` | ✗ | Batch size (default: 64) |  |
| `learning_rate` | `number` | ✗ | Learning rate (default: 0.0001) |  |

### 示例代码

#### 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": "REINVENT4",
    "tool_name": "staged_learning_staged_learning_post",
    "parameters": {
    "model_type": "<MODEL_TYPE>",
    "components": [
        "OPTION VALUE1",
        "OPTION VALUE2"
    ],
    "seed_smiles_file": "<SEED_SMILES_FILE_FILE_ID>",
    "ref_smiles_file": "<REF_SMILES_FILE_FILE_ID>",
    "input_model_file": "<INPUT_MODEL_FILE_FILE_ID>",
    "smarts_filters": "<SMARTS_FILTERS>",
    "protein_file": "<PROTEIN_FILE_FILE_ID>",
    "binding_site": "<BINDING_SITE>",
    "flexible_residues": "<FLEXIBLE_RESIDUES>",
    "max_steps": 20,
    "batch_size": 64,
    "learning_rate": 0.0001
},
    # 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/REINVENT4>
