ligand-workflow 0.0.8
A workflow for aligning ligands and calculating contacts.

# Ligand Workflow

`ligand_workflow` 是一个用于处理和分析分子对接数据的工作流工具。它包括多个功能模块，能够帮助你对齐配体，计算分子间接触并将 JSON 格式的数据转换为 CSV 表格，便于进一步分析。

## 功能

- **ligand-align**: 对齐多个结构中的配体到参考结构的配体（基于pymol的）。
- **ligand-contacts**: 计算分子之间的极性接触并输出结果（基于pymol的）。
- **json-to-csv**: 将包含多个 PDB 文件的 JSON 数据转换为 CSV 格式，便于后续分析和展示。

## 安装

你可以使用 `pip` 从 PyPI 安装该包，也可以从源代码安装。

### 通过 PyPI 安装

```bash
pip install ligand_workflow
```

## 用法
依托于config file进行工作流配置，config file的格式如下：

```plaintxt
6GZR.1-10_09 #这是x-ray结构的文件名
resn FH8 and chain A and resi 101 #这是需要处理的配体的筛选条件
chain A and polymer # 这是需要处理的RNA/DNA/蛋白质的筛选条件
```

### 设计

![img](structure.png)

### 使用说明

```python
from ligand_workflow import ligand_workflow

input_folder = "tests/testOut"
output_csv = "tests/testOut.csv"
output_json = "tests/testOut.json"
config_file = "tests/config.txt"

# Call the ligand_workflow function
ligand_workflow(input_folder=input_folder, output_csv=output_csv, output_json=output_json, config_file=config_file)
```

### 数据格式

使用json来记录contacts信息

```json
{
        "pdb_file": "6GZR.1-10_09.pdb",
        "contacts": [
            {
                "model1": "6GZR.1-10_09",
                "atom1": 785,
                "coord1": [
                    19.78,
                    2.151,
                    6.446
                ],
                "model2": "6GZR.1-10_09",
                "atom2": 1551,
                "coord2": [
                    18.238,
                    1.404,
                    4.299
                ],
                "calculated_distance": 2.747,
                "original_distance": 2.747
            },
            {
                "model1": "6GZR.1-10_09",
                "atom1": 787,
                "coord1": [
                    20.643,
                    0.423,
                    5.186
                ],
                "model2": "6GZR.1-10_09",
                "atom2": 1551,
                "coord2": [
                    18.238,
                    1.404,
                    4.299
                ],
                "calculated_distance": 2.745,
                "original_distance": 2.745
            },
            {
                "model1": "6GZR.1-10_09",
                "atom1": 1271,
                "coord1": [
                    17.308,
                    3.818,
                    5.241
                ],
                "model2": "6GZR.1-10_09",
                "atom2": 1551,
                "coord2": [
                    18.238,
                    1.404,
                    4.299
                ],
                "calculated_distance": 2.753,
                "original_distance": 2.753
            }
        ]
    },
```

用于展示的tables文件是

```plaintxt
contact序号,predict pdb name,x-ray,predict,匹配状态
contact 1,6GZR.1-10_08.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_08,785-6GZR.1-10_08,1551; (19.623,2.207,6.621) - (18.226,1.409,4.269); 2.850 Å",❌ 部分偏移
contact 2,6GZR.1-10_08.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_08,787-6GZR.1-10_08,1551; (20.393,0.322,5.542) - (18.226,1.409,4.269); 2.738 Å",✔️ 完全匹配
contact 3,6GZR.1-10_08.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_08,1271-6GZR.1-10_08,1551; (17.257,3.798,5.272) - (18.226,1.409,4.269); 2.766 Å",✔️ 完全匹配
contact 1,6GZR.1-10_06.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_06,785-6GZR.1-10_06,1551; (19.699,2.367,6.505) - (18.242,1.400,4.278); 2.832 Å",✔️ 完全匹配
contact 2,6GZR.1-10_06.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_06,787-6GZR.1-10_06,1551; (20.550,0.508,5.441) - (18.242,1.400,4.278); 2.734 Å",✔️ 完全匹配
contact 3,6GZR.1-10_06.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_06,1271-6GZR.1-10_06,1551; (17.209,3.789,5.214) - (18.242,1.400,4.278); 2.766 Å",✔️ 完全匹配
contact 1,6GZR.1-10_07.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_07,785-6GZR.1-10_07,1551; (19.669,2.312,6.541) - (18.197,1.425,4.315); 2.812 Å",✔️ 完全匹配
contact 2,6GZR.1-10_07.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_07,787-6GZR.1-10_07,1551; (20.506,0.470,5.438) - (18.197,1.425,4.315); 2.739 Å",✔️ 完全匹配
contact 3,6GZR.1-10_07.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_07,1271-6GZR.1-10_07,1551; (17.210,3.816,5.245) - (18.197,1.425,4.315); 2.749 Å",✔️ 完全匹配
contact 1,6GZR.1-10_05.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_05,785-6GZR.1-10_05,1551; (19.652,2.168,6.638) - (18.240,1.402,4.274); 2.858 Å",❌ 部分偏移
contact 2,6GZR.1-10_05.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_05,787-6GZR.1-10_05,1551; (20.345,0.240,5.582) - (18.240,1.402,4.274); 2.737 Å",✔️ 完全匹配
contact 3,6GZR.1-10_05.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_05,1271-6GZR.1-10_05,1551; (17.279,3.779,5.331) - (18.240,1.402,4.274); 2.773 Å",✔️ 完全匹配
contact 1,6GZR.1-10_10.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_10,785-6GZR.1-10_10,1551; (19.800,2.140,6.556) - (18.256,1.390,4.414); 2.745 Å",✔️ 完全匹配
contact 2,6GZR.1-10_10.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_10,787-6GZR.1-10_10,1551; (20.636,0.381,5.324) - (18.256,1.390,4.414); 2.741 Å",✔️ 完全匹配
contact 3,6GZR.1-10_10.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_10,1271-6GZR.1-10_10,1551; (17.293,3.812,5.263) - (18.256,1.390,4.414); 2.741 Å",✔️ 完全匹配
contact 1,6GZR.1-10_04.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_04,785-6GZR.1-10_04,1551; (19.419,1.955,6.677) - (18.306,1.363,4.203); 2.777 Å",✔️ 完全匹配
contact 2,6GZR.1-10_04.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_04,787-6GZR.1-10_04,1551; (20.150,0.000,5.697) - (18.306,1.363,4.203); 2.737 Å",✔️ 完全匹配
contact 3,6GZR.1-10_04.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_04,819-6GZR.1-10_04,1551; (20.352,4.026,3.986) - (18.306,1.363,4.203); 3.365 Å",❌ 部分偏移
extra 1,6GZR.1-10_04.pdb,,"6GZR.1-10_04,1267-6GZR.1-10_04,1547; (15.284,1.982,0.053) - (16.972,1.247,2.242); 2.860 Å",
extra 2,6GZR.1-10_04.pdb,,"6GZR.1-10_04,1271-6GZR.1-10_04,1551; (17.375,3.804,5.056) - (18.306,1.363,4.203); 2.748 Å",
extra 3,6GZR.1-10_04.pdb,,"6GZR.1-10_04,1272-6GZR.1-10_04,1547; (16.300,4.416,3.124) - (16.972,1.247,2.242); 3.357 Å",
contact 1,6GZR.1-10_01.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_01,785-6GZR.1-10_01,1551; (19.657,2.163,6.643) - (18.245,1.398,4.276); 2.860 Å",❌ 部分偏移
contact 2,6GZR.1-10_01.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_01,787-6GZR.1-10_01,1551; (20.345,0.230,5.593) - (18.245,1.398,4.276); 2.740 Å",✔️ 完全匹配
contact 3,6GZR.1-10_01.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_01,1271-6GZR.1-10_01,1551; (17.282,3.774,5.335) - (18.245,1.398,4.276); 2.774 Å",✔️ 完全匹配
contact 1,6GZR.1-10_03.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_03,785-6GZR.1-10_03,1551; (19.728,2.261,6.537) - (18.203,1.422,4.317); 2.821 Å",✔️ 完全匹配
contact 2,6GZR.1-10_03.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_03,787-6GZR.1-10_03,1551; (20.551,0.462,5.356) - (18.203,1.422,4.317); 2.741 Å",✔️ 完全匹配
contact 3,6GZR.1-10_03.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_03,1271-6GZR.1-10_03,1551; (17.279,3.823,5.309) - (18.203,1.422,4.317); 2.757 Å",✔️ 完全匹配
contact 1,6GZR.1-10_02.pdb,"6GZR.1-10_09,785-6GZR.1-10_09,1551; (19.780,2.151,6.446) - (18.238,1.404,4.299); 2.747 Å","6GZR.1-10_02,785-6GZR.1-10_02,1551; (19.498,2.088,6.758) - (18.244,1.399,4.253); 2.885 Å",❌ 部分偏移
contact 2,6GZR.1-10_02.pdb,"6GZR.1-10_09,787-6GZR.1-10_09,1551; (20.643,0.423,5.186) - (18.238,1.404,4.299); 2.745 Å","6GZR.1-10_02,787-6GZR.1-10_02,1551; (20.138,0.116,5.754) - (18.244,1.399,4.253); 2.736 Å",✔️ 完全匹配
contact 3,6GZR.1-10_02.pdb,"6GZR.1-10_09,1271-6GZR.1-10_09,1551; (17.308,3.818,5.241) - (18.238,1.404,4.299); 2.753 Å","6GZR.1-10_02,1271-6GZR.1-10_02,1551; (17.275,3.772,5.324) - (18.244,1.399,4.253); 2.778 Å",✔️ 完全匹配
```