<jupyter_start><jupyter_text>Notebook to add plddt results (b-factor) into pdb file  To run, you need to do the following  * Change output_dir to path of the output folder used when running AF2 * Change models to the list of model names you used in AF2 * If not installed before, you will need to install pickle `pip install pickle5` or through conda `conda install -c conda-forge pickle5`<jupyter_code>output_dir="/stornext/HPCScratch/home/iskander.j/AF/output/query_colab"
models=['model_1']

def set_bfactor(ip,op, bfac):
    I = open(ip,"r").readlines()
    O = open(op,"w")
    for line in I:
        if line[0:6] == "ATOM  ":
            seq_id = int(line[22:26].strip()) - 1
            O.write(f"{line[:60]}{bfac[seq_id]:6.2f}{line[66:]}")
    O.close()
import os
import pickle

for m in models:
    pdb_ip=os.path.join(output_dir, f'relaxed_{m}.pdb')
    pdb_op=os.path.join(output_dir, f'relaxed_{m}_modified.pdb')

    results = pickle.load(open(os.path.join(output_dir,f'result_{m}.pkl'), 'rb'))
    set_bfactor(pdb_ip,pdb_op, results['plddt'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1408839779005525, 'fraction_numerical': 0.016574585635359115, 'mean_word_length': 4.276699029126213, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '534600', 'license': 'Apache-2.0', 'n_tokens_mistral': 422, 'n_tokens_neox': 414, 'n_words': 99, 'path': 'notebooks/Modify_PDB.ipynb', 'repo_name': 'WEHI-ResearchComputing/alphafold2.0', 'size': '1086'}