# MotifAttnNet

A model for drug metabolism property training and prediction, enabling rapid evaluation of molecular metabolic behavior.

## 基础信息

| 项目 | 值 |
|------|-----|
| 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. Motifattnnet Train Model

**Tool Name:** `motifattnnet_train_model_motifattnnet_train_model_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `train_model_type` | `select` | ✓ | train model type, need to train both the PPB model and the Cmax model. | `PPB Model`, `Cmax Model` |
| `train_dataset` | `file` | ✓ | It must match the train model type.<br/>file suffix: `csv` |  |
| `epochs` | `number` | ✓ | The total number of training rounds. One round means going through the whole dataset once. |  |
| `evaluate_epoch` | `number` | ✓ | How often (in epochs) the model is evaluated during training. |  |
| `evaluate_step` | `number` | ✓ | How often (in training steps/batches) the model is evaluated. |  |
| `learning_rate` | `number` | ✓ | The speed of learning. Higher values train faster but may be unstable; lower values are slower but safer. |  |
| `eps` | `number` | ✓ | A very small value used inside the optimizer to avoid errors. |  |
| `betas` | `string` | ✓ | Optimizer parameters that control how smoothly learning happens. |  |
| `batch_size` | `number` | ✓ | The number of samples used in one training step. Larger = faster but needs more memory; smaller = slower but lighter. |  |
| `early_stopping_epochs` | `number` | ✓ | If the model doesn’t improve for many epochs, training stops early to save time. |  |

### 示例代码

#### 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": "MotifAttnNet",
    "tool_name": "motifattnnet_train_model_motifattnnet_train_model_post",
    "parameters": {
    "train_model_type": "PPB Model",
    "train_dataset": "<TRAIN_DATASET_FILE_ID>",
    "epochs": 1,
    "evaluate_epoch": 1,
    "evaluate_step": 500,
    "learning_rate": 0.0001,
    "eps": 1e-08,
    "betas": "0.9,0.999",
    "batch_size": 64,
    "early_stopping_epochs": 500
},
    # 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. Motifattnnet Predict Drugs Dose

**Tool Name:** `motifattnnet_predict_drugs_dose_motifattnnet_predict_drugs_dose_post`

**Method:** `POST`

### 参数

| 参数名 | 类型 | 必需 | 说明 | 枚举值 |
|--------|------|------|------|--------|
| `predict_dataset` | `file` | ✓ | file suffix: `csv` |  |
| `ppb_models` | `file` | ✓ | file suffix: `pt` |  |
| `cmax_model` | `file` | ✓ | file suffix: `pt` |  |
| `drugs_dose` | `string` | ✓ | Delimit multiple dose values with “,”. For example, “10, 100”. |  |
| `predict_batch_size` | `number` | ✓ |  |  |

### 示例代码

#### 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": "MotifAttnNet",
    "tool_name": "motifattnnet_predict_drugs_dose_motifattnnet_predict_drugs_dose_post",
    "parameters": {
    "predict_dataset": "<PREDICT_DATASET_FILE_ID>",
    "ppb_models": "<PPB_MODELS_FILE_ID>",
    "cmax_model": "<CMAX_MODEL_FILE_ID>",
    "drugs_dose": "<DRUGS_DOSE>",
    "predict_batch_size": 64
},
    # 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/MotifAttnNet>
