Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0125-preview· OpenAIAi2 WildChat-4.8M (AI2)

import os import pandas as pd from pdb2sql import interface from pdb2sql import pdb2sql…

  1. User

    import os import pandas as pd from pdb2sql import interface from pdb2sql import pdb2sql from Bio import pairwise2 from Bio.pairwise2 import format_alignment

    Read the CSV file

    triplet_complex_df = pd.read_csv('triplet_complex.csv')

    Define the Google Drive folder

    google_drive_folder = '/content/drive/MyDrive/pdb_files/'

    Iterate over each entry

    for index, row in triplet_complex_df.iterrows(): # Assuming 'Entry ID' is the column name containing the IDs entry_id = row['Entry ID']

    # Form the PDB file name
    pdb_file_path = os.path.join(google_drive_folder, f"{entry_id}.pdb")
    
    # Call pdb2sql with the PDB file name
    pdb_db = pdb2sql(pdb_file_path)
    db = interface(pdb_db)
    
    # Get contact residues
    itf_residue_pair = db.get_contact_residues(cutoff=3, return_contact_pairs=True)
    
    print("Interface residue pairs for Entry ID:", entry_id)
    print(itf_residue_pair)
    
    # Define the file name for each entry
    output_file = f"interface_residue_pairs_{entry_id}.txt"
    
    with open(output_file, "w") as file:
        for key, value in itf_residue_pair.items():
            # Convert key and value to strings
            key_str = str(key)
            value_str = str(value)
    
            # Calculate alignment similarity score
            alignments = pairwise2.align.globalxx(key_str, value_str)
            alignment = alignments[0]
            score = alignment[2]
            file.write(f"{key_str} -> {value_str} -> Similarity Score: {score}\n")
    
        print(f"Output saved to {output_file}")
    

    Now generate Euclidean distance between each residue pair instead of alignment similarity score and save the text files into google_drive_folder = '/content/drive/MyDrive/ALLtxt_files/'

  2. Assistant

    To calculate the Euclidean distance between each residue pair and save the output text files under a different Google Drive folder, you will need to modify the code segment that calculates the alignment similarity score. Instead, we will calculate the Euclidean distance between the points using their (x, y, z) coordinates. Note that this requires extracting the atomic coordinates of the residues involved in each pair.

    Here's an updated version of the loop segment that focuses on calculating the Euclidean distance and saving the output files to /content/drive/MyDrive/ALLtxt_files/:

    import numpy as np
    
    # Assuming other imports and code setup remain the same
    
    # Define the new Google Drive folder for saving output files
    all_txt_files_folder = '/content/drive/MyDrive/ALLtxt_files/'
    
    for index, row in triplet_complex_df.iterrows():
        entry_id = row['Entry ID']
        pdb_file_path = os.path.join(google_drive_folder, f"{entry_id}.pdb")
        
        pdb_db = pdb2sql(pdb_file_path)
        db = interface(pdb_db)
    
        itf_residue_pair = db.get_contact_residues(cutoff=3, return_contact_pairs=True)
    
        print("Interface residue pairs for Entry ID:", entry_id)
        print(itf_residue_pair)
    
        # Define the new output file path
        output_file_path = os.path.join(all_txt_files_folder, f"interface_residue_pairs_{entry_id}.txt")
    
        with open(output_file_path, "w") as file:
            for pair in itf_residue_pair:
                res1 = db.get('x,y,z', chainID=pair[0][0], resSeq=pair[0][1], name=pair[0][2])
                res2 = db.get('x,y,z', chainID=pair[1][0], resSeq=pair[1][1], name=pair[1][2])
    
                if res1 and res2:  # Ensure both residues have coordinate data
                    res1_coords = np.array(res1[0])
                    res2_coords = np.array(res2[0])
                    
                    # Calculate Euclidean distance
                    distance = np.linalg.norm(res1_coords - res2_coords)
                    
                    pair_str = f"{pair[0]} <-> {pair[1]}"
                    file.write(f"{pair_str} -> Euclidean Distance: {distance:.2f}\n")
    
            print(f"Output saved to {output_file_path}")
    

    This script:

    1. Iterates over each entry in your CSV file.
    2. For each pair of contact residues, retrieves their atomic coordinates (x,y,z).
    3. Calculates the Euclidean distance between each pair of residues.
    4. Writes the residue pair and their Euclidean distance to a new file in the specified Google Drive folder for text files.

    Make sure that the columns where you're trying to retrieve data (chainID, resSeq, name) exactly match the available columns in your PDB stand-ins within the pdb2sql database. Adjustments may be necessary depending on your specific PDB file data structure.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.