# Generate json


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Single protein sequence (default)

> Default pipeline, will run MSA and template search

------------------------------------------------------------------------

<a href="https://github.com/sky1ove/af_kit/blob/main/af_kit/json.py#L11"
target="_blank" style="float:right; font-size:smaller">source</a>

### dump_json

>  dump_json (data, save_path)

*Save json data into a file*

------------------------------------------------------------------------

<a href="https://github.com/sky1ove/af_kit/blob/main/af_kit/json.py#L17"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_protein_json

>  get_protein_json (name, seq, save_path=None, seeds=[1])

*Generate json of single protein sequence for input of docker command*

<table>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>name</td>
<td></td>
<td></td>
<td>job name</td>
</tr>
<tr>
<td>seq</td>
<td></td>
<td></td>
<td>aa sequence</td>
</tr>
<tr>
<td>save_path</td>
<td>NoneType</td>
<td>None</td>
<td>.json</td>
</tr>
<tr>
<td>seeds</td>
<td>list</td>
<td>[1]</td>
<td></td>
</tr>
</tbody>
</table>

``` python
data = get_protein_json('proteinA','AAA','data/proteinA.json',seeds=[1,2,3])
data
```

    {'name': 'proteinA',
     'modelSeeds': [1, 2, 3],
     'sequences': [{'protein': {'id': 'A', 'sequence': 'AAA'}}],
     'bondedAtomPairs': [],
     'dialect': 'alphafold3',
     'version': 2}

## Protein-SMILES

- First run the normal `sequence only` pipeline for the protein
- Get the output data.json file, read it, load the
  `["sequences"][0]["protein"]`

------------------------------------------------------------------------

<a href="https://github.com/sky1ove/af_kit/blob/main/af_kit/json.py#L45"
target="_blank" style="float:right; font-size:smaller">source</a>

### read_json

>  read_json (file_path)

``` python
protein_json = read_json('data/seq_only_data.json')
```

------------------------------------------------------------------------

<a href="https://github.com/sky1ove/af_kit/blob/main/af_kit/json.py#L51"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_protein_smiles_json

>  get_protein_smiles_json (smi_id:str, SMILES:str, protein_json,
>                               save_path=None, seeds=[1])

*Get json for protein-ligand docking task*

<table>
<thead>
<tr>
<th></th>
<th><strong>Type</strong></th>
<th><strong>Default</strong></th>
<th><strong>Details</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>smi_id</td>
<td>str</td>
<td></td>
<td></td>
</tr>
<tr>
<td>SMILES</td>
<td>str</td>
<td></td>
<td></td>
</tr>
<tr>
<td>protein_json</td>
<td></td>
<td></td>
<td>json type</td>
</tr>
<tr>
<td>save_path</td>
<td>NoneType</td>
<td>None</td>
<td>.json</td>
</tr>
<tr>
<td>seeds</td>
<td>list</td>
<td>[1]</td>
<td></td>
</tr>
</tbody>
</table>

``` python
out = get_protein_smiles_json('smi_name','CCC',protein_json,'data/protein_smi.json',seeds=[1,2,3])
```

Let’s take a look for the json:

``` python
str(out)[:100]
```

    "{'name': 'smi_name', 'modelSeeds': [1, 2, 3], 'sequences': [{'ligand': {'id': 'L', 'smiles': 'CCC'}}"

``` python
df = pd.DataFrame({'idx':['a','b'],'smi':['CCC','OCO']})
df
```

<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }
&#10;    .dataframe tbody tr th {
        vertical-align: top;
    }
&#10;    .dataframe thead th {
        text-align: right;
    }
</style>

<table class="dataframe" data-quarto-postprocess="true" data-border="1">
<thead>
<tr style="text-align: right;">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">idx</th>
<th data-quarto-table-cell-role="th">smi</th>
</tr>
</thead>
<tbody>
<tr>
<td data-quarto-table-cell-role="th">0</td>
<td>a</td>
<td>CCC</td>
</tr>
<tr>
<td data-quarto-table-cell-role="th">1</td>
<td>b</td>
<td>OCO</td>
</tr>
</tbody>
</table>

</div>

``` python
project_name='sdf'
for idx, smi in df.values:
    _ = get_protein_smiles_json(idx,smi,protein_json,f'af_input/{project_name}/{idx}.json',seeds=[1,2,3])
```

## Split the files to subfolder for multi-GPUs

------------------------------------------------------------------------

<a href="https://github.com/sky1ove/af_kit/blob/main/af_kit/json.py#L85"
target="_blank" style="float:right; font-size:smaller">source</a>

### split_nfolder

>  split_nfolder (folder_dir, n=4)

*Move json files from a folder into subfolders (folder_0, folder_1, …,
folder_N).*

``` python
split_nfolder(f'af_input/{project_name}')
```

    Distributed 2 files into 4 folders.

## End
